From 68f8be01ac631a664095d710fcd2af9f4c16180c Mon Sep 17 00:00:00 2001 From: tobtoht Date: Fri, 18 Dec 2020 23:39:27 +0100 Subject: [PATCH 1/2] Wizard: don't show stagenet wallet in mainnet mode --- src/utils/keysfiles.cpp | 18 ++++++++++++------ src/utils/keysfiles.h | 11 +++++++---- src/wizard/openwallet.cpp | 3 ++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/utils/keysfiles.cpp b/src/utils/keysfiles.cpp index 39081bc..72171ac 100644 --- a/src/utils/keysfiles.cpp +++ b/src/utils/keysfiles.cpp @@ -19,7 +19,7 @@ using namespace std::chrono; -WalletKeysFiles::WalletKeysFiles(const QFileInfo &info, quint8 networkType, QString address) : +WalletKeysFiles::WalletKeysFiles(const QFileInfo &info, int networkType, QString address) : m_fileName(info.fileName()), m_modified(info.lastModified().toSecsSinceEpoch()), m_path(QDir::toNativeSeparators(info.absoluteFilePath())), @@ -42,7 +42,7 @@ QString WalletKeysFiles::path() const { return m_path; } -quint8 WalletKeysFiles::networkType() const { +int WalletKeysFiles::networkType() const { return m_networkType; } @@ -168,7 +168,7 @@ QVariant WalletKeysFilesModel::data(const QModelIndex &index, int role) const { } else if(role == Qt::UserRole) { switch(index.column()) { case ModelColumns::NetworkType: - return static_cast(walletKeyFile.networkType()); + return static_cast(walletKeyFile.networkType()); case ModelColumns::FileName: return walletKeyFile.fileName(); case ModelColumns::Modified: @@ -201,9 +201,15 @@ QVariant WalletKeysFilesModel::headerData(int section, Qt::Orientation orientati return QVariant(); } -WalletKeysFilesProxyModel::WalletKeysFilesProxyModel(QObject *parent) : - QSortFilterProxyModel(parent) {} +WalletKeysFilesProxyModel::WalletKeysFilesProxyModel(QObject *parent, NetworkType::Type nettype) + : QSortFilterProxyModel(parent) + , m_nettype(nettype) +{ +} bool WalletKeysFilesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - return true; + QModelIndex nettypeIndex = sourceModel()->index(sourceRow, WalletKeysFilesModel::NetworkType, sourceParent); + NetworkType::Type nettype = static_cast(sourceModel()->data(nettypeIndex, Qt::UserRole).toInt()); + + return (m_nettype == nettype); } \ No newline at end of file diff --git a/src/utils/keysfiles.h b/src/utils/keysfiles.h index 4ce9a30..5277ab9 100644 --- a/src/utils/keysfiles.h +++ b/src/utils/keysfiles.h @@ -12,19 +12,19 @@ class WalletKeysFiles { public: - WalletKeysFiles(const QFileInfo &info, quint8 networkType, QString address); + WalletKeysFiles(const QFileInfo &info, int networkType, QString address); QString fileName() const; qint64 modified() const; QString path() const; - quint8 networkType() const; + int networkType() const; QString address() const; private: QString m_fileName; qint64 m_modified; QString m_path; - quint8 m_networkType; + int m_networkType; QString m_address; }; @@ -64,8 +64,11 @@ class WalletKeysFilesProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - explicit WalletKeysFilesProxyModel(QObject *parent = nullptr); + explicit WalletKeysFilesProxyModel(QObject *parent, NetworkType::Type nettype); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; + +private: + NetworkType::Type m_nettype; }; #endif // KEYSFILES_H diff --git a/src/wizard/openwallet.cpp b/src/wizard/openwallet.cpp index 397d552..7092917 100644 --- a/src/wizard/openwallet.cpp +++ b/src/wizard/openwallet.cpp @@ -49,11 +49,12 @@ OpenWalletPage::OpenWalletPage(AppContext *ctx, QWidget *parent) : this->walletKeysFilesModel = new WalletKeysFilesModel(m_ctx); this->walletKeysFilesModel->refresh(); - m_keysProxy = new WalletKeysFilesProxyModel(); + m_keysProxy = new WalletKeysFilesProxyModel(this, m_ctx->networkType); m_keysProxy->setSourceModel(this->walletKeysFilesModel); m_keysProxy->setSortRole(Qt::UserRole); ui->walletTable->setModel(m_keysProxy); + ui->walletTable->hideColumn(WalletKeysFilesModel::NetworkType); ui->walletTable->header()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->walletTable->header()->setSectionResizeMode(WalletKeysFilesModel::Path, QHeaderView::Stretch); ui->walletTable->setSortingEnabled(true); From 4476741ace6b95dc0705dfe551d674f9bbb9c58a Mon Sep 17 00:00:00 2001 From: tobtoht Date: Sat, 19 Dec 2020 00:13:33 +0100 Subject: [PATCH 2/2] Wizard: Sort wallets by modified date --- src/utils/keysfiles.cpp | 4 +++- src/wizard/openwallet.cpp | 22 +++++++++++++++++++--- src/wizard/openwallet.h | 2 ++ src/wizard/openwallet.ui | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/utils/keysfiles.cpp b/src/utils/keysfiles.cpp index 72171ac..4d44372 100644 --- a/src/utils/keysfiles.cpp +++ b/src/utils/keysfiles.cpp @@ -133,7 +133,7 @@ int WalletKeysFilesModel::rowCount(const QModelIndex & parent) const { } int WalletKeysFilesModel::columnCount(const QModelIndex &) const { - return 3; + return 4; } QVariant WalletKeysFilesModel::data(const QModelIndex &index, int role) const { @@ -162,6 +162,8 @@ QVariant WalletKeysFilesModel::data(const QModelIndex &index, int role) const { #endif return fp; } + case ModelColumns::Modified: + return walletKeyFile.modified(); default: break; } diff --git a/src/wizard/openwallet.cpp b/src/wizard/openwallet.cpp index 7092917..6ecab7a 100644 --- a/src/wizard/openwallet.cpp +++ b/src/wizard/openwallet.cpp @@ -55,11 +55,27 @@ OpenWalletPage::OpenWalletPage(AppContext *ctx, QWidget *parent) : ui->walletTable->setModel(m_keysProxy); ui->walletTable->hideColumn(WalletKeysFilesModel::NetworkType); - ui->walletTable->header()->setSectionResizeMode(QHeaderView::ResizeToContents); - ui->walletTable->header()->setSectionResizeMode(WalletKeysFilesModel::Path, QHeaderView::Stretch); + ui->walletTable->hideColumn(WalletKeysFilesModel::Path); + ui->walletTable->hideColumn(WalletKeysFilesModel::Modified); + ui->walletTable->header()->setSectionResizeMode(WalletKeysFilesModel::FileName, QHeaderView::Stretch); ui->walletTable->setSortingEnabled(true); - ui->walletTable->sortByColumn(WalletKeysFilesModel::Modified, Qt::AscendingOrder); // @TODO: this does not work + ui->walletTable->sortByColumn(WalletKeysFilesModel::Modified, Qt::DescendingOrder); ui->walletTable->show(); + + connect(ui->walletTable->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](QModelIndex current, QModelIndex prev){ + this->updatePath(); + }); +} + +void OpenWalletPage::updatePath() { + QModelIndex index = ui->walletTable->currentIndex(); + if (!index.isValid()) { + ui->labelPath->clear(); + return; + } + + QString path = index.model()->data(index.siblingAtColumn(WalletKeysFilesModel::Path), Qt::DisplayRole).toString(); + ui->labelPath->setText(path); } int OpenWalletPage::nextId() const { diff --git a/src/wizard/openwallet.h b/src/wizard/openwallet.h index b9f1929..558dcf6 100644 --- a/src/wizard/openwallet.h +++ b/src/wizard/openwallet.h @@ -28,6 +28,8 @@ signals: void openWallet(QString path); private: + void updatePath(); + AppContext *m_ctx; WalletKeysFilesModel *walletKeysFilesModel; WalletKeysFilesProxyModel *m_keysProxy; diff --git a/src/wizard/openwallet.ui b/src/wizard/openwallet.ui index 1010470..c0e3429 100644 --- a/src/wizard/openwallet.ui +++ b/src/wizard/openwallet.ui @@ -55,6 +55,13 @@ + + + + path + + +