[Galago-commits] r1995 - in trunk/libnotify: . libnotify tests tools

galago-commits at freedesktop.org galago-commits at freedesktop.org
Thu Jun 30 23:42:35 PDT 2005


Author: chipx86
Date: 2005-06-30 23:42:29 -0700 (Thu, 30 Jun 2005)
New Revision: 1995

Added:
   trunk/libnotify/tests/test-xy.c
Modified:
   trunk/libnotify/ChangeLog
   trunk/libnotify/libnotify/notify.c
   trunk/libnotify/libnotify/notify.h
   trunk/libnotify/tests/
   trunk/libnotify/tests/Makefile.am
   trunk/libnotify/tests/test-animation.c
   trunk/libnotify/tests/test-basic.c
   trunk/libnotify/tests/test-default-action.c
   trunk/libnotify/tests/test-error.c
   trunk/libnotify/tests/test-image.c
   trunk/libnotify/tests/test-markup.c
   trunk/libnotify/tests/test-multi-actions.c
   trunk/libnotify/tests/test-replace.c
   trunk/libnotify/tools/notify-send.c
Log:
A few things I did on the way home:
- Added support for hints in the API.
- Don't install the test programs during make install.


Modified: trunk/libnotify/ChangeLog
===================================================================
--- trunk/libnotify/ChangeLog	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/ChangeLog	2005-07-01 06:42:29 UTC (rev 1995)
@@ -1,3 +1,23 @@
+Thu Jun 30 21:09:18 PDT 2005  Christian Hammond <chipx86 at chipx86.com>
+
+	* tests/Makefile.am:
+	  - Don't install the test programs during make install.
+
+Thu Jun 30 21:03:30 PDT 2005  Christian Hammond <chipx86 at chipx86.com>
+
+	* libnotify/notify.c:
+	* libnotify/notify.h:
+	* tests/test-animation.c:
+	* tests/test-basic.c:
+	* tests/test-default-action.c:
+	* tests/test-error.c:
+	* tests/test-image.c:
+	* tests/test-markup.c:
+	* tests/test-multi-actions.c:
+	* tests/test-replace.c:
+	* tools/notify-send.c:
+	  - Added support for hints in the API.
+
 Mon Jun 20 06:13:02 PDT 2005  Christian Hammond <chipx86 at gnupdate.org>
 
 	* libnotify/notify.c:

Modified: trunk/libnotify/libnotify/notify.c
===================================================================
--- trunk/libnotify/libnotify/notify.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/libnotify/notify.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -508,7 +508,39 @@
 	return caps;
 }
 
+
 /**************************************************************************
+ * Notify Hints API
+ **************************************************************************/
+
+NotifyHints *
+notify_hints_new(void)
+{
+	return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+}
+
+void
+notify_hints_set_string(NotifyHints *hints, const char *key,
+						const char *value)
+{
+	g_return_if_fail(hints != NULL);
+	g_return_if_fail(key != NULL && *key != '\0');
+	g_return_if_fail(value != NULL && *value != '\0');
+
+	g_hash_table_replace(hints, g_strdup(key), g_strdup(value));
+}
+
+void
+notify_hints_set_int(NotifyHints *hints, const char *key, int value)
+{
+	g_return_if_fail(hints != NULL);
+	g_return_if_fail(key != NULL && *key != '\0');
+
+	g_hash_table_replace(hints, g_strdup(key), g_strdup_printf("%d", value));
+}
+
+
+/**************************************************************************
  * Icon API
  **************************************************************************/
 
@@ -616,7 +648,8 @@
 						 NotifyUrgency urgency, const char *summary,
 						 const char *body, const NotifyIcon *icon,
 						 gboolean expires, time_t timeout,
-						 gpointer user_data, size_t action_count, ...)
+						 GHashTable *hints, gpointer user_data,
+						 size_t action_count, ...)
 {
 	va_list actions;
 	NotifyHandle *handle;
@@ -626,20 +659,37 @@
 	va_start(actions, action_count);
 	handle = notify_send_notification_varg(replaces, type, urgency, summary,
 										   body, icon, expires,
-										   timeout, user_data,
+										   timeout, hints, user_data,
 										   action_count, actions);
 	va_end(actions);
 
 	return handle;
 }
 
+static void
+hint_foreach_func(const gchar *key, const gchar *value, DBusMessageIter *iter)
+{
+#if NOTIFY_CHECK_DBUS_VERSION(0, 30)
+	DBusMessageIter entry_iter;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL,
+									 &entry_iter);
+	dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING, key);
+	dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING, value);
+	dbus_message_iter_close_container(iter, &entry_iter);
+#else
+	dbus_message_iter_append_dict_key(iter, key);
+	dbus_message_iter_append_string(iter, value);
+#endif
+}
+
 NotifyHandle *
 notify_send_notification_varg(NotifyHandle *replaces, const char *type,
 							  NotifyUrgency urgency, const char *summary,
 							  const char *body, const NotifyIcon *icon,
 							  gboolean expires, time_t timeout,
-							  gpointer user_data, size_t action_count,
-							  va_list actions)
+							  GHashTable *hints, gpointer user_data,
+							  size_t action_count, va_list actions)
 {
 	DBusMessage *message, *reply;
 	DBusMessageIter iter, array_iter, dict_iter;
@@ -769,11 +819,19 @@
 									 DBUS_TYPE_STRING_AS_STRING
 									 DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
 									 &dict_iter);
-	dbus_message_iter_close_container(&iter, &dict_iter);
 #else
 	dbus_message_iter_append_dict(&iter, &dict_iter);
 #endif
 
+	if (hints != NULL)
+	{
+		g_hash_table_foreach(hints, (GHFunc)hint_foreach_func, &dict_iter);
+	}
+
+#if NOTIFY_CHECK_DBUS_VERSION(0, 30)
+	dbus_message_iter_close_container(&iter, &dict_iter);
+#endif
+
 	/* Expires */
 	_notify_dbus_message_iter_append_boolean(&iter, expires);
 
@@ -805,6 +863,9 @@
 	dbus_message_unref(reply);
 	dbus_error_free(&error);
 
+	if (hints != NULL)
+		g_hash_table_destroy(hints);
+
 	handle = _notify_handle_new(id);
 	handle->actions_table = table;
 	handle->action_count  = action_count;

Modified: trunk/libnotify/libnotify/notify.h
===================================================================
--- trunk/libnotify/libnotify/notify.h	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/libnotify/notify.h	2005-07-01 06:42:29 UTC (rev 1995)
@@ -42,6 +42,7 @@
 
 typedef struct _NotifyHandle NotifyHandle;
 typedef struct _NotifyIcon   NotifyIcon;
+typedef GHashTable           NotifyHints;
 
 typedef void (*NotifyCallback)(NotifyHandle *, guint32, gpointer);
 
@@ -108,6 +109,40 @@
 /*@}*/
 
 /**************************************************************************/
+/** @name Hints API                                                       */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Creates a hints table.
+ *
+ * @return A hints table.
+ */
+NotifyHints *notify_hints_new(void);
+
+/**
+ * Adds a string value to the hints table.
+ *
+ * @param hints The hints table.
+ * @param key   The key.
+ * @param value The value.
+ */
+void notify_hints_set_string(NotifyHints *hints, const char *key,
+							 const char *value);
+
+/**
+ * Adds an integer value to the hints table.
+ *
+ * @param hints The hints table.
+ * @param key   The key.
+ * @param value The value.
+ */
+void notify_hints_set_int(NotifyHints *hints, const char *key, int value);
+
+/*@}*/
+
+
+/**************************************************************************/
 /** @name NotifyIcon API                                                  */
 /**************************************************************************/
 /*@{*/
@@ -206,6 +241,7 @@
  *                       or FALSE to keep it open until manually closed.
  * @param timeout        The optional timeout to automatically close the
  *                       notification, or 0 for the daemon's default.
+ * @param hints          A hashtable of hints.
  * @param user_data      User-specified data to send to a callback.
  * @param action_count   The number of actions.
  * @param ...            The actions in uint32/string/callback sets.
@@ -219,6 +255,7 @@
 									   const char *body,
 									   const NotifyIcon *icon,
 									   gboolean expires, time_t timeout,
+									   NotifyHints *hints,
 									   gpointer user_data,
 									   size_t action_count, ...);
 
@@ -241,6 +278,7 @@
  *                       or FALSE to keep it open until manually closed.
  * @param timeout        The optional timeout to automatically close the
  *                       notification, or 0 for the daemon's default.
+ * @param hints          A hashtable of hints.
  * @param user_data      User-specified data to send to a callback.
  * @param action_count   The number of actions.
  * @param actions        The actions in string/callback pairs.
@@ -255,6 +293,7 @@
 											const NotifyIcon *icon,
 											gboolean expires,
 											time_t timeout,
+											NotifyHints *hints,
 											gpointer user_data,
 											size_t action_count,
 											va_list actions);


Property changes on: trunk/libnotify/tests
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
test-animation
test-basic
test-default-action
test-error
test-image
test-markup
test-multi-actions
test-replace
.deps
.libs

   + Makefile
Makefile.in
core*
test-animation
test-basic
test-default-action
test-error
test-image
test-markup
test-multi-actions
test-replace
test-xy
.deps
.libs


Modified: trunk/libnotify/tests/Makefile.am
===================================================================
--- trunk/libnotify/tests/Makefile.am	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/Makefile.am	2005-07-01 06:42:29 UTC (rev 1995)
@@ -1,4 +1,13 @@
-bin_PROGRAMS = test-replace test-default-action test-multi-actions test-image test-basic test-error test-animation test-markup
+noinst_PROGRAMS = \
+	test-replace \
+	test-default-action \
+	test-multi-actions \
+	test-image \
+	test-basic \
+	test-error \
+	test-animation \
+	test-markup \
+	test-xy
 
 common_ldflags = \
 	$(top_builddir)/libnotify/libnotify.la \
@@ -26,4 +35,7 @@
 test_markup_SOURCES = test-markup.c
 test_markup_LDADD = $(common_ldflags)
 
+test_xy_SOURCES = test-xy.c
+test_xy_LDADD = $(common_ldflags)
+
 INCLUDES = $(PACKAGE_CFLAGS) `pkg-config --cflags gdk-pixbuf-2.0`

Modified: trunk/libnotify/tests/test-animation.c
===================================================================
--- trunk/libnotify/tests/test-animation.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-animation.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -93,6 +93,7 @@
 											   "Summary", "Content",
 											   icon,
 											   TRUE, time(NULL) + 5,
+											   NULL, // no hints
 											   NULL, // no user data
 											   0); // no actions
 

Modified: trunk/libnotify/tests/test-basic.c
===================================================================
--- trunk/libnotify/tests/test-basic.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-basic.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -32,6 +32,7 @@
 											   "Summary", "Content",
 											   NULL, // no icon
 											   TRUE, time(NULL) + 5,
+											   NULL, // no hints
 											   NULL, // no user data
 											   0); // no actions
 

Modified: trunk/libnotify/tests/test-default-action.c
===================================================================
--- trunk/libnotify/tests/test-default-action.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-default-action.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -60,6 +60,7 @@
 								 "Matt is online", NULL,
 								 NULL, // no icon
 								 FALSE, 0, // does not expire
+								 NULL, // no hints
 								 NULL, // no user data
 								 1,
 								 0, "default", callback); // 1 action

Modified: trunk/libnotify/tests/test-error.c
===================================================================
--- trunk/libnotify/tests/test-error.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-error.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -34,6 +34,7 @@
 											   "Summary", "Content",
 											   icon, // no icon
 											   TRUE, time(NULL) + 5,
+											   NULL, // no hints
 											   NULL, // no user data
 											   0);
 

Modified: trunk/libnotify/tests/test-image.c
===================================================================
--- trunk/libnotify/tests/test-image.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-image.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -56,6 +56,7 @@
 								 s, b,
 								 icon,
 								 TRUE, time(NULL) + 5,
+								 NULL, // no hints
 								 NULL, // no user data
 								 0);
 

Modified: trunk/libnotify/tests/test-markup.c
===================================================================
--- trunk/libnotify/tests/test-markup.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-markup.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -32,9 +32,10 @@
 		NOTIFY_URGENCY_NORMAL,
 		"Summary",
 		"Some <b>bold</b>, <u>underlined</u>, <i>italic</i>, "
-		"<a href='google.com'>linked</a> text",
+		"<a href='http://www.google.com'>linked</a> text",
 		NULL, // no icon
 		TRUE, time(NULL) + 5,
+		NULL, // no hints
 		NULL, // no user data
 		0); // no actions
 

Modified: trunk/libnotify/tests/test-multi-actions.c
===================================================================
--- trunk/libnotify/tests/test-multi-actions.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-multi-actions.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -71,6 +71,7 @@
 								 "emptying the trash can.",
 								 NULL, // no icon
 								 FALSE, 0, // does not expire
+								 NULL, // no hints
 								 NULL, // no user data
 								 3,	   // 3 actions
 								 0, "default", callback,

Modified: trunk/libnotify/tests/test-replace.c
===================================================================
--- trunk/libnotify/tests/test-replace.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-replace.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -32,6 +32,7 @@
 	                                           "Summary", "Content",
 	                                           NULL, // no icon
 	                                           FALSE, 0, // does not expire
+											   NULL, // no hints
 	                                           NULL, // no user data
 	                                           0); // no actions
 
@@ -41,12 +42,11 @@
 	}
 
 
-	sleep(3);
+	sleep(20);
 
 	notify_send_notification(n, NULL, NOTIFY_URGENCY_NORMAL,
 	                         "Second Summary", "Second Content",
-	                         NULL, TRUE, 5, NULL, 0);
+	                         NULL, TRUE, 5, NULL, NULL, 0);
 
 	return 0;
 }
-        

Added: trunk/libnotify/tests/test-xy.c
===================================================================
--- trunk/libnotify/tests/test-xy.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tests/test-xy.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -0,0 +1,53 @@
+/*
+ * @file tests/test-xy.c Unit test: X, Y hints
+ *
+ * @Copyright (C) 2005 Christian Hammond <chipx86 at chipx86.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA  02111-1307, USA.
+ */
+
+#include <libnotify/notify.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int main() {
+	GHashTable *hints;
+
+	notify_init("XY");
+
+	hints = notify_hints_new();
+	notify_hints_set_int(hints, "x", 150);
+	notify_hints_set_int(hints, "y", 10);
+
+	NotifyHandle *n = notify_send_notification(
+		NULL, // replaces nothing
+		NULL,
+		NOTIFY_URGENCY_NORMAL,
+		"X, Y Test",
+		"This notification should point to 150, 10.",
+		NULL, // no icon
+		TRUE, time(NULL) + 5,
+		hints,
+		NULL, // no user data
+		0); // no actions
+
+	if (!n) {
+		fprintf(stderr, "failed to send notification\n");
+		return 1;
+	}
+
+	return 0;
+}

Modified: trunk/libnotify/tools/notify-send.c
===================================================================
--- trunk/libnotify/tools/notify-send.c	2005-06-27 22:23:52 UTC (rev 1994)
+++ trunk/libnotify/tools/notify-send.c	2005-07-01 06:42:29 UTC (rev 1995)
@@ -126,7 +126,7 @@
 		exit(1);
 
 	notify_send_notification(NULL, type, urgency, summary, body, icon,
-							 TRUE, expire_timeout, NULL, 0);
+							 TRUE, expire_timeout, NULL, NULL, 0);
 
 	if (icon != NULL)
 		notify_icon_destroy(icon);



More information about the galago-commits mailing list