/* Modify an image tag. Basically we turn it back into a picture, write out the file, and modify the ENML */ void NoteFormatter::modifyImageTags(QDomDocument &doc, QDomElement &docElement, QDomElement &enMedia, QDomAttr &hash) { QLOG_DEBUG() << "Entering NoteFormatter::modifyImageTags"; QString mimetype = enMedia.attribute("type"); ResourceTable resourceTable; qint32 resLid = resourceTable.getLidByHashHex(QString::fromStdString(note.guid), hash.value()); Resource r; if (resLid>0) { //QFile tfile(global.fileManager.getResDirPath(QString::number(resLid)+type)); resourceTable.get(r, resLid); MimeReference ref; QString filename; if (r.__isset.attributes && r.attributes.__isset.fileName) filename = QString::fromStdString(r.attributes.fileName); QString type = ref.getExtensionFromMime(mimetype, filename); if (r.__isset.data && r.data.__isset.body && r.data.body.length() > 0) { enMedia.setAttribute("src", "file:///"+global.fileManager.getDbDirPath(QString("dba/") +QString::number(resLid) +type)); // Check if this is a LaTeX image if (r.__isset.attributes && r.attributes.__isset.sourceURL && QString::fromStdString(r.attributes.sourceURL).toLower().startsWith("http://latex.codecogs.com/gif.latex?")) { QDomElement newText(doc.createElement("a")); enMedia.setAttribute("en-tag", "en-latex"); newText.setAttribute("onMouseOver", "style.cursor='pointer'"); newText.setAttribute("title", QString::fromStdString(r.attributes.sourceURL)); newText.setAttribute("href", "latex://"+QString::number(resLid)); enMedia.parentNode().replaceChild(newText, enMedia); newText.appendChild(enMedia); } enMedia.setAttribute("onContextMenu", "window.browserWindow.imageContextMenu('" +QString::number(resLid) +"', '" +QString::number(resLid) +type +"');"); } } else { resourceError = true; readOnly = true; } // Reset the tags to something that WebKit will understand enMedia.setAttribute("en-tag", "en-media"); enMedia.setNodeValue(""); enMedia.setAttribute("lid", resLid); enMedia.setTagName("img"); }
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(); }
// Return a note structure given the LID bool NoteTable::get(Note ¬e, qint32 lid,bool loadResources, bool loadResourceRecognition) { QSqlQuery query; query.prepare("Select key, data from DataStore where lid=:lid"); query.bindValue(":lid", lid); query.exec(); while (query.next()) { qint32 key = query.value(0).toInt(); switch (key) { case (NOTE_GUID): note.guid = query.value(1).toString().toStdString(); note.__isset.guid = true; break; case (NOTE_UPDATE_SEQUENCE_NUMBER): note.updateSequenceNum = query.value(1).toInt(); note.__isset.updateSequenceNum = true; break; case (NOTE_ACTIVE): note.active = query.value(1).toBool(); note.__isset.active = true; break; case (NOTE_DELETED_DATE): note.active = query.value(1).toLongLong(); note.__isset.deleted = true; break; case (NOTE_ATTRIBUTE_SOURCE_URL): note.attributes.sourceURL = query.value(1).toString().toStdString(); note.__isset.attributes = true; note.attributes.__isset.sourceURL = true; break; case (NOTE_ATTRIBUTE_SOURCE_APPLICATION): note.attributes.sourceApplication = query.value(1).toString().toStdString(); note.__isset.attributes = true; note.attributes.__isset.sourceApplication = true; break; case (NOTE_CONTENT_LENGTH): note.contentLength = query.value(1).toLongLong(); note.__isset.contentLength = true; break; case (NOTE_ATTRIBUTE_LONGITUDE): note.attributes.longitude = query.value(1).toFloat(); note.__isset.attributes = true; note.attributes.__isset.longitude = true; break; case (NOTE_TITLE): note.title = query.value(1).toString().toStdString(); note.__isset.title = true; break; case (NOTE_ATTRIBUTE_SOURCE): note.attributes.source = query.value(1).toString().toStdString(); note.__isset.attributes = true; note.attributes.__isset.source = true; break; case (NOTE_ATTRIBUTE_ALTITUDE): note.attributes.altitude = query.value(1).toFloat(); note.__isset.attributes = true; note.attributes.__isset.altitude = true; break; case (NOTE_NOTEBOOK_LID): { qint32 notebookLid = query.value(1).toInt(); NotebookTable ntable; QString notebookGuid; ntable.getGuid(notebookGuid, notebookLid); note.notebookGuid = notebookGuid.toStdString(); note.__isset.notebookGuid = true; break; } case (NOTE_UPDATED_DATE): note.updated = query.value(1).toLongLong(); note.__isset.updated = true; break; case (NOTE_CREATED_DATE): note.created = query.value(1).toLongLong(); note.__isset.created = true; break; case (NOTE_ATTRIBUTE_SUBJECT_DATE): note.attributes.subjectDate = query.value(1).toLongLong(); note.__isset.attributes = true; note.attributes.__isset.subjectDate = true; break; case (NOTE_ATTRIBUTE_LATITUDE): note.attributes.latitude = query.value(1).toFloat(); note.__isset.attributes = true; note.attributes.__isset.latitude = true; break; case (NOTE_CONTENT): note.content = query.value(1).toByteArray().data(); note.__isset.content = true; break; case (NOTE_CONTENT_HASH): note.contentHash = query.value(1).toString().toStdString(); note.__isset.contentHash = true; break; case (NOTE_ATTRIBUTE_AUTHOR): note.attributes.author = query.value(1).toString().toStdString(); note.__isset.attributes = true; note.attributes.__isset.author = true; break; case (NOTE_ISDIRTY): break; case (NOTE_ATTRIBUTE_SHARE_DATE) : note.attributes.shareDate = query.value(1).toLongLong(); note.__isset.attributes = true; note.attributes.__isset.shareDate = true; break; case (NOTE_ATTRIBUTE_PLACE_NAME) : note.attributes.placeName = query.value(1).toString().toStdString(); note.__isset.attributes = true; note.attributes.__isset.placeName = true; break; case (NOTE_ATTRIBUTE_CONTENT_CLASS) : note.attributes.contentClass = query.value(1).toString().toStdString(); note.__isset.attributes = true; note.attributes.__isset.contentClass = true; break; case (NOTE_TAG_LID) : TagTable tagTable; qint32 tagLid = query.value(1).toInt(); Tag tag; tagTable.get(tag, tagLid); note.__isset.tagGuids = true; note.__isset.tagNames = true; note.tagGuids.push_back(tag.guid); note.tagNames.push_back(tag.name); break; } } ResourceTable resTable; QList<qint32> resList; if (resTable.getResourceList(resList, lid)) { for (int i=0; i<resList.size(); i++) { Resource resource; if (loadResources) { resTable.get(resource, resList[i]); } else { QString resGuid = resTable.getGuid(resList[i]); resource.guid = resGuid.toStdString(); resource.__isset.guid = true; } note.__isset.resources = true; note.resources.push_back(resource); } } /* TagScanner test; test.setData(QString::fromStdString(note.content)); QList<TagScannerRecord> retval; int k = test.findAll(retval, QString("en-note")); */ if (note.__isset.guid) return true; else return false; }
// Modify the en-media tag into an attachment void NoteFormatter::modifyApplicationTags(QDomDocument &doc, QDomElement &docElem, QDomElement &enmedia, QDomAttr &hash, QString appl) { QLOG_TRACE() << "Entering NeverNote.modifyApplicationTags"; if (appl.toLower() == "vnd.evernote.ink") { inkNote = true; readOnly = true; buildInkNote(enmedia, hash); QLOG_DEBUG() << doc.toString(); return; } ResourceTable resTable; QString contextFileName; qint32 resLid = resTable.getLidByHashHex(QString::fromStdString(note.guid), hash.value()); Resource r; resTable.get(r, resLid); if (!r.__isset.data) resourceError = true; else { if (r.mime == "application/pdf" && pdfPreview) { modifyPdfTags(resLid, enmedia); return; } QString fileDetails = ""; MimeReference ref; if (r.__isset.attributes && r.attributes.__isset.fileName) fileDetails = QString::fromStdString(r.attributes.fileName); fileDetails = ref.getExtensionFromMime(QString::fromStdString(r.mime), fileDetails); if (fileDetails != "") { if (!noteHistory) { enmedia.setAttribute("href", QString("nnres:") +QString::number(resLid) +global.attachmentNameDelimeter +fileDetails); contextFileName = global.fileManager.getTmpDirPath(QString::number(resLid) +global.attachmentNameDelimeter + fileDetails); } else { enmedia.setAttribute("href", QString("nnres:") +QString::number(resLid) +QString("-")+ QString::number(note.updateSequenceNum) +global.attachmentNameDelimeter +fileDetails); contextFileName = global.fileManager.getTmpDirPath(QString::number(resLid) +QString("-")+ QString(note.updateSequenceNum) +global.attachmentNameDelimeter + fileDetails); } } else { if (!noteHistory) { enmedia.setAttribute("href", "nnres:" +QString::number(resLid) +QString("-") +QString(note.updateSequenceNum) +global.attachmentNameDelimeter +appl); contextFileName = global.fileManager.getTmpDirPath(QString::number(resLid) +QString("-") +QString(note.updateSequenceNum) +global.attachmentNameDelimeter + appl); } else { enmedia.setAttribute("href", "nnres:" +QString::number(resLid) +global.attachmentNameDelimeter +appl); contextFileName = global.fileManager.getTmpDirPath(QString::number(resLid) +global.attachmentNameDelimeter + appl); } } // Setup the context menu. This is useful if we want to do a "save as" or such contextFileName = contextFileName.replace("\\", "/"); enmedia.setAttribute("onContextMenu", "window.browserWindow.resourceContextMenu('" +contextFileName +"');"); enmedia.setAttribute("en-tag", "en-media"); enmedia.setAttribute("lid", QString::number(resLid)); enmedia.setTagName("a"); QDomElement newText = doc.createElement("img"); QFile tfile(contextFileName); tfile.open(QIODevice::WriteOnly); tfile.close(); // Build an icon of the image QString fileExt; if (r.__isset.attributes && r.attributes.__isset.fileName) fileExt = QString::fromStdString(r.attributes.fileName); else fileExt = appl; fileExt = ref.getExtensionFromMime(r.mime, r.attributes.fileName); QString icon = findIcon(resLid, r, fileExt); newText.setAttribute("src", "file:///"+icon); if (r.__isset.attributes && r.attributes.__isset.fileName) newText.setAttribute("title",QString::fromStdString(r.attributes.fileName)); newText.setAttribute("en-tag", "temporary"); enmedia.removeChild(enmedia.firstChild()); enmedia.appendChild(newText); QLOG_TRACE() << "Leaving NeverNote.modifyApplicationTags"; } }