Move FormatMessage to bubbles controller

This commit is contained in:
Hylke Bons 2011-11-18 20:53:53 +00:00
parent a16a829056
commit 444082f396
3 changed files with 64 additions and 58 deletions

View file

@ -72,7 +72,7 @@ namespace SparkleLib {
public delegate void NewChangeSetEventHandler (SparkleChangeSet change_set);
public event NewChangeSetEventHandler NewChangeSet;
public delegate void NewNoteEventHandler (string user_name, string user_email);
public delegate void NewNoteEventHandler (SparkleUser user);
public event NewNoteEventHandler NewNote;
public delegate void ConflictResolvedEventHandler ();
@ -482,7 +482,7 @@ namespace SparkleLib {
foreach (string added in change_set.Added) {
if (added.Contains (".notes")) {
if (NewNote != null)
NewNote (change_set.User.Name, change_set.User.Email);
NewNote (change_set.User);
note_added = true;
break;

View file

@ -16,6 +16,7 @@
using System;
using SparkleLib;
namespace SparkleShare {
@ -29,14 +30,18 @@ namespace SparkleShare {
{
Program.Controller.ConflictNotificationRaised += delegate {
ShowBubble ("Ouch! Mid-air collision!",
"Don't worry, SparkleShare made a copy of each conflicting file.",
null);
"Don't worry, SparkleShare made a copy of each conflicting file.",
null);
};
Program.Controller.NotificationRaised += delegate (string user_name, string user_email,
string message, string folder_path) {
ShowBubble (user_name, message,
Program.Controller.GetAvatar (user_email, 36));
Program.Controller.NotificationRaised += delegate (SparkleChangeSet change_set) {
ShowBubble (change_set.User.Name, FormatMessage (change_set),
Program.Controller.GetAvatar (change_set.User.Email, 36));
};
Program.Controller.NoteNotificationRaised += delegate (SparkleUser user, string folder_name) {
ShowBubble (user.Name, "added a note to '" + folder_name + "'",
Program.Controller.GetAvatar (user.Email, 36));
};
}
@ -46,5 +51,47 @@ namespace SparkleShare {
if (ShowBubbleEvent != null && Program.Controller.NotificationsEnabled)
ShowBubbleEvent (title, subtext, image_path);
}
private string FormatMessage (SparkleChangeSet change_set)
{
string file_name = "";
string message = "";
if (change_set.Added.Count > 0) {
file_name = change_set.Added [0];
message = String.Format (_("added {0}"), file_name);
}
if (change_set.MovedFrom.Count > 0) {
file_name = change_set.MovedFrom [0];
message = String.Format (_("moved {0}"), file_name);
}
if (change_set.Edited.Count > 0) {
file_name = change_set.Edited [0];
message = String.Format (_("edited {0}"), file_name);
}
if (change_set.Deleted.Count > 0) {
file_name = change_set.Deleted [0];
message = String.Format (_("deleted {0}"), file_name);
}
int changes_count = (change_set.Added.Count +
change_set.Edited.Count +
change_set.Deleted.Count +
change_set.MovedFrom.Count) - 1;
if (changes_count > 0) {
string msg = Catalog.GetPluralString ("and {0} more", "and {0} more", changes_count);
message += " " + String.Format (msg, changes_count);
} else if (changes_count < 0) {
message += _("did something magical");
}
return message;
}
}
}

View file

@ -75,8 +75,10 @@ namespace SparkleShare {
public delegate void ConflictNotificationRaisedEventHandler ();
public event NotificationRaisedEventHandler NotificationRaised;
public delegate void NotificationRaisedEventHandler (string user_name, string user_email,
string message, string repository_path);
public delegate void NotificationRaisedEventHandler (SparkleChangeSet change_set);
public event NoteNotificationRaisedEventHandler NoteNotificationRaised;
public delegate void NoteNotificationRaisedEventHandler (SparkleUser user, string folder_name);
public abstract string PluginsPath { get; }
@ -581,16 +583,15 @@ namespace SparkleShare {
SparkleRepoBase repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
repo.NewChangeSet += delegate (SparkleChangeSet change_set) {
string message = FormatMessage (change_set);
if (NotificationRaised != null)
NotificationRaised (change_set.User.Name, change_set.User.Email, message, repo.LocalPath);
NotificationRaised (change_set);
};
repo.NewNote += delegate (string user_name, string user_email) {
if (NotificationRaised != null)
NotificationRaised (user_name, user_email,
"added a note to " + Path.GetFileName (repo.LocalPath), repo.LocalPath);
repo.NewNote += delegate (SparkleUser user) {
if (NoteNotificationRaised != null)
NoteNotificationRaised (user, repo.Name);
};
repo.ConflictResolved += delegate {
@ -702,48 +703,6 @@ namespace SparkleShare {
}
private string FormatMessage (SparkleChangeSet change_set)
{
string file_name = "";
string message = "";
if (change_set.Added.Count > 0) {
file_name = change_set.Added [0];
message = String.Format (_("added {0}"), file_name);
}
if (change_set.MovedFrom.Count > 0) {
file_name = change_set.MovedFrom [0];
message = String.Format (_("moved {0}"), file_name);
}
if (change_set.Edited.Count > 0) {
file_name = change_set.Edited [0];
message = String.Format (_("edited {0}"), file_name);
}
if (change_set.Deleted.Count > 0) {
file_name = change_set.Deleted [0];
message = String.Format (_("deleted {0}"), file_name);
}
int changes_count = (change_set.Added.Count +
change_set.Edited.Count +
change_set.Deleted.Count +
change_set.MovedFrom.Count) - 1;
if (changes_count > 0) {
string msg = Catalog.GetPluralString ("and {0} more", "and {0} more", changes_count);
message += " " + String.Format (msg, changes_count);
} else if (changes_count < 0) {
message += _("did something magical");
}
return message;
} // TODO: move to bubbles controller
// Recursively gets a folder's size in bytes
private double CalculateFolderSize (DirectoryInfo parent)
{