OSDN Git Service

Correct problem with # in the file name of an attachment.
authorRandy Baumgarte <randy@fbn.cx>
Mon, 26 Sep 2011 16:08:09 +0000 (12:08 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Mon, 26 Sep 2011 16:08:09 +0000 (12:08 -0400)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/config/FileManager.java
src/cx/fbn/nevernote/gui/BrowserWindow.java
src/cx/fbn/nevernote/xml/NoteFormatter.java

index 7d9aa53..df4546a 100644 (file)
@@ -965,7 +965,7 @@ public class NeverNote extends QMainWindow{
             if (lower.startsWith("--disable-viewing"))
                startupConfig.setDisableViewing(true);
         }
-                Global.setup(startupConfig);
+        Global.setup(startupConfig);
     }
 
     // Exit point
index fc67ab0..9345fd2 100644 (file)
@@ -243,6 +243,15 @@ public class FileManager {
     public String getResDirPath(String relativePath) {
         return resDirPath + toPlatformPathSeparator(relativePath);
     }
+    
+    /**
+     * Get a path below the 'res' directory, using native {@link File#separator}.
+     * This will contain backslashes on Windows.  This is different from the 
+     * one above in that it will encode the relative path
+     */
+    public String getResDirPathSpecialChar(String relativePath) {
+               return resDirPath + toPlatformPathSeparator(relativePath).replace("#", "%23");
+    }
 
     /**
      * Get a file below the 'xml' directory.
@@ -262,7 +271,7 @@ public class FileManager {
     private static String toPlatformPathSeparator(String relativePath) {
        // Sometimes a space in the file name comes across as a %20.  This is to put it back as a space.
        relativePath = relativePath.replace("%20", " ");
-               return ALL_PATH_SEPARATORS_REGEX.matcher(relativePath).replaceAll(
+       return ALL_PATH_SEPARATORS_REGEX.matcher(relativePath).replaceAll(
                                // Must double-escape backslashes,
                                // because they have special meaning in the replacement string of Matcher.replaceAll
                                (File.separator.equals("\\") ? "\\\\" : File.separator));
index 052bad6..6c44862 100644 (file)
@@ -1099,8 +1099,6 @@ public class BrowserWindow extends QWidget {
                }\r
                QClipboard clipboard = QApplication.clipboard();\r
                QMimeData mime = clipboard.mimeData();\r
-               \r
-//              String x = mime.html();\r
 \r
                if (mime.hasImage()) {\r
                        logger.log(logger.EXTREME, "Image paste found");\r
@@ -1112,7 +1110,7 @@ public class BrowserWindow extends QWidget {
 \r
                if (mime.hasUrls()) {\r
                        logger.log(logger.EXTREME, "URL paste found");\r
-                       if (!mime.text().startsWith("evernote:")) {\r
+                       if (mime.text().startsWith("evernote:")) {\r
                                handleNoteLink(mime);\r
                        } else {\r
                                handleUrls(mime);\r
@@ -2406,15 +2404,15 @@ public class BrowserWindow extends QWidget {
                                imageURL = file.fileName() + ".png";\r
                                }\r
                        }\r
-                                               \r
+                       \r
                        logger.log(logger.EXTREME, "Generating link tags");\r
                        buffer.delete(0, buffer.length());\r
                        buffer.append("<a en-tag=\"en-media\" guid=\"" +newRes.getGuid()+"\" ");\r
                        buffer.append(" onContextMenu=\"window.jambi.imageContextMenu(&apos;")\r
                      .append(Global.getFileManager().getResDirPath(fileName))\r
                      .append("&apos;);\" ");                   buffer.append("type=\"" + mimeType + "\" href=\"nnres://" + fileName +"\" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\" >");\r
-                       buffer.append("<img src=\"" + imageURL + "\" title=\"" +newRes.getAttributes().getFileName());\r
-                       buffer.append("\"></img>");\r
+                       buffer.append("<img src='\"" + imageURL + "\" title=\"" +new QUrl(newRes.getAttributes().getFileName()).toEncoded().toString());\r
+                       buffer.append("\"'></img>");\r
                        buffer.append("</a>");\r
                        browser.page().mainFrame().evaluateJavaScript(\r
                                        script_start + buffer.toString() + script_end);\r
@@ -2424,13 +2422,18 @@ public class BrowserWindow extends QWidget {
 \r
        private Resource createResource(String url, int sequence, String mime, boolean attachment) {\r
                logger.log(logger.EXTREME, "Inside create resource");\r
-               QFile resourceFile;\r
+               QFile resourceFile; \r
+               //These two lines are added to handle odd characters in the name like #.  Without it\r
+               // toLocalFile() chokes and returns the wrong name.\r
+               url = url.replace("file:///", "");\r
+               url = url.replace("file://", "");\r
                String urlTest = new QUrl(url).toLocalFile();\r
+               urlTest = url;\r
                if (!urlTest.equals(""))\r
                        url = urlTest;\r
-               url = url.replace("/", File.separator);\r
+//             url = url.replace("/", File.separator);\r
                logger.log(logger.EXTREME, "Reading from file to create resource");\r
-       resourceFile = new QFile(url); \r
+               resourceFile = new QFile(url); \r
        resourceFile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly));\r
 //     logger.log(logger.EXTREME, "Error opening file "+url.toString()  +": "+resourceFile.errorString());\r
        byte[] fileData = resourceFile.readAll().toByteArray();\r
index 0632121..f93a523 100644 (file)
@@ -197,6 +197,7 @@ public class NoteFormatter {
                        for (int j=z-1; j>i+1; j--) \r
                                html.deleteCharAt(j);\r
                } \r
+\r
                return html.toString();\r
        }       \r
 \r
@@ -584,7 +585,7 @@ public class NoteFormatter {
                                newText.setAttribute("src", Global.getFileManager().getImageDirPath(icon));\r
                                if (goodPreview) {\r
                                // NFC TODO: should this be a 'file://' URL?\r
-                                       newText.setAttribute("src", fileManager.getResDirPath(filePath));\r
+                                       newText.setAttribute("src", fileManager.getResDirPathSpecialChar(filePath));\r
                                        newText.setAttribute("style", "border-style:solid; border-color:green; padding:0.5mm 0.5mm 0.5mm 0.5mm;");\r
                                }\r
                                newText.setAttribute("title", fileDetails);\r