From bf1580c814814beeadc31f0f0919a0916e641ec7 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 12 Jan 2024 18:02:18 +0300 Subject: [PATCH] UI: Options: Add "Purge Obsolete only on mounted drives" flag --- src/ui/conf/confappmanager.cpp | 19 ++++++++++++++++--- src/ui/conf/confappmanager.h | 2 +- src/ui/conf/inioptions.h | 3 +++ src/ui/form/opt/pages/optionspage.cpp | 23 ++++++++++++++++------- src/ui/form/opt/pages/optionspage.h | 3 ++- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/ui/conf/confappmanager.cpp b/src/ui/conf/confappmanager.cpp index 403faa99..58be0e02 100644 --- a/src/ui/conf/confappmanager.cpp +++ b/src/ui/conf/confappmanager.cpp @@ -367,8 +367,17 @@ bool ConfAppManager::deleteApp(qint64 appId, bool &isWildcard) bool ConfAppManager::purgeApps() { + quint32 driveMask = -1; + if (conf()->ini().progPurgeOnMounted()) { + driveMask = FileUtil::mountedDriveMask(FileUtil::driveMask()); + } + + const auto appIdList = collectObsoleteApps(driveMask); + if (appIdList.isEmpty()) + return true; + // Delete obsolete apps - return deleteApps(collectObsoleteApps()); + return deleteApps(appIdList); } bool ConfAppManager::updateAppsBlocked( @@ -430,7 +439,7 @@ bool ConfAppManager::checkAppBlockedChanged(App &app, bool blocked, bool killPro return true; } -QVector ConfAppManager::collectObsoleteApps() +QVector ConfAppManager::collectObsoleteApps(quint32 driveMask) { QVector appIdList; @@ -441,7 +450,11 @@ QVector ConfAppManager::collectObsoleteApps() while (stmt.step() == SqliteStmt::StepRow) { const QString appPath = stmt.columnText(1); - if (FileUtil::isDriveFilePath(appPath) && !AppInfoUtil::fileExists(appPath)) { + const quint32 mask = FileUtil::driveMaskByPath(appPath); + if ((mask & driveMask) == 0) + continue; // skip non-path or not-mounted + + if (!AppInfoUtil::fileExists(appPath)) { const qint64 appId = stmt.columnInt64(0); appIdList.append(appId); diff --git a/src/ui/conf/confappmanager.h b/src/ui/conf/confappmanager.h index 2a6e07c3..46efd0aa 100644 --- a/src/ui/conf/confappmanager.h +++ b/src/ui/conf/confappmanager.h @@ -72,7 +72,7 @@ private: bool updateAppBlocked(qint64 appId, bool blocked, bool killProcess, bool &isWildcard); bool checkAppBlockedChanged(App &app, bool blocked, bool killProcess); - QVector collectObsoleteApps(); + QVector collectObsoleteApps(quint32 driveMask); private: void emitAppAlerted(); diff --git a/src/ui/conf/inioptions.h b/src/ui/conf/inioptions.h index 0a298a54..32977835 100644 --- a/src/ui/conf/inioptions.h +++ b/src/ui/conf/inioptions.h @@ -96,6 +96,9 @@ public: bool progPurgeOnStart() const { return valueBool("prog/purgeOnStart"); } void setProgPurgeOnStart(bool v) { setValue("prog/purgeOnStart", v); } + bool progPurgeOnMounted() const { return valueBool("prog/purgeOnMounted"); } + void setProgPurgeOnMounted(bool v) { setValue("prog/purgeOnMounted", v); } + constexpr bool graphWindowAlwaysOnTopDefault() const { return true; } bool graphWindowAlwaysOnTop() const { return valueBool("graphWindow/alwaysOnTop", true); } void setGraphWindowAlwaysOnTop(bool on) { setValue("graphWindow/alwaysOnTop", on); } diff --git a/src/ui/form/opt/pages/optionspage.cpp b/src/ui/form/opt/pages/optionspage.cpp index 340008f9..a2de3a62 100644 --- a/src/ui/form/opt/pages/optionspage.cpp +++ b/src/ui/form/opt/pages/optionspage.cpp @@ -169,8 +169,9 @@ void OptionsPage::onRetranslateUi() .arg(settings()->passwordUnlockedTillText())); m_cbLogBlocked->setText(tr("Collect New Programs")); + m_cbAppNotifyMessage->setText(tr("Use System Notifications for New Programs")); m_cbPurgeOnStart->setText(tr("Purge Obsolete on startup")); - m_cbAppAlertMessage->setText(tr("Use System Notifications for New Programs")); + m_cbPurgeOnMounted->setText(tr("Purge Obsolete only on mounted drives")); m_cbExplorerMenu->setText(tr("Windows Explorer integration")); m_cbUseSystemLocale->setText(tr("Use System Regional Settings")); @@ -518,6 +519,12 @@ void OptionsPage::setupProgBox() { setupLogBlocked(); + m_cbAppNotifyMessage = + ControlUtil::createCheckBox(iniUser()->progNotifyMessage(), [&](bool checked) { + iniUser()->setProgNotifyMessage(checked); + ctrl()->setIniUserEdited(); + }); + m_cbPurgeOnStart = ControlUtil::createCheckBox(ini()->progPurgeOnStart(), [&](bool checked) { if (ini()->progPurgeOnStart() != checked) { ini()->setProgPurgeOnStart(checked); @@ -525,15 +532,17 @@ void OptionsPage::setupProgBox() } }); - m_cbAppAlertMessage = - ControlUtil::createCheckBox(iniUser()->progNotifyMessage(), [&](bool checked) { - iniUser()->setProgNotifyMessage(checked); - ctrl()->setIniUserEdited(); + m_cbPurgeOnMounted = + ControlUtil::createCheckBox(ini()->progPurgeOnMounted(), [&](bool checked) { + if (ini()->progPurgeOnMounted() != checked) { + ini()->setProgPurgeOnMounted(checked); + ctrl()->setIniEdited(); + } }); // Layout - auto layout = ControlUtil::createLayoutByWidgets( - { m_cbLogBlocked, m_cbPurgeOnStart, m_cbAppAlertMessage }); + auto layout = ControlUtil::createLayoutByWidgets({ m_cbLogBlocked, m_cbAppNotifyMessage, + ControlUtil::createSeparator(), m_cbPurgeOnStart, m_cbPurgeOnMounted }); m_gbProg = new QGroupBox(); m_gbProg->setLayout(layout); diff --git a/src/ui/form/opt/pages/optionspage.h b/src/ui/form/opt/pages/optionspage.h index 0737d6a0..15e5161b 100644 --- a/src/ui/form/opt/pages/optionspage.h +++ b/src/ui/form/opt/pages/optionspage.h @@ -98,8 +98,9 @@ private: QLineEdit *m_editPassword = nullptr; QToolButton *m_btPasswordLock = nullptr; QCheckBox *m_cbLogBlocked = nullptr; + QCheckBox *m_cbAppNotifyMessage = nullptr; QCheckBox *m_cbPurgeOnStart = nullptr; - QCheckBox *m_cbAppAlertMessage = nullptr; + QCheckBox *m_cbPurgeOnMounted = nullptr; QCheckBox *m_cbExplorerMenu = nullptr; QCheckBox *m_cbUseSystemLocale = nullptr;