Updated Spanish translation
[evolution.git] / libemail-engine / mail-config.c
blob09f0332567f248ae23aaf283861af92994427311
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 * Authors:
17 * Jeffrey Stedfast <fejj@ximian.com>
18 * Radek Doulik <rodo@ximian.com>
19 * Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>
21 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22 * Copyright (C) 2009 Intel Corporation
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
30 #include <gtk/gtk.h>
32 #include <libedataserver/e-data-server-util.h>
34 #include <libemail-utils/e-account-utils.h>
35 #include <libemail-utils/e-signature-utils.h>
37 #include "e-mail-folder-utils.h"
38 #include "mail-config.h"
39 #include "mail-tools.h"
41 typedef struct {
42 GSList *labels;
44 gboolean address_compress;
45 gint address_count;
47 GSList *jh_header;
48 gboolean jh_check;
49 gboolean book_lookup;
50 gboolean book_lookup_local_only;
51 } MailConfig;
53 extern gint camel_header_param_encode_filenames_in_rfc_2047;
55 static MailConfig *config = NULL;
56 static GSettings *mail_settings = NULL;
58 static void
59 settings_outlook_filenames_changed (GSettings *settings,
60 const gchar *key,
61 gpointer user_data)
63 /* pass option to the camel */
64 if (g_settings_get_boolean (settings, key))
65 camel_header_param_encode_filenames_in_rfc_2047 = 1;
66 else
67 camel_header_param_encode_filenames_in_rfc_2047 = 0;
70 static void
71 settings_jh_headers_changed (GSettings *settings,
72 const gchar *key,
73 EMailSession *session)
75 GSList *node;
76 GPtrArray *name, *value;
77 gchar **strv;
78 gint i;
80 g_slist_foreach (config->jh_header, (GFunc) g_free, NULL);
81 g_slist_free (config->jh_header);
82 config->jh_header = NULL;
84 strv = g_settings_get_strv (settings, "junk-custom-header");
85 for (i = 0; strv[i] != NULL; i++)
86 config->jh_header = g_slist_append (config->jh_header, g_strdup (strv[i]));
87 g_strfreev (strv);
89 node = config->jh_header;
90 name = g_ptr_array_new ();
91 value = g_ptr_array_new ();
92 while (node && node->data) {
93 gchar **tok = g_strsplit (node->data, "=", 2);
94 g_ptr_array_add (name, g_strdup (tok[0]));
95 g_ptr_array_add (value, g_strdup (tok[1]));
96 node = node->next;
97 g_strfreev (tok);
99 camel_session_set_junk_headers (
100 CAMEL_SESSION (session),
101 (const gchar **) name->pdata,
102 (const gchar **) value->pdata, name->len);
104 g_ptr_array_foreach (name, (GFunc) g_free, NULL);
105 g_ptr_array_foreach (value, (GFunc) g_free, NULL);
106 g_ptr_array_free (name, TRUE);
107 g_ptr_array_free (value, TRUE);
110 static void
111 settings_jh_check_changed (GSettings *settings,
112 const gchar *key,
113 EMailSession *session)
115 config->jh_check = g_settings_get_boolean (settings, "junk-check-custom-header");
116 if (!config->jh_check) {
117 camel_session_set_junk_headers (
118 CAMEL_SESSION (session), NULL, NULL, 0);
119 } else {
120 settings_jh_headers_changed (settings, NULL, session);
124 static void
125 settings_bool_value_changed (GSettings *settings,
126 const gchar *key,
127 gboolean *save_location)
129 *save_location = g_settings_get_boolean (settings, key);
132 static void
133 settings_int_value_changed (GSettings *settings,
134 const gchar *key,
135 gint *save_location)
137 *save_location = g_settings_get_int (settings, key);
140 void
141 mail_config_write (void)
143 EAccountList *account_list;
144 ESignatureList *signature_list;
146 if (!config)
147 return;
149 account_list = e_get_account_list ();
150 signature_list = e_get_signature_list ();
152 e_account_list_save (account_list);
153 e_signature_list_save (signature_list);
155 g_settings_sync ();
158 gint
159 mail_config_get_address_count (void)
161 if (!config->address_compress)
162 return -1;
164 return config->address_count;
167 /* timeout interval, in seconds, when to call server update */
168 gint
169 mail_config_get_sync_timeout (void)
171 gint res = 60;
173 res = g_settings_get_int (mail_settings, "sync-interval");
175 /* do not allow recheck sooner than every 30 seconds */
176 if (res == 0)
177 res = 60;
178 else if (res < 30)
179 res = 30;
181 return res;
184 gchar *
185 mail_config_folder_to_cachename (CamelFolder *folder,
186 const gchar *prefix)
188 gchar *folder_uri, *basename, *filename;
189 const gchar *config_dir;
191 config_dir = mail_session_get_config_dir ();
193 basename = g_build_filename (config_dir, "folders", NULL);
194 if (!g_file_test (basename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
195 /* create the folder if does not exist */
196 g_mkdir_with_parents (basename, 0700);
198 g_free (basename);
200 folder_uri = e_mail_folder_uri_from_folder (folder);
201 e_filename_make_safe (folder_uri);
202 basename = g_strdup_printf ("%s%s", prefix, folder_uri);
203 filename = g_build_filename (config_dir, "folders", basename, NULL);
204 g_free (basename);
205 g_free (folder_uri);
207 return filename;
210 void
211 mail_config_reload_junk_headers (EMailSession *session)
213 g_return_if_fail (E_IS_MAIL_SESSION (session));
215 /* It automatically sets in the session */
216 if (config == NULL)
217 mail_config_init (session);
218 else {
219 settings_jh_check_changed (mail_settings, NULL, session);
223 gboolean
224 mail_config_get_lookup_book (void)
226 g_return_val_if_fail (config != NULL, FALSE);
228 return config->book_lookup;
231 gboolean
232 mail_config_get_lookup_book_local_only (void)
234 g_return_val_if_fail (config != NULL, FALSE);
236 return config->book_lookup_local_only;
239 /* Config struct routines */
240 void
241 mail_config_init (EMailSession *session)
243 g_return_if_fail (E_IS_MAIL_SESSION (session));
245 if (config)
246 return;
248 config = g_new0 (MailConfig, 1);
250 mail_settings = g_settings_new ("org.gnome.evolution.mail");
252 /* Composer Configuration */
254 settings_outlook_filenames_changed (
255 mail_settings, "composer-outlook-filenames", NULL);
256 g_signal_connect (
257 mail_settings, "changed::composer-outlook-filenames",
258 G_CALLBACK (settings_outlook_filenames_changed), NULL);
260 /* Display Configuration */
262 g_signal_connect (
263 mail_settings, "changed::address-compress",
264 G_CALLBACK (settings_bool_value_changed),
265 &config->address_compress);
266 config->address_compress = g_settings_get_boolean (
267 mail_settings, "address-compress");
269 g_signal_connect (
270 mail_settings, "changed::address-count",
271 G_CALLBACK (settings_int_value_changed),
272 &config->address_count);
273 config->address_count = g_settings_get_int (
274 mail_settings, "address-count");
276 /* Junk Configuration */
278 g_signal_connect (
279 mail_settings, "changed::junk-check-custom-header",
280 G_CALLBACK (settings_jh_check_changed), session);
281 config->jh_check = g_settings_get_boolean (
282 mail_settings, "junk-check-custom-header");
284 g_signal_connect (
285 mail_settings, "changed::junk-custom-header",
286 G_CALLBACK (settings_jh_headers_changed), session);
288 g_signal_connect (
289 mail_settings, "changed::junk-lookup-addressbook",
290 G_CALLBACK (settings_bool_value_changed), &config->book_lookup);
291 config->book_lookup = g_settings_get_boolean (
292 mail_settings, "junk-lookup-addressbook");
294 g_signal_connect (
295 mail_settings, "changed::junk-lookup-addressbook-local-only",
296 G_CALLBACK (settings_bool_value_changed),
297 &config->book_lookup_local_only);
298 config->book_lookup_local_only = g_settings_get_boolean (
299 mail_settings, "junk-lookup-addressbook-local-only");
301 settings_jh_check_changed (mail_settings, NULL, session);