// Synchronize remote expunged linked notebooks void SyncRunner::syncRemoteExpungedLinkedNotebooks(QList<Guid> guids) { LinkedNotebookTable btable(db); for (int i=0; i<guids.size(); i++) { LinkedNotebookTable ntable(db); qint32 lid = ntable.getLid(guids[i]); btable.expunge(guids[i]); emit notebookExpunged(lid); } }
// Expunge deleted notebooks from the local database void SyncRunner::syncRemoteExpungedNotebooks(QList<Guid> guids) { QLOG_TRACE() << "Entering SyncRunner::syncRemoteExpungedNotebooks"; NotebookTable notebookTable(db); for (int i=0; i<guids.size(); i++) { int lid = notebookTable.getLid(guids[i]); notebookTable.expunge(guids[i]); if (!finalSync) emit notebookExpunged(lid); } QLOG_TRACE() << "Leaving SyncRunner::syncRemoteExpungedNotebooks"; }
// Synchronize remote linked notebooks bool SyncRunner::syncRemoteLinkedNotebooksActual() { LinkedNotebookTable ltable(db); QList<qint32> lids; ltable.getAll(lids); bool fs; for (int i=0; i<lids.size(); i++) { LinkedNotebook book; qint32 usn = ltable.getLastUpdateSequenceNumber(lids[i]); qint32 startingUSN = usn; ltable.get(book, lids[i]); int chunkSize = 5000; // If the share key is set, we need to authenticate if (!comm->authenticateToLinkedNotebookShard(book)) { this->communicationErrorHandler(); error = true; return false; } bool more = true; SyncState syncState; if (!comm->getLinkedNotebookSyncState(syncState, book)) { this->communicationErrorHandler(); error = true; return false; } if (syncState.updateCount <= usn) more=false; qint32 startingSequenceNumber = usn; if (usn == 0) fs = true; else fs = false; // ***** STARTING PASS #1 while (more && keepRunning) { SyncChunk chunk; if (!comm->getLinkedNotebookSyncChunk(chunk, book, usn, chunkSize, fs)) { more = false; if (comm->error.type == CommunicationError::EDAMNotFoundException) { ltable.expunge(lids[i]); if (!finalSync) emit(notebookExpunged(lids[i])); } else { this->communicationErrorHandler(); error = true; return false; } } else { processSyncChunk(chunk, lids[i]); usn = chunk.chunkHighUSN; if (chunk.updateCount > 0 && chunk.updateCount > startingSequenceNumber) { int pct = (usn-startingSequenceNumber)*100/(chunk.updateCount-startingSequenceNumber); QString sharename = ""; if (book.shareName.isSet()) sharename = book.shareName; emit setMessage(tr("Downloading ") +QString::number(pct) + tr("% complete for tags in shared notebook ") +sharename + tr("."), defaultMsgTimeout); } if (!chunk.chunkHighUSN.isSet()|| chunk.chunkHighUSN >= chunk.updateCount) more = false; } } //************* STARTING PASS 2 usn = startingUSN; more = true; chunkSize = 50; if (error == true) more=false; QString sharename = ""; if (book.shareName.isSet()) sharename = book.shareName; emit setMessage(tr("Downloading notes for shared notebook ") +sharename + tr("."), defaultMsgTimeout); while (more && keepRunning) { SyncChunk chunk; if (!comm->getLinkedNotebookSyncChunk(chunk, book, usn, chunkSize, fs)) { more = false; if (comm->error.type == CommunicationError::EDAMNotFoundException) { ltable.expunge(lids[i]); if (!finalSync) emit(notebookExpunged(lids[i])); } else { this->communicationErrorHandler(); error = true; return false; } } else { processSyncChunk(chunk, lids[i]); usn = chunk.chunkHighUSN; if (chunk.updateCount > 0 && chunk.updateCount > startingSequenceNumber) { int pct = (usn-startingSequenceNumber)*100/(chunk.updateCount-startingSequenceNumber); QString sharename = ""; if (book.shareName.isSet()) sharename = book.shareName; emit setMessage(tr("Downloading ") +QString::number(pct) + tr("% complete for shared notebook ") +sharename + tr("."), defaultMsgTimeout); } if (!chunk.chunkHighUSN.isSet() || chunk.chunkHighUSN >= chunk.updateCount) { more = false; ltable.setLastUpdateSequenceNumber(lids[i], syncState.updateCount); } } } qint32 noteUSN = uploadLinkedNotes(lids[i]); if (noteUSN > usn) ltable.setLastUpdateSequenceNumber(lids[i], noteUSN); } TagTable tagTable(db); tagTable.cleanupLinkedTags(); return true; }