Use a consistent style
This commit is contained in:
parent
ac8fe12f9a
commit
4db61ddb45
|
@ -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 <dbus/dbus.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
|
|
@ -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.c Notification object
|
||||
*
|
||||
|
@ -44,11 +44,14 @@
|
|||
static void notify_notification_class_init (NotifyNotificationClass *klass);
|
||||
static void notify_notification_init (NotifyNotification *sp);
|
||||
static void notify_notification_finalize (GObject *object);
|
||||
static void _close_signal_handler(DBusGProxy *proxy, guint32 id, guint32 reason,
|
||||
static void _close_signal_handler (DBusGProxy *proxy,
|
||||
guint32 id,
|
||||
guint32 reason,
|
||||
NotifyNotification *notification);
|
||||
|
||||
static void _action_signal_handler(DBusGProxy *proxy, guint32 id,
|
||||
gchar *action,
|
||||
static void _action_signal_handler (DBusGProxy *proxy,
|
||||
guint32 id,
|
||||
char *action,
|
||||
NotifyNotification *notification);
|
||||
|
||||
typedef struct
|
||||
|
@ -62,11 +65,11 @@ typedef struct
|
|||
struct _NotifyNotificationPrivate
|
||||
{
|
||||
guint32 id;
|
||||
gchar *summary;
|
||||
gchar *body;
|
||||
char *summary;
|
||||
char *body;
|
||||
|
||||
/* NULL to use icon data. Anything else to have server lookup icon */
|
||||
gchar *icon_name;
|
||||
char *icon_name;
|
||||
|
||||
/*
|
||||
* -1 = use server default
|
||||
|
@ -107,12 +110,16 @@ enum
|
|||
PROP_CLOSED_REASON
|
||||
};
|
||||
|
||||
static void notify_notification_set_property(GObject *object, guint prop_id,
|
||||
static void notify_notification_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void notify_notification_get_property(GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec);
|
||||
static void notify_notification_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static GObjectClass *parent_class = NULL;
|
||||
|
||||
G_DEFINE_TYPE (NotifyNotification, notify_notification, G_TYPE_OBJECT)
|
||||
|
@ -122,7 +129,10 @@ notify_notification_constructor(GType type,
|
|||
guint n_construct_properties,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object = parent_class->constructor(type, n_construct_properties,
|
||||
GObject *object;
|
||||
|
||||
object = parent_class->constructor (type,
|
||||
n_construct_properties,
|
||||
construct_params);
|
||||
|
||||
_notify_cache_add_notification (NOTIFY_NOTIFICATION (object));
|
||||
|
@ -152,8 +162,7 @@ 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_STRUCT_OFFSET (NotifyNotificationClass, closed), NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
||||
|
||||
g_object_class_install_property (object_class, PROP_ID,
|
||||
|
@ -162,75 +171,78 @@ notify_notification_class_init(NotifyNotificationClass *klass)
|
|||
0,
|
||||
G_MAXINT32,
|
||||
0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_NAME |
|
||||
G_PARAM_STATIC_NICK |
|
||||
G_PARAM_STATIC_BLURB));
|
||||
G_PARAM_READWRITE
|
||||
| G_PARAM_CONSTRUCT
|
||||
| G_PARAM_STATIC_NAME
|
||||
| G_PARAM_STATIC_NICK
|
||||
| G_PARAM_STATIC_BLURB));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_SUMMARY,
|
||||
g_param_spec_string("summary", "Summary",
|
||||
g_param_spec_string ("summary",
|
||||
"Summary",
|
||||
"The summary text",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_NAME |
|
||||
G_PARAM_STATIC_NICK |
|
||||
G_PARAM_STATIC_BLURB));
|
||||
G_PARAM_READWRITE
|
||||
| G_PARAM_CONSTRUCT
|
||||
| G_PARAM_STATIC_NAME
|
||||
| G_PARAM_STATIC_NICK
|
||||
| G_PARAM_STATIC_BLURB));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_BODY,
|
||||
g_param_spec_string("body", "Message Body",
|
||||
g_param_spec_string ("body",
|
||||
"Message Body",
|
||||
"The message body text",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_NAME |
|
||||
G_PARAM_STATIC_NICK |
|
||||
G_PARAM_STATIC_BLURB));
|
||||
G_PARAM_READWRITE
|
||||
| G_PARAM_CONSTRUCT
|
||||
| G_PARAM_STATIC_NAME
|
||||
| G_PARAM_STATIC_NICK
|
||||
| G_PARAM_STATIC_BLURB));
|
||||
|
||||
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",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_NAME |
|
||||
G_PARAM_STATIC_NICK |
|
||||
G_PARAM_STATIC_BLURB));
|
||||
G_PARAM_READWRITE
|
||||
| G_PARAM_CONSTRUCT
|
||||
| G_PARAM_STATIC_NAME
|
||||
| G_PARAM_STATIC_NICK
|
||||
| G_PARAM_STATIC_BLURB));
|
||||
|
||||
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",
|
||||
GTK_TYPE_WIDGET,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_NAME |
|
||||
G_PARAM_STATIC_NICK |
|
||||
G_PARAM_STATIC_BLURB));
|
||||
G_PARAM_READWRITE
|
||||
| G_PARAM_CONSTRUCT
|
||||
| G_PARAM_STATIC_NAME
|
||||
| G_PARAM_STATIC_NICK
|
||||
| G_PARAM_STATIC_BLURB));
|
||||
|
||||
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",
|
||||
GTK_TYPE_STATUS_ICON,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_NAME |
|
||||
G_PARAM_STATIC_NICK |
|
||||
G_PARAM_STATIC_BLURB));
|
||||
G_PARAM_READWRITE
|
||||
| G_PARAM_CONSTRUCT
|
||||
| G_PARAM_STATIC_NAME
|
||||
| G_PARAM_STATIC_NICK
|
||||
| G_PARAM_STATIC_BLURB));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_CLOSED_REASON,
|
||||
g_param_spec_int("closed-reason", "Closed Reason",
|
||||
g_param_spec_int ("closed-reason",
|
||||
"Closed Reason",
|
||||
"The reason code for why the notification was closed",
|
||||
-1,
|
||||
G_MAXINT32,
|
||||
-1,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_NAME |
|
||||
G_PARAM_STATIC_NICK |
|
||||
G_PARAM_STATIC_BLURB));
|
||||
G_PARAM_READABLE
|
||||
| G_PARAM_STATIC_NAME
|
||||
| G_PARAM_STATIC_NICK
|
||||
| G_PARAM_STATIC_BLURB));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -242,26 +254,30 @@ notify_notification_set_property(GObject *object,
|
|||
NotifyNotification *notification = NOTIFY_NOTIFICATION (object);
|
||||
NotifyNotificationPrivate *priv = notification->priv;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
switch (prop_id) {
|
||||
case PROP_ID:
|
||||
priv->id = g_value_get_int (value);
|
||||
break;
|
||||
|
||||
case PROP_SUMMARY:
|
||||
notify_notification_update(notification, g_value_get_string(value),
|
||||
priv->body, priv->icon_name);
|
||||
notify_notification_update (notification,
|
||||
g_value_get_string (value),
|
||||
priv->body,
|
||||
priv->icon_name);
|
||||
break;
|
||||
|
||||
case PROP_BODY:
|
||||
notify_notification_update(notification, priv->summary,
|
||||
notify_notification_update (notification,
|
||||
priv->summary,
|
||||
g_value_get_string (value),
|
||||
priv->icon_name);
|
||||
break;
|
||||
|
||||
case PROP_ICON_NAME:
|
||||
notify_notification_update(notification, priv->summary,
|
||||
priv->body, g_value_get_string(value));
|
||||
notify_notification_update (notification,
|
||||
priv->summary,
|
||||
priv->body,
|
||||
g_value_get_string (value));
|
||||
break;
|
||||
|
||||
case PROP_ATTACH_WIDGET:
|
||||
|
@ -289,8 +305,7 @@ notify_notification_get_property(GObject *object,
|
|||
NotifyNotification *notification = NOTIFY_NOTIFICATION (object);
|
||||
NotifyNotificationPrivate *priv = notification->priv;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
switch (prop_id) {
|
||||
case PROP_ID:
|
||||
g_value_set_int (value, priv->id);
|
||||
break;
|
||||
|
@ -347,11 +362,13 @@ notify_notification_init(NotifyNotification *obj)
|
|||
obj->priv = g_new0 (NotifyNotificationPrivate, 1);
|
||||
obj->priv->timeout = NOTIFY_EXPIRES_DEFAULT;
|
||||
obj->priv->closed_reason = -1;
|
||||
obj->priv->hints = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||
obj->priv->hints = g_hash_table_new_full (g_str_hash,
|
||||
g_str_equal,
|
||||
g_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_str_equal,
|
||||
g_free,
|
||||
(GFreeFunc) destroy_pair);
|
||||
}
|
||||
|
@ -369,8 +386,7 @@ notify_notification_finalize(GObject *object)
|
|||
g_free (priv->body);
|
||||
g_free (priv->icon_name);
|
||||
|
||||
if (priv->actions != NULL)
|
||||
{
|
||||
if (priv->actions != NULL) {
|
||||
g_slist_foreach (priv->actions, (GFunc) g_free, NULL);
|
||||
g_slist_free (priv->actions);
|
||||
}
|
||||
|
@ -388,12 +404,13 @@ notify_notification_finalize(GObject *object)
|
|||
g_object_remove_weak_pointer (G_OBJECT (priv->status_icon),
|
||||
(gpointer) & priv->status_icon);
|
||||
|
||||
if (priv->signals_registered)
|
||||
{
|
||||
dbus_g_proxy_disconnect_signal(proxy, "NotificationClosed",
|
||||
if (priv->signals_registered) {
|
||||
dbus_g_proxy_disconnect_signal (proxy,
|
||||
"NotificationClosed",
|
||||
G_CALLBACK (_close_signal_handler),
|
||||
object);
|
||||
dbus_g_proxy_disconnect_signal(proxy, "ActionInvoked",
|
||||
dbus_g_proxy_disconnect_signal (proxy,
|
||||
"ActionInvoked",
|
||||
G_CALLBACK (_action_signal_handler),
|
||||
object);
|
||||
}
|
||||
|
@ -417,8 +434,7 @@ _notify_notification_update_applet_hints(NotifyNotification *n)
|
|||
GdkScreen *screen = NULL;
|
||||
gint x, y;
|
||||
|
||||
if (priv->status_icon != NULL)
|
||||
{
|
||||
if (priv->status_icon != NULL) {
|
||||
GdkRectangle rect;
|
||||
GtkWidget *internal_tray = get_internal_tray_icon (priv->status_icon);
|
||||
GdkWindow *window;
|
||||
|
@ -427,45 +443,45 @@ _notify_notification_update_applet_hints(NotifyNotification *n)
|
|||
gtk_widget_realize (internal_tray);
|
||||
window = internal_tray->window;
|
||||
|
||||
if (window != NULL)
|
||||
{
|
||||
if (window != NULL) {
|
||||
guint32 xid = GDK_WINDOW_XID (window);
|
||||
notify_notification_set_hint_uint32(n, "window-xid", xid);
|
||||
|
||||
notify_notification_set_hint_uint32 (n,
|
||||
"window-xid",
|
||||
xid);
|
||||
}
|
||||
|
||||
if (!gtk_status_icon_get_geometry(priv->status_icon, &screen,
|
||||
&rect, NULL))
|
||||
{
|
||||
if (!gtk_status_icon_get_geometry (priv->status_icon,
|
||||
&screen,
|
||||
&rect, NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
x = rect.x + rect.width / 2;
|
||||
y = rect.y + rect.height / 2;
|
||||
}
|
||||
else if (priv->attached_widget != NULL)
|
||||
{
|
||||
} else if (priv->attached_widget != NULL) {
|
||||
GtkWidget *widget = priv->attached_widget;
|
||||
|
||||
screen = gtk_widget_get_screen (widget);
|
||||
|
||||
gdk_window_get_origin (widget->window, &x, &y);
|
||||
|
||||
if (GTK_WIDGET_NO_WINDOW(widget))
|
||||
{
|
||||
if (GTK_WIDGET_NO_WINDOW (widget)) {
|
||||
x += widget->allocation.x;
|
||||
y += widget->allocation.y;
|
||||
}
|
||||
|
||||
x += widget->allocation.width / 2;
|
||||
y += widget->allocation.height / 2;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
notify_notification_set_geometry_hints (n, screen, x, y);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/*
|
||||
* This is left here just incase we revisit autoupdating
|
||||
* One thought would be to check for updates every time the icon
|
||||
|
@ -479,18 +495,15 @@ _idle_check_updates(void *user_data)
|
|||
NotifyNotification *n = NOTIFY_NOTIFICATION (user_data);
|
||||
NotifyNotificationPrivate *priv = n->priv;
|
||||
|
||||
if (priv->is_visible)
|
||||
{
|
||||
priv->updates_pending = _notify_notification_update_applet_hints(n);
|
||||
if (priv->is_visible) {
|
||||
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 */
|
||||
priv->updates_pending = !notify_notification_show (n, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
priv->updates_pending = FALSE;
|
||||
}
|
||||
|
||||
|
@ -511,9 +524,9 @@ _idle_check_updates(void *user_data)
|
|||
* Returns: The new #NotifyNotification.
|
||||
*/
|
||||
NotifyNotification *
|
||||
notify_notification_new(const gchar *summary,
|
||||
const gchar *body,
|
||||
const gchar *icon,
|
||||
notify_notification_new (const char *summary,
|
||||
const char *body,
|
||||
const char *icon,
|
||||
GtkWidget *attach)
|
||||
{
|
||||
g_return_val_if_fail (attach == NULL || GTK_IS_WIDGET (attach), NULL);
|
||||
|
@ -522,8 +535,7 @@ notify_notification_new(const gchar *summary,
|
|||
"summary", summary,
|
||||
"body", body,
|
||||
"icon-name", icon,
|
||||
"attach-widget", attach,
|
||||
NULL);
|
||||
"attach-widget", attach, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -542,9 +554,9 @@ notify_notification_new(const gchar *summary,
|
|||
* Since: 0.4.1
|
||||
*/
|
||||
NotifyNotification *
|
||||
notify_notification_new_with_status_icon(const gchar *summary,
|
||||
const gchar *message,
|
||||
const gchar *icon,
|
||||
notify_notification_new_with_status_icon (const char *summary,
|
||||
const char *message,
|
||||
const char *icon,
|
||||
GtkStatusIcon *status_icon)
|
||||
{
|
||||
g_return_val_if_fail (status_icon != NULL, NULL);
|
||||
|
@ -573,34 +585,31 @@ notify_notification_new_with_status_icon(const gchar *summary,
|
|||
*/
|
||||
gboolean
|
||||
notify_notification_update (NotifyNotification *notification,
|
||||
const gchar *summary,
|
||||
const gchar *body,
|
||||
const gchar *icon)
|
||||
const char *summary,
|
||||
const char *body,
|
||||
const char *icon)
|
||||
{
|
||||
g_return_val_if_fail (notification != NULL, FALSE);
|
||||
g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), FALSE);
|
||||
g_return_val_if_fail (summary != NULL && *summary != '\0', FALSE);
|
||||
|
||||
if (notification->priv->summary != summary)
|
||||
{
|
||||
if (notification->priv->summary != summary) {
|
||||
g_free (notification->priv->summary);
|
||||
notification->priv->summary = g_strdup (summary);
|
||||
g_object_notify (G_OBJECT (notification), "summary");
|
||||
}
|
||||
|
||||
if (notification->priv->body != body)
|
||||
{
|
||||
if (notification->priv->body != body) {
|
||||
g_free (notification->priv->body);
|
||||
notification->priv->body =
|
||||
(body != NULL && *body != '\0' ? g_strdup(body) : NULL);
|
||||
notification->priv->body = (body != NULL
|
||||
&& *body != '\0' ? g_strdup (body) : NULL);
|
||||
g_object_notify (G_OBJECT (notification), "body");
|
||||
}
|
||||
|
||||
if (notification->priv->icon_name != icon)
|
||||
{
|
||||
if (notification->priv->icon_name != icon) {
|
||||
g_free (notification->priv->icon_name);
|
||||
notification->priv->icon_name =
|
||||
(icon != NULL && *icon != '\0' ? g_strdup(icon) : NULL);
|
||||
notification->priv->icon_name = (icon != NULL
|
||||
&& *icon != '\0' ? g_strdup (icon) : NULL);
|
||||
g_object_notify (G_OBJECT (notification), "icon-name");
|
||||
}
|
||||
|
||||
|
@ -654,23 +663,22 @@ notify_notification_attach_to_status_icon(NotifyNotification *notification,
|
|||
NotifyNotificationPrivate *priv;
|
||||
|
||||
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
|
||||
g_return_if_fail(status_icon == NULL || GTK_IS_STATUS_ICON(status_icon));
|
||||
g_return_if_fail (status_icon == NULL
|
||||
|| GTK_IS_STATUS_ICON (status_icon));
|
||||
|
||||
priv = notification->priv;
|
||||
|
||||
if (priv->status_icon == status_icon)
|
||||
return;
|
||||
|
||||
if (priv->status_icon != NULL)
|
||||
{
|
||||
if (priv->status_icon != NULL) {
|
||||
g_object_remove_weak_pointer (G_OBJECT (priv->status_icon),
|
||||
(gpointer) & priv->status_icon);
|
||||
}
|
||||
|
||||
priv->status_icon = status_icon;
|
||||
|
||||
if (priv->status_icon != NULL)
|
||||
{
|
||||
if (priv->status_icon != NULL) {
|
||||
g_object_add_weak_pointer (G_OBJECT (priv->status_icon),
|
||||
(gpointer) & priv->status_icon);
|
||||
}
|
||||
|
@ -708,7 +716,9 @@ notify_notification_set_geometry_hints(NotifyNotification *notification,
|
|||
notify_notification_set_hint_int32 (notification, "y", y);
|
||||
|
||||
display_name = gdk_screen_make_display_name (screen);
|
||||
notify_notification_set_hint_string(notification, "xdisplay", display_name);
|
||||
notify_notification_set_hint_string (notification,
|
||||
"xdisplay",
|
||||
display_name);
|
||||
g_free (display_name);
|
||||
}
|
||||
|
||||
|
@ -718,8 +728,7 @@ _close_signal_handler(DBusGProxy *proxy,
|
|||
guint32 reason,
|
||||
NotifyNotification *notification)
|
||||
{
|
||||
if (id == notification->priv->id)
|
||||
{
|
||||
if (id == notification->priv->id) {
|
||||
g_object_ref (G_OBJECT (notification));
|
||||
notification->priv->closed_reason = reason;
|
||||
g_signal_emit (notification, signals[SIGNAL_CLOSED], 0);
|
||||
|
@ -731,7 +740,7 @@ _close_signal_handler(DBusGProxy *proxy,
|
|||
static void
|
||||
_action_signal_handler (DBusGProxy *proxy,
|
||||
guint32 id,
|
||||
gchar *action,
|
||||
char *action,
|
||||
NotifyNotification *notification)
|
||||
{
|
||||
CallbackPair *pair;
|
||||
|
@ -742,31 +751,30 @@ _action_signal_handler(DBusGProxy *proxy,
|
|||
if (id != notification->priv->id)
|
||||
return;
|
||||
|
||||
pair = (CallbackPair *)g_hash_table_lookup(
|
||||
notification->priv->action_map, action);
|
||||
pair = (CallbackPair *) g_hash_table_lookup (notification->priv->action_map,
|
||||
action);
|
||||
|
||||
if (pair == NULL)
|
||||
{
|
||||
if (pair == NULL) {
|
||||
if (g_ascii_strcasecmp (action, "default"))
|
||||
g_warning ("Received unknown action %s", action);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pair->cb (notification, action, pair->user_data);
|
||||
}
|
||||
}
|
||||
|
||||
static gchar **
|
||||
static char **
|
||||
_gslist_to_string_array (GSList *list)
|
||||
{
|
||||
GSList *l;
|
||||
GArray *a = g_array_sized_new(TRUE, FALSE, sizeof(gchar *),
|
||||
GArray *a = g_array_sized_new (TRUE,
|
||||
FALSE,
|
||||
sizeof (char *),
|
||||
g_slist_length (list));
|
||||
|
||||
for (l = list; l != NULL; l = l->next)
|
||||
g_array_append_val (a, l->data);
|
||||
|
||||
return (gchar **)g_array_free(a, FALSE);
|
||||
return (char **) g_array_free (a, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -785,7 +793,7 @@ notify_notification_show(NotifyNotification *notification,
|
|||
{
|
||||
NotifyNotificationPrivate *priv;
|
||||
GError *tmp_error = NULL;
|
||||
gchar **action_array;
|
||||
char **action_array;
|
||||
DBusGProxy *proxy;
|
||||
|
||||
g_return_val_if_fail (notification != NULL, FALSE);
|
||||
|
@ -795,15 +803,18 @@ notify_notification_show(NotifyNotification *notification,
|
|||
priv = notification->priv;
|
||||
proxy = _notify_get_g_proxy ();
|
||||
|
||||
if (!priv->signals_registered)
|
||||
{
|
||||
dbus_g_proxy_connect_signal(proxy, "NotificationClosed",
|
||||
if (!priv->signals_registered) {
|
||||
dbus_g_proxy_connect_signal (proxy,
|
||||
"NotificationClosed",
|
||||
G_CALLBACK (_close_signal_handler),
|
||||
notification, NULL);
|
||||
notification,
|
||||
NULL);
|
||||
|
||||
dbus_g_proxy_connect_signal(proxy, "ActionInvoked",
|
||||
dbus_g_proxy_connect_signal (proxy,
|
||||
"ActionInvoked",
|
||||
G_CALLBACK (_action_signal_handler),
|
||||
notification, NULL);
|
||||
notification,
|
||||
NULL);
|
||||
|
||||
priv->signals_registered = TRUE;
|
||||
}
|
||||
|
@ -821,18 +832,18 @@ notify_notification_show(NotifyNotification *notification,
|
|||
G_TYPE_STRING, priv->summary,
|
||||
G_TYPE_STRING, priv->body,
|
||||
G_TYPE_STRV, action_array,
|
||||
dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
|
||||
G_TYPE_VALUE), priv->hints,
|
||||
dbus_g_type_get_map ("GHashTable",
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_VALUE),
|
||||
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);
|
||||
|
||||
if (tmp_error != NULL)
|
||||
{
|
||||
if (tmp_error != NULL) {
|
||||
g_propagate_error (error, tmp_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -883,7 +894,9 @@ notify_notification_set_category(NotifyNotification *notification,
|
|||
g_return_if_fail (notification != NULL);
|
||||
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
|
||||
|
||||
notify_notification_set_hint_string(notification, "category", category);
|
||||
notify_notification_set_hint_string (notification,
|
||||
"category",
|
||||
category);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -902,12 +915,15 @@ notify_notification_set_urgency(NotifyNotification *notification,
|
|||
g_return_if_fail (notification != NULL);
|
||||
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
|
||||
|
||||
notify_notification_set_hint_byte(notification, "urgency", (guchar)urgency);
|
||||
notify_notification_set_hint_byte (notification,
|
||||
"urgency",
|
||||
(guchar) urgency);
|
||||
}
|
||||
|
||||
#if CHECK_DBUS_VERSION(0, 60)
|
||||
static void
|
||||
_gvalue_array_append_int(GValueArray *array, gint i)
|
||||
_gvalue_array_append_int (GValueArray *array,
|
||||
gint i)
|
||||
{
|
||||
GValue value = { 0 };
|
||||
|
||||
|
@ -929,7 +945,9 @@ _gvalue_array_append_bool(GValueArray *array, gboolean b)
|
|||
}
|
||||
|
||||
static void
|
||||
_gvalue_array_append_byte_array(GValueArray *array, guchar *bytes, gsize len)
|
||||
_gvalue_array_append_byte_array (GValueArray *array,
|
||||
guchar *bytes,
|
||||
gsize len)
|
||||
{
|
||||
GArray *byte_array;
|
||||
GValue value = { 0 };
|
||||
|
@ -990,7 +1008,8 @@ notify_notification_set_icon_from_pixbuf(NotifyNotification *notification,
|
|||
_gvalue_array_append_int (image_struct, width);
|
||||
_gvalue_array_append_int (image_struct, height);
|
||||
_gvalue_array_append_int (image_struct, rowstride);
|
||||
_gvalue_array_append_bool(image_struct, gdk_pixbuf_get_has_alpha(icon));
|
||||
_gvalue_array_append_bool (image_struct,
|
||||
gdk_pixbuf_get_has_alpha (icon));
|
||||
_gvalue_array_append_int (image_struct, bits_per_sample);
|
||||
_gvalue_array_append_int (image_struct, n_channels);
|
||||
_gvalue_array_append_byte_array (image_struct, image, image_len);
|
||||
|
@ -1016,7 +1035,7 @@ notify_notification_set_icon_from_pixbuf(NotifyNotification *notification,
|
|||
*/
|
||||
void
|
||||
notify_notification_set_hint_int32 (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
gint value)
|
||||
{
|
||||
GValue *hint_value;
|
||||
|
@ -1029,7 +1048,8 @@ notify_notification_set_hint_int32(NotifyNotification *notification,
|
|||
g_value_init (hint_value, G_TYPE_INT);
|
||||
g_value_set_int (hint_value, value);
|
||||
g_hash_table_insert (notification->priv->hints,
|
||||
g_strdup(key), hint_value);
|
||||
g_strdup (key),
|
||||
hint_value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1043,7 +1063,7 @@ notify_notification_set_hint_int32(NotifyNotification *notification,
|
|||
*/
|
||||
void
|
||||
notify_notification_set_hint_uint32 (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
guint value)
|
||||
{
|
||||
GValue *hint_value;
|
||||
|
@ -1056,7 +1076,8 @@ notify_notification_set_hint_uint32(NotifyNotification *notification,
|
|||
g_value_init (hint_value, G_TYPE_UINT);
|
||||
g_value_set_uint (hint_value, value);
|
||||
g_hash_table_insert (notification->priv->hints,
|
||||
g_strdup(key), hint_value);
|
||||
g_strdup (key),
|
||||
hint_value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1069,7 +1090,7 @@ notify_notification_set_hint_uint32(NotifyNotification *notification,
|
|||
*/
|
||||
void
|
||||
notify_notification_set_hint_double (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
gdouble value)
|
||||
{
|
||||
GValue *hint_value;
|
||||
|
@ -1082,7 +1103,8 @@ notify_notification_set_hint_double(NotifyNotification *notification,
|
|||
g_value_init (hint_value, G_TYPE_FLOAT);
|
||||
g_value_set_float (hint_value, value);
|
||||
g_hash_table_insert (notification->priv->hints,
|
||||
g_strdup(key), hint_value);
|
||||
g_strdup (key),
|
||||
hint_value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1095,7 +1117,7 @@ notify_notification_set_hint_double(NotifyNotification *notification,
|
|||
*/
|
||||
void
|
||||
notify_notification_set_hint_byte (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
guchar value)
|
||||
{
|
||||
GValue *hint_value;
|
||||
|
@ -1108,7 +1130,9 @@ notify_notification_set_hint_byte(NotifyNotification *notification,
|
|||
g_value_init (hint_value, G_TYPE_UCHAR);
|
||||
g_value_set_uchar (hint_value, value);
|
||||
|
||||
g_hash_table_insert(notification->priv->hints, g_strdup(key), hint_value);
|
||||
g_hash_table_insert (notification->priv->hints,
|
||||
g_strdup (key),
|
||||
hint_value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1123,7 +1147,7 @@ notify_notification_set_hint_byte(NotifyNotification *notification,
|
|||
*/
|
||||
void
|
||||
notify_notification_set_hint_byte_array (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
const guchar *value,
|
||||
gsize len)
|
||||
{
|
||||
|
@ -1145,7 +1169,8 @@ notify_notification_set_hint_byte_array(NotifyNotification *notification,
|
|||
g_value_take_boxed (hint_value, byte_array);
|
||||
|
||||
g_hash_table_insert (notification->priv->hints,
|
||||
g_strdup(key), hint_value);
|
||||
g_strdup (key),
|
||||
hint_value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1158,8 +1183,8 @@ notify_notification_set_hint_byte_array(NotifyNotification *notification,
|
|||
*/
|
||||
void
|
||||
notify_notification_set_hint_string (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const gchar *value)
|
||||
const char *key,
|
||||
const char *value)
|
||||
{
|
||||
GValue *hint_value;
|
||||
|
||||
|
@ -1171,7 +1196,8 @@ notify_notification_set_hint_string(NotifyNotification *notification,
|
|||
g_value_init (hint_value, G_TYPE_STRING);
|
||||
g_value_set_string (hint_value, value);
|
||||
g_hash_table_insert (notification->priv->hints,
|
||||
g_strdup(key), hint_value);
|
||||
g_strdup (key),
|
||||
hint_value);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -1193,7 +1219,8 @@ notify_notification_clear_hints(NotifyNotification *notification)
|
|||
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
|
||||
|
||||
g_hash_table_foreach_remove (notification->priv->hints,
|
||||
(GHRFunc)_remove_all, NULL);
|
||||
(GHRFunc) _remove_all,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1209,11 +1236,13 @@ notify_notification_clear_actions(NotifyNotification *notification)
|
|||
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
|
||||
|
||||
g_hash_table_foreach_remove (notification->priv->action_map,
|
||||
(GHRFunc)_remove_all, NULL);
|
||||
(GHRFunc) _remove_all,
|
||||
NULL);
|
||||
|
||||
if (notification->priv->actions != NULL)
|
||||
{
|
||||
g_slist_foreach(notification->priv->actions, (GFunc)g_free, NULL);
|
||||
if (notification->priv->actions != NULL) {
|
||||
g_slist_foreach (notification->priv->actions,
|
||||
(GFunc) g_free,
|
||||
NULL);
|
||||
g_slist_free (notification->priv->actions);
|
||||
}
|
||||
|
||||
|
@ -1264,8 +1293,7 @@ notify_notification_add_action(NotifyNotification *notification,
|
|||
g_hash_table_insert (priv->action_map, g_strdup (action), pair);
|
||||
|
||||
if (!notification->priv->has_nondefault_actions &&
|
||||
g_ascii_strcasecmp(action, "default") != 0)
|
||||
{
|
||||
g_ascii_strcasecmp (action, "default") != 0) {
|
||||
notification->priv->has_nondefault_actions = TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -1302,12 +1330,15 @@ notify_notification_close(NotifyNotification *notification,
|
|||
|
||||
priv = notification->priv;
|
||||
|
||||
dbus_g_proxy_call(_notify_get_g_proxy(), "CloseNotification", &tmp_error,
|
||||
G_TYPE_UINT, priv->id, G_TYPE_INVALID,
|
||||
dbus_g_proxy_call (_notify_get_g_proxy (),
|
||||
"CloseNotification",
|
||||
&tmp_error,
|
||||
G_TYPE_UINT,
|
||||
priv->id,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
if (tmp_error != NULL)
|
||||
{
|
||||
if (tmp_error != NULL) {
|
||||
g_propagate_error (error, tmp_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
@ -33,20 +33,11 @@ G_BEGIN_DECLS
|
|||
#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_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;
|
||||
|
@ -78,27 +69,28 @@ typedef enum
|
|||
} NotifyUrgency;
|
||||
|
||||
typedef void (*NotifyActionCallback) (NotifyNotification *notification,
|
||||
gchar *action,
|
||||
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,
|
||||
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);
|
||||
const char *summary,
|
||||
const char *body,
|
||||
const char *icon);
|
||||
|
||||
void notify_notification_attach_to_widget (NotifyNotification *notification,
|
||||
GtkWidget *attach);
|
||||
|
@ -129,26 +121,26 @@ void notify_notification_set_icon_from_pixbuf(NotifyNotification *notification,
|
|||
GdkPixbuf *icon);
|
||||
|
||||
void notify_notification_set_hint_int32 (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
gint value);
|
||||
void notify_notification_set_hint_uint32 (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
guint value);
|
||||
|
||||
void notify_notification_set_hint_double (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
gdouble value);
|
||||
|
||||
void notify_notification_set_hint_string (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const gchar *value);
|
||||
const char *key,
|
||||
const char *value);
|
||||
|
||||
void notify_notification_set_hint_byte (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
guchar value);
|
||||
|
||||
void notify_notification_set_hint_byte_array (NotifyNotification *notification,
|
||||
const gchar *key,
|
||||
const char *key,
|
||||
const guchar *value,
|
||||
gsize len);
|
||||
|
||||
|
@ -168,5 +160,4 @@ gboolean notify_notification_close(NotifyNotification *notification,
|
|||
gint notify_notification_get_closed_reason (const NotifyNotification *notification);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NOTIFY_NOTIFICATION_H */
|
||||
|
|
|
@ -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>
|
||||
|
@ -29,7 +30,7 @@
|
|||
#include <libnotify/notify-marshal.h>
|
||||
|
||||
static gboolean _initted = FALSE;
|
||||
static gchar *_app_name = NULL;
|
||||
static char *_app_name = NULL;
|
||||
static DBusGProxy *_proxy = NULL;
|
||||
static DBusGConnection *_dbus_gconn = NULL;
|
||||
static GList *_active_notifications = NULL;
|
||||
|
@ -60,8 +61,7 @@ notify_init(const char *app_name)
|
|||
|
||||
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_error_free (error);
|
||||
return FALSE;
|
||||
|
@ -83,11 +83,15 @@ notify_init(const char *app_name)
|
|||
G_TYPE_UINT,
|
||||
G_TYPE_STRING, G_TYPE_INVALID);
|
||||
|
||||
dbus_g_proxy_add_signal(_proxy, "NotificationClosed",
|
||||
G_TYPE_UINT, G_TYPE_UINT,
|
||||
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,
|
||||
dbus_g_proxy_add_signal (_proxy,
|
||||
"ActionInvoked",
|
||||
G_TYPE_UINT,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
_initted = TRUE;
|
||||
|
@ -102,7 +106,7 @@ notify_init(const char *app_name)
|
|||
*
|
||||
* Returns: The registered application name, passed to notify_init().
|
||||
*/
|
||||
const gchar *
|
||||
const char *
|
||||
notify_get_app_name (void)
|
||||
{
|
||||
return _app_name;
|
||||
|
@ -124,19 +128,16 @@ notify_uninit(void)
|
|||
if (!_initted)
|
||||
return;
|
||||
|
||||
if (_app_name != NULL)
|
||||
{
|
||||
if (_app_name != NULL) {
|
||||
g_free (_app_name);
|
||||
_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);
|
||||
|
||||
if (_notify_notification_get_timeout (n) == 0 ||
|
||||
_notify_notification_has_nondefault_actions(n))
|
||||
{
|
||||
_notify_notification_has_nondefault_actions (n)) {
|
||||
notify_notification_close (n, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -182,23 +183,26 @@ GList *
|
|||
notify_get_server_caps (void)
|
||||
{
|
||||
GError *error = NULL;
|
||||
char **caps = NULL, **cap;
|
||||
char **caps = NULL;
|
||||
char **cap;
|
||||
GList *result = NULL;
|
||||
DBusGProxy *proxy = _notify_get_g_proxy ();
|
||||
|
||||
g_return_val_if_fail (proxy != NULL, NULL);
|
||||
|
||||
if (!dbus_g_proxy_call(proxy, "GetCapabilities", &error,
|
||||
if (!dbus_g_proxy_call (proxy,
|
||||
"GetCapabilities",
|
||||
&error,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_STRV, &caps, 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++)
|
||||
{
|
||||
for (cap = caps; *cap != NULL; cap++) {
|
||||
result = g_list_append (result, g_strdup (*cap));
|
||||
}
|
||||
|
||||
|
@ -230,19 +234,24 @@ notify_get_server_info(char **ret_name,
|
|||
{
|
||||
GError *error = NULL;
|
||||
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);
|
||||
|
||||
if (!dbus_g_proxy_call(proxy, "GetServerInformation", &error,
|
||||
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);
|
||||
G_TYPE_INVALID)) {
|
||||
g_message ("GetServerInformation call failed: %s",
|
||||
error->message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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,26 +35,24 @@
|
|||
static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
|
||||
|
||||
static gboolean
|
||||
g_option_arg_urgency_cb(const gchar *option_name,
|
||||
const gchar *value,
|
||||
g_option_arg_urgency_cb (const char *option_name,
|
||||
const char *value,
|
||||
gpointer data,
|
||||
GError **error)
|
||||
{
|
||||
if (value != NULL)
|
||||
{
|
||||
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,
|
||||
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);
|
||||
"normal, critical."), value);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -64,50 +63,44 @@ g_option_arg_urgency_cb(const gchar *option_name,
|
|||
|
||||
static gboolean
|
||||
notify_notification_set_hint_variant (NotifyNotification *notification,
|
||||
const gchar *type,
|
||||
const gchar *key,
|
||||
const gchar *value,
|
||||
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 (!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
|
||||
{
|
||||
else {
|
||||
gint h_int = (gint) g_ascii_strtoull (value, NULL, 10);
|
||||
notify_notification_set_hint_int32(notification, key, h_int);
|
||||
notify_notification_set_hint_int32 (notification,
|
||||
key,
|
||||
h_int);
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp(type, "double"))
|
||||
{
|
||||
} else if (!strcasecmp (type, "double")) {
|
||||
if (!g_ascii_isdigit (*value))
|
||||
conv_error = TRUE;
|
||||
else
|
||||
{
|
||||
else {
|
||||
gdouble h_double = g_strtod (value, NULL);
|
||||
notify_notification_set_hint_double(notification, key, h_double);
|
||||
notify_notification_set_hint_double (notification,
|
||||
key, h_double);
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp(type, "byte"))
|
||||
{
|
||||
} 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,
|
||||
else {
|
||||
notify_notification_set_hint_byte (notification,
|
||||
key,
|
||||
(guchar) h_byte);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*error = g_error_new (G_OPTION_ERROR,
|
||||
G_OPTION_ERROR_BAD_VALUE,
|
||||
N_("Invalid hint type \"%s\". Valid types "
|
||||
|
@ -116,13 +109,12 @@ notify_notification_set_hint_variant(NotifyNotification *notification,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (conv_error)
|
||||
{
|
||||
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);
|
||||
"parsed as type \"%s\"."), value, key,
|
||||
type);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -132,13 +124,13 @@ notify_notification_set_hint_variant(NotifyNotification *notification,
|
|||
int
|
||||
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 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;
|
||||
|
@ -147,13 +139,14 @@ main(int argc, char *argv[])
|
|||
GError *error = NULL;
|
||||
gboolean retval;
|
||||
|
||||
static const GOptionEntry entries[] =
|
||||
{
|
||||
{ "urgency", 'u', 0, G_OPTION_ARG_CALLBACK, g_option_arg_urgency_cb,
|
||||
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 "
|
||||
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."),
|
||||
|
@ -162,12 +155,14 @@ main(int argc, char *argv[])
|
|||
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_
|
||||
("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,
|
||||
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
|
||||
&n_text, NULL,
|
||||
NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
@ -182,15 +177,13 @@ main(int argc, char *argv[])
|
|||
retval = g_option_context_parse (opt_ctx, &argc, &argv, &error);
|
||||
g_option_context_free (opt_ctx);
|
||||
|
||||
if (!retval)
|
||||
{
|
||||
if (!retval) {
|
||||
fprintf (stderr, "%s\n", error->message);
|
||||
g_error_free (error);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (do_version)
|
||||
{
|
||||
if (do_version) {
|
||||
g_printf ("%s %s\n", g_get_prgname (), VERSION);
|
||||
exit (0);
|
||||
}
|
||||
|
@ -198,25 +191,22 @@ main(int argc, char *argv[])
|
|||
if (n_text != NULL && n_text[0] != NULL && *n_text[0] != '\0')
|
||||
summary = n_text[0];
|
||||
|
||||
if (summary == NULL)
|
||||
{
|
||||
if (summary == NULL) {
|
||||
fprintf (stderr, "%s\n", N_("No summary specified."));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (n_text[1] != NULL)
|
||||
{
|
||||
if (n_text[1] != NULL) {
|
||||
body = n_text[1];
|
||||
|
||||
if (n_text[2] != NULL)
|
||||
{
|
||||
fprintf(stderr, "%s\n", N_("Invalid number of options."));
|
||||
if (n_text[2] != NULL) {
|
||||
fprintf (stderr, "%s\n",
|
||||
N_("Invalid number of options."));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
if (icons != NULL)
|
||||
{
|
||||
if (icons != NULL) {
|
||||
char *c;
|
||||
|
||||
/* XXX */
|
||||
|
@ -235,31 +225,29 @@ main(int argc, char *argv[])
|
|||
notify_notification_set_timeout (notify, expire_timeout);
|
||||
|
||||
// Set hints
|
||||
if (hints != NULL)
|
||||
{
|
||||
if (hints != NULL) {
|
||||
gint i = 0;
|
||||
gint l;
|
||||
gchar *hint = NULL;
|
||||
gchar **tokens = NULL;
|
||||
char *hint = NULL;
|
||||
char **tokens = NULL;
|
||||
|
||||
while ((hint = hints[i++]))
|
||||
{
|
||||
while ((hint = hints[i++])) {
|
||||
tokens = g_strsplit (hint, ":", -1);
|
||||
l = g_strv_length (tokens);
|
||||
|
||||
if (l != 3)
|
||||
{
|
||||
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);
|
||||
} else {
|
||||
retval = notify_notification_set_hint_variant (notify,
|
||||
tokens[0],
|
||||
tokens[1],
|
||||
tokens[2],
|
||||
&error);
|
||||
|
||||
if (!retval)
|
||||
{
|
||||
if (!retval) {
|
||||
fprintf (stderr, "%s\n", error->message);
|
||||
g_error_free (error);
|
||||
hint_error = TRUE;
|
||||
|
|
Loading…
Reference in New Issue