2017-09-01 15:13:17 +00:00
|
|
|
#include "fortmanager.h"
|
2017-09-01 13:13:12 +00:00
|
|
|
|
2017-09-01 15:13:17 +00:00
|
|
|
#include <QCoreApplication>
|
2017-09-01 13:13:12 +00:00
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQmlContext>
|
|
|
|
|
|
|
|
#include "conf/appgroup.h"
|
|
|
|
#include "conf/firewallconf.h"
|
|
|
|
#include "fortsettings.h"
|
|
|
|
|
2017-09-01 15:13:17 +00:00
|
|
|
FortManager::FortManager(QObject *parent) :
|
2017-09-01 13:13:12 +00:00
|
|
|
QObject(parent),
|
2017-09-01 15:13:17 +00:00
|
|
|
m_fortSettings(new FortSettings(qApp->arguments(), this)),
|
|
|
|
m_firewallConf(new FirewallConf(this))
|
2017-09-01 13:13:12 +00:00
|
|
|
{
|
2017-09-01 15:13:17 +00:00
|
|
|
m_fortSettings->readConf(*m_firewallConf);
|
2017-09-01 13:13:12 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 15:13:17 +00:00
|
|
|
void FortManager::registerQmlTypes()
|
2017-09-01 13:13:12 +00:00
|
|
|
{
|
|
|
|
qmlRegisterUncreatableType<FortSettings>("com.fortfirewall", 1, 0, "FortSettings",
|
|
|
|
"Singleton");
|
|
|
|
|
|
|
|
qmlRegisterType<AppGroup>("com.fortfirewall", 1, 0, "AppGroup");
|
|
|
|
qmlRegisterType<FirewallConf>("com.fortfirewall", 1, 0, "FirewallConf");
|
|
|
|
}
|
|
|
|
|
2017-09-01 15:13:17 +00:00
|
|
|
void FortManager::setupContext()
|
2017-09-01 13:13:12 +00:00
|
|
|
{
|
|
|
|
QQmlContext *context = m_engine->rootContext();
|
|
|
|
|
|
|
|
context->setContextProperty("fortSettings", m_fortSettings);
|
2017-09-01 15:13:17 +00:00
|
|
|
context->setContextProperty("firewallConf", m_firewallConf);
|
|
|
|
context->setContextProperty("fortManager", this);
|
2017-09-01 13:13:12 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 15:13:17 +00:00
|
|
|
void FortManager::showWindow()
|
2017-09-01 13:13:12 +00:00
|
|
|
{
|
|
|
|
m_engine = new QQmlApplicationEngine(this);
|
|
|
|
|
|
|
|
setupContext();
|
|
|
|
|
|
|
|
m_engine->load(QUrl("qrc:/qml/main.qml"));
|
|
|
|
}
|
|
|
|
|
2017-09-01 15:13:17 +00:00
|
|
|
bool FortManager::saveConf()
|
2017-09-01 13:13:12 +00:00
|
|
|
{
|
2017-09-01 15:13:17 +00:00
|
|
|
FirewallConf *newConf = new FirewallConf(this);
|
|
|
|
emit fillConf(newConf);
|
|
|
|
|
|
|
|
if (!m_fortSettings->writeConf(*newConf)) {
|
|
|
|
delete newConf;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_firewallConf->deleteLater();
|
|
|
|
m_firewallConf = newConf;
|
|
|
|
|
|
|
|
return true;
|
2017-09-01 13:13:12 +00:00
|
|
|
}
|