Save the setting via gconf. (mail_config_add_account): Immediately save

2003-01-08  Jeffrey Stedfast  <fejj@ximian.com>

	* mail-config.c (mail_config_set_default_account): Save the
	setting via gconf.
	(mail_config_add_account): Immediately save the list of accounts.
	(mail_config_remove_account): Same.
	(mail_config_signature_run_script): g_free the charset value and
	use the composer's charset rather than the display charset.

svn path=/trunk/; revision=19284
This commit is contained in:
Jeffrey Stedfast
2003-01-08 18:26:56 +00:00
committed by Jeffrey Stedfast
parent 256a3d747f
commit d15ae27c17
3 changed files with 79 additions and 63 deletions

View File

@ -1,3 +1,12 @@
2003-01-08 Jeffrey Stedfast <fejj@ximian.com>
* mail-config.c (mail_config_set_default_account): Save the
setting via gconf.
(mail_config_add_account): Immediately save the list of accounts.
(mail_config_remove_account): Same.
(mail_config_signature_run_script): g_free the charset value and
use the composer's charset rather than the display charset.
2003-01-07 Jeffrey Stedfast <fejj@ximian.com> 2003-01-07 Jeffrey Stedfast <fejj@ximian.com>
* folder-browser.c (save_cursor_pos): Use gconf to get the paned * folder-browser.c (save_cursor_pos): Use gconf to get the paned

View File

@ -476,6 +476,19 @@
<!-- Account settings --> <!-- Account settings -->
<schema>
<key>/schemas/apps/evolution/mail/default_account</key>
<applyto>/apps/evolution/mail/default_account</applyto>
<owner>evolution-mail</owner>
<type>long</type>
<locale name="C">
<short>Index of the default account</short>
<long>
Index of the default account.
</long>
</locale>
</schema>
<schema> <schema>
<key>/schemas/apps/evolution/mail/accounts</key> <key>/schemas/apps/evolution/mail/accounts</key>
<applyto>/apps/evolution/mail/accounts</applyto> <applyto>/apps/evolution/mail/accounts</applyto>

View File

@ -78,7 +78,6 @@ typedef struct {
gboolean corrupt; gboolean corrupt;
GSList *accounts; GSList *accounts;
int default_account;
GHashTable *threaded_hash; GHashTable *threaded_hash;
GHashTable *preview_hash; GHashTable *preview_hash;
@ -101,7 +100,6 @@ static guint config_write_timeout = 0;
/* Prototypes */ /* Prototypes */
static void config_read (void); static void config_read (void);
static void mail_config_set_default_account_num (int new_default);
/* signatures */ /* signatures */
MailConfigSignature * MailConfigSignature *
@ -587,6 +585,42 @@ accounts_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointe
} }
} }
static void
accounts_save (void)
{
GSList *list, *tail, *n, *l;
char *xmlbuf;
list = NULL;
tail = (GSList *) &list;
l = config->accounts;
while (l != NULL) {
if ((xmlbuf = account_to_xml ((MailConfigAccount *) l->data))) {
n = g_slist_alloc ();
n->data = xmlbuf;
n->next = NULL;
tail->next = n;
tail = n;
}
l = l->next;
}
gconf_client_set_list (config->gconf, "/apps/evolution/mail/accounts", GCONF_VALUE_STRING, list, NULL);
l = list;
while (l != NULL) {
n = l->next;
g_free (l->data);
g_slist_free_1 (l);
l = n;
}
gconf_client_suggest_sync (config->gconf, NULL);
}
/* Config struct routines */ /* Config struct routines */
void void
mail_config_init (void) mail_config_init (void)
@ -762,54 +796,16 @@ config_read (void)
config_read_signatures (); config_read_signatures ();
accounts_changed (config->gconf, 0, NULL, NULL); accounts_changed (config->gconf, 0, NULL, NULL);
default_num = gconf_client_get_int (config->gconf, "/apps/evolution/mail/default_account", NULL);
mail_config_set_default_account_num (default_num);
} }
void void
mail_config_write (void) mail_config_write (void)
{ {
GSList *list, *l, *tail, *n;
int default_num, i;
char *xmlbuf;
if (!config) if (!config)
return; return;
config_write_signatures (); config_write_signatures ();
/* Accounts */
default_num = mail_config_get_default_account_num ();
gconf_client_set_int (config->gconf, "/apps/evolution/mail/default_account", default_num, NULL);
list = NULL;
tail = (GSList *) &list;
l = config->accounts;
while (l != NULL) {
if ((xmlbuf = account_to_xml ((MailConfigAccount *) l->data))) {
n = g_slist_alloc ();
n->data = xmlbuf;
n->next = NULL;
tail->next = n;
tail = n;
}
l = l->next;
}
gconf_client_set_list (config->gconf, "/apps/evolution/mail/accounts", GCONF_VALUE_STRING, list, NULL);
l = list;
while (l != NULL) {
n = l->next;
g_free (l->data);
g_slist_free_1 (l);
l = n;
}
gconf_client_suggest_sync (config->gconf, NULL); gconf_client_suggest_sync (config->gconf, NULL);
} }
@ -1114,21 +1110,21 @@ const MailConfigAccount *
mail_config_get_default_account (void) mail_config_get_default_account (void)
{ {
MailConfigAccount *account; MailConfigAccount *account;
int index;
if (config == NULL) { if (config == NULL)
mail_config_init (); mail_config_init ();
}
if (!config->accounts) if (!config->accounts)
return NULL; return NULL;
account = g_slist_nth_data (config->accounts, index = gconf_client_get_int (config->gconf, "/apps/evolution/mail/default_account", NULL);
config->default_account); account = g_slist_nth_data (config->accounts, index);
/* Looks like we have no default, so make the first account /* Looks like we have no default, so make the first account
the default */ the default */
if (account == NULL) { if (account == NULL) {
mail_config_set_default_account_num (0); gconf_client_set_int (config->gconf, "/apps/evolution/mail/default_account", 0, NULL);
account = config->accounts->data; account = config->accounts->data;
} }
@ -1254,40 +1250,40 @@ void
mail_config_add_account (MailConfigAccount *account) mail_config_add_account (MailConfigAccount *account)
{ {
config->accounts = g_slist_append (config->accounts, account); config->accounts = g_slist_append (config->accounts, account);
accounts_save ();
} }
const GSList * const GSList *
mail_config_remove_account (MailConfigAccount *account) mail_config_remove_account (MailConfigAccount *account)
{ {
int index; int index, cur;
cur = gconf_client_get_int (config->gconf, "/apps/evolution/mail/default_account", NULL);
/* Removing the current default, so make the first account the
default */
if (account == mail_config_get_default_account ()) { if (account == mail_config_get_default_account ()) {
config->default_account = 0; /* the default account has been deleted, the new
default becomes the first account in the list */
gconf_client_set_int (config->gconf, "/apps/evolution/mail/default_account", 0, NULL);
} else { } else {
/* adjust the default to make sure it points to the same one */ /* adjust the default to make sure it points to the same one */
index = g_slist_index (config->accounts, account); index = g_slist_index (config->accounts, account);
if (config->default_account > index) if (cur > index)
config->default_account--; gconf_client_set_int (config->gconf, "/apps/evolution/mail/default_account", cur - 1, NULL);
} }
config->accounts = g_slist_remove (config->accounts, account); config->accounts = g_slist_remove (config->accounts, account);
account_destroy (account); account_destroy (account);
accounts_save ();
return config->accounts; return config->accounts;
} }
int int
mail_config_get_default_account_num (void) mail_config_get_default_account_num (void)
{ {
return config->default_account; return gconf_client_get_int (config->gconf, "/apps/evolution/mail/default_account", NULL);
}
static void
mail_config_set_default_account_num (int new_default)
{
config->default_account = new_default;
} }
void void
@ -1299,9 +1295,7 @@ mail_config_set_default_account (const MailConfigAccount *account)
if (index == -1) if (index == -1)
return; return;
config->default_account = index; gconf_client_set_int (config->gconf, "/apps/evolution/mail/default_account", index, NULL);
return;
} }
const MailConfigIdentity * const MailConfigIdentity *
@ -2028,11 +2022,11 @@ mail_config_signature_run_script (gchar *script)
filtered_stream = camel_stream_filter_new_with_stream (stream); filtered_stream = camel_stream_filter_new_with_stream (stream);
camel_object_unref (stream); camel_object_unref (stream);
/* FIXME: if the composer ever gets it's own charset setting, use that instead? */ charset = gconf_client_get_string (gconf, "/apps/evolution/mail/composer/charset", NULL);
charset = gconf_client_get_string (gconf, "/apps/evolution/mail/format/charset", NULL);
charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "utf-8"); charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "utf-8");
camel_stream_filter_add (filtered_stream, charenc); camel_stream_filter_add (filtered_stream, charenc);
camel_object_unref (charenc); camel_object_unref (charenc);
g_free (charset);
camel_stream_write_to_stream ((CamelStream *) filtered_stream, (CamelStream *) memstream); camel_stream_write_to_stream ((CamelStream *) filtered_stream, (CamelStream *) memstream);
camel_object_unref (filtered_stream); camel_object_unref (filtered_stream);