Remove event handling boilerplate everywhere

This commit is contained in:
Hylke Bons 2012-07-18 12:35:22 +02:00
parent e0949ae082
commit 78e96474b2
8 changed files with 192 additions and 370 deletions

View file

@ -29,15 +29,15 @@ namespace SparkleLib {
// Sets up a fetcher that can get remote folders // Sets up a fetcher that can get remote folders
public abstract class SparkleFetcherBase { public abstract class SparkleFetcherBase {
public delegate void StartedEventHandler (); public event Action Started = delegate { };
public event Action Failed = delegate { };
public event FinishedEventHandler Finished = delegate { };
public delegate void FinishedEventHandler (bool repo_is_encrypted, bool repo_is_empty, string [] warnings); public delegate void FinishedEventHandler (bool repo_is_encrypted, bool repo_is_empty, string [] warnings);
public delegate void FailedEventHandler ();
public event ProgressChangedEventHandler ProgressChanged = delegate { };
public delegate void ProgressChangedEventHandler (double percentage); public delegate void ProgressChangedEventHandler (double percentage);
public event StartedEventHandler Started;
public event FinishedEventHandler Finished;
public event FailedEventHandler Failed;
public event ProgressChangedEventHandler ProgressChanged;
public abstract bool Fetch (); public abstract bool Fetch ();
public abstract void Stop (); public abstract void Stop ();
@ -117,9 +117,7 @@ namespace SparkleLib {
public void Start () public void Start ()
{ {
IsActive = true; IsActive = true;
Started ();
if (Started != null)
Started ();
SparkleHelpers.DebugInfo ("Fetcher", TargetFolder + " | Fetching folder: " + RemoteUrl); SparkleHelpers.DebugInfo ("Fetcher", TargetFolder + " | Fetching folder: " + RemoteUrl);
@ -130,9 +128,7 @@ namespace SparkleLib {
string host_key = GetHostKey (); string host_key = GetHostKey ();
if (string.IsNullOrEmpty (host) || host_key == null) { if (string.IsNullOrEmpty (host) || host_key == null) {
if (Failed != null) Failed ();
Failed ();
return; return;
} }
@ -144,9 +140,7 @@ namespace SparkleLib {
!RequiredFingerprint.Equals (host_fingerprint)) { !RequiredFingerprint.Equals (host_fingerprint)) {
SparkleHelpers.DebugInfo ("Auth", "Fingerprint doesn't match"); SparkleHelpers.DebugInfo ("Auth", "Fingerprint doesn't match");
Failed ();
if (Failed != null)
Failed ();
return; return;
} }
@ -170,18 +164,14 @@ namespace SparkleLib {
// TODO: Find better way to determine if folder should have crypto setup // TODO: Find better way to determine if folder should have crypto setup
bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("crypto"); bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("crypto");
Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
if (Finished != null)
Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
} else { } else {
Thread.Sleep (500); Thread.Sleep (500);
SparkleHelpers.DebugInfo ("Fetcher", "Failed"); SparkleHelpers.DebugInfo ("Fetcher", "Failed");
IsActive = false; IsActive = false;
Failed ();
if (Failed != null)
Failed ();
} }
}) })
); );
@ -263,8 +253,7 @@ namespace SparkleLib {
protected void OnProgressChanged (double percentage) { protected void OnProgressChanged (double percentage) {
if (ProgressChanged != null) ProgressChanged (percentage);
ProgressChanged (percentage);
} }

View file

@ -25,13 +25,10 @@ namespace SparkleLib {
// listens for change notifications // listens for change notifications
public abstract class SparkleListenerBase { public abstract class SparkleListenerBase {
public event ConnectedEventHandler Connected; public event Action Connected = delegate { };
public delegate void ConnectedEventHandler (); public event Action Disconnected = delegate { };
public event DisconnectedEventHandler Disconnected; public event AnnouncementReceivedEventHandler AnnouncementReceived = delegate { };
public delegate void DisconnectedEventHandler ();
public event AnnouncementReceivedEventHandler AnnouncementReceived;
public delegate void AnnouncementReceivedEventHandler (SparkleAnnouncement announcement); public delegate void AnnouncementReceivedEventHandler (SparkleAnnouncement announcement);
public readonly Uri Server; public readonly Uri Server;
@ -118,9 +115,7 @@ namespace SparkleLib {
public void OnConnected () public void OnConnected ()
{ {
SparkleHelpers.DebugInfo ("Listener", "Listening for announcements on " + Server); SparkleHelpers.DebugInfo ("Listener", "Listening for announcements on " + Server);
Connected ();
if (Connected != null)
Connected ();
if (this.queue_up.Count > 0) { if (this.queue_up.Count > 0) {
SparkleHelpers.DebugInfo ("Listener", "Delivering " + this.queue_up.Count + " queued messages..."); SparkleHelpers.DebugInfo ("Listener", "Delivering " + this.queue_up.Count + " queued messages...");
@ -138,9 +133,7 @@ namespace SparkleLib {
public void OnDisconnected (string message) public void OnDisconnected (string message)
{ {
SparkleHelpers.DebugInfo ("Listener", "Disconnected from " + Server + ": " + message); SparkleHelpers.DebugInfo ("Listener", "Disconnected from " + Server + ": " + message);
Disconnected ();
if (Disconnected != null)
Disconnected ();
} }
@ -163,8 +156,7 @@ namespace SparkleLib {
AddRecentAnnouncement (announcement); AddRecentAnnouncement (announcement);
this.queue_down [announcement.FolderIdentifier] = announcement; this.queue_down [announcement.FolderIdentifier] = announcement;
if (AnnouncementReceived != null) AnnouncementReceived (announcement);
AnnouncementReceived (announcement);
} }

View file

@ -48,20 +48,18 @@ namespace SparkleLib {
public abstract List<SparkleChangeSet> GetChangeSets (int count); public abstract List<SparkleChangeSet> GetChangeSets (int count);
public event SyncStatusChangedEventHandler SyncStatusChanged = delegate { };
public delegate void SyncStatusChangedEventHandler (SyncStatus new_status); public delegate void SyncStatusChangedEventHandler (SyncStatus new_status);
public event SyncStatusChangedEventHandler SyncStatusChanged;
public event ProgressChangedEventHandler ProgressChanged = delegate { };
public delegate void ProgressChangedEventHandler (double percentage, string speed); public delegate void ProgressChangedEventHandler (double percentage, string speed);
public event ProgressChangedEventHandler ProgressChanged;
public event NewChangeSetEventHandler NewChangeSet = delegate { };
public delegate void NewChangeSetEventHandler (SparkleChangeSet change_set); public delegate void NewChangeSetEventHandler (SparkleChangeSet change_set);
public event NewChangeSetEventHandler NewChangeSet;
public delegate void ConflictResolvedEventHandler (); public event Action ConflictResolved = delegate { };
public event ConflictResolvedEventHandler ConflictResolved; public event Action ChangesDetected = delegate { };
public delegate void ChangesDetectedEventHandler ();
public event ChangesDetectedEventHandler ChangesDetected;
public readonly string LocalPath; public readonly string LocalPath;
public readonly string Name; public readonly string Name;
@ -200,9 +198,7 @@ namespace SparkleLib {
if (IsBuffering) if (IsBuffering)
return; return;
if (ChangesDetected != null) ChangesDetected ();
ChangesDetected ();
string relative_path = args.FullPath.Replace (LocalPath, ""); string relative_path = args.FullPath.Replace (LocalPath, "");
foreach (string exclude_path in ExcludePaths) { foreach (string exclude_path in ExcludePaths) {
@ -242,8 +238,7 @@ namespace SparkleLib {
} while (HasLocalChanges); } while (HasLocalChanges);
} else { } else {
if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.Idle);
SyncStatusChanged (SyncStatus.Idle);
} }
} else { } else {
@ -258,8 +253,7 @@ namespace SparkleLib {
protected void OnConflictResolved () protected void OnConflictResolved ()
{ {
if (ConflictResolved != null) ConflictResolved ();
ConflictResolved ();
} }
@ -269,16 +263,14 @@ namespace SparkleLib {
if (DateTime.Compare (this.progress_last_change, DateTime.Now.Subtract (this.progress_change_interval)) >= 0) if (DateTime.Compare (this.progress_last_change, DateTime.Now.Subtract (this.progress_change_interval)) >= 0)
return; return;
if (ProgressChanged != null) { if (progress_percentage == 100.0)
if (progress_percentage == 100.0) progress_percentage = 99.0;
progress_percentage = 99.0;
ProgressPercentage = progress_percentage; ProgressPercentage = progress_percentage;
ProgressSpeed = progress_speed; ProgressSpeed = progress_speed;
this.progress_last_change = DateTime.Now; this.progress_last_change = DateTime.Now;
ProgressChanged (progress_percentage, progress_speed); ProgressChanged (progress_percentage, progress_speed);
}
} }
@ -288,16 +280,13 @@ namespace SparkleLib {
HasUnsyncedChanges = true; HasUnsyncedChanges = true;
this.remote_timer.Stop (); this.remote_timer.Stop ();
SyncStatusChanged (SyncStatus.SyncUp);
if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncUp);
if (SyncUp ()) { if (SyncUp ()) {
SparkleHelpers.DebugInfo ("SyncUp", Name + " | Done"); SparkleHelpers.DebugInfo ("SyncUp", Name + " | Done");
HasUnsyncedChanges = false;
if (SyncStatusChanged != null) HasUnsyncedChanges = false;
SyncStatusChanged (SyncStatus.Idle); SyncStatusChanged (SyncStatus.Idle);
this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision)); this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision));
@ -307,17 +296,13 @@ namespace SparkleLib {
if (ServerOnline && SyncUp ()) { if (ServerOnline && SyncUp ()) {
HasUnsyncedChanges = false; HasUnsyncedChanges = false;
SyncStatusChanged (SyncStatus.Idle);
if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.Idle);
this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision)); this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision));
} else { } else {
ServerOnline = false; ServerOnline = false;
SyncStatusChanged (SyncStatus.Error);
if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.Error);
} }
} }
@ -333,9 +318,7 @@ namespace SparkleLib {
SparkleHelpers.DebugInfo ("SyncDown", Name + " | Initiated"); SparkleHelpers.DebugInfo ("SyncDown", Name + " | Initiated");
this.remote_timer.Stop (); this.remote_timer.Stop ();
if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.SyncDown);
SyncStatusChanged (SyncStatus.SyncDown);
string pre_sync_revision = CurrentRevision; string pre_sync_revision = CurrentRevision;
if (SyncDown ()) { if (SyncDown ()) {
@ -347,11 +330,14 @@ namespace SparkleLib {
ChangeSets.Count > 0) { ChangeSets.Count > 0) {
bool emit_change_event = true; bool emit_change_event = true;
foreach (SparkleChange change in ChangeSets [0].Changes) foreach (SparkleChange change in ChangeSets [0].Changes) {
if (change.Path.EndsWith (".sparkleshare")) if (change.Path.EndsWith (".sparkleshare")) {
emit_change_event = false; emit_change_event = false;
break;
}
}
if (NewChangeSet != null && emit_change_event) if (emit_change_event)
NewChangeSet (ChangeSets [0]); NewChangeSet (ChangeSets [0]);
} }
} }
@ -360,29 +346,25 @@ namespace SparkleLib {
// conflict. Tries only once, then lets // conflict. Tries only once, then lets
// the timer try again periodically // the timer try again periodically
if (HasUnsyncedChanges) { if (HasUnsyncedChanges) {
if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.SyncUp);
SyncStatusChanged (SyncStatus.SyncUp);
SyncUp (); SyncUp ();
HasUnsyncedChanges = false; HasUnsyncedChanges = false;
} }
if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.Idle);
SyncStatusChanged (SyncStatus.Idle);
} else { } else {
SparkleHelpers.DebugInfo ("SyncDown", Name + " | Error"); SparkleHelpers.DebugInfo ("SyncDown", Name + " | Error");
ServerOnline = false; ServerOnline = false;
if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.Error);
SyncStatusChanged (SyncStatus.Error);
} }
ProgressPercentage = 0.0; ProgressPercentage = 0.0;
ProgressSpeed = ""; ProgressSpeed = "";
if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.Idle);
SyncStatusChanged (SyncStatus.Idle);
this.remote_timer.Start (); this.remote_timer.Start ();
} }

View file

@ -22,7 +22,7 @@ namespace SparkleShare {
public class SparkleBubblesController { public class SparkleBubblesController {
public event ShowBubbleEventHandler ShowBubbleEvent; public event ShowBubbleEventHandler ShowBubbleEvent = delegate { };
public delegate void ShowBubbleEventHandler (string title, string subtext, string image_path); public delegate void ShowBubbleEventHandler (string title, string subtext, string image_path);
@ -41,8 +41,7 @@ namespace SparkleShare {
public void ShowBubble (string title, string subtext, string image_path) public void ShowBubble (string title, string subtext, string image_path)
{ {
if (ShowBubbleEvent != null) ShowBubbleEvent (title, subtext, image_path);
ShowBubbleEvent (title, subtext, image_path);
} }

View file

@ -45,46 +45,36 @@ namespace SparkleShare {
public string ProgressSpeed = ""; public string ProgressSpeed = "";
public event ShowSetupWindowEventHandler ShowSetupWindowEvent; public event ShowSetupWindowEventHandler ShowSetupWindowEvent = delegate { };
public delegate void ShowSetupWindowEventHandler (PageType page_type); public delegate void ShowSetupWindowEventHandler (PageType page_type);
public event ShowAboutWindowEventHandler ShowAboutWindowEvent; public event Action ShowAboutWindowEvent = delegate { };
public delegate void ShowAboutWindowEventHandler (); public event Action ShowEventLogWindowEvent = delegate { };
public event ShowEventLogWindowEventHandler ShowEventLogWindowEvent; public event FolderFetchedEventHandler FolderFetched = delegate { };
public delegate void ShowEventLogWindowEventHandler ();
public event FolderFetchedEventHandler FolderFetched;
public delegate void FolderFetchedEventHandler (string remote_url, string [] warnings); public delegate void FolderFetchedEventHandler (string remote_url, string [] warnings);
public event FolderFetchErrorHandler FolderFetchError; public event FolderFetchErrorHandler FolderFetchError = delegate { };
public delegate void FolderFetchErrorHandler (string remote_url, string [] errors); public delegate void FolderFetchErrorHandler (string remote_url, string [] errors);
public event FolderFetchingHandler FolderFetching; public event FolderFetchingHandler FolderFetching = delegate { };
public delegate void FolderFetchingHandler (double percentage); public delegate void FolderFetchingHandler (double percentage);
public event FolderListChangedHandler FolderListChanged; public event Action FolderListChanged = delegate { };
public delegate void FolderListChangedHandler ();
public event OnIdleHandler OnIdle; public event Action OnIdle = delegate { };
public delegate void OnIdleHandler (); public event Action OnSyncing = delegate { };
public event Action OnError = delegate { };
public event OnSyncingHandler OnSyncing;
public delegate void OnSyncingHandler ();
public event OnErrorHandler OnError;
public delegate void OnErrorHandler ();
public event InviteReceivedHandler InviteReceived; public event InviteReceivedHandler InviteReceived = delegate { };
public delegate void InviteReceivedHandler (SparkleInvite invite); public delegate void InviteReceivedHandler (SparkleInvite invite);
public event NotificationRaisedEventHandler NotificationRaised; public event NotificationRaisedEventHandler NotificationRaised = delegate { };
public delegate void NotificationRaisedEventHandler (SparkleChangeSet change_set); public delegate void NotificationRaisedEventHandler (SparkleChangeSet change_set);
public event AlertNotificationRaisedEventHandler AlertNotificationRaised; public event AlertNotificationRaisedEventHandler AlertNotificationRaised = delegate { };
public delegate void AlertNotificationRaisedEventHandler (string title, string message); public delegate void AlertNotificationRaisedEventHandler (string title, string message);
@ -247,9 +237,7 @@ namespace SparkleShare {
new Thread (() => { new Thread (() => {
CheckRepositories (); CheckRepositories ();
RepositoriesLoaded = true; RepositoriesLoaded = true;
FolderListChanged ();
if (FolderListChanged != null)
FolderListChanged ();
}).Start (); }).Start ();
} }
@ -302,14 +290,13 @@ namespace SparkleShare {
}; };
repo.NewChangeSet += delegate (SparkleChangeSet change_set) { repo.NewChangeSet += delegate (SparkleChangeSet change_set) {
if (NotificationsEnabled && NotificationRaised != null) if (NotificationsEnabled)
NotificationRaised (change_set); NotificationRaised (change_set);
}; };
repo.ConflictResolved += delegate { repo.ConflictResolved += delegate {
if (AlertNotificationRaised != null) AlertNotificationRaised ("Conflict detected",
AlertNotificationRaised ("Conflict detected", "Don't worry, SparkleShare made a copy of each conflicting file.");
"Don't worry, SparkleShare made a copy of each conflicting file.");
}; };
this.repositories.Add (repo); this.repositories.Add (repo);
@ -380,8 +367,7 @@ namespace SparkleShare {
} }
} }
if (FolderListChanged != null) FolderListChanged ();
FolderListChanged ();
} }
} }
@ -404,13 +390,13 @@ namespace SparkleShare {
} }
} }
if (has_syncing_repos && OnSyncing != null) { if (has_syncing_repos) {
OnSyncing (); OnSyncing ();
} else if (has_unsynced_repos && OnError != null) { } else if (has_unsynced_repos) {
OnError (); OnError ();
} else if (OnIdle != null) { } else {
OnIdle (); OnIdle ();
} }
} }
@ -442,35 +428,29 @@ namespace SparkleShare {
if (this.fetcher != null && if (this.fetcher != null &&
this.fetcher.IsActive) { this.fetcher.IsActive) {
if (AlertNotificationRaised != null) AlertNotificationRaised ("SparkleShare Setup seems busy", "Please wait for it to finish");
AlertNotificationRaised ("SparkleShare Setup seems busy",
"Please wait for it to finish");
} else { } else {
if (InviteReceived != null) { SparkleInvite invite = new SparkleInvite (args.FullPath);
SparkleInvite invite = new SparkleInvite (args.FullPath);
// It may be that the invite we received a path to isn't // It may be that the invite we received a path to isn't
// fully downloaded yet, so we try to read it several times // fully downloaded yet, so we try to read it several times
int tries = 0; int tries = 0;
while (!invite.IsValid) { while (!invite.IsValid) {
Thread.Sleep (250); Thread.Sleep (250);
invite = new SparkleInvite (args.FullPath); invite = new SparkleInvite (args.FullPath);
tries++; tries++;
if (tries > 20) { if (tries > 20) {
if (AlertNotificationRaised != null) AlertNotificationRaised ("Oh noes!", "This invite seems screwed up...");
AlertNotificationRaised ("Oh noes!", "This invite seems screwed up..."); break;
break;
}
} }
if (invite.IsValid)
InviteReceived (invite);
File.Delete (args.FullPath);
} }
if (invite.IsValid)
InviteReceived (invite);
File.Delete (args.FullPath);
} }
} }
@ -485,8 +465,7 @@ namespace SparkleShare {
if (!Directory.Exists (tmp_path)) { if (!Directory.Exists (tmp_path)) {
Directory.CreateDirectory (tmp_path); Directory.CreateDirectory (tmp_path);
File.SetAttributes (tmp_path, File.SetAttributes (tmp_path, File.GetAttributes (tmp_path) | FileAttributes.Hidden);
File.GetAttributes (tmp_path) | FileAttributes.Hidden);
} }
string canonical_name = Path.GetFileNameWithoutExtension (remote_path); string canonical_name = Path.GetFileNameWithoutExtension (remote_path);
@ -507,10 +486,8 @@ namespace SparkleShare {
SparkleHelpers.DebugInfo ("Controller", SparkleHelpers.DebugInfo ("Controller",
"Failed to load '" + backend + "' backend for '" + canonical_name + "' " + e.Message); "Failed to load '" + backend + "' backend for '" + canonical_name + "' " + e.Message);
if (FolderFetchError != null) FolderFetchError (Path.Combine (address, remote_path).Replace (@"\", "/"),
FolderFetchError ( new string [] {"Failed to load \"" + backend + "\" backend for \"" + canonical_name + "\""});
Path.Combine (address, remote_path).Replace (@"\", "/"),
new string [] {"Failed to load \"" + backend + "\" backend for \"" + canonical_name + "\""});
return; return;
} }
@ -518,12 +495,10 @@ namespace SparkleShare {
this.fetcher.Finished += delegate (bool repo_is_encrypted, bool repo_is_empty, string [] warnings) { this.fetcher.Finished += delegate (bool repo_is_encrypted, bool repo_is_empty, string [] warnings) {
if (repo_is_encrypted && repo_is_empty) { if (repo_is_encrypted && repo_is_empty) {
if (ShowSetupWindowEvent != null) ShowSetupWindowEvent (PageType.CryptoSetup);
ShowSetupWindowEvent (PageType.CryptoSetup);
} else if (repo_is_encrypted) { } else if (repo_is_encrypted) {
if (ShowSetupWindowEvent != null) ShowSetupWindowEvent (PageType.CryptoPassword);
ShowSetupWindowEvent (PageType.CryptoPassword);
} else { } else {
FinishFetcher (); FinishFetcher ();
@ -531,15 +506,12 @@ namespace SparkleShare {
}; };
this.fetcher.Failed += delegate { this.fetcher.Failed += delegate {
if (FolderFetchError != null) FolderFetchError (this.fetcher.RemoteUrl.ToString (), this.fetcher.Errors);
FolderFetchError (this.fetcher.RemoteUrl.ToString (), this.fetcher.Errors);
StopFetcher (); StopFetcher ();
}; };
this.fetcher.ProgressChanged += delegate (double percentage) { this.fetcher.ProgressChanged += delegate (double percentage) {
if (FolderFetching != null) FolderFetching (percentage);
FolderFetching (percentage);
}; };
this.fetcher.Start (); this.fetcher.Start ();
@ -553,8 +525,7 @@ namespace SparkleShare {
if (Directory.Exists (this.fetcher.TargetFolder)) { if (Directory.Exists (this.fetcher.TargetFolder)) {
try { try {
Directory.Delete (this.fetcher.TargetFolder, true); Directory.Delete (this.fetcher.TargetFolder, true);
SparkleHelpers.DebugInfo ("Controller", SparkleHelpers.DebugInfo ("Controller", "Deleted " + this.fetcher.TargetFolder);
"Deleted " + this.fetcher.TargetFolder);
} catch (Exception e) { } catch (Exception e) {
SparkleHelpers.DebugInfo ("Controller", SparkleHelpers.DebugInfo ("Controller",
@ -616,8 +587,7 @@ namespace SparkleShare {
this.config.AddFolder (target_folder_name, this.fetcher.Identifier, this.config.AddFolder (target_folder_name, this.fetcher.Identifier,
this.fetcher.RemoteUrl.ToString (), backend); this.fetcher.RemoteUrl.ToString (), backend);
if (FolderFetched != null) FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ());
FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ());
/* TODO /* TODO
if (!string.IsNullOrEmpty (announcements_url)) { if (!string.IsNullOrEmpty (announcements_url)) {
@ -626,9 +596,7 @@ namespace SparkleShare {
*/ */
AddRepository (target_folder_path); AddRepository (target_folder_path);
FolderListChanged ();
if (FolderListChanged != null)
FolderListChanged ();
this.fetcher.Dispose (); this.fetcher.Dispose ();
this.fetcher = null; this.fetcher = null;
@ -643,22 +611,19 @@ namespace SparkleShare {
public void ShowSetupWindow (PageType page_type) public void ShowSetupWindow (PageType page_type)
{ {
if (ShowSetupWindowEvent != null) ShowSetupWindowEvent (page_type);
ShowSetupWindowEvent (page_type);
} }
public void ShowAboutWindow () public void ShowAboutWindow ()
{ {
if (ShowAboutWindowEvent != null) ShowAboutWindowEvent ();
ShowAboutWindowEvent ();
} }
public void ShowEventLogWindow () public void ShowEventLogWindow ()
{ {
if (ShowEventLogWindowEvent != null) ShowEventLogWindowEvent ();
ShowEventLogWindowEvent ();
} }

View file

@ -28,23 +28,19 @@ namespace SparkleShare {
public class SparkleEventLogController { public class SparkleEventLogController {
public event ShowWindowEventHandler ShowWindowEvent; public event Action ShowWindowEvent = delegate { };
public delegate void ShowWindowEventHandler (); public event Action HideWindowEvent = delegate { };
public event Action ContentLoadingEvent = delegate { };
public event HideWindowEventHandler HideWindowEvent; public event UpdateContentEventEventHandler UpdateContentEvent = delegate { };
public delegate void HideWindowEventHandler ();
public event UpdateContentEventEventHandler UpdateContentEvent;
public delegate void UpdateContentEventEventHandler (string html); public delegate void UpdateContentEventEventHandler (string html);
public event UpdateChooserEventHandler UpdateChooserEvent; public event UpdateChooserEventHandler UpdateChooserEvent = delegate { };
public delegate void UpdateChooserEventHandler (string [] folders); public delegate void UpdateChooserEventHandler (string [] folders);
public event UpdateSizeInfoEventHandler UpdateSizeInfoEvent; public event UpdateSizeInfoEventHandler UpdateSizeInfoEvent = delegate { };
public delegate void UpdateSizeInfoEventHandler (string size, string history_size); public delegate void UpdateSizeInfoEventHandler (string size, string history_size);
public event ContentLoadingEventHandler ContentLoadingEvent;
public delegate void ContentLoadingEventHandler ();
private string selected_folder; private string selected_folder;
@ -57,11 +53,8 @@ namespace SparkleShare {
set { set {
this.selected_folder = value; this.selected_folder = value;
if (ContentLoadingEvent != null) ContentLoadingEvent ();
ContentLoadingEvent (); UpdateSizeInfoEvent ("…", "…");
if (UpdateSizeInfoEvent != null)
UpdateSizeInfoEvent ("…", "…");
Stopwatch watch = new Stopwatch (); Stopwatch watch = new Stopwatch ();
watch.Start (); watch.Start ();
@ -77,11 +70,8 @@ namespace SparkleShare {
if (watch.ElapsedMilliseconds < delay) if (watch.ElapsedMilliseconds < delay)
Thread.Sleep (delay - (int) watch.ElapsedMilliseconds); Thread.Sleep (delay - (int) watch.ElapsedMilliseconds);
if (UpdateContentEvent != null) UpdateContentEvent (html);
UpdateContentEvent (html); UpdateSizeInfoEvent (Size, HistorySize);
if (UpdateSizeInfoEvent != null)
UpdateSizeInfoEvent (Size, HistorySize);
}).Start (); }).Start ();
} }
@ -92,9 +82,7 @@ namespace SparkleShare {
List<SparkleChangeSet> change_sets = GetLog (this.selected_folder); List<SparkleChangeSet> change_sets = GetLog (this.selected_folder);
string html = GetHTMLLog (change_sets); string html = GetHTMLLog (change_sets);
UpdateSizeInfoEvent (Size, HistorySize);
if (UpdateSizeInfoEvent != null)
UpdateSizeInfoEvent (Size, HistorySize);
return html; return html;
} }
@ -158,45 +146,33 @@ namespace SparkleShare {
Program.Controller.ShowEventLogWindowEvent += delegate { Program.Controller.ShowEventLogWindowEvent += delegate {
if (this.selected_folder == null) { if (this.selected_folder == null) {
new Thread (() => { new Thread (() => {
if (UpdateChooserEvent != null) UpdateChooserEvent (Folders);
UpdateChooserEvent (Folders); UpdateContentEvent (HTML);
if (UpdateContentEvent != null)
UpdateContentEvent (HTML);
}).Start (); }).Start ();
} }
if (ShowWindowEvent != null) ShowWindowEvent ();
ShowWindowEvent ();
}; };
Program.Controller.OnIdle += delegate { Program.Controller.OnIdle += delegate {
if (UpdateContentEvent != null) UpdateContentEvent (HTML);
UpdateContentEvent (HTML); UpdateSizeInfoEvent (Size, HistorySize);
if (UpdateSizeInfoEvent != null)
UpdateSizeInfoEvent (Size, HistorySize);
}; };
Program.Controller.FolderListChanged += delegate { Program.Controller.FolderListChanged += delegate {
if (this.selected_folder != null && !Program.Controller.Folders.Contains (this.selected_folder)) if (this.selected_folder != null && !Program.Controller.Folders.Contains (this.selected_folder))
this.selected_folder = null; this.selected_folder = null;
if (UpdateChooserEvent != null) UpdateChooserEvent (Folders);
UpdateChooserEvent (Folders); UpdateSizeInfoEvent (Size, HistorySize);
if (UpdateSizeInfoEvent != null)
UpdateSizeInfoEvent (Size, HistorySize);
}; };
} }
public void WindowClosed () public void WindowClosed ()
{ {
if (HideWindowEvent != null) HideWindowEvent ();
HideWindowEvent ();
this.selected_folder = null; this.selected_folder = null;
} }

View file

@ -46,34 +46,31 @@ namespace SparkleShare {
public class SparkleSetupController { public class SparkleSetupController {
public event ShowWindowEventHandler ShowWindowEvent; public event Action ShowWindowEvent = delegate { };
public delegate void ShowWindowEventHandler (); public event Action HideWindowEvent = delegate { };
public event HideWindowEventHandler HideWindowEvent; public event ChangePageEventHandler ChangePageEvent = delegate { };
public delegate void HideWindowEventHandler ();
public event ChangePageEventHandler ChangePageEvent;
public delegate void ChangePageEventHandler (PageType page, string [] warnings); public delegate void ChangePageEventHandler (PageType page, string [] warnings);
public event UpdateProgressBarEventHandler UpdateProgressBarEvent; public event UpdateProgressBarEventHandler UpdateProgressBarEvent = delegate { };
public delegate void UpdateProgressBarEventHandler (double percentage); public delegate void UpdateProgressBarEventHandler (double percentage);
public event UpdateSetupContinueButtonEventHandler UpdateSetupContinueButtonEvent; public event UpdateSetupContinueButtonEventHandler UpdateSetupContinueButtonEvent = delegate { };
public delegate void UpdateSetupContinueButtonEventHandler (bool button_enabled); public delegate void UpdateSetupContinueButtonEventHandler (bool button_enabled);
public event UpdateCryptoSetupContinueButtonEventHandler UpdateCryptoSetupContinueButtonEvent; public event UpdateCryptoSetupContinueButtonEventHandler UpdateCryptoSetupContinueButtonEvent = delegate { };
public delegate void UpdateCryptoSetupContinueButtonEventHandler (bool button_enabled); public delegate void UpdateCryptoSetupContinueButtonEventHandler (bool button_enabled);
public event UpdateCryptoPasswordContinueButtonEventHandler UpdateCryptoPasswordContinueButtonEvent; public event UpdateCryptoPasswordContinueButtonEventHandler UpdateCryptoPasswordContinueButtonEvent = delegate { };
public delegate void UpdateCryptoPasswordContinueButtonEventHandler (bool button_enabled); public delegate void UpdateCryptoPasswordContinueButtonEventHandler (bool button_enabled);
public event UpdateAddProjectButtonEventHandler UpdateAddProjectButtonEvent; public event UpdateAddProjectButtonEventHandler UpdateAddProjectButtonEvent = delegate { };
public delegate void UpdateAddProjectButtonEventHandler (bool button_enabled); public delegate void UpdateAddProjectButtonEventHandler (bool button_enabled);
public event ChangeAddressFieldEventHandler ChangeAddressFieldEvent; public event ChangeAddressFieldEventHandler ChangeAddressFieldEvent = delegate { };
public delegate void ChangeAddressFieldEventHandler (string text, string example_text, FieldState state); public delegate void ChangeAddressFieldEventHandler (string text, string example_text, FieldState state);
public event ChangePathFieldEventHandler ChangePathFieldEvent; public event ChangePathFieldEventHandler ChangePathFieldEvent = delegate { };
public delegate void ChangePathFieldEventHandler (string text, string example_text, FieldState state); public delegate void ChangePathFieldEventHandler (string text, string example_text, FieldState state);
public readonly List<SparklePlugin> Plugins = new List<SparklePlugin> (); public readonly List<SparklePlugin> Plugins = new List<SparklePlugin> ();
@ -167,27 +164,19 @@ namespace SparkleShare {
Program.Controller.InviteReceived += delegate (SparkleInvite invite) { Program.Controller.InviteReceived += delegate (SparkleInvite invite) {
PendingInvite = invite; PendingInvite = invite;
if (ChangePageEvent != null) ChangePageEvent (PageType.Invite, null);
ChangePageEvent (PageType.Invite, null); ShowWindowEvent ();
if (ShowWindowEvent != null)
ShowWindowEvent ();
}; };
Program.Controller.ShowSetupWindowEvent += delegate (PageType page_type) { Program.Controller.ShowSetupWindowEvent += delegate (PageType page_type) {
if (page_type == PageType.CryptoSetup || page_type == PageType.CryptoPassword) { if (page_type == PageType.CryptoSetup || page_type == PageType.CryptoPassword) {
if (ChangePageEvent != null) ChangePageEvent (page_type, null);
ChangePageEvent (page_type, null);
return; return;
} }
if (PendingInvite != null) { if (PendingInvite != null) {
WindowIsOpen = true; WindowIsOpen = true;
ShowWindowEvent ();
if (ShowWindowEvent != null)
ShowWindowEvent ();
return; return;
} }
@ -196,9 +185,7 @@ namespace SparkleShare {
this.current_page == PageType.CryptoSetup || this.current_page == PageType.CryptoSetup ||
this.current_page == PageType.CryptoPassword) { this.current_page == PageType.CryptoPassword) {
if (ShowWindowEvent != null) ShowWindowEvent ();
ShowWindowEvent ();
return; return;
} }
@ -207,34 +194,24 @@ namespace SparkleShare {
if (this.current_page == PageType.Error || if (this.current_page == PageType.Error ||
this.current_page == PageType.Finished || this.current_page == PageType.Finished ||
this.current_page == PageType.None) { this.current_page == PageType.None) {
if (ChangePageEvent != null) ChangePageEvent (PageType.Add, null);
ChangePageEvent (PageType.Add, null);
} }
if (ShowWindowEvent != null) ShowWindowEvent ();
ShowWindowEvent ();
} else if (!Program.Controller.FirstRun && TutorialPageNumber == 0) { } else if (!Program.Controller.FirstRun && TutorialPageNumber == 0) {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Add, null);
WindowIsOpen = true; WindowIsOpen = true;
ChangePageEvent (PageType.Add, null);
if (ShowWindowEvent != null) ShowWindowEvent ();
ShowWindowEvent ();
} }
return; return;
} }
WindowIsOpen = true; WindowIsOpen = true;
ChangePageEvent (page_type, null);
if (ChangePageEvent != null) ShowWindowEvent ();
ChangePageEvent (page_type, null);
if (ShowWindowEvent != null)
ShowWindowEvent ();
}; };
} }
@ -250,9 +227,7 @@ namespace SparkleShare {
this.fetch_prior_history = false; this.fetch_prior_history = false;
WindowIsOpen = false; WindowIsOpen = false;
HideWindowEvent ();
if (HideWindowEvent != null)
HideWindowEvent ();
} }
@ -262,9 +237,7 @@ namespace SparkleShare {
email = email.Trim (); email = email.Trim ();
bool fields_valid = (!string.IsNullOrEmpty (full_name) && IsValidEmail (email)); bool fields_valid = (!string.IsNullOrEmpty (full_name) && IsValidEmail (email));
UpdateSetupContinueButtonEvent (fields_valid);
if (UpdateSetupContinueButtonEvent != null)
UpdateSetupContinueButtonEvent (fields_valid);
} }
@ -295,18 +268,14 @@ namespace SparkleShare {
}).Start (); }).Start ();
TutorialPageNumber = 1; TutorialPageNumber = 1;
ChangePageEvent (PageType.Tutorial, null);
if (ChangePageEvent != null)
ChangePageEvent (PageType.Tutorial, null);
} }
public void TutorialSkipped () public void TutorialSkipped ()
{ {
TutorialPageNumber = 4; TutorialPageNumber = 4;
ChangePageEvent (PageType.Tutorial, null);
if (ChangePageEvent != null)
ChangePageEvent (PageType.Tutorial, null);
} }
@ -324,16 +293,13 @@ namespace SparkleShare {
TutorialPageNumber = 0; TutorialPageNumber = 0;
WindowIsOpen = false; WindowIsOpen = false;
HideWindowEvent ();
if (HideWindowEvent != null)
HideWindowEvent ();
if (this.create_startup_item) if (this.create_startup_item)
Program.Controller.CreateStartupItem (); Program.Controller.CreateStartupItem ();
} else { } else {
if (ChangePageEvent != null) ChangePageEvent (PageType.Tutorial, null);
ChangePageEvent (PageType.Tutorial, null);
} }
} }
@ -343,29 +309,23 @@ namespace SparkleShare {
SelectedPlugin = Plugins [plugin_index]; SelectedPlugin = Plugins [plugin_index];
if (SelectedPlugin.Address != null) { if (SelectedPlugin.Address != null) {
if (ChangeAddressFieldEvent != null) ChangeAddressFieldEvent (SelectedPlugin.Address, "", FieldState.Disabled);
ChangeAddressFieldEvent (SelectedPlugin.Address, "", FieldState.Disabled);
} else if (SelectedPlugin.AddressExample != null) { } else if (SelectedPlugin.AddressExample != null) {
if (ChangeAddressFieldEvent != null) ChangeAddressFieldEvent (this.saved_address, SelectedPlugin.AddressExample, FieldState.Enabled);
ChangeAddressFieldEvent (this.saved_address, SelectedPlugin.AddressExample, FieldState.Enabled);
} else { } else {
if (ChangeAddressFieldEvent != null) ChangeAddressFieldEvent (this.saved_address, "", FieldState.Enabled);
ChangeAddressFieldEvent (this.saved_address, "", FieldState.Enabled);
} }
if (SelectedPlugin.Path != null) { if (SelectedPlugin.Path != null) {
if (ChangePathFieldEvent != null) ChangePathFieldEvent (SelectedPlugin.Path, "", FieldState.Disabled);
ChangePathFieldEvent (SelectedPlugin.Path, "", FieldState.Disabled);
} else if (SelectedPlugin.PathExample != null) { } else if (SelectedPlugin.PathExample != null) {
if (ChangePathFieldEvent != null) ChangePathFieldEvent (this.saved_remote_path, SelectedPlugin.PathExample, FieldState.Enabled);
ChangePathFieldEvent (this.saved_remote_path, SelectedPlugin.PathExample, FieldState.Enabled);
} else { } else {
if (ChangePathFieldEvent != null) ChangePathFieldEvent (this.saved_remote_path, "", FieldState.Enabled);
ChangePathFieldEvent (this.saved_remote_path, "", FieldState.Enabled);
} }
} }
@ -387,11 +347,9 @@ namespace SparkleShare {
this.saved_remote_path = remote_path; this.saved_remote_path = remote_path;
bool fields_valid = (!string.IsNullOrEmpty (address) && bool fields_valid = (!string.IsNullOrEmpty (address) &&
!string.IsNullOrEmpty (remote_path) && !string.IsNullOrEmpty (remote_path) && !remote_path.Contains ("\""));
!remote_path.Contains ("\""));
if (UpdateAddProjectButtonEvent != null) UpdateAddProjectButtonEvent (fields_valid);
UpdateAddProjectButtonEvent (fields_valid);
} }
@ -400,8 +358,7 @@ namespace SparkleShare {
SyncingFolder = Path.GetFileNameWithoutExtension (remote_path); SyncingFolder = Path.GetFileNameWithoutExtension (remote_path);
ProgressBarPercentage = 1.0; ProgressBarPercentage = 1.0;
if (ChangePageEvent != null) ChangePageEvent (PageType.Syncing, null);
ChangePageEvent (PageType.Syncing, null);
address = address.Trim (); address = address.Trim ();
remote_path = remote_path.Trim (); remote_path = remote_path.Trim ();
@ -453,8 +410,7 @@ namespace SparkleShare {
} }
} }
if (ChangePageEvent != null) ChangePageEvent (PageType.Finished, warnings);
ChangePageEvent (PageType.Finished, warnings);
Program.Controller.FolderFetched -= AddPageFetchedDelegate; Program.Controller.FolderFetched -= AddPageFetchedDelegate;
Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate; Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate;
@ -465,9 +421,8 @@ namespace SparkleShare {
{ {
SyncingFolder = ""; SyncingFolder = "";
PreviousUrl = remote_url; PreviousUrl = remote_url;
if (ChangePageEvent != null) ChangePageEvent (PageType.Error, errors);
ChangePageEvent (PageType.Error, errors);
Program.Controller.FolderFetched -= AddPageFetchedDelegate; Program.Controller.FolderFetched -= AddPageFetchedDelegate;
Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate; Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate;
@ -477,9 +432,7 @@ namespace SparkleShare {
private void SyncingPageFetchingDelegate (double percentage) private void SyncingPageFetchingDelegate (double percentage)
{ {
ProgressBarPercentage = percentage; ProgressBarPercentage = percentage;
UpdateProgressBarEvent (ProgressBarPercentage);
if (UpdateProgressBarEvent != null)
UpdateProgressBarEvent (ProgressBarPercentage);
} }
@ -489,13 +442,10 @@ namespace SparkleShare {
PreviousAddress = PendingInvite.Address; PreviousAddress = PendingInvite.Address;
PreviousPath = PendingInvite.RemotePath; PreviousPath = PendingInvite.RemotePath;
if (ChangePageEvent != null) ChangePageEvent (PageType.Syncing, null);
ChangePageEvent (PageType.Syncing, null);
if (!PendingInvite.Accept ()) { if (!PendingInvite.Accept ()) {
if (ChangePageEvent != null) ChangePageEvent (PageType.Error, null);
ChangePageEvent (PageType.Error, null);
return; return;
} }
@ -515,8 +465,7 @@ namespace SparkleShare {
SyncingFolder = ""; SyncingFolder = "";
PendingInvite = null; PendingInvite = null;
if (ChangePageEvent != null) ChangePageEvent (PageType.Finished, warnings);
ChangePageEvent (PageType.Finished, warnings);
Program.Controller.FolderFetched -= AddPageFetchedDelegate; Program.Controller.FolderFetched -= AddPageFetchedDelegate;
Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate; Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate;
@ -528,8 +477,7 @@ namespace SparkleShare {
SyncingFolder = ""; SyncingFolder = "";
PreviousUrl = remote_url; PreviousUrl = remote_url;
if (ChangePageEvent != null) ChangePageEvent (PageType.Error, errors);
ChangePageEvent (PageType.Error, errors);
Program.Controller.FolderFetched -= AddPageFetchedDelegate; Program.Controller.FolderFetched -= AddPageFetchedDelegate;
Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate; Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate;
@ -541,12 +489,10 @@ namespace SparkleShare {
{ {
Program.Controller.StopFetcher (); Program.Controller.StopFetcher ();
if (ChangePageEvent != null) { if (PendingInvite != null)
if (PendingInvite != null) ChangePageEvent (PageType.Invite, null);
ChangePageEvent (PageType.Invite, null); else
else ChangePageEvent (PageType.Add, null);
ChangePageEvent (PageType.Add, null);
}
} }
@ -562,18 +508,14 @@ namespace SparkleShare {
public void CheckCryptoSetupPage (string password) public void CheckCryptoSetupPage (string password)
{ {
bool valid_password = (password.Length > 0 && !password.Contains (" ")); bool valid_password = (password.Length > 0 && !password.Contains (" "));
UpdateCryptoSetupContinueButtonEvent (valid_password);
if (UpdateCryptoSetupContinueButtonEvent != null)
UpdateCryptoSetupContinueButtonEvent (valid_password);
} }
public void CheckCryptoPasswordPage (string password) public void CheckCryptoPasswordPage (string password)
{ {
bool password_correct = Program.Controller.CheckPassword (password); bool password_correct = Program.Controller.CheckPassword (password);
UpdateCryptoPasswordContinueButtonEvent (password_correct);
if (UpdateCryptoPasswordContinueButtonEvent != null)
UpdateCryptoPasswordContinueButtonEvent (password_correct);
} }
@ -592,9 +534,7 @@ namespace SparkleShare {
public void CryptoPasswordPageCompleted (string password) public void CryptoPasswordPageCompleted (string password)
{ {
ProgressBarPercentage = 100.0; ProgressBarPercentage = 100.0;
ChangePageEvent (PageType.Syncing, null);
if (ChangePageEvent != null)
ChangePageEvent (PageType.Syncing, null);
new Thread (() => { new Thread (() => {
Thread.Sleep (1000); Thread.Sleep (1000);
@ -620,9 +560,7 @@ namespace SparkleShare {
this.fetch_prior_history = false; this.fetch_prior_history = false;
this.current_page = PageType.None; this.current_page = PageType.None;
HideWindowEvent ();
if (HideWindowEvent != null)
HideWindowEvent ();
} }

View file

@ -36,19 +36,19 @@ namespace SparkleShare {
public class SparkleStatusIconController { public class SparkleStatusIconController {
public event UpdateIconEventHandler UpdateIconEvent; public event UpdateIconEventHandler UpdateIconEvent = delegate { };
public delegate void UpdateIconEventHandler (int icon_frame); public delegate void UpdateIconEventHandler (int icon_frame);
public event UpdateMenuEventHandler UpdateMenuEvent; public event UpdateMenuEventHandler UpdateMenuEvent = delegate { };
public delegate void UpdateMenuEventHandler (IconState state); public delegate void UpdateMenuEventHandler (IconState state);
public event UpdateStatusItemEventHandler UpdateStatusItemEvent; public event UpdateStatusItemEventHandler UpdateStatusItemEvent = delegate { };
public delegate void UpdateStatusItemEventHandler (string state_text); public delegate void UpdateStatusItemEventHandler (string state_text);
public event UpdateQuitItemEventHandler UpdateQuitItemEvent; public event UpdateQuitItemEventHandler UpdateQuitItemEvent = delegate { };
public delegate void UpdateQuitItemEventHandler (bool quit_item_enabled); public delegate void UpdateQuitItemEventHandler (bool quit_item_enabled);
public event UpdateOpenRecentEventsItemEventHandler UpdateOpenRecentEventsItemEvent; public event UpdateOpenRecentEventsItemEventHandler UpdateOpenRecentEventsItemEvent = delegate { };
public delegate void UpdateOpenRecentEventsItemEventHandler (bool open_recent_events_item_enabled); public delegate void UpdateOpenRecentEventsItemEventHandler (bool open_recent_events_item_enabled);
public IconState CurrentState = IconState.Idle; public IconState CurrentState = IconState.Idle;
@ -138,14 +138,9 @@ namespace SparkleShare {
StateText = "Files up to date " + FolderSize; StateText = "Files up to date " + FolderSize;
} }
if (UpdateStatusItemEvent != null) UpdateStatusItemEvent (StateText);
UpdateStatusItemEvent (StateText); UpdateOpenRecentEventsItemEvent (OpenRecentEventsItemEnabled);
UpdateMenuEvent (CurrentState);
if (UpdateOpenRecentEventsItemEvent != null)
UpdateOpenRecentEventsItemEvent (OpenRecentEventsItemEnabled);
if (UpdateMenuEvent != null)
UpdateMenuEvent (CurrentState);
}; };
Program.Controller.OnIdle += delegate { Program.Controller.OnIdle += delegate {
@ -158,19 +153,13 @@ namespace SparkleShare {
StateText = "Files up to date " + FolderSize; StateText = "Files up to date " + FolderSize;
} }
if (UpdateQuitItemEvent != null) UpdateQuitItemEvent (QuitItemEnabled);
UpdateQuitItemEvent (QuitItemEnabled); UpdateStatusItemEvent (StateText);
if (UpdateStatusItemEvent != null)
UpdateStatusItemEvent (StateText);
this.animation.Stop (); this.animation.Stop ();
if (UpdateIconEvent != null) UpdateIconEvent (0);
UpdateIconEvent (0); UpdateMenuEvent (CurrentState);
if (UpdateMenuEvent != null)
UpdateMenuEvent (CurrentState);
}; };
Program.Controller.OnSyncing += delegate { Program.Controller.OnSyncing += delegate {
@ -202,11 +191,8 @@ namespace SparkleShare {
StateText += " " + ProgressPercentage + "% " + ProgressSpeed; StateText += " " + ProgressPercentage + "% " + ProgressSpeed;
if (UpdateStatusItemEvent != null) UpdateStatusItemEvent (StateText);
UpdateStatusItemEvent (StateText); UpdateQuitItemEvent (QuitItemEnabled);
if (UpdateQuitItemEvent != null)
UpdateQuitItemEvent (QuitItemEnabled);
this.animation.Start (); this.animation.Start ();
}; };
@ -215,16 +201,12 @@ namespace SparkleShare {
CurrentState = IconState.Error; CurrentState = IconState.Error;
StateText = "Failed to send some changes"; StateText = "Failed to send some changes";
if (UpdateQuitItemEvent != null) UpdateQuitItemEvent (QuitItemEnabled);
UpdateQuitItemEvent (QuitItemEnabled); UpdateStatusItemEvent (StateText);
if (UpdateStatusItemEvent != null)
UpdateStatusItemEvent (StateText);
this.animation.Stop (); this.animation.Stop ();
if (UpdateIconEvent != null) UpdateIconEvent (-1);
UpdateIconEvent (-1);
}; };
} }
@ -279,8 +261,7 @@ namespace SparkleShare {
else else
this.animation_frame_number = 0; this.animation_frame_number = 0;
if (UpdateIconEvent != null) UpdateIconEvent (this.animation_frame_number);
UpdateIconEvent (this.animation_frame_number);
}; };
} }
} }