Add KDE notification support.
authorRoy Marples <roy@marples.name>
Thu, 2 Oct 2014 20:57:15 +0000 (20:57 +0000)
committerRoy Marples <roy@marples.name>
Thu, 2 Oct 2014 20:57:15 +0000 (20:57 +0000)
README
TODO
configure
src/dhcpcd-qt/dhcpcd-qt.cpp
src/dhcpcd-qt/dhcpcd-qt.notifyrc [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-qt.pro

diff --git a/README b/README
index 7cb9b448205c0a49e2ef2d70a715028e5881aef5..95b91cbbce677325f7ca240d2d32df1ffea104f6 100644 (file)
--- a/README
+++ b/README
@@ -12,11 +12,12 @@ dhcpcd-online can report on network availability from dhcpcd
 (requires dhcpcd-6.4.4)
 
 Switches to control building of various parts:
-       --with-tools
+       --with-dhcpcd-online
        --with-gtk
        --with-qt
        --with-icons
-For each --with there is a --without.
+       --enable-notification
+For each --with there is a --without and for each --enable a --disable.
 If each part is not specified then the configure will test the system
 for the needed libraries to build and install it.
 
diff --git a/TODO b/TODO
index 6f0797e1cea5799ed6af03868bfe6bfac852d6b0..88d0cd4e3b0151b566117635b5ef1f34f8bd1f07 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,14 +1,3 @@
-dhcpcd-gtk
-----------
-SSID menus need updating when we get new scans like dhcpcd-qt handles it.
-
-dhcpcd-qt
----------
-Needs knotifyplugin support.
-Consider compiling with both this and the QSystemTray bubble and falling
-back to it if knotifyplugin fails to work, like say changing from KDE
-desktop to LXQT.
-
 dhcpcd-efl
 ----------
 Port it!
@@ -17,6 +6,7 @@ TODO's for all
 -----------------------------------
   *  Merge multiple BSSID's with the same SSID into one menu item rather
      than many, picking the strongest one.
+  *  SSID preference
   *  OpenVPN config screen per user and system wide, triggerd via dhcpcd hook.
 
 NON STARTING IDEAS
index f8d7c5dd830b36b0ed628396c7f0afd9214da745..48f30c5e92f98be43312443118894485232d13c9 100755 (executable)
--- a/configure
+++ b/configure
@@ -352,6 +352,8 @@ echo "LIB_DHCPCD=   $x" >>$CONFIG_MK
 # what we actually need.
 echo "LDADD+=          -Wl,--as-needed" >>$CONFIG_MK
 
+_NOTIFY="$NOTIFY"
+_WITH_GTK="$WITH_GTK"
 if [ "$WITH_GTK" = yes -o -z "$WITH_GTK" ]; then
        if pkg-config --cflags gtk+-2.0 >/dev/null 2>&3; then
                WITH_GTK="gtk+-2.0"
@@ -370,8 +372,7 @@ if [ -n "$WITH_GTK" -a "$WITH_GTK" != no ]; then
        if [ "$NOTIFY" = yes -o -z "$NOTIFY" ]; then
                if ! pkg-config --cflags libnotify >/dev/null 2>&3; then
                        echo "libnotify not found" >&2
-                       [ "$NOTIFY" = yes ] && exit 1
-                       NOTIFY=no
+                       [ "$NOTIFY" = yes -n "$_WITH_GTK" ] && exit 1
                fi
                NOTIFY=yes
        fi
@@ -407,6 +408,17 @@ elif [ -n "$WITH_QT" -a "$WITH_QT" != no ]; then
        fi
 fi
 
+NOTIFY="$_NOTIFY"
+if $DHCPCD_QT && [ -z "$NOTFY" -o "$NOTIFY" = yes ]; then
+       if type knotify4 >/dev/null 2>&3; then
+               QMAKE_CONFIG="$QMAKE_CONFIG CONFIG+=has_libkdeui"
+               echo "Building dhcpcd-qt with notification support"
+       elif [ "$NOTIFY" = yes ]; then
+               echo "$0: knotify4 not found" >&2
+               exit 1
+       fi
+fi
+
 if [ -n "$UI" -a -z "$WITH_ICONS" ]; then
        WITH_ICONS=yes
 fi
index 9e69befecac0636c4579503237b2e1fc5f08fa86..2330ad418976e6e2eecacac0509fad9daccba03b 100644 (file)
@@ -40,6 +40,8 @@
 #include "dhcpcd-ifmenu.h"
 #include "dhcpcd-ssidmenu.h"
 
+#include <knotification.h>
+
 DhcpcdQt::DhcpcdQt()
 {
 
@@ -257,8 +259,9 @@ void DhcpcdQt::ifCallback(DHCPCD_IF *i)
                                QSystemTrayIcon::MessageIcon icon =
                                    i->up ? QSystemTrayIcon::Information :
                                    QSystemTrayIcon::Warning;
-                               trayIcon->showMessage(tr("Network Event"),
-                                   msg, icon);
+                               QString t = tr("Network Event");
+                               QString m = msg;
+                               notify(t, m, icon);
                        }
                        free(msg);
                }
@@ -333,7 +336,10 @@ void DhcpcdQt::scanCallback(DHCPCD_WPA *wpa)
                }
                if (!txt.isEmpty() &&
                    (ssidMenu == NULL || !ssidMenu->isVisible()))
+               {
+                       qDebug("%s", qPrintable(txt));
                        notify(title, txt);
+               }
        }
 
        if (wi->setScans(scans) && ssidMenu->isVisible())
@@ -421,11 +427,22 @@ void DhcpcdQt::dispatch() {
 }
 
 void DhcpcdQt::notify(QString &title, QString &msg,
-    QSystemTrayIcon::MessageIcon icon)
+#ifdef NOTIFY
+    QSystemTrayIcon::MessageIcon
+#else
+    QSystemTrayIcon::MessageIcon icon
+#endif
+    )
 {
 
-       qDebug("%s", qPrintable(msg));
+#ifdef NOTIFY
+       KNotification *n = new KNotification("event", this);
+       n->setTitle(title);
+       n->setText(msg);
+       n->sendEvent();
+#else
        trayIcon->showMessage(title, msg, icon);
+#endif
 }
 
 
diff --git a/src/dhcpcd-qt/dhcpcd-qt.notifyrc b/src/dhcpcd-qt/dhcpcd-qt.notifyrc
new file mode 100644 (file)
index 0000000..0b49060
--- /dev/null
@@ -0,0 +1,13 @@
+[Global]
+IconName=dhcpcd
+Comment=Network Configurator
+Name=dhcpcd-qt
+
+[Context/event]
+Name=Network Event
+
+[Event/event]
+Name=Network Event
+Comment=A network event has occured
+Contexts=event
+Action=Popup
index 9168971bb2bd2cdc79f6f43c30acca11c20a830d..6c27c4eb212922e57702d14ac0ddaee2cdb05b9e 100644 (file)
@@ -18,6 +18,12 @@ has_libintl {
        LIBS +=         -lintl
 }
 
+has_libkdeui {
+       LIBS+=          -lkdeui
+       DEFINES+=       NOTIFY
+       INSTALLS+=      notifyrc
+}
+
 QMAKE_CLEAN+=          ${TARGET}
 
 isEmpty(PREFIX) {
@@ -41,4 +47,7 @@ desktop.files=                dhcpcd-qt.desktop
 autostart.path=                $$SYSCONFDIR/xdg/autostart
 autostart.files=       dhcpcd-qt.desktop
 
+notifyrc.path=         $$PREFIX/share/apps/dhcpcd-qt
+notifyrc.files=                dhcpcd-qt.notifyrc
+
 INSTALLS+=             target man8 desktop autostart