Warning, /multimedia/plasmatube/src/ui/settings/InvidiousSourcePage.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-3.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Window
0007 import QtQuick.Layouts
0008 
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.formcard as FormCard
0011 import org.kde.plasmatube
0012 
0013 FormCard.FormCardPage {
0014     id: page
0015 
0016     required property var source
0017 
0018     title: i18nc("@title:window", "Edit Source")
0019 
0020     FormCard.FormHeader {
0021         title: i18n("Account")
0022     }
0023 
0024     FormCard.FormCard {
0025         QQC2.Label {
0026             id: isLoggedInLabel
0027 
0028             visible: page.source.loggedIn
0029             Layout.fillWidth: true
0030             text: i18n("Currently logged in as %1.", page.source.username)
0031             wrapMode: Text.WordWrap
0032             horizontalAlignment: Text.AlignHCenter
0033             padding: Kirigami.Units.largeSpacing
0034         }
0035 
0036         FormCard.FormDelegateSeparator {
0037             above: isLoggedInLabel
0038         }
0039 
0040         Loader {
0041             id: preferencesLoader
0042 
0043             active: page.source.loggedIn && page.source.preferences
0044 
0045             Layout.fillWidth: true
0046 
0047             sourceComponent: ColumnLayout {
0048                 id: root
0049 
0050                 property var selectedSource
0051 
0052                 spacing: 0
0053 
0054                 FormCard.FormCheckDelegate {
0055                     text: i18n("Autoplay")
0056                     checked: root.selectedSource.preferences.autoPlay
0057                     onToggled: {
0058                         let preferences = root.selectedSource.preferences;
0059                         preferences.autoPlay = checked;
0060                         PlasmaTube.preferences = preferences;
0061                     }
0062                 }
0063 
0064                 FormCard.FormDelegateSeparator {}
0065 
0066                 FormCard.FormComboBoxDelegate {
0067                     id: defaultHomepageDelegate
0068                     Layout.fillWidth: true
0069                     text: i18n("Default homepage")
0070                     textRole: "display"
0071                     valueRole: "display"
0072                     // TODO: these need to be localized, but ListElement makes this difficult...
0073                     model: ListModel {
0074                         ListElement {
0075                             display: "Search"
0076                         }
0077                         ListElement {
0078                             display: "Trending"
0079                         }
0080                         ListElement {
0081                             display: "Subscriptions"
0082                         }
0083                         ListElement {
0084                             display: "Playlists"
0085                         }
0086                     }
0087                     function calculateIndex() {
0088                         let defaultHome = root.selectedSource.preferences.defaultHome;
0089                         switch (defaultHome) {
0090                             case "Search":
0091                                 currentIndex = 0;
0092                             case "Trending":
0093                                 currentIndex = 1;
0094                                 break;
0095                             case "Subscriptions":
0096                                 currentIndex = 2;
0097                                 break;
0098                             case "Playlists":
0099                                 currentIndex = 3;
0100                                 break;
0101                         }
0102                     }
0103 
0104                     onCurrentValueChanged: {
0105                         let preferences = root.selectedSource.preferences;
0106                         preferences.defaultHome = currentText;
0107                         PlasmaTube.preferences = preferences;
0108                     }
0109                 }
0110 
0111                 FormCard.FormDelegateSeparator {}
0112 
0113                 onSelectedSourceChanged: defaultHomepageDelegate.calculateIndex()
0114             }
0115 
0116             onLoaded: item.selectedSource = page.source
0117         }
0118 
0119         FormCard.FormButtonDelegate {
0120             visible: !page.source.loggedIn
0121             Layout.alignment: Qt.AlignHCenter
0122             text: i18n("Log in")
0123             onClicked: page.Window.window.pageStack.layers.push(Qt.createComponent("org.kde.plasmatube", "LoginPage"), {source: page.source});
0124         }
0125 
0126         FormCard.FormButtonDelegate {
0127             visible: page.source.loggedIn
0128             Layout.alignment: Qt.AlignHCenter
0129             text: i18n("Log out")
0130             onClicked: page.source.logOut();
0131         }
0132     }
0133 
0134     FormCard.FormCard {
0135         Layout.topMargin: Kirigami.Units.largeSpacing
0136         Layout.fillWidth: true
0137 
0138         FormCard.FormButtonDelegate {
0139             text: i18n("Remove Source")
0140             description: !enabled ? i18n("Cannot remove the only source.") : ""
0141             icon.name: "delete"
0142             enabled: PlasmaTube.sourceManager.canRemove()
0143 
0144             Kirigami.PromptDialog {
0145                 id: deletePrompt
0146 
0147                 title: i18nc("@title", "Remove Source")
0148                 subtitle: i18nc("@label", "Are you sure you want to remove this source?")
0149                 standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
0150                 showCloseButton: false
0151 
0152                 onAccepted: {
0153                     PlasmaTube.sourceManager.removeSource(page.source);
0154                     page.Window.window.pageStack.layers.pop();
0155                 }
0156             }
0157 
0158             onClicked: deletePrompt.open()
0159         }
0160     }
0161 }