UI: Options: Add "Purge Obsolete only on mounted drives" flag

This commit is contained in:
Nodir Temirkhodjaev 2024-01-12 18:02:18 +03:00
parent ad8078d569
commit bf1580c814
5 changed files with 38 additions and 12 deletions

View File

@ -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<qint64> ConfAppManager::collectObsoleteApps()
QVector<qint64> ConfAppManager::collectObsoleteApps(quint32 driveMask)
{
QVector<qint64> appIdList;
@ -441,7 +450,11 @@ QVector<qint64> 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);

View File

@ -72,7 +72,7 @@ private:
bool updateAppBlocked(qint64 appId, bool blocked, bool killProcess, bool &isWildcard);
bool checkAppBlockedChanged(App &app, bool blocked, bool killProcess);
QVector<qint64> collectObsoleteApps();
QVector<qint64> collectObsoleteApps(quint32 driveMask);
private:
void emitAppAlerted();

View File

@ -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); }

View File

@ -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);

View File

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