aboutsummaryrefslogtreecommitdiff
path: root/src/ChatWindow.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-25 17:51:19 +0200
committerdec05eba <dec05eba@protonmail.com>2018-10-25 17:51:19 +0200
commit616fb291ee1f62202affbec3a043f741c2c2469c (patch)
treeac4347b38cf598e29893fa2be5584324e5258b9a /src/ChatWindow.cpp
parent9096d6ef3710118f98c46f6e7f7689d5aa11c7f4 (diff)
Login works and showing messages, nothing else
Diffstat (limited to 'src/ChatWindow.cpp')
-rw-r--r--src/ChatWindow.cpp52
1 files changed, 36 insertions, 16 deletions
diff --git a/src/ChatWindow.cpp b/src/ChatWindow.cpp
index a428d0b..70dd734 100644
--- a/src/ChatWindow.cpp
+++ b/src/ChatWindow.cpp
@@ -1,10 +1,12 @@
#include "../include/ChatWindow.hpp"
#include "../include/ChatMessage.hpp"
#include <gtkmm/alignment.h>
+#include <cassert>
namespace dchat
{
- ChatWindow::ChatWindow()
+ ChatWindow::ChatWindow() :
+ channelCount(0)
{
setupTopBar();
@@ -54,14 +56,14 @@ namespace dchat
leftPanel->set_vexpand(true);
sidePanels->add1(*leftPanel);
- Gtk::Grid *leftPanelChannels = Gtk::manage(new Gtk::Grid());
- leftPanelChannels->set_vexpand(true);
- leftPanel->add1(*leftPanelChannels);
+ leftPanelChannels.set_vexpand(true);
+ leftPanel->add1(leftPanelChannels);
Gtk::Label *channelsTitle = Gtk::manage(new Gtk::Label());
channelsTitle->set_name("channels-title");
channelsTitle->set_text("Channels");
- leftPanelChannels->attach(*channelsTitle, 0, 0, 1, 1);
+ channelsTitle->set_halign(Gtk::ALIGN_START);
+ leftPanelChannels.attach(*channelsTitle, 0, 0, 1, 1);
////
Gtk::Grid *leftPanelUsers = Gtk::manage(new Gtk::Grid());
@@ -71,6 +73,7 @@ namespace dchat
Gtk::Label *usersTitle = Gtk::manage(new Gtk::Label());
usersTitle->set_name("users-title");
usersTitle->set_text("Users");
+ usersTitle->set_halign(Gtk::ALIGN_START);
leftPanelUsers->attach(*usersTitle, 0, 0, 1, 1);
}
@@ -79,17 +82,8 @@ namespace dchat
chatArea.set_vexpand(true);
rightPanel->attach(chatArea, 0, 0, 1, 2);
- Gtk::Grid *chatAreaLayout = Gtk::manage(new Gtk::Grid());
- chatAreaLayout->set_name("chat-area-layout");
- chatArea.add(*chatAreaLayout);
-
- for(int i = 0; i < 100; ++i)
- {
- ChatMessage *message = Gtk::manage(new ChatMessage("Arezu", "hellooooo" + std::to_string(i)));
- message->set_valign(Gtk::Align::ALIGN_START);
- message->set_hexpand(true);
- chatAreaLayout->attach(*message, 0, i, 1, 1);
- }
+ chatAreaLayout.set_name("chat-area-layout");
+ chatArea.add(chatAreaLayout);
}
void ChatWindow::setupChatInput(Gtk::Grid *rightPanel)
@@ -103,4 +97,30 @@ namespace dchat
chatInput.set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR);
chatScrollWindow->add(chatInput);
}
+
+ void ChatWindow::addChannel(const odhtdb::Hash &nodeHash)
+ {
+ assert(channelDataById.find(nodeHash) == channelDataById.end());
+ printf("Added channel\n");
+ Gtk::Button *channelButton = Gtk::manage(new Gtk::Button("Channel name"));
+ channelButton->get_style_context()->add_class("channel-button");
+ channelButton->set_hexpand(true);
+ channelButton->get_child()->set_halign(Gtk::ALIGN_START);
+ channelButton->show();
+ leftPanelChannels.attach(*channelButton, 0, 1 + channelCount, 1, 1);
+ ++channelCount;
+ channelDataById[nodeHash] = { channelButton, 0 };
+ }
+
+ void ChatWindow::addLocalMessage(const odhtdb::Hash &channelId, Glib::ustring msg)
+ {
+ auto it = channelDataById.find(channelId);
+ assert(it != channelDataById.end());
+ ChatMessage *message = Gtk::manage(new ChatMessage("Arezu", msg));
+ message->set_valign(Gtk::Align::ALIGN_START);
+ message->set_hexpand(true);
+ message->show_all();
+ chatAreaLayout.attach(*message, 0, it->second.messageCount, 1, 1);
+ ++it->second.messageCount;
+ }
} \ No newline at end of file