forked from hiimgoodpack/brainlet-client
design improvements! yay!
This commit is contained in:
parent
ab6eda1a4c
commit
022584bced
2 changed files with 249 additions and 256 deletions
193
design.glade
193
design.glade
|
@ -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,14 +18,18 @@ 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="GtkApplicationWindow" id="ChatWindow">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="default-width">500</property>
|
||||
<property name="default-height">300</property>
|
||||
<child>
|
||||
<object class="GtkPaned" id="Chat">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=2 -->
|
||||
<!-- n-columns=2 n-rows=1 -->
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
|
@ -34,10 +39,6 @@ SOFTWARE.
|
|||
<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>
|
||||
|
@ -60,37 +61,6 @@ SOFTWARE.
|
|||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="UsernameLabel">
|
||||
<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>
|
||||
|
@ -108,10 +78,6 @@ SOFTWARE.
|
|||
<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>
|
||||
|
@ -155,10 +121,18 @@ Select a channel on the box to the left.</property>
|
|||
<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>
|
||||
|
@ -173,9 +147,29 @@ Select a channel on the box to the left.</property>
|
|||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</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,28 +189,16 @@ Select a channel on the box to the left.</property>
|
|||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<!-- n-columns=3 n-rows=5 -->
|
||||
<object class="GtkApplicationWindow" id="LoginWindow">
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=4 -->
|
||||
<object class="GtkGrid" id="Login">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">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">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>
|
||||
<property name="row-homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
|
@ -230,24 +212,7 @@ Select a channel on the box to the left.</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>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -261,11 +226,43 @@ Select a channel on the box to the left.</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>
|
||||
|
@ -282,24 +279,7 @@ Select a channel on the box to the left.</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>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -318,8 +298,7 @@ Select a channel on the box to the left.</property>
|
|||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">3</property>
|
||||
<property name="width">2</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -334,17 +313,25 @@ Select a channel on the box to the left.</property>
|
|||
<property name="margin-bottom">5</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">4</property>
|
||||
<property name="width">3</property>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">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>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="visible">True</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>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
|
26
main.cpp
26
main.cpp
|
@ -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);
|
||||
}
|
||||
|
|
Reference in a new issue