Warning, /network/neochat/src/qml/UserInfo.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 import org.kde.kirigami as Kirigami
0008 import org.kde.kirigamiaddons.labs.components as KirigamiComponents
0009 import org.kde.kirigamiaddons.delegates as Delegates
0010 
0011 import org.kde.neochat
0012 import org.kde.neochat.config
0013 import org.kde.neochat.accounts
0014 
0015 RowLayout {
0016     id: root
0017 
0018     required property NeoChatConnection connection
0019 
0020     property bool bottomEdge: true
0021 
0022     property var addAccount
0023 
0024     spacing: Kirigami.Units.largeSpacing
0025 
0026     Layout.topMargin: Kirigami.Units.smallSpacing
0027     Layout.bottomMargin: Kirigami.Units.smallSpacing
0028     Layout.minimumHeight: bottomEdge ? Kirigami.Units.gridUnit * 2 : -1
0029 
0030     onVisibleChanged: {
0031         if (!visible) {
0032             accountsPopup.close();
0033             switchUserButton.checked = false;
0034         }
0035     }
0036 
0037     QQC2.AbstractButton {
0038         id: accountButton
0039 
0040         Layout.preferredWidth: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
0041         Layout.preferredHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
0042         Layout.leftMargin: Kirigami.Units.largeSpacing
0043 
0044         TapHandler {
0045             acceptedButtons: Qt.RightButton | Qt.LeftButton
0046             onTapped: (eventPoint, button) => {
0047                 // TODO Qt6 remove
0048                 if (!button) {
0049                     button = eventPoint.event.button;
0050                 }
0051                 if (button == Qt.RightButton) {
0052                     accountMenu.open();
0053                 } else {
0054                     pageStack.pushDialogLayer(Qt.resolvedUrl('qrc:/org/kde/neochat/qml/AccountEditorPage.qml'), {
0055                         connection: root.connection
0056                     }, {
0057                         title: i18n("Account editor")
0058                     });
0059                 }
0060             }
0061         }
0062 
0063         text: i18n("Edit this account")
0064 
0065         contentItem: KirigamiComponents.Avatar {
0066             readonly property string mediaId: root.connection.localUser.avatarMediaId
0067 
0068             source: mediaId ? ("image://mxc/" + mediaId) : ""
0069             name: root.connection.localUser.displayName ?? root.connection.localUser.id
0070         }
0071     }
0072 
0073     ColumnLayout {
0074         Layout.fillWidth: true
0075         spacing: 0
0076         QQC2.Label {
0077             id: displayNameLabel
0078             text: root.connection.localUser.displayName
0079             textFormat: Text.PlainText
0080             elide: Text.ElideRight
0081             Layout.fillWidth: true
0082         }
0083         QQC2.Label {
0084             text: (root.connection.label.length > 0 ? (root.connection.label + " ") : "") + root.connection.localUser.id
0085             font.pointSize: displayNameLabel.font.pointSize * 0.8
0086             opacity: 0.7
0087             textFormat: Text.PlainText
0088             elide: Text.ElideRight
0089             Layout.fillWidth: true
0090         }
0091     }
0092     QQC2.ToolButton {
0093         id: switchUserButton
0094         icon.name: "system-switch-user"
0095         checkable: true
0096         text: i18n("Switch User")
0097         display: QQC2.AbstractButton.IconOnly
0098         Accessible.name: text
0099         QQC2.ToolTip.text: text
0100         QQC2.ToolTip.visible: hovered
0101         QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0102         Layout.minimumWidth: Layout.preferredWidth
0103         Layout.alignment: Qt.AlignRight
0104         Shortcut {
0105             sequence: "Ctrl+U"
0106             onActivated: switchUserButton.toggle()
0107         }
0108     }
0109     QQC2.ToolButton {
0110         icon.name: "list-add"
0111         onClicked: ; //TODO
0112         text: i18n("Add") //TODO find better message
0113         display: QQC2.AbstractButton.IconOnly
0114         QQC2.ToolTip.text: text
0115         QQC2.ToolTip.visible: hovered
0116         QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0117         Layout.minimumWidth: Layout.preferredWidth
0118         Layout.alignment: Qt.AlignRight
0119         visible: false
0120     }
0121     QQC2.ToolButton {
0122         icon.name: "settings-configure"
0123         onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/SettingsPage.qml", {
0124             connection: root.connection
0125         }, {
0126             title: i18n("Configure")
0127         })
0128         text: i18n("Open Settings")
0129         display: QQC2.AbstractButton.IconOnly
0130         Layout.minimumWidth: Layout.preferredWidth
0131         Layout.alignment: Qt.AlignRight
0132         QQC2.ToolTip.text: text
0133         QQC2.ToolTip.visible: hovered
0134         QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0135     }
0136     Item {
0137         width: 1
0138     }
0139 
0140     AccountMenu {
0141         id: accountMenu
0142         y: root.bottomEdge ? -height : accountButton.height
0143         connection: root.connection
0144     }
0145     QQC2.Popup {
0146         id: accountsPopup
0147         parent: root
0148 
0149         visible: switchUserButton.checked
0150         onVisibleChanged: if (visible)
0151             accounts.forceActiveFocus()
0152 
0153         x: -Kirigami.Units.smallSpacing
0154         y: root.bottomEdge ? -height - Kirigami.Units.smallSpacing - 1 : root.height + Kirigami.Units.smallSpacing - 1
0155         width: root.width + (root.bottomEdge ? 0 : Kirigami.Units.smallSpacing * 2)
0156         leftPadding: 0
0157         rightPadding: 0
0158         bottomPadding: Kirigami.Units.smallSpacing
0159         topPadding: Kirigami.Units.smallSpacing
0160 
0161         closePolicy: QQC2.Popup.CloseOnEscape
0162 
0163         contentItem: ListView {
0164             id: accounts
0165             implicitHeight: contentHeight
0166 
0167             header: Kirigami.Separator {}
0168 
0169             footer: Delegates.RoundedItemDelegate {
0170                 id: addButton
0171                 width: parent.width
0172                 highlighted: focus || (addAccount.highlighted || addAccount.ListView.isCurrentItem) && !addAccount.pressed
0173                 Component.onCompleted: root.addAccount = this
0174                 icon {
0175                     name: "list-add"
0176                     width: Kirigami.Units.iconSizes.smallMedium
0177                     height: Kirigami.Units.iconSizes.smallMedium
0178                 }
0179                 text: i18n("Add Account")
0180                 contentItem: Delegates.SubtitleContentItem {
0181                     itemDelegate: parent
0182                     subtitle: i18n("Log in to an existing account")
0183                     labelItem.textFormat: Text.PlainText
0184                     subtitleItem.textFormat: Text.PlainText
0185                 }
0186 
0187                 onClicked: {
0188                     pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/WelcomePage.qml", {}, {
0189                         title: i18nc("@title:window", "Login")
0190                     });
0191                     if (switchUserButton.checked) {
0192                         switchUserButton.checked = false;
0193                     }
0194                     accounts.currentIndex = Controller.activeConnectionIndex;
0195                 }
0196                 Keys.onUpPressed: {
0197                     accounts.currentIndex = accounts.count - 1;
0198                     accounts.forceActiveFocus();
0199                 }
0200                 Keys.onDownPressed: {
0201                     accounts.currentIndex = 0;
0202                     accounts.forceActiveFocus();
0203                 }
0204             }
0205             clip: true
0206             model: AccountRegistry
0207 
0208             keyNavigationEnabled: false
0209             Keys.onDownPressed: {
0210                 if (accounts.currentIndex === accounts.count - 1) {
0211                     addAccount.forceActiveFocus();
0212                     accounts.currentIndex = -1;
0213                 } else {
0214                     accounts.incrementCurrentIndex();
0215                 }
0216             }
0217             Keys.onUpPressed: {
0218                 if (accounts.currentIndex === 0) {
0219                     addAccount.forceActiveFocus();
0220                     accounts.currentIndex = -1;
0221                 } else {
0222                     accounts.decrementCurrentIndex();
0223                 }
0224             }
0225 
0226             Keys.onReleased: if (event.key == Qt.Key_Escape) {
0227                 if (switchUserButton.checked) {
0228                     switchUserButton.checked = false;
0229                 }
0230             }
0231 
0232             onVisibleChanged: {
0233                 for (let i = 0; i < accounts.count; i++) {
0234                     if (model.data(model.index(i, 0), Qt.DisplayRole) === root.connection.localUser.id) {
0235                         accounts.currentIndex = i;
0236                         break;
0237                     }
0238                 }
0239             }
0240 
0241             delegate: Delegates.RoundedItemDelegate {
0242                 id: userDelegate
0243 
0244                 required property NeoChatConnection connection
0245 
0246                 width: parent.width
0247                 text: connection.localUser.displayName
0248 
0249                 contentItem: RowLayout {
0250                     KirigamiComponents.Avatar {
0251                         implicitWidth: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
0252                         implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
0253                         sourceSize {
0254                             width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
0255                             height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
0256                         }
0257                         source: userDelegate.connection.localUser.avatarMediaId ? ("image://mxc/" + userDelegate.connection.localUser.avatarMediaId) : ""
0258                         name: userDelegate.connection.localUser.displayName ?? userDelegate.connection.localUser.id
0259                     }
0260 
0261                     Delegates.SubtitleContentItem {
0262                         itemDelegate: userDelegate
0263                         subtitle: userDelegate.connection.localUser.id
0264                         labelItem.textFormat: Text.PlainText
0265                         subtitleItem.textFormat: Text.PlainText
0266                     }
0267                 }
0268 
0269                 onClicked: {
0270                     Controller.activeConnection = userDelegate.connection;
0271                     if (switchUserButton.checked) {
0272                         switchUserButton.checked = false;
0273                     }
0274                 }
0275             }
0276         }
0277 
0278         background: ColumnLayout {
0279             spacing: 0
0280             Kirigami.Separator {
0281                 Layout.fillWidth: true
0282                 visible: root.bottomEdge
0283             }
0284             Rectangle {
0285                 Layout.fillWidth: true
0286                 Layout.fillHeight: true
0287                 color: Kirigami.Theme.backgroundColor
0288             }
0289             Kirigami.Separator {
0290                 Layout.fillWidth: true
0291                 visible: !root.bottomEdge
0292             }
0293         }
0294     }
0295 }