Example #1
0
/**
 * Handles the versions loading
 *
 * @brief OwnCloudService::handleVersionsLoading
 * @param data
 */
void OwnCloudService::handleVersionsLoading(QString data) {
    mainWindow->enableShowVersionsButton();
    mainWindow->showStatusBarMessage(
            tr("done with loading note versions"), 2000);

    // check if we get any data at all
    if (data.isEmpty()) {
        showOwnCloudServerErrorMessage();
        return;
    }

    // we have to add [], so the string can be parsed as JSON
    data = QString("[") + data + QString("]");

    QJSEngine engine;
    QJSValue result = engine.evaluate(data);

    // get the information if versioning is available
    // we are casting to QVariant first because otherwise we might get a
    // "undefined" string if "message" is not set
    QString message = result.property(0).property("message").toVariant()
            .toString();

    // check if we got an error message
    if (!message.isEmpty()) {
        showOwnCloudServerErrorMessage(message);
        return;
    }

    // get the filename to check if everything is all right
    QString fileName = result.property(0).property("file_name").toVariant()
            .toString();

    // get the versions
    QJSValue versions = result.property(0).property("versions");
    QJSValueIterator versionsIterator(versions);

    // check if we got no useful data, we also need to do this to prevent crashs
    if (fileName.isEmpty() || !versionsIterator.hasNext() ||
            versions.toString().isEmpty()) {
        QMessageBox::information(
                0, tr("no other version"),
                tr("There are no other versions on the server for this note."));
        return;
    }

    VersionDialog *dialog = new VersionDialog(versions, mainWindow);
    dialog->exec();
}
Example #2
0
/**
 * Handles the versions loading
 *
 * @brief OwnCloudService::handleVersionsLoading
 * @param data
 */
void OwnCloudService::handleVersionsLoading(QString data) {
    // check if we get any data at all
    if (data == "") {
        if (QMessageBox::critical(
                0, "ownCloud server connection error!",
                "Cannot connect to the ownCloud server!<br />"
                        "Please check your configuration in the settings!",
                "Open &settings", "&Cancel", QString::null, 0, 1) == 0) {
            mainWindow->openSettingsDialog();
        }

        return;
    }

    // we have to add [], so the string can be parsed as JSON
    data = QString("[") + data + QString("]");

    QScriptEngine engine;
    QScriptValue result = engine.evaluate(data);

    // get the information if versioning is available
    QString message = result.property(0).property("message").toString();

    // check if we got an error message
    if (message != "") {
        if (QMessageBox::critical(
                0, "ownCloud server connection error!",
                "ownCloud server error: <strong>" + message + "</strong><br />"
                        "Please check your configuration in the settings!",
                "Open &settings", "&Cancel", QString::null, 0, 1) == 0) {
            mainWindow->openSettingsDialog();
        }

        return;
    }

    // get the filename to check if everything is all right
    QScriptValue fileName = result.property(0).property("file_name");

    // check if we got no usefull data
    if (fileName.toString() == "") {
        if (QMessageBox::critical(
                0, "ownCloud server connection error!",
                "QOwnNotes was unable to connect to your ownCloud server! "
                        "Please check the configuration in the settings!",
                "Open &settings", "&Cancel", QString::null, 0, 1) == 0) {
            mainWindow->openSettingsDialog();
        }

        return;
    }

    // get the versions
    QScriptValue versions = result.property(0).property("versions");

    // check if we got no useful data
    if (versions.toString() == "") {
        QMessageBox::information(
                0, "no other version",
                "There are no other versions on the server for this note.");
        return;
    }

    VersionDialog *dialog = new VersionDialog(versions, mainWindow);
    dialog->exec();
}