X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-connection-specific-smtp-window.c;h=45ce533ebf36f3b58fe79bf411d9eaee42a431c5;hb=f437bc152701d9a9b7cb75988ef04b30bbb0c8b4;hp=be4ad5c84bd3fec02deb87d612610b6667decd29;hpb=1c8928c2d9bf74d0df67eacf38aaf4947800dfb5;p=modest diff --git a/src/maemo/modest-connection-specific-smtp-window.c b/src/maemo/modest-connection-specific-smtp-window.c index be4ad5c..45ce533 100644 --- a/src/maemo/modest-connection-specific-smtp-window.c +++ b/src/maemo/modest-connection-specific-smtp-window.c @@ -46,10 +46,13 @@ #include "modest-hildon-includes.h" #include "modest-platform.h" +#include "modest-maemo-utils.h" #include +#include -G_DEFINE_TYPE (ModestConnectionSpecificSmtpWindow, modest_connection_specific_smtp_window, GTK_TYPE_WINDOW); +G_DEFINE_TYPE (ModestConnectionSpecificSmtpWindow, modest_connection_specific_smtp_window, + GTK_TYPE_DIALOG); #define CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_WINDOW, ModestConnectionSpecificSmtpWindowPrivate)) @@ -63,9 +66,10 @@ struct _ModestConnectionSpecificSmtpWindowPrivate GtkWidget *button_edit; ModestAccountMgr *account_manager; - gchar* account_name; }; +static gboolean on_key_pressed (GtkWidget *self, GdkEventKey *event, gpointer user_data); + static void modest_connection_specific_smtp_window_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) @@ -127,7 +131,6 @@ modest_connection_specific_smtp_window_finalize (GObject *object) } g_object_unref (G_OBJECT (priv->model)); - g_free (priv->account_name); G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->finalize (object); } @@ -151,13 +154,11 @@ modest_connection_specific_smtp_window_class_init (ModestConnectionSpecificSmtpW /* #define DEBUG_WITHOUT_LIBCONIC 1 */ void -modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self, ModestAccountMgr *account_manager, - const gchar* account_name) +modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self, ModestAccountMgr *account_manager) { ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self); priv->account_manager = account_manager; - priv->account_name = account_name ? g_strdup (account_name) : NULL; GtkListStore *liststore = GTK_LIST_STORE (priv->model); @@ -179,27 +180,26 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp ConIcIap *iap = (ConIcIap*)iter->data; if (iap) { #ifdef DEBUG_WITHOUT_LIBCONIC - const gchar *name = "debug name"; - const gchar *id = "debug id"; + const gchar *connection_name = "debug name"; + const gchar *connection_id = "debug id"; #else - const gchar *name = con_ic_iap_get_name (iap); - const gchar *id = con_ic_iap_get_id (iap); + const gchar *connection_name = con_ic_iap_get_name (iap); + const gchar *connection_id = con_ic_iap_get_id (iap); #endif - printf ("debug: iac name=%s, id=%s\n", name, id); + printf ("debug: iac name=%s, id=%s\n", connection_name, connection_id); /* Get any already-associated connection-specific server account: */ gchar *server_account_name = NULL; - if (priv->account_name) - server_account_name = modest_account_mgr_get_connection_specific_smtp ( - priv->account_manager, priv->account_name, name); + server_account_name = modest_account_mgr_get_connection_specific_smtp ( + priv->account_manager, connection_name); /* Add the row to the model: */ GtkTreeIter iter; gtk_list_store_append (liststore, &iter); gtk_list_store_set(liststore, &iter, - MODEL_COL_ID, id, - MODEL_COL_NAME, name, + MODEL_COL_ID, connection_id, + MODEL_COL_NAME, connection_name, MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1); @@ -285,11 +285,18 @@ on_button_edit (GtkButton *button, gpointer user_data) 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); + if (data) { + gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, + MODEL_COL_SERVER_ACCOUNT_DATA, data, + MODEL_COL_SERVER_NAME, data->hostname, + -1); + } else { + gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, + MODEL_COL_SERVER_ACCOUNT_DATA, NULL, + MODEL_COL_SERVER_NAME, NULL, + MODEL_COL_SERVER_ACCOUNT_NAME, NULL, + -1); + } } else { @@ -317,6 +324,7 @@ on_button_edit (GtkButton *button, gpointer user_data) g_free (connection_name); g_free (id); g_free (server_account_name); + update_model_server_names (self); } static void @@ -398,7 +406,8 @@ 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); + GtkWidget *vbox = GTK_DIALOG(self)->vbox; + //gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT); /* Introductory note: */ /* TODO: For some reason this label does not wrap. It is truncated. */ @@ -440,7 +449,7 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow g_signal_connect (G_OBJECT (button_cancel), "clicked", G_CALLBACK (on_button_cancel), self); - gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (vbox)); + //gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (vbox)); gtk_widget_show (vbox); /* Disable the Edit button when nothing is selected: */ @@ -457,6 +466,15 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow /* Set window title */ gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers")); + + /* Track key presses to close the window if the Escape is pressed */ + g_signal_connect (G_OBJECT (self), + "key-press-event", + G_CALLBACK (on_key_pressed), NULL); + + hildon_help_dialog_help_enable (GTK_DIALOG(self), + "applications_email_connectionsspecificsmtpconf", + modest_maemo_utils_get_osso_context()); } ModestConnectionSpecificSmtpWindow* @@ -466,11 +484,9 @@ modest_connection_specific_smtp_window_new (void) } /** The application should call this when the user changes should be saved. - * @account_name: Specify this again in case it was not previously known. */ gboolean -modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpecificSmtpWindow *self, - const gchar* account_name) +modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpecificSmtpWindow *self) { ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self); @@ -482,14 +498,16 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe /* Walk through the list, reading each row */ while (valid) { - gchar *id = NULL; + gchar *id = NULL; gchar *connection_name = NULL; gchar *server_account_name = NULL; + gchar *server_name = NULL; ModestServerAccountData *data = NULL; gtk_tree_model_get (priv->model, &iter, MODEL_COL_ID, &id, MODEL_COL_NAME, &connection_name, + MODEL_COL_SERVER_NAME, &server_name, MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name, MODEL_COL_SERVER_ACCOUNT_DATA, &data, -1); @@ -498,8 +516,7 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe if (id && data) { /* The presence of data suggests that there is something to save. */ if (!server_account_name) { /* Add a new server account, building a (non-human-visible) name: */ - gchar *name_start = g_strdup_printf("%s_specific_%s", - priv->account_name, connection_name); + gchar *name_start = g_strdup_printf("specific_%s", 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); @@ -512,11 +529,17 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe MODEST_PROTOCOL_TRANSPORT_SMTP, data->security, data->secure_auth); + if (success) { + TnyAccount *account = TNY_ACCOUNT (modest_tny_account_store_new_connection_specific_transport_account + (modest_runtime_get_account_store (), + server_account_name)); + if (account) + g_object_unref (account); + } /* associate the specific server account with this connection for this account: */ success = success && modest_account_mgr_set_connection_specific_smtp ( - priv->account_manager, priv->account_name, - connection_name, server_account_name); + priv->account_manager, connection_name, server_account_name); /* Save the new name in the treemodel, so it can be edited again later: */ gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, @@ -524,29 +547,35 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe } else { /* Change an existing server account: */ - success = modest_account_mgr_set_string (priv->account_manager, server_account_name, - MODEST_ACCOUNT_HOSTNAME, data->hostname, TRUE /* server account */); + modest_account_mgr_set_server_account_hostname (priv->account_manager, server_account_name, + data->hostname); - modest_server_account_set_username (priv->account_manager, server_account_name, + modest_account_mgr_set_server_account_username (priv->account_manager, server_account_name, data->username); - modest_server_account_set_password (priv->account_manager, server_account_name, + modest_account_mgr_set_server_account_password (priv->account_manager, server_account_name, data->password); - modest_server_account_set_secure_auth (priv->account_manager, server_account_name, + modest_account_mgr_set_server_account_secure_auth (priv->account_manager, server_account_name, data->secure_auth); - modest_server_account_set_security (priv->account_manager, server_account_name, + modest_account_mgr_set_server_account_security (priv->account_manager, server_account_name, data->security); - - modest_account_mgr_set_int (priv->account_manager, server_account_name, - MODEST_ACCOUNT_PORT, data->port, TRUE /* server account */); + + modest_account_mgr_set_server_account_port (priv->account_manager, server_account_name, data->port); } + } else if (connection_name && server_name && + !strcmp (server_name, _("mcen_ia_optionalsmtp_notdefined"))) { + modest_account_mgr_remove_connection_specific_smtp (priv->account_manager, + connection_name); + gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, + MODEL_COL_SERVER_ACCOUNT_NAME, NULL, -1); } g_free (connection_name); g_free (id); g_free (server_account_name); + g_free (server_name); if (!success) return FALSE; @@ -569,18 +598,24 @@ void update_model_server_names (ModestConnectionSpecificSmtpWindow *self) while (valid) { gchar *server_account_name = NULL; + ModestServerAccountData *data = NULL; gtk_tree_model_get (priv->model, &iter, MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name, + MODEL_COL_SERVER_ACCOUNT_DATA, &data, -1); - if (server_account_name) { + /* Get the server hostname and show it in the treemodel: */ - gchar *hostname = modest_account_mgr_get_string (priv->account_manager, - server_account_name, MODEST_ACCOUNT_HOSTNAME, TRUE /* server account */); + gchar *hostname = modest_account_mgr_get_server_account_hostname (priv->account_manager, + server_account_name); gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, MODEL_COL_SERVER_NAME, hostname, -1); g_free (hostname); + } else if (data && data->hostname && (data->hostname[0] != '\0')) { + gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, + MODEL_COL_SERVER_NAME, data->hostname, + -1); } else { gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, MODEL_COL_SERVER_NAME, _("mcen_ia_optionalsmtp_notdefined"), @@ -592,3 +627,15 @@ void update_model_server_names (ModestConnectionSpecificSmtpWindow *self) } } +static gboolean +on_key_pressed (GtkWidget *self, + GdkEventKey *event, + gpointer user_data) +{ + if (event->keyval == GDK_Escape) { + /* Simulate a press on Cancel to close the dialog */ + on_button_cancel (NULL, self); + } + + return FALSE; +}