Merge pull request 'Settings: allow changing default wallet directory' (#261) from tobtoht/feather:wizard_reset_restore_page into master

Reviewed-on: https://git.wownero.com/feather/feather/pulls/261
This commit is contained in:
tobtoht 2020-12-25 21:37:26 +00:00
commit d8625fdb29
13 changed files with 135 additions and 32 deletions

View file

@ -80,6 +80,8 @@ AppContext::AppContext(QCommandLineParser *cmdargs) {
this->accountName = Utils::getUnixAccountName();
this->homeDir = QDir::homePath();
QString walletDir = config()->get(Config::walletDirectory).toString();
if (walletDir.isEmpty()) {
#if defined(Q_OS_LINUX) or defined(Q_OS_MAC)
this->defaultWalletDir = QString("%1/Monero/wallets").arg(this->configRoot);
this->defaultWalletDirRoot = QString("%1/Monero").arg(this->configRoot);
@ -87,6 +89,10 @@ AppContext::AppContext(QCommandLineParser *cmdargs) {
this->defaultWalletDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Monero";
this->defaultWalletDirRoot = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
} else {
this->defaultWalletDir = walletDir;
this->defaultWalletDirRoot = walletDir;
}
// Create wallet dirs
if (!QDir().mkpath(defaultWalletDir))

View file

@ -522,6 +522,7 @@ void MainWindow::initWidgets() {
WalletWizard *MainWindow::createWizard(WalletWizard::Page startPage){
auto *wizard = new WalletWizard(m_ctx, startPage, this);
connect(wizard, &WalletWizard::openWallet, m_ctx, &AppContext::onOpenWallet);
connect(wizard, &WalletWizard::defaultWalletDirChanged, m_windowSettings, &Settings::updatePaths);
return wizard;
}

View file

@ -177,7 +177,6 @@ private:
Ui::MainWindow *ui;
Settings *m_windowSettings = nullptr;
CalcWindow *m_windowCalc = nullptr;
SignVerifyDialog *m_windowSignVerify = nullptr;
RestoreDialog *m_restoreDialog = nullptr;
AboutDialog *m_aboutDialog = nullptr;
XMRigWidget *m_xmrig = nullptr;

View file

@ -7,6 +7,8 @@
#include "utils/config.h"
#include "mainwindow.h"
#include <QFileDialog>
Settings::Settings(QWidget *parent) :
QDialog(parent),
ui(new Ui::Settings)
@ -58,16 +60,26 @@ Settings::Settings(QWidget *parent) :
connect(ui->comboBox_fiatCurrency, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Settings::fiatCurrencySelected);
// setup path tab
#if defined(Q_OS_LINUX)
ui->textEditPaths->appendPlainText(m_ctx->applicationPath);
#endif
ui->textEditPaths->appendPlainText(m_ctx->configDirectory);
ui->textEditPaths->appendPlainText(m_ctx->defaultWalletDir);
// setup paths tab
this->updatePaths();
connect(ui->btn_browseDefaultWalletDir, &QPushButton::clicked, [this]{
QString walletDir = QFileDialog::getExistingDirectory(this, "Select wallet directory ", m_ctx->defaultWalletDir, QFileDialog::ShowDirsOnly);
if (walletDir.isEmpty()) return;
m_ctx->defaultWalletDir = walletDir;
m_ctx->defaultWalletDirRoot = walletDir;
config()->set(Config::walletDirectory, walletDir);
ui->lineEdit_defaultWalletDir->setText(m_ctx->defaultWalletDir);
});
this->adjustSize();
}
void Settings::updatePaths() {
ui->lineEdit_defaultWalletDir->setText(m_ctx->defaultWalletDir);
ui->lineEdit_configDir->setText(m_ctx->configDirectory);
ui->lineEdit_applicationDir->setText(m_ctx->applicationPath);
}
void Settings::fiatCurrencySelected(int index) {
QString selection = ui->comboBox_fiatCurrency->itemText(index);
config()->set(Config::preferredFiatCurrency, selection);

View file

@ -31,6 +31,7 @@ signals:
void blockExplorerChanged(QString blockExplorer);
public slots:
void updatePaths();
void copyToClipboard();
void checkboxExternalLinkWarn();
void fiatCurrencySelected(int index);

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1019</width>
<height>336</height>
<width>1123</width>
<height>555</height>
</rect>
</property>
<property name="windowTitle">
@ -282,12 +282,75 @@
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="textEditPaths">
<property name="readOnly">
<bool>true</bool>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="lineEdit_defaultWalletDir">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_browseDefaultWalletDir">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Wallet directory:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Config directory:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_configDir">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Application directory:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_applicationDir">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_console">

View file

@ -46,19 +46,11 @@ int WalletKeysFiles::networkType() const {
return m_networkType;
}
WalletKeysFilesModel::WalletKeysFilesModel(AppContext *ctx, QObject *parent) :
QAbstractTableModel(parent),
m_ctx(ctx) {
this->walletDirectories << m_ctx->defaultWalletDirRoot;
auto walletPath = config()->get(Config::walletPath).toString();
if(!walletPath.isEmpty() && Utils::fileExists(walletPath)) {
QDir d = QFileInfo(walletPath).absoluteDir();
this->walletDirectories << d.absolutePath();
}
this->walletDirectories << m_ctx->homeDir;
this->walletDirectories.removeDuplicates();
WalletKeysFilesModel::WalletKeysFilesModel(AppContext *ctx, QObject *parent)
: QAbstractTableModel(parent)
, m_ctx(ctx)
{
this->updateDirectories();
this->m_walletKeysFilesItemModel = qobject_cast<QAbstractItemModel *>(this);
}
@ -71,6 +63,20 @@ void WalletKeysFilesModel::clear() {
void WalletKeysFilesModel::refresh() {
this->clear();
this->findWallets();
endResetModel();
}
void WalletKeysFilesModel::updateDirectories() {
this->walletDirectories.clear();
this->walletDirectories << m_ctx->defaultWalletDirRoot;
auto walletPath = config()->get(Config::walletPath).toString();
if(!walletPath.isEmpty() && Utils::fileExists(walletPath)) {
QDir d = QFileInfo(walletPath).absoluteDir();
this->walletDirectories << d.absolutePath();
}
this->walletDirectories << m_ctx->homeDir;
this->walletDirectories.removeDuplicates();
}
void WalletKeysFilesModel::findWallets() {

View file

@ -54,6 +54,8 @@ public:
QStringList walletDirectories;
private:
void updateDirectories();
AppContext *m_ctx;
QList<WalletKeysFiles> m_walletKeyFiles;
QAbstractItemModel *m_walletKeysFilesItemModel;

View file

@ -34,7 +34,11 @@ CreateWalletPage::CreateWalletPage(AppContext *ctx, QWidget *parent) :
connect(ui->btnChange, &QPushButton::clicked, [=] {
QString walletDir = QFileDialog::getExistingDirectory(this, "Select wallet directory ", m_ctx->defaultWalletDir, QFileDialog::ShowDirsOnly);
if(walletDir.isEmpty()) return;
m_ctx->defaultWalletDir = walletDir;
m_ctx->defaultWalletDirRoot = walletDir;
ui->directory->setText(walletDir);
config()->set(Config::walletDirectory, walletDir);
emit defaultWalletDirChanged(walletDir);
});
connect(ui->directory, &QLineEdit::textChanged, [=](const QString &data) {
@ -47,6 +51,10 @@ CreateWalletPage::CreateWalletPage(AppContext *ctx, QWidget *parent) :
});
}
void CreateWalletPage::initializePage() {
ui->directory->setText(m_ctx->defaultWalletDir);
}
bool CreateWalletPage::validateWidgets(){
ui->walletName->setStyleSheet("");
ui->directory->setStyleSheet("");

View file

@ -20,15 +20,16 @@ class CreateWalletPage : public QWizardPage
public:
explicit CreateWalletPage(AppContext *ctx, QWidget *parent = nullptr);
void initializePage() override;
bool validatePage() override;
int nextId() const override;
signals:
void createWallet();
void defaultWalletDirChanged(QString walletDir);
private:
AppContext *m_ctx;
QLabel *topLabel;
Ui::CreateWalletPage *ui;
QString m_walletDir;
bool validateWidgets();

View file

@ -23,7 +23,6 @@ public:
explicit CreateWalletSeedPage(AppContext *ctx, QWidget *parent = nullptr);
bool validatePage() override;
int nextId() const override;
// bool isFinalPage() const;
public slots:
void displaySeed(const QString &seed);

View file

@ -54,6 +54,9 @@ WalletWizard::WalletWizard(AppContext *ctx, WalletWizard::Page startPage, QWidge
connect(createWalletSeed, &CreateWalletSeedPage::createWallet, this, &WalletWizard::createWallet);
connect(createWallet, &CreateWalletPage::createWallet, this, &WalletWizard::createWallet);
connect(createWallet, &CreateWalletPage::defaultWalletDirChanged, [this](const QString &walletDir){
emit defaultWalletDirChanged(walletDir);
});
connect(openWalletPage, &OpenWalletPage::openWallet, [=](const QString &path){
const auto walletPasswd = this->field("walletPasswd").toString();

View file

@ -20,8 +20,10 @@ public:
enum Page { Page_Menu, Page_CreateWallet, Page_CreateWalletSeed, Page_OpenWallet, Page_Network, Page_Restore, Page_ViewOnly };
explicit WalletWizard(AppContext *ctx, WalletWizard::Page startPage = WalletWizard::Page::Page_Menu, QWidget *parent = nullptr);
signals:
void openWallet(QString path, QString password);
void defaultWalletDirChanged(QString walletDir);
private:
AppContext *m_ctx;