fort/src/ui/conf/firewallconf.cpp

152 lines
3.4 KiB
C++
Raw Normal View History

2017-08-28 10:35:15 +00:00
#include "firewallconf.h"
2017-09-02 10:17:51 +00:00
#include "addressgroup.h"
2017-08-29 08:40:23 +00:00
#include "appgroup.h"
2017-08-28 10:35:15 +00:00
FirewallConf::FirewallConf(QObject *parent) :
QObject(parent),
m_filterEnabled(true),
m_appLogBlocked(false),
2017-08-28 10:35:15 +00:00
m_appBlockAll(true),
2017-09-02 10:17:51 +00:00
m_appAllowAll(false),
m_ipInclude(new AddressGroup(this)),
m_ipExclude(new AddressGroup(this))
2017-08-28 10:35:15 +00:00
{
}
void FirewallConf::setFilterEnabled(bool filterEnabled)
2017-08-28 10:35:15 +00:00
{
if (m_filterEnabled != filterEnabled) {
m_filterEnabled = filterEnabled;
emit filterEnabledChanged();
2017-08-28 10:35:15 +00:00
}
}
void FirewallConf::setAppLogBlocked(bool appLogBlocked)
{
if (m_appLogBlocked != appLogBlocked) {
m_appLogBlocked = appLogBlocked;
emit appLogBlockedChanged();
}
}
void FirewallConf::setAppBlockAll(bool appBlockAll)
{
if (m_appBlockAll != appBlockAll) {
m_appBlockAll = appBlockAll;
emit appBlockAllChanged();
}
}
void FirewallConf::setAppAllowAll(bool appAllowAll)
{
if (m_appAllowAll != appAllowAll) {
m_appAllowAll = appAllowAll;
emit appAllowAllChanged();
}
}
2017-08-30 16:20:31 +00:00
quint32 FirewallConf::appGroupBits() const
{
quint32 groupBits = 0;
int i = 0;
foreach (const AppGroup *appGroup, appGroupsList()) {
if (appGroup->enabled()) {
groupBits |= (1 << i);
}
++i;
}
return groupBits;
}
void FirewallConf::setAppGroupBits(quint32 groupBits)
{
int i = 0;
foreach (AppGroup *appGroup, appGroupsList()) {
appGroup->setEnabled(groupBits & (1 << i));
++i;
}
}
2017-08-28 10:35:15 +00:00
QQmlListProperty<AppGroup> FirewallConf::appGroups()
{
return QQmlListProperty<AppGroup>(this, m_appGroups);
}
void FirewallConf::addAppGroup(AppGroup *appGroup, int to)
{
appGroup->setParent(this);
if (to < 0) {
m_appGroups.append(appGroup);
} else {
m_appGroups.insert(to, appGroup);
}
emit appGroupsChanged();
}
2017-09-02 12:52:39 +00:00
void FirewallConf::addAppGroupByName(const QString &name)
{
AppGroup *appGroup = new AppGroup();
appGroup->setName(name);
addAppGroup(appGroup);
}
2017-08-28 10:35:15 +00:00
void FirewallConf::moveAppGroup(int from, int to)
{
m_appGroups.move(from, to);
emit appGroupsChanged();
}
void FirewallConf::removeAppGroup(int from, int to)
{
for (int i = to; i >= from; --i) {
2017-09-02 12:52:39 +00:00
AppGroup *appGroup = m_appGroups.at(i);
appGroup->deleteLater();
2017-08-28 10:35:15 +00:00
m_appGroups.removeAt(i);
}
emit appGroupsChanged();
}
2017-08-30 07:03:28 +00:00
2017-09-03 03:48:29 +00:00
void FirewallConf::copyFlags(const FirewallConf &o)
{
setFilterEnabled(o.filterEnabled());
ipInclude()->setUseAll(o.ipInclude()->useAll());
ipExclude()->setUseAll(o.ipExclude()->useAll());
setAppBlockAll(o.appBlockAll());
setAppAllowAll(o.appAllowAll());
setAppGroupBits(o.appGroupBits());
}
2017-08-30 07:03:28 +00:00
QVariant FirewallConf::toVariant() const
{
QVariantMap map;
2017-09-02 10:17:51 +00:00
map["ipInclude"] = ipInclude()->toVariant();
map["ipExclude"] = ipExclude()->toVariant();
2017-08-30 07:03:28 +00:00
QVariantList groups;
foreach (const AppGroup *appGroup, appGroupsList()) {
groups.append(appGroup->toVariant());
}
map["appGroups"] = groups;
return map;
}
void FirewallConf::fromVariant(const QVariant &v)
{
QVariantMap map = v.toMap();
2017-09-02 10:17:51 +00:00
m_ipInclude->fromVariant(map["ipInclude"]);
m_ipExclude->fromVariant(map["ipExclude"]);
2017-08-30 07:03:28 +00:00
const QVariantList groups = map["appGroups"].toList();
foreach (const QVariant &gv, groups) {
AppGroup *appGroup = new AppGroup();
appGroup->fromVariant(gv);
addAppGroup(appGroup);
}
}