Merge pull request 'Wizard: autoselect open if wallets available & refresh wallets when wizard opened' (#253) from tobtoht/feather:wizard_open_refresh into master

Reviewed-on: https://git.wownero.com/feather/feather/pulls/253
This commit is contained in:
tobtoht 2020-12-23 03:00:31 +00:00
commit 7092116efd
7 changed files with 57 additions and 27 deletions

View file

@ -11,14 +11,23 @@
#include "libwalletqt/WalletManager.h" #include "libwalletqt/WalletManager.h"
MenuPage::MenuPage(AppContext *ctx, QWidget *parent) : MenuPage::MenuPage(AppContext *ctx, WalletKeysFilesModel *wallets, QWidget *parent)
QWizardPage(parent), : QWizardPage(parent)
ui(new Ui::MenuPage), , ui(new Ui::MenuPage)
m_ctx(ctx) { , m_ctx(ctx)
, m_walletKeysFilesModel(wallets)
{
ui->setupUi(this); ui->setupUi(this);
this->setButtonText(QWizard::FinishButton, "Open recent wallet"); this->setButtonText(QWizard::FinishButton, "Open recent wallet");
}
void MenuPage::initializePage() {
if (m_walletKeysFilesModel->rowCount() > 0) {
ui->radioOpen->setChecked(true);
} else {
ui->radioCreate->setChecked(true); ui->radioCreate->setChecked(true);
} }
}
int MenuPage::nextId() const { int MenuPage::nextId() const {
if (ui->radioOpen->isChecked()) if (ui->radioOpen->isChecked())

View file

@ -19,13 +19,14 @@ class MenuPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
explicit MenuPage(AppContext *ctx, QWidget *parent = nullptr); explicit MenuPage(AppContext *ctx, WalletKeysFilesModel *wallets, QWidget *parent = nullptr);
void initializePage() override;
bool validatePage() override; bool validatePage() override;
int nextId() const override; int nextId() const override;
private: private:
AppContext *m_ctx; AppContext *m_ctx;
QLabel *topLabel; WalletKeysFilesModel *m_walletKeysFilesModel;
Ui::MenuPage *ui; Ui::MenuPage *ui;
}; };

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>424</width> <width>617</width>
<height>245</height> <height>463</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -29,6 +29,9 @@
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioCreate"> <widget class="QRadioButton" name="radioCreate">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text"> <property name="text">
<string>Create new wallet</string> <string>Create new wallet</string>
</property> </property>
@ -36,6 +39,9 @@
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioOpen"> <widget class="QRadioButton" name="radioOpen">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text"> <property name="text">
<string>Open wallet file</string> <string>Open wallet file</string>
</property> </property>
@ -43,6 +49,9 @@
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioSeed"> <widget class="QRadioButton" name="radioSeed">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text"> <property name="text">
<string>Restore wallet from seed</string> <string>Restore wallet from seed</string>
</property> </property>
@ -50,6 +59,9 @@
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioViewOnly"> <widget class="QRadioButton" name="radioViewOnly">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text"> <property name="text">
<string>Import from keys</string> <string>Import from keys</string>
</property> </property>

View file

@ -10,12 +10,12 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
// @TODO: rescan wallet dir on wizard open OpenWalletPage::OpenWalletPage(AppContext *ctx, WalletKeysFilesModel *wallets, QWidget *parent)
: QWizardPage(parent)
OpenWalletPage::OpenWalletPage(AppContext *ctx, QWidget *parent) : , ui(new Ui::OpenWalletPage)
QWizardPage(parent), , m_ctx(ctx)
ui(new Ui::OpenWalletPage), , m_walletKeysFilesModel(wallets)
m_ctx(ctx) { {
ui->setupUi(this); ui->setupUi(this);
connect(ui->btnBrowse, &QPushButton::clicked, [=]{ connect(ui->btnBrowse, &QPushButton::clicked, [=]{
@ -46,11 +46,8 @@ OpenWalletPage::OpenWalletPage(AppContext *ctx, QWidget *parent) :
ui->walletTable->setSelectionBehavior(QAbstractItemView::SelectRows); ui->walletTable->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->walletTable->setContextMenuPolicy(Qt::CustomContextMenu); ui->walletTable->setContextMenuPolicy(Qt::CustomContextMenu);
this->walletKeysFilesModel = new WalletKeysFilesModel(m_ctx);
this->walletKeysFilesModel->refresh();
m_keysProxy = new WalletKeysFilesProxyModel(this, m_ctx->networkType); m_keysProxy = new WalletKeysFilesProxyModel(this, m_ctx->networkType);
m_keysProxy->setSourceModel(this->walletKeysFilesModel); m_keysProxy->setSourceModel(m_walletKeysFilesModel);
m_keysProxy->setSortRole(Qt::UserRole); m_keysProxy->setSortRole(Qt::UserRole);
ui->walletTable->setModel(m_keysProxy); ui->walletTable->setModel(m_keysProxy);
@ -67,6 +64,10 @@ OpenWalletPage::OpenWalletPage(AppContext *ctx, QWidget *parent) :
}); });
} }
void OpenWalletPage::initializePage() {
m_walletKeysFilesModel->refresh();
}
void OpenWalletPage::updatePath() { void OpenWalletPage::updatePath() {
QModelIndex index = ui->walletTable->currentIndex(); QModelIndex index = ui->walletTable->currentIndex();
if (!index.isValid()) { if (!index.isValid()) {

View file

@ -20,7 +20,8 @@ class OpenWalletPage : public QWizardPage
Q_OBJECT Q_OBJECT
public: public:
explicit OpenWalletPage(AppContext *ctx, QWidget *parent = nullptr); explicit OpenWalletPage(AppContext *ctx, WalletKeysFilesModel *wallets, QWidget *parent = nullptr);
void initializePage() override;
bool validatePage() override; bool validatePage() override;
int nextId() const override; int nextId() const override;
@ -31,10 +32,8 @@ private:
void updatePath(); void updatePath();
AppContext *m_ctx; AppContext *m_ctx;
WalletKeysFilesModel *walletKeysFilesModel; WalletKeysFilesModel *m_walletKeysFilesModel;
WalletKeysFilesProxyModel *m_keysProxy; WalletKeysFilesProxyModel *m_keysProxy;
QSortFilterProxyModel *ll;
QLabel *topLabel;
Ui::OpenWalletPage *ui; Ui::OpenWalletPage *ui;
QStandardItemModel *m_model; QStandardItemModel *m_model;
}; };

View file

@ -18,14 +18,20 @@
#include <QScreen> #include <QScreen>
#include <QApplication> #include <QApplication>
WalletWizard::WalletWizard(AppContext *ctx, WalletWizard::Page startPage, QWidget *parent) : QWizard(parent), WalletWizard::WalletWizard(AppContext *ctx, WalletWizard::Page startPage, QWidget *parent)
m_ctx(ctx) { : QWizard(parent)
, m_ctx(ctx)
{
this->setWindowTitle("Welcome to Feather Wallet"); this->setWindowTitle("Welcome to Feather Wallet");
this->setWindowIcon(QIcon(":/assets/images/appicons/64x64.png")); this->setWindowIcon(QIcon(":/assets/images/appicons/64x64.png"));
auto openWalletPage = new OpenWalletPage(m_ctx, this);
m_walletKeysFilesModel = new WalletKeysFilesModel(m_ctx, this);
m_walletKeysFilesModel->refresh();
auto openWalletPage = new OpenWalletPage(m_ctx, m_walletKeysFilesModel, this);
auto createWallet = new CreateWalletPage(m_ctx, this); auto createWallet = new CreateWalletPage(m_ctx, this);
auto createWalletSeed = new CreateWalletSeedPage(m_ctx, this); auto createWalletSeed = new CreateWalletSeedPage(m_ctx, this);
setPage(Page_Menu, new MenuPage(m_ctx, this)); setPage(Page_Menu, new MenuPage(m_ctx, m_walletKeysFilesModel, this));
setPage(Page_CreateWallet, createWallet); setPage(Page_CreateWallet, createWallet);
setPage(Page_OpenWallet, openWalletPage); setPage(Page_OpenWallet, openWalletPage);
setPage(Page_CreateWalletSeed, createWalletSeed); setPage(Page_CreateWalletSeed, createWalletSeed);

View file

@ -25,6 +25,8 @@ signals:
private: private:
AppContext *m_ctx; AppContext *m_ctx;
WalletKeysFilesModel *m_walletKeysFilesModel;
void createWallet(); void createWallet();
}; };