From: Nick Clarke Date: Mon, 19 Jul 2010 15:18:27 +0000 (+1200) Subject: Change generation of files/paths in images dir to use FileManager X-Git-Tag: version0.1.1~440 X-Git-Url: http://git.sourceforge.jp/view?p=neighbornote%2FNeighborNote.git;a=commitdiff_plain;h=2bcc06aee03e77343f15cf92b2aa63fde1edb299 Change generation of files/paths in images dir to use FileManager --- diff --git a/src/cx/fbn/nevernote/NeverNote.java b/src/cx/fbn/nevernote/NeverNote.java index 7af20d5..9bebc03 100644 --- a/src/cx/fbn/nevernote/NeverNote.java +++ b/src/cx/fbn/nevernote/NeverNote.java @@ -3771,9 +3771,11 @@ public class NeverNote extends QMainWindow{ private String findIcon(String appl) { logger.log(logger.HIGH, "Entering NeverNote.findIcon"); appl = appl.toLowerCase(); - File f = new File(Global.getDirectoryPath()+"images"+File.separator +appl +".png"); - if (f.exists()) - return appl+".png"; + String relativePath = appl + ".png"; + File f = Global.getFileManager().getImageDirFile(relativePath); + if (f.exists()) { + return relativePath; + } logger.log(logger.HIGH, "Leaving NeverNote.findIcon"); return "attachment.png"; } @@ -3857,8 +3859,9 @@ public class NeverNote extends QMainWindow{ QDomElement right = doc.createElement("img"); right.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')"); left.setAttribute("onMouseDown", "window.jambi.previousPage('" +file.fileName() +"')"); - left.setAttribute("src", Global.currentDir+"images/small_left.png"); - right.setAttribute("src", Global.currentDir+"images/small_right.png"); + // 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); @@ -3873,7 +3876,8 @@ public class NeverNote extends QMainWindow{ String icon = findIcon(appl); if (icon.equals("attachment.png")) icon = findIcon(fileDetails.substring(fileDetails.indexOf(".")+1)); - newText.setAttribute("src", Global.getDirectoryPath()+"images"+File.separator +icon); + // NFC TODO: should this be a 'file://' URL? + newText.setAttribute("src", Global.getFileManager().getImageDirPath(icon)); if (goodPreview) { newText.setAttribute("src", Global.getDirectoryPath()+"res/"+filePath); newText.setAttribute("style", "border-style:solid; border-color:green; padding:0.5mm 0.5mm 0.5mm 0.5mm;"); @@ -4000,7 +4004,7 @@ public class NeverNote extends QMainWindow{ for (int i=enCryptLen-1; i>=0; i--) { QDomElement enmedia = anchors.at(i).toElement(); enmedia.setAttribute("contentEditable","false"); - enmedia.setAttribute("src", Global.getDirectoryPath()+"images/encrypt.png"); + enmedia.setAttribute("src", Global.getFileManager().getImageDirPath("encrypt.png")); enmedia.setAttribute("en-tag","en-crypt"); enmedia.setAttribute("alt", enmedia.text()); Global.cryptCounter++; diff --git a/src/cx/fbn/nevernote/dialog/OnlineNoteHistory.java b/src/cx/fbn/nevernote/dialog/OnlineNoteHistory.java index 925b377..ce58148 100644 --- a/src/cx/fbn/nevernote/dialog/OnlineNoteHistory.java +++ b/src/cx/fbn/nevernote/dialog/OnlineNoteHistory.java @@ -42,6 +42,7 @@ import com.trolltech.qt.xml.QDomElement; import com.trolltech.qt.xml.QDomNodeList; import cx.fbn.nevernote.Global; +import cx.fbn.nevernote.NeverNote; import cx.fbn.nevernote.gui.BrowserWindow; import cx.fbn.nevernote.sql.DatabaseConnection; @@ -220,7 +221,7 @@ public class OnlineNoteHistory extends QDialog { QDomElement enmedia = anchors.at(i).toElement(); //enmedia.setAttribute("style","display:none"); enmedia.setAttribute("contentEditable","false"); - enmedia.setAttribute("src", Global.getDirectoryPath()+"images/encrypt.png"); + enmedia.setAttribute("src", Global.getFileManager().getImageDirPath("encrypt.png")); enmedia.setAttribute("en-tag","en-crypt"); enmedia.setAttribute("alt", enmedia.text()); Global.cryptCounter++; @@ -289,19 +290,25 @@ public class OnlineNoteHistory extends QDialog { String icon = findIcon(appl); if (icon.equals("attachment.png")) icon = findIcon(fileDetails.substring(fileDetails.indexOf(".")+1)); - newText.setAttribute("src", Global.getDirectoryPath()+"images"+File.separator +icon); + newText.setAttribute("src", Global.getFileManager().getImageDirPath(icon)); newText.setAttribute("title", fileDetails); enmedia.removeChild(enmedia.firstChild()); enmedia.appendChild(newText); } } } - // find the appropriate icon for an attachment + /** + * find the appropriate icon for an attachment + * + * NFC TODO: duplicate of {@link NeverNote#findIcon(String)} + */ private String findIcon(String appl) { appl = appl.toLowerCase(); - File f = new File(Global.getDirectoryPath()+"images"+File.separator +appl +".png"); - if (f.exists()) - return appl+".png"; + String relativePath = appl + ".png"; + File f = Global.getFileManager().getImageDirFile(relativePath); + if (f.exists()) { + return relativePath; + } return "attachment.png"; } diff --git a/src/cx/fbn/nevernote/gui/BrowserWindow.java b/src/cx/fbn/nevernote/gui/BrowserWindow.java index cf1ca27..e094038 100644 --- a/src/cx/fbn/nevernote/gui/BrowserWindow.java +++ b/src/cx/fbn/nevernote/gui/BrowserWindow.java @@ -93,6 +93,7 @@ import cx.fbn.nevernote.signals.NoteResourceSignal; import cx.fbn.nevernote.signals.NoteSignal; import cx.fbn.nevernote.sql.DatabaseConnection; import cx.fbn.nevernote.utilities.ApplicationLogger; +import cx.fbn.nevernote.utilities.FileUtils; public class BrowserWindow extends QWidget { @@ -1074,17 +1075,13 @@ public class BrowserWindow extends QWidget { QMessageBox.information(this, "Error", "Error Encrypting String"); return; } - StringBuffer imgPath = new StringBuffer(Global.getDirectoryPath()); - for (int i = 0; i < imgPath.length(); i++) - if (imgPath.charAt(i) == '\\') - imgPath.setCharAt(i, '/'); StringBuffer buffer = new StringBuffer(encrypted.length() + 100); buffer.append("\""); 0; z = imageBuffer - .indexOf("\\")) { - int w = imageBuffer.indexOf("\\"); - imageBuffer.replace(w, w + 1, "/"); - } + String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon)); - } logger.log(logger.EXTREME, "Creating resource "); Resource newRes = createResource(url, i, mimeType, true); if (newRes == null) @@ -1669,14 +1651,14 @@ public class BrowserWindow extends QWidget { PDFPreview pdfPreview = new PDFPreview(); if (pdfPreview.setupPreview(Global.currentDir+"res/"+fileName, "pdf",0)); - imageBuffer = new StringBuffer(file.fileName()+".png"); + imageURL = file.fileName() + ".png"; } logger.log(logger.EXTREME, "Generating link tags"); buffer.append(""); - buffer.append(""); buffer.append(""); browser.page().mainFrame().evaluateJavaScript( @@ -1765,7 +1747,7 @@ public class BrowserWindow extends QWidget { // find the appropriate icon for an attachment private String findIcon(String appl) { appl = appl.toLowerCase(); - File f = new File(Global.getDirectoryPath()+"images"+File.separator +appl +".png"); + File f = Global.getFileManager().getImageDirFile(appl + ".png"); if (f.exists()) return appl+".png"; return "attachment.png"; diff --git a/src/cx/fbn/nevernote/utilities/FileImporter.java b/src/cx/fbn/nevernote/utilities/FileImporter.java index 140c81d..709d824 100644 --- a/src/cx/fbn/nevernote/utilities/FileImporter.java +++ b/src/cx/fbn/nevernote/utilities/FileImporter.java @@ -38,6 +38,7 @@ import com.trolltech.qt.core.QIODevice; import com.trolltech.qt.webkit.QWebPage; import cx.fbn.nevernote.Global; +import cx.fbn.nevernote.NeverNote; import cx.fbn.nevernote.sql.DatabaseConnection; @@ -157,26 +158,10 @@ public class FileImporter { newRes.getAttributes().setFileName(fileInfo.fileName()); String icon = findIcon(fileInfo.completeSuffix()); - StringBuffer imageBuffer = new StringBuffer(); - String whichOS = System.getProperty("os.name"); - if (whichOS.contains("Windows")) - imageBuffer.append("file:///" + Global.getDirectoryPath() - + "images/" + icon); - else - imageBuffer.append("file://" + Global.getDirectoryPath() - + "images/" + icon); - // Fix stupid Windows file separation characters - if (whichOS.contains("Windows")) { - for (int z = imageBuffer.indexOf("\\"); z > 0; - z = imageBuffer.indexOf("\\")) { - int w = imageBuffer.indexOf("\\"); - imageBuffer.replace(w, w + 1, "/"); - } - - } + String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon)); buffer.append(""); - buffer.append(""); buffer.append(""); } @@ -407,15 +392,19 @@ public class FileImporter { public String getNoteContent() { return noteString; } - //******************************************************** - //* Find an icon for an attachment - //******************************************************** - // find the appropriate icon for an attachment + + /** + * find the appropriate icon for an attachment + * NFC TODO: duplicate of {@link NeverNote#findIcon(String)} + */ private String findIcon(String appl) { - appl = appl.toLowerCase(); - File f = new File(Global.getDirectoryPath()+"images"+File.separator +appl +".png"); - if (f.exists()) - return appl+".png"; - return "attachment.png"; + appl = appl.toLowerCase(); + String relativePath = appl + ".png"; + File f = Global.getFileManager().getImageDirFile(relativePath); + if (f.exists()) { + return relativePath; + } + return "attachment.png"; } + }