// 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; }
// 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; }
// 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; }