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->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) {

View 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;

View 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.
*

View 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();