type = "."+type.substring(6);
else
type="";
String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNoteGuid, hash.value());
QFile tfile = new QFile(Global.getFileManager().getResDirPath(resGuid + type));
// if (!tfile.exists()) {
Resource r = null;
if (resGuid != null)
r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid,true);
if (r==null || r.getData() == null || r.getData().getBody().length == 0) {
resourceError = true;
readOnly = true;
}
if (r!= null && r.getData() != null && r.getData().getBody().length > 0) {
tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
QByteArray binData = new QByteArray(r.getData().getBody());
tfile.write(binData);
tfile.close();
// If we have recognition text, outline it
addImageHilight(r.getGuid(), tfile);
enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());
enmedia.setAttribute("en-tag", "en-media");
enmedia.setNodeValue("");
enmedia.setAttribute("guid", r.getGuid());
enmedia.setTagName("img");
}
// }
// Technically, we should do a file:// to have a proper url, but for some reason QWebPage hates
// them and won't generate a thumbnail image properly if we use them.
// enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());
enmedia.setAttribute("src", tfile.fileName().toString());
enmedia.setAttribute("en-tag", "en-media");
enmedia.setTagName("img");
if (r != null && r.getAttributes() != null &&
(r.getAttributes().getSourceURL() == null || !r.getAttributes().getSourceURL().toLowerCase().startsWith("http://latex.codecogs.com/gif.latex?")))
enmedia.setAttribute("onContextMenu", "window.jambi.imageContextMenu('" +tfile.fileName() +"');");
else {
QDomElement newText = doc.createElement("a");
enmedia.setAttribute("src", tfile.fileName().toString());
enmedia.setAttribute("en-tag", "en-latex");
newText.setAttribute("onMouseOver", "style.cursor='hand'");
if (r!= null && r.getAttributes() != null && r.getAttributes().getSourceURL() != null)
newText.setAttribute("title", r.getAttributes().getSourceURL());
newText.setAttribute("href", "latex://"+tfile.fileName().toString());
enmedia.parentNode().replaceChild(newText, enmedia);
newText.appendChild(enmedia);
}
enmedia.setNodeValue("");