/SparkleShare/Mac/SparkleAbout.cs

http://github.com/hbons/SparkleShare · C# · 219 lines · 147 code · 57 blank · 15 comment · 4 complexity · d92dcb2181e69591215d661157b09b7c MD5 · raw file

  1. // SparkleShare, a collaboration and sharing tool.
  2. // Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. using System;
  17. using System.Drawing;
  18. using System.IO;
  19. using MonoMac.AppKit;
  20. using MonoMac.Foundation;
  21. namespace SparkleShare {
  22. public class SparkleAbout : NSWindow {
  23. public SparkleAboutController Controller = new SparkleAboutController ();
  24. private NSTextField version_text_field, updates_text_field, credits_text_field;
  25. private SparkleLink website_link, credits_link, report_problem_link, debug_log_link;
  26. private NSImage about_image;
  27. private NSImageView about_image_view;
  28. private NSButton hidden_close_button;
  29. public SparkleAbout (IntPtr handle) : base (handle) { }
  30. public SparkleAbout () : base ()
  31. {
  32. SetFrame (new RectangleF (0, 0, 640, 281), true);
  33. Center ();
  34. Delegate = new SparkleAboutDelegate ();
  35. StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled);
  36. Title = "About SparkleShare";
  37. MaxSize = new SizeF (640, 281);
  38. MinSize = new SizeF (640, 281);
  39. HasShadow = true;
  40. BackingType = NSBackingStore.Buffered;
  41. Level = NSWindowLevel.Floating;
  42. this.hidden_close_button = new NSButton () {
  43. Frame = new RectangleF (0, 0, 0, 0),
  44. KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
  45. KeyEquivalent = "w"
  46. };
  47. CreateAbout ();
  48. this.hidden_close_button.Activated += delegate { Controller.WindowClosed (); };
  49. Controller.HideWindowEvent += delegate {
  50. Program.Controller.Invoke (() => PerformClose (this));
  51. };
  52. Controller.ShowWindowEvent += delegate {
  53. Program.Controller.Invoke (() => OrderFrontRegardless ());
  54. };
  55. Controller.UpdateLabelEvent += delegate (string text) {
  56. Program.Controller.Invoke (() => { this.updates_text_field.StringValue = text; });
  57. };
  58. ContentView.AddSubview (this.hidden_close_button);
  59. }
  60. private void CreateAbout ()
  61. {
  62. this.about_image = NSImage.ImageNamed ("about");
  63. this.about_image.Size = new SizeF (720, 260);
  64. this.about_image_view = new NSImageView () {
  65. Image = this.about_image,
  66. Frame = new RectangleF (0, 0, 720, 260)
  67. };
  68. this.version_text_field = new SparkleLabel ("version " + Controller.RunningVersion, NSTextAlignment.Left) {
  69. DrawsBackground = false,
  70. Frame = new RectangleF (295, 140, 318, 22),
  71. TextColor = NSColor.White
  72. };
  73. this.updates_text_field = new SparkleLabel ("Checking for updates...", NSTextAlignment.Left) {
  74. DrawsBackground = false,
  75. Frame = new RectangleF (295, Frame.Height - 232, 318, 98),
  76. TextColor = NSColor.FromCalibratedRgba (1.0f, 1.0f, 1.0f, 0.5f)
  77. };
  78. this.credits_text_field = new SparkleLabel (
  79. @"Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others." +
  80. "\n\n" +
  81. "SparkleShare is Open Source. You are free to use, modify, and redistribute it " +
  82. "under the GNU GPLv3.", NSTextAlignment.Left) {
  83. DrawsBackground = false,
  84. Frame = new RectangleF (295, Frame.Height - 260, 318, 98),
  85. TextColor = NSColor.White
  86. };
  87. this.website_link = new SparkleLink ("Website", Controller.WebsiteLinkAddress);
  88. this.website_link.Frame = new RectangleF (new PointF (295, 25), this.website_link.Frame.Size);
  89. this.credits_link = new SparkleLink ("Credits", Controller.CreditsLinkAddress);
  90. this.credits_link.Frame = new RectangleF (
  91. new PointF (this.website_link.Frame.X + this.website_link.Frame.Width + 10, 25),
  92. this.credits_link.Frame.Size);
  93. this.report_problem_link = new SparkleLink ("Report a problem", Controller.ReportProblemLinkAddress);
  94. this.report_problem_link.Frame = new RectangleF (
  95. new PointF (this.credits_link.Frame.X + this.credits_link.Frame.Width + 10, 25),
  96. this.report_problem_link.Frame.Size);
  97. this.debug_log_link = new SparkleLink ("Debug log", Controller.DebugLogLinkAddress);
  98. this.debug_log_link.Frame = new RectangleF (
  99. new PointF (this.report_problem_link.Frame.X + this.report_problem_link.Frame.Width + 10, 25),
  100. this.debug_log_link.Frame.Size);
  101. ContentView.AddSubview (this.about_image_view);
  102. ContentView.AddSubview (this.version_text_field);
  103. ContentView.AddSubview (this.updates_text_field);
  104. ContentView.AddSubview (this.credits_text_field);
  105. ContentView.AddSubview (this.website_link);
  106. ContentView.AddSubview (this.credits_link);
  107. ContentView.AddSubview (this.report_problem_link);
  108. ContentView.AddSubview (this.debug_log_link);
  109. }
  110. public override void OrderFrontRegardless ()
  111. {
  112. NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
  113. MakeKeyAndOrderFront (this);
  114. if (Program.UI != null)
  115. Program.UI.UpdateDockIconVisibility ();
  116. base.OrderFrontRegardless ();
  117. }
  118. public override void PerformClose (NSObject sender)
  119. {
  120. base.OrderOut (this);
  121. if (Program.UI != null)
  122. Program.UI.UpdateDockIconVisibility ();
  123. return;
  124. }
  125. private class SparkleAboutDelegate : NSWindowDelegate {
  126. public override bool WindowShouldClose (NSObject sender)
  127. {
  128. (sender as SparkleAbout).Controller.WindowClosed ();
  129. return false;
  130. }
  131. }
  132. private class SparkleLink : NSTextField {
  133. private NSUrl url;
  134. public SparkleLink (string text, string address) : base ()
  135. {
  136. this.url = new NSUrl (address);
  137. AllowsEditingTextAttributes = true;
  138. BackgroundColor = NSColor.White;
  139. Bordered = false;
  140. DrawsBackground = false;
  141. Editable = false;
  142. Selectable = false;
  143. NSData name_data = NSData.FromString ("<a href='" + this.url +
  144. "' style='font-size: 9pt; font-family: \"Helvetica Neue\"; color: #739ECF'>" + text + "</a></font>");
  145. NSDictionary name_dictionary = new NSDictionary();
  146. NSAttributedString name_attributes = new NSAttributedString (name_data, new NSUrl ("file://"), out name_dictionary);
  147. NSMutableAttributedString s = new NSMutableAttributedString ();
  148. s.Append (name_attributes);
  149. Cell.AttributedStringValue = s;
  150. SizeToFit ();
  151. }
  152. public override void MouseUp (NSEvent e)
  153. {
  154. Program.Controller.OpenWebsite (this.url.ToString ());
  155. }
  156. public override void ResetCursorRects ()
  157. {
  158. AddCursorRect (Bounds, NSCursor.PointingHandCursor);
  159. }
  160. }
  161. }
  162. }