Merge pull request #349 from monich/sound
Made notification sound configurable
This commit is contained in:
commit
444649c3b2
4 changed files with 90 additions and 49 deletions
|
@ -561,11 +561,66 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
id: feedbackComboBox
|
||||
width: parent.columnWidth
|
||||
label: qsTr("Notification feedback")
|
||||
description: qsTr("Use non-graphical feedback (sound, vibration) for notifications")
|
||||
menu: ContextMenu {
|
||||
id: feedbackMenu
|
||||
x: 0
|
||||
width: feedbackComboBox.width
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TextSwitch {
|
||||
width: parent.columnWidth
|
||||
checked: appSettings.notificationTurnsDisplayOn && enabled
|
||||
text: qsTr("Notification turns on the display")
|
||||
height: appSettings.notificationFeedback === AppSettings.NotificationFeedbackNone ? 0 : implicitHeight
|
||||
enabled: appSettings.notificationFeedback !== AppSettings.NotificationFeedbackNone
|
||||
height: enabled ? implicitHeight: 0
|
||||
clip: height < implicitHeight
|
||||
visible: height > 0
|
||||
automaticCheck: false
|
||||
|
@ -574,57 +629,23 @@ Page {
|
|||
}
|
||||
Behavior on height { SmoothedAnimation { duration: 200 } }
|
||||
}
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
id: feedbackComboBox
|
||||
label: qsTr("Notification feedback")
|
||||
description: qsTr("Use non-graphical feedback (sound, vibration) for 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
|
||||
}
|
||||
TextSwitch {
|
||||
width: parent.columnWidth
|
||||
checked: appSettings.notificationSoundsEnabled && enabled
|
||||
text: qsTr("Enable notification sounds")
|
||||
description: qsTr("When sounds are enabled, Fernschreiber would use Sailfish OS notification sound for chats, which can be configured in system settings.")
|
||||
enabled: appSettings.notificationFeedback !== AppSettings.NotificationFeedbackNone
|
||||
height: enabled ? implicitHeight: 0
|
||||
clip: height < implicitHeight
|
||||
visible: height > 0
|
||||
automaticCheck: false
|
||||
onClicked: {
|
||||
appSettings.notificationSoundsEnabled = !checked
|
||||
}
|
||||
Behavior on height { SmoothedAnimation { duration: 200 } }
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace {
|
|||
const QString KEY_SHOW_STICKERS_AS_IMAGES("showStickersAsImages");
|
||||
const QString KEY_ANIMATE_STICKERS("animateStickers");
|
||||
const QString KEY_NOTIFICATION_TURNS_DISPLAY_ON("notificationTurnsDisplayOn");
|
||||
const QString KEY_NOTIFICATION_SOUNDS_ENABLED("notificationSoundsEnabled");
|
||||
const QString KEY_NOTIFICATION_FEEDBACK("notificationFeedback");
|
||||
const QString KEY_STORAGE_OPTIMIZER("storageOptimizer");
|
||||
const QString KEY_INLINEBOT_LOCATION_ACCESS("allowInlineBotLocationAccess");
|
||||
|
@ -122,6 +123,20 @@ void AppSettings::setNotificationTurnsDisplayOn(bool turnOn)
|
|||
}
|
||||
}
|
||||
|
||||
bool AppSettings::notificationSoundsEnabled() const
|
||||
{
|
||||
return settings.value(KEY_NOTIFICATION_SOUNDS_ENABLED, true).toBool();
|
||||
}
|
||||
|
||||
void AppSettings::setNotificationSoundsEnabled(bool enable)
|
||||
{
|
||||
if (notificationSoundsEnabled() != enable) {
|
||||
LOG(KEY_NOTIFICATION_SOUNDS_ENABLED << enable);
|
||||
settings.setValue(KEY_NOTIFICATION_SOUNDS_ENABLED, enable);
|
||||
emit notificationSoundsEnabledChanged();
|
||||
}
|
||||
}
|
||||
|
||||
AppSettings::NotificationFeedback AppSettings::notificationFeedback() const
|
||||
{
|
||||
return (NotificationFeedback) settings.value(KEY_NOTIFICATION_FEEDBACK, (int) NotificationFeedbackAll).toInt();
|
||||
|
|
|
@ -29,6 +29,7 @@ class AppSettings : public QObject {
|
|||
Q_PROPERTY(bool showStickersAsImages READ showStickersAsImages WRITE setShowStickersAsImages NOTIFY showStickersAsImagesChanged)
|
||||
Q_PROPERTY(bool animateStickers READ animateStickers WRITE setAnimateStickers NOTIFY animateStickersChanged)
|
||||
Q_PROPERTY(bool notificationTurnsDisplayOn READ notificationTurnsDisplayOn WRITE setNotificationTurnsDisplayOn NOTIFY notificationTurnsDisplayOnChanged)
|
||||
Q_PROPERTY(bool notificationSoundsEnabled READ notificationSoundsEnabled WRITE setNotificationSoundsEnabled NOTIFY notificationSoundsEnabledChanged)
|
||||
Q_PROPERTY(NotificationFeedback notificationFeedback READ notificationFeedback WRITE setNotificationFeedback NOTIFY notificationFeedbackChanged)
|
||||
Q_PROPERTY(bool storageOptimizer READ storageOptimizer WRITE setStorageOptimizer NOTIFY storageOptimizerChanged)
|
||||
Q_PROPERTY(bool allowInlineBotLocationAccess READ allowInlineBotLocationAccess WRITE setAllowInlineBotLocationAccess NOTIFY allowInlineBotLocationAccessChanged)
|
||||
|
@ -64,6 +65,9 @@ public:
|
|||
bool notificationTurnsDisplayOn() const;
|
||||
void setNotificationTurnsDisplayOn(bool turnOn);
|
||||
|
||||
bool notificationSoundsEnabled() const;
|
||||
void setNotificationSoundsEnabled(bool enable);
|
||||
|
||||
NotificationFeedback notificationFeedback() const;
|
||||
void setNotificationFeedback(NotificationFeedback feedback);
|
||||
|
||||
|
@ -86,6 +90,7 @@ signals:
|
|||
void showStickersAsImagesChanged();
|
||||
void animateStickersChanged();
|
||||
void notificationTurnsDisplayOnChanged();
|
||||
void notificationSoundsEnabledChanged();
|
||||
void notificationFeedbackChanged();
|
||||
void storageOptimizerChanged();
|
||||
void allowInlineBotLocationAccessChanged();
|
||||
|
|
|
@ -373,7 +373,7 @@ void NotificationManager::publishNotification(const NotificationGroup *notificat
|
|||
} else {
|
||||
nemoNotification->setPreviewBody(notificationBody);
|
||||
nemoNotification->setPreviewSummary(summary);
|
||||
nemoNotification->setHintValue(HINT_SUPPRESS_SOUND, false);
|
||||
nemoNotification->setHintValue(HINT_SUPPRESS_SOUND, !appSettings->notificationSoundsEnabled());
|
||||
nemoNotification->setHintValue(HINT_DISPLAY_ON, appSettings->notificationTurnsDisplayOn());
|
||||
nemoNotification->setHintValue(HINT_VISIBILITY, VISIBILITY_PUBLIC);
|
||||
nemoNotification->setUrgency(Notification::Normal);
|
||||
|
|
Loading…
Reference in a new issue