{
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);
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() {
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;
}