feat(Settings): add an field to choose chat notification sound

This commit is contained in:
Ronan Abhamon 2018-04-18 17:36:15 +02:00
parent 5ac0f684f7
commit b50dec69f7
12 changed files with 87 additions and 24 deletions

View file

@ -1188,7 +1188,11 @@ Server URL ist nicht konfiguriert.</translation>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatSoundNotificationEnabledLabel</source>
<source>chatNotificationSoundEnabledLabel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatNotificationSoundLabel</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1193,8 +1193,12 @@ your friend&apos;s SIP address or username.</translation>
<translation>Call recorder enabled</translation>
</message>
<message>
<source>chatSoundNotificationEnabledLabel</source>
<translation>Sound notification enabled</translation>
<source>chatNotificationSoundEnabledLabel</source>
<translation>Notification sound enabled</translation>
</message>
<message>
<source>chatNotificationSoundLabel</source>
<translation>Sound notification</translation>
</message>
</context>
<context>

View file

@ -1082,7 +1082,7 @@ Cliquez ici : &lt;a href=&quot;%1&quot;&gt;%1&lt;/a&gt;
</message>
<message>
<source>logsEnabledLabel</source>
<translation>Logs activés.</translation>
<translation>Logs activés</translation>
</message>
<message>
<source>cleanLogs</source>
@ -1191,9 +1191,13 @@ Cliquez ici : &lt;a href=&quot;%1&quot;&gt;%1&lt;/a&gt;
<translation>Enregistrement d&apos;appel activé</translation>
</message>
<message>
<source>chatSoundNotificationEnabledLabel</source>
<source>chatNotificationSoundEnabledLabel</source>
<translation>Son des notifications activé</translation>
</message>
<message>
<source>chatNotificationSoundLabel</source>
<translation>Son des notifications</translation>
</message>
</context>
<context>
<name>SettingsNetwork</name>

View file

@ -1188,7 +1188,11 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>chatSoundNotificationEnabledLabel</source>
<source>chatNotificationSoundEnabledLabel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatNotificationSoundLabel</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1193,7 +1193,11 @@ Tiesiog, įveskite savo draugo SIP adresą ar naudotojo vardą.</translation>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatSoundNotificationEnabledLabel</source>
<source>chatNotificationSoundEnabledLabel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatNotificationSoundLabel</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1191,7 +1191,11 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>chatSoundNotificationEnabledLabel</source>
<source>chatNotificationSoundEnabledLabel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatNotificationSoundLabel</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1187,7 +1187,11 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>chatSoundNotificationEnabledLabel</source>
<source>chatNotificationSoundEnabledLabel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatNotificationSoundLabel</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1193,7 +1193,11 @@ arkadaşınızın SIP adresini veya kullanıcı adını girin.</translation>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatSoundNotificationEnabledLabel</source>
<source>chatNotificationSoundEnabledLabel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chatNotificationSoundLabel</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -170,7 +170,8 @@ void CoreHandlers::onMessageReceived (
emit messageReceived(message);
// 1. Do not notify if chat is not activated.
if (!CoreManager::getInstance()->getSettingsModel()->getChatEnabled())
SettingsModel *settingsModel = CoreManager::getInstance()->getSettingsModel();
if (!settingsModel->getChatEnabled())
return;
// 2. Notify with Notification popup.
@ -179,7 +180,7 @@ void CoreHandlers::onMessageReceived (
app->getNotifier()->notifyReceivedMessage(message);
// 3. Notify with sound.
if (!CoreManager::getInstance()->getSettingsModel()->getChatSoundNotificationEnabled())
if (!settingsModel->getChatNotificationSoundEnabled())
return;
if (
@ -188,8 +189,7 @@ void CoreHandlers::onMessageReceived (
Utils::coreStringToAppString(message->getFromAddress()->asStringUriOnly())
)
)
// TODO: Provide a way to choose sound file.
core->playLocal(linphone::Factory::get()->getSoundResourcesDir() + "/incoming_chat.wav");
core->playLocal(Utils::appStringToCoreString(settingsModel->getChatNotificationSoundPath()));
}
}

View file

@ -303,13 +303,26 @@ void SettingsModel::setChatEnabled (bool status) {
// -----------------------------------------------------------------------------
bool SettingsModel::getChatSoundNotificationEnabled () const {
bool SettingsModel::getChatNotificationSoundEnabled () const {
return !!mConfig->getInt(UI_SECTION, "chat_sound_notification_enabled", 1);
}
void SettingsModel::setChatSoundNotificationEnabled (bool status) {
void SettingsModel::setChatNotificationSoundEnabled (bool status) {
mConfig->setInt(UI_SECTION, "chat_sound_notification_enabled", status);
emit chatSoundNotificationEnabledChanged(status);
emit chatNotificationSoundEnabledChanged(status);
}
// -----------------------------------------------------------------------------
QString SettingsModel::getChatNotificationSoundPath () const {
static const string defaultFile = linphone::Factory::get()->getSoundResourcesDir() + "/incoming_chat.wav";
return Utils::coreStringToAppString(mConfig->getString(UI_SECTION, "chat_sound_notification_file", defaultFile));
}
void SettingsModel::setChatNotificationSoundPath (const QString &path) {
QString cleanedPath = QDir::cleanPath(path);
mConfig->setString(UI_SECTION, "chat_sound_notification_file", Utils::appStringToCoreString(cleanedPath));
emit chatNotificationSoundPathChanged(cleanedPath);
}
// -----------------------------------------------------------------------------

View file

@ -73,7 +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(bool chatNotificationSoundEnabled READ getChatNotificationSoundEnabled WRITE setChatNotificationSoundEnabled NOTIFY chatNotificationSoundEnabledChanged);
Q_PROPERTY(QString chatNotificationSoundPath READ getChatNotificationSoundPath WRITE setChatNotificationSoundPath NOTIFY chatNotificationSoundPathChanged);
Q_PROPERTY(QString fileTransferUrl READ getFileTransferUrl WRITE setFileTransferUrl NOTIFY fileTransferUrlChanged);
@ -221,8 +222,11 @@ public:
bool getChatEnabled () const;
void setChatEnabled (bool status);
bool getChatSoundNotificationEnabled () const;
void setChatSoundNotificationEnabled (bool status);
bool getChatNotificationSoundEnabled () const;
void setChatNotificationSoundEnabled (bool status);
QString getChatNotificationSoundPath () const;
void setChatNotificationSoundPath (const QString &path);
QString getFileTransferUrl () const;
void setFileTransferUrl (const QString &url);
@ -378,7 +382,8 @@ signals:
void chatEnabledChanged (bool status);
void chatSoundNotificationEnabledChanged (bool status);
void chatNotificationSoundEnabledChanged (bool status);
void chatNotificationSoundPathChanged (const QString &path);
void fileTransferUrlChanged (const QString &url);

View file

@ -137,12 +137,25 @@ TabContainer {
FormLine {
FormGroup {
label: qsTr('chatSoundNotificationEnabledLabel')
label: qsTr('chatNotificationSoundEnabledLabel')
Switch {
checked: SettingsModel.chatSoundNotificationEnabled
id: enableChatNotificationSound
onClicked: SettingsModel.chatSoundNotificationEnabled = !checked
checked: SettingsModel.chatNotificationSoundEnabled
onClicked: SettingsModel.chatNotificationSoundEnabled = !checked
}
}
FormGroup {
label: qsTr('chatNotificationSoundLabel')
FileChooserButton {
enabled: enableChatNotificationSound.checked
selectedFile: SettingsModel.chatNotificationSoundPath
onAccepted: SettingsModel.chatNotificationSoundPath = selectedFile
}
}
}