void TrayMenu::buildActionMenu() { for (int i=actions.size()-1; i>=0; i--) { signalMapper->removeMappings(actions[i]); pinnedMenu->removeAction(actions[i]); recentlyUpdatedMenu->removeAction(actions[i]); } actions.clear(); QList< QPair< qint32, QString> > records; NoteTable noteTable(global.db); noteTable.getAllPinned(records); buildMenu(pinnedMenu, records); records.clear();; noteTable.getRecentlyUpdated(records); buildMenu(recentlyUpdatedMenu, records); records.clear(); FavoritesTable ftable(global.db); QList<qint32> lids; ftable.getAll(lids); for (int i=0; i<lids.size(); i++) { FavoritesRecord record; ftable.get(record, lids[i]); if (record.type == FavoritesRecord::Note) { QPair<qint32, QString> pair; pair.first = record.target.toInt(); pair.second = record.displayName; records.append(pair); } } favoriteNotesMenu->clear(); buildMenu(favoriteNotesMenu, records); }
// Synchronize remote notes with the current database void SyncRunner::syncRemoteNotes(QList<Note> notes, qint32 account) { QLOG_TRACE() << "Entering SyncRunner::syncRemoteNotes"; NoteTable noteTable(db); NotebookTable bookTable(db); for (int i=0; i<notes.size() && keepRunning; i++) { Note t = notes[i]; qint32 lid = noteTable.getLid(t.guid); if (lid > 0) { // Find out if it is a conflicting change if (noteTable.isDirty(lid)) { qint32 newLid = noteTable.duplicateNote(lid); qint32 conflictNotebook = bookTable.getConflictNotebook(); noteTable.updateNotebook(newLid, conflictNotebook, true); if (!finalSync) emit noteUpdated(newLid); } noteTable.sync(lid, notes.at(i), account); } else { noteTable.sync(t, account); lid = noteTable.getLid(t.guid); } // Remove it from the cache (if it exists) if (global.cache.contains(lid)) { delete global.cache[lid]; global.cache.remove(lid); } if (!finalSync) emit noteUpdated(lid); } QLOG_TRACE() << "Leaving SyncRunner::syncRemoteNotes"; }
// Expunge deleted notes from the local database void SyncRunner::syncRemoteExpungedNotes(QList<Guid> guids) { QLOG_TRACE() << "Entering SyncRunner::syncRemoteExpungedNotes"; NoteTable noteTable(db); for (int i=0; i<guids.size(); i++) { noteTable.expunge(guids[i]); } QLOG_TRACE() << "Leaving SyncRunner::syncRemoteExpungedNotes"; }
void NTitleEditor::checkNoteTitleChange() { if (this->text() != initialTitle) { NoteTable noteTable(global.db); noteTable.updateTitle(currentLid, text(), true); emit(titleChanged()); priorTitle = text(); } }
// Upload notes that belong to me qint32 SyncRunner::uploadLinkedNotes(qint32 notebookLid) { qint32 usn; qint32 maxUsn = 0; NoteTable noteTable(db); QList<qint32> lids, validLids, deletedLids; noteTable.getAllDirty(lids, notebookLid); // Split the list into deleted and updated notes for (int i=0; i<lids.size(); i++) { if (noteTable.isDeleted(lids[i])) deletedLids.append(lids[i]); else validLids.append(lids[i]); } // Start uploading notes for (int i=0; i<validLids.size(); i++) { Note note; noteTable.get(note, validLids[i],true, true); qint32 oldUsn = note.updateSequenceNum; usn = comm->uploadLinkedNote(note); if (usn == 0) { this->communicationErrorHandler(); error = true; return maxUsn; } if (usn > maxUsn) { maxUsn = usn; if (oldUsn == 0) noteTable.updateGuid(validLids[i], note.guid); noteTable.setUpdateSequenceNumber(validLids[i], usn); noteTable.setDirty(validLids[i], false); if (!finalSync) emit(noteSynchronized(validLids[i], false)); } else { error = true; } } // Start deleting notes for (int i=0; i<deletedLids.size(); i++) { QString guid = noteTable.getGuid(deletedLids[i]); noteTable.setDirty(lids[i], false); usn = comm->deleteLinkedNote(guid); if (usn > maxUsn) { maxUsn = usn; noteTable.setUpdateSequenceNumber(deletedLids[i], usn); noteTable.setDirty(deletedLids[i], false); if (!finalSync) emit(noteSynchronized(deletedLids[i], false)); } } return maxUsn; }
void Thumbnailer::render(qint32 lid) { idle = false; this->lid = lid; NoteFormatter formatter; formatter.thumbnail = true; NoteTable noteTable(db); Note n; noteTable.get(n,lid,false, false); formatter.setNote(n,false); QByteArray formattedContent = formatter.rebuildNoteHTML(); page->mainFrame()->setContent(formattedContent); }
void Thumbnailer::generateNextThumbnail() { // If we are connected we are downloading or uploading, so // we don't want to do this now. if (global.connected) return; timer.stop(); NoteTable noteTable(db); qint32 lid = noteTable.getNextThumbnailNeeded(); if (lid>0) { render(lid); timer.start(minTime); } else timer.start(maxTime); }
void AuthorEditor::textModified(QString text) { this->blockSignals(true); NoteTable noteTable(global.db); noteTable.updateAuthor(currentLid, text, true); if (text.trimmed() == "" && !hasFocus()) setText(defaultText); else setText(text); this->blockSignals(false); if (text.trimmed() != initialText.trimmed() || priorText.trimmed() != text.trimmed()) emit(textUpdated()); priorText = text; }
// Handle what happens when something is dropped onto a tag item bool NNotebookView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) { Q_UNUSED(index); // suppress unused variable Q_UNUSED(action); // suppress unused variable // If this is a note-to-tag drop we are assigning tags to a note if (data->hasFormat("application/x-nixnote-note")) { QByteArray d = data->data("application/x-nixnote-note"); QString data(d); // Find the tag lid we dropped onto qint32 bookLid = parent->data(NAME_POSITION, Qt::UserRole).toInt(); if (bookLid <=0) return false; NotebookTable bookTable(global.db); Notebook notebook; bookTable.get(notebook, bookLid); // The string has a long list of note lids. We parse them out & update the note QStringList stringLids = data.split(" "); for (int i=0; i<stringLids.size(); i++) { if (stringLids[i].trimmed() != "") { qint32 noteLid = stringLids.at(i).toInt(); if (noteLid > 0) { NoteTable noteTable(global.db); qint32 currentNotebook = noteTable.getNotebookLid(noteLid); if (currentNotebook != bookLid) { noteTable.updateNotebook(noteLid, bookLid, true); emit(updateNoteList(noteLid, NOTE_TABLE_NOTEBOOK_POSITION, notebook.name.value())); qint64 dt = QDateTime::currentMSecsSinceEpoch(); noteTable.updateDate(noteLid, dt, NOTE_UPDATED_DATE, true); emit(updateNoteList(noteLid, NOTE_TABLE_DATE_UPDATED_POSITION, dt)); } } } } if (stringLids.size() > 0) { emit(updateCounts()); } return true; } return false; }
// This function gets control whenever the text is edited. void NTitleEditor::titleChanged(QString text) { this->blockSignals(true); // Check that we have some type of title. If not we go with // the default text = cleanupTitle(text); this->setText(text); this->blockSignals(false); // Now check that the text has actually changed. We need to do this because // we can also get here when focus is lost. if (!hasFocus()) { if (text.trimmed() != initialTitle.trimmed() || priorTitle.trimmed() != text.trimmed()) { NoteTable noteTable(global.db); noteTable.updateTitle(currentLid, text, true); emit(titleChanged()); setText(text); priorTitle = text; initialTitle = text; } } }
void Thumbnailer::generateNextThumbnail() { // If we are connected we are downloading or uploading or // if we have thumbnails disabled, so // we don't want to do this now. if (global.connected || global.disableThumbnails) { timer.start(global.maximumThumbnailInterval*1000); return; } timer.stop(); NoteTable noteTable(db); int i=0; for (; i<global.batchThumbnailCount; i++) { QDateTime current; QDateTime deadlineTime; deadlineTime.addSecs(20); // Make sure we haven't been looping too long. if (current > deadlineTime) { QLOG_DEBUG() << "Thumbnail timer exceeded. Going to seep"; timer.start(global.maximumThumbnailInterval*1000); return; } if (this->idle) { i++; qint32 lid = noteTable.getNextThumbnailNeeded(); if (lid>0) { render(lid); } else { timer.start(global.maximumThumbnailInterval*1000); return; } } } timer.start(global.minimumThumbnailInterval*1000); }
void Thumbnailer::render(qint32 lid) { idle = false; this->lid = lid; NoteFormatter formatter; formatter.thumbnail = true; NoteTable noteTable(db); Note n; noteTable.get(n,lid,false, false); formatter.setNote(n,false); QByteArray formattedContent = formatter.rebuildNoteHTML(); // Windows check for font bug when viewing Unicode characters #ifdef _WIN32 for(int i = 0; i < formattedContent.size(); ++i) { char c = formattedContent.at(i); QChar cc(c); if(cc.unicode() > 127) { c = ' '; formattedContent.replace(c,' '); } } #endif page->mainFrame()->setContent(formattedContent); }
// Handle what happens when something is dropped onto a tag item bool NTagView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) { // If this is a note-to-tag drop we are assigning tags to a note if (data->hasFormat("application/x-nixnote-note")) { QByteArray d = data->data("application/x-nixnote-note"); QString data(d); // Find the tag lid we dropped onto qint32 tagLid = parent->data(NAME_POSITION, Qt::UserRole).toInt(); // The string has a long list of note lids. We parse them out & update the note QStringList stringLids = data.split(" "); for (int i=0; i<stringLids.size(); i++) { if (stringLids[i].trimmed() != "") { qint32 noteLid = stringLids.at(i).toInt(); if (noteLid > 0) { NoteTable noteTable(global.db); if (!noteTable.hasTag(noteLid, tagLid)) { noteTable.addTag(noteLid, tagLid, true); QString tagString = noteTable.getNoteListTags(noteLid); emit(updateNoteList(noteLid, NOTE_TABLE_TAGS_POSITION, tagString)); // qint64 dt = QDateTime::currentMSecsSinceEpoch(); // noteTable.updateDate(noteLid, dt, NOTE_UPDATED_DATE, true); // emit(updateNoteList(noteLid, NOTE_TABLE_DATE_UPDATED_POSITION, dt)); } } } } if (stringLids.size() > 0) emit updateCounts(); return true; } // If this is a tag-to-tag drop then we are modifying the hierarchy if (data->hasFormat("application/x-nixnote-tag")) { // If there is no parent, then they are trying to drop to the top level, which isn't permitted if (parent == NULL) return false; // Get the lid we are dropping. QByteArray d = data->data("application/x-nixnote-tag"); qint32 lid = d.toInt(); if (lid == 0) return false; qint32 newParentLid = parent->data(NAME_POSITION, Qt::UserRole).toInt(); qint32 oldParentLid = dataStore[lid]->parentLid; if (newParentLid == oldParentLid) return false; if (newParentLid == lid) return false; NTagViewItem *item = dataStore[lid]; // If we had an old parent, remove the child from it. if (oldParentLid > 0) { NTagViewItem *parent_ptr = dataStore[oldParentLid]; for (int i=0; i<parent_ptr->childrenLids.size(); i++) { if (parent_ptr->childrenLids[i] == lid) { parent_ptr->childrenLids.removeAt(i); i=parent_ptr->childrenLids.size(); } } parent_ptr->removeChild(item); } else { root->removeChild(item); } // Update the actual database Tag tag; TagTable tagTable(global.db); tagTable.get(tag, lid); QString guid; tagTable.getGuid(guid, newParentLid); tag.parentGuid = guid; tagTable.update(tag, true); if (newParentLid>0) { NTagViewItem *parent_ptr = dataStore[newParentLid]; parent_ptr->addChild(item); parent_ptr->childrenLids.append(lid); item->parentLid = newParentLid; item->parentGuid = tag.guid; } else { item->parentLid = 0; item->parentGuid = ""; root->addChild(item); } // Resort the data this->sortByColumn(NAME_POSITION, Qt::AscendingOrder); sortItems(NAME_POSITION, Qt::AscendingOrder); return QTreeWidget::dropMimeData(parent, index, data, action); } return false; }
//*********************************************************** //* This is the main entry point for an import. It is passed //* the file which contains the export data. It then //* opens up the file, checks the validity of the data, and //* then begins to parse through all of the crap. //*********************************************************** void ImportData::import(QString file) { fileName = file; errorMessage = ""; lastError = 0; QFile xmlFile(fileName); QFile scanFile(fileName); if (!xmlFile.open(QIODevice::ReadOnly) || !scanFile.open(QIODevice::ReadOnly)) { lastError = 16; errorMessage = "Cannot open file."; return; } QTextStream *countReader = new QTextStream(&scanFile); int recCnt = 0; QMessageBox mb; mb.setWindowTitle(tr("Scanning File")); mb.setText(QString::number(recCnt) + tr(" notes found.")); QPushButton *cancelButton = mb.addButton(QMessageBox::Cancel); connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); mb.show(); QCoreApplication::processEvents(); while (!countReader->atEnd() && !stopNow) { QString line = countReader->readLine(); if (line.contains("<note>", Qt::CaseInsensitive)) { recCnt++; mb.setText(QString::number(recCnt) + tr(" notes found.")); QCoreApplication::processEvents(); } } notebookData.clear(); progress->setMaximum(recCnt); progress->setMinimum(0); if (backup) { progress->setWindowTitle(tr("Importing")); progress->setLabelText(tr("Importing Notes")); } else { progress->setWindowTitle(tr("Restore")); progress->setLabelText(tr("Restoring Notes")); } progress->setWindowModality(Qt::ApplicationModal); connect(progress, SIGNAL(canceled()), this, SLOT(cancel())); progress->setVisible(true); mb.close(); progress->show(); recCnt = 0; reader = new QXmlStreamReader(&xmlFile); NSqlQuery query(global.db); query.exec("begin"); int commitCount = 100; while (!reader->atEnd() && !stopNow) { if (commitCount <= 0) { query.exec("commit"); commitCount = 100; } commitCount--; reader->readNext(); if (reader->hasError()) { errorMessage = reader->errorString(); QLOG_ERROR() << "************************* ERROR READING BACKUP " << errorMessage; lastError = 16; return; } if (reader->name().toString().toLower() == "nevernote-export" && reader->isStartElement()) { QXmlStreamAttributes attributes = reader->attributes(); QString version = attributes.value("version").toString(); QString type = attributes.value("exportType").toString(); QString application = attributes.value("application").toString(); if (version != "0.85" && version != "0.86" && version != "0.95") { lastError = 1; errorMessage = "Unknown backup version = " +version; return; } if (application.toLower() != "nevernote") { lastError = 2; errorMessage = "This backup is from an unknown application = " +application; return; } if (type.toLower() == "backup" && !backup) { lastError = 4; errorMessage = "This is backup file, not an export file"; progress->hide(); return; } if (type.toLower() == "export" && backup) { lastError = 5; errorMessage = "This is an export file, not a backup file"; return; } } if (reader->name().toString().toLower() == "synchronization" && reader->isStartElement() && backup) { processSynchronizationNode(); } if (reader->name().toString().toLower() == "note" && reader->isStartElement()) { processNoteNode(); recCnt++; progress->setValue(recCnt); } if (reader->name().toString().toLower() == "notebook" && reader->isStartElement() && (backup || importNotebooks)) { processNotebookNode(); } if (reader->name().toString().toLower() == "tag" && reader->isStartElement() && (backup || importTags)) { processTagNode(); } if (reader->name().toString().toLower() == "savedsearch" && reader->isStartElement() && backup) { processSavedSearchNode(); } if (reader->name().toString().toLower() == "linkednotebook" && reader->isStartElement() && backup) { processLinkedNotebookNode(); } if (reader->name().toString().toLower() == "SharedNotebook" && reader->isStartElement() && backup) { processSharedNotebookNode(); } } xmlFile.close(); query.exec("commit"); // Now we do what is a "ahem" hack. We need to // go through all of the notes & rebuild the NoteTable. This // is because we may have gotten notes & tags before the notebook // & tag names existed. There is probably a more efficient way // to do this, but since we don't really do this often this works // as well as any other way. NoteTable noteTable(global.db); for (qint32 i=0; i<noteList.size(); i++) { qint32 lid = noteTable.getLid(noteList[i]); if (lid > 0) { Note note; bool dirty = noteTable.isDirty(lid); noteTable.get(note, lid, false, false); noteTable.updateNoteList(lid, note, dirty, 0); } } query.exec("commit"); progress->hide(); }
//*********************************************************** //* 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; }
// Upload notes that belong to me qint32 SyncRunner::uploadPersonalNotes() { qint32 usn; qint32 maxUsn = 0; NotebookTable notebookTable(db); LinkedNotebookTable linkedNotebookTable(db); NoteTable noteTable(db); QList<qint32> lids, validLids, deletedLids, movedLids; noteTable.getAllDirty(lids); // Get a list of all notes that are both dirty and in an account we own and isn't deleted for (int i=0; i<lids.size(); i++) { qint32 notebookLid = noteTable.getNotebookLid(lids[i]); if (!linkedNotebookTable.exists(notebookLid)) { if (!notebookTable.isLocal(notebookLid)) { if (noteTable.isDeleted(lids[i])) deletedLids.append(lids[i]); else validLids.append(lids[i]); } else { // We have a note that is local. Check if it was once // synchronized. If so, it was moved to a local notebook // and now needs to be deleted on the remote end Note n; noteTable.get(n, lids[i], false, false); if (n.updateSequenceNum.isSet() && n.updateSequenceNum > 0) { movedLids.append(lids[i]); } } } } // Start deleting notes for (int i=0; i<deletedLids.size(); i++) { QString guid = noteTable.getGuid(deletedLids[i]); noteTable.setDirty(lids[i], false); usn = comm->deleteNote(guid); if (usn > maxUsn) { maxUsn = usn; noteTable.setUpdateSequenceNumber(deletedLids[i], usn); noteTable.setDirty(deletedLids[i], false); if (!finalSync) emit(noteSynchronized(deletedLids[i], false)); } } // Start handling notes moved to a local notebook. What // we do is to delete the note on Evernote, then give the // note in the local notebook a new GUID & set the // update sequence number to 0. for (int i=0; i<movedLids.size(); i++) { QUuid uuid; Guid newGuid = uuid.createUuid().toString().replace("{","").replace("}",""); QString guid = noteTable.getGuid(movedLids[i]); noteTable.setDirty(movedLids[i], false); noteTable.updateGuid(movedLids[i], newGuid); noteTable.setUpdateSequenceNumber(movedLids[0], 0); usn = comm->deleteNote(guid); if (usn > maxUsn) { maxUsn = usn; } if (!finalSync) emit(noteSynchronized(movedLids[i], false)); } // Start uploading notes for (int i=0; i<validLids.size(); i++) { Note note; noteTable.get(note, validLids[i],true, true); qint32 oldUsn=0; if (note.updateSequenceNum.isSet()) oldUsn = note.updateSequenceNum; usn = comm->uploadNote(note); if (usn == 0) { this->communicationErrorHandler(); error = true; return maxUsn; } if (usn > maxUsn) { maxUsn = usn; if (oldUsn == 0) noteTable.updateGuid(validLids[i], note.guid); noteTable.setUpdateSequenceNumber(validLids[i], usn); noteTable.setDirty(validLids[i], false); if (!finalSync) emit(noteSynchronized(validLids[i], false)); } else { error = true; } } return maxUsn; }
// 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; }
// Upload notes that belong to me qint32 SyncRunner::uploadLinkedNotes(qint32 notebookLid) { QLOG_TRACE_IN(); qint32 usn; qint32 maxUsn = 0; NoteTable noteTable(db); QList<qint32> lids, validLids, deletedLids; noteTable.getAllDirty(lids, notebookLid); // Split the list into deleted and updated notes for (int i = 0; i < lids.size(); i++) { if (noteTable.isDeleted(lids[i])) deletedLids.append(lids[i]); else validLids.append(lids[i]); } // Start deleting notes for (int i = 0; i < deletedLids.size(); i++) { QString guid = noteTable.getGuid(deletedLids[i]); noteTable.setDirty(lids[i], false); usn = comm->deleteLinkedNote(guid); if (usn > maxUsn) { maxUsn = usn; noteTable.setUpdateSequenceNumber(deletedLids[i], usn); noteTable.setDirty(deletedLids[i], false); if (!finalSync) emit(noteSynchronized(deletedLids[i], false)); } } // Start deleting notes that were in the trash, but the trash was // emptied. NotebookTable bookTable(db); QString notebookGuid = ""; bookTable.getGuid(notebookGuid, notebookLid); // Get all of the notes QStringList deleteQueueGuids; noteTable.getAllDeleteQueue(deleteQueueGuids, notebookGuid); // Do the actual deletes for (int i = 0; i < deleteQueueGuids.size(); i++) { QString guid = deleteQueueGuids[i]; usn = comm->deleteLinkedNote(guid); if (usn > maxUsn) { maxUsn = usn; } noteTable.expungeFromDeleteQueue(guid); } // Start uploading notes for (int i = 0; i < validLids.size(); i++) { Note note; noteTable.get(note, validLids[i], true, true); qint32 oldUsn = note.updateSequenceNum; usn = comm->uploadLinkedNote(note); if (usn == 0) { this->communicationErrorHandler(); error = true; QLOG_TRACE_OUT(); return maxUsn; } if (usn > maxUsn) { maxUsn = usn; if (oldUsn == 0) noteTable.updateGuid(validLids[i], note.guid); noteTable.setUpdateSequenceNumber(validLids[i], usn); noteTable.setDirty(validLids[i], false); if (!finalSync) emit(noteSynchronized(validLids[i], false)); } else { error = true; } } QLOG_TRACE_OUT(); return maxUsn; }
//*********************************************************** //* 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; }