~ubuntu-branches/ubuntu/natty/evolution-data-server/natty

« back to all changes in this revision

Viewing changes to servers/exchange/storage/exchange-esource.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
 
3
 
/* Copyright (C) 2001-2004 Novell, Inc.
4
 
 *
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.
8
 
 *
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.
13
 
 *
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.
18
 
 */
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
#include <config.h>
22
 
#endif
23
 
 
24
 
#include "exchange-esource.h"
25
 
 
26
 
#include <libedataserver/e-source.h>
27
 
#include <libedataserver/e-source-list.h>
28
 
#include <libedataserver/e-source-group.h>
29
 
 
30
 
#include <stdlib.h>
31
 
#include <string.h>
32
 
 
33
 
static gboolean is_offline (void);
34
 
 
35
 
static ESourceGroup *
36
 
find_account_group (ESourceList *source_list, ExchangeAccount *exa)
37
 
{
38
 
        ESourceGroup *group;
39
 
        EAccount *account;
40
 
 
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);
44
 
 
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);
48
 
 
49
 
        group = e_source_list_peek_group_by_properties (source_list, "account-uid", account->uid, NULL);
50
 
        if (!group) {
51
 
                /* check whether is stored only with an account name - the old style */
52
 
                GSList *g;
53
 
 
54
 
                for (g = e_source_list_peek_groups (source_list); g != NULL; g = g->next) {
55
 
                        group = E_SOURCE_GROUP (g->data);
56
 
 
57
 
                        if (strcmp (e_source_group_peek_name (group), exa->account_name) == 0)
58
 
                                break;
59
 
 
60
 
                        group = NULL;
61
 
                }
62
 
 
63
 
                if (group)
64
 
                        e_source_group_set_property (group, "account-uid", account->uid);
65
 
        }
66
 
 
67
 
        return group;
68
 
}
69
 
 
70
 
void
71
 
add_folder_esource (ExchangeAccount *account,
72
 
                    FolderType folder_type,
73
 
                    const gchar *folder_name,
74
 
                    const gchar *physical_uri)
75
 
{
76
 
        ESource *source = NULL;
77
 
        ESourceGroup *source_group = NULL;
78
 
        gchar *relative_uri = NULL;
79
 
        GSList *ids;
80
 
        GConfClient *client;
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;
84
 
        gint mode;
85
 
        ESourceList *source_list = NULL;
86
 
        gboolean offline_flag, update_selection = TRUE, foriegn_folder;
87
 
 
88
 
        client = gconf_client_get_default ();
89
 
 
90
 
        /* decode the flag */
91
 
        foriegn_folder = folder_type & FORIEGN_FOLDER_FLAG;
92
 
 
93
 
        /* Unset the flag */
94
 
        folder_type = folder_type & ~FORIEGN_FOLDER_FLAG;
95
 
 
96
 
        if (folder_type == EXCHANGE_CONTACTS_FOLDER) {
97
 
                source_list = e_source_list_new_for_gconf ( client,
98
 
                                                        CONF_KEY_CONTACTS);
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));
102
 
                }
103
 
        }
104
 
        else if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
105
 
                source_list = e_source_list_new_for_gconf ( client,
106
 
                                                        CONF_KEY_CAL);
107
 
                relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX));
108
 
                is_contacts_folder = FALSE;
109
 
        }
110
 
        else if (folder_type == EXCHANGE_TASKS_FOLDER) {
111
 
                source_list = e_source_list_new_for_gconf ( client,
112
 
                                                        CONF_KEY_TASKS);
113
 
                relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX));
114
 
                is_contacts_folder = FALSE;
115
 
        }
116
 
 
117
 
        exchange_account_is_offline_sync_set (account, &mode);
118
 
 
119
 
        windows_domain =  exchange_account_get_windows_domain (account);
120
 
        if (windows_domain)
121
 
                username = g_strdup_printf ("%s\\%s", windows_domain,
122
 
                                            exchange_account_get_username (account));
123
 
        else
124
 
                username = g_strdup (exchange_account_get_username (account));
125
 
 
126
 
        useremail = exchange_account_get_email_id (account);
127
 
        authtype = exchange_account_get_authtype (account);
128
 
 
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);
137
 
                        g_free (username);
138
 
                        if (authtype)
139
 
                                g_free (authtype);
140
 
                        return;
141
 
                }
142
 
                e_source_group_set_property (source_group, "account-uid", exchange_account_fetch (account)->uid);
143
 
 
144
 
                if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://")) {
145
 
                        gchar *browse = exchange_account_get_account_uri_param (account, "ad_browse");
146
 
 
147
 
                        source = e_source_new_with_absolute_uri (folder_name,
148
 
                                                                 physical_uri);
149
 
                        e_source_set_property (source, "completion", "true");
150
 
                        e_source_set_property (source, "can-browse", browse ? "1" : NULL);
151
 
                        g_free (browse);
152
 
                }
153
 
                else {
154
 
                        source = e_source_new (folder_name, relative_uri);
155
 
                }
156
 
 
157
 
                if (mode == OFFLINE_MODE) {
158
 
                        /* If account is marked for offline sync during account
159
 
                         * creation, mark all the folders for offline sync
160
 
                         */
161
 
                        e_source_set_property (source, "offline_sync", "1");
162
 
                }
163
 
 
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);
168
 
                }
169
 
 
170
 
                e_source_set_property (source, "username", username);
171
 
                e_source_set_property (source, "auth-domain", "Exchange");
172
 
                if (authtype)
173
 
                        e_source_set_property (source, "auth-type", authtype);
174
 
                if (is_contacts_folder)
175
 
                        e_source_set_property (source, "auth", "plain/password");
176
 
                else
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;
181
 
        }
182
 
        else {
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");
188
 
 
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);
193
 
                                g_free (browse);
194
 
                        }
195
 
                        else {
196
 
                                source = e_source_new (folder_name, relative_uri);
197
 
                        }
198
 
 
199
 
                        if (mode == OFFLINE_MODE)
200
 
                                e_source_set_property (source, "offline_sync", "1");
201
 
 
202
 
                        e_source_set_property (source, "username", username);
203
 
                        e_source_set_property (source, "auth-domain", "Exchange");
204
 
                        if (authtype)
205
 
                                e_source_set_property (source, "auth-type", authtype);
206
 
                        if (is_contacts_folder)
207
 
                                e_source_set_property (source, "auth", "plain/password");
208
 
                        else
209
 
                                e_source_set_property (source, "auth", "1");
210
 
 
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);
215
 
                        }
216
 
 
217
 
                        e_source_group_add_source (source_group, source, -1);
218
 
                        source_new = TRUE;
219
 
                        e_source_list_sync (source_list, NULL);
220
 
                } else {
221
 
                        update_selection = FALSE;
222
 
                        /* source group and source both already exist */
223
 
                        offline = e_source_get_property (source, "offline_sync");
224
 
                        if (!offline) {
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);
229
 
                                }
230
 
                        }
231
 
 
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");
235
 
 
236
 
                                if ((old_browse || browse) && (!old_browse || !browse)) {
237
 
                                        e_source_set_property (source, "can-browse", browse ? "1" : NULL);
238
 
                                }
239
 
 
240
 
                                g_free (browse);
241
 
                        }
242
 
                }
243
 
        }
244
 
 
245
 
        offline_flag = is_offline ();
246
 
        if (source && !is_contacts_folder && update_selection) {
247
 
 
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);
259
 
                        g_slist_free (ids);
260
 
                }
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);
265
 
 
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);
272
 
                        g_slist_free (ids);
273
 
                }
274
 
        }
275
 
 
276
 
        g_free (relative_uri);
277
 
        g_free (username);
278
 
        if (authtype)
279
 
                g_free (authtype);
280
 
 
281
 
        if (source_new)
282
 
                g_object_unref (source);
283
 
        if (group_new)
284
 
                g_object_unref (source_group);
285
 
        g_object_unref (source_list);
286
 
        g_object_unref (client);
287
 
}
288
 
 
289
 
void
290
 
remove_folder_esource (ExchangeAccount *account,
291
 
                       FolderType folder_type,
292
 
                       const gchar *physical_uri)
293
 
{
294
 
        ESourceGroup *group;
295
 
        ESource *source;
296
 
        GSList *groups;
297
 
        GSList *sources;
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;
302
 
        GConfClient *client;
303
 
        ESourceList *source_list = NULL;
304
 
 
305
 
        client = gconf_client_get_default ();
306
 
 
307
 
        /* Remove ESource for a given folder */
308
 
        if (folder_type == EXCHANGE_CONTACTS_FOLDER) {
309
 
                source_list = e_source_list_new_for_gconf ( client,
310
 
                                                        CONF_KEY_CONTACTS);
311
 
        }
312
 
        else if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
313
 
                source_list = e_source_list_new_for_gconf ( client,
314
 
                                                        CONF_KEY_CAL);
315
 
                is_contacts_folder = FALSE;
316
 
        }
317
 
        else if (folder_type == EXCHANGE_TASKS_FOLDER) {
318
 
                source_list = e_source_list_new_for_gconf ( client,
319
 
                                                        CONF_KEY_TASKS);
320
 
                is_contacts_folder = FALSE;
321
 
        }
322
 
 
323
 
        groups = e_source_list_peek_groups (source_list);
324
 
        found_group = FALSE;
325
 
 
326
 
        for (; groups != NULL && !found_group; groups = g_slist_next (groups)) {
327
 
                group = E_SOURCE_GROUP (groups->data);
328
 
 
329
 
                if (strcmp (e_source_group_peek_name (group), account->account_name) == 0
330
 
                    &&
331
 
                   strcmp (e_source_group_peek_base_uri (group), EXCHANGE_URI_PREFIX) == 0) {
332
 
 
333
 
                        sources = e_source_group_peek_sources (group);
334
 
 
335
 
                        for (; sources != NULL; sources = g_slist_next (sources)) {
336
 
 
337
 
                                source = E_SOURCE (sources->data);
338
 
                                read_uri = e_source_get_uri (source);
339
 
 
340
 
                                if (strcmp (read_uri, physical_uri) == 0) {
341
 
 
342
 
                                        source_uid = e_source_peek_uid (source);
343
 
                                        /* Folder Deleted - Remove only the source */
344
 
                                        /*
345
 
                                        e_source_group_remove_source_by_uid (
346
 
                                                                group,
347
 
                                                                source_uid);
348
 
                                        */
349
 
                                        e_source_group_remove_source (
350
 
                                                                group,
351
 
                                                                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 (
357
 
                                                                        client,
358
 
                                                                        CONF_KEY_SELECTED_CAL_SOURCES,
359
 
                                                                        GCONF_VALUE_STRING, NULL);
360
 
                                                        if (ids) {
361
 
                                                                node_to_be_deleted = g_slist_find_custom (ids,
362
 
                                                                                        source_uid,
363
 
                                                                                        (GCompareFunc) strcmp);
364
 
                                                                if (node_to_be_deleted) {
365
 
                                                                        g_free (node_to_be_deleted->data);
366
 
                                                                        ids = g_slist_delete_link (ids,
367
 
                                                                                        node_to_be_deleted);
368
 
                                                                }
369
 
                                                        }
370
 
                                                        temp_ids  = ids;
371
 
                                                        for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids))
372
 
                                                        g_free (temp_ids->data);
373
 
                                                        g_slist_free (ids);
374
 
                                                }
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);
379
 
                                                        if (ids) {
380
 
                                                                node_to_be_deleted = g_slist_find_custom (ids,
381
 
                                                                                        source_uid,
382
 
                                                                                        (GCompareFunc) strcmp);
383
 
                                                                if (node_to_be_deleted) {
384
 
                                                                        g_free (node_to_be_deleted->data);
385
 
                                                                        ids = g_slist_delete_link (ids,
386
 
                                                                                        node_to_be_deleted);
387
 
                                                                }
388
 
                                                        }
389
 
                                                        temp_ids  = ids;
390
 
                                                        for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids))
391
 
                                                                g_free (temp_ids->data);
392
 
                                                        g_slist_free (ids);
393
 
                                                }
394
 
                                        }
395
 
                                        found_group = TRUE;
396
 
                                        break;
397
 
                                }
398
 
                                g_free (read_uri);
399
 
                        }
400
 
                }
401
 
        }
402
 
        g_object_unref (source_list);
403
 
        g_object_unref (client);
404
 
}
405
 
 
406
 
static gboolean
407
 
is_offline (void)
408
 
{
409
 
        GConfClient *client;
410
 
        GConfValue *value;
411
 
        gboolean offline = FALSE;
412
 
 
413
 
        client = gconf_client_get_default ();
414
 
        value = gconf_client_get (client,
415
 
                                        "/apps/evolution/shell/start_offline", NULL);
416
 
        if (value)
417
 
                offline = gconf_value_get_bool (value);
418
 
 
419
 
        g_object_unref (client);
420
 
        gconf_value_free (value);
421
 
        return offline;
422
 
}