[tomboy] [sync] Convert SyncManager and SyncDialog to new ISyncUI interface
- From: Sanford Armstrong <sharm src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tomboy] [sync] Convert SyncManager and SyncDialog to new ISyncUI interface
- Date: Mon, 8 Feb 2010 20:06:24 +0000 (UTC)
commit 68155e914afda7873c8cae0fa38056fe85d3193b
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date: Mon Feb 8 11:51:51 2010 -0800
[sync] Convert SyncManager and SyncDialog to new ISyncUI interface
This interface can be implemented by other user interfaces for note sync.
Tomboy.mdp | 1 +
Tomboy/Synchronization/ISyncUI.cs | 43 ++++++++++++++++++++
Tomboy/Synchronization/SyncDialog.cs | 24 ++++-------
Tomboy/Synchronization/SyncManager.cs | 70 ++++++++++++++++++---------------
4 files changed, 91 insertions(+), 47 deletions(-)
---
diff --git a/Tomboy.mdp b/Tomboy.mdp
index f628354..d28779e 100644
--- a/Tomboy.mdp
+++ b/Tomboy.mdp
@@ -16,6 +16,7 @@
<Contents>
<File subtype="Code" buildaction="Compile" name="Tomboy/IRemoteControl.cs" />
<File subtype="Code" buildaction="Compile" name="Tomboy/RemoteControlWrapper.cs" />
+ <File subtype="Code" buildaction="Compile" name="Tomboy/Synchronization/ISyncUI.cs" />
<File name="Tomboy/ActionManager.cs" subtype="Code" buildaction="Compile" />
<File name="Tomboy/Applet.cs" subtype="Code" buildaction="Compile" />
<File name="Tomboy/Logger.cs" subtype="Code" buildaction="Compile" />
diff --git a/Tomboy/Synchronization/ISyncUI.cs b/Tomboy/Synchronization/ISyncUI.cs
new file mode 100644
index 0000000..952b4fe
--- /dev/null
+++ b/Tomboy/Synchronization/ISyncUI.cs
@@ -0,0 +1,43 @@
+// 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) 2010 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Sandy Armstrong <sanfordarmstrong gmail com>
+//
+
+using System;
+using System.Collections.Generic;
+using System.Threading;
+
+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 002d8ed..8c55a9f 100644
--- a/Tomboy/Synchronization/SyncManager.cs
+++ b/Tomboy/Synchronization/SyncManager.cs
@@ -117,26 +117,29 @@ namespace Tomboy.Sync
public class SyncManager
{
+ 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 ()
{
@@ -218,15 +221,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 ();
@@ -321,8 +327,8 @@ namespace Tomboy.Sync
Note existingNote = NoteMgr.Find (noteUpdate.Title);
if (existingNote != null && !noteUpdate.BasicallyEqualTo (existingNote)) {
// Logger.Debug ("Sync: Early conflict detection for '{0}'", noteUpdate.Title);
- 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.
@@ -363,8 +369,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.
@@ -395,8 +401,8 @@ namespace Tomboy.Sync
foreach (Note note in localNotes) {
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);
}
}
@@ -415,14 +421,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);
}
}
@@ -437,11 +443,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);
}
}
}
@@ -556,8 +562,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)
@@ -652,10 +658,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]