// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL import QtQuick import QtQuick.Controls as QQC2 import QtQuick.Dialogs import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard import org.kde.kirigamiaddons.components as Components import koutnet.app // Everything about the person using the application, in one tab: the identity // block, the three fields under it, the status, and the pictures. It is a // component rather than a block of the settings page because it is also where // the window's own profile sheet comes from, and a page that is also a sheet is // the reason it is written once. // // It owns the pickers and the crop sheet as well: those have nothing to say to // any other tab, so leaving them in the page would make this file read as // belonging to the page rather than to the tab. // // An Item rather than a Page: the settings page above it draws the background // and holds the padding, and a page of its own would draw a second one over the // first and give the scroll view inside it a height of its own to argue about. Item { id: root // Handed in so the cards line up with the rest of the settings rather than // starting at the window edge. property real formWidth: Kirigami.Units.gridUnit * 30 readonly property bool matrixProfileActive: appSettings.connectionMode === 1 && matrixManager.loggedIn readonly property bool telegramProfileActive: appSettings.connectionMode === 2 readonly property bool telegramSignedIn: typeof telegramRooms !== "undefined" && telegramRooms.authState === 5 // Telegram profile data is TDLib's, not this screen's: the local card hides // rather than showing fields that answer nothing. readonly property bool profileEditable: !telegramProfileActive readonly property string telegramOwnDisplayName: telegramSignedIn ? (telegramRooms.ownDisplayName || "") : "" readonly property string telegramOwnHandle: telegramSignedIn ? (telegramRooms.ownUsername || "") : "" readonly property string telegramOwnAvatar: telegramSignedIn ? (telegramRooms.ownAvatarUrl || "") : "" readonly property string shownName: matrixProfileActive && matrixManager.displayName.length > 0 ? matrixManager.displayName : (telegramProfileActive && telegramOwnDisplayName.length > 0 ? telegramOwnDisplayName : (appSettings.displayName.length > 0 ? appSettings.displayName : appSettings.username)) // phone picture almost never matches the avatar's square or the banner's // strip, and the crop writes into the app's own directory. FileDialog { id: avatarDialog title: i18nc("@title:window", "Change avatar") nameFilters: [i18nc("@item:inlistbox file dialog filter, keep the glob patterns", "Images (*.png *.jpg *.jpeg *.webp *.gif)")] onAccepted: root.openCrop(selectedFile, false) } FileDialog { id: bannerDialog title: i18nc("@title:window", "Change banner") nameFilters: [i18nc("@item:inlistbox file dialog filter, keep the glob patterns", "Images (*.png *.jpg *.jpeg *.webp *.gif)")] onAccepted: root.openCrop(selectedFile, true) } // the dialog hands over a file:// URL (a QUrl or a ready-made string); the // crop sheet shows it as-is and ImageCrop::cropToFile unwraps the prefix, // so asking for the text form is all that is needed or safe. CropSheet { id: cropSheet onApplied: (outPath) => { if (cropSheet.wide) { if (root.telegramProfileActive) return // The banner is pushed into Matrix rooms when Matrix is the mode // in charge (LAN push is appSettings' own); the strip reads the setting. appSettings.bannerPath = outPath if (root.matrixProfileActive) matrixManager.setBanner(outPath) } else { if (root.matrixProfileActive) matrixManager.setAvatar(outPath) else appSettings.avatarPath = outPath } } } function openCrop(fileUrl, wide) { cropSheet.wide = wide cropSheet.sourcePath = String(fileUrl) cropSheet.open() } FileDialog { id: badgeDialog title: i18nc("@title:window", "Choose name badge") nameFilters: [i18nc("@item:inlistbox file dialog filter, keep the glob patterns", "Images (*.png *.jpg *.jpeg *.webp *.gif)")] onAccepted: appSettings.nameBadgePath = FsUtils.toLocalPath(selectedFile) } // the composer's panel, which is where the emoji data and the search already // are; a picker of its own here would be a second copy of both. EmojiPopup { id: statusSheet onPicked: (emoji) => appSettings.statusEmoji = emoji } QQC2.ScrollView { id: profileScroll anchors.fill: parent contentWidth: availableWidth ColumnLayout { // the form column and nothing else: a wider one would put the cards // in the middle of the window, which is the thing being got rid of. width: Math.min(profileScroll.availableWidth, root.formWidth + Kirigami.Units.gridUnit * 2) spacing: 0 ThemedFormHeader { maximumWidth: root.formWidth title: i18nc("@title:group your own identity as other people see it", "Profile") } // no presence line: being reachable is the process running. No edit mode // either - everything writes straight through; "type here" says it. ProfileHeader { Layout.fillWidth: true Layout.maximumWidth: root.formWidth Layout.alignment: Qt.AlignHCenter displayName: root.shownName handle: root.matrixProfileActive ? matrixManager.userId : (root.telegramProfileActive ? (root.telegramOwnHandle.length > 0 ? root.telegramOwnHandle : i18nc("@info Telegram account handle placeholder", "Telegram account")) : appSettings.username) avatarSource: root.matrixProfileActive ? matrixManager.avatarUrl : (root.telegramProfileActive ? (root.telegramOwnAvatar.length > 0 ? root.telegramOwnAvatar : "") : FsUtils.toSourceUrl(appSettings.avatarPath)) // The banner is not Matrix account data, so the strip shows the local // setting in every mode; the pick below pushes it into the rooms Matrix // holds. Telegram's profile is TDLib's business, not this screen's. bannerSource: root.telegramProfileActive ? "" : appSettings.bannerPath badgeSource: root.matrixProfileActive ? "" : appSettings.nameBadgePath showPresence: false editable: root.profileEditable onAvatarPickRequested: if (root.profileEditable) avatarDialog.open() onBannerPickRequested: if (!root.telegramProfileActive) bannerDialog.open() } ThemedFormCard { maximumWidth: root.formWidth visible: root.telegramProfileActive Layout.topMargin: Kirigami.Units.smallSpacing FormCard.FormTextDelegate { text: i18nc("@title", "Active profile") description: i18nc("@info", "Telegram mode is selected. Telegram profile data/editing in this screen is not available yet; use Telegram account/login settings.") } } // one card rather than two loose blocks above a card of three fields: the // loose ones each carried four numbers that only ever agreed by hand. ThemedFormCard { maximumWidth: root.formWidth visible: root.profileEditable // FormHeader supplies its own gap above every other card here; this one has // the identity block over it, and the page lays children out with no spacing. Layout.topMargin: Kirigami.Units.smallSpacing FormCard.FormTextFieldDelegate { id: usernameField label: i18nc("@label:textbox the handle peers see", "Username") text: root.matrixProfileActive ? matrixManager.userId : appSettings.username enabled: !root.matrixProfileActive && !root.telegramProfileActive readOnly: root.matrixProfileActive onEditingFinished: if (!root.matrixProfileActive && !root.telegramProfileActive) appSettings.username = text } FormCard.FormDelegateSeparator { above: usernameField; below: displayNameField } FormCard.FormTextFieldDelegate { id: displayNameField label: i18nc("@label:textbox", "Display name") description: root.matrixProfileActive ? i18nc("@info:whatsthis", "The name shown on your Matrix account.") : i18nc("@info:whatsthis", "The name shown to peers, as opposed to the handle above.") text: root.matrixProfileActive ? matrixManager.displayName : appSettings.displayName enabled: root.profileEditable onEditingFinished: { if (root.matrixProfileActive) matrixManager.setDisplayName(text) else if (!root.telegramProfileActive) appSettings.displayName = text } } FormCard.FormDelegateSeparator { above: displayNameField; below: statusDelegate; visible: !root.matrixProfileActive } // no form delegate exists for a row of three controls, so this is an // AbstractFormDelegate with the row inside, which keeps height and padding. FormCard.AbstractFormDelegate { id: statusDelegate visible: !root.matrixProfileActive background: null enabled: root.profileEditable contentItem: ColumnLayout { spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: i18nc("@label:textbox caption over what somebody says they are up to", "Custom status") } RowLayout { Layout.fillWidth: true spacing: Kirigami.Units.smallSpacing // an icon rather than a placeholder character: with nothing set // there is no emoji to show, and a face says what the slot is for. QQC2.ToolButton { display: appSettings.statusEmoji.length > 0 ? QQC2.AbstractButton.TextOnly : QQC2.AbstractButton.IconOnly icon.name: "face-smile" text: appSettings.statusEmoji enabled: root.profileEditable Accessible.name: i18nc("@action:button", "Set a status emoji") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: Accessible.name onClicked: if (root.profileEditable) statusSheet.open() } // Device-local for now: the presence packet carries the emoji and // repeats on a timer, so free text has no business in it. QQC2.TextField { Layout.fillWidth: true text: appSettings.statusText enabled: root.profileEditable placeholderText: i18nc("@info:placeholder", "What are you up to?") onEditingFinished: if (root.profileEditable) appSettings.statusText = text } QQC2.ToolButton { display: QQC2.AbstractButton.IconOnly icon.name: "edit-clear" enabled: root.profileEditable && (appSettings.statusEmoji.length > 0 || appSettings.statusText.length > 0) text: i18nc("@action:button remove the custom status emoji", "Clear status emoji") QQC2.ToolTip.visible: hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: text onClicked: { appSettings.statusEmoji = "" appSettings.statusText = "" } } } } } FormCard.FormDelegateSeparator { above: statusDelegate; below: bioDelegate; visible: !root.matrixProfileActive } FormCard.AbstractFormDelegate { id: bioDelegate visible: !root.matrixProfileActive background: null enabled: root.profileEditable contentItem: ColumnLayout { spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: i18nc("@title:group free-form text about yourself", "About me") } // Plain TextArea rather than Markdown behind an edit mode: this // is where things are typed, so the source is what is on screen. QQC2.TextArea { Layout.fillWidth: true Layout.minimumHeight: Math.round(Kirigami.Units.gridUnit * 3) wrapMode: TextEdit.Wrap text: appSettings.bio enabled: root.profileEditable placeholderText: i18nc("@info:placeholder", "Tell us about yourself...") onEditingFinished: if (root.profileEditable) appSettings.bio = text } } } FormCard.FormDelegateSeparator { above: bioDelegate; below: badgeButton; visible: !root.matrixProfileActive } FormCard.FormButtonDelegate { id: badgeButton visible: !root.matrixProfileActive text: i18nc("@action:button", "Choose name badge") icon.name: "insert-image" enabled: root.profileEditable onClicked: if (root.profileEditable) badgeDialog.open() } } // read-only, one line per transport so all four identities sit together. // missing ones show "-" instead of a blank row. ThemedFormHeader { maximumWidth: root.formWidth title: i18nc("@title:group the identities this account has on each backend", "Usernames") } ThemedFormCard { id: usernamesCard maximumWidth: root.formWidth readonly property string kNone: i18nc("@info:status no username on this backend", "-") FormCard.FormTextDelegate { text: i18nc("@label the local-network identity", "LAN / VPN") description: appSettings.username.length > 0 ? appSettings.username : usernamesCard.kNone } FormCard.FormDelegateSeparator {} FormCard.FormTextDelegate { text: i18nc("@title:backend", "Matrix") description: (matrixManager.loggedIn && matrixManager.userId.length > 0) ? matrixManager.userId : usernamesCard.kNone } FormCard.FormDelegateSeparator {} FormCard.FormTextDelegate { text: i18nc("@title:backend", "Telegram") description: { if (typeof telegramRooms === "undefined" || telegramRooms.authState !== 5) return usernamesCard.kNone const uname = telegramRooms.ownUsername || "" const dname = telegramRooms.ownDisplayName || "" if (uname.length > 0 && dname.length > 0 && dname !== uname) return dname + " (" + uname + ")" if (uname.length > 0) return uname if (dname.length > 0) return dname return i18nc("@info", "Signed in") } } FormCard.FormDelegateSeparator {} FormCard.FormTextDelegate { text: i18nc("@title:backend", "Rocket.Chat") description: usernamesCard.kNone } } } } }