design improvements! yay!

This commit is contained in:
hippoz 2021-04-23 17:32:13 +03:00
parent ab6eda1a4c
commit 022584bced
No known key found for this signature in database
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"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- <!--
Copyright (c) 2021 hiimgoodpack Copyright (c) 2021 hiimgoodpack
Permission is hereby granted, free of charge, to any person obtaining a copy of 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 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
--> -->
<!-- Generated with glade 3.38.2 -->
<interface> <interface>
<requires lib="gtk+" version="3.24"/> <requires lib="gtk+" version="3.24"/>
<object class="GtkPaned" id="Chat"> <object class="GtkApplicationWindow" id="ChatWindow">
<property name="visible">True</property> <property name="can-focus">False</property>
<property name="can-focus">True</property> <property name="default-width">500</property>
<property name="default-height">300</property>
<child> <child>
<!-- n-columns=2 n-rows=2 --> <object class="GtkPaned" id="Chat">
<object class="GtkGrid">
<property name="visible">True</property> <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>
<child> <child>
<object class="GtkScrolledWindow"> <!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">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="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="shadow-type">in</property>
<child> <child>
<object class="GtkViewport"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <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> <child>
<object class="GtkListBox" id="Channels"> <object class="GtkViewport">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</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> </object>
</child> </child>
</object> </object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">2</property>
</packing>
</child> </child>
</object> </object>
<packing> <packing>
<property name="left-attach">0</property> <property name="resize">True</property>
<property name="top-attach">0</property> <property name="shrink">True</property>
<property name="width">2</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="UsernameLabel"> <!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</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="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="shadow-type">in</property>
<child> <child>
<object class="GtkViewport"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <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> <child>
<object class="GtkListBox" id="Messages"> <object class="GtkViewport">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="selection-mode">none</property>
<child> <child>
<object class="GtkListBoxRow"> <object class="GtkListBox" id="Messages">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">False</property>
<property name="selection-mode">none</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkListBoxRow">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">True</property>
<property name="label" translatable="yes">No channel has been opened. <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> Select a channel on the box to the left.</property>
<property name="wrap">True</property> <property name="wrap">True</property>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>
@ -142,40 +110,66 @@ Select a channel on the box to the left.</property>
</object> </object>
</child> </child>
</object> </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> </child>
</object> </object>
<packing> <packing>
<property name="left-attach">0</property> <property name="resize">True</property>
<property name="top-attach">0</property> <property name="shrink">True</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>
</packing> </packing>
</child> </child>
</object> </object>
<packing> </child>
<property name="resize">True</property> <child type="titlebar">
<property name="shrink">True</property> <object class="GtkHeaderBar" id="ChatHeader">
</packing> <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> </child>
</object> </object>
<object class="GtkMessageDialog" id="Error"> <object class="GtkMessageDialog" id="Error">
<property name="can-focus">False</property> <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="type-hint">dialog</property>
<property name="urgency-hint">True</property>
<property name="buttons">ok</property> <property name="buttons">ok</property>
<property name="text" translatable="yes">An error has occured</property> <property name="text" translatable="yes">An error has occured</property>
<property name="secondary-text" translatable="yes">[Error message goes here]</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> </object>
</child> </child>
</object> </object>
<!-- n-columns=3 n-rows=5 --> <object class="GtkApplicationWindow" id="LoginWindow">
<object class="GtkGrid" id="Login">
<property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child> <child>
<object class="GtkLabel"> <!-- n-columns=2 n-rows=4 -->
<object class="GtkGrid" id="Login">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</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="hexpand">True</property>
<property name="max-length">128</property> <property name="vexpand">True</property>
<property name="visibility">False</property> <property name="row-homogeneous">True</property>
<property name="width-chars">32</property> <child>
<property name="input-purpose">password</property> <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> </object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
<property name="width">2</property>
</packing>
</child> </child>
<child> <child type="titlebar">
<object class="GtkButton" id="LoginButton"> <object class="GtkHeaderBar">
<property name="label" translatable="yes">Log in</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">False</property>
<property name="receives-default">True</property> <property name="title" translatable="yes">Login</property>
<property name="margin-start">5</property> <property name="show-close-button">True</property>
<property name="margin-end">5</property> <child>
<property name="margin-top">5</property> <placeholder/>
<property name="margin-bottom">5</property> </child>
</object> </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> </child>
</object> </object>
</interface> </interface>

View file

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