diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 78c6218b..d8b73137 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -19,8 +19,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Security.Cryptography; -using System.Text; using System.Text.RegularExpressions; using System.Xml; @@ -122,8 +120,6 @@ namespace SparkleLib { return true; } else { - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching notes"); - SyncDown (); return false; } } @@ -386,7 +382,7 @@ namespace SparkleLib { List change_sets = new List (); - SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso --show-notes=*"); + SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso"); Console.OutputEncoding = System.Text.Encoding.Unicode; git_log.Start (); @@ -448,7 +444,6 @@ namespace SparkleLib { change_set.UserName = match.Groups [2].Value; change_set.UserEmail = match.Groups [3].Value; change_set.IsMerge = is_merge_commit; - change_set.SupportsNotes = true; change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value), int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value), @@ -471,7 +466,7 @@ namespace SparkleLib { string file_path = entry_line.Substring (39); string to_file_path; - if (change_type.Equals ("A")) { + if (change_type.Equals ("A") && !file_path.Contains (".notes")) { change_set.Added.Add (file_path); } else if (change_type.Equals ("M")) { @@ -488,30 +483,16 @@ namespace SparkleLib { change_set.MovedFrom.Add (file_path); change_set.MovedTo.Add (to_file_path); } - - } else if (entry_line.StartsWith (" ")) { - - Regex regex_notes = new Regex (@"(.+).*" + - "(.+).*" + - "([0-9]+).*" + - "(.+)", RegexOptions.Compiled); - - Match match_notes = regex_notes.Match (entry_line); - - if (match_notes.Success) { - SparkleNote note = new SparkleNote () { - UserName = match_notes.Groups [1].Value, - UserEmail = match_notes.Groups [2].Value, - Timestamp = new DateTime (1970, 1, 1).AddSeconds (int.Parse (match_notes.Groups [3].Value)), - Body = match_notes.Groups [4].Value - }; - - change_set.Notes.Add (note); - } } } - change_sets.Add (change_set); + if ((change_set.Added.Count + + change_set.Edited.Count + + change_set.Deleted.Count) > 0) { + + change_set.Notes.AddRange (GetNotes (change_set.Revision)); + change_sets.Add (change_set); + } } } @@ -587,59 +568,6 @@ namespace SparkleLib { } - public override void AddNote (string revision, string note) - { - string url = SparkleConfig.DefaultConfig.GetUrlForFolder (Name); - - if (url.StartsWith ("git") || url.StartsWith ("http")) - return; - - int timestamp = (int) (DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds; - - // Create the note in one line for easier merging - note = "" + - " " + - " " + SparkleConfig.DefaultConfig.UserName + "" + - " " + SparkleConfig.DefaultConfig.UserEmail + "" + - " " + - " " + timestamp + "" + - " " + note + "" + - ""; - - string note_namespace = SHA1 (timestamp.ToString () + note); - SparkleGit git_notes = new SparkleGit (LocalPath, - "notes --ref=" + note_namespace + " append -m \"" + note + "\" " + revision); - git_notes.Start (); - git_notes.WaitForExit (); - - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Added note to " + revision); - SyncUpNotes (); - } - - - public override void SyncUpNotes () - { - while (Status != SyncStatus.Idle) { - System.Threading.Thread.Sleep (5 * 20); - } - - SparkleGit git_push = new SparkleGit (LocalPath, "push origin refs/notes/*"); - git_push.Start (); - git_push.WaitForExit (); - - if (git_push.ExitCode == 0) { - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Notes pushed"); - - } else { - HasUnsyncedChanges = true; - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing notes failed, trying again later"); - } - - SparkleAnnouncement announcement = new SparkleAnnouncement (Identifier, SHA1 (DateTime.Now.ToString ())); - base.listener.Announce (announcement); - } - - public override bool UsesNotificationCenter { get { @@ -654,15 +582,5 @@ namespace SparkleLib { base.CreateInitialChangeSet (); SyncUp (); } - - - // Creates a SHA-1 hash of input - private string SHA1 (string s) - { - SHA1 sha1 = new SHA1CryptoServiceProvider (); - Byte[] bytes = ASCIIEncoding.Default.GetBytes (s); - Byte[] encoded_bytes = sha1.ComputeHash (bytes); - return BitConverter.ToString (encoded_bytes).ToLower ().Replace ("-", ""); - } } } diff --git a/SparkleLib/SparkleChangeSet.cs b/SparkleLib/SparkleChangeSet.cs index c0ddbf48..5adfa4dd 100644 --- a/SparkleLib/SparkleChangeSet.cs +++ b/SparkleLib/SparkleChangeSet.cs @@ -28,7 +28,6 @@ namespace SparkleLib { public string Folder; public string Revision; public DateTime Timestamp; - public bool SupportsNotes = false; public bool IsMerge = false; public List Added = new List (); @@ -38,7 +37,40 @@ namespace SparkleLib { public List MovedTo = new List (); public List Notes = new List (); - } + + public string RelativeTimestamp { + get { + TimeSpan time_span = DateTime.Now - Timestamp; + + if (time_span <= TimeSpan.FromSeconds (60)) + return "just now"; + + if (time_span <= TimeSpan.FromMinutes (60)) + return time_span.Minutes > 1 + ? time_span.Minutes + " minutes ago" + : "a minute ago"; + + if (time_span <= TimeSpan.FromHours (24)) + return time_span.Hours > 1 + ? time_span.Hours + " hours ago" + : "an hour ago"; + + if (time_span <= TimeSpan.FromDays (30)) + return time_span.Days > 1 + ? time_span.Days + " days ago" + : "a day ago"; + + if (time_span <= TimeSpan.FromDays (365)) + return time_span.Days > 30 + ? (time_span.Days / 30) + " months ago" + : "a month ago"; + + return time_span.Days > 365 + ? (time_span.Days / 365) + " years ago" + : "a year ago"; + } + } + } public class SparkleNote { diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 056b4cb3..e313faa2 100644 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -18,6 +18,8 @@ using System; using System.Collections.Generic; using System.IO; +using System.Security.Cryptography; +using System.Text; using System.Text.RegularExpressions; using System.Timers; using System.Xml; @@ -109,10 +111,8 @@ namespace SparkleLib { // In the unlikely case that we haven't synced up our // changes or the server was down, sync up again - if (HasUnsyncedChanges) { + if (HasUnsyncedChanges) SyncUpBase (); - SyncUpNotes (); - } }; // Sync up everything that changed @@ -239,10 +239,8 @@ namespace SparkleLib { SyncDownBase (); // Push changes that were made since the last disconnect - if (HasUnsyncedChanges) { + if (HasUnsyncedChanges) SyncUpBase (); - SyncUpNotes (); - } }; // Start polling when the connection to the irc channel is lost @@ -310,7 +308,8 @@ namespace SparkleLib { if (!this.watcher.EnableRaisingEvents) return; - if (args.FullPath.Contains (Path.DirectorySeparatorChar + ".")) + if (args.FullPath.Contains (Path.DirectorySeparatorChar + ".") && + !args.FullPath.Contains (Path.DirectorySeparatorChar + ".notes")) return; WatcherChangeTypes wct = args.ChangeType; @@ -337,6 +336,42 @@ namespace SparkleLib { } + public List GetNotes (string revision) { + List notes = new List (); + + string notes_path = Path.Combine (LocalPath, ".notes"); + + if (!Directory.Exists (notes_path)) + Directory.CreateDirectory (notes_path); + + Regex regex_notes = new Regex (@"(.+).*" + + "(.+).*" + + "([0-9]+).*" + + "(.+)", RegexOptions.Compiled); + + foreach (string file_path in Directory.GetFiles (notes_path)) { + if (Path.GetFileName (file_path).StartsWith (revision)) { + string note_xml = String.Join ("", File.ReadAllLines (file_path)); + + Match match_notes = regex_notes.Match (note_xml); + + if (match_notes.Success) { + SparkleNote note = new SparkleNote () { + UserName = match_notes.Groups [1].Value, + UserEmail = match_notes.Groups [2].Value, + Timestamp = new DateTime (1970, 1, 1).AddSeconds (int.Parse (match_notes.Groups [3].Value)), + Body = match_notes.Groups [4].Value + }; + + notes.Add (note); + } + } + } + + return notes; + } + + private void SyncUpBase () { try { @@ -452,15 +487,41 @@ namespace SparkleLib { } - public virtual void AddNote (string revision, string note) + public void AddNote (string revision, string note) { + string notes_path = Path.Combine (LocalPath, ".notes"); - } + if (!Directory.Exists (notes_path)) + Directory.CreateDirectory (notes_path); + + // Add a timestamp in seconds since unix epoch + int timestamp = (int) (DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds; + + string n = Environment.NewLine; + note = "" + n + + " " + n + + " " + SparkleConfig.DefaultConfig.UserName + "" + n + + " " + SparkleConfig.DefaultConfig.UserEmail + "" + n + + " " + n + + " " + timestamp + "" + n + + " " + note + "" + n + + "" + n; + + string note_name = revision + SHA1 (timestamp.ToString () + note); + string note_path = Path.Combine (notes_path, note_name); + + StreamWriter writer = new StreamWriter (note_path); + writer.Write (note); + writer.Close (); - public virtual void SyncUpNotes () - { + // The watcher doesn't like .*/ so we need to trigger + // a change manually + FileSystemEventArgs args = new FileSystemEventArgs (WatcherChangeTypes.Changed, + notes_path, note_name); + OnFileActivity (args); + SparkleHelpers.DebugInfo ("Note", "Added note to " + revision); } @@ -489,5 +550,15 @@ namespace SparkleLib { return size; } + + + // Creates a SHA-1 hash of input + private string SHA1 (string s) + { + SHA1 sha1 = new SHA1CryptoServiceProvider (); + Byte[] bytes = ASCIIEncoding.Default.GetBytes (s); + Byte[] encoded_bytes = sha1.ComputeHash (bytes); + return BitConverter.ToString (encoded_bytes).ToLower ().Replace ("-", ""); + } } } diff --git a/SparkleShare/Mac/SparkleShare.csproj b/SparkleShare/Mac/SparkleShare.csproj index d652eed3..e94e4bd5 100644 --- a/SparkleShare/Mac/SparkleShare.csproj +++ b/SparkleShare/Mac/SparkleShare.csproj @@ -264,6 +264,9 @@ Pixmaps\about.png + + HTML\jquery.js + diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 1088b3d5..931a8ea0 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -312,7 +312,7 @@ namespace SparkleShare { } new Thread (new ThreadStart (delegate { - FetchAvatars (emails, 36); + FetchAvatars (emails, 48); })).Start (); string event_log_html = EventLogHTML; @@ -325,7 +325,7 @@ namespace SparkleShare { foreach (SparkleChangeSet change_set in activity_day) { string event_entry = "
"; - + if (change_set.IsMerge) { event_entry += "
Did something magical
"; @@ -336,9 +336,9 @@ namespace SparkleShare { change_set.Folder, file_path); if (File.Exists (absolute_file_path)) - event_entry += "
" + file_path + "
"; + event_entry += "
" + file_path + "
"; else - event_entry += "
" + file_path + "
"; + event_entry += "
" + file_path + "
"; } } @@ -348,9 +348,9 @@ namespace SparkleShare { change_set.Folder, file_path); if (File.Exists (absolute_file_path)) - event_entry += "
" + file_path + "
"; + event_entry += "
" + file_path + "
"; else - event_entry += "
" + file_path + "
"; + event_entry += "
" + file_path + "
"; } } @@ -360,9 +360,9 @@ namespace SparkleShare { change_set.Folder, file_path); if (File.Exists (absolute_file_path)) - event_entry += "
" + file_path + "
"; + event_entry += "
" + file_path + "
"; else - event_entry += "
" + file_path + "
"; + event_entry += "
" + file_path + "
"; } } @@ -376,9 +376,9 @@ namespace SparkleShare { change_set.Folder, to_file_path); if (File.Exists (absolute_file_path)) - event_entry += "
" + file_path + "
"; + event_entry += "
" + file_path + "
"; else - event_entry += "
" + file_path + "
"; + event_entry += "
" + file_path + "
"; if (File.Exists (absolute_to_file_path)) event_entry += "" + to_file_path + "
"; @@ -391,34 +391,31 @@ namespace SparkleShare { } string comments = ""; - if (change_set.SupportsNotes) { - comments = ""; + comments = "
"; - if (change_set.Notes != null) { - change_set.Notes.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp))); - - foreach (SparkleNote note in change_set.Notes) { - comments += "
" + - " " + - " " + - "" + - "" + - " " + - ""; - } + if (change_set.Notes != null) { + change_set.Notes.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp))); + + foreach (SparkleNote note in change_set.Notes) { + comments += "
" + + "

" + + note.UserName + "

" + + note.Body + + "
"; } - - comments += "
" + note.UserName + "" + note.Timestamp.ToString ("d MMM") + "
" + note.Body + "
"; } + comments += ""; + string avatar_email = ""; - if (File.Exists (GetAvatar (change_set.UserEmail, 36))) + if (File.Exists (GetAvatar (change_set.UserEmail, 48))) avatar_email = change_set.UserEmail; event_entry += "
"; event_entries += event_entry_html.Replace ("", event_entry) .Replace ("", change_set.UserName) - .Replace ("", "file://" + GetAvatar (avatar_email, 36)) + .Replace ("", "file://" + GetAvatar (avatar_email, 48)) .Replace ("", change_set.Timestamp.ToString ("H:mm")) .Replace ("", change_set.Folder) .Replace ("", change_set.Revision) @@ -434,32 +431,35 @@ namespace SparkleShare { today.Month == activity_day.DateTime.Month && today.Year == activity_day.DateTime.Year) { - day_entry = day_entry_html.Replace ("", "Today"); + 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) { - day_entry = day_entry_html.Replace ("", "Yesterday"); + day_entry = day_entry_html.Replace ("", "Yesterday"); } else { if (activity_day.DateTime.Year != DateTime.Now.Year) { // TRANSLATORS: This is the date in the event logs day_entry = day_entry_html.Replace ("", - "" + activity_day.DateTime.ToString (_("ddd MMM d, yyyy")) + ""); + activity_day.DateTime.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 (_("ddd MMM d")) + ""); + activity_day.DateTime.ToString (_("dddd, MMMM d"))); } } event_log += day_entry.Replace ("", event_entries); } - return event_log_html.Replace ("", event_log) - .Replace ("", UserName); + string html = event_log_html.Replace ("", event_log) + .Replace ("", UserName) + .Replace ("", "file://" + GetAvatar (UserEmail, 48)); + + return html; } diff --git a/data/Makefile.am b/data/Makefile.am index 69b419e6..6f452209 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -3,8 +3,6 @@ SUBDIRS = \ html dist_pixmaps_DATA = \ - sparkleshare-gnome.svg \ - sparkleshare-mist.svg \ side-splash.png \ about.png diff --git a/data/actions.svg b/data/actions.svg deleted file mode 100644 index c349857c..00000000 --- a/data/actions.svg +++ /dev/null @@ -1,1960 +0,0 @@ - - - - - Text Editor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - Jakub Steiner - - - http://jimmac.musichall.cz - - Text Editor - - - text - editor - gedit - - - - - - - - - - - - - - - - - - - - - Lapo Calamandrei - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/data/gnome-design.sparkle b/data/gnome-design.sparkle deleted file mode 100644 index b44c8a77..00000000 --- a/data/gnome-design.sparkle +++ /dev/null @@ -1,9 +0,0 @@ - - - - - git.gnome.org - gnome-design - a22bc6f4b9ffe8e5acd4be0838d41aa10a1187dd - - diff --git a/data/html/event-entry.html b/data/html/event-entry.html index ac45a01d..b9d4bdaf 100644 --- a/data/html/event-entry.html +++ b/data/html/event-entry.html @@ -1,29 +1,22 @@ -
-
-
-
-
-
-
-
- -
- -
-
-
- -
-
- - +
+
+
- -
-
-
-
+ + +
+
+
Add note
+
Show all
+ +
+ +
+ + +
+
diff --git a/data/html/event-log.html b/data/html/event-log.html index 456387e8..680ccdff 100644 --- a/data/html/event-log.html +++ b/data/html/event-log.html @@ -5,11 +5,9 @@