// Synchronize remote resources with the current database void SyncRunner::syncRemoteResources(QList<Resource> resources) { QLOG_TRACE() << "Entering SyncRunner::syncRemoteResources"; ResourceTable resTable(db); for (int i=0; i<resources.size(); i++) { Resource r = resources[i]; qint32 lid = resTable.getLid(r.noteGuid, r.guid); if (lid > 0) resTable.sync(lid, r); else resTable.sync(r); } QLOG_TRACE() << "Leaving SyncRunner::syncRemoteResources"; }
int GetMaxPrice( int len, const std::vector<int>& priceTable ) { if( len < 1 || priceTable.empty() ) return 0; if( len == 1 ) return priceTable[0]; std::vector<int> resTable( len, -1 ); for( int i = 1; i <= len; ++i ){ if( i <= priceTable.size() ) resTable[i - 1] = priceTable[i - 1]; for( int j = 1; j < i; ++j ){ resTable[i - 1] = __max( resTable[i - 1], resTable[j - 1] + resTable[i - j - 1] ); } } return resTable[len - 1]; }
void NWebView::downloadRequested(QNetworkRequest req) { QString urlString = req.url().toString(); if (urlString == "") { downloadImageAction()->trigger(); return; } if (urlString.startsWith("nnres:")) { int pos = urlString.indexOf(global.attachmentNameDelimeter); QString extension = ""; if (pos > 0) { extension = urlString.mid(pos+global.attachmentNameDelimeter.length()); urlString = urlString.mid(0,pos); } urlString = urlString.mid(6); qint32 lid = urlString.toInt(); ResourceTable resTable(global.db); Resource r; resTable.get(r, lid, false); QString filename; ResourceAttributes attributes; if (r.attributes.isSet()) attributes = r.attributes; if (attributes.fileName.isSet()) filename = attributes.fileName; else filename = urlString + QString(".") + extension; QFileDialog fd; fd.setFileMode(QFileDialog::AnyFile); fd.setWindowTitle(tr("Save File")); fd.setAcceptMode(QFileDialog::AcceptSave); fd.selectFile(filename); fd.setConfirmOverwrite(true); if (fd.exec()) { if (fd.selectedFiles().size() == 0) return; filename = fd.selectedFiles()[0]; QFile newFile(filename); newFile.open(QIODevice::WriteOnly); Data d; if (r.data.isSet()) d = r.data; QByteArray body; if (d.body.isSet()) body = d.body; int size = 0; if (d.size.isSet()) size = d.size; newFile.write(body, size); newFile.close(); return; } } if (urlString.startsWith("file:////")) { if (!req.url().isValid()) return; urlString = urlString.mid(8); QFileDialog fd; fd.setFileMode(QFileDialog::AnyFile); fd.setWindowTitle(tr("Save File")); fd.setAcceptMode(QFileDialog::AcceptSave); QString oldname = urlString; fd.selectFile(urlString.replace(global.fileManager.getDbaDirPath(), "")); fd.setConfirmOverwrite(true); if (fd.exec()) { if (fd.selectedFiles().size() == 0) return; QString newname = fd.selectedFiles()[0]; QFile::remove(urlString); QFile::copy(oldname, newname); return; } } }
// Deal with the sync chunk returned void SyncRunner::processSyncChunk(SyncChunk &chunk, qint32 linkedNotebook) { // Now start processing the chunk if (chunk.expungedNotes.isSet()) syncRemoteExpungedNotes(chunk.expungedNotes); if (chunk.expungedNotebooks.isSet()) syncRemoteExpungedNotebooks(chunk.expungedNotebooks); if (chunk.expungedSearches.isSet()) syncRemoteExpungedSavedSearches(chunk.expungedSearches); if (chunk.expungedTags.isSet()) syncRemoteExpungedTags(chunk.expungedTags); if (chunk.expungedLinkedNotebooks.isSet()) syncRemoteExpungedLinkedNotebooks(chunk.expungedLinkedNotebooks); if (chunk.notebooks.isSet()) syncRemoteNotebooks(chunk.notebooks, linkedNotebook); if (chunk.tags.isSet()) syncRemoteTags(chunk.tags, linkedNotebook); if (chunk.searches.isSet()) syncRemoteSearches(chunk.searches); if (chunk.linkedNotebooks.isSet()) syncRemoteLinkedNotebooksChunk(chunk.linkedNotebooks); if (chunk.notes.isSet()) syncRemoteNotes(chunk.notes, linkedNotebook); if (chunk.resources.isSet()) syncRemoteResources(chunk.resources); chunk.expungedLinkedNotebooks.clear();; chunk.expungedNotebooks.clear(); chunk.expungedNotes.clear(); chunk.expungedSearches.clear(); chunk.expungedTags.clear(); chunk.notebooks.clear(); chunk.notes.clear(); chunk.tags.clear(); chunk.linkedNotebooks.clear(); chunk.searches.clear(); // Save any thumbnails notes while (comm->thumbnailList->size() > 0) { QPair<QString, QImage *> *pair = comm->thumbnailList->takeFirst(); NoteTable nTable(db); qint32 lid = nTable.getLid(pair->first); if (lid > 0) { QString filename = global.fileManager.getThumbnailDirPath() + QString::number(lid) + QString(".png"); pair->second->save(filename, "png"); nTable.setThumbnail(lid, filename); } delete pair->second; delete pair; } // Save any ink notes while (comm->inkNoteList->size() > 0) { QPair<QString, QImage *> *pair = comm->inkNoteList->takeFirst(); ResourceTable resTable(db); qint32 resLid = resTable.getLid(pair->first); if (resLid > 0) { QString filename = global.fileManager.getDbaDirPath() + QString::number(resLid) + QString(".png"); pair->second->save(filename); } delete pair->second; delete pair; } }