diff --git a/SparkleShare/Mac/Growl.plist b/SparkleShare/Mac/Growl.plist new file mode 100644 index 00000000..cb8e7130 --- /dev/null +++ b/SparkleShare/Mac/Growl.plist @@ -0,0 +1,20 @@ + + + + + TicketVersion + 1 + AllNotifications + + Start + Stop + Info + + DefaultNotifications + + Start + Stop + Info + + + diff --git a/SparkleShare/Mac/SparkleBubble.cs b/SparkleShare/Mac/SparkleBubble.cs new file mode 100644 index 00000000..cdf6378f --- /dev/null +++ b/SparkleShare/Mac/SparkleBubble.cs @@ -0,0 +1,58 @@ +// SparkleShare, an instant update workflow to Git. +// Copyright (C) 2010 Hylke Bons +// +// 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 . + + +using System; +using System.IO; + +using MonoMac.AppKit; +using MonoMac.Foundation; +using MonoMac.Growl; + +namespace SparkleShare { + + public class SparkleBubble : NSObject { + + public string ImagePath; + + private string title; + private string subtext; + + + public SparkleBubble (string title, string subtext) + { + this.title = title; + this.subtext = subtext; + } + + + public void Show () + { + InvokeOnMainThread (delegate { + if (ImagePath != null && File.Exists (ImagePath)) { + NSData image_data = NSData.FromFile (ImagePath); + + GrowlApplicationBridge.Notify (this.title, this.subtext, + "Start", image_data, 0, false, null); + + } else { + GrowlApplicationBridge.Notify (this.title, this.subtext, + "Start", null, 0, false, null); + } + }); + } + } +} diff --git a/SparkleShare/Mac/SparkleShare.csproj b/SparkleShare/Mac/SparkleShare.csproj index 35e04e30..e7665eef 100644 --- a/SparkleShare/Mac/SparkleShare.csproj +++ b/SparkleShare/Mac/SparkleShare.csproj @@ -22,6 +22,11 @@ prompt 4 false + + + + + none @@ -83,6 +88,7 @@ + @@ -144,6 +150,7 @@ Pixmaps\idle4.png + diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index ed310779..c3baa437 100644 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -24,7 +24,7 @@ using System.Timers; using MonoMac.Foundation; using MonoMac.AppKit; using MonoMac.ObjCRuntime; -using MonoMac.WebKit; +using MonoMac.Growl; namespace SparkleShare { @@ -60,11 +60,22 @@ namespace SparkleShare { public SparkleUI () { - NSApplication.Init (); + string content_path = Directory.GetParent ( + System.AppDomain.CurrentDomain.BaseDirectory).ToString (); + string app_path = Directory.GetParent (content_path).ToString (); + string growl_path = Path.Combine (app_path, "Frameworks", "Growl.framework", "Growl"); + + // Needed for Growl + Dlfcn.dlopen (growl_path, 0); + NSApplication.Init (); + + using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { + + // Needed for Growl + GrowlApplicationBridge.WeakDelegate = this; + + SetSparkleIcon (); - using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { - SetSparkleIcon (); - // TODO: Getting crashes when I remove this NSApplication.SharedApplication.ApplicationIconImage = NSImage.ImageNamed ("sparkleshare.icns"); @@ -97,8 +108,17 @@ namespace SparkleShare { NSApplication.SharedApplication.DockTile.BadgeLabel = (int.Parse (NSApplication.SharedApplication.DockTile.BadgeLabel) + 1).ToString (); - NSApplication.SharedApplication.RequestUserAttention - (NSRequestUserAttentionType.InformationalRequest); + if (GrowlApplicationBridge.IsGrowlRunning ()) { + SparkleBubble bubble = new SparkleBubble (user_name, message) { + ImagePath = SparkleShare.Controller.GetAvatar (user_email, 36) + }; + + bubble.Show (); + + } else { + NSApplication.SharedApplication.RequestUserAttention + (NSRequestUserAttentionType.InformationalRequest); + } } }); }; @@ -143,5 +163,13 @@ namespace SparkleShare { { NSApplication.Main (new string [0]); } + + + [Export("registrationDictionaryForGrowl")] + NSDictionary RegistrationDictionaryForGrowl () + { + string path = NSBundle.MainBundle.PathForResource ("Growl", "plist"); + return NSDictionary.FromFile (path); + } } }