2007-08-29 Murray Cumming <murrayc@murrayc.com>
[modest] / src / maemo / modest-connection-specific-smtp-window.c
index 26278ce..be4ad5c 100644 (file)
@@ -1,4 +1,31 @@
-/* connection-specific-smtp-window.c */
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
 #include "modest-connection-specific-smtp-window.h"
 #include "modest-connection-specific-smtp-edit-window.h"
@@ -17,6 +44,9 @@
 #include <gtk/gtkvbox.h>
 #include <gtk/gtkstock.h>
 
+#include "modest-hildon-includes.h"
+#include "modest-platform.h"
+
 #include <glib/gi18n.h>
 
 G_DEFINE_TYPE (ModestConnectionSpecificSmtpWindow, modest_connection_specific_smtp_window, GTK_TYPE_WINDOW);
@@ -232,33 +262,58 @@ on_button_edit (GtkButton *button, gpointer user_data)
                }
                        
                gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
-               gint response = gtk_dialog_run (GTK_DIALOG (window));
-               gtk_widget_hide (window);
                
-               if (response == GTK_RESPONSE_OK) {
-                       /* Delete any previous data for this row: */
-                       if (data) 
+               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 (data) 
+                               {
+                                       modest_account_mgr_free_server_account_data (priv->account_manager, data);
+                                       data = 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(). */
+                               data = modest_connection_specific_smtp_edit_window_get_settings (
+                                                       MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), 
+                                                       priv->account_manager);
+                               
+                               const gchar* server_name = data ? data->hostname : NULL;
+                               gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
+                                               MODEL_COL_SERVER_ACCOUNT_DATA, data,
+                                               MODEL_COL_SERVER_NAME, server_name,
+                                               -1);
+                       }
+                       else
                        {
-                               modest_account_mgr_free_server_account_data (priv->account_manager, data);
-                               data = NULL;
+                               if (!modest_connection_specific_smtp_edit_window_is_dirty(
+                                               MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW(window)))
+                               {
+                                       gtk_widget_hide(window);
+                                       dialog_finished = TRUE;
+                               }
+                               else
+                               {
+                                               
+                                       gint response;
+                                       response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window), 
+                                                                           _("imum_nc_wizard_confirm_lose_changes"));                   
+                                       if (response == GTK_RESPONSE_OK)
+                                       {
+                                               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(). */
-                       data = modest_connection_specific_smtp_edit_window_get_settings (
-                                               MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), 
-                                               priv->account_manager);
-                       
-                       const gchar* server_name = data ? data->hostname : NULL;
-                       gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
-                                       MODEL_COL_SERVER_ACCOUNT_DATA, data,
-                                       MODEL_COL_SERVER_NAME, server_name,
-                                       -1);
                }
        }
-       
        g_free (connection_name);
        g_free (id);
        g_free (server_account_name);
@@ -346,10 +401,15 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        GtkWidget *vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
 
        /* Introductory note: */
+       /* TODO: For some reason this label does not wrap. It is truncated. */
        GtkWidget *label = gtk_label_new(_("mcen_ia_optionalsmtp_note"));
        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
        /* So that it is shown without being truncated: */
-       gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
+       gtk_label_set_max_width_chars (GTK_LABEL (label), 20);
+       /* The documentation for gtk_label_set_line_wrap() says that we must 
+        * call gtk_widget_set_size_request() with a hard-coded width, 
+        * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
+       gtk_widget_set_size_request (label, 400, -1);
        gtk_widget_show (label);
        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, MODEST_MARGIN_HALF);
        
@@ -368,13 +428,13 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        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 (GTK_STOCK_EDIT);
+       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 (GTK_STOCK_CLOSE);
+       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",