[gnome-initial-setup] Update add accounts goa dialog
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup] Update add accounts goa dialog
- Date: Thu, 29 Aug 2013 20:13:35 +0000 (UTC)
commit 0bfd349d941eab0b160787b3d26959be8cf1f2bc
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Aug 5 11:55:58 2013 -0400
Update add accounts goa dialog
Copy/paste from gnome-control-center.
.../goa/cc-online-accounts-add-account-dialog.c | 377 ++++++++++++++------
.../goa/cc-online-accounts-add-account-dialog.h | 4 +
2 files changed, 263 insertions(+), 118 deletions(-)
---
diff --git a/gnome-initial-setup/pages/goa/cc-online-accounts-add-account-dialog.c
b/gnome-initial-setup/pages/goa/cc-online-accounts-add-account-dialog.c
index 7082575..d2eeb7e 100644
--- a/gnome-initial-setup/pages/goa/cc-online-accounts-add-account-dialog.c
+++ b/gnome-initial-setup/pages/goa/cc-online-accounts-add-account-dialog.c
@@ -1,6 +1,6 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
- * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2012, 2013 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -30,15 +30,27 @@
#include "cc-online-accounts-add-account-dialog.h"
+#define BRANDED_PAGE "_branded"
+#define OTHER_PAGE "_other"
+
struct _GoaPanelAddAccountDialogPrivate
{
+ GtkListBox *branded_list_box;
+ GtkListBox *contacts_list_box;
+ GtkListBox *mail_list_box;
+ GtkListBox *chat_list_box;
+ GtkListBox *ticketing_list_box;
GError *error;
GoaClient *client;
GoaObject *object;
+ GoaProvider *provider;
GtkListStore *list_store;
- GtkTreePath *path;
- GtkWidget *tree_view;
- gboolean ignore_release;
+ GtkWidget *contacts_grid;
+ GtkWidget *mail_grid;
+ GtkWidget *chat_grid;
+ GtkWidget *ticketing_grid;
+ GtkWidget *stack;
+ gboolean add_other;
};
#define GOA_ADD_ACCOUNT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),
GOA_TYPE_PANEL_ADD_ACCOUNT_DIALOG, GoaPanelAddAccountDialogPrivate))
@@ -59,36 +71,16 @@ enum
G_DEFINE_TYPE (GoaPanelAddAccountDialog, goa_panel_add_account_dialog, GTK_TYPE_DIALOG)
-static GoaProvider *
-add_account_dialog_get_provider (GoaPanelAddAccountDialog *add_account)
-{
- GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
- GoaProvider *provider;
- GtkTreeIter iter;
-
- if (priv->path == NULL)
- return NULL;
-
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, priv->path))
- return NULL;
-
- gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &iter, COLUMN_PROVIDER, &provider, -1);
- return provider;
-}
-
static void
-add_account_dialog_add_account (GoaPanelAddAccountDialog *add_account)
+add_account_dialog_add_account (GoaPanelAddAccountDialog *add_account,
+ GoaProvider *provider)
{
GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
GList *children;
GList *l;
- GoaProvider *provider;
GtkWidget *action_area;
GtkWidget *vbox;
- provider = add_account_dialog_get_provider (add_account);
- g_assert (provider != NULL);
-
action_area = gtk_dialog_get_action_area (GTK_DIALOG (add_account));
vbox = gtk_dialog_get_content_area (GTK_DIALOG (add_account));
children = gtk_container_get_children (GTK_CONTAINER (vbox));
@@ -100,70 +92,154 @@ add_account_dialog_add_account (GoaPanelAddAccountDialog *add_account)
}
g_list_free (children);
+ /* This spins gtk_dialog_run() */
priv->object = goa_provider_add_account (provider,
priv->client,
GTK_DIALOG (add_account),
GTK_BOX (vbox),
&priv->error);
- g_object_unref (provider);
}
-static gboolean
-tree_view_button_press_event_cb (GtkWidget *widget,
- GdkEventButton *event,
- gpointer *user_data)
+static void
+list_box_row_activated_cb (GoaPanelAddAccountDialog *add_account, GtkListBoxRow *row)
{
- GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (user_data);
- GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
+ GoaProvider *provider;
- /* be sure to ignore double and triple clicks */
- priv->ignore_release = (event->type != GDK_BUTTON_PRESS);
+ provider = g_object_get_data (G_OBJECT (row), "provider");
+ if (provider == NULL)
+ {
+ gtk_stack_set_visible_child_name (GTK_STACK (add_account->priv->stack), OTHER_PAGE);
+ return;
+ }
- return FALSE;
+ add_account_dialog_add_account (add_account, provider);
}
-static gboolean
-tree_view_button_release_event_cb (GtkWidget *widget,
- GdkEventButton *event,
- gpointer *user_data)
+static void
+update_header_func (GtkListBoxRow *row,
+ GtkListBoxRow *before,
+ gpointer user_data)
{
- GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (user_data);
- GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
- GtkTreePath *path;
- GtkTreeViewColumn *column;
+ GtkWidget *current;
- if (event->button != 1 || priv->ignore_release)
- return TRUE;
+ if (before == NULL)
+ return;
- gtk_tree_view_get_cursor (GTK_TREE_VIEW (widget), &path, &column);
- if (path == NULL)
- return TRUE;
+ current = gtk_list_box_row_get_header (row);
+ if (current == NULL)
+ {
+ current = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_show (current);
+ gtk_list_box_row_set_header (row, current);
+ }
+}
+
+static void
+add_account_dialog_create_group_ui (GoaPanelAddAccountDialog *add_account,
+ GtkListBox **list_box,
+ GtkWidget **group_grid,
+ GtkWidget *page_grid,
+ const gchar *name)
+{
+ GtkWidget *label;
+ GtkWidget *sw;
+ gchar *markup;
- gtk_tree_view_row_activated (GTK_TREE_VIEW (widget), path, column);
- gtk_tree_path_free (path);
+ *group_grid = gtk_grid_new ();
+ gtk_widget_set_no_show_all (*group_grid, TRUE);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (*group_grid), GTK_ORIENTATION_VERTICAL);
+ gtk_grid_set_row_spacing (GTK_GRID (*group_grid), 6);
+ gtk_container_add (GTK_CONTAINER (page_grid), *group_grid);
- return TRUE;
+ markup = g_strdup_printf ("<b>%s</b>", name);
+ label = gtk_label_new (NULL);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_hexpand (label, TRUE);
+ gtk_label_set_markup (GTK_LABEL (label), markup);
+ gtk_container_add (GTK_CONTAINER (*group_grid), label);
+ g_free (markup);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_set_hexpand (sw, TRUE);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
+ gtk_container_add (GTK_CONTAINER (*group_grid), sw);
+
+ *list_box = GTK_LIST_BOX (gtk_list_box_new ());
+ gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (*list_box));
+ gtk_list_box_set_selection_mode (*list_box, GTK_SELECTION_NONE);
+ gtk_list_box_set_header_func (*list_box, update_header_func, NULL, NULL);
+ g_signal_connect_swapped (*list_box, "row-activated",
+ G_CALLBACK (list_box_row_activated_cb), add_account);
}
static void
-tree_view_row_activated_cb (GtkTreeView *tree_view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- gpointer user_data)
+add_account_dialog_create_provider_ui (GoaPanelAddAccountDialog *add_account,
+ GoaProvider *provider,
+ GtkListBox *list_box)
{
- GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (user_data);
- GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
+ GIcon *icon;
+ GList *children;
+ GtkWidget *row;
+ GtkWidget *row_grid;
+ GtkWidget *image;
+ GtkWidget *label;
+ gchar *markup;
+ gchar *name;
+
+ row = gtk_list_box_row_new ();
+ row_grid = gtk_grid_new ();
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (row_grid), GTK_ORIENTATION_HORIZONTAL);
+ gtk_grid_set_column_spacing (GTK_GRID (row_grid), 6);
+ gtk_container_add (GTK_CONTAINER (row), row_grid);
+
+ if (provider == NULL)
+ {
+ g_object_set_data (G_OBJECT (row), "provider", NULL);
+ icon = g_themed_icon_new_with_default_fallbacks ("goa-account");
+ name = g_strdup (C_("Online Account", "Other"));
+ }
+ else
+ {
+ g_object_set_data_full (G_OBJECT (row), "provider", g_object_ref (provider), g_object_unref);
+ icon = goa_provider_get_provider_icon (provider, NULL);
+ name = goa_provider_get_provider_name (provider, NULL);
+ }
+
+ children = gtk_container_get_children (GTK_CONTAINER (list_box));
+ if (children != NULL)
+ {
+ /* FIXME: Ideally we want the list boxes to use as much space as
+ * it's available to try to show all the content, but GtkScrolledView
+ * ignores its child's natural size,
+ * see https://bugzilla.gnome.org/show_bug.cgi?id=660654
+ * For now we just make list boxes with multiple children expand as
+ * the result is quite similar. */
+ GtkWidget *sw;
+ sw = gtk_widget_get_parent (GTK_WIDGET (list_box));
+ gtk_widget_set_vexpand (sw, TRUE);
+ g_list_free (children);
+ }
+
+ gtk_container_add (GTK_CONTAINER (list_box), row);
+
+ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
+ gtk_container_add (GTK_CONTAINER (row_grid), image);
+
+ markup = g_strdup_printf ("<b>%s</b>", name);
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label), markup);
+ gtk_container_add (GTK_CONTAINER (row_grid), label);
+ g_free (markup);
- priv->path = gtk_tree_path_copy (path);
- add_account_dialog_add_account (add_account);
- gtk_dialog_response (GTK_DIALOG (add_account), GTK_RESPONSE_OK);
+ g_free (name);
+ g_object_unref (icon);
}
static void
goa_panel_add_account_dialog_realize (GtkWidget *widget)
{
GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (widget);
- GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
GtkWidget *button;
GtkWindow *parent;
@@ -177,8 +253,6 @@ goa_panel_add_account_dialog_realize (GtkWidget *widget)
gtk_widget_set_size_request (GTK_WIDGET (add_account), (gint) (0.5 * width), (gint) (0.9 * height));
}
- gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), GTK_TREE_MODEL (priv->list_store));
-
GTK_WIDGET_CLASS (goa_panel_add_account_dialog_parent_class)->realize (widget);
button = gtk_dialog_get_widget_for_response (GTK_DIALOG (add_account), GTK_RESPONSE_CANCEL);
@@ -191,12 +265,9 @@ goa_panel_add_account_dialog_dispose (GObject *object)
GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (object);
GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
- if (priv->tree_view != NULL)
- priv->tree_view = NULL;
-
- g_clear_object (&priv->list_store);
g_clear_object (&priv->object);
g_clear_object (&priv->client);
+ g_clear_object (&priv->provider);
G_OBJECT_CLASS (goa_panel_add_account_dialog_parent_class)->dispose (object);
}
@@ -207,10 +278,7 @@ goa_panel_add_account_dialog_finalize (GObject *object)
GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (object);
GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
- gtk_tree_path_free (priv->path);
-
- if (priv->error != NULL)
- g_error_free (priv->error);
+ g_clear_error (&priv->error);
G_OBJECT_CLASS (goa_panel_add_account_dialog_parent_class)->finalize (object);
}
@@ -236,9 +304,6 @@ static void
goa_panel_add_account_dialog_init (GoaPanelAddAccountDialog *add_account)
{
GoaPanelAddAccountDialogPrivate *priv;
- GtkCellRenderer *renderer;
- GtkTreeSelection *selection;
- GtkTreeViewColumn *column;
GtkWidget *sw;
GtkWidget *vbox;
GtkWidget *grid;
@@ -262,41 +327,57 @@ goa_panel_add_account_dialog_init (GoaPanelAddAccountDialog *add_account)
priv->list_store = gtk_list_store_new (N_COLUMNS, GOA_TYPE_PROVIDER, G_TYPE_ICON, G_TYPE_STRING);
+ priv->stack = gtk_stack_new ();
+ gtk_stack_set_transition_type (GTK_STACK (priv->stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE);
+ gtk_container_add (GTK_CONTAINER (grid), priv->stack);
+
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
gtk_widget_set_hexpand (sw, TRUE);
gtk_widget_set_vexpand (sw, TRUE);
- gtk_container_add (GTK_CONTAINER (grid), sw);
+ gtk_stack_add_named (GTK_STACK (priv->stack), sw, BRANDED_PAGE);
- priv->tree_view = gtk_tree_view_new ();
- gtk_widget_set_hexpand (priv->tree_view, TRUE);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
- gtk_container_add (GTK_CONTAINER (sw), priv->tree_view);
+ priv->branded_list_box = GTK_LIST_BOX (gtk_list_box_new ());
+ gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (priv->branded_list_box));
+ gtk_list_box_set_selection_mode (priv->branded_list_box, GTK_SELECTION_NONE);
+ gtk_list_box_set_header_func (priv->branded_list_box, update_header_func, NULL, NULL);
+ g_signal_connect_swapped (priv->branded_list_box, "row-activated",
+ G_CALLBACK (list_box_row_activated_cb), add_account);
- column = gtk_tree_view_column_new ();
- gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), column);
-
- renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_tree_view_column_pack_start (column, renderer, FALSE);
- g_object_set (G_OBJECT (renderer), "stock-size", GTK_ICON_SIZE_DIALOG, NULL);
- gtk_tree_view_column_set_attributes (column, renderer, "gicon", COLUMN_ICON, NULL);
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer, TRUE);
- gtk_tree_view_column_set_attributes (column, renderer, "markup", COLUMN_MARKUP, NULL);
-
- gtk_dialog_add_button (GTK_DIALOG (add_account), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+ grid = gtk_grid_new ();
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
+ gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
+ gtk_stack_add_named (GTK_STACK (priv->stack), grid, OTHER_PAGE);
+
+ add_account_dialog_create_group_ui (add_account,
+ &priv->mail_list_box,
+ &priv->mail_grid,
+ grid,
+ _("Mail"));
+
+ add_account_dialog_create_group_ui (add_account,
+ &priv->contacts_list_box,
+ &priv->contacts_grid,
+ grid,
+ _("Contacts"));
+
+ add_account_dialog_create_group_ui (add_account,
+ &priv->chat_list_box,
+ &priv->chat_grid,
+ grid,
+ _("Chat"));
+
+ add_account_dialog_create_group_ui (add_account,
+ &priv->ticketing_list_box,
+ &priv->ticketing_grid,
+ grid,
+ _("Resources"));
+
+ gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), BRANDED_PAGE);
+
+ gtk_dialog_add_button (GTK_DIALOG (add_account), _("_Cancel"), GTK_RESPONSE_CANCEL);
gtk_dialog_set_default_response (GTK_DIALOG (add_account), GTK_RESPONSE_CANCEL);
-
- g_signal_connect (priv->tree_view, "button-press-event",
- G_CALLBACK (tree_view_button_press_event_cb), add_account);
- g_signal_connect (priv->tree_view, "button-release-event",
- G_CALLBACK (tree_view_button_release_event_cb), add_account);
- g_signal_connect (priv->tree_view, "row-activated", G_CALLBACK (tree_view_row_activated_cb), add_account);
-
}
static void
@@ -331,27 +412,87 @@ goa_panel_add_account_dialog_new (GoaClient *client)
}
void
+goa_panel_add_account_dialog_set_preseed_data (GoaPanelAddAccountDialog *add_account,
+ GoaProvider *provider,
+ GVariant *preseed)
+{
+ GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
+
+ g_clear_object (&priv->provider);
+
+ if (provider != NULL)
+ {
+ priv->provider = g_object_ref (provider);
+ goa_provider_set_preseed_data (provider, preseed);
+ }
+}
+
+void
goa_panel_add_account_dialog_add_provider (GoaPanelAddAccountDialog *add_account, GoaProvider *provider)
{
GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
- GIcon *icon;
- GtkTreeIter iter;
- gchar *markup;
- gchar *name;
+ GtkListBox *list_box;
+ GoaProviderGroup group;
+ GtkWidget *group_grid = NULL;
- icon = goa_provider_get_provider_icon (provider, NULL);
- name = goa_provider_get_provider_name (provider, NULL);
- markup = g_strdup_printf ("<b>%s</b>", name);
- g_free (name);
+ g_return_if_fail (provider != NULL);
- gtk_list_store_append (priv->list_store, &iter);
- gtk_list_store_set (priv->list_store, &iter,
- COLUMN_PROVIDER, provider,
- COLUMN_ICON, icon,
- COLUMN_MARKUP, markup,
- -1);
- g_free (markup);
- g_object_unref (icon);
+ group = goa_provider_get_provider_group (provider);
+
+ /* The list of providers returned by GOA are sorted such that all
+ * the branded providers are at the beginning of the list, followed
+ * by the others. Since this is the order in which they are added,
+ * we can rely on this fact, which helps to simplify the code.
+ */
+ if (group != GOA_PROVIDER_GROUP_BRANDED && !priv->add_other)
+ {
+ add_account_dialog_create_provider_ui (add_account, NULL, priv->branded_list_box);
+ priv->add_other = TRUE;
+ }
+
+ switch (group)
+ {
+ case GOA_PROVIDER_GROUP_BRANDED:
+ list_box = priv->branded_list_box;
+ break;
+ case GOA_PROVIDER_GROUP_CONTACTS:
+ group_grid = priv->contacts_grid;
+ list_box = priv->contacts_list_box;
+ break;
+ case GOA_PROVIDER_GROUP_MAIL:
+ group_grid = priv->mail_grid;
+ list_box = priv->mail_list_box;
+ break;
+ case GOA_PROVIDER_GROUP_CHAT:
+ group_grid = priv->chat_grid;
+ list_box = priv->chat_list_box;
+ break;
+ case GOA_PROVIDER_GROUP_TICKETING:
+ group_grid = priv->ticketing_grid;
+ list_box = priv->ticketing_list_box;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ add_account_dialog_create_provider_ui (add_account, provider, list_box);
+
+ if (group_grid != NULL)
+ {
+ gtk_widget_set_no_show_all (group_grid, FALSE);
+ gtk_widget_show_all (group_grid);
+ }
+}
+
+void
+goa_panel_add_account_dialog_run (GoaPanelAddAccountDialog *add_account)
+{
+ GoaPanelAddAccountDialogPrivate *priv = add_account->priv;
+ if (priv->provider != NULL)
+ add_account_dialog_add_account (add_account, priv->provider);
+ else
+ gtk_dialog_run (GTK_DIALOG (add_account));
}
GoaObject *
diff --git a/gnome-initial-setup/pages/goa/cc-online-accounts-add-account-dialog.h
b/gnome-initial-setup/pages/goa/cc-online-accounts-add-account-dialog.h
index 0f503cb..9338575 100644
--- a/gnome-initial-setup/pages/goa/cc-online-accounts-add-account-dialog.h
+++ b/gnome-initial-setup/pages/goa/cc-online-accounts-add-account-dialog.h
@@ -54,6 +54,10 @@ GType goa_panel_add_account_dialog_get_type (void
GtkWidget *goa_panel_add_account_dialog_new (GoaClient *client);
void goa_panel_add_account_dialog_add_provider (GoaPanelAddAccountDialog
*add_account,
GoaProvider
*provider);
+void goa_panel_add_account_dialog_set_preseed_data (GoaPanelAddAccountDialog
*add_account,
+ GoaProvider
*provider,
+ GVariant
*preseed);
+void goa_panel_add_account_dialog_run (GoaPanelAddAccountDialog
*add_account);
GoaObject *goa_panel_add_account_dialog_get_account (GoaPanelAddAccountDialog
*add_account,
GError
**error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]