diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index 8a8a333b..3d5f55da 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -259,40 +259,45 @@ namespace SparkleLib { public void Fetch () { - try { + FetchTimer.Stop (); - FetchTimer.Stop (); + Process process = new Process () { + EnableRaisingEvents = true + }; - SparkleEventArgs args; - args = new SparkleEventArgs ("FetchingStarted"); + process.StartInfo.FileName = "git"; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.WorkingDirectory = LocalPath; - if (FetchingStarted != null) - FetchingStarted (this, args); + SparkleEventArgs args; + args = new SparkleEventArgs ("FetchingStarted"); - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes..."); + if (FetchingStarted != null) + FetchingStarted (this, args); - Process.StartInfo.Arguments = "fetch"; + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes..."); - Process.Start (); + process.StartInfo.Arguments = "fetch"; - Process.Exited += delegate { + process.Start (); - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched."); + process.Exited += delegate { - args = new SparkleEventArgs ("FetchingFinished"); + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched."); - if (FetchingFinished != null) - FetchingFinished (this, args); + // TODO: this doesn't exit sometimes - Rebase (); + args = new SparkleEventArgs ("FetchingFinished"); - }; + if (FetchingFinished != null) + FetchingFinished (this, args); - } finally { + Rebase (); FetchTimer.Start (); - } + }; } diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs index 773e40c8..b29cbae0 100644 --- a/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/SparkleStatusIcon.cs @@ -35,6 +35,8 @@ namespace SparkleShare { private string StateText; private Gdk.Pixbuf [] AnimationFrames; private int FrameNumber; + private Gtk.Action FolderAction; + private double FolderSize; // Short alias for the translations @@ -46,6 +48,8 @@ namespace SparkleShare { public SparkleStatusIcon () : base () { + FolderSize = GetFolderSize (new DirectoryInfo (SparklePaths.SparklePath)); + CreateAnimationFrames (); CreateTimer (); @@ -112,9 +116,48 @@ namespace SparkleShare { } + private double GetFolderSize (DirectoryInfo parent) + { + + double size = 0; + + FileInfo [] files = parent.GetFiles(); + + foreach (FileInfo file in files) + size += file.Length; + + foreach (DirectoryInfo directory in parent.GetDirectories()) + size += GetFolderSize (directory); + + return size; + + } + + + private string GetSize (double byte_count) + { + + string size = ""; + + if (byte_count >= 1099511627776) + size = String.Format ("{0:##.##}", Math.Round (byte_count / 1099511627776, 1)) + " TB"; + else if (byte_count >= 1073741824) + size = String.Format ("{0:##.##}", Math.Round (byte_count / 1073741824, 1)) + " GB"; + else if (byte_count >= 1048576) + size = String.Format ("{0:##.##}", Math.Round (byte_count / 1048576, 1)) + " MB"; + else if (byte_count >= 1024) + size = String.Format ("{0:##.##}", Math.Round (byte_count / 1024, 1)) + " KB"; + else + size = byte_count.ToString () + " bytes"; + + return size; + + } + + // Creates the menu that is popped up when the // user clicks the statusicon - private void CreateMenu () + public void CreateMenu () { Menu = new Menu (); @@ -127,13 +170,12 @@ namespace SparkleShare { Menu.Add (new SeparatorMenuItem ()); - // TODO: Append folder size in secondary text color - Gtk.Action folder_action = new Gtk.Action ("", _("SparkleShare Folder")) { + FolderAction = new Gtk.Action ("", "SparkleShare Folder (" + GetSize (FolderSize) + ")") { IconName = "folder-sparkleshare", IsImportant = true }; - folder_action.Activated += delegate { + FolderAction.Activated += delegate { Process process = new Process (); process.StartInfo.FileName = "xdg-open"; @@ -142,20 +184,20 @@ namespace SparkleShare { }; - Menu.Add (folder_action.CreateMenuItem ()); + Menu.Add (FolderAction.CreateMenuItem ()); if (SparkleUI.Repositories.Count > 0) { foreach (SparkleRepo SparkleRepo in SparkleUI.Repositories) { - folder_action = new Gtk.Action ("", SparkleRepo.Name) { + FolderAction = new Gtk.Action ("", SparkleRepo.Name) { IconName = "folder", IsImportant = true }; - folder_action.Activated += CreateWindowDelegate (SparkleRepo); + FolderAction.Activated += CreateWindowDelegate (SparkleRepo); - Menu.Add (folder_action.CreateMenuItem ()); + Menu.Add (FolderAction.CreateMenuItem ()); } @@ -259,6 +301,8 @@ namespace SparkleShare { SetIdleState (); UpdateStatusMenuItem (); + + Console.WriteLine ("Number of repos syncing: " + SyncingReposCount); } diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index 6cec2384..3d03e6b2 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -181,7 +181,7 @@ namespace SparkleShare { "Exec=sparkleshare start\n" + "Icon=folder-sparkleshare\n" + "Terminal=false\n" + - "Categories=Network"); + "Categories=Network;"); writer.Close (); // Give the launcher the right permissions so it can be launched by the user @@ -199,6 +199,8 @@ namespace SparkleShare { public void AddToBookmarks () { + // TODO: don't add when the bookmark is already there + string bookmarks_file_name = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks"); if (File.Exists (bookmarks_file_name)) { @@ -327,6 +329,10 @@ namespace SparkleShare { } + // Update the list in the statusicon + if (NotificationIcon != null) + NotificationIcon.CreateMenu (); + } } diff --git a/SparkleShare/sparkleshare.desktop b/SparkleShare/sparkleshare.desktop index c747b105..a83f45d4 100644 --- a/SparkleShare/sparkleshare.desktop +++ b/SparkleShare/sparkleshare.desktop @@ -5,4 +5,4 @@ Exec=sparkleshare start Icon=folder-sparkleshare Terminal=false X-GNOME-Autostart-enabled=true -Categories=Network +Categories=Network;