Display notifications via tray icon if dbus is not available

This commit is contained in:
Mike Gelfand
2015-10-18 11:48:10 +00:00
parent 7f46aeeccf
commit 3b8829d3fb
2 changed files with 11 additions and 1 deletions
+9 -1
View 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 ();
+2
View 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 ();