real-growl 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -3
- data/ext/real_growl_api.c +24 -6
- data/lib/real_growl.rb +14 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -8,17 +8,19 @@ A Growl notification library that uses native c bindings to interact with GrowlA
|
|
8
8
|
|
9
9
|
>> require 'real_growl'
|
10
10
|
=> true
|
11
|
-
>> rg("Check out", ["Real", "Growl"])
|
11
|
+
>> rg("Check out", ["Real", "Growl"], :icon => "/path/to/a/picture.jpg")
|
12
12
|
=> nil
|
13
13
|
|
14
14
|
>> Kernel.rg_sticky = false
|
15
15
|
=> false
|
16
16
|
>> Kernel.rg_priority = 3
|
17
17
|
=> 3
|
18
|
+
>> Kernel.rg_icon = "/the/path/cool.png"
|
19
|
+
=> "/the/path/cool.png"
|
18
20
|
|
19
21
|
>> my_own_application = RealGrowl::Application.new("AppName")
|
20
22
|
=> #<RealGrowl::Application:0x1018eb6b8>
|
21
|
-
>> my_own_application.notify("Title", "Desc", 0, true)
|
23
|
+
>> my_own_application.notify(:title => "Title", :description => "Desc", :priority => 0, :sticky => true, :icon => "/path/to/image.png")
|
22
24
|
|
23
25
|
>> RealGrowl.installed?
|
24
26
|
=> true
|
@@ -27,7 +29,6 @@ A Growl notification library that uses native c bindings to interact with GrowlA
|
|
27
29
|
|
28
30
|
== TODO:
|
29
31
|
* Add executable script
|
30
|
-
* Allow for custom icons
|
31
32
|
* Enable growl callbacks
|
32
33
|
|
33
34
|
== REQUIREMENTS:
|
data/ext/real_growl_api.c
CHANGED
@@ -3,6 +3,15 @@
|
|
3
3
|
VALUE rb_mRealGrowl;
|
4
4
|
VALUE rb_cRealGrowlApplication;
|
5
5
|
|
6
|
+
static NSString*
|
7
|
+
build_nsstring(VALUE string) {
|
8
|
+
if(string == Qnil) {
|
9
|
+
return nil;
|
10
|
+
} else {
|
11
|
+
return [NSString stringWithCString:STR2CSTR(string) encoding: NSASCIIStringEncoding];
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
6
15
|
static void
|
7
16
|
free_delegate(id delegate) {
|
8
17
|
[delegate release];
|
@@ -45,13 +54,22 @@ classMethod_running(VALUE self) {
|
|
45
54
|
}
|
46
55
|
|
47
56
|
VALUE
|
48
|
-
|
57
|
+
// VALUE title, VALUE description, VALUE priority, VALUE sticky, VALUE iconPath
|
58
|
+
method_notify(VALUE self, VALUE options) {
|
49
59
|
NSAutoreleasePool *pool = create_autorelease_pool();
|
50
60
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
61
|
+
VALUE title = rb_hash_aref(options, ID2SYM(rb_intern("title")));
|
62
|
+
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;
|
65
|
+
VALUE sticky = rb_hash_aref(options, ID2SYM(rb_intern("sticky")));
|
66
|
+
VALUE iconPath = rb_hash_aref(options, ID2SYM(rb_intern("icon")));
|
67
|
+
BOOL nsSticky = (sticky == Qtrue) ? YES : NO;
|
68
|
+
NSData *data = [NSData dataWithContentsOfFile:build_nsstring(iconPath)];
|
69
|
+
NSString *nsTitle = build_nsstring(title);
|
70
|
+
NSString *nsDescription = build_nsstring(description);
|
71
|
+
|
72
|
+
[GrowlApplicationBridge notifyWithTitle: nsTitle description: nsDescription notificationName: REAL_GROWL_NOTIFICATION iconData: data priority: NUM2INT(priority) isSticky:nsSticky clickContext:nil];
|
55
73
|
|
56
74
|
[pool drain];
|
57
75
|
|
@@ -82,6 +100,6 @@ Init_real_growl_api() {
|
|
82
100
|
rb_cRealGrowlApplication = rb_define_class_under(rb_mRealGrowl, "Application", rb_cObject);
|
83
101
|
rb_define_alloc_func(rb_cRealGrowlApplication, alloc_delegate);
|
84
102
|
rb_define_method(rb_cRealGrowlApplication, "initialize", method_init, 1);
|
85
|
-
rb_define_method(rb_cRealGrowlApplication, "notify", method_notify,
|
103
|
+
rb_define_method(rb_cRealGrowlApplication, "notify", method_notify, 1);
|
86
104
|
}
|
87
105
|
|
data/lib/real_growl.rb
CHANGED
@@ -3,19 +3,31 @@ require 'pp'
|
|
3
3
|
|
4
4
|
module Kernel
|
5
5
|
class<<self
|
6
|
-
attr_accessor :rg_sticky, :rg_priority
|
6
|
+
attr_accessor :rg_sticky, :rg_priority, :rg_icon
|
7
7
|
end
|
8
8
|
|
9
9
|
def rg(*args)
|
10
10
|
Kernel.rg_priority ||= 0
|
11
11
|
Kernel.rg_sticky = true if Kernel.rg_sticky.nil?
|
12
|
+
icon = Kernel.rg_icon
|
12
13
|
|
13
14
|
@__growl_app ||= RealGrowl::Application.new("RealGrowl")
|
14
15
|
|
16
|
+
if args.last.is_a?(Hash) and args.last[:icon]
|
17
|
+
icon = args.last[:icon]
|
18
|
+
args.pop
|
19
|
+
end
|
20
|
+
|
15
21
|
if RealGrowl.running?
|
16
22
|
notifications = args.map { |x| x.pretty_inspect }
|
17
23
|
notifications.each do |x|
|
18
|
-
@__growl_app.notify(
|
24
|
+
@__growl_app.notify(
|
25
|
+
:title => 'rg',
|
26
|
+
:description => x,
|
27
|
+
:priority => Kernel.rg_priority,
|
28
|
+
:sticky => Kernel.rg_sticky,
|
29
|
+
:icon => icon
|
30
|
+
)
|
19
31
|
end
|
20
32
|
end
|
21
33
|
|
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.
|
4
|
+
version: 0.2.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-
|
12
|
+
date: 2010-01-18 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|