add a controller for the about dialog
This commit is contained in:
parent
e0882bbca7
commit
eb8919847e
|
@ -24,14 +24,15 @@ using MonoMac.AppKit;
|
||||||
using MonoMac.ObjCRuntime;
|
using MonoMac.ObjCRuntime;
|
||||||
using MonoMac.WebKit;
|
using MonoMac.WebKit;
|
||||||
|
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleAbout : NSWindow {
|
public class SparkleAbout : NSWindow {
|
||||||
|
|
||||||
private NSButton WebsiteButton;
|
public SparkleAboutController Controller = new SparkleAboutController ();
|
||||||
private NSButton CreditsButton;
|
|
||||||
private NSBox Box;
|
private NSImage AboutImage;
|
||||||
private NSTextField HeaderTextField;
|
private NSImageView AboutImageView;
|
||||||
private NSTextField VersionTextField;
|
private NSTextField VersionTextField;
|
||||||
private NSTextField UpdatesTextField;
|
private NSTextField UpdatesTextField;
|
||||||
private NSTextField CreditsTextField;
|
private NSTextField CreditsTextField;
|
||||||
|
@ -41,21 +42,22 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public SparkleAbout () : base ()
|
public SparkleAbout () : base ()
|
||||||
{
|
{
|
||||||
SetFrame (new RectangleF (0, 0, 360, 288), true);
|
SetFrame (new RectangleF (0, 0, 640, 281), true);
|
||||||
Center ();
|
Center ();
|
||||||
|
|
||||||
Delegate = new SparkleAboutDelegate ();
|
Delegate = new SparkleAboutDelegate ();
|
||||||
StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled);
|
StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled);
|
||||||
Title = "About SparkleShare";
|
Title = "About SparkleShare";
|
||||||
MaxSize = new SizeF (360, 288);
|
MaxSize = new SizeF (640, 281);
|
||||||
MinSize = new SizeF (360, 288);
|
MinSize = new SizeF (640, 281);
|
||||||
HasShadow = true;
|
HasShadow = true;
|
||||||
BackingType = NSBackingStore.Buffered;
|
BackingType = NSBackingStore.Buffered;
|
||||||
|
|
||||||
CreateAbout ();
|
CreateAbout ();
|
||||||
|
OrderFrontRegardless ();
|
||||||
MakeKeyAndOrderFront (this);
|
MakeKeyAndOrderFront (this);
|
||||||
|
|
||||||
SparkleShare.Controller.NewVersionAvailable += delegate (string new_version) {
|
Controller.NewVersionEvent += delegate (string new_version) {
|
||||||
InvokeOnMainThread (delegate {
|
InvokeOnMainThread (delegate {
|
||||||
UpdatesTextField.StringValue = "A newer version (" + new_version + ") is available!";
|
UpdatesTextField.StringValue = "A newer version (" + new_version + ") is available!";
|
||||||
UpdatesTextField.TextColor =
|
UpdatesTextField.TextColor =
|
||||||
|
@ -63,7 +65,7 @@ namespace SparkleShare {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SparkleShare.Controller.VersionUpToDate += delegate {
|
Controller.VersionUpToDateEvent += delegate {
|
||||||
InvokeOnMainThread (delegate {
|
InvokeOnMainThread (delegate {
|
||||||
UpdatesTextField.StringValue = "You are running the latest version.";
|
UpdatesTextField.StringValue = "You are running the latest version.";
|
||||||
UpdatesTextField.TextColor =
|
UpdatesTextField.TextColor =
|
||||||
|
@ -71,103 +73,83 @@ namespace SparkleShare {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
CheckForNewVersion ();
|
Controller.CheckingForNewVersionEvent += delegate {
|
||||||
}
|
InvokeOnMainThread (delegate {
|
||||||
|
UpdatesTextField.StringValue = "Checking for updates...";
|
||||||
|
UpdatesTextField.TextColor = NSColor.DisabledControlText;
|
||||||
public void CheckForNewVersion ()
|
});
|
||||||
{
|
};
|
||||||
SparkleShare.Controller.CheckForNewVersion ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void CreateAbout ()
|
private void CreateAbout ()
|
||||||
{
|
{
|
||||||
Box = new NSBox () {
|
string about_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
|
||||||
FillColor = NSColor.White,
|
"Pixmaps", "about.png");
|
||||||
Frame = new RectangleF (-1, Frame.Height - 105, Frame.Width + 2, 105),
|
|
||||||
BoxType = NSBoxType.NSBoxCustom
|
AboutImage = new NSImage (about_image_path) {
|
||||||
|
Size = new SizeF (640, 260)
|
||||||
};
|
};
|
||||||
|
|
||||||
HeaderTextField = new NSTextField () {
|
AboutImageView = new NSImageView () {
|
||||||
StringValue = "SparkleShare",
|
Image = AboutImage,
|
||||||
Frame = new RectangleF (22, Frame.Height - 89, 318, 48),
|
Frame = new RectangleF (0, 0, 640, 260)
|
||||||
BackgroundColor = NSColor.White,
|
|
||||||
Bordered = false,
|
|
||||||
Editable = false,
|
|
||||||
Font = NSFontManager.SharedFontManager.FontWithFamily
|
|
||||||
("Lucida Grande", NSFontTraitMask.Condensed, 0, 24)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
VersionTextField = new NSTextField () {
|
VersionTextField = new NSTextField () {
|
||||||
StringValue = SparkleShare.Controller.Version,
|
StringValue = "version " + Controller.RunningVersion,
|
||||||
Frame = new RectangleF (22, Frame.Height - 94, 318, 22),
|
Frame = new RectangleF (295, 140, 318, 22),
|
||||||
BackgroundColor = NSColor.White,
|
BackgroundColor = NSColor.White,
|
||||||
Bordered = false,
|
Bordered = false,
|
||||||
Editable = false,
|
Editable = false,
|
||||||
|
DrawsBackground = false,
|
||||||
|
TextColor = NSColor.White,
|
||||||
Font = NSFontManager.SharedFontManager.FontWithFamily
|
Font = NSFontManager.SharedFontManager.FontWithFamily
|
||||||
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
|
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11)
|
||||||
TextColor = NSColor.DisabledControlText
|
|
||||||
};
|
};
|
||||||
|
|
||||||
UpdatesTextField = new NSTextField () {
|
UpdatesTextField = new NSTextField () {
|
||||||
StringValue = "Checking for updates...",
|
StringValue = "Checking for updates...",
|
||||||
Frame = new RectangleF (22, Frame.Height - 222, 318, 98),
|
Frame = new RectangleF (295, Frame.Height - 232, 318, 98),
|
||||||
BackgroundColor = NSColor.WindowBackground,
|
|
||||||
Bordered = false,
|
Bordered = false,
|
||||||
Editable = false,
|
Editable = false,
|
||||||
|
DrawsBackground = false,
|
||||||
Font = NSFontManager.SharedFontManager.FontWithFamily
|
Font = NSFontManager.SharedFontManager.FontWithFamily
|
||||||
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
|
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
|
||||||
TextColor = NSColor.DisabledControlText
|
TextColor = NSColor.DisabledControlText
|
||||||
};
|
};
|
||||||
|
|
||||||
CreditsTextField = new NSTextField () {
|
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" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"SparkleShare is Free and Open Source Software. You are free to use, modify, and redistribute it " +
|
"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.",
|
"under the GNU General Public License version 3 or later.",
|
||||||
Frame = new RectangleF (22, Frame.Height - 250, 318, 98),
|
Frame = new RectangleF (295, Frame.Height - 260, 318, 98),
|
||||||
BackgroundColor = NSColor.WindowBackground,
|
TextColor = NSColor.White,
|
||||||
|
DrawsBackground = false,
|
||||||
Bordered = false,
|
Bordered = false,
|
||||||
Editable = false,
|
Editable = false,
|
||||||
Font = NSFontManager.SharedFontManager.FontWithFamily
|
Font = NSFontManager.SharedFontManager.FontWithFamily
|
||||||
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
|
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebsiteButton = new NSButton () {
|
// WebsiteButton.Activated += delegate {
|
||||||
Frame = new RectangleF (12, 12, 120, 32),
|
// NSUrl url = new NSUrl ("http://www.sparkleshare.org/");
|
||||||
Title = "Visit Website",
|
// NSWorkspace.SharedWorkspace.OpenUrl (url);
|
||||||
BezelStyle = NSBezelStyle.Rounded,
|
// };
|
||||||
Font = SparkleUI.Font
|
|
||||||
};
|
|
||||||
|
|
||||||
WebsiteButton.Activated += delegate {
|
// CreditsButton.Activated += delegate {
|
||||||
NSUrl url = new NSUrl ("http://www.sparkleshare.org/");
|
// NSUrl url = new NSUrl ("http://www.sparkleshare.org/credits/");
|
||||||
NSWorkspace.SharedWorkspace.OpenUrl (url);
|
// NSWorkspace.SharedWorkspace.OpenUrl (url);
|
||||||
};
|
// };
|
||||||
|
|
||||||
CreditsButton = new NSButton () {
|
ContentView.AddSubview (AboutImageView);
|
||||||
Frame = new RectangleF (Frame.Width - 12 - 120, 12, 120, 32),
|
|
||||||
Title = "Show Credits",
|
|
||||||
BezelStyle = NSBezelStyle.Rounded,
|
|
||||||
Font = SparkleUI.Font
|
|
||||||
};
|
|
||||||
|
|
||||||
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 (VersionTextField);
|
||||||
ContentView.AddSubview (UpdatesTextField);
|
ContentView.AddSubview (UpdatesTextField);
|
||||||
ContentView.AddSubview (CreditsTextField);
|
ContentView.AddSubview (CreditsTextField);
|
||||||
ContentView.AddSubview (CreditsButton);
|
|
||||||
ContentView.AddSubview (WebsiteButton);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
95
SparkleShare/Mac/SparkleAboutController.cs
Normal file
95
SparkleShare/Mac/SparkleAboutController.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -103,6 +103,7 @@
|
||||||
<Compile Include="..\SparkleStatusIconController.cs">
|
<Compile Include="..\SparkleStatusIconController.cs">
|
||||||
<Link>SparkleStatusIconController.cs</Link>
|
<Link>SparkleStatusIconController.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="SparkleAboutController.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Page Include="MainMenu.xib" />
|
<Page Include="MainMenu.xib" />
|
||||||
|
@ -258,6 +259,9 @@
|
||||||
<Content Include="..\..\po\zh_TW.po">
|
<Content Include="..\..\po\zh_TW.po">
|
||||||
<Link>Translations\zh_TW.po</Link>
|
<Link>Translations\zh_TW.po</Link>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="..\..\data\about.png">
|
||||||
|
<Link>Pixmaps\about.png</Link>
|
||||||
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Pixmaps\" />
|
<Folder Include="Pixmaps\" />
|
||||||
|
|
|
@ -268,10 +268,6 @@ namespace SparkleShare {
|
||||||
|
|
||||||
if (SparkleUI.About == null)
|
if (SparkleUI.About == null)
|
||||||
SparkleUI.About = new SparkleAbout ();
|
SparkleUI.About = new SparkleAbout ();
|
||||||
|
|
||||||
SparkleUI.About.OrderFrontRegardless ();
|
|
||||||
SparkleUI.About.MakeKeyAndOrderFront (this);
|
|
||||||
SparkleUI.About.CheckForNewVersion ();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -75,12 +75,6 @@ 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)
|
||||||
|
@ -1058,11 +1052,6 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string Version {
|
|
||||||
get {
|
|
||||||
return SparkleBackend.Version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void AddNoteToFolder (string folder_name, string revision, string note)
|
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",
|
private string [] tango_palette = new string [] {"#eaab00", "#e37222",
|
||||||
|
|
BIN
data/about.png
Normal file
BIN
data/about.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
Loading…
Reference in a new issue