ruby-libnotify 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/AUTHORS.rdoc +4 -0
  2. data/CHANGELOG.rdoc +55 -0
  3. data/COPYING +504 -0
  4. data/README.rdoc +46 -0
  5. data/doc/classes/Notify.html +343 -0
  6. data/doc/classes/Notify.src/M000001.html +39 -0
  7. data/doc/classes/Notify.src/M000002.html +24 -0
  8. data/doc/classes/Notify.src/M000003.html +25 -0
  9. data/doc/classes/Notify.src/M000004.html +24 -0
  10. data/doc/classes/Notify.src/M000005.html +37 -0
  11. data/doc/classes/Notify.src/M000006.html +55 -0
  12. data/doc/classes/Notify/Notification.html +787 -0
  13. data/doc/classes/Notify/Notification.src/M000007.html +65 -0
  14. data/doc/classes/Notify/Notification.src/M000008.html +49 -0
  15. data/doc/classes/Notify/Notification.src/M000009.html +43 -0
  16. data/doc/classes/Notify/Notification.src/M000010.html +35 -0
  17. data/doc/classes/Notify/Notification.src/M000011.html +33 -0
  18. data/doc/classes/Notify/Notification.src/M000012.html +36 -0
  19. data/doc/classes/Notify/Notification.src/M000013.html +48 -0
  20. data/doc/classes/Notify/Notification.src/M000014.html +36 -0
  21. data/doc/classes/Notify/Notification.src/M000015.html +38 -0
  22. data/doc/classes/Notify/Notification.src/M000016.html +38 -0
  23. data/doc/classes/Notify/Notification.src/M000017.html +39 -0
  24. data/doc/classes/Notify/Notification.src/M000018.html +38 -0
  25. data/doc/classes/Notify/Notification.src/M000019.html +45 -0
  26. data/doc/classes/Notify/Notification.src/M000020.html +67 -0
  27. data/doc/classes/Notify/Notification.src/M000021.html +33 -0
  28. data/doc/classes/Notify/Notification.src/M000022.html +33 -0
  29. data/doc/classes/Notify/Notification.src/M000023.html +36 -0
  30. data/doc/classes/Notify/Notification.src/M000024.html +34 -0
  31. data/doc/created.rid +1 -0
  32. data/doc/files/lib/RNotify_rb.html +102 -0
  33. data/doc/files/rnotify_c.html +90 -0
  34. data/doc/fr_class_index.html +27 -0
  35. data/doc/fr_file_index.html +27 -0
  36. data/doc/fr_method_index.html +71 -0
  37. data/doc/index.html +21 -0
  38. data/doc/rdoc-style.css +299 -0
  39. data/examples/action.rb +39 -0
  40. data/examples/attach_to.rb +43 -0
  41. data/examples/attach_to_status_icon.rb +47 -0
  42. data/examples/base.rb +29 -0
  43. data/examples/geometry-hints.rb +37 -0
  44. data/examples/icon.png +0 -0
  45. data/examples/info.rb +27 -0
  46. data/examples/markup.rb +29 -0
  47. data/examples/multi-actions.rb +44 -0
  48. data/examples/update.rb +36 -0
  49. data/examples/urgency.rb +47 -0
  50. data/examples/xy.rb +32 -0
  51. data/ext/extconf.rb +67 -0
  52. data/ext/rnotify.c +814 -0
  53. data/lib/RNotify.rb +15 -0
  54. data/setup.rb +1333 -0
  55. metadata +120 -0
@@ -0,0 +1,814 @@
1
+ //
2
+ // rnotify.c
3
+ //
4
+ // Luca Russo <vargolo@gmail.com>
5
+ // Copyright (LGPL) 2006 - 2010
6
+ //
7
+
8
+ #include <libnotify/notify.h>
9
+ #include "ruby.h"
10
+ #include "rbgobject.h"
11
+
12
+ #define MODULE_NAME "Notify"
13
+ #define CLASS_NAME "Notification"
14
+
15
+ typedef struct _ActionData ActionData;
16
+ struct _ActionData
17
+ {
18
+ VALUE callback;
19
+ VALUE action;
20
+ VALUE user_data;
21
+ };
22
+
23
+ static void
24
+ _notification_action_cb(NotifyNotification *notify, const char *action,
25
+ ActionData *data)
26
+ {
27
+ ActionData *tmp = data;
28
+
29
+ if(tmp->user_data == Qnil)
30
+ rb_funcall(tmp->callback, rb_intern("call"), 1, tmp->action);
31
+ else
32
+ rb_funcall(tmp->callback, rb_intern("call"), 2, tmp->action, tmp->user_data);
33
+ }
34
+
35
+ static void
36
+ _notification_action_free(ActionData *data)
37
+ {
38
+ if(data != NULL)
39
+ g_free(data);
40
+ }
41
+
42
+ static void
43
+ _wrap_alloc_free(VALUE self)
44
+ {
45
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
46
+
47
+ if(n != NULL)
48
+ {
49
+ g_object_unref(G_OBJECT(n));
50
+ n = NULL;
51
+ }
52
+ }
53
+
54
+ /*
55
+ * call-seq:
56
+ * init(name)
57
+ *
58
+ * name = application name (required)
59
+ *
60
+ * Initialize libnotify. This must be called before any other functions.
61
+ * Throw an expection If name is empty or nil
62
+ *
63
+ * Returns TRUE if the library initialized properly, FALSE otherwise
64
+ */
65
+ static VALUE
66
+ _wrap_notify_init(VALUE self, VALUE app_name)
67
+ {
68
+ gboolean init;
69
+ char *name = NIL_P(app_name) ? NULL : StringValuePtr(app_name);
70
+
71
+ if(name == NULL || *name == '\0')
72
+ rb_raise(rb_eRuntimeError,
73
+ "You MUST call this method with a valid string that will be used as Application name");
74
+ else
75
+ init = notify_init(name);
76
+
77
+ if(init == TRUE)
78
+ return Qtrue;
79
+
80
+ return Qfalse;
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * uninit
86
+ *
87
+ * Deinitialize libnotify, you must to call this before quit the program
88
+ */
89
+ static VALUE
90
+ _wrap_notify_uninit(VALUE self)
91
+ {
92
+ notify_uninit();
93
+
94
+ return Qnil;
95
+ }
96
+
97
+ /*
98
+ * call-seq:
99
+ * init?
100
+ *
101
+ * Returns TRUE if libnotify is inizialized, FALSE otherwise
102
+ */
103
+ static VALUE
104
+ _wrap_notify_is_initted(VALUE self)
105
+ {
106
+ if(notify_is_initted())
107
+ return Qtrue;
108
+
109
+ return Qfalse;
110
+ }
111
+
112
+ /*
113
+ * call-seq:
114
+ * app_name
115
+ *
116
+ * Returns the application name passed to Notify.init
117
+ */
118
+ static VALUE
119
+ _wrap_notify_get_app_name(VALUE self)
120
+ {
121
+ const gchar *name = notify_get_app_name();
122
+
123
+ return rb_str_new2(name);
124
+ }
125
+
126
+ /*
127
+ * call-seq:
128
+ * server_caps
129
+ *
130
+ * Queries the server for its capabilities and returns them in an Array
131
+ */
132
+ static VALUE
133
+ _wrap_notify_get_server_caps(VALUE self)
134
+ {
135
+ GList *caps = NULL;
136
+ VALUE rb_caps;
137
+
138
+ caps = notify_get_server_caps();
139
+ rb_caps = rb_ary_new();
140
+
141
+ do
142
+ {
143
+ rb_ary_push(rb_caps, rb_str_new2(caps->data));
144
+ caps = caps->next;
145
+ } while(caps != NULL);
146
+
147
+ g_list_foreach(caps, (GFunc)g_free, NULL);
148
+ g_list_free(caps);
149
+
150
+ return rb_caps;
151
+ }
152
+
153
+ /*
154
+ * call-seq:
155
+ * server_info
156
+ *
157
+ * Queries the server for its information (name, vendor, server version,
158
+ * notification version)
159
+ *
160
+ * Returns FALSE if there were errors, an Hash otherwise
161
+ *
162
+ * example:
163
+ *
164
+ * h = Notify.server_info
165
+ * p h[:name] #print the product name of the server
166
+ * p h[:vendor] #print the vendor
167
+ * p h[:version] #print the server version
168
+ * p h[:spec_version] #print the specification version supported
169
+ */
170
+ static VALUE
171
+ _wrap_notify_get_server_info(VALUE self)
172
+ {
173
+ gchar *serv_name = NULL,
174
+ *vendor = NULL,
175
+ *serv_version = NULL,
176
+ *spec_vers = NULL;
177
+ VALUE rb_info;
178
+
179
+ if(!notify_get_server_info(&serv_name, &vendor, &serv_version, &spec_vers))
180
+ return Qfalse;
181
+ else
182
+ {
183
+ rb_info = rb_hash_new();
184
+ rb_hash_aset(rb_info, ID2SYM(rb_intern("name")), rb_str_new2(serv_name));
185
+ rb_hash_aset(rb_info, ID2SYM(rb_intern("vendor")), rb_str_new2(vendor));
186
+ rb_hash_aset(rb_info, ID2SYM(rb_intern("version")), rb_str_new2(serv_version));
187
+ rb_hash_aset(rb_info, ID2SYM(rb_intern("spec_version")), rb_str_new2(spec_vers));
188
+
189
+ g_free(serv_name);
190
+ g_free(vendor);
191
+ g_free(serv_version);
192
+ g_free(spec_vers);
193
+ }
194
+
195
+ return rb_info;
196
+ }
197
+
198
+ /*
199
+ * call-seq:
200
+ * new(summ, msg, icon, widget)
201
+ *
202
+ * summ = The summary text (required)
203
+ *
204
+ * msg = The body text or nil
205
+ *
206
+ * icon = The icon or nil
207
+ *
208
+ * widget = The widget (or a Gtk::StatusIcon, when compiled against GTK+ >= 2.9.2 and libnotify >= 0.4.1) to attach to or nil
209
+ *
210
+ * Creates and returns a new notification, throw an exception on error
211
+ */
212
+ static VALUE
213
+ _wrap_notification_init(VALUE self, VALUE summ, VALUE msg,
214
+ VALUE icon, VALUE widget)
215
+ {
216
+ GObject *obj = G_OBJECT(RVAL2GOBJ(widget));
217
+ char *nsumm = NIL_P(summ) ? NULL : StringValuePtr(summ);
218
+ NotifyNotification *n = NULL;
219
+
220
+ if(nsumm == NULL || *nsumm == '\0')
221
+ rb_raise( rb_eArgError, "REQUIRED: the `summ` field" );
222
+
223
+ #ifdef HAVE_STATUS_ICON
224
+ if(GTK_IS_STATUS_ICON(obj))
225
+ n = notify_notification_new_with_status_icon(nsumm,
226
+ NIL_P(msg) ? NULL : StringValuePtr(msg),
227
+ NIL_P(icon) ? NULL : StringValuePtr(icon),
228
+ GTK_STATUS_ICON(obj));
229
+ else
230
+ n = notify_notification_new(nsumm,
231
+ NIL_P(msg) ? NULL : StringValuePtr(msg),
232
+ NIL_P(icon) ? NULL : StringValuePtr(icon),
233
+ GTK_WIDGET(obj));
234
+ #else
235
+ n = notify_notification_new(nsumm,
236
+ NIL_P(msg) ? NULL : StringValuePtr(msg),
237
+ NIL_P(icon) ? NULL : StringValuePtr(icon),
238
+ GTK_WIDGET(obj));
239
+ #endif
240
+
241
+ if(n == NULL)
242
+ rb_raise(rb_eRuntimeError, "Can not create a new notification");
243
+
244
+ G_INITIALIZE(self, n);
245
+
246
+ #ifdef DEBUG
247
+ rb_warn("init, ok");
248
+ #endif
249
+
250
+ return self;
251
+ }
252
+
253
+ /*
254
+ * call-seq:
255
+ * update(summ, msg, icon)
256
+ *
257
+ * summ = The new summary text (required)
258
+ *
259
+ * msg = The new body text or nil
260
+ *
261
+ * icon = The new icon or nil
262
+ *
263
+ * This won't send the update out and display it on the screen.
264
+ * For that, you will need to call the Notification#show method.
265
+ *
266
+ * Returns TRUE if ok, FALSE otherwise
267
+ */
268
+ static VALUE
269
+ _wrap_notification_update(VALUE self, VALUE summ, VALUE msg, VALUE icon)
270
+ {
271
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
272
+ char *nsumm = NIL_P(summ) ? NULL : StringValuePtr(summ);
273
+ char *nmsg = NIL_P(msg) ? NULL : StringValuePtr(msg);
274
+ char *nicon = NIL_P(icon) ? NULL : StringValuePtr(icon);
275
+
276
+ #ifdef DEBUG
277
+ if(NOTIFY_IS_NOTIFICATION(n))
278
+ rb_warn("update, ok");
279
+ else
280
+ rb_warn("update, no ok");
281
+ #endif
282
+
283
+ if(nsumm == NULL || *nsumm == '\0')
284
+ rb_raise(rb_eArgError, "REQUIRED: the `summ` field");
285
+
286
+ if(notify_notification_update(n, nsumm, nmsg, nicon) == TRUE)
287
+ return Qtrue;
288
+
289
+ return Qfalse;
290
+ }
291
+
292
+ /*
293
+ * call-seq:
294
+ * attach_to(widget)
295
+ *
296
+ * widget = The widget (or a Gtk::StatusIcon, when compiled against GTK+ >= 2.9.2 and libnotify >= 0.4.1) to attach to
297
+ *
298
+ * Attaches the notification to a Gtk::Widget or Gtk::StatusIcon
299
+ */
300
+ static VALUE
301
+ _wrap_notification_attach_to(VALUE self, VALUE widget)
302
+ {
303
+ GObject *obj = G_OBJECT(RVAL2GOBJ(widget));
304
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
305
+
306
+ #ifdef DEBUG
307
+ if(NOTIFY_IS_NOTIFICATION(n))
308
+ rb_warn("attach_to, ok");
309
+ else
310
+ rb_warn("attach_to, no ok");
311
+ #endif
312
+
313
+ #ifdef HAVE_STATUS_ICON
314
+ if(GTK_IS_STATUS_ICON(obj))
315
+ notify_notification_attach_to_status_icon(n, GTK_STATUS_ICON(obj));
316
+ else
317
+ notify_notification_attach_to_widget(n, GTK_WIDGET(obj));
318
+ #else
319
+ notify_notification_attach_to_widget(n, GTK_WIDGET(obj));
320
+ #endif
321
+
322
+ return Qnil;
323
+ }
324
+
325
+ /*
326
+ * call-seq:
327
+ * show
328
+ *
329
+ * Tells the notification server to display the notification on the screen.
330
+ * if TRUE returns, show the notification otherwise returns FALSE
331
+ */
332
+ static VALUE
333
+ _wrap_notification_show(VALUE self)
334
+ {
335
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
336
+
337
+ #ifdef DEBUG
338
+ if(NOTIFY_IS_NOTIFICATION(n))
339
+ rb_warn("show, ok");
340
+ else
341
+ rb_warn("show, no ok");
342
+ #endif
343
+
344
+ if(notify_notification_show(n, NULL) == TRUE)
345
+ return Qtrue;
346
+
347
+ return Qfalse;
348
+ }
349
+
350
+ /*
351
+ * call-seq:
352
+ * timeout=(milliseconds)
353
+ *
354
+ * Sets the timeout in milliseconds.
355
+ */
356
+ static VALUE
357
+ _wrap_notification_set_timeout(VALUE self, VALUE ml)
358
+ {
359
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
360
+
361
+ #ifdef DEBUG
362
+ if(NOTIFY_IS_NOTIFICATION(n))
363
+ rb_warn("timeout, ok");
364
+ else
365
+ rb_warn("timeout, no ok");
366
+ #endif
367
+
368
+ notify_notification_set_timeout(n, FIX2INT(ml));
369
+
370
+ return Qnil;
371
+ }
372
+
373
+ /*
374
+ * call-seq:
375
+ * category=(category_name)
376
+ *
377
+ * category_name = The category name
378
+ *
379
+ * Sets the category
380
+ */
381
+ static VALUE
382
+ _wrap_notification_set_category(VALUE self, VALUE cat_name)
383
+ {
384
+ char *cname = NIL_P(cat_name) ? NULL : StringValuePtr(cat_name);
385
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
386
+
387
+ #ifdef DEBUG
388
+ if(NOTIFY_IS_NOTIFICATION(n))
389
+ rb_warn("set_category, ok");
390
+ else
391
+ rb_warn("set_category, not ok");
392
+ #endif
393
+
394
+ notify_notification_set_category(n, cname);
395
+
396
+ return Qnil;
397
+ }
398
+
399
+ /*
400
+ * call-seq:
401
+ * urgency=(urgency_level)
402
+ *
403
+ * urgency_level = The urgency level
404
+ *
405
+ * Sets the urgency level
406
+ */
407
+ static VALUE
408
+ _wrap_notification_set_urgency(VALUE self, VALUE urgency)
409
+ {
410
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
411
+
412
+ #ifdef DEBUG
413
+ if(NOTIFY_IS_NOTIFICATION(n))
414
+ rb_warn("set_urgency, ok");
415
+ else
416
+ rb_warn("set_urgency, no ok");
417
+ #endif
418
+
419
+ switch(FIX2INT(urgency))
420
+ {
421
+ case NOTIFY_URGENCY_LOW:
422
+ notify_notification_set_urgency(n, NOTIFY_URGENCY_LOW);
423
+ break;
424
+ case NOTIFY_URGENCY_NORMAL:
425
+ notify_notification_set_urgency(n, NOTIFY_URGENCY_NORMAL);
426
+ break;
427
+ case NOTIFY_URGENCY_CRITICAL:
428
+ notify_notification_set_urgency(n, NOTIFY_URGENCY_CRITICAL);
429
+ break;
430
+ default:
431
+ notify_notification_set_urgency(n, NOTIFY_URGENCY_NORMAL);
432
+ }
433
+
434
+ return Qnil;
435
+ }
436
+
437
+ /*
438
+ * call-seq:
439
+ * pixbuf_icon=(icon)
440
+ *
441
+ * icon = The icon
442
+ *
443
+ * Sets the icon from a Gdk::Pixbuf
444
+ */
445
+ static VALUE
446
+ _wrap_notification_set_pixbuf_icon(VALUE self, VALUE icon)
447
+ {
448
+ GdkPixbuf *pix = GDK_PIXBUF(RVAL2GOBJ(icon));
449
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
450
+
451
+ #ifdef DEBUG
452
+ if(NOTIFY_IS_NOTIFICATION(n) && GDK_IS_PIXBUF(pix))
453
+ rb_warn("pixbuf_icon, ok");
454
+ else
455
+ rb_warn("pixbuf_icon, no ok");
456
+ #endif
457
+
458
+ notify_notification_set_icon_from_pixbuf(n, pix);
459
+
460
+ return Qnil;
461
+ }
462
+
463
+ /*
464
+ * call-seq:
465
+ * hint32(key, value)
466
+ *
467
+ * key = The hint
468
+ *
469
+ * value = The hint's value
470
+ *
471
+ * Sets a hint with a 32-bit integer value
472
+ */
473
+ static VALUE
474
+ _wrap_notification_set_hint32(VALUE self, VALUE key, VALUE value)
475
+ {
476
+ char *vkey = NIL_P(key) ? NULL : StringValuePtr(key);
477
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
478
+
479
+ #ifdef DEBUG
480
+ if(NOTIFY_IS_NOTIFICATION(n))
481
+ rb_warn("set_hint32, ok");
482
+ else
483
+ rb_warn("set_hint32, no ok");
484
+ #endif
485
+
486
+ notify_notification_set_hint_int32(n, vkey, FIX2INT(value));
487
+
488
+ return Qnil;
489
+ }
490
+
491
+ /*
492
+ * call-seq:
493
+ * hint_double(key, value)
494
+ *
495
+ * key = The hint
496
+ *
497
+ * value = The hint's value
498
+ *
499
+ * Sets a hint with a double value
500
+ */
501
+ static VALUE
502
+ _wrap_notification_set_hint_double(VALUE self, VALUE key, VALUE value)
503
+ {
504
+ char *vkey = NIL_P(key) ? NULL : StringValuePtr(key);
505
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
506
+
507
+ #ifdef DEBUG
508
+ if(NOTIFY_IS_NOTIFICATION(n))
509
+ rb_warn("set_hint_double, ok");
510
+ else
511
+ rb_warn("set_hint_double, no ok");
512
+ #endif
513
+
514
+ notify_notification_set_hint_double(n, vkey, NUM2DBL(value));
515
+
516
+ return Qnil;
517
+ }
518
+
519
+ /*
520
+ * call-seq:
521
+ * hint_string(key, value)
522
+ *
523
+ * key = The hint
524
+ *
525
+ * value = The hint's value
526
+ *
527
+ * Sets a hint with a string value
528
+ */
529
+ static VALUE
530
+ _wrap_notification_set_hint_string(VALUE self, VALUE key, VALUE value)
531
+ {
532
+ char *vkey = NIL_P(key) ? NULL : StringValuePtr(key);
533
+ char *vvalue = NIL_P(value) ? NULL : StringValuePtr(value);
534
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
535
+
536
+ #ifdef DEBUG
537
+ if(NOTIFY_IS_NOTIFICATION(n))
538
+ rb_warn("set_hint_string, ok");
539
+ else
540
+ rb_warn("set_hint_string, no ok");
541
+ #endif
542
+
543
+ notify_notification_set_hint_string(n, vkey, vvalue);
544
+
545
+ return Qnil;
546
+ }
547
+
548
+ /*
549
+ * call-seq:
550
+ * hint_byte(key, value)
551
+ *
552
+ * key = The hint
553
+ *
554
+ * value = The hint's value
555
+ *
556
+ * Sets a hint with a byte value
557
+ */
558
+ static VALUE
559
+ _wrap_notification_set_hint_byte(VALUE self, VALUE key, VALUE value)
560
+ {
561
+ char *vkey = NIL_P(key) ? NULL : StringValuePtr(key);
562
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
563
+
564
+ #ifdef DEBUG
565
+ if(NOTIFY_IS_NOTIFICATION(n))
566
+ rb_warn("set_hint_byte, ok");
567
+ else
568
+ rb_warn("set_hint_byte, no ok");
569
+ #endif
570
+
571
+ notify_notification_set_hint_byte(n, vkey, FIX2INT(value));
572
+
573
+ return Qnil;
574
+ }
575
+
576
+ /*
577
+ * call-seq:
578
+ * clear_hints
579
+ *
580
+ * Clears all hints from the notification. Remember to use this method before call the Notification#close method.
581
+ */
582
+ static VALUE
583
+ _wrap_notification_clear_hints(VALUE self)
584
+ {
585
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
586
+
587
+ #ifdef DEBUG
588
+ if(NOTIFY_IS_NOTIFICATION(n))
589
+ rb_warn("clear_hints, ok");
590
+ else
591
+ rb_warn("clear_hints, no ok");
592
+ #endif
593
+
594
+ notify_notification_clear_hints(n);
595
+
596
+ return Qnil;
597
+ }
598
+
599
+ #ifdef HAVE_GEOMETRY_HINTS
600
+ /*
601
+ * call-seq:
602
+ * geometry_hints(screen, x, y)
603
+ *
604
+ * ** WHEN COMPILED AGAINST LIBNOTIFY 0.4.1 OR HIGHER **
605
+ *
606
+ * screen = The Gdk::Screen the notification should appear on
607
+ *
608
+ * x = The X coordinate to point to
609
+ *
610
+ * y = The Y coordinate to point to
611
+ *
612
+ * Sets the geometry hints on the notification
613
+ */
614
+ static VALUE
615
+ _wrap_notification_set_geometry_hints(VALUE self, VALUE screen, VALUE x, VALUE y)
616
+ {
617
+ GdkScreen *sc = GDK_SCREEN(RVAL2GOBJ(screen));
618
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
619
+
620
+ if(sc == NULL)
621
+ rb_raise(rb_eArgError, "REQUIRED: the `screen` field");
622
+
623
+ #ifdef DEBUG
624
+ if(NOTIFY_IS_NOTIFICATION(n) && GDK_IS_SCREEN(sc))
625
+ rb_warn("set_geometry_hints, ok");
626
+ else
627
+ rb_warn("set_geometry_hints, no ok");
628
+ #endif
629
+
630
+ notify_notification_set_geometry_hints(n, sc, FIX2INT(x), FIX2INT(y));
631
+
632
+ return Qnil;
633
+ }
634
+ #endif
635
+
636
+ /*
637
+ * call-seq:
638
+ * add_action(action, label, user_data) { |action, user_data| ... }
639
+ *
640
+ * action = The action id
641
+ *
642
+ * label = The action label
643
+ *
644
+ * user_data = Custom data to pass into the block (optional)
645
+ *
646
+ * Adds an action. When the action is invoked, the specified block will be called
647
+ *
648
+ * Examples:
649
+ *
650
+ * myinstance.add_action( "MyAction", "MyLabel" ) do |action|
651
+ * # something to do
652
+ * end
653
+ *
654
+ * Or
655
+ *
656
+ * myinstance.add_action( "MyAction", "MyLabel", MyData ) do |action, mydata|
657
+ * # something to do
658
+ * end
659
+ */
660
+ static VALUE
661
+ _wrap_notification_add_action(int argc, VALUE *argv, VALUE self)
662
+ {
663
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
664
+ VALUE action, label, data, body;
665
+ ActionData *actionData = NULL;
666
+
667
+ #ifdef DEBUG
668
+ if(NOTIFY_IS_NOTIFICATION(n))
669
+ rb_warn("add_action, ok");
670
+ else
671
+ rb_warn("add_action, no ok");
672
+ #endif
673
+
674
+ if(!rb_block_given_p())
675
+ rb_raise(rb_eRuntimeError, "This method requires a block");
676
+
677
+ rb_scan_args(argc, argv, "21&", &action, &label, &data, &body);
678
+
679
+ actionData = g_new0(ActionData, 1);
680
+ actionData->callback = body;
681
+ actionData->action = action;
682
+ actionData->user_data = data;
683
+
684
+ notify_notification_add_action(n,
685
+ NIL_P(action) ? NULL : StringValuePtr(action),
686
+ NIL_P(label) ? NULL : StringValuePtr(label),
687
+ (NotifyActionCallback) _notification_action_cb,
688
+ actionData, (GFreeFunc)_notification_action_free);
689
+
690
+ return Qnil;
691
+ }
692
+
693
+ /*
694
+ * call-seq:
695
+ * clear_actions
696
+ *
697
+ * Clears all actions from the notification. Remember to use this method before call the Notification#close method.
698
+ */
699
+ static VALUE
700
+ _wrap_notification_clear_actions(VALUE self)
701
+ {
702
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
703
+
704
+ #ifdef DEBUG
705
+ if(NOTIFY_IS_NOTIFICATION(n))
706
+ rb_warn("clear_actions, ok");
707
+ else
708
+ rb_warn("clear_actions, no ok");
709
+ #endif
710
+
711
+ notify_notification_clear_actions(n);
712
+
713
+ return Qnil;
714
+ }
715
+
716
+ /*
717
+ * call-seq:
718
+ * close
719
+ *
720
+ * Tells the notification server to hide the notification on the screen.
721
+ */
722
+ static VALUE
723
+ _wrap_notification_close(VALUE self)
724
+ {
725
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
726
+
727
+ #ifdef DEBUG
728
+ if(NOTIFY_IS_NOTIFICATION(n))
729
+ rb_warn("close, ok");
730
+ else
731
+ rb_warn("close, no ok");
732
+ #endif
733
+
734
+ if(notify_notification_close(n, NULL))
735
+ return Qtrue;
736
+
737
+ return Qfalse;
738
+ }
739
+
740
+ #ifdef HAVE_CLOSED_REASON
741
+ /*
742
+ * call-seq:
743
+ * closed_reason
744
+ *
745
+ * ** WHEN COMPILED AGAINST LIBNOTIFY 0.4.5 OR HIGHER **
746
+ *
747
+ * Returns the reason code why the notification was closed
748
+ */
749
+ static VALUE
750
+ _wrap_notification_get_closed_reason(VALUE self)
751
+ {
752
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
753
+ int reason = -1;
754
+
755
+ #ifdef DEBUG
756
+ if(NOTIFY_IS_NOTIFICATION(n))
757
+ rb_warn("closed_reason, ok");
758
+ else
759
+ rb_warn("closed_reason, no ok");
760
+ #endif
761
+
762
+ reason = notify_notification_get_closed_reason(n);
763
+
764
+ return INT2FIX(reason);
765
+ }
766
+ #endif
767
+
768
+ /*
769
+ * libnotify ruby interface
770
+ * [ http://www.galago-project.org ]
771
+ */
772
+ void
773
+ Init_rnotify()
774
+ {
775
+ VALUE mNotify = rb_define_module(MODULE_NAME);
776
+ VALUE cNotification = G_DEF_CLASS2(NOTIFY_TYPE_NOTIFICATION, CLASS_NAME, mNotify,
777
+ 0, _wrap_alloc_free);
778
+
779
+ rb_define_const(cNotification, "URGENCY_LOW", INT2FIX(NOTIFY_URGENCY_LOW));
780
+ rb_define_const(cNotification, "URGENCY_NORMAL", INT2FIX(NOTIFY_URGENCY_NORMAL));
781
+ rb_define_const(cNotification, "URGENCY_CRITICAL", INT2FIX(NOTIFY_URGENCY_CRITICAL));
782
+ rb_define_const(cNotification, "EXPIRES_DEFAULT", INT2FIX(NOTIFY_EXPIRES_DEFAULT));
783
+ rb_define_const(cNotification, "EXPIRES_NEVER", INT2FIX(NOTIFY_EXPIRES_NEVER));
784
+
785
+ rb_define_module_function(mNotify, "init", _wrap_notify_init, 1);
786
+ rb_define_module_function(mNotify, "uninit", _wrap_notify_uninit, 0);
787
+ rb_define_module_function(mNotify, "init?", _wrap_notify_is_initted, 0);
788
+ rb_define_module_function(mNotify, "app_name", _wrap_notify_get_app_name, 0);
789
+ rb_define_module_function(mNotify, "server_caps", _wrap_notify_get_server_caps, 0);
790
+ rb_define_module_function(mNotify, "server_info", _wrap_notify_get_server_info, 0);
791
+
792
+ rb_define_method(cNotification, "initialize", _wrap_notification_init, 4);
793
+ rb_define_method(cNotification, "update", _wrap_notification_update, 3);
794
+ rb_define_method(cNotification, "attach_to", _wrap_notification_attach_to, 1);
795
+ rb_define_method(cNotification, "show", _wrap_notification_show, 0);
796
+ rb_define_method(cNotification, "timeout=", _wrap_notification_set_timeout, 1);
797
+ rb_define_method(cNotification, "category=", _wrap_notification_set_category, 1);
798
+ rb_define_method(cNotification, "urgency=", _wrap_notification_set_urgency, 1);
799
+ rb_define_method(cNotification, "pixbuf_icon=", _wrap_notification_set_pixbuf_icon, 1);
800
+ rb_define_method(cNotification, "hint32", _wrap_notification_set_hint32, 2);
801
+ rb_define_method(cNotification, "hint_double", _wrap_notification_set_hint_double, 2);
802
+ rb_define_method(cNotification, "hint_string", _wrap_notification_set_hint_string, 2);
803
+ rb_define_method(cNotification, "hint_byte", _wrap_notification_set_hint_byte, 2);
804
+ #ifdef HAVE_GEOMETRY_HINTS
805
+ rb_define_method(cNotification, "geometry_hints", _wrap_notification_set_geometry_hints, 3);
806
+ #endif
807
+ rb_define_method(cNotification, "add_action", _wrap_notification_add_action, -1);
808
+ rb_define_method(cNotification, "clear_actions", _wrap_notification_clear_actions, 0);
809
+ rb_define_method(cNotification, "clear_hints", _wrap_notification_clear_hints, 0);
810
+ #ifdef HAVE_CLOSED_REASON
811
+ rb_define_method(cNotification, "closed_reason", _wrap_notification_get_closed_reason, 0);
812
+ #endif
813
+ rb_define_method(cNotification, "close", _wrap_notification_close, 0);
814
+ }