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

0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 import QtQuick 2.15
0005 import org.kde.kirigami 2.19 as Kirigami
0006 import QtQuick.Controls 2.15 as QQC2
0007 import QtQuick.Layouts 1.15
0008 import QtQml.Models 2.15
0009 import org.kde.kmasto 1.0
0010 import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm
0011 
0012 MastoPage {
0013     objectName: 'authorizationPage'
0014     property var account
0015     title: i18n("Authorization")
0016 
0017     leftPadding: 0
0018     rightPadding: 0
0019 
0020     ColumnLayout {
0021         width: parent.width
0022         MobileForm.FormCard {
0023             Layout.topMargin: Kirigami.Units.largeSpacing
0024             Layout.fillWidth: true
0025             contentItem: ColumnLayout {
0026                 spacing: 0
0027 
0028                 MobileForm.FormCardHeader {
0029                     title: i18n("Authorize Tokodon to act on your behalf")
0030                 }
0031 
0032                 MobileForm.AbstractFormDelegate {
0033                     background: Item {}
0034                     Layout.fillWidth: true
0035 
0036                     contentItem: TextEdit {
0037                         color: Kirigami.Theme.textColor
0038                         textFormat: Text.RichText
0039                         readOnly: true
0040                         selectByMouse: true
0041                         text: i18n("To continue, please open the following link and authorize Tokodon: %1", "<br /><a href='" + account.authorizeUrl + "'>" + account.authorizeUrl + "</a>")
0042                         wrapMode: Text.Wrap
0043                         onLinkActivated: Qt.openUrlExternally(account.authorizeUrl)
0044                         Layout.fillWidth: true
0045                         TapHandler {
0046                             acceptedButtons: Qt.RightButton
0047                             cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
0048                             onTapped: if (parent.hoveredLink.length > 0) {
0049                                 menuLink.link = parent.hoveredLink;
0050                                 menuLink.popup();
0051                             }
0052                         }
0053                         QQC2.Menu {
0054                             id: menuLink
0055                             property string link
0056                             QQC2.MenuItem {
0057                                 text: i18n("Open Link")
0058                                 onTriggered: Qt.openUrlExternally(menuLink.link)
0059                             }
0060 
0061                             QQC2.MenuItem {
0062                                 text: i18n("Copy Link")
0063                                 onTriggered: {
0064                                     Clipboard.saveText(menuLink.link)
0065                                     applicationWindow().showPassiveNotification(i18n("Link copied."));
0066                                 } 
0067                             }
0068                         }
0069                     }
0070                 }
0071 
0072                 MobileForm.FormDelegateSeparator { above: openLink }
0073 
0074                 MobileForm.FormButtonDelegate {
0075                     id: openLink
0076                     text: i18n("Open Link")
0077                     onClicked: Qt.openUrlExternally(account.authorizeUrl)
0078                 }
0079 
0080                 MobileForm.FormDelegateSeparator { above: openLink; below: copyLink }
0081 
0082                 MobileForm.FormButtonDelegate {
0083                     id: copyLink
0084                     text: i18n("Copy Link")
0085                     onClicked: {
0086                         Clipboard.saveText(account.authorizeUrl)
0087                         applicationWindow().showPassiveNotification(i18n("Link copied."));
0088                     } 
0089                 }
0090             }
0091         }
0092 
0093         MobileForm.FormCard {
0094             Layout.topMargin: Kirigami.Units.largeSpacing
0095             Layout.fillWidth: true
0096             contentItem: ColumnLayout {
0097                 spacing: 0
0098 
0099                 MobileForm.FormTextFieldDelegate {
0100                     id: tokenField
0101                     label: i18n("Enter token:")
0102                     onAccepted: continueButton.clicked()
0103                 }
0104 
0105                 MobileForm.FormDelegateSeparator { below: continueButton; above: tokenField }
0106 
0107                 MobileForm.FormButtonDelegate {
0108                     id: continueButton
0109                     text: i18n("Continue")
0110                     onClicked: {
0111                         if (!tokenField.text) {
0112                             applicationWindow().showPassiveNotification(i18n("Please insert the generated token."));
0113                             return;
0114                         }
0115                         account.setToken(tokenField.text);
0116                         pageStack.layers.clear();
0117                         pageStack.replace(mainTimeline, {
0118                             name: "home"
0119                         });
0120                     }
0121                 }
0122             }
0123         }
0124     }
0125 }