From 4449aabfed2fdb609f07a5f80224d715dbb43340 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 22 Jul 2022 10:28:30 -0400
Subject: [PATCH] conversationsmartlist: add confirm dialog for blocking and
 removing

Change-Id: I98f9d19176a0401d5498a74e9bcc318868388854
---
 qml.qrc                                       |   1 +
 src/app/commoncomponents/ConfirmDialog.qml    | 103 ++++++++++++++++++
 src/app/constant/JamiStrings.qml              |   4 +
 .../ConversationSmartListContextMenu.qml      |  32 ++++--
 4 files changed, 133 insertions(+), 7 deletions(-)
 create mode 100644 src/app/commoncomponents/ConfirmDialog.qml

diff --git a/qml.qrc b/qml.qrc
index 84ec262bf..2c6eb0550 100644
--- a/qml.qrc
+++ b/qml.qrc
@@ -15,6 +15,7 @@
         <file>src/app/commoncomponents/PhotoboothView.qml</file>
         <file>src/app/commoncomponents/JamiListView.qml</file>
         <file>src/app/commoncomponents/DeleteAccountDialog.qml</file>
+        <file>src/app/commoncomponents/ConfirmDialog.qml</file>
         <file>src/app/commoncomponents/CustomBorder.qml</file>
         <file>src/app/commoncomponents/PushButton.qml</file>
         <file>src/app/commoncomponents/JamiFileDialog.qml</file>
diff --git a/src/app/commoncomponents/ConfirmDialog.qml b/src/app/commoncomponents/ConfirmDialog.qml
new file mode 100644
index 000000000..582bc5427
--- /dev/null
+++ b/src/app/commoncomponents/ConfirmDialog.qml
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Layouts
+
+import net.jami.Models 1.1
+import net.jami.Adapters 1.1
+import net.jami.Constants 1.1
+
+BaseModalDialog {
+    id: root
+
+    signal accepted
+
+    width: JamiTheme.preferredDialogWidth
+    height: JamiTheme.preferredDialogHeight
+
+    property var confirmLabel: ""
+    property var textLabel: ""
+
+    popupContent: ColumnLayout {
+        id: column
+
+        Label {
+            id: labelAction
+
+            Layout.alignment: Qt.AlignHCenter
+            Layout.preferredWidth: column.width -
+                                   JamiTheme.preferredMarginSize * 2
+
+            color: JamiTheme.textColor
+            text: root.textLabel
+
+            font.pointSize: JamiTheme.textFontSize
+            font.kerning: true
+
+            horizontalAlignment: Text.AlignHCenter
+            verticalAlignment: Text.AlignVCenter
+            wrapMode: Text.Wrap
+        }
+
+        RowLayout {
+            spacing: 16
+            Layout.fillWidth: true
+            Layout.alignment: Qt.AlignCenter
+
+            MaterialButton {
+                id: primaryBtn
+
+                Layout.alignment: Qt.AlignHCenter
+                text: root.confirmLabel
+
+                preferredWidth: JamiTheme.preferredFieldWidth / 2 - 8
+                preferredHeight: JamiTheme.preferredFieldHeight
+
+                color: JamiTheme.buttonTintedRed
+                hoveredColor: JamiTheme.buttonTintedRedHovered
+                pressedColor: JamiTheme.buttonTintedRedPressed
+                outlined: true
+
+                onClicked: {
+                    close()
+                    accepted()
+                }
+            }
+
+            MaterialButton {
+                id: btnCancel
+
+                Layout.alignment: Qt.AlignHCenter
+
+                preferredWidth: JamiTheme.preferredFieldWidth / 2 - 8
+                preferredHeight: JamiTheme.preferredFieldHeight
+
+                color: JamiTheme.buttonTintedBlack
+                hoveredColor: JamiTheme.buttonTintedBlackHovered
+                pressedColor: JamiTheme.buttonTintedBlackPressed
+                outlined: true
+
+                text: JamiStrings.optionCancel
+
+                onClicked: close()
+            }
+        }
+    }
+}
diff --git a/src/app/constant/JamiStrings.qml b/src/app/constant/JamiStrings.qml
index 4415f275b..3cb0057e1 100644
--- a/src/app/constant/JamiStrings.qml
+++ b/src/app/constant/JamiStrings.qml
@@ -247,7 +247,10 @@ Item {
     property string startVideoCall: qsTr("Start video call")
     property string startAudioCall: qsTr("Start audio call")
     property string clearConversation: qsTr("Clear conversation")
+    property string confirmAction: qsTr("Confirm action")
     property string removeConversation: qsTr("Remove conversation")
+    property string confirmRmConversation: qsTr("Do you really want to remove this conversation")
+    property string confirmBlockConversation: qsTr("Do you really want to block this conversation")
     property string removeContact: qsTr("Remove contact")
     property string blockContact: qsTr("Block contact")
     property string blockSwarm: qsTr("Block swarm")
@@ -582,6 +585,7 @@ Item {
     property string optionUpgrade: qsTr("Upgrade")
     property string optionLater: qsTr("Later")
     property string optionDelete: qsTr("Delete")
+    property string optionBlock: qsTr("Block")
 
     // Conference moderation
     property string setModerator: qsTr("Set moderator")
diff --git a/src/app/mainview/components/ConversationSmartListContextMenu.qml b/src/app/mainview/components/ConversationSmartListContextMenu.qml
index e92bd4c6c..2e9173204 100644
--- a/src/app/mainview/components/ConversationSmartListContextMenu.qml
+++ b/src/app/mainview/components/ConversationSmartListContextMenu.qml
@@ -28,6 +28,29 @@ import "../../commoncomponents/contextmenu"
 ContextMenuAutoLoader {
     id: root
 
+    ConfirmDialog {
+        id: rmDialog
+
+        title: JamiStrings.confirmAction
+        textLabel: JamiStrings.confirmRmConversation
+        confirmLabel: JamiStrings.optionDelete
+        onAccepted: {
+            if (isSwarm)
+                MessagesAdapter.removeConversation(responsibleConvUid)
+            else
+                MessagesAdapter.removeContact(responsibleConvUid)
+        }
+    }
+
+    ConfirmDialog {
+        id: blockDialog
+
+        title: JamiStrings.confirmAction
+        textLabel: JamiStrings.confirmBlockConversation
+        confirmLabel: JamiStrings.optionBlock
+        onAccepted: MessagesAdapter.blockConversation(responsibleConvUid)
+    }
+
     property string responsibleAccountId: ""
     property string responsibleConvUid: ""
     property bool isBanned: false
@@ -89,12 +112,7 @@ ContextMenuAutoLoader {
                     return JamiStrings.removeContact
             }
             iconSource: JamiResources.ic_hangup_participant_24dp_svg
-            onClicked: {
-                if (isSwarm)
-                    MessagesAdapter.removeConversation(responsibleConvUid)
-                else
-                    MessagesAdapter.removeContact(responsibleConvUid)
-            }
+            onClicked: rmDialog.open()
         },
         GeneralMenuItem {
             id: hangup
@@ -131,7 +149,7 @@ ContextMenuAutoLoader {
             itemName: !(mode && mode !== Conversation.Mode.ONE_TO_ONE && mode !== Conversation.Mode.NON_SWARM) ? JamiStrings.blockContact : JamiStrings.blockSwarm
             iconSource: JamiResources.block_black_24dp_svg
             addMenuSeparatorAfter: contactType !== Profile.Type.SIP
-            onClicked: MessagesAdapter.blockConversation(responsibleConvUid)
+            onClicked: blockDialog.open()
         },
         GeneralMenuItem {
             id: unblockContact
-- 
GitLab