Avoid wait on taking screenshot. Now it shouldn't be required.
[modest] / src / hildon2 / modest-connection-specific-smtp-window.c
index 536fda3..e2f312e 100644 (file)
 #include "widgets/modest-ui-constants.h"
 
 #include <modest-runtime.h>
+
+#if MODEST_HAVE_CONIC
 #include <tny-maemo-conic-device.h>
+#endif
 
 #include <gtk/gtktreeview.h>
 #include <gtk/gtkcellrenderertext.h>
@@ -66,7 +69,6 @@ struct _ModestConnectionSpecificSmtpWindowPrivate
        GtkTreeModel *model;
        GtkWidget *no_connection_label;
        GtkWidget *pannable;
-       
        ModestAccountMgr *account_manager;
 };
 
@@ -112,35 +114,35 @@ enum MODEL_COLS {
 };
 
 
-void update_model_server_names (ModestConnectionSpecificSmtpWindow *self);
+static void update_model_server_names (ModestConnectionSpecificSmtpWindow *self);
 
 static void
 modest_connection_specific_smtp_window_finalize (GObject *object)
 {
        ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (object);
-       
+
        /* Free all the data items from the treemodel: */
        GtkTreeIter iter;
        gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
        while (valid) {
                ModestServerAccountSettings *server_settings = NULL;
-               
+
                gtk_tree_model_get (priv->model, &iter, 
                                    MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
                                    -1);
-                                
+
                if (server_settings)
                        g_object_unref (server_settings);
-                       
+
                /* Get next row: */
                valid = gtk_tree_model_iter_next (priv->model, &iter);
        }
-       
+
        g_object_unref (G_OBJECT (priv->model));
 
        g_object_unref (priv->treeview);
        g_object_unref (priv->no_connection_label);
-       
+
        G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->finalize (object);
 }
 
@@ -167,11 +169,10 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp
                                                              ModestAccountMgr *account_manager)
 {
        gboolean empty = TRUE;
-#ifdef MODEST_HAVE_CONIC
        ModestConnectionSpecificSmtpWindowPrivate *priv = 
                CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
        priv->account_manager = account_manager;
-       
+#ifdef MODEST_HAVE_CONIC
        GtkListStore *liststore = GTK_LIST_STORE (priv->model);
        
        TnyDevice *device = modest_runtime_get_device ();
@@ -267,11 +268,7 @@ edit_account (ModestConnectionSpecificSmtpWindow *self, GtkTreePath *path)
                                    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?
-                * If not then we should check for it. */
-               
+
                /* Get existing server account data if a server account is already specified: */
                gboolean settings_were_retrieved = FALSE;
                if (server_account_name && !server_settings) {
@@ -279,19 +276,19 @@ edit_account (ModestConnectionSpecificSmtpWindow *self, GtkTreePath *path)
                        if (server_settings)
                                settings_were_retrieved = TRUE;
                }
-               
+
                GtkWidget * window = GTK_WIDGET (modest_connection_specific_smtp_edit_window_new ());
                modest_connection_specific_smtp_edit_window_set_connection (
                        MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name, server_settings);
-                       
+
                /* Delete data, unless it was data from the rowmodel: */
                if (settings_were_retrieved) {
                        g_object_unref (server_settings);
                        server_settings = NULL;
                }
-                       
+
                modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (window), GTK_WINDOW (self));
-               
+
                gint response = gtk_dialog_run (GTK_DIALOG (window));
                if (response == GTK_RESPONSE_OK) {
 
@@ -300,14 +297,14 @@ edit_account (ModestConnectionSpecificSmtpWindow *self, GtkTreePath *path)
                                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,
@@ -340,16 +337,17 @@ static void
 modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow *self)
 {
        ModestWindowMgr *mgr;
+       GtkWidget *align;
 
        /* Specify a default size */
-       gtk_window_set_default_size (GTK_WINDOW (self), -1, 320);
-       
+       gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
+
        /* This seems to be necessary to make the window show at the front with decoration.
         * If we use property type=GTK_WINDOW_TOPLEVEL instead of the default GTK_WINDOW_POPUP+decoration, 
         * then the window will be below the others. */
        gtk_window_set_type_hint (GTK_WINDOW (self),
                            GDK_WINDOW_TYPE_HINT_DIALOG);
-                           
+
        ModestConnectionSpecificSmtpWindowPrivate *priv = 
                CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
 
@@ -371,50 +369,49 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        /* name column:
         * The ID model column in not shown in the view. */
        GtkTreeViewColumn *view_column = gtk_tree_view_column_new ();
+       gtk_tree_view_column_set_expand (view_column, TRUE);
        GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+       g_object_set (G_OBJECT (renderer), "xpad", MODEST_MARGIN_DOUBLE, NULL);
        gtk_tree_view_column_pack_start(view_column, renderer, TRUE);
        gtk_tree_view_column_set_attributes (view_column, renderer, 
        "text", MODEL_COL_NAME, NULL);
        gtk_tree_view_append_column (priv->treeview, view_column);
 
-       
        /* server name column: */
        view_column = gtk_tree_view_column_new ();
+       gtk_tree_view_column_set_expand (view_column, TRUE);
        renderer = gtk_cell_renderer_text_new ();
        gtk_tree_view_column_pack_start(view_column, renderer, TRUE);
        gtk_tree_view_column_set_attributes (view_column, renderer, 
        "text", MODEL_COL_SERVER_NAME, NULL);
        gtk_tree_view_append_column (priv->treeview, view_column);
-       
+
        /* The application must call modest_connection_specific_smtp_window_fill_with_connections(). */
-       
+
        GtkWidget *vbox = GTK_DIALOG(self)->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);
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-       /* So that it is shown without being truncated: */
-       /* 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_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE + MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
+       gtk_widget_set_size_request (label, 600, -1);
        gtk_widget_show (label);
-       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, MODEST_MARGIN_HALF);
-       
+       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
        /* Put the treeview in a pannable and add it to the box: */
        priv->pannable = hildon_pannable_area_new ();
+       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);
        g_object_set (G_OBJECT (priv->pannable), "initial-hint", TRUE, NULL);
-       gtk_container_set_border_width (GTK_CONTAINER (priv->pannable), MODEST_MARGIN_DEFAULT);
        gtk_widget_show (priv->pannable);
-       gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->pannable), TRUE, TRUE, MODEST_MARGIN_HALF);
+       gtk_widget_show (align);
+       gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->pannable));
+       gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (align), TRUE, TRUE, 0);
        gtk_widget_show (vbox);
-       
+
        g_signal_connect (G_OBJECT (priv->treeview), "row-activated", G_CALLBACK (on_row_activated), self);
-       
+
        /* When this window is shown, hibernation should not be possible, 
         * because there is no sensible way to save the state: */
        mgr = modest_runtime_get_window_mgr ();
@@ -425,7 +422,6 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers"));
 
        g_signal_connect (self, "response", G_CALLBACK (on_response), NULL);
-       
 }
 
 ModestConnectionSpecificSmtpWindow*
@@ -442,8 +438,8 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe
        ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
        ModestConnectionSpecificSmtpWindowPrivate *priv = 
                CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
-       
-       
+
+
        /* Get the first iter in the list */
        GtkTreeIter iter;
        gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
@@ -455,7 +451,7 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe
                gchar *server_account_name = NULL;
                gchar *server_name = NULL;
                ModestServerAccountSettings *server_settings = NULL;
-               
+
                gtk_tree_model_get (priv->model, &iter, 
                                    MODEL_COL_ID, &id, 
                                    MODEL_COL_NAME, &connection_name, 
@@ -463,8 +459,8 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe
                                    MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
                                    MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
                                    -1);
-                                
-               gboolean success = TRUE;   
+               gboolean success = TRUE;
                if (id && server_settings) { /* The presence of data suggests that there is something to save. */
                        if (!server_account_name) {
                                /* Add a new server account, building a (non-human-visible) name: */
@@ -473,7 +469,7 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe
                                        priv->account_manager, name_start, TRUE /* server account. */);
                                g_assert (server_account_name);
                                g_free (name_start);
-                               
+
                                modest_server_account_settings_set_account_name (server_settings, server_account_name);
                                success = modest_account_mgr_save_server_settings (mgr, server_settings);
                                if (success) {
@@ -483,16 +479,17 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe
                                        if (account)
                                                g_object_unref (account);
                                }
-                               
+
                                /* associate the specific server account with this connection for this account: */
                                success = success && modest_account_mgr_set_connection_specific_smtp (
                                        priv->account_manager, id, server_account_name);
-                               
+
                                /* Save the new name in the treemodel, so it can be edited again later: */
                                gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
                                        MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1);
-                               
+
                        } else {
+                               /* If the account already exists then update it and notify */
                                modest_account_mgr_save_server_settings (mgr, server_settings);
                        }
                } else if (id && server_name && 
@@ -502,49 +499,50 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe
                        gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
                                            MODEL_COL_SERVER_ACCOUNT_NAME, NULL, -1);
                }
-               
+
                g_free (connection_name);
                g_free (id);
                g_free (server_account_name);
                g_free (server_name);
-               
+
                if (!success)
                        return FALSE;
-                       
+
                /* Get next row: */
                valid = gtk_tree_model_iter_next (priv->model, &iter);
        }
-       
+
        update_model_server_names (self);
-       
+
        return TRUE;
 }
 
-void update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
+static void
+update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
 {
        ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
 
        GtkTreeIter iter;
        gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
        while (valid) {
-               
+
                gchar *server_account_name = NULL;
                ModestServerAccountSettings *server_settings = NULL;
                gtk_tree_model_get (priv->model, &iter, 
                                    MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
                                    MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
-                                   -1);        
+                                   -1);
                if (server_settings && modest_server_account_settings_get_hostname (server_settings)
                    && (modest_server_account_settings_get_hostname (server_settings) [0] != '\0')) {
                        gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
                                            MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
                                            -1);
                } else if (server_account_name) {
-                       
-                       /* Get the server hostname and show it in the treemodel: */     
-                       gchar *hostname = modest_account_mgr_get_server_account_hostname (priv->account_manager, 
+
+                       /* Get the server hostname and show it in the treemodel: */
+                       gchar *hostname = modest_account_mgr_get_server_account_hostname (priv->account_manager,
                                                                                          server_account_name);
-                       gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
+                       gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
                                            MODEL_COL_SERVER_NAME, hostname,
                                            -1);
                        g_free (hostname);
@@ -553,7 +551,7 @@ void update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
                                            MODEL_COL_SERVER_NAME, _("mcen_ia_optionalsmtp_notdefined"),
                                            -1);
                }
-                       
+
                /* Get next row: */
                valid = gtk_tree_model_iter_next (priv->model, &iter);
        }