Fixed the coding style.

This commit is contained in:
Christian Hammond 2006-01-20 05:55:30 +00:00
parent 3b0e8d2986
commit fd53ececa2
7 changed files with 740 additions and 778 deletions

View File

@ -1,3 +1,13 @@
Thu Jan 19 21:55:08 PST 2006 Christian Hammond <chipx86@chipx86.com>
* libnotify/dbus-compat.h:
* libnotify/notify.c:
* libnotify/notifycommon.h:
* libnotify/notify.h:
* libnotify/notifynotification.c:
* libnotify/notifynotification.h:
- Fixed the coding style.
Thu Jan 19 01:34:57 PST 2006 Christian Hammond <chipx86@chipx86.com> Thu Jan 19 01:34:57 PST 2006 Christian Hammond <chipx86@chipx86.com>
* tools/notify-send.c: * tools/notify-send.c:

View File

@ -1,3 +1,4 @@
/** /**
* @file libnotify/dbus-compat.h Private D-BUS Compatibility API * @file libnotify/dbus-compat.h Private D-BUS Compatibility API
* *

View File

@ -1,9 +1,8 @@
/* -*- mode: c-mode; tab-width: 4; indent-tabs-mode: t; -*- */
/** /**
* @file libnotify/notify.c Notifications library * @file libnotify/notify.c Notifications library
* *
* @Copyright (C) 2004 Christian Hammond <chipx86@chipx86.com> * @Copyright (C) 2004-2006 Christian Hammond <chipx86@chipx86.com>
* @Copyright (C) 2004 Mike Hearn <mike@navi.cx> * @Copyright (C) 2004-2006 Mike Hearn <mike@navi.cx>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public

View File

@ -1,8 +1,7 @@
/* -*- mode: c-mode; tab-width: 4; indent-tabs-mode: t; -*- */
/** /**
* @file libnotify/notify.h Notifications library * @file libnotify/notify.h Notifications library
* *
* @Copyright (C) 2004 Christian Hammond * @Copyright (C) 2004-2006 Christian Hammond
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -19,7 +18,6 @@
* 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.
*/ */
#ifndef _LIBNOTIFY_NOTIFY_H_ #ifndef _LIBNOTIFY_NOTIFY_H_
#define _LIBNOTIFY_NOTIFY_H_ #define _LIBNOTIFY_NOTIFY_H_
@ -58,6 +56,11 @@ void notify_uninit(void);
*/ */
gboolean notify_is_initted(void); gboolean notify_is_initted(void);
/**
* Returns the name of the application set when notify_init() was called.
*
* @return The name of the application.
*/
const gchar *notify_get_app_name(void); const gchar *notify_get_app_name(void);
/** /**
@ -79,8 +82,10 @@ GList *notify_get_server_caps(void);
* *
* @return TRUE if the call succeeded, or FALSE if there were errors. * @return TRUE if the call succeeded, or FALSE if there were errors.
*/ */
gboolean notify_get_server_info(char **ret_name, char **ret_vendor, gboolean notify_get_server_info(char **ret_name,
char **ret_version, char **ret_spec_version); char **ret_vendor,
char **ret_version,
char **ret_spec_version);
/*@}*/ /*@}*/

View File

@ -1,18 +1,22 @@
/* /**
* This program is free software; you can redistribute it and/or * @file libnotify/notifynotification.c Notification object
*
* @Copyright (C) 2006 Christian Hammond
* @Copyright (C) 2006 John Palmieri
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * version 2.1 of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with main.c; if not, write to: * License along with this library; if not, write to the
* The Free Software Foundation, Inc., * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include "config.h" #include "config.h"
@ -26,28 +30,26 @@
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, static void _close_signal_handler(DBusGProxy *proxy, guint32 id,
guint32 id,
NotifyNotification *notification); NotifyNotification *notification);
static void _action_signal_handler (DBusGProxy *proxy, static void _action_signal_handler(DBusGProxy *proxy, guint32 id,
guint32 id,
gchar *action, gchar *action,
NotifyNotification *notification); NotifyNotification *notification);
struct NotifyNotificationPrivate struct _NotifyNotificationPrivate
{ {
guint32 id; guint32 id;
gchar *summary; gchar *summary;
gchar *message; gchar *message;
/*NULL to use icon data /* NULL to use icon data anything else to have server lookup icon */
anything else to have server lookup icon */
gchar *icon_name; gchar *icon_name;
/*-1 = use server default /*
0 = never timeout * -1 = use server default
>0 = Number of milliseconds before we timeout * 0 = never timeout
* > 0 = Number of milliseconds before we timeout
*/ */
gint timeout; gint timeout;
@ -71,11 +73,13 @@ typedef enum
{ {
SIGNAL_TYPE_CLOSED, SIGNAL_TYPE_CLOSED,
LAST_SIGNAL LAST_SIGNAL
} NotifyNotificationSignalType; } NotifyNotificationSignalType;
typedef struct typedef struct
{ {
NotifyNotification *object; NotifyNotification *object;
} NotifyNotificationSignal; } NotifyNotificationSignal;
static guint notify_notification_signals[LAST_SIGNAL] = { 0 }; static guint notify_notification_signals[LAST_SIGNAL] = { 0 };
@ -122,16 +126,12 @@ notify_notification_class_init (NotifyNotificationClass * klass)
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_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
G_TYPE_NONE,
0);
dbus_g_object_register_marshaller(notify_marshal_VOID__UINT_STRING, dbus_g_object_register_marshaller(notify_marshal_VOID__UINT_STRING,
G_TYPE_NONE, G_TYPE_NONE,
G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
G_TYPE_INVALID);
} }
static void static void
@ -147,23 +147,17 @@ notify_notification_init (NotifyNotification * obj)
obj->priv = g_new0(NotifyNotificationPrivate, 1); obj->priv = g_new0(NotifyNotificationPrivate, 1);
obj->priv->id = 0; obj->priv->id = 0;
obj->priv->summary = NULL; obj->priv->summary = NULL;
obj->priv->message = NULL; obj->priv->message = NULL;
obj->priv->icon_name = NULL; obj->priv->icon_name = NULL;
obj->priv->timeout = NOTIFY_TIMEOUT_DEFAULT; obj->priv->timeout = NOTIFY_TIMEOUT_DEFAULT;
obj->priv->actions = NULL; obj->priv->actions = NULL;
obj->priv->hints = g_hash_table_new_full (g_str_hash, obj->priv->hints = g_hash_table_new_full(g_str_hash, g_str_equal,
g_str_equal,
g_free, g_free,
(GDestroyNotify) _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_free, NULL);
g_str_equal,
g_free,
NULL);
obj->priv->attached_widget = NULL; obj->priv->attached_widget = NULL;
obj->priv->user_data = NULL; obj->priv->user_data = NULL;
@ -175,23 +169,18 @@ notify_notification_init (NotifyNotification * obj)
obj->priv->widget_old_y = 0; obj->priv->widget_old_y = 0;
obj->priv->proxy = NULL; obj->priv->proxy = NULL;
} }
static void static void
notify_notification_finalize(GObject *object) notify_notification_finalize(GObject *object)
{ {
NotifyNotification *obj; NotifyNotification *obj = NOTIFY_NOTIFICATION(object);
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv = obj->priv;
obj = NOTIFY_NOTIFICATION (object);
priv = obj->priv;
g_free(priv->summary); g_free(priv->summary);
g_free(priv->message); g_free(priv->message);
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);
@ -205,17 +194,17 @@ notify_notification_finalize (GObject * object)
g_hash_table_destroy(priv->hints); g_hash_table_destroy(priv->hints);
if (priv->attached_widget != NULL) if (priv->attached_widget != NULL)
gtk_widget_unref (priv->attached_widget); g_object_unref(G_OBJECT(priv->attached_widget));
if (priv->user_data_free_func != NULL) if (priv->user_data_free_func != NULL)
priv->user_data_free_func(priv->user_data); priv->user_data_free_func(priv->user_data);
dbus_g_proxy_disconnect_signal(priv->proxy, "NotificationClosed", dbus_g_proxy_disconnect_signal(priv->proxy, "NotificationClosed",
(GCallback) _close_signal_handler, G_CALLBACK(_close_signal_handler),
object); object);
dbus_g_proxy_disconnect_signal(priv->proxy, "ActionInvoked", dbus_g_proxy_disconnect_signal(priv->proxy, "ActionInvoked",
(GCallback) _action_signal_handler, G_CALLBACK(_action_signal_handler),
object); object);
g_free(obj->priv); g_free(obj->priv);
@ -225,25 +214,21 @@ notify_notification_finalize (GObject * object)
static gboolean static gboolean
_notify_notification_update_applet_hints(NotifyNotification *n) _notify_notification_update_applet_hints(NotifyNotification *n)
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv = n->priv;
gboolean update_pending; gboolean update_pending = FALSE;
update_pending = FALSE;
priv = n->priv;
if (priv->attached_widget != NULL) if (priv->attached_widget != NULL)
{ {
gint x, y, h, w; gint x, y, h, w;
GtkWidget *widget; GtkWidget *widget = priv->attached_widget;
GtkRequisition requisition; GtkRequisition requisition;
widget = priv->attached_widget;
gtk_widget_size_request(widget, &requisition); gtk_widget_size_request(widget, &requisition);
w = requisition.width; w = requisition.width;
h = requisition.height; h = requisition.height;
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;
@ -284,15 +269,13 @@ _notify_notification_update_applet_hints (NotifyNotification * n)
static gboolean static gboolean
_idle_check_updates(void *user_data) _idle_check_updates(void *user_data)
{ {
NotifyNotification *n; NotifyNotification *n = NOTIFY_NOTIFICATION(user_data);
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv = n->priv;
n = NOTIFY_NOTIFICATION (user_data);
priv = n->priv;
if (priv->is_visible) if (priv->is_visible)
{ {
priv->updates_pending = _notify_notification_update_applet_hints(n); priv->updates_pending = _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 */
@ -304,9 +287,6 @@ _idle_check_updates (void *user_data)
priv->updates_pending = FALSE; priv->updates_pending = FALSE;
} }
n = NOTIFY_NOTIFICATION (user_data);
priv = n->priv;
return TRUE; return TRUE;
} }
#endif #endif
@ -315,14 +295,14 @@ GdkFilterReturn
_catch(GdkXEvent *xevent, GdkEvent *event, gpointer data) _catch(GdkXEvent *xevent, GdkEvent *event, gpointer data)
{ {
static int i = 1; static int i = 1;
printf("here, %i\n", i); printf("here, %i\n", i);
i++; i++;
return GDK_FILTER_CONTINUE; return GDK_FILTER_CONTINUE;
} }
NotifyNotification * NotifyNotification *
notify_notification_new (const gchar * summary, notify_notification_new(const gchar *summary, const gchar *message,
const gchar * message,
const gchar *icon, GtkWidget *attach) const gchar *icon, GtkWidget *attach)
{ {
NotifyNotification *obj; NotifyNotification *obj;
@ -338,7 +318,7 @@ notify_notification_new (const gchar * summary,
if (attach != NULL) if (attach != NULL)
{ {
gtk_widget_ref (attach); g_object_ref(G_OBJECT(attach));
obj->priv->attached_widget = attach; obj->priv->attached_widget = attach;
} }
@ -350,9 +330,8 @@ notify_notification_update (NotifyNotification * notification,
const gchar *summary, const gchar *summary,
const gchar *message, const gchar *icon) const gchar *message, const gchar *icon)
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv = notification->priv;
priv = notification->priv;
g_free(priv->summary); g_free(priv->summary);
g_free(priv->message); g_free(priv->message);
g_free(priv->icon_name); g_free(priv->icon_name);
@ -371,31 +350,25 @@ void
notify_notification_attach_to_widget(NotifyNotification *notification, notify_notification_attach_to_widget(NotifyNotification *notification,
GtkWidget *attach) GtkWidget *attach)
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv = notification->priv;
priv = notification->priv;
if (priv->attached_widget != NULL) if (priv->attached_widget != NULL)
gtk_widget_unref (priv->attached_widget); g_object_unref(priv->attached_widget);
if (attach != NULL)
priv->attached_widget = gtk_widget_ref (attach);
else
priv->attached_widget = NULL;
priv->attached_widget = (attach != NULL ? g_object_ref(attach) : NULL);
} }
gboolean gboolean
notify_notification_set_user_data(NotifyNotification *notification, notify_notification_set_user_data(NotifyNotification *notification,
void *user_data, GFreeFunc free_func) void *user_data, GFreeFunc free_func)
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv = notification->priv;
priv = notification->priv;
if (priv->user_data) if (priv->user_data)
{
if (priv->user_data_free_func) if (priv->user_data_free_func)
priv->user_data_free_func(priv->user_data); priv->user_data_free_func(priv->user_data);
}
priv->user_data = user_data; priv->user_data = user_data;
priv->user_data_free_func = free_func; priv->user_data_free_func = free_func;
@ -407,32 +380,28 @@ notify_notification_set_user_data (NotifyNotification * notification,
gpointer gpointer
notify_notification_get_user_data(NotifyNotification *notification) notify_notification_get_user_data(NotifyNotification *notification)
{ {
NotifyNotificationPrivate *priv; return notification->priv->user_data;
priv = notification->priv;
return priv->user_data;
} }
static void static void
_close_signal_handler (DBusGProxy *proxy, _close_signal_handler(DBusGProxy *proxy, guint32 id,
guint32 id,
NotifyNotification *notification) NotifyNotification *notification)
{ {
printf ("Got the NotificationClosed signal (id = %i, notification->id = %i)\n" printf("Got the NotificationClosed signal (id = %i, "
, id, notification->priv->id); "notification->id = %i)\n",
id, notification->priv->id);
if (id == notification->priv->id) if (id == notification->priv->id)
{
g_signal_emit(notification, g_signal_emit(notification,
notify_notification_signals[SIGNAL_TYPE_CLOSED], notify_notification_signals[SIGNAL_TYPE_CLOSED], 0);
0); }
} }
static void static void
_action_signal_handler(DBusGProxy *proxy, _action_signal_handler(DBusGProxy *proxy,
guint32 id, guint32 id,
gchar *action, gchar *action, NotifyNotification *notification)
NotifyNotification *notification)
{ {
g_assert(NOTIFY_IS_NOTIFICATION(notification)); g_assert(NOTIFY_IS_NOTIFICATION(notification));
@ -440,61 +409,47 @@ _action_signal_handler (DBusGProxy *proxy,
{ {
NotifyActionCallback callback; NotifyActionCallback callback;
callback = (NotifyActionCallback) g_hash_table_lookup (notification->priv->action_map, callback = (NotifyActionCallback)g_hash_table_lookup(
action); notification->priv->action_map, action);
if (callback == NULL) if (callback == NULL)
g_warning("Recieved unknown action %s", action); g_warning("Recieved unknown action %s", action);
else else
callback(notification, action); callback(notification, action);
} }
} }
static gchar ** static gchar **
_gslist_to_string_array(GSList *list) _gslist_to_string_array(GSList *list)
{ {
GSList *element; GSList *l;
GArray *a; GArray *a;
gsize len;
gchar **result;
len = g_slist_length (list); a = g_array_sized_new(TRUE, FALSE, sizeof(gchar *),
g_slist_length(list));
a = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), len); for (l = list; l != NULL; l = l->next)
g_array_append_val(a, l->data);
element = list; return (gchar **)g_array_free(a, FALSE);
while (element != NULL)
{
g_array_append_val (a, element->data);
element = g_slist_next (element);
}
result = (gchar **)g_array_free (a, FALSE);
return result;
} }
static gboolean static gboolean
_notify_notification_show_internal(NotifyNotification *notification, _notify_notification_show_internal(NotifyNotification *notification,
GError **error, GError **error, gboolean ignore_reply)
gboolean ignore_reply)
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv = notification->priv;
GError *tmp_error; GError *tmp_error = NULL;
gchar **action_array; gchar **action_array;
g_return_val_if_fail(error == NULL || *error == NULL, FALSE); g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
priv = notification->priv;
tmp_error = NULL;
if (priv->proxy == NULL) if (priv->proxy == NULL)
{ {
DBusGConnection *bus; DBusGConnection *bus;
bus = dbus_g_bus_get(DBUS_BUS_SESSION, &tmp_error); bus = dbus_g_bus_get(DBUS_BUS_SESSION, &tmp_error);
if (tmp_error != NULL) if (tmp_error != NULL)
{ {
g_propagate_error(error, tmp_error); g_propagate_error(error, tmp_error);
@ -509,54 +464,59 @@ _notify_notification_show_internal (NotifyNotification *notification,
dbus_g_proxy_add_signal(priv->proxy, "NotificationClosed", dbus_g_proxy_add_signal(priv->proxy, "NotificationClosed",
G_TYPE_UINT, G_TYPE_INVALID); G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(priv->proxy, "NotificationClosed", dbus_g_proxy_connect_signal(priv->proxy, "NotificationClosed",
(GCallback) _close_signal_handler, G_CALLBACK(_close_signal_handler),
notification, NULL); notification, NULL);
dbus_g_proxy_add_signal(priv->proxy, "ActionInvoked", dbus_g_proxy_add_signal(priv->proxy, "ActionInvoked",
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID); G_TYPE_UINT, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal(priv->proxy, "ActionInvoked", dbus_g_proxy_connect_signal(priv->proxy, "ActionInvoked",
(GCallback) _action_signal_handler, G_CALLBACK(_action_signal_handler),
notification, NULL); notification, NULL);
dbus_g_connection_unref(bus); dbus_g_connection_unref(bus);
} }
/*if attached to a widget modify x and y in hints */ /* If attached to a widget, modify x and y in hints */
_notify_notification_update_applet_hints(notification); _notify_notification_update_applet_hints(notification);
action_array = _gslist_to_string_array(priv->actions); action_array = _gslist_to_string_array(priv->actions);
/* TODO: make this nonblocking */ /* TODO: make this nonblocking */
if (!ignore_reply) if (!ignore_reply)
{
dbus_g_proxy_call(priv->proxy, "Notify", &tmp_error, dbus_g_proxy_call(priv->proxy, "Notify", &tmp_error,
G_TYPE_STRING, notify_get_app_name(), G_TYPE_STRING, notify_get_app_name(),
G_TYPE_STRING, G_TYPE_STRING,
(priv->icon_name != NULL) ? priv->icon_name : "", (priv->icon_name != NULL) ? priv->icon_name : "",
G_TYPE_UINT, priv->id, G_TYPE_STRING, priv->summary, G_TYPE_UINT, priv->id, G_TYPE_STRING,
G_TYPE_STRING, priv->message, priv->summary, G_TYPE_STRING, priv->message,
G_TYPE_STRV, G_TYPE_STRV, action_array,
action_array, dbus_g_type_get_map ("GHashTable", dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_VALUE), priv->hints,
G_TYPE_VALUE), G_TYPE_INT, priv->timeout, G_TYPE_INVALID,
priv->hints, G_TYPE_INT, priv->timeout, G_TYPE_INVALID,
G_TYPE_UINT, &priv->id, G_TYPE_INVALID); G_TYPE_UINT, &priv->id, G_TYPE_INVALID);
}
else else
{
dbus_g_proxy_call_no_reply(priv->proxy, "Notify", dbus_g_proxy_call_no_reply(priv->proxy, "Notify",
G_TYPE_STRING, notify_get_app_name(), G_TYPE_STRING, notify_get_app_name(),
G_TYPE_STRING, G_TYPE_STRING,
(priv->icon_name != NULL) ? priv->icon_name : "", (priv->icon_name !=
G_TYPE_UINT, priv->id, G_TYPE_STRING, priv->summary, NULL) ? priv->icon_name : "",
G_TYPE_STRING, priv->message, G_TYPE_UINT, priv->id, G_TYPE_STRING,
G_TYPE_STRV, priv->summary, G_TYPE_STRING,
action_array, dbus_g_type_get_map ("GHashTable", priv->message, G_TYPE_STRV,
action_array,
dbus_g_type_get_map("GHashTable",
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_VALUE), G_TYPE_VALUE),
priv->hints, G_TYPE_INT, priv->timeout, G_TYPE_INVALID); priv->hints, G_TYPE_INT, priv->timeout,
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)
@ -568,8 +528,6 @@ _notify_notification_show_internal (NotifyNotification *notification,
return TRUE; return TRUE;
} }
gboolean gboolean
notify_notification_show(NotifyNotification *notification, GError **error) notify_notification_show(NotifyNotification *notification, GError **error)
{ {
@ -577,11 +535,12 @@ notify_notification_show (NotifyNotification *notification, GError **error)
} }
gboolean gboolean
notify_notification_show_and_forget (NotifyNotification *notification, GError **error) notify_notification_show_and_forget(NotifyNotification *notification,
GError **error)
{ {
gboolean result; gboolean result =
_notify_notification_show_internal(notification, error, TRUE);
result = _notify_notification_show_internal (notification, error, TRUE);
g_object_unref(G_OBJECT(notification)); g_object_unref(G_OBJECT(notification));
return result; return result;
@ -613,15 +572,13 @@ notify_notification_set_urgency (NotifyNotification * notification,
static gboolean static gboolean
_gvalue_array_append_int(GValueArray *array, gint i) _gvalue_array_append_int(GValueArray *array, gint i)
{ {
GValue *value; GValue *value = g_new0(GValue, 1);
value = g_new0 (GValue, 1); if (value == NULL)
if (!value)
return FALSE; return FALSE;
g_value_init(value, G_TYPE_INT); g_value_init(value, G_TYPE_INT);
g_value_set_int(value, i); g_value_set_int(value, i);
g_value_array_append(array, value); g_value_array_append(array, value);
return TRUE; return TRUE;
@ -630,35 +587,32 @@ _gvalue_array_append_int (GValueArray * array, gint i)
static gboolean static gboolean
_gvalue_array_append_bool(GValueArray *array, gboolean b) _gvalue_array_append_bool(GValueArray *array, gboolean b)
{ {
GValue *value; GValue *value = g_new0(GValue, 1);
value = g_new0 (GValue, 1); if (value == NULL)
if (!value)
return FALSE; return FALSE;
g_value_init(value, G_TYPE_BOOLEAN); g_value_init(value, G_TYPE_BOOLEAN);
g_value_set_boolean(value, b); g_value_set_boolean(value, b);
g_value_array_append(array, value); g_value_array_append(array, value);
return TRUE; return TRUE;
} }
static gboolean static gboolean
_gvalue_array_append_byte_array (GValueArray * array, _gvalue_array_append_byte_array(GValueArray *array, guchar *bytes, gsize len)
guchar * bytes, gsize len)
{ {
GArray *byte_array; GArray *byte_array;
GValue *value; GValue *value;
byte_array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), len); byte_array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), len);
if (!byte_array)
if (byte_array == NULL)
return FALSE; return FALSE;
byte_array = g_array_append_vals(byte_array, bytes, len); byte_array = g_array_append_vals(byte_array, bytes, len);
value = g_new0 (GValue, 1); if ((value = g_new0(GValue, 1)) == NULL)
if (!value)
{ {
g_array_free(byte_array, TRUE); g_array_free(byte_array, TRUE);
return FALSE; return FALSE;
@ -666,17 +620,14 @@ _gvalue_array_append_byte_array (GValueArray * array,
g_value_init(value, dbus_g_type_get_collection("GArray", G_TYPE_UCHAR)); g_value_init(value, dbus_g_type_get_collection("GArray", G_TYPE_UCHAR));
g_value_set_boxed_take_ownership(value, byte_array); g_value_set_boxed_take_ownership(value, byte_array);
g_value_array_append(array, value); g_value_array_append(array, value);
return TRUE; return TRUE;
} }
gboolean gboolean
notify_notification_set_icon_data_from_pixbuf (NotifyNotification * notify_notification_set_icon_data_from_pixbuf(
notification, GdkPixbuf * icon) NotifyNotification *notification, GdkPixbuf *icon)
{ {
gint width; gint width;
gint height; gint height;
@ -686,8 +637,6 @@ notify_notification_set_icon_data_from_pixbuf (NotifyNotification *
gint n_channels; gint n_channels;
guchar *image; guchar *image;
gsize image_len; gsize image_len;
gchar *key_dup;
GValueArray *image_struct; GValueArray *image_struct;
GValue *value; GValue *value;
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
@ -700,15 +649,14 @@ notify_notification_set_icon_data_from_pixbuf (NotifyNotification *
n_channels = gdk_pixbuf_get_n_channels(icon); n_channels = gdk_pixbuf_get_n_channels(icon);
bits_per_sample = gdk_pixbuf_get_bits_per_sample(icon); bits_per_sample = gdk_pixbuf_get_bits_per_sample(icon);
alpha = gdk_pixbuf_get_has_alpha(icon); alpha = gdk_pixbuf_get_has_alpha(icon);
image_len = image_len = (height - 1) * rowstride + width *
(height - 1) * rowstride + ((n_channels * bits_per_sample + 7) / 8);
width * ((n_channels * bits_per_sample + 7) / 8);
image = gdk_pixbuf_get_pixels(icon); image = gdk_pixbuf_get_pixels(icon);
image_struct = g_value_array_new(8); image_struct = g_value_array_new(8);
if (!image_struct) if (image_struct == NULL)
goto fail; goto fail;
_gvalue_array_append_int(image_struct, width); _gvalue_array_append_int(image_struct, width);
@ -720,23 +668,21 @@ notify_notification_set_icon_data_from_pixbuf (NotifyNotification *
_gvalue_array_append_byte_array(image_struct, image, image_len); _gvalue_array_append_byte_array(image_struct, image, image_len);
value = g_new0(GValue, 1); value = g_new0(GValue, 1);
if (!value)
if (value == NULL)
goto fail; goto fail;
g_value_init(value, G_TYPE_VALUE_ARRAY); g_value_init(value, G_TYPE_VALUE_ARRAY);
g_value_set_boxed(value, image_struct); g_value_set_boxed(value, image_struct);
key_dup = g_strdup ("icon_data"); g_hash_table_insert(priv->hints, g_strdup("icon_data"), value);
if (!key_dup)
goto fail;
g_hash_table_insert (priv->hints, key_dup, value);
return TRUE; return TRUE;
fail: fail:
if (image_struct != NULL) if (image_struct != NULL)
g_value_array_free(image_struct); g_value_array_free(image_struct);
return FALSE; return FALSE;
} }
@ -746,7 +692,6 @@ notify_notification_set_hint_int32 (NotifyNotification * notification,
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
GValue *hint_value; GValue *hint_value;
gchar *key_dup;
priv = notification->priv; priv = notification->priv;
@ -754,9 +699,7 @@ 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);
key_dup = g_strdup (key); g_hash_table_insert(priv->hints, g_strdup(key), hint_value);
g_hash_table_insert (priv->hints, key_dup, hint_value);
/* TODO: return FALSE on OOM */ /* TODO: return FALSE on OOM */
return TRUE; return TRUE;
@ -768,7 +711,6 @@ notify_notification_set_hint_double (NotifyNotification * notification,
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
GValue *hint_value; GValue *hint_value;
gchar *key_dup;
priv = notification->priv; priv = notification->priv;
@ -776,9 +718,7 @@ 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);
key_dup = g_strdup (key); g_hash_table_insert(priv->hints, g_strdup(key), hint_value);
g_hash_table_insert (priv->hints, key_dup, hint_value);
/* TODO: return FALSE on OOM */ /* TODO: return FALSE on OOM */
return TRUE; return TRUE;
@ -790,7 +730,6 @@ notify_notification_set_hint_byte (NotifyNotification * notification,
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
GValue *hint_value; GValue *hint_value;
gchar *key_dup;
priv = notification->priv; priv = notification->priv;
@ -798,9 +737,7 @@ 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);
key_dup = g_strdup (key); g_hash_table_insert(priv->hints, g_strdup(key), hint_value);
g_hash_table_insert (priv->hints, key_dup, hint_value);
/* TODO: return FALSE on OOM */ /* TODO: return FALSE on OOM */
return TRUE; return TRUE;
@ -813,7 +750,6 @@ notify_notification_set_hint_byte_array (NotifyNotification * notification,
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
GValue *hint_value; GValue *hint_value;
gchar *key_dup;
GArray *byte_array; GArray *byte_array;
priv = notification->priv; priv = notification->priv;
@ -822,25 +758,22 @@ notify_notification_set_hint_byte_array (NotifyNotification * notification,
byte_array = g_array_append_vals(byte_array, value, len); byte_array = g_array_append_vals(byte_array, value, len);
hint_value = g_new0(GValue, 1); hint_value = g_new0(GValue, 1);
g_value_init (hint_value, g_value_init(hint_value, dbus_g_type_get_collection("GArray",
dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR)); G_TYPE_UCHAR));
g_value_set_boxed_take_ownership(hint_value, byte_array); g_value_set_boxed_take_ownership(hint_value, byte_array);
key_dup = g_strdup (key);
g_hash_table_insert (priv->hints, key_dup, hint_value); g_hash_table_insert(priv->hints, g_strdup(key), hint_value);
/* TODO: return FALSE on OOM */ /* TODO: return FALSE on OOM */
return TRUE; return TRUE;
} }
gboolean gboolean
notify_notification_set_hint_string(NotifyNotification *notification, notify_notification_set_hint_string(NotifyNotification *notification,
const gchar *key, const gchar *value) const gchar *key, const gchar *value)
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
GValue *hint_value; GValue *hint_value;
gchar *key_dup;
priv = notification->priv; priv = notification->priv;
@ -848,9 +781,7 @@ 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);
key_dup = g_strdup (key); g_hash_table_insert(priv->hints, g_strdup(key), hint_value);
g_hash_table_insert (priv->hints, key_dup, hint_value);
/* TODO: return FALSE on OOM */ /* TODO: return FALSE on OOM */
return TRUE; return TRUE;
@ -872,7 +803,8 @@ notify_notification_clear_hints (NotifyNotification *notification)
void void
notify_notification_clear_actions(NotifyNotification *notification) notify_notification_clear_actions(NotifyNotification *notification)
{ {
g_hash_table_foreach_remove (notification->priv->action_map, (GHRFunc) _remove_all, NULL); g_hash_table_foreach_remove(notification->priv->action_map,
(GHRFunc)_remove_all, NULL);
if (notification->priv->actions != NULL) if (notification->priv->actions != NULL)
{ {
@ -902,7 +834,8 @@ notify_notification_add_action (NotifyNotification *notification,
} }
gboolean gboolean
notify_notification_close (NotifyNotification * notification, GError ** error) notify_notification_close(NotifyNotification *notification,
GError **error)
{ {
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
GError *tmp_error; GError *tmp_error;
@ -915,9 +848,8 @@ notify_notification_close (NotifyNotification * notification, GError ** error)
if (priv->proxy == NULL) if (priv->proxy == NULL)
{ {
DBusGConnection *bus; DBusGConnection *bus = dbus_g_bus_get(DBUS_BUS_SESSION, &tmp_error);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &tmp_error);
if (tmp_error != NULL) if (tmp_error != NULL)
{ {
g_propagate_error(error, tmp_error); g_propagate_error(error, tmp_error);
@ -932,7 +864,8 @@ notify_notification_close (NotifyNotification * notification, GError ** error)
} }
dbus_g_proxy_call(priv->proxy, "CloseNotification", &tmp_error, dbus_g_proxy_call(priv->proxy, "CloseNotification", &tmp_error,
G_TYPE_UINT, priv->id, G_TYPE_INVALID, G_TYPE_INVALID); G_TYPE_UINT, priv->id, G_TYPE_INVALID,
G_TYPE_INVALID);
if (tmp_error != NULL) if (tmp_error != NULL)
{ {

View File

@ -1,23 +1,26 @@
/* /**
* This program is free software; you can redistribute it and/or * @file libnotify/notifynotification.h Notification object
*
* @Copyright (C) 2006 Christian Hammond
* @Copyright (C) 2006 John Palmieri
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * version 2.1 of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with main.c; if not, write to: * License along with this library; if not, write to the
* The Free Software Foundation, Inc., * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#ifndef _NOTIFY_NOTIFICATION_H_
#ifndef NOTIFY_NOTIFICATION_H #define _NOTIFY_NOTIFICATION_H_
#define NOTIFY_NOTIFICATION_H
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
@ -28,28 +31,42 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define NOTIFY_TYPE_NOTIFICATION (notify_notification_get_type ()) #define NOTIFY_TYPE_NOTIFICATION (notify_notification_get_type ())
#define NOTIFY_NOTIFICATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NOTIFY_TYPE_NOTIFICATION, NotifyNotification)) #define NOTIFY_NOTIFICATION(o) \
#define NOTIFY_NOTIFICATION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NOTIFY_TYPE_NOTIFICATION, NotifyNotificationClass)) (G_TYPE_CHECK_INSTANCE_CAST ((o), NOTIFY_TYPE_NOTIFICATION, \
#define NOTIFY_IS_NOTIFICATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NOTIFY_TYPE_NOTIFICATION)) NotifyNotification))
#define NOTIFY_IS_NOTIFICATION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NOTIFY_TYPE_NOTIFICATION)) #define NOTIFY_NOTIFICATION_CLASS(k) \
#define NOTIFY_NOTIFICATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NOTIFY_TYPE_NOTIFICATION, NotifyNotificationClass)) (G_TYPE_CHECK_CLASS_CAST((k), NOTIFY_TYPE_NOTIFICATION, \
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 NotifyNotificationPrivate NotifyNotificationPrivate; typedef struct _NotifyNotification NotifyNotification;
typedef struct _NotifyNotificationClass NotifyNotificationClass;
typedef struct _NotifyNotificationPrivate NotifyNotificationPrivate;
typedef struct { struct _NotifyNotification
{
GObject parent; GObject parent;
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
} NotifyNotification; };
typedef struct { struct _NotifyNotificationClass
{
GObjectClass parent_class; GObjectClass parent_class;
/* Add Signal Functions Here */
void (*closed) (void); /* Signals */
} NotifyNotificationClass; void (*closed)(NotifyNotification *notification);
};
typedef void (*NotifyActionCallback)(NotifyNotification *, gchar *); typedef void (*NotifyActionCallback)(NotifyNotification *, gchar *);
GType notify_notification_get_type(); GType notify_notification_get_type();
NotifyNotification *notify_notification_new(const gchar *summary, NotifyNotification *notify_notification_new(const gchar *summary,
const gchar *message, const gchar *message,
const gchar *icon, const gchar *icon,
@ -84,13 +101,11 @@ gboolean notify_notification_set_category (NotifyNotification *notification,
gboolean notify_notification_set_urgency(NotifyNotification *notification, gboolean notify_notification_set_urgency(NotifyNotification *notification,
NotifyUrgency l); NotifyUrgency l);
gboolean notify_notification_set_icon_data_from_pixbuf (NotifyNotification *notification, gboolean notify_notification_set_icon_data_from_pixbuf(
GdkPixbuf *icon); NotifyNotification *notification, GdkPixbuf *icon);
gboolean notify_notification_set_hint_int32(NotifyNotification *notification, gboolean notify_notification_set_hint_int32(NotifyNotification *notification,
const gchar *key, const gchar *key, gint value);
gint value);
gboolean notify_notification_set_hint_double(NotifyNotification *notification, gboolean notify_notification_set_hint_double(NotifyNotification *notification,
const gchar *key, const gchar *key,
@ -105,10 +120,8 @@ gboolean notify_notification_set_hint_byte (NotifyNotification *notification,
guchar value); guchar value);
gboolean notify_notification_set_hint_byte_array( gboolean notify_notification_set_hint_byte_array(
NotifyNotification *notification, NotifyNotification *notification, const gchar *key,
const gchar *key, const guchar *value, gsize len);
const guchar *value,
gsize len);
void notify_notification_clear_hints(NotifyNotification *notification); void notify_notification_clear_hints(NotifyNotification *notification);
@ -123,4 +136,5 @@ gboolean notify_notification_close (NotifyNotification *notification,
NotifyNotification *notify_notification_ref(NotifyNotification *notification); NotifyNotification *notify_notification_ref(NotifyNotification *notification);
void notify_notification_unref(NotifyNotification *notification); void notify_notification_unref(NotifyNotification *notification);
#endif /* NOTIFY_NOTIFICATION_H */ #endif /* NOTIFY_NOTIFICATION_H */