aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChatWindow.cpp20
-rw-r--r--src/Window.cpp14
2 files changed, 22 insertions, 12 deletions
diff --git a/src/ChatWindow.cpp b/src/ChatWindow.cpp
index b53e337..f7cc5e2 100644
--- a/src/ChatWindow.cpp
+++ b/src/ChatWindow.cpp
@@ -1,22 +1,25 @@
#include "../include/ChatWindow.hpp"
#include "../include/ChatMessage.hpp"
#include "../include/InputDialog.hpp"
+#include "../include/Window.hpp"
#include <gtkmm/alignment.h>
#include <gtkmm/viewport.h>
#include <gtkmm/scrollbar.h>
#include <gtkmm/eventbox.h>
-#include <cassert>
+#include <assert.h>
namespace dchat
{
// Merge all messages that are written by the same user without interrupt within a timeframe
const int MERGE_MESSAGE_TIMESTAMP_DIFF_SEC = 60;
- ChatWindow::ChatWindow() :
+ ChatWindow::ChatWindow(Window *_window) :
addRoomButton("images/add_button_small.png", " Add room"),
roomCount(0),
- currentRoomData(nullptr)
+ currentRoomData(nullptr),
+ window(_window)
{
+ assert(window);
leftPanelUsersStack.set_homogeneous(false);
messageAreaStack.set_homogeneous(false);
setupTopBar();
@@ -118,8 +121,12 @@ namespace dchat
{
case Gtk::RESPONSE_ACCEPT:
{
- // TODO: Do not allow if room name size is == 0 or > 32
- currentRoom->rooms->createRoom(createRoomDialog.getInput());
+ // TODO: Show error inline in the create room dialog
+ Glib::ustring roomName = createRoomDialog.getInput();
+ if(roomName.size() == 0 || roomName.size() > 32)
+ window->windowNotification->show("Room name has to be between 1 and 32 characters");
+ else
+ window->rooms->createRoom(roomName);
break;
}
default:
@@ -151,6 +158,7 @@ namespace dchat
chatArea->attach(*chatScrollWindow, 0, 0, 1, 1);
chatInput.set_hexpand(true);
+ chatInput.set_editable(false);
chatInput.set_name("chat-input");
chatInput.set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR);
chatScrollWindow->add(chatInput);
@@ -239,6 +247,7 @@ namespace dchat
currentRoomData = new RoomData { leftPanelUsersLayout, messageAreaLayout, roomButton };
roomDataById[*room->id] = currentRoomData;
currentRoom = room;
+ chatInput.set_editable(true);
leftPanelUsersStack.set_visible_child(roomIdStr);
messageAreaStack.set_visible_child(roomIdStr);
@@ -252,6 +261,7 @@ namespace dchat
currentChannelTitle.set_text(room->name);
currentRoom = room;
currentRoomData = roomDataById[*room->id];
+ chatInput.set_editable(true);
// TODO: Instead of scrolling to bottom, remember scroll position (even after restarting application).
// We want to show oldest unread message first
diff --git a/src/Window.cpp b/src/Window.cpp
index b5a9f26..22e5501 100644
--- a/src/Window.cpp
+++ b/src/Window.cpp
@@ -1,6 +1,5 @@
#include "../include/Window.hpp"
#include <dchat/RoomDataType.hpp>
-#include "../include/WindowNotification.hpp"
#include <dchat/Cache.hpp>
#include <sibs/SafeDeserializer.hpp>
#include <math.h>
@@ -11,10 +10,11 @@ namespace dchat
const int nodesPerColumn = 10;
const int nodesPerRow = 10;
- Window::Window()
+ Window::Window() :
+ chatWindow(this)
{
set_border_width(0);
- WindowNotification *windowNotification = Gtk::manage(new WindowNotification());
+ windowNotification = Gtk::manage(new WindowNotification());
overlay.add_overlay(*windowNotification);
overlay.set_overlay_pass_through(*windowNotification);
overlay.add(stack);
@@ -31,7 +31,7 @@ namespace dchat
//chatWindow.show_all();
//loginWindow.show();
- loginWindow.setLoginHandler([this, windowNotification](const Glib::ustring &username, const Glib::ustring &password)
+ loginWindow.setLoginHandler([this](const Glib::ustring &username, const Glib::ustring &password)
{
if(!rooms || !rooms->database)
{
@@ -57,7 +57,7 @@ namespace dchat
}
});
- loginWindow.setRegisterHandler([this, windowNotification](const Glib::ustring &username, const Glib::ustring &password)
+ loginWindow.setRegisterHandler([this](const Glib::ustring &username, const Glib::ustring &password)
{
if(!rooms || !rooms->database)
{
@@ -84,13 +84,13 @@ namespace dchat
}
});
- loginWindow.setRegisterPasswordMismatch([windowNotification]
+ loginWindow.setRegisterPasswordMismatch([this]
{
windowNotification->show("Passwords do not match");
});
RoomCallbackFuncs roomCallbackFuncs;
- roomCallbackFuncs.connectCallbackFunc = [this, windowNotification](std::shared_ptr<Rooms> rooms, const char *errMsg)
+ roomCallbackFuncs.connectCallbackFunc = [this](std::shared_ptr<Rooms> rooms, const char *errMsg)
{
this->rooms = rooms;
if(rooms)