mirror of
https://github.com/tnodir/fort
synced 2024-11-15 14:56:05 +00:00
UI: Conf: Refactor removed app groups handling.
This commit is contained in:
parent
fbbe90b130
commit
ab45fc565a
@ -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();
|
||||
|
@ -63,7 +63,6 @@ public:
|
||||
|
||||
QString menuLabel() const;
|
||||
|
||||
void clear();
|
||||
void copy(const AppGroup &o);
|
||||
|
||||
QVariant toVariant() const;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
@ -99,8 +99,8 @@ public:
|
||||
|
||||
const QList<AppGroup *> &appGroups() const { return m_appGroups; }
|
||||
|
||||
const QList<AppGroup *> &removedAppGroupsList() const { return m_removedAppGroups; }
|
||||
void clearRemovedAppGroups() const;
|
||||
const QVector<qint64> &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<AddressGroup *> m_addressGroups;
|
||||
QList<AppGroup *> m_appGroups;
|
||||
mutable QList<AppGroup *> m_removedAppGroups;
|
||||
mutable QVector<qint64> m_removedAppGroupIdList;
|
||||
|
||||
IniOptions m_iniOptions;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user