[gnome-online-accounts] Move Exchange & Kerberos dialog spinners to the action widget
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] Move Exchange & Kerberos dialog spinners to the action widget
- Date: Fri, 14 Sep 2012 22:15:47 +0000 (UTC)
commit 7bfea17c8ab900d4f665e56618c4beb7b444d93c
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Sep 14 23:57:27 2012 +0200
Move Exchange & Kerberos dialog spinners to the action widget
A new GoaSpinnerButton widget was introduced.
src/goabackend/Makefile.am | 1 +
src/goabackend/goaexchangeprovider.c | 23 ++---
src/goabackend/goakerberosprovider.c | 22 ++--
src/goabackend/goaspinnerbutton.c | 185 ++++++++++++++++++++++++++++++++++
src/goabackend/goaspinnerbutton.h | 61 +++++++++++
5 files changed, 265 insertions(+), 27 deletions(-)
---
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index bfd2239..0f96081 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -80,6 +80,7 @@ libgoa_backend_1_0_la_SOURCES = \
goatwitterprovider.h goatwitterprovider.c \
goawindowsliveprovider.h goawindowsliveprovider.c \
goautils.h goautils.c \
+ goaspinnerbutton.h goaspinnerbutton.c \
goawebview.h goawebview.c \
nautilus-floating-bar.h nautilus-floating-bar.c \
$(top_builddir)/src/goaidentity/org.gnome.Identity.c \
diff --git a/src/goabackend/goaexchangeprovider.c b/src/goabackend/goaexchangeprovider.c
index e7bf281..7429ee9 100644
--- a/src/goabackend/goaexchangeprovider.c
+++ b/src/goabackend/goaexchangeprovider.c
@@ -28,6 +28,7 @@
#include "goaprovider.h"
#include "goaexchangeprovider.h"
#include "goaeditablelabel.h"
+#include "goaspinnerbutton.h"
#include "goautils.h"
/**
@@ -361,7 +362,7 @@ typedef struct
GtkWidget *cluebar;
GtkWidget *cluebar_label;
- GtkWidget *spinner;
+ GtkWidget *spinner_button;
GtkWidget *email_address;
GtkWidget *password;
@@ -468,10 +469,6 @@ create_account_details_ui (GoaProvider *provider,
gtk_container_add (GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (data->cluebar))),
data->cluebar_label);
- data->spinner = gtk_spinner_new ();
- gtk_widget_set_no_show_all (data->spinner, TRUE);
- gtk_container_add (GTK_CONTAINER (grid0), data->spinner);
-
grid1 = gtk_grid_new ();
gtk_orientable_set_orientation (GTK_ORIENTABLE (grid1), GTK_ORIENTATION_VERTICAL);
gtk_grid_set_row_spacing (GTK_GRID (grid1), 12);
@@ -520,7 +517,8 @@ create_account_details_ui (GoaProvider *provider,
g_signal_connect (data->email_address, "changed", G_CALLBACK (on_email_address_or_password_changed), data);
g_signal_connect (data->password, "changed", G_CALLBACK (on_email_address_or_password_changed), data);
- gtk_dialog_add_button (data->dialog, GTK_STOCK_CONNECT, GTK_RESPONSE_OK);
+ data->spinner_button = goa_spinner_button_new_from_stock (GTK_STOCK_CONNECT);
+ gtk_dialog_add_action_widget (data->dialog, data->spinner_button, GTK_RESPONSE_OK);
gtk_dialog_set_default_response (data->dialog, GTK_RESPONSE_OK);
gtk_dialog_set_response_sensitive (data->dialog, GTK_RESPONSE_OK, FALSE);
@@ -549,8 +547,7 @@ autodiscover_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
goa_ews_client_autodiscover_finish (client, res, &data->error);
g_main_loop_quit (data->loop);
- gtk_spinner_stop (GTK_SPINNER (data->spinner));
- gtk_widget_hide (data->spinner);
+ goa_spinner_button_stop (GOA_SPINNER_BUTTON (data->spinner_button));
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -622,13 +619,11 @@ add_account (GoaProvider *provider,
NULL,
autodiscover_cb,
&data);
- gtk_spinner_start (GTK_SPINNER (data.spinner));
- gtk_widget_show (data.spinner);
+ goa_spinner_button_start (GOA_SPINNER_BUTTON (data.spinner_button));
g_main_loop_run (data.loop);
if (data.error != NULL)
{
- GtkWidget *button;
gchar *markup;
markup = g_strdup_printf ("<b>%s:</b> %s",
@@ -639,8 +634,7 @@ add_account (GoaProvider *provider,
gtk_label_set_markup (GTK_LABEL (data.cluebar_label), markup);
g_free (markup);
- button = gtk_dialog_get_widget_for_response (data.dialog, GTK_RESPONSE_OK);
- gtk_button_set_label (GTK_BUTTON (button), _("_Try Again"));
+ goa_spinner_button_set_label (GOA_SPINNER_BUTTON (data.spinner_button), _("_Try Again"));
gtk_expander_set_expanded (GTK_EXPANDER (data.expander), TRUE);
gtk_widget_set_no_show_all (data.cluebar, FALSE);
gtk_widget_show_all (data.cluebar);
@@ -781,8 +775,7 @@ refresh_account (GoaProvider *provider,
NULL,
autodiscover_cb,
&data);
- gtk_spinner_start (GTK_SPINNER (data.spinner));
- gtk_widget_show (data.spinner);
+ goa_spinner_button_start (GOA_SPINNER_BUTTON (data.spinner_button));
g_main_loop_run (data.loop);
if (data.error != NULL)
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index 82c2537..b45311b 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -29,6 +29,7 @@
#include "goaprovider.h"
#include "goakerberosprovider.h"
#include "goaeditablelabel.h"
+#include "goaspinnerbutton.h"
#include "goautils.h"
#include "goaidentity.h"
@@ -90,7 +91,7 @@ typedef struct
GtkWidget *cluebar;
GtkWidget *cluebar_label;
- GtkWidget *spinner;
+ GtkWidget *spinner_button;
GtkWidget *username;
GtkWidget *realm_entry;
@@ -987,10 +988,6 @@ create_account_details_ui (GoaKerberosProvider *self,
gtk_grid_set_row_spacing (GTK_GRID (grid0), 12);
gtk_container_add (GTK_CONTAINER (vbox), grid0);
- request->spinner = gtk_spinner_new ();
- gtk_widget_set_no_show_all (request->spinner, TRUE);
- gtk_container_add (GTK_CONTAINER (grid0), request->spinner);
-
request->cluebar = gtk_info_bar_new ();
gtk_info_bar_set_message_type (GTK_INFO_BAR (request->cluebar), GTK_MESSAGE_ERROR);
gtk_widget_set_hexpand (request->cluebar, TRUE);
@@ -1036,7 +1033,8 @@ create_account_details_ui (GoaKerberosProvider *self,
gtk_widget_grab_focus (request->realm_combo_box);
- gtk_dialog_add_button (request->dialog, GTK_STOCK_CONNECT, GTK_RESPONSE_OK);
+ request->spinner_button = goa_spinner_button_new_from_stock (GTK_STOCK_CONNECT);
+ gtk_dialog_add_action_widget (request->dialog, request->spinner_button, GTK_RESPONSE_OK);
gtk_dialog_set_default_response (request->dialog, GTK_RESPONSE_OK);
gtk_dialog_set_response_sensitive (request->dialog, GTK_RESPONSE_OK, TRUE);
@@ -1381,7 +1379,10 @@ start_over:
NULL, /* GCancellable* */
(GAsyncReadyCallback) add_account_cb,
&request);
+
+ goa_spinner_button_start (GOA_SPINNER_BUTTON (request.spinner_button));
g_main_loop_run (request.loop);
+ goa_spinner_button_stop (GOA_SPINNER_BUTTON (request.spinner_button));
if (request.error != NULL)
goto out;
@@ -1389,18 +1390,16 @@ start_over:
request.account_object_path));
account = goa_object_peek_account (object);
- gtk_spinner_start (GTK_SPINNER (request.spinner));
- gtk_widget_show (request.spinner);
-
/* After the account is created, try to sign it in
*/
perform_initial_sign_in (self, object, principal, &request);
+ goa_spinner_button_start (GOA_SPINNER_BUTTON (request.spinner_button));
g_main_loop_run (request.loop);
+ goa_spinner_button_stop (GOA_SPINNER_BUTTON (request.spinner_button));
if (request.error != NULL)
{
- GtkWidget *button;
gchar *markup;
translate_error (&request.error);
@@ -1415,8 +1414,7 @@ start_over:
gtk_label_set_markup (GTK_LABEL (request.cluebar_label), markup);
g_free (markup);
- button = gtk_dialog_get_widget_for_response (request.dialog, GTK_RESPONSE_OK);
- gtk_button_set_label (GTK_BUTTON (button), _("_Try Again"));
+ goa_spinner_button_set_label (GOA_SPINNER_BUTTON (request.spinner_button), _("_Try Again"));
gtk_widget_set_no_show_all (request.cluebar, FALSE);
gtk_widget_show_all (request.cluebar);
}
diff --git a/src/goabackend/goaspinnerbutton.c b/src/goabackend/goaspinnerbutton.c
new file mode 100644
index 0000000..fae1bf2
--- /dev/null
+++ b/src/goabackend/goaspinnerbutton.c
@@ -0,0 +1,185 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2012 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "goaspinnerbutton.h"
+
+struct _GoaSpinnerButtonPrivate
+{
+ GtkWidget *grid;
+ GtkWidget *label;
+ GtkWidget *spinner;
+ gboolean use_stock;
+ gchar *text;
+};
+
+enum
+{
+ PROP_0,
+ PROP_LABEL,
+ PROP_USE_STOCK
+};
+
+#define GOA_SPINNER_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOA_TYPE_SPINNER_BUTTON, GoaSpinnerButtonPrivate))
+
+G_DEFINE_TYPE (GoaSpinnerButton, goa_spinner_button, GTK_TYPE_BUTTON)
+
+static void
+goa_spinner_button_constructed (GObject *object)
+{
+ GoaSpinnerButton *self = GOA_SPINNER_BUTTON (object);
+ GoaSpinnerButtonPrivate *priv = self->priv;
+ GtkStockItem item;
+
+ G_OBJECT_CLASS (goa_spinner_button_parent_class)->constructed (object);
+
+ if (priv->use_stock && gtk_stock_lookup (priv->text, &item))
+ priv->label = gtk_label_new_with_mnemonic (item.label);
+ else
+ priv->label = gtk_label_new_with_mnemonic (priv->text);
+
+ gtk_widget_set_hexpand (priv->label, TRUE);
+ gtk_widget_set_halign (priv->label, GTK_ALIGN_CENTER);
+
+ gtk_label_set_mnemonic_widget (GTK_LABEL (priv->label), GTK_WIDGET (self));
+ gtk_container_add (GTK_CONTAINER (priv->grid), priv->label);
+}
+
+static void
+goa_spinner_button_finalize (GObject *object)
+{
+ GoaSpinnerButton *self = GOA_SPINNER_BUTTON (object);
+ GoaSpinnerButtonPrivate *priv = self->priv;
+
+ g_free (priv->text);
+
+ G_OBJECT_CLASS (goa_spinner_button_parent_class)->finalize (object);
+}
+
+static void
+goa_spinner_button_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GoaSpinnerButton *self = GOA_SPINNER_BUTTON (object);
+ GoaSpinnerButtonPrivate *priv = self->priv;
+
+ switch (prop_id)
+ {
+ case PROP_LABEL:
+ priv->text = g_value_dup_string (value);
+ break;
+
+ case PROP_USE_STOCK:
+ priv->use_stock = g_value_get_boolean (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+goa_spinner_button_init (GoaSpinnerButton *self)
+{
+ GoaSpinnerButtonPrivate *priv;
+
+ self->priv = GOA_SPINNER_BUTTON_GET_PRIVATE (self);
+ priv = self->priv;
+
+ gtk_widget_set_can_default (GTK_WIDGET (self), TRUE);
+
+ priv->grid = gtk_grid_new ();
+ gtk_grid_set_column_spacing (GTK_GRID (priv->grid), 6);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->grid), GTK_ORIENTATION_HORIZONTAL);
+ gtk_container_add (GTK_CONTAINER (self), priv->grid);
+
+ priv->spinner = gtk_spinner_new ();
+ gtk_widget_set_no_show_all (priv->spinner, TRUE);
+ gtk_container_add (GTK_CONTAINER (priv->grid), priv->spinner);
+}
+
+static void
+goa_spinner_button_class_init (GoaSpinnerButtonClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = goa_spinner_button_constructed;
+ object_class->finalize = goa_spinner_button_finalize;
+ object_class->set_property = goa_spinner_button_set_property;
+
+ g_object_class_install_property (object_class, PROP_LABEL,
+ g_param_spec_string ("label",
+ "Label",
+ "Text of the label widget inside the button, if the button contains a label widget.",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class, PROP_USE_STOCK,
+ g_param_spec_boolean ("use-stock",
+ "Use a stock item",
+ "If set, the label is used to pick a stock item instead of being displayed.",
+ FALSE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+ g_type_class_add_private (object_class, sizeof (GoaSpinnerButtonPrivate));
+}
+
+GtkWidget *
+goa_spinner_button_new_from_stock (const gchar *stock_id)
+{
+ return g_object_new (GOA_TYPE_SPINNER_BUTTON, "label", stock_id, "use-stock", TRUE, NULL);
+}
+
+void
+goa_spinner_button_set_label (GoaSpinnerButton *self, const gchar *label)
+{
+ GoaSpinnerButtonPrivate *priv = self->priv;
+
+ priv->use_stock = FALSE;
+
+ g_free (priv->text);
+ priv->text = g_strdup (label);
+ gtk_label_set_use_underline (GTK_LABEL (priv->label), TRUE);
+ gtk_label_set_label (GTK_LABEL (priv->label), priv->text);
+}
+
+void
+goa_spinner_button_start (GoaSpinnerButton *self)
+{
+ GoaSpinnerButtonPrivate *priv = self->priv;
+
+ gtk_spinner_start (GTK_SPINNER (priv->spinner));
+ gtk_widget_show (priv->spinner);
+}
+
+void
+goa_spinner_button_stop (GoaSpinnerButton *self)
+{
+ GoaSpinnerButtonPrivate *priv = self->priv;
+
+ gtk_spinner_stop (GTK_SPINNER (priv->spinner));
+ gtk_widget_hide (priv->spinner);
+}
diff --git a/src/goabackend/goaspinnerbutton.h b/src/goabackend/goaspinnerbutton.h
new file mode 100644
index 0000000..ceb880a
--- /dev/null
+++ b/src/goabackend/goaspinnerbutton.h
@@ -0,0 +1,61 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2012 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ */
+
+#ifndef __GOA_SPINNER_BUTTON_H__
+#define __GOA_SPINNER_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GOA_TYPE_SPINNER_BUTTON (goa_spinner_button_get_type ())
+#define GOA_SPINNER_BUTTON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOA_TYPE_SPINNER_BUTTON, GoaSpinnerButton))
+#define GOA_SPINNER_BUTTON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOA_TYPE_SPINNER_BUTTON, GoaSpinnerButtonClass))
+#define GOA_IS_SPINNER_BUTTON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOA_TYPE_SPINNER_BUTTON))
+#define GOA_IS_SPINNER_BUTTON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOA_TYPE_SPINNER_BUTTON))
+#define GOA_SPINNER_BUTTON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOA_TYPE_SPINNER_BUTTON, GoaSpinnerButtonClass))
+
+typedef struct _GoaSpinnerButton GoaSpinnerButton;
+typedef struct _GoaSpinnerButtonClass GoaSpinnerButtonClass;
+typedef struct _GoaSpinnerButtonPrivate GoaSpinnerButtonPrivate;
+
+struct _GoaSpinnerButton
+{
+ /*<private>*/
+ GtkButton parent_instance;
+ GoaSpinnerButtonPrivate *priv;
+};
+
+struct _GoaSpinnerButtonClass
+{
+ GtkButtonClass parent_class;
+};
+
+GType goa_spinner_button_get_type (void) G_GNUC_CONST;
+GtkWidget *goa_spinner_button_new_from_stock (const gchar *stock_id);
+void goa_spinner_button_set_label (GoaSpinnerButton *self, const gchar *label);
+void goa_spinner_button_start (GoaSpinnerButton *self);
+void goa_spinner_button_stop (GoaSpinnerButton *self);
+
+G_END_DECLS
+
+#endif /* _GOA_SPINNER_BUTTON_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]