* libnotify/notifynotification.c (notify_notification_add_action):
implement adding actions (_action_signal_handler): handle actions coming from the server (notify_notifcation_clear_actions): new method for clearning out the actions list and hash
This commit is contained in:
parent
4a3be1113e
commit
0e3f35c15e
|
@ -1,3 +1,11 @@
|
||||||
|
Fri Dec 02 2005 John (J5) Palmieri <johnp@redhat.com>
|
||||||
|
|
||||||
|
* libnotify/notifynotification.c (notify_notification_add_action):
|
||||||
|
implement adding actions
|
||||||
|
(_action_signal_handler): handle actions coming from the server
|
||||||
|
(notify_notifcation_clear_actions): new method for clearning out
|
||||||
|
the actions list and hash
|
||||||
|
|
||||||
Fri Dec 02 2005 John (J5) Palmieri <johnp@redhat.com>
|
Fri Dec 02 2005 John (J5) Palmieri <johnp@redhat.com>
|
||||||
|
|
||||||
* libnotify/notifynotification.c (notify_notification_show_and_forget):
|
* libnotify/notifynotification.c (notify_notification_show_and_forget):
|
||||||
|
|
|
@ -29,6 +29,11 @@ static void _close_signal_handler (DBusGProxy *proxy,
|
||||||
guint32 id,
|
guint32 id,
|
||||||
NotifyNotification *notification);
|
NotifyNotification *notification);
|
||||||
|
|
||||||
|
static void _action_signal_handler (DBusGProxy *proxy,
|
||||||
|
guint32 id,
|
||||||
|
gchar *action,
|
||||||
|
NotifyNotification *notification);
|
||||||
|
|
||||||
struct NotifyNotificationPrivate
|
struct NotifyNotificationPrivate
|
||||||
{
|
{
|
||||||
guint32 id;
|
guint32 id;
|
||||||
|
@ -46,6 +51,7 @@ struct NotifyNotificationPrivate
|
||||||
gint timeout;
|
gint timeout;
|
||||||
|
|
||||||
GSList *actions;
|
GSList *actions;
|
||||||
|
GHashTable *action_map;
|
||||||
GHashTable *hints;
|
GHashTable *hints;
|
||||||
|
|
||||||
GtkWidget *attached_widget;
|
GtkWidget *attached_widget;
|
||||||
|
@ -145,6 +151,12 @@ notify_notification_init (NotifyNotification * obj)
|
||||||
g_free,
|
g_free,
|
||||||
(GDestroyNotify) _g_value_free);
|
(GDestroyNotify) _g_value_free);
|
||||||
|
|
||||||
|
|
||||||
|
obj->priv->action_map = g_hash_table_new_full (g_str_hash,
|
||||||
|
g_str_equal,
|
||||||
|
g_free,
|
||||||
|
NULL);
|
||||||
|
|
||||||
obj->priv->attached_widget = NULL;
|
obj->priv->attached_widget = NULL;
|
||||||
obj->priv->user_data = NULL;
|
obj->priv->user_data = NULL;
|
||||||
obj->priv->user_data_free_func = NULL;
|
obj->priv->user_data_free_func = NULL;
|
||||||
|
@ -170,12 +182,16 @@ notify_notification_finalize (GObject * object)
|
||||||
g_free (priv->message);
|
g_free (priv->message);
|
||||||
g_free (priv->icon_name);
|
g_free (priv->icon_name);
|
||||||
|
|
||||||
|
|
||||||
if (priv->actions != NULL)
|
if (priv->actions != NULL)
|
||||||
{
|
{
|
||||||
g_slist_foreach (priv->actions, (GFunc) g_free, NULL);
|
g_slist_foreach (priv->actions, (GFunc) g_free, NULL);
|
||||||
g_slist_free (priv->actions);
|
g_slist_free (priv->actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (priv->action_map != NULL)
|
||||||
|
g_hash_table_destroy (priv->action_map);
|
||||||
|
|
||||||
if (priv->hints != NULL)
|
if (priv->hints != NULL)
|
||||||
g_hash_table_destroy (priv->hints);
|
g_hash_table_destroy (priv->hints);
|
||||||
|
|
||||||
|
@ -189,6 +205,10 @@ notify_notification_finalize (GObject * object)
|
||||||
(GCallback) _close_signal_handler,
|
(GCallback) _close_signal_handler,
|
||||||
object);
|
object);
|
||||||
|
|
||||||
|
dbus_g_proxy_disconnect_signal (priv->proxy, "ActionInvoked",
|
||||||
|
(GCallback) _action_signal_handler,
|
||||||
|
object);
|
||||||
|
|
||||||
g_free (obj->priv);
|
g_free (obj->priv);
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
@ -389,6 +409,32 @@ _close_signal_handler (DBusGProxy *proxy,
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_action_signal_handler (DBusGProxy *proxy,
|
||||||
|
guint32 id,
|
||||||
|
gchar *action,
|
||||||
|
NotifyNotification *notification)
|
||||||
|
{
|
||||||
|
g_assert (NOTIFY_IS_NOTIFICATION (notification));
|
||||||
|
|
||||||
|
printf ("Got the ActionInvoked signal for action %s (id = %i, notification->id = %i)\n",
|
||||||
|
action, id, notification->priv->id);
|
||||||
|
|
||||||
|
if (id == notification->priv->id)
|
||||||
|
{
|
||||||
|
NotifyActionCallback callback;
|
||||||
|
|
||||||
|
callback = (NotifyActionCallback) g_hash_table_lookup (notification->priv->action_map,
|
||||||
|
action);
|
||||||
|
|
||||||
|
if (callback == NULL)
|
||||||
|
g_warning ("Recieved unknown action %s", action);
|
||||||
|
else
|
||||||
|
callback (notification, action);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_notify_notification_show_internal (NotifyNotification *notification,
|
_notify_notification_show_internal (NotifyNotification *notification,
|
||||||
GError **error,
|
GError **error,
|
||||||
|
@ -425,6 +471,13 @@ _notify_notification_show_internal (NotifyNotification *notification,
|
||||||
(GCallback) _close_signal_handler,
|
(GCallback) _close_signal_handler,
|
||||||
notification, NULL);
|
notification, NULL);
|
||||||
|
|
||||||
|
dbus_g_proxy_add_signal (priv->proxy, "ActionInvoked",
|
||||||
|
G_TYPE_UINT, G_TYPE_STRING, NULL);
|
||||||
|
dbus_g_proxy_connect_signal (priv->proxy, "ActionInvoked",
|
||||||
|
(GCallback) _action_signal_handler,
|
||||||
|
notification, NULL);
|
||||||
|
|
||||||
|
|
||||||
dbus_g_connection_unref (bus);
|
dbus_g_connection_unref (bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,15 +822,35 @@ notify_notification_clear_hints (NotifyNotification *notification)
|
||||||
(GHRFunc) _remove_all, NULL);
|
(GHRFunc) _remove_all, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
notify_notification_clear_actions (NotifyNotification *notification)
|
||||||
|
{
|
||||||
|
g_hash_table_foreach_remove (notification->priv->action_map, (GHRFunc) _remove_all, NULL);
|
||||||
|
|
||||||
|
if (notification->priv->actions != NULL)
|
||||||
|
{
|
||||||
|
g_slist_foreach (notification->priv->actions, (GFunc) g_free, NULL);
|
||||||
|
g_slist_free (notification->priv->actions);
|
||||||
|
}
|
||||||
|
|
||||||
|
notification->priv->actions = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
notify_notification_add_action (NotifyNotification *notification,
|
notify_notification_add_action (NotifyNotification *notification,
|
||||||
const char *action,
|
const char *action,
|
||||||
const char *label,
|
const char *label,
|
||||||
NotifyActionCallback callback)
|
NotifyActionCallback callback)
|
||||||
{
|
{
|
||||||
/* TODO: implement actions which will also set up a dbus listener
|
NotifyNotificationPrivate *priv;
|
||||||
for those actions
|
|
||||||
*/
|
priv = notification->priv;
|
||||||
|
|
||||||
|
priv->actions = g_slist_append (priv->actions, g_strdup (action));
|
||||||
|
priv->actions = g_slist_append (priv->actions, g_strdup (label));
|
||||||
|
|
||||||
|
g_hash_table_insert (priv->action_map, g_strdup (action), callback);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,9 @@ gboolean notify_notification_set_user_data (NotifyNotification *notification,
|
||||||
gboolean notify_notification_show (NotifyNotification *notification,
|
gboolean notify_notification_show (NotifyNotification *notification,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gboolean notify_notification_show_and_forget (NotifyNotification *notification,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
void notify_notification_set_timeout (NotifyNotification *notification,
|
void notify_notification_set_timeout (NotifyNotification *notification,
|
||||||
gint timeout);
|
gint timeout);
|
||||||
|
|
||||||
|
@ -113,7 +116,8 @@ gboolean notify_notification_add_action (NotifyNotification *notification,
|
||||||
const char *label,
|
const char *label,
|
||||||
NotifyActionCallback callback);
|
NotifyActionCallback callback);
|
||||||
|
|
||||||
gboolean notify_notification_hide (NotifyNotification *notification,
|
void notify_notification_clear_actions (NotifyNotification *notification);
|
||||||
|
gboolean notify_notification_close (NotifyNotification *notification,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
NotifyNotification *notify_notification_ref (NotifyNotification *notification);
|
NotifyNotification *notify_notification_ref (NotifyNotification *notification);
|
||||||
|
|
Loading…
Reference in New Issue