public void NoteConflictDetected (NoteManager manager, Note localConflictNote, NoteUpdate remoteNote, IList<string> noteUpdateTitles) { SyncTitleConflictResolution savedBehavior = SyncTitleConflictResolution.Cancel; object dlgBehaviorPref = Preferences.Get (Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR); if (dlgBehaviorPref != null && dlgBehaviorPref is int) // TODO: Check range of this int savedBehavior = (SyncTitleConflictResolution)dlgBehaviorPref; SyncTitleConflictResolution resolution = SyncTitleConflictResolution.OverwriteExisting; // This event handler will be called by the synchronization thread // so we have to use the delegate here to manipulate the GUI. // To be consistent, any exceptions in the delgate will be caught // and then rethrown in the synchronization thread. Exception mainThreadException = null; Gtk.Application.Invoke (delegate { try { SyncTitleConflictDialog conflictDlg = new SyncTitleConflictDialog (localConflictNote, noteUpdateTitles); Gtk.ResponseType reponse = Gtk.ResponseType.Ok; bool noteSyncBitsMatch = SyncManager.SynchronizedNoteXmlMatches (localConflictNote.GetCompleteNoteXml (), remoteNote.XmlContent); // If the synchronized note content is in conflict // and there is no saved conflict handling behavior, show the dialog if (!noteSyncBitsMatch && savedBehavior == 0) reponse = (Gtk.ResponseType) conflictDlg.Run (); if (reponse == Gtk.ResponseType.Cancel) resolution = SyncTitleConflictResolution.Cancel; else { if (noteSyncBitsMatch) resolution = SyncTitleConflictResolution.OverwriteExisting; else if (savedBehavior == 0) resolution = conflictDlg.Resolution; else resolution = savedBehavior; switch (resolution) { case SyncTitleConflictResolution.OverwriteExisting: if (conflictDlg.AlwaysPerformThisAction) savedBehavior = resolution; // No need to delete if sync will overwrite if (localConflictNote.Id != remoteNote.UUID) manager.Delete (localConflictNote); break; case SyncTitleConflictResolution.RenameExistingAndUpdate: if (conflictDlg.AlwaysPerformThisAction) savedBehavior = resolution; RenameNote (localConflictNote, conflictDlg.RenamedTitle, true); break; case SyncTitleConflictResolution.RenameExistingNoUpdate: if (conflictDlg.AlwaysPerformThisAction) savedBehavior = resolution; RenameNote (localConflictNote, conflictDlg.RenamedTitle, false); break; } } Preferences.Set (Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR, (int) savedBehavior); // TODO: Clean up conflictDlg.Hide (); conflictDlg.Destroy (); // Let the SyncManager continue SyncManager.ResolveConflict (/*localConflictNote, */resolution); } catch (Exception e) { mainThreadException = e; } }); if (mainThreadException != null) throw mainThreadException; }
public void NoteConflictDetected(NoteManager manager, Note localConflictNote, NoteUpdate remoteNote, IList <string> noteUpdateTitles) { SyncTitleConflictResolution savedBehavior = SyncTitleConflictResolution.Cancel; object dlgBehaviorPref = Preferences.Get(Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR); if (dlgBehaviorPref != null && dlgBehaviorPref is int) // TODO: Check range of this int { savedBehavior = (SyncTitleConflictResolution)dlgBehaviorPref; } SyncTitleConflictResolution resolution = SyncTitleConflictResolution.OverwriteExisting; // This event handler will be called by the synchronization thread // so we have to use the delegate here to manipulate the GUI. // To be consistent, any exceptions in the delgate will be caught // and then rethrown in the synchronization thread. Exception mainThreadException = null; Gtk.Application.Invoke(delegate { try { SyncTitleConflictDialog conflictDlg = new SyncTitleConflictDialog(localConflictNote, noteUpdateTitles); Gtk.ResponseType reponse = Gtk.ResponseType.Ok; bool noteSyncBitsMatch = SyncManager.SynchronizedNoteXmlMatches(localConflictNote.GetCompleteNoteXml(), remoteNote.XmlContent); // If the synchronized note content is in conflict // and there is no saved conflict handling behavior, show the dialog if (!noteSyncBitsMatch && savedBehavior == 0) { reponse = (Gtk.ResponseType)conflictDlg.Run(); } if (reponse == Gtk.ResponseType.Cancel) { resolution = SyncTitleConflictResolution.Cancel; } else { if (noteSyncBitsMatch) { resolution = SyncTitleConflictResolution.OverwriteExisting; } else if (savedBehavior == 0) { resolution = conflictDlg.Resolution; } else { resolution = savedBehavior; } switch (resolution) { case SyncTitleConflictResolution.OverwriteExisting: if (conflictDlg.AlwaysPerformThisAction) { savedBehavior = resolution; } // No need to delete if sync will overwrite if (localConflictNote.Id != remoteNote.UUID) { manager.Delete(localConflictNote); } break; case SyncTitleConflictResolution.RenameExistingAndUpdate: if (conflictDlg.AlwaysPerformThisAction) { savedBehavior = resolution; } RenameNote(localConflictNote, conflictDlg.RenamedTitle, true); break; case SyncTitleConflictResolution.RenameExistingNoUpdate: if (conflictDlg.AlwaysPerformThisAction) { savedBehavior = resolution; } RenameNote(localConflictNote, conflictDlg.RenamedTitle, false); break; } } Preferences.Set(Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR, (int)savedBehavior); // TODO: Clean up conflictDlg.Hide(); conflictDlg.Destroy(); // Let the SyncManager continue SyncManager.ResolveConflict(/*localConflictNote, */ resolution); } catch (Exception e) { mainThreadException = e; } }); if (mainThreadException != null) { throw mainThreadException; } }