From 9800bcf421fc8dbda2e5f1b538c886781f12ce08 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 29 Apr 2012 15:19:36 +0100 Subject: [PATCH] Cache changesets in the backend --- SparkleLib/Git/SparkleRepoGit.cs | 18 +++-- SparkleLib/SparkleChangeSet.cs | 2 +- SparkleLib/SparkleRepoBase.cs | 23 +++--- SparkleShare/Linux/SparkleStatusIcon.cs | 20 ++++-- SparkleShare/Mac/SparkleBubbles.cs | 14 ++-- SparkleShare/Mac/SparkleStatusIcon.cs | 11 ++- SparkleShare/SparkleControllerBase.cs | 80 +++++++++++---------- SparkleShare/SparkleEventLogController.cs | 2 +- SparkleShare/SparkleStatusIconController.cs | 14 ++++ SparkleShare/Windows/SparkleStatusIcon.cs | 23 ++++-- 10 files changed, 130 insertions(+), 77 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 1a2194df..2b1b2e6f 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -161,7 +161,7 @@ namespace SparkleLib.Git { { get { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Checking for remote changes..."); - SparkleGit git = new SparkleGit (LocalPath, "ls-remote \"" + Url + "\" master"); + SparkleGit git = new SparkleGit (LocalPath, "ls-remote \"" + RemoteUrl + "\" master"); git.Start (); git.WaitForExit (); @@ -196,7 +196,7 @@ namespace SparkleLib.Git { SparkleGit git = new SparkleGit (LocalPath, "push --progress " + // Redirects progress stats to standarderror - "\"" + Url + "\" master"); + "\"" + RemoteUrl + "\" master"); git.StartInfo.RedirectStandardError = true; git.Start (); @@ -253,6 +253,7 @@ namespace SparkleLib.Git { git.WaitForExit (); UpdateSizes (); + ChangeSets = GetChangeSets (); if (git.ExitCode == 0) return true; @@ -263,7 +264,7 @@ namespace SparkleLib.Git { public override bool SyncDown () { - SparkleGit git = new SparkleGit (LocalPath, "fetch --progress \"" + Url + "\" master"); + SparkleGit git = new SparkleGit (LocalPath, "fetch --progress \"" + RemoteUrl + "\" master"); git.StartInfo.RedirectStandardError = true; git.Start (); @@ -322,10 +323,13 @@ namespace SparkleLib.Git { Path.Combine (LocalPath, ".sparkleshare"), FileAttributes.Hidden ); - + + ChangeSets = GetChangeSets (); + return true; } else { + ChangeSets = GetChangeSets (); return false; } } @@ -450,7 +454,7 @@ namespace SparkleLib.Git { private void ResolveConflict () { - // This is al list of conflict status codes that Git uses, their + // This is a list of conflict status codes that Git uses, their // meaning, and how SparkleShare should handle them. // // DD unmerged, both deleted -> Do nothing @@ -558,7 +562,7 @@ namespace SparkleLib.Git { // Returns a list of the latest change sets - public override List GetChangeSets (int count) + public override List GetChangeSets (int count) { if (count < 1) count = 30; @@ -637,7 +641,7 @@ namespace SparkleLib.Git { change_set.Revision = match.Groups [1].Value; change_set.User = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value); change_set.IsMagical = is_merge_commit; - change_set.Url = Url; + change_set.RemoteUrl = RemoteUrl; change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value), int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value), diff --git a/SparkleLib/SparkleChangeSet.cs b/SparkleLib/SparkleChangeSet.cs index 05ca7a0c..6f3934a1 100755 --- a/SparkleLib/SparkleChangeSet.cs +++ b/SparkleLib/SparkleChangeSet.cs @@ -30,7 +30,7 @@ namespace SparkleLib { public DateTime Timestamp; public DateTime FirstTimestamp; public bool IsMagical = false; - public Uri Url; + public Uri RemoteUrl; public List Added = new List (); public List Deleted = new List (); diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 968e744e..eec7d3f6 100755 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -74,7 +74,8 @@ namespace SparkleLib { public readonly string LocalPath; public readonly string Name; - public readonly Uri Url; + public readonly Uri RemoteUrl; + public List ChangeSets { get; protected set; } public abstract string ComputeIdentifier (); public abstract string CurrentRevision { get; } @@ -88,6 +89,9 @@ namespace SparkleLib { public abstract bool SyncDown (); public abstract List GetChangeSets (int count); + public List GetChangeSets () { + return GetChangeSets (30); + } public bool ServerOnline { get { @@ -157,7 +161,7 @@ namespace SparkleLib { { LocalPath = path; Name = Path.GetFileName (LocalPath); - Url = new Uri (SparkleConfig.DefaultConfig.GetUrlForFolder (Name)); + RemoteUrl = new Uri (SparkleConfig.DefaultConfig.GetUrlForFolder (Name)); this.poll_interval = this.short_interval; @@ -169,7 +173,8 @@ namespace SparkleLib { if (CurrentRevision == null) CreateInitialChangeSet (); - + + ChangeSets = GetChangeSets (); CreateWatcher (); CreateListener (); @@ -347,14 +352,12 @@ namespace SparkleLib { this.server_online = true; if (!pre_sync_revision.Equals (CurrentRevision)) { - List change_sets = GetChangeSets (1); - - if (change_sets != null && - change_sets.Count > 0 && - !change_sets [0].Added.Contains (".sparkleshare")) { + if (ChangeSets != null && + ChangeSets.Count > 0 && + !ChangeSets [0].Added.Contains (".sparkleshare")) { if (NewChangeSet != null) - NewChangeSet (change_sets [0]); + NewChangeSet (ChangeSets [0]); } } @@ -541,7 +544,7 @@ namespace SparkleLib { "Congratulations, you've successfully created a SparkleShare repository!" + n + "" + n + "Any files you add or change in this folder will be automatically synced to " + n + - Url + " and everyone connected to it." + n + + RemoteUrl + " and everyone connected to it." + n + "" + n + "SparkleShare is a Free and Open Source software program that helps people " + n + "collaborate and share files. If you like what we do, please consider a small " + n + diff --git a/SparkleShare/Linux/SparkleStatusIcon.cs b/SparkleShare/Linux/SparkleStatusIcon.cs index 086538a4..cd11a1e8 100644 --- a/SparkleShare/Linux/SparkleStatusIcon.cs +++ b/SparkleShare/Linux/SparkleStatusIcon.cs @@ -32,6 +32,7 @@ namespace SparkleShare { private Gdk.Pixbuf [] animation_frames; private Menu menu; + private MenuItem recent_events_item; private MenuItem quit_item; private MenuItem state_item; @@ -99,13 +100,20 @@ namespace SparkleShare { }); }; - Controller.UpdateQuitItemEvent += delegate (bool quit_item_enabled) { + Controller.UpdateQuitItemEvent += delegate (bool item_enabled) { Application.Invoke (delegate { - this.quit_item.Sensitive = quit_item_enabled; + this.quit_item.Sensitive = item_enabled; this.quit_item.ShowAll (); }); }; + Controller.UpdateOpenRecentEventsItemEvent += delegate (bool item_enabled) { + Application.Invoke (delegate { + this.recent_events_item.Sensitive = item_enabled; + this.recent_events_item.ShowAll (); + }); + }; + Controller.UpdateMenuEvent += delegate (IconState state) { Application.Invoke (delegate { CreateMenu (); @@ -199,15 +207,15 @@ namespace SparkleShare { this.menu.Add (sync_item); - MenuItem recent_events_item = new MenuItem (_("View Recent Changes…")); + this.recent_events_item = new MenuItem (_("View Recent Changes…")); - recent_events_item.Sensitive = (Controller.Folders.Length > 0); + this.recent_events_item.Sensitive = Controller.OpenRecentEventsItemEnabled; - recent_events_item.Activated += delegate { + this.recent_events_item.Activated += delegate { Controller.OpenRecentEventsClicked (); }; - this.menu.Add (recent_events_item); + this.menu.Add (this.recent_events_item); this.menu.Add (new SeparatorMenuItem ()); CheckMenuItem notify_item = new CheckMenuItem (_("Notifications")) { diff --git a/SparkleShare/Mac/SparkleBubbles.cs b/SparkleShare/Mac/SparkleBubbles.cs index a2a5ff11..ae5c0630 100755 --- a/SparkleShare/Mac/SparkleBubbles.cs +++ b/SparkleShare/Mac/SparkleBubbles.cs @@ -33,13 +33,6 @@ namespace SparkleShare { { Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) { InvokeOnMainThread (delegate { - if (!GrowlApplicationBridge.IsGrowlRunning ()) { - NSApplication.SharedApplication.RequestUserAttention ( - NSRequestUserAttentionType.InformationalRequest); - - return; - } - if (NSApplication.SharedApplication.DockTile.BadgeLabel == null) { NSApplication.SharedApplication.DockTile.BadgeLabel = "1"; @@ -48,6 +41,13 @@ namespace SparkleShare { NSApplication.SharedApplication.DockTile.BadgeLabel = (events + 1).ToString (); } + if (!GrowlApplicationBridge.IsGrowlRunning ()) { + NSApplication.SharedApplication.RequestUserAttention ( + NSRequestUserAttentionType.InformationalRequest); + + return; + } + if (image_path != null) { NSData image_data = NSData.FromFile (image_path); GrowlApplicationBridge.Notify (title, subtext, diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index 13070ade..831867e5 100755 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -135,6 +135,15 @@ namespace SparkleShare { }); } }; + + Controller.UpdateOpenRecentEventsItemEvent += delegate (bool events_item_enabled) { + using (var a = new NSAutoreleasePool ()) + { + InvokeOnMainThread (delegate { + this.recent_events_item.Enabled = events_item_enabled; + }); + } + }; } @@ -173,7 +182,7 @@ namespace SparkleShare { this.recent_events_item = new NSMenuItem () { Title = "View Recent Changes…", - Enabled = (Controller.Folders.Length > 0) + Enabled = Controller.OpenRecentEventsItemEnabled }; if (Controller.Folders.Length > 0) { diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index aebe6241..3c3b315a 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -43,6 +43,8 @@ namespace SparkleShare { } } + public bool RepositoriesLoaded { get; private set;} + public List repositories = new List (); public readonly string SparklePath = SparkleConfig.DefaultConfig.FoldersPath; @@ -220,6 +222,7 @@ namespace SparkleShare { RemoveRepository (folder_path); } } + if (FolderListChanged != null) FolderListChanged (); } @@ -304,7 +307,7 @@ namespace SparkleShare { List list = new List (); foreach (SparkleRepoBase repo in Repositories) { - List change_sets = repo.GetChangeSets (30); + List change_sets = repo.ChangeSets; if (change_sets != null) list.AddRange (change_sets); @@ -328,11 +331,12 @@ namespace SparkleShare { return GetLog (); string path = new SparkleFolder (name).FullPath; - int log_size = 50; - foreach (SparkleRepoBase repo in Repositories) { - if (repo.LocalPath.Equals (path)) - return repo.GetChangeSets (log_size); + lock (this.repo_lock) { + foreach (SparkleRepoBase repo in Repositories) { + if (repo.LocalPath.Equals (path)) + return repo.ChangeSets; + } } return null; @@ -360,9 +364,9 @@ namespace SparkleShare { bool change_set_inserted = false; foreach (ActivityDay stored_activity_day in activity_days) { - if (stored_activity_day.DateTime.Year == change_set.Timestamp.Year && - stored_activity_day.DateTime.Month == change_set.Timestamp.Month && - stored_activity_day.DateTime.Day == change_set.Timestamp.Day) { + if (stored_activity_day.Date.Year == change_set.Timestamp.Year && + stored_activity_day.Date.Month == change_set.Timestamp.Month && + stored_activity_day.Date.Day == change_set.Timestamp.Day) { bool squash = false; foreach (SparkleChangeSet existing_set in stored_activity_day) { @@ -492,7 +496,7 @@ namespace SparkleShare { .Replace ("", change_set_avatar) .Replace ("", timestamp) .Replace ("", change_set.Folder.Name) - .Replace ("", change_set.Url.ToString ()) + .Replace ("", change_set.RemoteUrl.ToString ()) .Replace ("", change_set.Revision); } @@ -500,34 +504,34 @@ namespace SparkleShare { DateTime today = DateTime.Now; DateTime yesterday = DateTime.Now.AddDays (-1); - if (today.Day == activity_day.DateTime.Day && - today.Month == activity_day.DateTime.Month && - today.Year == activity_day.DateTime.Year) { + if (today.Day == activity_day.Date.Day && + today.Month == activity_day.Date.Month && + today.Year == activity_day.Date.Year) { day_entry = day_entry_html.Replace ("", - "" + "" + _("Today") + ""); - } else if (yesterday.Day == activity_day.DateTime.Day && - yesterday.Month == activity_day.DateTime.Month && - yesterday.Year == activity_day.DateTime.Year) { + } 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") + ""); } else { - if (activity_day.DateTime.Year != DateTime.Now.Year) { + if (activity_day.Date.Year != DateTime.Now.Year) { // TRANSLATORS: This is the date in the event logs day_entry = day_entry_html.Replace ("", - activity_day.DateTime.ToString (_("dddd, MMMM d, yyyy"))); + activity_day.Date.ToString (_("dddd, MMMM d, yyyy"))); } else { // TRANSLATORS: This is the date in the event logs, without the year day_entry = day_entry_html.Replace ("", - activity_day.DateTime.ToString (_("dddd, MMMM d"))); + activity_day.Date.ToString (_("dddd, MMMM d"))); } } @@ -638,9 +642,9 @@ namespace SparkleShare { }; - lock (this.repo_lock) { + //lock (this.repo_lock) { this.repositories.Add (repo); - } + //} repo.Initialize (); } @@ -674,15 +678,19 @@ namespace SparkleShare { // folders in the SparkleShare folder private void PopulateRepositories () { - foreach (string folder_name in SparkleConfig.DefaultConfig.Folders) { - string folder_path = new SparkleFolder (folder_name).FullPath; + lock (this.repo_lock) { + foreach (string folder_name in SparkleConfig.DefaultConfig.Folders) { + string folder_path = new SparkleFolder (folder_name).FullPath; - if (Directory.Exists (folder_path)) - AddRepository (folder_path); - else - SparkleConfig.DefaultConfig.RemoveFolder (folder_name); + if (Directory.Exists (folder_path)) + AddRepository (folder_path); + else + SparkleConfig.DefaultConfig.RemoveFolder (folder_name); + } } + RepositoriesLoaded = true; + if (FolderListChanged != null) FolderListChanged (); } @@ -1056,7 +1064,9 @@ namespace SparkleShare { } TODO */ - AddRepository (target_folder_path); + lock (this.repo_lock) { + AddRepository (target_folder_path); + } if (FolderFetched != null) FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ()); @@ -1111,11 +1121,8 @@ namespace SparkleShare { private string FormatBreadCrumbs (string path_root, string path) { - path_root = path_root.Replace ("/", - Path.DirectorySeparatorChar.ToString ()); - - path = path.Replace ("/", - Path.DirectorySeparatorChar.ToString ()); + path_root = path_root.Replace ("/", Path.DirectorySeparatorChar.ToString ()); + path = path.Replace ("/", Path.DirectorySeparatorChar.ToString ()); string link = ""; string [] crumbs = path.Split (Path.DirectorySeparatorChar); @@ -1158,12 +1165,11 @@ namespace SparkleShare { // All change sets that happened on a day public class ActivityDay : List { - public DateTime DateTime; + public DateTime Date; public ActivityDay (DateTime date_time) { - DateTime = date_time; - DateTime = new DateTime (DateTime.Year, DateTime.Month, DateTime.Day); + Date = new DateTime (date_time.Year, date_time.Month, date_time.Day); } } } diff --git a/SparkleShare/SparkleEventLogController.cs b/SparkleShare/SparkleEventLogController.cs index 43ff8927..32eb985b 100755 --- a/SparkleShare/SparkleEventLogController.cs +++ b/SparkleShare/SparkleEventLogController.cs @@ -72,7 +72,7 @@ namespace SparkleShare { // A short delay is less annoying than // a flashing window - int delay = 1000; + int delay = 500; if (watch.ElapsedMilliseconds < delay) Thread.Sleep (delay - (int) watch.ElapsedMilliseconds); diff --git a/SparkleShare/SparkleStatusIconController.cs b/SparkleShare/SparkleStatusIconController.cs index 9f726d99..41eec601 100755 --- a/SparkleShare/SparkleStatusIconController.cs +++ b/SparkleShare/SparkleStatusIconController.cs @@ -46,6 +46,9 @@ namespace SparkleShare { public event UpdateQuitItemEventHandler UpdateQuitItemEvent; public delegate void UpdateQuitItemEventHandler (bool quit_item_enabled); + public event UpdateOpenRecentEventsItemEventHandler UpdateOpenRecentEventsItemEvent; + public delegate void UpdateOpenRecentEventsItemEventHandler (bool open_recent_events_item_enabled); + public IconState CurrentState = IconState.Idle; public string StateText = "Welcome to SparkleShare!"; @@ -111,6 +114,14 @@ namespace SparkleShare { } } + public bool OpenRecentEventsItemEnabled { + get { + return (Program.Controller.RepositoriesLoaded && + Program.Controller.Folders.Count > 0); + } + } + + private Timer animation; private int animation_frame_number; @@ -133,6 +144,9 @@ namespace SparkleShare { if (UpdateStatusItemEvent != null) UpdateStatusItemEvent (StateText); + if (UpdateOpenRecentEventsItemEvent != null) + UpdateOpenRecentEventsItemEvent (OpenRecentEventsItemEnabled); + if (UpdateMenuEvent != null) UpdateMenuEvent (CurrentState); }; diff --git a/SparkleShare/Windows/SparkleStatusIcon.cs b/SparkleShare/Windows/SparkleStatusIcon.cs index c6bc5845..3b28e5f7 100644 --- a/SparkleShare/Windows/SparkleStatusIcon.cs +++ b/SparkleShare/Windows/SparkleStatusIcon.cs @@ -37,7 +37,9 @@ namespace SparkleShare { private Drawing.Bitmap error_icon; private ContextMenu context_menu; - + + + private SparkleMenuItem log_item; private SparkleMenuItem state_item; private SparkleMenuItem exit_item; @@ -84,12 +86,19 @@ namespace SparkleShare { }); }; - Controller.UpdateQuitItemEvent += delegate (bool exit_item_enabled) { + Controller.UpdateQuitItemEvent += delegate (bool item_enabled) { Dispatcher.Invoke ((Action) delegate { - this.exit_item.IsEnabled = exit_item_enabled; + this.exit_item.IsEnabled = item_enabled; this.exit_item.UpdateLayout (); }); }; + + Controller.UpdatOpenRecentEventsItemEvent += delegate (bool item_enabled) { + Dispatcher.Invoke ((Action) delegate { + this.log_item.IsEnabled = item_enabled; + this.log_item.UpdateLayout (); + }); + }; } @@ -127,12 +136,12 @@ namespace SparkleShare { Controller.AddHostedProjectClicked (); }; - SparkleMenuItem log_item = new SparkleMenuItem () { + this.log_item = new SparkleMenuItem () { Header = "View recent changes…", - IsEnabled = (Program.Controller.Folders.Count > 0) + IsEnabled = Controller.OpenRecentEventsItemEnabled; }; - log_item.Click += delegate { + this.log_item.Click += delegate { Controller.OpenRecentEventsClicked (); }; @@ -246,7 +255,7 @@ namespace SparkleShare { this.context_menu.Items.Add (new Separator ()); this.context_menu.Items.Add (add_item); - this.context_menu.Items.Add (log_item); + this.context_menu.Items.Add (this.log_item); this.context_menu.Items.Add (new Separator ()); this.context_menu.Items.Add (notify_item); this.context_menu.Items.Add (new Separator ());