From d0afd46fd307f1d086aa2ed71a0766fa19529025 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 2 Apr 2011 08:54:28 +0000 Subject: [PATCH] Get rid of libnotify dependency (Use DBus instead) --- configure | 72 ----------------------------- qbittorrent.qc | 2 - src/mainwindow.cpp | 32 ++++++------- src/qtnotify/notifications.cpp | 26 +++++++++++ src/qtnotify/notifications.h | 84 ++++++++++++++++++++++++++++++++++ src/qtnotify/notifications.xml | 31 +++++++++++++ src/qtnotify/qtnotify.pri | 5 ++ unixconf.pri | 8 ++-- 8 files changed, 164 insertions(+), 96 deletions(-) create mode 100644 src/qtnotify/notifications.cpp create mode 100644 src/qtnotify/notifications.h create mode 100644 src/qtnotify/notifications.xml create mode 100644 src/qtnotify/qtnotify.pri diff --git a/configure b/configure index 1dc591b4f..dd08b44c8 100755 --- a/configure +++ b/configure @@ -27,7 +27,6 @@ Dependency options: files --with-libboost-lib=[path] Path to libboost library files - --disable-libnotify Disable use of libnotify --disable-geoip-database Disable use of geoip-database --with-geoip-database-embedded Geoip Database will be embedded in qBittorrent @@ -178,11 +177,6 @@ while [ $# -gt 0 ]; do shift ;; - --disable-libnotify) - QC_DISABLE_libnotify="Y" - shift - ;; - --disable-geoip-database) QC_DISABLE_geoip_database="Y" shift @@ -224,7 +218,6 @@ echo QC_DISABLE_GUI=$QC_DISABLE_GUI echo QC_DISABLE_qt_dbus=$QC_DISABLE_qt_dbus echo QC_WITH_LIBBOOST_INC=$QC_WITH_LIBBOOST_INC echo QC_WITH_LIBBOOST_LIB=$QC_WITH_LIBBOOST_LIB -echo QC_DISABLE_libnotify=$QC_DISABLE_libnotify echo QC_DISABLE_geoip_database=$QC_DISABLE_geoip_database echo QC_WITH_GEOIP_DATABASE_EMBEDDED=$QC_WITH_GEOIP_DATABASE_EMBEDDED echo QC_WITH_QTSINGLEAPPLICATION=$QC_WITH_QTSINGLEAPPLICATION @@ -552,67 +545,6 @@ public: return true; } }; -#line 1 "libnotify.qcm" -/* ------BEGIN QCMOD----- -name: libnotify ------END QCMOD----- -*/ -// see Conf::findPkgConfig -class qc_libnotify : public ConfObj -{ -public: - qc_libnotify(Conf *c) : ConfObj(c) {} - QString name() const { return "libnotify >= 0.4.2 (optional)"; } - QString shortname() const { return "libnotify"; } - QString checkString() const { - if(!conf->getenv("QC_DISABLE_libnotify").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty()) - return ""; - return ConfObj::checkString(); - } - bool exec(){ - if(!conf->getenv("QC_DISABLE_libnotify").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty()) { - return false; - } - QStringList incs; - QString req_ver = "0.4.2"; - QString version, libs, other; - VersionMode mode = VersionMin; - if(conf->findPkgConfig("libnotify", mode, req_ver, &version, &incs, &libs, &other)) { - conf->addExtra("CONFIG += libnotify"); - for(int n = 0; n < incs.count(); ++n) - conf->addIncludePath(incs[n]); - if(!libs.isEmpty()) - conf->addLib(libs); - QStringList incs2; - QString req_ver2 = "2.0"; - QString version2, libs2, other2; - if(conf->findPkgConfig("glib-2.0", mode, req_ver2, &version2, &incs2, &libs2, &other2)) { - for(int n = 0; n < incs2.count(); ++n) - conf->addIncludePath(incs2[n]); - if(!libs2.isEmpty()) - conf->addLib(libs2); - } else { - return false; - } - QStringList incs3; - QString req_ver3 = "2.0"; - QString version3, libs3, other3; - if(conf->findPkgConfig("gtk+-2.0", mode, req_ver3, &version3, &incs3, &libs3, &other3)) { - for(int n = 0; n < incs3.count(); ++n) - conf->addIncludePath(incs3[n]); - if(!libs3.isEmpty()) - conf->addLib(libs3); - } else { - return false; - } - } else { - return false; - } - - return true; - } -}; #line 1 "geoip-database.qcm" /* -----BEGIN QCMOD----- @@ -696,9 +628,6 @@ cat >$1/modules_new.cpp <required = true; o->disabled = false; - o = new qc_libnotify(conf); - o->required = false; - o->disabled = false; o = new qc_geoip_database(conf); o->required = false; o->disabled = false; @@ -1655,7 +1584,6 @@ export QC_DISABLE_GUI export QC_DISABLE_qt_dbus export QC_WITH_LIBBOOST_INC export QC_WITH_LIBBOOST_LIB -export QC_DISABLE_libnotify export QC_DISABLE_geoip_database export QC_WITH_GEOIP_DATABASE_EMBEDDED export QC_WITH_QTSINGLEAPPLICATION diff --git a/qbittorrent.qc b/qbittorrent.qc index 59726552b..6f10673f4 100644 --- a/qbittorrent.qc +++ b/qbittorrent.qc @@ -17,8 +17,6 @@ - - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a523b3869..c602e15af 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -27,10 +27,11 @@ * * Contact : chris@qbittorrent.org */ -#ifdef WITH_LIBNOTIFY -#include -#include -#include + +#include +#if defined(Q_WS_X11) && defined(QT_DBUS_LIB) +#include +#include "notifications.h" #endif #include @@ -1101,21 +1102,16 @@ void MainWindow::updateGUI() { void MainWindow::showNotificationBaloon(QString title, QString msg) const { if(!Preferences().useProgramNotification()) return; -#ifdef WITH_LIBNOTIFY - if (notify_init ("summary-body")) { - NotifyNotification* notification; - - notification = notify_notification_new (qPrintable(title), qPrintable(msg), "qbittorrent" - #if !defined(NOTIFY_VERSION_MINOR) || (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7) - , 0 - #endif - ); - gboolean success = notify_notification_show (notification, NULL); - g_object_unref(G_OBJECT(notification)); - notify_uninit (); - if(success) { +#if defined(Q_WS_X11) && defined(QT_DBUS_LIB) + org::freedesktop::Notifications notifications("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + QDBusConnection::sessionBus()); + if(notifications.isValid()) { + QDBusPendingReply reply = notifications.Notify("qBittorrent", 0, "qbittorrent", title, + msg, QStringList(), QVariantMap(), -1); + reply.waitForFinished(); + if(!reply.isError()) return; - } } #endif if(systrayIcon && QSystemTrayIcon::supportsMessages()) diff --git a/src/qtnotify/notifications.cpp b/src/qtnotify/notifications.cpp new file mode 100644 index 000000000..57722dd91 --- /dev/null +++ b/src/qtnotify/notifications.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -p notifications.h:notifications.cpp notifications.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "notifications.h" + +/* + * Implementation of interface class OrgFreedesktopNotificationsInterface + */ + +OrgFreedesktopNotificationsInterface::OrgFreedesktopNotificationsInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNotificationsInterface::~OrgFreedesktopNotificationsInterface() +{ +} + diff --git a/src/qtnotify/notifications.h b/src/qtnotify/notifications.h new file mode 100644 index 000000000..fe975fd27 --- /dev/null +++ b/src/qtnotify/notifications.h @@ -0,0 +1,84 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -p notifications.h:notifications.cpp notifications.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef NOTIFICATIONS_H_1301681398 +#define NOTIFICATIONS_H_1301681398 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.Notifications + */ +class OrgFreedesktopNotificationsInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "org.freedesktop.Notifications"; } + +public: + OrgFreedesktopNotificationsInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~OrgFreedesktopNotificationsInterface(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> CloseNotification(uint id) + { + QList argumentList; + argumentList << qVariantFromValue(id); + return asyncCallWithArgumentList(QLatin1String("CloseNotification"), argumentList); + } + + inline QDBusPendingReply GetCapabilities() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("GetCapabilities"), argumentList); + } + + inline QDBusPendingReply GetServerInformation() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("GetServerInformation"), argumentList); + } + inline QDBusReply GetServerInformation(QString &return_vendor, QString &return_version, QString &return_spec_version) + { + QList argumentList; + QDBusMessage reply = callWithArgumentList(QDBus::Block, QLatin1String("GetServerInformation"), argumentList); + if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 4) { + return_vendor = qdbus_cast(reply.arguments().at(1)); + return_version = qdbus_cast(reply.arguments().at(2)); + return_spec_version = qdbus_cast(reply.arguments().at(3)); + } + return reply; + } + + inline QDBusPendingReply Notify(const QString &app_name, uint id, const QString &icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout) + { + QList argumentList; + argumentList << qVariantFromValue(app_name) << qVariantFromValue(id) << qVariantFromValue(icon) << qVariantFromValue(summary) << qVariantFromValue(body) << qVariantFromValue(actions) << qVariantFromValue(hints) << qVariantFromValue(timeout); + return asyncCallWithArgumentList(QLatin1String("Notify"), argumentList); + } + +Q_SIGNALS: // SIGNALS +}; + +namespace org { + namespace freedesktop { + typedef ::OrgFreedesktopNotificationsInterface Notifications; + } +} +#endif diff --git a/src/qtnotify/notifications.xml b/src/qtnotify/notifications.xml new file mode 100644 index 000000000..7c1d2e7ad --- /dev/null +++ b/src/qtnotify/notifications.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/qtnotify/qtnotify.pri b/src/qtnotify/qtnotify.pri new file mode 100644 index 000000000..84d288a4a --- /dev/null +++ b/src/qtnotify/qtnotify.pri @@ -0,0 +1,5 @@ +INCLUDEPATH += $$PWD + +HEADERS += $$PWD/notifications.h + +SOURCES += $$PWD/notifications.cpp diff --git a/unixconf.pri b/unixconf.pri index 57c940dd5..fcaf6f887 100644 --- a/unixconf.pri +++ b/unixconf.pri @@ -10,10 +10,6 @@ QMAKE_LFLAGS_APP += -rdynamic CONFIG += link_pkgconfig PKGCONFIG += libtorrent-rasterbar -libnotify { - DEFINES += WITH_LIBNOTIFY -} - # Man page nox { man.files = ../doc/qbittorrent-nox.1 @@ -73,6 +69,10 @@ INSTALLS += man target.path = $$PREFIX/bin/ INSTALLS += target +dbus { + include(src/qtnotify/qtnotify.pri) +} + !nox { # DEFINE added by configure contains(DEFINES, WITH_GEOIP_EMBEDDED) {