OSDN Git Service

Change generation of files/paths in images dir to use FileManager
authorNick Clarke <memorius@gmail.com>
Mon, 19 Jul 2010 15:18:27 +0000 (03:18 +1200)
committerRandy Baumgarte <randy@fbn.cx>
Fri, 23 Jul 2010 09:31:06 +0000 (05:31 -0400)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/dialog/OnlineNoteHistory.java
src/cx/fbn/nevernote/gui/BrowserWindow.java
src/cx/fbn/nevernote/utilities/FileImporter.java

index 7af20d5..9bebc03 100644 (file)
@@ -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++;
index 925b377..ce58148 100644 (file)
@@ -42,6 +42,7 @@ import com.trolltech.qt.xml.QDomElement;
 import com.trolltech.qt.xml.QDomNodeList;\r
 \r
 import cx.fbn.nevernote.Global;\r
+import cx.fbn.nevernote.NeverNote;\r
 import cx.fbn.nevernote.gui.BrowserWindow;\r
 import cx.fbn.nevernote.sql.DatabaseConnection;\r
 \r
@@ -220,7 +221,7 @@ public class OnlineNoteHistory extends QDialog {
                        QDomElement enmedia = anchors.at(i).toElement();\r
                        //enmedia.setAttribute("style","display:none");\r
                        enmedia.setAttribute("contentEditable","false");\r
-                       enmedia.setAttribute("src", Global.getDirectoryPath()+"images/encrypt.png");\r
+                       enmedia.setAttribute("src", Global.getFileManager().getImageDirPath("encrypt.png"));\r
                        enmedia.setAttribute("en-tag","en-crypt");\r
                        enmedia.setAttribute("alt", enmedia.text());\r
                        Global.cryptCounter++;\r
@@ -289,19 +290,25 @@ public class OnlineNoteHistory extends QDialog {
                                        String icon = findIcon(appl);\r
                                        if (icon.equals("attachment.png"))\r
                                                icon = findIcon(fileDetails.substring(fileDetails.indexOf(".")+1));\r
-                                       newText.setAttribute("src", Global.getDirectoryPath()+"images"+File.separator +icon);   \r
+                                       newText.setAttribute("src", Global.getFileManager().getImageDirPath(icon));\r
                                        newText.setAttribute("title", fileDetails);\r
                                        enmedia.removeChild(enmedia.firstChild());\r
                                        enmedia.appendChild(newText);\r
                                }\r
                        }\r
            }\r
-           // find the appropriate icon for an attachment\r
+          /**\r
+           * find the appropriate icon for an attachment\r
+           *\r
+            * NFC TODO: duplicate of {@link NeverNote#findIcon(String)}\r
+           */\r
            private String findIcon(String appl) {\r
                appl = appl.toLowerCase();\r
-               File f = new File(Global.getDirectoryPath()+"images"+File.separator +appl +".png");\r
-               if (f.exists())\r
-                       return appl+".png";\r
+        String relativePath = appl + ".png";\r
+        File f = Global.getFileManager().getImageDirFile(relativePath);\r
+        if (f.exists()) {\r
+            return relativePath;\r
+        }\r
                return "attachment.png";\r
            }\r
            \r
index cf1ca27..e094038 100644 (file)
@@ -93,6 +93,7 @@ import cx.fbn.nevernote.signals.NoteResourceSignal;
 import cx.fbn.nevernote.signals.NoteSignal;\r
 import cx.fbn.nevernote.sql.DatabaseConnection;\r
 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
+import cx.fbn.nevernote.utilities.FileUtils;\r
 \r
 public class BrowserWindow extends QWidget {\r
 \r
@@ -1074,17 +1075,13 @@ public class BrowserWindow extends QWidget {
                        QMessageBox.information(this, "Error", "Error Encrypting String");\r
                        return;\r
                }\r
-               StringBuffer imgPath = new StringBuffer(Global.getDirectoryPath());\r
-               for (int i = 0; i < imgPath.length(); i++)\r
-                       if (imgPath.charAt(i) == '\\')\r
-                               imgPath.setCharAt(i, '/');\r
                StringBuffer buffer = new StringBuffer(encrypted.length() + 100);\r
                buffer.append("<img en-tag=\"en-crypt\" cipher=\"RC2\" hint=\""\r
                                + dialog.getHint().replace("'","\\'") + "\" length=\"64\" ");\r
                buffer.append("contentEditable=\"false\" alt=\"");\r
                buffer.append(encrypted);\r
-               buffer.append("\" src=\"" + imgPath.toString()\r
-                               + "images/encrypt.png\" ");\r
+               // NFC FIXME: should this be a file URL like in handleLocalAttachment and importAttachment?\r
+               buffer.append("\" src=\"").append(FileUtils.toForwardSlashedPath(Global.getFileManager().getImageDirPath("encrypt.png")));\r
                Global.cryptCounter++;\r
                buffer.append(" id=\"crypt"+Global.cryptCounter.toString() +"\"");\r
                buffer.append(" onMouseOver=\"style.cursor=\\'hand\\'\"");\r
@@ -1621,23 +1618,8 @@ public class BrowserWindow extends QWidget {
                                icon = findIcon(type[0]);\r
                        if (icon.equals("attachment.png"))\r
                                icon = findIcon(url.substring(url.lastIndexOf(".")+1));\r
-                       StringBuffer imageBuffer = new StringBuffer();\r
-                       String whichOS = System.getProperty("os.name");\r
-                       if (whichOS.contains("Windows")) \r
-                               imageBuffer.append("file:///" + Global.getDirectoryPath()\r
-                                               + "images/" + icon);\r
-                       else\r
-                               imageBuffer.append("file://" + Global.getDirectoryPath()\r
-                                               + "images/" + icon);\r
-                       // Fix stupid Windows file separation characters\r
-                       if (whichOS.contains("Windows")) {\r
-                               for (int z = imageBuffer.indexOf("\\"); z > 0; z = imageBuffer\r
-                                               .indexOf("\\")) {\r
-                                       int w = imageBuffer.indexOf("\\");\r
-                                       imageBuffer.replace(w, w + 1, "/");\r
-                               }\r
+                       String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon));\r
 \r
-                       }\r
                        logger.log(logger.EXTREME, "Creating resource ");\r
                        Resource newRes = createResource(url, i, mimeType, true);\r
                        if (newRes == null)\r
@@ -1669,14 +1651,14 @@ public class BrowserWindow extends QWidget {
 \r
                                PDFPreview pdfPreview = new PDFPreview();\r
                                if (pdfPreview.setupPreview(Global.currentDir+"res/"+fileName, "pdf",0));\r
-                                       imageBuffer = new StringBuffer(file.fileName()+".png");\r
+                                       imageURL = file.fileName() + ".png";\r
                        }\r
                                                \r
                        logger.log(logger.EXTREME, "Generating link tags");\r
                        buffer.append("<a en-tag=\"en-media\" guid=\"" +newRes.getGuid()+"\" ");\r
                        buffer.append(" onContextMenu=\"window.jambi.imageContextMenu(&apos;" +Global.getDirectoryPath() +"res/"+fileName +"&apos;);\" ");\r
                        buffer.append("type=\"" + mimeType + "\" href=\"nnres://" + fileName +"\" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\" >");\r
-                       buffer.append("<img src=\"" + imageBuffer.toString()+"\" title=\"" +newRes.getAttributes().getFileName());\r
+                       buffer.append("<img src=\"" + imageURL + "\" title=\"" +newRes.getAttributes().getFileName());\r
                        buffer.append("\"></img>");\r
                        buffer.append("</a>");\r
                        browser.page().mainFrame().evaluateJavaScript(\r
@@ -1765,7 +1747,7 @@ public class BrowserWindow extends QWidget {
     // find the appropriate icon for an attachment\r
     private String findIcon(String appl) {\r
        appl = appl.toLowerCase();\r
-       File f = new File(Global.getDirectoryPath()+"images"+File.separator +appl +".png");\r
+        File f = Global.getFileManager().getImageDirFile(appl + ".png");\r
        if (f.exists())\r
                return appl+".png";\r
        return "attachment.png";\r
index 140c81d..709d824 100644 (file)
@@ -38,6 +38,7 @@ import com.trolltech.qt.core.QIODevice;
 import com.trolltech.qt.webkit.QWebPage;\r
 \r
 import cx.fbn.nevernote.Global;\r
+import cx.fbn.nevernote.NeverNote;\r
 import cx.fbn.nevernote.sql.DatabaseConnection;\r
 \r
 \r
@@ -157,26 +158,10 @@ public class FileImporter  {
                newRes.getAttributes().setFileName(fileInfo.fileName());\r
                \r
                String icon = findIcon(fileInfo.completeSuffix());\r
-                       StringBuffer imageBuffer = new StringBuffer();\r
-                       String whichOS = System.getProperty("os.name");\r
-                       if (whichOS.contains("Windows")) \r
-                               imageBuffer.append("file:///" + Global.getDirectoryPath()\r
-                                               + "images/" + icon);\r
-                       else\r
-                               imageBuffer.append("file://" + Global.getDirectoryPath()\r
-                                               + "images/" + icon);\r
-                       // Fix stupid Windows file separation characters\r
-                       if (whichOS.contains("Windows")) {\r
-                               for (int z = imageBuffer.indexOf("\\"); z > 0; \r
-                                       z = imageBuffer.indexOf("\\")) {\r
-                                       int w = imageBuffer.indexOf("\\");\r
-                                       imageBuffer.replace(w, w + 1, "/");\r
-                               }\r
-\r
-                       }\r
+               String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon));\r
                buffer.append("<a en-tag=\"en-media\" guid=\"" +newRes.getGuid()+"\" ");\r
                        buffer.append("type=\"" + mimeType + "\" href=\"nnres://" + fileName +"\" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\" >");\r
-                       buffer.append("<img src=\"" + imageBuffer.toString()+"\" title=\"" +newRes.getAttributes().getFileName());\r
+                       buffer.append("<img src=\"" + imageURL +"\" title=\"" +newRes.getAttributes().getFileName());\r
                        buffer.append("\">");\r
                        buffer.append("</a>");\r
        }\r
@@ -407,15 +392,19 @@ public class FileImporter  {
        public String getNoteContent() {\r
                return noteString;\r
        }\r
-       //********************************************************\r
-       //* Find an icon for an attachment\r
-       //********************************************************\r
-    // find the appropriate icon for an attachment\r
+\r
+    /**\r
+     * find the appropriate icon for an attachment\r
+     * NFC TODO: duplicate of {@link NeverNote#findIcon(String)}\r
+     */\r
     private String findIcon(String appl) {\r
-       appl = appl.toLowerCase();\r
-       File f = new File(Global.getDirectoryPath()+"images"+File.separator +appl +".png");\r
-       if (f.exists())\r
-               return appl+".png";\r
-       return "attachment.png";\r
+        appl = appl.toLowerCase();\r
+        String relativePath = appl + ".png";\r
+        File f = Global.getFileManager().getImageDirFile(relativePath);\r
+        if (f.exists()) {\r
+            return relativePath;\r
+        }\r
+        return "attachment.png";\r
     }\r
+\r
 }\r