コード例 #1
0
DomainServerSettingsManager::DomainServerSettingsManager() :
    _descriptionArray(),
    _configMap()
{
    // load the description object from the settings description
    QFile descriptionFile(QCoreApplication::applicationDirPath() + SETTINGS_DESCRIPTION_RELATIVE_PATH);
    descriptionFile.open(QIODevice::ReadOnly);

    QJsonDocument descriptionDocument = QJsonDocument::fromJson(descriptionFile.readAll());

    if (descriptionDocument.isObject()) {
        QJsonObject descriptionObject = descriptionDocument.object();

        const QString DESCRIPTION_VERSION_KEY = "version";

        if (descriptionObject.contains(DESCRIPTION_VERSION_KEY)) {
            // read the version from the settings description
            _descriptionVersion = descriptionObject[DESCRIPTION_VERSION_KEY].toDouble();

            if (descriptionObject.contains(DESCRIPTION_SETTINGS_KEY)) {
                _descriptionArray = descriptionDocument.object()[DESCRIPTION_SETTINGS_KEY].toArray();
                return;
            }
        }
    }

    static const QString MISSING_SETTINGS_DESC_MSG =
        QString("Did not find settings decription in JSON at %1 - Unable to continue. domain-server will quit.")
        .arg(SETTINGS_DESCRIPTION_RELATIVE_PATH);
    static const int MISSING_SETTINGS_DESC_ERROR_CODE = 6;

    QMetaObject::invokeMethod(QCoreApplication::instance(), "queuedQuit", Qt::QueuedConnection,
                              Q_ARG(QString, MISSING_SETTINGS_DESC_MSG),
                              Q_ARG(int, MISSING_SETTINGS_DESC_ERROR_CODE));
}
コード例 #2
0
DomainServerSettingsManager::DomainServerSettingsManager() :
    _descriptionArray(),
    _settingsMap()
{
    // load the description object from the settings description
    QFile descriptionFile(QCoreApplication::applicationDirPath() + SETTINGS_DESCRIPTION_RELATIVE_PATH);
    descriptionFile.open(QIODevice::ReadOnly);
    
    _descriptionArray = QJsonDocument::fromJson(descriptionFile.readAll()).array();
}
コード例 #3
0
void FileController::setFileTranslation(const QString fileName, const QString translation)
{
    qDebug() << "FileController::setFileTranslation >> " << fileName << " : " << translation;
    QString path = getUserFilesDir() + fileName + TRANSL_TYPE;
    QFile descriptionFile(path);
    if (descriptionFile.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        QTextStream out(&descriptionFile);
        out.setCodec("UTF-8");
        out.setGenerateByteOrderMark(true);
        out << translation.toUtf8();
        descriptionFile.close();
    }
}
コード例 #4
0
ファイル: usage.cpp プロジェクト: stefanhans/ContextRouting
int usage(QStringList commands) {
    //qDebug() << "usage(" << commands.join(" ") << ")" << endl;

    /**
     * Check input
     */
    if(commands.size() < 2 ) {

        errorStream << "Error: usage(" << commands.join(" ") << ") has not enough parameters (usage cmd ...)" << endl;
        return 1;
    }

    if(commands.at(0)!="usage") {

        errorStream << "Error: usage(" << commands.join(" ") << ") is no valid call (usage cmd ...)" << endl;
        return 1;
    }

    QString filePath;

    /**
     * Read usage file
     */

    filePath = HELP_DIR;
    commands.pop_front();
    filePath += "/" + commands.join("/") + "/usage";

    //qDebug() << filePath << endl;



    QFile descriptionFile(filePath);
    if (!descriptionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {

        errorStream << "Error: usage(" << commands.join(" ") << ") can not read usage file " << filePath << endl;
        return 1;
    }

    while (!descriptionFile.atEnd()) {
        QByteArray line = descriptionFile.readLine();
        outStream << line << endl;
    }
    descriptionFile.close();


    return 0;
}
コード例 #5
0
DomainServerSettingsManager::DomainServerSettingsManager() :
    _descriptionObject(),
    _settingsMap()
{
    // load the description object from the settings description
    QFile descriptionFile(QCoreApplication::applicationDirPath() + SETTINGS_DESCRIPTION_RELATIVE_PATH);
    descriptionFile.open(QIODevice::ReadOnly);
    
    _descriptionObject = QJsonDocument::fromJson(descriptionFile.readAll()).object();
    
    // load the existing config file to get the current values
    QFile configFile(QCoreApplication::applicationDirPath() + SETTINGS_CONFIG_FILE_RELATIVE_PATH);
    
    if (configFile.exists()) {
        configFile.open(QIODevice::ReadOnly);
        
        _settingsMap = QJsonDocument::fromJson(configFile.readAll()).toVariant().toMap();
    }
}
コード例 #6
0
bool AppManager::readApp()
{
    QFile descriptionFile(QCoreApplication::applicationDirPath() + "/description.json");

    if(!descriptionFile.exists()) {

        qDebug() << "Não tem o arquivo!";
        qDebug() << "CURRENT DIR : " << descriptionFile.fileName();

        return false;
    }

    descriptionFile.open(QIODevice::ReadOnly);

    QJsonDocument doc = QJsonDocument::fromJson(descriptionFile.readAll());
    QJsonObject jsonObj = doc.object();

    qDebug() << "URL : " << jsonObj["url"].toString();
    qDebug() << "TITLE : " << jsonObj["title"].toString();

    emit appReaded(jsonObj["url"].toString(), jsonObj["title"].toString());
    descriptionFile.close();
}