* Fixes NB#85378, show the connection specific SMTP and not the account settings...
authorSergio Villar Senin <svillar@igalia.com>
Mon, 12 May 2008 16:47:19 +0000 (16:47 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Mon, 12 May 2008 16:47:19 +0000 (16:47 +0000)
* Track the "destroy" signal for modal dialogs, it could cause the "response" not to be issued
* Fixed the connection specific SMTP dialog modality (uses the window mgr)
* Add the buttons to the connection specific SMTP dialog with gtk_dialog_add_button as it should be
* Removed an invalid while

pmo-trunk-r4515

src/maemo/easysetup/modest-easysetup-wizard-dialog.c
src/maemo/modest-connection-specific-smtp-window.c
src/modest-tny-account-store.c
src/modest-ui-actions.c
src/widgets/modest-window-mgr.c

index 94845c1..5aab10c 100644 (file)
@@ -757,9 +757,6 @@ update_incoming_server_title (ModestEasysetupWizardDialog *self)
                 _("mail_fi_emailtype_imap") );
                        
                
-       /* Note that this produces a compiler warning, 
-        * because the compiler does not know that the translated string will have a %s in it.
-        * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
        gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
        g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
        g_free(incomingserver_title);
index 64513d2..8215147 100644 (file)
@@ -68,7 +68,11 @@ struct _ModestConnectionSpecificSmtpWindowPrivate
        ModestAccountMgr *account_manager;
 };
 
-static gboolean on_key_pressed (GtkWidget *self, GdkEventKey *event, gpointer user_data);
+static void on_response (GtkDialog *dialog, 
+                        gint response, 
+                        gpointer user_data);
+
+/* static gboolean on_key_pressed (GtkWidget *self, GdkEventKey *event, gpointer user_data); */
 
 static void
 modest_connection_specific_smtp_window_get_property (GObject *object, guint property_id,
@@ -219,11 +223,10 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp
        update_model_server_names (self);
 #endif /*MODEST_HAVE_CONIC */
 }
-       
+       
 static void
-on_button_edit (GtkButton *button, gpointer user_data)
+on_button_edit (ModestConnectionSpecificSmtpWindow *self)
 {
-       ModestConnectionSpecificSmtpWindow *self = MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (user_data);
        ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
        ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
        
@@ -235,15 +238,15 @@ on_button_edit (GtkButton *button, gpointer user_data)
        GtkTreeIter iter;
        GtkTreeModel *model = 0;
        if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
-               gtk_tree_model_get (priv->model, &iter, 
-                                   MODEL_COL_ID, &id, 
-                                   MODEL_COL_NAME, &connection_name, 
+               gtk_tree_model_get (priv->model, &iter,
+                                   MODEL_COL_ID, &id,
+                                   MODEL_COL_NAME, &connection_name,
                                    MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
                                    MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
                                    -1);
        
                /* printf("DEBUG: %s: BEFORE: connection-specific server_account_name=%s\n", __FUNCTION__, server_account_name); */
-               /* TODO: Is 0 an allowed libconic IAP ID? 
+               /* TODO: Is 0 an allowed libconic IAP ID?
                 * If not then we should check for it. */
                
                /* Get existing server account data if a server account is already specified: */
@@ -266,46 +269,36 @@ on_button_edit (GtkButton *button, gpointer user_data)
                        
                modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (window));
                
-               gboolean dialog_finished = FALSE;
-               while (!dialog_finished)
-               {
-                       gint response = gtk_dialog_run (GTK_DIALOG (window));
-                       if (response == GTK_RESPONSE_OK) {
-                               gtk_widget_hide (window);
-                               dialog_finished = TRUE;
-                               /* Delete any previous data for this row: */
-                               if (server_settings) 
-                               {
-                                       g_object_unref (server_settings);
-                                       server_settings = NULL;
-                               }
-                               
-                               /* Get the new account data and save it in the row for later:
-                                * We free this in finalize(),
-                                * and save it to our configuration in 
-                                * modest_connection_specific_smtp_window_save_server_accounts(). */
-                               server_settings = modest_connection_specific_smtp_edit_window_get_settings (
-                                       MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window));
-                               
-                               if (server_settings) {
-                                       gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
-                                                           MODEL_COL_SERVER_ACCOUNT_SETTINGS, server_settings,
-                                                           MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
-                                                           -1);
-                               } else {
-                                       gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
-                                                           MODEL_COL_SERVER_ACCOUNT_SETTINGS, NULL,
-                                                           MODEL_COL_SERVER_NAME, NULL,
-                                                           MODEL_COL_SERVER_ACCOUNT_NAME, NULL,
-                                                           -1);
-                               }
+               gint response = gtk_dialog_run (GTK_DIALOG (window));
+               if (response == GTK_RESPONSE_OK) {
+
+                       /* Delete any previous data for this row: */
+                       if (server_settings) {
+                               g_object_unref (server_settings);
+                               server_settings = NULL;
                        }
-                       else
-                       {
-                               gtk_widget_hide(window);
-                               dialog_finished = TRUE;
+                       
+                       /* Get the new account data and save it in the row for later:
+                        * We free this in finalize(),
+                        * and save it to our configuration in
+                        * modest_connection_specific_smtp_window_save_server_accounts(). */
+                       server_settings = modest_connection_specific_smtp_edit_window_get_settings (
+                                                                                                   MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window));
+                       
+                       if (server_settings) {
+                               gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
+                                                   MODEL_COL_SERVER_ACCOUNT_SETTINGS, server_settings,
+                                                   MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
+                                                   -1);
+                       } else {
+                               gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
+                                                   MODEL_COL_SERVER_ACCOUNT_SETTINGS, NULL,
+                                                   MODEL_COL_SERVER_NAME, NULL,
+                                                   MODEL_COL_SERVER_ACCOUNT_NAME, NULL,
+                                                   -1);
                        }
                }
+               gtk_widget_destroy (window);
        }
        g_free (connection_name);
        g_free (id);
@@ -314,16 +307,6 @@ on_button_edit (GtkButton *button, gpointer user_data)
 }
 
 static void
-on_button_cancel (GtkButton *button, gpointer user_data)
-{
-       ModestConnectionSpecificSmtpWindow *self = MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (user_data);
-
-       /* Hide the window.
-        * The code that showed it will respond to the hide signal. */  
-       gtk_widget_hide (GTK_WIDGET (self));
-}
-
-static void
 on_selection_changed (GtkTreeSelection *sel, ModestConnectionSpecificSmtpWindow *self)
 {
        ModestConnectionSpecificSmtpWindowPrivate *priv = 
@@ -367,7 +350,7 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
 
        /* Show the column headers,
         * which does not seem to be the default on Maemo.
-        */                     
+        */
        gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(priv->treeview), TRUE);
        
        /* name column:
@@ -417,27 +400,12 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (priv->treeview));
        gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (scrolled_window), TRUE, TRUE, MODEST_MARGIN_HALF);
        gtk_widget_show (GTK_WIDGET (priv->treeview));
-       
-       /* Add the buttons: */
-       GtkWidget *hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_HALF);
-       gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (hbox);
-       
-       priv->button_edit = gtk_button_new_from_stock (_("mcen_bd_edit"));
-       gtk_box_pack_start (GTK_BOX (hbox), priv->button_edit, TRUE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (priv->button_edit);
-       g_signal_connect (G_OBJECT (priv->button_edit), "clicked",
-               G_CALLBACK (on_button_edit), self);
-       
-       GtkWidget *button_cancel = gtk_button_new_from_stock (_("mcen_bd_close"));
-       gtk_box_pack_start (GTK_BOX (hbox), button_cancel, TRUE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (button_cancel);
-       g_signal_connect (G_OBJECT (button_cancel), "clicked",
-               G_CALLBACK (on_button_cancel), self);
-       
-       //gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (vbox));
        gtk_widget_show (vbox);
        
+       /* Hack: we use the response apply to identify the click on the edit button */
+       priv->button_edit = gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_edit"), GTK_RESPONSE_APPLY);
+       gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_close"), GTK_RESPONSE_CLOSE);
+       
        /* Disable the Edit button when nothing is selected: */
        GtkTreeSelection *sel = gtk_tree_view_get_selection (priv->treeview);
        g_signal_connect (sel, "changed",
@@ -453,10 +421,7 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        /* Set window title */
        gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers"));
 
-       /* Track key presses to close the window if the Escape is pressed */
-       g_signal_connect (G_OBJECT (self), 
-                         "key-press-event", 
-                         G_CALLBACK (on_key_pressed), NULL);
+       g_signal_connect (self, "response", G_CALLBACK (on_response), NULL);
        
        hildon_help_dialog_help_enable (GTK_DIALOG(self),
                                        "applications_email_connectionsspecificsmtpconf",
@@ -594,15 +559,23 @@ void update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
        }
 }
 
-static gboolean
-on_key_pressed (GtkWidget *self,
-               GdkEventKey *event,
-               gpointer user_data)
+static void
+on_response (GtkDialog *dialog,
+            gint response,
+            gpointer user_data)
 {
-       if (event->keyval == GDK_Escape) {
-               /* Simulate a press on Cancel to close the dialog */
-               on_button_cancel (NULL, self);
+       switch (response) {
+       case GTK_RESPONSE_APPLY:
+               /* We use it for the edit button */
+               on_button_edit (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog));
+               g_signal_stop_emission_by_name (dialog, "response");
+               break;
+       case GTK_RESPONSE_CLOSE:
+       case GTK_RESPONSE_NONE:
+       case GTK_RESPONSE_DELETE_EVENT:
+               /* Generated as a response to delete-event, i.e,
+                  pressin Esc, or by pressing the Close button */
+               modest_connection_specific_smtp_window_save_server_accounts (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog));
+               gtk_widget_destroy (GTK_WIDGET (dialog));
        }
-       
-       return FALSE;
 }
index 4d29902..a0fd3de 100644 (file)
@@ -521,9 +521,8 @@ show_wrong_password_dialog (TnyAccount *account)
 { 
        /* This is easier than using a struct for the user_data: */
        ModestTnyAccountStore *self = modest_runtime_get_account_store();
-       const gchar *modest_account_name;
        GtkWidget *main_window;
-       GtkWidget *dialog;
+       GtkWidget *dialog = NULL;
 
        main_window = (GtkWidget *) modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
                                                                       FALSE); /* don't create */
@@ -532,16 +531,16 @@ show_wrong_password_dialog (TnyAccount *account)
                return;
        }
 
-       modest_account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
-       if (!modest_account_name) {
-               g_warning ("%s: modest_tny_account_get_parent_modest_account_name_for_server_account() failed.\n", 
-                       __FUNCTION__);
+       if (g_object_get_data (G_OBJECT (account), "connection_specific") != NULL) {
+               modest_ui_actions_on_smtp_servers (NULL, NULL);
+       } else {
+               const gchar *modest_account_name;
+               modest_account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);   
+               dialog = modest_tny_account_store_show_account_settings_dialog (self, modest_account_name);
+               modest_account_settings_dialog_save_password (MODEST_ACCOUNT_SETTINGS_DIALOG (dialog));
        }
-       
-       dialog = modest_tny_account_store_show_account_settings_dialog (self, modest_account_name);
-       modest_account_settings_dialog_save_password (MODEST_ACCOUNT_SETTINGS_DIALOG (dialog));
        /* Show an explanatory temporary banner: */
-       modest_platform_information_banner (GTK_WIDGET(dialog), NULL, _("mcen_ib_username_pw_incorrect"));
+       modest_platform_information_banner (dialog, NULL, _("mcen_ib_username_pw_incorrect"));
 }
 
 /* This callback will be called by Tinymail when it needs the password
@@ -970,16 +969,8 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr,
           global OUTBOX hosted in the local account */
        add_existing_accounts (MODEST_TNY_ACCOUNT_STORE (obj));
        
-       /* FIXME: I'm doing this (adding an "if (FALSE)"because this
-          stuff is not working properly and could cause SIGSEVs, for
-          example one send queue will be created for each connection
-          specific SMTP server, so when tinymail asks for the outbox
-          it will return NULL because there is no outbox folder for
-          this specific transport accounts, and it's a must that the
-          send queue returns an outbox */
-       if (TRUE)
-               /* Add connection-specific transport accounts */
-               add_connection_specific_transport_accounts (MODEST_TNY_ACCOUNT_STORE(obj));
+       /* Add connection-specific transport accounts */
+       add_connection_specific_transport_accounts (MODEST_TNY_ACCOUNT_STORE(obj));
        
        /* This is a singleton, so it does not need to be unrefed. */
        if (volume_path_is_mounted (MODEST_MCC1_VOLUMEPATH)) {
@@ -1913,6 +1904,9 @@ modest_tny_account_store_new_connection_specific_transport_account (ModestTnyAcc
                g_object_set_data (G_OBJECT(tny_account), 
                                   "account_store", 
                                   (gpointer)self);
+               g_object_set_data (G_OBJECT(tny_account), 
+                                  "connection_specific", 
+                                  GINT_TO_POINTER (TRUE));
                
                tny_list_append (priv->transport_accounts, G_OBJECT (tny_account));
                add_outbox_from_transport_account_to_global_outbox (self, 
index 9106f02..f69a922 100644 (file)
@@ -655,18 +655,6 @@ modest_ui_actions_on_accounts (GtkAction *action,
        }
 }
 
-#ifdef MODEST_PLATFORM_MAEMO
-static void
-on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
-{
-       /* Save any changes. */
-       modest_connection_specific_smtp_window_save_server_accounts (
-                       MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
-       gtk_widget_destroy (GTK_WIDGET (window));
-}
-#endif
-
-
 void
 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
 {
@@ -682,14 +670,10 @@ modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
                MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), 
                modest_runtime_get_account_mgr());
 
-       /* Show the window: */  
-       gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
-       gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
+       /* Show the window: */
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
+                                    GTK_WINDOW (specific_window));
        gtk_widget_show (specific_window);
-    
-       /* Save changes when the window is hidden: */
-       g_signal_connect (specific_window, "hide", 
-               G_CALLBACK (on_smtp_servers_window_hide), win);
 #endif /* MODEST_PLATFORM_MAEMO */
 }
 
index 6e93da1..43297e9 100644 (file)
@@ -52,6 +52,9 @@ static gboolean on_modal_window_close    (GtkWidget *widget,
                                          GdkEvent *event,
                                          gpointer user_data);
 
+static void on_modal_dialog_destroy      (GtkObject *object,
+                                         gpointer   user_data);
+
 static void     on_modal_dialog_close    (GtkDialog *dialog,
                                          gint arg1,
                                          gpointer user_data);
@@ -1130,7 +1133,7 @@ modest_window_mgr_set_modal (ModestWindowMgr *self,
        g_queue_push_head (priv->modal_windows, window);
        g_mutex_unlock (priv->queue_lock);
 
-       if (GTK_IS_DIALOG (window))
+       if (GTK_IS_DIALOG (window)) {
                /* Note that response is not always enough because it
                   could be captured and removed easily by dialogs but
                   works for most of situations */
@@ -1140,13 +1143,23 @@ modest_window_mgr_set_modal (ModestWindowMgr *self,
                                                   "response",
                                                   G_CALLBACK (on_modal_dialog_close), 
                                                   self);
-       else
+               /* We need this as well because dialogs are often
+                  destroyed with gtk_widget_destroy and this one will
+                  prevent response from happening */
+               priv->modal_handler_uids = 
+                       modest_signal_mgr_connect (priv->modal_handler_uids, 
+                                                  G_OBJECT (window), 
+                                                  "destroy",
+                                                  G_CALLBACK (on_modal_dialog_destroy),
+                                                  self);
+       } else {
                priv->modal_handler_uids = 
                        modest_signal_mgr_connect (priv->modal_handler_uids, 
                                                   G_OBJECT (window), 
                                                   "delete-event",
                                                   G_CALLBACK (on_modal_window_close), 
                                                   self);
+       }
 }
 
 
@@ -1271,12 +1284,17 @@ remove_modal_from_queue (GtkWidget *widget,
        g_mutex_unlock (priv->queue_lock);
 
        /* Disconnect handler */
-       priv->modal_handler_uids = 
-               modest_signal_mgr_disconnect (priv->modal_handler_uids, 
+       priv->modal_handler_uids =
+               modest_signal_mgr_disconnect (priv->modal_handler_uids,
                                              G_OBJECT (widget),
-                                             GTK_IS_DIALOG (widget) ? 
-                                             "response" : 
-                                             "destroy-event");
+                                             GTK_IS_DIALOG (widget) ?
+                                             "response" :
+                                             "delete-event");
+       if (GTK_IS_DIALOG (widget))
+               priv->modal_handler_uids =
+                       modest_signal_mgr_disconnect (priv->modal_handler_uids,
+                                                     G_OBJECT (widget),
+                                                     "destroy");
 
        /* Schedule the next one for being shown */
        g_idle_add (idle_top_modal, self);
@@ -1303,10 +1321,22 @@ on_modal_dialog_close (GtkDialog *dialog,
 {
        ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data);
 
-       /* Remove modal window from queue */
+       /* Remove modal window from queue. Note that if "destroy"
+          signal was invoked before the response the window could be
+          already deleted */
        remove_modal_from_queue (GTK_WIDGET (dialog), self);
 }
 
+static void
+on_modal_dialog_destroy (GtkObject *object,
+                        gpointer   user_data)
+{
+       ModestWindowMgr *self = MODEST_WINDOW_MGR (user_data);
+
+       /* Remove modal window from queue */
+       remove_modal_from_queue (GTK_WIDGET (object), self);
+}
+
 gint 
 modest_window_mgr_num_windows (ModestWindowMgr *self)
 {