diff --git a/src/ui/conf/appgroup.cpp b/src/ui/conf/appgroup.cpp index 0e5cc538..87d7c2a0 100644 --- a/src/ui/conf/appgroup.cpp +++ b/src/ui/conf/appgroup.cpp @@ -144,32 +144,6 @@ QString AppGroup::menuLabel() const return text; } -void AppGroup::clear() -{ - m_edited = true; - m_enabled = true; - - m_logConn = true; - m_fragmentPacket = false; - m_periodEnabled = false; - - m_limitInEnabled = false; - m_limitOutEnabled = false; - - m_speedLimitIn = 0; - m_speedLimitOut = 0; - - // m_id should pe preserved - - m_name = QString(); - - m_blockText = QString(); - m_allowText = QString(); - - m_periodFrom = QString(); - m_periodTo = QString(); -} - void AppGroup::copy(const AppGroup &o) { m_edited = o.edited(); diff --git a/src/ui/conf/appgroup.h b/src/ui/conf/appgroup.h index 586e0795..54acc355 100644 --- a/src/ui/conf/appgroup.h +++ b/src/ui/conf/appgroup.h @@ -63,7 +63,6 @@ public: QString menuLabel() const; - void clear(); void copy(const AppGroup &o); QVariant toVariant() const; diff --git a/src/ui/conf/confmanager.cpp b/src/ui/conf/confmanager.cpp index f47ce2a8..a0a4d67c 100644 --- a/src/ui/conf/confmanager.cpp +++ b/src/ui/conf/confmanager.cpp @@ -1025,20 +1025,20 @@ bool ConfManager::removeAppGroupsInDb(const FirewallConf &conf) Q_ASSERT(!conf.appGroups().isEmpty()); const auto defaultAppGroupId = conf.appGroups().at(0)->id(); - for (AppGroup *appGroup : conf.removedAppGroupsList()) { + for (const qint64 appGroupId : conf.removedAppGroupIdList()) { bool ok; - sqliteDb()->executeEx(sqlUpdateAppResetGroup, - QVariantList() << appGroup->id() << defaultAppGroupId, 0, &ok); + sqliteDb()->executeEx( + sqlUpdateAppResetGroup, QVariantList() << appGroupId << defaultAppGroupId, 0, &ok); if (!ok) return false; - sqliteDb()->executeEx(sqlDeleteAppGroup, QVariantList() << appGroup->id(), 0, &ok); + sqliteDb()->executeEx(sqlDeleteAppGroup, QVariantList() << appGroupId, 0, &ok); if (!ok) return false; } - conf.clearRemovedAppGroups(); + conf.clearRemovedAppGroupIdList(); return true; } diff --git a/src/ui/conf/firewallconf.cpp b/src/ui/conf/firewallconf.cpp index 4d9222c5..e37fe566 100644 --- a/src/ui/conf/firewallconf.cpp +++ b/src/ui/conf/firewallconf.cpp @@ -152,7 +152,8 @@ void FirewallConf::addAppGroup(AppGroup *appGroup, int to) AppGroup *FirewallConf::addAppGroupByName(const QString &name) { - auto appGroup = !m_removedAppGroups.isEmpty() ? m_removedAppGroups.takeLast() : new AppGroup(); + auto appGroup = new AppGroup(); + appGroup->setId(m_removedAppGroupIdList.isEmpty() ? 0 : m_removedAppGroupIdList.takeLast()); appGroup->setName(name); addAppGroup(appGroup); return appGroup; @@ -176,12 +177,10 @@ void FirewallConf::removeAppGroup(int from, int to) const int hi = qMax(from, to); for (int i = hi; i >= lo; --i) { AppGroup *appGroup = m_appGroups.at(i); - if (appGroup->id() == 0) { - appGroup->deleteLater(); - } else { - appGroup->clear(); - m_removedAppGroups.append(appGroup); + if (appGroup->id() > 0) { + m_removedAppGroupIdList.append(appGroup->id()); } + appGroup->deleteLater(); m_appGroups.removeAt(i); } @@ -195,10 +194,9 @@ void FirewallConf::addDefaultAppGroup() appGroup->setAllowText(FileUtil::appBinLocation() + "/**"); } -void FirewallConf::clearRemovedAppGroups() const +void FirewallConf::clearRemovedAppGroupIdList() const { - qDeleteAll(m_removedAppGroups); - m_removedAppGroups.clear(); + m_removedAppGroupIdList.clear(); } void FirewallConf::loadAppGroupBits() @@ -387,6 +385,23 @@ void FirewallConf::appGroupsFromVariant(const QVariant &v) } } +QVariant FirewallConf::removedAppGroupIdListToVariant() const +{ + QVariantList list; + for (const qint64 id : removedAppGroupIdList()) { + list.append(id); + } + return list; +} + +void FirewallConf::removedAppGroupIdListFromVariant(const QVariant &v) +{ + const QVariantList list = v.toList(); + for (const QVariant &v : list) { + m_removedAppGroupIdList.append(v.toLongLong()); + } +} + QVariant FirewallConf::toVariant(bool onlyFlags) const { QVariantMap map; @@ -398,6 +413,7 @@ QVariant FirewallConf::toVariant(bool onlyFlags) const if (!onlyFlags || optEdited()) { map["addressGroups"] = addressesToVariant(); map["appGroups"] = appGroupsToVariant(); + map["removedAppGroupIdList"] = removedAppGroupIdListToVariant(); } if (!onlyFlags || flagsEdited()) { @@ -424,6 +440,7 @@ void FirewallConf::fromVariant(const QVariant &v, bool onlyFlags) if (optEdited()) { addressesFromVariant(map["addressGroups"]); appGroupsFromVariant(map["appGroups"]); + removedAppGroupIdListFromVariant(map["removedAppGroupIdList"]); } if (flagsEdited()) { diff --git a/src/ui/conf/firewallconf.h b/src/ui/conf/firewallconf.h index 3500cd5a..215e3a60 100644 --- a/src/ui/conf/firewallconf.h +++ b/src/ui/conf/firewallconf.h @@ -99,8 +99,8 @@ public: const QList &appGroups() const { return m_appGroups; } - const QList &removedAppGroupsList() const { return m_removedAppGroups; } - void clearRemovedAppGroups() const; + const QVector &removedAppGroupIdList() const { return m_removedAppGroupIdList; } + void clearRemovedAppGroupIdList() const; IniOptions &ini() { return m_iniOptions; } const IniOptions &ini() const { return m_iniOptions; } @@ -142,6 +142,9 @@ private: QVariant appGroupsToVariant() const; void appGroupsFromVariant(const QVariant &v); + QVariant removedAppGroupIdListToVariant() const; + void removedAppGroupIdListFromVariant(const QVariant &v); + private: uint m_editedFlags : 4; @@ -171,7 +174,7 @@ private: QList m_addressGroups; QList m_appGroups; - mutable QList m_removedAppGroups; + mutable QVector m_removedAppGroupIdList; IniOptions m_iniOptions; };