Skip to content

Commit

Permalink
#307 removed calling "QFileDialog" from QML
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr-Starun committed Jan 12, 2019
1 parent c282e62 commit 3735220
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
24 changes: 5 additions & 19 deletions ui/view/start.qml
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions ui/viewmodel/start_view.cpp
Expand Up @@ -18,6 +18,7 @@
#include <QStringBuilder>
#include <QApplication>
#include <QClipboard>
#include <QFileDialog>
#include <QVariant>
#include <QStandardPaths>
#if defined(QT_PRINTSUPPORT_LIB)
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions ui/viewmodel/start_view.h
Expand Up @@ -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();
Expand Down

0 comments on commit 3735220

Please sign in to comment.