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
*
@ -22,13 +22,7 @@
#ifndef _LIBNOTIFY_INTERNAL_H_
#define _LIBNOTIFY_INTERNAL_H_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef DBUS_API_SUBJECT_TO_CHANGE
# define DBUS_API_SUBJECT_TO_CHANGE 1
#endif
#include "config.h"
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
@ -39,13 +33,13 @@
G_BEGIN_DECLS
DBusGConnection *_notify_get_dbus_g_conn(void);
DBusGProxy *_notify_get_g_proxy(void);
DBusGConnection * _notify_get_dbus_g_conn (void);
DBusGProxy * _notify_get_g_proxy (void);
void _notify_cache_add_notification(NotifyNotification *n);
void _notify_cache_remove_notification(NotifyNotification *n);
gint _notify_notification_get_timeout(const NotifyNotification *n);
gboolean _notify_notification_has_nondefault_actions(const NotifyNotification *n);
void _notify_cache_add_notification (NotifyNotification *n);
void _notify_cache_remove_notification (NotifyNotification *n);
gint _notify_notification_get_timeout (const NotifyNotification *n);
gboolean _notify_notification_has_nondefault_actions (const NotifyNotification *n);
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
*
@ -32,38 +32,29 @@ G_BEGIN_DECLS
#define NOTIFY_EXPIRES_DEFAULT -1
#define NOTIFY_EXPIRES_NEVER 0
#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_CLASS(k) \
(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))
#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_CLASS(k) (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 _NotifyNotification NotifyNotification;
typedef struct _NotifyNotificationClass NotifyNotificationClass;
typedef struct _NotifyNotification NotifyNotification;
typedef struct _NotifyNotificationClass NotifyNotificationClass;
typedef struct _NotifyNotificationPrivate NotifyNotificationPrivate;
struct _NotifyNotification
{
GObject parent_object;
NotifyNotificationPrivate *priv;
GObject parent_object;
NotifyNotificationPrivate *priv;
};
struct _NotifyNotificationClass
{
GObjectClass parent_class;
GObjectClass parent_class;
/* Signals */
void (*closed)(NotifyNotification *notification);
/* Signals */
void (*closed) (NotifyNotification *notification);
};
/*
@ -71,102 +62,102 @@ struct _NotifyNotificationClass
*/
typedef enum
{
NOTIFY_URGENCY_LOW,
NOTIFY_URGENCY_NORMAL,
NOTIFY_URGENCY_CRITICAL,
NOTIFY_URGENCY_LOW,
NOTIFY_URGENCY_NORMAL,
NOTIFY_URGENCY_CRITICAL,
} NotifyUrgency;
typedef void (*NotifyActionCallback)(NotifyNotification *notification,
gchar *action,
gpointer user_data);
typedef void (*NotifyActionCallback) (NotifyNotification *notification,
char *action,
gpointer user_data);
#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,
const gchar *body,
const gchar *icon,
GtkWidget *attach);
NotifyNotification *notify_notification_new (const char *summary,
const char *body,
const char *icon,
GtkWidget *attach);
#if GTK_CHECK_VERSION(2, 9, 2)
NotifyNotification *notify_notification_new_with_status_icon(
const gchar *summary, const gchar *body,
const gchar *icon, GtkStatusIcon *status_icon);
NotifyNotification *notify_notification_new_with_status_icon (const char *summary,
const char *body,
const char *icon,
GtkStatusIcon *status_icon);
#endif
gboolean notify_notification_update(NotifyNotification *notification,
const gchar *summary,
const gchar *body,
const gchar *icon);
gboolean notify_notification_update (NotifyNotification *notification,
const char *summary,
const char *body,
const char *icon);
void notify_notification_attach_to_widget(NotifyNotification* notification,
GtkWidget *attach);
void notify_notification_attach_to_widget (NotifyNotification *notification,
GtkWidget *attach);
#if GTK_CHECK_VERSION(2, 9, 2)
void notify_notification_attach_to_status_icon(NotifyNotification *notification,
GtkStatusIcon *status_icon);
void notify_notification_attach_to_status_icon (NotifyNotification *notification,
GtkStatusIcon *status_icon);
#endif
void notify_notification_set_geometry_hints(NotifyNotification *notification,
GdkScreen *screen,
gint x,
gint y);
void notify_notification_set_geometry_hints (NotifyNotification *notification,
GdkScreen *screen,
gint x,
gint y);
gboolean notify_notification_show(NotifyNotification *notification,
GError **error);
gboolean notify_notification_show (NotifyNotification *notification,
GError **error);
void notify_notification_set_timeout(NotifyNotification *notification,
gint timeout);
void notify_notification_set_timeout (NotifyNotification *notification,
gint timeout);
void notify_notification_set_category(NotifyNotification *notification,
const char *category);
void notify_notification_set_category (NotifyNotification *notification,
const char *category);
void notify_notification_set_urgency(NotifyNotification *notification,
NotifyUrgency urgency);
void notify_notification_set_urgency (NotifyNotification *notification,
NotifyUrgency urgency);
void notify_notification_set_icon_from_pixbuf(NotifyNotification *notification,
GdkPixbuf *icon);
void notify_notification_set_icon_from_pixbuf (NotifyNotification *notification,
GdkPixbuf *icon);
void notify_notification_set_hint_int32(NotifyNotification *notification,
const gchar *key,
gint value);
void notify_notification_set_hint_uint32(NotifyNotification *notification,
const gchar *key,
guint value);
void notify_notification_set_hint_int32 (NotifyNotification *notification,
const char *key,
gint value);
void notify_notification_set_hint_uint32 (NotifyNotification *notification,
const char *key,
guint value);
void notify_notification_set_hint_double(NotifyNotification *notification,
const gchar *key,
gdouble value);
void notify_notification_set_hint_double (NotifyNotification *notification,
const char *key,
gdouble value);
void notify_notification_set_hint_string(NotifyNotification *notification,
const gchar *key,
const gchar *value);
void notify_notification_set_hint_string (NotifyNotification *notification,
const char *key,
const char *value);
void notify_notification_set_hint_byte(NotifyNotification *notification,
const gchar *key,
guchar value);
void notify_notification_set_hint_byte (NotifyNotification *notification,
const char *key,
guchar value);
void notify_notification_set_hint_byte_array(NotifyNotification *notification,
const gchar *key,
const guchar *value,
gsize len);
void notify_notification_set_hint_byte_array (NotifyNotification *notification,
const char *key,
const guchar *value,
gsize len);
void notify_notification_clear_hints(NotifyNotification *notification);
void notify_notification_clear_hints (NotifyNotification *notification);
void notify_notification_add_action(NotifyNotification *notification,
const char *action,
const char *label,
NotifyActionCallback callback,
gpointer user_data,
GFreeFunc free_func);
void notify_notification_add_action (NotifyNotification *notification,
const char *action,
const char *label,
NotifyActionCallback callback,
gpointer user_data,
GFreeFunc free_func);
void notify_notification_clear_actions(NotifyNotification *notification);
gboolean notify_notification_close(NotifyNotification *notification,
GError **error);
void notify_notification_clear_actions (NotifyNotification *notification);
gboolean notify_notification_close (NotifyNotification *notification,
GError **error);
gint notify_notification_get_closed_reason(const NotifyNotification *notification);
gint notify_notification_get_closed_reason (const NotifyNotification *notification);
G_END_DECLS
#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
*
@ -20,6 +20,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@ -28,11 +29,11 @@
#include <libnotify/internal.h>
#include <libnotify/notify-marshal.h>
static gboolean _initted = FALSE;
static gchar *_app_name = NULL;
static DBusGProxy *_proxy = NULL;
static gboolean _initted = FALSE;
static char *_app_name = NULL;
static DBusGProxy *_proxy = NULL;
static DBusGConnection *_dbus_gconn = NULL;
static GList *_active_notifications = NULL;
static GList *_active_notifications = NULL;
/**
* notify_init:
@ -43,56 +44,59 @@ static GList *_active_notifications = NULL;
* Returns: %TRUE if successful, or %FALSE on error.
*/
gboolean
notify_init(const char *app_name)
notify_init (const char *app_name)
{
GError *error = NULL;
DBusGConnection *bus = NULL;
GError *error = NULL;
DBusGConnection *bus = NULL;
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 != NULL, FALSE);
g_return_val_if_fail (*app_name != '\0', FALSE);
if (_initted)
return TRUE;
if (_initted)
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)
{
g_message("Unable to get session bus: %s", error->message);
g_error_free(error);
return FALSE;
}
if (error != NULL) {
g_message ("Unable to get session bus: %s", error->message);
g_error_free (error);
return FALSE;
}
_proxy = dbus_g_proxy_new_for_name(bus,
NOTIFY_DBUS_NAME,
NOTIFY_DBUS_CORE_OBJECT,
NOTIFY_DBUS_CORE_INTERFACE);
dbus_g_connection_unref(bus);
_proxy = dbus_g_proxy_new_for_name (bus,
NOTIFY_DBUS_NAME,
NOTIFY_DBUS_CORE_OBJECT,
NOTIFY_DBUS_CORE_INTERFACE);
dbus_g_connection_unref (bus);
dbus_g_object_register_marshaller(notify_marshal_VOID__UINT_UINT,
G_TYPE_NONE,
G_TYPE_UINT,
G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_UINT,
G_TYPE_NONE,
G_TYPE_UINT,
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);
dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_STRING,
G_TYPE_NONE,
G_TYPE_UINT,
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_add_signal(_proxy, "NotificationClosed",
G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_INVALID);
dbus_g_proxy_add_signal(_proxy, "ActionInvoked",
G_TYPE_UINT, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (_proxy,
"NotificationClosed",
G_TYPE_UINT,
G_TYPE_UINT,
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().
*/
const gchar *
notify_get_app_name(void)
const char *
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.
*/
void
notify_uninit(void)
notify_uninit (void)
{
GList *l;
GList *l;
if (!_initted)
return;
if (!_initted)
return;
if (_app_name != NULL)
{
g_free(_app_name);
_app_name = NULL;
}
if (_app_name != NULL) {
g_free (_app_name);
_app_name = NULL;
}
for (l = _active_notifications; l != NULL; l = l->next)
{
NotifyNotification *n = NOTIFY_NOTIFICATION(l->data);
for (l = _active_notifications; l != NULL; l = l->next) {
NotifyNotification *n = NOTIFY_NOTIFICATION (l->data);
if (_notify_notification_get_timeout(n) == 0 ||
_notify_notification_has_nondefault_actions(n))
{
notify_notification_close(n, NULL);
}
}
if (_notify_notification_get_timeout (n) == 0 ||
_notify_notification_has_nondefault_actions (n)) {
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.
*/
gboolean
notify_is_initted(void)
notify_is_initted (void)
{
return _initted;
return _initted;
}
DBusGConnection *
_notify_get_dbus_g_conn(void)
_notify_get_dbus_g_conn (void)
{
return _dbus_gconn;
return _dbus_gconn;
}
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.
*/
GList *
notify_get_server_caps(void)
GList *
notify_get_server_caps (void)
{
GError *error = NULL;
char **caps = NULL, **cap;
GList *result = NULL;
DBusGProxy *proxy = _notify_get_g_proxy();
GError *error = NULL;
char **caps = NULL;
char **cap;
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,
G_TYPE_INVALID,
G_TYPE_STRV, &caps, G_TYPE_INVALID))
{
g_message("GetCapabilities call failed: %s", error->message);
g_error_free(error);
return NULL;
}
if (!dbus_g_proxy_call (proxy,
"GetCapabilities",
&error,
G_TYPE_INVALID,
G_TYPE_STRV,
&caps,
G_TYPE_INVALID)) {
g_message ("GetCapabilities call failed: %s", error->message);
g_error_free (error);
return NULL;
}
for (cap = caps; *cap != NULL; cap++)
{
result = g_list_append(result, g_strdup(*cap));
}
for (cap = caps; *cap != NULL; 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.
*/
gboolean
notify_get_server_info(char **ret_name,
char **ret_vendor,
char **ret_version,
char **ret_spec_version)
notify_get_server_info (char **ret_name,
char **ret_vendor,
char **ret_version,
char **ret_spec_version)
{
GError *error = NULL;
DBusGProxy *proxy = _notify_get_g_proxy();
char *name, *vendor, *version, *spec_version;
GError *error = NULL;
DBusGProxy *proxy = _notify_get_g_proxy ();
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,
G_TYPE_INVALID,
G_TYPE_STRING, &name,
G_TYPE_STRING, &vendor,
G_TYPE_STRING, &version,
G_TYPE_STRING, &spec_version,
G_TYPE_INVALID))
{
g_message("GetServerInformation call failed: %s", error->message);
return FALSE;
}
if (!dbus_g_proxy_call (proxy,
"GetServerInformation",
&error,
G_TYPE_INVALID,
G_TYPE_STRING, &name,
G_TYPE_STRING, &vendor,
G_TYPE_STRING, &version,
G_TYPE_STRING, &spec_version,
G_TYPE_INVALID)) {
g_message ("GetServerInformation call failed: %s",
error->message);
return FALSE;
}
if (ret_name != NULL)
*ret_name = name;
if (ret_name != NULL)
*ret_name = name;
if (ret_vendor != NULL)
*ret_vendor = vendor;
if (ret_vendor != NULL)
*ret_vendor = vendor;
if (ret_version != NULL)
*ret_version = version;
if (ret_version != NULL)
*ret_version = version;
if (spec_version != NULL)
*ret_spec_version = spec_version;
if (spec_version != NULL)
*ret_spec_version = spec_version;
return TRUE;
return TRUE;
}
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
_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
*
@ -38,35 +38,35 @@ G_BEGIN_DECLS
* @return TRUE if the library initialized properly and a connection to a
* notification server was made.
*/
gboolean notify_init(const char *app_name);
gboolean notify_init (const char *app_name);
/**
* Uninitializes the notifications library.
*
* 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.
*
* @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.
*
* @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.
*
* @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.
@ -80,10 +80,10 @@ GList *notify_get_server_caps(void);
*
* @return TRUE if the call succeeded, or FALSE if there were errors.
*/
gboolean notify_get_server_info(char **ret_name,
char **ret_vendor,
char **ret_version,
char **ret_spec_version);
gboolean notify_get_server_info (char **ret_name,
char **ret_vendor,
char **ret_version,
char **ret_spec_version);
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.
*
@ -19,6 +19,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <libnotify/notify.h>
@ -34,250 +35,237 @@
static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
static gboolean
g_option_arg_urgency_cb(const gchar *option_name,
const gchar *value,
gpointer data,
GError **error)
g_option_arg_urgency_cb (const char *option_name,
const char *value,
gpointer data,
GError **error)
{
if (value != NULL)
{
if (!strcasecmp(value, "low"))
urgency = NOTIFY_URGENCY_LOW;
else if (!strcasecmp(value, "normal"))
urgency = NOTIFY_URGENCY_NORMAL;
else if (!strcasecmp(value, "critical"))
urgency = NOTIFY_URGENCY_CRITICAL;
else
{
*error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
N_("Unknown urgency %s specified. "
"Known urgency levels: low, "
"normal, critical."),
value);
if (value != NULL) {
if (!strcasecmp (value, "low"))
urgency = NOTIFY_URGENCY_LOW;
else if (!strcasecmp (value, "normal"))
urgency = NOTIFY_URGENCY_NORMAL;
else if (!strcasecmp (value, "critical"))
urgency = NOTIFY_URGENCY_CRITICAL;
else {
*error = g_error_new (G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE,
N_("Unknown urgency %s specified. "
"Known urgency levels: low, "
"normal, critical."), value);
return FALSE;
}
}
return FALSE;
}
}
return TRUE;
return TRUE;
}
static gboolean
notify_notification_set_hint_variant(NotifyNotification *notification,
const gchar *type,
const gchar *key,
const gchar *value,
GError **error)
notify_notification_set_hint_variant (NotifyNotification *notification,
const char *type,
const char *key,
const char *value,
GError **error)
{
static gboolean conv_error = FALSE;
if (!strcasecmp(type, "string"))
{
notify_notification_set_hint_string(notification, key, value);
}
else if (!strcasecmp(type, "int"))
{
if (!g_ascii_isdigit(*value))
conv_error = TRUE;
else
{
gint h_int = (gint)g_ascii_strtoull(value, NULL, 10);
notify_notification_set_hint_int32(notification, key, h_int);
}
}
else if (!strcasecmp(type, "double"))
{
if (!g_ascii_isdigit(*value))
conv_error = TRUE;
else
{
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);
static gboolean conv_error = FALSE;
if (!strcasecmp (type, "string")) {
notify_notification_set_hint_string (notification,
key,
value);
} else if (!strcasecmp (type, "int")) {
if (!g_ascii_isdigit (*value))
conv_error = TRUE;
else {
gint h_int = (gint) g_ascii_strtoull (value, NULL, 10);
notify_notification_set_hint_int32 (notification,
key,
h_int);
}
} else if (!strcasecmp (type, "double")) {
if (!g_ascii_isdigit (*value))
conv_error = TRUE;
else {
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);
if (h_byte < 0 || h_byte > 0xFF)
conv_error = TRUE;
else
{
notify_notification_set_hint_byte(notification, key,
(guchar)h_byte);
}
}
else
{
*error = g_error_new(G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE,
N_("Invalid hint type \"%s\". Valid types "
"are int, double, string and byte."),
type);
return FALSE;
}
if (h_byte < 0 || h_byte > 0xFF)
conv_error = TRUE;
else {
notify_notification_set_hint_byte (notification,
key,
(guchar) h_byte);
}
} else {
*error = g_error_new (G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE,
N_("Invalid hint type \"%s\". Valid types "
"are int, double, string and byte."),
type);
return FALSE;
}
if (conv_error)
{
*error = g_error_new(G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE,
N_("Value \"%s\" of hint \"%s\" could not be "
"parsed as type \"%s\"."),
value, key, type);
return FALSE;
}
if (conv_error) {
*error = g_error_new (G_OPTION_ERROR,
G_OPTION_ERROR_BAD_VALUE,
N_("Value \"%s\" of hint \"%s\" could not be "
"parsed as type \"%s\"."), value, key,
type);
return FALSE;
}
return TRUE;
return TRUE;
}
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
static const gchar *summary = NULL;
static const gchar *body = "";
static const gchar *type = NULL;
static gchar *icon_str = NULL;
static gchar *icons = NULL;
static gchar **n_text = NULL;
static gchar **hints = NULL;
static gboolean do_version = FALSE;
static gboolean hint_error = FALSE;
static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT;
GOptionContext *opt_ctx;
NotifyNotification *notify;
GError *error = NULL;
gboolean retval;
static const char *summary = NULL;
static const char *body = "";
static const char *type = NULL;
static char *icon_str = NULL;
static char *icons = NULL;
static char **n_text = NULL;
static char **hints = NULL;
static gboolean do_version = FALSE;
static gboolean hint_error = FALSE;
static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT;
GOptionContext *opt_ctx;
NotifyNotification *notify;
GError *error = NULL;
gboolean retval;
static const GOptionEntry entries[] =
{
{ "urgency", 'u', 0, G_OPTION_ARG_CALLBACK, g_option_arg_urgency_cb,
N_("Specifies the urgency level (low, normal, critical)."),
N_("LEVEL") },
{ "expire-time", 't', 0,G_OPTION_ARG_INT, &expire_timeout,
N_("Specifies the timeout in milliseconds at which to expire the "
"notification."), N_("TIME") },
{ "icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons,
N_("Specifies an icon filename or stock icon to display."),
N_("ICON[,ICON...]") },
{ "category", 'c', 0, G_OPTION_ARG_FILENAME, &type,
N_("Specifies the notification category."),
N_("TYPE[,TYPE...]") },
{ "hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints,
N_("Specifies basic extra data to pass. Valid types are int, double, string and byte."),
N_("TYPE:NAME:VALUE") },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
N_("Version of the package."),
NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &n_text, NULL,
NULL },
{ NULL }
};
static const GOptionEntry entries[] = {
{"urgency", 'u', 0, G_OPTION_ARG_CALLBACK,
g_option_arg_urgency_cb,
N_("Specifies the urgency level (low, normal, critical)."),
N_("LEVEL")},
{"expire-time", 't', 0, G_OPTION_ARG_INT, &expire_timeout,
N_
("Specifies the timeout in milliseconds at which to expire the "
"notification."), N_("TIME")},
{"icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons,
N_("Specifies an icon filename or stock icon to display."),
N_("ICON[,ICON...]")},
{"category", 'c', 0, G_OPTION_ARG_FILENAME, &type,
N_("Specifies the notification category."),
N_("TYPE[,TYPE...]")},
{"hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints,
N_
("Specifies basic extra data to pass. Valid types are int, double, string and byte."),
N_("TYPE:NAME:VALUE")},
{"version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
N_("Version of the package."),
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] - "
"create a notification"));
g_option_context_add_main_entries(opt_ctx, entries, GETTEXT_PACKAGE);
retval = g_option_context_parse(opt_ctx, &argc, &argv, &error);
g_option_context_free(opt_ctx);
opt_ctx = g_option_context_new (N_("<SUMMARY> [BODY] - "
"create a notification"));
g_option_context_add_main_entries (opt_ctx, entries, GETTEXT_PACKAGE);
retval = g_option_context_parse (opt_ctx, &argc, &argv, &error);
g_option_context_free (opt_ctx);
if (!retval)
{
fprintf(stderr, "%s\n", error->message);
g_error_free(error);
exit(1);
}
if (!retval) {
fprintf (stderr, "%s\n", error->message);
g_error_free (error);
exit (1);
}
if (do_version)
{
g_printf("%s %s\n", g_get_prgname(), VERSION);
exit(0);
}
if (do_version) {
g_printf ("%s %s\n", g_get_prgname (), VERSION);
exit (0);
}
if (n_text != NULL && n_text[0] != NULL && *n_text[0] != '\0')
summary = n_text[0];
if (n_text != NULL && n_text[0] != NULL && *n_text[0] != '\0')
summary = n_text[0];
if (summary == NULL)
{
fprintf(stderr, "%s\n", N_("No summary specified."));
exit(1);
}
if (summary == NULL) {
fprintf (stderr, "%s\n", N_("No summary specified."));
exit (1);
}
if (n_text[1] != NULL)
{
body = n_text[1];
if (n_text[1] != NULL) {
body = n_text[1];
if (n_text[2] != NULL)
{
fprintf(stderr, "%s\n", N_("Invalid number of options."));
exit(1);
}
}
if (n_text[2] != NULL) {
fprintf (stderr, "%s\n",
N_("Invalid number of options."));
exit (1);
}
}
if (icons != NULL)
{
char *c;
if (icons != NULL) {
char *c;
/* XXX */
if((c = strchr(icons, ',')) != NULL)
*c = '\0';
/* XXX */
if ((c = strchr (icons, ',')) != NULL)
*c = '\0';
icon_str = icons;
}
icon_str = icons;
}
if (!notify_init("notify-send"))
exit(1);
if (!notify_init ("notify-send"))
exit (1);
notify = notify_notification_new(summary, body, icon_str, NULL);
notify_notification_set_category(notify, type);
notify_notification_set_urgency(notify, urgency);
notify_notification_set_timeout(notify, expire_timeout);
notify = notify_notification_new (summary, body, icon_str, NULL);
notify_notification_set_category (notify, type);
notify_notification_set_urgency (notify, urgency);
notify_notification_set_timeout (notify, expire_timeout);
// Set hints
if (hints != NULL)
{
gint i = 0;
gint l;
gchar *hint = NULL;
gchar **tokens = NULL;
// Set hints
if (hints != NULL) {
gint i = 0;
gint l;
char *hint = NULL;
char **tokens = NULL;
while ((hint = hints[i++]))
{
tokens = g_strsplit(hint, ":", -1);
l = g_strv_length(tokens);
while ((hint = hints[i++])) {
tokens = g_strsplit (hint, ":", -1);
l = g_strv_length (tokens);
if (l != 3)
{
fprintf(stderr, "%s\n",
N_("Invalid hint syntax specified. "
"Use TYPE:NAME:VALUE."));
hint_error = TRUE;
}
else
{
retval = notify_notification_set_hint_variant(notify, tokens[0], tokens[1], tokens[2], &error);
if (l != 3) {
fprintf (stderr, "%s\n",
N_("Invalid hint syntax specified. "
"Use TYPE:NAME:VALUE."));
hint_error = TRUE;
} else {
retval = notify_notification_set_hint_variant (notify,
tokens[0],
tokens[1],
tokens[2],
&error);
if (!retval)
{
fprintf(stderr, "%s\n", error->message);
g_error_free(error);
hint_error = TRUE;
}
}
if (!retval) {
fprintf (stderr, "%s\n", error->message);
g_error_free (error);
hint_error = TRUE;
}
}
g_strfreev(tokens);
if (hint_error)
break;
}
}
g_strfreev (tokens);
if (hint_error)
break;
}
}
if (!hint_error)
notify_notification_show(notify, NULL);
if (!hint_error)
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);
}