This is a manual merge of branch drop split view intro trunk.
[modest] / src / hildon2 / modest-connection-specific-smtp-window.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "modest-connection-specific-smtp-window.h"
31 #include "modest-connection-specific-smtp-edit-window.h"
32 #include <modest-account-mgr-helpers.h>
33 #include "widgets/modest-ui-constants.h"
34
35 #include <modest-runtime.h>
36 #include <tny-maemo-conic-device.h>
37
38 #include <gtk/gtktreeview.h>
39 #include <gtk/gtkcellrenderertext.h>
40 #include <gtk/gtkliststore.h>
41 #include <hildon/hildon-pannable-area.h>
42 #include <hildon/hildon-gtk.h>
43 #include <gtk/gtkbutton.h>
44 #include <gtk/gtkhbox.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkstock.h>
47
48 #include "modest-hildon-includes.h"
49 #include "modest-platform.h"
50 #include "modest-maemo-utils.h"
51
52 #include <glib/gi18n.h>
53 #include <string.h>
54
55 G_DEFINE_TYPE (ModestConnectionSpecificSmtpWindow, modest_connection_specific_smtp_window,
56                GTK_TYPE_DIALOG);
57
58 #define CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE(o) \
59         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_WINDOW, ModestConnectionSpecificSmtpWindowPrivate))
60
61 typedef struct _ModestConnectionSpecificSmtpWindowPrivate ModestConnectionSpecificSmtpWindowPrivate;
62
63 struct _ModestConnectionSpecificSmtpWindowPrivate
64 {
65         GtkTreeView *treeview;
66         GtkTreeModel *model;
67         
68         ModestAccountMgr *account_manager;
69 };
70
71 static void on_response (GtkDialog *dialog, 
72                          gint response, 
73                          gpointer user_data);
74
75 /* static gboolean on_key_pressed (GtkWidget *self, GdkEventKey *event, gpointer user_data); */
76
77 static void
78 modest_connection_specific_smtp_window_get_property (GObject *object, guint property_id,
79                                                                                                                         GValue *value, GParamSpec *pspec)
80 {
81         switch (property_id) {
82         default:
83                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
84         }
85 }
86
87 static void
88 modest_connection_specific_smtp_window_set_property (GObject *object, guint property_id,
89                                                                                                                         const GValue *value, GParamSpec *pspec)
90 {
91         switch (property_id) {
92         default:
93                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
94         }
95 }
96
97 static void
98 modest_connection_specific_smtp_window_dispose (GObject *object)
99 {
100         if (G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose)
101                 G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose (object);
102 }
103
104 enum MODEL_COLS {
105         MODEL_COL_NAME = 0, /* libconic IAP Name: a string */
106         MODEL_COL_ID = 1, /* libconic IAP ID: a string */
107         MODEL_COL_SERVER_ACCOUNT_NAME = 2, /* a string */
108         MODEL_COL_SERVER_NAME = 3, /* a string */
109         MODEL_COL_SERVER_ACCOUNT_SETTINGS = 4 /* a gpointer */
110 };
111
112
113 void update_model_server_names (ModestConnectionSpecificSmtpWindow *self);
114
115 static void
116 modest_connection_specific_smtp_window_finalize (GObject *object)
117 {
118         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (object);
119         
120         /* Free all the data items from the treemodel: */
121         GtkTreeIter iter;
122         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
123         while (valid) {
124                 ModestServerAccountSettings *server_settings = NULL;
125                 
126                 gtk_tree_model_get (priv->model, &iter, 
127                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
128                                     -1);
129                                  
130                 if (server_settings)
131                         g_object_unref (server_settings);
132                         
133                 /* Get next row: */
134                 valid = gtk_tree_model_iter_next (priv->model, &iter);
135         }
136         
137         g_object_unref (G_OBJECT (priv->model));
138         
139         G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->finalize (object);
140 }
141
142 static void
143 modest_connection_specific_smtp_window_class_init (ModestConnectionSpecificSmtpWindowClass *klass)
144 {
145         GObjectClass *object_class = G_OBJECT_CLASS (klass);
146
147         g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpWindowPrivate));
148
149         object_class->get_property = modest_connection_specific_smtp_window_get_property;
150         object_class->set_property = modest_connection_specific_smtp_window_set_property;
151         object_class->dispose = modest_connection_specific_smtp_window_dispose;
152         object_class->finalize = modest_connection_specific_smtp_window_finalize;
153 }
154
155 /* libconic does not return a list of connections in scratchbox,
156  * so enable this to put a fake row in the list,
157  * so we can test other parts of the code. */
158 /* #define DEBUG_WITHOUT_LIBCONIC 1 */
159
160 void
161 modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self,
162                                                               ModestAccountMgr *account_manager)
163 {
164 #ifdef MODEST_HAVE_CONIC
165         ModestConnectionSpecificSmtpWindowPrivate *priv = 
166                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
167         priv->account_manager = account_manager;
168         
169         GtkListStore *liststore = GTK_LIST_STORE (priv->model);
170         
171         TnyDevice *device = modest_runtime_get_device ();
172         g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
173         
174         /* Get the list of Internet Access Points: */
175         #ifdef DEBUG_WITHOUT_LIBCONIC
176         GSList *list_iaps = g_slist_append(NULL, (gpointer)1);
177         #else
178         TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
179         GSList *list_iaps = tny_maemo_conic_device_get_iap_list (maemo_device);
180         #endif
181         
182         /* printf("debug: list_iaps=%p, list_iaps size = %d\n", list_iaps, g_slist_length(list_iaps)); */
183         
184         GSList* iter = list_iaps;
185         while (iter) {
186                 ConIcIap *iap = (ConIcIap*)iter->data;
187                 if (iap) {
188                         #ifdef DEBUG_WITHOUT_LIBCONIC
189                         const gchar *connection_name = "debug name";
190                         const gchar *connection_id = "debug id";
191                         #else
192                         const gchar *connection_name = con_ic_iap_get_name (iap);
193                         const gchar *connection_id = con_ic_iap_get_id (iap);
194                         #endif
195                         
196                         printf ("debug: iac name=%s, id=%s\n", connection_name, connection_id);
197                         
198                         /* Get any already-associated connection-specific server account: */
199                         gchar *server_account_name = NULL;
200                         server_account_name = modest_account_mgr_get_connection_specific_smtp (
201                                 priv->account_manager, connection_id);
202                                         
203                         /* Add the row to the model: */
204                         GtkTreeIter iter;
205                         gtk_list_store_append (liststore, &iter);
206                         gtk_list_store_set(liststore, &iter, 
207                                 MODEL_COL_ID, connection_id, 
208                                 MODEL_COL_NAME, connection_name,
209                                 MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name,
210                                 -1);
211                                 
212                         if (server_account_name)
213                                 g_free (server_account_name);
214                 }
215                 
216                 iter = g_slist_next (iter);     
217         }
218                 
219         #ifndef DEBUG_WITHOUT_LIBCONIC
220         if (list_iaps)
221                 tny_maemo_conic_device_free_iap_list (maemo_device, list_iaps);
222         #endif
223                 
224         update_model_server_names (self);
225 #endif /*MODEST_HAVE_CONIC */
226 }
227         
228 static void
229 edit_account (ModestConnectionSpecificSmtpWindow *self, GtkTreePath *path)
230 {
231         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
232         ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
233         
234         gchar *id = NULL;
235         gchar *connection_name = NULL;
236         gchar *server_account_name = NULL;
237         ModestServerAccountSettings *server_settings = NULL;
238         GtkTreeIter iter;
239         if (gtk_tree_model_get_iter (priv->model, &iter, path)) {
240                 gtk_tree_model_get (priv->model, &iter,
241                                     MODEL_COL_ID, &id,
242                                     MODEL_COL_NAME, &connection_name,
243                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
244                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
245                                     -1);
246         
247                 /* printf("DEBUG: %s: BEFORE: connection-specific server_account_name=%s\n", __FUNCTION__, server_account_name); */
248                 /* TODO: Is 0 an allowed libconic IAP ID?
249                  * If not then we should check for it. */
250                 
251                 /* Get existing server account data if a server account is already specified: */
252                 gboolean settings_were_retrieved = FALSE;
253                 if (server_account_name && !server_settings) {
254                         server_settings = modest_account_mgr_load_server_settings(mgr, server_account_name, TRUE);
255                         if (server_settings)
256                                 settings_were_retrieved = TRUE;
257                 }
258                 
259                 GtkWidget * window = GTK_WIDGET (modest_connection_specific_smtp_edit_window_new ());
260                 modest_connection_specific_smtp_edit_window_set_connection (
261                         MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name, server_settings);
262                         
263                 /* Delete data, unless it was data from the rowmodel: */
264                 if (settings_were_retrieved) {
265                         g_object_unref (server_settings);
266                         server_settings = NULL;
267                 }
268                         
269                 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (window), GTK_WINDOW (self));
270                 
271                 gint response = gtk_dialog_run (GTK_DIALOG (window));
272                 if (response == GTK_RESPONSE_OK) {
273
274                         /* Delete any previous data for this row: */
275                         if (server_settings) {
276                                 g_object_unref (server_settings);
277                                 server_settings = NULL;
278                         }
279                         
280                         /* Get the new account data and save it in the row for later:
281                          * We free this in finalize(),
282                          * and save it to our configuration in
283                          * modest_connection_specific_smtp_window_save_server_accounts(). */
284                         server_settings = modest_connection_specific_smtp_edit_window_get_settings (
285                                                                                                     MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window));
286                         
287                         if (server_settings) {
288                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
289                                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, server_settings,
290                                                     MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
291                                                     -1);
292                         } else {
293                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
294                                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, NULL,
295                                                     MODEL_COL_SERVER_NAME, NULL,
296                                                     MODEL_COL_SERVER_ACCOUNT_NAME, NULL,
297                                                     -1);
298                         }
299                 }
300                 gtk_widget_destroy (window);
301         }
302         g_free (connection_name);
303         g_free (id);
304         g_free (server_account_name);
305         update_model_server_names (self);
306 }
307
308 static void
309 on_row_activated (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, 
310                   ModestConnectionSpecificSmtpWindow *self)
311 {
312         edit_account (self, path);
313 }
314
315 static void
316 modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow *self)
317 {
318         ModestWindowMgr *mgr;
319
320         /* Specify a default size */
321         gtk_window_set_default_size (GTK_WINDOW (self), -1, 320);
322         
323         /* This seems to be necessary to make the window show at the front with decoration.
324          * If we use property type=GTK_WINDOW_TOPLEVEL instead of the default GTK_WINDOW_POPUP+decoration, 
325          * then the window will be below the others. */
326         gtk_window_set_type_hint (GTK_WINDOW (self),
327                             GDK_WINDOW_TYPE_HINT_DIALOG);
328                             
329         ModestConnectionSpecificSmtpWindowPrivate *priv = 
330                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
331
332         /* Create a tree model for the tree view:
333          * with a string for the name, a string for the server name, and an int for the ID.
334          * This must match our MODEL_COLS enum constants.
335          */
336         priv->model = GTK_TREE_MODEL (gtk_list_store_new (5, 
337                 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
338
339         /* Setup the tree view: */
340         priv->treeview = GTK_TREE_VIEW (hildon_gtk_tree_view_new_with_model (HILDON_UI_MODE_NORMAL, priv->model));
341
342         /* name column:
343          * The ID model column in not shown in the view. */
344         GtkTreeViewColumn *view_column = gtk_tree_view_column_new ();
345         GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
346         gtk_tree_view_column_pack_start(view_column, renderer, TRUE);
347         gtk_tree_view_column_set_attributes (view_column, renderer, 
348         "text", MODEL_COL_NAME, NULL);
349         gtk_tree_view_append_column (priv->treeview, view_column);
350
351         
352         /* server name column: */
353         view_column = gtk_tree_view_column_new ();
354         renderer = gtk_cell_renderer_text_new ();
355         gtk_tree_view_column_pack_start(view_column, renderer, TRUE);
356         gtk_tree_view_column_set_attributes (view_column, renderer, 
357         "text", MODEL_COL_SERVER_NAME, NULL);
358         gtk_tree_view_append_column (priv->treeview, view_column);
359         
360         /* The application must call modest_connection_specific_smtp_window_fill_with_connections(). */
361         
362         GtkWidget *vbox = GTK_DIALOG(self)->vbox;
363         //gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
364
365         /* Introductory note: */
366         /* TODO: For some reason this label does not wrap. It is truncated. */
367         GtkWidget *label = gtk_label_new(_("mcen_ia_optionalsmtp_note"));
368         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
369         gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
370         /* So that it is shown without being truncated: */
371         /* gtk_label_set_max_width_chars (GTK_LABEL (label), 20); */
372         /* The documentation for gtk_label_set_line_wrap() says that we must 
373          * call gtk_widget_set_size_request() with a hard-coded width, 
374          * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
375         /* gtk_widget_set_size_request (label, 400, -1); */
376         gtk_widget_show (label);
377         gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, MODEST_MARGIN_HALF);
378         
379         /* Put the treeview in a pannable and add it to the box: */
380         GtkWidget *pannable = hildon_pannable_area_new ();
381         g_object_set (G_OBJECT (pannable), "initial-hint", TRUE, NULL);
382         gtk_container_set_border_width (GTK_CONTAINER (pannable), MODEST_MARGIN_DEFAULT);
383         gtk_widget_show (pannable);
384         gtk_container_add (GTK_CONTAINER (pannable), GTK_WIDGET (priv->treeview));
385         gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (pannable), TRUE, TRUE, MODEST_MARGIN_HALF);
386         gtk_widget_show (GTK_WIDGET (priv->treeview));
387         gtk_widget_show (vbox);
388         
389         g_signal_connect (G_OBJECT (priv->treeview), "row-activated", G_CALLBACK (on_row_activated), self);
390         
391         /* When this window is shown, hibernation should not be possible, 
392          * because there is no sensible way to save the state: */
393         mgr = modest_runtime_get_window_mgr ();
394         modest_window_mgr_prevent_hibernation_while_window_is_shown (mgr, 
395                                                                      GTK_WINDOW (self)); 
396
397         /* Set window title */
398         gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers"));
399
400         g_signal_connect (self, "response", G_CALLBACK (on_response), NULL);
401         
402 }
403
404 ModestConnectionSpecificSmtpWindow*
405 modest_connection_specific_smtp_window_new (void)
406 {
407         return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_WINDOW, NULL);
408 }
409
410 /** The application should call this when the user changes should be saved.
411  */
412 gboolean
413 modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpecificSmtpWindow *self)
414 {
415         ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
416         ModestConnectionSpecificSmtpWindowPrivate *priv = 
417                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
418         
419         
420         /* Get the first iter in the list */
421         GtkTreeIter iter;
422         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
423
424         /* Walk through the list, reading each row */
425         while (valid) {
426                 gchar *id = NULL;
427                 gchar *connection_name = NULL;
428                 gchar *server_account_name = NULL;
429                 gchar *server_name = NULL;
430                 ModestServerAccountSettings *server_settings = NULL;
431                 
432                 gtk_tree_model_get (priv->model, &iter, 
433                                     MODEL_COL_ID, &id, 
434                                     MODEL_COL_NAME, &connection_name, 
435                                     MODEL_COL_SERVER_NAME, &server_name,
436                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
437                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
438                                     -1);
439                                  
440                 gboolean success = TRUE;   
441                 if (id && server_settings) { /* The presence of data suggests that there is something to save. */
442                         if (!server_account_name) {
443                                 /* Add a new server account, building a (non-human-visible) name: */
444                                 gchar *name_start = g_strdup_printf("specific_%s", connection_name);
445                                 server_account_name = modest_account_mgr_get_unused_account_name (
446                                         priv->account_manager, name_start, TRUE /* server account. */);
447                                 g_assert (server_account_name);
448                                 g_free (name_start);
449                                 
450                                 modest_server_account_settings_set_account_name (server_settings, server_account_name);
451                                 success = modest_account_mgr_save_server_settings (mgr, server_settings);
452                                 if (success) {
453                                         TnyAccount *account = TNY_ACCOUNT (modest_tny_account_store_new_connection_specific_transport_account 
454                                                                            (modest_runtime_get_account_store (),
455                                                                             server_account_name));
456                                         if (account)
457                                                 g_object_unref (account);
458                                 }
459                                 
460                                 /* associate the specific server account with this connection for this account: */
461                                 success = success && modest_account_mgr_set_connection_specific_smtp (
462                                         priv->account_manager, id, server_account_name);
463                                 
464                                 /* Save the new name in the treemodel, so it can be edited again later: */
465                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
466                                         MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1);
467                                 
468                         } else {
469                                 modest_account_mgr_save_server_settings (mgr, server_settings);
470                         }
471                 } else if (id && server_name && 
472                            !strcmp (server_name, _("mcen_ia_optionalsmtp_notdefined"))) {
473                         modest_account_mgr_remove_connection_specific_smtp (priv->account_manager, 
474                                                                             id);
475                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
476                                             MODEL_COL_SERVER_ACCOUNT_NAME, NULL, -1);
477                 }
478                 
479                 g_free (connection_name);
480                 g_free (id);
481                 g_free (server_account_name);
482                 g_free (server_name);
483                 
484                 if (!success)
485                         return FALSE;
486                         
487                 /* Get next row: */
488                 valid = gtk_tree_model_iter_next (priv->model, &iter);
489         }
490         
491         update_model_server_names (self);
492         
493         return TRUE;
494 }
495
496 void update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
497 {
498         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
499
500         GtkTreeIter iter;
501         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
502         while (valid) {
503                 
504                 gchar *server_account_name = NULL;
505                 ModestServerAccountSettings *server_settings = NULL;
506                 gtk_tree_model_get (priv->model, &iter, 
507                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
508                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
509                                     -1);        
510                 if (server_settings && modest_server_account_settings_get_hostname (server_settings)
511                     && (modest_server_account_settings_get_hostname (server_settings) [0] != '\0')) {
512                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
513                                             MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
514                                             -1);
515                 } else if (server_account_name) {
516                         
517                         /* Get the server hostname and show it in the treemodel: */     
518                         gchar *hostname = modest_account_mgr_get_server_account_hostname (priv->account_manager, 
519                                                                                           server_account_name);
520                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
521                                             MODEL_COL_SERVER_NAME, hostname,
522                                             -1);
523                         g_free (hostname);
524                 } else {
525                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
526                                             MODEL_COL_SERVER_NAME, _("mcen_ia_optionalsmtp_notdefined"),
527                                             -1);
528                 }
529                         
530                 /* Get next row: */
531                 valid = gtk_tree_model_iter_next (priv->model, &iter);
532         }
533 }
534
535 static void
536 on_response (GtkDialog *dialog,
537              gint response,
538              gpointer user_data)
539 {
540         modest_connection_specific_smtp_window_save_server_accounts (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog));
541         gtk_widget_destroy (GTK_WIDGET (dialog));
542 }