Menu: Add clear history for recently opened

This commit is contained in:
tobtoht 2021-07-08 14:03:54 +02:00
parent a6946b1665
commit a253022ecc
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
4 changed files with 36 additions and 7 deletions

View file

@ -223,6 +223,10 @@ void MainWindow::initMenu() {
connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::menuQuitClicked); // Quit application connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::menuQuitClicked); // Quit application
connect(ui->actionSettings, &QAction::triggered, this, &MainWindow::menuSettingsClicked); 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] // [Wallet]
connect(ui->actionInformation, &QAction::triggered, this, &MainWindow::showWalletInfoDialog); connect(ui->actionInformation, &QAction::triggered, this, &MainWindow::showWalletInfoDialog);
connect(ui->actionAccount, &QAction::triggered, this, &MainWindow::showAccountSwitcherDialog); 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); toggleTab->menuAction->setText((show ? QString("Hide ") : QString("Show ")) + toggleTab->name);
} }
void MainWindow::menuClearHistoryClicked() {
config()->remove(Config::recentlyOpenedWallets);
this->updateRecentlyOpenedMenu();
}
QString MainWindow::walletName() { QString MainWindow::walletName() {
return QFileInfo(m_ctx->wallet->cachePath()).fileName(); return QFileInfo(m_ctx->wallet->cachePath()).fileName();
} }
@ -469,7 +478,7 @@ void MainWindow::onWalletOpened() {
m_ctx->nodes->connectToNode(); m_ctx->nodes->connectToNode();
m_updateBytes.start(250); m_updateBytes.start(250);
this->updateRecentlyOpened(m_ctx->wallet->cachePath()); this->addToRecentlyOpened(m_ctx->wallet->cachePath());
} }
void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) { void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) {
@ -1497,7 +1506,7 @@ void MainWindow::donationNag() {
config()->set(Config::donateBeg, donationCounter); config()->set(Config::donateBeg, donationCounter);
} }
void MainWindow::updateRecentlyOpened(const QString &keysFile) { void MainWindow::addToRecentlyOpened(const QString &keysFile) {
auto recent = config()->get(Config::recentlyOpenedWallets).toList(); auto recent = config()->get(Config::recentlyOpenedWallets).toList();
if (recent.contains(keysFile)) { if (recent.contains(keysFile)) {
@ -1518,12 +1527,19 @@ void MainWindow::updateRecentlyOpened(const QString &keysFile) {
} }
config()->set(Config::recentlyOpenedWallets, recent_); config()->set(Config::recentlyOpenedWallets, recent_);
this->updateRecentlyOpenedMenu();
}
void MainWindow::updateRecentlyOpenedMenu() {
ui->menuRecently_open->clear(); ui->menuRecently_open->clear();
for (const auto &var : recent_) { const QStringList recentWallets = config()->get(Config::recentlyOpenedWallets).toStringList();
QString path = var.toString(); for (const auto &walletPath : recentWallets) {
QFileInfo fileInfo{path}; QFileInfo fileInfo{walletPath};
ui->menuRecently_open->addAction(fileInfo.fileName(), m_windowManager, std::bind(&WindowManager::tryOpenWallet, m_windowManager, path, "")); 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) { void MainWindow::toggleSearchbar(bool visible) {

View file

@ -113,6 +113,7 @@ private slots:
void menuWalletCloseClicked(); void menuWalletCloseClicked();
void menuTorClicked(); void menuTorClicked();
void menuToggleTabVisible(const QString &key); void menuToggleTabVisible(const QString &key);
void menuClearHistoryClicked();
void onExportHistoryCSV(bool checked); void onExportHistoryCSV(bool checked);
void onExportContactsCSV(bool checked); void onExportContactsCSV(bool checked);
void onCreateDesktopEntry(bool checked); void onCreateDesktopEntry(bool checked);
@ -208,7 +209,8 @@ private:
QString getHardwareDevice(); QString getHardwareDevice();
void updateTitle(); void updateTitle();
void donationNag(); void donationNag();
void updateRecentlyOpened(const QString &filename); void addToRecentlyOpened(const QString &filename);
void updateRecentlyOpenedMenu();
void updateWidgetIcons(); void updateWidgetIcons();
QIcon hardwareDevicePairedIcon(); QIcon hardwareDevicePairedIcon();
@ -237,6 +239,8 @@ private:
QList<PriceTickerWidget*> m_priceTickerWidgets; QList<PriceTickerWidget*> m_priceTickerWidgets;
BalanceTickerWidget *m_balanceTickerWidget; BalanceTickerWidget *m_balanceTickerWidget;
QPointer<QAction> m_clearRecentlyOpenAction;
// lower status bar // lower status bar
QPushButton *m_statusUpdateAvailable; QPushButton *m_statusUpdateAvailable;
ClickableLabel *m_statusLabelBalance; ClickableLabel *m_statusLabelBalance;

View file

@ -111,6 +111,14 @@ void Config::set(ConfigKey key, const QVariant& value)
emit changed(key); 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. * Sync configuration with persistent storage.
* *

View file

@ -102,6 +102,7 @@ public:
QVariant get(ConfigKey key); QVariant get(ConfigKey key);
QString getFileName(); QString getFileName();
void set(ConfigKey key, const QVariant& value); void set(ConfigKey key, const QVariant& value);
void remove(ConfigKey key);
void sync(); void sync();
void resetToDefaults(); void resetToDefaults();