[tomboy/autosync: 237/241] [sync] Introduce idea of having different ISyncUIs
- From: Sanford Armstrong <sharm src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tomboy/autosync: 237/241] [sync] Introduce idea of having different ISyncUIs
- Date: Mon, 25 Jan 2010 19:38:15 +0000 (UTC)
commit e1c52f9d1821c9f2230d1353c704572f1285d5a4
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date: Mon Jan 25 01:51:23 2010 -0800
[sync] Introduce idea of having different ISyncUIs
Tomboy.mdp | 1 +
Tomboy/Synchronization/ISyncUI.cs | 42 +++++++++++++++++++
Tomboy/Synchronization/SyncDialog.cs | 24 ++++-------
Tomboy/Synchronization/SyncManager.cs | 72 +++++++++++++++++---------------
4 files changed, 90 insertions(+), 49 deletions(-)
---
diff --git a/Tomboy.mdp b/Tomboy.mdp
index 8ab265b..494a73c 100644
--- a/Tomboy.mdp
+++ b/Tomboy.mdp
@@ -112,6 +112,7 @@
<File name="Tomboy/Synchronization/TomboySyncClient.cs" subtype="Code" buildaction="Compile" />
<File name="Tomboy/Synchronization/FileSystemSyncServer.cs" subtype="Code" buildaction="Compile" />
<File name="Tomboy/Synchronization/SyncServiceAddin.cs" subtype="Code" buildaction="Compile" />
+ <File name="Tomboy/Synchronization/ISyncUI.cs" subtype="Code" buildaction="Compile" />
<File name="Tomboy/Search.cs" subtype="Code" buildaction="Compile" />
<File name="Tomboy/Notebooks/Notebook.cs" subtype="Code" buildaction="Compile" />
<File name="Tomboy/Notebooks/NotebookManager.cs" subtype="Code" buildaction="Compile" />
diff --git a/Tomboy/Synchronization/ISyncUI.cs b/Tomboy/Synchronization/ISyncUI.cs
new file mode 100644
index 0000000..be7ffd9
--- /dev/null
+++ b/Tomboy/Synchronization/ISyncUI.cs
@@ -0,0 +1,42 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Sandy Armstrong <sanfordarmstrong gmail com>
+//
+
+using System;
+using System.Collections.Generic;
+
+namespace Tomboy.Sync
+{
+ public interface ISyncUI
+ {
+ void SyncStateChanged (SyncState state);
+
+ void NoteSynchronized (string noteTitle, NoteSyncType type);
+
+ void NoteConflictDetected (NoteManager manager,
+ Note localConflictNote,
+ NoteUpdate remoteNote,
+ IList<string> noteUpdateTitles);
+ }
+}
diff --git a/Tomboy/Synchronization/SyncDialog.cs b/Tomboy/Synchronization/SyncDialog.cs
index acbdeef..be35974 100644
--- a/Tomboy/Synchronization/SyncDialog.cs
+++ b/Tomboy/Synchronization/SyncDialog.cs
@@ -6,7 +6,7 @@ using Gtk;
namespace Tomboy.Sync
{
- public class SyncDialog : Gtk.Dialog
+ public class SyncDialog : Gtk.Dialog, ISyncUI
{
private Gtk.Image image;
private Gtk.Label headerLabel;
@@ -136,9 +136,6 @@ namespace Tomboy.Sync
public override void Destroy ()
{
- SyncManager.StateChanged -= OnSyncStateChanged;
- SyncManager.NoteSynchronized -= OnNoteSynchronized;
- SyncManager.NoteConflictDetected -= OnNoteConflictDetected;
base.Destroy ();
}
@@ -146,20 +143,16 @@ namespace Tomboy.Sync
{
base.OnRealized ();
- SyncManager.StateChanged += OnSyncStateChanged;
- SyncManager.NoteSynchronized += OnNoteSynchronized;
- SyncManager.NoteConflictDetected += OnNoteConflictDetected;
-
SyncState state = SyncManager.State;
if (state == SyncState.Idle) {
// Kick off a timer to keep the progress bar going
progressBarTimeoutId = GLib.Timeout.Add (500, OnPulseProgressBar);
// Kick off a new synchronization
- SyncManager.PerformSynchronization ();
+ SyncManager.PerformSynchronization (this);
} else {
// Adjust the GUI accordingly
- OnSyncStateChanged (state);
+ SyncStateChanged (state);
}
}
@@ -229,8 +222,10 @@ namespace Tomboy.Sync
// Return true to keep things going well
return true;
}
+ #endregion // Private Event Handlers
- void OnSyncStateChanged (SyncState state)
+ #region ISyncUI Members
+ public void SyncStateChanged (SyncState state)
{
// This event handler will be called by the synchronization thread
// so we have to use the delegate here to manipulate the GUI.
@@ -326,7 +321,7 @@ namespace Tomboy.Sync
});
}
- void OnNoteSynchronized (string noteTitle, NoteSyncType type)
+ public void NoteSynchronized (string noteTitle, NoteSyncType type)
{
// This event handler will be called by the synchronization thread
// so we have to use the delegate here to manipulate the GUI.
@@ -358,7 +353,7 @@ namespace Tomboy.Sync
});
}
- void OnNoteConflictDetected (NoteManager manager,
+ public void NoteConflictDetected (NoteManager manager,
Note localConflictNote,
NoteUpdate remoteNote,
IList<string> noteUpdateTitles)
@@ -436,8 +431,7 @@ namespace Tomboy.Sync
if (mainThreadException != null)
throw mainThreadException;
}
-
- #endregion // Private Event Handlers
+ #endregion // ISyncUI Members
#region Private Methods
// TODO: This appears to add <link:internal> around the note title
diff --git a/Tomboy/Synchronization/SyncManager.cs b/Tomboy/Synchronization/SyncManager.cs
index 2ccc906..1faff77 100644
--- a/Tomboy/Synchronization/SyncManager.cs
+++ b/Tomboy/Synchronization/SyncManager.cs
@@ -117,27 +117,29 @@ namespace Tomboy.Sync
public class SyncManager
{
- //private static SyncServer server;
+ private static ISyncUI syncUI;
private static SyncClient client;
private static SyncState state = SyncState.Idle;
private static Thread syncThread = null;
// TODO: Expose the next enum more publicly
private static SyncTitleConflictResolution conflictResolution;
- /// <summary>
- /// Emitted when the state of the synchronization changes
- /// </summary>
- public static event SyncStateChangedHandler StateChanged;
-
- /// <summary>
- /// Emmitted when a file is uploaded, downloaded, or deleted.
- /// </summary>
- public static event NoteSyncHandler NoteSynchronized;
-
- /// <summary>
- ///
- /// </summary>
- public static event NoteConflictHandler NoteConflictDetected;
+ // TODO: Are these needed in the era of ISyncUI? Probably,
+ // but leaving them out is good for testing right now
+// /// <summary>
+// /// Emitted when the state of the synchronization changes
+// /// </summary>
+// public static event SyncStateChangedHandler StateChanged;
+//
+// /// <summary>
+// /// Emmitted when a file is uploaded, downloaded, or deleted.
+// /// </summary>
+// public static event NoteSyncHandler NoteSynchronized;
+//
+// /// <summary>
+// ///
+// /// </summary>
+// public static event NoteConflictHandler NoteConflictDetected;
static SyncManager ()
{
@@ -251,15 +253,18 @@ namespace Tomboy.Sync
}
}
- public static void PerformSynchronization ()
+ public static void PerformSynchronization (ISyncUI syncUI)
{
if (syncThread != null) {
// A synchronization thread is already running
// TODO: Start new sync if existing dlg is for finished sync
- Tomboy.SyncDialog.Present ();
+ // TODO: ISyncUI-ize this somehow
+ if (SyncManager.syncUI == Tomboy.SyncDialog)
+ Tomboy.SyncDialog.Present ();
return;
}
+ SyncManager.syncUI = syncUI;
syncThread = new Thread (new ThreadStart (SynchronizationThread));
syncThread.IsBackground = true;
syncThread.Start ();
@@ -271,7 +276,6 @@ namespace Tomboy.Sync
/// </summary>
public static void SynchronizationThread ()
{
- // TODO: Try/finally this entire method so GUI doesn't hang?
SyncServiceAddin addin = null;
SyncServer server = null;
try {
@@ -354,8 +358,8 @@ namespace Tomboy.Sync
if (FindNoteByUUID (noteUpdate.UUID) == null) {
Note existingNote = NoteMgr.Find (noteUpdate.Title);
if (existingNote != null) {
- if (NoteConflictDetected != null) {
- NoteConflictDetected (NoteMgr, existingNote, noteUpdate, noteUpdateTitles);
+ if (syncUI != null) {
+ syncUI.NoteConflictDetected (NoteMgr, existingNote, noteUpdate, noteUpdateTitles);
// Suspend this thread while the GUI is presented to
// the user.
@@ -394,8 +398,8 @@ namespace Tomboy.Sync
"SyncManager: Content conflict in note update for note '{0}'",
noteUpdate.Title));
// Note already exists locally, but has been modified since last sync; prompt user
- if (NoteConflictDetected != null) {
- NoteConflictDetected (NoteMgr, existingNote, noteUpdate, noteUpdateTitles);
+ if (syncUI != null) {
+ syncUI.NoteConflictDetected (NoteMgr, existingNote, noteUpdate, noteUpdateTitles);
// Suspend this thread while the GUI is presented to
// the user.
@@ -430,8 +434,8 @@ namespace Tomboy.Sync
if (client.GetRevision (note) != -1 &&
!serverNotes.Contains (note.Id)) {
- if (NoteSynchronized != null)
- NoteSynchronized (note.Title, NoteSyncType.DeleteFromClient);
+ if (syncUI != null)
+ syncUI.NoteSynchronized (note.Title, NoteSyncType.DeleteFromClient);
NoteMgr.Delete (note);
}
}
@@ -458,14 +462,14 @@ namespace Tomboy.Sync
// TODO: Do the above NOW!!! (don't commit this dummy)
note.Save ();
newOrModifiedNotes.Add (note);
- if (NoteSynchronized != null)
- NoteSynchronized (note.Title, NoteSyncType.UploadNew);
+ if (syncUI != null)
+ syncUI.NoteSynchronized (note.Title, NoteSyncType.UploadNew);
} else if (client.GetRevision (note) <= client.LastSynchronizedRevision &&
note.MetadataChangeDate > client.LastSyncDate) {
note.Save ();
newOrModifiedNotes.Add (note);
- if (NoteSynchronized != null)
- NoteSynchronized (note.Title, NoteSyncType.UploadModified);
+ if (syncUI != null)
+ syncUI.NoteSynchronized (note.Title, NoteSyncType.UploadModified);
}
}
@@ -480,11 +484,11 @@ namespace Tomboy.Sync
foreach (string noteUUID in server.GetAllNoteUUIDs ()) {
if (FindNoteByUUID (noteUUID) == null) {
locallyDeletedUUIDs.Add (noteUUID);
- if (NoteSynchronized != null) {
+ if (syncUI != null) {
string deletedTitle = noteUUID;
if (client.DeletedNoteTitles.ContainsKey (noteUUID))
deletedTitle = client.DeletedNoteTitles [noteUUID];
- NoteSynchronized (deletedTitle, NoteSyncType.DeleteFromServer);
+ syncUI.NoteSynchronized (deletedTitle, NoteSyncType.DeleteFromServer);
}
}
}
@@ -635,8 +639,8 @@ namespace Tomboy.Sync
client.SetRevision (localNote, serverNote.LatestRevision);
// Update dialog's sync status
- if (NoteSynchronized != null)
- NoteSynchronized (localNote.Title, syncType);
+ if (syncUI != null)
+ syncUI.NoteSynchronized (localNote.Title, syncType);
}
private static Note FindNoteByUUID (string uuid)
@@ -731,10 +735,10 @@ namespace Tomboy.Sync
private static void SetState (SyncState newState)
{
state = newState;
- if (StateChanged != null) {
+ if (syncUI != null) {
// Notify the event handlers
try {
- StateChanged (state);
+ syncUI.SyncStateChanged (state);
} catch {}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]