From 12f74a149cfd3d317aa03e08caf6236bdc718c1a Mon Sep 17 00:00:00 2001 From: Christian Hammond Date: Wed, 27 Jul 2005 08:11:33 +0000 Subject: [PATCH] Patch (bug #3734) by Duarte Henriques to provide a convenient way of integrating libnotify with the glib mainloop. Modifications by me to make it even easier. --- ChangeLog | 11 +++++++++++ libnotify/notify.c | 18 ++++++++++++++++++ libnotify/notify.h | 22 ++++++++++++++++++++++ tests/test-default-action.c | 6 ++---- tests/test-image.c | 15 +++++++++------ tests/test-multi-actions.c | 10 +++++----- 6 files changed, 67 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f1dbd4..870954a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Wed Jul 27 01:08:56 PDT 2005 Christian Hammond + + * libnotify/notify.c: + * libnotify/notify.h: + * tests/test-default-action.c: + * tests/test-image.c: + * tests/test-multi-actions.c: + - Patch (bug #3734) by Duarte Henriques to provide a convenient way + of integrating libnotify with the glib mainloop. Modifications by + me to make it even easier. + Wed Jul 27 00:51:58 PDT 2005 Christian Hammond * tests/test-animation.c: diff --git a/libnotify/notify.c b/libnotify/notify.c index 920af35..4827103 100644 --- a/libnotify/notify.c +++ b/libnotify/notify.c @@ -33,6 +33,7 @@ #include "dbus-compat.h" #include #include +#include #include #include #include @@ -356,6 +357,17 @@ notify_init(const char *app_name) return TRUE; } +gboolean +notify_glib_init(const char *app_name, GMainContext *context) +{ + if (!notify_init(app_name)) + return FALSE; + + notify_setup_with_g_main(context); + + return TRUE; +} + void notify_uninit(void) { @@ -386,6 +398,12 @@ notify_is_initted(void) return _initted; } +void +notify_setup_with_g_main(GMainContext *context) +{ + dbus_connection_setup_with_g_main(_dbus_conn, context); +} + void notify_close(NotifyHandle *handle) { diff --git a/libnotify/notify.h b/libnotify/notify.h index d31f3c2..8b23058 100644 --- a/libnotify/notify.h +++ b/libnotify/notify.h @@ -61,6 +61,18 @@ typedef void (*NotifyCallback)(NotifyHandle *, guint32, gpointer); */ gboolean notify_init(const char *app_name); +/** + * Initializes the notifications library and sets it up with the + * glib mainloop. + * + * @param app_name The application name. + * @param context The mainloop context, or NULL for the default. + * + * @return TRUE if the library initialized properly and a connection to a + * notification server was made. + */ +gboolean notify_glib_init(const char *app_name, GMainContext *context); + /** * Uninitializes the notifications library. * @@ -75,6 +87,16 @@ void notify_uninit(void); */ gboolean notify_is_initted(void); +/** + * Sets up libnotify with the glib mainloop. + * + * This is usually best done by simply calling notify_glib_init(). However, + * there's no harm in calling this yourself. + * + * @param context the #GMainContext or NULL for default context + */ +void notify_setup_with_g_main(GMainContext *context); + /** * Manually closes a notification. * diff --git a/tests/test-default-action.c b/tests/test-default-action.c index 3f0a2ca..db53fdd 100644 --- a/tests/test-default-action.c +++ b/tests/test-default-action.c @@ -47,12 +47,10 @@ static void callback(NotifyHandle *handle, guint32 uid, void *user_data) int main() { - if (!notify_init("Default Action Test")) exit(1); - - DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL); loop = g_main_loop_new(NULL, FALSE); - dbus_connection_setup_with_g_main(conn, NULL); + if (!notify_glib_init("Default Action Test", NULL)) + exit(1); n = notify_send_notification(NULL, // replaces nothing "presence.online", diff --git a/tests/test-image.c b/tests/test-image.c index 566ef61..e012f90 100644 --- a/tests/test-image.c +++ b/tests/test-image.c @@ -68,15 +68,18 @@ static void send(char *i, size_t rawlen, char *s, char *b) notify_icon_destroy(icon); } -int main() { - if (!notify_init("Images Test")) exit(1); - - DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL); +int +main(int argc, char **argv) +{ loop = g_main_loop_new(NULL, FALSE); - dbus_connection_setup_with_g_main(conn, NULL); + if (!notify_glib_init("Images Test", NULL)) + exit(1); - // these images exist on fedora core 2 workstation profile. might not on yours + /* + * These images exist on fedora core 2 workstation profile. + * Might not on yours + */ send("gnome-starthere", 0, diff --git a/tests/test-multi-actions.c b/tests/test-multi-actions.c index 2aa4cc8..dd82543 100644 --- a/tests/test-multi-actions.c +++ b/tests/test-multi-actions.c @@ -55,13 +55,13 @@ static void callback(NotifyHandle *handle, guint32 uid, void *user_data) g_main_loop_quit(loop); } -int main() { - if (!notify_init("Multi Action Test")) exit(1); - - DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL); +int +main(int argc, char **argv) +{ loop = g_main_loop_new(NULL, FALSE); - dbus_connection_setup_with_g_main(conn, NULL); + if (!notify_glib_init("Multi Action Test", NULL)) + exit(1); n = notify_send_notification(NULL, // replaces nothing "device",