From 32637550d87f16dcb04659c63e6bfe253cdc8aae Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 17 Apr 2018 11:13:27 +0200 Subject: [PATCH] feat(Settings): add an option to disable chat features --- assets/languages/en.ts | 4 ++ assets/languages/fr_FR.ts | 4 ++ assets/languages/ru.ts | 4 ++ assets/languages/tr.ts | 4 ++ src/components/core/CoreHandlers.cpp | 2 +- src/components/core/CoreManager.cpp | 51 +++++++++--------- .../AbstractMessagesCountNotifier.cpp | 6 ++- src/components/settings/SettingsModel.cpp | 9 ++++ src/components/settings/SettingsModel.hpp | 7 +++ ui/modules/Linphone/Chat/Chat.js | 2 +- ui/modules/Linphone/Chat/Chat.qml | 35 +++++++----- .../SmartSearchBar/SmartSearchBar.qml | 2 +- ui/modules/Linphone/Timeline/Timeline.qml | 2 +- ui/views/App/Calls/CallsWindow.qml | 11 ++++ ui/views/App/Calls/Incall.qml | 4 +- ui/views/App/Main/Contacts.qml | 2 +- ui/views/App/Main/Conversation.js | 7 +-- ui/views/App/Main/Conversation.qml | 53 ++++++++++++------- ui/views/App/Settings/SettingsCallsChat.qml | 12 +++++ 19 files changed, 153 insertions(+), 68 deletions(-) diff --git a/assets/languages/en.ts b/assets/languages/en.ts index c0eebf2ae..3bfa267bd 100644 --- a/assets/languages/en.ts +++ b/assets/languages/en.ts @@ -1176,6 +1176,10 @@ your friend's SIP address or username. autoAnswerWithVideoLabel Auto answer (with video) + + chatEnabledLabel + Chat enabled + SettingsNetwork diff --git a/assets/languages/fr_FR.ts b/assets/languages/fr_FR.ts index 776dc109e..b6a17e5c4 100644 --- a/assets/languages/fr_FR.ts +++ b/assets/languages/fr_FR.ts @@ -1174,6 +1174,10 @@ Cliquez ici : <a href="%1">%1</a> autoAnswerWithVideoLabel Répondre autom. (avec vidéo) + + chatEnabledLabel + Chat activé + SettingsNetwork diff --git a/assets/languages/ru.ts b/assets/languages/ru.ts index 3b9e351ff..310804f4b 100644 --- a/assets/languages/ru.ts +++ b/assets/languages/ru.ts @@ -1174,6 +1174,10 @@ autoAnswerWithVideoLabel Принимать вызов автоматически (с видео) + + chatEnabledLabel + + SettingsNetwork diff --git a/assets/languages/tr.ts b/assets/languages/tr.ts index d11a3ba92..5504ccd97 100644 --- a/assets/languages/tr.ts +++ b/assets/languages/tr.ts @@ -1176,6 +1176,10 @@ arkadaşınızın SIP adresini veya kullanıcı adını girin. autoAnswerWithVideoLabel Kendiliğinden yanıtla (görüntüyle) + + chatEnabledLabel + + SettingsNetwork diff --git a/src/components/core/CoreHandlers.cpp b/src/components/core/CoreHandlers.cpp index 972b4cff0..99dae4143 100644 --- a/src/components/core/CoreHandlers.cpp +++ b/src/components/core/CoreHandlers.cpp @@ -170,7 +170,7 @@ void CoreHandlers::onMessageReceived ( emit messageReceived(message); const App *app = App::getInstance(); - if (!app->hasFocus()) + if (!app->hasFocus() && CoreManager::getInstance()->getSettingsModel()->getChatEnabled()) app->getNotifier()->notifyReceivedMessage(message); } } diff --git a/src/components/core/CoreManager.cpp b/src/components/core/CoreManager.cpp index b2f061d26..05ce4bd36 100644 --- a/src/components/core/CoreManager.cpp +++ b/src/components/core/CoreManager.cpp @@ -25,8 +25,8 @@ #include #include -#include "../../app/paths/Paths.hpp" -#include "../../utils/Utils.hpp" +#include "app/paths/Paths.hpp" +#include "utils/Utils.hpp" #if defined(Q_OS_LINUX) #include "messages-count-notifier/MessagesCountNotifierLinux.hpp" @@ -38,10 +38,10 @@ #include "CoreManager.hpp" -using namespace std; - // ============================================================================= +using namespace std; + namespace { constexpr int cCbsCallInterval = 20; @@ -73,17 +73,17 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) : CoreHandlers *coreHandlers = mHandlers.get(); QObject::connect(coreHandlers, &CoreHandlers::coreStarted, this, [] { - { - MessagesCountNotifier *messagesCountNotifier = new MessagesCountNotifier(mInstance); - messagesCountNotifier->updateUnreadMessagesCount(); - } - mInstance->mCallsListModel = new CallsListModel(mInstance); mInstance->mContactsListModel = new ContactsListModel(mInstance); mInstance->mSipAddressesModel = new SipAddressesModel(mInstance); mInstance->mSettingsModel = new SettingsModel(mInstance); mInstance->mAccountSettingsModel = new AccountSettingsModel(mInstance); + { + MessagesCountNotifier *messagesCountNotifier = new MessagesCountNotifier(mInstance); + messagesCountNotifier->updateUnreadMessagesCount(); + } + mInstance->migrate(); mInstance->mStarted = true; @@ -106,12 +106,12 @@ shared_ptr CoreManager::getChatModelFromSipAddress (const QString &si // Create a new chat model. if (!mChatModels.contains(sipAddress)) { - Q_ASSERT(mCore->createAddress(::Utils::appStringToCoreString(sipAddress)) != nullptr); + Q_ASSERT(mCore->createAddress(Utils::appStringToCoreString(sipAddress)) != nullptr); auto deleter = [this](ChatModel *chatModel) { - mChatModels.remove(chatModel->getSipAddress()); - delete chatModel; - }; + mChatModels.remove(chatModel->getSipAddress()); + delete chatModel; + }; shared_ptr chatModel(new ChatModel(sipAddress), deleter); mChatModels[chatModel->getSipAddress()] = chatModel; @@ -169,7 +169,7 @@ void CoreManager::sendLogs () const { Q_CHECK_PTR(mCore); qInfo() << QStringLiteral("Send logs to: `%1`.") - .arg(::Utils::coreStringToAppString(mCore->getLogCollectionUploadServerUrl())); + .arg(Utils::coreStringToAppString(mCore->getLogCollectionUploadServerUrl())); mCore->uploadLogCollection(); } @@ -185,7 +185,7 @@ void CoreManager::cleanLogs () const { do { \ qInfo() << QStringLiteral("Set `%1` path: `%2`") \ .arg( # DATABASE) \ - .arg(::Utils::coreStringToAppString(PATH)); \ + .arg(Utils::coreStringToAppString(PATH)); \ mCore->set ## DATABASE ## DatabasePath(PATH); \ } while (0); @@ -200,15 +200,12 @@ void CoreManager::setDatabasesPaths () { // ----------------------------------------------------------------------------- void CoreManager::setOtherPaths () { - if (mCore->getZrtpSecretsFile().empty() || !Paths::filePathExists(mCore->getZrtpSecretsFile())) { + if (mCore->getZrtpSecretsFile().empty() || !Paths::filePathExists(mCore->getZrtpSecretsFile())) mCore->setZrtpSecretsFile(Paths::getZrtpSecretsFilePath()); - } - if (mCore->getUserCertificatesPath().empty() || !Paths::filePathExists(mCore->getUserCertificatesPath())) { + if (mCore->getUserCertificatesPath().empty() || !Paths::filePathExists(mCore->getUserCertificatesPath())) mCore->setUserCertificatesPath(Paths::getUserCertificatesDirPath()); - } - if (mCore->getRootCa().empty() || !Paths::filePathExists(mCore->getRootCa())) { + if (mCore->getRootCa().empty() || !Paths::filePathExists(mCore->getRootCa())) mCore->setRootCa(Paths::getRootCaFilePath()); - } } void CoreManager::setResourcesPaths () { @@ -227,11 +224,15 @@ void CoreManager::createLinphoneCore (const QString &configPath) { setResourcesPaths(); - mCore = linphone::Factory::get()->createCore(mHandlers, Paths::getConfigFilePath(configPath), Paths::getFactoryConfigFilePath()); + mCore = linphone::Factory::get()->createCore( + mHandlers, + Paths::getConfigFilePath(configPath), + Paths::getFactoryConfigFilePath() + ); mCore->setVideoDisplayFilter("MSOGL"); mCore->usePreviewWindow(true); - mCore->setUserAgent("Linphone Desktop", ::Utils::appStringToCoreString(QCoreApplication::applicationVersion())); + mCore->setUserAgent("Linphone Desktop", Utils::appStringToCoreString(QCoreApplication::applicationVersion())); // Force capture/display. // Useful if the app was built without video support. @@ -274,7 +275,7 @@ void CoreManager::migrate () { // ----------------------------------------------------------------------------- QString CoreManager::getVersion () const { - return ::Utils::coreStringToAppString(mCore->getVersion()); + return Utils::coreStringToAppString(mCore->getVersion()); } // ----------------------------------------------------------------------------- @@ -294,7 +295,7 @@ void CoreManager::handleLogsUploadStateChanged (linphone::CoreLogCollectionUploa case linphone::CoreLogCollectionUploadStateDelivered: case linphone::CoreLogCollectionUploadStateNotDelivered: - emit logsUploaded(::Utils::coreStringToAppString(info)); + emit logsUploaded(Utils::coreStringToAppString(info)); break; } } diff --git a/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp index fd5d96bde..58ef47a30 100644 --- a/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp +++ b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp @@ -38,6 +38,10 @@ AbstractMessagesCountNotifier::AbstractMessagesCountNotifier (QObject *parent) : coreManager->getHandlers().get(), &CoreHandlers::messageReceived, this, &AbstractMessagesCountNotifier::handleMessageReceived ); + QObject::connect( + coreManager->getSettingsModel(), &SettingsModel::chatEnabledChanged, + this, &AbstractMessagesCountNotifier::internalNotifyUnreadMessagesCount + ); } // ----------------------------------------------------------------------------- @@ -54,7 +58,7 @@ void AbstractMessagesCountNotifier::internalNotifyUnreadMessagesCount () { qInfo() << QStringLiteral("Notify unread messages count: %1.").arg(mUnreadMessagesCount); int n = mUnreadMessagesCount > 99 ? 99 : mUnreadMessagesCount; - notifyUnreadMessagesCount(n); + notifyUnreadMessagesCount(CoreManager::getInstance()->getSettingsModel()->getChatEnabled() ? n : 0); } // ----------------------------------------------------------------------------- diff --git a/src/components/settings/SettingsModel.cpp b/src/components/settings/SettingsModel.cpp index 1a1ca87fb..08ea16e3e 100644 --- a/src/components/settings/SettingsModel.cpp +++ b/src/components/settings/SettingsModel.cpp @@ -281,6 +281,15 @@ void SettingsModel::setAutoAnswerVideoStatus (bool status) { // ----------------------------------------------------------------------------- +bool SettingsModel::getChatEnabled () const { + return !!mConfig->getInt(UI_SECTION, "chat_enabled", 1); +} + +void SettingsModel::setChatEnabled (bool status) { + mConfig->setInt(UI_SECTION, "chat_enabled", status); + emit chatEnabledChanged(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 a6b7cd9e4..3bdd20697 100644 --- a/src/components/settings/SettingsModel.hpp +++ b/src/components/settings/SettingsModel.hpp @@ -69,6 +69,8 @@ class SettingsModel : public QObject { Q_PROPERTY(bool autoAnswerVideoStatus READ getAutoAnswerVideoStatus WRITE setAutoAnswerVideoStatus NOTIFY autoAnswerVideoStatusChanged); Q_PROPERTY(int autoAnswerDelay READ getAutoAnswerDelay WRITE setAutoAnswerDelay NOTIFY autoAnswerDelayChanged); + Q_PROPERTY(bool chatEnabled READ getChatEnabled WRITE setChatEnabled NOTIFY chatEnabledChanged); + Q_PROPERTY(QString fileTransferUrl READ getFileTransferUrl WRITE setFileTransferUrl NOTIFY fileTransferUrlChanged); Q_PROPERTY(bool limeIsSupported READ getLimeIsSupported CONSTANT); @@ -207,6 +209,9 @@ public: int getAutoAnswerDelay () const; void setAutoAnswerDelay (int delay); + bool getChatEnabled () const; + void setChatEnabled (bool status); + QString getFileTransferUrl () const; void setFileTransferUrl (const QString &url); @@ -352,6 +357,8 @@ signals: void autoAnswerVideoStatusChanged (bool status); void autoAnswerDelayChanged (int delay); + void chatEnabledChanged (bool status); + void fileTransferUrlChanged (const QString &url); void mediaEncryptionChanged (MediaEncryption encryption); diff --git a/ui/modules/Linphone/Chat/Chat.js b/ui/modules/Linphone/Chat/Chat.js index b60db925f..2dce2e211 100644 --- a/ui/modules/Linphone/Chat/Chat.js +++ b/ui/modules/Linphone/Chat/Chat.js @@ -72,7 +72,7 @@ function handleTextChanged () { } function sendMessage (text) { - textArea.text = '' + textArea.item.text = '' chat.bindToEnd = true container.proxyModel.sendMessage(text) } diff --git a/ui/modules/Linphone/Chat/Chat.qml b/ui/modules/Linphone/Chat/Chat.qml index f2e3576e1..509263a55 100644 --- a/ui/modules/Linphone/Chat/Chat.qml +++ b/ui/modules/Linphone/Chat/Chat.qml @@ -203,26 +203,33 @@ Rectangle { // Send area. // ------------------------------------------------------------------------- - Borders { + Loader { + id: textArea + Layout.fillWidth: true - Layout.preferredHeight: ChatStyle.sendArea.height + ChatStyle.sendArea.border.width + Layout.preferredHeight: active ? ChatStyle.sendArea.height + ChatStyle.sendArea.border.width : 0 - borderColor: ChatStyle.sendArea.border.color - - topWidth: ChatStyle.sendArea.border.width - - DroppableTextArea { - id: textArea + active: SettingsModel.chatEnabled + sourceComponent: Borders { + property alias text: textArea.text anchors.fill: parent + borderColor: ChatStyle.sendArea.border.color + topWidth: ChatStyle.sendArea.border.width - dropEnabled: SettingsModel.fileTransferUrl.length > 0 - dropDisabledReason: qsTr('noFileTransferUrl') - placeholderText: qsTr('newMessagePlaceholder') + DroppableTextArea { + id: textArea - onDropped: Logic.handleFilesDropped(files) - onTextChanged: Logic.handleTextChanged(text) - onValidText: Logic.sendMessage(text) + anchors.fill: parent + + dropEnabled: SettingsModel.fileTransferUrl.length > 0 + dropDisabledReason: qsTr('noFileTransferUrl') + placeholderText: qsTr('newMessagePlaceholder') + + onDropped: Logic.handleFilesDropped(files) + onTextChanged: Logic.handleTextChanged(text) + onValidText: Logic.sendMessage(text) + } } } } diff --git a/ui/modules/Linphone/SmartSearchBar/SmartSearchBar.qml b/ui/modules/Linphone/SmartSearchBar/SmartSearchBar.qml index 357f09745..914d3698a 100644 --- a/ui/modules/Linphone/SmartSearchBar/SmartSearchBar.qml +++ b/ui/modules/Linphone/SmartSearchBar/SmartSearchBar.qml @@ -51,7 +51,7 @@ SearchBox { searchBox.launchCall(entry.sipAddress) } }, { - icon: 'chat', + icon: SettingsModel.chatEnabled ? 'chat' : 'history', handler: function (entry) { searchBox.closeMenu() searchBox.launchChat(entry.sipAddress) diff --git a/ui/modules/Linphone/Timeline/Timeline.qml b/ui/modules/Linphone/Timeline/Timeline.qml index 1dec35ca6..d260bd7b8 100644 --- a/ui/modules/Linphone/Timeline/Timeline.qml +++ b/ui/modules/Linphone/Timeline/Timeline.qml @@ -110,7 +110,7 @@ ColumnLayout { ? TimelineStyle.contact.backgroundColor.a : TimelineStyle.contact.backgroundColor.b ) - displayUnreadMessagesCount: view.currentIndex !== index + displayUnreadMessagesCount: SettingsModel.chatEnabled && view.currentIndex !== index entry: $timelineEntry sipAddressColor: view.currentIndex === index ? TimelineStyle.contact.sipAddress.color.selected diff --git a/ui/views/App/Calls/CallsWindow.qml b/ui/views/App/Calls/CallsWindow.qml index 7bc1d484f..f20fe2368 100644 --- a/ui/views/App/Calls/CallsWindow.qml +++ b/ui/views/App/Calls/CallsWindow.qml @@ -188,8 +188,19 @@ Window { Chat { proxyModel: ChatProxyModel { + Component.onCompleted: { + if (!SettingsModel.chatEnabled) { + setEntryTypeFilter(ChatModel.CallEntry) + } + } + sipAddress: window.sipAddress } + + Connections { + target: SettingsModel + onChatEnabledChanged: proxyModel.setEntryTypeFilter(status ? ChatModel.GenericEntry : ChatModel.CallEntry) + } } } diff --git a/ui/views/App/Calls/Incall.qml b/ui/views/App/Calls/Incall.qml index 1a36dda98..7f7515f9a 100644 --- a/ui/views/App/Calls/Incall.qml +++ b/ui/views/App/Calls/Incall.qml @@ -390,6 +390,8 @@ Rectangle { } ActionBar { + id: bottomActions + anchors { right: parent.right rightMargin: CallStyle.actionArea.rightButtonsGroupMargin @@ -417,7 +419,7 @@ Rectangle { } ActionButton { - icon: 'chat' + icon: SettingsModel.chatEnabled ? 'chat' : 'history' onClicked: { if (window.chatIsOpened) { diff --git a/ui/views/App/Main/Contacts.qml b/ui/views/App/Main/Contacts.qml index 333fe92d0..aa16d0a61 100644 --- a/ui/views/App/Main/Contacts.qml +++ b/ui/views/App/Main/Contacts.qml @@ -148,7 +148,7 @@ ColumnLayout { } ActionButton { - icon: 'chat' + icon: SettingsModel.chatEnabled ? 'chat' : 'history' onClicked: actions.itemAt(2).open() } } diff --git a/ui/views/App/Main/Conversation.js b/ui/views/App/Main/Conversation.js index 870ded9bd..28fc8beef 100644 --- a/ui/views/App/Main/Conversation.js +++ b/ui/views/App/Main/Conversation.js @@ -33,11 +33,12 @@ function getUsername () { } function updateChatFilter (button) { + var ChatModel = Linphone.ChatModel if (button === 0) { - chatProxyModel.setEntryTypeFilter(Linphone.ChatModel.GenericEntry) + chatProxyModel.setEntryTypeFilter(ChatModel.GenericEntry) } else if (button === 1) { - chatProxyModel.setEntryTypeFilter(Linphone.ChatModel.CallEntry) + chatProxyModel.setEntryTypeFilter(ChatModel.CallEntry) } else { - chatProxyModel.setEntryTypeFilter(Linphone.ChatModel.MessageEntry) + chatProxyModel.setEntryTypeFilter(ChatModel.MessageEntry) } } diff --git a/ui/views/App/Main/Conversation.qml b/ui/views/App/Main/Conversation.qml index 69bf4dbc0..d4872852c 100644 --- a/ui/views/App/Main/Conversation.qml +++ b/ui/views/App/Main/Conversation.qml @@ -118,29 +118,33 @@ ColumnLayout { // Messages/Calls filters. // --------------------------------------------------------------------------- - Borders { + Loader { Layout.fillWidth: true - Layout.preferredHeight: ConversationStyle.filters.height + Layout.preferredHeight: active ? ConversationStyle.filters.height : 0 - borderColor: ConversationStyle.filters.border.color - bottomWidth: ConversationStyle.filters.border.bottomWidth - color: ConversationStyle.filters.backgroundColor - topWidth: ConversationStyle.filters.border.topWidth + active: SettingsModel.chatEnabled + sourceComponent: Borders { + anchors.fill: parent + borderColor: ConversationStyle.filters.border.color + bottomWidth: ConversationStyle.filters.border.bottomWidth + color: ConversationStyle.filters.backgroundColor + topWidth: ConversationStyle.filters.border.topWidth - ExclusiveButtons { - anchors { - left: parent.left - leftMargin: ConversationStyle.filters.leftMargin - verticalCenter: parent.verticalCenter + ExclusiveButtons { + anchors { + left: parent.left + leftMargin: ConversationStyle.filters.leftMargin + verticalCenter: parent.verticalCenter + } + + texts: [ + qsTr('displayCallsAndMessages'), + qsTr('displayCalls'), + qsTr('displayMessages') + ] + + onClicked: Logic.updateChatFilter(button) } - - texts: [ - qsTr('displayCallsAndMessages'), - qsTr('displayCalls'), - qsTr('displayMessages') - ] - - onClicked: Logic.updateChatFilter(button) } } @@ -155,7 +159,18 @@ ColumnLayout { proxyModel: ChatProxyModel { id: chatProxyModel + Component.onCompleted: { + if (!SettingsModel.chatEnabled) { + setEntryTypeFilter(ChatModel.CallEntry) + } + } + sipAddress: conversation.sipAddress } } + + Connections { + target: SettingsModel + onChatEnabledChanged: chatProxyModel.setEntryTypeFilter(status ? ChatModel.GenericEntry : ChatModel.CallEntry) + } } diff --git a/ui/views/App/Settings/SettingsCallsChat.qml b/ui/views/App/Settings/SettingsCallsChat.qml index d231f2d10..0d1a53913 100644 --- a/ui/views/App/Settings/SettingsCallsChat.qml +++ b/ui/views/App/Settings/SettingsCallsChat.qml @@ -105,6 +105,18 @@ TabContainer { title: qsTr('chatTitle') width: parent.width + FormLine { + FormGroup { + label: qsTr('chatEnabledLabel') + + Switch { + checked: SettingsModel.chatEnabled + + onClicked: SettingsModel.chatEnabled = !checked + } + } + } + FormLine { FormGroup { label: qsTr('fileServerLabel')