From 6a5a4a54cba3fd795843678d87fd59f05d15e61f Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Mon, 16 Apr 2007 18:23:01 +0000 Subject: [PATCH] Attempt to commit. See ChangeLog2 pmo-trunk-r1568 --- ChangeLog2 | 20 ++ po/en_GB.po | 2 +- src/maemo/easysetup/modest-easysetup-wizard.c | 46 +++-- src/maemo/modest-account-settings-dialog.c | 242 +++++++++++++++---------- src/modest-account-mgr-helpers.c | 2 + src/modest-account-mgr.c | 34 ++++ src/modest-account-mgr.h | 17 +- 7 files changed, 251 insertions(+), 112 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index e898afc..4708bdb 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,5 +1,25 @@ 2007-04-16 Murray Cumming + * src/modest-account-mgr-helpers.c: Clarified the documentation to say that the initial + display name is based on the supplied account name. + * src/modest-account-mgr.c: + * src/modest-account-mgr.h: Added modest_account_mgr_account_with_display_name_exists(), + with an inefficient, but good-enough, implementation. + + * src/maemo/easysetup/modest-easysetup-wizard.c: + (create_page_account_details), (on_before_next), (create_account): + Check for existing display names rather than (non-user-visible) account names, and just + create and set a unique account name at the end. + + * src/maemo/modest-account-settings-dialog.c: + (modest_account_settings_dialog_init), + (modest_account_settings_dialog_set_account_name), + (create_page_incoming): Show the display name, instead of the account name. + (on_response): Do some (not all) extra checks, as in the UI spec. + (save_configuration): Save the display name if it was changed. + +2007-04-16 Murray Cumming + * po/en_GB.po: Added needed logical ID and translation. * src/widgets/modest-account-view.c: (on_account_default_toggled), (init_view): Made the is-default column clicking work. diff --git a/po/en_GB.po b/po/en_GB.po index bd235ee..b7d9533 100644 --- a/po/en_GB.po +++ b/po/en_GB.po @@ -1176,7 +1176,7 @@ msgstr "Complete" #. #: ../src/maemo/easysetup/modest-easysetup-wizard.c:907 #, fuzzy -msgid "mail_ib_account_name_already_existing." +msgid "mail_ib_account_name_already_existing" msgstr "E-mail account name already in use" # MSG-INF028: If user tries to enter invalid e-mail address during mail account setup. diff --git a/src/maemo/easysetup/modest-easysetup-wizard.c b/src/maemo/easysetup/modest-easysetup-wizard.c index c562146..744a719 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard.c +++ b/src/maemo/easysetup/modest-easysetup-wizard.c @@ -317,9 +317,10 @@ create_page_account_details (ModestEasysetupWizardDialog *self) self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ()); /* Set a default account title, choosing one that does not already exist: */ + /* Note that this is irrelevant to the non-user visible name, which we will create later. */ gchar* default_acount_name = g_strdup (_("mcen_ia_emailsetup_defaultname")); - while (modest_account_mgr_account_exists (self->account_manager, - default_acount_name, FALSE /* server_account */)) { + while (modest_account_mgr_account_with_display_name_exists (self->account_manager, + default_acount_name)) { gchar * default_account_name2 = util_increment_name (default_acount_name); g_free (default_acount_name); @@ -1007,13 +1008,13 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget * if ((!account_name) || (strlen(account_name) == 0)) return FALSE; - gboolean name_in_use = FALSE; - name_in_use = modest_account_mgr_account_exists (account_wizard->account_manager, - account_name, FALSE /* server_account */); - + /* Aavoid a clash with an existing display name: */ + const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists ( + account_wizard->account_manager, account_name); + if (name_in_use) { /* Warn the user via a dialog: */ - show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing.")); + show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing")); return FALSE; } @@ -1167,18 +1168,29 @@ create_account (ModestEasysetupWizardDialog *self) { ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self); - const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title)); + const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title)); /* Some checks: */ - if (!account_name) + if (!display_name) return FALSE; /* We should have checked for this already, * and changed that name accordingly, * but let's check again just in case: */ - if (modest_account_mgr_account_exists (self->account_manager, account_name, FALSE)) - return FALSE; + if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name)) + return FALSE; + + /* Increment the non-user visible name if necessary, + * based on the display name: */ + gchar *account_name = g_strdup_printf ("%sID", display_name); + while (modest_account_mgr_account_exists (self->account_manager, + account_name, FALSE /* server_account */)) { + + gchar * account_name2 = util_increment_name (account_name); + g_free (account_name); + account_name = account_name2; + } /* username and password (for both incoming and outgoing): */ const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username)); @@ -1353,13 +1365,17 @@ create_account (ModestEasysetupWizardDialog *self) const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name)); modest_account_mgr_set_string (self->account_manager, account_name, MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */); - + const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email)); modest_account_mgr_set_string (self->account_manager, account_name, MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */); - - /* TODO: Should we set MODEST_ACCOUNT_DISPLAY_NAME? It's not clear what it is. */ - + + /* Set the display name: */ + modest_account_mgr_set_string (self->account_manager, account_name, + MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */); + + g_free (account_name); + return FALSE; } diff --git a/src/maemo/modest-account-settings-dialog.c b/src/maemo/modest-account-settings-dialog.c index 9ec09ef..e04aaf0 100644 --- a/src/maemo/modest-account-settings-dialog.c +++ b/src/maemo/modest-account-settings-dialog.c @@ -51,7 +51,7 @@ struct _ModestAccountSettingsDialogPrivate static void enable_buttons (ModestAccountSettingsDialog *self); -static void +static gboolean save_configuration (ModestAccountSettingsDialog *dialog); static void @@ -95,10 +95,11 @@ modest_account_settings_dialog_finalize (GObject *object) G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object); } -#if 0 static void show_error (GtkWindow *parent_window, const gchar* text); -#endif + +static void +show_ok (GtkWindow *parent_window, const gchar* text); static void @@ -378,6 +379,7 @@ static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self) gtk_widget_show (caption); /* The port widgets: */ + /* TODO: There are various rules about this in the UI spec. */ if (!self->entry_incoming_port) self->entry_incoming_port = GTK_WIDGET (gtk_entry_new ()); caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"), @@ -567,6 +569,46 @@ static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self) return GTK_WIDGET (box); } +static gboolean +check_data (ModestAccountSettingsDialog *self) +{ + /* Check that the title is not already in use: */ + const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title)); + if ((!account_name) || (strlen(account_name) == 0)) + return FALSE; /* Should be prevented already anyway. */ + + if (strcmp(account_name, self->original_account_name) != 0) { + /* Check the changed title: */ + const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager, + account_name); + + if (name_in_use) { + /* Warn the user via a dialog: */ + show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing")); + + return FALSE; + } + } + + /* Check that the email address is valud: */ + const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email)); + if ((!email_address) || (strlen(email_address) == 0)) + return FALSE; + + if (!modest_text_utils_validate_email_address (email_address)) { + /* Warn the user via a dialog: */ + show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email")); + + /* Return focus to the email address entry: */ + gtk_widget_grab_focus (self->entry_user_email); + + return FALSE; + } + + /* TODO: The UI Spec wants us to check that the servernames are valid, + * but does not specify how. + */ +} /* */ static void @@ -579,8 +621,44 @@ on_response (GtkDialog *wizard_dialog, /* TODO: Prevent the OK response if the data is invalid. */ - if (response_id == GTK_RESPONSE_OK) - save_configuration (self); + gboolean prevent_response = FALSE; + + /* Warn about unsaved changes: */ + /* TODO: Actually detect whether changes were made. */ + if (response_id == GTK_RESPONSE_CANCEL) { + GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self), + (GtkDialogFlags)0, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */ + _("imum_nc_wizard_confirm_lose_changes") )); + + const gint dialog_response = gtk_dialog_run (dialog); + gtk_widget_destroy (GTK_WIDGET (dialog)); + + if (dialog_response != GTK_RESPONSE_OK) + prevent_response = TRUE; + } + /* Check for invalid input: */ + else if (!check_data (self)) { + prevent_response = TRUE; + } + + if (prevent_response) { + /* This is a nasty hack. murrayc. */ + /* Don't let the dialog close */ + g_signal_stop_emission_by_name (wizard_dialog, "response"); + return; + } + + + if (response_id == GTK_RESPONSE_OK) { + /* Try to save the changes: */ + const gboolean saved = save_configuration (self); + if (saved) + show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved")); + else + show_error (GTK_WINDOW (self), _("mail_ib_setting_failed")); + } } static void @@ -626,7 +704,11 @@ modest_account_settings_dialog_init (ModestAccountSettingsDialog *self) gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); /* Connect to the dialog's response signal: */ - g_signal_connect_after (G_OBJECT (self), "response", + /* We use connect-before + * so we can stop the signal emission, + * to stop the default signal handler from closing the dialog. + */ + g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self); } @@ -663,8 +745,12 @@ void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialo } /* Show the account data in the widgets: */ + + /* Note that we never show the non-display name in the UI. + * (Though the display name defaults to the non-display name at the start.) */ gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title), - account_name ? account_name : ""); + account_data->display_name ? account_data->display_name : ""); + gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name), account_data->fullname ? account_data->fullname : ""); gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email), @@ -735,7 +821,7 @@ void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialo modest_account_mgr_free_account_data (dialog->account_manager, account_data); } -static void +static gboolean save_configuration (ModestAccountSettingsDialog *dialog) { g_assert (dialog->original_account_name); @@ -744,39 +830,51 @@ save_configuration (ModestAccountSettingsDialog *dialog) /* Set the account data from the widgets: */ const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name)); - modest_account_mgr_set_string (dialog->account_manager, account_name, + gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name, MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */); + if (!test) + return FALSE; const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email)); - modest_account_mgr_set_string (dialog->account_manager, account_name, + test = modest_account_mgr_set_string (dialog->account_manager, account_name, MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */); - + if (!test) + return FALSE; + /* TODO: Change name: */ /* Possibly the account name may never change, but that should be hidden, * and the display name may change, defaulting to the account name. */ const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages)); - modest_account_mgr_set_bool (dialog->account_manager, account_name, + test = modest_account_mgr_set_bool (dialog->account_manager, account_name, MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */); - + if (!test) + return FALSE; + /* Incoming: */ gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name, MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */); g_assert (incoming_account_name); const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver)); - modest_account_mgr_set_string (dialog->account_manager, incoming_account_name, + test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name, MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */); - + if (!test) + return FALSE; + const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username)); - modest_account_mgr_set_string (dialog->account_manager, incoming_account_name, + test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name, MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */); - + if (!test) + return FALSE; + const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password)); - modest_account_mgr_set_string (dialog->account_manager, incoming_account_name, + test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name, MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */); - + if (!test) + return FALSE; + /* TODO: How can we set these in the server account?: ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) ? MODEST_PROTOCOL_AUTH_PASSWORD @@ -795,20 +893,22 @@ save_configuration (ModestAccountSettingsDialog *dialog) g_assert (outgoing_account_name); hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver)); - modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name, + test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name, MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */); + if (!test) + return FALSE; username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username)); - modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name, + test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name, MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */); + if (!test) + return FALSE; password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password)); - modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name, - MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */); - - password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password)); - modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name, + test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name, MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */); + if (!test) + return FALSE; /* TODO: How do we set these in the account data?: ModestProtocol protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity ( @@ -820,79 +920,22 @@ save_configuration (ModestAccountSettingsDialog *dialog) g_free (outgoing_account_name); -} - - -#if 0 -static gboolean -on_before_next (GtkDialog *dialog, GtkWidget *current_page, GtkWidget *next_page) -{ - ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (dialog); - /* Do extra validation that couldn't be done for every key press, - * either because it was too slow, - * or because it requires interaction: - */ - if (current_page == self->page_account_details) { - /* Check that the title is not already in use: */ - const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title)); - if ((!account_name) || (strlen(account_name) == 0)) - return FALSE; - - gboolean name_in_use = FALSE; - name_in_use = modest_account_mgr_account_exists (self->account_manager, - account_name, FALSE /* server_account */); + /* Set the changed account title last, to simplify the previous code: */ + const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title)); + if ((!account_title) || (strlen(account_title) == 0)) + return FALSE; /* Should be prevented already anyway. */ - if (name_in_use) { - /* Warn the user via a dialog: */ - show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing.")); - - return FALSE; - } - } - else if (current_page == self->page_user_details) { - /* Check that the email address is valud: */ - const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email)); - if ((!email_address) || (strlen(email_address) == 0)) - return FALSE; - - if (!modest_text_utils_validate_email_address (email_address)) { - /* Warn the user via a dialog: */ - show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email")); - - /* Return focus to the email address entry: */ - gtk_widget_grab_focus (self->entry_user_email); - + if (strcmp(account_title, account_name) != 0) { + /* Change the title: */ + gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name, + MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */); + if (!test) return FALSE; - } - - /* Make sure that the subsequent pages are appropriate for the provider choice. */ - create_subsequent_pages (self); } - /* TODO: The UI Spec wants us to check that the servernames are valid, - * but does not specify how. - */ - - if(next_page == self->page_incoming) { - set_default_custom_servernames (self); - } - else if (next_page == self->page_outgoing) { - set_default_custom_servernames (self); - } - - /* If this is the last page, and this is a click on Finish, - * then attempt to create the dialog. - */ - if(!next_page) /* This is NULL when this is a click on Finish. */ - { - create_account (self); - } - - return TRUE; } -#endif static gboolean entry_is_empty (GtkWidget *entry) { @@ -949,7 +992,6 @@ modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *kla object_class->finalize = modest_account_settings_dialog_finalize; } -#if 0 static void show_error (GtkWindow *parent_window, const gchar* text) { @@ -962,7 +1004,19 @@ show_error (GtkWindow *parent_window, const gchar* text) gtk_dialog_run (dialog); gtk_widget_destroy (GTK_WIDGET (dialog)); } -#endif + +static void +show_ok (GtkWindow *parent_window, const gchar* text) +{ + GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window, + (GtkDialogFlags)0, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + text )); + + gtk_dialog_run (dialog); + gtk_widget_destroy (GTK_WIDGET (dialog)); +} diff --git a/src/modest-account-mgr-helpers.c b/src/modest-account-mgr-helpers.c index 8930c35..3c839ca 100644 --- a/src/modest-account-mgr-helpers.c +++ b/src/modest-account-mgr-helpers.c @@ -107,6 +107,8 @@ modest_account_mgr_free_server_account_data (ModestAccountMgr *self, g_slice_free (ModestServerAccountData, data); } +/** You must use modest_account_mgr_free_account_data() on the result. + */ ModestAccountData* modest_account_mgr_get_account_data (ModestAccountMgr *self, const gchar* name) { diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index dfaec74..ceb8fe8 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -935,6 +935,40 @@ modest_account_mgr_account_exists (ModestAccountMgr * self, const gchar * name, return retval; } +gboolean modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self, + const gchar *display_name) +{ + GSList *account_names = NULL; + GSList *cursor = NULL; + + cursor = account_names = modest_account_mgr_account_names (self); + + gboolean found = FALSE; + + /* Look at each non-server account to check their display names; */ + while (cursor) { + const gchar * account_name = (gchar*)cursor->data; + + ModestAccountData *account_data = modest_account_mgr_get_account_data (self, account_name); + if (!account_data) { + g_printerr ("modest: failed to get account data for %s\n", account_name); + continue; + } + + if(account_data->display_name && (strcmp (account_data->display_name, display_name) == 0)) { + found = TRUE; + break; + } + + modest_account_mgr_free_account_data (self, account_data); + cursor = cursor->next; + } + g_slist_free (account_names); + + return found; +} + + gboolean diff --git a/src/modest-account-mgr.h b/src/modest-account-mgr.h index 84df591..6e8b888 100644 --- a/src/modest-account-mgr.h +++ b/src/modest-account-mgr.h @@ -92,7 +92,8 @@ ModestAccountMgr* modest_account_mgr_new (ModestConf *modest_c * @transport_name: the transport account (ie. sendmail/SMTP) * @err: a GError ptr, or NULL to ignore. * - * create a new account. the account with @name should not already exist + * Create a new account. The account with @name should not already exist. The @name will + * be used as the initial display name of the new account. * * Returns: TRUE if the creation succeeded, FALSE otherwise, * @err gives details in case of error @@ -202,7 +203,7 @@ GSList* modest_account_mgr_search_server_accounts (ModestAccountMgr *self, * @name: the account name to check * @server_account: if TRUE, this is a server account * - * check whether account @name exists + * check whether account @name exists. Note that this does not check the display name. * * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error) */ @@ -210,6 +211,18 @@ gboolean modest_account_mgr_account_exists (ModestAccountMgr *self, const gchar *name, gboolean server_account); +/** + * modest_account_mgr_account_exists: + * @self: a ModestAccountMgr instance + * @name: the account name to check + * + * check whether a non-server account with the @display_name exists. + * + * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error) + */ +gboolean modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self, + const gchar *display_name); + /** * modest_account_mgr_get_string: -- 1.7.9.5