[about] Move version checking to [controller] with events
This commit is contained in:
parent
353a2f58ad
commit
11557974c5
|
@ -45,11 +45,30 @@ namespace SparkleShare {
|
||||||
|
|
||||||
BorderWidth = 0;
|
BorderWidth = 0;
|
||||||
IconName = "folder-sparkleshare";
|
IconName = "folder-sparkleshare";
|
||||||
Resizable = true;
|
|
||||||
WindowPosition = WindowPosition.Center;
|
WindowPosition = WindowPosition.Center;
|
||||||
Title = "About SparkleShare";
|
Title = "About SparkleShare";
|
||||||
Resizable = false;
|
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);
|
Gdk.Color color = Style.Foreground (StateType.Insensitive);
|
||||||
string secondary_text_color = SparkleUIHelpers.GdkColorToHex (color);
|
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,12 @@ namespace SparkleShare {
|
||||||
public delegate void NotificationRaisedEventHandler (string user_name, string user_email,
|
public delegate void NotificationRaisedEventHandler (string user_name, string user_email,
|
||||||
string message, string repository_path);
|
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
|
// Short alias for the translations
|
||||||
public static string _ (string s)
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue