appmonitor test: avoid /usr/share
[platform/upstream/glib.git] / gio / tests / gdbus-example-proxy-subclass.c
index 6c09909..fb1a528 100644 (file)
@@ -160,7 +160,7 @@ accounts_user_get_user_name (AccountsUser *user)
   GVariant *value;
   const gchar *ret;
   g_return_val_if_fail (ACCOUNTS_IS_USER (user), NULL);
-  value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user), "UserName", NULL);
+  value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user), "UserName");
   ret = g_variant_get_string (value, NULL);
   g_variant_unref (value);
   return ret;
@@ -172,7 +172,7 @@ accounts_user_get_real_name (AccountsUser *user)
   GVariant *value;
   const gchar *ret;
   g_return_val_if_fail (ACCOUNTS_IS_USER (user), NULL);
-  value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user), "RealName", NULL);
+  value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user), "RealName");
   ret = g_variant_get_string (value, NULL);
   g_variant_unref (value);
   return ret;
@@ -184,7 +184,7 @@ accounts_user_get_automatic_login (AccountsUser *user)
   GVariant *value;
   gboolean ret;
   g_return_val_if_fail (ACCOUNTS_IS_USER (user), FALSE);
-  value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user), "AutomaticLogin", NULL);
+  value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user), "AutomaticLogin");
   ret = g_variant_get_boolean (value);
   g_variant_unref (value);
   return ret;
@@ -202,27 +202,27 @@ accounts_user_g_signal (GDBusProxy   *proxy,
 }
 
 static void
-accounts_user_g_properties_changed (GDBusProxy *proxy,
-                                    GVariant   *changed_properties)
+accounts_user_g_properties_changed (GDBusProxy          *proxy,
+                                    GVariant            *changed_properties,
+                                    const gchar* const  *invalidated_properties)
 {
   AccountsUser *user = ACCOUNTS_USER (proxy);
   GVariantIter *iter;
-  GVariant *item;
+  const gchar *key;
 
-  g_variant_get (changed_properties, "a{sv}", &iter);
-  while ((item = g_variant_iter_next_value (iter)) != NULL)
+  if (changed_properties != NULL)
     {
-      const gchar *key;
-      g_variant_get (item,
-                     "{sv}",
-                     &key,
-                     NULL);
-      if (g_strcmp0 (key, "AutomaticLogin") == 0)
-        g_object_notify (G_OBJECT (user), "automatic-login");
-      else if (g_strcmp0 (key, "RealName") == 0)
-        g_object_notify (G_OBJECT (user), "real-name");
-      else if (g_strcmp0 (key, "UserName") == 0)
-        g_object_notify (G_OBJECT (user), "user-name");
+      g_variant_get (changed_properties, "a{sv}", &iter);
+      while (g_variant_iter_next (iter, "{&sv}", &key, NULL))
+        {
+          if (g_strcmp0 (key, "AutomaticLogin") == 0)
+            g_object_notify (G_OBJECT (user), "automatic-login");
+          else if (g_strcmp0 (key, "RealName") == 0)
+            g_object_notify (G_OBJECT (user), "real-name");
+          else if (g_strcmp0 (key, "UserName") == 0)
+            g_object_notify (G_OBJECT (user), "user-name");
+        }
+      g_variant_iter_free (iter);
     }
 }
 
@@ -304,7 +304,6 @@ accounts_user_frobnicate_sync (AccountsUser        *user,
   if (value != NULL)
     {
       g_variant_get (value, "(s)", &ret);
-      ret = g_strdup (ret);
       g_variant_unref (value);
     }
   return ret;
@@ -345,99 +344,15 @@ accounts_user_frobnicate_finish (AccountsUser        *user,
   if (value != NULL)
     {
       g_variant_get (value, "(s)", &ret);
-      ret = g_strdup (ret);
       g_variant_unref (value);
     }
   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_proxy_appeared (GDBusConnection *connection,
-                   const gchar     *name,
-                   const gchar     *name_owner,
-                   GDBusProxy      *proxy,
-                   gpointer         user_data)
-{
-  AccountsUser *user = ACCOUNTS_USER (proxy);
-
-  g_print ("+++ Acquired proxy for user\n");
-  print_user (user);
-
-  g_signal_connect (proxy,
-                    "notify",
-                    G_CALLBACK (on_notify),
-                    NULL);
-  g_signal_connect (user,
-                    "changed",
-                    G_CALLBACK (on_changed),
-                    NULL);
-}
-
-static void
-on_proxy_vanished (GDBusConnection *connection,
-                   const gchar     *name,
-                   gpointer         user_data)
-{
-  g_print ("--- Cannot create proxy for user: no remote object\n");
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
 
 gint
 main (gint argc, gchar *argv[])
 {
-  guint watcher_id;
-  GMainLoop *loop;
-
-  g_type_init ();
-
-  watcher_id = g_bus_watch_proxy (G_BUS_TYPE_SYSTEM,
-                                  "org.freedesktop.Accounts",
-                                  G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
-                                  "/org/freedesktop/Accounts/User500",
-                                  "org.freedesktop.Accounts.User",
-                                  ACCOUNTS_TYPE_USER,
-                                  G_DBUS_PROXY_FLAGS_NONE,
-                                  on_proxy_appeared,
-                                  on_proxy_vanished,
-                                  NULL,
-                                  NULL);
-
-  loop = g_main_loop_new (NULL, FALSE);
-  g_main_loop_run (loop);
-  g_main_loop_unref (loop);
-  g_bus_unwatch_proxy (watcher_id);
-
   return 0;
 }