From 7f50a22d3d4b03e221fd8ce2d4f4631e9802fc87 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 23 Mar 2011 10:59:42 +0000 Subject: [PATCH 1/4] [about] some version check work --- SparkleShare/SparkleAbout.cs | 60 +++++++++++++++++++++++++++++-- SparkleShare/SparkleStatusIcon.cs | 4 +-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/SparkleShare/SparkleAbout.cs b/SparkleShare/SparkleAbout.cs index d2ef2a3d..6f9ef684 100644 --- a/SparkleShare/SparkleAbout.cs +++ b/SparkleShare/SparkleAbout.cs @@ -17,6 +17,8 @@ using System; using System.Diagnostics; +using System.IO; +using System.Net; using Gtk; using SparkleLib; @@ -24,7 +26,10 @@ using Mono.Unix; namespace SparkleShare { - public class SparkleDialog : Window { + public class SparkleAbout : Window { + + private Label Version; + // Short alias for the translations public static string _(string s) @@ -33,7 +38,7 @@ namespace SparkleShare { } - public SparkleDialog () : base ("") + public SparkleAbout () : base ("") { DefaultSize = new Gdk.Size (360, 260); @@ -62,6 +67,13 @@ namespace SparkleShare { box.Add (header); + Version = new Label () { + Markup = "Checking for updates...", + Xalign = 0, + Xpad = 18, + Ypad = 22, + }; + Label license = new Label () { Xalign = 0, Xpad = 18, @@ -115,6 +127,7 @@ namespace SparkleShare { button_bar.Add (credits_button); vbox.PackStart (box, true, true, 0); + vbox.PackStart (Version, false, false, 0); vbox.PackStart (license, true, true, 0); vbox.PackStart (button_bar, false, false, 0); @@ -122,6 +135,49 @@ namespace SparkleShare { } + + // TODO: Move to controller + private void CheckForNewVersion () + { + + string new_version_file_path = System.IO.Path.Combine (SparklePaths.SparkleTmpPath, + "version"); + + if (File.Exists (new_version_file_path)) + File.Delete (new_version_file_path); + + WebClient web_client = new WebClient (); + Uri uri = new Uri ("http://www.sparkleshare.org/version"); + + web_client.DownloadFileCompleted += delegate { + + if (new FileInfo (new_version_file_path).Length > 0) { + + StreamReader reader = new StreamReader (new_version_file_path); + string downloaded_version_number = reader.ReadToEnd ().Trim (); + + if (!Defines.VERSION.Equals (downloaded_version_number)) { + + Application.Invoke (delegate { + + + + }); + + } else { + + + + } + + } + + }; + + web_client.DownloadFileAsync (uri, new_version_file_path); + + } + } } diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs index df047f86..0c8d22f8 100644 --- a/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/SparkleStatusIcon.cs @@ -244,8 +244,8 @@ namespace SparkleShare { about_item.Activated += delegate { - SparkleDialog dialog = new SparkleDialog (); - dialog.ShowAll (); + SparkleAbout about = new SparkleAbout (); + about.ShowAll (); }; From 6310ba1f76a7de121d59b784ec5f23ce1a4c0e6c Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 24 Mar 2011 10:22:10 +0000 Subject: [PATCH 2/4] [about] Move version checking to [controller] with events --- SparkleShare/SparkleAbout.cs | 180 +++++++++++++----------------- SparkleShare/SparkleController.cs | 48 +++++++- 2 files changed, 125 insertions(+), 103 deletions(-) diff --git a/SparkleShare/SparkleAbout.cs b/SparkleShare/SparkleAbout.cs index 6f9ef684..6d086f2f 100644 --- a/SparkleShare/SparkleAbout.cs +++ b/SparkleShare/SparkleAbout.cs @@ -45,138 +45,114 @@ namespace SparkleShare { BorderWidth = 0; IconName = "folder-sparkleshare"; - Resizable = true; WindowPosition = WindowPosition.Center; Title = "About SparkleShare"; Resizable = false; - Gdk.Color color = Style.Foreground (StateType.Insensitive); - string secondary_text_color = SparkleUIHelpers.GdkColorToHex (color); + CreateAbout (); + + SparkleShare.Controller.CheckForNewVersion (); + SparkleShare.Controller.NewVersionAvailable += delegate (string new_version) { + + ApplicationId.Invoke (delegate { + + Version.Markup = "A newer version (" + new_version + ") is available!"; + Version.ShowAll (); + + }); + + }; + + } - EventBox box = new EventBox (); - box.ModifyBg (StateType.Normal, new TreeView ().Style.Base (StateType.Normal)); + private void CreateAbout () + { - Label header = new Label () { - Markup = "SparkleShare\n" + Defines.VERSION + "", - Xalign = 0, - Xpad = 18, - Ypad = 18 + Gdk.Color color = Style.Foreground (StateType.Insensitive); + string secondary_text_color = SparkleUIHelpers.GdkColorToHex (color); - }; - box.Add (header); + EventBox box = new EventBox (); + box.ModifyBg (StateType.Normal, new TreeView ().Style.Base (StateType.Normal)); - Version = new Label () { - Markup = "Checking for updates...", - Xalign = 0, - Xpad = 18, - Ypad = 22, - }; + Label header = new Label () { + Markup = "SparkleShare\n" + Defines.VERSION + "", + Xalign = 0, + Xpad = 18, + Ypad = 18 - Label license = new Label () { - Xalign = 0, - Xpad = 18, - Ypad = 22, - LineWrap = true, - Wrap = true, - LineWrapMode = Pango.WrapMode.Word, + }; - Markup = "Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others\n" + + box.Add (header); + + Version = new Label () { + Markup = "Checking for updates...", + Xalign = 0, + Xpad = 18, + Ypad = 22, + }; + + Label license = new Label () { + Xalign = 0, + Xpad = 18, + Ypad = 22, + LineWrap = true, + Wrap = true, + LineWrapMode = Pango.WrapMode.Word, + + Markup = "Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others\n" + "\n" + "SparkleShare is Free and Open Source Software. " + "You are free to use, modify, and redistribute it " + "under the terms of the GNU General Public License version 3 or later." - }; + }; - VBox vbox = new VBox (false, 0) { - BorderWidth = 0 - }; + VBox vbox = new VBox (false, 0) { + BorderWidth = 0 + }; - HButtonBox button_bar = new HButtonBox () { - BorderWidth = 12 - }; + HButtonBox button_bar = new HButtonBox () { + BorderWidth = 12 + }; - Button credits_button = new Button (_("_Show Credits")) { - UseUnderline = true - }; + Button credits_button = new Button (_("_Show Credits")) { + UseUnderline = true + }; - credits_button.Clicked += delegate { - - Process process = new Process (); - process.StartInfo.FileName = "xdg-open"; - process.StartInfo.Arguments = "http://www.sparkleshare.org/credits"; - process.Start (); + credits_button.Clicked += delegate { - }; + Process process = new Process (); + process.StartInfo.FileName = "xdg-open"; + process.StartInfo.Arguments = "http://www.sparkleshare.org/credits"; + process.Start (); - Button website_button = new Button (_("_Visit Website")) { - UseUnderline = true - }; - - website_button.Clicked += delegate { + }; - Process process = new Process (); - process.StartInfo.FileName = "xdg-open"; - process.StartInfo.Arguments = "http://www.sparkleshare.org/"; - process.Start (); + Button website_button = new Button (_("_Visit Website")) { + UseUnderline = true + }; - }; + website_button.Clicked += delegate { - button_bar.Add (website_button); - button_bar.Add (credits_button); + Process process = new Process (); + process.StartInfo.FileName = "xdg-open"; + process.StartInfo.Arguments = "http://www.sparkleshare.org/"; + process.Start (); - vbox.PackStart (box, true, true, 0); - vbox.PackStart (Version, false, false, 0); - vbox.PackStart (license, true, true, 0); - vbox.PackStart (button_bar, false, false, 0); + }; - Add (vbox); + button_bar.Add (website_button); + button_bar.Add (credits_button); - } + vbox.PackStart (box, true, true, 0); + vbox.PackStart (Version, false, false, 0); + vbox.PackStart (license, true, true, 0); + vbox.PackStart (button_bar, false, false, 0); + Add (vbox); - // TODO: Move to controller - private void CheckForNewVersion () - { - - string new_version_file_path = System.IO.Path.Combine (SparklePaths.SparkleTmpPath, - "version"); - - if (File.Exists (new_version_file_path)) - File.Delete (new_version_file_path); - - WebClient web_client = new WebClient (); - Uri uri = new Uri ("http://www.sparkleshare.org/version"); - - web_client.DownloadFileCompleted += delegate { - - if (new FileInfo (new_version_file_path).Length > 0) { - - StreamReader reader = new StreamReader (new_version_file_path); - string downloaded_version_number = reader.ReadToEnd ().Trim (); - - if (!Defines.VERSION.Equals (downloaded_version_number)) { - - Application.Invoke (delegate { - - - - }); - - } else { - - - - } - - } - - }; - - web_client.DownloadFileAsync (uri, new_version_file_path); - - } + } } diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 8cdcf15f..dac29bea 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -77,7 +77,13 @@ namespace SparkleShare { public delegate void NotificationRaisedEventHandler (string user_name, string user_email, string message, string repository_path); + public event NewVersionAvailableEventHandler NewVersionAvailable; + public delegate void NewVersionAvailableEventHandler (string new_version); + public event VersionUpToDateEventHandler VersionUpToDate; + public delegate void VersionUpToDateEventHandler (); + + // Short alias for the translations public static string _ (string s) { @@ -1279,7 +1285,47 @@ namespace SparkleShare { return regex.IsMatch (email); } - + + + private void CheckForNewVersion () + { + + string new_version_file_path = System.IO.Path.Combine (SparklePaths.SparkleTmpPath, + "version"); + + if (File.Exists (new_version_file_path)) + File.Delete (new_version_file_path); + + WebClient web_client = new WebClient (); + Uri uri = new Uri ("http://www.sparkleshare.org/version"); + + web_client.DownloadFileCompleted += delegate { + + if (new FileInfo (new_version_file_path).Length > 0) { + + StreamReader reader = new StreamReader (new_version_file_path); + string downloaded_version_number = reader.ReadToEnd ().Trim (); + + if (!Defines.VERSION.Equals (downloaded_version_number)) { + + if (NewVersionAvailable != null) + NewVersionAvailable (downloaded_version_number); + + } else { + + if (VersionUpToDate != null) + VersionUpToDate (); + + } + + } + + }; + + web_client.DownloadFileAsync (uri, new_version_file_path); + + } + } From 0749c1a5ce4ba1657f99116a8577d5a2c0badd81 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 24 Mar 2011 10:28:05 +0000 Subject: [PATCH 3/4] [about] hook up VersionUpToDate event --- SparkleShare/SparkleAbout.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/SparkleShare/SparkleAbout.cs b/SparkleShare/SparkleAbout.cs index 6d086f2f..1ed2f129 100644 --- a/SparkleShare/SparkleAbout.cs +++ b/SparkleShare/SparkleAbout.cs @@ -50,8 +50,8 @@ namespace SparkleShare { Resizable = false; CreateAbout (); - SparkleShare.Controller.CheckForNewVersion (); + SparkleShare.Controller.NewVersionAvailable += delegate (string new_version) { ApplicationId.Invoke (delegate { @@ -61,6 +61,18 @@ namespace SparkleShare { }); + }; + + + SparkleShare.Controller.VersionUpToDate += delegate { + + ApplicationId.Invoke (delegate { + + Version.Markup = "You are running the latest version."; + Version.ShowAll (); + + }); + }; } From 2adedd88f989fa05a917edaa7abf1f31b82280ac Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 25 Mar 2011 10:24:46 +0000 Subject: [PATCH 4/4] [controller] Prevent some crashes clicking logs byy only showing them once the list is done loading --- SparkleShare/SparkleController.cs | 53 +++++++++++++++++-------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index dac29bea..e8f80b61 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -137,11 +137,22 @@ namespace SparkleShare { RemoveRepository (args.FullPath); + if (FolderListChanged != null) + FolderListChanged (); + + + FolderSize = GetFolderSize (); + + if (FolderSizeChanged != null) + FolderSizeChanged (FolderSize); + }; // Add the repository when a create event occurs watcher.Created += delegate (object o, FileSystemEventArgs args) { - + + // TODO: Needs to wait until the copying over is done + // Handle invitations when the user saves an // invitation into the SparkleShare folder if (args.Name.EndsWith (".sparkle") && !FirstRun) { @@ -153,15 +164,22 @@ namespace SparkleShare { string folder = xml_doc.GetElementsByTagName ("folder") [0].InnerText; string token = xml_doc.GetElementsByTagName ("token") [0].InnerText; - // TODO: this is broken :\ + // FIXME: this is broken :\ if (OnInvitation != null) OnInvitation (server, folder, token); - // FIXME: big repos seem to often fail because they don't pass this test } else if (SparkleRepo.IsRepo (args.FullPath)) { AddRepository (args.FullPath); + if (FolderListChanged != null) + FolderListChanged (); + + FolderSize = GetFolderSize (); + + if (FolderSizeChanged != null) + FolderSizeChanged (FolderSize); + } }; @@ -589,16 +607,6 @@ namespace SparkleShare { Repositories.Add (repo); - - if (FolderListChanged != null) - FolderListChanged (); - - - FolderSize = GetFolderSize (); - - if (FolderSizeChanged != null) - FolderSizeChanged (FolderSize); - } @@ -624,16 +632,6 @@ namespace SparkleShare { } - - if (FolderListChanged != null) - FolderListChanged (); - - - FolderSize = GetFolderSize (); - - if (FolderSizeChanged != null) - FolderSizeChanged (FolderSize); - } @@ -647,6 +645,15 @@ namespace SparkleShare { foreach (string folder_path in Directory.GetDirectories (SparklePaths.SparklePath)) AddRepository (folder_path); + if (FolderListChanged != null) + FolderListChanged (); + + + FolderSize = GetFolderSize (); + + if (FolderSizeChanged != null) + FolderSizeChanged (FolderSize); + }