From f75e5a3f4b0efe33e9c38c3d9c55e0afe96db741 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sat, 10 Oct 2020 18:46:08 +0300 Subject: [PATCH] Added "Notification feedback" combo box --- qml/pages/SettingsPage.qml | 53 ++++++++++++++++++++++++++++++++++- src/appsettings.cpp | 15 ++++++++++ src/appsettings.h | 13 +++++++++ src/harbour-fernschreiber.cpp | 5 ++-- src/notificationmanager.cpp | 16 +++++++++-- src/notificationmanager.h | 4 ++- 6 files changed, 99 insertions(+), 7 deletions(-) diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index 32cda43..f1b27b9 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -18,9 +18,9 @@ */ import QtQuick 2.0 import Sailfish.Silica 1.0 +import WerkWolf.Fernschreiber 1.0 import "../js/functions.js" as Functions - Page { id: settingsPage allowedOrientations: Orientation.All @@ -52,6 +52,57 @@ Page { } } + ComboBox { + id: feedbackComboBox + label: qsTr("Notification feedback") + description: qsTr("Non-graphical feedback adds vibration to visual notifications.") + menu: ContextMenu { + id: feedbackMenu + + MenuItem { + readonly property int value: AppSettings.NotificationFeedbackAll + text: qsTr("All events") + onClicked: { + appSettings.notificationFeedback = value + } + } + MenuItem { + readonly property int value: AppSettings.NotificationFeedbackNew + text: qsTr("Only new events") + onClicked: { + appSettings.notificationFeedback = value + } + } + MenuItem { + readonly property int value: AppSettings.NotificationFeedbackNone + text: qsTr("None") + onClicked: { + appSettings.notificationFeedback = value + } + } + } + + Component.onCompleted: updateFeedbackSelection() + + function updateFeedbackSelection() { + var menuItems = feedbackMenu.children + var n = menuItems.length + for (var i=0; isetContextProperty("appSettings", appSettings); + qmlRegisterUncreatableType("WerkWolf.Fernschreiber", 1, 0, "AppSettings", QString()); TDLibWrapper *tdLibWrapper = new TDLibWrapper(view.data()); context->setContextProperty("tdLibWrapper", tdLibWrapper); - qmlRegisterType("WerkWolf.Fernschreiber", 1, 0, "TelegramAPI"); + qmlRegisterUncreatableType("WerkWolf.Fernschreiber", 1, 0, "TelegramAPI", QString()); DBusAdaptor *dBusAdaptor = tdLibWrapper->getDBusAdaptor(); context->setContextProperty("dBusAdaptor", dBusAdaptor); @@ -61,7 +62,7 @@ int main(int argc, char *argv[]) ChatModel chatModel(tdLibWrapper); context->setContextProperty("chatModel", &chatModel); - NotificationManager notificationManager(tdLibWrapper); + NotificationManager notificationManager(tdLibWrapper, appSettings); context->setContextProperty("notificationManager", ¬ificationManager); ProcessLauncher processLauncher; diff --git a/src/notificationmanager.cpp b/src/notificationmanager.cpp index 1f7be53..1300c88 100644 --- a/src/notificationmanager.cpp +++ b/src/notificationmanager.cpp @@ -29,11 +29,12 @@ #define LOG(x) qDebug() << "[NotificationManager]" << x -NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper) : +NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings) : mceInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", QDBusConnection::systemBus()) { LOG("Initializing..."); this->tdLibWrapper = tdLibWrapper; + this->appSettings = appSettings; this->ngfClient = new Ngf::Client(this); connect(this->tdLibWrapper, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList))); @@ -178,12 +179,15 @@ QVariantMap NotificationManager::sendNotification(const QString &chatId, const Q nemoNotification.setAppName("Fernschreiber"); nemoNotification.setAppIcon(appIconUrl.toLocalFile()); nemoNotification.setSummary(chatInformation.value("title").toString()); - nemoNotification.setCategory("x-nemo.messaging.im"); nemoNotification.setTimestamp(QDateTime::fromMSecsSinceEpoch(messageMap.value("date").toLongLong() * 1000)); QVariantList remoteActionArguments; remoteActionArguments.append(chatId); remoteActionArguments.append(messageMap.value("id").toString()); nemoNotification.setRemoteAction(Notification::remoteAction("default", "openMessage", "de.ygriega.fernschreiber", "/de/ygriega/fernschreiber", "de.ygriega.fernschreiber", "openMessage", remoteActionArguments)); + + bool needFeedback; + const AppSettings::NotificationFeedback feedbackStyle = appSettings->notificationFeedback(); + if (activeNotifications.isEmpty()) { QString notificationBody; if (addAuthor) { @@ -195,13 +199,19 @@ QVariantMap NotificationManager::sendNotification(const QString &chatId, const Q } notificationBody = notificationBody + this->getNotificationText(messageMap.value("content").toMap()); nemoNotification.setBody(notificationBody); + needFeedback = (feedbackStyle != AppSettings::NotificationFeedbackNone); } else { nemoNotification.setReplacesId(activeNotifications.first().toMap().value("replaces_id").toUInt()); nemoNotification.setBody(tr("%1 unread messages").arg(activeNotifications.size() + 1)); + needFeedback = (feedbackStyle == AppSettings::NotificationFeedbackAll); + } + + if (needFeedback) { + nemoNotification.setCategory("x-nemo.messaging.im"); + ngfClient->play("chat"); } nemoNotification.publish(); - this->ngfClient->play("chat"); this->controlLedNotification(true); updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId()); return updatedNotificationInformation; diff --git a/src/notificationmanager.h b/src/notificationmanager.h index 41419a9..7e1c123 100644 --- a/src/notificationmanager.h +++ b/src/notificationmanager.h @@ -24,12 +24,13 @@ #include #include #include "tdlibwrapper.h" +#include "appsettings.h" class NotificationManager : public QObject { Q_OBJECT public: - NotificationManager(TDLibWrapper *tdLibWrapper); + NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings); ~NotificationManager() override; signals: @@ -56,6 +57,7 @@ private: private: TDLibWrapper *tdLibWrapper; + AppSettings *appSettings; Ngf::Client *ngfClient; QVariantMap chatMap; QVariantMap notificationGroups;