From c3db3a3b4eabc57444f410718198b3074fa23ba8 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 4 Jul 2011 04:07:07 +0100 Subject: [PATCH] Move UI events to controllers --- SparkleShare/Mac/Growl.plist | 24 +++---- SparkleShare/Mac/SparkleBubbles.cs | 14 +++- ...troller.cs => SparkleBubblesController.cs} | 5 +- SparkleShare/Mac/SparkleShare.csproj | 2 +- SparkleShare/Mac/SparkleUI.cs | 65 +++++++------------ 5 files changed, 47 insertions(+), 63 deletions(-) rename SparkleShare/Mac/{SparkleBubbleController.cs => SparkleBubblesController.cs} (90%) diff --git a/SparkleShare/Mac/Growl.plist b/SparkleShare/Mac/Growl.plist index cb8e7130..af7016e0 100644 --- a/SparkleShare/Mac/Growl.plist +++ b/SparkleShare/Mac/Growl.plist @@ -2,19 +2,15 @@ - TicketVersion - 1 - AllNotifications - - Start - Stop - Info - - DefaultNotifications - - Start - Stop - Info - + TicketVersion + 1 + AllNotifications + + Event + + DefaultNotifications + + Event + diff --git a/SparkleShare/Mac/SparkleBubbles.cs b/SparkleShare/Mac/SparkleBubbles.cs index 7581b537..95487186 100644 --- a/SparkleShare/Mac/SparkleBubbles.cs +++ b/SparkleShare/Mac/SparkleBubbles.cs @@ -31,7 +31,7 @@ namespace SparkleShare { public SparkleBubbles () { - this.controller.ShowBubbleEvent += delegate(string title, string subtext, string image_path) { + this.controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) { InvokeOnMainThread (delegate { if (!GrowlApplicationBridge.IsGrowlRunning ()) { NSApplication.SharedApplication.RequestUserAttention ( @@ -40,14 +40,22 @@ namespace SparkleShare { return; } + if (NSApplication.SharedApplication.DockTile.BadgeLabel == null) { + NSApplication.SharedApplication.DockTile.BadgeLabel = "1"; + + } else { + int events = int.Parse (NSApplication.SharedApplication.DockTile.BadgeLabel); + NSApplication.SharedApplication.DockTile.BadgeLabel = (events + 1).ToString (); + } + if (image_path != null && File.Exists (image_path)) { NSData image_data = NSData.FromFile (image_path); GrowlApplicationBridge.Notify (title, subtext, - "Start", image_data, 0, false, null); + "Event", image_data, 0, false, null); } else { GrowlApplicationBridge.Notify (title, subtext, - "Start", null, 0, false, null); + "Event", null, 0, false, null); } }); }; diff --git a/SparkleShare/Mac/SparkleBubbleController.cs b/SparkleShare/Mac/SparkleBubblesController.cs similarity index 90% rename from SparkleShare/Mac/SparkleBubbleController.cs rename to SparkleShare/Mac/SparkleBubblesController.cs index 811b8154..56ffd3a9 100644 --- a/SparkleShare/Mac/SparkleBubbleController.cs +++ b/SparkleShare/Mac/SparkleBubblesController.cs @@ -28,14 +28,15 @@ namespace SparkleShare { public SparkleBubblesController () { SparkleShare.Controller.ConflictNotificationRaised += delegate { - if (ShowBubbleEvent != null) + if (ShowBubbleEvent != null && SparkleShare.Controller.NotificationsEnabled) ShowBubbleEvent ("Ouch! Mid-air collision!", "Don't worry, SparkleShare made a copy of each conflicting file.", null); }; SparkleShare.Controller.NotificationRaised += delegate (string user_name, string user_email, string message, string folder_path) { - if (ShowBubbleEvent != null) + + if (ShowBubbleEvent != null && SparkleShare.Controller.NotificationsEnabled) ShowBubbleEvent (user_name, message, SparkleShare.Controller.GetAvatar (user_email, 36)); }; diff --git a/SparkleShare/Mac/SparkleShare.csproj b/SparkleShare/Mac/SparkleShare.csproj index f8d67e36..8c3a898c 100644 --- a/SparkleShare/Mac/SparkleShare.csproj +++ b/SparkleShare/Mac/SparkleShare.csproj @@ -91,8 +91,8 @@ - + diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index e96a246f..1ac366ef 100644 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -29,25 +29,12 @@ using MonoMac.Growl; namespace SparkleShare { - public partial class AppDelegate : NSApplicationDelegate { - - public override void WillBecomeActive (NSNotification notification) - { - NSApplication.SharedApplication.DockTile.BadgeLabel = null; - } - - public override void WillTerminate (NSNotification notification) - { - SparkleShare.Controller.Quit (); - } - } - - public class SparkleUI : AppDelegate { public static SparkleStatusIcon StatusIcon; public static SparkleEventLog EventLog; public static SparkleIntro Intro; + public static SparkleBubbles Bubbles; public static SparkleAbout About; public static NSFont Font; @@ -69,7 +56,6 @@ namespace SparkleShare { // Use translations Catalog.Init ("sparkleshare", Path.Combine (NSBundle.MainBundle.ResourcePath, "Translations")); - using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { @@ -79,45 +65,24 @@ namespace SparkleShare { NSApplication.SharedApplication.ApplicationIconImage = NSImage.ImageNamed ("sparkleshare.icns"); - SetFolderIcon (); - if (!SparkleShare.Controller.BackendIsPresent) { this.alert = new SparkleAlert (); this.alert.RunModal (); return; } + + SetFolderIcon (); Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", NSFontTraitMask.Condensed, 0, 13); StatusIcon = new SparkleStatusIcon (); - } + Bubbles = new SparkleBubbles (); - SparkleShare.Controller.NotificationRaised += delegate (string user_name, string user_email, - string message, string repository_path) { - InvokeOnMainThread (delegate { - - if (SparkleShare.Controller.NotificationsEnabled) { - if (NSApplication.SharedApplication.DockTile.BadgeLabel == null) - NSApplication.SharedApplication.DockTile.BadgeLabel = "1"; - else - NSApplication.SharedApplication.DockTile.BadgeLabel = - (int.Parse (NSApplication.SharedApplication.DockTile.BadgeLabel) + 1).ToString (); - - } - }); - }; - - - - - - - - - if (SparkleShare.Controller.FirstRun) { - Intro = new SparkleIntro (); - Intro.ShowAccountForm (); + if (SparkleShare.Controller.FirstRun) { + Intro = new SparkleIntro (); + Intro.ShowAccountForm (); + } } } @@ -147,4 +112,18 @@ namespace SparkleShare { return NSDictionary.FromFile (path); } } + + + public partial class AppDelegate : NSApplicationDelegate { + + public override void WillBecomeActive (NSNotification notification) + { + NSApplication.SharedApplication.DockTile.BadgeLabel = null; + } + + public override void WillTerminate (NSNotification notification) + { + SparkleShare.Controller.Quit (); + } + } }