UI: ConfManager: Simplify checkEndTransaction()

This commit is contained in:
Nodir Temirkhodjaev 2023-12-02 12:27:32 +03:00
parent 9f22954373
commit 5590dcd049
2 changed files with 17 additions and 13 deletions

View File

@ -858,7 +858,7 @@ bool ConfManager::saveTasks(const QList<TaskInfo *> &taskInfos)
} }
} }
return checkEndTransaction(ok, true); return commitTransaction(ok);
} }
void ConfManager::logBlockedApp(const LogEntryBlocked &logEntry) void ConfManager::logBlockedApp(const LogEntryBlocked &logEntry)
@ -911,7 +911,7 @@ bool ConfManager::deleteApp(qint64 appId)
sqliteDb()->executeEx(sqlDeleteAppAlert, vars, 0, &ok); sqliteDb()->executeEx(sqlDeleteAppAlert, vars, 0, &ok);
} }
checkEndTransaction(ok, true); commitTransaction(ok);
if (ok) { if (ok) {
updateDriverDeleteApp(appPath); updateDriverDeleteApp(appPath);
@ -975,7 +975,7 @@ bool ConfManager::updateApp(const App &app)
sqliteDb()->executeEx(sqlDeleteAppAlert, { app.appId }, 0, &ok); sqliteDb()->executeEx(sqlDeleteAppAlert, { app.appId }, 0, &ok);
} }
checkEndTransaction(ok, true); commitTransaction(ok);
if (ok) { if (ok) {
if (!app.endTime.isNull()) { if (!app.endTime.isNull()) {
@ -1007,7 +1007,7 @@ bool ConfManager::updateAppBlocked(qint64 appId, bool blocked, bool killProcess)
sqliteDb()->executeEx(sqlDeleteAppAlert, { appId }, 0, &ok); sqliteDb()->executeEx(sqlDeleteAppAlert, { appId }, 0, &ok);
} }
checkEndTransaction(ok, true); commitTransaction(ok);
if (ok) { if (ok) {
emitAppUpdated(); emitAppUpdated();
@ -1141,7 +1141,7 @@ bool ConfManager::deleteZone(int zoneId)
sqliteDb()->executeEx(sqlDeleteAddressGroupZone, { qint64(zoneUnMask) }, 0, &ok); sqliteDb()->executeEx(sqlDeleteAddressGroupZone, { qint64(zoneUnMask) }, 0, &ok);
} }
checkEndTransaction(ok, true); commitTransaction(ok);
if (ok) { if (ok) {
emit zoneRemoved(zoneId); emit zoneRemoved(zoneId);
@ -1344,7 +1344,7 @@ bool ConfManager::addOrUpdateApp(const App &app)
sqliteDb()->executeEx(app.alerted ? sqlInsertAppAlert : sqlDeleteAppAlert, { appId }); sqliteDb()->executeEx(app.alerted ? sqlInsertAppAlert : sqlDeleteAppAlert, { appId });
} }
checkEndTransaction(ok, true); commitTransaction(ok);
if (ok) { if (ok) {
if (!app.endTime.isNull()) { if (!app.endTime.isNull()) {
@ -1484,7 +1484,7 @@ bool ConfManager::saveToDb(const FirewallConf &conf)
&& saveAppGroups(sqliteDb(), conf) // Save App Groups && saveAppGroups(sqliteDb(), conf) // Save App Groups
&& removeAppGroupsInDb(sqliteDb(), conf); // Remove App Groups && removeAppGroupsInDb(sqliteDb(), conf); // Remove App Groups
return checkEndTransaction(ok, /*commit=*/true); return commitTransaction(ok);
} }
void ConfManager::loadExtFlags(IniOptions &ini) void ConfManager::loadExtFlags(IniOptions &ini)
@ -1551,14 +1551,17 @@ bool ConfManager::saveTask(TaskInfo *taskInfo)
return true; return true;
} }
bool ConfManager::checkEndTransaction(bool ok, bool commit) bool ConfManager::commitTransaction(bool ok)
{
const bool success = sqliteDb()->endTransaction(ok);
return checkEndTransaction(ok && success);
}
bool ConfManager::checkEndTransaction(bool ok)
{ {
const auto errorMessage = ok ? QString() : sqliteDb()->errorMessage(); const auto errorMessage = ok ? QString() : sqliteDb()->errorMessage();
if (commit) {
sqliteDb()->endTransaction(ok);
}
if (!ok) { if (!ok) {
showErrorMessage(errorMessage); showErrorMessage(errorMessage);
} }

View File

@ -147,7 +147,8 @@ private:
bool loadTask(TaskInfo *taskInfo); bool loadTask(TaskInfo *taskInfo);
bool saveTask(TaskInfo *taskInfo); bool saveTask(TaskInfo *taskInfo);
bool checkEndTransaction(bool ok, bool commit = false); bool commitTransaction(bool ok);
bool checkEndTransaction(bool ok);
private: private:
quint32 m_driveMask = 0; quint32 m_driveMask = 0;