Warning, /office/klevernotes/src/contents/ui/dialogs/StorageDialog.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2022 Louis Schul <schul9louis@gmail.com>
0003 
0004 import QtQuick 2.15
0005 import QtQuick.Controls 2.15 as Controls
0006 import QtQuick.Layouts 1.3
0007 
0008 import org.kde.kirigami 2.19 as Kirigami
0009 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0010 
0011 import org.kde.Klever 1.0
0012 
0013 Kirigami.Dialog {
0014     id: setupPopup
0015 
0016     readonly property string newStorage: i18nc("Storage as in 'the folder where all the notes will be stored'; this text will be followed by the path to this folder", "Storage created at ")
0017     readonly property string existingStorage: i18nc("Storage as in 'the folder where all the notes will be stored'; this text will be followed by the path to this folder", "Existing storage chosen at ")
0018 
0019     property string folder
0020     property string userChoice
0021     property bool firstSetup: true
0022     property string subtitle: i18nc("@subtitle:dialog, Storage as in 'the folder where all the notes will be stored'", "It looks like this is your first time using this app!\n\nPlease choose a location for your future KleverNotes storage or select an existing one.")
0023 
0024     width: Kirigami.Units.gridUnit * 18
0025 
0026     closePolicy: Controls.Popup.NoAutoClose
0027     standardButtons: Kirigami.Dialog.NoButton
0028     showCloseButton: !firstSetup
0029 
0030     onFolderChanged: {
0031         setupStorage()
0032     }
0033 
0034     ColumnLayout{
0035         Controls.Label {
0036             text: subtitle
0037             wrapMode: Text.Wrap
0038 
0039             Layout.margins: Kirigami.Units.smallSpacing
0040             Layout.fillWidth: true
0041         }
0042 
0043         FormCard.FormButtonDelegate {
0044             icon.name: "folder-sync"
0045             text: i18nc("@label:button, Storage as in 'the folder where all the notes will be stored'", "Existing storage")
0046 
0047             Controls.ToolTip.text: i18nc("@label:button, Storage as in 'the folder where all the notes will be stored'", "Change the storage path")
0048             Controls.ToolTip.delay: Kirigami.Units.toolTipDelay
0049             Controls.ToolTip.visible: hovered
0050 
0051             Layout.fillWidth: true
0052 
0053             onClicked: {
0054                 setupPopup.userChoice = setupPopup.existingStorage
0055                 getFolder()
0056             }
0057         }
0058 
0059         FormCard.FormButtonDelegate {
0060             icon.name: "folder-new"
0061             text: i18nc("@label:button, Storage as in 'the folder where all the notes will be stored'", "Create storage")
0062 
0063             Controls.ToolTip.text: i18nc("Storage as in 'the folder where all the notes will be stored'", "Create a new storage")
0064             Controls.ToolTip.delay: Kirigami.Units.toolTipDelay
0065             Controls.ToolTip.visible: hovered
0066 
0067             Layout.fillWidth: true
0068 
0069             onClicked: {
0070                 setupPopup.userChoice = setupPopup.newStorage
0071                 getFolder()
0072             }
0073         }
0074     }
0075 
0076     function getFolder() {
0077         let component = Qt.createComponent("qrc:/contents/ui/dialogs/FolderPickerDialog.qml")
0078 
0079         if (component.status == Component.Ready) {
0080             var dialog = component.createObject(setupPopup);
0081             dialog.parent = setupPopup
0082             dialog.open()
0083         }
0084     }
0085 
0086     function setupStorage() {
0087         let folderPath = KleverUtility.getPath(setupPopup.folder)
0088         if (userChoice === setupPopup.newStorage){
0089             folderPath = folderPath.concat("/klevernotes")
0090         }
0091 
0092         var pathEnd = folderPath.substring(folderPath.length,folderPath.length-11)
0093 
0094         if (pathEnd.toLowerCase() !== "klevernotes"){
0095             subtitle = i18nc("@subtitle:dialog, Storage as in 'the folder where all the notes will be stored'", "It looks like the selected folder is not a KleverNotes storage.\n\nPlease choose a location for your future KleverNotes storage or select an existing one.")
0096             return
0097         }
0098         Config.storagePath = folderPath
0099 
0100         const fullNotification = setupPopup.userChoice+folderPath
0101 
0102         showPassiveNotification(fullNotification);
0103         setupPopup.close();
0104     }
0105 }