From 8dc9a1295b7c1a5f81c55244b5d2bb3a3bddb30b Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 13 Dec 2015 02:14:50 +0100 Subject: Separate NotificationMonitorPrivate into its own file --- libwatchfish.pro | 6 ++-- notificationmonitor.cpp | 70 +++------------------------------------- notificationmonitor.h | 1 - notificationmonitor_p.h | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 68 deletions(-) create mode 100644 notificationmonitor_p.h 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 #include #include -#include #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 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 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 _notifs; - /** Low level dbus connection used for sniffing. */ - DBusConnection *_conn; - /** Serials of DBUS method calls of which we are expecting a reply. */ - QHash _pendingConfirmation; - /** Cache of notification category info. */ - mutable QHash _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 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 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(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 +#include + +#include "notificationmonitor.h" + +#define CATEGORY_DEFINITION_FILE_DIRECTORY "/usr/share/lipstick/notificationcategories" +#define CATEGORY_REFRESH_CHECK_TIME 120 + +namespace watchfish +{ + +struct NotificationCategoryCacheEntry +{ + QHash data; + QDateTime lastReadTime; + QDateTime lastCheckTime; +}; + +struct ProtoNotification +{ + QString sender; + QString appIcon; + QString summary; + QString body; + QHash 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 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 _notifs; + /** Low level dbus connection used for sniffing. */ + DBusConnection *_conn; + /** Serials of DBUS method calls of which we are expecting a reply. */ + QHash _pendingConfirmation; + /** Cache of notification category info. */ + mutable QHash _categoryCache; +}; + + +} + +#endif // WATCHFISH_NOTIFICATIONMONITOR_P_H + -- cgit v1.2.3