/* If we have an ink note, then we need to pull the image and display it */ bool NoteFormatter::buildInkNote(QDomElement &docElem, QDomAttr &hash) { ResourceTable resTable; qint32 resLid = resTable.getLidByHashHex(QString::fromStdString(note.guid), hash.value()); if (resLid <= 0) return false; docElem.setAttribute("en-tag", "en-media"); docElem.setAttribute("lid", QString::number(resLid)); docElem.setAttribute("type", "application/vnd.evernote.ink"); QString filename = QString("file:///") +global.fileManager.getDbaDirPath()+QString::number(resLid)+QString(".png"); docElem.setAttribute("src", filename); docElem.setTagName("img"); return true; }
/* 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"); }
// 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"; } }