From 4ca581e134f86cb4760c920f21657ae7a9b73612 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 5 Nov 2020 14:41:25 -0500
Subject: [PATCH] settings: add some chatview settings

Add:
+ Display images and videos into the chatview
+ Show typing indicators

Change-Id: Icf5575ae9b176254394399073fe3926130ecc428
Gitlab: #160
---
 qml.qrc                                       |  1 +
 src/appsettingsmanager.h                      |  2 +
 src/constant/JamiStrings.qml                  |  5 ++
 src/mainview/components/MessageWebView.qml    |  1 +
 src/messagesadapter.cpp                       | 15 ++++
 src/messagesadapter.h                         |  1 +
 .../components/ChatviewSettings.qml           | 80 +++++++++++++++++++
 .../components/GeneralSettingsPage.qml        | 10 +++
 8 files changed, 115 insertions(+)
 create mode 100644 src/settingsview/components/ChatviewSettings.qml

diff --git a/qml.qrc b/qml.qrc
index 2d514ecbe..7f2d12277 100644
--- a/qml.qrc
+++ b/qml.qrc
@@ -2,6 +2,7 @@
     <qresource prefix="/">
         <file>src/constant/JamiStrings.qml</file>
         <file>src/settingsview/SettingsView.qml</file>
+        <file>src/settingsview/components/ChatviewSettings.qml</file>
         <file>src/settingsview/components/SettingsMenu.qml</file>
         <file>src/settingsview/components/SettingsHeader.qml</file>
         <file>src/settingsview/components/SystemSettings.qml</file>
diff --git a/src/appsettingsmanager.h b/src/appsettingsmanager.h
index a44aea2fd..69817f1d5 100644
--- a/src/appsettingsmanager.h
+++ b/src/appsettingsmanager.h
@@ -35,6 +35,8 @@ const QString defaultDownloadPath = QStandardPaths::writableLocation(
     X(MinimizeOnClose, true) \
     X(DownloadPath, defaultDownloadPath) \
     X(EnableNotifications, true) \
+    X(EnableTypingIndicator, true) \
+    X(DisplayImagesChatview, true) \
     X(AutoUpdate, true) \
     X(NeverShowMeAgain, false)
 
diff --git a/src/constant/JamiStrings.qml b/src/constant/JamiStrings.qml
index 07e795ba7..9c2ac2b2b 100644
--- a/src/constant/JamiStrings.qml
+++ b/src/constant/JamiStrings.qml
@@ -272,6 +272,11 @@ Item {
     property string tipChooseDownloadFolder: qsTr("Choose download directory")
     property string recordCall: qsTr("Record call")
 
+    // ChatviewSettings
+    property string chatview: qsTr("Chatview")
+    property string enableTypingIndicator: qsTr("Show typing indicator")
+    property string displayImages: qsTr("Display images and videos into the chatview")
+
     // Updates
     property string betaInstall: qsTr("Install beta version")
     property string checkForUpdates: qsTr("Check for updates now")
diff --git a/src/mainview/components/MessageWebView.qml b/src/mainview/components/MessageWebView.qml
index 0a35109fe..f0e46259c 100644
--- a/src/mainview/components/MessageWebView.qml
+++ b/src/mainview/components/MessageWebView.qml
@@ -259,6 +259,7 @@ Rectangle {
                             UtilsAdapter.qStringFromFile(":/chatview.js"),
                             function() {
                                 messageWebView.runJavaScript("init_i18n();")
+                                MessagesAdapter.setDisplayLinks()
                                 messageWebView.runJavaScript("displayNavbar(false);")
                                 jsLoaded = true
                             })
diff --git a/src/messagesadapter.cpp b/src/messagesadapter.cpp
index fbb384916..da4186f99 100644
--- a/src/messagesadapter.cpp
+++ b/src/messagesadapter.cpp
@@ -94,6 +94,9 @@ MessagesAdapter::setupChatView(const QString& uid)
     connect(LRCInstance::getCurrentConversationModel(),
             &ConversationModel::composingStatusChanged,
             [this](const QString& uid, const QString& contactUri, bool isComposing) {
+                if (!AppSettingsManager::getValue(Settings::Key::EnableTypingIndicator).toBool()) {
+                    return;
+                }
                 contactIsComposing(uid, contactUri, isComposing);
             });
 
@@ -428,6 +431,9 @@ MessagesAdapter::pasteKeyDetected()
 void
 MessagesAdapter::onComposing(bool isComposing)
 {
+    if (!AppSettingsManager::getValue(Settings::Key::EnableTypingIndicator).toBool()) {
+        return;
+    }
     LRCInstance::getCurrentConversationModel()->setIsComposing(LRCInstance::getCurrentConvUid(),
                                                                isComposing);
 }
@@ -535,6 +541,15 @@ MessagesAdapter::clear()
     QMetaObject::invokeMethod(qmlObj_, "webViewRunJavaScript", Q_ARG(QVariant, s));
 }
 
+void
+MessagesAdapter::setDisplayLinks()
+{
+    QString s = QString::fromLatin1("setDisplayLinks(%1);")
+                    .arg(
+                        AppSettingsManager::getValue(Settings::Key::DisplayImagesChatview).toBool());
+    QMetaObject::invokeMethod(qmlObj_, "webViewRunJavaScript", Q_ARG(QVariant, s));
+}
+
 void
 MessagesAdapter::printHistory(lrc::api::ConversationModel& conversationModel,
                               const std::map<uint64_t, lrc::api::interaction::Info> interactions)
diff --git a/src/messagesadapter.h b/src/messagesadapter.h
index 39842346b..27abe5ac8 100644
--- a/src/messagesadapter.h
+++ b/src/messagesadapter.h
@@ -49,6 +49,7 @@ protected:
     Q_INVOKABLE void refuseInvitation(const QString& convUid = "");
     Q_INVOKABLE void blockConversation(const QString& convUid = "");
     Q_INVOKABLE void setNewMessagesContent(const QString& path);
+    Q_INVOKABLE void setDisplayLinks();
     Q_INVOKABLE void sendMessage(const QString& message);
     Q_INVOKABLE void sendImage(const QString& message);
     Q_INVOKABLE void sendFile(const QString& message);
diff --git a/src/settingsview/components/ChatviewSettings.qml b/src/settingsview/components/ChatviewSettings.qml
new file mode 100644
index 000000000..8b4d7e732
--- /dev/null
+++ b/src/settingsview/components/ChatviewSettings.qml
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2020 by Savoir-faire Linux
+ * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import QtQuick 2.14
+import QtQuick.Controls 2.14
+import QtQuick.Controls.Universal 2.14
+import QtQuick.Layouts 1.14
+import QtGraphicalEffects 1.14
+import QtQuick.Controls.Styles 1.4
+import net.jami.Models 1.0
+import net.jami.Adapters 1.0
+import net.jami.Enums 1.0
+import Qt.labs.platform 1.1
+
+import "../../commoncomponents"
+
+ColumnLayout {
+    id:root
+
+    property int itemWidth
+
+    Label {
+        Layout.fillWidth: true
+
+        text: JamiStrings.chatview
+        font.pointSize: JamiTheme.headerFontSize
+        font.kerning: true
+
+        horizontalAlignment: Text.AlignLeft
+        verticalAlignment: Text.AlignVCenter
+    }
+
+    ToggleSwitch {
+        id: enableTypingIndicatorCheckbox
+        Layout.fillWidth: true
+        Layout.leftMargin: JamiTheme.preferredMarginSize
+
+        checked: SettingsAdapter.getAppValue(Settings.EnableTypingIndicator)
+
+        labelText: JamiStrings.enableTypingIndicator
+        fontPointSize: JamiTheme.settingsFontSize
+
+        tooltipText: JamiStrings.enableTypingIndicator
+
+        onSwitchToggled: SettingsAdapter.setAppValue(Settings.Key.EnableTypingIndicator, checked)
+    }
+
+    ToggleSwitch {
+        id: displayImagesCheckbox
+        Layout.fillWidth: true
+        Layout.leftMargin: JamiTheme.preferredMarginSize
+
+        checked: SettingsAdapter.getAppValue(Settings.DisplayImagesChatview)
+
+        labelText: JamiStrings.displayImages
+        fontPointSize: JamiTheme.settingsFontSize
+
+        tooltipText: JamiStrings.displayImages
+
+        onSwitchToggled: {
+            SettingsAdapter.setAppValue(Settings.Key.DisplayImagesChatview, checked)
+            MessagesAdapter.setDisplayLinks()
+        }
+    }
+}
diff --git a/src/settingsview/components/GeneralSettingsPage.qml b/src/settingsview/components/GeneralSettingsPage.qml
index 25b2826c4..6d9bcfc34 100644
--- a/src/settingsview/components/GeneralSettingsPage.qml
+++ b/src/settingsview/components/GeneralSettingsPage.qml
@@ -52,6 +52,16 @@ Rectangle {
             itemWidth: preferredColumnWidth
         }
 
+        // chatview setting panel
+        ChatviewSettings {
+            Layout.fillWidth: true
+            Layout.topMargin: JamiTheme.preferredMarginSize
+            Layout.leftMargin: JamiTheme.preferredMarginSize
+            Layout.rightMargin: JamiTheme.preferredMarginSize
+
+            itemWidth: preferredColumnWidth
+        }
+
         // call recording setting panel
         RecordingSettings {
             Layout.fillWidth: true
-- 
GitLab