Warning, /plasma/plasma-mobile/initialstart/modules/cellular/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.kirigamiaddons.formcard 1 as FormCard
0010 import org.kde.plasma.mm as PlasmaMM
0011 
0012 Item {
0013     id: root
0014     property string name: i18n("Cellular")
0015 
0016     readonly property real cardWidth: Math.min(Kirigami.Units.gridUnit * 30, root.width - Kirigami.Units.gridUnit * 2)
0017 
0018     function toggleMobileData() {
0019         if (PlasmaMM.SignalIndicator.needsAPNAdded || !PlasmaMM.SignalIndicator.mobileDataSupported) {
0020             // open settings if unable to toggle mobile data
0021             MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_cellular_network");
0022         } else {
0023             PlasmaMM.SignalIndicator.mobileDataEnabled = !PlasmaMM.SignalIndicator.mobileDataEnabled;
0024         }
0025     }
0026 
0027     EditProfileDialog {
0028         id: profileDialog
0029         profile: null
0030     }
0031 
0032     ColumnLayout {
0033         anchors {
0034             fill: parent
0035             topMargin: Kirigami.Units.gridUnit
0036             bottomMargin: Kirigami.Units.largeSpacing
0037         }
0038         width: root.width
0039         spacing: Kirigami.Units.gridUnit
0040 
0041         Label {
0042             Layout.leftMargin: Kirigami.Units.gridUnit
0043             Layout.rightMargin: Kirigami.Units.gridUnit
0044             Layout.alignment: Qt.AlignTop
0045             Layout.fillWidth: true
0046 
0047             wrapMode: Text.Wrap
0048             horizontalAlignment: Text.AlignHCenter
0049             text: {
0050                 if (!PlasmaMM.SignalIndicator.modemAvailable) {
0051                     return i18n("Your device does not have a modem available.");
0052                 } else if (PlasmaMM.SignalIndicator.needsAPNAdded) {
0053                     return i18n("Please configure your APN below for mobile data, further information will be available with your carrier.");
0054                 } else if (PlasmaMM.SignalIndicator.mobileDataSupported) {
0055                     return i18n("You are connected to the mobile network.");
0056                 } else if (PlasmaMM.SignalIndicator.simEmpty) {
0057                     return i18n("Please insert a SIM card into your device.");
0058                 } else {
0059                     return i18n("Your device does not have a modem available.");
0060                 }
0061             }
0062         }
0063 
0064         FormCard.FormCard {
0065             visible: PlasmaMM.SignalIndicator.modemAvailable && PlasmaMM.SignalIndicator.mobileDataSupported
0066             maximumWidth: root.cardWidth
0067 
0068             Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
0069 
0070             FormCard.FormSwitchDelegate {
0071                 text: i18n("Mobile Data")
0072                 checked: PlasmaMM.SignalIndicator.mobileDataEnabled
0073                 onCheckedChanged: {
0074                     if (checked !== PlasmaMM.SignalIndicator.mobileDataEnabled) {
0075                         root.toggleMobileData();
0076                     }
0077                 }
0078             }
0079         }
0080 
0081         FormCard.FormCard {
0082             visible: PlasmaMM.SignalIndicator.modemAvailable && !PlasmaMM.SignalIndicator.simEmpty
0083             maximumWidth: root.cardWidth
0084 
0085             Layout.fillHeight: true
0086             Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
0087 
0088             ListView {
0089                 id: listView
0090                 currentIndex: -1
0091                 clip: true
0092 
0093                 Layout.fillWidth: true
0094                 Layout.fillHeight: true
0095 
0096                 model: PlasmaMM.SignalIndicator.profiles
0097 
0098                 delegate: FormCard.FormRadioDelegate {
0099                     width: listView.width
0100                     text: modelData.name
0101                     description: modelData.apn
0102                     checked: modem.activeConnectionUni == modelData.connectionUni
0103 
0104                     onCheckedChanged: {
0105                         if (checked) {
0106                             PlasmaMM.SignalIndicator.activateProfile(modelData.connectionUni);
0107                             checked = Qt.binding(() => { return modem.activeConnectionUni == modelData.connectionUni });
0108                         }
0109                     }
0110 
0111                     trailing: RowLayout {
0112                         ToolButton {
0113                             icon.name: "entry-edit"
0114                             text: i18n("Edit")
0115                             onClicked: {
0116                                 profileDialog.profile = modelData;
0117                                 profileDialog.open();
0118                             }
0119                         }
0120                         ToolButton {
0121                             icon.name: "delete"
0122                             text: i18n("Delete")
0123                             onClicked: PlasmaMM.SignalIndicator.removeProfile(modelData.connectionUni)
0124                         }
0125                     }
0126                 }
0127             }
0128 
0129             FormCard.FormButtonDelegate {
0130                 icon.name: "list-add"
0131                 text: i18n("Add APN")
0132                 onClicked: {
0133                     profileDialog.profile = null;
0134                     profileDialog.open();
0135                 }
0136             }
0137         }
0138     }
0139 }