diff --git a/ChangeLog b/ChangeLog index 51fcdf7..49719df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Sun Jan 15 17:52:39 PST 2006 Christian Hammond + + * docs/notification-spec.xml: + * libnotify/notify.c: + * libnotify/notify.h: + * libnotify/notifynotification.c: + * tests/Makefile.am: + A tests/test-server-info.c: + * tests/test-xy.c: + - Add back notify_get_server_info() and notify_get_server_caps(). + Thu Jan 12 2006 John (J5) Palmieri * libnotify/notifynotification.c (notify_notification_set_user_data): diff --git a/docs/notification-spec.xml b/docs/notification-spec.xml index 484a212..ea4bd49 100644 --- a/docs/notification-spec.xml +++ b/docs/notification-spec.xml @@ -1033,11 +1033,13 @@ out STRING name out STRING vendor out STRING version + out STRING spec_version This message returns the information on the server. Specifically, - the server name, vendor, and version number. + the server name, vendor, version number, and specification version number + supported. GetServerInformation Return Values @@ -1068,6 +1070,11 @@ STRINGThe server's version number. + + spec_version + STRING + The supported specification version number. +
diff --git a/libnotify/notify.c b/libnotify/notify.c index 5efc785..2077448 100644 --- a/libnotify/notify.c +++ b/libnotify/notify.c @@ -40,6 +40,8 @@ static gboolean _initted = FALSE; static gchar *_app_name = NULL; +static DBusGProxy *_proxy = NULL; + #ifdef __GNUC__ # define format_func __attribute__((format(printf, 1, 2))) #else /* no format string checking with this compiler */ @@ -85,7 +87,7 @@ notify_init (const char *app_name) } const gchar * -_notify_get_app_name (void) +notify_get_app_name (void) { return _app_name; } @@ -108,3 +110,83 @@ notify_is_initted (void) { return _initted; } + +static DBusGProxy * +get_proxy(void) +{ + DBusGConnection *bus; + GError *error = NULL; + + if (_proxy != NULL) + return _proxy; + + bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + + if (error != NULL) + { + g_message("Unable to get session bus: %s", error->message); + g_error_free(error); + return NULL; + } + + _proxy = dbus_g_proxy_new_for_name(bus, + NOTIFY_DBUS_NAME, + NOTIFY_DBUS_CORE_OBJECT, + NOTIFY_DBUS_CORE_INTERFACE); + dbus_g_connection_unref(bus); + + return _proxy; +} + +GList * +notify_get_server_caps(void) +{ + GError *error = NULL; + char **caps = NULL, **cap; + GList *result = NULL; + DBusGProxy *proxy = get_proxy(); + + g_return_val_if_fail(proxy != NULL, NULL); + + if (!dbus_g_proxy_call(proxy, "GetCapabilities", &error, + G_TYPE_INVALID, + G_TYPE_STRV, &caps, G_TYPE_INVALID)) + { + g_message("GetCapabilities call failed: %s", error->message); + g_error_free(error); + return NULL; + } + + for (cap = caps; *cap != NULL; cap++) + { + result = g_list_append(result, g_strdup(*cap)); + } + + g_strfreev(caps); + + return result; +} + +gboolean +notify_get_server_info(char **ret_name, char **ret_vendor, + char **ret_version, char **ret_spec_version) +{ + GError *error = NULL; + DBusGProxy *proxy = get_proxy(); + + g_return_val_if_fail(proxy != NULL, FALSE); + + if (!dbus_g_proxy_call(proxy, "GetServerInformation", &error, + G_TYPE_INVALID, + G_TYPE_STRING, ret_name, + G_TYPE_STRING, ret_vendor, + G_TYPE_STRING, ret_version, + G_TYPE_STRING, ret_spec_version, + G_TYPE_INVALID)) + { + g_message("GetServerInformation call failed: %s", error->message); + return FALSE; + } + + return TRUE; +} diff --git a/libnotify/notify.h b/libnotify/notify.h index 017cb19..2b07e34 100644 --- a/libnotify/notify.h +++ b/libnotify/notify.h @@ -18,9 +18,6 @@ * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. - * - * @todo We talk about URIs, but they are actually file paths not URIs - * @todo Un-glibify? */ #ifndef _LIBNOTIFY_NOTIFY_H_ @@ -61,8 +58,30 @@ void notify_uninit(void); */ gboolean notify_is_initted(void); -const gchar *_notify_get_app_name(void); +const gchar *notify_get_app_name(void); + +/** + * Returns the capabilities of the notification server. + * + * @return A list of capability strings. These strings must be freed. + */ +GList *notify_get_server_caps(void); + +/** + * Returns the server notification information. + * + * The strings returned must be freed. + * + * @param ret_name The returned product name of the server. + * @param ret_vendor The returned vendor. + * @param ret_version The returned server version. + * @param ret_spec_ver The returned specification version supported. + * + * @return TRUE if the call succeeded, or FALSE if there were errors. + */ +gboolean notify_get_server_info(char **ret_name, char **ret_vendor, + char **ret_version, char **ret_spec_version); + /*@}*/ - #endif /* _LIBNOTIFY_NOTIFY_H_ */ diff --git a/libnotify/notifynotification.c b/libnotify/notifynotification.c index 57635eb..bcbb0c7 100644 --- a/libnotify/notifynotification.c +++ b/libnotify/notifynotification.c @@ -530,7 +530,7 @@ _notify_notification_show_internal (NotifyNotification *notification, /*TODO: make this nonblocking */ if (!ignore_reply) dbus_g_proxy_call (priv->proxy, "Notify", &tmp_error, - G_TYPE_STRING, _notify_get_app_name (), + G_TYPE_STRING, notify_get_app_name (), G_TYPE_STRING, (priv->icon_name != NULL) ? priv->icon_name : "", G_TYPE_UINT, priv->id, G_TYPE_STRING, priv->summary, @@ -543,7 +543,7 @@ _notify_notification_show_internal (NotifyNotification *notification, G_TYPE_UINT, &priv->id, G_TYPE_INVALID); else dbus_g_proxy_call_no_reply (priv->proxy, "Notify", - G_TYPE_STRING, _notify_get_app_name (), + G_TYPE_STRING, notify_get_app_name (), G_TYPE_STRING, (priv->icon_name != NULL) ? priv->icon_name : "", G_TYPE_UINT, priv->id, G_TYPE_STRING, priv->summary, diff --git a/tests/Makefile.am b/tests/Makefile.am index 9f4195a..4b8b9a3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -10,6 +10,7 @@ endif noinst_PROGRAMS = \ test-replace \ test-replace-widget \ + test-server-info \ test-default-action \ test-multi-actions \ test-image \ @@ -26,16 +27,25 @@ common_ldflags = \ test_replace_SOURCES = test-replace.c test_replace_LDADD = $(common_ldflags) + test_replace_widget_SOURCES = test-replace-widget.c test_replace_widget_LDADD = $(common_ldflags) + +test_server_info_SOURCES = test-server-info.c +test_server_info_LDADD = $(common_ldflags) + test_default_action_SOURCES = test-default-action.c test_default_action_LDADD = $(common_ldflags) + test_multi_actions_SOURCES = test-multi-actions.c test_multi_actions_LDADD = $(common_ldflags) + test_image_SOURCES = test-image.c test_image_LDADD = $(common_ldflags) + test_basic_SOURCES = test-basic.c test_basic_LDADD = $(common_ldflags) + test_error_SOURCES = test-error.c test_error_LDADD = $(common_ldflags) diff --git a/tests/test-server-info.c b/tests/test-server-info.c new file mode 100644 index 0000000..643cf33 --- /dev/null +++ b/tests/test-server-info.c @@ -0,0 +1,60 @@ +/* + * @file tests/test-server-info.c Retrieves the server info and caps + * + * @Copyright (C) 2004 Mike Hearn + * + * 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 +#include +#include + +int +main(int argc, char **argv) +{ + notify_init("TestCaps"); + GList *l, *caps; + char *name, *vendor, *version, *spec_version; + + if (!notify_get_server_info(&name, &vendor, &version, &spec_version)) + { + fprintf(stderr, "Failed to receive server info.\n"); + exit(1); + } + + printf("Name: %s\n", name); + printf("Vendor: %s\n", vendor); + printf("Version: %s\n", version); + printf("Spec Version: %s\n", spec_version); + printf("Capabilities:\n"); + + caps = notify_get_server_caps(); + + if (caps == NULL) + { + fprintf(stderr, "Failed to receive server caps.\n"); + exit(1); + } + + for (l = caps; l != NULL; l = l->next) + printf("\t%s\n", (char *)l->data); + + g_list_foreach(caps, (GFunc)g_free, NULL); + g_list_free(caps); + + return 0; +} diff --git a/tests/test-xy.c b/tests/test-xy.c index 612a04f..f9daf8e 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", 30); + notify_notification_set_hint_int32 (n, "x", 150); notify_notification_set_hint_int32 (n, "y", 10); if (!notify_notification_show (n, NULL)) {