void NotebookMenuButton::reloadData() { for (int i=actions.size()-1; i>=0; i--) { delete actions[i]; } for (int i=stackMenus.size()-1; i>=0; i--) { delete stackMenus[i]; } stackMenus.clear(); actions.clear(); loadData(); // Restore the proper notebook selection Note n; NoteTable noteTable; NotebookTable notebookTable; noteTable.get(n, currentNoteLid, false,false); QString notebookGuid = QString::fromStdString(n.notebookGuid); QList<qint32> bookList; notebookTable.getAll(bookList); QString bookName; for (int i=0; i<bookList.size(); i++) { Notebook book; notebookTable.get(book, bookList[i]); if (notebookGuid == QString::fromStdString(book.guid)) { bookName = QString::fromStdString(book.name); i=bookList.size(); } } setCurrentNotebook(currentNoteLid, n); return; }
void IndexRunner::index() { indexTimer->stop(); QList<qint32> lids; NoteTable noteTable; ResourceTable resourceTable; if (keepRunning && noteTable.getIndexNeeded(lids) > 0 && !pauseIndexing) { QLOG_DEBUG() << "Unindexed Notes found: " << lids.size(); for (qint32 i=0; i<lids.size() && keepRunning && !pauseIndexing; i++) { QSqlQuery sql; sql.prepare("Delete from SearchIndex where lid=:lid"); sql.bindValue(":lid", lids.at(i)); sql.exec(); Note n; noteTable.get(n, lids.at(i), false, false); indexNote(lids.at(i),n); //hammer->setNote(lids.at(i), n); noteTable.setIndexNeeded(lids.at(i), false); } } lids.empty(); if (keepRunning && resourceTable.getIndexNeeded(lids) > 0 && !pauseIndexing) { QLOG_DEBUG() << "Unindexed Resources found: " << lids.size(); for (qint32 i=0; i<lids.size() && keepRunning && !pauseIndexing; i++) { Resource r; resourceTable.get(r, lids.at(i)); indexRecognition(lids.at(i), r); resourceTable.setIndexNeeded(lids.at(i), false); } } indexTimer->start(); }
//*********************************************************** //* 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); if (!xmlFile.open(QIODevice::ReadOnly)) { lastError = 16; errorMessage = "Cannot open file."; } reader = new QXmlStreamReader(&xmlFile); QSqlQuery query; query.exec("begin"); while (!reader->atEnd()) { 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 an export file, not a backup file"; return; } if (type.toLower() == "export" && backup) { lastError = 5; errorMessage = "This is a backup file, not an export file"; return; } } if (reader->name().toString().toLower() == "synchronization" && reader->isStartElement() && backup) { processSynchronizationNode(); } if (reader->name().toString().toLower() == "note" && reader->isStartElement()) { processNoteNode(); } 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 awy. NoteTable noteTable; 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); } } }