[add] system setting
This commit is contained in:
@@ -19,7 +19,7 @@ JsonObject::~JsonObject()
|
||||
savecfg();
|
||||
|
||||
}
|
||||
void JsonObject::setJsonString(const char* catergory, const char* stringName, const char* stringValue)
|
||||
void JsonObject::setJsonString(const char* catergory, const char* stringName, const char* stringValue, bool save)
|
||||
{
|
||||
if (!loadcfg())
|
||||
return;
|
||||
@@ -29,8 +29,10 @@ void JsonObject::setJsonString(const char* catergory, const char* stringName, co
|
||||
|
||||
cJSON* Item = cJSON_CreateString(stringValue);
|
||||
cJSON_ReplaceItemInObject(first, stringName, Item);
|
||||
|
||||
savecfg();
|
||||
if (save)
|
||||
{
|
||||
savecfg();
|
||||
}
|
||||
}
|
||||
|
||||
char* JsonObject::getJsonString(const char* catergory, const char* stringName)
|
||||
@@ -74,8 +76,6 @@ void JsonObject::setDefaultProtocal(QString str)
|
||||
setJsonString("protocol", "default", str.toStdString().c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString JsonObject::defaultFilter()
|
||||
{
|
||||
char* str = getJsonString("worklistfilter", "default");
|
||||
@@ -227,4 +227,83 @@ bool JsonObject::savecfg()
|
||||
outFile.close();
|
||||
m_bLoaded = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -6,24 +6,33 @@ class QString;
|
||||
class QStringList;
|
||||
class QTranslator;
|
||||
|
||||
//#define setJsonString(catergory,stringName,stringValue)\
|
||||
// if (!loadcfg())\
|
||||
// return;\
|
||||
// cJSON* first = cJSON_FindItemInObject(json_root, #catergory);\
|
||||
// if (first){\
|
||||
// cJSON* Item = cJSON_CreateString(#stringValue);\
|
||||
// cJSON_ReplaceItemInObject(first, #stringName, Item);\
|
||||
// }\
|
||||
// savecfg();
|
||||
|
||||
struct host {
|
||||
QString name;
|
||||
QString ae;
|
||||
QString ip;
|
||||
QString port;
|
||||
//QString isDefault;
|
||||
};
|
||||
struct localhost {
|
||||
QString ip;
|
||||
QString mask;
|
||||
QString gateway;
|
||||
};
|
||||
|
||||
class JsonObject
|
||||
{
|
||||
public:
|
||||
|
||||
static JsonObject* Instance()
|
||||
{
|
||||
static JsonObject obj;
|
||||
return &obj;
|
||||
}
|
||||
enum ServerType
|
||||
{
|
||||
WORKLIST, PACS, DAQ, RECON
|
||||
};
|
||||
|
||||
QStringList language();
|
||||
void setDefaultLanguage(QString str);
|
||||
@@ -49,8 +58,14 @@ public:
|
||||
QString defaultFilter();
|
||||
void setDefaultFilter(QString str);
|
||||
|
||||
host getServer(ServerType type);
|
||||
void setServer(ServerType type, const host& list);
|
||||
|
||||
localhost getLocalHost();
|
||||
void setLocalHost(const localhost& lh);
|
||||
|
||||
private:
|
||||
void setJsonString(const char* catergory, const char* stringName, const char* stringValue);
|
||||
void setJsonString(const char* catergory, const char* stringName, const char* stringValue, bool save = true);
|
||||
char* getJsonString(const char* catergory, const char* stringName);
|
||||
|
||||
bool loadcfg();
|
||||
|
||||
Reference in New Issue
Block a user