Warning, /network/tokodon/src/content/ui/LoginFlow/ServersPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls 2 as QQC2
0006 import QtQuick.Layouts
0007 import QtQml.Models
0008 
0009 import org.kde.kirigami 2 as Kirigami
0010 import org.kde.kirigamiaddons.formcard 1 as FormCard
0011 import org.kde.kirigamiaddons.components 1 as Components
0012 
0013 import org.kde.tokodon
0014 
0015 MastoPage {
0016     id: root
0017 
0018     title: i18nc("@title:window", "Pick a Server")
0019 
0020     property var account
0021 
0022     data: Connections {
0023         target: Controller
0024         function onNetworkErrorOccurred(error) {
0025             message.text = i18nc("@info:status Network status", "Failed to contact server: %1. Please check your proxy settings.", error)
0026             message.visible = true;
0027         }
0028     }
0029 
0030     header: Components.Banner {
0031         id: message
0032         type: Kirigami.MessageType.Error
0033         width: parent.width
0034 
0035         showCloseButton: true
0036 
0037         actions: Kirigami.Action {
0038             text: i18n("Proxy Settings")
0039             icon.name: "settings-configure"
0040             onTriggered: pageStack.pushDialogLayer(Qt.createComponent("org.kde.tokodon", "NetworkProxySettings"))
0041         }
0042     }
0043 
0044     function handleRegistration() {
0045         if (!account.registrationsOpen) {
0046             instanceUrl.status = Kirigami.MessageType.Error;
0047             instanceUrl.statusMessage = i18n("This server is closed for registration: %1", account.registrationMessage);
0048             return;
0049         }
0050 
0051         account.fetchedInstanceMetadata.disconnect(handleRegistration);
0052 
0053         Window.window.pageStack.layers.push(Qt.createComponent("org.kde.tokodon", "RulesPage"), {
0054             account: account,
0055         });
0056     }
0057 
0058     Component.onCompleted: instanceUrl.forceActiveFocus()
0059 
0060     FormCard.FormHeader {
0061         title: i18nc("@title:group", "Pick a Server")
0062     }
0063 
0064     FormCard.FormCard {
0065         FormCard.FormTextFieldDelegate {
0066             id: instanceUrl
0067             label: i18n("Server URL:")
0068             placeholderText: i18n("mastodon.social")
0069             onAccepted: continueButton.clicked()
0070             inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
0071         }
0072 
0073         FormCard.FormDelegateSeparator { above: continueButton }
0074 
0075         FormCard.FormButtonDelegate {
0076             id: continueButton
0077             text: i18n("Continue")
0078             onClicked: {
0079                 instanceUrl.statusMessage = "";
0080 
0081                 if (!instanceUrl.text) {
0082                     instanceUrl.status = Kirigami.MessageType.Error;
0083                     instanceUrl.statusMessage = i18n("Server URL must not be empty.");
0084                     return;
0085                 }
0086 
0087                 root.account = AccountManager.createNewAccount(instanceUrl.text, sslErrors.checked, false);
0088                 root.account.fetchedInstanceMetadata.connect(handleRegistration);
0089             }
0090         }
0091     }
0092 
0093     FormCard.FormHeader {
0094         title: i18nc("@title:group", "Network Settings")
0095     }
0096 
0097     FormCard.FormCard {
0098         FormCard.FormSwitchDelegate {
0099             id: sslErrors
0100             text: i18nc("@option:check Login page", "Ignore SSL errors")
0101         }
0102 
0103         FormCard.FormDelegateSeparator { above: proxySettingDelegate; below: sslErrors }
0104 
0105         FormCard.FormButtonDelegate {
0106             id: proxySettingDelegate
0107             text: i18n("Proxy Settings")
0108             onClicked: Window.window.pageStack.layers.push(Qt.createComponent("org.kde.tokodon", "NetworkProxyPage"))
0109         }
0110     }
0111 }