From 6fe50d2c90e8df8ba7aa949e990a917f746a1b15 Mon Sep 17 00:00:00 2001 From: Quentin Rouland Date: Fri, 7 Feb 2025 13:38:09 +0100 Subject: [PATCH] Save last git clone settings (urls,types) --- CMakeLists.txt | 4 + .../git => components}/GitCloneHttp.qml | 7 + .../git => components}/GitCloneHttpAuth.qml | 7 + qml/pages/PasswordList.qml | 14 +- qml/pages/settings/DeleteRepo.qml | 3 + qml/pages/settings/ImportGitClone.qml | 149 ++++++++++++++++++ qml/pages/settings/Settings.qml | 4 +- .../settings/git/GitModeOptionSelector.qml | 38 ----- qml/pages/settings/git/ImportGitClone.qml | 93 ----------- qml/settings/GitSettings.qml | 7 + qml/settings/qmldir | 2 + 11 files changed, 187 insertions(+), 141 deletions(-) rename qml/{pages/settings/git => components}/GitCloneHttp.qml (84%) rename qml/{pages/settings/git => components}/GitCloneHttpAuth.qml (89%) create mode 100644 qml/pages/settings/ImportGitClone.qml delete mode 100644 qml/pages/settings/git/GitModeOptionSelector.qml delete mode 100644 qml/pages/settings/git/ImportGitClone.qml create mode 100644 qml/settings/GitSettings.qml create mode 100644 qml/settings/qmldir diff --git a/CMakeLists.txt b/CMakeLists.txt index dbf2338..9bda49b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,10 @@ endif() qt5_use_modules(${PROJECT_NAME} Gui Qml Quick QuickTest) +set_source_files_properties(qml/singletons/GitSettings.qml PROPERTIES + QT_QML_SINGLETON_TYPE TRUE +) + if(TESTS_RUNNER) qt5_use_modules(${PROJECT_NAME} QuickTest) endif() diff --git a/qml/pages/settings/git/GitCloneHttp.qml b/qml/components/GitCloneHttp.qml similarity index 84% rename from qml/pages/settings/git/GitCloneHttp.qml rename to qml/components/GitCloneHttp.qml index c22884e..3d3a42b 100644 --- a/qml/pages/settings/git/GitCloneHttp.qml +++ b/qml/components/GitCloneHttp.qml @@ -4,6 +4,12 @@ import Pass 1.0 import QtQuick 2.4 Column { + signal repoUrlChanged(string url) + + function setRepoUrl(url) { + repoUrlInput.text = url; + } + width: parent.width spacing: units.gu(1) @@ -24,6 +30,7 @@ Column { verticalAlignment: Text.AlignVCenter width: parent.width placeholderText: "http(s)://" + onContentWidthChanged: repoUrlChanged(repoUrlInput.text) } Rectangle { diff --git a/qml/pages/settings/git/GitCloneHttpAuth.qml b/qml/components/GitCloneHttpAuth.qml similarity index 89% rename from qml/pages/settings/git/GitCloneHttpAuth.qml rename to qml/components/GitCloneHttpAuth.qml index 8a52585..5503585 100644 --- a/qml/pages/settings/git/GitCloneHttpAuth.qml +++ b/qml/components/GitCloneHttpAuth.qml @@ -4,6 +4,12 @@ import Pass 1.0 import QtQuick 2.4 Column { + signal repoUrlChanged(string url) + + function setRepoUrl(url) { + repoUrlInput.text = url; + } + anchors.top: parent.fill spacing: units.gu(1) @@ -24,6 +30,7 @@ Column { verticalAlignment: Text.AlignVCenter width: parent.width placeholderText: "http(s)://@" + onContentWidthChanged: repoUrlChanged(repoUrlInput.text) } Text { diff --git a/qml/pages/PasswordList.qml b/qml/pages/PasswordList.qml index f39d15b..93a5eab 100644 --- a/qml/pages/PasswordList.qml +++ b/qml/pages/PasswordList.qml @@ -31,15 +31,15 @@ Page { for (var i = 0; i < ret.length; i++) { if (ret[i]) passwordListSearch.model.append({ - "fileName": ret[i] - }); + "fileName": ret[i] + }); } } anchors.fill: parent Component.onCompleted: { - __passwordStorePath = "file:" + Pass.password_store; + passwordListPage.__passwordStorePath = "file:" + Pass.password_store; Pass.onShowSucceed.connect(function(filename, text) { pageStack.push(Qt.resolvedUrl("../pages/Password.qml"), { "plainText": text, @@ -50,7 +50,7 @@ Page { PopupUtils.open(passwordPageDecryptError); }); Pass.onLsSucceed.connect(function(passwords) { - __passwords = passwords; + passwordListPage.__passwords = passwords; }); Pass.ls(); } @@ -113,8 +113,8 @@ Page { model: FolderListModel { nameFilters: ["*.gpg"] - rootFolder: __passwordStorePath - folder: __passwordStorePath + rootFolder: passwordListPage.__passwordStorePath + folder: passwordListPage.__passwordStorePath showDirs: true } @@ -156,7 +156,7 @@ Page { fName: fileName fIsDir: false onClicked: { - var path = __passwordStorePath + "/" + fileName; + var path = passwordListPage.__passwordStorePath + "/" + fileName; console.debug("pass show %1".arg(path)); Pass.show(path); } diff --git a/qml/pages/settings/DeleteRepo.qml b/qml/pages/settings/DeleteRepo.qml index aead819..aa23c75 100644 --- a/qml/pages/settings/DeleteRepo.qml +++ b/qml/pages/settings/DeleteRepo.qml @@ -1,5 +1,6 @@ import "../../components" import "../../dialogs" +import "../../settings" import "../headers" import Lomiri.Components 1.3 import Lomiri.Components.Popups 1.3 @@ -77,6 +78,8 @@ Page { SuccessDialog { textSuccess: i18n.tr("Password Store deleted !") onDialogClosed: { + GitSettings.type = 0; + GitSettings.repoUrl = null; pageStack.clear(); pageStack.push(Qt.resolvedUrl("../PasswordList.qml")); } diff --git a/qml/pages/settings/ImportGitClone.qml b/qml/pages/settings/ImportGitClone.qml new file mode 100644 index 0000000..b5e0f69 --- /dev/null +++ b/qml/pages/settings/ImportGitClone.qml @@ -0,0 +1,149 @@ +import "../../components" +import "../../dialogs" +import "../../settings" +import "../headers" +import Git 1.0 +import Lomiri.Components 1.3 +import Lomiri.Components.Pickers 1.3 +import Lomiri.Components.Popups 1.3 +import Pass 1.0 +import QtQuick 2.4 + +Page { + id: importGitClonePage + + property string __repoUrl + + function __loadForm() { + console.debug("yo"); + switch (combo.selectedIndex) { + case 0: + importGitCloneForm.source = Qt.resolvedUrl("../../components/GitCloneHttp.qml"); + break; + case 1: + importGitCloneForm.source = Qt.resolvedUrl("../../components/GitCloneHttpAuth.qml"); + break; + } + } + + Component.onCompleted: { + Git.cloneSucceed.connect(function() { + GitSettings.type = combo.selectedIndex; + GitSettings.repoUrl = importGitClonePage.__repoUrl; + PopupUtils.open(dialogGitCloneSuccess); + }); + Git.cloneFailed.connect(function() { + PopupUtils.open(dialogGitCloneError); + }); + if (GitSettings.repoUrl) + __repoUrl = GitSettings.repoUrl; + + if (GitSettings.type < combo.count && GitSettings.type > 0) + combo.selectedIndex = GitSettings.type; + else + combo.selectedIndex = 0; + __loadForm(); + PopupUtils.open(importGitCloneValidation, importGitClonePage); + } + + Column { + anchors.top: importGitCloneHeader.bottom + anchors.right: parent.right + anchors.left: parent.left + anchors.bottom: parent.bottom + anchors.leftMargin: units.gu(2) + anchors.rightMargin: units.gu(2) + spacing: units.gu(1) + + Rectangle { + width: parent.width + height: units.gu(1) + color: theme.palette.normal.background + } + + OptionSelector { + id: combo + + width: parent.width + model: ["HTTP", "HTTP AUTH"] + onDelegateClicked: function(i) { + timer.setTimeout(function() { + __loadForm(); + }, 500); + } + + Timer { + id: timer + + function setTimeout(cb, delayTime) { + timer.interval = delayTime; + timer.repeat = false; + timer.triggered.connect(cb); + timer.triggered.connect(function release() { + timer.triggered.disconnect(cb); // This is important + timer.triggered.disconnect(release); // This is important as well + }); + timer.start(); + } + + } + + } + + Loader { + id: importGitCloneForm + + width: parent.width + onLoaded: { + importGitCloneForm.item.repoUrlChanged.connect(function(url) { + importGitClonePage.__repoUrl = url; + }); + importGitCloneForm.item.setRepoUrl(importGitClonePage.__repoUrl); + } + } + + } + + Component { + id: importGitCloneValidation + + SimpleValidationDialog { + text: i18n.tr("Importing a git repo will delete
any existing password store!
Continue ?") + continueText: i18n.tr("Yes") + continueColor: theme.palette.normal.negative + onCanceled: { + pageStack.pop(); + } + } + + } + + Component { + id: dialogGitCloneError + + ErrorDialog { + textError: i18n.tr("An error occured during git clone !") + } + + } + + Component { + id: dialogGitCloneSuccess + + SuccessDialog { + textSuccess: i18n.tr("Password store sucessfully imported !") + onDialogClosed: { + pageStack.clear(); + pageStack.push(Qt.resolvedUrl("../PasswordList.qml")); + } + } + + } + + header: StackHeader { + id: importGitCloneHeader + + title: i18n.tr('Git Clone Import') + } + +} diff --git a/qml/pages/settings/Settings.qml b/qml/pages/settings/Settings.qml index 37d192b..020ef39 100644 --- a/qml/pages/settings/Settings.qml +++ b/qml/pages/settings/Settings.qml @@ -7,8 +7,6 @@ import QtQuick 2.4 Page { id: settingsPage - property string gpgKeyId: "" - Flow { anchors.top: settingsHeader.bottom anchors.bottom: parent.bottom @@ -44,7 +42,7 @@ Page { } PageStackLink { - page: Qt.resolvedUrl("git/ImportGitClone.qml") + page: Qt.resolvedUrl("ImportGitClone.qml") text: i18n.tr('Import a Password Store using Git') } diff --git a/qml/pages/settings/git/GitModeOptionSelector.qml b/qml/pages/settings/git/GitModeOptionSelector.qml deleted file mode 100644 index b7f9a97..0000000 --- a/qml/pages/settings/git/GitModeOptionSelector.qml +++ /dev/null @@ -1,38 +0,0 @@ -import Git 1.0 -import Lomiri.Components 1.3 -import Lomiri.Components.Pickers 1.3 -import QtQuick 2.4 - -OptionSelector { - id: combo - - width: parent.width - model: ["HTTP", "HTTP AUTH"] - onDelegateClicked: function(i) { - if (i === 0) - timer.setTimeout(function() { - importGitCloneForm.source = Qt.resolvedUrl("GitCloneHttp.qml"); - }, 500); - else if (i === 1) - timer.setTimeout(function() { - importGitCloneForm.source = Qt.resolvedUrl("GitCloneHttpAuth.qml"); - }, 500); - } - - Timer { - id: timer - - function setTimeout(cb, delayTime) { - timer.interval = delayTime; - timer.repeat = false; - timer.triggered.connect(cb); - timer.triggered.connect(function release() { - timer.triggered.disconnect(cb); // This is important - timer.triggered.disconnect(release); // This is important as well - }); - timer.start(); - } - - } - -} diff --git a/qml/pages/settings/git/ImportGitClone.qml b/qml/pages/settings/git/ImportGitClone.qml deleted file mode 100644 index b79e675..0000000 --- a/qml/pages/settings/git/ImportGitClone.qml +++ /dev/null @@ -1,93 +0,0 @@ -import "../../../components" -import "../../../dialogs" -import "../../headers" -import Git 1.0 -import Lomiri.Components 1.3 -import Lomiri.Components.Popups 1.3 -import Pass 1.0 -import QtQuick 2.4 - -Page { - id: importGitClonePage - - Component.onCompleted: { - Git.cloneSucceed.connect(function() { - PopupUtils.open(dialogGitCloneSuccess); - }); - Git.cloneFailed.connect(function() { - PopupUtils.open(dialogGitCloneError); - }); - PopupUtils.open(importGitCloneValidation, importGitClonePage); - importGitCloneForm.source = Qt.resolvedUrl("GitCloneHttp.qml"); - } - - Column { - anchors.top: importGitCloneHeader.bottom - anchors.right: parent.right - anchors.left: parent.left - anchors.bottom: parent.bottom - anchors.leftMargin: units.gu(2) - anchors.rightMargin: units.gu(2) - spacing: units.gu(1) - - Rectangle { - width: parent.width - height: units.gu(1) - color: theme.palette.normal.background - } - - GitModeOptionSelector { - id: combo - } - - Loader { - id: importGitCloneForm - - width: parent.width - } - - } - - Component { - id: importGitCloneValidation - - SimpleValidationDialog { - text: i18n.tr("Importing a git repo will delete
any existing password store!
Continue ?") - continueText: i18n.tr("Yes") - continueColor: theme.palette.normal.negative - onCanceled: { - pageStack.pop(); - } - } - - } - - Component { - id: dialogGitCloneError - - ErrorDialog { - textError: i18n.tr("An error occured during git clone !") - } - - } - - Component { - id: dialogGitCloneSuccess - - SuccessDialog { - textSuccess: i18n.tr("Password store sucessfully imported !") - onDialogClosed: { - pageStack.clear(); - pageStack.push(Qt.resolvedUrl("../../PasswordList.qml")); - } - } - - } - - header: StackHeader { - id: importGitCloneHeader - - title: i18n.tr('Git Clone Import') - } - -} diff --git a/qml/settings/GitSettings.qml b/qml/settings/GitSettings.qml new file mode 100644 index 0000000..f4bd366 --- /dev/null +++ b/qml/settings/GitSettings.qml @@ -0,0 +1,7 @@ +import Qt.labs.settings 1.0 +pragma Singleton + +Settings { + property int type: 0 + property string repoUrl: null +} diff --git a/qml/settings/qmldir b/qml/settings/qmldir new file mode 100644 index 0000000..64db4d9 --- /dev/null +++ b/qml/settings/qmldir @@ -0,0 +1,2 @@ +module settings +singleton GitSettings 1.0 GitSettings.qml