1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
/* Copyright (C) 2002-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.
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.
30
#include "exchange-hierarchy.h"
31
#include "e-folder-exchange.h"
39
static guint signals [LAST_SIGNAL] = { 0 };
41
#define PARENT_TYPE G_TYPE_OBJECT
42
static GObjectClass *parent_class = NULL;
44
#define HIER_CLASS(hier) (EXCHANGE_HIERARCHY_CLASS (G_OBJECT_GET_CLASS (hier)))
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,
53
static void rescan (ExchangeHierarchy *hier);
54
static ExchangeAccountFolderResult create_folder (ExchangeHierarchy *hier,
58
static ExchangeAccountFolderResult remove_folder (ExchangeHierarchy *hier,
60
static ExchangeAccountFolderResult xfer_folder (ExchangeHierarchy *hier,
63
const gchar *dest_name,
64
gboolean remove_source);
67
class_init (GObjectClass *object_class)
69
ExchangeHierarchyClass *exchange_hierarchy_class =
70
EXCHANGE_HIERARCHY_CLASS (object_class);
72
parent_class = g_type_class_ref (PARENT_TYPE);
75
object_class->dispose = dispose;
76
object_class->finalize = finalize;
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;
88
g_signal_new ("new_folder",
89
G_OBJECT_CLASS_TYPE (object_class),
91
G_STRUCT_OFFSET (ExchangeHierarchyClass, new_folder),
93
g_cclosure_marshal_VOID__POINTER,
96
signals[REMOVED_FOLDER] =
97
g_signal_new ("removed_folder",
98
G_OBJECT_CLASS_TYPE (object_class),
100
G_STRUCT_OFFSET (ExchangeHierarchyClass, removed_folder),
102
g_cclosure_marshal_VOID__POINTER,
108
dispose (GObject *object)
110
ExchangeHierarchy *hier = EXCHANGE_HIERARCHY (object);
112
if (hier->toplevel) {
113
g_object_unref (hier->toplevel);
114
hier->toplevel = NULL;
117
G_OBJECT_CLASS (parent_class)->dispose (object);
121
finalize (GObject *object)
123
ExchangeHierarchy *hier = EXCHANGE_HIERARCHY (object);
125
g_free (hier->owner_name);
126
g_free (hier->owner_email);
127
g_free (hier->source_uri);
129
G_OBJECT_CLASS (parent_class)->finalize (object);
132
E2K_MAKE_TYPE (exchange_hierarchy, ExchangeHierarchy, class_init, NULL, PARENT_TYPE)
135
* exchange_hierarchy_new_folder:
136
* @hier: the hierarchy
137
* @folder: the new folder
139
* Emits a %new_folder signal.
142
exchange_hierarchy_new_folder (ExchangeHierarchy *hier,
145
g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
146
g_return_if_fail (E_IS_FOLDER (folder));
148
g_signal_emit (hier, signals[NEW_FOLDER], 0, folder);
152
* exchange_hierarchy_removed_folder:
153
* @hier: the hierarchy
154
* @folder: the (about-to-be-)removed folder
156
* Emits a %removed_folder signal.
159
exchange_hierarchy_removed_folder (ExchangeHierarchy *hier,
162
g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
163
g_return_if_fail (E_IS_FOLDER (folder));
165
g_signal_emit (hier, signals[REMOVED_FOLDER], 0, folder);
169
is_empty (ExchangeHierarchy *hier)
175
exchange_hierarchy_is_empty (ExchangeHierarchy *hier)
177
g_return_val_if_fail (EXCHANGE_IS_HIERARCHY (hier), TRUE);
179
return HIER_CLASS (hier)->is_empty (hier);
182
static ExchangeAccountFolderResult
183
create_folder (ExchangeHierarchy *hier, EFolder *parent,
184
const gchar *name, const gchar *type)
186
return EXCHANGE_ACCOUNT_FOLDER_PERMISSION_DENIED;
189
static ExchangeAccountFolderResult
190
remove_folder (ExchangeHierarchy *hier, EFolder *folder)
192
return EXCHANGE_ACCOUNT_FOLDER_PERMISSION_DENIED;
195
static ExchangeAccountFolderResult
196
xfer_folder (ExchangeHierarchy *hier, EFolder *source,
197
EFolder *dest_parent, const gchar *dest_name,
198
gboolean remove_source)
200
return EXCHANGE_ACCOUNT_FOLDER_PERMISSION_DENIED;
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
210
* Attempts to create a new folder.
212
* Return value: the result code
214
ExchangeAccountFolderResult
215
exchange_hierarchy_create_folder (ExchangeHierarchy *hier, EFolder *parent,
216
const gchar *name, const gchar *type)
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);
223
return HIER_CLASS (hier)->create_folder (hier, parent, name, type);
227
* exchange_hierarchy_remove_folder:
228
* @hier: the hierarchy
229
* @folder: the folder to remove
231
* Attempts to remove a folder.
233
* Return value: the result code
235
ExchangeAccountFolderResult
236
exchange_hierarchy_remove_folder (ExchangeHierarchy *hier, EFolder *folder)
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);
241
return HIER_CLASS (hier)->remove_folder (hier, folder);
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
252
* Attempts to move or copy a folder.
254
* Return value: the result code
256
ExchangeAccountFolderResult
257
exchange_hierarchy_xfer_folder (ExchangeHierarchy *hier, EFolder *source,
258
EFolder *dest_parent, const gchar *dest_name,
259
gboolean remove_source)
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);
266
return HIER_CLASS (hier)->xfer_folder (hier, source,
267
dest_parent, dest_name,
272
rescan (ExchangeHierarchy *hier)
278
* exchange_hierarchy_rescan:
279
* @hier: the hierarchy
281
* Tells the hierarchy to rescan its folder tree
284
exchange_hierarchy_rescan (ExchangeHierarchy *hier)
286
g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
288
HIER_CLASS (hier)->rescan (hier);
291
static ExchangeAccountFolderResult
292
scan_subtree (ExchangeHierarchy *hier, EFolder *folder, gint mode)
294
return EXCHANGE_ACCOUNT_FOLDER_OK;
298
* exchange_hierarchy_scan_subtree:
299
* @hier: the hierarchy
300
* @folder: the folder to scan under
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.
306
* Return value: the result code
308
ExchangeAccountFolderResult
309
exchange_hierarchy_scan_subtree (ExchangeHierarchy *hier, EFolder *folder, gint mode)
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);
314
return HIER_CLASS (hier)->scan_subtree (hier, folder, mode);
318
add_to_storage (ExchangeHierarchy *hier)
320
e_folder_set_sorting_priority (hier->toplevel, hier->type);
321
exchange_hierarchy_new_folder (hier, hier->toplevel);
325
* exchange_hierarchy_add_to_storage:
326
* @hier: the hierarchy
328
* Tells the hierarchy to fill in its folder tree, emitting %new_folder
329
* signals as appropriate.
332
exchange_hierarchy_add_to_storage (ExchangeHierarchy *hier)
334
g_return_if_fail (EXCHANGE_IS_HIERARCHY (hier));
336
HIER_CLASS (hier)->add_to_storage (hier);
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.
349
* Constructs the hierarchy. @owner_name, @owner_email, and @source_uri
350
* can be %NULL if not relevant to this hierarchy.
353
exchange_hierarchy_construct (ExchangeHierarchy *hier,
354
ExchangeAccount *account,
355
ExchangeHierarchyType type,
357
const gchar *owner_name,
358
const gchar *owner_email,
359
const gchar *source_uri)
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));
365
/* We don't ref the account since we'll be destroyed when
368
hier->account = account;
370
hier->toplevel = toplevel;
371
g_object_ref (toplevel);
374
hier->owner_name = g_strdup (owner_name);
375
hier->owner_email = g_strdup (owner_email);
376
hier->source_uri = g_strdup (source_uri);