aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-config.c
diff options
context:
space:
mode:
authorJason Leach <jleach@ximian.com>2001-07-19 09:25:09 +0800
committerJacob Leach <jleach@src.gnome.org>2001-07-19 09:25:09 +0800
commitc87ef1f0a3302d89aacafcff22de49e442c18dc4 (patch)
treeade4574bee3d8204047b40ac6881d4cae5a5786b /mail/mail-config.c
parent150e7c57f8f542baf7e4f71caf38fe0d60c8917b (diff)
downloadgsoc2013-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/mail-config.c')
-rw-r--r--mail/mail-config.c106
1 files changed, 41 insertions, 65 deletions
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;