X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-connection-specific-smtp-window.c;h=077879889febe79509afaed79d8a2e231c25581c;hp=91767b4c4f692b962215103063c4bed5383995dc;hb=40a8f5cbe03bd040fe3403dbfa6806df4fb6bc8a;hpb=a47ab3efd66045f23fe4196ddfc288d76abc6f6b diff --git a/src/maemo/modest-connection-specific-smtp-window.c b/src/maemo/modest-connection-specific-smtp-window.c index 91767b4..0778798 100644 --- a/src/maemo/modest-connection-specific-smtp-window.c +++ b/src/maemo/modest-connection-specific-smtp-window.c @@ -17,6 +17,9 @@ #include #include +#include "modest-hildon-includes.h" +#include "modest-platform.h" + #include G_DEFINE_TYPE (ModestConnectionSpecificSmtpWindow, modest_connection_specific_smtp_window, GTK_TYPE_WINDOW); @@ -208,51 +211,82 @@ on_button_edit (GtkButton *button, gpointer user_data) MODEL_COL_SERVER_ACCOUNT_DATA, &data, -1); - printf("DEBUG: %s: BEFORE: connection-specific server_account_name=%s\n", __FUNCTION__, server_account_name); + /* printf("DEBUG: %s: BEFORE: connection-specific server_account_name=%s\n", __FUNCTION__, server_account_name); */ /* TODO: Is 0 an allowed libconic IAP ID? * If not then we should check for it. */ /* Get existing server account data if a server account is already specified: */ - ModestServerAccountData *data_retrieved = NULL; + gboolean data_was_retrieved = FALSE; if (server_account_name && !data) { - data_retrieved = modest_account_mgr_get_server_account_data (priv->account_manager, + data = modest_account_mgr_get_server_account_data (priv->account_manager, server_account_name); - data = data_retrieved; + if (data) + data_was_retrieved = TRUE; } GtkWidget * window = GTK_WIDGET (modest_connection_specific_smtp_edit_window_new ()); modest_connection_specific_smtp_edit_window_set_connection ( MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name, data); - if (data_retrieved) - modest_account_mgr_free_server_account_data (priv->account_manager, data_retrieved); + /* Delete data, unless it was data from the rowmodel: */ + if (data_was_retrieved) { + modest_account_mgr_free_server_account_data (priv->account_manager, data); + data = NULL; + } gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window)); - gint response = gtk_dialog_run (GTK_DIALOG (window)); - gtk_widget_hide (window); - if (response == GTK_RESPONSE_OK) { - /* Delete any previous data for this row: */ - if (data) + gboolean dialog_finished = FALSE; + while (!dialog_finished) + { + gint response = gtk_dialog_run (GTK_DIALOG (window)); + if (response == GTK_RESPONSE_OK) { + gtk_widget_hide (window); + dialog_finished = TRUE; + /* Delete any previous data for this row: */ + if (data) + { + modest_account_mgr_free_server_account_data (priv->account_manager, data); + data = NULL; + } + + /* Get the new account data and save it in the row for later: + * We free this in finalize(), + * and save it to our configuration in + * modest_connection_specific_smtp_window_save_server_accounts(). */ + data = modest_connection_specific_smtp_edit_window_get_settings ( + MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), + priv->account_manager); + + const gchar* server_name = data ? data->hostname : NULL; + gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, + MODEL_COL_SERVER_ACCOUNT_DATA, data, + MODEL_COL_SERVER_NAME, server_name, + -1); + } + else { - modest_account_mgr_free_server_account_data (priv->account_manager, data); - data = NULL; + if (!modest_connection_specific_smtp_edit_window_is_dirty( + MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW(window))) + { + gtk_widget_hide(window); + dialog_finished = TRUE; + } + else + { + + gint response; + response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window), + _("imum_nc_wizard_confirm_lose_changes")); + if (response == GTK_RESPONSE_OK) + { + gtk_widget_hide(window); + dialog_finished = TRUE; + } + } } - - /* Get the new account data and save it in the row for later: - * We free this in finalize(), - * and save it to our configuration in - * modest_connection_specific_smtp_window_save_server_accounts(). */ - data = modest_connection_specific_smtp_edit_window_get_settings ( - MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), - priv->account_manager); - - gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, - MODEL_COL_SERVER_ACCOUNT_DATA, data, - -1); } } - g_free (connection_name); g_free (id); g_free (server_account_name); @@ -285,9 +319,11 @@ on_selection_changed (GtkTreeSelection *sel, ModestConnectionSpecificSmtpWindow static void modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow *self) { + ModestWindowMgr *mgr; + /* Specify a default size, because the GtkTreeView's default requested size * is not big enough: */ - gtk_window_set_default_size (GTK_WINDOW (self), 500, 200); + gtk_window_set_default_size (GTK_WINDOW (self), 500, 300); /* This seems to be necessary to make the window show at the front with decoration. * If we use property type=GTK_WINDOW_TOPLEVEL instead of the default GTK_WINDOW_POPUP+decoration, @@ -308,6 +344,11 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow /* Setup the tree view: */ priv->treeview = GTK_TREE_VIEW (gtk_tree_view_new_with_model (priv->model)); + /* Show the column headers, + * which does not seem to be the default on Maemo. + */ + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(priv->treeview), TRUE); + /* name column: * The ID model column in not shown in the view. */ GtkTreeViewColumn *view_column = gtk_tree_view_column_new (); @@ -331,6 +372,19 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow /* The application must call modest_connection_specific_smtp_window_fill_with_connections(). */ GtkWidget *vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT); + + /* Introductory note: */ + /* TODO: For some reason this label does not wrap. It is truncated. */ + GtkWidget *label = gtk_label_new(_("mcen_ia_optionalsmtp_note")); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + /* So that it is shown without being truncated: */ + gtk_label_set_max_width_chars (GTK_LABEL (label), 20); + /* The documentation for gtk_label_set_line_wrap() says that we must + * call gtk_widget_set_size_request() with a hard-coded width, + * though I wonder why gtk_label_set_max_width_chars() isn't enough. */ + gtk_widget_set_size_request (label, 400, -1); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, MODEST_MARGIN_HALF); /* Put the treeview in a scrolled window and add it to the box: */ GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL); @@ -370,8 +424,12 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow /* When this window is shown, hibernation should not be possible, * because there is no sensible way to save the state: */ - modest_window_mgr_prevent_hibernation_while_window_is_shown ( - modest_runtime_get_window_mgr (), GTK_WINDOW (self)); + mgr = modest_runtime_get_window_mgr (); + modest_window_mgr_prevent_hibernation_while_window_is_shown (mgr, + GTK_WINDOW (self)); + + /* Set window title */ + gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers")); } ModestConnectionSpecificSmtpWindow* @@ -417,15 +475,16 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe priv->account_name, connection_name); server_account_name = modest_account_mgr_get_unused_account_name ( priv->account_manager, name_start, TRUE /* server account. */); + g_assert (server_account_name); g_free (name_start); success = modest_account_mgr_add_server_account (priv->account_manager, - server_account_name, - data->hostname, - data->username, data->password, - MODEST_PROTOCOL_TRANSPORT_SMTP, - data->security, - data->secure_auth); + server_account_name, + data->hostname, 0, + data->username, data->password, + MODEST_PROTOCOL_TRANSPORT_SMTP, + data->security, + data->secure_auth); /* associate the specific server account with this connection for this account: */ success = success && modest_account_mgr_set_connection_specific_smtp ( @@ -495,6 +554,10 @@ void update_model_server_names (ModestConnectionSpecificSmtpWindow *self) MODEL_COL_SERVER_NAME, hostname, -1); g_free (hostname); + } else { + gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, + MODEL_COL_SERVER_NAME, _("mcen_ia_optionalsmtp_notdefined"), + -1); } /* Get next row: */