Skip to content

Commit d0afd46

Browse files
author
Christophe Dumez
committed
Get rid of libnotify dependency (Use DBus instead)
1 parent ba7ece3 commit d0afd46

8 files changed

Lines changed: 164 additions & 96 deletions

File tree

configure

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Dependency options:
2727
files
2828
--with-libboost-lib=[path] Path to libboost library
2929
files
30-
--disable-libnotify Disable use of libnotify
3130
--disable-geoip-database Disable use of geoip-database
3231
--with-geoip-database-embedded Geoip Database will be
3332
embedded in qBittorrent
@@ -178,11 +177,6 @@ while [ $# -gt 0 ]; do
178177
shift
179178
;;
180179

181-
--disable-libnotify)
182-
QC_DISABLE_libnotify="Y"
183-
shift
184-
;;
185-
186180
--disable-geoip-database)
187181
QC_DISABLE_geoip_database="Y"
188182
shift
@@ -224,7 +218,6 @@ echo QC_DISABLE_GUI=$QC_DISABLE_GUI
224218
echo QC_DISABLE_qt_dbus=$QC_DISABLE_qt_dbus
225219
echo QC_WITH_LIBBOOST_INC=$QC_WITH_LIBBOOST_INC
226220
echo QC_WITH_LIBBOOST_LIB=$QC_WITH_LIBBOOST_LIB
227-
echo QC_DISABLE_libnotify=$QC_DISABLE_libnotify
228221
echo QC_DISABLE_geoip_database=$QC_DISABLE_geoip_database
229222
echo QC_WITH_GEOIP_DATABASE_EMBEDDED=$QC_WITH_GEOIP_DATABASE_EMBEDDED
230223
echo QC_WITH_QTSINGLEAPPLICATION=$QC_WITH_QTSINGLEAPPLICATION
@@ -552,67 +545,6 @@ public:
552545
return true;
553546
}
554547
};
555-
#line 1 "libnotify.qcm"
556-
/*
557-
-----BEGIN QCMOD-----
558-
name: libnotify
559-
-----END QCMOD-----
560-
*/
561-
// see Conf::findPkgConfig
562-
class qc_libnotify : public ConfObj
563-
{
564-
public:
565-
qc_libnotify(Conf *c) : ConfObj(c) {}
566-
QString name() const { return "libnotify >= 0.4.2 (optional)"; }
567-
QString shortname() const { return "libnotify"; }
568-
QString checkString() const {
569-
if(!conf->getenv("QC_DISABLE_libnotify").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty())
570-
return "";
571-
return ConfObj::checkString();
572-
}
573-
bool exec(){
574-
if(!conf->getenv("QC_DISABLE_libnotify").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty()) {
575-
return false;
576-
}
577-
QStringList incs;
578-
QString req_ver = "0.4.2";
579-
QString version, libs, other;
580-
VersionMode mode = VersionMin;
581-
if(conf->findPkgConfig("libnotify", mode, req_ver, &version, &incs, &libs, &other)) {
582-
conf->addExtra("CONFIG += libnotify");
583-
for(int n = 0; n < incs.count(); ++n)
584-
conf->addIncludePath(incs[n]);
585-
if(!libs.isEmpty())
586-
conf->addLib(libs);
587-
QStringList incs2;
588-
QString req_ver2 = "2.0";
589-
QString version2, libs2, other2;
590-
if(conf->findPkgConfig("glib-2.0", mode, req_ver2, &version2, &incs2, &libs2, &other2)) {
591-
for(int n = 0; n < incs2.count(); ++n)
592-
conf->addIncludePath(incs2[n]);
593-
if(!libs2.isEmpty())
594-
conf->addLib(libs2);
595-
} else {
596-
return false;
597-
}
598-
QStringList incs3;
599-
QString req_ver3 = "2.0";
600-
QString version3, libs3, other3;
601-
if(conf->findPkgConfig("gtk+-2.0", mode, req_ver3, &version3, &incs3, &libs3, &other3)) {
602-
for(int n = 0; n < incs3.count(); ++n)
603-
conf->addIncludePath(incs3[n]);
604-
if(!libs3.isEmpty())
605-
conf->addLib(libs3);
606-
} else {
607-
return false;
608-
}
609-
} else {
610-
return false;
611-
}
612-
613-
return true;
614-
}
615-
};
616548
#line 1 "geoip-database.qcm"
617549
/*
618550
-----BEGIN QCMOD-----
@@ -696,9 +628,6 @@ cat >$1/modules_new.cpp <<EOT
696628
o = new qc_libboost(conf);
697629
o->required = true;
698630
o->disabled = false;
699-
o = new qc_libnotify(conf);
700-
o->required = false;
701-
o->disabled = false;
702631
o = new qc_geoip_database(conf);
703632
o->required = false;
704633
o->disabled = false;
@@ -1655,7 +1584,6 @@ export QC_DISABLE_GUI
16551584
export QC_DISABLE_qt_dbus
16561585
export QC_WITH_LIBBOOST_INC
16571586
export QC_WITH_LIBBOOST_LIB
1658-
export QC_DISABLE_libnotify
16591587
export QC_DISABLE_geoip_database
16601588
export QC_WITH_GEOIP_DATABASE_EMBEDDED
16611589
export QC_WITH_QTSINGLEAPPLICATION

qbittorrent.qc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
<dep type='libboost'>
1818
<required/>
1919
</dep>
20-
<dep type='libnotify'>
21-
</dep>
2220
<dep type='geoip-database'>
2321
</dep>
2422
<dep type='qtsingleapplication'>

src/mainwindow.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
*
2828
* Contact : chris@qbittorrent.org
2929
*/
30-
#ifdef WITH_LIBNOTIFY
31-
#include <glib.h>
32-
#include <unistd.h>
33-
#include <libnotify/notify.h>
30+
31+
#include <QtGlobal>
32+
#if defined(Q_WS_X11) && defined(QT_DBUS_LIB)
33+
#include <QDBusConnection>
34+
#include "notifications.h"
3435
#endif
3536

3637
#include <QFileDialog>
@@ -1101,21 +1102,16 @@ void MainWindow::updateGUI() {
11011102

11021103
void MainWindow::showNotificationBaloon(QString title, QString msg) const {
11031104
if(!Preferences().useProgramNotification()) return;
1104-
#ifdef WITH_LIBNOTIFY
1105-
if (notify_init ("summary-body")) {
1106-
NotifyNotification* notification;
1107-
1108-
notification = notify_notification_new (qPrintable(title), qPrintable(msg), "qbittorrent"
1109-
#if !defined(NOTIFY_VERSION_MINOR) || (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7)
1110-
, 0
1111-
#endif
1112-
);
1113-
gboolean success = notify_notification_show (notification, NULL);
1114-
g_object_unref(G_OBJECT(notification));
1115-
notify_uninit ();
1116-
if(success) {
1105+
#if defined(Q_WS_X11) && defined(QT_DBUS_LIB)
1106+
org::freedesktop::Notifications notifications("org.freedesktop.Notifications",
1107+
"/org/freedesktop/Notifications",
1108+
QDBusConnection::sessionBus());
1109+
if(notifications.isValid()) {
1110+
QDBusPendingReply<uint> reply = notifications.Notify("qBittorrent", 0, "qbittorrent", title,
1111+
msg, QStringList(), QVariantMap(), -1);
1112+
reply.waitForFinished();
1113+
if(!reply.isError())
11171114
return;
1118-
}
11191115
}
11201116
#endif
11211117
if(systrayIcon && QSystemTrayIcon::supportsMessages())

src/qtnotify/notifications.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* This file was generated by qdbusxml2cpp version 0.7
3+
* Command line was: qdbusxml2cpp -p notifications.h:notifications.cpp notifications.xml
4+
*
5+
* qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
6+
*
7+
* This is an auto-generated file.
8+
* This file may have been hand-edited. Look for HAND-EDIT comments
9+
* before re-generating it.
10+
*/
11+
12+
#include "notifications.h"
13+
14+
/*
15+
* Implementation of interface class OrgFreedesktopNotificationsInterface
16+
*/
17+
18+
OrgFreedesktopNotificationsInterface::OrgFreedesktopNotificationsInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
19+
: QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
20+
{
21+
}
22+
23+
OrgFreedesktopNotificationsInterface::~OrgFreedesktopNotificationsInterface()
24+
{
25+
}
26+

src/qtnotify/notifications.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* This file was generated by qdbusxml2cpp version 0.7
3+
* Command line was: qdbusxml2cpp -p notifications.h:notifications.cpp notifications.xml
4+
*
5+
* qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
6+
*
7+
* This is an auto-generated file.
8+
* Do not edit! All changes made to it will be lost.
9+
*/
10+
11+
#ifndef NOTIFICATIONS_H_1301681398
12+
#define NOTIFICATIONS_H_1301681398
13+
14+
#include <QtCore/QObject>
15+
#include <QtCore/QByteArray>
16+
#include <QtCore/QList>
17+
#include <QtCore/QMap>
18+
#include <QtCore/QString>
19+
#include <QtCore/QStringList>
20+
#include <QtCore/QVariant>
21+
#include <QtDBus/QtDBus>
22+
23+
/*
24+
* Proxy class for interface org.freedesktop.Notifications
25+
*/
26+
class OrgFreedesktopNotificationsInterface: public QDBusAbstractInterface
27+
{
28+
Q_OBJECT
29+
public:
30+
static inline const char *staticInterfaceName()
31+
{ return "org.freedesktop.Notifications"; }
32+
33+
public:
34+
OrgFreedesktopNotificationsInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
35+
36+
~OrgFreedesktopNotificationsInterface();
37+
38+
public Q_SLOTS: // METHODS
39+
inline QDBusPendingReply<> CloseNotification(uint id)
40+
{
41+
QList<QVariant> argumentList;
42+
argumentList << qVariantFromValue(id);
43+
return asyncCallWithArgumentList(QLatin1String("CloseNotification"), argumentList);
44+
}
45+
46+
inline QDBusPendingReply<QStringList> GetCapabilities()
47+
{
48+
QList<QVariant> argumentList;
49+
return asyncCallWithArgumentList(QLatin1String("GetCapabilities"), argumentList);
50+
}
51+
52+
inline QDBusPendingReply<QString, QString, QString, QString> GetServerInformation()
53+
{
54+
QList<QVariant> argumentList;
55+
return asyncCallWithArgumentList(QLatin1String("GetServerInformation"), argumentList);
56+
}
57+
inline QDBusReply<QString> GetServerInformation(QString &return_vendor, QString &return_version, QString &return_spec_version)
58+
{
59+
QList<QVariant> argumentList;
60+
QDBusMessage reply = callWithArgumentList(QDBus::Block, QLatin1String("GetServerInformation"), argumentList);
61+
if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 4) {
62+
return_vendor = qdbus_cast<QString>(reply.arguments().at(1));
63+
return_version = qdbus_cast<QString>(reply.arguments().at(2));
64+
return_spec_version = qdbus_cast<QString>(reply.arguments().at(3));
65+
}
66+
return reply;
67+
}
68+
69+
inline QDBusPendingReply<uint> Notify(const QString &app_name, uint id, const QString &icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout)
70+
{
71+
QList<QVariant> argumentList;
72+
argumentList << qVariantFromValue(app_name) << qVariantFromValue(id) << qVariantFromValue(icon) << qVariantFromValue(summary) << qVariantFromValue(body) << qVariantFromValue(actions) << qVariantFromValue(hints) << qVariantFromValue(timeout);
73+
return asyncCallWithArgumentList(QLatin1String("Notify"), argumentList);
74+
}
75+
76+
Q_SIGNALS: // SIGNALS
77+
};
78+
79+
namespace org {
80+
namespace freedesktop {
81+
typedef ::OrgFreedesktopNotificationsInterface Notifications;
82+
}
83+
}
84+
#endif

src/qtnotify/notifications.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
2+
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
3+
<node>
4+
<interface name="org.freedesktop.Notifications">
5+
<method name="GetServerInformation">
6+
<arg name="return_name" type="s" direction="out"/>
7+
<arg name="return_vendor" type="s" direction="out"/>
8+
<arg name="return_version" type="s" direction="out"/>
9+
<arg name="return_spec_version" type="s" direction="out"/>
10+
</method>
11+
<method name="GetCapabilities">
12+
<arg name="return_caps" type="as" direction="out"/>
13+
</method>
14+
<method name="CloseNotification">
15+
<arg name="id" type="u" direction="in"/>
16+
</method>
17+
<method name="Notify">
18+
<arg name="app_name" type="s" direction="in"/>
19+
<arg name="id" type="u" direction="in"/>
20+
<arg name="icon" type="s" direction="in"/>
21+
<arg name="summary" type="s" direction="in"/>
22+
<arg name="body" type="s" direction="in"/>
23+
<arg name="actions" type="as" direction="in"/>
24+
<arg name="hints" type="a{sv}" direction="in"/>
25+
<annotation name="com.trolltech.QtDBus.QtTypeName.In6" value="QVariantMap"/>
26+
<arg name="timeout" type="i" direction="in"/>
27+
<arg name="return_id" type="u" direction="out"/>
28+
</method>
29+
</interface>
30+
</node>
31+

src/qtnotify/qtnotify.pri

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
INCLUDEPATH += $$PWD
2+
3+
HEADERS += $$PWD/notifications.h
4+
5+
SOURCES += $$PWD/notifications.cpp

unixconf.pri

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ QMAKE_LFLAGS_APP += -rdynamic
1010
CONFIG += link_pkgconfig
1111
PKGCONFIG += libtorrent-rasterbar
1212

13-
libnotify {
14-
DEFINES += WITH_LIBNOTIFY
15-
}
16-
1713
# Man page
1814
nox {
1915
man.files = ../doc/qbittorrent-nox.1
@@ -73,6 +69,10 @@ INSTALLS += man
7369
target.path = $$PREFIX/bin/
7470
INSTALLS += target
7571

72+
dbus {
73+
include(src/qtnotify/qtnotify.pri)
74+
}
75+
7676
!nox {
7777
# DEFINE added by configure
7878
contains(DEFINES, WITH_GEOIP_EMBEDDED) {

0 commit comments

Comments
 (0)