From 37352204b9c3a25064b3215825cd5a4cd6433798 Mon Sep 17 00:00:00 2001 From: Aleksandr Starun Date: Sat, 12 Jan 2019 14:55:57 +0300 Subject: [PATCH] #307 removed calling "QFileDialog" from QML --- ui/view/start.qml | 24 +++++------------------- ui/viewmodel/start_view.cpp | 9 +++++++++ ui/viewmodel/start_view.h | 1 + 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/ui/view/start.qml b/ui/view/start.qml index 1d5e4ac0e..dc4416abf 100644 --- a/ui/view/start.qml +++ b/ui/view/start.qml @@ -6,7 +6,6 @@ import QtGraphicalEffects 1.0 import "controls" import Beam.Wallet 1.0 import QtQuick.Layouts 1.3 -import QtQuick.Dialogs 1.0 Item { @@ -348,7 +347,11 @@ Item icon.source: "qrc:/assets/icon-folder.svg" onClicked: { // open fileOpenDialog - fileDialog.open(); + var path = viewModel.selectCustomWalletDB(); + + if (path.length > 0) { + buttons.migrateWalletDB(path); + } } } @@ -362,23 +365,6 @@ Item } } - FileDialog { - id: fileDialog - title: qsTr("Select the wallet database file") - folder: shortcuts.home - visible: false - nameFilters: [ "SQLite database file (*.db)" ] - onAccepted: { - var path = fileDialog.fileUrl.toString(); - // remove prefixed "file:///" - path = path.replace(/^(file:\/{3})/,""); - // unescape html codes like '%23' for '#' - buttons.migrateWalletDB(decodeURIComponent(path)); - } - onRejected: { - } - } - function backAction() { // remove wallet.db file viewModel.deleteCurrentWalletDB(); diff --git a/ui/viewmodel/start_view.cpp b/ui/viewmodel/start_view.cpp index 89611b7e1..fad67ffdd 100644 --- a/ui/viewmodel/start_view.cpp +++ b/ui/viewmodel/start_view.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #if defined(QT_PRINTSUPPORT_LIB) @@ -574,4 +575,12 @@ void StartViewModel::migrateWalletDB(const QString& path) void StartViewModel::copyToClipboard(const QString& text) { QApplication::clipboard()->setText(text); +} + +QString StartViewModel::selectCustomWalletDB() +{ + QString filePath = QFileDialog::getOpenFileName(nullptr, tr("Select the wallet database file"), + QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), tr("SQLite database file (*.db)")); + + return filePath; } \ No newline at end of file diff --git a/ui/viewmodel/start_view.h b/ui/viewmodel/start_view.h index c1e895775..1f29d484a 100644 --- a/ui/viewmodel/start_view.h +++ b/ui/viewmodel/start_view.h @@ -126,6 +126,7 @@ class StartViewModel : public QObject Q_INVOKABLE void deleteCurrentWalletDB(); Q_INVOKABLE void migrateWalletDB(const QString& path); Q_INVOKABLE void copyToClipboard(const QString& text); + Q_INVOKABLE QString selectCustomWalletDB(); signals: void walletExistsChanged();