From a4084dcd38a78dfc9113168e378b5fa7f7e9f6ea Mon Sep 17 00:00:00 2001 From: Philipp Andreas Date: Thu, 10 Jul 2014 21:56:19 +0200 Subject: Adding support for default notifications. --- daemon/notificationmanager.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 daemon/notificationmanager.h (limited to 'daemon/notificationmanager.h') diff --git a/daemon/notificationmanager.h b/daemon/notificationmanager.h new file mode 100644 index 0000000..dd3f8bb --- /dev/null +++ b/daemon/notificationmanager.h @@ -0,0 +1,41 @@ +#ifndef NOTIFICATIONMANAGER_H +#define NOTIFICATIONMANAGER_H + +#include + +#include +#include + +class NotificationManager : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications") + + Q_PROPERTY(QDBusInterface* interface READ interface) +public: + explicit NotificationManager(QObject *parent = 0); + ~NotificationManager(); + + QDBusInterface* interface() const; + +Q_SIGNALS: + void error(const QString &message); + void smsNotify(const QString &sender, const QString &data); + void emailNotify(const QString &sender, const QString &data,const QString &subject); + +public Q_SLOTS: + void Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout); + +protected Q_SLOTS: + void initialize(bool notifyError = false); + +private: + class NotificationManagerPrivate *d_ptr; + + QString detectCleanAppname(QString app_name); + + Q_DISABLE_COPY(NotificationManager) + Q_DECLARE_PRIVATE(NotificationManager) +}; + +#endif // NOTIFICATIONMANAGER_H -- cgit v1.2.3 From b8e1190847ff8cad9276bc1bc751aef454a713d4 Mon Sep 17 00:00:00 2001 From: Philipp Andreas Date: Sat, 12 Jul 2014 09:45:33 +0200 Subject: Using log4qt logging instead of qDebug() --- daemon/notificationmanager.cpp | 2 +- daemon/notificationmanager.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'daemon/notificationmanager.h') diff --git a/daemon/notificationmanager.cpp b/daemon/notificationmanager.cpp index 8a2129e..8524083 100644 --- a/daemon/notificationmanager.cpp +++ b/daemon/notificationmanager.cpp @@ -93,7 +93,7 @@ void NotificationManager::Notify(const QString &app_name, uint replaces_id, cons return; } - qDebug() << "Got notification via dbus from" << detectCleanAppname(app_name); + logger()->debug() << Q_FUNC_INFO << "Got notification via dbus from" << detectCleanAppname(app_name); if (app_name == "messageserver5") { emit this->emailNotify(hints.value("x-nemo-preview-summary", detectCleanAppname(app_name)).toString(), diff --git a/daemon/notificationmanager.h b/daemon/notificationmanager.h index dd3f8bb..45ae090 100644 --- a/daemon/notificationmanager.h +++ b/daemon/notificationmanager.h @@ -2,6 +2,7 @@ #define NOTIFICATIONMANAGER_H #include +#include "Logger" #include #include @@ -9,6 +10,7 @@ class NotificationManager : public QObject { Q_OBJECT + LOG4QT_DECLARE_QCLASS_LOGGER Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications") Q_PROPERTY(QDBusInterface* interface READ interface) -- cgit v1.2.3 From c911932934f0a7d8bf1c252be4a3e718859b3b09 Mon Sep 17 00:00:00 2001 From: Philipp Andreas Date: Sat, 12 Jul 2014 19:07:33 +0200 Subject: Adding basic Mitakuuluu support, started reading the notification category, a bit cleanup --- daemon/notificationmanager.cpp | 37 ++++++++++++++++++++++++++++++++----- daemon/notificationmanager.h | 5 ++++- 2 files changed, 36 insertions(+), 6 deletions(-) (limited to 'daemon/notificationmanager.h') diff --git a/daemon/notificationmanager.cpp b/daemon/notificationmanager.cpp index a0a99e0..917a245 100644 --- a/daemon/notificationmanager.cpp +++ b/daemon/notificationmanager.cpp @@ -70,9 +70,9 @@ QDBusInterface* NotificationManager::interface() const return d->interface; } -QString NotificationManager::detectCleanAppname(QString app_name) +QString NotificationManager::getCleanAppName(QString app_name) { - QString desktopFile = "/usr/share/applications/" + app_name + ".desktop"; + QString desktopFile = QString("/usr/share/applications/%1.desktop").arg(app_name); QFile testFile(desktopFile); if (testFile.exists()) { QSettings settings(desktopFile, QSettings::IniFormat); @@ -86,6 +86,24 @@ QString NotificationManager::detectCleanAppname(QString app_name) return app_name; } +QStringHash NotificationManager::getCategoryParams(QString category) +{ + if (!category.isEmpty()) { + QString categoryConfigFile = QString("/usr/share/lipstick/notificationcategories/%1.conf").arg(category); + QFile testFile(categoryConfigFile); + if (testFile.exists()) { + QStringHash categories; + QSettings settings(categoryConfigFile, QSettings::IniFormat); + const QStringList settingKeys = settings.allKeys(); + foreach (const QString &settingKey, settingKeys) { + categories[settingKey] = settings.value(settingKey).toString(); + } + return categories; + } + } + return QStringHash(); +} + void NotificationManager::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout) { //Ignore notifcations from myself @@ -93,10 +111,10 @@ void NotificationManager::Notify(const QString &app_name, uint replaces_id, cons return; } - logger()->debug() << Q_FUNC_INFO << "Got notification via dbus from" << detectCleanAppname(app_name); + logger()->debug() << Q_FUNC_INFO << "Got notification via dbus from" << this->getCleanAppName(app_name); if (app_name == "messageserver5") { - emit this->emailNotify(hints.value("x-nemo-preview-summary", detectCleanAppname(app_name)).toString(), + emit this->emailNotify(hints.value("x-nemo-preview-summary", this->getCleanAppName(app_name)).toString(), hints.value("x-nemo-preview-body", "default").toString(), "" ); @@ -106,10 +124,19 @@ void NotificationManager::Notify(const QString &app_name, uint replaces_id, cons hints.value("x-nemo-preview-body", "default").toString() ); } + } else if (app_name == "harbour-mitakuuluu2-server") { + emit this->smsNotify(hints.value("x-nemo-preview-body", "default").toString(), + hints.value("x-nemo-preview-summary", "default").toString() + ); } else { //Prioritize x-nemo-preview* over dbus direct summary and body QString subject = hints.value("x-nemo-preview-summary", "").toString(); QString data = hints.value("x-nemo-preview-body", "").toString(); + QString category = hints.value("category", "").toString(); + QStringHash categoryParams = this->getCategoryParams(category); + int prio = categoryParams.value("x-nemo-priority", "0").toInt(); + + logger()->debug() << "MSG Prio:" << prio; if (subject.isEmpty()) { subject = summary; @@ -130,6 +157,6 @@ void NotificationManager::Notify(const QString &app_name, uint replaces_id, cons return; } - emit this->emailNotify(detectCleanAppname(app_name), data, subject); + emit this->emailNotify(this->getCleanAppName(app_name), data, subject); } } diff --git a/daemon/notificationmanager.h b/daemon/notificationmanager.h index 45ae090..d2640eb 100644 --- a/daemon/notificationmanager.h +++ b/daemon/notificationmanager.h @@ -7,6 +7,8 @@ #include #include +typedef QHash QStringHash; + class NotificationManager : public QObject { Q_OBJECT @@ -34,7 +36,8 @@ protected Q_SLOTS: private: class NotificationManagerPrivate *d_ptr; - QString detectCleanAppname(QString app_name); + QString getCleanAppName(QString app_name); + QStringHash getCategoryParams(QString category); Q_DISABLE_COPY(NotificationManager) Q_DECLARE_PRIVATE(NotificationManager) -- cgit v1.2.3