Add NGF daemon and LED control for notifications

This commit is contained in:
Sebastian J. Wolf 2020-09-13 21:54:36 +02:00
parent c52a544e51
commit fdf89fd8a8
5 changed files with 73 additions and 5 deletions

View file

@ -14,7 +14,7 @@ TARGET = harbour-fernschreiber
CONFIG += sailfishapp sailfishapp_i18n CONFIG += sailfishapp sailfishapp_i18n
PKGCONFIG += nemonotifications-qt5 PKGCONFIG += nemonotifications-qt5 ngf-qt5
QT += core dbus QT += core dbus

View file

@ -12,7 +12,7 @@ Name: harbour-fernschreiber
Summary: Fernschreiber is a Telegram client for Sailfish OS Summary: Fernschreiber is a Telegram client for Sailfish OS
Version: 0.1 Version: 0.1
Release: 3 Release: 4
Group: Qt/Qt Group: Qt/Qt
License: LICENSE License: LICENSE
URL: http://werkwolf.eu/ URL: http://werkwolf.eu/

View file

@ -1,7 +1,7 @@
Name: harbour-fernschreiber Name: harbour-fernschreiber
Summary: Fernschreiber is a Telegram client for Sailfish OS Summary: Fernschreiber is a Telegram client for Sailfish OS
Version: 0.1 Version: 0.1
Release: 3 Release: 4
# The contents of the Group field should be one of the groups listed here: # The contents of the Group field should be one of the groups listed here:
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
Group: Qt/Qt Group: Qt/Qt
@ -30,7 +30,7 @@ PkgConfigBR:
# Runtime dependencies which are not automatically detected # Runtime dependencies which are not automatically detected
Requires: Requires:
- sailfishsilica-qt5 >= 0.10.9 - sailfishsilica-qt5 >= 0.10.9
# All installed files # All installed files
Files: Files:

View file

@ -24,16 +24,32 @@
#include <QListIterator> #include <QListIterator>
#include <QUrl> #include <QUrl>
#include <QDateTime> #include <QDateTime>
#include <QDBusConnection>
#include <QDBusInterface>
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent) NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent)
{ {
qDebug() << "[NotificationManager] Initializing..."; qDebug() << "[NotificationManager] Initializing...";
this->tdLibWrapper = tdLibWrapper; this->tdLibWrapper = tdLibWrapper;
this->ngfClient = new Ngf::Client(this);
connect(this->tdLibWrapper, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList))); connect(this->tdLibWrapper, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList)));
connect(this->tdLibWrapper, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap))); connect(this->tdLibWrapper, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(notificationUpdated(QVariantMap)), this, SLOT(handleUpdateNotification(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->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() NotificationManager::~NotificationManager()
@ -90,6 +106,10 @@ void NotificationManager::handleUpdateNotificationGroup(const QVariantMap notifi
activeNotifications = newActiveNotifications; activeNotifications = newActiveNotifications;
} }
if (activeNotifications.isEmpty()) {
this->controlLedNotification(false);
}
QVariantList addedNotifications = notificationGroupUpdate.value("added_notifications").toList(); QVariantList addedNotifications = notificationGroupUpdate.value("added_notifications").toList();
QListIterator<QVariant> addedNotificationIterator(addedNotifications); QListIterator<QVariant> addedNotificationIterator(addedNotifications);
while (addedNotificationIterator.hasNext()) { while (addedNotificationIterator.hasNext()) {
@ -115,6 +135,31 @@ void NotificationManager::handleChatDiscovered(const QString &chatId, const QVar
this->chatListMutex.unlock(); 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 &notificationInformation, const QVariantMap &activeNotifications) QVariantMap NotificationManager::sendNotification(const QString &chatId, const QVariantMap &notificationInformation, const QVariantMap &activeNotifications)
{ {
qDebug() << "[NotificationManager] Sending notification" << notificationInformation.value("id").toString(); qDebug() << "[NotificationManager] Sending notification" << notificationInformation.value("id").toString();
@ -152,6 +197,8 @@ QVariantMap NotificationManager::sendNotification(const QString &chatId, const Q
} }
nemoNotification.publish(); nemoNotification.publish();
this->ngfClient->play("chat");
this->controlLedNotification(true);
updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId()); updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId());
return updatedNotificationInformation; return updatedNotificationInformation;
} }
@ -205,3 +252,17 @@ QString NotificationManager::getNotificationText(const QVariantMap &notification
} }
return tr("Unsupported message: %1").arg(contentType.mid(7)); 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");
}
}

View file

@ -22,7 +22,7 @@
#include <QObject> #include <QObject>
#include <QMutex> #include <QMutex>
#include <ngf-qt5/NgfClient>
#include "tdlibwrapper.h" #include "tdlibwrapper.h"
class NotificationManager : public QObject class NotificationManager : public QObject
@ -40,10 +40,16 @@ public slots:
void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate); void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate);
void handleUpdateNotification(const QVariantMap updatedNotification); void handleUpdateNotification(const QVariantMap updatedNotification);
void handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation); 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: private:
TDLibWrapper *tdLibWrapper; TDLibWrapper *tdLibWrapper;
Ngf::Client *ngfClient;
QVariantMap chatMap; QVariantMap chatMap;
QVariantMap notificationGroups; QVariantMap notificationGroups;
QMutex chatListMutex; QMutex chatListMutex;
@ -51,6 +57,7 @@ private:
QVariantMap sendNotification(const QString &chatId, const QVariantMap &notificationInformation, const QVariantMap &activeNotifications); QVariantMap sendNotification(const QString &chatId, const QVariantMap &notificationInformation, const QVariantMap &activeNotifications);
void removeNotification(const QVariantMap &notificationInformation); void removeNotification(const QVariantMap &notificationInformation);
QString getNotificationText(const QVariantMap &notificationContent); QString getNotificationText(const QVariantMap &notificationContent);
void controlLedNotification(const bool &enabled);
}; };