Cancel check support requests on tapping on cancel in the wizard checks dialog.
[modest] / src / hildon2 / modest-easysetup-wizard-dialog.c
index c68b833..8c9731c 100644 (file)
@@ -106,6 +106,7 @@ struct _ModestEasysetupWizardDialogPrivate
        GtkWidget *page_welcome;
        gboolean  check_support_done;
        guint check_support_show_progress_id;
+       GtkWidget *check_support_cancel_note;
        gint pending_check_support;
        gboolean destroyed;
 
@@ -387,23 +388,37 @@ create_page_welcome (ModestEasysetupWizardDialog *self)
        GtkWidget *box;
        GtkWidget *align;
        GtkWidget *label;
+       GtkWidget *privacy_note;
+       GtkWidget *pannable;
        ModestEasysetupWizardDialogPrivate *priv;
 
        priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
        box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
+       pannable = hildon_pannable_area_new ();
        label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
+       privacy_note = gtk_label_new (_("mcen_ia_privacy_notice"));
        align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
        gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
        gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+       gtk_widget_set_size_request (privacy_note, LABELS_WIDTH, -1);
+       gtk_label_set_line_wrap (GTK_LABEL (privacy_note), TRUE);
+       hildon_helper_set_logical_font (privacy_note, "SmallSystemFont");
        /* So that it is not truncated: */
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
        gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
-       gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (box), privacy_note, FALSE, FALSE, 0);
        gtk_container_add (GTK_CONTAINER (align), box);
        gtk_widget_show (label);
+       gtk_widget_show (privacy_note);
+
+       hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
        gtk_widget_show (GTK_WIDGET (box));
-       return GTK_WIDGET (align);
+       gtk_widget_show (GTK_WIDGET (align));
+       gtk_widget_show (pannable);
+
+       return GTK_WIDGET (pannable);
 }
 
 static void
@@ -1424,6 +1439,7 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
        /* Initialize fields */
        priv->check_support_done = FALSE;
        priv->check_support_show_progress_id = 0;
+       priv->check_support_cancel_note = NULL;
        priv->pending_check_support = 0;
        priv->destroyed = FALSE;
        priv->page_welcome = create_page_welcome (self);
@@ -1484,7 +1500,6 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
 
        priv->settings = modest_account_settings_new ();
 
-       check_support_of_protocols (self);
 }
 
 ModestEasysetupWizardDialog*
@@ -1567,17 +1582,31 @@ create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
 
 /* */
 static void
-remove_non_common_tabs (GtkNotebook *notebook,
+remove_non_common_tabs (ModestEasysetupWizardDialog *self,
                        gboolean remove_user_details)
 {
        gint starting_tab;
+       GtkNotebook *notebook;
+       ModestEasysetupWizardDialogPrivate *priv;
+
+       priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+       g_object_get (self, "wizard-notebook", &notebook, NULL);
+
        /* The first 2 tabs are the common ones (welcome tab and the
           providers tab), so we always remove starting from the
           end */
-
        starting_tab = (remove_user_details) ? 2 : 3;
-       while (gtk_notebook_get_n_pages (notebook) > starting_tab)
+       while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
+               /* Disconnect signal */
+               GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
+               if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
+                       priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
+                                                                                  (GObject *) page,
+                                                                                  "missing-mandatory-data");
+               }
+               /* Remove page from notebook */
                gtk_notebook_remove_page (notebook, -1);
+       }
 }
 
 static void
@@ -1604,8 +1633,12 @@ create_subsequent_pages (ModestEasysetupWizardDialog *self)
        picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
        id_type = modest_provider_picker_get_active_id_type (picker);
        g_object_get (self, "wizard-notebook", &notebook, NULL);
-       modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
-                                                           NULL);
+
+       /* Remove the response override handler for non-plugin
+          protocols. For plugins it'll be overriden later */
+       if (id_type != MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL)
+               modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
+                                                                   NULL);
 
 
        if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
@@ -1613,13 +1646,13 @@ create_subsequent_pages (ModestEasysetupWizardDialog *self)
 
                /* If we come from a rollbacked easysetup */
                if (priv->page_complete_easysetup) {
-                       remove_non_common_tabs (notebook, FALSE);
+                       remove_non_common_tabs (self, FALSE);
                        priv->page_complete_easysetup = NULL;
                }
 
                /* If we come from a rollbacked plugin protocol setup */
                if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
-                       remove_non_common_tabs (notebook, TRUE);
+                       remove_non_common_tabs (self, TRUE);
                        priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
                        modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
                        priv->missing_data_signals = NULL;
@@ -1629,7 +1662,7 @@ create_subsequent_pages (ModestEasysetupWizardDialog *self)
        } else {
                /* If we come from a rollbacked custom setup */
                if (priv->page_custom_incoming) {
-                       remove_non_common_tabs (notebook, TRUE);
+                       remove_non_common_tabs (self, TRUE);
                        init_user_page (priv);
                        init_incoming_page (priv);
                        init_outgoing_page (priv);
@@ -1642,6 +1675,7 @@ create_subsequent_pages (ModestEasysetupWizardDialog *self)
                        ModestProtocol *protocol;
                        gchar *proto_name;
                        ModestProtocolType proto_type;
+                       ModestWizardDialogResponseOverrideFunc response_override;
 
                        /* Get protocol data */
                        proto_name = modest_provider_picker_get_active_provider_id (picker);
@@ -1654,27 +1688,30 @@ create_subsequent_pages (ModestEasysetupWizardDialog *self)
                        /* If we come from a rollbacked easy setup */
                        if (priv->last_plugin_protocol_selected != proto_type &&
                            priv->page_complete_easysetup) {
-                               remove_non_common_tabs (notebook, TRUE);
+                               remove_non_common_tabs (self, TRUE);
                                init_user_page (priv);
                                priv->page_complete_easysetup = NULL;
                        }
 
+                       /* Ensure that the response override handler
+                          is set. It might happen that plugins clear
+                          them incorrectly */
+                       response_override = modest_account_protocol_get_wizard_response_override
+                               (MODEST_ACCOUNT_PROTOCOL (protocol));
+                       modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
+                                                                           response_override);
+
                        if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
                            proto_type != priv->last_plugin_protocol_selected) {
                                ModestPairList *tabs;
                                GSList *tmp;
                                gboolean first_page = TRUE;
-                               ModestWizardDialogResponseOverrideFunc response_override;
 
                                /* Remember the last selected plugin protocol */
                                priv->last_plugin_protocol_selected = proto_type;
 
                                /* Get tabs */
                                tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
-                               response_override = modest_account_protocol_get_wizard_response_override
-                                       (MODEST_ACCOUNT_PROTOCOL (protocol));
-                               modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
-                                                                                   response_override);
                                tmp = (GSList *) tabs;
                                while (tmp) {
                                        ModestPair *pair = (ModestPair *) tmp->data;
@@ -1708,7 +1745,7 @@ create_subsequent_pages (ModestEasysetupWizardDialog *self)
                } else {
                        if (priv->last_plugin_protocol_selected !=
                            MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
-                               remove_non_common_tabs (notebook, TRUE);
+                               remove_non_common_tabs (self, TRUE);
                                init_user_page (priv);
                                priv->page_complete_easysetup = NULL;
                                priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
@@ -1861,7 +1898,12 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *
         * either because it was too slow,
         * or because it requires interaction:
         */
-       if (current_page == priv->page_account_details) {
+       if (current_page == priv->page_welcome) {
+               if (!priv->check_support_done) {
+                       check_support_of_protocols (self);
+                       return priv->check_support_done;
+               }
+       } else if (current_page == priv->page_account_details) {
                /* Check that the title is not already in use: */
                gchar* account_title = get_entered_account_title (self);
                if (!account_title)
@@ -2008,7 +2050,7 @@ real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
 
                /* If the check support is not done then do not enable
                   the wizard to continue */
-               enable_next = enable_next && priv->check_support_done;
+               enable_next = enable_next && priv->pending_check_support == 0;
        }
 
        gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
@@ -2458,16 +2500,62 @@ check_support_callback (ModestAccountProtocol *protocol,
        if (priv->pending_check_support == 0) {
                priv->check_support_done = TRUE;
 
+               if (priv->check_support_cancel_note) {
+                       gtk_widget_destroy (priv->check_support_cancel_note);
+                       priv->check_support_cancel_note = NULL;
+               }
+
                if (!priv->destroyed) {
                        if (priv->presets)
                                fill_providers (self);
                        hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
                        invoke_enable_buttons_vfunc (self);
+                       gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
                }
        }
        g_object_unref (self);
 }
 
+static void
+on_check_support_cancel (GtkDialog *cancel_note,
+                        gint response,
+                        ModestEasysetupWizardDialog *self)
+{
+       ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+       ModestProtocolRegistry *registry;
+       GSList *provider_protos, *node;
+
+       registry = modest_runtime_get_protocol_registry ();
+       provider_protos = modest_protocol_registry_get_by_tag (registry,
+                                                              MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
+
+       for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
+               ModestProtocol *proto = MODEST_PROTOCOL (node->data);
+
+               if (!modest_protocol_registry_protocol_type_has_tag (registry,
+                                                                    modest_protocol_get_type_id (proto),
+                                                                    MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
+                       continue;
+
+               if (modest_protocol_registry_protocol_type_has_tag
+                   (registry,
+                    modest_protocol_get_type_id (proto),
+                    MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
+                       /* Check if there's already an account configured with this account type */
+                       if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
+                                                                         modest_protocol_get_type_id (proto)))
+                               continue;
+               }
+
+               if (MODEST_ACCOUNT_PROTOCOL (proto)) {
+                       modest_account_protocol_cancel_check_support (MODEST_ACCOUNT_PROTOCOL (proto));
+               }
+       }
+       g_slist_free (provider_protos);
+
+       gtk_widget_destroy (GTK_WIDGET (cancel_note));
+       priv->check_support_cancel_note = NULL;
+}
 
 static void
 check_support_of_protocols (ModestEasysetupWizardDialog *self)
@@ -2511,6 +2599,11 @@ check_support_of_protocols (ModestEasysetupWizardDialog *self)
                priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
                                                                           check_support_show_progress,
                                                                           g_object_ref (self), g_object_unref);
+               priv->check_support_cancel_note = hildon_note_new_cancel_with_progress_bar (GTK_WINDOW (self),
+                                                                                           _("mcen_cn_availability_check"),
+                                                                                           NULL);
+               gtk_widget_show (priv->check_support_cancel_note);
+               g_signal_connect (priv->check_support_cancel_note, "response", G_CALLBACK (on_check_support_cancel), self);
        } else {
                priv->check_support_done = TRUE;
        }