[about] Move version checking to [controller] with events
This commit is contained in:
parent
353a2f58ad
commit
11557974c5
|
@ -45,138 +45,114 @@ 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;
|
||||||
|
|
||||||
Gdk.Color color = Style.Foreground (StateType.Insensitive);
|
CreateAbout ();
|
||||||
string secondary_text_color = SparkleUIHelpers.GdkColorToHex (color);
|
|
||||||
|
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 ();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EventBox box = new EventBox ();
|
private void CreateAbout ()
|
||||||
box.ModifyBg (StateType.Normal, new TreeView ().Style.Base (StateType.Normal));
|
{
|
||||||
|
|
||||||
Label header = new Label () {
|
Gdk.Color color = Style.Foreground (StateType.Insensitive);
|
||||||
Markup = "<span font_size='xx-large'>SparkleShare</span>\n<span fgcolor='" + secondary_text_color + "'><small>" + Defines.VERSION + "</small></span>",
|
string secondary_text_color = SparkleUIHelpers.GdkColorToHex (color);
|
||||||
Xalign = 0,
|
|
||||||
Xpad = 18,
|
|
||||||
Ypad = 18
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
box.Add (header);
|
EventBox box = new EventBox ();
|
||||||
|
box.ModifyBg (StateType.Normal, new TreeView ().Style.Base (StateType.Normal));
|
||||||
|
|
||||||
Version = new Label () {
|
Label header = new Label () {
|
||||||
Markup = "<small>Checking for updates...</small>",
|
Markup = "<span font_size='xx-large'>SparkleShare</span>\n<span fgcolor='" + secondary_text_color + "'><small>" + Defines.VERSION + "</small></span>",
|
||||||
Xalign = 0,
|
Xalign = 0,
|
||||||
Xpad = 18,
|
Xpad = 18,
|
||||||
Ypad = 22,
|
Ypad = 18
|
||||||
};
|
|
||||||
|
|
||||||
Label license = new Label () {
|
};
|
||||||
Xalign = 0,
|
|
||||||
Xpad = 18,
|
|
||||||
Ypad = 22,
|
|
||||||
LineWrap = true,
|
|
||||||
Wrap = true,
|
|
||||||
LineWrapMode = Pango.WrapMode.Word,
|
|
||||||
|
|
||||||
Markup = "<small>Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others\n" +
|
box.Add (header);
|
||||||
|
|
||||||
|
Version = new Label () {
|
||||||
|
Markup = "<small>Checking for updates...</small>",
|
||||||
|
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 = "<small>Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"SparkleShare is Free and Open Source Software. " +
|
"SparkleShare is Free and Open Source Software. " +
|
||||||
"You are free to use, modify, and redistribute it " +
|
"You are free to use, modify, and redistribute it " +
|
||||||
"under the terms of the GNU General Public License version 3 or later.</small>"
|
"under the terms of the GNU General Public License version 3 or later.</small>"
|
||||||
};
|
};
|
||||||
|
|
||||||
VBox vbox = new VBox (false, 0) {
|
VBox vbox = new VBox (false, 0) {
|
||||||
BorderWidth = 0
|
BorderWidth = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
HButtonBox button_bar = new HButtonBox () {
|
HButtonBox button_bar = new HButtonBox () {
|
||||||
BorderWidth = 12
|
BorderWidth = 12
|
||||||
};
|
};
|
||||||
|
|
||||||
Button credits_button = new Button (_("_Show Credits")) {
|
Button credits_button = new Button (_("_Show Credits")) {
|
||||||
UseUnderline = true
|
UseUnderline = true
|
||||||
};
|
};
|
||||||
|
|
||||||
credits_button.Clicked += delegate {
|
credits_button.Clicked += delegate {
|
||||||
|
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.FileName = "xdg-open";
|
|
||||||
process.StartInfo.Arguments = "http://www.sparkleshare.org/credits";
|
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
};
|
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 ();
|
Button website_button = new Button (_("_Visit Website")) {
|
||||||
process.StartInfo.FileName = "xdg-open";
|
UseUnderline = true
|
||||||
process.StartInfo.Arguments = "http://www.sparkleshare.org/";
|
};
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
};
|
website_button.Clicked += delegate {
|
||||||
|
|
||||||
button_bar.Add (website_button);
|
Process process = new Process ();
|
||||||
button_bar.Add (credits_button);
|
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,13 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -1285,7 +1291,47 @@ namespace SparkleShare {
|
||||||
return regex.IsMatch (email);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue