// 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.Layouts import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard import koutnet.app // The Telegram half of the protocols tab. Telegram issues an api id and hash at // my.telegram.org and TDLib will not start without them, so they are asked for // here rather than shipped in the source. Item { id: root property real formWidth: Kirigami.Units.gridUnit * 30 signal saved() // the login page asks for this, so the settings page can open it signal telegramAccountRequested() QQC2.ScrollView { id: telegramScroll anchors.fill: parent contentWidth: availableWidth ColumnLayout { width: Math.min(telegramScroll.availableWidth, root.formWidth + Kirigami.Units.gridUnit * 2) spacing: 0 ThemedFormHeader { maximumWidth: root.formWidth title: i18nc("@title:group the Telegram side of the connection", "Telegram (experimental)") } ThemedFormCard { maximumWidth: root.formWidth FormCard.FormTextDelegate { icon.name: "send-to" text: i18nc("@info:status what has to be entered for Telegram to work at all", "Application credentials") description: i18nc("@info:whatsthis", "Telegram issues an api id and an api hash to whoever asks for one at my.telegram.org under API development tools. TDLib will not connect without them. They belong to the application rather than to the account signing in, so the same pair serves every account here.") } FormCard.FormTextFieldDelegate { id: apiIdField label: i18nc("@label:textbox the application id issued by Telegram", "API id") placeholderText: i18nc("@info:placeholder a number from my.telegram.org", "1234567") text: appSettings.telegramApiId inputMethodHints: Qt.ImhDigitsOnly onEditingFinished: appSettings.telegramApiId = apiIdField.text.trim() } FormCard.FormTextFieldDelegate { id: apiHashField label: i18nc("@label:textbox the application hash issued by Telegram", "API hash") placeholderText: i18nc("@info:placeholder a hexadecimal string from my.telegram.org", "0123456789abcdef0123456789abcdef") text: appSettings.telegramApiHash // A hash is not a password, but it is a credential and it is // not something to read out over somebody's shoulder. echoMode: TextInput.PasswordEchoOnEdit onEditingFinished: appSettings.telegramApiHash = apiHashField.text.trim() } FormCard.FormDelegateSeparator { above: apiHashField; below: applyDelegate } FormCard.FormButtonDelegate { id: applyDelegate text: i18nc("@action:button save the application credentials and start the transport", "Save and connect") icon.name: "dialog-ok-apply" onClicked: { appSettings.telegramApiId = apiIdField.text.trim() appSettings.telegramApiHash = apiHashField.text.trim() appSettings.telegramProxyEnabled = proxyEnabledSwitch.checked appSettings.telegramProxyType = proxyTypeDelegate.currentIndex appSettings.telegramProxyServer = proxyServerField.text.trim() appSettings.telegramProxyPort = proxyPortField.value appSettings.telegramProxyUsername = proxyUsernameField.text appSettings.telegramProxyPassword = proxyPasswordField.text appSettings.telegramProxySecret = proxySecretField.text.trim() telegramRooms.start({ "api_id": appSettings.telegramApiId, "api_hash": appSettings.telegramApiHash, "proxy_enabled": appSettings.telegramProxyEnabled, "proxy_type": appSettings.telegramProxyType, "proxy_server": appSettings.telegramProxyServer, "proxy_port": appSettings.telegramProxyPort, "proxy_username": appSettings.telegramProxyUsername, "proxy_password": appSettings.telegramProxyPassword, "proxy_secret": appSettings.telegramProxySecret }) root.saved() root.telegramAccountRequested() } } } ThemedFormHeader { maximumWidth: root.formWidth title: i18nc("@title:group proxy settings for Telegram", "Proxy") } ThemedFormCard { maximumWidth: root.formWidth FormCard.FormSwitchDelegate { id: proxyEnabledSwitch text: i18nc("@option:check enable Telegram proxy", "Use proxy") description: i18nc("@info:whatsthis", "Route Telegram (TDLib) connections through a proxy. Supports HTTP, SOCKS5 and MTProto proxies.") checked: appSettings.telegramProxyEnabled onToggled: appSettings.telegramProxyEnabled = checked } FormCard.FormDelegateSeparator { above: proxyEnabledSwitch; below: proxyTypeDelegate } FormCard.FormComboBoxDelegate { id: proxyTypeDelegate text: i18nc("@label:listbox proxy type", "Proxy type") model: [ i18nc("@item:inlistbox", "HTTP"), i18nc("@item:inlistbox", "SOCKS5"), i18nc("@item:inlistbox", "MTProto") ] currentIndex: Math.max(0, Math.min(2, appSettings.telegramProxyType)) onActivated: appSettings.telegramProxyType = currentIndex } FormCard.FormDelegateSeparator { above: proxyTypeDelegate; below: proxyServerField } FormCard.FormTextFieldDelegate { id: proxyServerField label: i18nc("@label:textbox proxy server hostname or IP", "Server") placeholderText: i18nc("@info:placeholder proxy host", "proxy.example.com") text: appSettings.telegramProxyServer onEditingFinished: appSettings.telegramProxyServer = proxyServerField.text.trim() } FormCard.FormDelegateSeparator { above: proxyServerField; below: proxyPortField } FormCard.FormSpinBoxDelegate { id: proxyPortField label: i18nc("@label:spinbox proxy server port", "Port") from: 1 to: 65535 value: appSettings.telegramProxyPort onValueChanged: appSettings.telegramProxyPort = proxyPortField.value } FormCard.FormDelegateSeparator { above: proxyPortField; below: proxyUsernameField } FormCard.FormTextFieldDelegate { id: proxyUsernameField label: i18nc("@label:textbox proxy username", "Username") text: appSettings.telegramProxyUsername visible: proxyTypeDelegate.currentIndex !== 2 onEditingFinished: appSettings.telegramProxyUsername = proxyUsernameField.text } FormCard.FormDelegateSeparator { above: proxyUsernameField; below: proxyPasswordField; visible: proxyUsernameField.visible } FormCard.FormTextFieldDelegate { id: proxyPasswordField label: i18nc("@label:textbox proxy password", "Password") text: appSettings.telegramProxyPassword echoMode: TextInput.PasswordEchoOnEdit visible: proxyTypeDelegate.currentIndex !== 2 onEditingFinished: appSettings.telegramProxyPassword = proxyPasswordField.text } FormCard.FormDelegateSeparator { above: proxyPasswordField; below: proxySecretField; visible: proxySecretField.visible } FormCard.FormTextFieldDelegate { id: proxySecretField label: i18nc("@label:textbox MTProto proxy secret", "MTProto secret") placeholderText: i18nc("@info:placeholder", "ee...") text: appSettings.telegramProxySecret visible: proxyTypeDelegate.currentIndex === 2 onEditingFinished: appSettings.telegramProxySecret = proxySecretField.text.trim() } FormCard.FormDelegateSeparator { above: proxyTypeDelegate.currentIndex === 2 ? proxySecretField : proxyPasswordField below: applyProxyDelegate } FormCard.FormButtonDelegate { id: applyProxyDelegate text: i18nc("@action:button apply proxy settings to Telegram", "Apply proxy") icon.name: "network-connect" onClicked: { appSettings.telegramProxyEnabled = proxyEnabledSwitch.checked appSettings.telegramProxyType = proxyTypeDelegate.currentIndex appSettings.telegramProxyServer = proxyServerField.text.trim() appSettings.telegramProxyPort = proxyPortField.value appSettings.telegramProxyUsername = proxyUsernameField.text appSettings.telegramProxyPassword = proxyPasswordField.text appSettings.telegramProxySecret = proxySecretField.text.trim() telegramRooms.applyProxy( appSettings.telegramProxyEnabled, appSettings.telegramProxyType, appSettings.telegramProxyServer, appSettings.telegramProxyPort, appSettings.telegramProxyUsername, appSettings.telegramProxyPassword, appSettings.telegramProxySecret ) root.saved() } } } } } }