ext/rnotify.c in ruby-libnotify-0.5.0 vs ext/rnotify.c in ruby-libnotify-0.5.1
- old
+ new
@@ -1,10 +1,10 @@
//
// rnotify.c
//
// Luca Russo <vargolo@gmail.com>
-// Copyright (LGPL) 2006 - 2011
+// Copyright (LGPL) 2006 - 2012
//
#include <libnotify/notify.h>
#include "ruby.h"
#include "rbgobject.h"
@@ -34,11 +34,14 @@
static void
_notification_action_free(ActionData *data)
{
if(data != NULL)
+ {
g_free(data);
+ data = NULL;
+ }
}
static void
_wrap_alloc_free(VALUE self)
{
@@ -61,11 +64,11 @@
* Throw an expection If name is empty or nil
*
* Returns TRUE if the library initialized properly, FALSE otherwise
*/
static VALUE
-_wrap_notify_init(VALUE self, VALUE app_name)
+_wrap_notify_init(VALUE UNUSED(self), VALUE app_name)
{
gboolean init;
char *name = NIL_P(app_name) ? NULL : StringValuePtr(app_name);
if(name == NULL || *name == '\0')
@@ -85,11 +88,11 @@
* uninit
*
* Deinitialize libnotify, you must to call this before quit the program
*/
static VALUE
-_wrap_notify_uninit(VALUE self)
+_wrap_notify_uninit(VALUE UNUSED(self))
{
notify_uninit();
return Qnil;
}
@@ -99,11 +102,11 @@
* init?
*
* Returns TRUE if libnotify is inizialized, FALSE otherwise
*/
static VALUE
-_wrap_notify_is_initted(VALUE self)
+_wrap_notify_is_initted(VALUE UNUSED(self))
{
if(notify_is_initted())
return Qtrue;
return Qfalse;
@@ -114,11 +117,11 @@
* name
*
* Returns the application name passed to Notify.init
*/
static VALUE
-_wrap_notify_get_app_name(VALUE self)
+_wrap_notify_get_app_name(VALUE UNUSED(self))
{
const gchar *name = notify_get_app_name();
return rb_str_new2(name);
}
@@ -132,11 +135,11 @@
* otherwise nothing will be changed
*
* ** ONLY WHEN COMPILED AGAINST LIBNOTIFY >= 0.7.2 **
*/
static VALUE
-_wrap_notify_set_app_name(VALUE self, VALUE app_name)
+_wrap_notify_set_app_name(VALUE UNUSED(self), VALUE app_name)
{
char *name = NIL_P(app_name) ? NULL : StringValuePtr(app_name);
if(name != NULL || *name != '\0')
notify_set_app_name(name);
@@ -150,11 +153,11 @@
* server_caps
*
* Queries the server for its capabilities and returns them in an Array
*/
static VALUE
-_wrap_notify_get_server_caps(VALUE self)
+_wrap_notify_get_server_caps(VALUE UNUSED(self))
{
GList *caps = NULL;
VALUE rb_caps;
caps = notify_get_server_caps();
@@ -188,11 +191,11 @@
* p h[:vendor] #print the vendor
* p h[:version] #print the server version
* p h[:spec_version] #print the specification version supported
*/
static VALUE
-_wrap_notify_get_server_info(VALUE self)
+_wrap_notify_get_server_info(VALUE UNUSED(self))
{
gchar *serv_name = NULL,
*vendor = NULL,
*serv_version = NULL,
*spec_vers = NULL;
@@ -252,12 +255,35 @@
#endif
return self;
}
+#ifdef HAVE_SET_APP_PNAME
/*
* call-seq:
+ * name= new_name
+ *
+ * if new_name is a valid string, sets the application name for the notification.
+ * otherwise nothing will be changed
+ *
+ * ** ONLY WHEN COMPILED AGAINST LIBNOTIFY >= 0.7.3 **
+ */
+static VALUE
+_wrap_notification_set_app_pname(VALUE self, VALUE notification_name)
+{
+ NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
+ char *name = NIL_P(notification_name) ? NULL : StringValuePtr(notification_name);
+
+ if(name != NULL || *name != '\0')
+ notify_notification_set_app_name(n, name);
+
+ return Qnil;
+}
+#endif
+
+/*
+ * call-seq:
* update(summ, msg, icon)
*
* summ = The new summary text (required)
*
* msg = The new body text or nil
@@ -695,15 +721,17 @@
return INT2FIX(reason);
}
/*
* libnotify ruby interface
+ * [ http://ftp.gnome.org/pub/GNOME/sources/libnotify ]
* [ http://www.galago-project.org ]
*/
void
Init_rnotify()
{
+ g_type_init();
VALUE mNotify = rb_define_module(MODULE_NAME);
VALUE cNotification = G_DEF_CLASS2(NOTIFY_TYPE_NOTIFICATION, CLASS_NAME, mNotify,
0, _wrap_alloc_free);
rb_define_const(cNotification, "URGENCY_LOW", INT2FIX(NOTIFY_URGENCY_LOW));
@@ -721,9 +749,12 @@
#endif
rb_define_module_function(mNotify, "server_caps", _wrap_notify_get_server_caps, 0);
rb_define_module_function(mNotify, "server_info", _wrap_notify_get_server_info, 0);
rb_define_method(cNotification, "initialize", _wrap_notification_init, 3);
+#ifdef HAVE_SET_APP_PNAME
+ rb_define_method(cNotification, "name=", _wrap_notification_set_app_pname, 1);
+#endif
rb_define_method(cNotification, "update", _wrap_notification_update, 3);
rb_define_method(cNotification, "show", _wrap_notification_show, 0);
rb_define_method(cNotification, "timeout=", _wrap_notification_set_timeout, 1);
rb_define_method(cNotification, "category=", _wrap_notification_set_category, 1);
rb_define_method(cNotification, "urgency=", _wrap_notification_set_urgency, 1);