[tomboy/autosync: 15/15] Use autosync prefs, move more work to SilentUI, other cleanups
- From: Sanford Armstrong <sharm src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tomboy/autosync: 15/15] Use autosync prefs, move more work to SilentUI, other cleanups
- Date: Mon, 8 Feb 2010 08:52:46 +0000 (UTC)
commit 14f7496bae030fd9a5418bdb785eb65cba1a1401
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date: Mon Feb 8 00:49:36 2010 -0800
Use autosync prefs, move more work to SilentUI, other cleanups
Tomboy/Synchronization/ISyncUI.cs | 38 ++++++++++++++++++++
Tomboy/Synchronization/SyncManager.cs | 61 +++++++++++++++++---------------
2 files changed, 70 insertions(+), 29 deletions(-)
---
diff --git a/Tomboy/Synchronization/ISyncUI.cs b/Tomboy/Synchronization/ISyncUI.cs
index b93d271..ea2da7e 100644
--- a/Tomboy/Synchronization/ISyncUI.cs
+++ b/Tomboy/Synchronization/ISyncUI.cs
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
+using System.Threading;
namespace Tomboy.Sync
{
@@ -42,6 +43,14 @@ namespace Tomboy.Sync
public class SilentUI : ISyncUI
{
+ private bool uiDisabled = false;
+ private NoteManager manager;
+
+ public SilentUI (NoteManager manager)
+ {
+ this.manager = manager;
+ }
+
#region ISyncUI implementation
public void SyncStateChanged (SyncState state)
{
@@ -49,6 +58,35 @@ namespace Tomboy.Sync
// D-Bus event?
// libnotify bubbles when appropriate
Logger.Debug ("SilentUI: SyncStateChanged: {0}", state);
+ AutoResetEvent evt;
+ switch (state) {
+ case SyncState.Connecting:
+ uiDisabled = true;
+ // 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
+ GuiUtils.GtkInvokeAndWait (() => {
+ manager.ReadOnly = true;
+ foreach (Note note in new List<Note> (manager.Notes)) {
+ note.Enabled = false;
+ }
+ });
+ break;
+ case SyncState.Idle:
+ if (uiDisabled) {
+ GuiUtils.GtkInvokeAndWait (() => {
+ manager.ReadOnly = false;
+ foreach (Note note in new List<Note> (manager.Notes)) {
+ note.Enabled = true;
+ }
+ });
+ uiDisabled = false;
+ }
+ break;
+ default:
+ break;
+ }
}
public void NoteSynchronized (string noteTitle, NoteSyncType type)
diff --git a/Tomboy/Synchronization/SyncManager.cs b/Tomboy/Synchronization/SyncManager.cs
index b45e88d..0f2ef72 100644
--- a/Tomboy/Synchronization/SyncManager.cs
+++ b/Tomboy/Synchronization/SyncManager.cs
@@ -197,13 +197,40 @@ namespace Tomboy.Sync
// Update sync item based on configuration.
UpdateSyncAction ();
+ }
- // TODO: Prefs, etc
- // TODO: No need to do this on main loop
- GLib.Timeout.Add (30000, BackgroundSyncChecker);
+ static void Preferences_SettingChanged (object sender, EventArgs args)
+ {
+ // Update sync item based on configuration.
+ UpdateSyncAction ();
}
- static bool BackgroundSyncChecker ()
+ private static Timer autosyncTimer;
+ private static int autosyncTimeout = -1;
+
+ static void UpdateSyncAction ()
+ {
+ string sync_addin_id = Preferences.Get (Preferences.SYNC_SELECTED_SERVICE_ADDIN) as string;
+ Tomboy.ActionManager["SyncNotesAction"].Sensitive = !string.IsNullOrEmpty (sync_addin_id);
+
+ int timeoutPref = (int) Preferences.Get (Preferences.SYNC_AUTOSYNC_TIMEOUT);
+ if (timeoutPref != autosyncTimeout) {
+ autosyncTimeout = timeoutPref;
+ if (autosyncTimer != null) {
+ autosyncTimer.Dispose ();
+ autosyncTimer = null;
+ }
+ if (autosyncTimeout > 0) {
+ autosyncTimeout = autosyncTimeout >= 5 ? autosyncTimeout : 5;
+ autosyncTimer = new Timer ((o) => BackgroundSyncChecker (),
+ null,
+ 60000, // Perform a sync one minute after setting change
+ autosyncTimeout * 60000);
+ }
+ }
+ }
+
+ static void BackgroundSyncChecker ()
{
// TODO: Exit if syncing, block sync while checking
var addin = GetConfiguredSyncService ();
@@ -231,33 +258,9 @@ namespace Tomboy.Sync
if (clientHasUpdates || serverHasUpdates) {
Logger.Debug ("BackgroundSyncChecker: Detected that sync would be a good idea now");
// 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;
- }
+ PerformSynchronization (new SilentUI (NoteMgr));
}
}
-
- return true;
- }
-
- static void Preferences_SettingChanged (object sender, EventArgs args)
- {
- // Update sync item based on configuration.
- UpdateSyncAction ();
- }
-
- static void UpdateSyncAction ()
- {
- string sync_addin_id = Preferences.Get (Preferences.SYNC_SELECTED_SERVICE_ADDIN) as string;
- Tomboy.ActionManager["SyncNotesAction"].Sensitive = !string.IsNullOrEmpty (sync_addin_id);
}
public static void ResetClient ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]