From b5b2bf6a0b714875c1ec2c57b22ba3a40bf51a1c Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 24 Dec 2016 11:32:48 +0100 Subject: [PATCH] Automatically clear old icons and VACUUM database every 20 runs --- src/lib/app/mainapplication.cpp | 24 +++++++++++++++++++++++- src/lib/app/mainapplication.h | 5 ++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index b5570bd4f..eaeb6c325 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -677,7 +677,7 @@ void MainApplication::postLaunch() QtWin::createJumpList(); - QTimer::singleShot(1000, this, SLOT(checkDefaultWebBrowser())); + QTimer::singleShot(5000, this, &MainApplication::runDeferredPostLaunchActions); } void MainApplication::saveSession() @@ -828,6 +828,12 @@ void MainApplication::onFocusChanged() } } +void MainApplication::runDeferredPostLaunchActions() +{ + checkDefaultWebBrowser(); + checkOptimizeDatabase(); +} + void MainApplication::downloadRequested(QWebEngineDownloadItem *download) { downloadManager()->download(download); @@ -1067,6 +1073,22 @@ void MainApplication::checkDefaultWebBrowser() #endif } +void MainApplication::checkOptimizeDatabase() +{ + Settings settings; + settings.beginGroup(QSL("Browser")); + const int numberOfRuns = settings.value(QSL("RunsWithoutOptimizeDb"), 0).toInt(); + settings.setValue(QSL("RunsWithoutOptimizeDb"), numberOfRuns + 1); + + if (numberOfRuns > 20) { + std::cout << "Optimizing database..." << std::endl; + IconProvider::instance()->clearOldIconsInDatabase(); + settings.setValue(QSL("RunsWithoutOptimizeDb"), 0); + } + + settings.endGroup(); +} + void MainApplication::setUserStyleSheet(const QString &filePath) { QString userCss; diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index 7393f464c..120d62a88 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -129,7 +129,7 @@ private slots: void messageReceived(const QString &message); void windowDestroyed(QObject* window); void onFocusChanged(); - void checkDefaultWebBrowser(); + void runDeferredPostLaunchActions(); void downloadRequested(QWebEngineDownloadItem *download); @@ -148,6 +148,9 @@ private: void setUserStyleSheet(const QString &filePath); + void checkDefaultWebBrowser(); + void checkOptimizeDatabase(); + bool m_isPrivate; bool m_isPortable; bool m_isClosing;