[about] Move version checking to [controller] with events

This commit is contained in:
Hylke Bons 2011-03-24 10:22:10 +00:00
parent dc003cba89
commit 2f4922d5b7
2 changed files with 125 additions and 103 deletions

View file

@ -45,11 +45,30 @@ namespace SparkleShare {
BorderWidth = 0;
IconName = "folder-sparkleshare";
Resizable = true;
WindowPosition = WindowPosition.Center;
Title = "About SparkleShare";
Resizable = false;
CreateAbout ();
SparkleShare.Controller.CheckForNewVersion ();
SparkleShare.Controller.NewVersionAvailable += delegate (string new_version) {
ApplicationId.Invoke (delegate {
Version.Markup = "<small><span fgcolor='#f57900'>A newer version (" + new_version + ") is available!</span></small>";
Version.ShowAll ();
});
};
}
private void CreateAbout ()
{
Gdk.Color color = Style.Foreground (StateType.Insensitive);
string secondary_text_color = SparkleUIHelpers.GdkColorToHex (color);
@ -135,49 +154,6 @@ 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);
}
}
}

View file

@ -77,6 +77,12 @@ 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)
@ -1286,6 +1292,46 @@ namespace SparkleShare {
}
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);
}
}