1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
/* Copyright (C) 2001-2004 Novell, Inc.
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of version 2 of the GNU Lesser General Public
7
* License as published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
24
#include "exchange-esource.h"
26
#include <libedataserver/e-source.h>
27
#include <libedataserver/e-source-list.h>
28
#include <libedataserver/e-source-group.h>
33
static gboolean is_offline (void);
36
find_account_group (ESourceList *source_list, ExchangeAccount *exa)
41
g_return_val_if_fail (exa != NULL, NULL);
42
g_return_val_if_fail (exa->account_name != NULL, NULL);
43
g_return_val_if_fail (source_list != NULL, NULL);
45
account = exchange_account_fetch (exa);
46
g_return_val_if_fail (account != NULL, NULL);
47
g_return_val_if_fail (account->uid != NULL, NULL);
49
group = e_source_list_peek_group_by_properties (source_list, "account-uid", account->uid, NULL);
51
/* check whether is stored only with an account name - the old style */
54
for (g = e_source_list_peek_groups (source_list); g != NULL; g = g->next) {
55
group = E_SOURCE_GROUP (g->data);
57
if (strcmp (e_source_group_peek_name (group), exa->account_name) == 0)
64
e_source_group_set_property (group, "account-uid", account->uid);
71
add_folder_esource (ExchangeAccount *account,
72
FolderType folder_type,
73
const gchar *folder_name,
74
const gchar *physical_uri)
76
ESource *source = NULL;
77
ESourceGroup *source_group = NULL;
78
gchar *relative_uri = NULL;
81
gboolean is_contacts_folder = TRUE, group_new = FALSE, source_new = FALSE;
82
const gchar *offline = NULL;
83
gchar *username, *windows_domain, *useremail, *authtype = NULL;
85
ESourceList *source_list = NULL;
86
gboolean offline_flag, update_selection = TRUE, foriegn_folder;
88
client = gconf_client_get_default ();
91
foriegn_folder = folder_type & FORIEGN_FOLDER_FLAG;
94
folder_type = folder_type & ~FORIEGN_FOLDER_FLAG;
96
if (folder_type == EXCHANGE_CONTACTS_FOLDER) {
97
source_list = e_source_list_new_for_gconf ( client,
99
/* Modify the URI handling of Contacts to the same way as calendar and tasks */
100
if (!g_str_has_prefix (physical_uri, "gal://")) {
101
relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX));
104
else if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
105
source_list = e_source_list_new_for_gconf ( client,
107
relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX));
108
is_contacts_folder = FALSE;
110
else if (folder_type == EXCHANGE_TASKS_FOLDER) {
111
source_list = e_source_list_new_for_gconf ( client,
113
relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX));
114
is_contacts_folder = FALSE;
117
exchange_account_is_offline_sync_set (account, &mode);
119
windows_domain = exchange_account_get_windows_domain (account);
121
username = g_strdup_printf ("%s\\%s", windows_domain,
122
exchange_account_get_username (account));
124
username = g_strdup (exchange_account_get_username (account));
126
useremail = exchange_account_get_email_id (account);
127
authtype = exchange_account_get_authtype (account);
129
if ((source_group = find_account_group (source_list, account)) == NULL) {
130
source_group = e_source_group_new (account->account_name,
131
EXCHANGE_URI_PREFIX);
132
if (!e_source_list_add_group (source_list, source_group, -1)) {
133
g_object_unref (source_list);
134
g_object_unref (source_group);
135
g_object_unref (client);
136
g_free (relative_uri);
142
e_source_group_set_property (source_group, "account-uid", exchange_account_fetch (account)->uid);
144
if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://")) {
145
gchar *browse = exchange_account_get_account_uri_param (account, "ad_browse");
147
source = e_source_new_with_absolute_uri (folder_name,
149
e_source_set_property (source, "completion", "true");
150
e_source_set_property (source, "can-browse", browse ? "1" : NULL);
154
source = e_source_new (folder_name, relative_uri);
157
if (mode == OFFLINE_MODE) {
158
/* If account is marked for offline sync during account
159
* creation, mark all the folders for offline sync
161
e_source_set_property (source, "offline_sync", "1");
164
if (foriegn_folder && (folder_type != EXCHANGE_CONTACTS_FOLDER)) {
165
e_source_set_property (source, "alarm", "false");
166
e_source_set_property (source, "foreign", "1");
167
e_source_set_property (source, "subscriber", useremail);
170
e_source_set_property (source, "username", username);
171
e_source_set_property (source, "auth-domain", "Exchange");
173
e_source_set_property (source, "auth-type", authtype);
174
if (is_contacts_folder)
175
e_source_set_property (source, "auth", "plain/password");
177
e_source_set_property (source, "auth", "1");
178
e_source_group_add_source (source_group, source, -1);
179
e_source_list_sync (source_list, NULL);
180
group_new = source_new = TRUE;
183
/* source group already exists*/
184
if ((source = e_source_group_peek_source_by_name (source_group,
185
folder_name)) == NULL) {
186
if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://")) {
187
gchar *browse = exchange_account_get_account_uri_param (account, "ad_browse");
189
source = e_source_new_with_absolute_uri (
190
folder_name, physical_uri);
191
e_source_set_property (source, "completion", "true");
192
e_source_set_property (source, "can-browse", browse ? "1" : NULL);
196
source = e_source_new (folder_name, relative_uri);
199
if (mode == OFFLINE_MODE)
200
e_source_set_property (source, "offline_sync", "1");
202
e_source_set_property (source, "username", username);
203
e_source_set_property (source, "auth-domain", "Exchange");
205
e_source_set_property (source, "auth-type", authtype);
206
if (is_contacts_folder)
207
e_source_set_property (source, "auth", "plain/password");
209
e_source_set_property (source, "auth", "1");
211
if (foriegn_folder && (folder_type != EXCHANGE_CONTACTS_FOLDER)) {
212
e_source_set_property (source, "alarm", "false");
213
e_source_set_property (source, "foreign", "1");
214
e_source_set_property (source, "subscriber", useremail);
217
e_source_group_add_source (source_group, source, -1);
219
e_source_list_sync (source_list, NULL);
221
update_selection = FALSE;
222
/* source group and source both already exist */
223
offline = e_source_get_property (source, "offline_sync");
225
/* Folder doesn't have any offline property set */
226
if (mode == OFFLINE_MODE) {
227
e_source_set_property (source, "offline_sync", "1");
228
e_source_list_sync (source_list, NULL);
232
if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://")) {
233
gchar *browse = exchange_account_get_account_uri_param (account, "ad_browse");
234
const gchar *old_browse = e_source_get_property (source, "can-browse");
236
if ((old_browse || browse) && (!old_browse || !browse)) {
237
e_source_set_property (source, "can-browse", browse ? "1" : NULL);
245
offline_flag = is_offline ();
246
if (source && !is_contacts_folder && update_selection) {
248
/* Select the folder created */
249
if (folder_type == EXCHANGE_CALENDAR_FOLDER && !offline_flag) {
250
ids = gconf_client_get_list (client,
251
CONF_KEY_SELECTED_CAL_SOURCES,
252
GCONF_VALUE_STRING, NULL);
253
ids = g_slist_append (ids,
254
g_strdup (e_source_peek_uid (source)));
255
gconf_client_set_list (client,
256
CONF_KEY_SELECTED_CAL_SOURCES,
257
GCONF_VALUE_STRING, ids, NULL);
258
g_slist_foreach (ids, (GFunc) g_free, NULL);
261
else if (folder_type == EXCHANGE_TASKS_FOLDER && !offline_flag) {
262
ids = gconf_client_get_list (client,
263
CONF_KEY_SELECTED_TASKS_SOURCES,
264
GCONF_VALUE_STRING, NULL);
266
ids = g_slist_append (ids,
267
g_strdup (e_source_peek_uid (source)));
268
gconf_client_set_list (client,
269
CONF_KEY_SELECTED_TASKS_SOURCES,
270
GCONF_VALUE_STRING, ids, NULL);
271
g_slist_foreach (ids, (GFunc) g_free, NULL);
276
g_free (relative_uri);
282
g_object_unref (source);
284
g_object_unref (source_group);
285
g_object_unref (source_list);
286
g_object_unref (client);
290
remove_folder_esource (ExchangeAccount *account,
291
FolderType folder_type,
292
const gchar *physical_uri)
298
gboolean found_group, is_contacts_folder = TRUE;
299
gchar *read_uri = NULL;
300
const gchar *source_uid;
301
GSList *ids, *temp_ids, *node_to_be_deleted;
303
ESourceList *source_list = NULL;
305
client = gconf_client_get_default ();
307
/* Remove ESource for a given folder */
308
if (folder_type == EXCHANGE_CONTACTS_FOLDER) {
309
source_list = e_source_list_new_for_gconf ( client,
312
else if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
313
source_list = e_source_list_new_for_gconf ( client,
315
is_contacts_folder = FALSE;
317
else if (folder_type == EXCHANGE_TASKS_FOLDER) {
318
source_list = e_source_list_new_for_gconf ( client,
320
is_contacts_folder = FALSE;
323
groups = e_source_list_peek_groups (source_list);
326
for (; groups != NULL && !found_group; groups = g_slist_next (groups)) {
327
group = E_SOURCE_GROUP (groups->data);
329
if (strcmp (e_source_group_peek_name (group), account->account_name) == 0
331
strcmp (e_source_group_peek_base_uri (group), EXCHANGE_URI_PREFIX) == 0) {
333
sources = e_source_group_peek_sources (group);
335
for (; sources != NULL; sources = g_slist_next (sources)) {
337
source = E_SOURCE (sources->data);
338
read_uri = e_source_get_uri (source);
340
if (strcmp (read_uri, physical_uri) == 0) {
342
source_uid = e_source_peek_uid (source);
343
/* Folder Deleted - Remove only the source */
345
e_source_group_remove_source_by_uid (
349
e_source_group_remove_source (
352
e_source_list_sync (source_list, NULL);
353
if (!is_contacts_folder) {
354
/* Remove from the selected folders */
355
if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
356
ids = gconf_client_get_list (
358
CONF_KEY_SELECTED_CAL_SOURCES,
359
GCONF_VALUE_STRING, NULL);
361
node_to_be_deleted = g_slist_find_custom (ids,
363
(GCompareFunc) strcmp);
364
if (node_to_be_deleted) {
365
g_free (node_to_be_deleted->data);
366
ids = g_slist_delete_link (ids,
371
for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids))
372
g_free (temp_ids->data);
375
else if (folder_type == EXCHANGE_TASKS_FOLDER) {
376
ids = gconf_client_get_list (client,
377
CONF_KEY_SELECTED_TASKS_SOURCES,
378
GCONF_VALUE_STRING, NULL);
380
node_to_be_deleted = g_slist_find_custom (ids,
382
(GCompareFunc) strcmp);
383
if (node_to_be_deleted) {
384
g_free (node_to_be_deleted->data);
385
ids = g_slist_delete_link (ids,
390
for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids))
391
g_free (temp_ids->data);
402
g_object_unref (source_list);
403
g_object_unref (client);
411
gboolean offline = FALSE;
413
client = gconf_client_get_default ();
414
value = gconf_client_get (client,
415
"/apps/evolution/shell/start_offline", NULL);
417
offline = gconf_value_get_bool (value);
419
g_object_unref (client);
420
gconf_value_free (value);