Fix a lot of crashes due to calling to GTK UI updates from multiple threads.

This commit is contained in:
Hylke Bons 2010-07-24 13:32:05 +01:00
parent 6881fbe793
commit 2d2aa11a75
6 changed files with 147 additions and 95 deletions

1
.gitignore vendored
View file

@ -38,3 +38,4 @@ build/m4/shave/shave-libtool
Defines.cs
SparkleShare/sparkleshare
po/sparkleshare.pot
SparkleShare/Nautilus/sparkleshare-nautilus-extension.py

View file

@ -12,6 +12,7 @@ Contributors:
Łukasz Jernaś <deejay1@srem.org>
Oleg Khlystov <pktfag@gmail.com>
Philipp Gildein <rmbl@openspeak-project.org>
Ruben Vermeersch <rubenv@gnome.org>
Sandy Armstrong <sanfordarmstrong@gmail.com>
Simon Pither <simon@pither.com>
Steven Harms <sharms@ubuntu.com>

View file

@ -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);

View file

@ -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;
}
}
}

View file

@ -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);

View file

@ -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