b7c5266cc0dee65b58f8b64f1af76848fe4e41fa
[modest] / src / maemo / modest-connection-specific-smtp-window.c
1 /* connection-specific-smtp-window.c */
2
3 #include "modest-connection-specific-smtp-window.h"
4 #include "modest-connection-specific-smtp-edit-window.h"
5 #include <modest-account-mgr-helpers.h>
6 #include "widgets/modest-ui-constants.h"
7
8 #include <modest-runtime.h>
9 #include <tny-maemo-conic-device.h>
10
11 #include <gtk/gtktreeview.h>
12 #include <gtk/gtkcellrenderertext.h>
13 #include <gtk/gtkliststore.h>
14 #include <gtk/gtkscrolledwindow.h>
15 #include <gtk/gtkbutton.h>
16 #include <gtk/gtkhbox.h>
17 #include <gtk/gtkvbox.h>
18 #include <gtk/gtkstock.h>
19
20 #include "modest-hildon-includes.h"
21 #include "modest-platform.h"
22
23 #include <glib/gi18n.h>
24
25 G_DEFINE_TYPE (ModestConnectionSpecificSmtpWindow, modest_connection_specific_smtp_window, GTK_TYPE_WINDOW);
26
27 #define CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE(o) \
28         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_WINDOW, ModestConnectionSpecificSmtpWindowPrivate))
29
30 typedef struct _ModestConnectionSpecificSmtpWindowPrivate ModestConnectionSpecificSmtpWindowPrivate;
31
32 struct _ModestConnectionSpecificSmtpWindowPrivate
33 {
34         GtkTreeView *treeview;
35         GtkTreeModel *model;
36         GtkWidget *button_edit;
37         
38         ModestAccountMgr *account_manager;
39         gchar* account_name;
40 };
41
42 static void
43 modest_connection_specific_smtp_window_get_property (GObject *object, guint property_id,
44                                                                                                                         GValue *value, GParamSpec *pspec)
45 {
46         switch (property_id) {
47         default:
48                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
49         }
50 }
51
52 static void
53 modest_connection_specific_smtp_window_set_property (GObject *object, guint property_id,
54                                                                                                                         const GValue *value, GParamSpec *pspec)
55 {
56         switch (property_id) {
57         default:
58                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
59         }
60 }
61
62 static void
63 modest_connection_specific_smtp_window_dispose (GObject *object)
64 {
65         if (G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose)
66                 G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose (object);
67 }
68
69 enum MODEL_COLS {
70         MODEL_COL_NAME = 0, /* libconic IAP Name: a string */
71         MODEL_COL_ID = 1, /* libconic IAP ID: a string */
72         MODEL_COL_SERVER_ACCOUNT_NAME = 2, /* a string */
73         MODEL_COL_SERVER_NAME = 3, /* a string */
74         MODEL_COL_SERVER_ACCOUNT_DATA = 4 /* a gpointer */
75 };
76
77
78 void update_model_server_names (ModestConnectionSpecificSmtpWindow *self);
79
80 static void
81 modest_connection_specific_smtp_window_finalize (GObject *object)
82 {
83         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (object);
84         
85         /* Free all the data items from the treemodel: */
86         GtkTreeIter iter;
87         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
88         while (valid) {
89                 ModestServerAccountData *data = NULL;
90                 
91                 gtk_tree_model_get (priv->model, &iter, 
92                                     MODEL_COL_SERVER_ACCOUNT_DATA, &data,
93                                     -1);
94                                  
95                 if (data)
96                         modest_account_mgr_free_server_account_data (priv->account_manager, data);
97                         
98                 /* Get next row: */
99                 valid = gtk_tree_model_iter_next (priv->model, &iter);
100         }
101         
102         g_object_unref (G_OBJECT (priv->model));
103         g_free (priv->account_name);
104         
105         G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->finalize (object);
106 }
107
108 static void
109 modest_connection_specific_smtp_window_class_init (ModestConnectionSpecificSmtpWindowClass *klass)
110 {
111         GObjectClass *object_class = G_OBJECT_CLASS (klass);
112
113         g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpWindowPrivate));
114
115         object_class->get_property = modest_connection_specific_smtp_window_get_property;
116         object_class->set_property = modest_connection_specific_smtp_window_set_property;
117         object_class->dispose = modest_connection_specific_smtp_window_dispose;
118         object_class->finalize = modest_connection_specific_smtp_window_finalize;
119 }
120
121 /* libconic does not return a list of connections in scratchbox,
122  * so enable this to put a fake row in the list,
123  * so we can test other parts of the code. */
124 /* #define DEBUG_WITHOUT_LIBCONIC 1 */
125
126 void
127 modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self, ModestAccountMgr *account_manager,
128         const gchar* account_name)
129 {
130         ModestConnectionSpecificSmtpWindowPrivate *priv = 
131                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
132         priv->account_manager = account_manager;
133         priv->account_name = account_name ? g_strdup (account_name) : NULL;
134         
135         GtkListStore *liststore = GTK_LIST_STORE (priv->model);
136         
137         TnyDevice *device = modest_runtime_get_device ();
138         g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
139         
140         /* Get the list of Internet Access Points: */
141         #ifdef DEBUG_WITHOUT_LIBCONIC
142         GSList *list_iaps = g_slist_append(NULL, (gpointer)1);
143         #else
144         TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
145         GSList *list_iaps = tny_maemo_conic_device_get_iap_list (maemo_device);
146         #endif
147         
148         /* printf("debug: list_iaps=%p, list_iaps size = %d\n", list_iaps, g_slist_length(list_iaps)); */
149         
150         GSList* iter = list_iaps;
151         while (iter) {
152                 ConIcIap *iap = (ConIcIap*)iter->data;
153                 if (iap) {
154                         #ifdef DEBUG_WITHOUT_LIBCONIC
155                         const gchar *name = "debug name";
156                         const gchar *id = "debug id";
157                         #else
158                         const gchar *name = con_ic_iap_get_name (iap);
159                         const gchar *id = con_ic_iap_get_id (iap);
160                         #endif
161                         
162                         printf ("debug: iac name=%s, id=%s\n", name, id);
163                         
164                         /* Get any already-associated connection-specific server account: */
165                         gchar *server_account_name = NULL;
166                         if (priv->account_name)
167                                 server_account_name = modest_account_mgr_get_connection_specific_smtp (
168                                         priv->account_manager, priv->account_name, name);
169                                         
170                         /* Add the row to the model: */
171                         GtkTreeIter iter;
172                         gtk_list_store_append (liststore, &iter);
173                         gtk_list_store_set(liststore, &iter, 
174                                 MODEL_COL_ID, id, 
175                                 MODEL_COL_NAME, name,
176                                 MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name,
177                                 -1);
178                                 
179                         g_free (server_account_name);
180                 }
181                 
182                 iter = g_slist_next (iter);     
183         }
184                 
185         #ifndef DEBUG_WITHOUT_LIBCONIC
186         if (list_iaps)
187                 tny_maemo_conic_device_free_iap_list (maemo_device, list_iaps);
188         #endif
189                 
190         update_model_server_names (self);
191 }
192         
193 static void
194 on_button_edit (GtkButton *button, gpointer user_data)
195 {
196         ModestConnectionSpecificSmtpWindow *self = MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (user_data);
197         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
198         
199         gchar *id = NULL;
200         gchar *connection_name = NULL;
201         gchar *server_account_name = NULL;
202         ModestServerAccountData *data = NULL;
203         GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
204         GtkTreeIter iter;
205         GtkTreeModel *model = 0;
206         if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
207                 gtk_tree_model_get (priv->model, &iter, 
208                                     MODEL_COL_ID, &id, 
209                                     MODEL_COL_NAME, &connection_name, 
210                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
211                                     MODEL_COL_SERVER_ACCOUNT_DATA, &data,
212                                     -1);
213         
214                 /* printf("DEBUG: %s: BEFORE: connection-specific server_account_name=%s\n", __FUNCTION__, server_account_name); */
215                 /* TODO: Is 0 an allowed libconic IAP ID? 
216                  * If not then we should check for it. */
217                 
218                 /* Get existing server account data if a server account is already specified: */
219                 gboolean data_was_retrieved = FALSE;
220                 if (server_account_name && !data) {
221                         data = modest_account_mgr_get_server_account_data (priv->account_manager, 
222                                 server_account_name);
223                         if (data)
224                                 data_was_retrieved = TRUE;
225                 }
226                 
227                 GtkWidget * window = GTK_WIDGET (modest_connection_specific_smtp_edit_window_new ());
228                 modest_connection_specific_smtp_edit_window_set_connection (
229                         MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name, data);
230                         
231                 /* Delete data, unless it was data from the rowmodel: */
232                 if (data_was_retrieved) {
233                         modest_account_mgr_free_server_account_data (priv->account_manager, data);
234                         data = NULL;
235                 }
236                         
237                 gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
238                 
239                 gboolean dialog_finished = FALSE;
240                 while (!dialog_finished)
241                 {
242                         gint response = gtk_dialog_run (GTK_DIALOG (window));
243                         if (response == GTK_RESPONSE_OK) {
244                                 gtk_widget_hide (window);
245                                 dialog_finished = TRUE;
246                                 /* Delete any previous data for this row: */
247                                 if (data) 
248                                 {
249                                         modest_account_mgr_free_server_account_data (priv->account_manager, data);
250                                         data = NULL;
251                                 }
252                                 
253                                 /* Get the new account data and save it in the row for later:
254                                  * We free this in finalize(),
255                                  * and save it to our configuration in 
256                                  * modest_connection_specific_smtp_window_save_server_accounts(). */
257                                 data = modest_connection_specific_smtp_edit_window_get_settings (
258                                                         MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), 
259                                                         priv->account_manager);
260                                 
261                                 const gchar* server_name = data ? data->hostname : NULL;
262                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
263                                                 MODEL_COL_SERVER_ACCOUNT_DATA, data,
264                                                 MODEL_COL_SERVER_NAME, server_name,
265                                                 -1);
266                         }
267                         else
268                         {
269                                 if (!modest_connection_specific_smtp_edit_window_is_dirty(
270                                                 MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW(window)))
271                                 {
272                                         gtk_widget_hide(window);
273                                         dialog_finished = TRUE;
274                                 }
275                                 else
276                                 {
277                                                 
278                                         gint response;
279                                         response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window), 
280                                                                             _("imum_nc_wizard_confirm_lose_changes"));                   
281                                         if (response == GTK_RESPONSE_OK)
282                                         {
283                                                 gtk_widget_hide(window);
284                                                 dialog_finished = TRUE;
285                                         }
286                                 }
287                         }
288                 }
289         }
290         g_free (connection_name);
291         g_free (id);
292         g_free (server_account_name);
293 }
294
295 static void
296 on_button_cancel (GtkButton *button, gpointer user_data)
297 {
298         ModestConnectionSpecificSmtpWindow *self = MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (user_data);
299
300         /* Hide the window.
301          * The code that showed it will respond to the hide signal. */  
302         gtk_widget_hide (GTK_WIDGET (self));
303 }
304
305 static void
306 on_selection_changed (GtkTreeSelection *sel, ModestConnectionSpecificSmtpWindow *self)
307 {
308         ModestConnectionSpecificSmtpWindowPrivate *priv = 
309                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
310
311         GtkTreeModel *model = NULL;
312         GtkTreeIter iter;
313         const gboolean has_selection =
314                 gtk_tree_selection_get_selected (sel, &model, &iter);
315
316         gtk_widget_set_sensitive (priv->button_edit, has_selection);
317 }
318
319 static void
320 modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow *self)
321 {
322         ModestWindowMgr *mgr;
323
324         /* Specify a default size, because the GtkTreeView's default requested size  
325          * is not big enough: */
326         gtk_window_set_default_size (GTK_WINDOW (self), 500, 300);
327         
328         /* This seems to be necessary to make the window show at the front with decoration.
329          * If we use property type=GTK_WINDOW_TOPLEVEL instead of the default GTK_WINDOW_POPUP+decoration, 
330          * then the window will be below the others. */
331         gtk_window_set_type_hint (GTK_WINDOW (self),
332                             GDK_WINDOW_TYPE_HINT_DIALOG);
333                             
334         ModestConnectionSpecificSmtpWindowPrivate *priv = 
335                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
336
337         /* Create a tree model for the tree view:
338          * with a string for the name, a string for the server name, and an int for the ID.
339          * This must match our MODEL_COLS enum constants.
340          */
341         priv->model = GTK_TREE_MODEL (gtk_list_store_new (5, 
342                 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
343
344         /* Setup the tree view: */
345         priv->treeview = GTK_TREE_VIEW (gtk_tree_view_new_with_model (priv->model));
346
347         /* Show the column headers,
348          * which does not seem to be the default on Maemo.
349          */                     
350         gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(priv->treeview), TRUE);
351         
352         /* name column:
353          * The ID model column in not shown in the view. */
354         GtkTreeViewColumn *view_column = gtk_tree_view_column_new ();
355         GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
356         gtk_tree_view_column_pack_start(view_column, renderer, TRUE);
357         gtk_tree_view_column_set_attributes (view_column, renderer, 
358         "text", MODEL_COL_NAME, NULL);
359         gtk_tree_view_column_set_title (view_column, _("mcen_ia_optionalsmtp_connection_name"));
360         gtk_tree_view_append_column (priv->treeview, view_column);
361
362         
363         /* server name column: */
364         view_column = gtk_tree_view_column_new ();
365         renderer = gtk_cell_renderer_text_new ();
366         gtk_tree_view_column_pack_start(view_column, renderer, TRUE);
367         gtk_tree_view_column_set_attributes (view_column, renderer, 
368         "text", MODEL_COL_SERVER_NAME, NULL);
369         gtk_tree_view_column_set_title (view_column, _("mcen_ia_optionalsmtp_servername"));
370         gtk_tree_view_append_column (priv->treeview, view_column);
371         
372         /* The application must call modest_connection_specific_smtp_window_fill_with_connections(). */
373         
374         GtkWidget *vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
375
376         /* Introductory note: */
377         /* TODO: For some reason this label does not wrap. It is truncated. */
378         GtkWidget *label = gtk_label_new(_("mcen_ia_optionalsmtp_note"));
379         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
380         /* So that it is shown without being truncated: */
381         gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
382         gtk_widget_show (label);
383         gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, MODEST_MARGIN_HALF);
384         
385         /* Put the treeview in a scrolled window and add it to the box: */
386         GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
387         gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), MODEST_MARGIN_DEFAULT);
388         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, 
389                 GTK_POLICY_AUTOMATIC);
390         gtk_widget_show (scrolled_window);
391         gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (priv->treeview));
392         gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (scrolled_window), TRUE, TRUE, MODEST_MARGIN_HALF);
393         gtk_widget_show (GTK_WIDGET (priv->treeview));
394         
395         /* Add the buttons: */
396         GtkWidget *hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_HALF);
397         gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, MODEST_MARGIN_HALF);
398         gtk_widget_show (hbox);
399         
400         priv->button_edit = gtk_button_new_from_stock (GTK_STOCK_EDIT);
401         gtk_box_pack_start (GTK_BOX (hbox), priv->button_edit, TRUE, FALSE, MODEST_MARGIN_HALF);
402         gtk_widget_show (priv->button_edit);
403         g_signal_connect (G_OBJECT (priv->button_edit), "clicked",
404                 G_CALLBACK (on_button_edit), self);
405         
406         GtkWidget *button_cancel = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
407         gtk_box_pack_start (GTK_BOX (hbox), button_cancel, TRUE, FALSE, MODEST_MARGIN_HALF);
408         gtk_widget_show (button_cancel);
409         g_signal_connect (G_OBJECT (button_cancel), "clicked",
410                 G_CALLBACK (on_button_cancel), self);
411         
412         gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (vbox));
413         gtk_widget_show (vbox);
414         
415         /* Disable the Edit button when nothing is selected: */
416         GtkTreeSelection *sel = gtk_tree_view_get_selection (priv->treeview);
417         g_signal_connect (sel, "changed",
418                           G_CALLBACK(on_selection_changed), self);
419         on_selection_changed (sel, self);
420         
421         /* When this window is shown, hibernation should not be possible, 
422          * because there is no sensible way to save the state: */
423         mgr = modest_runtime_get_window_mgr ();
424         modest_window_mgr_prevent_hibernation_while_window_is_shown (mgr, 
425                                                                      GTK_WINDOW (self)); 
426
427         /* Set window title */
428         gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers"));
429 }
430
431 ModestConnectionSpecificSmtpWindow*
432 modest_connection_specific_smtp_window_new (void)
433 {
434         return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_WINDOW, NULL);
435 }
436
437 /** The application should call this when the user changes should be saved.
438  * @account_name: Specify this again in case it was not previously known.
439  */
440 gboolean
441 modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpecificSmtpWindow *self, 
442         const gchar* account_name)
443 {
444         ModestConnectionSpecificSmtpWindowPrivate *priv = 
445                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
446         
447         
448         /* Get the first iter in the list */
449         GtkTreeIter iter;
450         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
451
452         /* Walk through the list, reading each row */
453         while (valid) {
454         gchar *id = NULL;
455                 gchar *connection_name = NULL;
456                 gchar *server_account_name = NULL;
457                 ModestServerAccountData *data = NULL;
458                 
459                 gtk_tree_model_get (priv->model, &iter, 
460                                     MODEL_COL_ID, &id, 
461                                     MODEL_COL_NAME, &connection_name, 
462                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
463                                     MODEL_COL_SERVER_ACCOUNT_DATA, &data,
464                                     -1);
465                                  
466                 gboolean success = TRUE;   
467                 if (id && data) { /* The presence of data suggests that there is something to save. */
468                         if (!server_account_name) {
469                                 /* Add a new server account, building a (non-human-visible) name: */
470                                 gchar *name_start = g_strdup_printf("%s_specific_%s", 
471                                         priv->account_name, connection_name);
472                                 server_account_name = modest_account_mgr_get_unused_account_name (
473                                         priv->account_manager, name_start, TRUE /* server account. */);
474                                 g_assert (server_account_name);
475                                 g_free (name_start);
476                                 
477                                 success = modest_account_mgr_add_server_account (priv->account_manager,
478                                                                                  server_account_name,
479                                                                                  data->hostname, 0,
480                                                                                  data->username, data->password,
481                                                                                  MODEST_PROTOCOL_TRANSPORT_SMTP,
482                                                                                  data->security,
483                                                                                  data->secure_auth);
484                                         
485                                 /* associate the specific server account with this connection for this account: */
486                                 success = success && modest_account_mgr_set_connection_specific_smtp (
487                                         priv->account_manager, priv->account_name,
488                                          connection_name, server_account_name);
489         
490                                 /* Save the new name in the treemodel, so it can be edited again later: */
491                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
492                                         MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1);
493                                 
494                         } else {
495                                 /* Change an existing server account: */
496                                 success = modest_account_mgr_set_string (priv->account_manager, server_account_name,
497                                         MODEST_ACCOUNT_HOSTNAME, data->hostname, TRUE /* server account */);
498                                                 
499                                 modest_server_account_set_username (priv->account_manager, server_account_name,
500                                         data->username);
501                                                         
502                                 modest_server_account_set_password (priv->account_manager, server_account_name,
503                                         data->password);
504                                                 
505                                 modest_server_account_set_secure_auth (priv->account_manager, server_account_name, 
506                                         data->secure_auth);
507                                                 
508                                 modest_server_account_set_security (priv->account_manager, server_account_name, 
509                                         data->security);
510                                 
511                                 modest_account_mgr_set_int (priv->account_manager, server_account_name,
512                                                 MODEST_ACCOUNT_PORT, data->port, TRUE /* server account */);
513                         }
514                 }
515                 
516                 g_free (connection_name);
517                 g_free (id);
518                 g_free (server_account_name);
519                 
520                 if (!success)
521                         return FALSE;
522                         
523                 /* Get next row: */
524                 valid = gtk_tree_model_iter_next (priv->model, &iter);
525         }
526         
527         update_model_server_names (self);
528         
529         return TRUE;
530 }
531
532 void update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
533 {
534         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
535
536         GtkTreeIter iter;
537         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
538         while (valid) {
539                 
540                 gchar *server_account_name = NULL;
541                 gtk_tree_model_get (priv->model, &iter, 
542                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
543                                     -1);
544                                  
545                 if (server_account_name) {
546                         /* Get the server hostname and show it in the treemodel: */     
547                         gchar *hostname = modest_account_mgr_get_string (priv->account_manager, 
548                                 server_account_name, MODEST_ACCOUNT_HOSTNAME, TRUE /* server account */);
549                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
550                                             MODEL_COL_SERVER_NAME, hostname,
551                                             -1);
552                         g_free (hostname);
553                 } else {
554                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
555                                             MODEL_COL_SERVER_NAME, _("mcen_ia_optionalsmtp_notdefined"),
556                                             -1);
557                 }
558                         
559                 /* Get next row: */
560                 valid = gtk_tree_model_iter_next (priv->model, &iter);
561         }
562 }
563