Example #1
0
//***********************************************************
//* Process a <note> tag
//***********************************************************
void ImportData::processNoteNode() {
    QLOG_DEBUG() << "Processing Note Node";
    Note note;
    QUuid uuid;
    QString newGuid = uuid.createUuid().toString().replace("{", "").replace("}", "");
    note.guid = newGuid;
    NoteMetaData meta;
    bool noteIsDirty = false;

    bool atEnd = false;
    while(!atEnd) {
        QString name = reader->name().toString().toLower();
        if (name == "guid" && !reader->isEndElement() && backup) {
            note.guid = textValue();
            noteList.append(note.guid);
        }
        if (name == "updatesequencenumber" && !reader->isEndElement()) {
            note.updateSequenceNum = textValue().toLong();
        }
        if (name == "title" && !reader->isEndElement()) {
            note.title = textValue();
        }
        if (name == "created" && !reader->isEndElement()) {
            note.created = longLongValue();
        }
        if (name == "updated" && !reader->isEndElement()) {
            note.updated = longLongValue();
        }
        if (name == "deleted" && !reader->isEndElement()) {
            note.deleted = longLongValue();
        }
        if (name == "active" && !reader->isEndElement()) {
            note.active = booleanValue();
        }
        if (name == "notebookguid" && !reader->isEndElement()) {
            note.notebookGuid = textValue();
        }
        if (name == "dirty" && !reader->isEndElement()) {
            noteIsDirty = booleanValue();
        }
        if (name == "content" && !reader->isEndElement()) {
            note.content = textValue();
        }
        if (name == "titlecolor" && !reader->isEndElement()) {
            meta.setColor(intValue());
        }
        if (name == "notetags" && (createTags || backup) && !reader->isEndElement()) {
            QStringList names, guids;
            processNoteTagList(guids, names);
            QList<QString> tagGuids;
            QList<QString> tagNames;
            for (qint32 i=0; i<guids.size(); i++) {
                tagGuids.append(guids[i]);
                tagNames.append(names[i]);
            }
            note.tagNames = tagNames;
            note.tagGuids = tagGuids;
        }
        if (name == "noteattributes" && !reader->isEndElement()) {
            processNoteAttributes(note.attributes);
        }
        if (name == "noteresource" && !reader->isEndElement()) {
            Resource newRes;
            processResource(newRes);
            newRes.noteGuid = note.guid;
            if (!backup)
                newRes.updateSequenceNum = 0;
            QList<Resource> resources;
            if (note.resources.isSet())
                resources = note.resources;
            resources.append(newRes);
            note.resources = resources;
        }
        reader->readNext();
        QString endName = reader->name().toString().toLower();
        if (endName == "note" && reader->isEndElement())
            atEnd = true;
    }

    // Loop through the resources & make sure they all have the
    // proper guid for this note
    QList<Resource> resources;
    if (note.resources.isSet())
        resources = note.resources;
    for (int i=0; i<resources.size(); i++) {
        resources[i].noteGuid = note.guid;
    }
    note.resources = resources;
    NoteTable noteTable(global.db);
    if (backup)
        noteTable.add(0,note, noteIsDirty);
    else {
        note.updateSequenceNum = 0;
        if (notebookGuid != NULL)
            note.notebookGuid = notebookGuid;
        noteTable.add(0,note, true);
        if (metaData.contains(note.guid)) {
            QLOG_ERROR() << "ERROR IN IMPORTING DATA:  Metadata not yet supported";
        }
    }
    return;
}
Example #2
0
//***********************************************************
//* Process a <note> tag
//***********************************************************
void ImportEnex::processNoteNode() {
    Note note;
    QUuid uuid;
    QString newGuid = uuid.createUuid().toString().replace("{", "").replace("}", "");
    note.guid = newGuid;
    note.active = true;
    QList<Resource> resources;
    //QList<QString> tagNames;

    bool atEnd = false;
    while(!atEnd) {
        QString name = reader->name().toString().toLower();
        if (name == "title" && !reader->isEndElement()) {
            note.title = textValue();
        }
        if (name == "created" && !reader->isEndElement()) {
            note.created = datetimeValue();
        }
        if (name == "updated" && !reader->isEndElement()) {
            note.updated = datetimeValue();
        }
        if (name == "deleted" && !reader->isEndElement()) {
            note.deleted = datetimeValue();
        }
        if (name == "active" && !reader->isEndElement()) {
            note.active = booleanValue();
        }
        if (name == "content" && !reader->isEndElement()) {
            note.content = textValue();
        }
        if (name == "note-attributes" && !reader->isEndElement()) {
            NoteAttributes na;
            note.attributes = na;
            processNoteAttributes(note.attributes);
        }
        if (name == "resource" && !reader->isEndElement()) {
            Resource newRes;
            processResource(newRes);
            newRes.noteGuid = note.guid;
            newRes.updateSequenceNum = 0;
            resources.append(newRes);
        }
        if (name == "tag" && !reader->isEndElement()) {
            if (!note.tagNames.isSet())
                note.tagNames = QStringList();
           note.tagNames->append(textValue());
        }
        reader->readNext();
        QString endName = reader->name().toString().toLower();
        if (endName == "note" && reader->isEndElement())
            atEnd = true;
    }


    // Loop through the resources & make sure they all have the
    // proper guid for this note
    for (int i=0; i<resources.size(); i++) {
        Resource *r = &resources[i];
        r->noteGuid = note.guid;
    }

    // Loop through the tag names & find any matching tags.
    if (note.tagNames.isSet()) {
        note.tagGuids = QList< Guid >();
        for (int i=0; i<note.tagNames->size(); i++) {
            QString tagGuid = tagList[note.tagNames->at(i)];
            if (tagGuid != "") {
                note.tagGuids->append(tagGuid);
            } else {
                QUuid uuid;
                QString g =  uuid.createUuid().toString().replace("{","").replace("}","");
                Tag newTag;
                newTag.name = note.tagNames->at(i);
                newTag.guid = g;
                TagTable tt(global.db);
                tt.add(0, newTag, true, 0);
                tagList.insert(note.tagNames->at(i), g);
                note.tagGuids->append(g);
            }
        }
    }
    note.resources = resources;
//    note.tagNames = tagNames;

    NoteTable noteTable(global.db);
    note.updateSequenceNum = 0;
    note.notebookGuid = notebookGuid;

    if (note.created.isSet() == false) {
        note.created = QDateTime::currentDateTime().toMSecsSinceEpoch();
    }
    if (note.updated.isSet() == false) {
        note.updated = note.created;
    }
    if (metaData.contains(note.guid)) {
        QLOG_ERROR() << "ERROR IN IMPORTING DATA:  Metadata not yet supported";
    }

    noteTable.add(0,note, true);
    return;
}