]> granicus.if.org Git - transmission/commitdiff
Display notifications via tray icon if dbus is not available
authorMike Gelfand <mikedld@mikedld.com>
Sun, 18 Oct 2015 11:48:10 +0000 (11:48 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Sun, 18 Oct 2015 11:48:10 +0000 (11:48 +0000)
qt/Application.cc
qt/MainWindow.h

index e7bd90d3bcaabf78f285a3bccb43696c2d063e80..26758df957a23c668a076cad506efd6be4449775 100644 (file)
@@ -19,6 +19,7 @@
 #include <QMessageBox>
 #include <QProcess>
 #include <QRect>
+#include <QSystemTrayIcon>
 
 #include <libtransmission/transmission.h>
 #include <libtransmission/tr-getopt.h>
@@ -545,6 +546,13 @@ Application::raise ()
 bool
 Application::notifyApp (const QString& title, const QString& body) const
 {
+  QDBusConnection bus = QDBusConnection::sessionBus ();
+  if (!bus.isConnected ())
+    {
+      myWindow->trayIcon ().showMessage (title, body);
+      return true;
+    }
+
   const QString dbusServiceName   = QString::fromUtf8 ("org.freedesktop.Notifications");
   const QString dbusInterfaceName = QString::fromUtf8 ("org.freedesktop.Notifications");
   const QString dbusPath          = QString::fromUtf8 ("/org/freedesktop/Notifications");
@@ -560,7 +568,7 @@ Application::notifyApp (const QString& title, const QString& body) const
   args.append (QVariantMap ());                       // hints - unused atm
   args.append (static_cast<int32_t> (-1));            // use the default timeout period
   m.setArguments (args);
-  QDBusMessage replyMsg = QDBusConnection::sessionBus ().call (m);
+  QDBusMessage replyMsg = bus.call (m);
   //std::cerr << qPrintable (replyMsg.errorName ()) << std::endl;
   //std::cerr << qPrintable (replyMsg.errorMessage ()) << std::endl;
   return (replyMsg.type () == QDBusMessage::ReplyMessage) && !replyMsg.arguments ().isEmpty ();
index b9e6217ba785e1876286102dc88ad2f05a010737..4dcb620c47fc47d1bdc33415500617defcb51eee 100644 (file)
@@ -53,6 +53,8 @@ class MainWindow: public QMainWindow
     MainWindow (Session&, Prefs&, TorrentModel&, bool minized);
     virtual ~MainWindow ();
 
+    QSystemTrayIcon& trayIcon () { return myTrayIcon; }
+
   public slots:
     void startAll ();
     void startSelected ();