Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Compile FreeFileSync with desktop notification support

FreeFileSync is a great graphical file sync tool. I talk about it a lot. Today, I'm sharing a small patch I hacked after stealing from the fabulous arch wiki.

diff -aur 11.9-1/FreeFileSync/Source/Makefile 11.9-2/FreeFileSync/Source/Makefile
--- 11.9-1/FreeFileSync/Source/Makefile 2021-05-06 16:24:53.987902373 -0400
+++ 11.9-2/FreeFileSync/Source/Makefile 2021-05-06 17:09:31.512474440 -0400
@@ -21,6 +22,13 @@
 #treat as system headers so that warnings are hidden:
 cxxFlags  += -isystem/usr/include/gtk-3.0

+with_notifications ?= NO
+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)
diff -aur 11.9-1/FreeFileSync/Source/ui/progress_indicator.cpp 11.9-2/FreeFileSync/Source/ui/progress_indicator.cpp
--- 11.9-1/FreeFileSync/Source/ui/progress_indicator.cpp    2021-05-06 15:20:34.286831934 -0400
+++ 11.9-2/FreeFileSync/Source/ui/progress_indicator.cpp    2021-05-06 17:11:45.486004158 -0400
@@ -32,6 +32,9 @@
 #include "../perf_check.h"
 #include "../icon_buffer.h"

+#ifdef with_notifications
+#include<giomm-2.4/giomm.h>
+#endif

 using namespace zen;
 using namespace fff;
@@ -1359,6 +1362,22 @@
     pnl_.m_staticTextPhase->SetLabel(getSyncResultLabel(syncResult));
     //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_.get())
         switch (syncResult)

The gist of the patch is that it uses the glibmm 2.4 library to make the bare minimum connection to the notification daemon. That's pretty much it. It took me more time to compile this than hack the logic (particularly with the surely weak type conversion) required. So for the niche crowd who tolerates the notification daemon on dbus, and use the same software as me, here you go. On Fedora, the dependency package is pkgconfig(giomm-2.4) (glibmm24-devel) and on Devuan it's libglibmm-2.4-dev.

References

Weblinks

  1. The patch upstream location
  2. Desktop notifications#C++ on the Arch wiki

Comments