design improvements! yay!

This commit is contained in:
hippoz 2021-04-23 17:32:13 +03:00
parent ab6eda1a4c
commit 022584bced
Signed by: hippoz
GPG key ID: 7C52899193467641
2 changed files with 249 additions and 256 deletions

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!--
Copyright (c) 2021 hiimgoodpack
Permission is hereby granted, free of charge, to any person obtaining a copy of
@ -17,124 +18,91 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkPaned" id="Chat">
<property name="visible">True</property>
<property name="can-focus">True</property>
<object class="GtkApplicationWindow" id="ChatWindow">
<property name="can-focus">False</property>
<property name="default-width">500</property>
<property name="default-height">300</property>
<child>
<!-- n-columns=2 n-rows=2 -->
<object class="GtkGrid">
<object class="GtkPaned" id="Chat">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="can-focus">True</property>
<child>
<object class="GtkScrolledWindow">
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkListBox" id="Channels">
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkListBox" id="Channels">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">2</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">2</property>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="UsernameLabel">
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">[Username goes here]</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkImage" id="SettingsButton">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="events">GDK_BUTTON_PRESS_MASK</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="icon-name">applications-system-symbolic.symbolic</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkListBox" id="Messages">
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="selection-mode">none</property>
<child>
<object class="GtkListBoxRow">
<object class="GtkListBox" id="Messages">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="selection-mode">none</property>
<child>
<object class="GtkLabel">
<object class="GtkListBoxRow">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">No channel has been opened.
<property name="can-focus">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">No channel has been opened.
Select a channel on the box to the left.</property>
<property name="wrap">True</property>
<property name="wrap">True</property>
</object>
</child>
</object>
</child>
</object>
@ -142,40 +110,66 @@ Select a channel on the box to the left.</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">3</property>
<property name="height">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="Message">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="is-focus">True</property>
<property name="margin-start">1</property>
<property name="margin-end">1</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="max-length">2000</property>
<property name="secondary-icon-name">face-smile-symbolic</property>
<property name="secondary-icon-tooltip-markup" translatable="yes">Insert Emoji</property>
<property name="placeholder-text" translatable="yes">Message (2000 character max)</property>
<property name="input-hints">GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_WORD_COMPLETION | GTK_INPUT_HINT_EMOJI | GTK_INPUT_HINT_NONE</property>
<property name="show-emoji-icon">True</property>
<property name="enable-emoji-completion">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
<property name="width">3</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">3</property>
<property name="height">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="Message">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="max-length">2000</property>
<property name="placeholder-text" translatable="yes">Message (2000 character max)</property>
<property name="input-hints">GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_WORD_COMPLETION | GTK_INPUT_HINT_EMOJI | GTK_INPUT_HINT_NONE</property>
<property name="show-emoji-icon">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
<property name="width">3</property>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
<child type="titlebar">
<object class="GtkHeaderBar" id="ChatHeader">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Welcome</property>
<property name="show-close-button">True</property>
<child>
<object class="GtkLabel" id="UsernameLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">[Username]</property>
</object>
</child>
</object>
</child>
</object>
<object class="GtkMessageDialog" id="Error">
<property name="can-focus">False</property>
<property name="modal">True</property>
<property name="destroy-with-parent">True</property>
<property name="type-hint">dialog</property>
<property name="urgency-hint">True</property>
<property name="buttons">ok</property>
<property name="text" translatable="yes">An error has occured</property>
<property name="secondary-text" translatable="yes">[Error message goes here]</property>
@ -195,156 +189,149 @@ Select a channel on the box to the left.</property>
</object>
</child>
</object>
<!-- n-columns=3 n-rows=5 -->
<object class="GtkGrid" id="Login">
<property name="visible">True</property>
<object class="GtkApplicationWindow" id="LoginWindow">
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<object class="GtkLabel">
<!-- n-columns=2 n-rows=4 -->
<object class="GtkGrid" id="Login">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Log into Brainlet</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Domain:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="Domain">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="placeholder-text" translatable="yes">example.com</property>
<property name="input-purpose">url</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Username:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="Username">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="max-length">32</property>
<property name="width-chars">32</property>
<property name="caps-lock-warning">False</property>
<property name="input-purpose">name</property>
<property name="input-hints">GTK_INPUT_HINT_LOWERCASE | GTK_INPUT_HINT_UPPERCASE_CHARS | GTK_INPUT_HINT_NONE</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Password:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="Password">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
<property name="max-length">128</property>
<property name="visibility">False</property>
<property name="width-chars">32</property>
<property name="input-purpose">password</property>
<property name="vexpand">True</property>
<property name="row-homogeneous">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Domain:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Username:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Password:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="Domain">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="placeholder-text" translatable="yes">example.com</property>
<property name="input-purpose">url</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="Username">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="max-length">32</property>
<property name="width-chars">32</property>
<property name="caps-lock-warning">False</property>
<property name="input-purpose">name</property>
<property name="input-hints">GTK_INPUT_HINT_LOWERCASE | GTK_INPUT_HINT_UPPERCASE_CHARS | GTK_INPUT_HINT_NONE</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="Password">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="hexpand">True</property>
<property name="max-length">128</property>
<property name="visibility">False</property>
<property name="width-chars">32</property>
<property name="input-purpose">password</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="LoginButton">
<property name="label" translatable="yes">Log in</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="LoginButton">
<property name="label" translatable="yes">Log in</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Login</property>
<property name="show-close-button">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
<property name="width">3</property>
</packing>
</child>
</object>
<object class="GtkWindow" id="Window">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Brainlet</property>
<child>
<placeholder/>
</child>
</object>
</interface>

View file

@ -29,11 +29,13 @@
static std::unique_ptr<Brainlet::Client> client = nullptr;
static std::unordered_map<Gtk::ListBoxRow*, std::string> channelRowToId;
static std::unordered_map<Gtk::ListBoxRow*, Brainlet::Channel> channelRowToChannel;
static std::unordered_map<std::string, std::vector<Brainlet::Message>> messages;
static std::string currentChannelId;
static Gtk::Window* window;
static Gtk::ApplicationWindow* loginWindow;
static Gtk::ApplicationWindow* chatWindow;
static Gtk::HeaderBar* chatHeader;
static Gtk::Widget* loginInterface;
static Gtk::Entry* domainEntry;
@ -66,7 +68,7 @@ void addChannel(const Brainlet::Channel channel) {
row->show_all_children();
row->show();
channelRowToId.emplace(row, channel.id);
channelRowToChannel.emplace(row, channel);
messages.emplace(
std::piecewise_construct,
std::forward_as_tuple(channel.id),
@ -100,7 +102,9 @@ int main(int argc, char* argv[]) {
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create("org.hiimgoodpack.brainlet_client");
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("./design.glade");
builder->get_widget("Window", window);
builder->get_widget("LoginWindow", loginWindow);
builder->get_widget("ChatWindow", chatWindow);
builder->get_widget("ChatHeader", chatHeader);
builder->get_widget("Login", loginInterface);
builder->get_widget("Domain", domainEntry);
@ -120,8 +124,9 @@ int main(int argc, char* argv[]) {
const std::string username = usernameEntry->get_text();
const std::string password = passwordEntry->get_text();
usernameLabel->set_text(username.c_str());
window->remove();
window->add(*chatInterface);
app->add_window(*chatWindow);
chatWindow->show_all();
loginWindow->close();
client.reset(new Brainlet::Client(domainEntry->get_text()));
client->login(username, password);
@ -143,7 +148,10 @@ int main(int argc, char* argv[]) {
messageList->foreach(std::bind(std::mem_fn(&Gtk::ListBox::remove), messageList, std::placeholders::_1));
// Add messages in the channel selected
currentChannelId = channelRowToId.at(row);
currentChannelId = channelRowToChannel.at(row).id;
// Set the title in the HeaderBar to the currently selected channel's name
chatHeader->set_title(channelRowToChannel.at(row).name);
const std::vector<Brainlet::Message>& channelMessages = messages.at(currentChannelId);
std::for_each(channelMessages.begin(), channelMessages.end(), addMessage);
@ -157,7 +165,5 @@ int main(int argc, char* argv[]) {
messageEntry->set_text("");
});
window->add(*loginInterface);
app->run(*window);
app->run(*loginWindow);
}