Add NGF daemon and LED control for notifications
This commit is contained in:
parent
c52a544e51
commit
fdf89fd8a8
5 changed files with 73 additions and 5 deletions
|
@ -14,7 +14,7 @@ TARGET = harbour-fernschreiber
|
|||
|
||||
CONFIG += sailfishapp sailfishapp_i18n
|
||||
|
||||
PKGCONFIG += nemonotifications-qt5
|
||||
PKGCONFIG += nemonotifications-qt5 ngf-qt5
|
||||
|
||||
QT += core dbus
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ Name: harbour-fernschreiber
|
|||
|
||||
Summary: Fernschreiber is a Telegram client for Sailfish OS
|
||||
Version: 0.1
|
||||
Release: 3
|
||||
Release: 4
|
||||
Group: Qt/Qt
|
||||
License: LICENSE
|
||||
URL: http://werkwolf.eu/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Name: harbour-fernschreiber
|
||||
Summary: Fernschreiber is a Telegram client for Sailfish OS
|
||||
Version: 0.1
|
||||
Release: 3
|
||||
Release: 4
|
||||
# The contents of the Group field should be one of the groups listed here:
|
||||
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
|
||||
Group: Qt/Qt
|
||||
|
|
|
@ -24,16 +24,32 @@
|
|||
#include <QListIterator>
|
||||
#include <QUrl>
|
||||
#include <QDateTime>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
|
||||
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent)
|
||||
{
|
||||
qDebug() << "[NotificationManager] Initializing...";
|
||||
this->tdLibWrapper = tdLibWrapper;
|
||||
this->ngfClient = new Ngf::Client(this);
|
||||
|
||||
connect(this->tdLibWrapper, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList)));
|
||||
connect(this->tdLibWrapper, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap)));
|
||||
connect(this->tdLibWrapper, SIGNAL(notificationUpdated(QVariantMap)), this, SLOT(handleUpdateNotification(QVariantMap)));
|
||||
connect(this->tdLibWrapper, SIGNAL(newChatDiscovered(QString, QVariantMap)), this, SLOT(handleChatDiscovered(QString, QVariantMap)));
|
||||
connect(this->ngfClient, SIGNAL(connectionStatus(bool)), this, SLOT(handleNgfConnectionStatus(bool)));
|
||||
connect(this->ngfClient, SIGNAL(eventCompleted(quint32)), this, SLOT(handleNgfEventCompleted(quint32)));
|
||||
connect(this->ngfClient, SIGNAL(eventFailed(quint32)), this, SLOT(handleNgfEventFailed(quint32)));
|
||||
connect(this->ngfClient, SIGNAL(eventPlaying(quint32)), this, SLOT(handleNgfEventPlaying(quint32)));
|
||||
|
||||
if (this->ngfClient->connect()) {
|
||||
qDebug() << "[NotificationManager] NGF Client successfully initialized...";
|
||||
} else {
|
||||
qDebug() << "[NotificationManager] Failed to initialize NGF Client...";
|
||||
}
|
||||
|
||||
this->controlLedNotification(false);
|
||||
|
||||
}
|
||||
|
||||
NotificationManager::~NotificationManager()
|
||||
|
@ -90,6 +106,10 @@ void NotificationManager::handleUpdateNotificationGroup(const QVariantMap notifi
|
|||
activeNotifications = newActiveNotifications;
|
||||
}
|
||||
|
||||
if (activeNotifications.isEmpty()) {
|
||||
this->controlLedNotification(false);
|
||||
}
|
||||
|
||||
QVariantList addedNotifications = notificationGroupUpdate.value("added_notifications").toList();
|
||||
QListIterator<QVariant> addedNotificationIterator(addedNotifications);
|
||||
while (addedNotificationIterator.hasNext()) {
|
||||
|
@ -115,6 +135,31 @@ void NotificationManager::handleChatDiscovered(const QString &chatId, const QVar
|
|||
this->chatListMutex.unlock();
|
||||
}
|
||||
|
||||
void NotificationManager::handleNgfConnectionStatus(const bool &connected)
|
||||
{
|
||||
qDebug() << "[NotificationManager] NGF Daemon connection status changed " << connected;
|
||||
}
|
||||
|
||||
void NotificationManager::handleNgfEventFailed(const quint32 &eventId)
|
||||
{
|
||||
qDebug() << "[NotificationManager] NGF event failed, id: " << eventId;
|
||||
}
|
||||
|
||||
void NotificationManager::handleNgfEventCompleted(const quint32 &eventId)
|
||||
{
|
||||
qDebug() << "[NotificationManager] NGF event completed, id: " << eventId;
|
||||
}
|
||||
|
||||
void NotificationManager::handleNgfEventPlaying(const quint32 &eventId)
|
||||
{
|
||||
qDebug() << "[NotificationManager] NGF event playing, id: " << eventId;
|
||||
}
|
||||
|
||||
void NotificationManager::handleNgfEventPaused(const quint32 &eventId)
|
||||
{
|
||||
qDebug() << "[NotificationManager] NGF event paused, id: " << eventId;
|
||||
}
|
||||
|
||||
QVariantMap NotificationManager::sendNotification(const QString &chatId, const QVariantMap ¬ificationInformation, const QVariantMap &activeNotifications)
|
||||
{
|
||||
qDebug() << "[NotificationManager] Sending notification" << notificationInformation.value("id").toString();
|
||||
|
@ -152,6 +197,8 @@ QVariantMap NotificationManager::sendNotification(const QString &chatId, const Q
|
|||
}
|
||||
|
||||
nemoNotification.publish();
|
||||
this->ngfClient->play("chat");
|
||||
this->controlLedNotification(true);
|
||||
updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId());
|
||||
return updatedNotificationInformation;
|
||||
}
|
||||
|
@ -205,3 +252,17 @@ QString NotificationManager::getNotificationText(const QVariantMap ¬ification
|
|||
}
|
||||
return tr("Unsupported message: %1").arg(contentType.mid(7));
|
||||
}
|
||||
|
||||
void NotificationManager::controlLedNotification(const bool &enabled)
|
||||
{
|
||||
qDebug() << "[NotificationManager] 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);
|
||||
|
||||
if (enabled) {
|
||||
dbusInterface.call("req_led_pattern_activate", "PatternCommunicationIM");
|
||||
} else {
|
||||
dbusInterface.call("req_led_pattern_deactivate", "PatternCommunicationIM");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
|
||||
#include <ngf-qt5/NgfClient>
|
||||
#include "tdlibwrapper.h"
|
||||
|
||||
class NotificationManager : public QObject
|
||||
|
@ -40,10 +40,16 @@ public slots:
|
|||
void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate);
|
||||
void handleUpdateNotification(const QVariantMap updatedNotification);
|
||||
void handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation);
|
||||
void handleNgfConnectionStatus(const bool &connected);
|
||||
void handleNgfEventFailed(const quint32 &eventId);
|
||||
void handleNgfEventCompleted(const quint32 &eventId);
|
||||
void handleNgfEventPlaying(const quint32 &eventId);
|
||||
void handleNgfEventPaused(const quint32 &eventId);
|
||||
|
||||
private:
|
||||
|
||||
TDLibWrapper *tdLibWrapper;
|
||||
Ngf::Client *ngfClient;
|
||||
QVariantMap chatMap;
|
||||
QVariantMap notificationGroups;
|
||||
QMutex chatListMutex;
|
||||
|
@ -51,6 +57,7 @@ private:
|
|||
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);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue