Version: 12.5
Date: 2023-07-25
Author: bgstack15
Message: Add support for building with desktop notification support.
--- a/FreeFileSync/Source/Makefile
+++ b/FreeFileSync/Source/Makefile
@@ -26,6 +26,13 @@ LDFLAGS  += `pkg-config --libs   gtk+-3.
 #treat as system headers so that warnings are hidden:
 CXXFLAGS += -isystem/usr/include/gtk-3.0
 
+with_notifications ?= YES
+ifeq ($(with_notifications),YES)
+# package libglibmm-2.4-dev or glibmm24-devel
+cxxFlags  += `pkg-config --cflags giomm-2.4` -Dwith_notifications
+linkFlags += `pkg-config --libs   giomm-2.4`
+endif
+
 #support for SELinux (optional)
 SELINUX_EXISTING=$(shell pkg-config --exists libselinux && echo YES)
 ifeq ($(SELINUX_EXISTING),YES)
--- a/FreeFileSync/Source/ui/progress_indicator.cpp
+++ b/FreeFileSync/Source/ui/progress_indicator.cpp
@@ -23,6 +23,9 @@
 #include "../icon_buffer.h"
 #include "../base/speed_test.h"
 
+#ifdef with_notifications
+#include<giomm-2.4/giomm.h>
+#endif
 
 using namespace zen;
 using namespace fff;
@@ -1449,6 +1452,22 @@ void SyncProgressDialogImpl<TopLevelDial
 
     //pnl_.m_bitmapStatus->SetToolTip(); -> redundant
 
+#ifdef with_notifications
+    // Desktop notification for Linux
+    char title[] = "FreeFileSync";
+    // from https://stackoverflow.com/a/12097772
+    std::wstring ssR {getSyncResultLabel(syncResult)};
+    std::string body;
+    std::transform(ssR.begin(), ssR.end(), std::back_inserter(body), [] (wchar_t c){ return (char)c;});
+    char icon[] = "freefilesync";
+    auto Application = Gio::Application::create("org.zenju.freefilesync", Gio::APPLICATION_FLAGS_NONE);
+    Application->register_application();
+    auto Notification = Gio::Notification::create(title);
+    Notification->set_body(body);
+    auto Icon = Gio::ThemedIcon::create(icon);
+    Notification->set_icon (Icon);
+    Application->send_notification(Notification);
+#endif
     //show status on Windows 7 taskbar
     if (taskbar_)
         switch (syncResult)
