~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to servers/exchange/storage/exchange-hierarchy.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) 2002-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
 
/* ExchangeHierarchy: abstract class for a hierarchy of folders
21
 
 * in an Exchange storage. Subclasses of ExchangeHierarchy implement
22
 
 * normal WebDAV hierarchies, the GAL hierarchy, and hierarchies
23
 
 * of individually-selected other users' folders.
24
 
 */
25
 
 
26
 
#ifdef HAVE_CONFIG_H
27
 
#include <config.h>
28
 
#endif
29
 
 
30
 
#include "exchange-hierarchy.h"
31
 
#include "e-folder-exchange.h"
32
 
 
33
 
enum {
34
 
        NEW_FOLDER,
35
 
        REMOVED_FOLDER,
36
 
        LAST_SIGNAL
37
 
};
38
 
 
39
 
static guint signals [LAST_SIGNAL] = { 0 };
40
 
 
41
 
#define PARENT_TYPE G_TYPE_OBJECT
42
 
static GObjectClass *parent_class = NULL;
43
 
 
44
 
#define HIER_CLASS(hier) (EXCHANGE_HIERARCHY_CLASS (G_OBJECT_GET_CLASS (hier)))
45
 
 
46
 
static void dispose (GObject *object);
47
 
static void finalize (GObject *object);
48
 
static gboolean is_empty        (ExchangeHierarchy *hier);
49
 
static void add_to_storage      (ExchangeHierarchy *hier);
50
 
static ExchangeAccountFolderResult scan_subtree  (ExchangeHierarchy *hier,
51
 
                                                  EFolder *folder,
52
 
                                                  gint mode);
53
 
static void                        rescan        (ExchangeHierarchy *hier);
54
 
static ExchangeAccountFolderResult create_folder (ExchangeHierarchy *hier,
55
 
                                                  EFolder *parent,
56
 
                                                  const gchar *name,
57
 
                                                  const gchar *type);
58
 
static ExchangeAccountFolderResult remove_folder (ExchangeHierarchy *hier,
59
 
                                                  EFolder *folder);
60
 
static ExchangeAccountFolderResult xfer_folder   (ExchangeHierarchy *hier,
61
 
                                                  EFolder *source,
62
 
                                                  EFolder *dest_parent,
63
 
                                                  const gchar *dest_name,
64
 
                                                  gboolean remove_source);
65
 
 
66
 
static void
67
 
class_init (GObjectClass *object_class)
68
 
{
69
 
        ExchangeHierarchyClass *exchange_hierarchy_class =
70
 
                EXCHANGE_HIERARCHY_CLASS (object_class);
71
 
 
72
 
        parent_class = g_type_class_ref (PARENT_TYPE);
73
 
 
74
 
        /* methods */
75
 
        object_class->dispose = dispose;
76
 
        object_class->finalize = finalize;
77
 
 
78
 
        exchange_hierarchy_class->is_empty = is_empty;
79
 
        exchange_hierarchy_class->add_to_storage = add_to_storage;
80
 
        exchange_hierarchy_class->rescan = rescan;
81
 
        exchange_hierarchy_class->scan_subtree = scan_subtree;
82
 
        exchange_hierarchy_class->create_folder = create_folder;
83
 
        exchange_hierarchy_class->remove_folder = remove_folder;
84
 
        exchange_hierarchy_class->xfer_folder = xfer_folder;
85
 
 
86
 
        /* signals */
87
 
        signals[NEW_FOLDER] =
88
 
                g_signal_new ("new_folder",
89
 
                              G_OBJECT_CLASS_TYPE (object_class),
90
 
                              G_SIGNAL_RUN_LAST,
91
 
                              G_STRUCT_OFFSET (ExchangeHierarchyClass, new_folder),
92
 
                              NULL, NULL,
93
 
                              g_cclosure_marshal_VOID__POINTER,
94
 
                              G_TYPE_NONE, 1,
95
 
                              G_TYPE_POINTER);
96
 
        signals[REMOVED_FOLDER] =
97
 
                g_signal_new ("removed_folder",
98
 
                              G_OBJECT_CLASS_TYPE (object_class),
99
 
                              G_SIGNAL_RUN_LAST,
100
 
                              G_STRUCT_OFFSET (ExchangeHierarchyClass, removed_folder),
101
 
                              NULL, NULL,
102
 
                              g_cclosure_marshal_VOID__POINTER,
103
 
                              G_TYPE_NONE, 1,
104
 
                              G_TYPE_POINTER);
105
 
}
106
 
 
107
 
static void
108
 
dispose (GObject *object)
109
 
{
110
 
        ExchangeHierarchy *hier = EXCHANGE_HIERARCHY (object);
111
 
 
112
 
        if (hier->toplevel) {
113
 
                g_object_unref (hier->toplevel);
114
 
                hier->toplevel = NULL;
115
 
        }
116
 
 
117
 
        G_OBJECT_CLASS (parent_class)->dispose (object);
118
 
}
119
 
 
120
 
static void
121
 
finalize (GObject *object)
122
 
{
123
 
        ExchangeHierarchy *hier = EXCHANGE_HIERARCHY (object);
124
 
 
125
 
        g_free (hier->owner_name);
126
 
        g_free (hier->owner_email);
127
 
        g_free (hier->source_uri);
128
 
 
129
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
130
 
}
131
 
 
132
 
E2K_MAKE_TYPE (exchange_hierarchy, ExchangeHierarchy, class_init, NULL, PARENT_TYPE)
133
 
 
134
 
/**
135
 
 * exchange_hierarchy_new_folder:
136
 
 * @hier: the hierarchy
137
 
 * @folder: the new folder
138
 
 *
139
 
 * Emits a %new_folder signal.
140
 
 **/
141
 
void
142
 
exchange_hierarchy_new_folder (ExchangeHierarchy *hier,
143
 
                               EFolder *folder)
144
 
{
145
 
        g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
146
 
        g_return_if_fail (E_IS_FOLDER (folder));
147
 
 
148
 
        g_signal_emit (hier, signals[NEW_FOLDER], 0, folder);
149
 
}
150
 
 
151
 
/**
152
 
 * exchange_hierarchy_removed_folder:
153
 
 * @hier: the hierarchy
154
 
 * @folder: the (about-to-be-)removed folder
155
 
 *
156
 
 * Emits a %removed_folder signal.
157
 
 **/
158
 
void
159
 
exchange_hierarchy_removed_folder (ExchangeHierarchy *hier,
160
 
                                   EFolder *folder)
161
 
{
162
 
        g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
163
 
        g_return_if_fail (E_IS_FOLDER (folder));
164
 
 
165
 
        g_signal_emit (hier, signals[REMOVED_FOLDER], 0, folder);
166
 
}
167
 
 
168
 
static gboolean
169
 
is_empty (ExchangeHierarchy *hier)
170
 
{
171
 
        return FALSE;
172
 
}
173
 
 
174
 
gboolean
175
 
exchange_hierarchy_is_empty (ExchangeHierarchy *hier)
176
 
{
177
 
        g_return_val_if_fail (EXCHANGE_IS_HIERARCHY (hier), TRUE);
178
 
 
179
 
        return HIER_CLASS (hier)->is_empty (hier);
180
 
}
181
 
 
182
 
static ExchangeAccountFolderResult
183
 
create_folder (ExchangeHierarchy *hier, EFolder *parent,
184
 
               const gchar *name, const gchar *type)
185
 
{
186
 
        return EXCHANGE_ACCOUNT_FOLDER_PERMISSION_DENIED;
187
 
}
188
 
 
189
 
static ExchangeAccountFolderResult
190
 
remove_folder (ExchangeHierarchy *hier, EFolder *folder)
191
 
{
192
 
        return EXCHANGE_ACCOUNT_FOLDER_PERMISSION_DENIED;
193
 
}
194
 
 
195
 
static ExchangeAccountFolderResult
196
 
xfer_folder (ExchangeHierarchy *hier, EFolder *source,
197
 
             EFolder *dest_parent, const gchar *dest_name,
198
 
             gboolean remove_source)
199
 
{
200
 
        return EXCHANGE_ACCOUNT_FOLDER_PERMISSION_DENIED;
201
 
}
202
 
 
203
 
/**
204
 
 * exchange_hierarchy_create_folder:
205
 
 * @hier: the hierarchy
206
 
 * @parent: the parent folder of the new folder
207
 
 * @name: name of the new folder (UTF8)
208
 
 * @type: Evolution folder type of the new folder
209
 
 *
210
 
 * Attempts to create a new folder.
211
 
 *
212
 
 * Return value: the result code
213
 
 **/
214
 
ExchangeAccountFolderResult
215
 
exchange_hierarchy_create_folder (ExchangeHierarchy *hier, EFolder *parent,
216
 
                                  const gchar *name, const gchar *type)
217
 
{
218
 
        g_return_val_if_fail (EXCHANGE_IS_HIERARCHY (hier), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
219
 
        g_return_val_if_fail (E_IS_FOLDER (parent), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
220
 
        g_return_val_if_fail (name != NULL, EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
221
 
        g_return_val_if_fail (type != NULL, EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
222
 
 
223
 
        return HIER_CLASS (hier)->create_folder (hier, parent, name, type);
224
 
}
225
 
 
226
 
/**
227
 
 * exchange_hierarchy_remove_folder:
228
 
 * @hier: the hierarchy
229
 
 * @folder: the folder to remove
230
 
 *
231
 
 * Attempts to remove a folder.
232
 
 *
233
 
 * Return value: the result code
234
 
 **/
235
 
ExchangeAccountFolderResult
236
 
exchange_hierarchy_remove_folder (ExchangeHierarchy *hier, EFolder *folder)
237
 
{
238
 
        g_return_val_if_fail (EXCHANGE_IS_HIERARCHY (hier), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
239
 
        g_return_val_if_fail (E_IS_FOLDER (folder), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
240
 
 
241
 
        return HIER_CLASS (hier)->remove_folder (hier, folder);
242
 
}
243
 
 
244
 
/**
245
 
 * exchange_hierarchy_xfer_folder:
246
 
 * @hier: the hierarchy
247
 
 * @source: the source folder
248
 
 * @dest_parent: the parent of the destination folder
249
 
 * @dest_name: name of the destination (UTF8)
250
 
 * @remove_source: %TRUE if this is a move, %FALSE if it is a copy
251
 
 *
252
 
 * Attempts to move or copy a folder.
253
 
 *
254
 
 * Return value: the result code
255
 
 **/
256
 
ExchangeAccountFolderResult
257
 
exchange_hierarchy_xfer_folder (ExchangeHierarchy *hier, EFolder *source,
258
 
                                EFolder *dest_parent, const gchar *dest_name,
259
 
                                gboolean remove_source)
260
 
{
261
 
        g_return_val_if_fail (EXCHANGE_IS_HIERARCHY (hier), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
262
 
        g_return_val_if_fail (E_IS_FOLDER (source), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
263
 
        g_return_val_if_fail (E_IS_FOLDER (dest_parent), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
264
 
        g_return_val_if_fail (dest_name != NULL, EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
265
 
 
266
 
        return HIER_CLASS (hier)->xfer_folder (hier, source,
267
 
                                               dest_parent, dest_name,
268
 
                                               remove_source);
269
 
}
270
 
 
271
 
static void
272
 
rescan (ExchangeHierarchy *hier)
273
 
{
274
 
        ;
275
 
}
276
 
 
277
 
/**
278
 
 * exchange_hierarchy_rescan:
279
 
 * @hier: the hierarchy
280
 
 *
281
 
 * Tells the hierarchy to rescan its folder tree
282
 
 **/
283
 
void
284
 
exchange_hierarchy_rescan (ExchangeHierarchy *hier)
285
 
{
286
 
        g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
287
 
 
288
 
        HIER_CLASS (hier)->rescan (hier);
289
 
}
290
 
 
291
 
static ExchangeAccountFolderResult
292
 
scan_subtree (ExchangeHierarchy *hier, EFolder *folder, gint mode)
293
 
{
294
 
        return EXCHANGE_ACCOUNT_FOLDER_OK;
295
 
}
296
 
 
297
 
/**
298
 
 * exchange_hierarchy_scan_subtree:
299
 
 * @hier: the hierarchy
300
 
 * @folder: the folder to scan under
301
 
 *
302
 
 * Scans for folders in @hier underneath @folder, emitting %new_folder
303
 
 * signals for each one found. Depending on the kind of hierarchy,
304
 
 * this may initiate a recursive scan.
305
 
 *
306
 
 * Return value: the result code
307
 
 **/
308
 
ExchangeAccountFolderResult
309
 
exchange_hierarchy_scan_subtree (ExchangeHierarchy *hier, EFolder *folder, gint mode)
310
 
{
311
 
        g_return_val_if_fail (EXCHANGE_IS_HIERARCHY (hier), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
312
 
        g_return_val_if_fail (E_IS_FOLDER (folder), EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR);
313
 
 
314
 
        return HIER_CLASS (hier)->scan_subtree (hier, folder, mode);
315
 
}
316
 
 
317
 
static void
318
 
add_to_storage (ExchangeHierarchy *hier)
319
 
{
320
 
        e_folder_set_sorting_priority (hier->toplevel, hier->type);
321
 
        exchange_hierarchy_new_folder (hier, hier->toplevel);
322
 
}
323
 
 
324
 
/**
325
 
 * exchange_hierarchy_add_to_storage:
326
 
 * @hier: the hierarchy
327
 
 *
328
 
 * Tells the hierarchy to fill in its folder tree, emitting %new_folder
329
 
 * signals as appropriate.
330
 
 **/
331
 
void
332
 
exchange_hierarchy_add_to_storage (ExchangeHierarchy *hier)
333
 
{
334
 
        g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
335
 
 
336
 
        HIER_CLASS (hier)->add_to_storage (hier);
337
 
}
338
 
 
339
 
/**
340
 
 * exchange_hierarchy_construct:
341
 
 * @hier: the hierarchy
342
 
 * @account: the hierarchy's account
343
 
 * @type: the type of hierarchy
344
 
 * @toplevel: the top-level folder of the hierarchy
345
 
 * @owner_name: the display name of the owner of this hierarchy
346
 
 * @owner_email: the email address of the owner of this hierarchy
347
 
 * @source_uri: the evolution-mail source URI of this hierarchy.
348
 
 *
349
 
 * Constructs the hierarchy. @owner_name, @owner_email, and @source_uri
350
 
 * can be %NULL if not relevant to this hierarchy.
351
 
 **/
352
 
void
353
 
exchange_hierarchy_construct (ExchangeHierarchy *hier,
354
 
                              ExchangeAccount *account,
355
 
                              ExchangeHierarchyType type,
356
 
                              EFolder *toplevel,
357
 
                              const gchar *owner_name,
358
 
                              const gchar *owner_email,
359
 
                              const gchar *source_uri)
360
 
{
361
 
        g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
362
 
        g_return_if_fail (EXCHANGE_IS_ACCOUNT (account));
363
 
        g_return_if_fail (E_IS_FOLDER (toplevel));
364
 
 
365
 
        /* We don't ref the account since we'll be destroyed when
366
 
         * the account is
367
 
         */
368
 
        hier->account = account;
369
 
 
370
 
        hier->toplevel = toplevel;
371
 
        g_object_ref (toplevel);
372
 
 
373
 
        hier->type = type;
374
 
        hier->owner_name = g_strdup (owner_name);
375
 
        hier->owner_email = g_strdup (owner_email);
376
 
        hier->source_uri = g_strdup (source_uri);
377
 
}