From ad3b78b9114df2787155d2b5234ddfdf18e66bc0 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 2 Nov 2010 10:45:10 +0000 Subject: [PATCH] [notifications] restructure and make commit messages translatable --- SparkleLib/SparkleRepo.cs | 17 +++++----- SparkleShare/SparkleController.cs | 9 +++--- SparkleShare/SparkleIntro.cs | 17 ++++++++-- SparkleShare/SparkleLog.cs | 14 ++++----- SparkleShare/SparkleUI.cs | 52 ++++++++++++++++++++++++++++--- 5 files changed, 82 insertions(+), 27 deletions(-) diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index bdfc88a3..078b7fd2 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -216,7 +216,7 @@ namespace SparkleLib { /// /// Raised when the repository has received one or multiple new remote commits /// - public delegate void NewCommitEventHandler (object o, NewCommitArgs args); + public delegate void NewCommitEventHandler (SparkleCommit commit, string repository_path); /// /// Raised when the newly fetched commits are conflicting with local changes @@ -786,13 +786,10 @@ namespace SparkleLib { } - Commit commit = Head.CurrentCommit; - - NewCommitArgs new_commit_args = new NewCommitArgs (commit.Author.Name, commit.Author.EmailAddress, - commit.Message, LocalPath); + List commits = GetCommits (1); if (NewCommit != null) - NewCommit (this, new_commit_args); + NewCommit (commits [0], LocalPath); } @@ -1023,7 +1020,7 @@ namespace SparkleLib { break; } - message = "added ‘" + file_name + "’"; + message = "+ ‘" + file_name + "’"; } @@ -1034,7 +1031,7 @@ namespace SparkleLib { break; } - message = "edited ‘" + file_name + "’"; + message = "/ ‘" + file_name + "’"; } @@ -1045,7 +1042,7 @@ namespace SparkleLib { break; } - message = "deleted ‘" + file_name + "’"; + message = "- ‘" + file_name + "’"; } @@ -1054,7 +1051,7 @@ namespace SparkleLib { status.Removed.Count); if (changes_count > 1) - message += " and " + (changes_count - 1) + " more"; + message += " + " + (changes_count - 1); return message; diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 9fa10aee..b7b0257b 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -58,8 +58,7 @@ namespace SparkleShare { public delegate void ConflictNotificationRaisedEventHandler (); public event NotificationRaisedEventHandler NotificationRaised; - public delegate void NotificationRaisedEventHandler (string author, string email, string message, - string repository_path); + public delegate void NotificationRaisedEventHandler (SparkleCommit commit, string repository_path); public SparkleController () @@ -356,9 +355,11 @@ namespace SparkleShare { SparkleRepo repo = new SparkleRepo (folder_path); - repo.NewCommit += delegate (object o, NewCommitArgs args) { + repo.NewCommit += delegate (SparkleCommit commit, string repository_path) { + if (NotificationsEnabled && NotificationRaised != null) - NotificationRaised (args.Author, args.Email, args.Message, args.RepositoryPath); + NotificationRaised (commit, repository_path); + }; repo.FetchingStarted += delegate { diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index 3ea02fcb..e809f286 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -487,13 +487,17 @@ namespace SparkleShare { } - + private ProgressBar ProgressBar; // The page shown whilst syncing private void ShowSyncingPage (string name) { Reset (); + ProgressBar = new ProgressBar () { + Fraction = 0 + }; + VBox layout_vertical = new VBox (false, 0); Label header = new Label ("" + @@ -524,7 +528,7 @@ namespace SparkleShare { SparkleSpinner spinner = new SparkleSpinner (22); - Table table = new Table (2, 2, false) { + Table table = new Table (3, 2, false) { RowSpacing = 12, ColumnSpacing = 9 }; @@ -534,6 +538,7 @@ namespace SparkleShare { table.Attach (spinner, 0, 1, 0, 1); table.Attach (header, 1, 2, 0, 1); table.Attach (information, 1, 2, 1, 2); + table.Attach (ProgressBar, 2, 3, 0, 2); box.PackStart (table, false, false, 0); @@ -640,6 +645,14 @@ namespace SparkleShare { }; + fetcher.Progress.ProgressChanged += delegate { + Application.Invoke (delegate { ProgressBar.Fraction = fetcher.Progress.Fraction; + ProgressBar.ShowAll (); + }); + Console.WriteLine ("!!!!!!!!!!!UPDATED BAR!!!!!!!!1"); + }; + + fetcher.CloningFinished += delegate { DeleteEvent -= PreventClose; diff --git a/SparkleShare/SparkleLog.cs b/SparkleShare/SparkleLog.cs index 13c31c2a..4984883c 100644 --- a/SparkleShare/SparkleLog.cs +++ b/SparkleShare/SparkleLog.cs @@ -146,12 +146,12 @@ namespace SparkleShare { if (repo.LocalPath.Equals (LocalPath)) { - // Remove the eventhooks +/* // Remove the eventhooks repo.NewCommit -= UpdateEventLog; repo.PushingFinished -= UpdateEventLog; - repo.PushingFailed -= UpdateEventLog; + repo.PushingFailed -= UpdateEventLog; TODO: Move to controller repo.FetchingFinished -= UpdateEventLog; - repo.FetchingFailed -= UpdateEventLog; + repo.FetchingFailed -= UpdateEventLog;*/ } @@ -162,7 +162,7 @@ namespace SparkleShare { } - public void UpdateEventLog (object o, EventArgs args) + public void UpdateEventLog (SparkleCommit commit, string repository_path) { Application.Invoke (delegate { @@ -190,16 +190,16 @@ namespace SparkleShare { commits = repo.GetCommits (25); - // Update the log when there are new remote changes +/* // Update the log when there are new remote changes repo.NewCommit += UpdateEventLog; // Update the log when changes are being sent repo.PushingFinished += UpdateEventLog; repo.PushingFailed += UpdateEventLog; - repo.FetchingFinished += UpdateEventLog; + repo.FetchingFinished += UpdateEventLog; TODO: Move to controller repo.FetchingFailed += UpdateEventLog; - +*/ break; } diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index 98afcf45..1ef06ea4 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -17,6 +17,7 @@ using Gtk; using Mono.Unix; using Mono.Unix.Native; +using SparkleLib; using System; using System.Collections.Generic; using System.Diagnostics; @@ -71,13 +72,56 @@ namespace SparkleShare { }; // Show a bubble when there are new changes - SparkleShare.Controller.NotificationRaised += delegate (string author, string email, string message, - string repository_path) { + SparkleShare.Controller.NotificationRaised += delegate (SparkleCommit commit, string repository_path) { + + string file_name = ""; + string message = null; + + if (commit.Added.Count > 0) { + + foreach (string added in commit.Added) { + file_name = added; + break; + } + + message = String.Format (_("added ‘{0}’"), file_name); + + } + + if (commit.Edited.Count > 0) { + + foreach (string modified in commit.Edited) { + file_name = modified; + break; + } + + message = String.Format (_("edited ‘{0}’"), file_name); + + } + + if (commit.Deleted.Count > 0) { + + foreach (string removed in commit.Deleted) { + file_name = removed; + break; + } + + message = String.Format (_("deleted ‘{0}’"), file_name); + + } + + int changes_count = (commit.Added.Count + + commit.Edited.Count + + commit.Deleted.Count); + + if (changes_count > 1) + message += " + " + (changes_count - 1); + Application.Invoke (delegate { - SparkleBubble bubble = new SparkleBubble (author, message) { - Icon = SparkleUIHelpers.GetAvatar (email, 32) + SparkleBubble bubble = new SparkleBubble (commit.UserName, message) { + Icon = SparkleUIHelpers.GetAvatar (commit.UserEmail, 32) }; bubble.AddAction ("", "Show Events", delegate {