String fileDetails = null;
if (r.getAttributes() != null && r.getAttributes().getFileName() != null && !r.getAttributes().getFileName().equals(""))
fileDetails = r.getAttributes().getFileName();
String contextFileName;
FileManager fileManager = Global.getFileManager();
if (fileDetails != null && !fileDetails.equals("")) {
if (!noteHistory) {
enmedia.setAttribute("href", "nnres://" +r.getGuid()
+Global.attachmentNameDelimeter +fileDetails);
contextFileName = fileManager.getResDirPath(r.getGuid()
+Global.attachmentNameDelimeter + fileDetails);
} else {
enmedia.setAttribute("href", "nnres://" +r.getGuid() + currentNote.getUpdateSequenceNum()
+Global.attachmentNameDelimeter +fileDetails);
contextFileName = fileManager.getResDirPath(r.getGuid() + currentNote.getUpdateSequenceNum()
+Global.attachmentNameDelimeter + fileDetails);
}
} else {
if (!noteHistory) {
enmedia.setAttribute("href", "nnres://" +r.getGuid() +currentNote.getUpdateSequenceNum()
+Global.attachmentNameDelimeter +appl);
contextFileName = fileManager.getResDirPath(r.getGuid() +currentNote.getUpdateSequenceNum()
+Global.attachmentNameDelimeter + appl);
} else {
enmedia.setAttribute("href", "nnres://" +r.getGuid()
+Global.attachmentNameDelimeter +appl);
contextFileName = fileManager.getResDirPath(r.getGuid()
+Global.attachmentNameDelimeter + appl);
}
}
contextFileName = contextFileName.replace("\\", "/");
enmedia.setAttribute("onContextMenu", "window.jambi.resourceContextMenu('" +contextFileName +"');");
if (fileDetails == null || fileDetails.equals(""))
fileDetails = "";
enmedia.setAttribute("en-tag", "en-media");
enmedia.setAttribute("guid", r.getGuid());
enmedia.setTagName("a");
QDomElement newText = doc.createElement("img");
boolean goodPreview = false;
String filePath = "";
if (appl.equalsIgnoreCase("pdf") && pdfPreview) {
String fileName;
Resource res = conn.getNoteTable().noteResourceTable.getNoteResource(r.getGuid(), true);
if (res.getAttributes() != null &&
res.getAttributes().getFileName() != null &&
!res.getAttributes().getFileName().trim().equals(""))
fileName = res.getGuid()+Global.attachmentNameDelimeter+res.getAttributes().getFileName();
else
fileName = res.getGuid()+".pdf";
QFile file = new QFile(fileManager.getResDirPath(fileName));
QFile.OpenMode mode = new QFile.OpenMode();
mode.set(QFile.OpenModeFlag.WriteOnly);
file.open(mode);
QDataStream out = new QDataStream(file);
Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(res.getGuid(), true);
QByteArray binData = new QByteArray(resBinary.getData().getBody());
resBinary = null;
out.writeBytes(binData.toByteArray());
file.close();
PDFPreview pdfPreview = new PDFPreview();
goodPreview = pdfPreview.setupPreview(file.fileName(), appl,0);
if (goodPreview) {
QDomElement span = doc.createElement("span");
QDomElement table = doc.createElement("table");
span.setAttribute("pdfNavigationTable", "true");
QDomElement tr = doc.createElement("tr");
QDomElement td = doc.createElement("td");
QDomElement left = doc.createElement("img");
left.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
left.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
left.setAttribute("onMouseOver", "style.cursor='hand'");
QDomElement right = doc.createElement("img");
right.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
left.setAttribute("onMouseDown", "window.jambi.previousPage('" +file.fileName() +"')");
// NFC TODO: should these be file:// URLs?
left.setAttribute("src", Global.getFileManager().getImageDirPath("small_left.png"));
right.setAttribute("src", Global.getFileManager().getImageDirPath("small_right.png"));
right.setAttribute("onMouseOver", "style.cursor='hand'");
table.appendChild(tr);
tr.appendChild(td);
td.appendChild(left);
td.appendChild(right);
span.appendChild(table);
enmedia.parentNode().insertBefore(span, enmedia);
}
filePath = fileName+".png";
}
String icon = findIcon(appl);
if (icon.equals("attachment.png"))
icon = findIcon(fileDetails.substring(fileDetails.indexOf(".")+1));
// NFC TODO: should this be a 'file://' URL?
newText.setAttribute("src", Global.getFileManager().getImageDirPath(icon));
if (goodPreview) {
// NFC TODO: should this be a 'file://' URL?
newText.setAttribute("src", fileManager.getResDirPathSpecialChar(filePath));
newText.setAttribute("style", "border-style:solid; border-color:green; padding:0.5mm 0.5mm 0.5mm 0.5mm;");
}
newText.setAttribute("title", fileDetails);
enmedia.removeChild(enmedia.firstChild());