static void
proxy_new_cb (GObject *source,
              GAsyncResult *result,
              gpointer user_data)
{
    EmpathyWebcredentialsMonitor *self;
    TpWeakRef *wr = user_data;
    GError *error = NULL;

    self = tp_weak_ref_dup_object (wr);
    if (self == NULL)
        goto out;

    self->priv->proxy = g_dbus_proxy_new_for_bus_finish (result, &error);
    if (self->priv->proxy == NULL)
    {
        g_debug ("Failed to create webcredentials proxy: %s", error->message);
        g_error_free (error);
        goto out;
    }

    update_failures (self);

    g_signal_connect (self->priv->proxy, "g-properties-changed",
                      G_CALLBACK (properties_changed_cb), self);

out:
    tp_weak_ref_destroy (wr);
    g_clear_object (&self);
}
static void
manager_prepared_cb (GObject *source,
    GAsyncResult *result,
    gpointer user_data)
{
  TpWeakRef *wr = user_data;
  EmpathyAppPluginWidget *self = tp_weak_ref_dup_object (wr);
  TpAccountManager *manager = (TpAccountManager *) source;
  GList *accounts;
  GError *error = NULL;

  if (self == NULL)
    {
      tp_weak_ref_destroy (wr);
      return;
    }

  if (!tp_proxy_prepare_finish (manager, result, &error))
    {
      g_debug ("Error preparing Account Manager: %s", error->message);
      g_clear_error (&error);
      goto out;
    }

  accounts = tp_account_manager_dup_valid_accounts (manager);
  while (accounts != NULL)
    {
      TpAccount *account = accounts->data;
      const GValue *value;

      value = tp_account_get_storage_identifier (account);
      if (G_VALUE_HOLDS_UINT (value) &&
          g_value_get_uint (value) == self->priv->account->id)
        {
          GtkWidget *alig;

          alig = gtk_alignment_new (0.5, 0, 0, 0);
          self->priv->user_info = tpaw_user_info_new (account);
          gtk_container_add (GTK_CONTAINER (alig), self->priv->user_info);
          gtk_widget_show (self->priv->user_info);

          gtk_box_pack_start (GTK_BOX (self), alig, TRUE, TRUE, 0);
          gtk_widget_show (alig);
          break;
        }

      accounts = g_list_delete_link (accounts, accounts);
    }
  g_list_free_full (accounts, g_object_unref);

out:
  tp_weak_ref_destroy (wr);
  g_object_unref (self);
}
static void
fake_network_monitor_get_properties_cb (GObject *proxy,
    GAsyncResult *result,
    gpointer user_data)
{
  FakeNetworkMonitor *self = tp_weak_ref_dup_object (user_data);
  GVariant *tuple = NULL;
  GVariant *asv = NULL;
  const gchar *state;

  if (self == NULL)
    return;

  tuple = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, NULL);

  if (tuple == NULL)
    {
      DEBUG ("GetProperties() failed");
      goto finally;
    }

  if (!g_variant_is_of_type (tuple, G_VARIANT_TYPE ("(a{sv})")))
    {
      DEBUG ("GetProperties() returned wrong type");
      goto finally;
    }

  asv = g_variant_get_child_value (tuple, 0);

  if (g_variant_lookup (asv, "State", "&s", &state))
    {
      DEBUG ("Initial state: %s", state);
      fake_network_monitor_set_state (self, state);
    }
  else
    {
      DEBUG ("Failed to get initial state, not in GetProperties return");
      fake_network_monitor_set_state (self, "offline");
    }

finally:
  if (asv != NULL)
    g_variant_unref (asv);

  if (tuple != NULL)
    g_variant_unref (tuple);

  g_object_unref (self);
}