aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Window.cpp24
-rw-r--r--src/WindowNotification.cpp34
2 files changed, 50 insertions, 8 deletions
diff --git a/src/Window.cpp b/src/Window.cpp
index 6493b2d..38c187e 100644
--- a/src/Window.cpp
+++ b/src/Window.cpp
@@ -1,34 +1,39 @@
#include "../include/Window.hpp"
#include "../include/Cache.hpp"
#include "../include/ChannelDataType.hpp"
+#include "../include/WindowNotification.hpp"
namespace dchat
{
Window::Window()
{
set_border_width(0);
- add(stack);
+ Gtk::Overlay *overlay = Gtk::manage(new Gtk::Overlay());
+ WindowNotification *windowNotification = Gtk::manage(new WindowNotification());
+ overlay->add_overlay(*windowNotification);
+ overlay->add(stack);
+ add(*overlay);
stack.set_transition_type(Gtk::StackTransitionType::STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT);
stack.set_transition_duration(250);
stack.add(loginWindow, "login");
stack.add(chatWindow, "chat");
- show_all_children();
+ show_all();
- loginWindow.setLoginHandler([this](const Glib::ustring &username, const Glib::ustring &password)
+ loginWindow.setLoginHandler([this, windowNotification](const Glib::ustring &username, const Glib::ustring &password)
{
if(!database)
{
- fprintf(stderr, "You are not connected to the bootstrap node yet! please wait...\n");
+ windowNotification->show("You are not connected to the bootstrap node yet! please wait...");
return;
}
try
{
- printf("Trying to login with username %s\n", username.raw().c_str());
+ fprintf(stderr, "Trying to login with username %s\n", username.raw().c_str());
auto storedNodes = database->getStoredNodeUserInfoDecrypted(username.raw(), password.raw());
- printf("Successfully logged in as %s\n", username.raw().c_str());
+ fprintf(stderr, "Successfully logged in as %s\n", username.raw().c_str());
stack.set_visible_child(chatWindow);
for(auto &nodeInfo : storedNodes)
@@ -38,7 +43,9 @@ namespace dchat
}
catch(std::exception &e)
{
- fprintf(stderr, "Failed to login, reason: %s\n", e.what());
+ Glib::ustring errMsg = "Failed to login, reason: ";
+ errMsg += e.what();
+ windowNotification->show(errMsg);
}
});
@@ -74,9 +81,10 @@ namespace dchat
std::lock_guard<std::mutex> lock(databaseCallbackMutex);
};
- printf("Connecting...\n");
+ fprintf(stderr, "Connecting...\n");
database = odhtdb::Database::connect("83.252.53.188", 27130, Cache::getDchatDir(), callbackFuncs).get();
stack.set_visible_child(loginWindow);
+ windowNotification->show("Connected to 83.252.53.188:27130");
}
Window::~Window()
diff --git a/src/WindowNotification.cpp b/src/WindowNotification.cpp
new file mode 100644
index 0000000..acb47da
--- /dev/null
+++ b/src/WindowNotification.cpp
@@ -0,0 +1,34 @@
+#include "../include/WindowNotification.hpp"
+#include <gtkmm.h>
+
+static Gtk::Overlay *overlay = nullptr;
+static Gtk::Label *label = nullptr;
+
+namespace dchat
+{
+ WindowNotification::WindowNotification()
+ {
+ label.set_line_wrap(true);
+ label.set_line_wrap_mode(Pango::WRAP_WORD_CHAR);
+ label.set_halign(Gtk::ALIGN_START);
+ revealer.add(label);
+ add(revealer);
+ set_valign(Gtk::ALIGN_START);
+ set_halign(Gtk::ALIGN_CENTER);
+ revealer.get_style_context()->add_class("window-notification");
+ show_all();
+ }
+
+ void WindowNotification::show(const Glib::ustring &text)
+ {
+ hideTimer.disconnect();
+ label.set_text(text);
+ revealer.set_reveal_child(true);
+ int showTime = (int)std::max(1.0, (double)text.size() * 0.1);
+ hideTimer = Glib::signal_timeout().connect_seconds([this]
+ {
+ revealer.set_reveal_child(false);
+ return false;
+ }, showTime);
+ }
+} \ No newline at end of file