From 2ca2c12475af90dd570a37c94537b4336951bccc Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 17 Jul 2012 15:09:57 +0200 Subject: [PATCH] controller: Code cleanups --- SparkleLib/SparkleConfig.cs | 28 +++------ SparkleLib/SparkleListenerBase.cs | 53 ++++++---------- SparkleLib/SparkleListenerTcp.cs | 19 +++--- SparkleLib/SparkleRepoBase.cs | 68 ++++++++++----------- SparkleShare/Program.cs | 27 ++++---- SparkleShare/SparkleAboutController.cs | 18 +++--- SparkleShare/SparkleBubblesController.cs | 39 +++++------- SparkleShare/SparkleControllerBase.cs | 61 ++++++++---------- SparkleShare/SparkleEventLogController.cs | 33 +++++----- SparkleShare/SparkleExtensions.cs | 2 +- SparkleShare/SparkleInvite.cs | 5 +- SparkleShare/SparkleSetupController.cs | 29 +++------ SparkleShare/SparkleStatusIconController.cs | 24 +++----- 13 files changed, 167 insertions(+), 239 deletions(-) diff --git a/SparkleLib/SparkleConfig.cs b/SparkleLib/SparkleConfig.cs index 50ea2b95..d5c1d64f 100755 --- a/SparkleLib/SparkleConfig.cs +++ b/SparkleLib/SparkleConfig.cs @@ -105,7 +105,6 @@ namespace SparkleLib { CreateInitialConfig (); } catch (XmlException) { - FileInfo file = new FileInfo (FullPath); if (file.Length == 0) { @@ -180,10 +179,10 @@ namespace SparkleLib { set { SparkleUser user = (SparkleUser) value; - XmlNode name_node = SelectSingleNode ("/sparkleshare/user/name/text()"); + XmlNode name_node = SelectSingleNode ("/sparkleshare/user/name/text()"); name_node.InnerText = user.Name; - XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()"); + XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()"); email_node.InnerText = user.Email; Save (); @@ -205,16 +204,16 @@ namespace SparkleLib { public void AddFolder (string name, string identifier, string url, string backend) { - XmlNode node_name = CreateElement ("name"); + XmlNode node_name = CreateElement ("name"); node_name.InnerText = name; - XmlNode node_identifier = CreateElement ("identifier"); + XmlNode node_identifier = CreateElement ("identifier"); node_identifier.InnerText = identifier; - XmlNode node_url = CreateElement ("url"); + XmlNode node_url = CreateElement ("url"); node_url.InnerText = url; - XmlNode node_backend = CreateElement ("backend"); + XmlNode node_backend = CreateElement ("backend"); node_backend.InnerText = backend; XmlNode node_folder = CreateNode (XmlNodeType.Element, "folder", null); @@ -365,7 +364,7 @@ namespace SparkleLib { node_root.AppendChild (node); } - SparkleHelpers.DebugInfo ("Config", "Updated " + name + ":" + content); + SparkleHelpers.DebugInfo ("Config", "Updated option " + name + ":" + content); Save (); } @@ -373,19 +372,10 @@ namespace SparkleLib { private void Save () { if (!File.Exists (FullPath)) - throw new ConfigFileNotFoundException (FullPath + " does not exist"); + throw new FileNotFoundException (FullPath + " does not exist"); Save (FullPath); - SparkleHelpers.DebugInfo ("Config", "Updated \"" + FullPath + "\""); - } - } - - - public class ConfigFileNotFoundException : Exception { - - public ConfigFileNotFoundException (string message) : base (message) - { + SparkleHelpers.DebugInfo ("Config", "Writen to '" + FullPath + "'"); } } } - diff --git a/SparkleLib/SparkleListenerBase.cs b/SparkleLib/SparkleListenerBase.cs index ac7408b4..d16a2a97 100755 --- a/SparkleLib/SparkleListenerBase.cs +++ b/SparkleLib/SparkleListenerBase.cs @@ -36,14 +36,14 @@ namespace SparkleLib { public readonly Uri Server; - public abstract void Connect (); public abstract bool IsConnected { get; } public abstract bool IsConnecting { get; } + + protected abstract void AnnounceInternal (SparkleAnnouncement announcent); protected abstract void AlsoListenToInternal (string folder_identifier); - protected List channels = new List (); @@ -52,11 +52,8 @@ namespace SparkleLib { private Dictionary> recent_announcements = new Dictionary> (); - private Dictionary queue_up = - new Dictionary (); - - private Dictionary queue_down = - new Dictionary (); + private Dictionary queue_up = new Dictionary (); + private Dictionary queue_down = new Dictionary (); private Timer reconnect_timer = new Timer { Interval = 60 * 1000, @@ -82,25 +79,20 @@ namespace SparkleLib { { if (!IsRecentAnnouncement (announcement)) { if (IsConnected) { - SparkleHelpers.DebugInfo ("Listener", - "Announcing message " + announcement.Message + " to " + - announcement.FolderIdentifier + " on " + Server); + SparkleHelpers.DebugInfo ("Listener", "Announcing message " + announcement.Message + + " to " + announcement.FolderIdentifier + " on " + Server); AnnounceInternal (announcement); AddRecentAnnouncement (announcement); } else { - SparkleHelpers.DebugInfo ("Listener", - "Can't send message to " + - Server + ". Queuing message"); - + SparkleHelpers.DebugInfo ("Listener", "Can't send message to " + Server + ". Queuing message"); this.queue_up [announcement.FolderIdentifier] = announcement; } } else { - SparkleHelpers.DebugInfo ("Listener", - "Already processed message " + announcement.Message + " to " + - announcement.FolderIdentifier + " from " + Server); + SparkleHelpers.DebugInfo ("Listener", "Already processed message " + announcement.Message + + " to " + announcement.FolderIdentifier + " from " + Server); } } @@ -108,8 +100,7 @@ namespace SparkleLib { public void AlsoListenTo (string channel) { if (!this.channels.Contains (channel) && IsConnected) { - SparkleHelpers.DebugInfo ("Listener", - "Subscribing to channel " + channel + " on " + Server); + SparkleHelpers.DebugInfo ("Listener", "Subscribing to channel " + channel + " on " + Server); this.channels.Add (channel); AlsoListenToInternal (channel); @@ -132,8 +123,7 @@ namespace SparkleLib { Connected (); 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..."); foreach (KeyValuePair item in this.queue_up) { SparkleAnnouncement announcement = item.Value; @@ -161,15 +151,13 @@ namespace SparkleLib { announcement.FolderIdentifier + " on " + Server); if (IsRecentAnnouncement (announcement)) { - SparkleHelpers.DebugInfo ("Listener", - "Ignoring previously processed message " + announcement.Message + + SparkleHelpers.DebugInfo ("Listener", "Ignoring previously processed message " + announcement.Message + " from " + announcement.FolderIdentifier + " on " + Server); return; } - SparkleHelpers.DebugInfo ("Listener", - "Processing message " + announcement.Message + " from " + + SparkleHelpers.DebugInfo ("Listener", "Processing message " + announcement.Message + " from " + announcement.FolderIdentifier + " on " + Server); AddRecentAnnouncement (announcement); @@ -188,16 +176,12 @@ namespace SparkleLib { private bool IsRecentAnnouncement (SparkleAnnouncement announcement) { - if (!this.recent_announcements - .ContainsKey (announcement.FolderIdentifier)) { - + if (!this.recent_announcements.ContainsKey (announcement.FolderIdentifier)) { return false; } else { - foreach (SparkleAnnouncement recent_announcement in - GetRecentAnnouncements (announcement.FolderIdentifier)) { - - if (recent_announcement.Message.Equals (announcement.Message)) + foreach (SparkleAnnouncement recent_announcement in GetRecentAnnouncements (announcement.FolderIdentifier)) { + if (recent_announcement.Message.Equals (recent_announcement.Message)) return true; } @@ -211,7 +195,7 @@ namespace SparkleLib { if (!this.recent_announcements.ContainsKey (folder_identifier)) this.recent_announcements [folder_identifier] = new List (); - return (List) this.recent_announcements [folder_identifier]; + return this.recent_announcements [folder_identifier]; } @@ -224,8 +208,7 @@ namespace SparkleLib { recent_announcements.Add (announcement); if (recent_announcements.Count > this.max_recent_announcements) - recent_announcements.RemoveRange (0, - (recent_announcements.Count - this.max_recent_announcements)); + recent_announcements.RemoveRange (0, recent_announcements.Count - this.max_recent_announcements); } } } diff --git a/SparkleLib/SparkleListenerTcp.cs b/SparkleLib/SparkleListenerTcp.cs index c0d76713..6f87d736 100755 --- a/SparkleLib/SparkleListenerTcp.cs +++ b/SparkleLib/SparkleListenerTcp.cs @@ -31,8 +31,7 @@ namespace SparkleLib { private DateTime last_ping = DateTime.Now; - public SparkleListenerTcp (Uri server, string folder_identifier) : - base (server, folder_identifier) + public SparkleListenerTcp (Uri server, string folder_identifier) : base (server, folder_identifier) { } @@ -179,12 +178,9 @@ namespace SparkleLib { string folder_identifier = line.Substring (0, line.IndexOf ("!")); string message = CleanMessage (line.Substring (line.IndexOf ("!") + 1)); - if (!folder_identifier.Equals ("debug") && - !String.IsNullOrEmpty (message)) { - - // We have a message! + // We have a message! + if (!folder_identifier.Equals ("debug") && !String.IsNullOrEmpty (message)) OnAnnouncement (new SparkleAnnouncement (folder_identifier, message)); - } } } }); @@ -212,8 +208,7 @@ namespace SparkleLib { protected override void AnnounceInternal (SparkleAnnouncement announcement) { - string to_send = "announce " + announcement.FolderIdentifier - + " " + announcement.Message + "\n"; + string to_send = "announce " + announcement.FolderIdentifier + " " + announcement.Message + "\n"; try { if (this.socket != null) @@ -244,9 +239,9 @@ namespace SparkleLib { private string CleanMessage (string message) { - return message.Trim () - .Replace ("\n", "") - .Replace ("\0", ""); + message = message.Replace ("\n", ""); + message = message.Replace ("\0", ""); + return message.Trim (); } } } diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index eeb84601..7248126d 100755 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -116,8 +116,11 @@ namespace SparkleLib { private string identifier; private SparkleListenerBase listener; - private TimeSpan poll_interval = PollInterval.Short; - private DateTime last_poll = DateTime.Now; + private TimeSpan poll_interval = PollInterval.Short; + private DateTime last_poll = DateTime.Now; + private DateTime progress_last_change = DateTime.Now; + private TimeSpan progress_change_interval = new TimeSpan (0, 0, 0, 1); + private Timers.Timer remote_timer = new Timers.Timer () { Interval = 5000 @@ -138,22 +141,19 @@ namespace SparkleLib { public SparkleRepoBase (string path, SparkleConfig config) { this.local_config = config; - - LocalPath = path; - Name = Path.GetFileName (LocalPath); - RemoteUrl = new Uri (this.local_config.GetUrlForFolder (Name)); - IsBuffering = false; - ServerOnline = true; + LocalPath = path; + Name = Path.GetFileName (LocalPath); + RemoteUrl = new Uri (this.local_config.GetUrlForFolder (Name)); + IsBuffering = false; + ServerOnline = true; + this.identifier = Identifier; + ChangeSets = GetChangeSets (); SyncStatusChanged += delegate (SyncStatus status) { Status = status; }; - this.identifier = Identifier; - - ChangeSets = GetChangeSets (); SparkleWatcherFactory.CreateWatcher (this); - new Thread (() => CreateListener ()).Start (); this.remote_timer.Elapsed += delegate { @@ -252,7 +252,6 @@ namespace SparkleLib { } while (IsBuffering); - this.remote_timer.Start (); } @@ -264,6 +263,25 @@ namespace SparkleLib { } + protected void OnProgressChanged (double progress_percentage, string progress_speed) + { + // Only trigger the ProgressChanged event once per second + if (DateTime.Compare (this.progress_last_change, DateTime.Now.Subtract (this.progress_change_interval)) >= 0) + return; + + if (ProgressChanged != null) { + if (progress_percentage == 100.0) + progress_percentage = 99.0; + + ProgressPercentage = progress_percentage; + ProgressSpeed = progress_speed; + this.progress_last_change = DateTime.Now; + + ProgressChanged (progress_percentage, progress_speed); + } + } + + private void SyncUpBase () { SparkleHelpers.DebugInfo ("SyncUp", Name + " | Initiated"); @@ -274,7 +292,6 @@ namespace SparkleLib { if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.SyncUp); - if (SyncUp ()) { SparkleHelpers.DebugInfo ("SyncUp", Name + " | Done"); HasUnsyncedChanges = false; @@ -442,29 +459,6 @@ namespace SparkleLib { } - private DateTime progress_last_change = DateTime.Now; - private TimeSpan progress_change_interval = new TimeSpan (0, 0, 0, 1); - - protected void OnProgressChanged (double progress_percentage, string progress_speed) - { - // Only trigger the ProgressChanged event once per second - if (DateTime.Compare (this.progress_last_change, DateTime.Now.Subtract (this.progress_change_interval)) >= 0) - return; - - if (ProgressChanged != null) { - if (progress_percentage == 100.0) - progress_percentage = 99.0; - - ProgressPercentage = progress_percentage; - ProgressSpeed = progress_speed; - - this.progress_last_change = DateTime.Now; - - ProgressChanged (progress_percentage, progress_speed); - } - } - - // Recursively gets a folder's size in bytes private double CalculateSize (DirectoryInfo parent) { diff --git a/SparkleShare/Program.cs b/SparkleShare/Program.cs index e40fb245..c4f7c093 100644 --- a/SparkleShare/Program.cs +++ b/SparkleShare/Program.cs @@ -39,19 +39,20 @@ namespace SparkleShare { public static void Main (string [] args) { if (args.Length != 0 && !args [0].Equals ("start")) { - Console.WriteLine (" "); - Console.WriteLine ("SparkleShare is a collaboration and sharing tool that is "); - Console.WriteLine ("designed to keep things simple and to stay out of your way."); - Console.WriteLine (" "); - Console.WriteLine ("Version: " + SparkleLib.SparkleBackend.Version); - Console.WriteLine ("Copyright (C) 2010 Hylke Bons"); - Console.WriteLine (" "); - Console.WriteLine ("This program comes with ABSOLUTELY NO WARRANTY."); - Console.WriteLine (" "); - Console.WriteLine ("This is free software, and you are welcome to redistribute it "); - Console.WriteLine ("under certain conditions. Please read the GNU GPLv3 for details."); - Console.WriteLine (" "); - Console.WriteLine ("Usage: sparkleshare [start|stop|restart]"); + string n = Environment.NewLine; + + Console.WriteLine (n + + "SparkleShare is a collaboration and sharing tool that is" + n + + "designed to keep things simple and to stay out of your way." + n + + n + + "Version: " + SparkleLib.SparkleBackend.Version + n + + "Copyright (C) 2010 Hylke Bons" + n + + "This program comes with ABSOLUTELY NO WARRANTY." + n + + n + + "This is free software, and you are welcome to redistribute it" + n + + "under certain conditions. Please read the GNU GPLv3 for details." + n + + n + + "Usage: sparkleshare [start|stop|restart]"); Environment.Exit (-1); } diff --git a/SparkleShare/SparkleAboutController.cs b/SparkleShare/SparkleAboutController.cs index 4c8f824c..0092fb87 100755 --- a/SparkleShare/SparkleAboutController.cs +++ b/SparkleShare/SparkleAboutController.cs @@ -99,12 +99,12 @@ namespace SparkleShare { int running_major; int running_minor; - int running_build; + int running_micro; try { - string[] running_split = running_version_string.Split ('.'); + string [] running_split = running_version_string.Split ('.'); running_major = int.Parse (running_split [0]); running_minor = int.Parse (running_split [1]); - running_build = int.Parse (running_split [2]); + running_micro = int.Parse (running_split [2]); } catch (Exception e) { throw new FormatException ("running_version_string", e); @@ -112,12 +112,12 @@ namespace SparkleShare { int latest_major; int latest_minor; - int latest_build; + int latest_micro; try { - string[] latest_split = latest_version_string.Split ('.'); + string [] latest_split = latest_version_string.Split ('.'); latest_major = int.Parse (latest_split [0]); latest_minor = int.Parse (latest_split [1]); - latest_build = int.Parse (latest_split [2]); + latest_micro = int.Parse (latest_split [2]); } catch (Exception e) { throw new FormatException ("latest_version_string", e); @@ -125,9 +125,9 @@ namespace SparkleShare { bool higher_major = latest_major > running_major; bool higher_minor = latest_major == running_major && latest_minor > running_minor; - bool higher_build = latest_major == running_major && latest_minor == running_minor && latest_build > running_build; + bool higher_micro = latest_major == running_major && latest_minor == running_minor && latest_micro > running_micro; - return higher_major || higher_minor || higher_build; + return (higher_major || higher_minor || higher_micro); } } -} \ No newline at end of file +} diff --git a/SparkleShare/SparkleBubblesController.cs b/SparkleShare/SparkleBubblesController.cs index 2b682d2a..211f2d2d 100755 --- a/SparkleShare/SparkleBubblesController.cs +++ b/SparkleShare/SparkleBubblesController.cs @@ -33,9 +33,8 @@ namespace SparkleShare { }; Program.Controller.NotificationRaised += delegate (SparkleChangeSet change_set) { - if (Program.Controller.NotificationsEnabled) - ShowBubble (change_set.User.Name, FormatMessage (change_set), - Program.Controller.GetAvatar (change_set.User.Email, 48)); + ShowBubble (change_set.User.Name, FormatMessage (change_set), + Program.Controller.GetAvatar (change_set.User.Email, 48)); }; } @@ -55,29 +54,23 @@ namespace SparkleShare { private string FormatMessage (SparkleChangeSet change_set) { - string message = ""; + string message = "added ‘{0}’"; - if (change_set.Changes [0].Type == SparkleChangeType.Deleted) - message = string.Format ("moved ‘{0}’", change_set.Changes [0].Path); - - if (change_set.Changes [0].Type == SparkleChangeType.Moved) - message = string.Format ("moved ‘{0}’", change_set.Changes [0].Path); - - if (change_set.Changes [0].Type == SparkleChangeType.Added) - message = string.Format ("added ‘{0}’", change_set.Changes [0].Path); - - if (change_set.Changes [0].Type == SparkleChangeType.Edited) - message = string.Format ("moved ‘{0}’", change_set.Changes [0].Path); - - if (change_set.Changes.Count > 0) { - string msg = string.Format ("and {0} more", change_set.Changes.Count); - message = message + " " + string.Format (msg, change_set.Changes.Count); - - } else { - message = "did something magical"; + switch (change_set.Changes [0].Type) { + case SparkleChangeType.Edited: message = "edited ‘{0}’"; break; + case SparkleChangeType.Deleted: message = "deleted ‘{0}’"; break; + case SparkleChangeType.Moved: message = "moved ‘{0}’"; break; } - return message; + if (change_set.Changes.Count == 1) { + return message = string.Format (message, change_set.Changes [0].Path); + + } else if (change_set.Changes.Count > 1) { + return string.Format (message + " and {0} more", change_set.Changes.Count - 1); + + } else { + return "did something magical"; + } } } } diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 7d5cb02e..39a8f424 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -218,7 +218,6 @@ namespace SparkleShare { // key in the user's SparkleShare folder if (File.Exists (pubkey_file_path) && !File.Exists (link_code_file_path)) File.Copy (pubkey_file_path, link_code_file_path, true /* Overwriting allowed */ ); - } SparkleKeys.ListPrivateKeys (); @@ -241,20 +240,19 @@ namespace SparkleShare { public void UIHasLoaded () { - if (FirstRun) + if (FirstRun) { ShowSetupWindow (PageType.Setup); - else - new Thread (() => PopulateRepositories ()).Start (); - } + } else { + new Thread (() => { + CheckRepositories (); + RepositoriesLoaded = true; - private void PopulateRepositories () - { - CheckRepositories (); - RepositoriesLoaded = true; + if (FolderListChanged != null) + FolderListChanged (); - if (FolderListChanged != null) - FolderListChanged (); + }).Start (); + } } @@ -304,7 +302,7 @@ namespace SparkleShare { }; repo.NewChangeSet += delegate (SparkleChangeSet change_set) { - if (NotificationRaised != null) + if (NotificationsEnabled && NotificationRaised != null) NotificationRaised (change_set); }; @@ -406,17 +404,14 @@ namespace SparkleShare { } } - if (has_syncing_repos) { - if (OnSyncing != null) - OnSyncing (); + if (has_syncing_repos && OnSyncing != null) { + OnSyncing (); - } else if (has_unsynced_repos) { - if (OnError != null) - OnError (); + } else if (has_unsynced_repos && OnError != null) { + OnError (); - } else { - if (OnIdle != null) - OnIdle (); + } else if (OnIdle != null) { + OnIdle (); } } @@ -441,6 +436,7 @@ namespace SparkleShare { } } + public void HandleInvite (FileSystemEventArgs args) { if (this.fetcher != null && @@ -458,22 +454,21 @@ namespace SparkleShare { // fully downloaded yet, so we try to read it several times int tries = 0; while (!invite.IsValid) { - Thread.Sleep (1 * 250); + Thread.Sleep (250); invite = new SparkleInvite (args.FullPath); tries++; - if (tries > 20) + + if (tries > 20) { + if (AlertNotificationRaised != null) + AlertNotificationRaised ("Oh noes!", "This invite seems screwed up..."); + break; + } } - if (invite.IsValid) { + if (invite.IsValid) InviteReceived (invite); - } else { - if (AlertNotificationRaised != null) - AlertNotificationRaised ("Oh noes!", - "This invite seems screwed up..."); - } - File.Delete (args.FullPath); } } @@ -681,11 +676,7 @@ namespace SparkleShare { public void ToggleNotifications () { bool notifications_enabled = this.config.GetConfigOption ("notifications").Equals (bool.TrueString); - - if (notifications_enabled) - this.config.SetConfigOption ("notifications", bool.FalseString); - else - this.config.SetConfigOption ("notifications", bool.TrueString); + this.config.SetConfigOption ("notifications", (!notifications_enabled).ToString ()); } diff --git a/SparkleShare/SparkleEventLogController.cs b/SparkleShare/SparkleEventLogController.cs index 796d80ec..649bd1cc 100755 --- a/SparkleShare/SparkleEventLogController.cs +++ b/SparkleShare/SparkleEventLogController.cs @@ -111,9 +111,10 @@ namespace SparkleShare { double size = 0; foreach (SparkleRepoBase repo in Program.Controller.Repositories) { - if (this.selected_folder == null) + if (this.selected_folder == null) { size += repo.Size; - else if (this.selected_folder.Equals (repo.Name)) { + + } else if (this.selected_folder.Equals (repo.Name)) { if (repo.Size == 0) return "???"; else @@ -133,9 +134,10 @@ namespace SparkleShare { double size = 0; foreach (SparkleRepoBase repo in Program.Controller.Repositories) { - if (this.selected_folder == null) + if (this.selected_folder == null) { size += repo.HistorySize; - else if (this.selected_folder.Equals (repo.Name)) { + + } else if (this.selected_folder.Equals (repo.Name)) { if (repo.HistorySize == 0) return "???"; else @@ -178,11 +180,8 @@ namespace SparkleShare { }; 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; - } if (UpdateChooserEvent != null) UpdateChooserEvent (Folders); @@ -325,8 +324,10 @@ namespace SparkleShare { string timestamp = change_set.Timestamp.ToString ("H:mm"); if (!change_set.FirstTimestamp.Equals (new DateTime ()) && - !change_set.Timestamp.ToString ("H:mm").Equals (change_set.FirstTimestamp.ToString ("H:mm"))) + !change_set.Timestamp.ToString ("H:mm").Equals (change_set.FirstTimestamp.ToString ("H:mm"))) { + timestamp = change_set.FirstTimestamp.ToString ("H:mm") + " – " + timestamp; + } event_entries += event_entry_html.Replace ("", event_entry) .Replace ("", change_set.User.Name) @@ -345,16 +346,18 @@ namespace SparkleShare { today.Year == activity_day.Date.Year) { day_entry = day_entry_html.Replace ("", - "" - + "Today" + ""); + "" + "Today" + + ""); } else if (yesterday.Day == activity_day.Date.Day && yesterday.Month == activity_day.Date.Month && yesterday.Year == activity_day.Date.Year) { day_entry = day_entry_html.Replace ("", - "" - + "Yesterday" + ""); + "" + + "Yesterday" + + ""); } else { if (activity_day.Date.Year != DateTime.Now.Year) { @@ -372,8 +375,8 @@ namespace SparkleShare { int midnight = (int) (DateTime.Today.AddDays (1) - new DateTime (1970, 1, 1)).TotalSeconds; - string html = event_log_html.Replace ("", event_log) - .Replace ("", midnight.ToString ()); + string html = event_log_html.Replace ("", event_log); + html = html.Replace ("", midnight.ToString ()); return html; } diff --git a/SparkleShare/SparkleExtensions.cs b/SparkleShare/SparkleExtensions.cs index 348835b9..2ae86606 100644 --- a/SparkleShare/SparkleExtensions.cs +++ b/SparkleShare/SparkleExtensions.cs @@ -22,7 +22,7 @@ namespace SparkleShare { public static class Extensions { - public static string Combine (this String [] parts) + public static string Combine (this string [] parts) { string new_path = ""; diff --git a/SparkleShare/SparkleInvite.cs b/SparkleShare/SparkleInvite.cs index 0c287c4f..ee4ff3f6 100644 --- a/SparkleShare/SparkleInvite.cs +++ b/SparkleShare/SparkleInvite.cs @@ -36,8 +36,7 @@ namespace SparkleShare { public bool IsValid { get { - return (!string.IsNullOrEmpty (Address) && - !string.IsNullOrEmpty (RemotePath)); + return (!string.IsNullOrEmpty (Address) && !string.IsNullOrEmpty (RemotePath)); } } @@ -101,7 +100,6 @@ namespace SparkleShare { WebResponse response = request.GetResponse (); response.Close (); - if ((response as HttpWebResponse).StatusCode == HttpStatusCode.OK) { SparkleHelpers.DebugInfo ("Invite", "Uploaded public key to " + AcceptUrl); return true; @@ -113,7 +111,6 @@ namespace SparkleShare { } catch (WebException e) { SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message); - return false; } } diff --git a/SparkleShare/SparkleSetupController.cs b/SparkleShare/SparkleSetupController.cs index 7f89a0dc..0f832d4f 100755 --- a/SparkleShare/SparkleSetupController.cs +++ b/SparkleShare/SparkleSetupController.cs @@ -164,7 +164,6 @@ namespace SparkleShare { SelectedPlugin = Plugins [0]; - Program.Controller.InviteReceived += delegate (SparkleInvite invite) { PendingInvite = invite; @@ -175,7 +174,6 @@ namespace SparkleShare { ShowWindowEvent (); }; - Program.Controller.ShowSetupWindowEvent += delegate (PageType page_type) { if (page_type == PageType.CryptoSetup || page_type == PageType.CryptoPassword) { if (ChangePageEvent != null) @@ -263,8 +261,7 @@ namespace SparkleShare { full_name = full_name.Trim (); email = email.Trim (); - bool fields_valid = (!string.IsNullOrEmpty (full_name) && - IsValidEmail (email)); + bool fields_valid = (!string.IsNullOrEmpty (full_name) && IsValidEmail (email)); if (UpdateSetupContinueButtonEvent != null) UpdateSetupContinueButtonEvent (fields_valid); @@ -544,13 +541,12 @@ namespace SparkleShare { { Program.Controller.StopFetcher (); - if (ChangePageEvent == null) - return; - - if (PendingInvite != null) - ChangePageEvent (PageType.Invite, null); - else - ChangePageEvent (PageType.Add, null); + if (ChangePageEvent != null) { + if (PendingInvite != null) + ChangePageEvent (PageType.Invite, null); + else + ChangePageEvent (PageType.Add, null); + } } @@ -610,9 +606,7 @@ namespace SparkleShare { public void OpenFolderClicked () { - Program.Controller.OpenSparkleShareFolder ( - Path.GetFileName (PreviousPath)); - + Program.Controller.OpenSparkleShareFolder (Path.GetFileName (PreviousPath)); FinishPageCompleted (); } @@ -629,17 +623,12 @@ namespace SparkleShare { if (HideWindowEvent != null) HideWindowEvent (); - - //Program.Controller.UpdateState (); TODO: still relevant? } private bool IsValidEmail (string email) { - Regex regex = new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", - RegexOptions.IgnoreCase); - - return regex.IsMatch (email); + return new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase).IsMatch (email); } } } diff --git a/SparkleShare/SparkleStatusIconController.cs b/SparkleShare/SparkleStatusIconController.cs index 7e7f4259..0aede2cd 100755 --- a/SparkleShare/SparkleStatusIconController.cs +++ b/SparkleShare/SparkleStatusIconController.cs @@ -55,16 +55,16 @@ namespace SparkleShare { public string StateText = "Welcome to SparkleShare!"; - public readonly int MenuOverFlowThreshold = 9; + public readonly int MenuOverflowThreshold = 9; public readonly int MinSubmenuOverflowCount = 3; public string [] Folders { get { - int overflow_count = (Program.Controller.Folders.Count - MenuOverFlowThreshold); + int overflow_count = (Program.Controller.Folders.Count - MenuOverflowThreshold); if (overflow_count >= MinSubmenuOverflowCount) - return Program.Controller.Folders.GetRange (0, MenuOverFlowThreshold).ToArray (); + return Program.Controller.Folders.GetRange (0, MenuOverflowThreshold).ToArray (); else return Program.Controller.Folders.ToArray (); } @@ -72,16 +72,15 @@ namespace SparkleShare { public string [] OverflowFolders { get { - int overflow_count = (Program.Controller.Folders.Count - MenuOverFlowThreshold); + int overflow_count = (Program.Controller.Folders.Count - MenuOverflowThreshold); if (overflow_count >= MinSubmenuOverflowCount) - return Program.Controller.Folders.GetRange (MenuOverFlowThreshold, overflow_count).ToArray (); + return Program.Controller.Folders.GetRange (MenuOverflowThreshold, overflow_count).ToArray (); else return new string [0]; } } - public string FolderSize { get { double size = 0; @@ -110,21 +109,17 @@ namespace SparkleShare { public bool QuitItemEnabled { get { - return (CurrentState != IconState.Syncing && - CurrentState != IconState.SyncingDown && - CurrentState != IconState.SyncingUp); + return (CurrentState == IconState.Idle || CurrentState == IconState.Error); } } public bool OpenRecentEventsItemEnabled { get { - return (Program.Controller.RepositoriesLoaded && - Program.Controller.Folders.Count > 0); + return (Program.Controller.RepositoriesLoaded && Program.Controller.Folders.Count > 0); } } - private Timer animation; private int animation_frame_number; @@ -254,10 +249,7 @@ namespace SparkleShare { public void OpenRecentEventsClicked () { - new Threading.Thread (() => { - Program.Controller.ShowEventLogWindow (); - - }).Start (); + new Threading.Thread (() => Program.Controller.ShowEventLogWindow ()).Start (); }