diff options
author | Jason Leach <jleach@ximian.com> | 2001-07-19 09:25:09 +0800 |
---|---|---|
committer | Jacob Leach <jleach@src.gnome.org> | 2001-07-19 09:25:09 +0800 |
commit | c87ef1f0a3302d89aacafcff22de49e442c18dc4 (patch) | |
tree | ade4574bee3d8204047b40ac6881d4cae5a5786b /mail | |
parent | 150e7c57f8f542baf7e4f71caf38fe0d60c8917b (diff) | |
download | gsoc2013-evolution-c87ef1f0a3302d89aacafcff22de49e442c18dc4.tar gsoc2013-evolution-c87ef1f0a3302d89aacafcff22de49e442c18dc4.tar.gz gsoc2013-evolution-c87ef1f0a3302d89aacafcff22de49e442c18dc4.tar.bz2 gsoc2013-evolution-c87ef1f0a3302d89aacafcff22de49e442c18dc4.tar.lz gsoc2013-evolution-c87ef1f0a3302d89aacafcff22de49e442c18dc4.tar.xz gsoc2013-evolution-c87ef1f0a3302d89aacafcff22de49e442c18dc4.tar.zst gsoc2013-evolution-c87ef1f0a3302d89aacafcff22de49e442c18dc4.zip |
[Simplifying how default account is stored and used internally, fixes
2001-07-18 Jason Leach <jleach@ximian.com>
[Simplifying how default account is stored and used internally,
fixes possabilities of having multiple default accounts and things
like deleting the current default account]
* mail-account-gui.c (mail_account_gui_new): Update for new way of
finding out the default account.
(mail_account_gui_save): Ditto.
* mail-accounts.c (load_accounts): Ditto.
* mail-config-druid.c (make_default_account): Ditto.
* mail-config.c: Added an int MailConfig::default_account, to be
used instead of a 'default_account' boolean on each mail account.
(mail_config_set_default_account_num): New function, facilitates
things.
* Mail.idl: removed the Account::default_account boolean.
svn path=/trunk/; revision=11218
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 21 | ||||
-rw-r--r-- | mail/Mail.idl | 1 | ||||
-rw-r--r-- | mail/mail-account-gui.c | 9 | ||||
-rw-r--r-- | mail/mail-accounts.c | 10 | ||||
-rw-r--r-- | mail/mail-config-druid.c | 21 | ||||
-rw-r--r-- | mail/mail-config.c | 106 | ||||
-rw-r--r-- | mail/mail-config.h | 3 |
7 files changed, 89 insertions, 82 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 0126bf2156..56a38a5bee 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,24 @@ +2001-07-18 Jason Leach <jleach@ximian.com> + + [Simplifying how default account is stored and used internally, + fixes possabilities of having multiple default accounts and things + like deleting the current default account] + + * mail-account-gui.c (mail_account_gui_new): Update for new way of + finding out the default account. + (mail_account_gui_save): Ditto. + + * mail-accounts.c (load_accounts): Ditto. + + * mail-config-druid.c (make_default_account): Ditto. + + * mail-config.c: Added an int MailConfig::default_account, to be + used instead of a 'default_account' boolean on each mail account. + (mail_config_set_default_account_num): New function, facilitates + things. + + * Mail.idl: removed the Account::default_account boolean. + 2001-07-18 Jeffrey Stedfast <fejj@ximian.com> * mail-tools.c (mail_tool_generate_forward_subject): Do what was diff --git a/mail/Mail.idl b/mail/Mail.idl index 6144bb22a8..f68889e0c2 100644 --- a/mail/Mail.idl +++ b/mail/Mail.idl @@ -61,7 +61,6 @@ module Evolution { struct Account { string name; - boolean default_account; Identity id; Service source; diff --git a/mail/mail-account-gui.c b/mail/mail-account-gui.c index 6d32b7527b..6e0e09d444 100644 --- a/mail/mail-account-gui.c +++ b/mail/mail-account-gui.c @@ -1131,7 +1131,9 @@ mail_account_gui_new (MailConfigAccount *account) gui->default_account = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui->xml, "management_default")); if (account->name) e_utf8_gtk_entry_set_text (gui->account_name, account->name); - gtk_toggle_button_set_active (gui->default_account, account->default_account); + if (!mail_config_get_default_account() + || (account == mail_config_get_default_account())) + gtk_toggle_button_set_active (gui->default_account, TRUE); /* Identity */ gui->full_name = GTK_ENTRY (glade_xml_get_widget (gui->xml, "identity_full_name")); @@ -1531,8 +1533,9 @@ mail_account_gui_save (MailAccountGui *gui) g_free (account->name); account->name = e_utf8_gtk_entry_get_text (gui->account_name); - account->default_account = gtk_toggle_button_get_active (gui->default_account); - + if (gtk_toggle_button_get_active (gui->default_account)) + mail_config_set_default_account (account); + /* construct the identity */ identity_destroy (account->id); account->id = g_new0 (MailConfigIdentity, 1); diff --git a/mail/mail-accounts.c b/mail/mail-accounts.c index cbf20fa1db..d1abcb136d 100644 --- a/mail/mail-accounts.c +++ b/mail/mail-accounts.c @@ -110,15 +110,18 @@ load_accounts (MailAccountsDialog *dialog) const MailConfigAccount *account; const GSList *node = dialog->accounts; int i = 0; - + int default_account; + gtk_clist_freeze (dialog->mail_accounts); gtk_clist_clear (dialog->mail_accounts); + default_account = mail_config_get_default_account_num (); + while (node) { CamelURL *url; gchar *text[3]; - + account = node->data; if (account->source && account->source->url) @@ -129,7 +132,7 @@ load_accounts (MailAccountsDialog *dialog) text[0] = (account->source && account->source->enabled) ? "+" : ""; text[1] = account->name; text[2] = g_strdup_printf ("%s%s", url && url->protocol ? url->protocol : _("None"), - account->default_account ? _(" (default)") : ""); + (i == default_account) ? _(" (default)") : ""); if (url) camel_url_free (url); @@ -310,6 +313,7 @@ mail_delete (GtkButton *button, gpointer data) len = dialog->accounts ? g_slist_length ((GSList *) dialog->accounts) : 0; if (len > 0) { row = sel >= len ? len - 1 : sel; + load_accounts (dialog); gtk_clist_select_row (dialog->mail_accounts, row, 0); } else { dialog->accounts_row = -1; diff --git a/mail/mail-config-druid.c b/mail/mail-config-druid.c index 018b220b61..84730f3cf0 100644 --- a/mail/mail-config-druid.c +++ b/mail/mail-config-druid.c @@ -164,7 +164,6 @@ create_html (const char *name) static void druid_cancel (GnomeDruid *druid, gpointer user_data) { - /* Cancel the setup of the account */ MailConfigDruid *config = user_data; gtk_widget_destroy (GTK_WIDGET (config)); @@ -173,17 +172,23 @@ druid_cancel (GnomeDruid *druid, gpointer user_data) static void druid_finish (GnomeDruidPage *page, gpointer arg1, gpointer user_data) { - /* Cancel the setup of the account */ MailConfigDruid *druid = user_data; MailAccountGui *gui = druid->gui; GSList *mini; - + + /* Add the account to our list (do it first 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; - mail_config_add_account (gui->account); + + /* Write out the config info */ mail_config_write (); - + + /* Load up this new account */ mini = g_slist_prepend (NULL, gui->account); mail_load_storages (druid->shell, mini, TRUE); g_slist_free (mini); @@ -376,15 +381,13 @@ management_changed (GtkWidget *widget, gpointer data) static MailConfigAccount * -make_default_account (void) +make_account (void) { MailConfigAccount *account; char *name, *user; struct utsname uts; account = g_new0 (MailConfigAccount, 1); - if (!mail_config_get_default_account) - account->default_account = TRUE; account->id = g_new0 (MailConfigIdentity, 1); name = g_get_real_name (); @@ -450,7 +453,7 @@ construct (MailConfigDruid *druid) MailConfigAccount *account; int i; - account = make_default_account (); + account = make_account (); druid->gui = mail_account_gui_new (account); /* get our toplevel widget and reparent it */ diff --git a/mail/mail-config.c b/mail/mail-config.c index 204ed35bd3..dd5ec54e87 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -70,6 +70,8 @@ typedef struct { gboolean empty_trash_on_exit; GSList *accounts; + gint default_account; + GSList *news; char *pgp_path; @@ -91,7 +93,8 @@ static MailConfig *config = NULL; /* Prototypes */ static void config_read (void); -static gint mail_config_get_default_account_num (void); +static void mail_config_set_default_account_num (gint new_default); + /* Identity */ MailConfigIdentity * @@ -173,7 +176,6 @@ account_copy (const MailConfigAccount *account) new = g_new0 (MailConfigAccount, 1); new->name = g_strdup (account->name); - new->default_account = account->default_account; new->id = identity_copy (account->id); new->source = service_copy (account->source); @@ -280,9 +282,6 @@ config_read (void) len = bonobo_config_get_long_with_default (config->db, "/Mail/Accounts/num", 0, NULL); - default_num = bonobo_config_get_long_with_default (config->db, - "/Mail/Accounts/default_account", 0, NULL); - for (i = 0; i < len; i++) { MailConfigAccount *account; MailConfigIdentity *id; @@ -295,11 +294,6 @@ config_read (void) account->name = bonobo_config_get_string (config->db, path, NULL); g_free (path); - if (default_num == i) - account->default_account = TRUE; - else - account->default_account = FALSE; - path = g_strdup_printf ("/Mail/Accounts/account_drafts_folder_name_%d", i); val = bonobo_config_get_string (config->db, path, NULL); g_free (path); @@ -447,7 +441,13 @@ config_read (void) config->accounts = g_slist_append (config->accounts, account); } - + + + default_num = bonobo_config_get_long_with_default (config->db, + "/Mail/Accounts/default_account", 0, NULL); + + mail_config_set_default_account_num (default_num); + #ifdef ENABLE_NNTP /* News */ @@ -1268,25 +1268,20 @@ mail_config_get_default_account (void) { const MailConfigAccount *account; GSList *l; + MailConfigAccount *retval; if (!config->accounts) return NULL; - - /* find the default account */ - l = config->accounts; - while (l) { - account = l->data; - if (account->default_account) - return account; - - l = l->next; - } - - /* none are marked as default so mark the first one as the default */ - account = config->accounts->data; - mail_config_set_default_account (account); - - return account; + + retval = g_slist_nth_data (config->accounts, + config->default_account); + + /* Looks like we have no default, so make the first account + the default */ + if (retval == NULL) + mail_config_set_default_account_num (0); + + return retval; } const MailConfigAccount * @@ -1340,64 +1335,46 @@ mail_config_get_accounts (void) void mail_config_add_account (MailConfigAccount *account) { - if (account->default_account) { - /* Un-defaultify other accounts */ - GSList *node = config->accounts; - - while (node) { - MailConfigAccount *acnt = node->data; - - acnt->default_account = FALSE; - - node = node->next; - } - } - config->accounts = g_slist_append (config->accounts, account); } const GSList * mail_config_remove_account (MailConfigAccount *account) { + /* Removing the current default, so make the first account the + default */ + if (account == mail_config_get_default_account ()) + config->default_account = 0; + config->accounts = g_slist_remove (config->accounts, account); account_destroy (account); - + return config->accounts; } -static gint +gint mail_config_get_default_account_num (void) { - int i = 0; - GSList *node = config->accounts; - - while (node) { - MailConfigAccount *account = node->data; - - if (account->default_account) - return i; - - i++; - node = node->next; - } + return config->default_account; +} - return 0; +static void +mail_config_set_default_account_num (gint new_default) +{ + config->default_account = new_default; } void mail_config_set_default_account (const MailConfigAccount *account) { GSList *node = config->accounts; - - while (node) { - MailConfigAccount *acnt = node->data; - - acnt->default_account = FALSE; + gint position = 0; + + position = g_slist_index (config->accounts, (void*)account); + + config->default_account = position; - node = node->next; - } - - ((MailConfigAccount *) account)->default_account = TRUE; + return; } const MailConfigIdentity * @@ -1630,7 +1607,6 @@ impl_GNOME_Evolution_MailConfig_addAccount (PortableServer_Servant servant, mail_account = g_new0 (MailConfigAccount, 1); mail_account->name = g_strdup (account->name); - mail_account->default_account = account->default_account; /* Copy ID */ id = account->id; diff --git a/mail/mail-config.h b/mail/mail-config.h index 365d97a7af..551d6a81ff 100644 --- a/mail/mail-config.h +++ b/mail/mail-config.h @@ -51,7 +51,6 @@ typedef struct { typedef struct { gchar *name; - gboolean default_account; MailConfigIdentity *id; MailConfigService *source; @@ -164,11 +163,13 @@ const char *mail_config_get_default_charset (void); void mail_config_set_default_charset (const char *charset); const MailConfigAccount *mail_config_get_default_account (void); +gint mail_config_get_default_account_num (void); const MailConfigAccount *mail_config_get_account_by_name (const char *account_name); const MailConfigAccount *mail_config_get_account_by_source_url (const char *url); const GSList *mail_config_get_accounts (void); void mail_config_add_account (MailConfigAccount *account); const GSList *mail_config_remove_account (MailConfigAccount *account); + void mail_config_set_default_account (const MailConfigAccount *account); const MailConfigIdentity *mail_config_get_default_identity (void); |