e310913154a466e2cc847f4020bcb64523149409
[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         GtkWidget *no_connection_label;
68         GtkWidget *pannable;
69         ModestAccountMgr *account_manager;
70 };
71
72 static void on_response (GtkDialog *dialog, 
73                          gint response, 
74                          gpointer user_data);
75
76 /* static gboolean on_key_pressed (GtkWidget *self, GdkEventKey *event, gpointer user_data); */
77
78 static void
79 modest_connection_specific_smtp_window_get_property (GObject *object, guint property_id,
80                                                                                                                         GValue *value, GParamSpec *pspec)
81 {
82         switch (property_id) {
83         default:
84                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
85         }
86 }
87
88 static void
89 modest_connection_specific_smtp_window_set_property (GObject *object, guint property_id,
90                                                                                                                         const GValue *value, GParamSpec *pspec)
91 {
92         switch (property_id) {
93         default:
94                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
95         }
96 }
97
98 static void
99 modest_connection_specific_smtp_window_dispose (GObject *object)
100 {
101         if (G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose)
102                 G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose (object);
103 }
104
105 enum MODEL_COLS {
106         MODEL_COL_NAME = 0, /* libconic IAP Name: a string */
107         MODEL_COL_ID = 1, /* libconic IAP ID: a string */
108         MODEL_COL_SERVER_ACCOUNT_NAME = 2, /* a string */
109         MODEL_COL_SERVER_NAME = 3, /* a string */
110         MODEL_COL_SERVER_ACCOUNT_SETTINGS = 4 /* a gpointer */
111 };
112
113
114 static void update_model_server_names (ModestConnectionSpecificSmtpWindow *self);
115
116 static void
117 modest_connection_specific_smtp_window_finalize (GObject *object)
118 {
119         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (object);
120
121         /* Free all the data items from the treemodel: */
122         GtkTreeIter iter;
123         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
124         while (valid) {
125                 ModestServerAccountSettings *server_settings = NULL;
126
127                 gtk_tree_model_get (priv->model, &iter, 
128                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
129                                     -1);
130
131                 if (server_settings)
132                         g_object_unref (server_settings);
133
134                 /* Get next row: */
135                 valid = gtk_tree_model_iter_next (priv->model, &iter);
136         }
137
138         g_object_unref (G_OBJECT (priv->model));
139
140         g_object_unref (priv->treeview);
141         g_object_unref (priv->no_connection_label);
142
143         G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->finalize (object);
144 }
145
146 static void
147 modest_connection_specific_smtp_window_class_init (ModestConnectionSpecificSmtpWindowClass *klass)
148 {
149         GObjectClass *object_class = G_OBJECT_CLASS (klass);
150
151         g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpWindowPrivate));
152
153         object_class->get_property = modest_connection_specific_smtp_window_get_property;
154         object_class->set_property = modest_connection_specific_smtp_window_set_property;
155         object_class->dispose = modest_connection_specific_smtp_window_dispose;
156         object_class->finalize = modest_connection_specific_smtp_window_finalize;
157 }
158
159 /* libconic does not return a list of connections in scratchbox,
160  * so enable this to put a fake row in the list,
161  * so we can test other parts of the code. */
162 /* #define DEBUG_WITHOUT_LIBCONIC 1 */
163
164 void
165 modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self,
166                                                               ModestAccountMgr *account_manager)
167 {
168         gboolean empty = TRUE;
169 #ifdef MODEST_HAVE_CONIC
170         ModestConnectionSpecificSmtpWindowPrivate *priv = 
171                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
172         priv->account_manager = account_manager;
173         
174         GtkListStore *liststore = GTK_LIST_STORE (priv->model);
175         
176         TnyDevice *device = modest_runtime_get_device ();
177         g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
178         
179         /* Get the list of Internet Access Points: */
180         #ifdef DEBUG_WITHOUT_LIBCONIC
181         GSList *list_iaps = g_slist_append(NULL, (gpointer)1);
182         #else
183         TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
184         GSList *list_iaps = tny_maemo_conic_device_get_iap_list (maemo_device);
185         #endif
186         
187         /* printf("debug: list_iaps=%p, list_iaps size = %d\n", list_iaps, g_slist_length(list_iaps)); */
188         
189         GSList* iter = list_iaps;
190         if (list_iaps != NULL)
191                 empty = FALSE;
192
193         while (iter) {
194                 ConIcIap *iap = (ConIcIap*)iter->data;
195                 if (iap) {
196                         #ifdef DEBUG_WITHOUT_LIBCONIC
197                         const gchar *connection_name = "debug name";
198                         const gchar *connection_id = "debug id";
199                         #else
200                         const gchar *connection_name = con_ic_iap_get_name (iap);
201                         const gchar *connection_id = con_ic_iap_get_id (iap);
202                         #endif
203                         
204                         printf ("debug: iac name=%s, id=%s\n", connection_name, connection_id);
205                         
206                         /* Get any already-associated connection-specific server account: */
207                         gchar *server_account_name = NULL;
208                         server_account_name = modest_account_mgr_get_connection_specific_smtp (
209                                 priv->account_manager, connection_id);
210                                         
211                         /* Add the row to the model: */
212                         GtkTreeIter iter;
213                         gtk_list_store_append (liststore, &iter);
214                         gtk_list_store_set(liststore, &iter, 
215                                 MODEL_COL_ID, connection_id, 
216                                 MODEL_COL_NAME, connection_name,
217                                 MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name,
218                                 -1);
219                                 
220                         if (server_account_name)
221                                 g_free (server_account_name);
222                 }
223                 
224                 iter = g_slist_next (iter);     
225         }
226                 
227         #ifndef DEBUG_WITHOUT_LIBCONIC
228         if (list_iaps)
229                 tny_maemo_conic_device_free_iap_list (maemo_device, list_iaps);
230         #endif
231                 
232         update_model_server_names (self);
233 #endif /*MODEST_HAVE_CONIC */
234
235         GtkWidget *child;
236         child = gtk_bin_get_child (GTK_BIN (priv->pannable));
237         if (child) {
238                 gtk_container_remove (GTK_CONTAINER (priv->pannable), child);
239         }
240
241         if (empty) {
242                 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (priv->pannable), 
243                                                         priv->no_connection_label);
244                 gtk_widget_show (priv->no_connection_label);
245         } else {
246                 gtk_container_add (GTK_CONTAINER (priv->pannable), GTK_WIDGET (priv->treeview));
247                 gtk_widget_show (GTK_WIDGET (priv->treeview));
248         }
249 }
250         
251 static void
252 edit_account (ModestConnectionSpecificSmtpWindow *self, GtkTreePath *path)
253 {
254         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
255         ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
256         
257         gchar *id = NULL;
258         gchar *connection_name = NULL;
259         gchar *server_account_name = NULL;
260         ModestServerAccountSettings *server_settings = NULL;
261         GtkTreeIter iter;
262         if (gtk_tree_model_get_iter (priv->model, &iter, path)) {
263                 gtk_tree_model_get (priv->model, &iter,
264                                     MODEL_COL_ID, &id,
265                                     MODEL_COL_NAME, &connection_name,
266                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
267                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
268                                     -1);
269
270                 /* Get existing server account data if a server account is already specified: */
271                 gboolean settings_were_retrieved = FALSE;
272                 if (server_account_name && !server_settings) {
273                         server_settings = modest_account_mgr_load_server_settings(mgr, server_account_name, TRUE);
274                         if (server_settings)
275                                 settings_were_retrieved = TRUE;
276                 }
277
278                 GtkWidget * window = GTK_WIDGET (modest_connection_specific_smtp_edit_window_new ());
279                 modest_connection_specific_smtp_edit_window_set_connection (
280                         MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name, server_settings);
281
282                 /* Delete data, unless it was data from the rowmodel: */
283                 if (settings_were_retrieved) {
284                         g_object_unref (server_settings);
285                         server_settings = NULL;
286                 }
287
288                 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (window), GTK_WINDOW (self));
289
290                 gint response = gtk_dialog_run (GTK_DIALOG (window));
291                 if (response == GTK_RESPONSE_OK) {
292
293                         /* Delete any previous data for this row: */
294                         if (server_settings) {
295                                 g_object_unref (server_settings);
296                                 server_settings = NULL;
297                         }
298
299                         /* Get the new account data and save it in the row for later:
300                          * We free this in finalize(),
301                          * and save it to our configuration in
302                          * modest_connection_specific_smtp_window_save_server_accounts(). */
303                         server_settings = modest_connection_specific_smtp_edit_window_get_settings (
304                                                                                                     MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window));
305
306                         if (server_settings) {
307                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
308                                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, server_settings,
309                                                     MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
310                                                     -1);
311                         } else {
312                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
313                                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, NULL,
314                                                     MODEL_COL_SERVER_NAME, NULL,
315                                                     MODEL_COL_SERVER_ACCOUNT_NAME, NULL,
316                                                     -1);
317                         }
318                 }
319                 gtk_widget_destroy (window);
320         }
321         g_free (connection_name);
322         g_free (id);
323         g_free (server_account_name);
324         update_model_server_names (self);
325 }
326
327 static void
328 on_row_activated (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, 
329                   ModestConnectionSpecificSmtpWindow *self)
330 {
331         edit_account (self, path);
332 }
333
334 static void
335 modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow *self)
336 {
337         ModestWindowMgr *mgr;
338         GtkWidget *align;
339
340         /* Specify a default size */
341         gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
342
343         /* This seems to be necessary to make the window show at the front with decoration.
344          * If we use property type=GTK_WINDOW_TOPLEVEL instead of the default GTK_WINDOW_POPUP+decoration, 
345          * then the window will be below the others. */
346         gtk_window_set_type_hint (GTK_WINDOW (self),
347                             GDK_WINDOW_TYPE_HINT_DIALOG);
348
349         ModestConnectionSpecificSmtpWindowPrivate *priv = 
350                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
351
352         /* Create a tree model for the tree view:
353          * with a string for the name, a string for the server name, and an int for the ID.
354          * This must match our MODEL_COLS enum constants.
355          */
356         priv->model = GTK_TREE_MODEL (gtk_list_store_new (5, 
357                 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
358
359         /* Setup the tree view: */
360         priv->treeview = GTK_TREE_VIEW (hildon_gtk_tree_view_new_with_model (HILDON_UI_MODE_NORMAL, priv->model));
361         g_object_ref_sink (G_OBJECT (priv->treeview));
362
363         /* No connections label */
364         priv->no_connection_label = gtk_label_new (_("mcen_ia_optionalsmtp_noconnection"));
365         g_object_ref_sink (G_OBJECT (priv->no_connection_label));
366
367         /* name column:
368          * The ID model column in not shown in the view. */
369         GtkTreeViewColumn *view_column = gtk_tree_view_column_new ();
370         gtk_tree_view_column_set_expand (view_column, TRUE);
371         GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
372         g_object_set (G_OBJECT (renderer), "xpad", MODEST_MARGIN_DOUBLE, NULL);
373         gtk_tree_view_column_pack_start(view_column, renderer, TRUE);
374         gtk_tree_view_column_set_attributes (view_column, renderer, 
375         "text", MODEL_COL_NAME, NULL);
376         gtk_tree_view_append_column (priv->treeview, view_column);
377
378         /* server name column: */
379         view_column = gtk_tree_view_column_new ();
380         gtk_tree_view_column_set_expand (view_column, TRUE);
381         renderer = gtk_cell_renderer_text_new ();
382         gtk_tree_view_column_pack_start(view_column, renderer, TRUE);
383         gtk_tree_view_column_set_attributes (view_column, renderer, 
384         "text", MODEL_COL_SERVER_NAME, NULL);
385         gtk_tree_view_append_column (priv->treeview, view_column);
386
387         /* The application must call modest_connection_specific_smtp_window_fill_with_connections(). */
388
389         GtkWidget *vbox = GTK_DIALOG(self)->vbox;
390
391         /* Introductory note: */
392         GtkWidget *label = gtk_label_new(_("mcen_ia_optionalsmtp_note"));
393         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
394         gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
395         gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE + MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
396         gtk_widget_set_size_request (label, 600, -1);
397         gtk_widget_show (label);
398         gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
399
400         /* Put the treeview in a pannable and add it to the box: */
401         priv->pannable = hildon_pannable_area_new ();
402         align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
403         gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
404         g_object_set (G_OBJECT (priv->pannable), "initial-hint", TRUE, NULL);
405         gtk_widget_show (priv->pannable);
406         gtk_widget_show (align);
407         gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->pannable));
408         gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (align), TRUE, TRUE, 0);
409         gtk_widget_show (vbox);
410
411         g_signal_connect (G_OBJECT (priv->treeview), "row-activated", G_CALLBACK (on_row_activated), self);
412
413         /* When this window is shown, hibernation should not be possible, 
414          * because there is no sensible way to save the state: */
415         mgr = modest_runtime_get_window_mgr ();
416         modest_window_mgr_prevent_hibernation_while_window_is_shown (mgr, 
417                                                                      GTK_WINDOW (self)); 
418
419         /* Set window title */
420         gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers"));
421
422         g_signal_connect (self, "response", G_CALLBACK (on_response), NULL);
423 }
424
425 ModestConnectionSpecificSmtpWindow*
426 modest_connection_specific_smtp_window_new (void)
427 {
428         return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_WINDOW, NULL);
429 }
430
431 /** The application should call this when the user changes should be saved.
432  */
433 gboolean
434 modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpecificSmtpWindow *self)
435 {
436         ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
437         ModestConnectionSpecificSmtpWindowPrivate *priv = 
438                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
439
440
441         /* Get the first iter in the list */
442         GtkTreeIter iter;
443         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
444
445         /* Walk through the list, reading each row */
446         while (valid) {
447                 gchar *id = NULL;
448                 gchar *connection_name = NULL;
449                 gchar *server_account_name = NULL;
450                 gchar *server_name = NULL;
451                 ModestServerAccountSettings *server_settings = NULL;
452
453                 gtk_tree_model_get (priv->model, &iter, 
454                                     MODEL_COL_ID, &id, 
455                                     MODEL_COL_NAME, &connection_name, 
456                                     MODEL_COL_SERVER_NAME, &server_name,
457                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
458                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
459                                     -1);
460  
461                 gboolean success = TRUE;
462                 if (id && server_settings) { /* The presence of data suggests that there is something to save. */
463                         if (!server_account_name) {
464                                 /* Add a new server account, building a (non-human-visible) name: */
465                                 gchar *name_start = g_strdup_printf("specific_%s", connection_name);
466                                 server_account_name = modest_account_mgr_get_unused_account_name (
467                                         priv->account_manager, name_start, TRUE /* server account. */);
468                                 g_assert (server_account_name);
469                                 g_free (name_start);
470
471                                 modest_server_account_settings_set_account_name (server_settings, server_account_name);
472                                 success = modest_account_mgr_save_server_settings (mgr, server_settings);
473                                 if (success) {
474                                         TnyAccount *account = TNY_ACCOUNT (modest_tny_account_store_new_connection_specific_transport_account 
475                                                                            (modest_runtime_get_account_store (),
476                                                                             server_account_name));
477                                         if (account)
478                                                 g_object_unref (account);
479                                 }
480
481                                 /* associate the specific server account with this connection for this account: */
482                                 success = success && modest_account_mgr_set_connection_specific_smtp (
483                                         priv->account_manager, id, server_account_name);
484
485                                 /* Save the new name in the treemodel, so it can be edited again later: */
486                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
487                                         MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1);
488
489                         } else {
490                                 /* If the account already exists then update it and notify */
491                                 modest_account_mgr_save_server_settings (mgr, server_settings);
492                         }
493                 } else if (id && server_name && 
494                            !strcmp (server_name, _("mcen_ia_optionalsmtp_notdefined"))) {
495                         modest_account_mgr_remove_connection_specific_smtp (priv->account_manager, 
496                                                                             id);
497                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
498                                             MODEL_COL_SERVER_ACCOUNT_NAME, NULL, -1);
499                 }
500
501                 g_free (connection_name);
502                 g_free (id);
503                 g_free (server_account_name);
504                 g_free (server_name);
505
506                 if (!success)
507                         return FALSE;
508
509                 /* Get next row: */
510                 valid = gtk_tree_model_iter_next (priv->model, &iter);
511         }
512
513         update_model_server_names (self);
514
515         return TRUE;
516 }
517
518 static void
519 update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
520 {
521         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
522
523         GtkTreeIter iter;
524         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
525         while (valid) {
526
527                 gchar *server_account_name = NULL;
528                 ModestServerAccountSettings *server_settings = NULL;
529                 gtk_tree_model_get (priv->model, &iter, 
530                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
531                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
532                                     -1);
533                 if (server_settings && modest_server_account_settings_get_hostname (server_settings)
534                     && (modest_server_account_settings_get_hostname (server_settings) [0] != '\0')) {
535                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
536                                             MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
537                                             -1);
538                 } else if (server_account_name) {
539
540                         /* Get the server hostname and show it in the treemodel: */
541                         gchar *hostname = modest_account_mgr_get_server_account_hostname (priv->account_manager,
542                                                                                           server_account_name);
543                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
544                                             MODEL_COL_SERVER_NAME, hostname,
545                                             -1);
546                         g_free (hostname);
547                 } else {
548                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
549                                             MODEL_COL_SERVER_NAME, _("mcen_ia_optionalsmtp_notdefined"),
550                                             -1);
551                 }
552
553                 /* Get next row: */
554                 valid = gtk_tree_model_iter_next (priv->model, &iter);
555         }
556 }
557
558 static void
559 on_response (GtkDialog *dialog,
560              gint response,
561              gpointer user_data)
562 {
563         modest_connection_specific_smtp_window_save_server_accounts (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog));
564         gtk_widget_destroy (GTK_WIDGET (dialog));
565 }