diff --git a/design.glade b/design.glade index e6a6524..8848f4c 100644 --- a/design.glade +++ b/design.glade @@ -1,4 +1,5 @@ + - - - True - True + + False + 500 + 300 - - + True - False - True - True + True - + + True - True - 5 - 5 - 5 - 5 + False True True - in - + True - False + True + True + True + in - + True False + + + True + False + + + + 0 + 0 + 2 + - 0 - 0 - 2 + True + True - + + True False - 5 - 5 - 5 - 5 - [Username goes here] - - - 0 - 1 - - - - - True - False - GDK_BUTTON_PRESS_MASK - 5 - 5 - 5 - 5 - applications-system-symbolic.symbolic - - - 1 - 1 - - - - - True - True - - - - - - True - False - True - True - - - True - True - 5 - 5 - 5 - 5 True True - in - + True - False + True + True + True + in - + True False - none - + True - True + False + none - + True - False - No channel has been opened. + True + + + True + False + No channel has been opened. Select a channel on the box to the left. - True + True + + @@ -142,40 +110,66 @@ Select a channel on the box to the left. + + 0 + 0 + 3 + 2 + + + + + True + True + True + 1 + 1 + 1 + 1 + 2000 + face-smile-symbolic + Insert Emoji + Message (2000 character max) + GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_WORD_COMPLETION | GTK_INPUT_HINT_EMOJI | GTK_INPUT_HINT_NONE + True + True + + + 0 + 2 + 3 + - 0 - 0 - 3 - 2 - - - - - True - True - 2000 - Message (2000 character max) - GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_WORD_COMPLETION | GTK_INPUT_HINT_EMOJI | GTK_INPUT_HINT_NONE - True - - - 0 - 2 - 3 + True + True - - True - True - + + + + True + False + Welcome + True + + + True + False + [Username] + + + False + True + True dialog + True ok An error has occured [Error message goes here] @@ -195,156 +189,149 @@ Select a channel on the box to the left. - - - True + False - True - True - + + True False - 5 - 5 - 5 - 5 - Log into Brainlet - - - 0 - 0 - 3 - - - - - True - False - 5 - 5 - 5 - 5 - Domain: - right - - - 0 - 1 - - - - - True - True - 5 - 5 - 5 - 5 - example.com - url - - - 1 - 1 - 2 - - - - - True - False - 5 - 5 - 5 - 5 - Username: - right - - - 0 - 2 - - - - - True - True - 5 - 5 - 5 - 5 - 32 - 32 - False - name - GTK_INPUT_HINT_LOWERCASE | GTK_INPUT_HINT_UPPERCASE_CHARS | GTK_INPUT_HINT_NONE - - - 1 - 2 - 2 - - - - - True - False - 5 - 5 - 5 - 5 - Password: - right - - - 0 - 3 - - - - - True - True - 5 - 5 - 5 - 5 True - 128 - False - 32 - password + True + True + + + True + False + 5 + 5 + 5 + 5 + Domain: + right + + + 0 + 0 + + + + + True + False + 5 + 5 + 5 + 5 + Username: + right + + + 0 + 1 + + + + + True + False + 5 + 5 + 5 + 5 + Password: + right + + + 0 + 2 + + + + + True + True + 5 + 5 + 5 + 5 + example.com + url + + + 1 + 0 + + + + + True + True + 5 + 5 + 5 + 5 + 32 + 32 + False + name + GTK_INPUT_HINT_LOWERCASE | GTK_INPUT_HINT_UPPERCASE_CHARS | GTK_INPUT_HINT_NONE + + + 1 + 1 + + + + + True + True + 5 + 5 + 5 + 5 + True + 128 + False + 32 + password + + + 1 + 2 + + + + + Log in + True + True + True + 5 + 5 + 5 + 5 + + + 1 + 3 + + + + + - - 1 - 3 - 2 - - - - Log in + + True - True - True - 5 - 5 - 5 - 5 + False + Login + True + + + - - 0 - 4 - 3 - - - - - False - Brainlet - - diff --git a/main.cpp b/main.cpp index 255b45f..ebce8cc 100644 --- a/main.cpp +++ b/main.cpp @@ -29,11 +29,13 @@ static std::unique_ptr client = nullptr; -static std::unordered_map channelRowToId; +static std::unordered_map channelRowToChannel; static std::unordered_map> 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 app = Gtk::Application::create("org.hiimgoodpack.brainlet_client"); Glib::RefPtr 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& 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); }