diff --git a/src/notificationmanager.cpp b/src/notificationmanager.cpp index eb69e23..1f7be53 100644 --- a/src/notificationmanager.cpp +++ b/src/notificationmanager.cpp @@ -26,11 +26,11 @@ #include #include #include -#include #define LOG(x) qDebug() << "[NotificationManager]" << x -NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent) +NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper) : + mceInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", QDBusConnection::systemBus()) { LOG("Initializing..."); this->tdLibWrapper = tdLibWrapper; @@ -131,10 +131,8 @@ void NotificationManager::handleUpdateNotification(const QVariantMap updatedNoti void NotificationManager::handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation) { - this->chatListMutex.lock(); LOG("Adding chat to internal map" << chatId); this->chatMap.insert(chatId, chatInformation); - this->chatListMutex.unlock(); } void NotificationManager::handleNgfConnectionStatus(const bool &connected) @@ -226,13 +224,10 @@ QString NotificationManager::getNotificationText(const QVariantMap ¬ification void NotificationManager::controlLedNotification(const bool &enabled) { - LOG("Controlling notification LED" << enabled; - QDBusConnection dbusConnection = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system"); - QDBusInterface dbusInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", dbusConnection); + static const QString PATTERN("PatternCommunicationIM"); + static const QString ACTIVATE("req_led_pattern_activate"); + static const QString DEACTIVATE("req_led_pattern_deactivate"); - if (enabled) { - dbusInterface.call("req_led_pattern_activate", "PatternCommunicationIM"); - } else { - dbusInterface.call("req_led_pattern_deactivate", "PatternCommunicationIM"); - } + LOG("Controlling notification LED" << enabled); + mceInterface.call(enabled ? ACTIVATE : DEACTIVATE, PATTERN); } diff --git a/src/notificationmanager.h b/src/notificationmanager.h index 52c57b4..41419a9 100644 --- a/src/notificationmanager.h +++ b/src/notificationmanager.h @@ -21,7 +21,7 @@ #define NOTIFICATIONMANAGER_H #include -#include +#include #include #include "tdlibwrapper.h" @@ -29,7 +29,7 @@ class NotificationManager : public QObject { Q_OBJECT public: - explicit NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent = nullptr); + NotificationManager(TDLibWrapper *tdLibWrapper); ~NotificationManager() override; signals: @@ -48,17 +48,19 @@ public slots: private: - TDLibWrapper *tdLibWrapper; - Ngf::Client *ngfClient; - QVariantMap chatMap; - QVariantMap notificationGroups; - QMutex chatListMutex; - QVariantMap sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation, const QVariantMap &activeNotifications); void removeNotification(const QVariantMap ¬ificationInformation); QString getNotificationText(const QVariantMap ¬ificationContent); void controlLedNotification(const bool &enabled); +private: + + TDLibWrapper *tdLibWrapper; + Ngf::Client *ngfClient; + QVariantMap chatMap; + QVariantMap notificationGroups; + QDBusInterface mceInterface; + }; #endif // NOTIFICATIONMANAGER_H