Various cleanups

This commit is contained in:
William Jon McCann 2010-06-24 02:07:09 -04:00
parent d6476d362b
commit dedef26ef9
2 changed files with 97 additions and 60 deletions

View File

@ -1,9 +1,8 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* *
* @file libnotify/notification.c Notification object * Copyright (C) 2006 Christian Hammond
* * Copyright (C) 2006 John Palmieri
* @Copyright (C) 2006 Christian Hammond * Copyright (C) 2010 Red Hat, Inc.
* @Copyright (C) 2006 John Palmieri
* *
* 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
@ -20,16 +19,18 @@
* 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 <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include <libnotify/notify.h>
#include <libnotify/internal.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include "notify.h"
#include "internal.h"
#define CHECK_DBUS_VERSION(major, minor) \ #define CHECK_DBUS_VERSION(major, minor) \
(DBUS_MAJOR_VER > (major) || \ (DBUS_MAJOR_VER > (major) || \
(DBUS_MAJOR_VER == (major) && DBUS_MINOR_VER >= (minor))) (DBUS_MAJOR_VER == (major) && DBUS_MINOR_VER >= (minor)))
@ -162,10 +163,15 @@ 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), NULL, NULL, G_STRUCT_OFFSET (NotifyNotificationClass, closed),
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); NULL,
NULL,
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,
g_param_spec_int ("id", "ID", g_param_spec_int ("id", "ID",
"The notification ID", "The notification ID",
0, 0,
@ -177,7 +183,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| 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", g_param_spec_string ("summary",
"Summary", "Summary",
"The summary text", "The summary text",
@ -188,7 +195,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| 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", g_param_spec_string ("body",
"Message Body", "Message Body",
"The message body text", "The message body text",
@ -199,7 +207,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| 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",
@ -210,7 +219,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| 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",
@ -221,7 +231,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| 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",
@ -232,7 +243,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| 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", g_param_spec_int ("closed-reason",
"Closed Reason", "Closed Reason",
"The reason code for why the notification was closed", "The reason code for why the notification was closed",
@ -350,8 +362,9 @@ _g_value_free (GValue *value)
static void static void
destroy_pair (CallbackPair *pair) destroy_pair (CallbackPair *pair)
{ {
if (pair->user_data != NULL && pair->free_func != NULL) if (pair->user_data != NULL && pair->free_func != NULL) {
pair->free_func (pair->user_data); pair->free_func (pair->user_data);
}
g_free (pair); g_free (pair);
} }
@ -378,7 +391,7 @@ notify_notification_finalize (GObject *object)
{ {
NotifyNotification *obj = NOTIFY_NOTIFICATION (object); NotifyNotification *obj = NOTIFY_NOTIFICATION (object);
NotifyNotificationPrivate *priv = obj->priv; NotifyNotificationPrivate *priv = obj->priv;
DBusGProxy *proxy = _notify_get_g_proxy (); DBusGProxy *proxy;
_notify_cache_remove_notification (obj); _notify_cache_remove_notification (obj);
@ -404,6 +417,7 @@ 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);
proxy = _notify_get_g_proxy ();
if (proxy != NULL && priv->signals_registered) { if (proxy != NULL && priv->signals_registered) {
dbus_g_proxy_disconnect_signal (proxy, dbus_g_proxy_disconnect_signal (proxy,
"NotificationClosed", "NotificationClosed",
@ -492,7 +506,8 @@ notify_notification_new (const char *summary,
"summary", summary, "summary", summary,
"body", body, "body", body,
"icon-name", icon, "icon-name", icon,
"attach-widget", attach, NULL); "attach-widget", attach,
NULL);
} }
/** /**
@ -712,8 +727,9 @@ _action_signal_handler (DBusGProxy *proxy,
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);
} }
@ -723,13 +739,16 @@ 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, GArray *a;
a = g_array_sized_new (TRUE,
FALSE, FALSE,
sizeof (char *), 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 (char **) g_array_free (a, FALSE); return (char **) g_array_free (a, FALSE);
} }
@ -809,7 +828,9 @@ notify_notification_show (NotifyNotification *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 */
dbus_g_proxy_call (proxy, "Notify", &tmp_error, dbus_g_proxy_call (proxy,
"Notify",
&tmp_error,
G_TYPE_STRING, notify_get_app_name (), G_TYPE_STRING, notify_get_app_name (),
G_TYPE_UINT, priv->id, G_TYPE_UINT, priv->id,
G_TYPE_STRING, priv->icon_name, G_TYPE_STRING, priv->icon_name,
@ -822,7 +843,8 @@ notify_notification_show (NotifyNotification *notification,
priv->hints, 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_INVALID); G_TYPE_UINT, &priv->id,
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);

View File

@ -1,9 +1,8 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* *
* @file libnotify/notify.c Notifications library * Copyright (C) 2004-2006 Christian Hammond <chipx86@chipx86.com>
* * Copyright (C) 2004-2006 Mike Hearn <mike@navi.cx>
* @Copyright (C) 2004-2006 Christian Hammond <chipx86@chipx86.com> * Copyright (C) 2010 Red Hat, Inc.
* @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
@ -21,13 +20,16 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include "config.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <unistd.h> #include <unistd.h>
#include <libnotify/notify.h>
#include <libnotify/internal.h> #include "notify.h"
#include <libnotify/notify-marshal.h> #include "internal.h"
#include "notify-marshal.h"
static gboolean _initted = FALSE; static gboolean _initted = FALSE;
static char *_app_name = NULL; static char *_app_name = NULL;
@ -53,8 +55,9 @@ _notify_update_spec_version (void)
{ {
char *spec_version; char *spec_version;
if (!notify_get_server_info (NULL, NULL, NULL, &spec_version)) if (!notify_get_server_info (NULL, NULL, NULL, &spec_version)) {
return FALSE; return FALSE;
}
sscanf (spec_version, sscanf (spec_version,
"%d.%d", "%d.%d",
@ -118,8 +121,9 @@ notify_uninit (void)
{ {
GList *l; GList *l;
if (!_initted) if (!_initted) {
return; return;
}
if (_app_name != NULL) { if (_app_name != NULL) {
g_free (_app_name); g_free (_app_name);
@ -169,13 +173,14 @@ on_proxy_destroy (DBusGProxy *proxy,
DBusGProxy * DBusGProxy *
_notify_get_g_proxy (void) _notify_get_g_proxy (void)
{ {
GError *error = NULL; GError *error;
DBusGConnection *bus = NULL; DBusGConnection *bus;
if (_proxy != NULL) if (_proxy != NULL)
return _proxy; return _proxy;
/* lazily initialize D-Bus connection */ /* lazily initialize D-Bus connection */
error = NULL;
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (error != NULL) { if (error != NULL) {
@ -198,12 +203,14 @@ _notify_get_g_proxy (void)
dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_UINT, dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_UINT,
G_TYPE_NONE, G_TYPE_NONE,
G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_UINT, G_TYPE_INVALID); G_TYPE_UINT,
G_TYPE_INVALID);
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_INVALID); G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (_proxy, dbus_g_proxy_add_signal (_proxy,
"NotificationClosed", "NotificationClosed",
@ -234,17 +241,21 @@ _notify_get_g_proxy (void)
GList * GList *
notify_get_server_caps (void) notify_get_server_caps (void)
{ {
GError *error = NULL; GError *error;
char **caps = NULL; char **caps;
char **cap; char **cap;
GList *result = NULL; GList *result;
DBusGProxy *proxy; DBusGProxy *proxy;
caps = NULL;
result = NULL;
proxy = _notify_get_g_proxy (); proxy = _notify_get_g_proxy ();
if (proxy == NULL) { if (proxy == NULL) {
return NULL; return NULL;
} }
error = NULL;
if (!dbus_g_proxy_call (proxy, if (!dbus_g_proxy_call (proxy,
"GetCapabilities", "GetCapabilities",
&error, &error,
@ -313,25 +324,29 @@ notify_get_server_info (char **ret_name,
return FALSE; return FALSE;
} }
if (ret_name != NULL) if (ret_name != NULL) {
*ret_name = name; *ret_name = name;
else } else {
g_free (name); g_free (name);
}
if (ret_vendor != NULL) if (ret_vendor != NULL) {
*ret_vendor = vendor; *ret_vendor = vendor;
else } else {
g_free (vendor); g_free (vendor);
}
if (ret_version != NULL) if (ret_version != NULL) {
*ret_version = version; *ret_version = version;
else } else {
g_free (version); g_free (version);
}
if (spec_version != NULL) if (spec_version != NULL) {
*ret_spec_version = spec_version; *ret_spec_version = spec_version;
else } else {
g_free (spec_version); g_free (spec_version);
}
return TRUE; return TRUE;
} }