summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Jon McCann <jmccann@redhat.com>2010-06-24 02:07:09 -0400
committerWilliam Jon McCann <jmccann@redhat.com>2010-06-24 02:12:40 -0400
commitdedef26ef95b22558920c7d6e1c505114f4d550a (patch)
tree0300cca4a9f1f4466820b80e0d5b5b015553eb15
parentd6476d362b807f8bf06e56cbe17d6b3c817e665e (diff)
downloadlibnotify-dedef26ef95b22558920c7d6e1c505114f4d550a.tar.gz
Various cleanups
-rw-r--r--libnotify/notification.c90
-rw-r--r--libnotify/notify.c69
2 files changed, 98 insertions, 61 deletions
diff --git a/libnotify/notification.c b/libnotify/notification.c
index fa45c1e..c50ea07 100644
--- a/libnotify/notification.c
+++ b/libnotify/notification.c
@@ -1,9 +1,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) 2006 John Palmieri
+ * Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,16 +19,18 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+
#include "config.h"
+
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
-#include <libnotify/notify.h>
-#include <libnotify/internal.h>
-
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
+#include "notify.h"
+#include "internal.h"
+
#define CHECK_DBUS_VERSION(major, minor) \
(DBUS_MAJOR_VER > (major) || \
(DBUS_MAJOR_VER == (major) && DBUS_MINOR_VER >= (minor)))
@@ -162,10 +163,15 @@ notify_notification_class_init (NotifyNotificationClass *klass)
g_signal_new ("closed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NotifyNotificationClass, closed), NULL, NULL,
- g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
-
- g_object_class_install_property (object_class, PROP_ID,
+ G_STRUCT_OFFSET (NotifyNotificationClass, closed),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ g_object_class_install_property (object_class,
+ PROP_ID,
g_param_spec_int ("id", "ID",
"The notification ID",
0,
@@ -177,7 +183,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| G_PARAM_STATIC_NICK
| 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",
"The summary text",
@@ -188,7 +195,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| G_PARAM_STATIC_NICK
| 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",
"The message body text",
@@ -199,7 +207,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| G_PARAM_STATIC_NICK
| 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",
"Icon 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_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",
"Attach Widget",
"The widget to attach the notification to",
@@ -221,7 +231,8 @@ notify_notification_class_init (NotifyNotificationClass *klass)
| G_PARAM_STATIC_NICK
| 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",
"Status Icon",
"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_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",
"The reason code for why the notification was closed",
@@ -350,8 +362,9 @@ _g_value_free (GValue *value)
static void
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);
+ }
g_free (pair);
}
@@ -378,7 +391,7 @@ notify_notification_finalize (GObject *object)
{
NotifyNotification *obj = NOTIFY_NOTIFICATION (object);
NotifyNotificationPrivate *priv = obj->priv;
- DBusGProxy *proxy = _notify_get_g_proxy ();
+ DBusGProxy *proxy;
_notify_cache_remove_notification (obj);
@@ -404,6 +417,7 @@ notify_notification_finalize (GObject *object)
g_object_remove_weak_pointer (G_OBJECT (priv->status_icon),
(gpointer) & priv->status_icon);
+ proxy = _notify_get_g_proxy ();
if (proxy != NULL && priv->signals_registered) {
dbus_g_proxy_disconnect_signal (proxy,
"NotificationClosed",
@@ -492,7 +506,8 @@ notify_notification_new (const char *summary,
"summary", summary,
"body", body,
"icon-name", icon,
- "attach-widget", attach, NULL);
+ "attach-widget", attach,
+ NULL);
}
/**
@@ -712,8 +727,9 @@ _action_signal_handler (DBusGProxy *proxy,
action);
if (pair == NULL) {
- if (g_ascii_strcasecmp (action, "default"))
+ if (g_ascii_strcasecmp (action, "default")) {
g_warning ("Received unknown action %s", action);
+ }
} else {
pair->cb (notification, action, pair->user_data);
}
@@ -722,14 +738,17 @@ _action_signal_handler (DBusGProxy *proxy,
static char **
_gslist_to_string_array (GSList *list)
{
- GSList *l;
- GArray *a = g_array_sized_new (TRUE,
- FALSE,
- sizeof (char *),
- g_slist_length (list));
+ GSList *l;
+ GArray *a;
+
+ a = g_array_sized_new (TRUE,
+ FALSE,
+ sizeof (char *),
+ 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);
+ }
return (char **) g_array_free (a, FALSE);
}
@@ -809,7 +828,9 @@ notify_notification_show (NotifyNotification *notification,
action_array = _gslist_to_string_array (priv->actions);
/* 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_UINT, priv->id,
G_TYPE_STRING, priv->icon_name,
@@ -822,7 +843,8 @@ notify_notification_show (NotifyNotification *notification,
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);
/* Don't free the elements because they are owned by priv->actions */
g_free (action_array);
@@ -909,7 +931,7 @@ static void
_gvalue_array_append_int (GValueArray *array,
gint i)
{
- GValue value = { 0 };
+ GValue value = { 0 };
g_value_init (&value, G_TYPE_INT);
g_value_set_int (&value, i);
@@ -920,7 +942,7 @@ _gvalue_array_append_int (GValueArray *array,
static void
_gvalue_array_append_bool (GValueArray *array, gboolean b)
{
- GValue value = { 0 };
+ GValue value = { 0 };
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, b);
@@ -933,8 +955,8 @@ _gvalue_array_append_byte_array (GValueArray *array,
guchar *bytes,
gsize len)
{
- GArray *byte_array;
- GValue value = { 0 };
+ GArray *byte_array;
+ GValue value = { 0 };
byte_array = g_array_sized_new (FALSE, FALSE, sizeof (guchar), len);
g_assert (byte_array != NULL);
@@ -1198,7 +1220,7 @@ notify_notification_set_hint_string (NotifyNotification *notification,
const char *key,
const char *value)
{
- GValue *hint_value;
+ GValue *hint_value;
g_return_if_fail (notification != NULL);
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
diff --git a/libnotify/notify.c b/libnotify/notify.c
index beba480..6737acd 100644
--- a/libnotify/notify.c
+++ b/libnotify/notify.c
@@ -1,9 +1,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) 2004-2006 Mike Hearn <mike@navi.cx>
+ * Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,13 +20,16 @@
* Boston, MA 02111-1307, USA.
*/
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
-#include <libnotify/notify.h>
-#include <libnotify/internal.h>
-#include <libnotify/notify-marshal.h>
+
+#include "notify.h"
+#include "internal.h"
+#include "notify-marshal.h"
static gboolean _initted = FALSE;
static char *_app_name = NULL;
@@ -53,8 +55,9 @@ _notify_update_spec_version (void)
{
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;
+ }
sscanf (spec_version,
"%d.%d",
@@ -118,8 +121,9 @@ notify_uninit (void)
{
GList *l;
- if (!_initted)
+ if (!_initted) {
return;
+ }
if (_app_name != NULL) {
g_free (_app_name);
@@ -169,13 +173,14 @@ on_proxy_destroy (DBusGProxy *proxy,
DBusGProxy *
_notify_get_g_proxy (void)
{
- GError *error = NULL;
- DBusGConnection *bus = NULL;
+ GError *error;
+ DBusGConnection *bus;
if (_proxy != NULL)
return _proxy;
/* lazily initialize D-Bus connection */
+ error = NULL;
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (error != NULL) {
@@ -198,12 +203,14 @@ _notify_get_g_proxy (void)
dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_UINT,
G_TYPE_NONE,
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,
G_TYPE_NONE,
G_TYPE_UINT,
- G_TYPE_STRING, G_TYPE_INVALID);
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
dbus_g_proxy_add_signal (_proxy,
"NotificationClosed",
@@ -231,20 +238,24 @@ _notify_get_g_proxy (void)
*
* Returns: A #GList of server capability strings.
*/
-GList *
+GList *
notify_get_server_caps (void)
{
- GError *error = NULL;
- char **caps = NULL;
+ GError *error;
+ char **caps;
char **cap;
- GList *result = NULL;
+ GList *result;
DBusGProxy *proxy;
+ caps = NULL;
+ result = NULL;
+
proxy = _notify_get_g_proxy ();
if (proxy == NULL) {
return NULL;
}
+ error = NULL;
if (!dbus_g_proxy_call (proxy,
"GetCapabilities",
&error,
@@ -313,37 +324,41 @@ notify_get_server_info (char **ret_name,
return FALSE;
}
- if (ret_name != NULL)
+ if (ret_name != NULL) {
*ret_name = name;
- else
+ } else {
g_free (name);
+ }
- if (ret_vendor != NULL)
+ if (ret_vendor != NULL) {
*ret_vendor = vendor;
- else
+ } else {
g_free (vendor);
+ }
- if (ret_version != NULL)
+ if (ret_version != NULL) {
*ret_version = version;
- else
+ } else {
g_free (version);
+ }
- if (spec_version != NULL)
+ if (spec_version != NULL) {
*ret_spec_version = spec_version;
- else
+ } else {
g_free (spec_version);
+ }
return TRUE;
}
void
-_notify_cache_add_notification (NotifyNotification * n)
+_notify_cache_add_notification (NotifyNotification *n)
{
_active_notifications = g_list_prepend (_active_notifications, n);
}
void
-_notify_cache_remove_notification (NotifyNotification * n)
+_notify_cache_remove_notification (NotifyNotification *n)
{
_active_notifications = g_list_remove (_active_notifications, n);
}