static void
enterprise_add_user (UmAccountDialog *self)
{
        GtkTreeIter iter;

        begin_action (self);

        g_clear_object (&self->selected_realm);
        self->join_prompted = FALSE;

        /* Already know about this realm, try to login as user */
        if (gtk_combo_box_get_active_iter (self->enterprise_domain, &iter)) {
                gtk_tree_model_get (gtk_combo_box_get_model (self->enterprise_domain),
                                    &iter, 1, &self->selected_realm, -1);
                enterprise_check_login (self);

        /* Something the user typed, we need to discover realm */
        } else {
                um_realm_manager_discover (self->realm_manager,
                                           gtk_entry_get_text (self->enterprise_domain_entry),
                                           self->cancellable,
                                           on_realm_discover_input,
                                           g_object_ref (self));
        }
}
static void
on_realm_discover_input (GObject *source,
                         GAsyncResult *result,
                         gpointer user_data)
{
  GisAccountPageEnterprise *page = user_data;
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  GError *error = NULL;
  GList *realms;

  realms = um_realm_manager_discover_finish (priv->realm_manager,
                                             result, &error);

  /* Found a realm, log user into domain */
  if (error == NULL) {
    g_assert (realms != NULL);
    priv->realm = g_object_ref (realms->data);
    enterprise_check_login (page);
    g_list_free_full (realms, g_object_unref);

  } else {
    /* The domain is likely invalid */
    g_dbus_error_strip_remote_error (error);
    g_message ("Couldn't discover domain: %s", error->message);
    gtk_widget_grab_focus (priv->domain_entry);
    set_entry_validation_error (GTK_ENTRY (priv->domain_entry), error->message);
    apply_complete (page, FALSE);
    g_error_free (error);
  }
}
static void
on_realm_discover_input (GObject *source,
                         GAsyncResult *result,
                         gpointer user_data)
{
        UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
        GError *error = NULL;
        GList *realms;

        realms = um_realm_manager_discover_finish (self->realm_manager,
                                                   result, &error);

        /* Found a realm, log user into domain */
        if (error == NULL) {
                g_assert (realms != NULL);
                self->selected_realm = g_object_ref (realms->data);
                enterprise_check_login (self);
                g_list_free_full (realms, g_object_unref);

        /* The domain is likely invalid*/
        } else {
                finish_action (self);
                g_message ("Couldn't discover domain: %s", error->message);
                gtk_widget_grab_focus (GTK_WIDGET (self->enterprise_domain_entry));
                g_dbus_error_strip_remote_error (error);
                set_entry_validation_error (self->enterprise_domain_entry,
                                            error->message);
                g_error_free (error);
        }

        g_object_unref (self);
}
static void
enterprise_add_user (GisAccountPageEnterprise *page)
{
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  GtkTreeIter iter;

  priv->join_prompted = FALSE;
  g_clear_object (&priv->realm);

  /* Already know about this realm, try to login as user */
  if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->domain), &iter)) {
    gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (priv->domain)),
                        &iter, 1, &priv->realm, -1);
    enterprise_check_login (page);

    /* Something the user typed, we need to discover realm */
  } else {
    um_realm_manager_discover (priv->realm_manager,
                               gtk_entry_get_text (GTK_ENTRY (priv->domain_entry)),
                               priv->cancellable,
                               on_realm_discover_input,
                               page);
  }
}