536fda38ebdfcfb36166e78872996c760804d97e
[modest] / src / hildon2 / modest-connection-specific-smtp-window.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "modest-connection-specific-smtp-window.h"
31 #include "modest-connection-specific-smtp-edit-window.h"
32 #include <modest-account-mgr-helpers.h>
33 #include "widgets/modest-ui-constants.h"
34
35 #include <modest-runtime.h>
36 #include <tny-maemo-conic-device.h>
37
38 #include <gtk/gtktreeview.h>
39 #include <gtk/gtkcellrenderertext.h>
40 #include <gtk/gtkliststore.h>
41 #include <hildon/hildon-pannable-area.h>
42 #include <hildon/hildon-gtk.h>
43 #include <gtk/gtkbutton.h>
44 #include <gtk/gtkhbox.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkstock.h>
47
48 #include "modest-hildon-includes.h"
49 #include "modest-platform.h"
50 #include "modest-maemo-utils.h"
51
52 #include <glib/gi18n.h>
53 #include <string.h>
54
55 G_DEFINE_TYPE (ModestConnectionSpecificSmtpWindow, modest_connection_specific_smtp_window,
56                GTK_TYPE_DIALOG);
57
58 #define CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE(o) \
59         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_WINDOW, ModestConnectionSpecificSmtpWindowPrivate))
60
61 typedef struct _ModestConnectionSpecificSmtpWindowPrivate ModestConnectionSpecificSmtpWindowPrivate;
62
63 struct _ModestConnectionSpecificSmtpWindowPrivate
64 {
65         GtkTreeView *treeview;
66         GtkTreeModel *model;
67         GtkWidget *no_connection_label;
68         GtkWidget *pannable;
69         
70         ModestAccountMgr *account_manager;
71 };
72
73 static void on_response (GtkDialog *dialog, 
74                          gint response, 
75                          gpointer user_data);
76
77 /* static gboolean on_key_pressed (GtkWidget *self, GdkEventKey *event, gpointer user_data); */
78
79 static void
80 modest_connection_specific_smtp_window_get_property (GObject *object, guint property_id,
81                                                                                                                         GValue *value, GParamSpec *pspec)
82 {
83         switch (property_id) {
84         default:
85                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
86         }
87 }
88
89 static void
90 modest_connection_specific_smtp_window_set_property (GObject *object, guint property_id,
91                                                                                                                         const GValue *value, GParamSpec *pspec)
92 {
93         switch (property_id) {
94         default:
95                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
96         }
97 }
98
99 static void
100 modest_connection_specific_smtp_window_dispose (GObject *object)
101 {
102         if (G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose)
103                 G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose (object);
104 }
105
106 enum MODEL_COLS {
107         MODEL_COL_NAME = 0, /* libconic IAP Name: a string */
108         MODEL_COL_ID = 1, /* libconic IAP ID: a string */
109         MODEL_COL_SERVER_ACCOUNT_NAME = 2, /* a string */
110         MODEL_COL_SERVER_NAME = 3, /* a string */
111         MODEL_COL_SERVER_ACCOUNT_SETTINGS = 4 /* a gpointer */
112 };
113
114
115 void update_model_server_names (ModestConnectionSpecificSmtpWindow *self);
116
117 static void
118 modest_connection_specific_smtp_window_finalize (GObject *object)
119 {
120         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (object);
121         
122         /* Free all the data items from the treemodel: */
123         GtkTreeIter iter;
124         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
125         while (valid) {
126                 ModestServerAccountSettings *server_settings = NULL;
127                 
128                 gtk_tree_model_get (priv->model, &iter, 
129                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
130                                     -1);
131                                  
132                 if (server_settings)
133                         g_object_unref (server_settings);
134                         
135                 /* Get next row: */
136                 valid = gtk_tree_model_iter_next (priv->model, &iter);
137         }
138         
139         g_object_unref (G_OBJECT (priv->model));
140
141         g_object_unref (priv->treeview);
142         g_object_unref (priv->no_connection_label);
143         
144         G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->finalize (object);
145 }
146
147 static void
148 modest_connection_specific_smtp_window_class_init (ModestConnectionSpecificSmtpWindowClass *klass)
149 {
150         GObjectClass *object_class = G_OBJECT_CLASS (klass);
151
152         g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpWindowPrivate));
153
154         object_class->get_property = modest_connection_specific_smtp_window_get_property;
155         object_class->set_property = modest_connection_specific_smtp_window_set_property;
156         object_class->dispose = modest_connection_specific_smtp_window_dispose;
157         object_class->finalize = modest_connection_specific_smtp_window_finalize;
158 }
159
160 /* libconic does not return a list of connections in scratchbox,
161  * so enable this to put a fake row in the list,
162  * so we can test other parts of the code. */
163 /* #define DEBUG_WITHOUT_LIBCONIC 1 */
164
165 void
166 modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self,
167                                                               ModestAccountMgr *account_manager)
168 {
169         gboolean empty = TRUE;
170 #ifdef MODEST_HAVE_CONIC
171         ModestConnectionSpecificSmtpWindowPrivate *priv = 
172                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
173         priv->account_manager = account_manager;
174         
175         GtkListStore *liststore = GTK_LIST_STORE (priv->model);
176         
177         TnyDevice *device = modest_runtime_get_device ();
178         g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
179         
180         /* Get the list of Internet Access Points: */
181         #ifdef DEBUG_WITHOUT_LIBCONIC
182         GSList *list_iaps = g_slist_append(NULL, (gpointer)1);
183         #else
184         TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
185         GSList *list_iaps = tny_maemo_conic_device_get_iap_list (maemo_device);
186         #endif
187         
188         /* printf("debug: list_iaps=%p, list_iaps size = %d\n", list_iaps, g_slist_length(list_iaps)); */
189         
190         GSList* iter = list_iaps;
191         if (list_iaps != NULL)
192                 empty = FALSE;
193
194         while (iter) {
195                 ConIcIap *iap = (ConIcIap*)iter->data;
196                 if (iap) {
197                         #ifdef DEBUG_WITHOUT_LIBCONIC
198                         const gchar *connection_name = "debug name";
199                         const gchar *connection_id = "debug id";
200                         #else
201                         const gchar *connection_name = con_ic_iap_get_name (iap);
202                         const gchar *connection_id = con_ic_iap_get_id (iap);
203                         #endif
204                         
205                         printf ("debug: iac name=%s, id=%s\n", connection_name, connection_id);
206                         
207                         /* Get any already-associated connection-specific server account: */
208                         gchar *server_account_name = NULL;
209                         server_account_name = modest_account_mgr_get_connection_specific_smtp (
210                                 priv->account_manager, connection_id);
211                                         
212                         /* Add the row to the model: */
213                         GtkTreeIter iter;
214                         gtk_list_store_append (liststore, &iter);
215                         gtk_list_store_set(liststore, &iter, 
216                                 MODEL_COL_ID, connection_id, 
217                                 MODEL_COL_NAME, connection_name,
218                                 MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name,
219                                 -1);
220                                 
221                         if (server_account_name)
222                                 g_free (server_account_name);
223                 }
224                 
225                 iter = g_slist_next (iter);     
226         }
227                 
228         #ifndef DEBUG_WITHOUT_LIBCONIC
229         if (list_iaps)
230                 tny_maemo_conic_device_free_iap_list (maemo_device, list_iaps);
231         #endif
232                 
233         update_model_server_names (self);
234 #endif /*MODEST_HAVE_CONIC */
235
236         GtkWidget *child;
237         child = gtk_bin_get_child (GTK_BIN (priv->pannable));
238         if (child) {
239                 gtk_container_remove (GTK_CONTAINER (priv->pannable), child);
240         }
241
242         if (empty) {
243                 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (priv->pannable), 
244                                                         priv->no_connection_label);
245                 gtk_widget_show (priv->no_connection_label);
246         } else {
247                 gtk_container_add (GTK_CONTAINER (priv->pannable), GTK_WIDGET (priv->treeview));
248                 gtk_widget_show (GTK_WIDGET (priv->treeview));
249         }
250 }
251         
252 static void
253 edit_account (ModestConnectionSpecificSmtpWindow *self, GtkTreePath *path)
254 {
255         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
256         ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
257         
258         gchar *id = NULL;
259         gchar *connection_name = NULL;
260         gchar *server_account_name = NULL;
261         ModestServerAccountSettings *server_settings = NULL;
262         GtkTreeIter iter;
263         if (gtk_tree_model_get_iter (priv->model, &iter, path)) {
264                 gtk_tree_model_get (priv->model, &iter,
265                                     MODEL_COL_ID, &id,
266                                     MODEL_COL_NAME, &connection_name,
267                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
268                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
269                                     -1);
270         
271                 /* printf("DEBUG: %s: BEFORE: connection-specific server_account_name=%s\n", __FUNCTION__, server_account_name); */
272                 /* TODO: Is 0 an allowed libconic IAP ID?
273                  * If not then we should check for it. */
274                 
275                 /* Get existing server account data if a server account is already specified: */
276                 gboolean settings_were_retrieved = FALSE;
277                 if (server_account_name && !server_settings) {
278                         server_settings = modest_account_mgr_load_server_settings(mgr, server_account_name, TRUE);
279                         if (server_settings)
280                                 settings_were_retrieved = TRUE;
281                 }
282                 
283                 GtkWidget * window = GTK_WIDGET (modest_connection_specific_smtp_edit_window_new ());
284                 modest_connection_specific_smtp_edit_window_set_connection (
285                         MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name, server_settings);
286                         
287                 /* Delete data, unless it was data from the rowmodel: */
288                 if (settings_were_retrieved) {
289                         g_object_unref (server_settings);
290                         server_settings = NULL;
291                 }
292                         
293                 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (window), GTK_WINDOW (self));
294                 
295                 gint response = gtk_dialog_run (GTK_DIALOG (window));
296                 if (response == GTK_RESPONSE_OK) {
297
298                         /* Delete any previous data for this row: */
299                         if (server_settings) {
300                                 g_object_unref (server_settings);
301                                 server_settings = NULL;
302                         }
303                         
304                         /* Get the new account data and save it in the row for later:
305                          * We free this in finalize(),
306                          * and save it to our configuration in
307                          * modest_connection_specific_smtp_window_save_server_accounts(). */
308                         server_settings = modest_connection_specific_smtp_edit_window_get_settings (
309                                                                                                     MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window));
310                         
311                         if (server_settings) {
312                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
313                                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, server_settings,
314                                                     MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
315                                                     -1);
316                         } else {
317                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
318                                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, NULL,
319                                                     MODEL_COL_SERVER_NAME, NULL,
320                                                     MODEL_COL_SERVER_ACCOUNT_NAME, NULL,
321                                                     -1);
322                         }
323                 }
324                 gtk_widget_destroy (window);
325         }
326         g_free (connection_name);
327         g_free (id);
328         g_free (server_account_name);
329         update_model_server_names (self);
330 }
331
332 static void
333 on_row_activated (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, 
334                   ModestConnectionSpecificSmtpWindow *self)
335 {
336         edit_account (self, path);
337 }
338
339 static void
340 modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow *self)
341 {
342         ModestWindowMgr *mgr;
343
344         /* Specify a default size */
345         gtk_window_set_default_size (GTK_WINDOW (self), -1, 320);
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         priv->treeview = GTK_TREE_VIEW (hildon_gtk_tree_view_new_with_model (HILDON_UI_MODE_NORMAL, priv->model));
365         g_object_ref_sink (G_OBJECT (priv->treeview));
366
367         /* No connections label */
368         priv->no_connection_label = gtk_label_new (_("mcen_ia_optionalsmtp_noconnection"));
369         g_object_ref_sink (G_OBJECT (priv->no_connection_label));
370
371         /* name column:
372          * The ID model column in not shown in the view. */
373         GtkTreeViewColumn *view_column = gtk_tree_view_column_new ();
374         GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
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         
381         /* server name column: */
382         view_column = gtk_tree_view_column_new ();
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         //gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
393
394         /* Introductory note: */
395         /* TODO: For some reason this label does not wrap. It is truncated. */
396         GtkWidget *label = gtk_label_new(_("mcen_ia_optionalsmtp_note"));
397         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
398         gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
399         /* So that it is shown without being truncated: */
400         /* gtk_label_set_max_width_chars (GTK_LABEL (label), 20); */
401         /* The documentation for gtk_label_set_line_wrap() says that we must 
402          * call gtk_widget_set_size_request() with a hard-coded width, 
403          * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
404         /* gtk_widget_set_size_request (label, 400, -1); */
405         gtk_widget_show (label);
406         gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, MODEST_MARGIN_HALF);
407         
408         /* Put the treeview in a pannable and add it to the box: */
409         priv->pannable = hildon_pannable_area_new ();
410         g_object_set (G_OBJECT (priv->pannable), "initial-hint", TRUE, NULL);
411         gtk_container_set_border_width (GTK_CONTAINER (priv->pannable), MODEST_MARGIN_DEFAULT);
412         gtk_widget_show (priv->pannable);
413         gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->pannable), TRUE, TRUE, MODEST_MARGIN_HALF);
414         gtk_widget_show (vbox);
415         
416         g_signal_connect (G_OBJECT (priv->treeview), "row-activated", G_CALLBACK (on_row_activated), self);
417         
418         /* When this window is shown, hibernation should not be possible, 
419          * because there is no sensible way to save the state: */
420         mgr = modest_runtime_get_window_mgr ();
421         modest_window_mgr_prevent_hibernation_while_window_is_shown (mgr, 
422                                                                      GTK_WINDOW (self)); 
423
424         /* Set window title */
425         gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers"));
426
427         g_signal_connect (self, "response", G_CALLBACK (on_response), NULL);
428         
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  */
439 gboolean
440 modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpecificSmtpWindow *self)
441 {
442         ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
443         ModestConnectionSpecificSmtpWindowPrivate *priv = 
444                 CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
445         
446         
447         /* Get the first iter in the list */
448         GtkTreeIter iter;
449         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
450
451         /* Walk through the list, reading each row */
452         while (valid) {
453                 gchar *id = NULL;
454                 gchar *connection_name = NULL;
455                 gchar *server_account_name = NULL;
456                 gchar *server_name = NULL;
457                 ModestServerAccountSettings *server_settings = 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_NAME, &server_name,
463                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
464                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
465                                     -1);
466                                  
467                 gboolean success = TRUE;   
468                 if (id && server_settings) { /* The presence of data suggests that there is something to save. */
469                         if (!server_account_name) {
470                                 /* Add a new server account, building a (non-human-visible) name: */
471                                 gchar *name_start = g_strdup_printf("specific_%s", 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                                 modest_server_account_settings_set_account_name (server_settings, server_account_name);
478                                 success = modest_account_mgr_save_server_settings (mgr, server_settings);
479                                 if (success) {
480                                         TnyAccount *account = TNY_ACCOUNT (modest_tny_account_store_new_connection_specific_transport_account 
481                                                                            (modest_runtime_get_account_store (),
482                                                                             server_account_name));
483                                         if (account)
484                                                 g_object_unref (account);
485                                 }
486                                 
487                                 /* associate the specific server account with this connection for this account: */
488                                 success = success && modest_account_mgr_set_connection_specific_smtp (
489                                         priv->account_manager, id, server_account_name);
490                                 
491                                 /* Save the new name in the treemodel, so it can be edited again later: */
492                                 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
493                                         MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1);
494                                 
495                         } else {
496                                 modest_account_mgr_save_server_settings (mgr, server_settings);
497                         }
498                 } else if (id && server_name && 
499                            !strcmp (server_name, _("mcen_ia_optionalsmtp_notdefined"))) {
500                         modest_account_mgr_remove_connection_specific_smtp (priv->account_manager, 
501                                                                             id);
502                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
503                                             MODEL_COL_SERVER_ACCOUNT_NAME, NULL, -1);
504                 }
505                 
506                 g_free (connection_name);
507                 g_free (id);
508                 g_free (server_account_name);
509                 g_free (server_name);
510                 
511                 if (!success)
512                         return FALSE;
513                         
514                 /* Get next row: */
515                 valid = gtk_tree_model_iter_next (priv->model, &iter);
516         }
517         
518         update_model_server_names (self);
519         
520         return TRUE;
521 }
522
523 void update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
524 {
525         ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
526
527         GtkTreeIter iter;
528         gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
529         while (valid) {
530                 
531                 gchar *server_account_name = NULL;
532                 ModestServerAccountSettings *server_settings = NULL;
533                 gtk_tree_model_get (priv->model, &iter, 
534                                     MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
535                                     MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings,
536                                     -1);        
537                 if (server_settings && modest_server_account_settings_get_hostname (server_settings)
538                     && (modest_server_account_settings_get_hostname (server_settings) [0] != '\0')) {
539                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
540                                             MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings),
541                                             -1);
542                 } else if (server_account_name) {
543                         
544                         /* Get the server hostname and show it in the treemodel: */     
545                         gchar *hostname = modest_account_mgr_get_server_account_hostname (priv->account_manager, 
546                                                                                           server_account_name);
547                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
548                                             MODEL_COL_SERVER_NAME, hostname,
549                                             -1);
550                         g_free (hostname);
551                 } else {
552                         gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
553                                             MODEL_COL_SERVER_NAME, _("mcen_ia_optionalsmtp_notdefined"),
554                                             -1);
555                 }
556                         
557                 /* Get next row: */
558                 valid = gtk_tree_model_iter_next (priv->model, &iter);
559         }
560 }
561
562 static void
563 on_response (GtkDialog *dialog,
564              gint response,
565              gpointer user_data)
566 {
567         modest_connection_specific_smtp_window_save_server_accounts (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog));
568         gtk_widget_destroy (GTK_WIDGET (dialog));
569 }