OSDN Git Service

Add Linked notebooks to the ignore sync process.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / threads / SyncRunner.java
index 57fb0fb..1fcc42a 100644 (file)
@@ -29,8 +29,8 @@ import java.util.ArrayList;
 import java.util.Calendar;\r
 import java.util.Date;\r
 import java.util.GregorianCalendar;\r
-import java.util.HashMap;\r
 import java.util.List;\r
+import java.util.TreeSet;\r
 import java.util.Vector;\r
 import java.util.concurrent.LinkedBlockingQueue;\r
 \r
@@ -138,8 +138,9 @@ public class SyncRunner extends QObject implements Runnable {
                String dburl;\r
                String dbpswd;\r
                String dbcpswd;\r
-               private final HashMap<String,String> ignoreTags;\r
-               private final HashMap<String,String> ignoreNotebooks;\r
+               private final TreeSet<String> ignoreTags;\r
+               private final TreeSet<String> ignoreNotebooks;\r
+               private final TreeSet<String> ignoreLinkedNotebooks;\r
        \r
                \r
                \r
@@ -170,8 +171,9 @@ public class SyncRunner extends QObject implements Runnable {
                userStore = null;\r
                authToken = null;\r
                disableUploads = false;\r
-               ignoreTags = new HashMap<String,String>();\r
-               ignoreNotebooks = new HashMap<String,String>();\r
+               ignoreTags = new TreeSet<String>();\r
+               ignoreNotebooks = new TreeSet<String>();\r
+               ignoreLinkedNotebooks = new TreeSet<String>();\r
                \r
 //             setAutoDelete(false);\r
                workQueue=new LinkedBlockingQueue<String>(MAX_QUEUED_WAITING);\r
@@ -266,12 +268,17 @@ public class SyncRunner extends QObject implements Runnable {
                ignoreNotebooks.clear();\r
                List<String> ignore = conn.getSyncTable().getIgnoreRecords("NOTEBOOK");\r
                for (int i=0; i<ignore.size(); i++) \r
-                       ignoreNotebooks.put(ignore.get(i),"");\r
+                       ignoreNotebooks.add(ignore.get(i));\r
+               \r
+               ignore.clear();\r
+               ignore = conn.getSyncTable().getIgnoreRecords("LINKEDNOTEBOOK");\r
+               for (int i=0; i<ignore.size(); i++) \r
+                       ignoreLinkedNotebooks.add(ignore.get(i));\r
                \r
                ignoreTags.clear();\r
                ignore = conn.getSyncTable().getIgnoreRecords("TAG");\r
                for (int i=0; i<ignore.size(); i++) \r
-                       ignoreTags.put(ignore.get(i),"");\r
+                       ignoreTags.add(ignore.get(i));\r
 \r
                // Make sure we are connected & should keep running\r
                if (isConnected && keepRunning) {\r
@@ -412,7 +419,8 @@ public class SyncRunner extends QObject implements Runnable {
                        }\r
                        \r
                        status.message.emit(tr("Cleaning up"));\r
-                       List<String> notes = conn.getNoteTable().expungeIgnoreSynchronizedNotes(conn.getSyncTable().getIgnoreRecords("NOTEBOOK"), conn.getSyncTable().getIgnoreRecords("TAG"));\r
+                       List<String> notes = conn.getNoteTable().expungeIgnoreSynchronizedNotes(conn.getSyncTable().getIgnoreRecords("NOTEBOOK"), \r
+                                       conn.getSyncTable().getIgnoreRecords("TAG"), conn.getSyncTable().getIgnoreRecords("LINKEDNOTEBOOK"));\r
                        if (notes.size() > 0)\r
                                syncSignal.refreshLists.emit();\r
                        \r
@@ -1228,10 +1236,10 @@ public class SyncRunner extends QObject implements Runnable {
                                        moveConflictingNote(n.getGuid());\r
                        }\r
                        boolean ignoreNote = false;\r
-                       if (ignoreNotebooks.containsKey(n.getNotebookGuid()))\r
+                       if (ignoreNotebooks.contains(n.getNotebookGuid()))\r
                                ignoreNote = true;\r
                        for (int i=0; i<n.getTagGuidsSize(); i++) {\r
-                               if (ignoreTags.containsKey(n.getTagGuids().get(i))) {\r
+                               if (ignoreTags.contains(n.getTagGuids().get(i))) {\r
                                        ignoreNote = true;\r
                                        i=n.getTagGuidsSize();\r
                                }\r
@@ -1784,17 +1792,17 @@ public class SyncRunner extends QObject implements Runnable {
        List<LinkedNotebook> books = conn.getLinkedNotebookTable().getAll();\r
        for (int i=0; i<books.size(); i++) {\r
                try {\r
-                       long lastSyncDate = conn.getLinkedNotebookTable().getLastSequenceDate(books.get(i).getGuid());\r
-                       int lastSequenceNumber = conn.getLinkedNotebookTable().getLastSequenceNumber(books.get(i).getGuid());\r
-                       linkedAuthResult = noteStore.authenticateToSharedNotebook(books.get(i).getShareKey(), authToken);\r
-                       SyncState linkedSyncState = \r
-                               noteStore.getLinkedNotebookSyncState(linkedAuthResult.getAuthenticationToken(), books.get(i));\r
-                       if (linkedSyncState.getUpdateCount() > lastSequenceNumber) {\r
-                               if (lastSyncDate < linkedSyncState.getFullSyncBefore()) {\r
-                                       lastSequenceNumber = 0;\r
-                               }\r
+                               long lastSyncDate = conn.getLinkedNotebookTable().getLastSequenceDate(books.get(i).getGuid());\r
+                               int lastSequenceNumber = conn.getLinkedNotebookTable().getLastSequenceNumber(books.get(i).getGuid());\r
+                               linkedAuthResult = noteStore.authenticateToSharedNotebook(books.get(i).getShareKey(), authToken);\r
+                               SyncState linkedSyncState = \r
+                                       noteStore.getLinkedNotebookSyncState(linkedAuthResult.getAuthenticationToken(), books.get(i));\r
+                               if (linkedSyncState.getUpdateCount() > lastSequenceNumber) {\r
+                                       if (lastSyncDate < linkedSyncState.getFullSyncBefore()) {\r
+                                               lastSequenceNumber = 0;\r
+                                       } \r
                                        syncLinkedNotebook(books.get(i), lastSequenceNumber, linkedSyncState.getUpdateCount());\r
-                       }\r
+                               }\r
                        \r
                        // Synchronize local changes\r
                        syncLocalLinkedNoteChanges(books.get(i));\r
@@ -1834,15 +1842,14 @@ public class SyncRunner extends QObject implements Runnable {
                        try {\r
                                SyncChunk chunk = \r
                                        noteStore.getLinkedNotebookSyncChunk(authToken, book, usn, 10, fullSync);\r
-//                                     noteStore.getLinkedNotebookSyncChunk(linkedAuthResult.getAuthenticationToken(), book, usn, 10, fullSync);\r
 \r
-                               syncRemoteNotes(chunk.getNotes(), fullSync, linkedAuthResult.getAuthenticationToken());\r
+                               if (!ignoreLinkedNotebooks.contains(book.getGuid()))\r
+                                       syncRemoteNotes(chunk.getNotes(), fullSync, linkedAuthResult.getAuthenticationToken());\r
                                findNewLinkedTags(chunk.getNotes(), linkedAuthResult.getAuthenticationToken());\r
                                for (int i=0; i<chunk.getResourcesSize(); i++) {\r
                                        syncRemoteResource(chunk.getResources().get(i), linkedAuthResult.getAuthenticationToken());\r
                                }\r
                                syncRemoteLinkedNotebooks(chunk.getNotebooks(), false, book);\r
-//                             String notebookGuid = conn.getLinkedNotebookTable().getNotebookGuid(book.getGuid());\r
                                SharedNotebook s = noteStore.getSharedNotebookByAuth(linkedAuthResult.getAuthenticationToken());\r
                                syncLinkedTags(chunk.getTags(), s.getNotebookGuid());\r
                                \r