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>
@ -39,13 +33,13 @@
G_BEGIN_DECLS G_BEGIN_DECLS
DBusGConnection *_notify_get_dbus_g_conn(void); DBusGConnection * _notify_get_dbus_g_conn (void);
DBusGProxy *_notify_get_g_proxy(void); DBusGProxy * _notify_get_g_proxy (void);
void _notify_cache_add_notification(NotifyNotification *n); void _notify_cache_add_notification (NotifyNotification *n);
void _notify_cache_remove_notification(NotifyNotification *n); void _notify_cache_remove_notification (NotifyNotification *n);
gint _notify_notification_get_timeout(const NotifyNotification *n); gint _notify_notification_get_timeout (const NotifyNotification *n);
gboolean _notify_notification_has_nondefault_actions(const NotifyNotification *n); gboolean _notify_notification_has_nondefault_actions (const NotifyNotification *n);
G_END_DECLS G_END_DECLS

File diff suppressed because it is too large Load Diff

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
* *
@ -32,38 +32,29 @@ G_BEGIN_DECLS
#define NOTIFY_EXPIRES_DEFAULT -1 #define NOTIFY_EXPIRES_DEFAULT -1
#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;
typedef struct _NotifyNotificationPrivate NotifyNotificationPrivate; typedef struct _NotifyNotificationPrivate NotifyNotificationPrivate;
struct _NotifyNotification struct _NotifyNotification
{ {
GObject parent_object; GObject parent_object;
NotifyNotificationPrivate *priv; NotifyNotificationPrivate *priv;
}; };
struct _NotifyNotificationClass struct _NotifyNotificationClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
/* Signals */ /* Signals */
void (*closed)(NotifyNotification *notification); void (*closed) (NotifyNotification *notification);
}; };
/* /*
@ -71,102 +62,102 @@ struct _NotifyNotificationClass
*/ */
typedef enum typedef enum
{ {
NOTIFY_URGENCY_LOW, NOTIFY_URGENCY_LOW,
NOTIFY_URGENCY_NORMAL, NOTIFY_URGENCY_NORMAL,
NOTIFY_URGENCY_CRITICAL, NOTIFY_URGENCY_CRITICAL,
} 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);
#if GTK_CHECK_VERSION(2, 9, 2) #if GTK_CHECK_VERSION(2, 9, 2)
void notify_notification_attach_to_status_icon(NotifyNotification *notification, void notify_notification_attach_to_status_icon (NotifyNotification *notification,
GtkStatusIcon *status_icon); GtkStatusIcon *status_icon);
#endif #endif
void notify_notification_set_geometry_hints(NotifyNotification *notification, void notify_notification_set_geometry_hints (NotifyNotification *notification,
GdkScreen *screen, GdkScreen *screen,
gint x, gint x,
gint y); gint y);
gboolean notify_notification_show(NotifyNotification *notification, gboolean notify_notification_show (NotifyNotification *notification,
GError **error); GError **error);
void notify_notification_set_timeout(NotifyNotification *notification, void notify_notification_set_timeout (NotifyNotification *notification,
gint timeout); gint timeout);
void notify_notification_set_category(NotifyNotification *notification, void notify_notification_set_category (NotifyNotification *notification,
const char *category); const char *category);
void notify_notification_set_urgency(NotifyNotification *notification, void notify_notification_set_urgency (NotifyNotification *notification,
NotifyUrgency urgency); NotifyUrgency urgency);
void notify_notification_set_icon_from_pixbuf(NotifyNotification *notification, 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);
void notify_notification_clear_hints(NotifyNotification *notification); void notify_notification_clear_hints (NotifyNotification *notification);
void notify_notification_add_action(NotifyNotification *notification, void notify_notification_add_action (NotifyNotification *notification,
const char *action, const char *action,
const char *label, const char *label,
NotifyActionCallback callback, NotifyActionCallback callback,
gpointer user_data, gpointer user_data,
GFreeFunc free_func); GFreeFunc free_func);
void notify_notification_clear_actions(NotifyNotification *notification); void notify_notification_clear_actions (NotifyNotification *notification);
gboolean notify_notification_close(NotifyNotification *notification, gboolean notify_notification_close (NotifyNotification *notification,
GError **error); GError **error);
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>
@ -28,11 +29,11 @@
#include <libnotify/internal.h> #include <libnotify/internal.h>
#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;
/** /**
* notify_init: * notify_init:
@ -43,56 +44,59 @@ static GList *_active_notifications = NULL;
* Returns: %TRUE if successful, or %FALSE on error. * Returns: %TRUE if successful, or %FALSE on error.
*/ */
gboolean gboolean
notify_init(const char *app_name) notify_init (const char *app_name)
{ {
GError *error = NULL; GError *error = NULL;
DBusGConnection *bus = NULL; DBusGConnection *bus = NULL;
g_return_val_if_fail(app_name != NULL, FALSE); g_return_val_if_fail (app_name != NULL, FALSE);
g_return_val_if_fail(*app_name != '\0', FALSE); g_return_val_if_fail (*app_name != '\0', FALSE);
if (_initted) if (_initted)
return TRUE; return TRUE;
_app_name = g_strdup(app_name); _app_name = g_strdup (app_name);
g_type_init(); g_type_init ();
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; }
}
_proxy = dbus_g_proxy_new_for_name(bus, _proxy = dbus_g_proxy_new_for_name (bus,
NOTIFY_DBUS_NAME, NOTIFY_DBUS_NAME,
NOTIFY_DBUS_CORE_OBJECT, NOTIFY_DBUS_CORE_OBJECT,
NOTIFY_DBUS_CORE_INTERFACE); NOTIFY_DBUS_CORE_INTERFACE);
dbus_g_connection_unref(bus); dbus_g_connection_unref (bus);
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, "NotificationClosed", dbus_g_proxy_add_signal (_proxy,
G_TYPE_UINT, G_TYPE_UINT, "NotificationClosed",
G_TYPE_INVALID); G_TYPE_UINT,
dbus_g_proxy_add_signal(_proxy, "ActionInvoked", G_TYPE_UINT,
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID);
G_TYPE_INVALID); dbus_g_proxy_add_signal (_proxy,
"ActionInvoked",
G_TYPE_UINT,
G_TYPE_STRING,
G_TYPE_INVALID);
_initted = TRUE; _initted = TRUE;
return TRUE; return TRUE;
} }
/** /**
@ -102,10 +106,10 @@ 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;
} }
/** /**
@ -117,33 +121,30 @@ notify_get_app_name(void)
* the rest of its lifecycle, typically just before exitting. * the rest of its lifecycle, typically just before exitting.
*/ */
void void
notify_uninit(void) 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); _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); }
} }
}
g_object_unref(_proxy); g_object_unref (_proxy);
_initted = FALSE; _initted = FALSE;
} }
/** /**
@ -154,21 +155,21 @@ notify_uninit(void)
* Returns: %TRUE if libnotify is initialized, or %FALSE otherwise. * Returns: %TRUE if libnotify is initialized, or %FALSE otherwise.
*/ */
gboolean gboolean
notify_is_initted(void) notify_is_initted (void)
{ {
return _initted; return _initted;
} }
DBusGConnection * DBusGConnection *
_notify_get_dbus_g_conn(void) _notify_get_dbus_g_conn (void)
{ {
return _dbus_gconn; return _dbus_gconn;
} }
DBusGProxy * DBusGProxy *
_notify_get_g_proxy(void) _notify_get_g_proxy (void)
{ {
return _proxy; return _proxy;
} }
/** /**
@ -178,33 +179,36 @@ _notify_get_g_proxy(void)
* *
* Returns: A #GList of server capability strings. * Returns: A #GList of server capability strings.
*/ */
GList * GList *
notify_get_server_caps(void) notify_get_server_caps (void)
{ {
GError *error = NULL; GError *error = NULL;
char **caps = NULL, **cap; char **caps = NULL;
GList *result = NULL; char **cap;
DBusGProxy *proxy = _notify_get_g_proxy(); GList *result = NULL;
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,
G_TYPE_INVALID, "GetCapabilities",
G_TYPE_STRV, &caps, G_TYPE_INVALID)) &error,
{ G_TYPE_INVALID,
g_message("GetCapabilities call failed: %s", error->message); G_TYPE_STRV,
g_error_free(error); &caps,
return NULL; G_TYPE_INVALID)) {
} g_message ("GetCapabilities call failed: %s", error->message);
g_error_free (error);
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)); }
}
g_strfreev(caps); g_strfreev (caps);
return result; return result;
} }
/** /**
@ -223,52 +227,57 @@ notify_get_server_caps(void)
* on failure. * on failure.
*/ */
gboolean gboolean
notify_get_server_info(char **ret_name, notify_get_server_info (char **ret_name,
char **ret_vendor, char **ret_vendor,
char **ret_version, char **ret_version,
char **ret_spec_version) char **ret_spec_version)
{ {
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,
G_TYPE_INVALID, "GetServerInformation",
G_TYPE_STRING, &name, &error,
G_TYPE_STRING, &vendor, G_TYPE_INVALID,
G_TYPE_STRING, &version, G_TYPE_STRING, &name,
G_TYPE_STRING, &spec_version, G_TYPE_STRING, &vendor,
G_TYPE_INVALID)) G_TYPE_STRING, &version,
{ G_TYPE_STRING, &spec_version,
g_message("GetServerInformation call failed: %s", error->message); G_TYPE_INVALID)) {
return FALSE; g_message ("GetServerInformation call failed: %s",
} error->message);
return FALSE;
}
if (ret_name != NULL) if (ret_name != NULL)
*ret_name = name; *ret_name = name;
if (ret_vendor != NULL) if (ret_vendor != NULL)
*ret_vendor = vendor; *ret_vendor = vendor;
if (ret_version != NULL) if (ret_version != NULL)
*ret_version = version; *ret_version = version;
if (spec_version != NULL) if (spec_version != NULL)
*ret_spec_version = spec_version; *ret_spec_version = spec_version;
return TRUE; return TRUE;
} }
void void
_notify_cache_add_notification(NotifyNotification *n) _notify_cache_add_notification (NotifyNotification * n)
{ {
_active_notifications = g_list_prepend(_active_notifications, n); _active_notifications = g_list_prepend (_active_notifications, n);
} }
void void
_notify_cache_remove_notification(NotifyNotification *n) _notify_cache_remove_notification (NotifyNotification * n)
{ {
_active_notifications = g_list_remove(_active_notifications, n); _active_notifications = g_list_remove (_active_notifications, n);
} }

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
* *
@ -38,35 +38,35 @@ G_BEGIN_DECLS
* @return TRUE if the library initialized properly and a connection to a * @return TRUE if the library initialized properly and a connection to a
* notification server was made. * notification server was made.
*/ */
gboolean notify_init(const char *app_name); gboolean notify_init (const char *app_name);
/** /**
* Uninitializes the notifications library. * Uninitializes the notifications library.
* *
* This will be automatically called on exit unless previously called. * This will be automatically called on exit unless previously called.
*/ */
void notify_uninit(void); void notify_uninit (void);
/** /**
* Returns whether or not the notification library is initialized. * Returns whether or not the notification library is initialized.
* *
* @return TRUE if the library is initialized, or FALSE. * @return TRUE if the library is initialized, or FALSE.
*/ */
gboolean notify_is_initted(void); gboolean notify_is_initted (void);
/** /**
* Returns the name of the application set when notify_init() was called. * Returns the name of the application set when notify_init() was called.
* *
* @return The name of the application. * @return The name of the application.
*/ */
const gchar *notify_get_app_name(void); const gchar *notify_get_app_name (void);
/** /**
* Returns the capabilities of the notification server. * Returns the capabilities of the notification server.
* *
* @return A list of capability strings. These strings must be freed. * @return A list of capability strings. These strings must be freed.
*/ */
GList *notify_get_server_caps(void); GList *notify_get_server_caps (void);
/** /**
* Returns the server notification information. * Returns the server notification information.
@ -80,10 +80,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, gboolean notify_get_server_info (char **ret_name,
char **ret_vendor, char **ret_vendor,
char **ret_version, char **ret_version,
char **ret_spec_version); char **ret_spec_version);
G_END_DECLS G_END_DECLS

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,250 +35,237 @@
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,
{ G_OPTION_ERROR_BAD_VALUE,
*error = g_error_new(G_OPTION_ERROR, 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."), value);
"normal, critical."),
value);
return FALSE; return FALSE;
} }
} }
return TRUE; return TRUE;
} }
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);
{ notify_notification_set_hint_int32 (notification,
gint h_int = (gint)g_ascii_strtoull(value, NULL, 10); key,
notify_notification_set_hint_int32(notification, key, h_int); h_int);
} }
} } else if (!strcasecmp (type, "double")) {
else if (!strcasecmp(type, "double")) if (!g_ascii_isdigit (*value))
{ conv_error = TRUE;
if (!g_ascii_isdigit(*value)) else {
conv_error = TRUE; gdouble h_double = g_strtod (value, NULL);
else notify_notification_set_hint_double (notification,
{ key, h_double);
gdouble h_double = g_strtod(value, NULL); }
notify_notification_set_hint_double(notification, key, h_double); } else if (!strcasecmp (type, "byte")) {
} gint h_byte = (gint) g_ascii_strtoull (value, NULL, 10);
}
else if (!strcasecmp(type, "byte"))
{
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,
{ G_OPTION_ERROR_BAD_VALUE,
*error = g_error_new(G_OPTION_ERROR, N_("Invalid hint type \"%s\". Valid types "
G_OPTION_ERROR_BAD_VALUE, "are int, double, string and byte."),
N_("Invalid hint type \"%s\". Valid types " type);
"are int, double, string and byte."), return FALSE;
type); }
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\"."), value, key,
"parsed as type \"%s\"."), type);
value, key, type); return FALSE;
return FALSE; }
}
return TRUE; return TRUE;
} }
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;
GOptionContext *opt_ctx; GOptionContext *opt_ctx;
NotifyNotification *notify; NotifyNotification *notify;
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_
"notification."), N_("TIME") }, ("Specifies the timeout in milliseconds at which to expire the "
{ "icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons, "notification."), N_("TIME")},
N_("Specifies an icon filename or stock icon to display."), {"icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons,
N_("ICON[,ICON...]") }, N_("Specifies an icon filename or stock icon to display."),
{ "category", 'c', 0, G_OPTION_ARG_FILENAME, &type, N_("ICON[,ICON...]")},
N_("Specifies the notification category."), {"category", 'c', 0, G_OPTION_ARG_FILENAME, &type,
N_("TYPE[,TYPE...]") }, N_("Specifies the notification category."),
{ "hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints, N_("TYPE[,TYPE...]")},
N_("Specifies basic extra data to pass. Valid types are int, double, string and byte."), {"hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints,
N_("TYPE:NAME:VALUE") }, N_
{ "version", 'v', 0, G_OPTION_ARG_NONE, &do_version, ("Specifies basic extra data to pass. Valid types are int, double, string and byte."),
N_("Version of the package."), N_("TYPE:NAME:VALUE")},
NULL }, {"version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &n_text, NULL, N_("Version of the package."),
NULL }, NULL},
{ NULL } {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
}; &n_text, NULL,
NULL},
{NULL}
};
g_type_init(); g_type_init ();
g_set_prgname(argv[0]); g_set_prgname (argv[0]);
opt_ctx = g_option_context_new(N_("<SUMMARY> [BODY] - " opt_ctx = g_option_context_new (N_("<SUMMARY> [BODY] - "
"create a notification")); "create a notification"));
g_option_context_add_main_entries(opt_ctx, entries, GETTEXT_PACKAGE); g_option_context_add_main_entries (opt_ctx, entries, GETTEXT_PACKAGE);
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); }
}
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 */
if((c = strchr(icons, ',')) != NULL) if ((c = strchr (icons, ',')) != NULL)
*c = '\0'; *c = '\0';
icon_str = icons; icon_str = icons;
} }
if (!notify_init("notify-send")) if (!notify_init ("notify-send"))
exit(1); exit (1);
notify = notify_notification_new(summary, body, icon_str, NULL); notify = notify_notification_new (summary, body, icon_str, NULL);
notify_notification_set_category(notify, type); notify_notification_set_category (notify, type);
notify_notification_set_urgency(notify, urgency); notify_notification_set_urgency (notify, urgency);
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; char *hint = NULL;
gchar *hint = NULL; char **tokens = NULL;
gchar **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 {
} retval = notify_notification_set_hint_variant (notify,
else tokens[0],
{ tokens[1],
retval = notify_notification_set_hint_variant(notify, tokens[0], tokens[1], tokens[2], &error); 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; }
} }
}
g_strfreev(tokens); g_strfreev (tokens);
if (hint_error) if (hint_error)
break; break;
} }
} }
if (!hint_error) if (!hint_error)
notify_notification_show(notify, NULL); notify_notification_show (notify, NULL);
g_object_unref(G_OBJECT(notify)); g_object_unref (G_OBJECT (notify));
notify_uninit(); notify_uninit ();
exit(hint_error); exit (hint_error);
} }