Don't initialize MCE QDBusInterface on every D-Bus call
It's enough to initialize it once at startup. Also avoided a few per-call ASCII => QString conversions and dropped unnecessary mutex.
This commit is contained in:
parent
65738a4ddf
commit
6e1e100a87
2 changed files with 17 additions and 20 deletions
|
@ -26,11 +26,11 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusInterface>
|
|
||||||
|
|
||||||
#define LOG(x) qDebug() << "[NotificationManager]" << x
|
#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...");
|
LOG("Initializing...");
|
||||||
this->tdLibWrapper = tdLibWrapper;
|
this->tdLibWrapper = tdLibWrapper;
|
||||||
|
@ -131,10 +131,8 @@ void NotificationManager::handleUpdateNotification(const QVariantMap updatedNoti
|
||||||
|
|
||||||
void NotificationManager::handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation)
|
void NotificationManager::handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation)
|
||||||
{
|
{
|
||||||
this->chatListMutex.lock();
|
|
||||||
LOG("Adding chat to internal map" << chatId);
|
LOG("Adding chat to internal map" << chatId);
|
||||||
this->chatMap.insert(chatId, chatInformation);
|
this->chatMap.insert(chatId, chatInformation);
|
||||||
this->chatListMutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationManager::handleNgfConnectionStatus(const bool &connected)
|
void NotificationManager::handleNgfConnectionStatus(const bool &connected)
|
||||||
|
@ -226,13 +224,10 @@ QString NotificationManager::getNotificationText(const QVariantMap ¬ification
|
||||||
|
|
||||||
void NotificationManager::controlLedNotification(const bool &enabled)
|
void NotificationManager::controlLedNotification(const bool &enabled)
|
||||||
{
|
{
|
||||||
LOG("Controlling notification LED" << enabled;
|
static const QString PATTERN("PatternCommunicationIM");
|
||||||
QDBusConnection dbusConnection = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
|
static const QString ACTIVATE("req_led_pattern_activate");
|
||||||
QDBusInterface dbusInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", dbusConnection);
|
static const QString DEACTIVATE("req_led_pattern_deactivate");
|
||||||
|
|
||||||
if (enabled) {
|
LOG("Controlling notification LED" << enabled);
|
||||||
dbusInterface.call("req_led_pattern_activate", "PatternCommunicationIM");
|
mceInterface.call(enabled ? ACTIVATE : DEACTIVATE, PATTERN);
|
||||||
} else {
|
|
||||||
dbusInterface.call("req_led_pattern_deactivate", "PatternCommunicationIM");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#define NOTIFICATIONMANAGER_H
|
#define NOTIFICATIONMANAGER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMutex>
|
#include <QDBusInterface>
|
||||||
#include <ngf-qt5/NgfClient>
|
#include <ngf-qt5/NgfClient>
|
||||||
#include "tdlibwrapper.h"
|
#include "tdlibwrapper.h"
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class NotificationManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent = nullptr);
|
NotificationManager(TDLibWrapper *tdLibWrapper);
|
||||||
~NotificationManager() override;
|
~NotificationManager() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -48,17 +48,19 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TDLibWrapper *tdLibWrapper;
|
|
||||||
Ngf::Client *ngfClient;
|
|
||||||
QVariantMap chatMap;
|
|
||||||
QVariantMap notificationGroups;
|
|
||||||
QMutex chatListMutex;
|
|
||||||
|
|
||||||
QVariantMap sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation, const QVariantMap &activeNotifications);
|
QVariantMap sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation, const QVariantMap &activeNotifications);
|
||||||
void removeNotification(const QVariantMap ¬ificationInformation);
|
void removeNotification(const QVariantMap ¬ificationInformation);
|
||||||
QString getNotificationText(const QVariantMap ¬ificationContent);
|
QString getNotificationText(const QVariantMap ¬ificationContent);
|
||||||
void controlLedNotification(const bool &enabled);
|
void controlLedNotification(const bool &enabled);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
TDLibWrapper *tdLibWrapper;
|
||||||
|
Ngf::Client *ngfClient;
|
||||||
|
QVariantMap chatMap;
|
||||||
|
QVariantMap notificationGroups;
|
||||||
|
QDBusInterface mceInterface;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NOTIFICATIONMANAGER_H
|
#endif // NOTIFICATIONMANAGER_H
|
||||||
|
|
Loading…
Reference in a new issue