OSDN Git Service

Cleanup compiler warning messages and alter backup & restore to handle new database...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / xml / ImportData.java
index 47e8aa6..30f9a38 100644 (file)
@@ -25,16 +25,23 @@ import java.util.List;
 import java.util.Random;\r
 \r
 import com.evernote.edam.type.Data;\r
+import com.evernote.edam.type.LinkedNotebook;\r
 import com.evernote.edam.type.Note;\r
 import com.evernote.edam.type.NoteAttributes;\r
+import com.evernote.edam.type.NoteSortOrder;\r
 import com.evernote.edam.type.Notebook;\r
+import com.evernote.edam.type.Publishing;\r
 import com.evernote.edam.type.Resource;\r
 import com.evernote.edam.type.ResourceAttributes;\r
 import com.evernote.edam.type.SavedSearch;\r
+import com.evernote.edam.type.SharedNotebook;\r
 import com.evernote.edam.type.Tag;\r
 import com.trolltech.qt.core.QByteArray;\r
 import com.trolltech.qt.core.QFile;\r
 import com.trolltech.qt.core.QIODevice;\r
+import com.trolltech.qt.gui.QIcon;\r
+import com.trolltech.qt.gui.QImage;\r
+import com.trolltech.qt.gui.QPixmap;\r
 import com.trolltech.qt.xml.QXmlStreamAttributes;\r
 import com.trolltech.qt.xml.QXmlStreamReader;\r
 \r
@@ -53,6 +60,8 @@ public class ImportData {
        private Notebook                                        notebook;\r
        private boolean                                         notebookIsDirty;\r
        private boolean                                         notebookIsLocal;\r
+       private boolean                                         notebookIsReadOnly;\r
+       private QIcon                                           notebookIcon;\r
        private Tag                                                     tag;\r
        private boolean                                         tagIsDirty;\r
        private final HashMap<String,Integer>           titleColors;\r
@@ -63,19 +72,19 @@ public class ImportData {
        private final ApplicationLogger         logger;\r
        private final boolean                           backup;\r
        private String                                          notebookGuid;\r
+       private boolean                                         linkedNotebookIsDirty;\r
+       private boolean                                         sharedNotebookIsDirty;\r
+       private LinkedNotebook                          linkedNotebook;\r
+       private SharedNotebook                          sharedNotebook;\r
        public final boolean                            importTags = false;\r
        public final boolean                            importNotebooks = false;\r
-       private final HashMap<String,String>            tagMap;\r
        private final HashMap<String,String>            noteMap;\r
-       private final HashMap<String,String>            notebookMap;\r
        \r
        public ImportData(DatabaseConnection c, boolean full) {\r
                logger = new ApplicationLogger("import.log");\r
                backup = full;\r
                conn = c;\r
                titleColors = new HashMap<String,Integer>();\r
-               notebookMap = new HashMap<String,String>();\r
-               tagMap = new HashMap<String,String>();\r
                noteMap = new HashMap<String,String>();\r
        }\r
        \r
@@ -105,7 +114,8 @@ public class ImportData {
                                String version = attributes.value("version");\r
                                String type = attributes.value("exportType");\r
                                String application = attributes.value("application");\r
-                               if (!version.equalsIgnoreCase("0.85") && !version.equalsIgnoreCase("0.86")) {\r
+                               if (!version.equalsIgnoreCase("0.85") && !version.equalsIgnoreCase("0.86")\r
+                                               && !version.equalsIgnoreCase("0.95")) {\r
                                        lastError = 1;\r
                                        errorMessage = "Unknown backup version = " +version;\r
                                        return;\r
@@ -153,14 +163,14 @@ public class ImportData {
                        if (reader.name().equalsIgnoreCase("notebook") && reader.isStartElement() && (backup || importNotebooks)) {\r
                                processNotebookNode();\r
                        String existingGuid = conn.getNotebookTable().findNotebookByName(notebook.getName());\r
-                       if (existingGuid == null)\r
+                       if (existingGuid == null) {\r
                                conn.getNotebookTable().addNotebook(notebook, notebookIsDirty, notebookIsLocal);\r
-                       else \r
-                       {\r
+                       } else {\r
                                conn.getNotebookTable().updateNotebookGuid(existingGuid, notebook.getGuid());\r
                                conn.getNotebookTable().updateNotebook(notebook, notebookIsDirty);\r
                        }\r
-\r
+                       conn.getNotebookTable().setIcon(notebook.getGuid(), notebookIcon, "PNG");\r
+                       conn.getNotebookTable().setReadOnly(notebook.getGuid(), notebookIsReadOnly);\r
                        }\r
                        if (reader.name().equalsIgnoreCase("tag") && reader.isStartElement() && (backup || importTags)) {\r
                                processTagNode();\r
@@ -176,6 +186,14 @@ public class ImportData {
                                processSavedSearchNode();\r
                        conn.getSavedSearchTable().addSavedSearch(search, searchIsDirty);\r
                        }\r
+                       if (reader.name().equalsIgnoreCase("LinkedNotebook") && reader.isStartElement() && backup) {\r
+                               processLinkedNotebookNode();\r
+                       conn.getLinkedNotebookTable().addNotebook(linkedNotebook, linkedNotebookIsDirty);\r
+                       }\r
+                       if (reader.name().equalsIgnoreCase("SharedNotebook") && reader.isStartElement() && backup) {\r
+                               processSharedNotebookNode();\r
+                       conn.getSharedNotebookTable().addNotebook(sharedNotebook, sharedNotebookIsDirty);\r
+                       }\r
                }\r
                xmlFile.close();\r
        }\r
@@ -452,13 +470,84 @@ public class ImportData {
                                atEnd = true;           }       \r
                return;\r
        }\r
+       \r
+       \r
+       private void processLinkedNotebookNode() {\r
+               linkedNotebook = new LinkedNotebook();\r
+               linkedNotebookIsDirty = false;\r
+               \r
+               boolean atEnd = false;\r
+               while(!atEnd) {\r
+                       if (reader.isStartElement()) {\r
+                               if (reader.name().equalsIgnoreCase("Guid")) \r
+                                       linkedNotebook.setGuid(textValue());\r
+                               if (reader.name().equalsIgnoreCase("ShardID")) \r
+                                       linkedNotebook.setShardId(textValue());\r
+                               if (reader.name().equalsIgnoreCase("UpdateSequenceNumber")) \r
+                                       linkedNotebook.setUpdateSequenceNum(intValue());\r
+                               if (reader.name().equalsIgnoreCase("ShareKey")) \r
+                                       linkedNotebook.setShareKey(textValue());\r
+                               if (reader.name().equalsIgnoreCase("ShareName")) \r
+                                       linkedNotebook.setShareName(textValue());\r
+                               if (reader.name().equalsIgnoreCase("Uri")) \r
+                                       linkedNotebook.setUri(textValue());\r
+                               if (reader.name().equalsIgnoreCase("Username")) \r
+                                       linkedNotebook.setUsername(textValue());\r
+                               if (reader.name().equalsIgnoreCase("Dirty")) {\r
+                                       if (booleanValue())\r
+                                               linkedNotebookIsDirty = true;\r
+                               }\r
+                       }\r
+                       reader.readNext();\r
+                       if (reader.name().equalsIgnoreCase("LinkedNotebook") && reader.isEndElement())\r
+                               atEnd = true;           }       \r
+               return;\r
+       }\r
+\r
+\r
+       private void processSharedNotebookNode() {\r
+               sharedNotebook = new SharedNotebook();\r
+               sharedNotebookIsDirty = false;\r
+               \r
+               boolean atEnd = false;\r
+               while(!atEnd) {\r
+                       if (reader.isStartElement()) {\r
+                               if (reader.name().equalsIgnoreCase("Id")) \r
+                                       sharedNotebook.setId(intValue());\r
+                               if (reader.name().equalsIgnoreCase("Userid")) \r
+                                       sharedNotebook.setUserId(intValue());\r
+                               if (reader.name().equalsIgnoreCase("Email")) \r
+                                       sharedNotebook.setEmail(textValue());\r
+                               if (reader.name().equalsIgnoreCase("NotebookGuid")) \r
+                                       sharedNotebook.setNotebookGuid(textValue());\r
+                               if (reader.name().equalsIgnoreCase("ShareKey")) \r
+                                       sharedNotebook.setShareKey(textValue());\r
+                               if (reader.name().equalsIgnoreCase("Username")) \r
+                                       sharedNotebook.setUsername(textValue());\r
+                               if (reader.name().equalsIgnoreCase("ServiceCreated")) \r
+                                       sharedNotebook.setServiceCreated(longValue());\r
+                               if (reader.name().equalsIgnoreCase("Dirty")) {\r
+                                       if (booleanValue())\r
+                                               sharedNotebookIsDirty = true;\r
+                               }\r
+                       }\r
+                       reader.readNext();\r
+                       if (reader.name().equalsIgnoreCase("LinkedNotebook") && reader.isEndElement())\r
+                               atEnd = true;           }       \r
+               return;\r
+       }\r
 \r
+       \r
 \r
        \r
        private void processNotebookNode() {\r
                notebook = new Notebook();\r
+               Publishing p = new Publishing();\r
+               notebook.setPublishing(p);\r
                notebookIsDirty = false;\r
                notebookIsLocal = false;\r
+               notebookIsReadOnly = false;\r
+               notebookIcon = null;\r
                boolean atEnd = false;\r
                while(!atEnd) {\r
                        if (reader.isStartElement()) {\r
@@ -482,7 +571,38 @@ public class ImportData {
                                if (reader.name().equalsIgnoreCase("LocalNotebook")) {\r
                                        if (booleanValue())\r
                                                notebookIsLocal = true;\r
-                               }       \r
+                               }\r
+                               if (reader.name().equalsIgnoreCase("ReadOnly")) {\r
+                                       if (booleanValue())\r
+                                               notebookIsReadOnly = true;\r
+                               }\r
+                               if (reader.name().equalsIgnoreCase("PublishingPublicDescription")) {\r
+                                       notebook.getPublishing().setPublicDescription(textValue());\r
+                               }\r
+                               if (reader.name().equalsIgnoreCase("PublishingUri")) {\r
+                                       notebook.getPublishing().setUri(textValue());\r
+                               }\r
+                               if (reader.name().equalsIgnoreCase("PublishingOrder")) {\r
+                                       notebook.getPublishing().setOrder(NoteSortOrder.findByValue(intValue()));\r
+                               }\r
+                               if (reader.name().equalsIgnoreCase("ReadOnly")) {\r
+                                       if (booleanValue())\r
+                                               notebookIsReadOnly = true;\r
+                               }\r
+                               if (reader.name().equalsIgnoreCase("PublishingAscending")) {\r
+                                       if (booleanValue())\r
+                                               notebook.getPublishing().setAscending(true);\r
+                                       else\r
+                                               notebook.getPublishing().setAscending(false);\r
+                               }               \r
+                               if (reader.name().equalsIgnoreCase("Icon")) {\r
+                                       byte[] b = textValue().getBytes();   // data binary\r
+                                       QByteArray hexData = new QByteArray(b);\r
+                                       QByteArray binData = new QByteArray(QByteArray.fromHex(hexData));\r
+                                       notebookIcon = new QIcon(QPixmap.fromImage(QImage.fromData(binData)));\r
+                               }\r
+                               if (reader.name().equalsIgnoreCase("Stack"))\r
+                                       notebook.setStack(textValue());\r
                        }\r
                        reader.readNext();\r
                        if (reader.name().equalsIgnoreCase("notebook") && reader.isEndElement())\r