From 38f4870d463c9f4b27091f575fd0c337fd320fd6 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Tue, 17 Apr 2018 14:22:10 +0200 Subject: [PATCH] feat(Settings): add an option to play chat sound notification when receiving an incoming message Co-authored-by: Ronan Abhamon --- assets/languages/de.ts | 4 ++++ assets/languages/en.ts | 4 ++++ assets/languages/fr_FR.ts | 4 ++++ assets/languages/ja.ts | 4 ++++ assets/languages/lt.ts | 4 ++++ assets/languages/ru.ts | 4 ++++ assets/languages/sv.ts | 4 ++++ assets/languages/tr.ts | 4 ++++ src/components/core/CoreHandlers.cpp | 22 +++++++++++++++++++-- src/components/core/CoreManager.cpp | 4 ++++ src/components/core/CoreManager.hpp | 1 + src/components/settings/SettingsModel.cpp | 11 +++++++++++ src/components/settings/SettingsModel.hpp | 7 +++++++ ui/views/App/Settings/SettingsCallsChat.qml | 12 +++++++++++ 14 files changed, 87 insertions(+), 2 deletions(-) diff --git a/assets/languages/de.ts b/assets/languages/de.ts index ebc601623..36827165e 100644 --- a/assets/languages/de.ts +++ b/assets/languages/de.ts @@ -1187,6 +1187,10 @@ Server URL ist nicht konfiguriert. callRecorderEnabledLabel + + chatSoundNotificationEnabledLabel + + SettingsNetwork diff --git a/assets/languages/en.ts b/assets/languages/en.ts index 3f65841c3..cc2632de2 100644 --- a/assets/languages/en.ts +++ b/assets/languages/en.ts @@ -1192,6 +1192,10 @@ your friend's SIP address or username. callRecorderEnabledLabel Call recorder enabled + + chatSoundNotificationEnabledLabel + + SettingsNetwork diff --git a/assets/languages/fr_FR.ts b/assets/languages/fr_FR.ts index 29ea44683..9d1293042 100644 --- a/assets/languages/fr_FR.ts +++ b/assets/languages/fr_FR.ts @@ -1190,6 +1190,10 @@ Cliquez ici : <a href="%1">%1</a> callRecorderEnabledLabel Enregistrement d'appel activé + + chatSoundNotificationEnabledLabel + + SettingsNetwork diff --git a/assets/languages/ja.ts b/assets/languages/ja.ts index 030782637..41a71ca23 100644 --- a/assets/languages/ja.ts +++ b/assets/languages/ja.ts @@ -1187,6 +1187,10 @@ callRecorderEnabledLabel + + chatSoundNotificationEnabledLabel + + SettingsNetwork diff --git a/assets/languages/lt.ts b/assets/languages/lt.ts index 1f590c819..01440d680 100644 --- a/assets/languages/lt.ts +++ b/assets/languages/lt.ts @@ -1192,6 +1192,10 @@ Tiesiog, įveskite savo draugo SIP adresą ar naudotojo vardą. callRecorderEnabledLabel + + chatSoundNotificationEnabledLabel + + SettingsNetwork diff --git a/assets/languages/ru.ts b/assets/languages/ru.ts index 836117d32..66249d764 100644 --- a/assets/languages/ru.ts +++ b/assets/languages/ru.ts @@ -1190,6 +1190,10 @@ callRecorderEnabledLabel + + chatSoundNotificationEnabledLabel + + SettingsNetwork diff --git a/assets/languages/sv.ts b/assets/languages/sv.ts index 32701af9a..afeea08c3 100644 --- a/assets/languages/sv.ts +++ b/assets/languages/sv.ts @@ -1186,6 +1186,10 @@ chatEnabledLabel + + chatSoundNotificationEnabledLabel + + SettingsNetwork diff --git a/assets/languages/tr.ts b/assets/languages/tr.ts index 9059c3a85..6b7e67a69 100644 --- a/assets/languages/tr.ts +++ b/assets/languages/tr.ts @@ -1192,6 +1192,10 @@ arkadaşınızın SIP adresini veya kullanıcı adını girin. callRecorderEnabledLabel + + chatSoundNotificationEnabledLabel + + SettingsNetwork diff --git a/src/components/core/CoreHandlers.cpp b/src/components/core/CoreHandlers.cpp index 375e0799c..d57bbb80c 100644 --- a/src/components/core/CoreHandlers.cpp +++ b/src/components/core/CoreHandlers.cpp @@ -168,10 +168,28 @@ void CoreHandlers::onMessageReceived ( if (contentType == "text/plain" || contentType == "application/vnd.gsma.rcs-ft-http+xml") { emit messageReceived(message); - core->playLocal("OUTPUT/desktop/share/sounds/linphone/incoming_chat.wav"); + + // 1. Do not notify if chat is not activated. + if (!CoreManager::getInstance()->getSettingsModel()->getChatEnabled()) + return; + + // 2. Notify with Notification popup. const App *app = App::getInstance(); - if (!app->hasFocus() && CoreManager::getInstance()->getSettingsModel()->getChatEnabled()) + if (!app->hasFocus()) app->getNotifier()->notifyReceivedMessage(message); + + // 3. Notify with sound. + if (!CoreManager::getInstance()->getSettingsModel()->getChatSoundNotificationEnabled()) + return; + + if ( + !app->hasFocus() || + !CoreManager::getInstance()->chatModelExists( + Utils::coreStringToAppString(message->getFromAddress()->asStringUriOnly()) + ) + ) + // TODO: Provide a way to choose sound file. + core->playLocal(linphone::Factory::get()->getSoundResourcesDir() + "/incoming_chat.wav"); } } diff --git a/src/components/core/CoreManager.cpp b/src/components/core/CoreManager.cpp index 05ce4bd36..f34a1f958 100644 --- a/src/components/core/CoreManager.cpp +++ b/src/components/core/CoreManager.cpp @@ -127,6 +127,10 @@ shared_ptr CoreManager::getChatModelFromSipAddress (const QString &si return chatModel; } +bool CoreManager::chatModelExists (const QString &sipAddress) { + return mChatModels.contains(sipAddress); +} + // ----------------------------------------------------------------------------- void CoreManager::init (QObject *parent, const QString &configPath) { diff --git a/src/components/core/CoreManager.hpp b/src/components/core/CoreManager.hpp index 08252ada0..6e607c273 100644 --- a/src/components/core/CoreManager.hpp +++ b/src/components/core/CoreManager.hpp @@ -62,6 +62,7 @@ public: } std::shared_ptr getChatModelFromSipAddress (const QString &sipAddress); + bool chatModelExists (const QString &sipAddress); // --------------------------------------------------------------------------- // Video render lock. diff --git a/src/components/settings/SettingsModel.cpp b/src/components/settings/SettingsModel.cpp index 0ccb7d805..f9f657d83 100644 --- a/src/components/settings/SettingsModel.cpp +++ b/src/components/settings/SettingsModel.cpp @@ -303,6 +303,17 @@ void SettingsModel::setChatEnabled (bool status) { // ----------------------------------------------------------------------------- +bool SettingsModel::getChatSoundNotificationEnabled () const { + return !!mConfig->getInt(UI_SECTION, "chat_sound_notification_enabled", 1); +} + +void SettingsModel::setChatSoundNotificationEnabled (bool status) { + mConfig->setInt(UI_SECTION, "chat_sound_notification_enabled", status); + emit chatSoundNotificationEnabledChanged(status); +} + +// ----------------------------------------------------------------------------- + QString SettingsModel::getFileTransferUrl () const { return Utils::coreStringToAppString( CoreManager::getInstance()->getCore()->getFileTransferServer() diff --git a/src/components/settings/SettingsModel.hpp b/src/components/settings/SettingsModel.hpp index f62396244..174abf7ae 100644 --- a/src/components/settings/SettingsModel.hpp +++ b/src/components/settings/SettingsModel.hpp @@ -73,6 +73,8 @@ class SettingsModel : public QObject { Q_PROPERTY(bool chatEnabled READ getChatEnabled WRITE setChatEnabled NOTIFY chatEnabledChanged); + Q_PROPERTY(bool chatSoundNotificationEnabled READ getChatSoundNotificationEnabled WRITE setChatSoundNotificationEnabled NOTIFY chatSoundNotificationEnabledChanged); + Q_PROPERTY(QString fileTransferUrl READ getFileTransferUrl WRITE setFileTransferUrl NOTIFY fileTransferUrlChanged); Q_PROPERTY(bool limeIsSupported READ getLimeIsSupported CONSTANT); @@ -219,6 +221,9 @@ public: bool getChatEnabled () const; void setChatEnabled (bool status); + bool getChatSoundNotificationEnabled () const; + void setChatSoundNotificationEnabled (bool status); + QString getFileTransferUrl () const; void setFileTransferUrl (const QString &url); @@ -373,6 +378,8 @@ signals: void chatEnabledChanged (bool status); + void chatSoundNotificationEnabledChanged (bool status); + void fileTransferUrlChanged (const QString &url); void mediaEncryptionChanged (MediaEncryption encryption); diff --git a/ui/views/App/Settings/SettingsCallsChat.qml b/ui/views/App/Settings/SettingsCallsChat.qml index 29d036a9d..bfa94b9aa 100644 --- a/ui/views/App/Settings/SettingsCallsChat.qml +++ b/ui/views/App/Settings/SettingsCallsChat.qml @@ -135,6 +135,18 @@ TabContainer { } } + FormLine { + FormGroup { + label: qsTr('chatSoundNotificationEnabledLabel') + + Switch { + checked: SettingsModel.chatSoundNotificationEnabled + + onClicked: SettingsModel.chatSoundNotificationEnabled = !checked + } + } + } + FormLine { FormGroup { label: qsTr('fileServerLabel')