From 38c83b0ef58b36fd171a5fd87a86798ce880eaa9 Mon Sep 17 00:00:00 2001 From: "John (J5) Palmieri" Date: Fri, 2 Dec 2005 20:36:46 +0000 Subject: [PATCH] * libnotify/notifynotification.c (SIGNAL_TYPE_CLOSED): "closed" glib signal added (notify_notification_clear_hints): New API for clearing out the hints hash (notify_notification_ref, notify_notification_unref): removed - use g_object_ref/unref * tests/*: Various changes to the test binaries --- libnotify/notifynotification.c | 81 +++++++++++++++++++++++----------- libnotify/notifynotification.h | 3 ++ tests/test-basic.c | 2 +- tests/test-image.c | 4 ++ tests/test-xy-stress.c | 66 ++++++++++++++++----------- tests/test-xy.c | 2 +- 6 files changed, 104 insertions(+), 54 deletions(-) diff --git a/libnotify/notifynotification.c b/libnotify/notifynotification.c index 7174380..66e849e 100644 --- a/libnotify/notifynotification.c +++ b/libnotify/notifynotification.c @@ -25,11 +25,13 @@ 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, + NotifyNotification *notification); struct NotifyNotificationPrivate { guint32 id; - gchar *summary; gchar *message; @@ -58,19 +60,18 @@ struct NotifyNotificationPrivate DBusGProxy *proxy; }; -#if 0 typedef enum { + SIGNAL_TYPE_CLOSED, LAST_SIGNAL } NotifyNotificationSignalType; -#endif typedef struct { NotifyNotification *object; } NotifyNotificationSignal; -/* static guint notify_notification_signals[LAST_SIGNAL] = { 0 }; */ +static guint notify_notification_signals[LAST_SIGNAL] = { 0 }; static GObjectClass *parent_class = NULL; GType @@ -107,9 +108,16 @@ notify_notification_class_init (NotifyNotificationClass * klass) parent_class = g_type_class_peek_parent (klass); object_class->finalize = notify_notification_finalize; - /* Create signals here: - notify_notification_signals[SIGNAL_TYPE_EXAMPLE] = g_signal_new(...) - */ + /* Create signals here: */ + notify_notification_signals[SIGNAL_TYPE_CLOSED] = + g_signal_new ("closed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NotifyNotificationClass, closed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); } static void @@ -177,6 +185,10 @@ notify_notification_finalize (GObject * object) if (priv->user_data_free_func != NULL) priv->user_data_free_func (priv->user_data); + dbus_g_proxy_disconnect_signal (priv->proxy, "NotificationClosed", + _close_signal_handler, + object); + g_free (obj->priv); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -304,18 +316,6 @@ notify_notification_new (const gchar * summary, return obj; } -NotifyNotification * -notify_notification_ref (NotifyNotification * notification) -{ - return NOTIFY_NOTIFICATION (g_object_ref (G_OBJECT (notification))); -} - -void -notify_notification_unref (NotifyNotification * notification) -{ - g_object_unref (G_OBJECT (notification)); -} - gboolean notify_notification_update (NotifyNotification * notification, const gchar * summary, @@ -385,8 +385,22 @@ filter_func (DBusConnection *connection, return DBUS_HANDLER_RESULT_HANDLED; } +static void +_close_signal_handler (DBusGProxy *proxy, + guint32 id, + NotifyNotification *notification) +{ + printf ("Got the NotificationClosed signal (id = %i, notification->id = %i)\n" +, id, notification->priv->id); + + if (id == notification->priv->id) + g_signal_emit (notification, + notify_notification_signals[SIGNAL_TYPE_CLOSED], + 0); +} + gboolean -notify_notification_show (NotifyNotification * notification, GError ** error) +notify_notification_show (NotifyNotification *notification, GError **error) { NotifyNotificationPrivate *priv; GError *tmp_error; @@ -408,15 +422,17 @@ notify_notification_show (NotifyNotification * notification, GError ** error) return FALSE; } - /* Register the object here because - * we need to start listening for signals - */ - dbus_g_connection_register_g_object (bus, "/org/freedesktop/NotifyNotification", G_OBJECT (notification)); - priv->proxy = dbus_g_proxy_new_for_name (bus, NOTIFY_DBUS_NAME, NOTIFY_DBUS_CORE_OBJECT, NOTIFY_DBUS_CORE_INTERFACE); + + dbus_g_proxy_add_signal (priv->proxy, "NotificationClosed", + G_TYPE_UINT, NULL); + dbus_g_proxy_connect_signal (priv->proxy, "NotificationClosed", + _close_signal_handler, + notification, NULL); + dbus_g_connection_unref (bus); } @@ -715,8 +731,21 @@ notify_notification_set_hint_string (NotifyNotification * notification, return TRUE; } +static gboolean +_remove_all (void) +{ + return TRUE; +} + +void +notify_notification_clear_hints (NotifyNotification *notification) +{ + g_hash_table_foreach_remove (notification->priv->hints, + (GHRFunc) _remove_all, NULL); +} + gboolean -notify_notification_add_action (NotifyNotification * notification, +notify_notification_add_action (NotifyNotification *notification, const char *action, const char *label, NotifyActionCallback callback) diff --git a/libnotify/notifynotification.h b/libnotify/notifynotification.h index 85b6c10..4c53e4b 100644 --- a/libnotify/notifynotification.h +++ b/libnotify/notifynotification.h @@ -45,6 +45,7 @@ typedef struct { typedef struct { GObjectClass parent_class; /* Add Signal Functions Here */ + void (*closed) (void); } NotifyNotificationClass; typedef void (*NotifyActionCallback )(NotifyNotification *, gchar *); @@ -105,6 +106,8 @@ gboolean notify_notification_set_hint_byte_array ( const guchar *value, gsize len); +void notify_notification_clear_hints (NotifyNotification *notification); + gboolean notify_notification_add_action (NotifyNotification *notification, const char *action, const char *label, diff --git a/tests/test-basic.c b/tests/test-basic.c index e04a5fa..cc2b83d 100644 --- a/tests/test-basic.c +++ b/tests/test-basic.c @@ -29,7 +29,7 @@ int main() { notify_init("Basics"); n = notify_notification_new ("Summary", - "Content", + "Content that is very long 8374983278r32j4 rhjjfh dw8f 43jhf 8ds7 ur2389f jdbjkt h8924yf jkdbjkt 892hjfiHER98HEJIF BDSJHF hjdhF JKLH 890YRHEJHFU 89HRJKSHFJ YE8UI HR3UIH89EFHIUEUF9DHFUIBuiew f89hsajiJ FHJKDSKJFH SDJKFH KJASDFJK HKJADSHFK JSAHF89WE HUIIUG JG kjG JKGJGHJg JHG H J HJGJHDG HJKJG hgd hgjhf df h3eui fusidyaiu rh f98ehkrnm e8rv9y 43heh vijdhjkewdkjsjfjk sdhkjf hdkj fadskj hfkjdsh", NULL, NULL); notify_notification_set_timeout (n, 3000); //3 seconds diff --git a/tests/test-image.c b/tests/test-image.c index 151e609..a026d19 100644 --- a/tests/test-image.c +++ b/tests/test-image.c @@ -56,6 +56,10 @@ int main(int argc, char *argv[]) { if (!notify_init("Images Test")) exit(1); n = notify_notification_new ("Icon Test", "Testing stock icon", "stock_help", NULL); + + notify_notification_set_hint_int32 (n, "x", 300); + notify_notification_set_hint_int32 (n, "y", 24); + notify_notification_set_timeout (n, NOTIFY_TIMEOUT_NEVER); if (!notify_notification_show (n, NULL)) { fprintf(stderr, "failed to send notification\n"); diff --git a/tests/test-xy-stress.c b/tests/test-xy-stress.c index 0888cf6..66dbc1b 100644 --- a/tests/test-xy-stress.c +++ b/tests/test-xy-stress.c @@ -24,6 +24,16 @@ #include #include +#include +#include + +static void +_handle_closed (GObject *o) +{ + g_message ("closing"); + g_object_unref (o); +} + static void emit_notification(int x, int y) { @@ -40,47 +50,51 @@ emit_notification(int x, int y) notify_notification_set_hint_int32 (n, "x", x); notify_notification_set_hint_int32 (n, "y", y); + g_signal_connect (n, "closed", _handle_closed, NULL); + if (!notify_notification_show (n, NULL)) { fprintf(stderr, "failed to send notification\n"); return 1; } } -int -main(int argc, char **argv) +static gboolean +_popup_random_bubble (void) { GdkDisplay *display; GdkScreen *screen; + int screen_x2, screen_y2; - - gdk_init(&argc, &argv); - - notify_init("XY"); + int x, y; display = gdk_display_get_default(); screen = gdk_display_get_default_screen(display); screen_x2 = gdk_screen_get_width(screen) - 1; screen_y2 = gdk_screen_get_height(screen) - 1; - emit_notification(0, 0); - g_usleep (1000000); - emit_notification(screen_x2, 0); - g_usleep (1000000); - emit_notification(5, 150); - g_usleep (1000000); - emit_notification(screen_x2 - 5, 150); - g_usleep (1000000); - emit_notification(0, screen_y2 / 2); - g_usleep (1000000); - emit_notification(screen_x2, screen_y2 / 2); - g_usleep (1000000); - emit_notification(5, screen_y2 - 150); - g_usleep (1000000); - emit_notification(screen_x2 - 5, screen_y2 - 150); - g_usleep (1000000); - emit_notification(0, screen_y2); - g_usleep (1000000); - emit_notification(screen_x2, screen_y2); + x = g_random_int_range (0, screen_x2); + y = g_random_int_range (0, screen_y2); + emit_notification(x, y); - return 0; + return TRUE; +} + +int +main(int argc, char **argv) +{ + GMainLoop *loop; + DBusConnection *conn; + + gdk_init(&argc, &argv); + + notify_init("XY"); + + conn = dbus_bus_get (DBUS_BUS_SESSION, NULL); + + dbus_connection_setup_with_g_main (conn, NULL); + + g_timeout_add (1000, _popup_random_bubble, NULL); + + loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (loop); } diff --git a/tests/test-xy.c b/tests/test-xy.c index f9daf8e..612a04f 100644 --- a/tests/test-xy.c +++ b/tests/test-xy.c @@ -32,7 +32,7 @@ int main() { "This notification should point to 150, 10", NULL, NULL); - notify_notification_set_hint_int32 (n, "x", 150); + notify_notification_set_hint_int32 (n, "x", 30); notify_notification_set_hint_int32 (n, "y", 10); if (!notify_notification_show (n, NULL)) {