tin 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/Rakefile +9 -0
  2. data/lib/sn.rb +35 -26
  3. data/spec/sn_spec.rb +149 -0
  4. metadata +37 -4
data/Rakefile CHANGED
@@ -0,0 +1,9 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new('spec')
4
+
5
+ task :default => :spec
6
+
7
+ task :build do
8
+ system "gem build tin.gemspec"
9
+ end
data/lib/sn.rb CHANGED
@@ -24,16 +24,14 @@ Tin is a simple interface to libnotify using Fiddle.
24
24
 
25
25
  Deprecated functions are not included in the those available through Sn.
26
26
 
27
- These function are also not included (for lack of a good implementation):
28
- * void notify_notification_set_hint(NotifyNotification *notification,
29
- const char *key, GVariant *value);
30
- * void notify_notification_clear_hints(NotifyNotification *notification);
31
- * void notify_notification_set_image_from_pixbuf(
32
- NotifyNotification *notification, GdkPixbuf *pixbuf);
33
- * void notify_notification_add_action(NotifyNotification *notification,
34
- const char *action, const char *label, NotifyActionCallback callback,
35
- gpointer user_data, GFreeFunc free_func);
36
- * void notify_notification_clear_actions(NotifyNotification *notification);
27
+ These function are also not included:
28
+ * notify_get_server_caps
29
+ * notify_get_server_info
30
+ * notify_notification_set_hint
31
+ * notify_notification_clear_hints
32
+ * notify_notification_set_image_from_pixbuf
33
+ * notify_notification_add_action
34
+ * notify_notification_clear_actions
37
35
  =end
38
36
 
39
37
  module Sn
@@ -42,30 +40,34 @@ module Sn
42
40
  # Mapping from keyword urgencies to the in values used by libnotify
43
41
  URGENCIES = {:low => 0, :normal => 1, :critical => 2}
44
42
 
43
+ # Mapping from keyword timeouts to the int values libnotify uses
44
+ TIMEOUTS = {:default => -1, :never => 0}
45
+
45
46
  # Uninitialize libnotify
46
47
  def self.stop
47
- @notify[:uninit].call
48
+ @notify[:uninit].call if @notify[:is_initted].call == 1
48
49
  end
49
50
 
50
51
  # Setup the libnotify interface and initialize libnotify.
51
52
  def self.start(app_name)
52
53
  notify_cmd = {
53
54
  :init => {:arg => [TYPE_VOIDP], :ret => TYPE_INT},
54
- :uninit => {:arg => [], :ret => TYPE_INT}
55
+ :uninit => {:arg => [], :ret => TYPE_INT},
56
+ :is_initted => {:arg => [], :ret => TYPE_INT},
57
+ :get_app_name => {:arg => [], :ret => TYPE_VOIDP},
58
+ :set_app_name => {:arg => [TYPE_VOIDP], :ret => TYPE_VOID}
55
59
  }
56
60
 
57
61
  notification_cmd = {
58
- :new => {:arg => [TYPE_VOIDP, TYPE_VOIDP, TYPE_VOIDP],
59
- :ret => TYPE_VOIDP},
60
- :show => {:arg => [TYPE_VOIDP, TYPE_VOIDP], :ret => TYPE_INT},
61
- :update => {:arg => [TYPE_VOIDP, TYPE_VOIDP, TYPE_VOIDP, TYPE_VOIDP],
62
- :ret => TYPE_INT},
62
+ :new => {:arg => [TYPE_VOIDP] * 3, :ret => TYPE_VOIDP},
63
+ :show => {:arg => [TYPE_VOIDP] * 2, :ret => TYPE_INT},
64
+ :update => {:arg => [TYPE_VOIDP] * 4, :ret => TYPE_INT},
63
65
  :set_urgency => {:arg => [TYPE_VOIDP, TYPE_INT], :ret => TYPE_VOID},
64
- :close => {:arg => [TYPE_VOIDP, TYPE_VOIDP], :ret => TYPE_INT},
66
+ :close => {:arg => [TYPE_VOIDP] * 2, :ret => TYPE_INT},
65
67
  :get_closed_reason => {:arg => [TYPE_VOIDP], :ret => TYPE_INT},
66
- :set_app_name => {:arg => [TYPE_VOIDP, TYPE_VOIDP], :ret => TYPE_VOID},
68
+ :set_app_name => {:arg => [TYPE_VOIDP] * 2, :ret => TYPE_VOID},
67
69
  :set_timeout => {:arg => [TYPE_VOIDP, TYPE_INT], :ret => TYPE_VOID},
68
- :set_category => {:arg => [TYPE_VOIDP, TYPE_VOIDP], :ret => TYPE_VOID},
70
+ :set_category => {:arg => [TYPE_VOIDP] * 2, :ret => TYPE_VOID}
69
71
  }
70
72
 
71
73
  dl = DL.dlopen 'libnotify.so'
@@ -104,12 +106,21 @@ module Sn
104
106
  @notification[:show].call n, nil
105
107
  end
106
108
 
109
+ def self.app_name
110
+ NOTIFY[:get_app_name].call
111
+ end
112
+
113
+ def self.set_app_name(value=$0)
114
+ NOTIFY[:set_app_name].call value
115
+ end
116
+
107
117
  # This class manages an application notification.
108
118
  class Notification
109
119
  attr_reader :app_name, :category, :summary, :message, :urgency, :icon
120
+ attr_reader :timeout
110
121
 
111
122
  # Mapping from keyword timeouts to the int values libnotify uses
112
- @@timeout_consts = {:default => -1, :never => 0}
123
+ @@timeout_consts = TIMEOUTS
113
124
 
114
125
  # +summary+:: the summary line generally displayed at the top of the
115
126
  # notification
@@ -167,7 +178,7 @@ module Sn
167
178
  end
168
179
 
169
180
  def category=(value)
170
- @category = category
181
+ @category = value
171
182
  NOTIFICATION[:set_category].call @notification, @category
172
183
  end
173
184
 
@@ -175,16 +186,14 @@ module Sn
175
186
  # timeout can be specified as a number of milliseconds or using the keywords
176
187
  # +:default+ or +:never+.
177
188
  def timeout=(timeout=:default)
178
- @timeout = @@timeout_consts[timeout] if @@timeout_consts.member?(timeout)
189
+ @timeout = TIMEOUTS.member?(timeout) ? TIMEOUTS[timeout] : timeout
179
190
  NOTIFICATION[:set_timeout].call @notification, @timeout
180
191
  end
181
192
 
182
193
  def urgency=(value)
183
- @urgency = value
194
+ @urgency = URGENCIES[value]
184
195
  NOTIFICATION[:set_urgency].call @notification, URGENCIES[@urgency]
185
196
  end
186
197
  end
187
198
  end
188
199
 
189
-
190
-
@@ -0,0 +1,149 @@
1
+ require 'fiddle'
2
+
3
+ module Fiddle
4
+ class Function
5
+ attr_accessor :count
6
+
7
+ def initialize(lib, args, ret)
8
+ @count = 0
9
+ @lib = lib
10
+ @args = args
11
+ @ret = ret
12
+ end
13
+
14
+ def call(*args)
15
+ @count += 1
16
+ raise "Wrong # of args" unless @args.size == args.size
17
+ end
18
+ end
19
+ end
20
+
21
+ require 'sn'
22
+
23
+ describe Sn, ".notify" do
24
+ it "should show a notification" do
25
+ Sn::NOTIFICATION[:new].count = 0
26
+ Sn::NOTIFICATION[:show].count = 0
27
+ Sn.notify "summary", "message", ""
28
+ Sn::NOTIFICATION[:new].count.should eq(1)
29
+ Sn::NOTIFICATION[:show].count.should eq(1)
30
+ end
31
+ end
32
+
33
+ describe Sn::Notification, ".show" do
34
+ it "should show a notification" do
35
+ Sn::NOTIFICATION[:show].count = 0
36
+ n = Sn::Notification.new "summary", "message", ""
37
+ n.show
38
+ Sn::NOTIFICATION[:show].count.should eq(1)
39
+ end
40
+ end
41
+
42
+ describe Sn::Notification, ".close" do
43
+ it "should close a notification" do
44
+ Sn::NOTIFICATION[:close].count = 0
45
+ n = Sn::Notification.new "summary", "message", ""
46
+ n.show
47
+ n.close
48
+ Sn::NOTIFICATION[:close].count.should eq(1)
49
+ end
50
+ end
51
+
52
+ describe Sn::Notification, ".summary=" do
53
+ it "should update a notification's summary" do
54
+ summary = "Stuff"
55
+ Sn::NOTIFICATION[:update].count = 0
56
+ n = Sn::Notification.new "summary", "message", ""
57
+ n.summary = summary
58
+ n.show
59
+ Sn::NOTIFICATION[:update].count.should eq(1)
60
+ n.summary.should eq(summary)
61
+ end
62
+ end
63
+
64
+
65
+ describe Sn::Notification, ".message=" do
66
+ it "should update a notification's message" do
67
+ message = "Stuff"
68
+ Sn::NOTIFICATION[:update].count = 0
69
+ n = Sn::Notification.new "summary", "message", ""
70
+ n.message = message
71
+ n.show
72
+ Sn::NOTIFICATION[:update].count.should eq(1)
73
+ n.message.should eq(message)
74
+ end
75
+ end
76
+
77
+ describe Sn::Notification, ".icon=" do
78
+ it "should update a notification's icon" do
79
+ icon = "refresh"
80
+ Sn::NOTIFICATION[:update].count = 0
81
+ n = Sn::Notification.new "summary", "message", ""
82
+ n.icon =icon
83
+ n.show
84
+ Sn::NOTIFICATION[:update].count.should eq(1)
85
+ n.icon.should eq(icon)
86
+ end
87
+ end
88
+
89
+ describe Sn::Notification, ".category=" do
90
+ it "should set a notification's category" do
91
+ category = "Category"
92
+ Sn::NOTIFICATION[:set_category].count = 0
93
+ n = Sn::Notification.new "summary", "message", ""
94
+ n.category = category
95
+ n.show
96
+ Sn::NOTIFICATION[:set_category].count.should eq(1)
97
+ n.category.should eq(category)
98
+ end
99
+ end
100
+
101
+ describe Sn::Notification, ".urgency=" do
102
+ it "should set a notification's urgency" do
103
+ Sn::NOTIFICATION[:set_urgency].count = 0
104
+ n = Sn::Notification.new "summary", "message", ""
105
+ n.urgency = :low
106
+ n.show
107
+ Sn::NOTIFICATION[:set_urgency].count.should eq(1)
108
+ end
109
+
110
+ it "should map keyword urgencies properly" do
111
+ n = Sn::Notification.new "summary", "message", ""
112
+ n.urgency = :low
113
+ n.urgency.should eq(Sn::URGENCIES[:low])
114
+ n.urgency = :normal
115
+ n.urgency.should eq(Sn::URGENCIES[:normal])
116
+ n.urgency = :critical
117
+ n.urgency.should eq(Sn::URGENCIES[:critical])
118
+ end
119
+ end
120
+
121
+ describe Sn::Notification, ".timeout=" do
122
+ it "should set a notification's timeout" do
123
+ Sn::NOTIFICATION[:set_timeout].count = 0
124
+ n = Sn::Notification.new "summary", "message", ""
125
+ n.timeout = 1023
126
+ n.show
127
+ Sn::NOTIFICATION[:set_timeout].count.should eq(1)
128
+ n.timeout.should eq(1023)
129
+ end
130
+
131
+ it "should map keyword timeout properly" do
132
+ n = Sn::Notification.new "summary", "message", ""
133
+ n.timeout = :default
134
+ n.timeout.should eq(Sn::TIMEOUTS[:default])
135
+ n.timeout = :never
136
+ n.timeout.should eq(Sn::TIMEOUTS[:never])
137
+ end
138
+ end
139
+
140
+ describe Sn::Notification, ".closed_reason" do
141
+ it "should get a notification's closing reason" do
142
+ Sn::NOTIFICATION[:get_closed_reason].count = 0
143
+ n = Sn::Notification.new "summary", "message", ""
144
+ n.show
145
+ n.close
146
+ n.closed_reason
147
+ Sn::NOTIFICATION[:get_closed_reason].count.should eq(1)
148
+ end
149
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,47 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-21 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.3
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.3
14
46
  description: An incredibly simple interface to libnotify using Fiddle.
15
47
  email: baguthrie@sbcglobal.net
16
48
  executables: []
17
49
  extensions: []
18
50
  extra_rdoc_files: []
19
51
  files:
52
+ - spec/sn_spec.rb
20
53
  - lib/sn.rb
21
54
  - README.md
22
55
  - Rakefile
@@ -40,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
73
  version: '0'
41
74
  requirements: []
42
75
  rubyforge_project: tin
43
- rubygems_version: 1.8.15
76
+ rubygems_version: 1.8.23
44
77
  signing_key:
45
78
  specification_version: 3
46
79
  summary: Very simple libnotify access