add a controller for the about dialog

This commit is contained in:
Hylke Bons 2011-07-09 01:42:43 +01:00
parent bf2078b396
commit 5db31e9f8e
6 changed files with 145 additions and 102 deletions

View file

@ -24,14 +24,15 @@ using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit;
namespace SparkleShare {
public class SparkleAbout : NSWindow {
private NSButton WebsiteButton;
private NSButton CreditsButton;
private NSBox Box;
private NSTextField HeaderTextField;
public SparkleAboutController Controller = new SparkleAboutController ();
private NSImage AboutImage;
private NSImageView AboutImageView;
private NSTextField VersionTextField;
private NSTextField UpdatesTextField;
private NSTextField CreditsTextField;
@ -41,21 +42,22 @@ namespace SparkleShare {
public SparkleAbout () : base ()
{
SetFrame (new RectangleF (0, 0, 360, 288), true);
SetFrame (new RectangleF (0, 0, 640, 281), true);
Center ();
Delegate = new SparkleAboutDelegate ();
StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled);
Title = "About SparkleShare";
MaxSize = new SizeF (360, 288);
MinSize = new SizeF (360, 288);
MaxSize = new SizeF (640, 281);
MinSize = new SizeF (640, 281);
HasShadow = true;
BackingType = NSBackingStore.Buffered;
CreateAbout ();
OrderFrontRegardless ();
MakeKeyAndOrderFront (this);
SparkleShare.Controller.NewVersionAvailable += delegate (string new_version) {
Controller.NewVersionEvent += delegate (string new_version) {
InvokeOnMainThread (delegate {
UpdatesTextField.StringValue = "A newer version (" + new_version + ") is available!";
UpdatesTextField.TextColor =
@ -63,7 +65,7 @@ namespace SparkleShare {
});
};
SparkleShare.Controller.VersionUpToDate += delegate {
Controller.VersionUpToDateEvent += delegate {
InvokeOnMainThread (delegate {
UpdatesTextField.StringValue = "You are running the latest version.";
UpdatesTextField.TextColor =
@ -71,103 +73,83 @@ namespace SparkleShare {
});
};
CheckForNewVersion ();
}
public void CheckForNewVersion ()
{
SparkleShare.Controller.CheckForNewVersion ();
Controller.CheckingForNewVersionEvent += delegate {
InvokeOnMainThread (delegate {
UpdatesTextField.StringValue = "Checking for updates...";
UpdatesTextField.TextColor = NSColor.DisabledControlText;
});
};
}
private void CreateAbout ()
{
Box = new NSBox () {
FillColor = NSColor.White,
Frame = new RectangleF (-1, Frame.Height - 105, Frame.Width + 2, 105),
BoxType = NSBoxType.NSBoxCustom
string about_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"Pixmaps", "about.png");
AboutImage = new NSImage (about_image_path) {
Size = new SizeF (640, 260)
};
HeaderTextField = new NSTextField () {
StringValue = "SparkleShare",
Frame = new RectangleF (22, Frame.Height - 89, 318, 48),
BackgroundColor = NSColor.White,
Bordered = false,
Editable = false,
Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Condensed, 0, 24)
AboutImageView = new NSImageView () {
Image = AboutImage,
Frame = new RectangleF (0, 0, 640, 260)
};
VersionTextField = new NSTextField () {
StringValue = SparkleShare.Controller.Version,
Frame = new RectangleF (22, Frame.Height - 94, 318, 22),
StringValue = "version " + Controller.RunningVersion,
Frame = new RectangleF (295, 140, 318, 22),
BackgroundColor = NSColor.White,
Bordered = false,
Editable = false,
DrawsBackground = false,
TextColor = NSColor.White,
Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
TextColor = NSColor.DisabledControlText
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11)
};
UpdatesTextField = new NSTextField () {
StringValue = "Checking for updates...",
Frame = new RectangleF (22, Frame.Height - 222, 318, 98),
BackgroundColor = NSColor.WindowBackground,
Frame = new RectangleF (295, Frame.Height - 232, 318, 98),
Bordered = false,
Editable = false,
DrawsBackground = false,
Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
TextColor = NSColor.DisabledControlText
};
CreditsTextField = new NSTextField () {
StringValue = @"Copyright © 2010" + DateTime.Now.Year + " Hylke Bons and others" +
StringValue = @"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 GNU General Public License version 3 or later.",
Frame = new RectangleF (22, Frame.Height - 250, 318, 98),
BackgroundColor = NSColor.WindowBackground,
Frame = new RectangleF (295, Frame.Height - 260, 318, 98),
TextColor = NSColor.White,
DrawsBackground = false,
Bordered = false,
Editable = false,
Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
};
WebsiteButton = new NSButton () {
Frame = new RectangleF (12, 12, 120, 32),
Title = "Visit Website",
BezelStyle = NSBezelStyle.Rounded,
Font = SparkleUI.Font
};
// WebsiteButton.Activated += delegate {
// NSUrl url = new NSUrl ("http://www.sparkleshare.org/");
// NSWorkspace.SharedWorkspace.OpenUrl (url);
// };
WebsiteButton.Activated += delegate {
NSUrl url = new NSUrl ("http://www.sparkleshare.org/");
NSWorkspace.SharedWorkspace.OpenUrl (url);
};
// CreditsButton.Activated += delegate {
// NSUrl url = new NSUrl ("http://www.sparkleshare.org/credits/");
// NSWorkspace.SharedWorkspace.OpenUrl (url);
// };
CreditsButton = new NSButton () {
Frame = new RectangleF (Frame.Width - 12 - 120, 12, 120, 32),
Title = "Show Credits",
BezelStyle = NSBezelStyle.Rounded,
Font = SparkleUI.Font
};
ContentView.AddSubview (AboutImageView);
CreditsButton.Activated += delegate {
NSUrl url = new NSUrl ("http://www.sparkleshare.org/credits/");
NSWorkspace.SharedWorkspace.OpenUrl (url);
};
ContentView.AddSubview (Box);
ContentView.AddSubview (HeaderTextField);
ContentView.AddSubview (VersionTextField);
ContentView.AddSubview (UpdatesTextField);
ContentView.AddSubview (CreditsTextField);
ContentView.AddSubview (CreditsButton);
ContentView.AddSubview (WebsiteButton);
}
}

View file

@ -0,0 +1,95 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Net;
using System.Threading;
using System.Timers;
using SparkleLib;
namespace SparkleShare {
public class SparkleAboutController {
public event NewVersionEventHandler NewVersionEvent;
public delegate void NewVersionEventHandler (string new_version);
public event VersionUpToDateEventHandler VersionUpToDateEvent;
public delegate void VersionUpToDateEventHandler ();
public event CheckingForNewVersionEventHandler CheckingForNewVersionEvent;
public delegate void CheckingForNewVersionEventHandler ();
public string RunningVersion {
get {
return SparkleBackend.Version;
}
}
// Check for a new version once a day
private System.Timers.Timer version_checker = new System.Timers.Timer () {
Enabled = true,
Interval = 24 * 60 * 60 * 1000
};
public SparkleAboutController ()
{
CheckForNewVersion ();
this.version_checker.Elapsed += delegate {
CheckForNewVersion ();
};
}
public void CheckForNewVersion ()
{
this.version_checker.Stop ();
if (CheckingForNewVersionEvent != null)
CheckingForNewVersionEvent ();
WebClient web_client = new WebClient ();
Uri uri = new Uri ("http://www.sparkleshare.org/version");
web_client.DownloadStringCompleted += delegate (object o, DownloadStringCompletedEventArgs args) {
if (args.Error != null)
return;
string new_version = args.Result.Trim ();
// Add a little delay, making it seems we're
// actually doing hard work
Thread.Sleep (2 * 1000);
if (RunningVersion.Equals (new_version)) {
if (VersionUpToDateEvent != null)
VersionUpToDateEvent ();
} else {
if (NewVersionEvent != null)
NewVersionEvent (new_version);
}
this.version_checker.Start ();
};
web_client.DownloadStringAsync (uri);
}
}
}

View file

@ -103,6 +103,7 @@
<Compile Include="..\SparkleStatusIconController.cs">
<Link>SparkleStatusIconController.cs</Link>
</Compile>
<Compile Include="SparkleAboutController.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainMenu.xib" />
@ -258,6 +259,9 @@
<Content Include="..\..\po\zh_TW.po">
<Link>Translations\zh_TW.po</Link>
</Content>
<Content Include="..\..\data\about.png">
<Link>Pixmaps\about.png</Link>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Pixmaps\" />

View file

@ -268,10 +268,6 @@ namespace SparkleShare {
if (SparkleUI.About == null)
SparkleUI.About = new SparkleAbout ();
SparkleUI.About.OrderFrontRegardless ();
SparkleUI.About.MakeKeyAndOrderFront (this);
SparkleUI.About.CheckForNewVersion ();
});
};

View file

@ -75,12 +75,6 @@ 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)
@ -1058,11 +1052,6 @@ namespace SparkleShare {
}
public string Version {
get {
return SparkleBackend.Version;
}
}
public void AddNoteToFolder (string folder_name, string revision, string note)
@ -1074,29 +1063,6 @@ namespace SparkleShare {
}
public void CheckForNewVersion ()
{
WebClient web_client = new WebClient ();
Uri uri = new Uri ("http://www.sparkleshare.org/version");
web_client.DownloadStringCompleted += delegate (object o, DownloadStringCompletedEventArgs args) {
if (args.Error != null)
return;
string new_version = args.Result.Trim ();
if (Version.Equals (new_version)) {
if (VersionUpToDate != null)
VersionUpToDate ();
} else {
if (NewVersionAvailable != null)
NewVersionAvailable (new_version);
}
};
web_client.DownloadStringAsync (uri);
}
private string [] tango_palette = new string [] {"#eaab00", "#e37222",

BIN
data/about.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB