#include "SettingConfig.h"
#include <QApplication>


SettingConfig::SettingConfig()
{
    filename = QApplication::applicationDirPath() + "/conf/config.ini";
    setting = new QSettings(this->filename, QSettings::IniFormat);
    setting->setIniCodec("UTF-8");

    init();
}


QVariant SettingConfig::getProperty(QString nodeName, QString keyName) {
    QVariant var = this->setting->value(QString("/%1/%2").arg(nodeName).arg(keyName));
    return var;
}

void SettingConfig::setProperty(QString nodeName, QString keyName, QString value) {
    this->setting->setValue(QString("/%1/%2").arg(nodeName).arg(keyName), value);
}

void SettingConfig::init()
{
    LOCAL_Mode = getProperty("database", "localMode").toString();
    LOCAL_HOST = getProperty("database", "localHost").toString();
    LOCAL_ODBC_NAME = getProperty("database", "localODBCName").toString();
    LOCAL_USERNAME = getProperty("database", "localUserName").toString();
    LOCAL_PASSWORD = getProperty("database", "localPassword").toString();
    LOCAL_PORT = getProperty("database", "localPort").toString();
    LOCAL_SCHEMA = getProperty("database", "localSchema").toString();

    REMOTE_HOST = getProperty("database", "remoteHost").toString();
    REMOTE_ODBC_NAME = getProperty("database", "remoteODBCName").toString();
    REMOTE_USERNAME = getProperty("database", "remoteUserName").toString();
    REMOTE_PASSWORD = getProperty("database", "remotePassword").toString();

    CLIENT_TITLE = getProperty("client", "title").toString();
    BASE_LOG_PATH = getProperty("client", "baseLogPath").toString();
    BASE_RES_FILE_PATH = getProperty("client", "baseResFilePath").toString();
    BASE_CER_FILE_PATH = getProperty("client", "baseCertificateFilePaht").toString();
    BASE_HTTP_FILE = getProperty("client", "baseHttpPath").toString();
}
