ext/rnotify.c in ruby-libnotify-0.4.1.1 vs ext/rnotify.c in ruby-libnotify-0.5.0
- old
+ new
@@ -109,11 +109,11 @@
return Qfalse;
}
/*
* call-seq:
- * app_name
+ * name
*
* Returns the application name passed to Notify.init
*/
static VALUE
_wrap_notify_get_app_name(VALUE self)
@@ -121,12 +121,34 @@
const gchar *name = notify_get_app_name();
return rb_str_new2(name);
}
+#ifdef HAVE_SET_APP_NAME
/*
* call-seq:
+ * name= new_name
+ *
+ * if new_name is a valid string, change the application name to new_name
+ * 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)
+{
+ char *name = NIL_P(app_name) ? NULL : StringValuePtr(app_name);
+
+ if(name != NULL || *name != '\0')
+ notify_set_app_name(name);
+
+ return Qnil;
+}
+#endif
+
+/*
+ * call-seq:
* server_caps
*
* Queries the server for its capabilities and returns them in an Array
*/
static VALUE
@@ -195,50 +217,32 @@
return rb_info;
}
/*
* call-seq:
- * new(summ, msg, icon, widget)
+ * new(summ, msg, icon)
*
* summ = The summary text (required)
*
* msg = The body text or nil
*
* icon = The icon or nil
*
- * widget = The widget (or a Gtk::StatusIcon, when compiled against GTK+ >= 2.9.2 and libnotify >= 0.4.1) to attach to or nil
- *
* Creates and returns a new notification, throw an exception on error
*/
static VALUE
-_wrap_notification_init(VALUE self, VALUE summ, VALUE msg,
- VALUE icon, VALUE widget)
+_wrap_notification_init(VALUE self, VALUE summ, VALUE msg, VALUE icon)
{
- GObject *obj = G_OBJECT(RVAL2GOBJ(widget));
char *nsumm = NIL_P(summ) ? NULL : StringValuePtr(summ);
NotifyNotification *n = NULL;
if(nsumm == NULL || *nsumm == '\0')
- rb_raise( rb_eArgError, "REQUIRED: the `summ` field" );
+ rb_raise(rb_eArgError, "You need to supply a valid summary string");
-#ifdef HAVE_STATUS_ICON
- if(GTK_IS_STATUS_ICON(obj))
- n = notify_notification_new_with_status_icon(nsumm,
- NIL_P(msg) ? NULL : StringValuePtr(msg),
- NIL_P(icon) ? NULL : StringValuePtr(icon),
- GTK_STATUS_ICON(obj));
- else
- n = notify_notification_new(nsumm,
- NIL_P(msg) ? NULL : StringValuePtr(msg),
- NIL_P(icon) ? NULL : StringValuePtr(icon),
- GTK_WIDGET(obj));
-#else
n = notify_notification_new(nsumm,
NIL_P(msg) ? NULL : StringValuePtr(msg),
- NIL_P(icon) ? NULL : StringValuePtr(icon),
- GTK_WIDGET(obj));
-#endif
+ NIL_P(icon) ? NULL : StringValuePtr(icon));
if(n == NULL)
rb_raise(rb_eRuntimeError, "Can not create a new notification");
G_INITIALIZE(self, n);
@@ -279,53 +283,20 @@
else
rb_warn("update, no ok");
#endif
if(nsumm == NULL || *nsumm == '\0')
- rb_raise(rb_eArgError, "REQUIRED: the `summ` field");
+ rb_raise(rb_eArgError, "You need to supply a valid summary string");
if(notify_notification_update(n, nsumm, nmsg, nicon) == TRUE)
return Qtrue;
return Qfalse;
}
/*
* call-seq:
- * attach_to(widget)
- *
- * widget = The widget (or a Gtk::StatusIcon, when compiled against GTK+ >= 2.9.2 and libnotify >= 0.4.1) to attach to
- *
- * Attaches the notification to a Gtk::Widget or Gtk::StatusIcon
- */
-static VALUE
-_wrap_notification_attach_to(VALUE self, VALUE widget)
-{
- GObject *obj = G_OBJECT(RVAL2GOBJ(widget));
- NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
-
-#ifdef DEBUG
- if(NOTIFY_IS_NOTIFICATION(n))
- rb_warn("attach_to, ok");
- else
- rb_warn("attach_to, no ok");
-#endif
-
-#ifdef HAVE_STATUS_ICON
- if(GTK_IS_STATUS_ICON(obj))
- notify_notification_attach_to_status_icon(n, GTK_STATUS_ICON(obj));
- else
- notify_notification_attach_to_widget(n, GTK_WIDGET(obj));
-#else
- notify_notification_attach_to_widget(n, GTK_WIDGET(obj));
-#endif
-
- return Qnil;
-}
-
-/*
- * call-seq:
* show
*
* Tells the notification server to display the notification on the screen.
* if TRUE returns, show the notification otherwise returns FALSE
*/
@@ -453,25 +424,25 @@
rb_warn("pixbuf_icon, ok");
else
rb_warn("pixbuf_icon, no ok");
#endif
- notify_notification_set_icon_from_pixbuf(n, pix);
+ notify_notification_set_image_from_pixbuf(n, pix);
return Qnil;
}
/*
- * call-seq:
- * hint32(key, value)
- *
- * key = The hint
- *
- * value = The hint's value
- *
- * Sets a hint with a 32-bit integer value
- */
+* call-seq:
+* hint32(key, value)
+*
+* key = The hint
+*
+* value = The hint's value
+*
+* Sets a hint with a 32-bit integer value
+*/
static VALUE
_wrap_notification_set_hint32(VALUE self, VALUE key, VALUE value)
{
char *vkey = NIL_P(key) ? NULL : StringValuePtr(key);
NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
@@ -487,19 +458,19 @@
return Qnil;
}
/*
- * call-seq:
- * hint_double(key, value)
- *
- * key = The hint
- *
- * value = The hint's value
- *
- * Sets a hint with a double value
- */
+* call-seq:
+* hint_double(key, value)
+*
+* key = The hint
+*
+* value = The hint's value
+*
+* Sets a hint with a double value
+*/
static VALUE
_wrap_notification_set_hint_double(VALUE self, VALUE key, VALUE value)
{
char *vkey = NIL_P(key) ? NULL : StringValuePtr(key);
NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
@@ -515,19 +486,19 @@
return Qnil;
}
/*
- * call-seq:
- * hint_string(key, value)
- *
- * key = The hint
- *
- * value = The hint's value
- *
- * Sets a hint with a string value
- */
+* call-seq:
+* hint_string(key, value)
+*
+* key = The hint
+*
+* value = The hint's value
+*
+* Sets a hint with a string value
+*/
static VALUE
_wrap_notification_set_hint_string(VALUE self, VALUE key, VALUE value)
{
char *vkey = NIL_P(key) ? NULL : StringValuePtr(key);
char *vvalue = NIL_P(value) ? NULL : StringValuePtr(value);
@@ -544,19 +515,19 @@
return Qnil;
}
/*
- * call-seq:
- * hint_byte(key, value)
- *
- * key = The hint
- *
- * value = The hint's value
- *
- * Sets a hint with a byte value
- */
+* call-seq:
+* hint_byte(key, value)
+*
+* key = The hint
+*
+* value = The hint's value
+*
+* Sets a hint with a byte value
+*/
static VALUE
_wrap_notification_set_hint_byte(VALUE self, VALUE key, VALUE value)
{
char *vkey = NIL_P(key) ? NULL : StringValuePtr(key);
NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
@@ -594,49 +565,12 @@
notify_notification_clear_hints(n);
return Qnil;
}
-#ifdef HAVE_GEOMETRY_HINTS
/*
* call-seq:
- * geometry_hints(screen, x, y)
- *
- * ** WHEN COMPILED AGAINST LIBNOTIFY 0.4.1 OR HIGHER **
- *
- * screen = The Gdk::Screen the notification should appear on
- *
- * x = The X coordinate to point to
- *
- * y = The Y coordinate to point to
- *
- * Sets the geometry hints on the notification
- */
-static VALUE
-_wrap_notification_set_geometry_hints(VALUE self, VALUE screen, VALUE x, VALUE y)
-{
- GdkScreen *sc = GDK_SCREEN(RVAL2GOBJ(screen));
- NotifyNotification *n = NOTIFY_NOTIFICATION(RVAL2GOBJ(self));
-
- if(sc == NULL)
- rb_raise(rb_eArgError, "REQUIRED: the `screen` field");
-
-#ifdef DEBUG
- if(NOTIFY_IS_NOTIFICATION(n) && GDK_IS_SCREEN(sc))
- rb_warn("set_geometry_hints, ok");
- else
- rb_warn("set_geometry_hints, no ok");
-#endif
-
- notify_notification_set_geometry_hints(n, sc, FIX2INT(x), FIX2INT(y));
-
- return Qnil;
-}
-#endif
-
-/*
- * call-seq:
* add_action(action, label, user_data) { |action, user_data| ... }
*
* action = The action id
*
* label = The action label
@@ -682,11 +616,11 @@
actionData->user_data = data;
notify_notification_add_action(n,
NIL_P(action) ? NULL : StringValuePtr(action),
NIL_P(label) ? NULL : StringValuePtr(label),
- (NotifyActionCallback) _notification_action_cb,
+ NOTIFY_ACTION_CALLBACK(_notification_action_cb),
actionData, (GFreeFunc)_notification_action_free);
return Qnil;
}
@@ -735,17 +669,14 @@
return Qtrue;
return Qfalse;
}
-#ifdef HAVE_CLOSED_REASON
/*
* call-seq:
* closed_reason
*
- * ** WHEN COMPILED AGAINST LIBNOTIFY 0.4.5 OR HIGHER **
- *
* Returns the reason code why the notification was closed
*/
static VALUE
_wrap_notification_get_closed_reason(VALUE self)
{
@@ -761,11 +692,10 @@
reason = notify_notification_get_closed_reason(n);
return INT2FIX(reason);
}
-#endif
/*
* libnotify ruby interface
* [ http://www.galago-project.org ]
*/
@@ -783,32 +713,29 @@
rb_define_const(cNotification, "EXPIRES_NEVER", INT2FIX(NOTIFY_EXPIRES_NEVER));
rb_define_module_function(mNotify, "init", _wrap_notify_init, 1);
rb_define_module_function(mNotify, "uninit", _wrap_notify_uninit, 0);
rb_define_module_function(mNotify, "init?", _wrap_notify_is_initted, 0);
- rb_define_module_function(mNotify, "app_name", _wrap_notify_get_app_name, 0);
+ rb_define_module_function(mNotify, "name", _wrap_notify_get_app_name, 0);
+#ifdef HAVE_SET_APP_NAME
+ rb_define_module_function(mNotify, "name=", _wrap_notify_set_app_name, 1);
+#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, 4);
+ rb_define_method(cNotification, "initialize", _wrap_notification_init, 3);
rb_define_method(cNotification, "update", _wrap_notification_update, 3);
- rb_define_method(cNotification, "attach_to", _wrap_notification_attach_to, 1);
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);
rb_define_method(cNotification, "pixbuf_icon=", _wrap_notification_set_pixbuf_icon, 1);
rb_define_method(cNotification, "hint32", _wrap_notification_set_hint32, 2);
rb_define_method(cNotification, "hint_double", _wrap_notification_set_hint_double, 2);
rb_define_method(cNotification, "hint_string", _wrap_notification_set_hint_string, 2);
rb_define_method(cNotification, "hint_byte", _wrap_notification_set_hint_byte, 2);
-#ifdef HAVE_GEOMETRY_HINTS
- rb_define_method(cNotification, "geometry_hints", _wrap_notification_set_geometry_hints, 3);
-#endif
rb_define_method(cNotification, "add_action", _wrap_notification_add_action, -1);
rb_define_method(cNotification, "clear_actions", _wrap_notification_clear_actions, 0);
rb_define_method(cNotification, "clear_hints", _wrap_notification_clear_hints, 0);
-#ifdef HAVE_CLOSED_REASON
rb_define_method(cNotification, "closed_reason", _wrap_notification_get_closed_reason, 0);
-#endif
rb_define_method(cNotification, "close", _wrap_notification_close, 0);
}