OSDN Git Service

Cleanup public linked notebook table logic.
authorRandy Baumgarte <randy@fbn.cx>
Mon, 28 Mar 2011 16:30:02 +0000 (12:30 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 3 Apr 2011 18:03:14 +0000 (14:03 -0400)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/threads/SyncRunner.java

index d712f56..3b55dc0 100644 (file)
@@ -2299,6 +2299,7 @@ public class NeverNote extends QMainWindow{
        
        }
        // Merge tags
+       @SuppressWarnings("unused")
        private void mergeTags() {
                List<Tag> tags = new ArrayList<Tag>();
                List<QTreeWidgetItem> selections = tagTree.selectedItems();
index c5e96b4..f2e1cae 100644 (file)
@@ -1833,15 +1833,22 @@ public class SyncRunner extends QObject implements Runnable {
                                THttpClient linkedNoteStoreTrans        = new THttpClient(linkedNoteStoreUrl);\r
                                TBinaryProtocol linkedNoteStoreProt     = new TBinaryProtocol(linkedNoteStoreTrans);\r
                                Client linkedNoteStore = new NoteStore.Client(linkedNoteStoreProt, linkedNoteStoreProt);                                \r
-                               \r
-                               linkedAuthResult = linkedNoteStore.authenticateToSharedNotebook(books.get(i).getShareKey(), authToken);\r
+\r
+                               linkedAuthResult = null;\r
+                               if (books.get(i).getShareKey() != null)\r
+                                       linkedAuthResult = linkedNoteStore.authenticateToSharedNotebook(books.get(i).getShareKey(), authToken);\r
+                               else {\r
+                                       linkedAuthResult = new AuthenticationResult();\r
+                                       linkedAuthResult.setAuthenticationToken("");\r
+                               }\r
                                SyncState linkedSyncState = \r
                                        linkedNoteStore.getLinkedNotebookSyncState(linkedAuthResult.getAuthenticationToken(), books.get(i));\r
                                if (linkedSyncState.getUpdateCount() > lastSequenceNumber) {\r
                                        if (lastSyncDate < linkedSyncState.getFullSyncBefore()) {\r
                                                lastSequenceNumber = 0;\r
                                        } \r
-                                       syncLinkedNotebook(linkedNoteStore, books.get(i), lastSequenceNumber, linkedSyncState.getUpdateCount());\r
+                                       syncLinkedNotebook(linkedNoteStore, books.get(i), \r
+                                                       lastSequenceNumber, linkedSyncState.getUpdateCount(), linkedAuthResult.getAuthenticationToken());\r
                                }\r
                        \r
                        // Synchronize local changes\r
@@ -1873,7 +1880,7 @@ public class SyncRunner extends QObject implements Runnable {
     //**************************************************************\r
     //* Linked notebook contents (from someone else's account)\r
     //*************************************************************\r
-       private void syncLinkedNotebook(Client linkedNoteStore, LinkedNotebook book, int usn, int highSequence) {\r
+       private void syncLinkedNotebook(Client linkedNoteStore, LinkedNotebook book, int usn, int highSequence, String token) {\r
                if (ignoreLinkedNotebooks.contains(book.getGuid()))\r
                        return;\r
                List<Note> dirtyNotes = conn.getNoteTable().getDirtyLinkedNotes();\r
@@ -1886,11 +1893,12 @@ public class SyncRunner extends QObject implements Runnable {
                boolean fullSync = false;\r
                if (usn == 0)\r
                        fullSync = true;\r
-               while (usn < highSequence) {\r
+               boolean syncError = false;\r
+               while (usn < highSequence && !syncError) {\r
                        refreshNeeded = true;\r
                        try {\r
                                SyncChunk chunk = \r
-                                       linkedNoteStore.getLinkedNotebookSyncChunk(authToken, book, usn, 10, fullSync);\r
+                                       linkedNoteStore.getLinkedNotebookSyncChunk(token, book, usn, 10, fullSync);\r
                                \r
                                // Expunge notes\r
                                syncExpungedNotes(chunk);\r
@@ -1902,8 +1910,9 @@ public class SyncRunner extends QObject implements Runnable {
                                        syncRemoteResource(linkedNoteStore, chunk.getResources().get(i), linkedAuthResult.getAuthenticationToken());\r
                                }\r
                                syncRemoteLinkedNotebooks(linkedNoteStore, chunk.getNotebooks(), false, book);\r
-                               SharedNotebook s = linkedNoteStore.getSharedNotebookByAuth(linkedAuthResult.getAuthenticationToken());\r
-                               syncLinkedTags(chunk.getTags(), s.getNotebookGuid());\r
+//                             SharedNotebook s = linkedNoteStore.getSharedNotebookByAuth(linkedAuthResult.getAuthenticationToken());\r
+//                             syncLinkedTags(chunk.getTags(), s.getNotebookGuid());\r
+                               syncLinkedTags(chunk.getTags(), book.getGuid());\r
                                \r
                                // Go through & signal any notes that have changed so we can refresh the user's view\r
                                for (int i=0; i<chunk.getNotesSize(); i++) \r
@@ -1918,13 +1927,25 @@ public class SyncRunner extends QObject implements Runnable {
                                conn.getLinkedNotebookTable().setLastSequenceDate(book.getGuid(),chunk.getCurrentTime());\r
                                conn.getLinkedNotebookTable().setLastSequenceNumber(book.getGuid(),chunk.getChunkHighUSN());\r
                        } catch (EDAMUserException e) {\r
+                               syncError = true;\r
+                               status.message.emit(tr("EDAM UserException synchronizing linked notbook.  See the log for datails."));\r
                                e.printStackTrace();\r
+                               logger.log(logger.LOW, e.getMessage());\r
                        } catch (EDAMSystemException e) {\r
+                               syncError = true;\r
+                               status.message.emit(tr("EDAM SystemException synchronizing linked notbook.  See the log for datails."));\r
                                e.printStackTrace();\r
+                               logger.log(logger.LOW, e.getMessage());\r
                        } catch (EDAMNotFoundException e) {\r
-                               e.printStackTrace();\r
+                               syncError = true;\r
+                               status.message.emit(tr("EDAM NotFoundException synchronizing linked notbook.  See the log for datails."));\r
+                               e.printStackTrace();   /// DELETE OLD NOTEBOOKS HERE\r
+                               logger.log(logger.LOW, e.getMessage());\r
                        } catch (TException e) {\r
+                               syncError = true;\r
+                               status.message.emit(tr("EDAM TException synchronizing linked notbook.  See the log for datails."));\r
                                e.printStackTrace();\r
+                               logger.log(logger.LOW, e.getMessage());\r
                        }\r
                }\r
        }\r
@@ -1945,9 +1966,13 @@ public class SyncRunner extends QObject implements Runnable {
                if (notebooks != null) {\r
                        for (int i=0; i<notebooks.size() && keepRunning; i++) {\r
                                try {\r
-                                       SharedNotebook s = noteStore.getSharedNotebookByAuth(linkedAuthResult.getAuthenticationToken());\r
-                                       conn.getLinkedNotebookTable().setNotebookGuid(s.getShareKey(), s.getNotebookGuid());\r
-                                       readOnly = !s.isNotebookModifiable();\r
+                                       if (!linkedAuthResult.getAuthenticationToken().equals("")) {\r
+                                               SharedNotebook s = noteStore.getSharedNotebookByAuth(linkedAuthResult.getAuthenticationToken());\r
+                                               conn.getLinkedNotebookTable().setNotebookGuid(s.getShareKey(), s.getNotebookGuid());\r
+                                               readOnly = !s.isNotebookModifiable();\r
+                                       } else {\r
+                                               readOnly = true;\r
+                                       }\r
                                        notebooks.get(i).setName(linked.getShareName());\r
                                        notebooks.get(i).setDefaultNotebook(false);\r
                                        conn.getNotebookTable().syncLinkedNotebook(notebooks.get(i), false, readOnly); \r