dmathieu-growlcocoa 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
File without changes
data/README.textile ADDED
@@ -0,0 +1,57 @@
1
+ h1. Growl Notifier
2
+
3
+ Copyright (c) 2007-2008 Satoshi Nakagawa <psychs@limechat.net>
4
+ Exported as a gem by Damien MATHIEU <42@dmathieu.com>
5
+ You can redistribute it and/or modify it under the same terms as Ruby.
6
+
7
+ h2. Overview
8
+
9
+ Growl Notifier is a class to post notifications to the Growl daemon.
10
+ And also it can receive clicked and timeout notifications from Growl.
11
+
12
+ h2. Requirements
13
+
14
+ Mac OS X 10.4 or 10.5
15
+ Ruby 1.8 (http://ruby-lang.org/)
16
+ RubyCocoa (http://rubycocoa.sourceforge.net/)
17
+
18
+ h2. How to install
19
+
20
+ The Growl Notifier is a gem. So to install it, you only need to do :
21
+
22
+ > gem sources -a http://gems.github.com
23
+ > sudo gem install dmathieu-growlcocoa
24
+
25
+ And you're ready to go :)
26
+
27
+
28
+ h2. How to use Growl Notifier
29
+
30
+ A simple example:
31
+
32
+ > require 'growl'
33
+
34
+ > g = Growl::Notifier.alloc.init<br />
35
+ > g.start('test_app', ['message_type'])<br />
36
+ > g.notify('message_type', 'title', 'desc')
37
+
38
+ How to receive clicked and timeout notifications in your application:
39
+
40
+ > require 'growl'
41
+
42
+ > class GrowlController < OSX::NSObject
43
+ > def init
44
+ > @g = Growl::Notifier.alloc.initWithDelegate(self)
45
+ > @g.start('test_app', ['message_type'])
46
+ > @g.notify('message_type', 'title', 'desc', 'click_context')
47
+ > self
48
+ > end
49
+
50
+ > def growl_onClicked(sender, context)
51
+ > puts 'clicked'
52
+ > end
53
+
54
+ > def growl_onTimeout(sender, context)
55
+ > puts 'timeout'
56
+ > end
57
+ > end
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "growlcocoa"
8
+ gem.summary = %Q{A library to send growl alerts using rubycocoa}
9
+ gem.email = "42@dmathieu.com"
10
+ gem.homepage = "http://github.com/dmathieu/growlcocoa"
11
+ gem.authors = ["Satoshi Nakagawa", "Damien MATHIEU"]
12
+ end
13
+ rescue LoadError
14
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
15
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,38 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{growlcocoa}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Satoshi Nakagawa", "Damien MATHIEU"]
12
+ s.date = %q{2009-09-20}
13
+ s.email = %q{42@dmathieu.com}
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/dmathieu/growlcocoa}
16
+ s.rdoc_options = ["--charset=UTF-8"]
17
+ s.require_paths = ["lib"]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.textile",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "growlcocoa.gemspec",
24
+ "lib/growl.rb",
25
+ ]
26
+ s.rubygems_version = %q{1.3.1}
27
+ s.summary = %q{A library to send growl alerts using rubycocoa}
28
+
29
+ if s.respond_to? :specification_version then
30
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
31
+ s.specification_version = 2
32
+
33
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
34
+ else
35
+ end
36
+ else
37
+ end
38
+ end
data/lib/growl.rb ADDED
@@ -0,0 +1,154 @@
1
+ #
2
+ # = growl.rb
3
+ #
4
+ # Growl Notifier
5
+ #
6
+ # Copyright (c) 2007-2008 Satoshi Nakagawa <psychs@limechat.net>
7
+ # Exported as a gem by Damien MATHIEU <42@dmathieu.com>
8
+ # You can redistribute it and/or modify it under the same terms as Ruby.
9
+ #
10
+ # == Overview
11
+ #
12
+ # Growl Notifier is a class to post notifications to the Growl daemon.
13
+ # And also it can receive clicked and timeout notifications from Growl.
14
+ #
15
+ # == Requirements
16
+ #
17
+ # Mac OS X 10.4 or 10.5
18
+ # Ruby 1.8 (http://ruby-lang.org/)
19
+ # RubyCocoa (http://rubycocoa.sourceforge.net/)
20
+ #
21
+ # == How to use Growl Notifier
22
+ #
23
+ # A simple example:
24
+ #
25
+ # require 'growl'
26
+ #
27
+ # g = Growl::Notifier.alloc.init
28
+ # g.start('test_app', ['message_type'])
29
+ # g.notify('message_type', 'title', 'desc')
30
+ #
31
+ # How to receive clicked and timeout notifications in your application:
32
+ #
33
+ # require 'growl'
34
+ #
35
+ # class GrowlController < OSX::NSObject
36
+ # def init
37
+ # @g = Growl::Notifier.alloc.initWithDelegate(self)
38
+ # @g.start('test_app', ['message_type'])
39
+ # @g.notify('message_type', 'title', 'desc', 'click_context')
40
+ # self
41
+ # end
42
+ #
43
+ # def growl_onClicked(sender, context)
44
+ # puts 'clicked'
45
+ # end
46
+ #
47
+ # def growl_onTimeout(sender, context)
48
+ # puts 'timeout'
49
+ # end
50
+ # end
51
+ #
52
+
53
+ require 'osx/cocoa'
54
+
55
+ module Growl
56
+ class Notifier < OSX::NSObject
57
+ include OSX
58
+ attr_accessor :delegate
59
+
60
+ GROWL_IS_READY = "Lend Me Some Sugar; I Am Your Neighbor!"
61
+ GROWL_NOTIFICATION_CLICKED = "GrowlClicked!"
62
+ GROWL_NOTIFICATION_TIMED_OUT = "GrowlTimedOut!"
63
+ GROWL_KEY_CLICKED_CONTEXT = "ClickedContext"
64
+
65
+
66
+ def initWithDelegate(delegate)
67
+ init
68
+ @delegate = delegate
69
+ self
70
+ end
71
+
72
+ def start(appname, notifications, default_notifications=nil, appicon=nil)
73
+ @appname = appname
74
+ @notifications = notifications
75
+ @default_notifications = default_notifications
76
+ @appicon = appicon
77
+ @default_notifications = @notifications unless @default_notifications
78
+ register
79
+ end
80
+
81
+ def notify(type, title, desc, click_context=nil, sticky=false, priority=0, icon=nil)
82
+ dic = {
83
+ :ApplicationName => @appname,
84
+ :ApplicationPID => NSProcessInfo.processInfo.processIdentifier,
85
+ :NotificationName => type,
86
+ :NotificationTitle => title,
87
+ :NotificationDescription => desc,
88
+ :NotificationPriority => priority,
89
+ }
90
+ dic[:NotificationIcon] = icon.TIFFRepresentation if icon
91
+ dic[:NotificationSticky] = 1 if sticky
92
+ dic[:NotificationClickContext] = click_context if click_context
93
+
94
+ c = NSDistributedNotificationCenter.defaultCenter
95
+ c.postNotificationName_object_userInfo_deliverImmediately(:GrowlNotification, nil, dic, true)
96
+ end
97
+
98
+ KEY_TABLE = {
99
+ :type => :NotificationName,
100
+ :title => :NotificationTitle,
101
+ :desc => :NotificationDescription,
102
+ :clickContext => :NotificationClickContext,
103
+ :sticky => :NotificationSticky,
104
+ :priority => :NotificationPriority,
105
+ :icon => :NotificationIcon,
106
+ }
107
+
108
+ def notifyWith(hash)
109
+ dic = {}
110
+ KEY_TABLE.each {|k,v| dic[v] = hash[k] if hash.key?(k) }
111
+ dic[:ApplicationName] = @appname
112
+ dic[:ApplicationPID] = NSProcessInfo.processInfo.processIdentifier
113
+
114
+ c = NSDistributedNotificationCenter.defaultCenter
115
+ c.postNotificationName_object_userInfo_deliverImmediately(:GrowlNotification, nil, dic, true)
116
+ end
117
+
118
+
119
+ def onReady(n)
120
+ register
121
+ end
122
+
123
+ def onClicked(n)
124
+ context = n.userInfo[GROWL_KEY_CLICKED_CONTEXT].to_s
125
+ @delegate.growl_onClicked(self, context) if @delegate && @delegate.respond_to?(:growl_onClicked)
126
+ end
127
+
128
+ def onTimeout(n)
129
+ context = n.userInfo[GROWL_KEY_CLICKED_CONTEXT].to_s
130
+ @delegate.growl_onTimeout(self, context) if @delegate && @delegate.respond_to?(:growl_onTimeout)
131
+ end
132
+
133
+
134
+ private
135
+
136
+ def register
137
+ pid = NSProcessInfo.processInfo.processIdentifier.to_i
138
+
139
+ c = NSDistributedNotificationCenter.defaultCenter
140
+ c.addObserver_selector_name_object(self, 'onReady:', GROWL_IS_READY, nil)
141
+ c.addObserver_selector_name_object(self, 'onClicked:', "#{@appname}-#{pid}-#{GROWL_NOTIFICATION_CLICKED}", nil)
142
+ c.addObserver_selector_name_object(self, 'onTimeout:', "#{@appname}-#{pid}-#{GROWL_NOTIFICATION_TIMED_OUT}", nil)
143
+
144
+ icon = @appicon || NSApplication.sharedApplication.applicationIconImage
145
+ dic = {
146
+ :ApplicationName => @appname,
147
+ :AllNotifications => @notifications,
148
+ :DefaultNotifications => @default_notifications,
149
+ :ApplicationIcon => icon.TIFFRepresentation,
150
+ }
151
+ c.postNotificationName_object_userInfo_deliverImmediately(:GrowlApplicationRegistrationNotification, nil, dic, true)
152
+ end
153
+ end
154
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmathieu-growlcocoa
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Satoshi Nakagawa
8
+ - Damien MATHIEU
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-09-20 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: 42@dmathieu.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - .gitignore
27
+ - README.textile
28
+ - Rakefile
29
+ - VERSION
30
+ - growlcocoa.gemspec
31
+ - lib/growl.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/dmathieu/growlcocoa
34
+ licenses:
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --charset=UTF-8
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.3.5
56
+ signing_key:
57
+ specification_version: 2
58
+ summary: A library to send growl alerts using rubycocoa
59
+ test_files: []
60
+