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