From e84ebd2e0a9ff78773bdd2cecfe0f2b6ebc2c252 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 22 Aug 2001 15:50:42 +0000 Subject: Prevent the user from creating two accounts with the same name. 2001-08-22 Peter Williams Prevent the user from creating two accounts with the same name. * mail-config.c (impl_GNOME_Evolution_MailConfig_addAccount): Abort if the account has the same name as another account. * mail-account-gui.c (mail_account_gui_save): Don't let the user save if the account has the same name as another account. * mail-config-druid.c (management_check): Disable the next button if the account name is the same as a preexisting account. (construct): The only part of 'pages' that was being used was the name. 'wizard_pages' now has the callbacks, while 'pages' is just an array of char *'s. (wizard_finish_cb): Save the account first because that's the right way, and try to honor mail_account_gui_save's return value. * mail-config.glade: Add a label noting that you're not allowed to create two accounts with the same name. svn path=/trunk/; revision=12384 --- mail/ChangeLog | 21 +++++++++++++++ mail/mail-account-gui.c | 19 ++++++++++++- mail/mail-config-druid.c | 69 ++++++++++++++---------------------------------- mail/mail-config.c | 5 ++++ mail/mail-config.glade | 17 ++++++++++++ 5 files changed, 81 insertions(+), 50 deletions(-) diff --git a/mail/ChangeLog b/mail/ChangeLog index 639122624a..66673e48bb 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,24 @@ +2001-08-22 Peter Williams + + Prevent the user from creating two accounts with the same name. + + * mail-config.c (impl_GNOME_Evolution_MailConfig_addAccount): Abort + if the account has the same name as another account. + + * mail-account-gui.c (mail_account_gui_save): Don't let the user + save if the account has the same name as another account. + + * mail-config-druid.c (management_check): Disable the next button + if the account name is the same as a preexisting account. + (construct): The only part of 'pages' that was being used was the + name. 'wizard_pages' now has the callbacks, while 'pages' is just + an array of char *'s. + (wizard_finish_cb): Save the account first because that's the + right way, and try to honor mail_account_gui_save's return value. + + * mail-config.glade: Add a label noting that you're not allowed + to create two accounts with the same name. + 2001-08-22 Peter Williams * folder-browser-ui.c (fbui_sensitize_timeout): Check for NULL uic diff --git a/mail/mail-account-gui.c b/mail/mail-account-gui.c index 0769ad1ab8..26c6fbf5b4 100644 --- a/mail/mail-account-gui.c +++ b/mail/mail-account-gui.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "shell/evolution-shell-client.h" #include "mail-account-gui.h" @@ -1562,6 +1563,8 @@ gboolean mail_account_gui_save (MailAccountGui *gui) { MailConfigAccount *account = gui->account; + const MailConfigAccount *old_account; + gchar *new_name; gboolean old_enabled; if (!mail_account_gui_identity_complete (gui, NULL) || @@ -1570,8 +1573,22 @@ mail_account_gui_save (MailAccountGui *gui) !mail_account_gui_management_complete (gui, NULL)) return FALSE; + /* this would happen at an inconvenient time in the druid, + * but the druid performs its own check so this can't happen + * here. */ + + new_name = e_utf8_gtk_entry_get_text (gui->account_name); + old_account = mail_config_get_account_by_name (new_name); + + if (old_account != account) { + e_notice (NULL, GNOME_MESSAGE_BOX_ERROR, + _("You may not create two accounts with the same name.")); + return FALSE; + } + g_free (account->name); - account->name = e_utf8_gtk_entry_get_text (gui->account_name); + account->name = new_name; + if (gtk_toggle_button_get_active (gui->default_account)) mail_config_set_default_account (account); diff --git a/mail/mail-config-druid.c b/mail/mail-config-druid.c index 966894bc81..f5781cacb9 100644 --- a/mail/mail-config-druid.c +++ b/mail/mail-config-druid.c @@ -355,6 +355,10 @@ management_check (MailConfigWizard *wizard) text = gtk_entry_get_text (wizard->gui->account_name); next_sensitive = text && *text; + /* no accounts with the same name */ + if (next_sensitive && mail_config_get_account_by_name (text)) + next_sensitive = FALSE; + evolution_wizard_set_buttons_sensitive (wizard->wizard, TRUE, next_sensitive, TRUE, NULL); } @@ -380,7 +384,6 @@ management_changed (GtkWidget *widget, gpointer data) management_check (gui); } - static MailConfigAccount * make_account (void) { @@ -403,48 +406,14 @@ make_account (void) return account; } -static struct { - char *name; - GtkSignalFunc next_func; - GtkSignalFunc prepare_func; - GtkSignalFunc back_func; - GtkSignalFunc finish_func; -} pages[] = { - { "identity_page", - GTK_SIGNAL_FUNC (identity_next), - GTK_SIGNAL_FUNC (identity_prepare), - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL) }, - { "source_page", - GTK_SIGNAL_FUNC (source_next), - GTK_SIGNAL_FUNC (source_prepare), - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL) }, - { "extra_page", - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (extra_prepare), - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL) }, - { "transport_page", - GTK_SIGNAL_FUNC (transport_next), - GTK_SIGNAL_FUNC (transport_prepare), - GTK_SIGNAL_FUNC (transport_back), - GTK_SIGNAL_FUNC (NULL) }, - { "management_page", - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (management_prepare), - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL) }, - { "finish_page", - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (druid_finish) }, - { NULL, - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL), - GTK_SIGNAL_FUNC (NULL) } +static const char *pages[] = { + "identity_page", + "source_page", + "extra_page", + "transport_page", + "management_page", + "finish_page", + NULL }; static int @@ -611,11 +580,11 @@ construct (MailConfigDruid *druid) g_hash_table_destroy (page_hash); } page_hash = g_hash_table_new (NULL, NULL); - for (i = 0; pages[i].name != NULL; i++) { + for (i = 0; pages[i] != NULL; i++) { GtkWidget *page; GnomeDruidPageStandard *dpage; - page = glade_xml_get_widget (druid->xml, pages[i].name); + page = glade_xml_get_widget (druid->xml, pages[i]); /* Store pages */ g_hash_table_insert (page_hash, page, GINT_TO_POINTER (i)); page_list = g_list_append (page_list, page); @@ -703,7 +672,6 @@ get_fn (EvolutionWizard *wizard, gtk_signal_connect (GTK_OBJECT (gui->gui->source.path), "changed", source_changed, gui); gtk_signal_connect (GTK_OBJECT (gui->gui->transport.hostname), - "changed", transport_changed, gui); gtk_signal_connect (GTK_OBJECT (gui->gui->transport.username), "changed", transport_changed, gui); @@ -837,12 +805,15 @@ wizard_finish_cb (EvolutionWizard *wizard, { MailAccountGui *gui = w->gui; - /* Add the account to our list (do it first because future + /* Save the settings for that account */ + if (mail_account_gui_save (gui) == FALSE) + /* problem. Um, how to keep the druid alive? */ + return; + + /* Add the account to our list (do it early because future steps might want to access config->accounts) */ mail_config_add_account (gui->account); - /* Save the settings for that account */ - mail_account_gui_save (gui); if (gui->account->source) gui->account->source->enabled = TRUE; diff --git a/mail/mail-config.c b/mail/mail-config.c index a406ba1367..7c0b4a4c97 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -1925,6 +1925,11 @@ impl_GNOME_Evolution_MailConfig_addAccount (PortableServer_Servant servant, MailConfigService *mail_service; MailConfigIdentity *mail_id; + if (mail_config_get_account_by_name (account->name)) { + /* FIXME: we need an exception. */ + return; + } + mail_account = g_new0 (MailConfigAccount, 1); mail_account->name = g_strdup (account->name); diff --git a/mail/mail-config.glade b/mail/mail-config.glade index 6dbce2a568..73309bdf1a 100644 --- a/mail/mail-config.glade +++ b/mail/mail-config.glade @@ -251,6 +251,23 @@ Click "Finish" to save your settings. False 0 + + GtkLabel + label40 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 4 + 0 + + 0 + False + False + + + GtkHBox hbox24 -- cgit v1.2.3