PIJSON::new* now accept optional initial fields

This commit is contained in:
2025-07-09 12:41:23 +03:00
parent 7b52f6d70d
commit ed3d4c4217
5 changed files with 72 additions and 51 deletions

Binary file not shown.

View File

@@ -20,7 +20,7 @@
<context> <context>
<name>PIFile</name> <name>PIFile</name>
<message> <message>
<location filename="../libs/main/io_devices/pifile.cpp" line="299"/> <location filename="../libs/main/io_devices/pifile.cpp" line="300"/>
<source>Downsize is not supported yet :-(</source> <source>Downsize is not supported yet :-(</source>
<translation>Уменьшение размера не поддерживается</translation> <translation>Уменьшение размера не поддерживается</translation>
</message> </message>
@@ -46,50 +46,50 @@
<context> <context>
<name>PICrypt</name> <name>PICrypt</name>
<message> <message>
<location filename="../libs/crypt/picrypt.cpp" line="205"/> <location filename="../libs/crypt/picrypt.cpp" line="187"/>
<source>internal error: bad hash size</source> <source>internal error: bad hash size</source>
<translation>внутренняя ошибка: плохой размер хэша</translation> <translation>внутренняя ошибка: плохой размер хэша</translation>
</message> </message>
<message> <message>
<location filename="../libs/crypt/picrypt.cpp" line="39"/> <location filename="../libs/crypt/picrypt.cpp" line="35"/>
<source>Error while initialize sodium!</source> <source>Error while initialize sodium!</source>
<translation>Ошибка инициализации sodium!</translation> <translation>Ошибка инициализации sodium!</translation>
</message> </message>
<message> <message>
<location filename="../libs/crypt/picrypt.cpp" line="209"/> <location filename="../libs/crypt/picrypt.cpp" line="190"/>
<source>invalid key size %1, should be %2, filled with zeros</source> <source>invalid key size %1, should be %2, filled with zeros</source>
<translation>неверный размер ключа %1, должен быть %2, заполненный нулями</translation> <translation>неверный размер ключа %1, должен быть %2, заполненный нулями</translation>
</message> </message>
<message> <message>
<location filename="../libs/crypt/picrypt.cpp" line="29"/> <location filename="../libs/crypt/picrypt.cpp" line="29"/>
<source>Warning: PICrypt is disabled, to enable install sodium library and rebuild pip</source> <source>Warning: PICrypt is disabled, to enable install sodium library and rebuild pip</source>
<translation>Предупреждение: PICrypt неактивен, для активации установите библиотеку sodium и пересоберите PIP</translation> <translation type="vanished">Предупреждение: PICrypt неактивен, для активации установите библиотеку sodium и пересоберите PIP</translation>
</message> </message>
</context> </context>
<context> <context>
<name>PIBinLog</name> <name>PIBinLog</name>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="436"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="438"/>
<source>Read record error</source> <source>Read record error</source>
<translation>Ошибка чтения записи</translation> <translation>Ошибка чтения записи</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="432"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="434"/>
<source>End of BinLog file</source> <source>End of BinLog file</source>
<translation>Конец BinLog файла</translation> <translation>Конец BinLog файла</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="776"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="778"/>
<source>Error, can&apos;t open &quot;%1&quot;</source> <source>Error, can&apos;t open &quot;%1&quot;</source>
<translation>Ошибка, невозможно открыть &quot;%1&quot;</translation> <translation>Ошибка, невозможно открыть &quot;%1&quot;</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="262"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="264"/>
<source>Creating directory &quot;%1&quot;</source> <source>Creating directory &quot;%1&quot;</source>
<translation>Создание директории &quot;%1&quot;</translation> <translation>Создание директории &quot;%1&quot;</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="785"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="787"/>
<source>Error, can&apos;t create &quot;%1&quot;</source> <source>Error, can&apos;t create &quot;%1&quot;</source>
<translation>Ошибка, невозможно создать &quot;%1&quot;</translation> <translation>Ошибка, невозможно создать &quot;%1&quot;</translation>
</message> </message>
@@ -99,32 +99,32 @@
<translation>Ошибка, Файл пуст &quot;%1&quot;</translation> <translation>Ошибка, Файл пуст &quot;%1&quot;</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="789"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="791"/>
<source>Start join binlogs to &quot;%1&quot;</source> <source>Start join binlogs to &quot;%1&quot;</source>
<translation>Начало слияния логов в &quot;%1&quot;</translation> <translation>Начало слияния логов в &quot;%1&quot;</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="514"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="516"/>
<source>BinLogFile has too old verion</source> <source>BinLogFile has too old verion</source>
<translation>BinLogFile очень старой версии</translation> <translation>BinLogFile очень старой версии</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="513"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="515"/>
<source>BinLogFile has invalid version</source> <source>BinLogFile has invalid version</source>
<translation>BinLogFile неверной версии</translation> <translation>BinLogFile неверной версии</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="515"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="517"/>
<source>BinLogFile has too new version</source> <source>BinLogFile has too new version</source>
<translation>BinLogFile очень новой версии</translation> <translation>BinLogFile очень новой версии</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="386"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="388"/>
<source>Can&apos;t find record with id = %1</source> <source>Can&apos;t find record with id = %1</source>
<translation>Невозможно найти запись с ID = %1</translation> <translation>Невозможно найти запись с ID = %1</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="803"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="805"/>
<source>Error, can&apos;t write to file &quot;%1&quot;</source> <source>Error, can&apos;t write to file &quot;%1&quot;</source>
<translation>Ошибка, невозможно записать в &quot;%1&quot;</translation> <translation>Ошибка, невозможно записать в &quot;%1&quot;</translation>
</message> </message>
@@ -139,12 +139,12 @@
<translation>Предупреждение: Пустой BinLog файл &quot;%1&quot;</translation> <translation>Предупреждение: Пустой BinLog файл &quot;%1&quot;</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="825"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="827"/>
<source>Finish join binlogs, total time %1</source> <source>Finish join binlogs, total time %1</source>
<translation>Завершение слияния логов, общее время %1</translation> <translation>Завершение слияния логов, общее время %1</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="440"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="442"/>
<source>too small read buffer: %1, data size: %2</source> <source>too small read buffer: %1, data size: %2</source>
<translation>слишком маленький буфер: %1, размер данных: %2</translation> <translation>слишком маленький буфер: %1, размер данных: %2</translation>
</message> </message>
@@ -154,22 +154,22 @@
<translation>Ошибка: Невозможно записать заголовок в &quot;%1&quot;</translation> <translation>Ошибка: Невозможно записать заголовок в &quot;%1&quot;</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="319"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="321"/>
<source>Error: can`t write with id = 0! ID must be &gt; 0</source> <source>Error: can`t write with id = 0! ID must be &gt; 0</source>
<translation>Ошибка: Невозможно записать с ID = 0! ID должен быть &gt; 0</translation> <translation>Ошибка: Невозможно записать с ID = 0! ID должен быть &gt; 0</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="495"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="497"/>
<source>BinLogFile signature is corrupted or invalid file</source> <source>BinLogFile signature is corrupted or invalid file</source>
<translation>Неверный заголовок BinLogFile, либо файл поврежден</translation> <translation>Неверный заголовок BinLogFile, либо файл поврежден</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="295"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="297"/>
<source>Can&apos;t create new file, maybe path &quot;%1&quot; is invalid</source> <source>Can&apos;t create new file, maybe path &quot;%1&quot; is invalid</source>
<translation>Невозможно создать новый файл, возможно путь &quot;%1&quot; неверен</translation> <translation>Невозможно создать новый файл, возможно путь &quot;%1&quot; неверен</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/pibinarylog.cpp" line="286"/> <location filename="../libs/main/io_devices/pibinarylog.cpp" line="288"/>
<source>Can&apos;t create new file, maybe LogDir &quot;%1&quot; is invalid</source> <source>Can&apos;t create new file, maybe LogDir &quot;%1&quot; is invalid</source>
<translation>Невозможно создать новый файл, возможно LogDir &quot;%1&quot; неверен</translation> <translation>Невозможно создать новый файл, возможно LogDir &quot;%1&quot; неверен</translation>
</message> </message>
@@ -182,22 +182,22 @@
<context> <context>
<name>PIOpenCL</name> <name>PIOpenCL</name>
<message> <message>
<location filename="../libs/opencl/piopencl.cpp" line="509"/> <location filename="../libs/opencl/piopencl.cpp" line="549"/>
<source>Error: empty range</source> <source>Error: empty range</source>
<translation>Ошибка: пустой диапазон</translation> <translation>Ошибка: пустой диапазон</translation>
</message> </message>
<message> <message>
<location filename="../libs/opencl/piopencl.cpp" line="586"/> <location filename="../libs/opencl/piopencl.cpp" line="626"/>
<source>setArgValue invalid index %1</source> <source>setArgValue invalid index %1</source>
<translation>setArgValue неверный индекс %1</translation> <translation>setArgValue неверный индекс %1</translation>
</message> </message>
<message> <message>
<location filename="../libs/opencl/piopencl.cpp" line="616"/> <location filename="../libs/opencl/piopencl.cpp" line="656"/>
<source>bindArgValue invalid index %1</source> <source>bindArgValue invalid index %1</source>
<translation>bindArgValue неверный индекс %1</translation> <translation>bindArgValue неверный индекс %1</translation>
</message> </message>
<message> <message>
<location filename="../libs/opencl/piopencl.cpp" line="592"/> <location filename="../libs/opencl/piopencl.cpp" line="632"/>
<source>setArgValue set scalar to &quot;%1 %2&quot;</source> <source>setArgValue set scalar to &quot;%1 %2&quot;</source>
<translation>setArgValue устанавливается скаляр в &quot;%1 %2&quot;</translation> <translation>setArgValue устанавливается скаляр в &quot;%1 %2&quot;</translation>
</message> </message>
@@ -207,7 +207,7 @@
<translation>Ошибка: Платформы OpenCL не найдены!</translation> <translation>Ошибка: Платформы OpenCL не найдены!</translation>
</message> </message>
<message> <message>
<location filename="../libs/opencl/piopencl.cpp" line="622"/> <location filename="../libs/opencl/piopencl.cpp" line="662"/>
<source>bindArgValue set buffer to &quot;%1 %2&quot;</source> <source>bindArgValue set buffer to &quot;%1 %2&quot;</source>
<translation>bindArgValue устанавливается буфер в &quot;%1 %2&quot;</translation> <translation>bindArgValue устанавливается буфер в &quot;%1 %2&quot;</translation>
</message> </message>
@@ -253,47 +253,47 @@
<context> <context>
<name>PIString</name> <name>PIString</name>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1774"/> <location filename="../libs/main/text/pistring.cpp" line="1787"/>
<source>B</source> <source>B</source>
<translation>Б</translation> <translation>Б</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1794"/> <location filename="../libs/main/text/pistring.cpp" line="1807"/>
<source>EiB</source> <source>EiB</source>
<translation>ЭиБ</translation> <translation>ЭиБ</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1791"/> <location filename="../libs/main/text/pistring.cpp" line="1804"/>
<source>GiB</source> <source>GiB</source>
<translation>ГиБ</translation> <translation>ГиБ</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1789"/> <location filename="../libs/main/text/pistring.cpp" line="1802"/>
<source>KiB</source> <source>KiB</source>
<translation>КиБ</translation> <translation>КиБ</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1790"/> <location filename="../libs/main/text/pistring.cpp" line="1803"/>
<source>MiB</source> <source>MiB</source>
<translation>МиБ</translation> <translation>МиБ</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1793"/> <location filename="../libs/main/text/pistring.cpp" line="1806"/>
<source>PiB</source> <source>PiB</source>
<translation>ПиБ</translation> <translation>ПиБ</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1792"/> <location filename="../libs/main/text/pistring.cpp" line="1805"/>
<source>TiB</source> <source>TiB</source>
<translation>ТиБ</translation> <translation>ТиБ</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1796"/> <location filename="../libs/main/text/pistring.cpp" line="1809"/>
<source>YiB</source> <source>YiB</source>
<translation>ЙиБ</translation> <translation>ЙиБ</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/text/pistring.cpp" line="1795"/> <location filename="../libs/main/text/pistring.cpp" line="1808"/>
<source>ZiB</source> <source>ZiB</source>
<translation>ЗиБ</translation> <translation>ЗиБ</translation>
</message> </message>
@@ -301,17 +301,17 @@
<context> <context>
<name>PIThread</name> <name>PIThread</name>
<message> <message>
<location filename="../libs/main/thread/pithread.cpp" line="667"/> <location filename="../libs/main/thread/pithread.cpp" line="668"/>
<source>Warning, terminate!</source> <source>Warning, terminate!</source>
<translation>Предупреждение, прекращение потока!</translation> <translation>Предупреждение, прекращение потока!</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/thread/pithread.cpp" line="785"/> <location filename="../libs/main/thread/pithread.cpp" line="781"/>
<source>Error: Can`t start new thread: %1</source> <source>Error: Can`t start new thread: %1</source>
<translation>Ошибка: Невозможно начать новый поток: %1</translation> <translation>Ошибка: Невозможно начать новый поток: %1</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/thread/pithread.cpp" line="572"/> <location filename="../libs/main/thread/pithread.cpp" line="573"/>
<source>[PIThread &quot;%1&quot;] Warning, terminate on destructor!</source> <source>[PIThread &quot;%1&quot;] Warning, terminate on destructor!</source>
<translation>[PIThread &quot;%1&quot;] Предупреждение, прекращение в деструкторе!</translation> <translation>[PIThread &quot;%1&quot;] Предупреждение, прекращение в деструкторе!</translation>
</message> </message>
@@ -358,17 +358,17 @@
<context> <context>
<name>PIEthernet</name> <name>PIEthernet</name>
<message> <message>
<location filename="../libs/main/io_devices/piethernet.cpp" line="1233"/> <location filename="../libs/main/io_devices/piethernet.cpp" line="1272"/>
<source>Can`t get interfaces: %1</source> <source>Can`t get interfaces: %1</source>
<translation>Невозможно получить интерфейсы: %1</translation> <translation>Невозможно получить интерфейсы: %1</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/piethernet.cpp" line="903"/> <location filename="../libs/main/io_devices/piethernet.cpp" line="942"/>
<source>Can`t accept new connection, %1</source> <source>Can`t accept new connection, %1</source>
<translation>Невозможно принять новое соединение, %1</translation> <translation>Невозможно принять новое соединение, %1</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/io_devices/piethernet.cpp" line="1096"/> <location filename="../libs/main/io_devices/piethernet.cpp" line="1135"/>
<source>Error allocating memory needed to call GetAdaptersInfo</source> <source>Error allocating memory needed to call GetAdaptersInfo</source>
<translation>Ошибка выделения памяти для вызова GetAdaptersInfo</translation> <translation>Ошибка выделения памяти для вызова GetAdaptersInfo</translation>
</message> </message>
@@ -445,12 +445,12 @@
<context> <context>
<name>PISystemTime</name> <name>PISystemTime</name>
<message> <message>
<location filename="../libs/main/types/pisystemtime.cpp" line="335"/> <location filename="../libs/main/types/pisystemtime.cpp" line="343"/>
<source>fromSystemTime() Warning: null frequency</source> <source>fromSystemTime() Warning: null frequency</source>
<translation>fromSystemTime() Предупреждение: нулевая частота</translation> <translation>fromSystemTime() Предупреждение: нулевая частота</translation>
</message> </message>
<message> <message>
<location filename="../libs/main/types/pisystemtime.cpp" line="325"/> <location filename="../libs/main/types/pisystemtime.cpp" line="333"/>
<source>toSystemTime() Warning: invalid hertz: %1</source> <source>toSystemTime() Warning: invalid hertz: %1</source>
<translation>toSystemTime() Предупреждение: неверная частота: %1</translation> <translation>toSystemTime() Предупреждение: неверная частота: %1</translation>
</message> </message>
@@ -510,7 +510,7 @@
<context> <context>
<name>PIStreamPacker</name> <name>PIStreamPacker</name>
<message> <message>
<location filename="../libs/io_utils/pistreampacker.cpp" line="218"/> <location filename="../libs/io_utils/pistreampacker.cpp" line="168"/>
<source>Warning! Not recommended to use with non-reliable device</source> <source>Warning! Not recommended to use with non-reliable device</source>
<translation>Предупреждение! Не рекомендуется использовать с ненадежными устройствами</translation> <translation>Предупреждение! Не рекомендуется использовать с ненадежными устройствами</translation>
</message> </message>

View File

@@ -325,10 +325,10 @@ public:
//! Network interface descriptor //! Network interface descriptor
struct PIP_EXPORT Interface { struct PIP_EXPORT Interface {
//! System index //! System index
int index; int index = -1;
//! MTU //! MTU
int mtu; int mtu = 0;
//! System name //! System name
PIString name; PIString name;
@@ -351,6 +351,9 @@ public:
//! Flags of interface //! Flags of interface
InterfaceFlags flags; InterfaceFlags flags;
//! Returns if interface is active
bool isValid() const { return name.isNotEmpty(); }
//! Returns if interface is active //! Returns if interface is active
bool isActive() const { return flags[PIEthernet::ifActive]; } bool isActive() const { return flags[PIEthernet::ifActive]; }

View File

@@ -204,16 +204,21 @@
//! //!
PIJSON PIJSON::newObject() { PIJSON PIJSON::newObject(const PIVariantMap & fields) {
PIJSON ret; PIJSON ret;
ret.c_type = Object; ret.c_type = Object;
auto it = fields.makeIterator();
while (it.next())
ret[it.key()] = it.value();
return ret; return ret;
} }
PIJSON PIJSON::newArray() { PIJSON PIJSON::newArray(const PIVariantVector & fields) {
PIJSON ret; PIJSON ret;
ret.c_type = Array; ret.c_type = Array;
for (const auto & i: fields)
ret << i;
return ret; return ret;
} }
@@ -325,6 +330,15 @@ PIJSON & PIJSON::operator<<(const PIJSON & element) {
} }
PIJSON & PIJSON::operator<<(const PIVariant & element) {
c_type = Array;
PIJSON e;
e = element;
c_array << e;
return *this;
}
PIJSON & PIJSON::operator=(const PIJSON & v) { PIJSON & PIJSON::operator=(const PIJSON & v) {
c_type = v.c_type; c_type = v.c_type;
c_value = v.c_value; c_value = v.c_value;

View File

@@ -160,6 +160,10 @@ public:
//! \~russian Устанавливает тип элемента в \a PIJSON::Array и добавляет элемент в массив. //! \~russian Устанавливает тип элемента в \a PIJSON::Array и добавляет элемент в массив.
PIJSON & operator<<(const PIJSON & element); PIJSON & operator<<(const PIJSON & element);
//! \~english Set element type to \a PIJSON::Array and add element to the end of array.
//! \~russian Устанавливает тип элемента в \a PIJSON::Array и добавляет элемент в массив.
PIJSON & operator<<(const PIVariant & value);
//! \~english Returns element from map with key "key" if type is \a PIJSON::Object, otherwise returns invalid %PIJSON. //! \~english Returns element from map with key "key" if type is \a PIJSON::Object, otherwise returns invalid %PIJSON.
//! \~russian Возвращает элемент из словаря по ключу "key" если тип \a PIJSON::Object, иначе возвращает недействительный %PIJSON. //! \~russian Возвращает элемент из словаря по ключу "key" если тип \a PIJSON::Object, иначе возвращает недействительный %PIJSON.
@@ -183,8 +187,8 @@ public:
//! \~russian Разбирает текстовое представление JSON "str" и возвращает его корневой элемент. //! \~russian Разбирает текстовое представление JSON "str" и возвращает его корневой элемент.
static PIJSON fromJSON(PIString str); static PIJSON fromJSON(PIString str);
static PIJSON newObject(); static PIJSON newObject(const PIVariantMap & fields = {});
static PIJSON newArray(); static PIJSON newArray(const PIVariantVector & fields = {});
static PIJSON newString(const PIString & v = PIString()); static PIJSON newString(const PIString & v = PIString());
private: private: