From 948144935881e08f283d234a796cf886df5bc530 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 22 Jul 2010 22:10:38 +0100 Subject: [PATCH] fix some bugs and crashes --- SparkleShare/Defines.cs.in | 30 ++++ SparkleShare/SparkleIntro.cs | 5 +- SparkleShare/SparkleRepo.cs | 41 +++-- SparkleShare/SparkleShare.cs | 1 - SparkleShare/SparkleStatusIcon.cs | 254 ++++++++++++++++++++++++++++++ SparkleShare/SparkleUI.cs | 47 +++--- SparkleShare/SparkleWindow.cs | 10 +- 7 files changed, 343 insertions(+), 45 deletions(-) create mode 100644 SparkleShare/Defines.cs.in create mode 100644 SparkleShare/SparkleStatusIcon.cs diff --git a/SparkleShare/Defines.cs.in b/SparkleShare/Defines.cs.in new file mode 100644 index 00000000..b5c4dcfc --- /dev/null +++ b/SparkleShare/Defines.cs.in @@ -0,0 +1,30 @@ +// SparkleShare, an instant update workflow to Git. +// Copyright (C) 2010 Hylke Bons +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; + +namespace SparkleShare { + + public class Defines { + + public const string VERSION = "@VERSION@"; + public const string LOCALE_DIR = "@prefix@/share/locale"; + public const string GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@"; + public const string PREFIX = "@prefix@"; + + } + +} diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index bf3a3bb3..f107d873 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -12,7 +12,7 @@ // GNU General private License for more details. // // You should have received a copy of the GNU General private License -// along with this program. If not, see . +// along with this program. If not, see . using Gtk; using Mono.Unix; @@ -268,7 +268,7 @@ namespace SparkleShare { } - // Enables or disables the "Next" button depending on the + // Enables or disables the 'Next' button depending on the // entries filled in by the user private void CheckFields () { @@ -361,7 +361,6 @@ namespace SparkleShare { process.StartInfo.FileName = "ssh-keygen"; process.StartInfo.Arguments = "-t rsa -P " + user_email + " -f " + key_file_name; - process.WaitForExit (); process.Start (); process.Exited += delegate { diff --git a/SparkleShare/SparkleRepo.cs b/SparkleShare/SparkleRepo.cs index 3500596a..3dfac41d 100644 --- a/SparkleShare/SparkleRepo.cs +++ b/SparkleShare/SparkleRepo.cs @@ -12,7 +12,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program. If not, see . +// along with this program. If not, see . using Gtk; using Mono.Unix; @@ -25,7 +25,7 @@ using System.Timers; namespace SparkleShare { - // SparkleRepo class holds repository information and timers + // Holds repository information and timers public class SparkleRepo { @@ -55,8 +55,14 @@ namespace SparkleShare { public delegate void PushedEventHandler (object o, SparkleEventArgs args); public event PushedEventHandler Pushed; - public delegate void FetchedEventHandler (object o, SparkleEventArgs args); - public event FetchedEventHandler Fetched; + 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, SparkleEventArgs args); + public event NewCommitEventHandler NewCommit; public static string _ (string s) @@ -221,9 +227,6 @@ namespace SparkleShare { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes staged."); -// SparkleUI.NotificationIcon.SetSyncingState (); -// SparkleUI.NotificationIcon.SetIdleState (); - SparkleEventArgs args = new SparkleEventArgs ("Added"); if (Added != null) @@ -258,7 +261,11 @@ namespace SparkleShare { FetchTimer.Stop (); -// SparkleUI.NotificationIcon.SetSyncingState (); + SparkleEventArgs args; + args = new SparkleEventArgs ("FetchingStarted"); + + if (FetchingStarted != null) + FetchingStarted (this, args); SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes..."); @@ -270,16 +277,15 @@ namespace SparkleShare { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched."); - SparkleEventArgs args = new SparkleEventArgs ("Fetched"); + args = new SparkleEventArgs ("FetchingFinished"); - if (Fetched != null) - Fetched (this, args); + if (FetchingFinished != null) + FetchingFinished (this, args); + // Rebase if there are changes if (!Output.Contains ("up to date")) Rebase (); -// SparkleUI.NotificationIcon.SetIdleState (); - } finally { FetchTimer.Start (); @@ -297,7 +303,7 @@ namespace SparkleShare { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Rebasing changes..."); - Process.StartInfo.Arguments = "rebase origin"; + Process.StartInfo.Arguments = "rebase -v master"; Process.WaitForExit (); Process.Start (); @@ -339,7 +345,7 @@ namespace SparkleShare { Process.Start (); string conflict_title = "A mid-air collision happened!\n"; - string conflict_subtext = "Don't worry, SparkleShare made\na copy of the conflicting files."; + string conflict_subtext = "Don't worry, SparkleShare made\na copy of each conflicting file."; // SparkleBubble ConflictBubble = // new SparkleBubble(_(ConflictTitle), _(ConflictSubtext)); @@ -385,6 +391,11 @@ namespace SparkleShare { 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); diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs index 350f0bc6..edade95e 100644 --- a/SparkleShare/SparkleShare.cs +++ b/SparkleShare/SparkleShare.cs @@ -30,7 +30,6 @@ namespace SparkleShare { return Catalog.GetString (s); } - public static SparkleRepo [] Repositories; public static SparkleUI SparkleUI; public static void Main (string [] args) diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs new file mode 100644 index 00000000..f35d151f --- /dev/null +++ b/SparkleShare/SparkleStatusIcon.cs @@ -0,0 +1,254 @@ +// SparkleShare, an instant update workflow to Git. +// Copyright (C) 2010 Hylke Bons +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using Gtk; +using Mono.Unix; +using SparkleShare; +using System; +using System.Diagnostics; +using System.IO; +using System.Timers; + +namespace SparkleShare { + + public class SparkleStatusIcon : StatusIcon + { + + private Timer Timer; + private int SyncingState; + + public int SyncingReposCount; + + // Short alias for the translations + public static string _ (string s) { + return Catalog.GetString (s); + } + + public EventHandler CreateWindowDelegate (SparkleRepo SparkleRepo) + { + return delegate { + SparkleWindow SparkleWindow = new SparkleWindow (SparkleRepo); + SparkleWindow.ShowAll (); + }; + } + + public SparkleStatusIcon () : base () + { + + Timer = new Timer (); + Activate += ShowMenu; + + SyncingReposCount = 0; + + // 0 = Everything up to date + // 1 = Syncing in progress + // -1 = Error syncing + SyncingState = 0; + + SetIdleState (); + + } + + public void ShowMenu (object o, EventArgs Args) + { + + Menu Menu = new Menu (); + + string StateText = ""; + switch (SyncingState) { + case -1: + StateText = _("Error syncing"); + break; + case 0: + StateText = _("Everything is up to date"); + break; + case 1: + StateText = _("Syncing…"); + break; + } + + MenuItem StatusMenuItem = new MenuItem (StateText); + StatusMenuItem.Sensitive = false; + + Menu.Add (StatusMenuItem); + Menu.Add (new SeparatorMenuItem ()); + + Gtk.Action FolderAction = new Gtk.Action ("", "SparkleShare Folder"); + FolderAction.IconName = "folder-sparkleshare"; + FolderAction.IsImportant = true; + FolderAction.Activated += delegate { + Process Process = new Process (); + switch (SparklePlatform.Name) { + case "GNOME": + Process.StartInfo.FileName = "xdg-open"; + break; + case "OSX": + Process.StartInfo.FileName = "open"; + break; + } + Process.StartInfo.Arguments = SparklePaths.SparklePath; + Process.Start (); + }; + Menu.Add (FolderAction.CreateMenuItem ()); + + Gtk.Action [] FolderItems = + new Gtk.Action [SparkleUI.Repositories.Length]; + + int i = 0; + foreach (SparkleRepo SparkleRepo in SparkleUI.Repositories) { + FolderItems [i] = new Gtk.Action ("", SparkleRepo.Name); + FolderItems [i].IconName = "folder"; + FolderItems [i].IsImportant = true; + FolderItems [i].Activated += CreateWindowDelegate (SparkleRepo); + Menu.Add (FolderItems [i].CreateMenuItem ()); + i++; + } + + MenuItem AddItem = new MenuItem (_("Add Remote Folder…")); + AddItem.Activated += delegate { + SparkleDialog SparkleDialog = new SparkleDialog (""); + SparkleDialog.ShowAll (); + }; + Menu.Add (AddItem); + Menu.Add (new SeparatorMenuItem ()); + + CheckMenuItem NotifyCheckMenuItem = new CheckMenuItem (_("Show Notifications")); + Menu.Add (NotifyCheckMenuItem); + Menu.Add (new SeparatorMenuItem ()); + + string NotifyChangesFileName = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, + "sparkleshare.notify"); + + if (System.IO.File.Exists (NotifyChangesFileName)) + NotifyCheckMenuItem.Active = true; + + NotifyCheckMenuItem.Toggled += delegate { + if (System.IO.File.Exists (NotifyChangesFileName)) { + File.Delete (NotifyChangesFileName); + } else { + System.IO.File.Create (NotifyChangesFileName); + } + }; + + MenuItem AboutItem = new MenuItem (_("About")); + AboutItem.Activated += delegate { + Process Process = new Process (); + switch (SparklePlatform.Name) { + case "GNOME": + Process.StartInfo.FileName = "xdg-open"; + break; + case "OSX": + Process.StartInfo.FileName = "open"; + break; + } + Process.StartInfo.Arguments = "http://www.sparkleshare.org/"; + Process.Start (); + }; + Menu.Add (AboutItem); + + Menu.Add (new SeparatorMenuItem ()); + MenuItem QuitItem = new MenuItem (_("Quit")); + QuitItem.Activated += Quit; + Menu.Add (QuitItem); + Menu.ShowAll (); + Menu.Popup (null, null, SetPosition, 0, Global.CurrentEventTime); + } + + + public void UpdateState () + { + + if (SyncingReposCount > 0) + SetSyncingState (); + else + SetIdleState (); + + } + + + public void SetIdleState () + { + Timer.Stop (); + IconName = "folder-sparkleshare"; + SyncingState = 0; + } + + // Changes the status icon to the syncing animation + // TODO: There are UI freezes when switching back and forth + // bewteen syncing and idle state + public void SetSyncingState () + { + + IconName = "view-refresh"; + + SyncingState = 1; + +/* int CycleDuration = 250; + int CurrentStep = 0; + int Size = 24; + + Gdk.Pixbuf SpinnerGallery = SparkleHelpers.GetIcon ("process-syncing-sparkleshare", Size); + + int FramesInWidth = SpinnerGallery.Width / Size; + int FramesInHeight = SpinnerGallery.Height / Size; + int NumSteps = FramesInWidth * FramesInHeight; + Gdk.Pixbuf [] Images = new Gdk.Pixbuf [NumSteps - 1]; + + int i = 0; + for (int y = 0; y < FramesInHeight; y++) { + for (int x = 0; x < FramesInWidth; x++) { + if (!(y == 0 && x == 0)) { + Images [i] = new Gdk.Pixbuf (SpinnerGallery, x * Size, y * Size, Size, Size); + i++; + } + } + } + + Timer = new Timer (); + Timer.Interval = CycleDuration / NumSteps; + Timer.Elapsed += delegate { + if (CurrentStep < NumSteps) + CurrentStep++; + else + CurrentStep = 0; + Pixbuf = Images [CurrentStep]; + }; + Timer.Start (); +*/ + } + + // Changes the status icon to the error icon + public void SetErrorState () + { + IconName = "folder-sync-error"; + SyncingState = -1; + } + + public void SetPosition (Menu menu, out int x, out int y, out bool push_in) + { + PositionMenu (menu, out x, out y, out push_in, Handle); + } + + // Quits the program + public void Quit (object o, EventArgs args) + { + System.IO.File.Delete (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, "sparkleshare.pid")); + Application.Quit (); + } + + } + +} diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index e2f2deed..5f31c13a 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -12,7 +12,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program. If not, see . +// along with this program. If not, see . using Gtk; using Mono.Unix; @@ -27,6 +27,7 @@ namespace SparkleShare { public class SparkleUI { private Process Process; + public static SparkleRepo [] Repositories; // Short alias for the translations public static string _(string s) @@ -64,7 +65,7 @@ namespace SparkleShare { NotificationIcon = new SparkleStatusIcon (); // Show a notification if there are no folders yet - if (SparkleShare.Repositories.Length == 0) { + if (Repositories.Length == 0) { SparkleBubble NoFoldersBubble; NoFoldersBubble = new SparkleBubble (_("Welcome to SparkleShare!"), @@ -238,11 +239,27 @@ namespace SparkleShare { } - public void Test (object o, SparkleEventArgs args) { + public void ShowNewCommitBubble (object o, SparkleEventArgs args) { Console.WriteLine ("AAAAAAAAAAAAAAAAAA"); } + public void UpdateStatusIcon (object o, SparkleEventArgs args) { + + if (args.Message.Equals ("FetchingStarted")) { + NotificationIcon.SyncingReposCount++; + NotificationIcon.UpdateState (); + } + + if (args.Message.Equals ("FetchingFinished")) { + NotificationIcon.SyncingReposCount--; + NotificationIcon.UpdateState (); + } + + } + + + // TODO: Make this a List instead of an array public void UpdateRepositories () { @@ -257,32 +274,18 @@ namespace SparkleShare { if (Directory.Exists (SparkleHelpers.CombineMore (folder, ".git"))) { TmpRepos [FolderCount] = new SparkleRepo (folder); + TmpRepos [FolderCount].NewCommit += ShowNewCommitBubble; + TmpRepos [FolderCount].FetchingStarted += UpdateStatusIcon; + TmpRepos [FolderCount].FetchingFinished += UpdateStatusIcon; FolderCount++; - // TODO: emblems don't show up in nautilus - // Attach emblems - switch (SparklePlatform.Name) { - case "GNOME": - - Process.StartInfo.FileName = "gvfs-set-attribute"; - Process.StartInfo.Arguments = "-t string \"" + folder + - "\" metadata::emblems [synced]"; - Process.Start (); - - break; - - } - } } - SparkleRepo a = TmpRepos [0]; - a.Added += Test; - - SparkleShare.Repositories = new SparkleRepo [FolderCount]; - Array.Copy (TmpRepos, SparkleShare.Repositories, FolderCount); + Repositories = new SparkleRepo [FolderCount]; + Array.Copy (TmpRepos, Repositories, FolderCount); } diff --git a/SparkleShare/SparkleWindow.cs b/SparkleShare/SparkleWindow.cs index 090aaa0b..0c90cc3d 100644 --- a/SparkleShare/SparkleWindow.cs +++ b/SparkleShare/SparkleWindow.cs @@ -99,13 +99,15 @@ namespace SparkleShare { private ScrolledWindow CreateEventLog () { + int number_of_events = 50; + Process process = new Process (); process.EnableRaisingEvents = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.WorkingDirectory = SparkleRepo.LocalPath; process.StartInfo.FileName = "git"; - process.StartInfo.Arguments = "log --format=\"%at☃%an☃%ae☃%s\" -50"; + process.StartInfo.Arguments = "log --format=\"%at☃%an☃%ae☃%s\" -" + number_of_events; string output = ""; @@ -122,7 +124,7 @@ namespace SparkleShare { List activity_days = new List (); - for (int i = 0; i < 25 && i < lines.Length; i++) { + for (int i = 0; i < number_of_events && i < lines.Length; i++) { string line = lines [i]; @@ -214,7 +216,7 @@ namespace SparkleShare { } - layout_vertical.PackStart (date_label, true, true, 0); + layout_vertical.PackStart (date_label, false, false, 0); IconView icon_view = new IconView (list_store) { ItemWidth = 480, @@ -224,7 +226,7 @@ namespace SparkleShare { Spacing = 9 }; - layout_vertical.PackStart (icon_view); + layout_vertical.PackStart (icon_view, false, false, 0); }