diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2014-02-11 23:36:17 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2014-02-11 23:44:21 +0800 |
commit | 528ef6db79c8d389e6a005dcbe5028fe6219b0a3 (patch) | |
tree | 9ca1f0d95fb9fac93e3689c9cd955a489ea52827 | |
parent | 052bfc93fe1f76584b213759f4087dc452ece60b (diff) | |
download | gsoc2013-evolution-528ef6db79c8d389e6a005dcbe5028fe6219b0a3.tar gsoc2013-evolution-528ef6db79c8d389e6a005dcbe5028fe6219b0a3.tar.gz gsoc2013-evolution-528ef6db79c8d389e6a005dcbe5028fe6219b0a3.tar.bz2 gsoc2013-evolution-528ef6db79c8d389e6a005dcbe5028fe6219b0a3.tar.lz gsoc2013-evolution-528ef6db79c8d389e6a005dcbe5028fe6219b0a3.tar.xz gsoc2013-evolution-528ef6db79c8d389e6a005dcbe5028fe6219b0a3.tar.zst gsoc2013-evolution-528ef6db79c8d389e6a005dcbe5028fe6219b0a3.zip |
EMailConfigAssistant: Hack the "Go Back" button after autoconfig.
After account autoconfiguration, you can click the "Go Back" button to
revise the account details. That's been in place for some time now, but
it's not obvious from the button label. "Go Back" implies going back to
the Identity page.
Temporarily rename the "Go Back" button on the Summary page to something
more accurate after a successful autoconfiguration, then reset it to its
original "Go Back" label.
Unfortunately the GtkAssistant API does not make this easy. I had to
resort to crawling the assistant's internal child widgets and comparing
button labels to locate the right button. So this hack may not be very
future-proof.
-rw-r--r-- | mail/e-mail-config-assistant.c | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/mail/e-mail-config-assistant.c b/mail/e-mail-config-assistant.c index aceeacc73e..62944943f4 100644 --- a/mail/e-mail-config-assistant.c +++ b/mail/e-mail-config-assistant.c @@ -35,6 +35,9 @@ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_MAIL_CONFIG_ASSISTANT, EMailConfigAssistantPrivate)) +/* GtkAssistant's back button label. */ +#define BACK_BUTTON_LABEL N_("Go _Back") + typedef struct _AutoconfigContext AutoconfigContext; struct _EMailConfigAssistantPrivate { @@ -47,7 +50,10 @@ struct _EMailConfigAssistantPrivate { EMailConfigSummaryPage *summary_page; EMailConfigPage *lookup_page; GHashTable *visited_pages; - gboolean auto_configure_done; + gboolean auto_configured; + + /* GtkAssistant owns this. */ + GtkButton *back_button; /* not referenced */ }; struct _AutoconfigContext { @@ -273,9 +279,6 @@ mail_config_assistant_autoconfigure_cb (GObject *source_object, context = (AutoconfigContext *) user_data; priv = E_MAIL_CONFIG_ASSISTANT_GET_PRIVATE (context->assistant); - /* Whether it works or not, we only do this once. */ - priv->auto_configure_done = TRUE; - autoconfig = e_mail_autoconfig_finish (result, &error); /* We don't really care about errors, we only capture the GError @@ -292,6 +295,9 @@ mail_config_assistant_autoconfigure_cb (GObject *source_object, /* Autoconfiguration worked! Feed the results to the * service pages and then skip to the Summary page. */ + /* For the summary page... */ + priv->auto_configured = TRUE; + e_mail_config_service_page_auto_configure ( priv->receiving_page, autoconfig); @@ -395,6 +401,40 @@ mail_config_assistant_close_cb (GObject *object, } static void +mail_config_assistant_find_back_button_cb (GtkWidget *widget, + gpointer user_data) +{ + EMailConfigAssistant *assistant; + + assistant = E_MAIL_CONFIG_ASSISTANT (user_data); + + if (GTK_IS_BUTTON (widget)) { + GtkButton *button; + const gchar *gtk_label; + const gchar *our_label; + + button = GTK_BUTTON (widget); + + /* XXX The gtkassistant.ui file assigns the back button + * an ID of "back", but I don't think we have access + * to it from here. I guess just compare by label, + * and hope our translation matches GTK's. Yuck. */ + + gtk_label = gtk_button_get_label (button); + our_label = gettext (BACK_BUTTON_LABEL); + + if (g_strcmp0 (gtk_label, our_label) == 0) + assistant->priv->back_button = button; + + } else if (GTK_IS_CONTAINER (widget)) { + gtk_container_forall ( + GTK_CONTAINER (widget), + mail_config_assistant_find_back_button_cb, + assistant); + } +} + +static void mail_config_assistant_set_session (EMailConfigAssistant *assistant, EMailSession *session) { @@ -565,6 +605,16 @@ mail_config_assistant_constructed (GObject *object) session = e_mail_config_assistant_get_session (assistant); registry = e_mail_session_get_registry (session); + /* XXX Locate the GtkAssistant's internal "Go Back" button so + * we can temporarily rename it for autoconfigure results. + * Walking the container like this is an extremely naughty + * and brittle hack, but GtkAssistant does not provide API + * to access it directly. */ + gtk_container_forall ( + GTK_CONTAINER (assistant), + mail_config_assistant_find_back_button_cb, + assistant); + /* Configure a new identity source. */ identity_source = e_source_new (NULL, NULL, NULL); @@ -817,6 +867,25 @@ mail_config_assistant_prepare (GtkAssistant *assistant, first_visit = TRUE; } + /* Are we viewing autoconfiguration results? If so, temporarily + * rename the back button to clarify that account details can be + * revised. Otherwise reset the button to its original label. */ + if (priv->back_button != NULL) { + gboolean auto_configure_results; + const gchar *label; + + auto_configure_results = + E_IS_MAIL_CONFIG_SUMMARY_PAGE (page) && + priv->auto_configured && first_visit; + + if (auto_configure_results) + label = _("_Revise Details"); + else + label = gettext (BACK_BUTTON_LABEL); + + gtk_button_set_label (priv->back_button, label); + } + if (E_IS_MAIL_CONFIG_LOOKUP_PAGE (page)) { AutoconfigContext *context; ESource *source; |