From 2d2aa11a75a7b1e24abfc36cb5bd43386d8e1add Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 24 Jul 2010 13:32:05 +0100 Subject: [PATCH] Fix a lot of crashes due to calling to GTK UI updates from multiple threads. --- .gitignore | 1 + AUTHORS | 1 + SparkleShare/SparkleIntro.cs | 3 +- SparkleShare/SparkleRepo.cs | 100 ++++++++++++--------------- SparkleShare/SparkleUI.cs | 128 ++++++++++++++++++++++++----------- data/Makefile.am | 9 ++- 6 files changed, 147 insertions(+), 95 deletions(-) diff --git a/.gitignore b/.gitignore index 50049d80..0269ef86 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ build/m4/shave/shave-libtool Defines.cs SparkleShare/sparkleshare po/sparkleshare.pot +SparkleShare/Nautilus/sparkleshare-nautilus-extension.py diff --git a/AUTHORS b/AUTHORS index 529e1fd3..230a6c16 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,6 +12,7 @@ Contributors: Łukasz Jernaś Oleg Khlystov Philipp Gildein + Ruben Vermeersch Sandy Armstrong Simon Pither Steven Harms diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index bcb3bd43..db2e5b82 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -59,7 +59,8 @@ namespace SparkleShare { HBox layout_horizontal = new HBox (false, 6); // TODO: Fix the path - Image side_splash = new Image ("/home/hbons/github/SparkleShare/data/side-splash.png"); + Image side_splash = new Image (SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", + "pixmaps", "side-splash.png")); VBox wrapper = new VBox (false, 0); diff --git a/SparkleShare/SparkleRepo.cs b/SparkleShare/SparkleRepo.cs index 3dfac41d..55e57d15 100644 --- a/SparkleShare/SparkleRepo.cs +++ b/SparkleShare/SparkleRepo.cs @@ -52,8 +52,11 @@ namespace SparkleShare { public delegate void CommitedEventHandler (object o, SparkleEventArgs args); public event CommitedEventHandler Commited; - public delegate void PushedEventHandler (object o, SparkleEventArgs args); - public event PushedEventHandler Pushed; + 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; @@ -61,7 +64,7 @@ namespace SparkleShare { public delegate void FetchingFinishedEventHandler (object o, SparkleEventArgs args); public event FetchingFinishedEventHandler FetchingFinished; - public delegate void NewCommitEventHandler (object o, SparkleEventArgs args); + public delegate void NewCommitEventHandler (object o, NewCommitArgs args); public event NewCommitEventHandler NewCommit; @@ -139,8 +142,6 @@ namespace SparkleShare { private void CheckForChanges () { - SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Checking for changes."); - lock (ChangeLock) { if (HasChanged) { @@ -270,8 +271,8 @@ namespace SparkleShare { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes..."); Process.StartInfo.Arguments = "fetch -v"; - Process.Start (); Process.WaitForExit (); + Process.Start (); string Output = Process.StandardOutput.ReadToEnd ().Trim (); // TODO: This doesn't work :( @@ -369,55 +370,25 @@ namespace SparkleShare { } + // Get the last commiter + Process.StartInfo.Arguments = "log --format=\"%an\" -1"; + Process.Start (); + string author = Process.StandardOutput.ReadToEnd ().Trim (); + // Get the last committer e-mail Process.StartInfo.Arguments = "log --format=\"%ae\" -1"; Process.Start (); - string LastCommitEmail = Process.StandardOutput.ReadToEnd ().Trim (); + string email = Process.StandardOutput.ReadToEnd ().Trim (); // Get the last commit message Process.StartInfo.Arguments = "log --format=\"%s\" -1"; Process.Start (); - string LastCommitMessage = Process.StandardOutput.ReadToEnd ().Trim (); + string message = Process.StandardOutput.ReadToEnd ().Trim (); - // Get the last commiter - Process.StartInfo.Arguments = "log --format=\"%an\" -1"; - Process.Start (); - string LastCommitUserName = Process.StandardOutput.ReadToEnd ().Trim (); + NewCommitArgs args = new NewCommitArgs (author, email, message); - string NotifySettingFile = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, - "sparkleshare.notify"); - - if (File.Exists (NotifySettingFile)) { - - SparkleHelpers.DebugInfo ("Notification", "[" + Name + "] Showing message..."); - - SparkleEventArgs args = new SparkleEventArgs ("NewCommit"); - - if (NewCommit != null) - NewCommit (this, args); - -// SparkleBubble StuffChangedBubble = new SparkleBubble (LastCommitUserName, LastCommitMessage); - // StuffChangedBubble.Icon = SparkleHelpers.GetAvatar (LastCommitEmail, 32); - - // Add a button to open the folder where the changed file is - /* StuffChangedBubble.AddAction ("", _("Open Folder"), - delegate { - switch (SparklePlatform.Name) { - case "GNOME": - Process.StartInfo.FileName = "xdg-open"; - break; - case "OSX": - Process.StartInfo.FileName = "open"; - break; - } - Process.StartInfo.Arguments = LocalPath; - Process.Start (); - Process.StartInfo.FileName = "git"; - } ); - - StuffChangedBubble.Show (); -*/ - } + if (NewCommit != null) + NewCommit (this, args); } @@ -431,20 +402,27 @@ namespace SparkleShare { public void Push () { + SparkleEventArgs args = new SparkleEventArgs ("PushingStarted"); + + if (PushingStarted != null) + PushingStarted (this, args); + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes..."); Process.StartInfo.Arguments = "push"; Process.Start (); Process.WaitForExit (); - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed."); + Process.Exited += delegate { + + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed."); - SparkleEventArgs args = new SparkleEventArgs ("Pushed"); + args = new SparkleEventArgs ("PushingFinished"); - if (Pushed != null) - Pushed (this, args); + if (PushingFinished != null) + PushingFinished (this, args); -// SparkleUI.NotificationIcon.SetIdleState (); + }; } @@ -701,8 +679,20 @@ namespace SparkleShare { } + + public class NewCommitArgs : System.EventArgs { + + public string Author; + public string Email; + public string Message; + + public NewCommitArgs (string author, string email, string message) + { + Author = author; + Email = email; + Message = message; + } + + } + } - - - - diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index 10321154..c8f00881 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -51,6 +51,7 @@ namespace SparkleShare { string SparklePath = SparklePaths.SparklePath; EnableSystemAutostart (); + InstallLauncher (); CreateSparkleShareFolder (); // Create a directory to store temporary files in @@ -138,44 +139,67 @@ namespace SparkleShare { public void EnableSystemAutostart () { - switch (SparklePlatform.Name) { + string autostart_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".config", "autostart"); + string desktopfile_path = SparkleHelpers.CombineMore (autostart_path, "sparkleshare.desktop"); - case "GNOME": + if (!File.Exists (desktopfile_path)) { - string autostart_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".config", "autostart"); - string desktopfile_path = SparkleHelpers.CombineMore (autostart_path, "sparkleshare.desktop"); + if (!Directory.Exists (autostart_path)) + Directory.CreateDirectory (autostart_path); - if (!File.Exists (desktopfile_path)) { + TextWriter writer = new StreamWriter (desktopfile_path); + writer.WriteLine ("[Desktop Entry]\n" + + "Type=Application\n" + + "Name=SparkleShare\n" + + "Exec=sparkleshare start\n" + + "Icon=folder-sparkleshare\n" + + "Terminal=false\n" + + "X-GNOME-Autostart-enabled=true\n" + + "Categories=Network"); + writer.Close (); - if (!Directory.Exists (autostart_path)) - Directory.CreateDirectory (autostart_path); + // Give the launcher the right permissions so it can be launched by the user + Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); - TextWriter writer = new StreamWriter (desktopfile_path); + SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); - writer.WriteLine ("[Desktop Entry]\n" + - "Type=Application\n" + - "Name=SparkleShare\n" + - "Exec=sparkleshare start\n" + - "Icon=folder-sparkleshare\n" + - "Terminal=false\n" + - "X-GNOME-Autostart-enabled=true"); + } - writer.Close (); - - // Give the launcher the right permissions so it can be launched by the user - Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); - - SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); - - } - - break; - - } - } + public void InstallLauncher () + { + + string apps_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".local", "share", "applications"); + string desktopfile_path = SparkleHelpers.CombineMore (apps_path, "sparkleshare.desktop"); + + if (!File.Exists (desktopfile_path)) { + + if (!Directory.Exists (apps_path)) + Directory.CreateDirectory (apps_path); + + TextWriter writer = new StreamWriter (desktopfile_path); + writer.WriteLine ("[Desktop Entry]\n" + + "Type=Application\n" + + "Name=SparkleShare\n" + + "Comment=Share documents\n" + + "Exec=sparkleshare start\n" + + "Icon=folder-sparkleshare\n" + + "Terminal=false\n" + + "Categories=Network"); + writer.Close (); + + // Give the launcher the right permissions so it can be launched by the user + Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); + + SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); + + } + + } + + // Adds the SparkleShare folder to the user's // list of bookmarked folders public void AddToBookmarks () @@ -233,24 +257,36 @@ namespace SparkleShare { } - public void ShowNewCommitBubble (object o, SparkleEventArgs args) { + public void ShowNewCommitBubble (string author, string email, string message) { - // TODO: Show bubble + string notify_settings_file = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, + "sparkleshare.notify"); + + if (File.Exists (notify_settings_file)) { + + SparkleBubble bubble= new SparkleBubble (author, message); + bubble.Icon = SparkleHelpers.GetAvatar (email, 32); + bubble.Show (); + + } } - public void UpdateStatusIcon (object o, SparkleEventArgs args) { + public void UpdateStatusIconSyncing (object o, EventArgs args) + { - if (args.Message.Equals ("FetchingStarted")) { NotificationIcon.SyncingReposCount++; NotificationIcon.ShowState (); - } - if (args.Message.Equals ("FetchingFinished")) { + } + + + public void UpdateStatusIconIdle (object o, EventArgs args) + { + NotificationIcon.SyncingReposCount--; NotificationIcon.ShowState (); - } } @@ -269,9 +305,25 @@ namespace SparkleShare { SparkleRepo repo = new SparkleRepo (folder); - repo.NewCommit += ShowNewCommitBubble; - repo.FetchingStarted += UpdateStatusIcon; - repo.FetchingFinished += UpdateStatusIcon; + repo.NewCommit += delegate (object o, NewCommitArgs args) { + Application.Invoke (delegate { ShowNewCommitBubble (args.Author, args.Email, args.Message); }); + }; + + repo.FetchingStarted += delegate { + Application.Invoke (UpdateStatusIconSyncing); + }; + + repo.FetchingFinished += delegate { + Application.Invoke (UpdateStatusIconIdle); + }; + + repo.PushingStarted += delegate { + Application.Invoke (UpdateStatusIconSyncing); + }; + + repo.PushingFinished += delegate { + Application.Invoke (UpdateStatusIconIdle); + }; Repositories.Add (repo); diff --git a/data/Makefile.am b/data/Makefile.am index 2bf7d453..b6efc474 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -2,8 +2,15 @@ SUBDIRS = \ icons EXTRA_DIST = \ - sparkleshare.svg + sparkleshare.svg \ + side-splash.png MAINTAINERCLEANFILES = \ Makefile.in +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(datadir)/pixmaps + $(INSTALL_DATA) $(srcdir)/side-splash.png $(DESTDIR)$(datadir)/pixmaps/side-splash.png + +uninstall-hook: + rm -f $(DESTDIR)$(datadir)/pixmaps/side-splash.png