real-growl 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ real-growl
2
+
3
+ Description
4
+ ===========
5
+
6
+ A Growl notification library that uses native c bindings to interact with GrowlApplicationBridge rather than Growl's network API.
7
+
8
+ Synopsis
9
+ ========
10
+
11
+ ### rg
12
+
13
+ >> require 'real_growl'
14
+ => true
15
+ >> rg("Check out", ["Real", "Growl"], :icon => "/path/to/a/picture.jpg")
16
+ >> rg("Google", ["Real", "Growl"], :icon => "http://www.google.com/logos/stpatricks_d4gwinner_eo09.gif")
17
+ => nil
18
+
19
+ >> Kernel.rg_sticky = false
20
+ => false
21
+ >> Kernel.rg_priority = 3
22
+ => 3
23
+ >> Kernel.rg_icon = "/the/path/cool.png"
24
+ => "/the/path/cool.png"
25
+
26
+ ### Custom Application
27
+
28
+ >> require 'real_growl'
29
+ >> my_own_application = RealGrowl::Application.new("AppName")
30
+ => #<RealGrowl::Application:0x1018eb6b8>
31
+ >> my_own_application.notify(:title => "Title", :description => "Desc", :priority => 0, :sticky => true, :icon => "/path/to/image.png")
32
+
33
+ ### Extras
34
+ >> RealGrowl.installed?
35
+ => true
36
+ >> RealGrowl.running?
37
+ => true
38
+
39
+ TODO
40
+ ====
41
+ * Add executable script
42
+ * Enable growl callbacks
43
+
44
+ Requirements
45
+ ============
46
+
47
+ * MacOS X 10.5 > ??
48
+ * Growl Framework - http://growl.info/downloads_developers.php
49
+
50
+ INSTALL
51
+ =======
52
+
53
+ Download and install Growl.framework into either ~/Library/Frameworks or /Library/Frameworks
54
+ gem install real-growl
55
+
56
+ INSTALLATION HINTS
57
+ ==================
58
+
59
+ Make sure that the Growl.framework is either 32bit or the 64bit depending on the version of MacOS X
60
+ installed and the kind of machine it is installed on.
data/ext/extconf.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'mkmf'
3
3
 
4
4
 
5
- $CFLAGS << ' ' + "-ObjC"
5
+ $CFLAGS << ' ' + "-ObjC "
6
6
  $LDFLAGS << ' ' + "-lobjc -framework Foundation -framework Growl"
7
7
  $objs = %w(ruby_delegate.o real_growl_api.o)
8
8
 
data/ext/real_growl_api.c CHANGED
@@ -12,6 +12,28 @@ build_nsstring(VALUE string) {
12
12
  }
13
13
  }
14
14
 
15
+ static NSData*
16
+ get_icon_data(VALUE pathOrUrl) {
17
+ NSString *nsPathOrUrl = build_nsstring(pathOrUrl);
18
+ NSData *iconData = nil;
19
+
20
+ if(nsPathOrUrl != nil) {
21
+ iconData = [NSData dataWithContentsOfFile: nsPathOrUrl];
22
+
23
+ if(iconData == nil) {
24
+ iconData = [NSData dataWithContentsOfURL: [NSURL URLWithString: nsPathOrUrl]];
25
+ }
26
+ }
27
+
28
+ return iconData;
29
+ }
30
+
31
+
32
+ static NSAutoreleasePool*
33
+ create_autorelease_pool() {
34
+ return [[NSAutoreleasePool alloc] init];
35
+ }
36
+
15
37
  static void
16
38
  free_delegate(id delegate) {
17
39
  [delegate release];
@@ -22,11 +44,6 @@ alloc_delegate(VALUE klass) {
22
44
  return Data_Wrap_Struct(klass, 0, free_delegate, [[RubyDelegate alloc] init]);
23
45
  }
24
46
 
25
- static NSAutoreleasePool*
26
- create_autorelease_pool() {
27
- return [[NSAutoreleasePool alloc] init];
28
- }
29
-
30
47
  VALUE
31
48
  classMethod_installed(VALUE self) {
32
49
  NSAutoreleasePool *pool = create_autorelease_pool();
@@ -54,22 +71,34 @@ classMethod_running(VALUE self) {
54
71
  }
55
72
 
56
73
  VALUE
57
- // VALUE title, VALUE description, VALUE priority, VALUE sticky, VALUE iconPath
58
74
  method_notify(VALUE self, VALUE options) {
59
75
  NSAutoreleasePool *pool = create_autorelease_pool();
76
+ id delegate = NULL;
77
+ Data_Get_Struct(self, RubyDelegate, delegate);
60
78
 
61
79
  VALUE title = rb_hash_aref(options, ID2SYM(rb_intern("title")));
62
80
  VALUE description = rb_hash_aref(options, ID2SYM(rb_intern("description")));
63
- VALUE priority = rb_hash_aref(options, ID2SYM(rb_intern("priority")));
64
- priority = (priority == Qnil) ? INT2NUM(0) : priority;
81
+ VALUE priority = rb_Integer(rb_hash_aref(options, ID2SYM(rb_intern("priority"))));
65
82
  VALUE sticky = rb_hash_aref(options, ID2SYM(rb_intern("sticky")));
66
83
  VALUE iconPath = rb_hash_aref(options, ID2SYM(rb_intern("icon")));
84
+ VALUE click = rb_hash_aref(options, ID2SYM(rb_intern("click")));
85
+
67
86
  BOOL nsSticky = (sticky == Qtrue) ? YES : NO;
68
- NSData *data = [NSData dataWithContentsOfFile:build_nsstring(iconPath)];
87
+ NSData *data = get_icon_data(iconPath);
69
88
  NSString *nsTitle = build_nsstring(title);
70
89
  NSString *nsDescription = build_nsstring(description);
90
+ NSNumber *clickContext = [NSNumber numberWithUnsignedLong: self];
71
91
 
72
- [GrowlApplicationBridge notifyWithTitle: nsTitle description: nsDescription notificationName: REAL_GROWL_NOTIFICATION iconData: data priority: NUM2INT(priority) isSticky:nsSticky clickContext:nil];
92
+ [delegate setCallbackProc: click];
93
+ [GrowlApplicationBridge setGrowlDelegate: delegate];
94
+ [GrowlApplicationBridge
95
+ notifyWithTitle: nsTitle
96
+ description: nsDescription
97
+ notificationName: REAL_GROWL_NOTIFICATION
98
+ iconData: data
99
+ priority: NUM2INT(priority)
100
+ isSticky:nsSticky
101
+ clickContext:clickContext];
73
102
 
74
103
  [pool drain];
75
104
 
@@ -82,9 +111,8 @@ method_init(VALUE self, VALUE applicationName) {
82
111
  id delegate = NULL;
83
112
 
84
113
  Data_Get_Struct(self, RubyDelegate, delegate);
85
- NSString *nsAppName = [NSString stringWithCString:STR2CSTR(applicationName) encoding: NSASCIIStringEncoding];
114
+ NSString *nsAppName = build_nsstring(applicationName);
86
115
  [delegate setApplicationName: nsAppName];
87
- [GrowlApplicationBridge setGrowlDelegate: delegate];
88
116
 
89
117
  [pool drain];
90
118
 
data/ext/real_growl_api.h CHANGED
@@ -2,4 +2,4 @@
2
2
  #include "ruby.h"
3
3
  #include <objc/runtime.h>
4
4
  #include <Growl/Growl.h>
5
- #include <Foundation/Foundation.h>
5
+ #include <Foundation/Foundation.h>
@@ -1,7 +1,7 @@
1
1
  #include "ruby_delegate.h"
2
2
 
3
3
  @implementation RubyDelegate
4
- @synthesize applicationName;
4
+ @synthesize applicationName, callbackProc;
5
5
 
6
6
  -(id)init {
7
7
  if(self = [super init]) {
@@ -12,9 +12,19 @@
12
12
  return nil;
13
13
  }
14
14
 
15
+ -(NSString *)applicationNameForGrowl {
16
+ return applicationName;
17
+ }
18
+
15
19
  -(NSDictionary *)registrationDictionaryForGrowl {
16
20
  NSArray *notifications = [NSArray arrayWithObject:REAL_GROWL_NOTIFICATION];
17
- return [NSDictionary dictionaryWithObjectsAndKeys: [self applicationName], GROWL_APP_ID, [self applicationName], GROWL_APP_NAME, notifications, GROWL_NOTIFICATIONS_ALL, nil];
21
+ return [NSDictionary dictionaryWithObjectsAndKeys: [self applicationName], GROWL_APP_ID, [self applicationName], GROWL_APP_NAME, notifications, GROWL_NOTIFICATIONS_ALL, notifications, GROWL_NOTIFICATIONS_DEFAULT, nil];
22
+ }
23
+
24
+ -(void)growlNotificationWasClicked:(id)clickContext {
25
+ if(callbackProc != Qnil) {
26
+ rb_funcall(callbackProc, rb_intern("call"), 0);
27
+ }
18
28
  }
19
29
 
20
30
  -(void)dealloc {
data/ext/ruby_delegate.h CHANGED
@@ -1,12 +1,19 @@
1
1
  #include <Foundation/Foundation.h>
2
2
  #include <Growl/Growl.h>
3
+ #include "ruby.h"
4
+
3
5
  #define REAL_GROWL_NOTIFICATION XSTR("RealGrowlNotification")
4
6
 
5
7
  @interface RubyDelegate : NSObject<GrowlApplicationBridgeDelegate>
6
8
  {
7
9
  NSString *applicationName;
10
+ VALUE callbackProc;
8
11
  }
9
12
 
10
13
  -(NSDictionary *) registrationDictionaryForGrowl;
14
+ -(void) growlNotificationWasClicked:(id)clickContext;
15
+ -(NSString *)applicationNameForGrowl;
16
+
17
+ @property(nonatomic, assign) VALUE callbackProc;
11
18
  @property(nonatomic, retain) NSString *applicationName;
12
19
  @end
data/lib/real_growl.rb CHANGED
@@ -10,11 +10,13 @@ module Kernel
10
10
  Kernel.rg_priority ||= 0
11
11
  Kernel.rg_sticky = true if Kernel.rg_sticky.nil?
12
12
  icon = Kernel.rg_icon
13
+ click = nil
13
14
 
14
15
  @__growl_app ||= RealGrowl::Application.new("RealGrowl")
15
16
 
16
- if args.last.is_a?(Hash) and args.last[:icon]
17
+ if args.last.is_a?(Hash) and (args.last[:icon] or args.last[:click])
17
18
  icon = args.last[:icon]
19
+ click = args.last[:click]
18
20
  args.pop
19
21
  end
20
22
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: real-growl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin DeWind
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-18 00:00:00 -05:00
12
+ date: 2010-02-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,15 +20,15 @@ executables: []
20
20
  extensions:
21
21
  - ext/extconf.rb
22
22
  extra_rdoc_files:
23
- - README.rdoc
23
+ - README.md
24
24
  files:
25
- - README.rdoc
26
25
  - Rakefile
27
26
  - ext/real_growl_api.c
28
27
  - ext/real_growl_api.h
28
+ - ext/ruby_delegate.c
29
29
  - ext/ruby_delegate.h
30
- - ext/ruby_delegate.m
31
30
  - lib/real_growl.rb
31
+ - README.md
32
32
  has_rdoc: true
33
33
  homepage: http://github.com/dewind/real-growl
34
34
  licenses: []
data/README.rdoc DELETED
@@ -1,47 +0,0 @@
1
- real-growl
2
-
3
- == DESCRIPTION:
4
-
5
- A Growl notification library that uses native c bindings to interact with GrowlApplicationBridge rather than Growl's network API.
6
-
7
- == SYNOPSIS:
8
-
9
- >> require 'real_growl'
10
- => true
11
- >> rg("Check out", ["Real", "Growl"], :icon => "/path/to/a/picture.jpg")
12
- => nil
13
-
14
- >> Kernel.rg_sticky = false
15
- => false
16
- >> Kernel.rg_priority = 3
17
- => 3
18
- >> Kernel.rg_icon = "/the/path/cool.png"
19
- => "/the/path/cool.png"
20
-
21
- >> my_own_application = RealGrowl::Application.new("AppName")
22
- => #<RealGrowl::Application:0x1018eb6b8>
23
- >> my_own_application.notify(:title => "Title", :description => "Desc", :priority => 0, :sticky => true, :icon => "/path/to/image.png")
24
-
25
- >> RealGrowl.installed?
26
- => true
27
- >> RealGrowl.running?
28
- => true
29
-
30
- == TODO:
31
- * Add executable script
32
- * Enable growl callbacks
33
-
34
- == REQUIREMENTS:
35
-
36
- * MacOS X 10.5 > ??
37
- * Growl Framework - http://growl.info/downloads_developers.php
38
-
39
- == INSTALL:
40
-
41
- Download and install Growl.framework into either ~/Library/Frameworks or /Library/Frameworks
42
- gem install real-growl
43
-
44
- == INSTALLATION HINTS:
45
-
46
- Make sure that the Growl.framework is either 32bit or the 64bit depending on the version of MacOS X
47
- installed and the kind of machine it is installed on.