Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Move Growl bindings to it's own assembly, usable by MonoMac or Xamari…
Browse files Browse the repository at this point in the history
…n.Mac
  • Loading branch information
spouliot committed Jan 10, 2013
1 parent 2934eb1 commit 802f2f1
Show file tree
Hide file tree
Showing 19 changed files with 5,170 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
bin/
obj/
*.dll*
*.userprefs
.DS_Store
7 changes: 7 additions & 0 deletions Growl/README.md
@@ -0,0 +1,7 @@
Growl Bindings
==============

This is a copy of the Growl bindings that were included directly in monomac.dll in the past. Since Growl is an external application/framework, with a different release schedule than OSX, it is being moved to a separate assembly.

The current bindings are for Growl 1.2.1. For information in:
http://cocoa-mono.org/archives/254/growl-my-monomac-application-says/
183 changes: 183 additions & 0 deletions Growl/binding/ApiDefinition.cs
@@ -0,0 +1,183 @@
//
// Copyright 2010, Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

//
// growl.cs: Definitions for the Growl Framework
//
using System;
using MonoMac.Foundation;
using MonoMac.ObjCRuntime;
using MonoMac.AppKit;

namespace MonoMac.Growl {
[BaseType (typeof (NSObject))]
interface GrowlApplicationBridge {
[Static]
[Export ("isGrowlInstalled")]
bool IsGrowlInstalled ();

[Static]
[Export ("isGrowlRunning")]
bool IsGrowlRunning ();

[Static]
[Export ("notifyWithTitle:description:notificationName:iconData:priority:isSticky:clickContext:")]
void Notify (string title, string description, string notifName, [NullAllowed] NSData iconData, int priority, bool isSticky, [NullAllowed] NSObject clickContext);

[Static]
[Export ("notifyWithTitle:description:notificationName:iconData:priority:isSticky:clickContext:identifier:")]
void Notify (string title, string description, string notifName, [NullAllowed] NSData iconData, int priority, bool isSticky, [NullAllowed] NSObject clickContext, string identifier);

[Static]
[Export ("notifyWithDictionary:")]
void Notify (NSDictionary userInfo);

[Export ("registerWithDictionary:")]
bool Register (NSDictionary regDict);

[Static]
[Export ("reregisterGrowlNotifications")]
void ReRegister ();

[Export ("registrationDictionaryFromDelegate")]
NSDictionary RegistrationDictionaryFromDelegate ();

[Static]
[Export ("registrationDictionaryFromBundle:")]
NSDictionary RegistrationDictionaryFromBundle (NSBundle bundle);

[Static]
[Export ("bestRegistrationDictionary")]
NSDictionary BestRegistrationDictionary ();

[Static]
[Export ("registrationDictionaryByFillingInDictionary:")]
NSDictionary FromDictionary (NSDictionary regDict);

[Static]
[Export ("registrationDictionaryByFillingInDictionary:restrictToKeys:")]
NSDictionary FromDictionary (NSDictionary regDict, NSSet restrictToKeys);

[Static]
[Export ("notificationDictionaryByFillingInDictionary:")]
NSDictionary NotificationDictionary (NSDictionary regDict);

[Static]
[Export ("frameworkInfoDictionary")]
NSDictionary FrameworkInfoDictionary { get; }

//Detected properties
//[Export ("growlDelegate")]
//NSObject<GrowlApplicationBridgeDelegate> GrowlDelegate { get; set; }

[Static]
[Export ("growlDelegate", ArgumentSemantic.Assign), NullAllowed]
NSObject WeakDelegate { get; set; }

[Static]
[Wrap ("WeakDelegate")]
GrowlDelegate Delegate { get; set; }

[Static]
[Export ("willRegisterWhenGrowlIsReady")]
bool WillRegisterWhenGrowlIsReady { get; set; }

}
[BaseType (typeof(NSObject))]
[Model]
interface GrowlDelegate {
[Export ("registrationDictionaryForGrowl")]
NSDictionary RegistrationDictionaryForGrowl ();

[Export ("applicationNameForGrowl")]
string ApplicationNameForGrowl ();

[Export ("applicationIconForGrowl")]
NSImage ApplicationIconForGrowl ();

[Export ("applicationIconDataForGrowl")]
NSData ApplicationIconDataForGrowl ();

[Export ("growlIsReady")]
void GrowlIsReady ();

[Export ("growlNotificationWasClicked:")]
void GrowlNotificationWasClicked (NSObject clickContext);

[Export ("growlNotificationTimedOut:")]
void GrowlNotificationTimedOut (NSObject clickContext);

// Installer informal protocol
[Export ("growlInstallationWindowTitle")]
string GrowlInstallationWindowTitle ();

[Export ("growlUpdateWindowTitle")]
string GrowlUpdateWindowTitle ();

[Export ("growlInstallationInformation")]
NSAttributedString GrowlInstallationInformation ();

[Export ("growlUpdateInformation")]
NSAttributedString GrowlUpdateInformation ();
}

/* Growl has two informal protocols (NSObject categories) rather than a delegate protocol since version 0.7 */
/* This would be the literal interpretation of the ObjC code
interface NSObject {
[Bind ("registrationDictionaryForGrowl")]
NSDictionary RegistrationDictionaryForGrowl ([Target] NSObject target);
[Bind ("applicationNameForGrowl")]
string ApplicationNameForGrowl ([Target] NSObject target);
[Bind ("applicationIconForGrowl")]
NSImage ApplicationIconForGrowl ([Target] NSObject target);
[Bind ("applicationIconDataForGrowl")]
NSData ApplicationIconDataForGrowl ([Target] NSObject target);
[Bind ("growlIsReady")]
void GrowlIsReady ([Target] NSObject target);
[Bind ("growlNotificationWasClicked:")]
void GrowlNotificationWasClicked ([Target] NSObject target, NSObject clickContext);
[Bind ("growlNotificationTimedOut:")]
void GrowlNotificationTimedOut ([Target] NSObject target, NSObject clickContext);
// Installer informal protocol
[Bind ("growlInstallationWindowTitle")]
string GrowlInstallationWindowTitle ([Target] NSObject target);
[Bind ("growlUpdateWindowTitle")]
string GrowlUpdateWindowTitle ([Target] NSObject target);
[Bind ("growlInstallationInformation")]
NSAttributedString GrowlInstallationInformation ([Target] NSObject target);
[Bind ("growlUpdateInformation")]
NSAttributedString GrowlUpdateInformation ([Target] NSObject target);
}
*/
}
73 changes: 73 additions & 0 deletions Growl/binding/Extra.cs
@@ -0,0 +1,73 @@
//
// Copyright 2010, Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software";, to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

//
// Constants.cs: Constants for the Growl Framework
//
using System;
using MonoMac.Foundation;
using MonoMac.ObjCRuntime;
using MonoMac.AppKit;

namespace MonoMac.Growl {
public static class RegistrationUserInfoKeys {
static public string ApplicationName = "ApplicationName";
static public string ApplicationId = "ApplicationId";
static public string ApplicationIcon = "ApplicationIcon";
static public string DefaultNotifications = "DefaultNotifications";
static public string AllNotifications = "AllNotifications";
static public string HumanReadableNames = "HumanReadableNames";
static public string NotificationDescriptions = "NotificationDescriptions";
static public string TicketVersion = "TicketVersion";
}

public static class NotificationUserInfoKeys {
static public string NotificationName = "NotificationName";
static public string NotificationTitle = "NotificationTitle";
static public string NotificationDescription = "NotificationDescription";
static public string NotificationIcon = "NotificationIcon";
static public string NotificationAppIcon = "NotificationAppIcon";
static public string NotificationPriority = "NotificationPriority";
static public string NotificationSticky = "NotificationSticky";
static public string NotificationClickContext = "NotificationClickContext";
static public string NotificationDisplayPlugin = "NotificationDisplayPlugin";
static public string GrowlNotificationIdentifier = "GrowlNotificationIdentifier";
static public string ApplicationPID = "ApplicationPID";
static public string NotificationProgress = "NotificationProgress";
}

public static class GrowlNotifications {
static public string ApplicationRegistrationNotification = "GrowlApplicationRegistrationNotification";
static public string ApplicationRegistrationConfirmationNotification = "GrowlApplicationRegistrationConfirmationNotification";
static public string Notification = "GrowlNotification";
static public string Shutdown = "GrowlShutdown";
static public string Ping = "Honey, Mind Taking Out The Trash";
static public string Pong = "What Do You Want From Me, Woman";
static public string IsReady = "Lend Me Some Sugar; I Am Your Neighbor!";
static public string Clicked = "GrowlClicked!";
static public string TimedOut = "GrowlTimedOut!";
static public string ClickedContext = "ClickedContext";
static public string RegDictExtension = "growlRegDict";
static public string GrowlSelectedPosition = "GrowlSelectedPosition";
}
}
22 changes: 22 additions & 0 deletions Growl/binding/Makefile
@@ -0,0 +1,22 @@
# MONOMAC variable needs to be edited to match your setup
MONOMAC=/Developer/MonoTouch/Source/monomac/
MONOMAC_DLL=$(MONOMAC)/src/MonoMac.dll
XAMMAC=/Library/Frameworks/Xamarin.Mac.framework/Versions/Current
XAMMAC_DLL=$(XAMMAC)/usr/lib/mono/XamMac.dll
MCS=mcs

all: Mono.Growl.dll Xamarin.Growl.dll

clean:
-rm -f *.dll*
-rm -rf xamarin mono

Mono.Growl.dll: ApiDefinition.cs Extra.cs
mkdir -p mono
mono $(MONOMAC)/src/bmac.exe -e ApiDefinition.cs --tmpdir=mono -baselib=$(MONOMAC_DLL) -sourceonly mono/sources.list
$(MCS) -target:library -unsafe -out:$@ Extra.cs @mono/sources.list -r:System.Drawing -r:$(MONOMAC_DLL)

Xamarin.Growl.dll: ApiDefinition.cs Extra.cs
mkdir -p xamarin
$(XAMMAC)/usr/bin/bmac -e ApiDefinition.cs --tmpdir=xamarin -baselib=$(XAMMAC_DLL) -sourceonly xamarin/sources.list
$(MCS) -target:library -unsafe -out:$@ Extra.cs @xamarin/sources.list -r:System.Drawing -r:$(XAMMAC_DLL)
27 changes: 27 additions & 0 deletions Growl/samples/TwoMinuteGrowler/AppDelegate.cs
@@ -0,0 +1,27 @@
using System;
using System.Drawing;
using MonoMac.Foundation;
using MonoMac.AppKit;


namespace TwoMinuteGrowler {
public partial class AppDelegate : NSApplicationDelegate {
MainWindowController mainWindowController;

public AppDelegate ()
{
}

public override void FinishedLaunching (NSObject notification)
{
mainWindowController = new MainWindowController ();
mainWindowController.Window.MakeKeyAndOrderFront (this);
}

public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
{
return true;
}
}
}

61 changes: 61 additions & 0 deletions Growl/samples/TwoMinuteGrowler/CountDownTimer.cs
@@ -0,0 +1,61 @@
using System;
using System.Timers;
using System.Threading;

using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.Growl;

namespace TwoMinuteGrowler
{
public class CountDownTimer : NSObject {
NSTimer myTTimer;
string timer;
TimeSpan currentTime;

public CountDownTimer () : base()
{
currentTime = TimeSpan.FromMinutes (2);
TimeLeft = formatTimeSpan (currentTime);
}

public void Start ()
{
currentTime = TimeSpan.FromMinutes (2);
TimeLeft = formatTimeSpan (currentTime);

myTTimer = NSTimer.CreateRepeatingScheduledTimer (1, delegate {
currentTime = currentTime - TimeSpan.FromSeconds (1);
TimeLeft = formatTimeSpan (currentTime);
});
}

private string formatTimeSpan (TimeSpan ts)
{
return String.Format ("{0}:{1:00}", ts.Minutes, ts.Seconds);
}

public void Stop ()
{
myTTimer.Invalidate ();
}

[Export ("timeLeft")]
public string TimeLeft {
get {
return timer;
}
set {
WillChangeValue ("timeLeft");
timer = value;
DidChangeValue ("timeLeft");
}
}

public TimeSpan TimerMark {
get { return currentTime; }
}

}
}

0 comments on commit 802f2f1

Please sign in to comment.