Use a consistent style

This commit is contained in:
William Jon McCann 2010-01-29 04:30:15 -05:00
parent ac8fe12f9a
commit 4db61ddb45
6 changed files with 1187 additions and 1174 deletions

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* *
* @file libnotify/internal.h Internal definitions * @file libnotify/internal.h Internal definitions
* *
@ -22,13 +22,7 @@
#ifndef _LIBNOTIFY_INTERNAL_H_ #ifndef _LIBNOTIFY_INTERNAL_H_
#define _LIBNOTIFY_INTERNAL_H_ #define _LIBNOTIFY_INTERNAL_H_
#ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#ifndef DBUS_API_SUBJECT_TO_CHANGE
# define DBUS_API_SUBJECT_TO_CHANGE 1
#endif
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* *
* @file libnotify/notification.c Notification object * @file libnotify/notification.c Notification object
* *
@ -44,11 +44,14 @@
static void notify_notification_class_init (NotifyNotificationClass *klass); static void notify_notification_class_init (NotifyNotificationClass *klass);
static void notify_notification_init (NotifyNotification *sp); static void notify_notification_init (NotifyNotification *sp);
static void notify_notification_finalize (GObject *object); static void notify_notification_finalize (GObject *object);
static void _close_signal_handler(DBusGProxy *proxy, guint32 id, guint32 reason, static void _close_signal_handler (DBusGProxy *proxy,
guint32 id,
guint32 reason,
NotifyNotification *notification); NotifyNotification *notification);
static void _action_signal_handler(DBusGProxy *proxy, guint32 id, static void _action_signal_handler (DBusGProxy *proxy,
gchar *action, guint32 id,
char *action,
NotifyNotification *notification); NotifyNotification *notification);
typedef struct typedef struct
@ -62,11 +65,11 @@ typedef struct
struct _NotifyNotificationPrivate struct _NotifyNotificationPrivate
{ {
guint32 id; guint32 id;
gchar *summary; char *summary;
gchar *body; char *body;
/* NULL to use icon data. Anything else to have server lookup icon */ /* NULL to use icon data. Anything else to have server lookup icon */
gchar *icon_name; char *icon_name;
/* /*
* -1 = use server default * -1 = use server default
@ -107,12 +110,16 @@ enum
PROP_CLOSED_REASON PROP_CLOSED_REASON
}; };
static void notify_notification_set_property(GObject *object, guint prop_id, static void notify_notification_set_property (GObject *object,
guint prop_id,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void notify_notification_get_property(GObject *object, guint prop_id, static void notify_notification_get_property (GObject *object,
GValue *value, GParamSpec *pspec); guint prop_id,
GValue *value,
GParamSpec *pspec);
static guint signals[LAST_SIGNAL] = { 0 }; static guint signals[LAST_SIGNAL] = { 0 };
static GObjectClass *parent_class = NULL; static GObjectClass *parent_class = NULL;
G_DEFINE_TYPE (NotifyNotification, notify_notification, G_TYPE_OBJECT) G_DEFINE_TYPE (NotifyNotification, notify_notification, G_TYPE_OBJECT)
@ -122,7 +129,10 @@ notify_notification_constructor(GType type,
guint n_construct_properties, guint n_construct_properties,
GObjectConstructParam *construct_params) GObjectConstructParam *construct_params)
{ {
GObject *object = parent_class->constructor(type, n_construct_properties, GObject *object;
object = parent_class->constructor (type,
n_construct_properties,
construct_params); construct_params);
_notify_cache_add_notification (NOTIFY_NOTIFICATION (object)); _notify_cache_add_notification (NOTIFY_NOTIFICATION (object));
@ -152,8 +162,7 @@ notify_notification_class_init(NotifyNotificationClass *klass)
g_signal_new ("closed", g_signal_new ("closed",
G_TYPE_FROM_CLASS (object_class), G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(NotifyNotificationClass, closed), G_STRUCT_OFFSET (NotifyNotificationClass, closed), NULL, NULL,
NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
g_object_class_install_property (object_class, PROP_ID, g_object_class_install_property (object_class, PROP_ID,
@ -162,75 +171,78 @@ notify_notification_class_init(NotifyNotificationClass *klass)
0, 0,
G_MAXINT32, G_MAXINT32,
0, 0,
G_PARAM_READWRITE | G_PARAM_READWRITE
G_PARAM_CONSTRUCT | | G_PARAM_CONSTRUCT
G_PARAM_STATIC_NAME | | G_PARAM_STATIC_NAME
G_PARAM_STATIC_NICK | | G_PARAM_STATIC_NICK
G_PARAM_STATIC_BLURB)); | G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class, PROP_SUMMARY, g_object_class_install_property (object_class, PROP_SUMMARY,
g_param_spec_string("summary", "Summary", g_param_spec_string ("summary",
"Summary",
"The summary text", "The summary text",
NULL, NULL,
G_PARAM_READWRITE | G_PARAM_READWRITE
G_PARAM_CONSTRUCT | | G_PARAM_CONSTRUCT
G_PARAM_STATIC_NAME | | G_PARAM_STATIC_NAME
G_PARAM_STATIC_NICK | | G_PARAM_STATIC_NICK
G_PARAM_STATIC_BLURB)); | G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class, PROP_BODY, g_object_class_install_property (object_class, PROP_BODY,
g_param_spec_string("body", "Message Body", g_param_spec_string ("body",
"Message Body",
"The message body text", "The message body text",
NULL, NULL,
G_PARAM_READWRITE | G_PARAM_READWRITE
G_PARAM_CONSTRUCT | | G_PARAM_CONSTRUCT
G_PARAM_STATIC_NAME | | G_PARAM_STATIC_NAME
G_PARAM_STATIC_NICK | | G_PARAM_STATIC_NICK
G_PARAM_STATIC_BLURB)); | G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class, PROP_ICON_NAME, g_object_class_install_property (object_class, PROP_ICON_NAME,
g_param_spec_string ("icon-name", g_param_spec_string ("icon-name",
"Icon Name", "Icon Name",
"The icon filename or icon theme-compliant name", "The icon filename or icon theme-compliant name",
NULL, NULL,
G_PARAM_READWRITE | G_PARAM_READWRITE
G_PARAM_CONSTRUCT | | G_PARAM_CONSTRUCT
G_PARAM_STATIC_NAME | | G_PARAM_STATIC_NAME
G_PARAM_STATIC_NICK | | G_PARAM_STATIC_NICK
G_PARAM_STATIC_BLURB)); | G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class, PROP_ATTACH_WIDGET, g_object_class_install_property (object_class, PROP_ATTACH_WIDGET,
g_param_spec_object ("attach-widget", g_param_spec_object ("attach-widget",
"Attach Widget", "Attach Widget",
"The widget to attach the notification to", "The widget to attach the notification to",
GTK_TYPE_WIDGET, GTK_TYPE_WIDGET,
G_PARAM_READWRITE | G_PARAM_READWRITE
G_PARAM_CONSTRUCT | | G_PARAM_CONSTRUCT
G_PARAM_STATIC_NAME | | G_PARAM_STATIC_NAME
G_PARAM_STATIC_NICK | | G_PARAM_STATIC_NICK
G_PARAM_STATIC_BLURB)); | G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class, PROP_STATUS_ICON, g_object_class_install_property (object_class, PROP_STATUS_ICON,
g_param_spec_object ("status-icon", g_param_spec_object ("status-icon",
"Status Icon", "Status Icon",
"The status icon to attach the notification to", "The status icon to attach the notification to",
GTK_TYPE_STATUS_ICON, GTK_TYPE_STATUS_ICON,
G_PARAM_READWRITE | G_PARAM_READWRITE
G_PARAM_CONSTRUCT | | G_PARAM_CONSTRUCT
G_PARAM_STATIC_NAME | | G_PARAM_STATIC_NAME
G_PARAM_STATIC_NICK | | G_PARAM_STATIC_NICK
G_PARAM_STATIC_BLURB)); | G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class, PROP_CLOSED_REASON, g_object_class_install_property (object_class, PROP_CLOSED_REASON,
g_param_spec_int("closed-reason", "Closed Reason", g_param_spec_int ("closed-reason",
"Closed Reason",
"The reason code for why the notification was closed", "The reason code for why the notification was closed",
-1, -1,
G_MAXINT32, G_MAXINT32,
-1, -1,
G_PARAM_READABLE | G_PARAM_READABLE
G_PARAM_STATIC_NAME | | G_PARAM_STATIC_NAME
G_PARAM_STATIC_NICK | | G_PARAM_STATIC_NICK
G_PARAM_STATIC_BLURB)); | G_PARAM_STATIC_BLURB));
} }
static void static void
@ -242,26 +254,30 @@ notify_notification_set_property(GObject *object,
NotifyNotification *notification = NOTIFY_NOTIFICATION (object); NotifyNotification *notification = NOTIFY_NOTIFICATION (object);
NotifyNotificationPrivate *priv = notification->priv; NotifyNotificationPrivate *priv = notification->priv;
switch (prop_id) switch (prop_id) {
{
case PROP_ID: case PROP_ID:
priv->id = g_value_get_int (value); priv->id = g_value_get_int (value);
break; break;
case PROP_SUMMARY: case PROP_SUMMARY:
notify_notification_update(notification, g_value_get_string(value), notify_notification_update (notification,
priv->body, priv->icon_name); g_value_get_string (value),
priv->body,
priv->icon_name);
break; break;
case PROP_BODY: case PROP_BODY:
notify_notification_update(notification, priv->summary, notify_notification_update (notification,
priv->summary,
g_value_get_string (value), g_value_get_string (value),
priv->icon_name); priv->icon_name);
break; break;
case PROP_ICON_NAME: case PROP_ICON_NAME:
notify_notification_update(notification, priv->summary, notify_notification_update (notification,
priv->body, g_value_get_string(value)); priv->summary,
priv->body,
g_value_get_string (value));
break; break;
case PROP_ATTACH_WIDGET: case PROP_ATTACH_WIDGET:
@ -289,8 +305,7 @@ notify_notification_get_property(GObject *object,
NotifyNotification *notification = NOTIFY_NOTIFICATION (object); NotifyNotification *notification = NOTIFY_NOTIFICATION (object);
NotifyNotificationPrivate *priv = notification->priv; NotifyNotificationPrivate *priv = notification->priv;
switch (prop_id) switch (prop_id) {
{
case PROP_ID: case PROP_ID:
g_value_set_int (value, priv->id); g_value_set_int (value, priv->id);
break; break;
@ -347,11 +362,13 @@ notify_notification_init(NotifyNotification *obj)
obj->priv = g_new0 (NotifyNotificationPrivate, 1); obj->priv = g_new0 (NotifyNotificationPrivate, 1);
obj->priv->timeout = NOTIFY_EXPIRES_DEFAULT; obj->priv->timeout = NOTIFY_EXPIRES_DEFAULT;
obj->priv->closed_reason = -1; obj->priv->closed_reason = -1;
obj->priv->hints = g_hash_table_new_full(g_str_hash, g_str_equal, obj->priv->hints = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free, g_free,
(GFreeFunc) _g_value_free); (GFreeFunc) _g_value_free);
obj->priv->action_map = g_hash_table_new_full(g_str_hash, g_str_equal, obj->priv->action_map = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free, g_free,
(GFreeFunc) destroy_pair); (GFreeFunc) destroy_pair);
} }
@ -369,8 +386,7 @@ notify_notification_finalize(GObject *object)
g_free (priv->body); g_free (priv->body);
g_free (priv->icon_name); g_free (priv->icon_name);
if (priv->actions != NULL) if (priv->actions != NULL) {
{
g_slist_foreach (priv->actions, (GFunc) g_free, NULL); g_slist_foreach (priv->actions, (GFunc) g_free, NULL);
g_slist_free (priv->actions); g_slist_free (priv->actions);
} }
@ -388,12 +404,13 @@ notify_notification_finalize(GObject *object)
g_object_remove_weak_pointer (G_OBJECT (priv->status_icon), g_object_remove_weak_pointer (G_OBJECT (priv->status_icon),
(gpointer) & priv->status_icon); (gpointer) & priv->status_icon);
if (priv->signals_registered) if (priv->signals_registered) {
{ dbus_g_proxy_disconnect_signal (proxy,
dbus_g_proxy_disconnect_signal(proxy, "NotificationClosed", "NotificationClosed",
G_CALLBACK (_close_signal_handler), G_CALLBACK (_close_signal_handler),
object); object);
dbus_g_proxy_disconnect_signal(proxy, "ActionInvoked", dbus_g_proxy_disconnect_signal (proxy,
"ActionInvoked",
G_CALLBACK (_action_signal_handler), G_CALLBACK (_action_signal_handler),
object); object);
} }
@ -417,8 +434,7 @@ _notify_notification_update_applet_hints(NotifyNotification *n)
GdkScreen *screen = NULL; GdkScreen *screen = NULL;
gint x, y; gint x, y;
if (priv->status_icon != NULL) if (priv->status_icon != NULL) {
{
GdkRectangle rect; GdkRectangle rect;
GtkWidget *internal_tray = get_internal_tray_icon (priv->status_icon); GtkWidget *internal_tray = get_internal_tray_icon (priv->status_icon);
GdkWindow *window; GdkWindow *window;
@ -427,45 +443,45 @@ _notify_notification_update_applet_hints(NotifyNotification *n)
gtk_widget_realize (internal_tray); gtk_widget_realize (internal_tray);
window = internal_tray->window; window = internal_tray->window;
if (window != NULL) if (window != NULL) {
{
guint32 xid = GDK_WINDOW_XID (window); guint32 xid = GDK_WINDOW_XID (window);
notify_notification_set_hint_uint32(n, "window-xid", xid);
notify_notification_set_hint_uint32 (n,
"window-xid",
xid);
} }
if (!gtk_status_icon_get_geometry(priv->status_icon, &screen, if (!gtk_status_icon_get_geometry (priv->status_icon,
&rect, NULL)) &screen,
{ &rect, NULL)) {
return; return;
} }
x = rect.x + rect.width / 2; x = rect.x + rect.width / 2;
y = rect.y + rect.height / 2; y = rect.y + rect.height / 2;
} } else if (priv->attached_widget != NULL) {
else if (priv->attached_widget != NULL)
{
GtkWidget *widget = priv->attached_widget; GtkWidget *widget = priv->attached_widget;
screen = gtk_widget_get_screen (widget); screen = gtk_widget_get_screen (widget);
gdk_window_get_origin (widget->window, &x, &y); gdk_window_get_origin (widget->window, &x, &y);
if (GTK_WIDGET_NO_WINDOW(widget)) if (GTK_WIDGET_NO_WINDOW (widget)) {
{
x += widget->allocation.x; x += widget->allocation.x;
y += widget->allocation.y; y += widget->allocation.y;
} }
x += widget->allocation.width / 2; x += widget->allocation.width / 2;
y += widget->allocation.height / 2; y += widget->allocation.height / 2;
} } else {
else
return; return;
}
notify_notification_set_geometry_hints (n, screen, x, y); notify_notification_set_geometry_hints (n, screen, x, y);
} }
#if 0 #if 0
/* /*
* This is left here just incase we revisit autoupdating * This is left here just incase we revisit autoupdating
* One thought would be to check for updates every time the icon * One thought would be to check for updates every time the icon
@ -479,18 +495,15 @@ _idle_check_updates(void *user_data)
NotifyNotification *n = NOTIFY_NOTIFICATION (user_data); NotifyNotification *n = NOTIFY_NOTIFICATION (user_data);
NotifyNotificationPrivate *priv = n->priv; NotifyNotificationPrivate *priv = n->priv;
if (priv->is_visible) if (priv->is_visible) {
{ priv->updates_pending =
priv->updates_pending = _notify_notification_update_applet_hints(n); _notify_notification_update_applet_hints (n);
if (priv->updates_pending) if (priv->updates_pending) {
{
/* Try again if we fail on next idle */ /* Try again if we fail on next idle */
priv->updates_pending = !notify_notification_show (n, NULL); priv->updates_pending = !notify_notification_show (n, NULL);
} }
} } else {
else
{
priv->updates_pending = FALSE; priv->updates_pending = FALSE;
} }
@ -511,9 +524,9 @@ _idle_check_updates(void *user_data)
* Returns: The new #NotifyNotification. * Returns: The new #NotifyNotification.
*/ */
NotifyNotification * NotifyNotification *
notify_notification_new(const gchar *summary, notify_notification_new (const char *summary,
const gchar *body, const char *body,
const gchar *icon, const char *icon,
GtkWidget *attach) GtkWidget *attach)
{ {
g_return_val_if_fail (attach == NULL || GTK_IS_WIDGET (attach), NULL); g_return_val_if_fail (attach == NULL || GTK_IS_WIDGET (attach), NULL);
@ -522,8 +535,7 @@ notify_notification_new(const gchar *summary,
"summary", summary, "summary", summary,
"body", body, "body", body,
"icon-name", icon, "icon-name", icon,
"attach-widget", attach, "attach-widget", attach, NULL);
NULL);
} }
/** /**
@ -542,9 +554,9 @@ notify_notification_new(const gchar *summary,
* Since: 0.4.1 * Since: 0.4.1
*/ */
NotifyNotification * NotifyNotification *
notify_notification_new_with_status_icon(const gchar *summary, notify_notification_new_with_status_icon (const char *summary,
const gchar *message, const char *message,
const gchar *icon, const char *icon,
GtkStatusIcon *status_icon) GtkStatusIcon *status_icon)
{ {
g_return_val_if_fail (status_icon != NULL, NULL); g_return_val_if_fail (status_icon != NULL, NULL);
@ -573,34 +585,31 @@ notify_notification_new_with_status_icon(const gchar *summary,
*/ */
gboolean gboolean
notify_notification_update (NotifyNotification *notification, notify_notification_update (NotifyNotification *notification,
const gchar *summary, const char *summary,
const gchar *body, const char *body,
const gchar *icon) const char *icon)
{ {
g_return_val_if_fail (notification != NULL, FALSE); g_return_val_if_fail (notification != NULL, FALSE);
g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), FALSE); g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), FALSE);
g_return_val_if_fail (summary != NULL && *summary != '\0', FALSE); g_return_val_if_fail (summary != NULL && *summary != '\0', FALSE);
if (notification->priv->summary != summary) if (notification->priv->summary != summary) {
{
g_free (notification->priv->summary); g_free (notification->priv->summary);
notification->priv->summary = g_strdup (summary); notification->priv->summary = g_strdup (summary);
g_object_notify (G_OBJECT (notification), "summary"); g_object_notify (G_OBJECT (notification), "summary");
} }
if (notification->priv->body != body) if (notification->priv->body != body) {
{
g_free (notification->priv->body); g_free (notification->priv->body);
notification->priv->body = notification->priv->body = (body != NULL
(body != NULL && *body != '\0' ? g_strdup(body) : NULL); && *body != '\0' ? g_strdup (body) : NULL);
g_object_notify (G_OBJECT (notification), "body"); g_object_notify (G_OBJECT (notification), "body");
} }
if (notification->priv->icon_name != icon) if (notification->priv->icon_name != icon) {
{
g_free (notification->priv->icon_name); g_free (notification->priv->icon_name);
notification->priv->icon_name = notification->priv->icon_name = (icon != NULL
(icon != NULL && *icon != '\0' ? g_strdup(icon) : NULL); && *icon != '\0' ? g_strdup (icon) : NULL);
g_object_notify (G_OBJECT (notification), "icon-name"); g_object_notify (G_OBJECT (notification), "icon-name");
} }
@ -654,23 +663,22 @@ notify_notification_attach_to_status_icon(NotifyNotification *notification,
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification)); g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
g_return_if_fail(status_icon == NULL || GTK_IS_STATUS_ICON(status_icon)); g_return_if_fail (status_icon == NULL
|| GTK_IS_STATUS_ICON (status_icon));
priv = notification->priv; priv = notification->priv;
if (priv->status_icon == status_icon) if (priv->status_icon == status_icon)
return; return;
if (priv->status_icon != NULL) if (priv->status_icon != NULL) {
{
g_object_remove_weak_pointer (G_OBJECT (priv->status_icon), g_object_remove_weak_pointer (G_OBJECT (priv->status_icon),
(gpointer) & priv->status_icon); (gpointer) & priv->status_icon);
} }
priv->status_icon = status_icon; priv->status_icon = status_icon;
if (priv->status_icon != NULL) if (priv->status_icon != NULL) {
{
g_object_add_weak_pointer (G_OBJECT (priv->status_icon), g_object_add_weak_pointer (G_OBJECT (priv->status_icon),
(gpointer) & priv->status_icon); (gpointer) & priv->status_icon);
} }
@ -708,7 +716,9 @@ notify_notification_set_geometry_hints(NotifyNotification *notification,
notify_notification_set_hint_int32 (notification, "y", y); notify_notification_set_hint_int32 (notification, "y", y);
display_name = gdk_screen_make_display_name (screen); display_name = gdk_screen_make_display_name (screen);
notify_notification_set_hint_string(notification, "xdisplay", display_name); notify_notification_set_hint_string (notification,
"xdisplay",
display_name);
g_free (display_name); g_free (display_name);
} }
@ -718,8 +728,7 @@ _close_signal_handler(DBusGProxy *proxy,
guint32 reason, guint32 reason,
NotifyNotification *notification) NotifyNotification *notification)
{ {
if (id == notification->priv->id) if (id == notification->priv->id) {
{
g_object_ref (G_OBJECT (notification)); g_object_ref (G_OBJECT (notification));
notification->priv->closed_reason = reason; notification->priv->closed_reason = reason;
g_signal_emit (notification, signals[SIGNAL_CLOSED], 0); g_signal_emit (notification, signals[SIGNAL_CLOSED], 0);
@ -731,7 +740,7 @@ _close_signal_handler(DBusGProxy *proxy,
static void static void
_action_signal_handler (DBusGProxy *proxy, _action_signal_handler (DBusGProxy *proxy,
guint32 id, guint32 id,
gchar *action, char *action,
NotifyNotification *notification) NotifyNotification *notification)
{ {
CallbackPair *pair; CallbackPair *pair;
@ -742,31 +751,30 @@ _action_signal_handler(DBusGProxy *proxy,
if (id != notification->priv->id) if (id != notification->priv->id)
return; return;
pair = (CallbackPair *)g_hash_table_lookup( pair = (CallbackPair *) g_hash_table_lookup (notification->priv->action_map,
notification->priv->action_map, action); action);
if (pair == NULL) if (pair == NULL) {
{
if (g_ascii_strcasecmp (action, "default")) if (g_ascii_strcasecmp (action, "default"))
g_warning ("Received unknown action %s", action); g_warning ("Received unknown action %s", action);
} } else {
else
{
pair->cb (notification, action, pair->user_data); pair->cb (notification, action, pair->user_data);
} }
} }
static gchar ** static char **
_gslist_to_string_array (GSList *list) _gslist_to_string_array (GSList *list)
{ {
GSList *l; GSList *l;
GArray *a = g_array_sized_new(TRUE, FALSE, sizeof(gchar *), GArray *a = g_array_sized_new (TRUE,
FALSE,
sizeof (char *),
g_slist_length (list)); g_slist_length (list));
for (l = list; l != NULL; l = l->next) for (l = list; l != NULL; l = l->next)
g_array_append_val (a, l->data); g_array_append_val (a, l->data);
return (gchar **)g_array_free(a, FALSE); return (char **) g_array_free (a, FALSE);
} }
/** /**
@ -785,7 +793,7 @@ notify_notification_show(NotifyNotification *notification,
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
GError *tmp_error = NULL; GError *tmp_error = NULL;
gchar **action_array; char **action_array;
DBusGProxy *proxy; DBusGProxy *proxy;
g_return_val_if_fail (notification != NULL, FALSE); g_return_val_if_fail (notification != NULL, FALSE);
@ -795,15 +803,18 @@ notify_notification_show(NotifyNotification *notification,
priv = notification->priv; priv = notification->priv;
proxy = _notify_get_g_proxy (); proxy = _notify_get_g_proxy ();
if (!priv->signals_registered) if (!priv->signals_registered) {
{ dbus_g_proxy_connect_signal (proxy,
dbus_g_proxy_connect_signal(proxy, "NotificationClosed", "NotificationClosed",
G_CALLBACK (_close_signal_handler), G_CALLBACK (_close_signal_handler),
notification, NULL); notification,
NULL);
dbus_g_proxy_connect_signal(proxy, "ActionInvoked", dbus_g_proxy_connect_signal (proxy,
"ActionInvoked",
G_CALLBACK (_action_signal_handler), G_CALLBACK (_action_signal_handler),
notification, NULL); notification,
NULL);
priv->signals_registered = TRUE; priv->signals_registered = TRUE;
} }
@ -821,18 +832,18 @@ notify_notification_show(NotifyNotification *notification,
G_TYPE_STRING, priv->summary, G_TYPE_STRING, priv->summary,
G_TYPE_STRING, priv->body, G_TYPE_STRING, priv->body,
G_TYPE_STRV, action_array, G_TYPE_STRV, action_array,
dbus_g_type_get_map("GHashTable", G_TYPE_STRING, dbus_g_type_get_map ("GHashTable",
G_TYPE_VALUE), priv->hints, G_TYPE_STRING,
G_TYPE_VALUE),
priv->hints,
G_TYPE_INT, priv->timeout, G_TYPE_INT, priv->timeout,
G_TYPE_INVALID, G_TYPE_INVALID,
G_TYPE_UINT, &priv->id, G_TYPE_UINT, &priv->id, G_TYPE_INVALID);
G_TYPE_INVALID);
/* Don't free the elements because they are owned by priv->actions */ /* Don't free the elements because they are owned by priv->actions */
g_free (action_array); g_free (action_array);
if (tmp_error != NULL) if (tmp_error != NULL) {
{
g_propagate_error (error, tmp_error); g_propagate_error (error, tmp_error);
return FALSE; return FALSE;
} }
@ -883,7 +894,9 @@ notify_notification_set_category(NotifyNotification *notification,
g_return_if_fail (notification != NULL); g_return_if_fail (notification != NULL);
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification)); g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
notify_notification_set_hint_string(notification, "category", category); notify_notification_set_hint_string (notification,
"category",
category);
} }
/** /**
@ -902,12 +915,15 @@ notify_notification_set_urgency(NotifyNotification *notification,
g_return_if_fail (notification != NULL); g_return_if_fail (notification != NULL);
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification)); g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
notify_notification_set_hint_byte(notification, "urgency", (guchar)urgency); notify_notification_set_hint_byte (notification,
"urgency",
(guchar) urgency);
} }
#if CHECK_DBUS_VERSION(0, 60) #if CHECK_DBUS_VERSION(0, 60)
static void static void
_gvalue_array_append_int(GValueArray *array, gint i) _gvalue_array_append_int (GValueArray *array,
gint i)
{ {
GValue value = { 0 }; GValue value = { 0 };
@ -929,7 +945,9 @@ _gvalue_array_append_bool(GValueArray *array, gboolean b)
} }
static void static void
_gvalue_array_append_byte_array(GValueArray *array, guchar *bytes, gsize len) _gvalue_array_append_byte_array (GValueArray *array,
guchar *bytes,
gsize len)
{ {
GArray *byte_array; GArray *byte_array;
GValue value = { 0 }; GValue value = { 0 };
@ -990,7 +1008,8 @@ notify_notification_set_icon_from_pixbuf(NotifyNotification *notification,
_gvalue_array_append_int (image_struct, width); _gvalue_array_append_int (image_struct, width);
_gvalue_array_append_int (image_struct, height); _gvalue_array_append_int (image_struct, height);
_gvalue_array_append_int (image_struct, rowstride); _gvalue_array_append_int (image_struct, rowstride);
_gvalue_array_append_bool(image_struct, gdk_pixbuf_get_has_alpha(icon)); _gvalue_array_append_bool (image_struct,
gdk_pixbuf_get_has_alpha (icon));
_gvalue_array_append_int (image_struct, bits_per_sample); _gvalue_array_append_int (image_struct, bits_per_sample);
_gvalue_array_append_int (image_struct, n_channels); _gvalue_array_append_int (image_struct, n_channels);
_gvalue_array_append_byte_array (image_struct, image, image_len); _gvalue_array_append_byte_array (image_struct, image, image_len);
@ -1016,7 +1035,7 @@ notify_notification_set_icon_from_pixbuf(NotifyNotification *notification,
*/ */
void void
notify_notification_set_hint_int32 (NotifyNotification *notification, notify_notification_set_hint_int32 (NotifyNotification *notification,
const gchar *key, const char *key,
gint value) gint value)
{ {
GValue *hint_value; GValue *hint_value;
@ -1029,7 +1048,8 @@ notify_notification_set_hint_int32(NotifyNotification *notification,
g_value_init (hint_value, G_TYPE_INT); g_value_init (hint_value, G_TYPE_INT);
g_value_set_int (hint_value, value); g_value_set_int (hint_value, value);
g_hash_table_insert (notification->priv->hints, g_hash_table_insert (notification->priv->hints,
g_strdup(key), hint_value); g_strdup (key),
hint_value);
} }
@ -1043,7 +1063,7 @@ notify_notification_set_hint_int32(NotifyNotification *notification,
*/ */
void void
notify_notification_set_hint_uint32 (NotifyNotification *notification, notify_notification_set_hint_uint32 (NotifyNotification *notification,
const gchar *key, const char *key,
guint value) guint value)
{ {
GValue *hint_value; GValue *hint_value;
@ -1056,7 +1076,8 @@ notify_notification_set_hint_uint32(NotifyNotification *notification,
g_value_init (hint_value, G_TYPE_UINT); g_value_init (hint_value, G_TYPE_UINT);
g_value_set_uint (hint_value, value); g_value_set_uint (hint_value, value);
g_hash_table_insert (notification->priv->hints, g_hash_table_insert (notification->priv->hints,
g_strdup(key), hint_value); g_strdup (key),
hint_value);
} }
/** /**
@ -1069,7 +1090,7 @@ notify_notification_set_hint_uint32(NotifyNotification *notification,
*/ */
void void
notify_notification_set_hint_double (NotifyNotification *notification, notify_notification_set_hint_double (NotifyNotification *notification,
const gchar *key, const char *key,
gdouble value) gdouble value)
{ {
GValue *hint_value; GValue *hint_value;
@ -1082,7 +1103,8 @@ notify_notification_set_hint_double(NotifyNotification *notification,
g_value_init (hint_value, G_TYPE_FLOAT); g_value_init (hint_value, G_TYPE_FLOAT);
g_value_set_float (hint_value, value); g_value_set_float (hint_value, value);
g_hash_table_insert (notification->priv->hints, g_hash_table_insert (notification->priv->hints,
g_strdup(key), hint_value); g_strdup (key),
hint_value);
} }
/** /**
@ -1095,7 +1117,7 @@ notify_notification_set_hint_double(NotifyNotification *notification,
*/ */
void void
notify_notification_set_hint_byte (NotifyNotification *notification, notify_notification_set_hint_byte (NotifyNotification *notification,
const gchar *key, const char *key,
guchar value) guchar value)
{ {
GValue *hint_value; GValue *hint_value;
@ -1108,7 +1130,9 @@ notify_notification_set_hint_byte(NotifyNotification *notification,
g_value_init (hint_value, G_TYPE_UCHAR); g_value_init (hint_value, G_TYPE_UCHAR);
g_value_set_uchar (hint_value, value); g_value_set_uchar (hint_value, value);
g_hash_table_insert(notification->priv->hints, g_strdup(key), hint_value); g_hash_table_insert (notification->priv->hints,
g_strdup (key),
hint_value);
} }
/** /**
@ -1123,7 +1147,7 @@ notify_notification_set_hint_byte(NotifyNotification *notification,
*/ */
void void
notify_notification_set_hint_byte_array (NotifyNotification *notification, notify_notification_set_hint_byte_array (NotifyNotification *notification,
const gchar *key, const char *key,
const guchar *value, const guchar *value,
gsize len) gsize len)
{ {
@ -1145,7 +1169,8 @@ notify_notification_set_hint_byte_array(NotifyNotification *notification,
g_value_take_boxed (hint_value, byte_array); g_value_take_boxed (hint_value, byte_array);
g_hash_table_insert (notification->priv->hints, g_hash_table_insert (notification->priv->hints,
g_strdup(key), hint_value); g_strdup (key),
hint_value);
} }
/** /**
@ -1158,8 +1183,8 @@ notify_notification_set_hint_byte_array(NotifyNotification *notification,
*/ */
void void
notify_notification_set_hint_string (NotifyNotification *notification, notify_notification_set_hint_string (NotifyNotification *notification,
const gchar *key, const char *key,
const gchar *value) const char *value)
{ {
GValue *hint_value; GValue *hint_value;
@ -1171,7 +1196,8 @@ notify_notification_set_hint_string(NotifyNotification *notification,
g_value_init (hint_value, G_TYPE_STRING); g_value_init (hint_value, G_TYPE_STRING);
g_value_set_string (hint_value, value); g_value_set_string (hint_value, value);
g_hash_table_insert (notification->priv->hints, g_hash_table_insert (notification->priv->hints,
g_strdup(key), hint_value); g_strdup (key),
hint_value);
} }
static gboolean static gboolean
@ -1193,7 +1219,8 @@ notify_notification_clear_hints(NotifyNotification *notification)
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification)); g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
g_hash_table_foreach_remove (notification->priv->hints, g_hash_table_foreach_remove (notification->priv->hints,
(GHRFunc)_remove_all, NULL); (GHRFunc) _remove_all,
NULL);
} }
/** /**
@ -1209,11 +1236,13 @@ notify_notification_clear_actions(NotifyNotification *notification)
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification)); g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
g_hash_table_foreach_remove (notification->priv->action_map, g_hash_table_foreach_remove (notification->priv->action_map,
(GHRFunc)_remove_all, NULL); (GHRFunc) _remove_all,
NULL);
if (notification->priv->actions != NULL) if (notification->priv->actions != NULL) {
{ g_slist_foreach (notification->priv->actions,
g_slist_foreach(notification->priv->actions, (GFunc)g_free, NULL); (GFunc) g_free,
NULL);
g_slist_free (notification->priv->actions); g_slist_free (notification->priv->actions);
} }
@ -1264,8 +1293,7 @@ notify_notification_add_action(NotifyNotification *notification,
g_hash_table_insert (priv->action_map, g_strdup (action), pair); g_hash_table_insert (priv->action_map, g_strdup (action), pair);
if (!notification->priv->has_nondefault_actions && if (!notification->priv->has_nondefault_actions &&
g_ascii_strcasecmp(action, "default") != 0) g_ascii_strcasecmp (action, "default") != 0) {
{
notification->priv->has_nondefault_actions = TRUE; notification->priv->has_nondefault_actions = TRUE;
} }
} }
@ -1302,12 +1330,15 @@ notify_notification_close(NotifyNotification *notification,
priv = notification->priv; priv = notification->priv;
dbus_g_proxy_call(_notify_get_g_proxy(), "CloseNotification", &tmp_error, dbus_g_proxy_call (_notify_get_g_proxy (),
G_TYPE_UINT, priv->id, G_TYPE_INVALID, "CloseNotification",
&tmp_error,
G_TYPE_UINT,
priv->id,
G_TYPE_INVALID,
G_TYPE_INVALID); G_TYPE_INVALID);
if (tmp_error != NULL) if (tmp_error != NULL) {
{
g_propagate_error (error, tmp_error); g_propagate_error (error, tmp_error);
return FALSE; return FALSE;
} }

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* *
* @file libnotify/notification.h Notification object * @file libnotify/notification.h Notification object
* *
@ -33,20 +33,11 @@ G_BEGIN_DECLS
#define NOTIFY_EXPIRES_NEVER 0 #define NOTIFY_EXPIRES_NEVER 0
#define NOTIFY_TYPE_NOTIFICATION (notify_notification_get_type ()) #define NOTIFY_TYPE_NOTIFICATION (notify_notification_get_type ())
#define NOTIFY_NOTIFICATION(o) \ #define NOTIFY_NOTIFICATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NOTIFY_TYPE_NOTIFICATION, NotifyNotification))
(G_TYPE_CHECK_INSTANCE_CAST ((o), NOTIFY_TYPE_NOTIFICATION, \ #define NOTIFY_NOTIFICATION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NOTIFY_TYPE_NOTIFICATION, NotifyNotificationClass))
NotifyNotification)) #define NOTIFY_IS_NOTIFICATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NOTIFY_TYPE_NOTIFICATION))
#define NOTIFY_NOTIFICATION_CLASS(k) \ #define NOTIFY_IS_NOTIFICATION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NOTIFY_TYPE_NOTIFICATION))
(G_TYPE_CHECK_CLASS_CAST((k), NOTIFY_TYPE_NOTIFICATION, \ #define NOTIFY_NOTIFICATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NOTIFY_TYPE_NOTIFICATION, NotifyNotificationClass))
NotifyNotificationClass))
#define NOTIFY_IS_NOTIFICATION(o) \
(G_TYPE_CHECK_INSTANCE_TYPE ((o), NOTIFY_TYPE_NOTIFICATION))
#define NOTIFY_IS_NOTIFICATION_CLASS(k) \
(G_TYPE_CHECK_CLASS_TYPE ((k), NOTIFY_TYPE_NOTIFICATION))
#define NOTIFY_NOTIFICATION_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS ((o), NOTIFY_TYPE_NOTIFICATION, \
NotifyNotificationClass))
typedef struct _NotifyNotification NotifyNotification; typedef struct _NotifyNotification NotifyNotification;
typedef struct _NotifyNotificationClass NotifyNotificationClass; typedef struct _NotifyNotificationClass NotifyNotificationClass;
@ -78,27 +69,28 @@ typedef enum
} NotifyUrgency; } NotifyUrgency;
typedef void (*NotifyActionCallback) (NotifyNotification *notification, typedef void (*NotifyActionCallback) (NotifyNotification *notification,
gchar *action, char *action,
gpointer user_data); gpointer user_data);
#define NOTIFY_ACTION_CALLBACK(func) ((NotifyActionCallback)(func)) #define NOTIFY_ACTION_CALLBACK(func) ((NotifyActionCallback)(func))
GType notify_notification_get_type(); GType notify_notification_get_type (void);
NotifyNotification *notify_notification_new(const gchar *summary, NotifyNotification *notify_notification_new (const char *summary,
const gchar *body, const char *body,
const gchar *icon, const char *icon,
GtkWidget *attach); GtkWidget *attach);
#if GTK_CHECK_VERSION(2, 9, 2) #if GTK_CHECK_VERSION(2, 9, 2)
NotifyNotification *notify_notification_new_with_status_icon( NotifyNotification *notify_notification_new_with_status_icon (const char *summary,
const gchar *summary, const gchar *body, const char *body,
const gchar *icon, GtkStatusIcon *status_icon); const char *icon,
GtkStatusIcon *status_icon);
#endif #endif
gboolean notify_notification_update (NotifyNotification *notification, gboolean notify_notification_update (NotifyNotification *notification,
const gchar *summary, const char *summary,
const gchar *body, const char *body,
const gchar *icon); const char *icon);
void notify_notification_attach_to_widget (NotifyNotification *notification, void notify_notification_attach_to_widget (NotifyNotification *notification,
GtkWidget *attach); GtkWidget *attach);
@ -129,26 +121,26 @@ void notify_notification_set_icon_from_pixbuf(NotifyNotification *notification,
GdkPixbuf *icon); GdkPixbuf *icon);
void notify_notification_set_hint_int32 (NotifyNotification *notification, void notify_notification_set_hint_int32 (NotifyNotification *notification,
const gchar *key, const char *key,
gint value); gint value);
void notify_notification_set_hint_uint32 (NotifyNotification *notification, void notify_notification_set_hint_uint32 (NotifyNotification *notification,
const gchar *key, const char *key,
guint value); guint value);
void notify_notification_set_hint_double (NotifyNotification *notification, void notify_notification_set_hint_double (NotifyNotification *notification,
const gchar *key, const char *key,
gdouble value); gdouble value);
void notify_notification_set_hint_string (NotifyNotification *notification, void notify_notification_set_hint_string (NotifyNotification *notification,
const gchar *key, const char *key,
const gchar *value); const char *value);
void notify_notification_set_hint_byte (NotifyNotification *notification, void notify_notification_set_hint_byte (NotifyNotification *notification,
const gchar *key, const char *key,
guchar value); guchar value);
void notify_notification_set_hint_byte_array (NotifyNotification *notification, void notify_notification_set_hint_byte_array (NotifyNotification *notification,
const gchar *key, const char *key,
const guchar *value, const guchar *value,
gsize len); gsize len);
@ -168,5 +160,4 @@ gboolean notify_notification_close(NotifyNotification *notification,
gint notify_notification_get_closed_reason (const NotifyNotification *notification); gint notify_notification_get_closed_reason (const NotifyNotification *notification);
G_END_DECLS G_END_DECLS
#endif /* NOTIFY_NOTIFICATION_H */ #endif /* NOTIFY_NOTIFICATION_H */

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* *
* @file libnotify/notify.c Notifications library * @file libnotify/notify.c Notifications library
* *
@ -20,6 +20,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
@ -29,7 +30,7 @@
#include <libnotify/notify-marshal.h> #include <libnotify/notify-marshal.h>
static gboolean _initted = FALSE; static gboolean _initted = FALSE;
static gchar *_app_name = NULL; static char *_app_name = NULL;
static DBusGProxy *_proxy = NULL; static DBusGProxy *_proxy = NULL;
static DBusGConnection *_dbus_gconn = NULL; static DBusGConnection *_dbus_gconn = NULL;
static GList *_active_notifications = NULL; static GList *_active_notifications = NULL;
@ -60,8 +61,7 @@ notify_init(const char *app_name)
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (error != NULL) if (error != NULL) {
{
g_message ("Unable to get session bus: %s", error->message); g_message ("Unable to get session bus: %s", error->message);
g_error_free (error); g_error_free (error);
return FALSE; return FALSE;
@ -83,11 +83,15 @@ notify_init(const char *app_name)
G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_STRING, G_TYPE_INVALID); G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_add_signal(_proxy, "NotificationClosed", dbus_g_proxy_add_signal (_proxy,
G_TYPE_UINT, G_TYPE_UINT, "NotificationClosed",
G_TYPE_UINT,
G_TYPE_UINT,
G_TYPE_INVALID); G_TYPE_INVALID);
dbus_g_proxy_add_signal(_proxy, "ActionInvoked", dbus_g_proxy_add_signal (_proxy,
G_TYPE_UINT, G_TYPE_STRING, "ActionInvoked",
G_TYPE_UINT,
G_TYPE_STRING,
G_TYPE_INVALID); G_TYPE_INVALID);
_initted = TRUE; _initted = TRUE;
@ -102,7 +106,7 @@ notify_init(const char *app_name)
* *
* Returns: The registered application name, passed to notify_init(). * Returns: The registered application name, passed to notify_init().
*/ */
const gchar * const char *
notify_get_app_name (void) notify_get_app_name (void)
{ {
return _app_name; return _app_name;
@ -124,19 +128,16 @@ notify_uninit(void)
if (!_initted) if (!_initted)
return; return;
if (_app_name != NULL) if (_app_name != NULL) {
{
g_free (_app_name); g_free (_app_name);
_app_name = NULL; _app_name = NULL;
} }
for (l = _active_notifications; l != NULL; l = l->next) for (l = _active_notifications; l != NULL; l = l->next) {
{
NotifyNotification *n = NOTIFY_NOTIFICATION (l->data); NotifyNotification *n = NOTIFY_NOTIFICATION (l->data);
if (_notify_notification_get_timeout (n) == 0 || if (_notify_notification_get_timeout (n) == 0 ||
_notify_notification_has_nondefault_actions(n)) _notify_notification_has_nondefault_actions (n)) {
{
notify_notification_close (n, NULL); notify_notification_close (n, NULL);
} }
} }
@ -182,23 +183,26 @@ GList *
notify_get_server_caps (void) notify_get_server_caps (void)
{ {
GError *error = NULL; GError *error = NULL;
char **caps = NULL, **cap; char **caps = NULL;
char **cap;
GList *result = NULL; GList *result = NULL;
DBusGProxy *proxy = _notify_get_g_proxy (); DBusGProxy *proxy = _notify_get_g_proxy ();
g_return_val_if_fail (proxy != NULL, NULL); g_return_val_if_fail (proxy != NULL, NULL);
if (!dbus_g_proxy_call(proxy, "GetCapabilities", &error, if (!dbus_g_proxy_call (proxy,
"GetCapabilities",
&error,
G_TYPE_INVALID, G_TYPE_INVALID,
G_TYPE_STRV, &caps, G_TYPE_INVALID)) G_TYPE_STRV,
{ &caps,
G_TYPE_INVALID)) {
g_message ("GetCapabilities call failed: %s", error->message); g_message ("GetCapabilities call failed: %s", error->message);
g_error_free (error); g_error_free (error);
return NULL; return NULL;
} }
for (cap = caps; *cap != NULL; cap++) for (cap = caps; *cap != NULL; cap++) {
{
result = g_list_append (result, g_strdup (*cap)); result = g_list_append (result, g_strdup (*cap));
} }
@ -230,19 +234,24 @@ notify_get_server_info(char **ret_name,
{ {
GError *error = NULL; GError *error = NULL;
DBusGProxy *proxy = _notify_get_g_proxy (); DBusGProxy *proxy = _notify_get_g_proxy ();
char *name, *vendor, *version, *spec_version; char *name;
char *vendor;
char *version;
char *spec_version;
g_return_val_if_fail (proxy != NULL, FALSE); g_return_val_if_fail (proxy != NULL, FALSE);
if (!dbus_g_proxy_call(proxy, "GetServerInformation", &error, if (!dbus_g_proxy_call (proxy,
"GetServerInformation",
&error,
G_TYPE_INVALID, G_TYPE_INVALID,
G_TYPE_STRING, &name, G_TYPE_STRING, &name,
G_TYPE_STRING, &vendor, G_TYPE_STRING, &vendor,
G_TYPE_STRING, &version, G_TYPE_STRING, &version,
G_TYPE_STRING, &spec_version, G_TYPE_STRING, &spec_version,
G_TYPE_INVALID)) G_TYPE_INVALID)) {
{ g_message ("GetServerInformation call failed: %s",
g_message("GetServerInformation call failed: %s", error->message); error->message);
return FALSE; return FALSE;
} }

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* *
* @file libnotify/notify.h Notifications library * @file libnotify/notify.h Notifications library
* *

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* *
* @file notify-send.c A tool for sending notifications. * @file notify-send.c A tool for sending notifications.
* *
@ -19,6 +19,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include <config.h> #include <config.h>
#include <libnotify/notify.h> #include <libnotify/notify.h>
@ -34,26 +35,24 @@
static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL; static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
static gboolean static gboolean
g_option_arg_urgency_cb(const gchar *option_name, g_option_arg_urgency_cb (const char *option_name,
const gchar *value, const char *value,
gpointer data, gpointer data,
GError **error) GError **error)
{ {
if (value != NULL) if (value != NULL) {
{
if (!strcasecmp (value, "low")) if (!strcasecmp (value, "low"))
urgency = NOTIFY_URGENCY_LOW; urgency = NOTIFY_URGENCY_LOW;
else if (!strcasecmp (value, "normal")) else if (!strcasecmp (value, "normal"))
urgency = NOTIFY_URGENCY_NORMAL; urgency = NOTIFY_URGENCY_NORMAL;
else if (!strcasecmp (value, "critical")) else if (!strcasecmp (value, "critical"))
urgency = NOTIFY_URGENCY_CRITICAL; urgency = NOTIFY_URGENCY_CRITICAL;
else else {
{ *error = g_error_new (G_OPTION_ERROR,
*error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, G_OPTION_ERROR_BAD_VALUE,
N_("Unknown urgency %s specified. " N_("Unknown urgency %s specified. "
"Known urgency levels: low, " "Known urgency levels: low, "
"normal, critical."), "normal, critical."), value);
value);
return FALSE; return FALSE;
} }
@ -64,50 +63,44 @@ g_option_arg_urgency_cb(const gchar *option_name,
static gboolean static gboolean
notify_notification_set_hint_variant (NotifyNotification *notification, notify_notification_set_hint_variant (NotifyNotification *notification,
const gchar *type, const char *type,
const gchar *key, const char *key,
const gchar *value, const char *value,
GError **error) GError **error)
{ {
static gboolean conv_error = FALSE; static gboolean conv_error = FALSE;
if (!strcasecmp(type, "string")) if (!strcasecmp (type, "string")) {
{ notify_notification_set_hint_string (notification,
notify_notification_set_hint_string(notification, key, value); key,
} value);
else if (!strcasecmp(type, "int")) } else if (!strcasecmp (type, "int")) {
{
if (!g_ascii_isdigit (*value)) if (!g_ascii_isdigit (*value))
conv_error = TRUE; conv_error = TRUE;
else else {
{
gint h_int = (gint) g_ascii_strtoull (value, NULL, 10); gint h_int = (gint) g_ascii_strtoull (value, NULL, 10);
notify_notification_set_hint_int32(notification, key, h_int); notify_notification_set_hint_int32 (notification,
key,
h_int);
} }
} } else if (!strcasecmp (type, "double")) {
else if (!strcasecmp(type, "double"))
{
if (!g_ascii_isdigit (*value)) if (!g_ascii_isdigit (*value))
conv_error = TRUE; conv_error = TRUE;
else else {
{
gdouble h_double = g_strtod (value, NULL); gdouble h_double = g_strtod (value, NULL);
notify_notification_set_hint_double(notification, key, h_double); notify_notification_set_hint_double (notification,
key, h_double);
} }
} } else if (!strcasecmp (type, "byte")) {
else if (!strcasecmp(type, "byte"))
{
gint h_byte = (gint) g_ascii_strtoull (value, NULL, 10); gint h_byte = (gint) g_ascii_strtoull (value, NULL, 10);
if (h_byte < 0 || h_byte > 0xFF) if (h_byte < 0 || h_byte > 0xFF)
conv_error = TRUE; conv_error = TRUE;
else else {
{ notify_notification_set_hint_byte (notification,
notify_notification_set_hint_byte(notification, key, key,
(guchar) h_byte); (guchar) h_byte);
} }
} } else {
else
{
*error = g_error_new (G_OPTION_ERROR, *error = g_error_new (G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE, G_OPTION_ERROR_BAD_VALUE,
N_("Invalid hint type \"%s\". Valid types " N_("Invalid hint type \"%s\". Valid types "
@ -116,13 +109,12 @@ notify_notification_set_hint_variant(NotifyNotification *notification,
return FALSE; return FALSE;
} }
if (conv_error) if (conv_error) {
{
*error = g_error_new (G_OPTION_ERROR, *error = g_error_new (G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE, G_OPTION_ERROR_BAD_VALUE,
N_("Value \"%s\" of hint \"%s\" could not be " N_("Value \"%s\" of hint \"%s\" could not be "
"parsed as type \"%s\"."), "parsed as type \"%s\"."), value, key,
value, key, type); type);
return FALSE; return FALSE;
} }
@ -132,13 +124,13 @@ notify_notification_set_hint_variant(NotifyNotification *notification,
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
static const gchar *summary = NULL; static const char *summary = NULL;
static const gchar *body = ""; static const char *body = "";
static const gchar *type = NULL; static const char *type = NULL;
static gchar *icon_str = NULL; static char *icon_str = NULL;
static gchar *icons = NULL; static char *icons = NULL;
static gchar **n_text = NULL; static char **n_text = NULL;
static gchar **hints = NULL; static char **hints = NULL;
static gboolean do_version = FALSE; static gboolean do_version = FALSE;
static gboolean hint_error = FALSE; static gboolean hint_error = FALSE;
static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT; static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT;
@ -147,13 +139,14 @@ main(int argc, char *argv[])
GError *error = NULL; GError *error = NULL;
gboolean retval; gboolean retval;
static const GOptionEntry entries[] = static const GOptionEntry entries[] = {
{ {"urgency", 'u', 0, G_OPTION_ARG_CALLBACK,
{ "urgency", 'u', 0, G_OPTION_ARG_CALLBACK, g_option_arg_urgency_cb, g_option_arg_urgency_cb,
N_("Specifies the urgency level (low, normal, critical)."), N_("Specifies the urgency level (low, normal, critical)."),
N_("LEVEL")}, N_("LEVEL")},
{"expire-time", 't', 0, G_OPTION_ARG_INT, &expire_timeout, {"expire-time", 't', 0, G_OPTION_ARG_INT, &expire_timeout,
N_("Specifies the timeout in milliseconds at which to expire the " N_
("Specifies the timeout in milliseconds at which to expire the "
"notification."), N_("TIME")}, "notification."), N_("TIME")},
{"icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons, {"icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons,
N_("Specifies an icon filename or stock icon to display."), N_("Specifies an icon filename or stock icon to display."),
@ -162,12 +155,14 @@ main(int argc, char *argv[])
N_("Specifies the notification category."), N_("Specifies the notification category."),
N_("TYPE[,TYPE...]")}, N_("TYPE[,TYPE...]")},
{"hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints, {"hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints,
N_("Specifies basic extra data to pass. Valid types are int, double, string and byte."), N_
("Specifies basic extra data to pass. Valid types are int, double, string and byte."),
N_("TYPE:NAME:VALUE")}, N_("TYPE:NAME:VALUE")},
{"version", 'v', 0, G_OPTION_ARG_NONE, &do_version, {"version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
N_("Version of the package."), N_("Version of the package."),
NULL}, NULL},
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &n_text, NULL, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
&n_text, NULL,
NULL}, NULL},
{NULL} {NULL}
}; };
@ -182,15 +177,13 @@ main(int argc, char *argv[])
retval = g_option_context_parse (opt_ctx, &argc, &argv, &error); retval = g_option_context_parse (opt_ctx, &argc, &argv, &error);
g_option_context_free (opt_ctx); g_option_context_free (opt_ctx);
if (!retval) if (!retval) {
{
fprintf (stderr, "%s\n", error->message); fprintf (stderr, "%s\n", error->message);
g_error_free (error); g_error_free (error);
exit (1); exit (1);
} }
if (do_version) if (do_version) {
{
g_printf ("%s %s\n", g_get_prgname (), VERSION); g_printf ("%s %s\n", g_get_prgname (), VERSION);
exit (0); exit (0);
} }
@ -198,25 +191,22 @@ main(int argc, char *argv[])
if (n_text != NULL && n_text[0] != NULL && *n_text[0] != '\0') if (n_text != NULL && n_text[0] != NULL && *n_text[0] != '\0')
summary = n_text[0]; summary = n_text[0];
if (summary == NULL) if (summary == NULL) {
{
fprintf (stderr, "%s\n", N_("No summary specified.")); fprintf (stderr, "%s\n", N_("No summary specified."));
exit (1); exit (1);
} }
if (n_text[1] != NULL) if (n_text[1] != NULL) {
{
body = n_text[1]; body = n_text[1];
if (n_text[2] != NULL) if (n_text[2] != NULL) {
{ fprintf (stderr, "%s\n",
fprintf(stderr, "%s\n", N_("Invalid number of options.")); N_("Invalid number of options."));
exit (1); exit (1);
} }
} }
if (icons != NULL) if (icons != NULL) {
{
char *c; char *c;
/* XXX */ /* XXX */
@ -235,31 +225,29 @@ main(int argc, char *argv[])
notify_notification_set_timeout (notify, expire_timeout); notify_notification_set_timeout (notify, expire_timeout);
// Set hints // Set hints
if (hints != NULL) if (hints != NULL) {
{
gint i = 0; gint i = 0;
gint l; gint l;
gchar *hint = NULL; char *hint = NULL;
gchar **tokens = NULL; char **tokens = NULL;
while ((hint = hints[i++])) while ((hint = hints[i++])) {
{
tokens = g_strsplit (hint, ":", -1); tokens = g_strsplit (hint, ":", -1);
l = g_strv_length (tokens); l = g_strv_length (tokens);
if (l != 3) if (l != 3) {
{
fprintf (stderr, "%s\n", fprintf (stderr, "%s\n",
N_("Invalid hint syntax specified. " N_("Invalid hint syntax specified. "
"Use TYPE:NAME:VALUE.")); "Use TYPE:NAME:VALUE."));
hint_error = TRUE; hint_error = TRUE;
} } else {
else retval = notify_notification_set_hint_variant (notify,
{ tokens[0],
retval = notify_notification_set_hint_variant(notify, tokens[0], tokens[1], tokens[2], &error); tokens[1],
tokens[2],
&error);
if (!retval) if (!retval) {
{
fprintf (stderr, "%s\n", error->message); fprintf (stderr, "%s\n", error->message);
g_error_free (error); g_error_free (error);
hint_error = TRUE; hint_error = TRUE;