示例#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();
}
示例#2
0
VersionDialog::VersionDialog(QScriptValue versions, MainWindow *mainWindow, QWidget *parent) :
        MasterDialog(parent),
    ui(new Ui::VersionDialog)
{
    this->mainWindow = mainWindow;
    ui->setupUi(this);

    setupMainSplitter();

    QPushButton *button;
    ui->buttonBox->clear();

    button = new QPushButton( tr( "&Restore selected version" ) );
    button->setProperty( "ActionRole", Restore );
    button->setDefault( false );
    button->setIcon( QIcon( ":/images/breeze/edit-download.svg" ) );
    ui->buttonBox->addButton( button, QDialogButtonBox::ActionRole );

    button = new QPushButton( tr( "&Cancel" ) );
    button->setProperty( "ActionRole", Cancel );
    button->setIcon( QIcon( ":/images/breeze/dialog-cancel.svg" ) );
    button->setDefault( true );
    ui->buttonBox->addButton( button, QDialogButtonBox::ActionRole );

    connect( this->ui->buttonBox, SIGNAL( clicked( QAbstractButton* ) ), SLOT( dialogButtonClicked( QAbstractButton* ) ) );
    connect( this, SIGNAL( finished(int) ), this, SLOT( storeSettings() ) );

    QString itemName;
    QString diffHtml;
    ui->versionListWidget->clear();
    diffList = new QStringList();
    dataList = new QStringList();

    // init the iterator for the verions
    QScriptValueIterator versionsIterator( versions );

    // iterate over the versions
    while ( versionsIterator.hasNext() ) {
        versionsIterator.next();
//        qDebug() << versionsIterator.name() << ": " << versionsIterator.value().property( "timestamp" ).toString() << " - " << versionsIterator.value().property( "humanReadableTimestamp" ).toString() << " - " << versionsIterator.value().property( "diffHtml" ).toString();

        itemName = versionsIterator.value().property( "humanReadableTimestamp" ).toString();

        if ( itemName == "" ) {
            continue;
        }

        diffHtml = versionsIterator.value().property( "diffHtml" ).toString();
        diffHtml.replace( "<ins>", "<span style='background-color: rgb(214, 255, 199)'>" );
        diffHtml.replace( "</ins>", "</span>" );
        diffHtml.replace( "<del>", "<span style='background-color: rgb(255, 215, 215)'>" );
        diffHtml.replace( "</del>", "</span>" );
        diffHtml.replace( "\n", "<br />" );

        ui->versionListWidget->addItem( itemName );
        diffList->append( diffHtml );
        dataList->append( versionsIterator.value().property( "data" ).toString() );
    }

    ui->versionListWidget->setCurrentRow( 0 );
    ui->diffBrowser->setHtml( diffList->at( 0 ) );
}