From a253022ecc08a7407170a618219a7c01c8f0942d Mon Sep 17 00:00:00 2001 From: tobtoht Date: Thu, 8 Jul 2021 14:03:54 +0200 Subject: [PATCH] Menu: Add clear history for recently opened --- src/MainWindow.cpp | 28 ++++++++++++++++++++++------ src/MainWindow.h | 6 +++++- src/utils/config.cpp | 8 ++++++++ src/utils/config.h | 1 + 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c36717c..e1c7b96 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -223,6 +223,10 @@ void MainWindow::initMenu() { connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::menuQuitClicked); // Quit application connect(ui->actionSettings, &QAction::triggered, this, &MainWindow::menuSettingsClicked); + // [File] -> [Recently open] + m_clearRecentlyOpenAction = new QAction("Clear history", ui->menuFile); + connect(m_clearRecentlyOpenAction, &QAction::triggered, this, &MainWindow::menuClearHistoryClicked); + // [Wallet] connect(ui->actionInformation, &QAction::triggered, this, &MainWindow::showWalletInfoDialog); connect(ui->actionAccount, &QAction::triggered, this, &MainWindow::showAccountSwitcherDialog); @@ -389,6 +393,11 @@ void MainWindow::menuToggleTabVisible(const QString &key){ toggleTab->menuAction->setText((show ? QString("Hide ") : QString("Show ")) + toggleTab->name); } +void MainWindow::menuClearHistoryClicked() { + config()->remove(Config::recentlyOpenedWallets); + this->updateRecentlyOpenedMenu(); +} + QString MainWindow::walletName() { return QFileInfo(m_ctx->wallet->cachePath()).fileName(); } @@ -469,7 +478,7 @@ void MainWindow::onWalletOpened() { m_ctx->nodes->connectToNode(); m_updateBytes.start(250); - this->updateRecentlyOpened(m_ctx->wallet->cachePath()); + this->addToRecentlyOpened(m_ctx->wallet->cachePath()); } void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) { @@ -1497,7 +1506,7 @@ void MainWindow::donationNag() { config()->set(Config::donateBeg, donationCounter); } -void MainWindow::updateRecentlyOpened(const QString &keysFile) { +void MainWindow::addToRecentlyOpened(const QString &keysFile) { auto recent = config()->get(Config::recentlyOpenedWallets).toList(); if (recent.contains(keysFile)) { @@ -1518,12 +1527,19 @@ void MainWindow::updateRecentlyOpened(const QString &keysFile) { } config()->set(Config::recentlyOpenedWallets, recent_); + + this->updateRecentlyOpenedMenu(); +} + +void MainWindow::updateRecentlyOpenedMenu() { ui->menuRecently_open->clear(); - for (const auto &var : recent_) { - QString path = var.toString(); - QFileInfo fileInfo{path}; - ui->menuRecently_open->addAction(fileInfo.fileName(), m_windowManager, std::bind(&WindowManager::tryOpenWallet, m_windowManager, path, "")); + const QStringList recentWallets = config()->get(Config::recentlyOpenedWallets).toStringList(); + for (const auto &walletPath : recentWallets) { + QFileInfo fileInfo{walletPath}; + ui->menuRecently_open->addAction(fileInfo.fileName(), m_windowManager, std::bind(&WindowManager::tryOpenWallet, m_windowManager, walletPath, "")); } + ui->menuRecently_open->addSeparator(); + ui->menuRecently_open->addAction(m_clearRecentlyOpenAction); } void MainWindow::toggleSearchbar(bool visible) { diff --git a/src/MainWindow.h b/src/MainWindow.h index aa90fa4..b83f0a1 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -113,6 +113,7 @@ private slots: void menuWalletCloseClicked(); void menuTorClicked(); void menuToggleTabVisible(const QString &key); + void menuClearHistoryClicked(); void onExportHistoryCSV(bool checked); void onExportContactsCSV(bool checked); void onCreateDesktopEntry(bool checked); @@ -208,7 +209,8 @@ private: QString getHardwareDevice(); void updateTitle(); void donationNag(); - void updateRecentlyOpened(const QString &filename); + void addToRecentlyOpened(const QString &filename); + void updateRecentlyOpenedMenu(); void updateWidgetIcons(); QIcon hardwareDevicePairedIcon(); @@ -237,6 +239,8 @@ private: QList m_priceTickerWidgets; BalanceTickerWidget *m_balanceTickerWidget; + QPointer m_clearRecentlyOpenAction; + // lower status bar QPushButton *m_statusUpdateAvailable; ClickableLabel *m_statusLabelBalance; diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 3454429..2e434ea 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -111,6 +111,14 @@ void Config::set(ConfigKey key, const QVariant& value) emit changed(key); } +void Config::remove(ConfigKey key) +{ + auto cfg = configStrings[key]; + m_settings->remove(cfg.name); + + emit changed(key); +} + /** * Sync configuration with persistent storage. * diff --git a/src/utils/config.h b/src/utils/config.h index 220a7f3..1dce530 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -102,6 +102,7 @@ public: QVariant get(ConfigKey key); QString getFileName(); void set(ConfigKey key, const QVariant& value); + void remove(ConfigKey key); void sync(); void resetToDefaults();