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.

This commit is contained in:
Christian Hammond 2005-07-27 08:11:33 +00:00
parent 56cdbb7087
commit 12f74a149c
6 changed files with 67 additions and 15 deletions

View File

@ -1,3 +1,14 @@
Wed Jul 27 01:08:56 PDT 2005 Christian Hammond <chipx86@chipx86.com>
* 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 <chipx86@chipx86.com> Wed Jul 27 00:51:58 PDT 2005 Christian Hammond <chipx86@chipx86.com>
* tests/test-animation.c: * tests/test-animation.c:

View File

@ -33,6 +33,7 @@
#include "dbus-compat.h" #include "dbus-compat.h"
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
@ -356,6 +357,17 @@ notify_init(const char *app_name)
return TRUE; 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 void
notify_uninit(void) notify_uninit(void)
{ {
@ -386,6 +398,12 @@ notify_is_initted(void)
return _initted; return _initted;
} }
void
notify_setup_with_g_main(GMainContext *context)
{
dbus_connection_setup_with_g_main(_dbus_conn, context);
}
void void
notify_close(NotifyHandle *handle) notify_close(NotifyHandle *handle)
{ {

View File

@ -61,6 +61,18 @@ typedef void (*NotifyCallback)(NotifyHandle *, guint32, gpointer);
*/ */
gboolean notify_init(const char *app_name); 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. * Uninitializes the notifications library.
* *
@ -75,6 +87,16 @@ void notify_uninit(void);
*/ */
gboolean notify_is_initted(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. * Manually closes a notification.
* *

View File

@ -47,12 +47,10 @@ static void callback(NotifyHandle *handle, guint32 uid, void *user_data)
int int
main() 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); 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 n = notify_send_notification(NULL, // replaces nothing
"presence.online", "presence.online",

View File

@ -68,15 +68,18 @@ static void send(char *i, size_t rawlen, char *s, char *b)
notify_icon_destroy(icon); notify_icon_destroy(icon);
} }
int main() { int
if (!notify_init("Images Test")) exit(1); main(int argc, char **argv)
{
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
loop = g_main_loop_new(NULL, FALSE); 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", send("gnome-starthere",
0, 0,

View File

@ -55,13 +55,13 @@ static void callback(NotifyHandle *handle, guint32 uid, void *user_data)
g_main_loop_quit(loop); g_main_loop_quit(loop);
} }
int main() { int
if (!notify_init("Multi Action Test")) exit(1); main(int argc, char **argv)
{
DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
loop = g_main_loop_new(NULL, FALSE); 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 n = notify_send_notification(NULL, // replaces nothing
"device", "device",