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