libnotify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/.gitignore +4 -0
  2. data/README.rdoc +32 -0
  3. data/Rakefile +55 -0
  4. data/VERSION +1 -0
  5. data/lib/libnotify.rb +89 -0
  6. metadata +68 -0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ doc
2
+ pkg
3
+ coverage
4
+ tags
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ = Libnotify
2
+
3
+ Ruby binding for libnotify using FFI.
4
+
5
+ == Usage
6
+
7
+ require 'libnotify'
8
+
9
+ # Using a block
10
+ Libnotify.new do |notify|
11
+ notify.summary = "world"
12
+ notify.body = "hello"
13
+ notify.timeout = 1.5 # or 1000ms, nil, false
14
+ notify.urgency = :critical # or :low, :normal, :critical
15
+ notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
16
+ notify.show!
17
+ end
18
+
19
+ # Alternative syntax
20
+ Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
21
+
22
+ == Install via gemcutter
23
+ gem install gemcutter
24
+ gem tumble
25
+ gem install libnotify
26
+
27
+ == Authors
28
+ * Peter Suschlik
29
+
30
+ == TODO
31
+
32
+ * Tests!
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = "libnotify"
11
+ gem.summary = 'Ruby bindings for libnotify using FFI'
12
+ gem.email = "peter-libnotify@suschlik.de"
13
+ gem.homepage = "http://github.com/splattael/libnotify"
14
+ gem.authors = ["Peter Suschlik"]
15
+
16
+ gem.has_rdoc = true
17
+ gem.extra_rdoc_files = [ "README.rdoc" ]
18
+
19
+ gem.add_dependency "ffi"
20
+
21
+ #gem.add_development_dependency "riot", "= 0.10.4"
22
+
23
+ #gem.test_files = Dir.glob('test/test_*.rb')
24
+ end
25
+
26
+ Jeweler::GemcutterTasks.new
27
+
28
+ # Test
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.test_files = FileList.new('test/test_*.rb')
32
+ test.libs << 'test'
33
+ test.verbose = true
34
+ end
35
+
36
+ # RDoc
37
+ Rake::RDocTask.new do |rd|
38
+ rd.title = "Riot Notifier"
39
+ rd.main = "README.rdoc"
40
+ rd.rdoc_files.include("README.rdoc", "lib/*.rb")
41
+ rd.rdoc_dir = "doc"
42
+ end
43
+
44
+
45
+ # Misc
46
+ desc "Tag files for vim"
47
+ task :ctags do
48
+ dirs = $LOAD_PATH.select {|path| File.directory?(path) }
49
+ system "ctags -R #{dirs.join(" ")}"
50
+ end
51
+
52
+ desc "Find whitespace at line ends"
53
+ task :eol do
54
+ system "grep -nrE ' +$' *"
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/libnotify.rb ADDED
@@ -0,0 +1,89 @@
1
+
2
+
3
+ require 'rubygems'
4
+ require 'ffi'
5
+
6
+ module Libnotify
7
+
8
+ def self.new(*args, &block)
9
+ API.new(*args, &block)
10
+ end
11
+
12
+ def self.show(*args, &block)
13
+ API.show(*args, &block)
14
+ end
15
+
16
+ module FFI
17
+ extend ::FFI::Library
18
+
19
+ ffi_lib 'libnotify'
20
+
21
+ enum :urgency, [ :low, :normal, :critical ]
22
+
23
+ attach_function :notify_init, [:string], :bool
24
+ attach_function :notify_uninit, [], :void
25
+
26
+ attach_function :notify_notification_new, [:string, :string, :string, :pointer], :pointer
27
+ attach_function :notify_notification_set_urgency, [:pointer, :urgency], :void
28
+ attach_function :notify_notification_set_timeout, [:pointer, :long], :void
29
+ attach_function :notify_notification_show, [:pointer, :pointer], :bool
30
+ end
31
+
32
+ class API
33
+ include FFI
34
+ attr_accessor :name, :summary, :body, :icon_path, :timeout, :urgency
35
+
36
+ def initialize(options = {}, &block)
37
+ self.summary = self.body = " "
38
+ self.urgency = :normal
39
+ self.timeout = nil
40
+ options.each { |key, value| send("#{key}=", value) if respond_to?(key) }
41
+ yield(self) if block_given?
42
+ end
43
+
44
+ def self.show(*args, &block)
45
+ new(*args, &block).show!
46
+ end
47
+
48
+ def show!
49
+ notify_init(self.class.to_s) or raise "notify_init failed"
50
+ notify = FFI.notify_notification_new(summary, body, icon_path, nil)
51
+ notify_notification_set_urgency(notify, urgency)
52
+ notify_notification_set_timeout(notify, timeout)
53
+ notify_notification_show(notify, nil)
54
+ ensure
55
+ notify_uninit
56
+ end
57
+
58
+ def timeout=(timeout)
59
+ @timeout = case timeout
60
+ when NilClass, FalseClass
61
+ -1
62
+ when Float
63
+ (timeout * 1000).to_i
64
+ when Fixnum
65
+ if timeout > 100 # assume miliseconds
66
+ timeout
67
+ else
68
+ timeout * 1000
69
+ end
70
+ else
71
+ timeout.to_i
72
+ end
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ if $0 == __FILE__
79
+ Libnotify.new do |notify|
80
+ notify.summary = "world"
81
+ notify.body = "hello"
82
+ notify.timeout = 1.5 # or 1000ms, nil, false
83
+ notify.urgency = :critical # or :low, :normal, :critical
84
+ notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
85
+ notify.show!
86
+ end
87
+
88
+ Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
89
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libnotify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Suschlik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-06 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ffi
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: peter-libnotify@suschlik.de
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - .gitignore
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - lib/libnotify.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/splattael/libnotify
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --charset=UTF-8
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.5
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Ruby bindings for libnotify using FFI
67
+ test_files: []
68
+