[tomboy/autosync: 239/241] [sync] implement super-simple autosync



commit b563d7fe12f839b8d43ee8005983b4c3d447a4f4
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date:   Mon Jan 25 02:29:16 2010 -0800

    [sync] implement super-simple autosync

 Tomboy/Synchronization/ISyncUI.cs     |   20 ++++++++++++++++++++
 Tomboy/Synchronization/SyncManager.cs |   27 ++++++++++++++++++++-------
 2 files changed, 40 insertions(+), 7 deletions(-)
---
diff --git a/Tomboy/Synchronization/ISyncUI.cs b/Tomboy/Synchronization/ISyncUI.cs
index be7ffd9..0063a96 100644
--- a/Tomboy/Synchronization/ISyncUI.cs
+++ b/Tomboy/Synchronization/ISyncUI.cs
@@ -39,4 +39,24 @@ namespace Tomboy.Sync
 		                             NoteUpdate remoteNote,
 		                             IList<string> noteUpdateTitles);
 	}
+
+	public class SilentUI : ISyncUI
+	{
+		#region ISyncUI implementation
+		public void SyncStateChanged (SyncState state)
+		{
+			Logger.Debug ("SilentUI: SyncStateChanged");
+		}
+
+		public void NoteSynchronized (string noteTitle, NoteSyncType type)
+		{
+			Logger.Debug ("SilentUI: NoteSynchronized");
+		}
+
+		public void NoteConflictDetected (NoteManager manager, Note localConflictNote, NoteUpdate remoteNote, IList<string> noteUpdateTitles)
+		{
+			Logger.Debug ("SilentUI: NoteConflictDetected, ignoring this update");
+		}
+		#endregion
+	}
 }
diff --git a/Tomboy/Synchronization/SyncManager.cs b/Tomboy/Synchronization/SyncManager.cs
index da6cfb5..10c6360 100644
--- a/Tomboy/Synchronization/SyncManager.cs
+++ b/Tomboy/Synchronization/SyncManager.cs
@@ -209,13 +209,15 @@ namespace Tomboy.Sync
 			var addin = GetConfiguredSyncService ();
 			if (addin != null) {
 				var server = addin.CreateSyncServer ();
-				bool clientHasUpdates = false;
+				bool clientHasUpdates = client.DeletedNoteTitles.Count > 0;
 				bool serverHasUpdates = false;
-				foreach (Note note in new List<Note> (NoteMgr.Notes)) {
-					if (client.GetRevision (note) == -1 ||
-					    note.MetadataChangeDate > client.LastSyncDate) {
-						clientHasUpdates = true;
-						break;
+				if (!clientHasUpdates) {
+					foreach (Note note in new List<Note> (NoteMgr.Notes)) {
+						if (client.GetRevision (note) == -1 ||
+						    note.MetadataChangeDate > client.LastSyncDate) {
+							clientHasUpdates = true;
+							break;
+						}
 					}
 				}
 				// Wasteful to check when we'll sync anyway
@@ -228,7 +230,18 @@ namespace Tomboy.Sync
 
 				if (clientHasUpdates || serverHasUpdates) {
 					Logger.Debug ("BackgroundSyncChecker: Detected that sync would be a good idea now");
-					// TODO: Sync!
+					// TODO: Check that it's safe to sync, block other sync UIs
+					// TODO: Disable all kinds of note editing
+					//         -New notes from server should be disabled, too
+					//         -Anyway we could skip this when uploading changes?
+					//         -Should store original Enabled state
+					foreach (Note note in new List<Note> (NoteMgr.Notes)) {
+						note.Enabled = false;
+					}
+					PerformSynchronization (new SilentUI ());
+					foreach (Note note in new List<Note> (NoteMgr.Notes)) {
+						note.Enabled = true;
+					}
 				}
 			}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]