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