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 --- notificationmonitor.cpp | 70 ++++--------------------------------------------- 1 file changed, 5 insertions(+), 65 deletions(-) (limited to 'notificationmonitor.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; } -- cgit v1.2.3