From 8d7c1f9b7524dd1ad60fa1727b28c480ed6bd91d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 18 Jul 2010 19:24:23 -0400 Subject: [PATCH] tests: Finish update of gdbus-example-proxy-subclass to new GDBus API This fixes bug #624696. Incorporates a more recent change from 1dc774a653e992e1 to drop the `g_type_init()` call, and reformats the indentation a bit. Fixes: #322 --- gio/tests/gdbus-example-proxy-subclass.c | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/gio/tests/gdbus-example-proxy-subclass.c b/gio/tests/gdbus-example-proxy-subclass.c index 05314ba2a..91b377c48 100644 --- a/gio/tests/gdbus-example-proxy-subclass.c +++ b/gio/tests/gdbus-example-proxy-subclass.c @@ -339,10 +339,112 @@ accounts_user_frobnicate_finish (AccountsUser *user, return ret; } +/* ---------------------------------------------------------------------------------------------------- */ +/* Example usage of the AccountsUser type */ +/* ---------------------------------------------------------------------------------------------------- */ + +static void +print_user (AccountsUser *user) +{ + g_print (" user-name = `%s'\n", accounts_user_get_user_name (user)); + g_print (" real-name = `%s'\n", accounts_user_get_real_name (user)); + g_print (" automatic-login = %s\n", accounts_user_get_automatic_login (user) ? "true" : "false"); +} + +static void +on_changed (AccountsUser *user, + gpointer user_data) +{ + g_print ("+++ Received the AccountsUser::changed signal\n"); + print_user (user); +} + +static void +on_notify (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + AccountsUser *user = ACCOUNTS_USER (object); + g_print ("+++ Received the GObject::notify signal for property `%s'\n", + pspec->name); + print_user (user); +} + +static void +on_accounts_proxy_available (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + GObject *user_object; + AccountsUser *user; + + user_object = g_async_initable_new_finish (G_ASYNC_INITABLE (object), + result, + &error); + if (!user_object) + { + g_error ("Failed to create proxy: %s", error->message); + g_clear_error (&error); + return; + } + user = ACCOUNTS_USER (user_object); + + g_print ("+++ Acquired proxy for user\n"); + print_user (user); + + g_signal_connect (user, + "notify", + G_CALLBACK (on_notify), + NULL); + g_signal_connect (user, + "changed", + G_CALLBACK (on_changed), + NULL); +} + +static void +on_accounts_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data) +{ + g_async_initable_new_async (ACCOUNTS_TYPE_USER, 0, NULL, + on_accounts_proxy_available, + "g-flags", 0, + "g-interface-info", NULL, + "g-unique-bus-name", name_owner, + "g-connection", connection, + "g-object-path", "/org/freedesktop/Accounts/User500", + "g-interface-name", "org.freedesktop.Accounts.User"); +} + +static void +on_accounts_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ +} + /* ---------------------------------------------------------------------------------------------------- */ gint main (gint argc, gchar *argv[]) { + guint watcher_id; + GMainLoop *loop; + + watcher_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM, + "org.freedesktop.Accounts", + G_BUS_NAME_WATCHER_FLAGS_AUTO_START, + on_accounts_appeared, + on_accounts_vanished, + NULL, NULL); + + loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (loop); + g_main_loop_unref (loop); + g_bus_unwatch_name (watcher_id); + return 0; }