From 00febee4c7975446bff4de41bef983cf1e97311c Mon Sep 17 00:00:00 2001
From: pmagnier-slimani <page.magnier-slimani@savoirfairelinux.com>
Date: Mon, 24 Feb 2025 11:59:01 -0500
Subject: [PATCH] UserProfile: add ID copy functionnality

Allow to copy UID from the user profile menu.
Make the alias always visible and assure we cannot copy it by mistake.
Allow to copy the username from the chatViewHeader.

Change-Id: I8ff257850286e8a1142c5bd2fbb26e29e8fe5060
---
 .../mainview/components/ChatViewHeader.qml    | 14 ++++
 src/app/mainview/components/UserProfile.qml   | 76 ++++++++++++++-----
 2 files changed, 72 insertions(+), 18 deletions(-)

diff --git a/src/app/mainview/components/ChatViewHeader.qml b/src/app/mainview/components/ChatViewHeader.qml
index 12b6c24c..60e8e3b9 100644
--- a/src/app/mainview/components/ChatViewHeader.qml
+++ b/src/app/mainview/components/ChatViewHeader.qml
@@ -116,6 +116,20 @@ Rectangle {
 
                 spacing: 0
 
+                LineEditContextMenu {
+                    id: displayNameContextMenu
+                    lineEditObj: title
+                    selectOnly: true
+                        }
+                MouseArea {
+                    anchors.fill: parent
+                    acceptedButtons: Qt.RightButton
+                    cursorShape: Qt.IBeamCursor
+                    onClicked: function (mouse) {
+                        displayNameContextMenu.openMenuAt(mouse);
+                    }
+                        }
+
                 ElidedTextLabel {
                     id: title
 
diff --git a/src/app/mainview/components/UserProfile.qml b/src/app/mainview/components/UserProfile.qml
index ac298364..22aa8898 100644
--- a/src/app/mainview/components/UserProfile.qml
+++ b/src/app/mainview/components/UserProfile.qml
@@ -38,7 +38,7 @@ BaseModalDialog {
         height: userProfileDialogLayout.height + 10
         radius: 5
 
-        Rectangle{
+        Rectangle {
             id: qrImageBackground
             radius: 5
             anchors.right: parent.right
@@ -90,8 +90,7 @@ BaseModalDialog {
                     spacing: 10
                     Layout.alignment: Qt.AlignLeft
 
-                    // Visible when user alias is not empty and not equal to id.
-                    TextEdit {
+                    Text {
                         id: contactAlias
 
                         Layout.alignment: Qt.AlignLeft
@@ -99,22 +98,19 @@ BaseModalDialog {
                         font.kerning: true
 
                         color: JamiTheme.textColor
-                        visible: aliasText ? (aliasText === idText ? false : true) : false
-
-                        selectByMouse: true
-                        readOnly: true
+                        visible: true
 
                         text: textMetricsContactAliasText.elidedText
                         horizontalAlignment: Text.AlignLeft
                         verticalAlignment: Text.AlignVCenter
+                    }
 
-                        TextMetrics {
-                            id: textMetricsContactAliasText
-                            font: contactAlias.font
-                            text: aliasText
-                            elideWidth: userProfileDialogLayout.width - qrImageBackground.width - 100
-                            elide: Qt.ElideRight
-                        }
+                    TextMetrics {
+                        id: textMetricsContactAliasText
+                        font: contactAlias.font
+                        text: aliasText
+                        elideWidth: userProfileDialogLayout.width - qrImageBackground.width - 100
+                        elide: Qt.ElideRight
                     }
 
                     // Visible when user name is not empty or equals to id.
@@ -135,6 +131,21 @@ BaseModalDialog {
                         horizontalAlignment: Text.AlignLeft
                         verticalAlignment: Text.AlignVCenter
 
+                        LineEditContextMenu {
+                            id: displayNameContextMenu
+                            lineEditObj: contactDisplayName
+                            selectOnly: true
+                        }
+
+                        MouseArea {
+                            anchors.fill: parent
+                            acceptedButtons: Qt.RightButton
+                            cursorShape: Qt.IBeamCursor
+                            onClicked: function (mouse) {
+                                displayNameContextMenu.openMenuAt(mouse);
+                            }
+                        }
+
                         TextMetrics {
                             id: textMetricsContactDisplayNameText
                             font: contactDisplayName.font
@@ -146,8 +157,6 @@ BaseModalDialog {
                 }
             }
 
-
-
             Rectangle {
                 id: idRectangle
 
@@ -181,7 +190,7 @@ BaseModalDialog {
                     TextEdit {
                         id: contactId
                         Layout.alignment: Qt.AlignLeft
-                        Layout.minimumWidth: 400 - identifierText.width - 2 * root.popupMargins - 35
+                        Layout.minimumWidth: 400 - identifierText.width - copyButton.width - 2 * root.popupMargins - 35
 
                         font.pointSize: JamiTheme.textFontSize
                         font.kerning: true
@@ -191,6 +200,21 @@ BaseModalDialog {
                         readOnly: true
                         text: textMetricsContacIdText.elidedText
 
+                        LineEditContextMenu {
+                            id: idContextMenu
+                            lineEditObj: contactId
+                            selectOnly: true
+                        }
+
+                        MouseArea {
+                            anchors.fill: parent
+                            acceptedButtons: Qt.RightButton
+                            cursorShape: Qt.IBeamCursor
+                            onClicked: function (mouse) {
+                                idContextMenu.openMenuAt(mouse);
+                            }
+                        }
+
                         TextMetrics {
                             id: textMetricsContacIdText
                             font: contactDisplayName.font
@@ -202,9 +226,25 @@ BaseModalDialog {
                         horizontalAlignment: Text.AlignLeft
                         verticalAlignment: Text.AlignVCenter
                     }
+
+                    PushButton {
+                        id: copyButton
+                        preferredHeight: 24
+                        preferredWidth: 24
+                        circled: false
+                        radius: 3
+
+                        toolTipText: JamiStrings.copy
+                        source: JamiResources.copy_svg
+
+                        onClicked: {
+                            contactId.selectAll();
+                            contactId.copy();
+                            contactId.deselect();
+                        }
+                    }
                 }
             }
         }
     }
 }
-
-- 
GitLab