From a1766fb9389931481aad96a21a52a0a56d95f55c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 17 May 2018 07:29:25 +0200 Subject: Send notification when a new message is received and window is not focused --- project.conf | 1 + src/Cache.cpp | 1 + src/main.cpp | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/project.conf b/project.conf index cf60d63..bfe9719 100644 --- a/project.conf +++ b/project.conf @@ -15,3 +15,4 @@ gl = "17.3" x11 = "1.6.5" libnsgif = "0.2.0" libpreview = "0.2.0" +libnotify = "0.7.0" diff --git a/src/Cache.cpp b/src/Cache.cpp index cf1510a..a6270f0 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -357,6 +357,7 @@ namespace dchat string downloadLimitBytesStr = to_string(downloadLimitBytes); + // TODO: Escape url, it can contain escape sequence and execute shell code maliciously... Process::string_type cmd = "curl -L --silent -o '"; cmd += filepath.native(); cmd += "' --max-filesize " + downloadLimitBytesStr + " --range 0-" + downloadLimitBytesStr + " --url '" + url + "'"; diff --git a/src/main.cpp b/src/main.cpp index 9d8c6aa..fa33556 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,11 +19,14 @@ #include #include #include +#include #include using namespace std; using namespace dchat; -using namespace TinyProcessLib; + +static bool focused = true; +static NotifyNotification *notification = nullptr; void channelChangeUserNickname(Channel *channel, const StringView data, const odhtdb::Signature::PublicKey &userPublicKey) { @@ -63,6 +66,12 @@ void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash, { string msg(decryptedData.data, decryptedData.size); channel->addLocalMessage(msg, user, ntp::NtpTimestamp::fromCombined(timestamp).seconds, requestHash); + if(!focused) + { + notify_notification_update(notification, "dchat", msg.c_str(), 0); + notify_notification_set_timeout(notification, 5000); // 5 sec timeout + notify_notification_show(notification, 0); + } break; } case ChannelDataType::DELETE_MESSAGE: @@ -104,6 +113,8 @@ int main(int argc, char **argv) printf("parent path: %s\n", parentPath.string().c_str()); boost::filesystem::current_path(parentPath); // Ensures loading of resources works no matter which path we run this executable from */ + notify_init("dchat"); + notification = notify_notification_new("dchat", "", 0); const int FRAMERATE_FOCUSED = 200; const int FRAMERATE_NOT_FOCUSED = 30; @@ -673,6 +684,12 @@ int main(int argc, char **argv) window.setFramerateLimit(FRAMERATE_FOCUSED); //else if(event.type == sf::Event::LostFocus) // window.setFramerateLimit(FRAMERATE_NOT_FOCUSED); + + if(event.type == sf::Event::GainedFocus) + focused = true; + else if(event.type == sf::Event::LostFocus) + focused = false; + GlobalContextMenu::processEvent(event); currentChannel->processEvent(event); } -- cgit v1.2.3