mirror of
https://github.com/tnodir/fort
synced 2024-11-15 11:25:08 +00:00
UI: AddressesPage: Prepare Zones.
This commit is contained in:
parent
1b43674554
commit
71f8839f69
@ -4,6 +4,7 @@
|
|||||||
#define FORT_CONF_IP_MAX (10 * 1024 * 1024)
|
#define FORT_CONF_IP_MAX (10 * 1024 * 1024)
|
||||||
#define FORT_CONF_IP_ARR_SIZE(n) ((n) * sizeof(UINT32))
|
#define FORT_CONF_IP_ARR_SIZE(n) ((n) * sizeof(UINT32))
|
||||||
#define FORT_CONF_IP_RANGE_SIZE(n) (FORT_CONF_IP_ARR_SIZE(n) * 2)
|
#define FORT_CONF_IP_RANGE_SIZE(n) (FORT_CONF_IP_ARR_SIZE(n) * 2)
|
||||||
|
#define FORT_CONF_ZONE_MAX 32
|
||||||
#define FORT_CONF_GROUP_MAX 16
|
#define FORT_CONF_GROUP_MAX 16
|
||||||
#define FORT_CONF_APPS_LEN_MAX (64 * 1024 * 1024)
|
#define FORT_CONF_APPS_LEN_MAX (64 * 1024 * 1024)
|
||||||
#define FORT_CONF_APP_PATH_MAX (2 * 1024)
|
#define FORT_CONF_APP_PATH_MAX (2 * 1024)
|
||||||
|
@ -178,15 +178,23 @@ const char * const sqlUpdateAppResetGroup =
|
|||||||
;
|
;
|
||||||
|
|
||||||
const char * const sqlInsertZone =
|
const char * const sqlInsertZone =
|
||||||
"INSERT INTO zone(name, enabled, store_text, custom_url,"
|
"INSERT INTO zone(zone_id, name, enabled, store_text, custom_url,"
|
||||||
" source_code, url, form_data)"
|
" source_code, url, form_data)"
|
||||||
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7);"
|
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8);"
|
||||||
|
;
|
||||||
|
|
||||||
|
const char * const sqlSelectZoneIds =
|
||||||
|
"SELECT zone_id FROM zone ORDER BY zone_id;"
|
||||||
;
|
;
|
||||||
|
|
||||||
const char * const sqlDeleteZone =
|
const char * const sqlDeleteZone =
|
||||||
"DELETE FROM zone WHERE zone_id = ?1;"
|
"DELETE FROM zone WHERE zone_id = ?1;"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
const char * const sqlDeleteAddressGroupZone =
|
||||||
|
"DELETE FROM address_group_zone WHERE zone_id = ?1;"
|
||||||
|
;
|
||||||
|
|
||||||
const char * const sqlUpdateZone =
|
const char * const sqlUpdateZone =
|
||||||
"UPDATE zone"
|
"UPDATE zone"
|
||||||
" SET name = ?2, enabled = ?3, store_text = ?4, custom_url = ?5,"
|
" SET name = ?2, enabled = ?3, store_text = ?4, custom_url = ?5,"
|
||||||
@ -333,6 +341,22 @@ void ConfManager::showErrorMessage(const QString &errorMessage)
|
|||||||
fortManager()->showErrorBox(errorMessage, tr("Configuration Error"));
|
fortManager()->showErrorBox(errorMessage, tr("Configuration Error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ConfManager::checkResult(bool ok, bool commit)
|
||||||
|
{
|
||||||
|
const auto errorMessage = ok ? QString()
|
||||||
|
: m_sqliteDb->errorMessage();
|
||||||
|
|
||||||
|
if (commit) {
|
||||||
|
m_sqliteDb->endTransaction(ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
showErrorMessage(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
bool ConfManager::initialize()
|
bool ConfManager::initialize()
|
||||||
{
|
{
|
||||||
if (!m_sqliteDb->open()) {
|
if (!m_sqliteDb->open()) {
|
||||||
@ -454,13 +478,7 @@ bool ConfManager::saveTasks(const QList<TaskInfo *> &taskInfos)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ok) {
|
return checkResult(ok, true);
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sqliteDb->endTransaction(ok);
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::addApp(const QString &appPath, const QString &appName,
|
bool ConfManager::addApp(const QString &appPath, const QString &appName,
|
||||||
@ -495,11 +513,7 @@ bool ConfManager::addApp(const QString &appPath, const QString &appName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (!ok) {
|
checkResult(ok, true);
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sqliteDb->endTransaction(ok);
|
|
||||||
|
|
||||||
if (ok && !endTime.isNull()) {
|
if (ok && !endTime.isNull()) {
|
||||||
m_appEndTimer.start();
|
m_appEndTimer.start();
|
||||||
@ -522,13 +536,7 @@ bool ConfManager::deleteApp(qint64 appId)
|
|||||||
m_sqliteDb->executeEx(sqlDeleteAppAlert, vars, 0, &ok);
|
m_sqliteDb->executeEx(sqlDeleteAppAlert, vars, 0, &ok);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (!ok) {
|
return checkResult(ok, true);
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sqliteDb->endTransaction(ok);
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateApp(qint64 appId, const QString &appName, const QDateTime &endTime,
|
bool ConfManager::updateApp(qint64 appId, const QString &appName, const QDateTime &endTime,
|
||||||
@ -553,11 +561,7 @@ bool ConfManager::updateApp(qint64 appId, const QString &appName, const QDateTim
|
|||||||
m_sqliteDb->executeEx(sqlDeleteAppAlert, {appId}, 0, &ok);
|
m_sqliteDb->executeEx(sqlDeleteAppAlert, {appId}, 0, &ok);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (!ok) {
|
checkResult(ok, true);
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sqliteDb->endTransaction(ok);
|
|
||||||
|
|
||||||
if (ok && !endTime.isNull()) {
|
if (ok && !endTime.isNull()) {
|
||||||
m_appEndTimer.start();
|
m_appEndTimer.start();
|
||||||
@ -576,11 +580,8 @@ bool ConfManager::updateAppName(qint64 appId, const QString &appName)
|
|||||||
;
|
;
|
||||||
|
|
||||||
m_sqliteDb->executeEx(sqlUpdateAppName, vars, 0, &ok);
|
m_sqliteDb->executeEx(sqlUpdateAppName, vars, 0, &ok);
|
||||||
if (!ok) {
|
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
return checkResult(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::walkApps(std::function<walkAppsCallback> func)
|
bool ConfManager::walkApps(std::function<walkAppsCallback> func)
|
||||||
@ -648,11 +649,15 @@ void ConfManager::checkAppEndTimes()
|
|||||||
|
|
||||||
bool ConfManager::addZone(const QString &zoneName, const QString &sourceCode,
|
bool ConfManager::addZone(const QString &zoneName, const QString &sourceCode,
|
||||||
const QString &url, const QString &formData,
|
const QString &url, const QString &formData,
|
||||||
bool enabled, bool storeText, bool customUrl)
|
bool enabled, bool storeText, bool customUrl,
|
||||||
|
int &zoneId)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
|
zoneId = getFreeZoneId();
|
||||||
|
|
||||||
const auto vars = QVariantList()
|
const auto vars = QVariantList()
|
||||||
|
<< zoneId
|
||||||
<< zoneName
|
<< zoneName
|
||||||
<< enabled
|
<< enabled
|
||||||
<< storeText
|
<< storeText
|
||||||
@ -663,28 +668,45 @@ bool ConfManager::addZone(const QString &zoneName, const QString &sourceCode,
|
|||||||
;
|
;
|
||||||
|
|
||||||
m_sqliteDb->executeEx(sqlInsertZone, vars, 0, &ok);
|
m_sqliteDb->executeEx(sqlInsertZone, vars, 0, &ok);
|
||||||
if (!ok) {
|
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
return checkResult(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::deleteZone(qint64 zoneId)
|
int ConfManager::getFreeZoneId()
|
||||||
|
{
|
||||||
|
int zoneId = 1;
|
||||||
|
|
||||||
|
SqliteStmt stmt;
|
||||||
|
if (stmt.prepare(m_sqliteDb->db(), sqlSelectZoneIds)) {
|
||||||
|
while (stmt.step() == SqliteStmt::StepRow) {
|
||||||
|
const int id = stmt.columnInt(0);
|
||||||
|
if (id > zoneId) break;
|
||||||
|
|
||||||
|
zoneId = id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return zoneId;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConfManager::deleteZone(int zoneId)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
|
m_sqliteDb->beginTransaction();
|
||||||
|
|
||||||
const auto vars = QVariantList() << zoneId;
|
const auto vars = QVariantList() << zoneId;
|
||||||
|
|
||||||
m_sqliteDb->executeEx(sqlDeleteZone, vars, 0, &ok);
|
m_sqliteDb->executeEx(sqlDeleteZone, vars, 0, &ok);
|
||||||
if (!ok) {
|
if (!ok) goto end;
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
m_sqliteDb->executeEx(sqlDeleteAddressGroupZone, vars, 0, &ok);
|
||||||
|
|
||||||
|
end:
|
||||||
|
return checkResult(ok, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateZone(qint64 zoneId, const QString &zoneName,
|
bool ConfManager::updateZone(int zoneId, const QString &zoneName,
|
||||||
const QString &sourceCode, const QString &url,
|
const QString &sourceCode, const QString &url,
|
||||||
const QString &formData, bool enabled,
|
const QString &formData, bool enabled,
|
||||||
bool storeText, bool customUrl)
|
bool storeText, bool customUrl)
|
||||||
@ -703,14 +725,11 @@ bool ConfManager::updateZone(qint64 zoneId, const QString &zoneName,
|
|||||||
;
|
;
|
||||||
|
|
||||||
m_sqliteDb->executeEx(sqlUpdateZone, vars, 0, &ok);
|
m_sqliteDb->executeEx(sqlUpdateZone, vars, 0, &ok);
|
||||||
if (!ok) {
|
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
return checkResult(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateZoneName(qint64 zoneId, const QString &zoneName)
|
bool ConfManager::updateZoneName(int zoneId, const QString &zoneName)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
@ -720,14 +739,11 @@ bool ConfManager::updateZoneName(qint64 zoneId, const QString &zoneName)
|
|||||||
;
|
;
|
||||||
|
|
||||||
m_sqliteDb->executeEx(sqlUpdateZoneName, vars, 0, &ok);
|
m_sqliteDb->executeEx(sqlUpdateZoneName, vars, 0, &ok);
|
||||||
if (!ok) {
|
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
return checkResult(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateZoneEnabled(qint64 zoneId, bool enabled)
|
bool ConfManager::updateZoneEnabled(int zoneId, bool enabled)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
@ -737,14 +753,11 @@ bool ConfManager::updateZoneEnabled(qint64 zoneId, bool enabled)
|
|||||||
;
|
;
|
||||||
|
|
||||||
m_sqliteDb->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok);
|
m_sqliteDb->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok);
|
||||||
if (!ok) {
|
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
return checkResult(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::updateZoneResult(qint64 zoneId, const QString &textChecksum,
|
bool ConfManager::updateZoneResult(int zoneId, const QString &textChecksum,
|
||||||
const QString &binChecksum,
|
const QString &binChecksum,
|
||||||
const QDateTime &sourceModTime,
|
const QDateTime &sourceModTime,
|
||||||
const QDateTime &lastRun,
|
const QDateTime &lastRun,
|
||||||
@ -762,11 +775,8 @@ bool ConfManager::updateZoneResult(qint64 zoneId, const QString &textChecksum,
|
|||||||
;
|
;
|
||||||
|
|
||||||
m_sqliteDb->executeEx(sqlUpdateZoneResult, vars, 0, &ok);
|
m_sqliteDb->executeEx(sqlUpdateZoneResult, vars, 0, &ok);
|
||||||
if (!ok) {
|
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
return checkResult(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::validateDriver()
|
bool ConfManager::validateDriver()
|
||||||
@ -939,13 +949,7 @@ bool ConfManager::saveToDb(const FirewallConf &conf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (!ok) {
|
return checkResult(ok, true);
|
||||||
showErrorMessage(m_sqliteDb->errorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sqliteDb->endTransaction(ok);
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfManager::loadTask(TaskInfo *taskInfo)
|
bool ConfManager::loadTask(TaskInfo *taskInfo)
|
||||||
|
@ -67,15 +67,17 @@ public:
|
|||||||
|
|
||||||
bool addZone(const QString &zoneName, const QString &sourceCode,
|
bool addZone(const QString &zoneName, const QString &sourceCode,
|
||||||
const QString &url, const QString &formData,
|
const QString &url, const QString &formData,
|
||||||
bool enabled, bool storeText, bool customUrl);
|
bool enabled, bool storeText, bool customUrl,
|
||||||
bool deleteZone(qint64 zoneId);
|
int &zoneId);
|
||||||
bool updateZone(qint64 zoneId, const QString &zoneName,
|
int getFreeZoneId();
|
||||||
|
bool deleteZone(int zoneId);
|
||||||
|
bool updateZone(int zoneId, const QString &zoneName,
|
||||||
const QString &sourceCode, const QString &url,
|
const QString &sourceCode, const QString &url,
|
||||||
const QString &formData, bool enabled,
|
const QString &formData, bool enabled,
|
||||||
bool storeText, bool customUrl);
|
bool storeText, bool customUrl);
|
||||||
bool updateZoneName(qint64 zoneId, const QString &zoneName);
|
bool updateZoneName(int zoneId, const QString &zoneName);
|
||||||
bool updateZoneEnabled(qint64 zoneId, bool enabled);
|
bool updateZoneEnabled(int zoneId, bool enabled);
|
||||||
bool updateZoneResult(qint64 zoneId, const QString &textChecksum,
|
bool updateZoneResult(int zoneId, const QString &textChecksum,
|
||||||
const QString &binChecksum,
|
const QString &binChecksum,
|
||||||
const QDateTime &sourceModTime,
|
const QDateTime &sourceModTime,
|
||||||
const QDateTime &lastRun,
|
const QDateTime &lastRun,
|
||||||
@ -95,6 +97,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void showErrorMessage(const QString &errorMessage);
|
void showErrorMessage(const QString &errorMessage);
|
||||||
|
bool checkResult(bool ok, bool commit = false);
|
||||||
|
|
||||||
void setupDefault(FirewallConf &conf) const;
|
void setupDefault(FirewallConf &conf) const;
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ CREATE TABLE address_group(
|
|||||||
CREATE TABLE address_group_zone(
|
CREATE TABLE address_group_zone(
|
||||||
addr_group_id INTEGER NOT NULL,
|
addr_group_id INTEGER NOT NULL,
|
||||||
zone_id INTEGER NOT NULL,
|
zone_id INTEGER NOT NULL,
|
||||||
|
order_index INTEGER NOT NULL,
|
||||||
include BOOLEAN NOT NULL
|
include BOOLEAN NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -88,6 +88,11 @@ TranslationManager *OptionsController::translationManager() const
|
|||||||
return TranslationManager::instance();
|
return TranslationManager::instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZoneListModel *OptionsController::zoneListModel() const
|
||||||
|
{
|
||||||
|
return fortManager()->zoneListModel();
|
||||||
|
}
|
||||||
|
|
||||||
void OptionsController::closeWindow()
|
void OptionsController::closeWindow()
|
||||||
{
|
{
|
||||||
fortManager()->closeOptionsWindow();
|
fortManager()->closeOptionsWindow();
|
||||||
|
@ -10,6 +10,7 @@ QT_FORWARD_DECLARE_CLASS(FortManager)
|
|||||||
QT_FORWARD_DECLARE_CLASS(FortSettings)
|
QT_FORWARD_DECLARE_CLASS(FortSettings)
|
||||||
QT_FORWARD_DECLARE_CLASS(TaskManager)
|
QT_FORWARD_DECLARE_CLASS(TaskManager)
|
||||||
QT_FORWARD_DECLARE_CLASS(TranslationManager)
|
QT_FORWARD_DECLARE_CLASS(TranslationManager)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(ZoneListModel)
|
||||||
|
|
||||||
class OptionsController : public QObject
|
class OptionsController : public QObject
|
||||||
{
|
{
|
||||||
@ -43,6 +44,7 @@ public:
|
|||||||
TaskManager *taskManager() const;
|
TaskManager *taskManager() const;
|
||||||
DriverManager *driverManager() const;
|
DriverManager *driverManager() const;
|
||||||
TranslationManager *translationManager() const;
|
TranslationManager *translationManager() const;
|
||||||
|
ZoneListModel *zoneListModel() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void editedChanged();
|
void editedChanged();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "../../../controls/controlutil.h"
|
#include "../../../controls/controlutil.h"
|
||||||
@ -14,6 +15,12 @@ AddressesColumn::AddressesColumn(QWidget *parent) :
|
|||||||
setupUi();
|
setupUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddressesColumn::retranslateUi()
|
||||||
|
{
|
||||||
|
m_btSelectZones->setText(tr("Zones:"));
|
||||||
|
m_btSelectZones->setToolTip(tr("Select Zones"));
|
||||||
|
}
|
||||||
|
|
||||||
void AddressesColumn::setupUi()
|
void AddressesColumn::setupUi()
|
||||||
{
|
{
|
||||||
auto layout = new QVBoxLayout();
|
auto layout = new QVBoxLayout();
|
||||||
@ -32,6 +39,10 @@ void AddressesColumn::setupUi()
|
|||||||
headerLayout->addStretch();
|
headerLayout->addStretch();
|
||||||
headerLayout->addWidget(m_cbUseAll);
|
headerLayout->addWidget(m_cbUseAll);
|
||||||
|
|
||||||
|
// Zones Row
|
||||||
|
auto zonesLayout = setupZonesRow();
|
||||||
|
layout->addLayout(zonesLayout);
|
||||||
|
|
||||||
// Text Area
|
// Text Area
|
||||||
m_editIpText = new PlainTextEdit();
|
m_editIpText = new PlainTextEdit();
|
||||||
m_editIpText->setTabChangesFocus(true);
|
m_editIpText->setTabChangesFocus(true);
|
||||||
@ -39,3 +50,24 @@ void AddressesColumn::setupUi()
|
|||||||
|
|
||||||
this->setLayout(layout);
|
this->setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QLayout *AddressesColumn::setupZonesRow()
|
||||||
|
{
|
||||||
|
auto layout = new QHBoxLayout();
|
||||||
|
layout->setMargin(0);
|
||||||
|
layout->setSpacing(0);
|
||||||
|
|
||||||
|
m_btSelectZones = ControlUtil::createLinkButton(":/images/map_magnify.png");
|
||||||
|
layout->addWidget(m_btSelectZones);
|
||||||
|
|
||||||
|
m_labelZones = ControlUtil::createLabel();
|
||||||
|
m_labelZones->setWordWrap(true);
|
||||||
|
|
||||||
|
auto font = ControlUtil::fontDemiBold();
|
||||||
|
font.setItalic(true);
|
||||||
|
m_labelZones->setFont(font);
|
||||||
|
|
||||||
|
layout->addWidget(m_labelZones, 1);
|
||||||
|
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QCheckBox)
|
QT_FORWARD_DECLARE_CLASS(QCheckBox)
|
||||||
QT_FORWARD_DECLARE_CLASS(QLabel)
|
QT_FORWARD_DECLARE_CLASS(QLabel)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(PlainTextEdit)
|
QT_FORWARD_DECLARE_CLASS(PlainTextEdit)
|
||||||
|
|
||||||
@ -17,14 +18,22 @@ public:
|
|||||||
|
|
||||||
QLabel *labelTitle() const { return m_labelTitle; }
|
QLabel *labelTitle() const { return m_labelTitle; }
|
||||||
QCheckBox *cbUseAll() const { return m_cbUseAll; }
|
QCheckBox *cbUseAll() const { return m_cbUseAll; }
|
||||||
|
QPushButton *btSelectZones() const { return m_btSelectZones; }
|
||||||
|
QLabel *labelZones() const { return m_labelZones; }
|
||||||
PlainTextEdit *editIpText() const { return m_editIpText; }
|
PlainTextEdit *editIpText() const { return m_editIpText; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void retranslateUi();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupUi();
|
void setupUi();
|
||||||
|
QLayout *setupZonesRow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *m_labelTitle = nullptr;
|
QLabel *m_labelTitle = nullptr;
|
||||||
QCheckBox *m_cbUseAll = nullptr;
|
QCheckBox *m_cbUseAll = nullptr;
|
||||||
|
QPushButton *m_btSelectZones = nullptr;
|
||||||
|
QLabel *m_labelZones = nullptr;
|
||||||
PlainTextEdit *m_editIpText = nullptr;
|
PlainTextEdit *m_editIpText = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "../../../conf/firewallconf.h"
|
#include "../../../conf/firewallconf.h"
|
||||||
#include "../../../fortmanager.h"
|
#include "../../../fortmanager.h"
|
||||||
#include "../../../fortsettings.h"
|
#include "../../../fortsettings.h"
|
||||||
|
#include "../../../model/zonelistmodel.h"
|
||||||
#include "../../../util/net/netutil.h"
|
#include "../../../util/net/netutil.h"
|
||||||
#include "../../../util/textareautil.h"
|
#include "../../../util/textareautil.h"
|
||||||
#include "../../controls/controlutil.h"
|
#include "../../controls/controlutil.h"
|
||||||
@ -61,9 +62,11 @@ void AddressesPage::onRetranslateUi()
|
|||||||
|
|
||||||
m_includeAddresses->labelTitle()->setText(tr("Include"));
|
m_includeAddresses->labelTitle()->setText(tr("Include"));
|
||||||
m_includeAddresses->cbUseAll()->setText(tr("Include All"));
|
m_includeAddresses->cbUseAll()->setText(tr("Include All"));
|
||||||
|
m_includeAddresses->retranslateUi();
|
||||||
|
|
||||||
m_excludeAddresses->labelTitle()->setText(tr("Exclude"));
|
m_excludeAddresses->labelTitle()->setText(tr("Exclude"));
|
||||||
m_excludeAddresses->cbUseAll()->setText(tr("Exclude All"));
|
m_excludeAddresses->cbUseAll()->setText(tr("Exclude All"));
|
||||||
|
m_excludeAddresses->retranslateUi();
|
||||||
|
|
||||||
m_splitter->handle()->btMoveAllFrom1To2()->setToolTip(tr("Move All Lines to 'Exclude'"));
|
m_splitter->handle()->btMoveAllFrom1To2()->setToolTip(tr("Move All Lines to 'Exclude'"));
|
||||||
m_splitter->handle()->btMoveAllFrom2To1()->setToolTip(tr("Move All Lines to 'Include'"));
|
m_splitter->handle()->btMoveAllFrom2To1()->setToolTip(tr("Move All Lines to 'Include'"));
|
||||||
@ -207,9 +210,11 @@ void AddressesPage::setupSplitterButtons()
|
|||||||
void AddressesPage::updateGroup()
|
void AddressesPage::updateGroup()
|
||||||
{
|
{
|
||||||
m_includeAddresses->cbUseAll()->setChecked(addressGroup()->includeAll());
|
m_includeAddresses->cbUseAll()->setChecked(addressGroup()->includeAll());
|
||||||
|
m_includeAddresses->labelZones()->setText(zonesText(true));
|
||||||
m_includeAddresses->editIpText()->setText(addressGroup()->includeText());
|
m_includeAddresses->editIpText()->setText(addressGroup()->includeText());
|
||||||
|
|
||||||
m_excludeAddresses->cbUseAll()->setChecked(addressGroup()->excludeAll());
|
m_excludeAddresses->cbUseAll()->setChecked(addressGroup()->excludeAll());
|
||||||
|
m_excludeAddresses->labelZones()->setText(zonesText(false));
|
||||||
m_excludeAddresses->editIpText()->setText(addressGroup()->excludeText());
|
m_excludeAddresses->editIpText()->setText(addressGroup()->excludeText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,6 +242,21 @@ AddressGroup *AddressesPage::addressGroupByIndex(int index) const
|
|||||||
return addressGroups().at(index);
|
return addressGroups().at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString AddressesPage::zonesText(bool include) const
|
||||||
|
{
|
||||||
|
const auto zoneIds = zoneListModel()->addressGroupZones(
|
||||||
|
addressGroup()->id(), include);
|
||||||
|
if (zoneIds.isEmpty())
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
QStringList list;
|
||||||
|
for (const int zoneId : zoneIds) {
|
||||||
|
const auto zoneName = zoneListModel()->zoneNameById(zoneId);
|
||||||
|
list.append(zoneName);
|
||||||
|
}
|
||||||
|
return list.join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
QString AddressesPage::localNetworks()
|
QString AddressesPage::localNetworks()
|
||||||
{
|
{
|
||||||
return NetUtil::localIpv4Networks().join('\n');
|
return NetUtil::localIpv4Networks().join('\n');
|
||||||
|
@ -10,6 +10,7 @@ QT_FORWARD_DECLARE_CLASS(TextArea2Splitter)
|
|||||||
class AddressesPage : public BasePage
|
class AddressesPage : public BasePage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AddressesPage(OptionsController *ctrl = nullptr,
|
explicit AddressesPage(OptionsController *ctrl = nullptr,
|
||||||
QWidget *parent = nullptr);
|
QWidget *parent = nullptr);
|
||||||
@ -43,6 +44,8 @@ private:
|
|||||||
const QList<AddressGroup *> &addressGroups() const;
|
const QList<AddressGroup *> &addressGroups() const;
|
||||||
AddressGroup *addressGroupByIndex(int index) const;
|
AddressGroup *addressGroupByIndex(int index) const;
|
||||||
|
|
||||||
|
QString zonesText(bool include) const;
|
||||||
|
|
||||||
static QString localNetworks();
|
static QString localNetworks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -44,6 +44,11 @@ TaskManager *BasePage::taskManager() const
|
|||||||
return ctrl()->taskManager();
|
return ctrl()->taskManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZoneListModel *BasePage::zoneListModel() const
|
||||||
|
{
|
||||||
|
return ctrl()->zoneListModel();
|
||||||
|
}
|
||||||
|
|
||||||
void BasePage::setupController()
|
void BasePage::setupController()
|
||||||
{
|
{
|
||||||
Q_ASSERT(ctrl());
|
Q_ASSERT(ctrl());
|
||||||
|
@ -20,6 +20,7 @@ QT_FORWARD_DECLARE_CLASS(FortSettings)
|
|||||||
QT_FORWARD_DECLARE_CLASS(OptionsController)
|
QT_FORWARD_DECLARE_CLASS(OptionsController)
|
||||||
QT_FORWARD_DECLARE_CLASS(TaskManager)
|
QT_FORWARD_DECLARE_CLASS(TaskManager)
|
||||||
QT_FORWARD_DECLARE_CLASS(TranslationManager)
|
QT_FORWARD_DECLARE_CLASS(TranslationManager)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(ZoneListModel)
|
||||||
|
|
||||||
class BasePage : public QFrame
|
class BasePage : public QFrame
|
||||||
{
|
{
|
||||||
@ -37,6 +38,7 @@ protected:
|
|||||||
DriverManager *driverManager() const;
|
DriverManager *driverManager() const;
|
||||||
TranslationManager *translationManager() const;
|
TranslationManager *translationManager() const;
|
||||||
TaskManager *taskManager() const;
|
TaskManager *taskManager() const;
|
||||||
|
ZoneListModel *zoneListModel() const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void onEditResetted() {}
|
virtual void onEditResetted() {}
|
||||||
|
@ -115,6 +115,9 @@ void ZonesWindow::setupUi()
|
|||||||
// Actions on zones table's current changed
|
// Actions on zones table's current changed
|
||||||
setupTableZonesChanged();
|
setupTableZonesChanged();
|
||||||
|
|
||||||
|
// Actions on zone list model's changed
|
||||||
|
setupZoneListModelChanged();
|
||||||
|
|
||||||
this->setLayout(layout);
|
this->setLayout(layout);
|
||||||
|
|
||||||
// Font
|
// Font
|
||||||
@ -307,6 +310,18 @@ void ZonesWindow::setupTableZonesChanged()
|
|||||||
connect(m_zoneListView, &TableView::currentIndexChanged, this, refreshTableZonesChanged);
|
connect(m_zoneListView, &TableView::currentIndexChanged, this, refreshTableZonesChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZonesWindow::setupZoneListModelChanged()
|
||||||
|
{
|
||||||
|
const auto refreshAddZone = [&] {
|
||||||
|
m_actAddZone->setEnabled(zoneListModel()->rowCount() < 32);
|
||||||
|
};
|
||||||
|
|
||||||
|
refreshAddZone();
|
||||||
|
|
||||||
|
connect(zoneListModel(), &ZoneListModel::modelReset, this, refreshAddZone);
|
||||||
|
connect(zoneListModel(), &ZoneListModel::rowsRemoved, this, refreshAddZone);
|
||||||
|
}
|
||||||
|
|
||||||
void ZonesWindow::updateZoneEditForm(bool editCurrentZone)
|
void ZonesWindow::updateZoneEditForm(bool editCurrentZone)
|
||||||
{
|
{
|
||||||
ZoneRow zoneRow;
|
ZoneRow zoneRow;
|
||||||
@ -351,6 +366,12 @@ bool ZonesWindow::saveZoneEditForm()
|
|||||||
const auto url = m_editUrl->text();
|
const auto url = m_editUrl->text();
|
||||||
const auto formData = m_editFormData->text();
|
const auto formData = m_editFormData->text();
|
||||||
|
|
||||||
|
// Check zone name
|
||||||
|
if (zoneName.isEmpty()) {
|
||||||
|
m_editZoneName->setFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check custom url
|
// Check custom url
|
||||||
if (customUrl && url.isEmpty()) {
|
if (customUrl && url.isEmpty()) {
|
||||||
m_editUrl->setText(zoneSource.url());
|
m_editUrl->setText(zoneSource.url());
|
||||||
@ -362,8 +383,13 @@ bool ZonesWindow::saveZoneEditForm()
|
|||||||
|
|
||||||
// Add new zone
|
// Add new zone
|
||||||
if (m_formZoneIsNew) {
|
if (m_formZoneIsNew) {
|
||||||
return zoneListModel()->addZone(zoneName, sourceCode, url, formData,
|
int zoneId;
|
||||||
enabled, storeText, customUrl);
|
if (zoneListModel()->addZone(zoneName, sourceCode, url, formData,
|
||||||
|
enabled, storeText, customUrl, zoneId)) {
|
||||||
|
m_zoneListView->selectRow(zoneId - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edit selected zone
|
// Edit selected zone
|
||||||
|
@ -42,6 +42,7 @@ private:
|
|||||||
void setupTableZones();
|
void setupTableZones();
|
||||||
void setupTableZonesHeader();
|
void setupTableZonesHeader();
|
||||||
void setupTableZonesChanged();
|
void setupTableZonesChanged();
|
||||||
|
void setupZoneListModelChanged();
|
||||||
|
|
||||||
void updateZoneEditForm(bool editCurrentZone);
|
void updateZoneEditForm(bool editCurrentZone);
|
||||||
bool saveZoneEditForm();
|
bool saveZoneEditForm();
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
<file>images/map_add.png</file>
|
<file>images/map_add.png</file>
|
||||||
<file>images/map_delete.png</file>
|
<file>images/map_delete.png</file>
|
||||||
<file>images/map_edit.png</file>
|
<file>images/map_edit.png</file>
|
||||||
|
<file>images/map_magnify.png</file>
|
||||||
<file>images/page_copy.png</file>
|
<file>images/page_copy.png</file>
|
||||||
<file>images/plugin.png</file>
|
<file>images/plugin.png</file>
|
||||||
<file>images/plugin_disabled.png</file>
|
<file>images/plugin_disabled.png</file>
|
||||||
|
BIN
src/ui/images/map_magnify.png
Normal file
BIN
src/ui/images/map_magnify.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 797 B |
@ -6,6 +6,7 @@
|
|||||||
#include <sqlite/sqlitestmt.h>
|
#include <sqlite/sqlitestmt.h>
|
||||||
|
|
||||||
#include "../conf/confmanager.h"
|
#include "../conf/confmanager.h"
|
||||||
|
#include "../util/conf/confutil.h"
|
||||||
#include "../util/fileutil.h"
|
#include "../util/fileutil.h"
|
||||||
#include "../util/json/jsonutil.h"
|
#include "../util/json/jsonutil.h"
|
||||||
#include "zonesourcewrapper.h"
|
#include "zonesourcewrapper.h"
|
||||||
@ -125,10 +126,11 @@ const ZoneRow &ZoneListModel::zoneRowAt(int row) const
|
|||||||
|
|
||||||
bool ZoneListModel::addZone(const QString &zoneName, const QString &sourceCode,
|
bool ZoneListModel::addZone(const QString &zoneName, const QString &sourceCode,
|
||||||
const QString &url, const QString &formData,
|
const QString &url, const QString &formData,
|
||||||
bool enabled, bool storeText, bool customUrl)
|
bool enabled, bool storeText, bool customUrl,
|
||||||
|
int &zoneId)
|
||||||
{
|
{
|
||||||
if (confManager()->addZone(zoneName, sourceCode, url, formData,
|
if (confManager()->addZone(zoneName, sourceCode, url, formData,
|
||||||
enabled, storeText, customUrl)) {
|
enabled, storeText, customUrl, zoneId)) {
|
||||||
reset();
|
reset();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -136,7 +138,7 @@ bool ZoneListModel::addZone(const QString &zoneName, const QString &sourceCode,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneListModel::updateZone(qint64 zoneId, const QString &zoneName,
|
bool ZoneListModel::updateZone(int zoneId, const QString &zoneName,
|
||||||
const QString &sourceCode, const QString &url,
|
const QString &sourceCode, const QString &url,
|
||||||
const QString &formData, bool enabled, bool storeText,
|
const QString &formData, bool enabled, bool storeText,
|
||||||
bool customUrl, bool updateDriver)
|
bool customUrl, bool updateDriver)
|
||||||
@ -150,7 +152,7 @@ bool ZoneListModel::updateZone(qint64 zoneId, const QString &zoneName,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneListModel::updateZoneName(qint64 zoneId, const QString &zoneName)
|
bool ZoneListModel::updateZoneName(int zoneId, const QString &zoneName)
|
||||||
{
|
{
|
||||||
if (confManager()->updateZoneName(zoneId, zoneName)) {
|
if (confManager()->updateZoneName(zoneId, zoneName)) {
|
||||||
refresh();
|
refresh();
|
||||||
@ -160,7 +162,7 @@ bool ZoneListModel::updateZoneName(qint64 zoneId, const QString &zoneName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneListModel::updateZoneEnabled(qint64 zoneId, bool enabled)
|
bool ZoneListModel::updateZoneEnabled(int zoneId, bool enabled)
|
||||||
{
|
{
|
||||||
if (confManager()->updateZoneEnabled(zoneId, enabled)) {
|
if (confManager()->updateZoneEnabled(zoneId, enabled)) {
|
||||||
refresh();
|
refresh();
|
||||||
@ -170,7 +172,7 @@ bool ZoneListModel::updateZoneEnabled(qint64 zoneId, bool enabled)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneListModel::updateZoneResult(qint64 zoneId, const QString &textChecksum,
|
bool ZoneListModel::updateZoneResult(int zoneId, const QString &textChecksum,
|
||||||
const QString &binChecksum,
|
const QString &binChecksum,
|
||||||
const QDateTime &sourceModTime,
|
const QDateTime &sourceModTime,
|
||||||
const QDateTime &lastRun,
|
const QDateTime &lastRun,
|
||||||
@ -185,7 +187,7 @@ bool ZoneListModel::updateZoneResult(qint64 zoneId, const QString &textChecksum,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneListModel::deleteZone(qint64 zoneId, int row)
|
void ZoneListModel::deleteZone(int zoneId, int row)
|
||||||
{
|
{
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
|
|
||||||
@ -197,6 +199,41 @@ void ZoneListModel::deleteZone(qint64 zoneId, int row)
|
|||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<int> ZoneListModel::addressGroupZones(qint64 addrGroupId, bool include)
|
||||||
|
{
|
||||||
|
static const char * const sql =
|
||||||
|
"SELECT zone_id"
|
||||||
|
" FROM address_group_zone"
|
||||||
|
" WHERE addr_group_id = ?1 AND include = ?2"
|
||||||
|
" ORDER BY order_index;"
|
||||||
|
;
|
||||||
|
|
||||||
|
QVector<int> list;
|
||||||
|
SqliteStmt stmt;
|
||||||
|
if (sqliteDb()->prepare(stmt, sql, {addrGroupId, include})) {
|
||||||
|
while (stmt.step() == SqliteStmt::StepRow) {
|
||||||
|
const int id = stmt.columnInt(0);
|
||||||
|
list.append(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ZoneListModel::zoneNameById(int zoneId)
|
||||||
|
{
|
||||||
|
static const char * const sql =
|
||||||
|
"SELECT name FROM zone"
|
||||||
|
" WHERE zone_id = ?1;"
|
||||||
|
;
|
||||||
|
|
||||||
|
SqliteStmt stmt;
|
||||||
|
if (sqliteDb()->prepare(stmt, sql, {zoneId})
|
||||||
|
&& stmt.step() == SqliteStmt::StepRow) {
|
||||||
|
return stmt.columnText(0);
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
QVariant ZoneListModel::zoneTypeByCode(const QString &typeCode) const
|
QVariant ZoneListModel::zoneTypeByCode(const QString &typeCode) const
|
||||||
{
|
{
|
||||||
return m_zoneTypesMap.value(typeCode);
|
return m_zoneTypesMap.value(typeCode);
|
||||||
@ -214,7 +251,7 @@ bool ZoneListModel::updateTableRow(int row) const
|
|||||||
&& stmt.step() == SqliteStmt::StepRow))
|
&& stmt.step() == SqliteStmt::StepRow))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_zoneRow.zoneId = stmt.columnInt64(0);
|
m_zoneRow.zoneId = stmt.columnInt(0);
|
||||||
m_zoneRow.enabled = stmt.columnBool(1);
|
m_zoneRow.enabled = stmt.columnBool(1);
|
||||||
m_zoneRow.storeText = stmt.columnBool(2);
|
m_zoneRow.storeText = stmt.columnBool(2);
|
||||||
m_zoneRow.customUrl = stmt.columnBool(3);
|
m_zoneRow.customUrl = stmt.columnBool(3);
|
||||||
|
@ -14,7 +14,7 @@ struct ZoneRow : TableRow {
|
|||||||
bool storeText = false;
|
bool storeText = false;
|
||||||
bool customUrl = false;
|
bool customUrl = false;
|
||||||
|
|
||||||
qint64 zoneId = 0;
|
int zoneId = 0;
|
||||||
|
|
||||||
QString zoneName;
|
QString zoneName;
|
||||||
QString sourceCode;
|
QString sourceCode;
|
||||||
@ -56,19 +56,24 @@ public:
|
|||||||
|
|
||||||
bool addZone(const QString &zoneName, const QString &sourceCode,
|
bool addZone(const QString &zoneName, const QString &sourceCode,
|
||||||
const QString &url, const QString &formData,
|
const QString &url, const QString &formData,
|
||||||
bool enabled, bool storeText, bool customUrl);
|
bool enabled, bool storeText, bool customUrl,
|
||||||
bool updateZone(qint64 zoneId, const QString &zoneName,
|
int &zoneId);
|
||||||
|
bool updateZone(int zoneId, const QString &zoneName,
|
||||||
const QString &sourceCode, const QString &url,
|
const QString &sourceCode, const QString &url,
|
||||||
const QString &formData, bool enabled, bool storeText,
|
const QString &formData, bool enabled, bool storeText,
|
||||||
bool customUrl, bool updateDriver = true);
|
bool customUrl, bool updateDriver = true);
|
||||||
bool updateZoneName(qint64 zoneId, const QString &zoneName);
|
bool updateZoneName(int zoneId, const QString &zoneName);
|
||||||
bool updateZoneEnabled(qint64 zoneId, bool enabled);
|
bool updateZoneEnabled(int zoneId, bool enabled);
|
||||||
bool updateZoneResult(qint64 zoneId, const QString &textChecksum,
|
bool updateZoneResult(int zoneId, const QString &textChecksum,
|
||||||
const QString &binChecksum,
|
const QString &binChecksum,
|
||||||
const QDateTime &sourceModTime,
|
const QDateTime &sourceModTime,
|
||||||
const QDateTime &lastRun,
|
const QDateTime &lastRun,
|
||||||
const QDateTime &lastSuccess);
|
const QDateTime &lastSuccess);
|
||||||
void deleteZone(qint64 zoneId, int row);
|
void deleteZone(int zoneId, int row);
|
||||||
|
|
||||||
|
QVector<int> addressGroupZones(qint64 addrGroupId, bool include);
|
||||||
|
|
||||||
|
QString zoneNameById(int zoneId);
|
||||||
|
|
||||||
QVariant zoneTypeByCode(const QString &typeCode) const;
|
QVariant zoneTypeByCode(const QString &typeCode) const;
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ void TaskInfoZoneDownloader::processSubResult(bool success)
|
|||||||
void TaskInfoZoneDownloader::removeOrphanCacheFiles()
|
void TaskInfoZoneDownloader::removeOrphanCacheFiles()
|
||||||
{
|
{
|
||||||
for (const auto fi : QDir(cachePath()).entryInfoList(QDir::Files)) {
|
for (const auto fi : QDir(cachePath()).entryInfoList(QDir::Files)) {
|
||||||
const auto zoneId = fi.baseName().toLongLong();
|
const auto zoneId = fi.baseName().toInt();
|
||||||
if (zoneId != 0 && !m_zoneIdSet.contains(zoneId)) {
|
if (zoneId != 0 && !m_zoneIdSet.contains(zoneId)) {
|
||||||
FileUtil::removeFile(fi.filePath());
|
FileUtil::removeFile(fi.filePath());
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ private:
|
|||||||
bool m_success = false;
|
bool m_success = false;
|
||||||
int m_zoneIndex = 0;
|
int m_zoneIndex = 0;
|
||||||
|
|
||||||
QSet<qint64> m_zoneIdSet;
|
QSet<int> m_zoneIdSet;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TASKINFOZONEDOWNLOADER_H
|
#endif // TASKINFOZONEDOWNLOADER_H
|
||||||
|
@ -117,7 +117,9 @@ bool TaskZoneDownloader::storeAddresses(const QVector<QStringRef> &list,
|
|||||||
data.resize(bufSize);
|
data.resize(bufSize);
|
||||||
data = qCompress(data);
|
data = qCompress(data);
|
||||||
|
|
||||||
binChecksum = QCryptographicHash::hash(data, QCryptographicHash::Sha256);
|
const auto binChecksumData = QCryptographicHash::hash(
|
||||||
|
data, QCryptographicHash::Sha256);
|
||||||
|
binChecksum = QString::fromLatin1(binChecksumData.toHex());
|
||||||
|
|
||||||
return FileUtil::writeFileData(cacheFileBinPath(), data);
|
return FileUtil::writeFileData(cacheFileBinPath(), data);
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ public:
|
|||||||
int emptyNetMask() const { return m_emptyNetMask; }
|
int emptyNetMask() const { return m_emptyNetMask; }
|
||||||
void setEmptyNetMask(int v) { m_emptyNetMask = v; }
|
void setEmptyNetMask(int v) { m_emptyNetMask = v; }
|
||||||
|
|
||||||
qint64 zoneId() const { return m_zoneId; }
|
int zoneId() const { return m_zoneId; }
|
||||||
void setZoneId(qint64 v) { m_zoneId = v; }
|
void setZoneId(int v) { m_zoneId = v; }
|
||||||
|
|
||||||
QString url() const { return m_url; }
|
QString url() const { return m_url; }
|
||||||
void setUrl(const QString &v) { m_url = v; }
|
void setUrl(const QString &v) { m_url = v; }
|
||||||
@ -72,7 +72,7 @@ private:
|
|||||||
|
|
||||||
int m_emptyNetMask = 32;
|
int m_emptyNetMask = 32;
|
||||||
|
|
||||||
qint64 m_zoneId = 0;
|
int m_zoneId = 0;
|
||||||
|
|
||||||
QString m_url;
|
QString m_url;
|
||||||
QString m_formData;
|
QString m_formData;
|
||||||
|
@ -55,6 +55,11 @@ ConfUtil::ConfUtil(QObject *parent) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ConfUtil::zoneMaxCount()
|
||||||
|
{
|
||||||
|
return FORT_CONF_ZONE_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
void ConfUtil::setErrorMessage(const QString &errorMessage)
|
void ConfUtil::setErrorMessage(const QString &errorMessage)
|
||||||
{
|
{
|
||||||
if (m_errorMessage != errorMessage) {
|
if (m_errorMessage != errorMessage) {
|
||||||
|
@ -32,6 +32,8 @@ class ConfUtil : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit ConfUtil(QObject *parent = nullptr);
|
explicit ConfUtil(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
static int zoneMaxCount();
|
||||||
|
|
||||||
QString errorMessage() const { return m_errorMessage; }
|
QString errorMessage() const { return m_errorMessage; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
Loading…
Reference in New Issue
Block a user