[Galago-commits] r2355 - in trunk/libnotify-ng: . libnotify
galago-commits at freedesktop.org
galago-commits at freedesktop.org
Fri Dec 2 14:46:54 PST 2005
Author: johnp
Date: 2005-12-02 14:46:52 -0800 (Fri, 02 Dec 2005)
New Revision: 2355
Modified:
trunk/libnotify-ng/ChangeLog
trunk/libnotify-ng/libnotify/notifynotification.c
trunk/libnotify-ng/libnotify/notifynotification.h
Log:
* 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
Modified: trunk/libnotify-ng/ChangeLog
===================================================================
--- trunk/libnotify-ng/ChangeLog 2005-12-02 21:03:40 UTC (rev 2354)
+++ trunk/libnotify-ng/ChangeLog 2005-12-02 22:46:52 UTC (rev 2355)
@@ -1,5 +1,13 @@
Fri Dec 02 2005 John (J5) Palmieri <johnp at 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 at redhat.com>
+
* libnotify/notifynotification.c (notify_notification_show_and_forget):
new method that shows and then unrefs the NotifyNotification object.
use this if you just want to fire off a quick notification.
Modified: trunk/libnotify-ng/libnotify/notifynotification.c
===================================================================
--- trunk/libnotify-ng/libnotify/notifynotification.c 2005-12-02 21:03:40 UTC (rev 2354)
+++ trunk/libnotify-ng/libnotify/notifynotification.c 2005-12-02 22:46:52 UTC (rev 2355)
@@ -29,6 +29,11 @@
guint32 id,
NotifyNotification *notification);
+static void _action_signal_handler (DBusGProxy *proxy,
+ guint32 id,
+ gchar *action,
+ NotifyNotification *notification);
+
struct NotifyNotificationPrivate
{
guint32 id;
@@ -46,6 +51,7 @@
gint timeout;
GSList *actions;
+ GHashTable *action_map;
GHashTable *hints;
GtkWidget *attached_widget;
@@ -145,6 +151,12 @@
g_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->user_data = NULL;
obj->priv->user_data_free_func = NULL;
@@ -170,12 +182,16 @@
g_free (priv->message);
g_free (priv->icon_name);
+
if (priv->actions != NULL)
{
g_slist_foreach (priv->actions, (GFunc) g_free, NULL);
g_slist_free (priv->actions);
}
+ if (priv->action_map != NULL)
+ g_hash_table_destroy (priv->action_map);
+
if (priv->hints != NULL)
g_hash_table_destroy (priv->hints);
@@ -189,6 +205,10 @@
(GCallback) _close_signal_handler,
object);
+ dbus_g_proxy_disconnect_signal (priv->proxy, "ActionInvoked",
+ (GCallback) _action_signal_handler,
+ object);
+
g_free (obj->priv);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -389,6 +409,32 @@
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
_notify_notification_show_internal (NotifyNotification *notification,
GError **error,
@@ -425,6 +471,13 @@
(GCallback) _close_signal_handler,
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);
}
@@ -769,15 +822,35 @@
(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
notify_notification_add_action (NotifyNotification *notification,
const char *action,
const char *label,
NotifyActionCallback callback)
{
- /* TODO: implement actions which will also set up a dbus listener
- for those actions
- */
+ NotifyNotificationPrivate *priv;
+
+ 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;
}
Modified: trunk/libnotify-ng/libnotify/notifynotification.h
===================================================================
--- trunk/libnotify-ng/libnotify/notifynotification.h 2005-12-02 21:03:40 UTC (rev 2354)
+++ trunk/libnotify-ng/libnotify/notifynotification.h 2005-12-02 22:46:52 UTC (rev 2355)
@@ -71,6 +71,9 @@
gboolean notify_notification_show (NotifyNotification *notification,
GError **error);
+gboolean notify_notification_show_and_forget (NotifyNotification *notification,
+ GError **error);
+
void notify_notification_set_timeout (NotifyNotification *notification,
gint timeout);
@@ -112,10 +115,11 @@
const char *action,
const char *label,
NotifyActionCallback callback);
+
+void notify_notification_clear_actions (NotifyNotification *notification);
+gboolean notify_notification_close (NotifyNotification *notification,
+ GError **error);
-gboolean notify_notification_hide (NotifyNotification *notification,
- GError **error);
-
NotifyNotification *notify_notification_ref (NotifyNotification *notification);
void notify_notification_unref (NotifyNotification *notification);
#endif /* NOTIFY_NOTIFICATION_H */
More information about the galago-commits
mailing list