UI: AddressesPage: Prepare Zones.

This commit is contained in:
Nodir Temirkhodjaev 2020-02-11 15:09:34 +05:00
parent 1b43674554
commit 71f8839f69
24 changed files with 262 additions and 96 deletions

View File

@ -4,6 +4,7 @@
#define FORT_CONF_IP_MAX (10 * 1024 * 1024)
#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_ZONE_MAX 32
#define FORT_CONF_GROUP_MAX 16
#define FORT_CONF_APPS_LEN_MAX (64 * 1024 * 1024)
#define FORT_CONF_APP_PATH_MAX (2 * 1024)

View File

@ -178,15 +178,23 @@ const char * const sqlUpdateAppResetGroup =
;
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)"
" 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 =
"DELETE FROM zone WHERE zone_id = ?1;"
;
const char * const sqlDeleteAddressGroupZone =
"DELETE FROM address_group_zone WHERE zone_id = ?1;"
;
const char * const sqlUpdateZone =
"UPDATE zone"
" 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"));
}
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()
{
if (!m_sqliteDb->open()) {
@ -454,13 +478,7 @@ bool ConfManager::saveTasks(const QList<TaskInfo *> &taskInfos)
}
}
if (!ok) {
showErrorMessage(m_sqliteDb->errorMessage());
}
m_sqliteDb->endTransaction(ok);
return ok;
return checkResult(ok, true);
}
bool ConfManager::addApp(const QString &appPath, const QString &appName,
@ -495,11 +513,7 @@ bool ConfManager::addApp(const QString &appPath, const QString &appName,
}
end:
if (!ok) {
showErrorMessage(m_sqliteDb->errorMessage());
}
m_sqliteDb->endTransaction(ok);
checkResult(ok, true);
if (ok && !endTime.isNull()) {
m_appEndTimer.start();
@ -522,13 +536,7 @@ bool ConfManager::deleteApp(qint64 appId)
m_sqliteDb->executeEx(sqlDeleteAppAlert, vars, 0, &ok);
end:
if (!ok) {
showErrorMessage(m_sqliteDb->errorMessage());
}
m_sqliteDb->endTransaction(ok);
return ok;
return checkResult(ok, true);
}
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);
end:
if (!ok) {
showErrorMessage(m_sqliteDb->errorMessage());
}
m_sqliteDb->endTransaction(ok);
checkResult(ok, true);
if (ok && !endTime.isNull()) {
m_appEndTimer.start();
@ -576,11 +580,8 @@ bool ConfManager::updateAppName(qint64 appId, const QString &appName)
;
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)
@ -648,11 +649,15 @@ void ConfManager::checkAppEndTimes()
bool ConfManager::addZone(const QString &zoneName, const QString &sourceCode,
const QString &url, const QString &formData,
bool enabled, bool storeText, bool customUrl)
bool enabled, bool storeText, bool customUrl,
int &zoneId)
{
bool ok = false;
zoneId = getFreeZoneId();
const auto vars = QVariantList()
<< zoneId
<< zoneName
<< enabled
<< storeText
@ -663,28 +668,45 @@ bool ConfManager::addZone(const QString &zoneName, const QString &sourceCode,
;
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;
m_sqliteDb->beginTransaction();
const auto vars = QVariantList() << zoneId;
m_sqliteDb->executeEx(sqlDeleteZone, vars, 0, &ok);
if (!ok) {
showErrorMessage(m_sqliteDb->errorMessage());
}
if (!ok) goto end;
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 &formData, bool enabled,
bool storeText, bool customUrl)
@ -703,14 +725,11 @@ bool ConfManager::updateZone(qint64 zoneId, const QString &zoneName,
;
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;
@ -720,14 +739,11 @@ bool ConfManager::updateZoneName(qint64 zoneId, const QString &zoneName)
;
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;
@ -737,14 +753,11 @@ bool ConfManager::updateZoneEnabled(qint64 zoneId, bool enabled)
;
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 QDateTime &sourceModTime,
const QDateTime &lastRun,
@ -762,11 +775,8 @@ bool ConfManager::updateZoneResult(qint64 zoneId, const QString &textChecksum,
;
m_sqliteDb->executeEx(sqlUpdateZoneResult, vars, 0, &ok);
if (!ok) {
showErrorMessage(m_sqliteDb->errorMessage());
}
return ok;
return checkResult(ok);
}
bool ConfManager::validateDriver()
@ -939,13 +949,7 @@ bool ConfManager::saveToDb(const FirewallConf &conf)
}
end:
if (!ok) {
showErrorMessage(m_sqliteDb->errorMessage());
}
m_sqliteDb->endTransaction(ok);
return ok;
return checkResult(ok, true);
}
bool ConfManager::loadTask(TaskInfo *taskInfo)

View File

@ -67,15 +67,17 @@ public:
bool addZone(const QString &zoneName, const QString &sourceCode,
const QString &url, const QString &formData,
bool enabled, bool storeText, bool customUrl);
bool deleteZone(qint64 zoneId);
bool updateZone(qint64 zoneId, const QString &zoneName,
bool enabled, bool storeText, bool customUrl,
int &zoneId);
int getFreeZoneId();
bool deleteZone(int zoneId);
bool updateZone(int zoneId, const QString &zoneName,
const QString &sourceCode, const QString &url,
const QString &formData, bool enabled,
bool storeText, bool customUrl);
bool updateZoneName(qint64 zoneId, const QString &zoneName);
bool updateZoneEnabled(qint64 zoneId, bool enabled);
bool updateZoneResult(qint64 zoneId, const QString &textChecksum,
bool updateZoneName(int zoneId, const QString &zoneName);
bool updateZoneEnabled(int zoneId, bool enabled);
bool updateZoneResult(int zoneId, const QString &textChecksum,
const QString &binChecksum,
const QDateTime &sourceModTime,
const QDateTime &lastRun,
@ -95,6 +97,7 @@ signals:
private:
void showErrorMessage(const QString &errorMessage);
bool checkResult(bool ok, bool commit = false);
void setupDefault(FirewallConf &conf) const;

View File

@ -26,6 +26,7 @@ CREATE TABLE address_group(
CREATE TABLE address_group_zone(
addr_group_id INTEGER NOT NULL,
zone_id INTEGER NOT NULL,
order_index INTEGER NOT NULL,
include BOOLEAN NOT NULL
);

View File

@ -88,6 +88,11 @@ TranslationManager *OptionsController::translationManager() const
return TranslationManager::instance();
}
ZoneListModel *OptionsController::zoneListModel() const
{
return fortManager()->zoneListModel();
}
void OptionsController::closeWindow()
{
fortManager()->closeOptionsWindow();

View File

@ -10,6 +10,7 @@ QT_FORWARD_DECLARE_CLASS(FortManager)
QT_FORWARD_DECLARE_CLASS(FortSettings)
QT_FORWARD_DECLARE_CLASS(TaskManager)
QT_FORWARD_DECLARE_CLASS(TranslationManager)
QT_FORWARD_DECLARE_CLASS(ZoneListModel)
class OptionsController : public QObject
{
@ -43,6 +44,7 @@ public:
TaskManager *taskManager() const;
DriverManager *driverManager() const;
TranslationManager *translationManager() const;
ZoneListModel *zoneListModel() const;
signals:
void editedChanged();

View File

@ -3,6 +3,7 @@
#include <QCheckBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include "../../../controls/controlutil.h"
@ -14,6 +15,12 @@ AddressesColumn::AddressesColumn(QWidget *parent) :
setupUi();
}
void AddressesColumn::retranslateUi()
{
m_btSelectZones->setText(tr("Zones:"));
m_btSelectZones->setToolTip(tr("Select Zones"));
}
void AddressesColumn::setupUi()
{
auto layout = new QVBoxLayout();
@ -32,6 +39,10 @@ void AddressesColumn::setupUi()
headerLayout->addStretch();
headerLayout->addWidget(m_cbUseAll);
// Zones Row
auto zonesLayout = setupZonesRow();
layout->addLayout(zonesLayout);
// Text Area
m_editIpText = new PlainTextEdit();
m_editIpText->setTabChangesFocus(true);
@ -39,3 +50,24 @@ void AddressesColumn::setupUi()
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;
}

View File

@ -5,6 +5,7 @@
QT_FORWARD_DECLARE_CLASS(QCheckBox)
QT_FORWARD_DECLARE_CLASS(QLabel)
QT_FORWARD_DECLARE_CLASS(QPushButton)
QT_FORWARD_DECLARE_CLASS(PlainTextEdit)
@ -17,14 +18,22 @@ public:
QLabel *labelTitle() const { return m_labelTitle; }
QCheckBox *cbUseAll() const { return m_cbUseAll; }
QPushButton *btSelectZones() const { return m_btSelectZones; }
QLabel *labelZones() const { return m_labelZones; }
PlainTextEdit *editIpText() const { return m_editIpText; }
public slots:
void retranslateUi();
private:
void setupUi();
QLayout *setupZonesRow();
private:
QLabel *m_labelTitle = nullptr;
QCheckBox *m_cbUseAll = nullptr;
QPushButton *m_btSelectZones = nullptr;
QLabel *m_labelZones = nullptr;
PlainTextEdit *m_editIpText = nullptr;
};

View File

@ -13,6 +13,7 @@
#include "../../../conf/firewallconf.h"
#include "../../../fortmanager.h"
#include "../../../fortsettings.h"
#include "../../../model/zonelistmodel.h"
#include "../../../util/net/netutil.h"
#include "../../../util/textareautil.h"
#include "../../controls/controlutil.h"
@ -61,9 +62,11 @@ void AddressesPage::onRetranslateUi()
m_includeAddresses->labelTitle()->setText(tr("Include"));
m_includeAddresses->cbUseAll()->setText(tr("Include All"));
m_includeAddresses->retranslateUi();
m_excludeAddresses->labelTitle()->setText(tr("Exclude"));
m_excludeAddresses->cbUseAll()->setText(tr("Exclude All"));
m_excludeAddresses->retranslateUi();
m_splitter->handle()->btMoveAllFrom1To2()->setToolTip(tr("Move All Lines to 'Exclude'"));
m_splitter->handle()->btMoveAllFrom2To1()->setToolTip(tr("Move All Lines to 'Include'"));
@ -207,9 +210,11 @@ void AddressesPage::setupSplitterButtons()
void AddressesPage::updateGroup()
{
m_includeAddresses->cbUseAll()->setChecked(addressGroup()->includeAll());
m_includeAddresses->labelZones()->setText(zonesText(true));
m_includeAddresses->editIpText()->setText(addressGroup()->includeText());
m_excludeAddresses->cbUseAll()->setChecked(addressGroup()->excludeAll());
m_excludeAddresses->labelZones()->setText(zonesText(false));
m_excludeAddresses->editIpText()->setText(addressGroup()->excludeText());
}
@ -237,6 +242,21 @@ AddressGroup *AddressesPage::addressGroupByIndex(int index) const
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()
{
return NetUtil::localIpv4Networks().join('\n');

View File

@ -10,6 +10,7 @@ QT_FORWARD_DECLARE_CLASS(TextArea2Splitter)
class AddressesPage : public BasePage
{
Q_OBJECT
public:
explicit AddressesPage(OptionsController *ctrl = nullptr,
QWidget *parent = nullptr);
@ -43,6 +44,8 @@ private:
const QList<AddressGroup *> &addressGroups() const;
AddressGroup *addressGroupByIndex(int index) const;
QString zonesText(bool include) const;
static QString localNetworks();
private:

View File

@ -44,6 +44,11 @@ TaskManager *BasePage::taskManager() const
return ctrl()->taskManager();
}
ZoneListModel *BasePage::zoneListModel() const
{
return ctrl()->zoneListModel();
}
void BasePage::setupController()
{
Q_ASSERT(ctrl());

View File

@ -20,6 +20,7 @@ QT_FORWARD_DECLARE_CLASS(FortSettings)
QT_FORWARD_DECLARE_CLASS(OptionsController)
QT_FORWARD_DECLARE_CLASS(TaskManager)
QT_FORWARD_DECLARE_CLASS(TranslationManager)
QT_FORWARD_DECLARE_CLASS(ZoneListModel)
class BasePage : public QFrame
{
@ -37,6 +38,7 @@ protected:
DriverManager *driverManager() const;
TranslationManager *translationManager() const;
TaskManager *taskManager() const;
ZoneListModel *zoneListModel() const;
protected slots:
virtual void onEditResetted() {}

View File

@ -115,6 +115,9 @@ void ZonesWindow::setupUi()
// Actions on zones table's current changed
setupTableZonesChanged();
// Actions on zone list model's changed
setupZoneListModelChanged();
this->setLayout(layout);
// Font
@ -307,6 +310,18 @@ void ZonesWindow::setupTableZonesChanged()
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)
{
ZoneRow zoneRow;
@ -351,6 +366,12 @@ bool ZonesWindow::saveZoneEditForm()
const auto url = m_editUrl->text();
const auto formData = m_editFormData->text();
// Check zone name
if (zoneName.isEmpty()) {
m_editZoneName->setFocus();
return false;
}
// Check custom url
if (customUrl && url.isEmpty()) {
m_editUrl->setText(zoneSource.url());
@ -362,8 +383,13 @@ bool ZonesWindow::saveZoneEditForm()
// Add new zone
if (m_formZoneIsNew) {
return zoneListModel()->addZone(zoneName, sourceCode, url, formData,
enabled, storeText, customUrl);
int zoneId;
if (zoneListModel()->addZone(zoneName, sourceCode, url, formData,
enabled, storeText, customUrl, zoneId)) {
m_zoneListView->selectRow(zoneId - 1);
return true;
}
return false;
}
// Edit selected zone

View File

@ -42,6 +42,7 @@ private:
void setupTableZones();
void setupTableZonesHeader();
void setupTableZonesChanged();
void setupZoneListModelChanged();
void updateZoneEditForm(bool editCurrentZone);
bool saveZoneEditForm();

View File

@ -39,6 +39,7 @@
<file>images/map_add.png</file>
<file>images/map_delete.png</file>
<file>images/map_edit.png</file>
<file>images/map_magnify.png</file>
<file>images/page_copy.png</file>
<file>images/plugin.png</file>
<file>images/plugin_disabled.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

View File

@ -6,6 +6,7 @@
#include <sqlite/sqlitestmt.h>
#include "../conf/confmanager.h"
#include "../util/conf/confutil.h"
#include "../util/fileutil.h"
#include "../util/json/jsonutil.h"
#include "zonesourcewrapper.h"
@ -125,10 +126,11 @@ const ZoneRow &ZoneListModel::zoneRowAt(int row) const
bool ZoneListModel::addZone(const QString &zoneName, const QString &sourceCode,
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,
enabled, storeText, customUrl)) {
enabled, storeText, customUrl, zoneId)) {
reset();
return true;
}
@ -136,7 +138,7 @@ bool ZoneListModel::addZone(const QString &zoneName, const QString &sourceCode,
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 &formData, bool enabled, bool storeText,
bool customUrl, bool updateDriver)
@ -150,7 +152,7 @@ bool ZoneListModel::updateZone(qint64 zoneId, const QString &zoneName,
return false;
}
bool ZoneListModel::updateZoneName(qint64 zoneId, const QString &zoneName)
bool ZoneListModel::updateZoneName(int zoneId, const QString &zoneName)
{
if (confManager()->updateZoneName(zoneId, zoneName)) {
refresh();
@ -160,7 +162,7 @@ bool ZoneListModel::updateZoneName(qint64 zoneId, const QString &zoneName)
return false;
}
bool ZoneListModel::updateZoneEnabled(qint64 zoneId, bool enabled)
bool ZoneListModel::updateZoneEnabled(int zoneId, bool enabled)
{
if (confManager()->updateZoneEnabled(zoneId, enabled)) {
refresh();
@ -170,7 +172,7 @@ bool ZoneListModel::updateZoneEnabled(qint64 zoneId, bool enabled)
return false;
}
bool ZoneListModel::updateZoneResult(qint64 zoneId, const QString &textChecksum,
bool ZoneListModel::updateZoneResult(int zoneId, const QString &textChecksum,
const QString &binChecksum,
const QDateTime &sourceModTime,
const QDateTime &lastRun,
@ -185,7 +187,7 @@ bool ZoneListModel::updateZoneResult(qint64 zoneId, const QString &textChecksum,
return false;
}
void ZoneListModel::deleteZone(qint64 zoneId, int row)
void ZoneListModel::deleteZone(int zoneId, int row)
{
beginRemoveRows(QModelIndex(), row, row);
@ -197,6 +199,41 @@ void ZoneListModel::deleteZone(qint64 zoneId, int row)
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
{
return m_zoneTypesMap.value(typeCode);
@ -214,7 +251,7 @@ bool ZoneListModel::updateTableRow(int row) const
&& stmt.step() == SqliteStmt::StepRow))
return false;
m_zoneRow.zoneId = stmt.columnInt64(0);
m_zoneRow.zoneId = stmt.columnInt(0);
m_zoneRow.enabled = stmt.columnBool(1);
m_zoneRow.storeText = stmt.columnBool(2);
m_zoneRow.customUrl = stmt.columnBool(3);

View File

@ -14,7 +14,7 @@ struct ZoneRow : TableRow {
bool storeText = false;
bool customUrl = false;
qint64 zoneId = 0;
int zoneId = 0;
QString zoneName;
QString sourceCode;
@ -56,19 +56,24 @@ public:
bool addZone(const QString &zoneName, const QString &sourceCode,
const QString &url, const QString &formData,
bool enabled, bool storeText, bool customUrl);
bool updateZone(qint64 zoneId, const QString &zoneName,
bool enabled, bool storeText, bool customUrl,
int &zoneId);
bool updateZone(int zoneId, const QString &zoneName,
const QString &sourceCode, const QString &url,
const QString &formData, bool enabled, bool storeText,
bool customUrl, bool updateDriver = true);
bool updateZoneName(qint64 zoneId, const QString &zoneName);
bool updateZoneEnabled(qint64 zoneId, bool enabled);
bool updateZoneResult(qint64 zoneId, const QString &textChecksum,
bool updateZoneName(int zoneId, const QString &zoneName);
bool updateZoneEnabled(int zoneId, bool enabled);
bool updateZoneResult(int zoneId, const QString &textChecksum,
const QString &binChecksum,
const QDateTime &sourceModTime,
const QDateTime &lastRun,
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;

View File

@ -115,7 +115,7 @@ void TaskInfoZoneDownloader::processSubResult(bool success)
void TaskInfoZoneDownloader::removeOrphanCacheFiles()
{
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)) {
FileUtil::removeFile(fi.filePath());
}

View File

@ -39,7 +39,7 @@ private:
bool m_success = false;
int m_zoneIndex = 0;
QSet<qint64> m_zoneIdSet;
QSet<int> m_zoneIdSet;
};
#endif // TASKINFOZONEDOWNLOADER_H

View File

@ -117,7 +117,9 @@ bool TaskZoneDownloader::storeAddresses(const QVector<QStringRef> &list,
data.resize(bufSize);
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);
}

View File

@ -21,8 +21,8 @@ public:
int emptyNetMask() const { return m_emptyNetMask; }
void setEmptyNetMask(int v) { m_emptyNetMask = v; }
qint64 zoneId() const { return m_zoneId; }
void setZoneId(qint64 v) { m_zoneId = v; }
int zoneId() const { return m_zoneId; }
void setZoneId(int v) { m_zoneId = v; }
QString url() const { return m_url; }
void setUrl(const QString &v) { m_url = v; }
@ -72,7 +72,7 @@ private:
int m_emptyNetMask = 32;
qint64 m_zoneId = 0;
int m_zoneId = 0;
QString m_url;
QString m_formData;

View File

@ -55,6 +55,11 @@ ConfUtil::ConfUtil(QObject *parent) :
{
}
int ConfUtil::zoneMaxCount()
{
return FORT_CONF_ZONE_MAX;
}
void ConfUtil::setErrorMessage(const QString &errorMessage)
{
if (m_errorMessage != errorMessage) {

View File

@ -32,6 +32,8 @@ class ConfUtil : public QObject
public:
explicit ConfUtil(QObject *parent = nullptr);
static int zoneMaxCount();
QString errorMessage() const { return m_errorMessage; }
signals: