Пример #1
0
int Note::storeDirtyNotesToDisk( Note &currentNote ) {
    QSqlQuery query;
    Note note;
//    qDebug() << "storeDirtyNotesToDisk";

    query.prepare( "SELECT * FROM note WHERE has_dirty_data = 1" );
    if( !query.exec() )
    {
        qDebug() << __func__ << ": " << query.lastError();
        return 0;
    }
    else
    {
        int count = 0;
        for( int r=0; query.next(); r++ )
        {
            note = noteFromQuery( query );
            QString oldFileName = note.getFileName();
            note.storeNoteTextFileToDisk();
            QString newFileName = note.getFileName();

            // reassign currentNote if filename of currentNote has changed
            if ( ( oldFileName == currentNote.getFileName() ) && ( oldFileName != newFileName ) )
            {
                currentNote = note;
                qDebug() << "filename of currentNote has changed to: " << newFileName;
            }

            qDebug() << "stored note: " << note;
            count++;
        }

        return count;
    }
}
Пример #2
0
int Note::storeDirtyNotesToDisk(Note &currentNote) {
    QSqlDatabase db = QSqlDatabase::database("memory");
    QSqlQuery query(db);
    ScriptingService* scriptingService = ScriptingService::instance();
    Note note;
//    qDebug() << "storeDirtyNotesToDisk";

    query.prepare("SELECT * FROM note WHERE has_dirty_data = 1");
    if (!query.exec()) {
        qWarning() << __func__ << ": " << query.lastError();
        return 0;
    } else {
        int count = 0;
        for (int r = 0; query.next(); r++) {
            note = noteFromQuery(query);
            QString oldFileName = note.getFileName();
            note.storeNoteTextFileToDisk();
            QString newFileName = note.getFileName();

            // emit the signal for the QML that the note was stored
            emit scriptingService->noteStored(
                    QVariant::fromValue(
                            static_cast<QObject*>(NoteApi::fromNote(note))));

            // reassign currentNote if filename of currentNote has changed
            if ((oldFileName == currentNote.getFileName()) &&
                (oldFileName != newFileName)) {
                currentNote = note;
                qDebug() << "filename of currentNote has changed to: "
                << newFileName;
            }

            qDebug() << "stored note: " << note;
            count++;
        }

        return count;
    }
}