From 98b040670c0edc5f1cf97ce9493524cd5408ee9d Mon Sep 17 00:00:00 2001 From: Jaquee Date: Wed, 3 May 2017 14:37:33 +0200 Subject: [PATCH 1/2] Settings: Rescan wallet cache button --- pages/Settings.qml | 36 +++++++++++++++++++++++++++++++ src/libwalletqt/WalletManager.cpp | 19 ++++++++++++++++ src/libwalletqt/WalletManager.h | 3 +++ 3 files changed, 58 insertions(+) diff --git a/pages/Settings.qml b/pages/Settings.qml index 9301a92e..292658af 100644 --- a/pages/Settings.qml +++ b/pages/Settings.qml @@ -121,6 +121,42 @@ Rectangle { settingsPasswordDialog.open(); } } + + + + StandardButton { + id: rescanWalletbutton + shadowReleasedColor: "#FF4304" + shadowPressedColor: "#B32D00" + releasedColor: "#FF6C3C" + pressedColor: "#FF4304" + text: qsTr("Rescan wallet cache") + translationManager.emptyString + onClicked: { + // Show confirmation dialog + confirmationDialog.title = qsTr("Rescan wallet cache") + translationManager.emptyString; + confirmationDialog.text = qsTr("Are you sure you want to rebuild the wallet cache?\n" + + "The following information will be deleted\n" + + "- Recipient addresses\n" + + "- Tx keys\n" + + "- Tx descriptions\n\n" + + "The old wallet cache file will be renamed and can be restored later.\n" + ); + confirmationDialog.icon = StandardIcon.Question + confirmationDialog.cancelText = qsTr("Cancel") + confirmationDialog.onAcceptedCallback = function() { + walletManager.closeWallet(); + walletManager.clearWalletCache(persistentSettings.wallet_path); + walletManager.openWalletAsync(persistentSettings.wallet_path, appWindow.password, + persistentSettings.testnet); + } + + confirmationDialog.onRejectedCallback = null; + + confirmationDialog.open() + + } + } + } //! Manage daemon diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index ad77ad48..300b3699 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -11,6 +11,7 @@ #include #include #include +#include WalletManager * WalletManager::m_instance = nullptr; @@ -338,6 +339,24 @@ QString WalletManager::checkUpdates(const QString &software, const QString &subd return QString::fromStdString(std::get<1>(result) + "|" + std::get<2>(result) + "|" + std::get<3>(result) + "|" + std::get<4>(result)); } +bool WalletManager::clearWalletCache(const QString &wallet_path) const +{ + + QString fileName = wallet_path; + // Make sure wallet file is not .keys + fileName.replace(".keys",""); + QFile walletCache(fileName); + QString suffix = ".old_cache"; + QString newFileName = fileName + suffix; + + // create unique file name + for (int i = 1; QFile::exists(newFileName); i++) { + newFileName = QString("%1%2.%3").arg(fileName).arg(suffix).arg(i); + } + + return walletCache.rename(newFileName); +} + WalletManager::WalletManager(QObject *parent) : QObject(parent) { m_pimpl = Monero::WalletManagerFactory::getWalletManager(); diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 01afc064..6824d603 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -136,6 +136,9 @@ public: Q_INVOKABLE bool saveQrCode(const QString &, const QString &) const; Q_INVOKABLE QString checkUpdates(const QString &software, const QString &subdir) const; + // clear/rename wallet cache + Q_INVOKABLE bool clearWalletCache(const QString &fileName) const; + signals: void walletOpened(Wallet * wallet); From f00a1818432fa8e09ccb643a5ce22e11bbbe1896 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Wed, 3 May 2017 15:57:41 +0200 Subject: [PATCH 2/2] Disable rescan cache btn until we know if it's needed --- pages/Settings.qml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pages/Settings.qml b/pages/Settings.qml index 292658af..2e0e8f77 100644 --- a/pages/Settings.qml +++ b/pages/Settings.qml @@ -123,6 +123,7 @@ Rectangle { } +/* Rescan cache - Disabled until we know it's needed StandardButton { id: rescanWalletbutton @@ -156,7 +157,7 @@ Rectangle { } } - +*/ } //! Manage daemon