Example #1
0
// Copy (duplicate) a note
void NTableView::copyNote() {
    QList<qint32> lids;
    ConfigStore cs(global.db);
    getSelectedLids(lids);
    if (lids.size() == 0)
        return;

    NoteTable noteTable(global.db);
    for (int i=0; i<lids.size(); i++) {
        noteTable.duplicateNote(lids[i]);
    }
    FilterEngine engine;
    engine.filter();
    refreshData();
}
Example #2
0
// Combine multiple notes
void NTableView::mergeNotes() {
    QList<qint32> lids;
    getSelectedLids(lids);
    if (lids.size() == 0)
        return;

    NoteTable nTable(global.db);
    ResourceTable rTable(global.db);

    Note note;
    qint32 lid = lids[0];
    nTable.get(note, lid, false,false);
    QString content = QString::fromStdString(note.content);
    content = content.replace("</en-note>","<p/>");

    // Duplicate the source notes so we can undelete them later if something
    // goes horribly wrong
    for (int i=1; i<lids.size(); i++) {
        qint32 newLid = nTable.duplicateNote(lids[i]);
        QList<qint32> resLids;
        rTable.getResourceList(resLids, newLid);
        for (int j=0; j<resLids.size(); j++) {
            rTable.updateNoteLid(resLids[j], lid);
        }

        Note oldNote;
        nTable.get(oldNote, lids[i], false,false);
        QString oldContent = QString::fromStdString(oldNote.content);
        oldContent = oldContent.replace("</en-note>", "<p/>");
        int startPos = oldContent.indexOf("<en-note");
        startPos = oldContent.indexOf(">", startPos)+1;
        content = content+oldContent.mid(startPos);
        QLOG_DEBUG() << content;

        nTable.deleteNote(lids[i], true);
        nTable.expunge(newLid);
    }
    content = content+QString("</en-note>");
    QLOG_DEBUG() << content;
    nTable.updateNoteContent(lid, content, true);
    global.cache.remove(lid);

    FilterEngine engine;
    engine.filter();
    refreshData();
    emit(refreshNoteContent(lid));
}
Example #3
0
// Do the alter.  If the notebook is not found we create it.
// If a tag is not found for an add, we add it.  If a tag is
// not found for a deleteTag, we just ignore it.
int AlterNote::alterNote() {

    // If a query is specified, we find the matching notes.
    if (query != "") {
        FilterCriteria *filter = new FilterCriteria();
        global.filterCriteria.append(filter);
        global.filterPosition = 0;
        FilterEngine engine;
        filter->setSearchString(query);
        QList<qint32> lids;
        engine.filter(filter, &lids);
        this->lids.append(lids);
    }

    NotebookTable bookTable(global.db);
    TagTable tagTable(global.db);
    NoteTable noteTable(global.db);

    // Loop through each note requested.
    for (int i=0; i<lids.size(); i++) {
        qint32 lid = lids[i];

        // Do the notebook request
        if (notebook != "") {
            qint32 notebookLid = bookTable.findByName(notebook);
            if (notebookLid<0) {
                Notebook book;
                book.name = notebook;
                NUuid uuid;
                book.guid = uuid.create();
                notebookLid = bookTable.add(0,book,true,true);
            }
            if (noteTable.getNotebookLid(lid) != notebookLid)
                noteTable.updateNotebook(lid, notebookLid, true);
        }

        // Add the tags
        for (int j=0; j<addTagNames.size(); j++) {
            qint32 tagLid = tagTable.findByName(addTagNames[j],0);
            if (tagLid <= 0) {
                Tag t;
                t.name = addTagNames[j];
                NUuid uuid;
                t.guid = uuid.create();
                tagLid = tagTable.add(0,t,true,0);
            }
            if (!noteTable.hasTag(lid,tagLid))
                noteTable.addTag(lid, tagLid, true);
        }

        // Remove any tags specified
        for (int j=0; j<delTagNames.size(); j++) {
            qint32 tagLid = tagTable.findByName(delTagNames[j],0);
            if (tagLid > 0 && noteTable.hasTag(lid,tagLid)) {
                noteTable.removeTag(lid, tagLid, true);
            }
        }

        if (reminderCompleted) {
            noteTable.setReminderCompleted(lid, true);
        }

        if (clearReminder) {
            noteTable.removeReminder(lid);
        }
    }

    return 0;
}