Warning, /network/tokodon/src/content/ui/UserInfo.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2022 Tobias Fella <fella@posteo.de> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Controls 2 as QQC2 0006 import QtQuick.Layouts 0007 import org.kde.kirigami 2 as Kirigami 0008 import org.kde.kirigamiaddons.delegates 1 as Delegates 0009 import org.kde.kirigamiaddons.labs.components 1 as KirigamiComponents 0010 0011 import org.kde.tokodon 0012 0013 QQC2.Pane { 0014 id: userInfo 0015 0016 property alias accountsListVisible: accounts.visible 0017 property var addAccount 0018 0019 visible: AccountManager.selectedAccount 0020 padding: 0 0021 0022 function openAccountPage() { 0023 const accountId = AccountManager.selectedAccountId; 0024 if (!pageStack.currentItem.model || !pageStack.currentItem.model.accountId || accountId !== pageStack.currentItem.accountId) { 0025 const item = pageStack.push(Qt.createComponent("org.kde.tokodon", "AccountInfo"), { 0026 accountId: accountId, 0027 }); 0028 } 0029 } 0030 0031 contentItem: ColumnLayout { 0032 id: content 0033 0034 spacing: 0 0035 0036 Delegates.RoundedItemDelegate { 0037 id: currentAccountDelegate 0038 0039 readonly property string name: { 0040 if (!AccountManager.selectedAccount) { 0041 return ''; 0042 } 0043 0044 if (AccountManager.selectedAccount.identity.displayNameHtml.length !== 0) { 0045 return AccountManager.selectedAccount.identity.displayNameHtml; 0046 } 0047 0048 return AccountManager.selectedAccount.username; 0049 } 0050 0051 text: name 0052 0053 onClicked: openAccountPage() 0054 Layout.fillWidth: true 0055 0056 contentItem: RowLayout { 0057 spacing: Kirigami.Units.smallSpacing 0058 0059 QQC2.AbstractButton { 0060 Layout.preferredHeight: Kirigami.Units.iconSizes.medium 0061 Layout.preferredWidth: Kirigami.Units.iconSizes.medium 0062 Layout.leftMargin: Kirigami.Units.smallSpacing 0063 Layout.rightMargin: Kirigami.Units.smallSpacing 0064 0065 contentItem: KirigamiComponents.Avatar { 0066 name: currentAccountDelegate.name 0067 source: AccountManager.selectedAccount ? AccountManager.selectedAccount.identity.avatarUrl : '' 0068 } 0069 0070 onClicked: openAccountPage() 0071 } 0072 0073 Delegates.SubtitleContentItem { 0074 subtitle: AccountManager.selectedAccount ? AccountManager.selectedAccount.instanceName : '' 0075 subtitleItem.textFormat: Text.PlainText 0076 itemDelegate: currentAccountDelegate 0077 Layout.fillWidth: true 0078 } 0079 0080 QQC2.ToolButton { 0081 icon.name: "system-switch-user" 0082 onClicked: { 0083 userInfo.accountsListVisible = !userInfo.accountsListVisible 0084 } 0085 text: i18n("Switch Account") 0086 display: QQC2.AbstractButton.IconOnly 0087 QQC2.ToolTip.text: text 0088 QQC2.ToolTip.visible: hovered 0089 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0090 Layout.minimumWidth: Layout.preferredWidth 0091 } 0092 } 0093 } 0094 0095 ListView { 0096 id: accounts 0097 0098 model: AccountManager 0099 currentIndex: AccountManager.selectedIndex 0100 0101 header: Kirigami.Separator { 0102 anchors { 0103 left: parent.left 0104 leftMargin: Kirigami.Units.smallSpacing 0105 0106 right: parent.right 0107 rightMargin: Kirigami.Units.smallSpacing 0108 } 0109 } 0110 0111 footer: Delegates.RoundedItemDelegate { 0112 id: addAccountDelegaze 0113 0114 width: parent.width 0115 highlighted: focus 0116 icon { 0117 name: "list-add" 0118 width: Kirigami.Units.iconSizes.medium 0119 height: Kirigami.Units.iconSizes.medium 0120 } 0121 text: i18n("Add Account") 0122 enabled: AccountManager.hasAccounts && applicationWindow().pageStack.depth > 0 && applicationWindow().pageStack.get(0).objectName !== 'loginPage' && applicationWindow().pageStack.get(0).objectName !== 'authorizationPage' && (applicationWindow().pageStack.layers.depth === 1 || applicationWindow().pageStack.layers.get(1).objectName !== 'loginPage' && applicationWindow().pageStack.layers.get(1).objectName !== 'authorizationPage') 0123 0124 contentItem: Delegates.SubtitleContentItem { 0125 itemDelegate: addAccountDelegaze 0126 subtitle: i18n("Log in to an existing account") 0127 } 0128 0129 onClicked: { 0130 pageStack.pushDialogLayer(Qt.createComponent("org.kde.tokodon", "WelcomePage")); 0131 userInfo.accountsListVisible = false 0132 accounts.currentIndex = AccountManager.selectedIndex 0133 } 0134 0135 Component.onCompleted: userInfo.addAccount = this 0136 Keys.onUpPressed: { 0137 accounts.currentIndex = accounts.count - 1 0138 accounts.forceActiveFocus() 0139 } 0140 Keys.onDownPressed: { 0141 accounts.currentIndex = 0 0142 accounts.forceActiveFocus() 0143 } 0144 } 0145 0146 visible: false 0147 onVisibleChanged: if (visible) focus = true 0148 clip: true 0149 0150 keyNavigationEnabled: false 0151 Keys.onDownPressed: { 0152 if (accounts.currentIndex === accounts.count - 1) { 0153 addAccount.forceActiveFocus() 0154 accounts.currentIndex = -1 0155 } else { 0156 accounts.incrementCurrentIndex() 0157 } 0158 } 0159 Keys.onUpPressed: { 0160 if (accounts.currentIndex === 0) { 0161 addAccount.forceActiveFocus() 0162 accounts.currentIndex = -1 0163 } else { 0164 accounts.decrementCurrentIndex() 0165 } 0166 } 0167 0168 Keys.onReleased: if (event.key == Qt.Key_Escape) { 0169 userInfo.accountsListVisible = false 0170 } 0171 0172 Layout.fillWidth: true 0173 Layout.preferredHeight: contentHeight 0174 Layout.topMargin: Kirigami.Units.smallSpacing 0175 0176 delegate: Delegates.RoundedItemDelegate { 0177 id: accountDelegate 0178 0179 required property int index 0180 required property string displayName 0181 required property string instance 0182 required property var account 0183 0184 text: displayName 0185 0186 contentItem: RowLayout { 0187 spacing: Kirigami.Units.smallSpacing 0188 0189 KirigamiComponents.Avatar { 0190 source: accountDelegate.account.identity.avatarUrl 0191 name: accountDelegate.displayName 0192 Layout.preferredHeight: Kirigami.Units.iconSizes.medium 0193 Layout.preferredWidth: Kirigami.Units.iconSizes.medium 0194 Layout.leftMargin: Kirigami.Units.smallSpacing 0195 Layout.rightMargin: Kirigami.Units.smallSpacing 0196 } 0197 0198 Delegates.SubtitleContentItem { 0199 itemDelegate: accountDelegate 0200 subtitleItem.textFormat: Text.PlainText 0201 subtitle: accountDelegate.instance 0202 Layout.fillWidth: true 0203 } 0204 } 0205 0206 onClicked: { 0207 if (AccountManager.selectedAccount !== accountDelegate.account) { 0208 AccountManager.selectedAccount = accountDelegate.account; 0209 accounts.currentIndex = accountDelegate.index; 0210 } 0211 userInfo.accountsListVisible = false 0212 } 0213 } 0214 } 0215 0216 } 0217 }