]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Menu: Add clear history for recently opened
authortobtoht <thotbot@protonmail.com>
Thu, 8 Jul 2021 12:03:54 +0000 (14:03 +0200)
committertobtoht <thotbot@protonmail.com>
Thu, 8 Jul 2021 12:03:54 +0000 (14:03 +0200)
src/MainWindow.cpp
src/MainWindow.h
src/utils/config.cpp
src/utils/config.h

index c36717cf299b6fbd719abdf2ec0a59b2c1b63dc7..e1c7b962bcb0d83217a7f4729c7cba078e6d47a0 100644 (file)
@@ -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) {
index aa90fa44b7d613f1910dc94b4592dccb7f77789c..b83f0a1699a5a08eabdeaf6f8d8081268aa32084 100644 (file)
@@ -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<PriceTickerWidget*> m_priceTickerWidgets;
     BalanceTickerWidget *m_balanceTickerWidget;
 
+    QPointer<QAction> m_clearRecentlyOpenAction;
+
     // lower status bar
     QPushButton *m_statusUpdateAvailable;
     ClickableLabel *m_statusLabelBalance;
index 34544293e571ca355cfa5c81805247cbbc935b29..2e434ea526a6d7ef6438957a8feb773f4f7103a0 100644 (file)
@@ -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.
  *
index 220a7f3cc926393ad820acc3b65f8f55e740e241..1dce5303742c899f8f0bcef1814107d9e9f9a387 100644 (file)
@@ -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();