summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hammond <chipx86@chipx86.com>2005-07-27 08:11:33 +0000
committerChristian Hammond <chipx86@chipx86.com>2005-07-27 08:11:33 +0000
commit12f74a149cfd3d317aa03e08caf6236bdc718c1a (patch)
tree096cd857f208e081b7863bf236240836c0a9c12b
parent56cdbb708775d9509aaf938fa376efea0e0b4165 (diff)
downloadlibnotify-12f74a149cfd3d317aa03e08caf6236bdc718c1a.tar.gz
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.
-rw-r--r--ChangeLog11
-rw-r--r--libnotify/notify.c18
-rw-r--r--libnotify/notify.h22
-rw-r--r--tests/test-default-action.c6
-rw-r--r--tests/test-image.c15
-rw-r--r--tests/test-multi-actions.c10
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 <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>
* 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 <dbus/dbus.h>
#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -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)
{
@@ -387,6 +399,12 @@ notify_is_initted(void)
}
void
+notify_setup_with_g_main(GMainContext *context)
+{
+ dbus_connection_setup_with_g_main(_dbus_conn, context);
+}
+
+void
notify_close(NotifyHandle *handle)
{
DBusMessage *message;
diff --git a/libnotify/notify.h b/libnotify/notify.h
index d31f3c2..8b23058 100644
--- a/libnotify/notify.h
+++ b/libnotify/notify.h
@@ -62,6 +62,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.
*
* This will be automatically called on exit unless previously called.
@@ -76,6 +88,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.
*
* @param handle The notification handle.
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",