Added "Notification feedback" combo box
This commit is contained in:
parent
6e1e100a87
commit
f75e5a3f4b
6 changed files with 99 additions and 7 deletions
|
@ -18,9 +18,9 @@
|
||||||
*/
|
*/
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
import WerkWolf.Fernschreiber 1.0
|
||||||
import "../js/functions.js" as Functions
|
import "../js/functions.js" as Functions
|
||||||
|
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
id: settingsPage
|
id: settingsPage
|
||||||
allowedOrientations: Orientation.All
|
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; i<n; i++) {
|
||||||
|
if (menuItems[i].value === appSettings.notificationFeedback) {
|
||||||
|
currentIndex = i
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: appSettings
|
||||||
|
onNotificationFeedbackChanged: {
|
||||||
|
feedbackComboBox.updateFeedbackSelection()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SectionHeader {
|
SectionHeader {
|
||||||
text: qsTr("Appearance")
|
text: qsTr("Appearance")
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
namespace {
|
namespace {
|
||||||
const QString KEY_SEND_BY_ENTER("sendByEnter");
|
const QString KEY_SEND_BY_ENTER("sendByEnter");
|
||||||
const QString KEY_SHOW_STICKERS_AS_IMAGES("showStickersAsImages");
|
const QString KEY_SHOW_STICKERS_AS_IMAGES("showStickersAsImages");
|
||||||
|
const QString KEY_NOTIFICATION_FEEDBACK("notificationFeedback");
|
||||||
}
|
}
|
||||||
|
|
||||||
AppSettings::AppSettings(QObject *parent) : QObject(parent), settings("harbour-fernschreiber", "settings")
|
AppSettings::AppSettings(QObject *parent) : QObject(parent), settings("harbour-fernschreiber", "settings")
|
||||||
|
@ -56,3 +57,17 @@ void AppSettings::setShowStickersAsImages(bool showAsImages)
|
||||||
emit showStickersAsImagesChanged();
|
emit showStickersAsImagesChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppSettings::NotificationFeedback AppSettings::notificationFeedback() const
|
||||||
|
{
|
||||||
|
return (NotificationFeedback) settings.value(KEY_NOTIFICATION_FEEDBACK, (int) NotificationFeedbackAll).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppSettings::setNotificationFeedback(NotificationFeedback feedback)
|
||||||
|
{
|
||||||
|
if (notificationFeedback() != feedback) {
|
||||||
|
LOG(KEY_NOTIFICATION_FEEDBACK << feedback);
|
||||||
|
settings.setValue(KEY_NOTIFICATION_FEEDBACK, (int) feedback);
|
||||||
|
emit notificationFeedbackChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,15 @@ class AppSettings : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool sendByEnter READ getSendByEnter WRITE setSendByEnter NOTIFY sendByEnterChanged)
|
Q_PROPERTY(bool sendByEnter READ getSendByEnter WRITE setSendByEnter NOTIFY sendByEnterChanged)
|
||||||
Q_PROPERTY(bool showStickersAsImages READ showStickersAsImages WRITE setShowStickersAsImages NOTIFY showStickersAsImagesChanged)
|
Q_PROPERTY(bool showStickersAsImages READ showStickersAsImages WRITE setShowStickersAsImages NOTIFY showStickersAsImagesChanged)
|
||||||
|
Q_PROPERTY(NotificationFeedback notificationFeedback READ notificationFeedback WRITE setNotificationFeedback NOTIFY notificationFeedbackChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum NotificationFeedback {
|
||||||
|
NotificationFeedbackNone,
|
||||||
|
NotificationFeedbackNew,
|
||||||
|
NotificationFeedbackAll
|
||||||
|
};
|
||||||
|
Q_ENUM(NotificationFeedback)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AppSettings(QObject *parent = Q_NULLPTR);
|
AppSettings(QObject *parent = Q_NULLPTR);
|
||||||
|
@ -35,9 +44,13 @@ public:
|
||||||
bool showStickersAsImages() const;
|
bool showStickersAsImages() const;
|
||||||
void setShowStickersAsImages(bool showAsImages);
|
void setShowStickersAsImages(bool showAsImages);
|
||||||
|
|
||||||
|
NotificationFeedback notificationFeedback() const;
|
||||||
|
void setNotificationFeedback(NotificationFeedback feedback);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sendByEnterChanged();
|
void sendByEnterChanged();
|
||||||
void showStickersAsImagesChanged();
|
void showStickersAsImagesChanged();
|
||||||
|
void notificationFeedbackChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
|
@ -47,10 +47,11 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
AppSettings *appSettings = new AppSettings(view.data());
|
AppSettings *appSettings = new AppSettings(view.data());
|
||||||
context->setContextProperty("appSettings", appSettings);
|
context->setContextProperty("appSettings", appSettings);
|
||||||
|
qmlRegisterUncreatableType<AppSettings>("WerkWolf.Fernschreiber", 1, 0, "AppSettings", QString());
|
||||||
|
|
||||||
TDLibWrapper *tdLibWrapper = new TDLibWrapper(view.data());
|
TDLibWrapper *tdLibWrapper = new TDLibWrapper(view.data());
|
||||||
context->setContextProperty("tdLibWrapper", tdLibWrapper);
|
context->setContextProperty("tdLibWrapper", tdLibWrapper);
|
||||||
qmlRegisterType<TDLibWrapper>("WerkWolf.Fernschreiber", 1, 0, "TelegramAPI");
|
qmlRegisterUncreatableType<TDLibWrapper>("WerkWolf.Fernschreiber", 1, 0, "TelegramAPI", QString());
|
||||||
|
|
||||||
DBusAdaptor *dBusAdaptor = tdLibWrapper->getDBusAdaptor();
|
DBusAdaptor *dBusAdaptor = tdLibWrapper->getDBusAdaptor();
|
||||||
context->setContextProperty("dBusAdaptor", dBusAdaptor);
|
context->setContextProperty("dBusAdaptor", dBusAdaptor);
|
||||||
|
@ -61,7 +62,7 @@ int main(int argc, char *argv[])
|
||||||
ChatModel chatModel(tdLibWrapper);
|
ChatModel chatModel(tdLibWrapper);
|
||||||
context->setContextProperty("chatModel", &chatModel);
|
context->setContextProperty("chatModel", &chatModel);
|
||||||
|
|
||||||
NotificationManager notificationManager(tdLibWrapper);
|
NotificationManager notificationManager(tdLibWrapper, appSettings);
|
||||||
context->setContextProperty("notificationManager", ¬ificationManager);
|
context->setContextProperty("notificationManager", ¬ificationManager);
|
||||||
|
|
||||||
ProcessLauncher processLauncher;
|
ProcessLauncher processLauncher;
|
||||||
|
|
|
@ -29,11 +29,12 @@
|
||||||
|
|
||||||
#define LOG(x) qDebug() << "[NotificationManager]" << x
|
#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())
|
mceInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", QDBusConnection::systemBus())
|
||||||
{
|
{
|
||||||
LOG("Initializing...");
|
LOG("Initializing...");
|
||||||
this->tdLibWrapper = tdLibWrapper;
|
this->tdLibWrapper = tdLibWrapper;
|
||||||
|
this->appSettings = appSettings;
|
||||||
this->ngfClient = new Ngf::Client(this);
|
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)));
|
||||||
|
@ -178,12 +179,15 @@ QVariantMap NotificationManager::sendNotification(const QString &chatId, const Q
|
||||||
nemoNotification.setAppName("Fernschreiber");
|
nemoNotification.setAppName("Fernschreiber");
|
||||||
nemoNotification.setAppIcon(appIconUrl.toLocalFile());
|
nemoNotification.setAppIcon(appIconUrl.toLocalFile());
|
||||||
nemoNotification.setSummary(chatInformation.value("title").toString());
|
nemoNotification.setSummary(chatInformation.value("title").toString());
|
||||||
nemoNotification.setCategory("x-nemo.messaging.im");
|
|
||||||
nemoNotification.setTimestamp(QDateTime::fromMSecsSinceEpoch(messageMap.value("date").toLongLong() * 1000));
|
nemoNotification.setTimestamp(QDateTime::fromMSecsSinceEpoch(messageMap.value("date").toLongLong() * 1000));
|
||||||
QVariantList remoteActionArguments;
|
QVariantList remoteActionArguments;
|
||||||
remoteActionArguments.append(chatId);
|
remoteActionArguments.append(chatId);
|
||||||
remoteActionArguments.append(messageMap.value("id").toString());
|
remoteActionArguments.append(messageMap.value("id").toString());
|
||||||
nemoNotification.setRemoteAction(Notification::remoteAction("default", "openMessage", "de.ygriega.fernschreiber", "/de/ygriega/fernschreiber", "de.ygriega.fernschreiber", "openMessage", remoteActionArguments));
|
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()) {
|
if (activeNotifications.isEmpty()) {
|
||||||
QString notificationBody;
|
QString notificationBody;
|
||||||
if (addAuthor) {
|
if (addAuthor) {
|
||||||
|
@ -195,13 +199,19 @@ QVariantMap NotificationManager::sendNotification(const QString &chatId, const Q
|
||||||
}
|
}
|
||||||
notificationBody = notificationBody + this->getNotificationText(messageMap.value("content").toMap());
|
notificationBody = notificationBody + this->getNotificationText(messageMap.value("content").toMap());
|
||||||
nemoNotification.setBody(notificationBody);
|
nemoNotification.setBody(notificationBody);
|
||||||
|
needFeedback = (feedbackStyle != AppSettings::NotificationFeedbackNone);
|
||||||
} else {
|
} else {
|
||||||
nemoNotification.setReplacesId(activeNotifications.first().toMap().value("replaces_id").toUInt());
|
nemoNotification.setReplacesId(activeNotifications.first().toMap().value("replaces_id").toUInt());
|
||||||
nemoNotification.setBody(tr("%1 unread messages").arg(activeNotifications.size() + 1));
|
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();
|
nemoNotification.publish();
|
||||||
this->ngfClient->play("chat");
|
|
||||||
this->controlLedNotification(true);
|
this->controlLedNotification(true);
|
||||||
updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId());
|
updatedNotificationInformation.insert("replaces_id", nemoNotification.replacesId());
|
||||||
return updatedNotificationInformation;
|
return updatedNotificationInformation;
|
||||||
|
|
|
@ -24,12 +24,13 @@
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <ngf-qt5/NgfClient>
|
#include <ngf-qt5/NgfClient>
|
||||||
#include "tdlibwrapper.h"
|
#include "tdlibwrapper.h"
|
||||||
|
#include "appsettings.h"
|
||||||
|
|
||||||
class NotificationManager : public QObject
|
class NotificationManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
NotificationManager(TDLibWrapper *tdLibWrapper);
|
NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings);
|
||||||
~NotificationManager() override;
|
~NotificationManager() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -56,6 +57,7 @@ private:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TDLibWrapper *tdLibWrapper;
|
TDLibWrapper *tdLibWrapper;
|
||||||
|
AppSettings *appSettings;
|
||||||
Ngf::Client *ngfClient;
|
Ngf::Client *ngfClient;
|
||||||
QVariantMap chatMap;
|
QVariantMap chatMap;
|
||||||
QVariantMap notificationGroups;
|
QVariantMap notificationGroups;
|
||||||
|
|
Loading…
Reference in a new issue