Exemplo n.º 1
0
Info::Private::Private(Info *info, const QJsonObject &rootObject)
    : untranslatedGroupName(info->value("X-Kexi-GroupName"))
    , typeName(info->value("X-Kexi-TypeName"))
    , supportedViewModes(0)
    , supportedUserViewModes(0)
    , isVisibleInNavigator(isTrue(info, "X-Kexi-VisibleInProjectNavigator"))
    , isDataExportSupported(isTrue(info, "X-Kexi-SupportsDataExport"))
    , isPrintingSupported(isTrue(info, "X-Kexi-SupportsPrinting"))
    , isExecuteSupported(isTrue(info, "X-Kexi-SupportsExecution"))
    , isPropertyEditorAlwaysVisibleInDesignMode(
          isTrue(info, "X-Kexi-PropertyEditorAlwaysVisibleInDesignMode"))
{
    groupName = info->readTranslatedString(rootObject, "X-Kexi-GroupName", untranslatedGroupName);
    const QStringList serviceTypes = info->serviceTypes();
    if (serviceTypes.contains("Kexi/Viewer")) {
        supportedViewModes |= Kexi::DataViewMode;
    }
    if (serviceTypes.contains("Kexi/Designer")) {
        supportedViewModes |= Kexi::DesignViewMode;
    }
    if (serviceTypes.contains("Kexi/Editor")) {
        supportedViewModes |= Kexi::TextViewMode;
    }

    const QJsonArray userServiceTypes = rootObject.value("X-Kexi-ServiceTypesInUserMode").toArray();
    if (userServiceTypes.contains(QJsonValue("Kexi/Viewer"))) {
        supportedUserViewModes |= Kexi::DataViewMode;
    }
    if (userServiceTypes.contains(QJsonValue("Kexi/Designer"))) {
        supportedUserViewModes |= Kexi::DesignViewMode;
    }
    if (userServiceTypes.contains(QJsonValue("Kexi/Editor"))) {
        supportedUserViewModes |= Kexi::TextViewMode;
    }
}
Exemplo n.º 2
0
int testAndReturnInt(const QJsonArray& arr, int key, Optional optional, int defaultValue)
{
    if (optional == Optional::Yes && !arr.contains(key)) {
        return defaultValue;
    }

    if (!arr.contains(key)) {
        throw std::runtime_error("Missing key '" + std::to_string(key) + "'");
    }
    if (!arr[key].isDouble()) {
        throw std::runtime_error("Key '" + std::to_string(key) + "' is not an integer");
    }

    return arr[key].toInt();
}
Exemplo n.º 3
0
QString testAndReturnString(const QJsonArray& arr, int key, Optional optional,
                            QString defaultValue)
{
    if (optional == Optional::Yes && !arr.contains(key)) {
        return defaultValue;
    }

    if (!arr.contains(key)) {
        throw std::runtime_error("Missing key '" + std::to_string(key) + "'");
    }
    if (!arr[key].isString()) {
        throw std::runtime_error("Key '" + std::to_string(key) + "' is not a string");
    }

    return arr[key].toString();
}
Exemplo n.º 4
0
bool testAndReturnBool(const QJsonArray& arr, int index, Optional optional,
                       bool defaultValue)
{
    if (optional == Optional::Yes && !arr.contains(index)) {
        return defaultValue;
    }

    if (!arr.contains(index)) {
        throw std::runtime_error("Missing key '" + std::to_string(index) + "'");
    }
    if (!arr[index].isBool()) {
        throw std::runtime_error("Key '" + std::to_string(index) + "' is not a boolean");
    }

    return arr[index].toBool();
}
Exemplo n.º 5
0
QJsonObject testAndReturnObject(const QJsonArray& arr, int index, Optional optional,
                                QJsonObject defaultValue)
{
    if (optional == Optional::Yes && !arr.contains(index)) {
        return defaultValue;
    }

    if (!arr.contains(index)) {
        throw std::runtime_error("Missing key '" + std::to_string(index) + "'");
    }
    if (!arr[index].isObject()) {
        throw std::runtime_error("Key '" + std::to_string(index) + "' is not an object");
    }

    return arr[index].toObject();
};
Exemplo n.º 6
0
QString SourceCodeGenerator::processElement(const QDomNode &element, int level) {
    QString sp = QString("  ").repeated(level);
    QJsonObject obj = rule.object().value(element.nodeName()).toObject();
    QString tpl = sp+obj.value("template").toString();
    for(int i = 0; i < element.attributes().size(); ++i) {
       if(obj.contains("list")) {
           QJsonArray list = obj["list"].toArray();
           if (list.contains(QJsonValue(element.attributes().item(i).nodeName()))) {
                QStringList sl = element.attributes().item(i).nodeValue().split(obj["separator"].toString(), QString::SkipEmptyParts);
                QString prefix = obj["prefix"].toString();
                QString suffix = obj["suffix"].toString();
                for(int k=0; k < sl.size(); ++k) {
                    QString s = sl[k];
                    s = prefix + s + suffix;
                    s.replace("%$%", sl[k]);
                    sl[k] = s;
                }
                tpl.replace("%"+element.attributes().item(i).nodeName() + "%", sl.join(obj["glue"].toString()));
           }
           tpl.replace("%"+element.attributes().item(i).nodeName() + "%", element.attributes().item(i).nodeValue());
       }
       else
           tpl.replace("%"+element.attributes().item(i).nodeName() + "%", element.attributes().item(i).nodeValue());

    }
    tpl.replace("\n","\n" + sp);
    tpl.replace("\t", sp);

    for(int i = 0; i < element.childNodes().size(); ++i) {
        if (element.childNodes().item(i).nodeName() == "branch") {
            QDomNode branch = element.childNodes().item(i);
            QString bt = QString("%branch%1%").arg(i + 1);
            QStringList body;
            for(int j = 0; j < branch.childNodes().size(); ++j) {

                body << processElement(branch.childNodes().item(j), level + 1);
            }
            tpl.replace(bt, "\n" + body.join("\n"));
        }
    }
    return tpl;

}
Exemplo n.º 7
0
QStringList testAndReturnStringList(const QJsonArray& arr, int index, Optional optional,
                                    QStringList defaultValue)
{
    if (optional == Optional::Yes && !arr.contains(index)) {
        return defaultValue;
    }

    QStringList result;
    QJsonArray array = testAndReturnArray(arr, index);
    for (const QJsonValue& value : array) {
        if (!value.isString()) {
            throw std::runtime_error(
                "Array '" + std::to_string(index) + "' is not an array of strings"
            );
        }
        result.push_back(value.toString());
    }
    return result;
}
Exemplo n.º 8
0
void LoginHandler::expectIdentified(const protocol::ServerReply &msg)
{
	if(msg.reply["state"] == "needPass") {
		// Looks like guest logins are not possible
		m_needUserPassword = true;
		prepareToSendIdentity();
		return;
	}

	if(msg.reply["state"] != "identOk") {
		qWarning() << "Expected identOk state, got" << msg.reply["state"];
		failLogin(tr("Invalid state"));
		return;
	}

	//bool isGuest = msg.reply["guest"].toBool();
	QJsonArray flags = msg.reply["flags"].toArray();

	if(m_mode == HOST) {
		m_state = EXPECT_SESSIONLIST_TO_HOST;

		// Query host password if needed
		if(m_mode == HOST && m_needHostPassword && !flags.contains("HOST")) {
			showPasswordDialog(tr("Password is needed to host a session"), tr("Enter hosting password"));
		}

	} else {
		// Show session selector if in multisession mode
		if(m_multisession) {
			_selectorDialog = new dialogs::SelectSessionDialog(m_sessions, _widgetParent);
			_selectorDialog->setWindowModality(Qt::WindowModal);
			_selectorDialog->setAttribute(Qt::WA_DeleteOnClose);

			connect(_selectorDialog, SIGNAL(selected(QString,bool)), this, SLOT(joinSelectedSession(QString,bool)));
			connect(_selectorDialog, SIGNAL(rejected()), this, SLOT(cancelLogin()));

			_selectorDialog->show();
		}

		m_state = EXPECT_SESSIONLIST_TO_JOIN;
	}
}
QJsonObject DomainServerSettingsManager::responseObjectForType(const QString& typeValue, bool isAuthenticated) {
    QJsonObject responseObject;
    
    if (!typeValue.isEmpty() || isAuthenticated) {
        // convert the string type value to a QJsonValue
        QJsonValue queryType = typeValue.isEmpty() ? QJsonValue() : QJsonValue(typeValue.toInt());
        
        const QString AFFECTED_TYPES_JSON_KEY = "assignment-types";
        
        // enumerate the groups in the description object to find which settings to pass
        foreach(const QJsonValue& groupValue, _descriptionArray) {
            QJsonObject groupObject = groupValue.toObject();
            QString groupKey = groupObject[DESCRIPTION_NAME_KEY].toString();
            QJsonArray groupSettingsArray = groupObject[DESCRIPTION_SETTINGS_KEY].toArray();
            
            QJsonObject groupResponseObject;
            
            foreach(const QJsonValue& settingValue, groupSettingsArray) {
                const QString VALUE_HIDDEN_FLAG_KEY = "value-hidden";
                
                QJsonObject settingObject = settingValue.toObject();
                
                if (!settingObject[VALUE_HIDDEN_FLAG_KEY].toBool()) {
                    QJsonArray affectedTypesArray = settingObject[AFFECTED_TYPES_JSON_KEY].toArray();
                    if (affectedTypesArray.isEmpty()) {
                        affectedTypesArray = groupObject[AFFECTED_TYPES_JSON_KEY].toArray();
                    }
                    
                    if (affectedTypesArray.contains(queryType) ||
                        (queryType.isNull() && isAuthenticated)) {
                        // this is a setting we should include in the responseObject
                        
                        QString settingName = settingObject[DESCRIPTION_NAME_KEY].toString();
                        
                        // we need to check if the settings map has a value for this setting
                        QVariant variantValue;
                        QVariant settingsMapGroupValue = _settingsMap.value(groupObject[DESCRIPTION_NAME_KEY].toString());
                        
                        if (!settingsMapGroupValue.isNull()) {
                            variantValue = settingsMapGroupValue.toMap().value(settingName);
                        }
                        
                        if (variantValue.isNull()) {
                            // no value for this setting, pass the default
                            if (settingObject.contains(SETTING_DEFAULT_KEY)) {
                                groupResponseObject[settingName] = settingObject[SETTING_DEFAULT_KEY];
                            } else {
                                // users are allowed not to provide a default for string values
                                // if so we set to the empty string
                                groupResponseObject[settingName] = QString("");
                            }
                            
                        } else {
                            groupResponseObject[settingName] = QJsonValue::fromVariant(variantValue);
                        }
                    }
                }
            }
            
            if (!groupResponseObject.isEmpty()) {
                // set this group's object to the constructed object
                responseObject[groupKey] = groupResponseObject;
            }
        }
bool DomainServerSettingsManager::handleHTTPRequest(HTTPConnection* connection, const QUrl &url) {
    if (connection->requestOperation() == QNetworkAccessManager::PostOperation && url.path() == "/settings.json") {
        // this is a POST operation to change one or more settings
        QJsonDocument postedDocument = QJsonDocument::fromJson(connection->requestContent());
        QJsonObject postedObject = postedDocument.object();
        
        // we recurse one level deep below each group for the appropriate setting
        recurseJSONObjectAndOverwriteSettings(postedObject, _settingsMap, _descriptionObject);
        
        // store whatever the current _settingsMap is to file
        persistToFile();
        
        // return success to the caller
        QString jsonSuccess = "{\"status\": \"success\"}";
        connection->respond(HTTPConnection::StatusCode200, jsonSuccess.toUtf8(), "application/json");
        
        return true;
    } else if (connection->requestOperation() == QNetworkAccessManager::GetOperation && url.path() == "/settings.json") {
        // this is a GET operation for our settings
        
        // check if there is a query parameter for settings affecting a particular type of assignment
        const QString SETTINGS_TYPE_QUERY_KEY = "type";
        QUrlQuery settingsQuery(url);
        QString typeValue = settingsQuery.queryItemValue(SETTINGS_TYPE_QUERY_KEY);
        
        QJsonObject responseObject;
        
        if (typeValue.isEmpty()) {
            // combine the description object and our current settings map
            responseObject["descriptions"] = _descriptionObject;
            responseObject["values"] = QJsonDocument::fromVariant(_settingsMap).object();
        } else {
            // convert the string type value to a QJsonValue
            QJsonValue queryType = QJsonValue(typeValue.toInt());
            
            const QString AFFECTED_TYPES_JSON_KEY = "assignment-types";
            
            // enumerate the groups in the description object to find which settings to pass
            foreach(const QString& group, _descriptionObject.keys()) {
                QJsonObject groupObject = _descriptionObject[group].toObject();
                QJsonObject groupSettingsObject = groupObject[DESCRIPTION_SETTINGS_KEY].toObject();
                
                QJsonObject groupResponseObject;
                
                
                foreach(const QString& settingKey, groupSettingsObject.keys()) {
                    QJsonObject settingObject = groupSettingsObject[settingKey].toObject();
                    
                    QJsonArray affectedTypesArray = settingObject[AFFECTED_TYPES_JSON_KEY].toArray();
                    if (affectedTypesArray.isEmpty()) {
                        affectedTypesArray = groupObject[AFFECTED_TYPES_JSON_KEY].toArray();
                    }
                    
                    if (affectedTypesArray.contains(queryType)) {
                        // this is a setting we should include in the responseObject
                        
                        // we need to check if the settings map has a value for this setting
                        QVariant variantValue;
                        QVariant settingsMapGroupValue = _settingsMap.value(group);
                        
                        if (!settingsMapGroupValue.isNull()) {
                            variantValue = settingsMapGroupValue.toMap().value(settingKey);
                        }
                        
                        if (variantValue.isNull()) {
                            // no value for this setting, pass the default
                            groupResponseObject[settingKey] = settingObject[SETTING_DEFAULT_KEY];
                        } else {
                            groupResponseObject[settingKey] = QJsonValue::fromVariant(variantValue);
                        }
                    }
                }
                
                if (!groupResponseObject.isEmpty()) {
                    // set this group's object to the constructed object
                    responseObject[group] = groupResponseObject;
                }
            }
            
        }
        
        connection->respond(HTTPConnection::StatusCode200, QJsonDocument(responseObject).toJson(), "application/json");
        return true;
    }
    
    return false;
}