diff --git a/SparkleShare/SparkleRepo.cs b/SparkleShare/SparkleRepo.cs index 55e57d15..baf82884 100644 --- a/SparkleShare/SparkleRepo.cs +++ b/SparkleShare/SparkleRepo.cs @@ -25,7 +25,6 @@ using System.Timers; namespace SparkleShare { - // Holds repository information and timers public class SparkleRepo { @@ -45,34 +44,25 @@ namespace SparkleShare { public string UserEmail; public string UserName; - public delegate void AddedEventHandler (object o, SparkleEventArgs args); - public event AddedEventHandler Added; - public delegate void CommitedEventHandler (object o, SparkleEventArgs args); - public event CommitedEventHandler Commited; - public delegate void PushingStartedEventHandler (object o, SparkleEventArgs args); - public event PushingStartedEventHandler PushingStarted; - public delegate void PushingFinishedEventHandler (object o, SparkleEventArgs args); - public event PushingFinishedEventHandler PushingFinished; - public delegate void FetchingStartedEventHandler (object o, SparkleEventArgs args); - public event FetchingStartedEventHandler FetchingStarted; - public delegate void FetchingFinishedEventHandler (object o, SparkleEventArgs args); - public event FetchingFinishedEventHandler FetchingFinished; - public delegate void NewCommitEventHandler (object o, NewCommitArgs args); + public delegate void ConflictDetectedEventHandler (object o, SparkleEventArgs args); + + public event AddedEventHandler Added; + public event CommitedEventHandler Commited; + public event PushingStartedEventHandler PushingStarted; + public event PushingFinishedEventHandler PushingFinished; + public event FetchingStartedEventHandler FetchingStarted; + public event FetchingFinishedEventHandler FetchingFinished; public event NewCommitEventHandler NewCommit; + public event ConflictDetectedEventHandler ConflictDetected; - public static string _ (string s) - { - return Catalog.GetString (s); - } - public SparkleRepo (string path) { @@ -177,8 +167,10 @@ namespace SparkleShare { FetchTimer.Stop (); lock (ChangeLock) { + LastChange = DateTime.UtcNow; HasChanged = true; + } } @@ -197,13 +189,15 @@ namespace SparkleShare { FetchTimer.Stop (); Add (); + string message = FormatCommitMessage (); if (!message.Equals ("")) { + Commit (message); Fetch (); Push (); - CheckForUnicorns (message); + } } finally { @@ -237,19 +231,20 @@ namespace SparkleShare { // Commits the made changes - public void Commit (string Message) + public void Commit (string message) { - SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + Message); + SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message); - Process.StartInfo.Arguments = "commit -m \"" + Message + "\""; + Process.StartInfo.Arguments = "commit -m \"" + message + "\""; Process.Start (); Process.WaitForExit (); SparkleEventArgs args = new SparkleEventArgs ("Commited"); + args.Message = message; if (Commited != null) - Commited (this, args); + Commited (this, args); } @@ -335,23 +330,18 @@ namespace SparkleShare { Process.WaitForExit (); Process.Start (); - string TimeStamp = DateTime.Now.ToString ("H:mm d MMM yyyy"); + string timestamp = DateTime.Now.ToString ("H:mm d MMM yyyy"); - File.Move (problem_file_name, - problem_file_name + " (" + UserName + ", " + TimeStamp + ")"); + File.Move (problem_file_name, problem_file_name + " (" + UserName + ", " + timestamp + ")"); - Process.StartInfo.Arguments - = "checkout --theirs " + problem_file_name; + Process.StartInfo.Arguments = "checkout --theirs " + problem_file_name; Process.WaitForExit (); Process.Start (); - string conflict_title = "A mid-air collision happened!\n"; - string conflict_subtext = "Don't worry, SparkleShare made\na copy of each conflicting file."; + SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected"); -// SparkleBubble ConflictBubble = - // new SparkleBubble(_(ConflictTitle), _(ConflictSubtext)); - - // ConflictBubble.Show (); + if (ConflictDetected != null) + ConflictDetected (this, args); } @@ -385,10 +375,10 @@ namespace SparkleShare { Process.Start (); string message = Process.StandardOutput.ReadToEnd ().Trim (); - NewCommitArgs args = new NewCommitArgs (author, email, message); + NewCommitArgs new_commit_args = new NewCommitArgs (author, email, message); if (NewCommit != null) - NewCommit (this, args); + NewCommit (this, new_commit_args); } @@ -649,32 +639,17 @@ namespace SparkleShare { } - - // Checks for unicorns - public static void CheckForUnicorns (string s) { - - s = s.ToLower (); - if (s.Contains ("unicorn") && (s.Contains (".png") || s.Contains (".jpg"))) { - string title = _("Hold your ponies!"); - string subtext = _("SparkleShare is known to be insanely fast with \n" + - "pictures of unicorns. Please make sure your internets\n" + - "are upgraded to the latest version to avoid problems."); -// SparkleBubble unicorn_bubble = new SparkleBubble (title, subtext); - // unicorn_bubble.Show (); - } - - } - } public class SparkleEventArgs : System.EventArgs { + public string Type; public string Message; - public SparkleEventArgs (string s) + public SparkleEventArgs (string type) { - Message = s; + Type = type; } } diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index c8f00881..170fd073 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -27,40 +27,48 @@ namespace SparkleShare { public class SparkleUI { - private Process Process; + public static SparkleStatusIcon NotificationIcon; public static List Repositories; + private Process Process; + + // Short alias for the translations public static string _(string s) { return Catalog.GetString (s); } - public static SparkleStatusIcon NotificationIcon; public SparkleUI (bool HideUI) { Repositories = new List (); - Process = new Process (); - Process.EnableRaisingEvents = true; + Process = new Process () { + EnableRaisingEvents = true + }; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.UseShellExecute = false; - string SparklePath = SparklePaths.SparklePath; - EnableSystemAutostart (); InstallLauncher (); - CreateSparkleShareFolder (); + + // Create the SparkleShare folder and add it to the bookmarks + if (!Directory.Exists (SparklePaths.SparklePath)) { + + CreateSparkleShareFolder (); + AddToBookmarks (); + + } // Create a directory to store temporary files in if (!Directory.Exists (SparklePaths.SparkleTmpPath)) Directory.CreateDirectory (SparklePaths.SparkleTmpPath); + CreateConfigurationFolders (); UpdateRepositories (); - // Don't create the window and status // icon when --disable-gui was given if (!HideUI) { @@ -78,58 +86,34 @@ namespace SparkleShare { } } - - // TODO: This crashes -/* + } - // Watch the SparkleShare folder and pop up the - // Add dialog when a new folder is created - FileSystemWatcher Watcher = new FileSystemWatcher (SparklePaths.SparklePath); - Watcher.IncludeSubdirectories = false; - Watcher.EnableRaisingEvents = true; - Watcher.Created += delegate (object o, FileSystemEventArgs args) { - WatcherChangeTypes wct = args.ChangeType; - SparkleHelpers.DebugInfo ("Event", - wct.ToString () + - " '" + args.Name + "'"); - SparkleDialog SparkleDialog = new SparkleDialog (); - SparkleDialog.ShowAll (); - }; + // Creates a folder in the user's home folder to store configuration + public void CreateConfigurationFolders () + { - // When a repo folder is deleted, don't sync and update the UI - Watcher.Deleted += delegate (object o, FileSystemEventArgs args) { - WatcherChangeTypes wct = args.ChangeType; - SparkleHelpers.DebugInfo ("Event", - wct.ToString () + - " '" + args.Name + "'"); - SparkleUI SparkleUI = new SparkleUI (); - SparkleUI.ShowAll (); - }; -*/ + string config_path = SparklePaths.SparkleConfigPath; + string local_icon_path = SparklePaths.SparkleLocalIconPath; - // Create place to store configuration user's home folder - string ConfigPath = SparklePaths.SparkleConfigPath; - string LocalIconPath = SparklePaths.SparkleLocalIconPath; + if (!Directory.Exists (config_path)) { - if (!Directory.Exists (ConfigPath)) { + // Create a folder to store settings + Directory.CreateDirectory (config_path); + SparkleHelpers.DebugInfo ("Config", "Created '" + config_path + "'"); - Directory.CreateDirectory (ConfigPath); - SparkleHelpers.DebugInfo ("Config", "Created '" + ConfigPath + "'"); + // Create a folder to store the avatars + Directory.CreateDirectory (local_icon_path); + SparkleHelpers.DebugInfo ("Config", "Created '" + local_icon_path + "'"); - // Create a place to store the avatars - Directory.CreateDirectory (LocalIconPath); - SparkleHelpers.DebugInfo ("Config", "Created '" + LocalIconPath + "'"); + string notify_setting_file = SparkleHelpers.CombineMore (config_path, "sparkleshare.notify"); + + // Enable notifications by default + if (!File.Exists (notify_setting_file)) + File.Create (notify_setting_file); } - - string notify_setting_file = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, - "sparkleshare.notify"); - - // Enable notifications by default - if (!File.Exists (notify_setting_file)) - File.Create (notify_setting_file); } @@ -168,6 +152,8 @@ namespace SparkleShare { } + // Installs a launcher so the user can launch SparkleShare + // from the Internet category if needed public void InstallLauncher () { @@ -204,21 +190,14 @@ namespace SparkleShare { // list of bookmarked folders public void AddToBookmarks () { - - // Add the SparkleShare folder to the bookmarks - switch (SparklePlatform.Name) { - case "GNOME": + string bookmarks_file_name = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks"); - string bookmarks_file_name = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks"); + if (File.Exists (bookmarks_file_name)) { - if (File.Exists (bookmarks_file_name)) { - TextWriter writer = File.AppendText (bookmarks_file_name); - writer.WriteLine ("file://" + SparklePaths.SparklePath + " SparkleShare"); - writer.Close (); - } - - break; + TextWriter writer = File.AppendText (bookmarks_file_name); + writer.WriteLine ("file://" + SparklePaths.SparklePath + " SparkleShare"); + writer.Close (); } @@ -230,33 +209,21 @@ namespace SparkleShare { public void CreateSparkleShareFolder () { - if (!Directory.Exists (SparklePaths.SparklePath)) { - - Directory.CreateDirectory (SparklePaths.SparklePath); - SparkleHelpers.DebugInfo ("Config", "Created '" + SparklePaths.SparklePath + "'"); - - // Add a special icon to the SparkleShare folder - switch (SparklePlatform.Name) { - - case "GNOME": - - Process.StartInfo.FileName = "gvfs-set-attribute"; - Process.StartInfo.Arguments = SparklePaths.SparklePath + " metadata::custom-icon " + - "file:///usr/share/icons/hicolor/48x48/places/" + - "folder-sparkleshare.png"; - Process.Start (); - - break; - - } - - AddToBookmarks (); - - } + Directory.CreateDirectory (SparklePaths.SparklePath); + SparkleHelpers.DebugInfo ("Config", "Created '" + SparklePaths.SparklePath + "'"); + + // Add a special icon to the SparkleShare folder + Process.StartInfo.FileName = "gvfs-set-attribute"; + Process.StartInfo.Arguments = SparklePaths.SparklePath + " metadata::custom-icon " + + "file:///usr/share/icons/hicolor/48x48/places/" + + "folder-sparkleshare.png"; + Process.Start (); } + // Shows a notification bubble when someone + // made a change to the repository public void ShowNewCommitBubble (string author, string email, string message) { string notify_settings_file = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, @@ -273,6 +240,20 @@ namespace SparkleShare { } + // Shows a notification bubble when there + // was a conflict + public void ShowConflictBubble (object o, EventArgs args) { + + string title = _("Ouch! Mid-air collision!"); + string subtext = _("Don't worry, SparkleShare made a copy of each conflicting file."); + + SparkleBubble bubble = new SparkleBubble(title, subtext); + bubble.Show (); + + } + + + // Updates the statusicon to the syncing state public void UpdateStatusIconSyncing (object o, EventArgs args) { @@ -282,6 +263,7 @@ namespace SparkleShare { } + // Updates the syncing icon to the idle state public void UpdateStatusIconIdle (object o, EventArgs args) { @@ -309,22 +291,30 @@ namespace SparkleShare { Application.Invoke (delegate { ShowNewCommitBubble (args.Author, args.Email, args.Message); }); }; - repo.FetchingStarted += delegate { + repo.Commited += delegate (object o, SparkleEventArgs args) { + Application.Invoke (delegate { CheckForUnicorns (args.Message); }); + }; + + repo.FetchingStarted += delegate { Application.Invoke (UpdateStatusIconSyncing); }; - repo.FetchingFinished += delegate { + repo.FetchingFinished += delegate { Application.Invoke (UpdateStatusIconIdle); }; - repo.PushingStarted += delegate { + repo.PushingStarted += delegate { Application.Invoke (UpdateStatusIconSyncing); }; - repo.PushingFinished += delegate { + repo.PushingFinished += delegate { Application.Invoke (UpdateStatusIconIdle); }; + repo.ConflictDetected += delegate { + Application.Invoke (ShowConflictBubble); + }; + Repositories.Add (repo); } @@ -333,6 +323,26 @@ namespace SparkleShare { } + + // Warns the user implicitly that unicorns are actually lethal creatures + public static void CheckForUnicorns (string message) { + + message = message.ToLower (); + + if (message.Contains ("unicorn") && (message.Contains (".png") || message.Contains (".jpg"))) { + + string title = _("Hold your ponies!"); + string subtext = _("SparkleShare is known to be insanely fast with " + + "pictures of unicorns. Please make sure your internets " + + "are upgraded to the latest version to avoid any problems."); + + SparkleBubble bubble = new SparkleBubble (title, subtext); + bubble.Show (); + + } + + } + } } diff --git a/SparkleShare/SparkleWindow.cs b/SparkleShare/SparkleWindow.cs index c8ac3c69..e92ef9bc 100644 --- a/SparkleShare/SparkleWindow.cs +++ b/SparkleShare/SparkleWindow.cs @@ -42,7 +42,7 @@ namespace SparkleShare { { SparkleRepo = sparkle_repo; - SetSizeRequest (550, 720); + SetSizeRequest (540, 640); SetPosition (WindowPosition.Center); BorderWidth = 12; @@ -219,7 +219,7 @@ namespace SparkleShare { layout_vertical.PackStart (date_label, false, false, 0); IconView icon_view = new IconView (list_store) { - ItemWidth = 480, + ItemWidth = 470, MarkupColumn = 1, Orientation = Orientation.Horizontal, PixbufColumn = 0,