2021-12-07 14:09:24 +08:00
|
|
|
#include "jsonobject.h"
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <QTranslator>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QApplication>
|
2021-12-08 10:52:38 +08:00
|
|
|
#include "json/cJSON.h"
|
2021-12-07 14:09:24 +08:00
|
|
|
const char* strProductFileName = "./cfgs/usct-product.json";
|
|
|
|
|
|
|
|
|
|
JsonObject::JsonObject()
|
|
|
|
|
{
|
|
|
|
|
loadcfg();
|
|
|
|
|
}
|
|
|
|
|
JsonObject::~JsonObject()
|
|
|
|
|
{
|
|
|
|
|
savecfg();
|
|
|
|
|
|
|
|
|
|
}
|
2021-12-09 10:00:01 +08:00
|
|
|
void JsonObject::setJsonString(const char* catergory, const char* stringName, const char* stringValue, bool save)
|
2021-12-07 14:09:24 +08:00
|
|
|
{
|
|
|
|
|
if (!loadcfg())
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-08 10:52:38 +08:00
|
|
|
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, catergory);
|
2021-12-07 14:09:24 +08:00
|
|
|
if (!first) return;
|
|
|
|
|
|
|
|
|
|
cJSON* Item = cJSON_CreateString(stringValue);
|
|
|
|
|
cJSON_ReplaceItemInObject(first, stringName, Item);
|
2021-12-09 10:00:01 +08:00
|
|
|
if (save)
|
|
|
|
|
{
|
|
|
|
|
savecfg();
|
|
|
|
|
}
|
2021-12-07 14:09:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* JsonObject::getJsonString(const char* catergory, const char* stringName)
|
|
|
|
|
{
|
|
|
|
|
if (!loadcfg())
|
|
|
|
|
return "";
|
|
|
|
|
|
2021-12-08 10:52:38 +08:00
|
|
|
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, catergory);
|
2021-12-07 14:09:24 +08:00
|
|
|
if (!first) return "";
|
|
|
|
|
|
|
|
|
|
cJSON* second = cJSON_FindItemInObject(first, stringName);
|
|
|
|
|
return second->valuestring;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList JsonObject::protocals()
|
|
|
|
|
{
|
|
|
|
|
if (!loadcfg())
|
|
|
|
|
return QStringList();
|
|
|
|
|
|
2021-12-08 10:52:38 +08:00
|
|
|
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, "protocol");
|
2021-12-07 14:09:24 +08:00
|
|
|
if (!first) return QStringList();
|
|
|
|
|
|
|
|
|
|
cJSON* second = cJSON_FindItemInObject(first, "lists");
|
|
|
|
|
std::string lans = second->valuestring;
|
|
|
|
|
QString str = QString::fromLocal8Bit(QByteArray::fromRawData(lans.c_str(), lans.size()));
|
|
|
|
|
return str.split(";");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonObject::defaultProtocal()
|
|
|
|
|
{
|
|
|
|
|
char* str = getJsonString("protocol", "default");
|
|
|
|
|
return QString(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonObject::setDefaultProtocal(QString str)
|
|
|
|
|
{
|
|
|
|
|
setJsonString("protocol", "default", str.toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonObject::defaultFilter()
|
|
|
|
|
{
|
|
|
|
|
char* str = getJsonString("worklistfilter", "default");
|
|
|
|
|
return QString(str);
|
|
|
|
|
}
|
|
|
|
|
void JsonObject::setDefaultFilter(QString str)
|
|
|
|
|
{
|
|
|
|
|
setJsonString("worklistfilter", "default", str.toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
QStringList JsonObject::worklistFilters()
|
|
|
|
|
{
|
|
|
|
|
if (!loadcfg())
|
|
|
|
|
return QStringList();
|
|
|
|
|
|
2021-12-08 10:52:38 +08:00
|
|
|
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, "worklistfilter");
|
2021-12-07 14:09:24 +08:00
|
|
|
if (!first) return QStringList();
|
|
|
|
|
|
|
|
|
|
cJSON* second = cJSON_FindItemInObject(first, "lists");
|
|
|
|
|
std::string lans = second->valuestring;
|
|
|
|
|
QString str = QString::fromLocal8Bit(QByteArray::fromRawData(lans.c_str(), lans.size()));
|
|
|
|
|
return str.split(";");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList JsonObject::language()
|
|
|
|
|
{
|
|
|
|
|
if (!loadcfg())
|
|
|
|
|
return QStringList();
|
|
|
|
|
|
2021-12-08 10:52:38 +08:00
|
|
|
cJSON* first = cJSON_FindItemInObject((cJSON*)json_root, "general");
|
2021-12-07 14:09:24 +08:00
|
|
|
if (!first) return QStringList();
|
|
|
|
|
|
|
|
|
|
cJSON* second = cJSON_FindItemInObject(first, "language");
|
|
|
|
|
std::string lans = second->valuestring;
|
|
|
|
|
QString str = QString::fromLocal8Bit(QByteArray::fromRawData(lans.c_str(), lans.size()));
|
|
|
|
|
return str.split(";");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonObject::setDefaultLanguage(QString str)
|
|
|
|
|
{
|
|
|
|
|
setJsonString("general", "defaultlanguage", str.toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonObject::defaultLanguage()
|
|
|
|
|
{
|
|
|
|
|
char* str = getJsonString("general", "defaultlanguage");
|
|
|
|
|
return QString(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonObject::institutionName()
|
|
|
|
|
{
|
|
|
|
|
char* str = getJsonString("general", "institutionName");
|
|
|
|
|
return QString(str);
|
|
|
|
|
}
|
|
|
|
|
void JsonObject::setInstitutionName(QString str)
|
|
|
|
|
{
|
|
|
|
|
setJsonString("general", "institutionName", str.toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonObject::institutionAddr()
|
|
|
|
|
{
|
|
|
|
|
char* str = getJsonString("general", "institutionAddr");
|
|
|
|
|
return QString(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonObject::setInstitutionAddr(QString str)
|
|
|
|
|
{
|
|
|
|
|
setJsonString("general", "institutionAddr", str.toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int JsonObject::lockerCount()
|
|
|
|
|
{
|
|
|
|
|
char* str = getJsonString("general", "lockscreen");
|
|
|
|
|
int interval = QString(str).toInt() * 1000;
|
|
|
|
|
return interval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString JsonObject::lockScreenTimeout()
|
|
|
|
|
{
|
|
|
|
|
char* str = getJsonString("general", "lockscreen");
|
|
|
|
|
return QString(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonObject::setLockScreenTimeout(QString str)
|
|
|
|
|
{
|
|
|
|
|
setJsonString("general", "lockscreen", str.toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JsonObject::loadcfg()
|
|
|
|
|
{
|
|
|
|
|
if (m_bLoaded)
|
|
|
|
|
return true;
|
|
|
|
|
std::ifstream inFile(strProductFileName);
|
|
|
|
|
if (!inFile.is_open())
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << inFile.rdbuf();
|
|
|
|
|
std::string strJsonData = ss.str();
|
|
|
|
|
json_root = cJSON_Parse(strJsonData.c_str());
|
|
|
|
|
|
|
|
|
|
//modify somthing
|
|
|
|
|
//QJsonValueRef ref = m_JsonRootObject.find("general").value();
|
|
|
|
|
//QJsonObject obj = ref.toObject();
|
|
|
|
|
//obj["language"] = language;
|
|
|
|
|
|
|
|
|
|
//cJSON* parent = cJSON_FindItemInObject(json_root, "waitinglist");
|
|
|
|
|
//if (parent)
|
|
|
|
|
//{
|
|
|
|
|
// //const char* newtime = QDateTime::currentDateTime().toString("yyyyMMdd").toStdString().c_str();
|
|
|
|
|
// cJSON* Item = cJSON_CreateString(QDateTime::currentDateTime().toString("yyyy-MM-dd").toStdString().c_str());
|
|
|
|
|
// cJSON_ReplaceItemInObject(parent, "waitinglistDefaultDate", Item);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//cJSON* parent = cJSON_FindItemInObject(json_root, "pacsservers");
|
|
|
|
|
//if (parent)
|
|
|
|
|
//{
|
|
|
|
|
// cJSON* p2 = cJSON_FindItemInArray(parent, 1);
|
|
|
|
|
// cJSON* Item = cJSON_CreateString("KISS");
|
|
|
|
|
// //const char* newtime = QDateTime::currentDateTime().toString("yyyyMMdd").toStdString().c_str();
|
|
|
|
|
// cJSON_ReplaceItemInObject(p2, "ae", Item);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
inFile.close();
|
|
|
|
|
m_bLoaded = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool JsonObject::savecfg()
|
|
|
|
|
{
|
|
|
|
|
if (!m_bLoaded)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
std::ofstream outFile(strProductFileName);
|
|
|
|
|
if (!outFile.is_open())
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 10:52:38 +08:00
|
|
|
char* strJsonData = cJSON_Print((cJSON*)json_root);
|
2021-12-07 14:09:24 +08:00
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << strJsonData;
|
|
|
|
|
outFile << ss.rdbuf();
|
|
|
|
|
outFile.close();
|
|
|
|
|
m_bLoaded = false;
|
|
|
|
|
return true;
|
2021-12-09 10:00:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
host JsonObject::getServer(ServerType type)
|
|
|
|
|
{
|
|
|
|
|
QString typeName;
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
case JsonObject::WORKLIST:
|
|
|
|
|
typeName = "worklist";
|
|
|
|
|
break;
|
|
|
|
|
case JsonObject::PACS:
|
|
|
|
|
typeName = "pacs";
|
|
|
|
|
break;
|
|
|
|
|
case JsonObject::DAQ:
|
|
|
|
|
typeName = "daq";
|
|
|
|
|
break;
|
|
|
|
|
case JsonObject::RECON:
|
|
|
|
|
typeName = "recon";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
host list;
|
|
|
|
|
list.ae = QString(getJsonString(typeName.toStdString().c_str(), "ae"));
|
|
|
|
|
list.ip = QString(getJsonString(typeName.toStdString().c_str(), "ip"));
|
|
|
|
|
list.name = QString(getJsonString(typeName.toStdString().c_str(), "name"));
|
|
|
|
|
list.port = QString(getJsonString(typeName.toStdString().c_str(), "port"));
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonObject::setServer(ServerType type, const host& list)
|
|
|
|
|
{
|
|
|
|
|
QString typeName;
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
case JsonObject::WORKLIST:
|
|
|
|
|
typeName = "worklist";
|
|
|
|
|
break;
|
|
|
|
|
case JsonObject::PACS:
|
|
|
|
|
typeName = "pacs";
|
|
|
|
|
break;
|
|
|
|
|
case JsonObject::DAQ:
|
|
|
|
|
typeName = "daq";
|
|
|
|
|
break;
|
|
|
|
|
case JsonObject::RECON:
|
|
|
|
|
typeName = "recon";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
setJsonString(typeName.toStdString().c_str(), "ae", list.ae.toStdString().c_str(), false);
|
|
|
|
|
setJsonString(typeName.toStdString().c_str(), "ip", list.ip.toStdString().c_str(), false);
|
|
|
|
|
setJsonString(typeName.toStdString().c_str(), "name", list.name.toStdString().c_str(), false);
|
|
|
|
|
setJsonString(typeName.toStdString().c_str(), "port", list.port.toStdString().c_str(), false);
|
|
|
|
|
|
|
|
|
|
savecfg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
localhost JsonObject::getLocalHost()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
localhost lhost;
|
|
|
|
|
lhost.ip = QString(getJsonString("localhost", "ip"));
|
|
|
|
|
lhost.mask = QString(getJsonString("localhost", "mask"));
|
|
|
|
|
lhost.gateway = QString(getJsonString("localhost", "gateway"));
|
|
|
|
|
return lhost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void JsonObject::setLocalHost(const localhost& lh)
|
|
|
|
|
{
|
|
|
|
|
setJsonString("localhost", "ip", lh.ip.toStdString().c_str(), false);
|
|
|
|
|
setJsonString("localhost", "mask", lh.mask.toStdString().c_str(), false);
|
|
|
|
|
setJsonString("localhost", "gateway", lh.gateway.toStdString().c_str(), false);
|
|
|
|
|
|
|
|
|
|
savecfg();
|
2021-12-07 14:09:24 +08:00
|
|
|
}
|