Warning, /plasma-mobile/plasma-dialer/plasma-dialer/src/qml/main.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2014 Aaron Seigo <aseigo@kde.org>
0002 // SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org>
0003 // SPDX-FileCopyrightText: 2021 Alexey Andreyev <aa13q@ya.ru>
0004 // SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 import QtQuick
0007 import QtQuick.Controls
0008 import QtQuick.Layouts
0009 import QtQuick.LocalStorage
0010 
0011 import org.kde.kirigami as Kirigami
0012 
0013 import org.kde.telephony
0014 
0015 import "call"
0016 
0017 Kirigami.ApplicationWindow {
0018     wideScreen: false
0019     id: root
0020     
0021     pageStack.globalToolBar.canContainHandles: true
0022     pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar
0023     pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.ShowBackButton;
0024     pageStack.popHiddenPages: true
0025 
0026     pageStack.columnView.columnResizeMode: Kirigami.ColumnView.SingleColumn
0027     
0028     // needs to work with 360x720 (+ panel heights)
0029     minimumWidth: 300
0030     minimumHeight: minimumWidth + 1
0031     width: Kirigami.Settings.isMobile ? 400 : 550
0032     height: Kirigami.Settings.isMobile ? 650 : 500
0033     visibility: lockscreenMode ? "FullScreen" : "Windowed"
0034 
0035     title: i18n("Phone")
0036 
0037     contextDrawer: Kirigami.ContextDrawer {}
0038 
0039     readonly property bool smallMode: applicationWindow().height < Kirigami.Units.gridUnit * 28
0040     property bool lockscreenMode: ScreenSaverUtils.getActive()
0041     
0042     function updateLockscreenMode(mode) {
0043         root.lockscreenMode = mode
0044     }
0045 
0046     Kirigami.PagePool { id: pagePool }
0047 
0048     function getPage(name) {
0049         switch (name) {
0050         case "History": return pagePool.loadPage("qrc:/HistoryPage.qml");
0051         case "Contacts": return pagePool.loadPage("qrc:/ContactsPage.qml");
0052         case "Dialer": return pagePool.loadPage("qrc:/DialerPage.qml");
0053         case "Call": return pagePool.loadPage("qrc:/call/CallPage.qml");
0054         case "Settings": return pagePool.loadPage("qrc:/settings/SettingsPage.qml");
0055         case "CallBlockSettings": return pagePool.loadPage("qrc:/settings/CallBlockSettingsPage.qml");
0056         case "About": return pagePool.loadPage("qrc:/AboutPage.qml");
0057         }
0058     }
0059 
0060     property bool isWidescreen: root.width >= root.height
0061     onIsWidescreenChanged: changeNav(isWidescreen);
0062 
0063     function switchToPage(page, depth) {
0064         if (!page) {
0065             return
0066         }
0067 
0068         while (pageStack.depth > depth) pageStack.pop()
0069             
0070         // page switch animation
0071         yAnim.target = page;
0072         yAnim.properties = "yTranslate";
0073         anim.target = page;
0074         anim.properties = "contentItem.opacity";
0075         if (page.header) {
0076             anim.properties += ",header.opacity";
0077         }
0078         yAnim.restart();
0079         anim.restart();
0080             
0081         pageStack.push(page)
0082         page.forceActiveFocus()
0083     }
0084 
0085     // switch between bottom toolbar and sidebar
0086     function changeNav(toWidescreen) {
0087         if (toWidescreen) {
0088             if (footer != null) {
0089                 footer.destroy();
0090                 footer = null;
0091             }
0092             sidebarLoader.active = true;
0093             globalDrawer = sidebarLoader.item;
0094         } else {
0095             sidebarLoader.active = false;
0096             globalDrawer = null;
0097 
0098             let bottomToolbar = Qt.createComponent("qrc:/components/BottomToolbar.qml")
0099             footer = bottomToolbar.createObject(root);
0100         }
0101     }
0102 
0103     function selectModem() {
0104         const deviceUniList = DeviceUtils.deviceUniList
0105         if (deviceUniList.length === 0) {
0106             console.warn("Modem devices not found")
0107             return ""
0108         }
0109 
0110         if (deviceUniList.length === 1) {
0111             return deviceUniList[0]
0112         }
0113         console.log("TODO: select device uni")
0114     }
0115 
0116     function call(number) {
0117         getPage("Dialer").pad.number = number
0118         switchToPage(getPage("Dialer"), 0)
0119     }
0120 
0121     signal ussdUserInitiated()
0122 
0123     Component.onCompleted: {
0124         // initial page and nav type
0125         switchToPage(getPage("Dialer"), 1);
0126         changeNav(isWidescreen);
0127     }
0128     
0129     // page switch animation
0130     NumberAnimation {
0131         id: anim
0132         from: 0
0133         to: 1
0134         duration: Kirigami.Units.longDuration * 2
0135         easing.type: Easing.InOutQuad
0136     }
0137     NumberAnimation {
0138         id: yAnim
0139         from: Kirigami.Units.gridUnit * 3
0140         to: 0
0141         duration: Kirigami.Units.longDuration * 3
0142         easing.type: Easing.OutQuint
0143     }
0144 
0145     Loader {
0146         id: sidebarLoader
0147         source: "qrc:/components/Sidebar.qml"
0148         active: false
0149     }
0150 
0151     USSDSheet {
0152         id: ussdSheet
0153         onResponseReady: {
0154             const deviceUni = applicationWindow().selectModem()
0155             UssdUtils.respond(deviceUni,response)
0156         }
0157         onCancelSessionRequested: {
0158             const deviceUni = applicationWindow().selectModem()
0159             UssdUtils.cancel(deviceUni)
0160         }
0161     }
0162 
0163     ImeiSheet {
0164         id: imeiSheet
0165         function show() {
0166             imeiSheet.imeis = DeviceUtils.equipmentIdentifiers()
0167             imeiSheet.open()
0168         }
0169     }
0170 
0171     Connections {
0172         target: CallUtils
0173 
0174         function onCallStateChanged(callData) {
0175             if (callData.state === DialerTypes.CallState.Active) {
0176                 getPage("Dialer").pad.clear()
0177             }
0178             // TODO: also activate on Dialing state
0179         }
0180     }
0181 
0182     Connections {
0183         target: UssdUtils
0184 
0185         function onNotificationReceived(deviceUni, message) {
0186             ussdSheet.showNotification(message)
0187         }
0188 
0189         function onStateChanged(deviceUni, state) {
0190             ussdSheet.changeState(state)
0191         }
0192 
0193         function onErrorReceived(deviceUni, error) {
0194             ussdSheet.showError(error)
0195         }
0196 
0197         function onInitiated(deviceUni, command) {
0198             ussdSheet.open()
0199         }
0200     }
0201 
0202     onUssdUserInitiated: {
0203         ussdSheet.open() // open it already since async interaction is not immediate
0204     }
0205 }