libnotify 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gem "ffi", ">= 0.6.2"
4
4
 
5
5
  group :test do
6
6
  gem "jeweler"
7
+ gem "watchr"
7
8
  gem "riot", "= 0.11.2"
8
9
  gem "riot_notifier", "~> 0.4.0"
9
10
  gem "yard"
@@ -23,6 +23,7 @@ GEM
23
23
  rubyforge (2.0.4)
24
24
  json_pure (>= 1.1.7)
25
25
  term-ansicolor (1.0.5)
26
+ watchr (0.7)
26
27
  yard (0.6.0)
27
28
 
28
29
  PLATFORMS
@@ -33,4 +34,5 @@ DEPENDENCIES
33
34
  jeweler
34
35
  riot (= 0.11.2)
35
36
  riot_notifier (~> 0.4.0)
37
+ watchr
36
38
  yard
@@ -3,7 +3,9 @@
3
3
  Ruby bindings for libnotify using FFI.
4
4
 
5
5
  Source[http://github.com/splattael/libnotify] |
6
- RDoc[http://rdoc.info/projects/splattael/libnotify]
6
+ RDoc[http://rdoc.info/github/splattael/libnotify/master/file/README.rdoc]
7
+
8
+ http://github.com/splattael/libnotify/raw/master/libnotify.png
7
9
 
8
10
  == Usage
9
11
 
@@ -11,12 +13,12 @@ RDoc[http://rdoc.info/projects/splattael/libnotify]
11
13
 
12
14
  # Block syntax
13
15
  n = Libnotify.new do |notify|
14
- notify.summary = "world"
15
- notify.body = "hello"
16
- notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
17
- notify.urgency = :critical # :low, :normal, :critical
18
- notify.append = false # default true - append onto existing notification
19
- notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
16
+ notify.summary = "hello"
17
+ notify.body = "world"
18
+ notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
19
+ notify.urgency = :critical # :low, :normal, :critical
20
+ notify.append = false # default true - append onto existing notification
21
+ notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
20
22
  end
21
23
  n.show!
22
24
 
@@ -28,6 +30,11 @@ RDoc[http://rdoc.info/projects/splattael/libnotify]
28
30
  n.timeout = 1.5 # overrides :timeout in options
29
31
  end
30
32
 
33
+ # Icon path auto-detection
34
+ Libnotify.icon_dirs << "/usr/share/icons/gnome/*/"
35
+ Libnotify.show(:icon_path => "emblem-default.png")
36
+ Libnotify.show(:icon_path => :"emblem-default")
37
+
31
38
  == Installation
32
39
 
33
40
  gem install libnotify
@@ -38,9 +45,9 @@ You'll need libnotify. On Debian just type:
38
45
 
39
46
  == Testing
40
47
 
41
- git co git://github.com/splattael/libnotify.git
48
+ git clone git://github.com/splattael/libnotify.git
42
49
  cd libnotify
43
- gem install bundler
50
+ (gem install bundler)
44
51
  bundle install
45
52
  rake
46
53
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -13,14 +13,18 @@ module Libnotify
13
13
  #
14
14
  # @example Block syntax
15
15
  # n = Libnotify.new do |notify|
16
- # notify.summary = "world"
17
- # notify.body = "hello"
18
- # notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
19
- # notify.urgency = :critical # :low, :normal, :critical
20
- # notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
16
+ # notify.summary = "hello"
17
+ # notify.body = "world"
18
+ # notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
19
+ # notify.urgency = :critical # :low, :normal, :critical
20
+ # notify.append = false # default true - append onto existing notification
21
+ # notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
21
22
  # end
22
23
  # n.show!
23
24
  #
25
+ # @example Hash syntax
26
+ # Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
27
+ #
24
28
  # @example Mixed syntax
25
29
  # Libnotify.new(options) do |n|
26
30
  # n.timeout = 1.5 # overrides :timeout in options
@@ -46,18 +50,6 @@ module Libnotify
46
50
 
47
51
  # Shows a notification. It takes the same +options+ as Libnotify.new.
48
52
  #
49
- # @example Block syntax
50
- # Libnotify.show do |notify|
51
- # notify.summary = "world"
52
- # notify.body = "hello"
53
- # notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
54
- # notify.urgency = :critical # :low, :normal, :critical
55
- # notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
56
- # end
57
- #
58
- # @example Hash syntax
59
- # Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
60
- #
61
53
  # @see Libnotify.new
62
54
  def self.show(options={}, &block)
63
55
  API.show(options, &block)
@@ -85,8 +77,19 @@ module Libnotify
85
77
  class API
86
78
  include FFI
87
79
 
88
- attr_reader :timeout
89
- attr_accessor :summary, :body, :icon_path, :urgency, :append
80
+ attr_reader :timeout, :icon_path
81
+ attr_accessor :summary, :body, :urgency, :append
82
+
83
+ class << self
84
+ # List of globs to icons
85
+ attr_accessor :icon_dirs
86
+ end
87
+
88
+ self.icon_dirs = [
89
+ "/usr/share/icons/gnome/48x48/emblems",
90
+ "/usr/share/icons/gnome/256x256/emblems",
91
+ "/usr/share/icons/gnome/*/emblems"
92
+ ]
90
93
 
91
94
  # Creates a notification object.
92
95
  #
@@ -141,6 +144,32 @@ module Libnotify
141
144
  end
142
145
  end
143
146
 
147
+ # Sets icon path.
148
+ #
149
+ # Path can be absolute, relative (will be resolved) or an symbol.
150
+ #
151
+ # @todo document and refactor
152
+ def icon_path=(path)
153
+ case path
154
+ when /^\// # absolute
155
+ @icon_path = path
156
+ when String
157
+ # TODO refactor!
158
+ self.class.icon_dirs.map { |d| Dir[d] }.flatten.uniq.each do |dir|
159
+ full_path = File.join(dir, path)
160
+ if File.exist?(full_path)
161
+ @icon_path = full_path
162
+ return
163
+ end
164
+ end
165
+ @icon_path = path
166
+ when Symbol
167
+ self.icon_path = "#{path}.png"
168
+ else
169
+ @icon_path = nil
170
+ end
171
+ end
172
+
144
173
  # Creates and shows a notification. It's a shortcut for +Libnotify.new(options).show!+.
145
174
  #
146
175
  # @see Libnotify.show
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{libnotify}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Suschlik"]
12
- s.date = %q{2011-04-23}
12
+ s.date = %q{2011-05-05}
13
13
  s.email = %q{peter-libnotify@suschlik.de}
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "VERSION",
25
25
  "lib/libnotify.rb",
26
26
  "libnotify.gemspec",
27
+ "libnotify.png",
27
28
  "test.watchr",
28
29
  "test/helper.rb",
29
30
  "test/test_libnotify.rb"
Binary file
@@ -1,15 +1,50 @@
1
1
  #!/usr/bin/env watchr
2
2
 
3
- begin
4
- require File.join(ENV["HOME"], ".watchr.test.rb")
5
- rescue LoadError
6
- warn "Unable to load #{File.join(ENV["HOME"], ".watchr.test.rb")}"
7
- warn "You might try this: http://gist.github.com/raw/273574/8804dff44b104e9b8706826dc8882ed985b4fd13/.watchr.test.rb"
8
- exit
3
+ #!/usr/bin/env watchr
4
+
5
+ def run(cmd)
6
+ puts(cmd)
7
+ system cmd
8
+ end
9
+
10
+ def run_test_file(file)
11
+ clear
12
+ run "ruby -rubygems -Ilib:test #{file}"
13
+ end
14
+
15
+ def run_tests
16
+ clear
17
+ run "rake"
18
+ end
19
+
20
+ def clear
21
+ system "clear"
22
+ end
23
+
24
+ def underscore(file)
25
+ file.gsub('/', '_')
26
+ end
27
+
28
+ @interrupted = false
29
+
30
+ Signal.trap 'QUIT' do
31
+ run_tests
32
+ end
33
+
34
+ Signal.trap 'INT' do
35
+ if @interrupted then
36
+ abort("\n")
37
+ else
38
+ puts "Interrupt a second time to quit"
39
+ @interrupted = true
40
+ Kernel.sleep 1.5
41
+ # raise Interrupt, nil # let the run loop catch it
42
+ run_tests
43
+ end
9
44
  end
10
45
 
11
46
  run_tests
12
47
 
13
- watch('test/test_.*\.rb') {|md| run md[0] }
14
- watch('lib/(.*)\.rb') {|md| run "test/test_#{underscore(md[1])}.rb" }
48
+ watch('test/test_.*\.rb') {|md| run_test_file md[0] }
49
+ watch('lib/(.*)\.rb') {|md| run_test_file "test/test_#{underscore(md[1])}.rb" }
15
50
  watch('test/helper.rb') { run_tests }
@@ -58,10 +58,19 @@ context Libnotify::API do
58
58
  asserts("with to_s.to_i") { topic.timeout = :"2 seconds"; topic.timeout }.equals(2)
59
59
  end
60
60
 
61
+ context "icon_path=" do
62
+ setup { topic.new }
63
+
64
+ asserts("with absolute path") { topic.icon_path = "/some/path/image.jpg"; topic.icon_path }.equals("/some/path/image.jpg")
65
+ asserts("with invalid relative path") { topic.icon_path = "some-invalid-path.jpg"; topic.icon_path }.equals("some-invalid-path.jpg")
66
+ asserts("with relative path") { topic.icon_path = "emblem-favorite.png"; topic.icon_path }.equals("/usr/share/icons/gnome/48x48/emblems/emblem-favorite.png")
67
+ asserts("with symbol") { topic.icon_path = :"emblem-favorite"; topic.icon_path }.equals("/usr/share/icons/gnome/48x48/emblems/emblem-favorite.png")
68
+ end
69
+
61
70
  # TODO Mock FFI calls with rrriot.
62
71
  context "show!" do
63
72
  setup do
64
- topic.new(:timeout => 1.0, :icon_path => "/usr/share/icons/gnome/48x48/emblems/emblem-favorite.png")
73
+ topic.new(:timeout => 1.0, :icon_path => :"emblem-favorite")
65
74
  end
66
75
 
67
76
  context "for real" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libnotify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Suschlik
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-23 00:00:00 +02:00
18
+ date: 2011-05-05 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -96,6 +96,7 @@ files:
96
96
  - VERSION
97
97
  - lib/libnotify.rb
98
98
  - libnotify.gemspec
99
+ - libnotify.png
99
100
  - test.watchr
100
101
  - test/helper.rb
101
102
  - test/test_libnotify.rb