libnotify 0.5.1-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rvmrc +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/README.rdoc +61 -0
- data/Rakefile +51 -0
- data/lib/libnotify/api.rb +119 -0
- data/lib/libnotify/ffi.rb +39 -0
- data/lib/libnotify/tasks/rubies.rake +45 -0
- data/lib/libnotify/version.rb +3 -0
- data/lib/libnotify.rb +58 -0
- data/libnotify.gemspec +35 -0
- data/libnotify.png +0 -0
- data/test/helper.rb +6 -0
- data/test/libnotify_io.rb +36 -0
- data/test/test_libnotify.rb +109 -0
- metadata +106 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm @libnotify --create
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= Libnotify
|
2
|
+
|
3
|
+
Ruby bindings for libnotify using FFI.
|
4
|
+
|
5
|
+
Source[http://github.com/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
|
9
|
+
|
10
|
+
== Usage
|
11
|
+
|
12
|
+
require 'libnotify'
|
13
|
+
|
14
|
+
# Block syntax
|
15
|
+
n = Libnotify.new do |notify|
|
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"
|
22
|
+
end
|
23
|
+
n.show!
|
24
|
+
|
25
|
+
# Hash syntax
|
26
|
+
Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
|
27
|
+
|
28
|
+
# Mixed syntax
|
29
|
+
Libnotify.show(options) do |n|
|
30
|
+
n.timeout = 1.5 # overrides :timeout in options
|
31
|
+
end
|
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
|
+
|
38
|
+
== Installation
|
39
|
+
|
40
|
+
gem install libnotify
|
41
|
+
|
42
|
+
You'll need libnotify. On Debian just type:
|
43
|
+
|
44
|
+
apt-get install libnotify1
|
45
|
+
|
46
|
+
== Testing
|
47
|
+
|
48
|
+
git clone git://github.com/splattael/libnotify.git
|
49
|
+
cd libnotify
|
50
|
+
(gem install bundler)
|
51
|
+
bundle install
|
52
|
+
rake
|
53
|
+
|
54
|
+
== Authors
|
55
|
+
|
56
|
+
* Peter Suschlik (http://github.com/splattael)
|
57
|
+
* Dennis Collective (http://github.com/denniscollective)
|
58
|
+
|
59
|
+
== TODO
|
60
|
+
|
61
|
+
* Mock FFI calls with rrriot. (test/test_libnotify.rb:61)
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'rubygems'
|
7
|
+
load 'libnotify/tasks/rubies.rake'
|
8
|
+
|
9
|
+
# Test
|
10
|
+
require 'rake/testtask'
|
11
|
+
desc 'Default: run unit tests.'
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
Rake::TestTask.new(:test) do |test|
|
15
|
+
test.test_files = FileList.new('test/test_*.rb')
|
16
|
+
test.libs << 'test'
|
17
|
+
test.verbose = true
|
18
|
+
end
|
19
|
+
# Yard
|
20
|
+
begin
|
21
|
+
require 'yard'
|
22
|
+
YARD::Rake::YardocTask.new
|
23
|
+
rescue LoadError
|
24
|
+
task :yardoc do
|
25
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Alias for `rake yard`"
|
30
|
+
task :doc => :yard
|
31
|
+
|
32
|
+
# Misc
|
33
|
+
desc "Tag files for vim"
|
34
|
+
task :ctags do
|
35
|
+
dirs = $LOAD_PATH.select {|path| File.directory?(path) }
|
36
|
+
system "ctags -R #{dirs.join(" ")}"
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Find whitespace at line ends"
|
40
|
+
task :eol do
|
41
|
+
system "grep -nrE ' +$' *"
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Display TODOs"
|
45
|
+
task :todo do
|
46
|
+
`grep -Inr TODO lib test`.each do |line|
|
47
|
+
line.scan(/^(.*?:.*?):\s*#\s*TODO\s*(.*)$/) do |(file, todo)|
|
48
|
+
puts "* #{todo} (#{file})"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module Libnotify
|
2
|
+
# API for Libnotify
|
3
|
+
#
|
4
|
+
# @see Libnotify
|
5
|
+
class API
|
6
|
+
include FFI
|
7
|
+
|
8
|
+
attr_reader :timeout, :icon_path
|
9
|
+
attr_accessor :summary, :body, :urgency, :append
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# List of globs to icons
|
13
|
+
attr_accessor :icon_dirs
|
14
|
+
end
|
15
|
+
|
16
|
+
self.icon_dirs = [
|
17
|
+
"/usr/share/icons/gnome/*/emblems",
|
18
|
+
"/usr/share/icons/gnome/*/emotes"
|
19
|
+
]
|
20
|
+
|
21
|
+
# TODO refactor & test!
|
22
|
+
ICON_REGEX = /(\d+)x\d/
|
23
|
+
ICON_SORTER = proc do |a, b|
|
24
|
+
ma = a.scan ICON_REGEX
|
25
|
+
mb = b.scan ICON_REGEX
|
26
|
+
|
27
|
+
if ma.first && mb.first
|
28
|
+
mb.first.first.to_i <=> ma.first.first.to_i
|
29
|
+
elsif ma.first && !mb.first
|
30
|
+
1
|
31
|
+
elsif !ma.first && ma.first
|
32
|
+
-1
|
33
|
+
else
|
34
|
+
a <=> b
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Creates a notification object.
|
39
|
+
#
|
40
|
+
# @see Libnotify.new
|
41
|
+
def initialize(options={}, &block)
|
42
|
+
set_defaults
|
43
|
+
options.each { |key, value| send("#{key}=", value) if respond_to?(key) }
|
44
|
+
yield(self) if block_given?
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_defaults
|
48
|
+
self.summary = self.body = ' '
|
49
|
+
self.urgency = :normal
|
50
|
+
self.timeout = nil
|
51
|
+
self.append = true
|
52
|
+
end
|
53
|
+
private :set_defaults
|
54
|
+
|
55
|
+
# Shows a notification.
|
56
|
+
#
|
57
|
+
# @see Libnotify.show
|
58
|
+
def show!
|
59
|
+
notify_init(self.class.to_s) or raise "notify_init failed"
|
60
|
+
notify = notify_notification_new(summary, body, icon_path, nil)
|
61
|
+
notify_notification_set_urgency(notify, lookup_urgency(urgency))
|
62
|
+
notify_notification_set_timeout(notify, timeout || -1)
|
63
|
+
if append
|
64
|
+
notify_notification_set_hint_string(notify, "x-canonical-append", "")
|
65
|
+
notify_notification_set_hint_string(notify, "append", "")
|
66
|
+
end
|
67
|
+
notify_notification_show(notify, nil)
|
68
|
+
ensure
|
69
|
+
notify_notification_clear_hints(notify) if append
|
70
|
+
end
|
71
|
+
|
72
|
+
# @todo Simplify timeout=
|
73
|
+
def timeout=(timeout)
|
74
|
+
@timeout = case timeout
|
75
|
+
when Float
|
76
|
+
timeout /= 10 if RUBY_VERSION == "1.8.6" # Strange workaround?
|
77
|
+
(timeout * 1000).to_i
|
78
|
+
when Fixnum
|
79
|
+
if timeout >= 100 # assume miliseconds
|
80
|
+
timeout
|
81
|
+
else
|
82
|
+
timeout * 1000
|
83
|
+
end
|
84
|
+
when NilClass, FalseClass
|
85
|
+
nil
|
86
|
+
else
|
87
|
+
timeout.to_s.to_i
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Sets icon path.
|
92
|
+
#
|
93
|
+
# Path can be absolute, relative (will be resolved) or an symbol.
|
94
|
+
#
|
95
|
+
# @todo document and refactor
|
96
|
+
def icon_path=(path)
|
97
|
+
case path
|
98
|
+
when /^\// # absolute
|
99
|
+
@icon_path = path
|
100
|
+
when String
|
101
|
+
list = self.class.icon_dirs.map { |d| Dir[File.join(d, path)] }.flatten.sort(&ICON_SORTER)
|
102
|
+
@icon_path = list.detect { |full_path| File.exist?(full_path) } || path
|
103
|
+
when Symbol
|
104
|
+
self.icon_path = "#{path}.png"
|
105
|
+
else
|
106
|
+
@icon_path = nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Creates and shows a notification. It's a shortcut for +Libnotify.new(options).show!+.
|
111
|
+
#
|
112
|
+
# @see Libnotify.show
|
113
|
+
# @see Libnotify.new
|
114
|
+
def self.show(options={}, &block)
|
115
|
+
new(options, &block).show!
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Libnotify
|
2
|
+
# Raw FFI bindings.
|
3
|
+
module FFI
|
4
|
+
require 'ffi'
|
5
|
+
extend ::FFI::Library
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
ffi_lib %w[libnotify libnotify.so libnotify.so.1]
|
9
|
+
attach_functions!
|
10
|
+
rescue LoadError => e
|
11
|
+
warn e.message
|
12
|
+
end
|
13
|
+
|
14
|
+
URGENCY = [ :low, :normal, :critical ]
|
15
|
+
|
16
|
+
def self.attach_functions!
|
17
|
+
attach_function :notify_init, [:string], :bool
|
18
|
+
attach_function :notify_uninit, [], :void
|
19
|
+
attach_function :notify_notification_new, [:string, :string, :string, :pointer], :pointer
|
20
|
+
attach_function :notify_notification_set_urgency, [:pointer, :int], :void
|
21
|
+
attach_function :notify_notification_set_timeout, [:pointer, :long], :void
|
22
|
+
attach_function :notify_notification_set_hint_string, [:pointer, :string, :string], :void
|
23
|
+
attach_function :notify_notification_clear_hints, [:pointer], :void
|
24
|
+
attach_function :notify_notification_show, [:pointer, :pointer], :bool
|
25
|
+
end
|
26
|
+
|
27
|
+
def lookup_urgency(urgency)
|
28
|
+
URGENCY.index(urgency)
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_missing(method, *args, &block)
|
32
|
+
if method.to_s =~ /^notify_/
|
33
|
+
warn "libnotify.so not found!"
|
34
|
+
end
|
35
|
+
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
SUPPORTED_RUBIES = %w[ree 1.9.2 jruby rbx]
|
2
|
+
|
3
|
+
GEMSPEC = Bundler::GemHelper.new(Dir.pwd).gemspec
|
4
|
+
|
5
|
+
def with_rubies(command)
|
6
|
+
SUPPORTED_RUBIES.each do |ruby|
|
7
|
+
with_ruby(ruby, command)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def with_ruby(ruby, command)
|
12
|
+
rvm = "#{ruby}@#{GEMSPEC.name}"
|
13
|
+
command = %{rvm #{rvm} exec bash -c '#{command}'}
|
14
|
+
|
15
|
+
puts "\n" * 3
|
16
|
+
puts "CMD: #{command}"
|
17
|
+
puts "=" * 40
|
18
|
+
|
19
|
+
system command
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :rubies do
|
23
|
+
desc "Run tests for following supported platforms #{SUPPORTED_RUBIES.inspect}"
|
24
|
+
task :test do
|
25
|
+
command = "bundle check || bundle install && rake"
|
26
|
+
with_rubies(command)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Build gems for following supported platforms #{SUPPORTED_RUBIES.inspect}"
|
30
|
+
task :build do
|
31
|
+
command = "rake build"
|
32
|
+
with_rubies(command)
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Pushes gems for following supported platforms #{SUPPORTED_RUBIES.inspect}"
|
36
|
+
#task :push => :build do
|
37
|
+
task :push do
|
38
|
+
Dir[File.join("pkg", "#{GEMSPEC.name}-#{GEMSPEC.version}*.gem")].each do |gem|
|
39
|
+
command = "gem push #{gem}"
|
40
|
+
puts command
|
41
|
+
system command
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/libnotify.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Ruby bindings for libnotify using FFI.
|
2
|
+
#
|
3
|
+
# See README.rdoc for usage examples.
|
4
|
+
#
|
5
|
+
# @see README.rdoc
|
6
|
+
# @see Libnotify.new
|
7
|
+
# @author Peter Suschlik
|
8
|
+
module Libnotify
|
9
|
+
# Creates a notification.
|
10
|
+
#
|
11
|
+
# @example Block syntax
|
12
|
+
# n = Libnotify.new do |notify|
|
13
|
+
# notify.summary = "hello"
|
14
|
+
# notify.body = "world"
|
15
|
+
# notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
|
16
|
+
# notify.urgency = :critical # :low, :normal, :critical
|
17
|
+
# notify.append = false # default true - append onto existing notification
|
18
|
+
# notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
|
19
|
+
# end
|
20
|
+
# n.show!
|
21
|
+
#
|
22
|
+
# @example Hash syntax
|
23
|
+
# Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
|
24
|
+
#
|
25
|
+
# @example Mixed syntax
|
26
|
+
# Libnotify.new(options) do |n|
|
27
|
+
# n.timeout = 1.5 # overrides :timeout in options
|
28
|
+
# n.show!
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# @param [Hash] options options creating a notification
|
32
|
+
# @option options [String] :summary (' ') summary/title of the notification
|
33
|
+
# @option options [String] :body (' ') the body
|
34
|
+
# @option options [Fixnum, Float, nil, FalseClass, String] :timeout (nil) display duration of the notification.
|
35
|
+
# Use +false+ or +nil+ for no timeout.
|
36
|
+
# @option options [Symbol] :urgency (:normal) the urgency of the notification.
|
37
|
+
# Possible values are: +:low+, +:normal+ and +:critical+
|
38
|
+
# @option options [String] :icon_path path the an icon displayed.
|
39
|
+
#
|
40
|
+
# @yield [notify] passes the notification object
|
41
|
+
# @yieldparam [API] notify the notification object
|
42
|
+
#
|
43
|
+
# @return [API] the notification object
|
44
|
+
def self.new(options={}, &block)
|
45
|
+
API.new(options, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Shows a notification. It takes the same +options+ as Libnotify.new.
|
49
|
+
#
|
50
|
+
# @see Libnotify.new
|
51
|
+
def self.show(options={}, &block)
|
52
|
+
API.show(options, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
autoload :VERSION, 'libnotify/version'
|
56
|
+
autoload :API, 'libnotify/api'
|
57
|
+
autoload :FFI, 'libnotify/ffi'
|
58
|
+
end
|
data/libnotify.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "libnotify"
|
4
|
+
|
5
|
+
platform = Gem::Platform::CURRENT
|
6
|
+
needs_ffi = true
|
7
|
+
|
8
|
+
if RUBY_PLATFORM =~ /java/
|
9
|
+
needs_ffi = false
|
10
|
+
elsif defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
11
|
+
needs_ffi = false
|
12
|
+
platform = Gem::Platform::new ['universal', 'rubinius', '1.2']
|
13
|
+
end
|
14
|
+
|
15
|
+
Gem::Specification.new do |s|
|
16
|
+
s.name = "libnotify"
|
17
|
+
s.version = Libnotify::VERSION
|
18
|
+
s.platform = platform
|
19
|
+
s.authors = ["Peter Suschlik"]
|
20
|
+
s.email = ["peter-libnotify@suschlik.de"]
|
21
|
+
s.homepage = "http://rubygems.org/gems/libnotify"
|
22
|
+
s.summary = %q{Ruby bindings for libnotify using FFI}
|
23
|
+
|
24
|
+
s.files = `git ls-files`.split("\n")
|
25
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
|
29
|
+
if needs_ffi
|
30
|
+
s.add_runtime_dependency 'ffi', '~> 1.0'
|
31
|
+
end
|
32
|
+
|
33
|
+
s.add_development_dependency 'minitest'
|
34
|
+
s.add_development_dependency 'yard', '~> 0.7.0'
|
35
|
+
end
|
data/libnotify.png
ADDED
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class LibnotifyIO
|
2
|
+
attr_reader :io, :libnotify
|
3
|
+
|
4
|
+
def initialize io
|
5
|
+
@io = io
|
6
|
+
@libnotify = begin
|
7
|
+
require 'libnotify'
|
8
|
+
Libnotify.new(:timeout => 2.5, :append => false)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def puts *o
|
13
|
+
if o.first =~ /(\d+) failures, (\d+) errors/
|
14
|
+
description = [ RUBY_ENGINE, RUBY_VERSION, RUBY_PLATFORM ].join(" ")
|
15
|
+
libnotify.body = o.first
|
16
|
+
if $1.to_i > 0 || $2.to_i > 0 # fail?
|
17
|
+
libnotify.summary = ":-( #{description}"
|
18
|
+
libnotify.urgency = :critical
|
19
|
+
libnotify.icon_path = "face-angry.*"
|
20
|
+
else
|
21
|
+
libnotify.summary += ":-) #{description}"
|
22
|
+
libnotify.urgency = :normal
|
23
|
+
libnotify.icon_path = "face-laugh.*"
|
24
|
+
end
|
25
|
+
libnotify.show!
|
26
|
+
else
|
27
|
+
io.puts *o
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_missing msg, *args
|
32
|
+
io.send(msg, *args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
MiniTest::Unit.output = LibnotifyIO.new(MiniTest::Unit.output)
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestLibnotify < MiniTest::Unit::TestCase
|
4
|
+
def test_respond_to
|
5
|
+
assert_respond_to Libnotify, :new
|
6
|
+
assert_respond_to Libnotify, :show
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_delegation
|
10
|
+
skip "test delegation using mock"
|
11
|
+
|
12
|
+
# old code
|
13
|
+
asserts("#new calls API#new") do
|
14
|
+
mock(Libnotify::API).new(hash_including(:body => "test")) { true }
|
15
|
+
Libnotify.new(:body => "test")
|
16
|
+
end
|
17
|
+
asserts("#show calls API#show") do
|
18
|
+
mock(Libnotify::API).show(hash_including(:body => "test")) { true }
|
19
|
+
Libnotify.show(:body => "test")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_version
|
24
|
+
assert defined?(Libnotify::VERSION), "version is defined"
|
25
|
+
assert Libnotify::VERSION
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class TestLibnotifyAPI < MiniTest::Unit::TestCase
|
30
|
+
def test_without_options_and_block
|
31
|
+
assert_equal " ", libnotify.summary
|
32
|
+
assert_equal " ", libnotify.body
|
33
|
+
assert_equal :normal, libnotify.urgency
|
34
|
+
assert_nil libnotify.timeout
|
35
|
+
assert_nil libnotify.icon_path
|
36
|
+
assert libnotify.append
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_with_options_and_block
|
40
|
+
libnotify(:summary => "hello", :body => "body", :invalid_option => 23) do |n|
|
41
|
+
n.body = "overwritten"
|
42
|
+
n.icon_path = "/path/to/icon"
|
43
|
+
n.append = false
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_equal "hello", libnotify.summary
|
47
|
+
assert_equal "overwritten", libnotify.body
|
48
|
+
assert_equal "/path/to/icon", libnotify.icon_path
|
49
|
+
assert !libnotify.append
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_timeout_setter
|
53
|
+
assert_timeout 2500, 2.5, "with float"
|
54
|
+
assert_timeout 100, 100, "with fixnum ms"
|
55
|
+
assert_timeout 101, 101, "with fixnum ms"
|
56
|
+
assert_timeout 1000, 1, "with fixnum seconds"
|
57
|
+
assert_timeout 99000, 99, "with fixnum seconds"
|
58
|
+
assert_timeout nil, nil, "with nil"
|
59
|
+
assert_timeout nil, false, "with false"
|
60
|
+
assert_timeout 2, :"2 s", "with to_s.to_i"
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_icon_path_setter
|
64
|
+
Libnotify::API.icon_dirs << File.expand_path("../..", __FILE__)
|
65
|
+
assert_icon_path "/some/path/image.jpg", "/some/path/image.jpg", "with absolute path"
|
66
|
+
assert_icon_path "some-invalid-path.jpg", "some-invalid-path.jpg", "with non-existant relative path"
|
67
|
+
assert_icon_path %r{^/.*/libnotify.png}, "libnotify.png", "with relative path"
|
68
|
+
assert_icon_path %r{^/.*/libnotify.png}, :"libnotify", "with symbol"
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_integration
|
72
|
+
skip "enable integration"
|
73
|
+
|
74
|
+
libnotify = Libnotify::API.new(:timeout => 0.5, :icon_path => :"emblem-favorite", :append => true)
|
75
|
+
|
76
|
+
[ :low, :normal, :critical ].each do |urgency|
|
77
|
+
libnotify.summary = "#{RUBY_VERSION} at #{RUBY_PLATFORM}"
|
78
|
+
libnotify.body = [ urgency, defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : '?' ].join(" ")
|
79
|
+
libnotify.urgency = urgency
|
80
|
+
libnotify.show!
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def libnotify(options={}, &block)
|
87
|
+
@libnotify ||= Libnotify::API.new(options, &block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def assert_timeout(expected, value, message)
|
91
|
+
assert_value_set :timeout, expected, value, message
|
92
|
+
end
|
93
|
+
|
94
|
+
def assert_icon_path(expected, value, message)
|
95
|
+
assert_value_set :icon_path, expected, value, message
|
96
|
+
end
|
97
|
+
|
98
|
+
def assert_value_set(attribute, expected, value, message)
|
99
|
+
libnotify.send("#{attribute}=", value)
|
100
|
+
got = libnotify.send(attribute)
|
101
|
+
case expected
|
102
|
+
when Regexp
|
103
|
+
assert_match expected, got, message
|
104
|
+
else
|
105
|
+
assert_equal expected, got, message
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libnotify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.5.1
|
6
|
+
platform: x86-linux
|
7
|
+
authors:
|
8
|
+
- Peter Suschlik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-19 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: ffi
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "1.0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: yard
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.7.0
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
description:
|
50
|
+
email:
|
51
|
+
- peter-libnotify@suschlik.de
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- .rvmrc
|
61
|
+
- .travis.yml
|
62
|
+
- Gemfile
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- lib/libnotify.rb
|
66
|
+
- lib/libnotify/api.rb
|
67
|
+
- lib/libnotify/ffi.rb
|
68
|
+
- lib/libnotify/tasks/rubies.rake
|
69
|
+
- lib/libnotify/version.rb
|
70
|
+
- libnotify.gemspec
|
71
|
+
- libnotify.png
|
72
|
+
- test/helper.rb
|
73
|
+
- test/libnotify_io.rb
|
74
|
+
- test/test_libnotify.rb
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://rubygems.org/gems/libnotify
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.6.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Ruby bindings for libnotify using FFI
|
103
|
+
test_files:
|
104
|
+
- test/helper.rb
|
105
|
+
- test/libnotify_io.rb
|
106
|
+
- test/test_libnotify.rb
|