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