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 / NeverNote.java
index 6b8615c..becfe8f 100644 (file)
@@ -392,6 +392,7 @@ public class NeverNote extends QMainWindow{
 //                     saveTimer.setInterval(1000*10); // auto save every 20 seconds;
                        saveTimer.start();
                }
+               listManager.saveRunner.noteSignals.noteSaveRunnerError.connect(this, "saveRunnerError(String, String)");
                
                logger.log(logger.EXTREME, "Starting external file monitor timer");
                externalFileSaveTimer = new QTimer();
@@ -803,15 +804,14 @@ public class NeverNote extends QMainWindow{
         syncRunner.noteIndexSignal.listChanged.connect(this, "noteIndexUpdated(boolean)");
         syncRunner.noteSignal.quotaChanged.connect(this, "updateQuotaBar()");
         
-//             syncRunner.syncSignal.setSequenceDate.connect(this,"setSequenceDate(long)");
                syncRunner.syncSignal.saveUploadAmount.connect(this,"saveUploadAmount(long)");
-//             syncRunner.syncSignal.setUpdateSequenceNumber.connect(this,"setUpdateSequenceNumber(int)");
                syncRunner.syncSignal.saveUserInformation.connect(this,"saveUserInformation(User)");
                syncRunner.syncSignal.saveEvernoteUpdateCount.connect(this,"saveEvernoteUpdateCount(int)");
                
                syncRunner.noteSignal.guidChanged.connect(this, "noteGuidChanged(String, String)");
                syncRunner.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
                syncRunner.resourceSignal.resourceGuidChanged.connect(this, "noteResourceGuidChanged(String,String,String)");
+               syncRunner.noteSignal.noteDownloaded.connect(listManager, "noteDownloaded(Note)");
                
                syncRunner.syncSignal.refreshLists.connect(this, "refreshLists()");
        }
@@ -824,7 +824,7 @@ public class NeverNote extends QMainWindow{
                browserWindow.noteSignal.noteChanged.connect(this, "invalidateNoteCache(String, String)");
            browserWindow.noteSignal.noteChanged.connect(this, "setNoteDirty()");
            browserWindow.noteSignal.titleChanged.connect(listManager, "updateNoteTitle(String, String)");
-//         browserWindow.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
+           browserWindow.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
            browserWindow.noteSignal.createdDateChanged.connect(listManager, "updateNoteCreatedDate(String, QDateTime)");
            browserWindow.noteSignal.alteredDateChanged.connect(listManager, "updateNoteAlteredDate(String, QDateTime)");
            browserWindow.noteSignal.subjectDateChanged.connect(listManager, "updateNoteSubjectDate(String, QDateTime)");
@@ -1521,25 +1521,31 @@ public class NeverNote extends QMainWindow{
                if (tagName == null)
                        return;
                
-               for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
-                       QModelIndex modelIndex =  listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
-                       if (modelIndex != null) {
-                               SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
-                               String titleGuid = (String)ix.values().toArray()[0];
-                               if (titleGuid.equals(noteGuid)) {
-                                       String text = (String)listManager.getNoteTableModel().data(i, Global.noteTableTagPosition);
-                                       if (!text.trim().equals(""))
-                                               text = text + Global.tagDelimeter + " " +tagName;
-                                       else
-                                               text = tagName;
-                                       listManager.getNoteTableModel().setData(i, Global.noteTableTagPosition, text);
-                                       listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
-                                       if (noteGuid.equals(currentNoteGuid))
-                                               browserWindow.setTag(text);
-                                       i=listManager.getNoteTableModel().rowCount();
+               for (int i=0; i<listManager.getMasterNoteIndex().size(); i++) {
+                       if (listManager.getMasterNoteIndex().get(i).getGuid().equals(noteGuid)) {
+                               List<String> tagNames = new ArrayList<String>();
+                               tagNames.add(new String(tagName));
+                               Note n = listManager.getMasterNoteIndex().get(i);
+                               for (int j=0; j<n.getTagNames().size(); j++) {
+                                       tagNames.add(new String(n.getTagNames().get(j)));
+                               }
+                               listManager.getNoteTableModel().updateNoteTags(noteGuid, n.getTagGuids(), tagNames);
+                               if (n.getGuid().equals(currentNoteGuid)) {
+                                       Collections.sort(tagNames);
+                                       String display = "";
+                                       for (int j=0; j<tagNames.size(); j++) {
+                                               display = display+tagNames.get(j);
+                                               if (j+2<tagNames.size()) 
+                                                       display = display+Global.tagDelimeter+" ";
+                                       }
+                                       browserWindow.setTag(display);
                                }
+                               i=listManager.getMasterNoteIndex().size();
                        }
                }
+               
+               
+               listManager.getNoteTableModel().updateNoteSyncStatus(noteGuid, false);
        }
        private void clearTagFilter() {
                tagTree.blockSignals(true);
@@ -2598,21 +2604,7 @@ public class NeverNote extends QMainWindow{
     }
        private void updateListNoteNotebook(String guid, String notebook) {
        logger.log(logger.HIGH, "Entering NeverNote.updateListNoteNotebook");
-
-       for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
-               //QModelIndex modelIndex =  noteTableView.proxyModel.index(i, Global.noteTableGuidPosition);
-               QModelIndex modelIndex =  listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
-               if (modelIndex != null) {
-//                     SortedMap<Integer, Object> ix = noteTableView.proxyModel.itemData(modelIndex);
-                       SortedMap<Integer, Object> ix = listManager.getNoteTableModel().itemData(modelIndex);
-                       String tableGuid =  (String)ix.values().toArray()[0];
-                       if (tableGuid.equals(guid)) {
-                               listManager.getNoteTableModel().setData(i, Global.noteTableNotebookPosition,notebook);
-                               listManager.getNoteTableModel().setData(i, Global.noteTableSynchronizedPosition, "false");
-                               return;
-                       }       
-               }
-       }
+       listManager.getNoteTableModel().updateNoteSyncStatus(guid, false);
        logger.log(logger.HIGH, "Leaving NeverNote.updateListNoteNotebook");
     }
     // Update a title for a specific note in the list
@@ -2908,8 +2900,9 @@ public class NeverNote extends QMainWindow{
                                return;
                }
                
-               // If tihs wasn't already marked as unsynchronized, then we need to update the table
-       listManager.getUnsynchronizedNotes().add(currentNoteGuid);
+               // If this wasn't already marked as unsynchronized, then we need to update the table
+               listManager.getNoteTableModel().updateNoteSyncStatus(currentNoteGuid, false);
+/*     listManager.getUnsynchronizedNotes().add(currentNoteGuid);
        for (int i=0; i<listManager.getNoteTableModel().rowCount(); i++) {
                QModelIndex modelIndex =  listManager.getNoteTableModel().index(i, Global.noteTableGuidPosition);
                if (modelIndex != null) {
@@ -2921,7 +2914,7 @@ public class NeverNote extends QMainWindow{
                        }
                }
        }
-       
+ */    
                logger.log(logger.EXTREME, "Leaving NeverNote.setNoteDirty()");
     }
     private void saveNote() {
@@ -3290,11 +3283,11 @@ public class NeverNote extends QMainWindow{
        na.setLongitude(0.0);
        na.setAltitude(0.0);
        newNote.setAttributes(new NoteAttributes());
-
+               newNote.setTagGuids(new ArrayList<String>());
+               newNote.setTagNames(new ArrayList<String>());
+       
        // If new notes are to be created based upon the selected tags, then we need to assign the tags
        if (Global.newNoteWithSelectedTags()) { 
-               newNote.setTagGuids(new ArrayList<String>());
-               newNote.setTagNames(new ArrayList<String>());
                List<QTreeWidgetItem> selections = tagTree.selectedItems();
                QTreeWidgetItem currentSelection;
                for (int i=0; i<selections.size(); i++) {
@@ -3307,7 +3300,7 @@ public class NeverNote extends QMainWindow{
        conn.getNoteTable().addNote(newNote, true);
        listManager.getUnsynchronizedNotes().add(newNote.getGuid());
        listManager.addNote(newNote);
-       noteTableView.insertRow(newNote, true, -1);
+//     noteTableView.insertRow(newNote, true, -1);
        
        currentNote = newNote;
        currentNoteGuid = currentNote.getGuid();
@@ -3584,7 +3577,25 @@ public class NeverNote extends QMainWindow{
                if (!thumbnailViewer.isVisible()) 
                        thumbnailViewer.showFullScreen();
        }
-
+       // An error happened while saving a note.  Inform the user
+       @SuppressWarnings("unused")
+       private void saveRunnerError(String guid, String msg) {
+               if (msg == null) {
+                       String title = "*Unknown*";
+                       for (int i=0; i<listManager.getMasterNoteIndex().size(); i++) {
+                               if (listManager.getMasterNoteIndex().get(i).getGuid().equals(guid)) {
+                                       title = listManager.getMasterNoteIndex().get(i).getTitle();
+                                       i=listManager.getMasterNoteIndex().size();
+                               }
+                       }
+                       msg = "An error has happened saving the note \"" +title+
+                       "\". \nThis is probably due to a document that is too complex for Nevernote to process.  "+
+                       "As a result, changes to the note may not be saved.\n\nPlease review the note for any potential problems.";
+                       
+                       QMessageBox.information(this, tr("Error Saving Note"), tr(msg));
+               }
+       }
+       
        //**********************************************************
     //**********************************************************
     //* Online user actions
@@ -4115,14 +4126,17 @@ public class NeverNote extends QMainWindow{
                synchronizeAnimationTimer.stop();
                synchronizeButton.setIcon(synchronizeAnimation.get(0));
                saveNote();
+               if (currentNote == null) {
+                       currentNote = conn.getNoteTable().getNote(currentNoteGuid, false, false, false, false, true);
+               }
                listManager.setUnsynchronizedNotes(conn.getNoteTable().getUnsynchronizedGUIDs());
-               listManager.reloadIndexes();
-               noteIndexUpdated(true);
+               noteIndexUpdated(false);
                noteTableView.selectionModel().blockSignals(true);
                scrollToGuid(currentNoteGuid);
                noteTableView.selectionModel().blockSignals(false);
                refreshEvernoteNote(false);
                scrollToGuid(currentNoteGuid);
+               waitCursor(false);
                setMessage(tr("Synchronization Complete"));
                logger.log(logger.MEDIUM, "Sync complete.");
        }