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 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; i<n; i++) {
|
||||
if (menuItems[i].value === appSettings.notificationFeedback) {
|
||||
currentIndex = i
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: appSettings
|
||||
onNotificationFeedbackChanged: {
|
||||
feedbackComboBox.updateFeedbackSelection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SectionHeader {
|
||||
text: qsTr("Appearance")
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
namespace {
|
||||
const QString KEY_SEND_BY_ENTER("sendByEnter");
|
||||
const QString KEY_SHOW_STICKERS_AS_IMAGES("showStickersAsImages");
|
||||
const QString KEY_NOTIFICATION_FEEDBACK("notificationFeedback");
|
||||
}
|
||||
|
||||
AppSettings::AppSettings(QObject *parent) : QObject(parent), settings("harbour-fernschreiber", "settings")
|
||||
|
@ -56,3 +57,17 @@ void AppSettings::setShowStickersAsImages(bool showAsImages)
|
|||
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_PROPERTY(bool sendByEnter READ getSendByEnter WRITE setSendByEnter NOTIFY sendByEnterChanged)
|
||||
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:
|
||||
AppSettings(QObject *parent = Q_NULLPTR);
|
||||
|
@ -35,9 +44,13 @@ public:
|
|||
bool showStickersAsImages() const;
|
||||
void setShowStickersAsImages(bool showAsImages);
|
||||
|
||||
NotificationFeedback notificationFeedback() const;
|
||||
void setNotificationFeedback(NotificationFeedback feedback);
|
||||
|
||||
signals:
|
||||
void sendByEnterChanged();
|
||||
void showStickersAsImagesChanged();
|
||||
void notificationFeedbackChanged();
|
||||
|
||||
private:
|
||||
QSettings settings;
|
||||
|
|
|
@ -47,10 +47,11 @@ int main(int argc, char *argv[])
|
|||
|
||||
AppSettings *appSettings = new AppSettings(view.data());
|
||||
context->setContextProperty("appSettings", appSettings);
|
||||
qmlRegisterUncreatableType<AppSettings>("WerkWolf.Fernschreiber", 1, 0, "AppSettings", QString());
|
||||
|
||||
TDLibWrapper *tdLibWrapper = new TDLibWrapper(view.data());
|
||||
context->setContextProperty("tdLibWrapper", tdLibWrapper);
|
||||
qmlRegisterType<TDLibWrapper>("WerkWolf.Fernschreiber", 1, 0, "TelegramAPI");
|
||||
qmlRegisterUncreatableType<TDLibWrapper>("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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -24,12 +24,13 @@
|
|||
#include <QDBusInterface>
|
||||
#include <ngf-qt5/NgfClient>
|
||||
#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;
|
||||
|
|
Loading…
Reference in a new issue