OSDN Git Service

Alter save thread logic so that if an error happens, a message box is produced rather...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / threads / SaveRunner.java
index 9efbd1a..418c211 100644 (file)
@@ -29,6 +29,7 @@ import com.trolltech.qt.core.QObject;
 \r
 import cx.fbn.nevernote.Global;\r
 import cx.fbn.nevernote.evernote.EnmlConverter;\r
+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.Pair;\r
@@ -40,6 +41,7 @@ public class SaveRunner extends QObject implements Runnable {
        public QMutex                                           threadLock;\r
        private final DatabaseConnection        conn;\r
        private boolean                                         idle;\r
+       public NoteSignal                                       noteSignals;\r
 \r
        private volatile LinkedBlockingQueue<Pair<String, String>> workQueue = new LinkedBlockingQueue<Pair<String, String>>();\r
        \r
@@ -52,6 +54,7 @@ public class SaveRunner extends QObject implements Runnable {
                conn = new DatabaseConnection(logger, u, uid, pswd, cpswd);\r
                threadLock = new QMutex();\r
                keepRunning = true;\r
+               noteSignals = new NoteSignal();\r
        }\r
        \r
        \r
@@ -136,14 +139,15 @@ public class SaveRunner extends QObject implements Runnable {
                EnmlConverter enml = new EnmlConverter(logger);\r
                String newContent = enml.convert(guid, content);\r
                String fixedContent = enml.fixEnXMLCrap(newContent);\r
-               conn.getNoteTable().updateNoteContent(guid, fixedContent);\r
-\r
-\r
-               logger.log(logger.EXTREME, "Saving new note resources");\r
-               List<Resource> oldResources = conn.getNoteTable().noteResourceTable.getNoteResources(guid, false);\r
-               List<String> newResources = enml.getResources();\r
-               removeObsoleteResources(oldResources, newResources);\r
-               \r
+               if (fixedContent != null) {\r
+                       conn.getNoteTable().updateNoteContent(guid, fixedContent);\r
+                       logger.log(logger.EXTREME, "Saving new note resources");\r
+                       List<Resource> oldResources = conn.getNoteTable().noteResourceTable.getNoteResources(guid, false);\r
+                       List<String> newResources = enml.getResources();\r
+                       removeObsoleteResources(oldResources, newResources);\r
+               } else {\r
+                       noteSignals.noteSaveRunnerError.emit(guid, null);\r
+               }\r
                logger.log(logger.HIGH, "Leaving ListManager.updateNoteContent");\r
        }\r
        \r