From bed855689404ebb9a7688d4a9b7a801ffe1abb94 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sat, 5 Oct 2024 11:49:22 +0500 Subject: [PATCH] UI: Zones: Translate Sources --- src/ui/form/zone/zoneeditdialog.cpp | 5 +++-- src/ui/model/zonelistmodel.cpp | 21 +++++++++++++++++++-- src/ui/model/zonelistmodel.h | 2 ++ src/ui/model/zonesourcewrapper.cpp | 14 ++++++++------ src/ui/model/zonesourcewrapper.h | 14 +++++++++++--- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/ui/form/zone/zoneeditdialog.cpp b/src/ui/form/zone/zoneeditdialog.cpp index df74434c..0f0827c9 100644 --- a/src/ui/form/zone/zoneeditdialog.cpp +++ b/src/ui/form/zone/zoneeditdialog.cpp @@ -35,11 +35,12 @@ void ZoneEditDialog::initialize(const ZoneRow &zoneRow) retranslateUi(); - const QString sourceCode = isEmpty() ? ZoneSourceWrapper::textSourceCode() : zoneRow.sourceCode; + const QString sourceCode = + isEmpty() ? ZoneSourceWrapper::defaultSourceCode() : zoneRow.sourceCode; const ZoneSourceWrapper zoneSource(zoneListModel()->zoneSourceByCode(sourceCode)); m_editName->setStartText(zoneRow.zoneName); - m_comboSources->setCurrentIndex(zoneSource.index()); + m_comboSources->setCurrentIndex(zoneSource.id()); m_cbEnabled->setChecked(zoneRow.enabled); m_cbCustomUrl->setChecked(zoneRow.customUrl); diff --git a/src/ui/model/zonelistmodel.cpp b/src/ui/model/zonelistmodel.cpp index 6e5fdd20..756fb634 100644 --- a/src/ui/model/zonelistmodel.cpp +++ b/src/ui/model/zonelistmodel.cpp @@ -114,7 +114,7 @@ QVariant ZoneListModel::dataDisplay(const QModelIndex &index) const return QString("%1) %2").arg(QString::number(m_zoneRow.zoneId), zoneRow.zoneName); case 1: { const auto zoneSource = ZoneSourceWrapper(zoneSourceByCode(zoneRow.sourceCode)); - return zoneSource.title(); + return zoneSourceTitleById(zoneSource.id()); } case 2: return zoneRow.addressCount; @@ -263,8 +263,25 @@ void ZoneListModel::setupZoneSources() int index = 0; for (const auto &sourceVar : zoneSources) { ZoneSourceWrapper zoneSource(sourceVar); - zoneSource.setIndex(index++); + zoneSource.setId(index++); m_zoneSourcesMap.insert(zoneSource.code(), zoneSource.map()); m_zoneSources.append(zoneSource.map()); } } + +QString ZoneListModel::zoneSourceTitleById(const int sourceId) +{ + static const char *const sourceTitles[] = { + QT_TR_NOOP("Addresses from Inline Text"), + QT_TR_NOOP("Addresses from Local File"), + QT_TR_NOOP("WindowsSpyBlocker"), + QT_TR_NOOP("FireHOL Level-1"), + QT_TR_NOOP("TAS-IX Addresses"), + }; + + if (sourceId >= 0 && sourceId < std::size(sourceTitles)) { + return tr(sourceTitles[sourceId]); + } + + return {}; +} diff --git a/src/ui/model/zonelistmodel.h b/src/ui/model/zonelistmodel.h index 101ab3d0..cdd0fb65 100644 --- a/src/ui/model/zonelistmodel.h +++ b/src/ui/model/zonelistmodel.h @@ -44,6 +44,8 @@ public: QVariant zoneSourceByCode(const QString &sourceCode) const; const QVariantList &zoneSources() const { return m_zoneSources; } + static QString zoneSourceTitleById(const int sourceId); + protected: Qt::ItemFlags flagIsUserCheckable(const QModelIndex &index) const override; diff --git a/src/ui/model/zonesourcewrapper.cpp b/src/ui/model/zonesourcewrapper.cpp index e6fe2ec2..fe4883f8 100644 --- a/src/ui/model/zonesourcewrapper.cpp +++ b/src/ui/model/zonesourcewrapper.cpp @@ -1,15 +1,17 @@ #include "zonesourcewrapper.h" +#include + ZoneSourceWrapper::ZoneSourceWrapper(const QVariant &var) : MapWrapper(var) { } -int ZoneSourceWrapper::index() const +int ZoneSourceWrapper::id() const { - return valueInt("index"); + return valueInt("id"); } -void ZoneSourceWrapper::setIndex(int index) +void ZoneSourceWrapper::setId(int id) { - setValue("index", index); + setValue("id", id); } QString ZoneSourceWrapper::code() const @@ -39,10 +41,10 @@ QString ZoneSourceWrapper::formData() const bool ZoneSourceWrapper::isTextInline() const { - return code() == textSourceCode(); + return code() == defaultSourceCode(); } -QString ZoneSourceWrapper::textSourceCode() +QString ZoneSourceWrapper::defaultSourceCode() { return "text"; } diff --git a/src/ui/model/zonesourcewrapper.h b/src/ui/model/zonesourcewrapper.h index c4df0595..1e617550 100644 --- a/src/ui/model/zonesourcewrapper.h +++ b/src/ui/model/zonesourcewrapper.h @@ -6,10 +6,18 @@ class ZoneSourceWrapper : public MapWrapper { public: + enum SourceId { + SourceText = 0, + SourceFile, + SourceWinSpyBlock, + SourceFireHolLevel1, + SourceTasix, + }; + explicit ZoneSourceWrapper(const QVariant &var = QVariant()); - int index() const; - void setIndex(int index); + int id() const; + void setId(int id); QString code() const; QString title() const; @@ -19,7 +27,7 @@ public: bool isTextInline() const; - static QString textSourceCode(); + static QString defaultSourceCode(); }; #endif // ZONESOURCEWRAPPER_H