mirror of
https://github.com/feather-wallet/feather.git
synced 2024-12-23 03:59:29 +00:00
Wizard: close wizard on wallet open via browse
This commit is contained in:
parent
c7558c2676
commit
f005e4643b
2 changed files with 37 additions and 36 deletions
|
@ -17,34 +17,15 @@ PageOpenWallet::PageOpenWallet(WalletKeysFilesModel *wallets, QWidget *parent)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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->setTitle("Open wallet file");
|
||||||
this->setButtonText(QWizard::FinishButton, "Open wallet");
|
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 = new WalletKeysFilesProxyModel(this, constants::networkType);
|
||||||
m_keysProxy->setSourceModel(m_walletKeysFilesModel);
|
m_keysProxy->setSourceModel(m_walletKeysFilesModel);
|
||||||
m_keysProxy->setSortRole(Qt::UserRole);
|
m_keysProxy->setSortRole(Qt::UserRole);
|
||||||
|
|
||||||
|
ui->walletTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
ui->walletTable->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
ui->walletTable->setModel(m_keysProxy);
|
ui->walletTable->setModel(m_keysProxy);
|
||||||
ui->walletTable->hideColumn(WalletKeysFilesModel::NetworkType);
|
ui->walletTable->hideColumn(WalletKeysFilesModel::NetworkType);
|
||||||
ui->walletTable->hideColumn(WalletKeysFilesModel::Path);
|
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->header()->setSectionResizeMode(WalletKeysFilesModel::FileName, QHeaderView::Stretch);
|
||||||
ui->walletTable->setSortingEnabled(true);
|
ui->walletTable->setSortingEnabled(true);
|
||||||
ui->walletTable->sortByColumn(WalletKeysFilesModel::Modified, Qt::DescendingOrder);
|
ui->walletTable->sortByColumn(WalletKeysFilesModel::Modified, Qt::DescendingOrder);
|
||||||
ui->walletTable->show();
|
|
||||||
|
|
||||||
connect(ui->walletTable->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](QModelIndex current, QModelIndex prev){
|
connect(ui->walletTable->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](QModelIndex current, QModelIndex prev){
|
||||||
this->updatePath();
|
this->updatePath();
|
||||||
});
|
});
|
||||||
connect(ui->walletTable, &QTreeView::doubleClicked, [this]{
|
connect(ui->walletTable, &QTreeView::doubleClicked, this, &PageOpenWallet::nextPage);
|
||||||
// Simulate next button click
|
|
||||||
QWizard *wizard = this->wizard();
|
connect(ui->btnBrowse, &QPushButton::clicked, [this]{
|
||||||
if (wizard) {
|
QString walletDir = config()->get(Config::walletDirectory).toString();
|
||||||
wizard->button(QWizard::FinishButton)->click();
|
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() {
|
void PageOpenWallet::initializePage() {
|
||||||
|
@ -77,25 +61,38 @@ void PageOpenWallet::updatePath() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path = index.model()->data(index.siblingAtColumn(WalletKeysFilesModel::Path), Qt::DisplayRole).toString();
|
m_walletFile = index.model()->data(index.siblingAtColumn(WalletKeysFilesModel::Path), Qt::DisplayRole).toString();
|
||||||
ui->linePath->setText(path);
|
ui->linePath->setText(m_walletFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PageOpenWallet::nextId() const {
|
int PageOpenWallet::nextId() const {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PageOpenWallet::nextPage() {
|
||||||
|
// Simulate next button click
|
||||||
|
QWizard *wizard = this->wizard();
|
||||||
|
if (wizard) {
|
||||||
|
wizard->button(QWizard::FinishButton)->click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool PageOpenWallet::validatePage() {
|
bool PageOpenWallet::validatePage() {
|
||||||
QModelIndex index = ui->walletTable->currentIndex();
|
if (m_walletFile.isEmpty()) {
|
||||||
if(!index.isValid()) {
|
QMessageBox::warning(this, "No wallet file selected", "Please select a wallet from the list.");
|
||||||
QMessageBox::warning(this, "Wallet not selected", "Please select a wallet from the list.");
|
|
||||||
return false;
|
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) : "";
|
QFileInfo infoPath(m_walletFile);
|
||||||
|
if (!infoPath.isReadable()) {
|
||||||
|
QMessageBox::warning(this, "Permission error", "Cannot read wallet file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
config()->set(Config::autoOpenWalletPath, autoWallet);
|
||||||
|
|
||||||
emit openWallet(walletPath);
|
emit openWallet(m_walletFile);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,9 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void openWallet(QString path);
|
void openWallet(QString path);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void nextPage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updatePath();
|
void updatePath();
|
||||||
|
|
||||||
|
@ -35,6 +38,7 @@ private:
|
||||||
WalletKeysFilesModel *m_walletKeysFilesModel;
|
WalletKeysFilesModel *m_walletKeysFilesModel;
|
||||||
WalletKeysFilesProxyModel *m_keysProxy;
|
WalletKeysFilesProxyModel *m_keysProxy;
|
||||||
QStandardItemModel *m_model;
|
QStandardItemModel *m_model;
|
||||||
|
QString m_walletFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FEATHER_OPENWALLET_H
|
#endif //FEATHER_OPENWALLET_H
|
||||||
|
|
Loading…
Reference in a new issue