From db7977923d9f2c38bb0f7e1dbf3f7e12ca8e9b87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 21 Feb 2022 16:05:20 -0500
Subject: [PATCH] swarmdetailspanel: add about part

Change-Id: I2af7ff4e785529f37d5e7d532ed0295c6f1055b6
GitLab: #670
---
 src/constant/JamiStrings.qml                  |   7 +
 src/constant/JamiTheme.qml                    |   1 +
 src/currentconversation.cpp                   |  11 ++
 src/currentconversation.h                     |   1 +
 src/mainview/components/SwarmDetailsPanel.qml | 152 +++++++++++++++++-
 5 files changed, 169 insertions(+), 3 deletions(-)

diff --git a/src/constant/JamiStrings.qml b/src/constant/JamiStrings.qml
index f8a4856fc..1753fe694 100644
--- a/src/constant/JamiStrings.qml
+++ b/src/constant/JamiStrings.qml
@@ -624,6 +624,13 @@ Item {
     property string editTitle: qsTr("Edit title")
     property string editDescription: qsTr("Edit description")
 
+    property string ignoreTheSwarm: qsTr("Ignore the swarm")
+    property string ignoreTheSwarmTooltip: qsTr("Ignore all notifications from this conversation")
+    property string chooseAColor: qsTr("Choose a color")
+    property string leaveTheSwarm: qsTr("Leave the swarm")
+    property string leave: qsTr("Leave")
+    property string typeOfSwarm: qsTr("Type of swarm")
+
     // NewSwarmPage
     property string youCanAdd8: qsTr("You can add 8 people in the swarm")
     property string youCanAddMore: qsTr("You can add %1 more people in the swarm")
diff --git a/src/constant/JamiTheme.qml b/src/constant/JamiTheme.qml
index ac381c868..9402e74f6 100644
--- a/src/constant/JamiTheme.qml
+++ b/src/constant/JamiTheme.qml
@@ -372,6 +372,7 @@ Item {
 
     // Details page
     property real detailsPageMinWidth: 300
+    property int aboutBtnSize: 24
 
     // Messages point size
     property real contactEventPointSize: 10 + fontSizeOffset
diff --git a/src/currentconversation.cpp b/src/currentconversation.cpp
index dfa7176b8..534d6881c 100644
--- a/src/currentconversation.cpp
+++ b/src/currentconversation.cpp
@@ -89,6 +89,17 @@ CurrentConversation::updateData()
                     qInfo() << "Contact not found: " << e.what();
                 }
             set_isContact(isContact);
+
+            QString modeString;
+            if (convInfo.mode == conversation::Mode::ONE_TO_ONE) {
+                set_modeString(tr("Private"));
+            } else if (convInfo.mode == conversation::Mode::ADMIN_INVITES_ONLY) {
+                set_modeString(tr("Private group (restricted invites)"));
+            } else if (convInfo.mode == conversation::Mode::INVITES_ONLY) {
+                set_modeString(tr("Private group"));
+            } else if (convInfo.mode == conversation::Mode::PUBLIC) {
+                set_modeString(tr("Public group"));
+            }
         }
     } catch (...) {
         qWarning() << "Can't update current conversation data for" << convId;
diff --git a/src/currentconversation.h b/src/currentconversation.h
index 76962e1e1..58e393c80 100644
--- a/src/currentconversation.h
+++ b/src/currentconversation.h
@@ -47,6 +47,7 @@ class CurrentConversation final : public QObject
     QML_PROPERTY(bool, isTemporary)
     QML_PROPERTY(bool, isContact)
     QML_PROPERTY(bool, allMessagesLoaded)
+    QML_PROPERTY(QString, modeString)
 
 public:
     explicit CurrentConversation(LRCInstance* lrcInstance, QObject* parent = nullptr);
diff --git a/src/mainview/components/SwarmDetailsPanel.qml b/src/mainview/components/SwarmDetailsPanel.qml
index 5ea44f1bc..95dbab059 100644
--- a/src/mainview/components/SwarmDetailsPanel.qml
+++ b/src/mainview/components/SwarmDetailsPanel.qml
@@ -19,12 +19,14 @@
 import QtQuick
 import QtQuick.Controls
 import QtQuick.Layouts
+import Qt.labs.platform
 
 import net.jami.Models 1.1
 import net.jami.Adapters 1.1
 import net.jami.Constants 1.1
 
 import "../../commoncomponents"
+import "../../settingsview/components"
 
 Rectangle {
     id: root
@@ -108,11 +110,13 @@ Rectangle {
             TabBar {
                 id: tabBar
 
+                currentIndex: 1
+
                 Layout.topMargin: JamiTheme.preferredMarginSize
                 Layout.preferredWidth: root.width
                 Layout.preferredHeight: membersTabButton.height
 
-                /*FilterTabButton {
+                FilterTabButton {
                     id: aboutTabButton
                     backgroundColor: CurrentConversation.color
                     hoverColor: CurrentConversation.color
@@ -128,7 +132,7 @@ Rectangle {
 
                     down: tabBar.currentIndex === 0
                     labelText: JamiStrings.about
-                }*/
+                }
 
                 FilterTabButton {
                     id: membersTabButton
@@ -144,7 +148,7 @@ Rectangle {
                             JamiTheme.chatviewTextColorLight :
                             JamiTheme.chatviewTextColorDark
 
-                    down: true//tabBar.currentIndex === 1
+                    down: tabBar.currentIndex === 1
                     labelText: {
                         var membersNb = CurrentConversation.uris.length;
                         if (membersNb > 1)
@@ -173,17 +177,159 @@ Rectangle {
             }
         }
 
+        ColorDialog {
+            id: colorDialog
+            title: JamiTheme.chooseAColor
+            onAccepted: {
+                console.warn("TODO SAVE preference")
+                CurrentConversation.color = colorDialog.color
+            }
+        }
+
         Rectangle {
             id: details
             Layout.fillWidth: true
             Layout.preferredHeight: root.height - header.height
             color: JamiTheme.secondaryBackgroundColor
 
+            ColumnLayout {
+                id: aboutSwarm
+                anchors.left: parent.left
+                anchors.right: parent.right
+                anchors.rightMargin: JamiTheme.settingsMarginSize
+                spacing: JamiTheme.preferredMarginSize
+                visible: tabBar.currentIndex === 0
+                Layout.alignment: Qt.AlignTop
+
+                ToggleSwitch {
+                    id: ignoreSwarm
+
+                    Layout.fillWidth: true
+                    Layout.leftMargin: JamiTheme.preferredMarginSize
+                    Layout.topMargin: JamiTheme.preferredMarginSize
+
+                    checked: false // TODO
+
+                    labelText: JamiStrings.ignoreTheSwarm
+                    fontPointSize: JamiTheme.settingsFontSize
+
+                    tooltipText: JamiStrings.ignoreTheSwarmTooltip
+
+                    onSwitchToggled: {
+                        // TODO
+                    }
+                }
+
+                RowLayout {
+                    Layout.leftMargin: JamiTheme.preferredMarginSize
+
+                    Text {
+                        Layout.fillWidth: true
+                        Layout.preferredHeight: 30
+                        Layout.rightMargin: JamiTheme.preferredMarginSize
+
+                        text: JamiStrings.leaveTheSwarm
+                        font.pointSize: JamiTheme.settingsFontSize
+                        font.kerning: true
+                        elide: Text.ElideRight
+                        horizontalAlignment: Text.AlignLeft
+                        verticalAlignment: Text.AlignVCenter
+
+                        color: JamiTheme.textColor
+                    }
+
+                    PushButton {
+                        id: leaveTheSwarmBtn
+
+                        anchors.verticalCenter: parent.verticalCenter
+                        source: JamiResources.round_close_24dp_svg
+
+                        normalColor: JamiTheme.backgroundColor
+                        imageColor: JamiTheme.textColor
+                        toolTipText: JamiStrings.leave
+
+                        onClicked: {
+                            MessagesAdapter.removeConversation(LRCInstance.selectedConvUid)
+                        }
+                    }
+                }
+
+                RowLayout {
+                    Layout.leftMargin: JamiTheme.preferredMarginSize
+
+                    Text {
+                        Layout.fillWidth: true
+                        Layout.preferredHeight: 30
+                        Layout.rightMargin: JamiTheme.preferredMarginSize
+
+                        text: JamiStrings.chooseAColor
+                        font.pointSize: JamiTheme.settingsFontSize
+                        font.kerning: true
+                        elide: Text.ElideRight
+                        horizontalAlignment: Text.AlignLeft
+                        verticalAlignment: Text.AlignVCenter
+
+                        color: JamiTheme.textColor
+                    }
+
+                    Rectangle {
+                        id: chooseAColorBtn
+
+                        Layout.alignment: Qt.AlignRight
+
+                        width: JamiTheme.aboutBtnSize
+                        height: JamiTheme.aboutBtnSize
+                        radius: JamiTheme.aboutBtnSize / 2
+
+                        color: CurrentConversation.color
+
+                        MouseArea {
+                            id: mouseArea
+                            anchors.fill: parent
+                            hoverEnabled: true
+                            onClicked: colorDialog.open()
+                        }
+                    }
+                }
+
+
+                RowLayout {
+                    Layout.leftMargin: JamiTheme.preferredMarginSize
+
+                    Text {
+                        Layout.fillWidth: true
+                        Layout.preferredHeight: 30
+                        Layout.rightMargin: JamiTheme.preferredMarginSize
+
+                        text: JamiStrings.typeOfSwarm
+                        font.pointSize: JamiTheme.settingsFontSize
+                        font.kerning: true
+                        elide: Text.ElideRight
+                        horizontalAlignment: Text.AlignLeft
+                        verticalAlignment: Text.AlignVCenter
+
+                        color: JamiTheme.textColor
+                    }
+
+                    Label {
+                        id: typeOfSwarmLabel
+
+                        Layout.alignment: Qt.AlignRight
+
+                        color: JamiTheme.buttonTintedBlack
+
+                        text: CurrentConversation.modeString
+                    }
+                }
+            }
+
             JamiListView {
                 id: members
                 anchors.fill: parent
                 anchors.topMargin: JamiTheme.preferredMarginSize
 
+                visible: tabBar.currentIndex === 1
+
                 SwarmParticipantContextMenu {
                     id: contextMenu
                     role: UtilsAdapter.getParticipantRole(CurrentAccount.id, CurrentConversation.id, CurrentAccount.uri)
-- 
GitLab