// Synchronize remote notebooks with the current database // If there is a conflict, the remote wins void SyncRunner::syncRemoteNotebooks(QList<Notebook> books, qint32 account) { QLOG_TRACE() << "Entering SyncRunner::syncRemoteNotebooks"; NotebookTable notebookTable(db); LinkedNotebookTable ltable(db); SharedNotebookTable stable(db); for (int i = 0; i < books.size() && keepRunning; i++) { Notebook t = books.at(i); // There are a few to get the notebook. // We can get it by the guid, the share key, the uri, or the name. qint32 lid = account; if (lid == 0) lid = notebookTable.getLid(t.guid); if (lid == 0) lid = ltable.getLid(t.guid); if (lid == 0 && t.sharedNotebooks.isSet()) { QList<SharedNotebook> sharedNotebooks = t.sharedNotebooks; for (int j = 0; j < sharedNotebooks.size() && lid == 0; j++) { lid = stable.findById(sharedNotebooks[j].id); } } Publishing publishing; if (t.publishing.isSet()) publishing = t.publishing; if (lid == 0 && publishing.uri.isSet()) { lid = notebookTable.findByUri(publishing.uri); } if (lid == 0) lid = notebookTable.findByName(t.name); if (lid > 0) { notebookTable.sync(lid, t); } else { lid = notebookTable.sync(t); } changedNotebooks.insert(t.guid, t.name); QString stack = ""; if (t.stack.isSet()) stack = t.stack; bool shared = false; if (t.sharedNotebookIds.isSet() || t.sharedNotebooks.isSet()) shared = true; if (account > 0) { LinkedNotebookTable ltb(db); LinkedNotebook lbook; ltb.get(lbook, account); if (lbook.username.isSet()) stack = QString::fromStdString(username); } if (!finalSync) { if (t.name.isSet()) emit notebookUpdated(lid, t.name, stack, false, shared); else emit notebookUpdated(lid, "", stack, false, shared); } } QLOG_TRACE() << "Leaving SyncRunner::syncRemoteNotebooks"; }
// Synchronize remote linked notebooks void SyncRunner::syncRemoteLinkedNotebooksChunk(QList<LinkedNotebook> books) { LinkedNotebookTable ltable(db); for (int i=0; i<books.size(); i++) { qint32 lid = ltable.sync(books[i]); LinkedNotebook lbk = books[i]; QString sharename = ""; QString username = ""; if (lbk.shareName.isSet()) sharename = lbk.shareName; if (lbk.username.isSet()) username = lbk.username; if (!finalSync) emit notebookUpdated(lid, sharename, username, true, false); } }
void VNotebookSelector::editNotebookInfo() { QList<QListWidgetItem *> items = m_listWidget->selectedItems(); if (items.isEmpty()) { return; } Q_ASSERT(items.size() == 1); VNotebook *notebook = getNotebook(items[0]); VNotebookInfoDialog dialog(tr("Notebook Information"), "", notebook, m_notebooks, this); if (dialog.exec() == QDialog::Accepted) { bool updated = false; bool configUpdated = false; QString name = dialog.getName(); if (name != notebook->getName()) { updated = true; notebook->rename(name); g_config->setNotebooks(m_notebooks); } QString imageFolder = dialog.getImageFolder(); if (imageFolder != notebook->getImageFolderConfig()) { configUpdated = true; notebook->setImageFolder(imageFolder); } if (configUpdated) { updated = true; notebook->writeConfigNotebook(); } if (updated) { fillItem(items[0], notebook); emit notebookUpdated(notebook); } } }