]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Wizard: close wizard on wallet open via browse
authortobtoht <thotbot@protonmail.com>
Fri, 2 Jul 2021 20:47:10 +0000 (22:47 +0200)
committertobtoht <thotbot@protonmail.com>
Fri, 2 Jul 2021 20:47:10 +0000 (22:47 +0200)
src/wizard/PageOpenWallet.cpp
src/wizard/PageOpenWallet.h

index 4c0e18834738c73591caf20f56b53e3207b58aeb..ed9fa2a80336cfdb631269d34609caa695a93580 100644 (file)
@@ -17,34 +17,15 @@ PageOpenWallet::PageOpenWallet(WalletKeysFilesModel *wallets, QWidget *parent)
 {
     ui->setupUi(this);
 
-    connect(ui->btnBrowse, &QPushButton::clicked, [this]{
-        QString walletDir = config()->get(Config::walletDirectory).toString();
-        QString path = QFileDialog::getOpenFileName(this, "Select your wallet file", walletDir, "Wallet file (*.keys)");
-        if (path.isEmpty())
-            return;
-
-        QFileInfo infoPath(path);
-        if(!infoPath.isReadable()) {
-            QMessageBox::warning(this, "Cannot read wallet file", "Permission error.");
-            return;
-        }
-
-        if (ui->openOnStartup->isChecked())
-            config()->set(Config::autoOpenWalletPath, QString("%1%2").arg(constants::networkType).arg(path));
-
-        emit openWallet(path);
-    });
-
     this->setTitle("Open wallet file");
     this->setButtonText(QWizard::FinishButton, "Open wallet");
 
-    ui->walletTable->setSelectionBehavior(QAbstractItemView::SelectRows);
-    ui->walletTable->setContextMenuPolicy(Qt::CustomContextMenu);
-
     m_keysProxy = new WalletKeysFilesProxyModel(this, constants::networkType);
     m_keysProxy->setSourceModel(m_walletKeysFilesModel);
     m_keysProxy->setSortRole(Qt::UserRole);
 
+    ui->walletTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+    ui->walletTable->setContextMenuPolicy(Qt::CustomContextMenu);
     ui->walletTable->setModel(m_keysProxy);
     ui->walletTable->hideColumn(WalletKeysFilesModel::NetworkType);
     ui->walletTable->hideColumn(WalletKeysFilesModel::Path);
@@ -52,18 +33,21 @@ PageOpenWallet::PageOpenWallet(WalletKeysFilesModel *wallets, QWidget *parent)
     ui->walletTable->header()->setSectionResizeMode(WalletKeysFilesModel::FileName, QHeaderView::Stretch);
     ui->walletTable->setSortingEnabled(true);
     ui->walletTable->sortByColumn(WalletKeysFilesModel::Modified, Qt::DescendingOrder);
-    ui->walletTable->show();
 
     connect(ui->walletTable->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](QModelIndex current, QModelIndex prev){
         this->updatePath();
     });
-    connect(ui->walletTable, &QTreeView::doubleClicked, [this]{
-        // Simulate next button click
-        QWizard *wizard = this->wizard();
-        if (wizard) {
-            wizard->button(QWizard::FinishButton)->click();
-        }
+    connect(ui->walletTable, &QTreeView::doubleClicked, this, &PageOpenWallet::nextPage);
+
+    connect(ui->btnBrowse, &QPushButton::clicked, [this]{
+        QString walletDir = config()->get(Config::walletDirectory).toString();
+        m_walletFile = QFileDialog::getOpenFileName(this, "Select your wallet file", walletDir, "Wallet file (*.keys)");
+        if (m_walletFile.isEmpty())
+            return;
+        this->nextPage();
     });
+
+    this->updatePath();
 }
 
 void PageOpenWallet::initializePage() {
@@ -77,25 +61,38 @@ void PageOpenWallet::updatePath() {
         return;
     }
 
-    QString path = index.model()->data(index.siblingAtColumn(WalletKeysFilesModel::Path), Qt::DisplayRole).toString();
-    ui->linePath->setText(path);
+    m_walletFile = index.model()->data(index.siblingAtColumn(WalletKeysFilesModel::Path), Qt::DisplayRole).toString();
+    ui->linePath->setText(m_walletFile);
 }
 
 int PageOpenWallet::nextId() const {
     return -1;
 }
 
+void PageOpenWallet::nextPage() {
+    // Simulate next button click
+    QWizard *wizard = this->wizard();
+    if (wizard) {
+        wizard->button(QWizard::FinishButton)->click();
+    }
+}
+
 bool PageOpenWallet::validatePage() {
-    QModelIndex index = ui->walletTable->currentIndex();
-    if(!index.isValid()) {
-        QMessageBox::warning(this, "Wallet not selected", "Please select a wallet from the list.");
+    if (m_walletFile.isEmpty()) {
+        QMessageBox::warning(this, "No wallet file selected", "Please select a wallet from the list.");
+        return false;
+    }
+
+    QFileInfo infoPath(m_walletFile);
+    if (!infoPath.isReadable()) {
+        QMessageBox::warning(this, "Permission error", "Cannot read wallet file.");
         return false;
     }
-    QString walletPath = index.model()->data(index.siblingAtColumn(WalletKeysFilesModel::Column::Path), Qt::UserRole).toString();
 
-    auto autoWallet = ui->openOnStartup->isChecked() ? QString("%1%2").arg(constants::networkType).arg(walletPath) : "";
+    // Clear autoOpen if openOnStartup is not checked
+    auto autoWallet = ui->openOnStartup->isChecked() ? QString("%1%2").arg(constants::networkType).arg(m_walletFile) : "";
     config()->set(Config::autoOpenWalletPath, autoWallet);
 
-    emit openWallet(walletPath);
+    emit openWallet(m_walletFile);
     return true;
 }
index 1385203dd7f2a12cc0130852f44cb4272c1f2f44..b41e0e32053bcdbe17b2ca5a956966d647cfee7a 100644 (file)
@@ -28,6 +28,9 @@ public:
 signals:
     void openWallet(QString path);
 
+private slots:
+    void nextPage();
+
 private:
     void updatePath();
 
@@ -35,6 +38,7 @@ private:
     WalletKeysFilesModel *m_walletKeysFilesModel;
     WalletKeysFilesProxyModel *m_keysProxy;
     QStandardItemModel *m_model;
+    QString m_walletFile;
 };
 
 #endif //FEATHER_OPENWALLET_H