From: Mike Gelfand Date: Sun, 18 Oct 2015 11:48:10 +0000 (+0000) Subject: Display notifications via tray icon if dbus is not available X-Git-Tag: 2.90~112 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b8829d3fbeea63e7ea91f66491e1d637892710e;p=transmission Display notifications via tray icon if dbus is not available --- diff --git a/qt/Application.cc b/qt/Application.cc index e7bd90d3b..26758df95 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -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 (-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 (); diff --git a/qt/MainWindow.h b/qt/MainWindow.h index b9e6217ba..4dcb620c4 100644 --- a/qt/MainWindow.h +++ b/qt/MainWindow.h @@ -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 ();