summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-12-13 02:14:50 +0100
committerJavier <dev.git@javispedro.com>2015-12-13 02:14:50 +0100
commit8dc9a1295b7c1a5f81c55244b5d2bb3a3bddb30b (patch)
treedb221c4dfe14ba7d248b940c6473a9bbecd25e46
parent9a3aaa3ded78ece418ac9b8b9576d8a433519034 (diff)
downloadlibwatchfish-8dc9a1295b7c1a5f81c55244b5d2bb3a3bddb30b.tar.gz
libwatchfish-8dc9a1295b7c1a5f81c55244b5d2bb3a3bddb30b.zip
Separate NotificationMonitorPrivate into its own file
-rw-r--r--libwatchfish.pro6
-rw-r--r--notificationmonitor.cpp70
-rw-r--r--notificationmonitor.h1
-rw-r--r--notificationmonitor_p.h85
4 files changed, 94 insertions, 68 deletions
diff --git a/libwatchfish.pro b/libwatchfish.pro
index e430a95..59b26ba 100644
--- a/libwatchfish.pro
+++ b/libwatchfish.pro
@@ -2,11 +2,13 @@ TARGET = watchfish
TEMPLATE = lib
CONFIG += staticlib
+QT += dbus
CONFIG += link_pkgconfig
PKGCONFIG += dbus-1 timed-qt5
-HEADERS = notificationmonitor.h notification.h \
- walltimemonitor.h
+HEADERS = notificationmonitor.h notificationmonitor_p.h notification.h \
+ walltimemonitor.h walltimemonitor_p.h
+
SOURCES = notificationmonitor.cpp notification.cpp \
walltimemonitor.cpp
diff --git a/notificationmonitor.cpp b/notificationmonitor.cpp
index 8b30330..3b4b035 100644
--- a/notificationmonitor.cpp
+++ b/notificationmonitor.cpp
@@ -20,32 +20,16 @@
#include <QtCore/QMessageLogger>
#include <QtCore/QSettings>
#include <QtCore/QSocketNotifier>
-#include <dbus/dbus.h>
#include "notification.h"
#include "notificationmonitor.h"
-
-#define CATEGORY_DEFINITION_FILE_DIRECTORY "/usr/share/lipstick/notificationcategories"
-#define CATEGORY_REFRESH_CHECK_TIME 120
+#include "notificationmonitor_p.h"
namespace watchfish
{
Q_LOGGING_CATEGORY(notificationMonitorCat, "watchfish-NotificationMonitor")
-namespace
-{
-struct ProtoNotification
-{
- QString sender;
- QString appIcon;
- QString summary;
- QString body;
- QHash<QString, QString> hints;
- int expireTimeout;
- QStringList actions;
-};
-
QDebug operator<<(QDebug &debug, const ProtoNotification &proto)
{
QDebugStateSaver saver(debug);
@@ -57,52 +41,6 @@ QDebug operator<<(QDebug &debug, const ProtoNotification &proto)
return debug;
}
-struct CategoryCacheEntry
-{
- QHash<QString, QString> data;
- QDateTime lastReadTime;
- QDateTime lastCheckTime;
-};
-
-}
-
-class NotificationMonitorPrivate
-{
- NotificationMonitor * const q_ptr;
- Q_DECLARE_PUBLIC(NotificationMonitor)
-
- /** The current set of monitored notifications, indexed by id. */
- QMap<quint32, Notification*> _notifs;
- /** Low level dbus connection used for sniffing. */
- DBusConnection *_conn;
- /** Serials of DBUS method calls of which we are expecting a reply. */
- QHash<quint32, ProtoNotification> _pendingConfirmation;
- /** Cache of notification category info. */
- mutable QHash<QString, CategoryCacheEntry> _categoryCache;
-
- NotificationMonitorPrivate(NotificationMonitor *q);
- ~NotificationMonitorPrivate();
-
- void processIncomingNotification(quint32 id, const ProtoNotification &proto);
- void processCloseNotification(quint32 id, quint32 reason);
-
- void sendMessageWithString(const char *service, const char *path, const char *iface, const char *method, const char *arg);
- void addMatchRule(const char *rule);
- void removeMatchRule(const char *rule);
-
- ProtoNotification parseNotifyCall(DBusMessage *msg) const;
-
- QHash<QString,QString> getCategoryInfo(const QString &s) const;
-
- static dbus_bool_t busWatchAdd(DBusWatch *watch, void *data);
- static void busWatchRemove(DBusWatch *watch, void *data);
- static void busWatchToggle(DBusWatch *watch, void *data);
-
- static DBusHandlerResult busMessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data);
-
- void handleBusSocketActivated();
-};
-
NotificationMonitorPrivate::NotificationMonitorPrivate(NotificationMonitor *q)
: q_ptr(q)
{
@@ -138,9 +76,11 @@ NotificationMonitorPrivate::~NotificationMonitorPrivate()
delete it.value();
}
+#if 0 /* No need to remove match rules since we're closing the connection. */
removeMatchRule("type='method_call',interface='org.freedesktop.Notifications',member='Notify',eavesdrop='true'");
removeMatchRule("type='method_return',sender='org.freedesktop.Notifications',eavesdrop='true'");
removeMatchRule("type='signal',sender='org.freedesktop.Notifications',path='/org/freedesktop/Notifications',interface='org.freedesktop.Notifications',member='NotificationClosed'");
+#endif
dbus_connection_remove_filter(_conn, busMessageFilter, this);
@@ -319,7 +259,7 @@ QHash<QString,QString> NotificationMonitorPrivate::getCategoryInfo(const QString
if (needs_check) {
QFileInfo finfo(QString("%1/%2.conf").arg(CATEGORY_DEFINITION_FILE_DIRECTORY, category));
if (finfo.exists()) {
- CategoryCacheEntry &entry = _categoryCache[category];
+ NotificationCategoryCacheEntry &entry = _categoryCache[category];
if (!in_cache || finfo.lastModified() > entry.lastReadTime) {
QSettings settings(finfo.absoluteFilePath(), QSettings::IniFormat);
entry.data.clear();
@@ -367,7 +307,7 @@ dbus_bool_t NotificationMonitorPrivate::busWatchAdd(DBusWatch *watch, void *data
notifier->setProperty("dbus-watch", QVariant::fromValue<void*>(watch));
notifier->connect(notifier, SIGNAL(activated(int)),
- monitor, SLOT(handleBusSocketActivated()));
+ self, SLOT(handleBusSocketActivated()));
return TRUE;
}
diff --git a/notificationmonitor.h b/notificationmonitor.h
index b5fdbdb..4aad942 100644
--- a/notificationmonitor.h
+++ b/notificationmonitor.h
@@ -46,7 +46,6 @@ signals:
void notification(Notification *n);
private:
- Q_PRIVATE_SLOT(d_func(), void handleBusSocketActivated())
NotificationMonitorPrivate * const d_ptr;
};
diff --git a/notificationmonitor_p.h b/notificationmonitor_p.h
new file mode 100644
index 0000000..069abc4
--- /dev/null
+++ b/notificationmonitor_p.h
@@ -0,0 +1,85 @@
+#ifndef WATCHFISH_NOTIFICATIONMONITOR_P_H
+#define WATCHFISH_NOTIFICATIONMONITOR_P_H
+
+#include <QtCore/QObject>
+#include <dbus/dbus.h>
+
+#include "notificationmonitor.h"
+
+#define CATEGORY_DEFINITION_FILE_DIRECTORY "/usr/share/lipstick/notificationcategories"
+#define CATEGORY_REFRESH_CHECK_TIME 120
+
+namespace watchfish
+{
+
+struct NotificationCategoryCacheEntry
+{
+ QHash<QString, QString> data;
+ QDateTime lastReadTime;
+ QDateTime lastCheckTime;
+};
+
+struct ProtoNotification
+{
+ QString sender;
+ QString appIcon;
+ QString summary;
+ QString body;
+ QHash<QString, QString> hints;
+ int expireTimeout;
+ QStringList actions;
+};
+
+class NotificationMonitorPrivate : public QObject
+{
+ Q_OBJECT
+
+public:
+ NotificationMonitorPrivate(NotificationMonitor *q);
+ ~NotificationMonitorPrivate();
+
+private:
+ /** Converts a ProtoNotification into a Notification object and raises it. */
+ void processIncomingNotification(quint32 id, const ProtoNotification &proto);
+ /** Raises appropiate notification signal. */
+ void processCloseNotification(quint32 id, quint32 reason);
+
+ /** Sends a D-Bus message for a method call with a single string argument. */
+ void sendMessageWithString(const char *service, const char *path, const char *iface, const char *method, const char *arg);
+ /** Adds a D-Bus filter match rule. */
+ void addMatchRule(const char *rule);
+ void removeMatchRule(const char *rule);
+
+ /** Converts a fdo Notification D-Bus message into a ProtoNotification object. */
+ ProtoNotification parseNotifyCall(DBusMessage *msg) const;
+
+ QHash<QString,QString> getCategoryInfo(const QString &s) const;
+
+ static dbus_bool_t busWatchAdd(DBusWatch *watch, void *data);
+ static void busWatchRemove(DBusWatch *watch, void *data);
+ static void busWatchToggle(DBusWatch *watch, void *data);
+
+ static DBusHandlerResult busMessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data);
+
+private slots:
+ void handleBusSocketActivated();
+
+private:
+ NotificationMonitor * const q_ptr;
+ Q_DECLARE_PUBLIC(NotificationMonitor)
+
+ /** The current set of monitored notifications, indexed by id. */
+ QMap<quint32, Notification*> _notifs;
+ /** Low level dbus connection used for sniffing. */
+ DBusConnection *_conn;
+ /** Serials of DBUS method calls of which we are expecting a reply. */
+ QHash<quint32, ProtoNotification> _pendingConfirmation;
+ /** Cache of notification category info. */
+ mutable QHash<QString, NotificationCategoryCacheEntry> _categoryCache;
+};
+
+
+}
+
+#endif // WATCHFISH_NOTIFICATIONMONITOR_P_H
+