diff options
author | Debarshi Ray <debarshir@gnome.org> | 2013-01-24 13:15:17 +0100 |
---|---|---|
committer | Debarshi Ray <debarshir@gnome.org> | 2013-01-28 13:11:15 +0100 |
commit | 4a86ebff502e10f94b7e73649fa81c051de3fb38 (patch) | |
tree | ee6745aae06ec0b4c1b85c03d8aeaddfcfc439ed /panels/online-accounts | |
parent | 4358230b0e223039b98aa596181a01eeff2640c9 (diff) | |
download | gnome-control-center-4a86ebff502e10f94b7e73649fa81c051de3fb38.tar.gz |
online-accounts: Replace the hacked up GtkTreeView with a EggListBox
https://bugzilla.gnome.org/show_bug.cgi?id=692442
Diffstat (limited to 'panels/online-accounts')
-rw-r--r-- | panels/online-accounts/cc-online-accounts-add-account-dialog.c | 155 |
1 files changed, 40 insertions, 115 deletions
diff --git a/panels/online-accounts/cc-online-accounts-add-account-dialog.c b/panels/online-accounts/cc-online-accounts-add-account-dialog.c index 708257546..dc2b0c1d1 100644 --- a/panels/online-accounts/cc-online-accounts-add-account-dialog.c +++ b/panels/online-accounts/cc-online-accounts-add-account-dialog.c @@ -28,17 +28,16 @@ #define GOA_BACKEND_API_IS_SUBJECT_TO_CHANGE #include <goabackend/goabackend.h> +#include <egg-list-box/egg-list-box.h> #include "cc-online-accounts-add-account-dialog.h" struct _GoaPanelAddAccountDialogPrivate { + EggListBox *list_box; GError *error; GoaClient *client; GoaObject *object; GtkListStore *list_store; - GtkTreePath *path; - GtkWidget *tree_view; - gboolean ignore_release; }; #define GOA_ADD_ACCOUNT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOA_TYPE_PANEL_ADD_ACCOUNT_DIALOG, GoaPanelAddAccountDialogPrivate)) @@ -59,36 +58,15 @@ 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)); @@ -105,65 +83,35 @@ add_account_dialog_add_account (GoaPanelAddAccountDialog *add_account) 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) -{ - GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (user_data); - GoaPanelAddAccountDialogPrivate *priv = add_account->priv; - - /* be sure to ignore double and triple clicks */ - priv->ignore_release = (event->type != GDK_BUTTON_PRESS); - - return FALSE; -} - -static gboolean -tree_view_button_release_event_cb (GtkWidget *widget, - GdkEventButton *event, - gpointer *user_data) +static void +list_box_child_activated_cb (GoaPanelAddAccountDialog *add_account, GtkWidget *child) { - GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (user_data); - GoaPanelAddAccountDialogPrivate *priv = add_account->priv; - GtkTreePath *path; - GtkTreeViewColumn *column; - - if (event->button != 1 || priv->ignore_release) - return TRUE; - - gtk_tree_view_get_cursor (GTK_TREE_VIEW (widget), &path, &column); - if (path == NULL) - return TRUE; - - gtk_tree_view_row_activated (GTK_TREE_VIEW (widget), path, column); - gtk_tree_path_free (path); + GoaProvider *provider; - return TRUE; + provider = g_object_get_data (G_OBJECT (child), "provider"); + add_account_dialog_add_account (add_account, provider); + gtk_dialog_response (GTK_DIALOG (add_account), GTK_RESPONSE_OK); } static void -tree_view_row_activated_cb (GtkTreeView *tree_view, - GtkTreePath *path, - GtkTreeViewColumn *column, - gpointer user_data) +list_box_separator_cb (GtkWidget **separator, GtkWidget *child, GtkWidget *before, gpointer user_data) { - GoaPanelAddAccountDialog *add_account = GOA_PANEL_ADD_ACCOUNT_DIALOG (user_data); - GoaPanelAddAccountDialogPrivate *priv = add_account->priv; + if (*separator == NULL && before != NULL) + { + *separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); - priv->path = gtk_tree_path_copy (path); - add_account_dialog_add_account (add_account); - gtk_dialog_response (GTK_DIALOG (add_account), GTK_RESPONSE_OK); + /* https://bugzilla.gnome.org/show_bug.cgi?id=690545 */ + g_object_ref_sink (*separator); + gtk_widget_show (*separator); + } } 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 +125,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,10 +137,6 @@ 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); @@ -207,8 +149,6 @@ 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); @@ -236,9 +176,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; @@ -269,34 +206,15 @@ goa_panel_add_account_dialog_init (GoaPanelAddAccountDialog *add_account) gtk_widget_set_vexpand (sw, TRUE); gtk_container_add (GTK_CONTAINER (grid), sw); - 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); - - 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); + priv->list_box = egg_list_box_new (); + egg_list_box_add_to_scrolled (priv->list_box, GTK_SCROLLED_WINDOW (sw)); + egg_list_box_set_selection_mode (priv->list_box, GTK_SELECTION_NONE); + egg_list_box_set_separator_funcs (priv->list_box, list_box_separator_cb, NULL, NULL); + g_signal_connect_swapped (priv->list_box, "child-activated", + G_CALLBACK (list_box_child_activated_cb), add_account); gtk_dialog_add_button (GTK_DIALOG (add_account), GTK_STOCK_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 @@ -335,23 +253,30 @@ goa_panel_add_account_dialog_add_provider (GoaPanelAddAccountDialog *add_account { GoaPanelAddAccountDialogPrivate *priv = add_account->priv; GIcon *icon; - GtkTreeIter iter; + GtkWidget *grid; + GtkWidget *image; + GtkWidget *label; gchar *markup; gchar *name; + grid = gtk_grid_new (); + g_object_set_data_full (G_OBJECT (grid), "provider", g_object_ref (provider), g_object_unref); + gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_HORIZONTAL); + gtk_grid_set_column_spacing (GTK_GRID (grid), 6); + gtk_container_add (GTK_CONTAINER (priv->list_box), grid); + icon = goa_provider_get_provider_icon (provider, NULL); + image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); + gtk_container_add (GTK_CONTAINER (grid), image); + g_object_unref (icon); + name = goa_provider_get_provider_name (provider, NULL); markup = g_strdup_printf ("<b>%s</b>", name); - g_free (name); - - 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); + label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), markup); + gtk_container_add (GTK_CONTAINER (grid), label); g_free (markup); - g_object_unref (icon); + g_free (name); } GoaObject * |