1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /* e-corba-storage.c |
---|
3 | * |
---|
4 | * Copyright (C) 2000, 2001 Ximian, Inc. |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of version 2 of the GNU General Public |
---|
8 | * License as published by the Free Software Foundation. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | * General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public |
---|
16 | * License along with this program; if not, write to the |
---|
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
18 | * Boston, MA 02111-1307, USA. |
---|
19 | * |
---|
20 | * Author: Ettore Perazzoli |
---|
21 | */ |
---|
22 | |
---|
23 | #ifdef HAVE_CONFIG_H |
---|
24 | #include <config.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | #include "e-corba-storage.h" |
---|
28 | |
---|
29 | #include "e-shell-constants.h" |
---|
30 | |
---|
31 | #include "Evolution.h" |
---|
32 | |
---|
33 | #include <glib.h> |
---|
34 | #include <gal/util/e-util.h> |
---|
35 | |
---|
36 | #include <bonobo/bonobo-main.h> |
---|
37 | #include <bonobo/bonobo-exception.h> |
---|
38 | |
---|
39 | #include <gdk/gdkx.h> |
---|
40 | |
---|
41 | |
---|
42 | #define PARENT_TYPE E_TYPE_STORAGE |
---|
43 | static EStorageClass *parent_class = NULL; |
---|
44 | |
---|
45 | typedef struct _StorageListenerServant StorageListenerServant; |
---|
46 | |
---|
47 | struct _ECorbaStoragePrivate { |
---|
48 | GNOME_Evolution_Storage storage_interface; |
---|
49 | |
---|
50 | /* The Evolution::StorageListener interface we expose. */ |
---|
51 | |
---|
52 | GNOME_Evolution_StorageListener storage_listener_interface; |
---|
53 | StorageListenerServant *storage_listener_servant; |
---|
54 | }; |
---|
55 | |
---|
56 | |
---|
57 | /* Implementation of the CORBA Evolution::StorageListener interface. */ |
---|
58 | |
---|
59 | static POA_GNOME_Evolution_StorageListener__vepv storage_listener_vepv; |
---|
60 | |
---|
61 | struct _StorageListenerServant { |
---|
62 | POA_GNOME_Evolution_StorageListener servant; |
---|
63 | EStorage *storage; |
---|
64 | }; |
---|
65 | |
---|
66 | static StorageListenerServant * |
---|
67 | storage_listener_servant_new (ECorbaStorage *corba_storage) |
---|
68 | { |
---|
69 | StorageListenerServant *servant; |
---|
70 | |
---|
71 | servant = g_new0 (StorageListenerServant, 1); |
---|
72 | |
---|
73 | servant->servant.vepv = &storage_listener_vepv; |
---|
74 | |
---|
75 | gtk_object_ref (GTK_OBJECT (corba_storage)); |
---|
76 | servant->storage = E_STORAGE (corba_storage); |
---|
77 | |
---|
78 | return servant; |
---|
79 | } |
---|
80 | |
---|
81 | static void |
---|
82 | storage_listener_servant_free (StorageListenerServant *servant) |
---|
83 | { |
---|
84 | gtk_object_unref (GTK_OBJECT (servant->storage)); |
---|
85 | |
---|
86 | g_free (servant); |
---|
87 | } |
---|
88 | |
---|
89 | #if 0 |
---|
90 | static void |
---|
91 | impl_StorageListener_destroy (PortableServer_Servant servant, |
---|
92 | CORBA_Environment *ev) |
---|
93 | { |
---|
94 | /* FIXME */ |
---|
95 | } |
---|
96 | #endif |
---|
97 | |
---|
98 | static void |
---|
99 | impl_StorageListener_notifyFolderCreated (PortableServer_Servant servant, |
---|
100 | const CORBA_char *path, |
---|
101 | const GNOME_Evolution_Folder *folder, |
---|
102 | CORBA_Environment *ev) |
---|
103 | { |
---|
104 | StorageListenerServant *storage_listener_servant; |
---|
105 | EStorage *storage; |
---|
106 | EFolder *e_folder; |
---|
107 | |
---|
108 | storage_listener_servant = (StorageListenerServant *) servant; |
---|
109 | storage = storage_listener_servant->storage; |
---|
110 | |
---|
111 | e_folder = e_folder_new (folder->displayName, folder->type, folder->description); |
---|
112 | |
---|
113 | e_folder_set_physical_uri (e_folder, folder->physicalUri); |
---|
114 | e_folder_set_unread_count (e_folder, folder->unreadCount); |
---|
115 | e_folder_set_can_sync_offline (e_folder, folder->canSyncOffline); |
---|
116 | e_folder_set_sorting_priority (e_folder, folder->sortingPriority); |
---|
117 | |
---|
118 | if (folder->customIconName[0] != '\0') |
---|
119 | e_folder_set_custom_icon (e_folder, folder->customIconName); |
---|
120 | |
---|
121 | if (! e_storage_new_folder (storage, path, e_folder)) { |
---|
122 | g_warning ("Cannot register folder -- %s %s\n", path, folder->displayName); |
---|
123 | CORBA_exception_set (ev, |
---|
124 | CORBA_USER_EXCEPTION, |
---|
125 | ex_GNOME_Evolution_StorageListener_Exists, |
---|
126 | NULL); |
---|
127 | gtk_object_unref (GTK_OBJECT (e_folder)); |
---|
128 | return; |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | static void |
---|
133 | impl_StorageListener_notifyFolderUpdated (PortableServer_Servant servant, |
---|
134 | const CORBA_char *path, |
---|
135 | CORBA_long unread_count, |
---|
136 | CORBA_Environment *ev) |
---|
137 | { |
---|
138 | StorageListenerServant *storage_listener_servant; |
---|
139 | EStorage *storage; |
---|
140 | EFolder *e_folder; |
---|
141 | |
---|
142 | storage_listener_servant = (StorageListenerServant *) servant; |
---|
143 | storage = storage_listener_servant->storage; |
---|
144 | |
---|
145 | e_folder = e_storage_get_folder (storage, path); |
---|
146 | if (e_folder == NULL) { |
---|
147 | CORBA_exception_set (ev, |
---|
148 | CORBA_USER_EXCEPTION, |
---|
149 | ex_GNOME_Evolution_StorageListener_NotFound, |
---|
150 | NULL); |
---|
151 | return; |
---|
152 | } |
---|
153 | |
---|
154 | e_folder_set_unread_count (e_folder, unread_count); |
---|
155 | } |
---|
156 | |
---|
157 | static void |
---|
158 | impl_StorageListener_notifyFolderRemoved (PortableServer_Servant servant, |
---|
159 | const CORBA_char *path, |
---|
160 | CORBA_Environment *ev) |
---|
161 | { |
---|
162 | StorageListenerServant *storage_listener_servant; |
---|
163 | EStorage *storage; |
---|
164 | |
---|
165 | storage_listener_servant = (StorageListenerServant *) servant; |
---|
166 | storage = storage_listener_servant->storage; |
---|
167 | |
---|
168 | if (! e_storage_removed_folder (storage, path)) |
---|
169 | CORBA_exception_set (ev, |
---|
170 | CORBA_USER_EXCEPTION, |
---|
171 | ex_GNOME_Evolution_StorageListener_NotFound, |
---|
172 | NULL); |
---|
173 | } |
---|
174 | |
---|
175 | static void |
---|
176 | impl_StorageListener_notifyHasSubfolders (PortableServer_Servant servant, |
---|
177 | const CORBA_char *path, |
---|
178 | const CORBA_char *message, |
---|
179 | CORBA_Environment *ev) |
---|
180 | { |
---|
181 | StorageListenerServant *storage_listener_servant; |
---|
182 | EStorage *storage; |
---|
183 | |
---|
184 | storage_listener_servant = (StorageListenerServant *) servant; |
---|
185 | storage = storage_listener_servant->storage; |
---|
186 | |
---|
187 | if (! e_storage_has_subfolders (storage, path, message)) { |
---|
188 | g_warning ("Cannot register subfolder tree -- %s\n", path); |
---|
189 | CORBA_exception_set (ev, |
---|
190 | CORBA_USER_EXCEPTION, |
---|
191 | ex_GNOME_Evolution_StorageListener_Exists, |
---|
192 | NULL); |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | static gboolean |
---|
198 | setup_storage_listener (ECorbaStorage *corba_storage) |
---|
199 | { |
---|
200 | StorageListenerServant *servant; |
---|
201 | ECorbaStoragePrivate *priv; |
---|
202 | GNOME_Evolution_StorageListener storage_listener_interface; |
---|
203 | CORBA_Environment ev; |
---|
204 | |
---|
205 | priv = corba_storage->priv; |
---|
206 | |
---|
207 | servant = storage_listener_servant_new (corba_storage); |
---|
208 | |
---|
209 | CORBA_exception_init (&ev); |
---|
210 | |
---|
211 | POA_GNOME_Evolution_StorageListener__init (servant, &ev); |
---|
212 | if (ev._major != CORBA_NO_EXCEPTION) |
---|
213 | goto error; |
---|
214 | |
---|
215 | CORBA_free (PortableServer_POA_activate_object (bonobo_poa (), servant, &ev)); |
---|
216 | if (ev._major != CORBA_NO_EXCEPTION) |
---|
217 | goto error; |
---|
218 | |
---|
219 | storage_listener_interface = PortableServer_POA_servant_to_reference (bonobo_poa (), |
---|
220 | servant, &ev); |
---|
221 | if (ev._major != CORBA_NO_EXCEPTION) |
---|
222 | goto error; |
---|
223 | |
---|
224 | priv->storage_listener_interface = storage_listener_interface; |
---|
225 | priv->storage_listener_servant = servant; |
---|
226 | |
---|
227 | return TRUE; |
---|
228 | |
---|
229 | error: |
---|
230 | storage_listener_servant_free (servant); |
---|
231 | CORBA_exception_free (&ev); |
---|
232 | return FALSE; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | /* GtkObject methods. */ |
---|
237 | |
---|
238 | static void |
---|
239 | destroy (GtkObject *object) |
---|
240 | { |
---|
241 | CORBA_Environment ev; |
---|
242 | ECorbaStorage *corba_storage; |
---|
243 | ECorbaStoragePrivate *priv; |
---|
244 | |
---|
245 | corba_storage = E_CORBA_STORAGE (object); |
---|
246 | priv = corba_storage->priv; |
---|
247 | |
---|
248 | CORBA_exception_init (&ev); |
---|
249 | |
---|
250 | if (priv->storage_interface != CORBA_OBJECT_NIL) { |
---|
251 | Bonobo_Unknown_unref (priv->storage_interface, &ev); |
---|
252 | CORBA_Object_release (priv->storage_interface, &ev); |
---|
253 | } |
---|
254 | |
---|
255 | if (priv->storage_listener_interface != CORBA_OBJECT_NIL) |
---|
256 | CORBA_Object_release (priv->storage_listener_interface, &ev); |
---|
257 | |
---|
258 | if (priv->storage_listener_servant != NULL) { |
---|
259 | PortableServer_ObjectId *object_id; |
---|
260 | |
---|
261 | object_id = PortableServer_POA_servant_to_id (bonobo_poa (), priv->storage_listener_servant, |
---|
262 | &ev); |
---|
263 | PortableServer_POA_deactivate_object (bonobo_poa (), object_id, &ev); |
---|
264 | |
---|
265 | POA_GNOME_Evolution_StorageListener__fini (priv->storage_listener_servant, &ev); |
---|
266 | CORBA_free (object_id); |
---|
267 | } |
---|
268 | |
---|
269 | CORBA_exception_free (&ev); |
---|
270 | |
---|
271 | g_free (priv); |
---|
272 | |
---|
273 | corba_storage->priv = NULL; |
---|
274 | |
---|
275 | (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | /* EStorage methods. */ |
---|
280 | |
---|
281 | struct async_folder_closure { |
---|
282 | EStorageResultCallback callback; |
---|
283 | EStorage *storage; |
---|
284 | void *data; |
---|
285 | }; |
---|
286 | |
---|
287 | static void |
---|
288 | async_folder_cb (BonoboListener *listener, char *event_name, |
---|
289 | CORBA_any *any, CORBA_Environment *ev, |
---|
290 | gpointer user_data) |
---|
291 | { |
---|
292 | struct async_folder_closure *closure = user_data; |
---|
293 | GNOME_Evolution_Storage_Result *corba_result; |
---|
294 | EStorageResult result; |
---|
295 | |
---|
296 | corba_result = any->_value; |
---|
297 | result = e_corba_storage_corba_result_to_storage_result (*corba_result); |
---|
298 | |
---|
299 | (* closure->callback) (closure->storage, result, closure->data); |
---|
300 | bonobo_object_unref (BONOBO_OBJECT (listener)); |
---|
301 | g_free (closure); |
---|
302 | } |
---|
303 | |
---|
304 | static void |
---|
305 | async_create_folder (EStorage *storage, const char *path, |
---|
306 | const char *type, const char *description, |
---|
307 | EStorageResultCallback callback, void *data) |
---|
308 | { |
---|
309 | ECorbaStorage *corba_storage; |
---|
310 | ECorbaStoragePrivate *priv; |
---|
311 | const char *parent_uri; |
---|
312 | char *p; |
---|
313 | BonoboListener *listener; |
---|
314 | Bonobo_Listener corba_listener; |
---|
315 | CORBA_Environment ev; |
---|
316 | struct async_folder_closure *closure; |
---|
317 | |
---|
318 | corba_storage = E_CORBA_STORAGE (storage); |
---|
319 | priv = corba_storage->priv; |
---|
320 | |
---|
321 | p = strrchr (path, '/'); |
---|
322 | if (p && p != path) { |
---|
323 | char *parent_path; |
---|
324 | EFolder *parent; |
---|
325 | |
---|
326 | parent_path = g_strndup (path, p - path); |
---|
327 | parent = e_storage_get_folder (storage, parent_path); |
---|
328 | parent_uri = e_folder_get_physical_uri (parent); |
---|
329 | } else |
---|
330 | parent_uri = ""; |
---|
331 | |
---|
332 | closure = g_new (struct async_folder_closure, 1); |
---|
333 | closure->callback = callback; |
---|
334 | closure->storage = storage; |
---|
335 | closure->data = data; |
---|
336 | listener = bonobo_listener_new (async_folder_cb, closure); |
---|
337 | corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener)); |
---|
338 | |
---|
339 | CORBA_exception_init (&ev); |
---|
340 | GNOME_Evolution_Storage_asyncCreateFolder (priv->storage_interface, |
---|
341 | path, type, description, |
---|
342 | parent_uri, |
---|
343 | corba_listener, &ev); |
---|
344 | |
---|
345 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
346 | (* callback) (storage, E_STORAGE_GENERICERROR, data); |
---|
347 | bonobo_object_unref (BONOBO_OBJECT (listener)); |
---|
348 | g_free (closure); |
---|
349 | } |
---|
350 | CORBA_exception_free (&ev); |
---|
351 | } |
---|
352 | |
---|
353 | static void |
---|
354 | async_remove_folder (EStorage *storage, |
---|
355 | const char *path, |
---|
356 | EStorageResultCallback callback, |
---|
357 | void *data) |
---|
358 | { |
---|
359 | ECorbaStorage *corba_storage; |
---|
360 | ECorbaStoragePrivate *priv; |
---|
361 | EFolder *folder; |
---|
362 | BonoboListener *listener; |
---|
363 | Bonobo_Listener corba_listener; |
---|
364 | CORBA_Environment ev; |
---|
365 | struct async_folder_closure *closure; |
---|
366 | |
---|
367 | corba_storage = E_CORBA_STORAGE (storage); |
---|
368 | priv = corba_storage->priv; |
---|
369 | |
---|
370 | folder = e_storage_get_folder (storage, path); |
---|
371 | if (e_folder_get_is_stock (folder)) { |
---|
372 | (* callback) (storage, E_STORAGE_CANTCHANGESTOCKFOLDER, data); |
---|
373 | return; |
---|
374 | } |
---|
375 | if (e_folder_get_physical_uri (folder) == NULL) { |
---|
376 | (* callback) (storage, E_STORAGE_GENERICERROR, data); |
---|
377 | return; |
---|
378 | } |
---|
379 | |
---|
380 | closure = g_new (struct async_folder_closure, 1); |
---|
381 | closure->callback = callback; |
---|
382 | closure->storage = storage; |
---|
383 | closure->data = data; |
---|
384 | listener = bonobo_listener_new (async_folder_cb, closure); |
---|
385 | corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener)); |
---|
386 | |
---|
387 | CORBA_exception_init (&ev); |
---|
388 | GNOME_Evolution_Storage_asyncRemoveFolder (priv->storage_interface, |
---|
389 | path, |
---|
390 | e_folder_get_physical_uri (folder), |
---|
391 | corba_listener, &ev); |
---|
392 | |
---|
393 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
394 | (* callback) (storage, E_STORAGE_GENERICERROR, data); |
---|
395 | bonobo_object_unref (BONOBO_OBJECT (listener)); |
---|
396 | g_free (closure); |
---|
397 | } |
---|
398 | CORBA_exception_free (&ev); |
---|
399 | } |
---|
400 | |
---|
401 | static void |
---|
402 | async_xfer_folder (EStorage *storage, |
---|
403 | const char *source_path, |
---|
404 | const char *destination_path, |
---|
405 | gboolean remove_source, |
---|
406 | EStorageResultCallback callback, |
---|
407 | void *data) |
---|
408 | { |
---|
409 | ECorbaStorage *corba_storage; |
---|
410 | ECorbaStoragePrivate *priv; |
---|
411 | EFolder *folder; |
---|
412 | BonoboListener *listener; |
---|
413 | Bonobo_Listener corba_listener; |
---|
414 | CORBA_Environment ev; |
---|
415 | struct async_folder_closure *closure; |
---|
416 | |
---|
417 | corba_storage = E_CORBA_STORAGE (storage); |
---|
418 | priv = corba_storage->priv; |
---|
419 | |
---|
420 | folder = e_storage_get_folder (storage, source_path); |
---|
421 | if (e_folder_get_is_stock (folder) && remove_source) |
---|
422 | (* callback) (storage, E_STORAGE_CANTCHANGESTOCKFOLDER, data); |
---|
423 | |
---|
424 | closure = g_new (struct async_folder_closure, 1); |
---|
425 | closure->callback = callback; |
---|
426 | closure->storage = storage; |
---|
427 | closure->data = data; |
---|
428 | listener = bonobo_listener_new (async_folder_cb, closure); |
---|
429 | corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener)); |
---|
430 | |
---|
431 | CORBA_exception_init (&ev); |
---|
432 | GNOME_Evolution_Storage_asyncXferFolder (priv->storage_interface, |
---|
433 | source_path, destination_path, |
---|
434 | remove_source, corba_listener, &ev); |
---|
435 | |
---|
436 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
437 | (* callback) (storage, E_STORAGE_GENERICERROR, data); |
---|
438 | bonobo_object_unref (BONOBO_OBJECT (listener)); |
---|
439 | g_free (closure); |
---|
440 | } |
---|
441 | CORBA_exception_free (&ev); |
---|
442 | } |
---|
443 | |
---|
444 | static gboolean |
---|
445 | async_open_folder_idle (gpointer data) |
---|
446 | { |
---|
447 | gpointer *pair = data; |
---|
448 | |
---|
449 | EStorage *storage = pair[0]; |
---|
450 | char *path = pair[1]; |
---|
451 | |
---|
452 | ECorbaStorage *corba_storage; |
---|
453 | CORBA_Environment ev; |
---|
454 | |
---|
455 | corba_storage = E_CORBA_STORAGE (storage); |
---|
456 | |
---|
457 | if (corba_storage->priv != NULL) { |
---|
458 | |
---|
459 | CORBA_exception_init (&ev); |
---|
460 | GNOME_Evolution_Storage_asyncOpenFolder (corba_storage->priv->storage_interface, |
---|
461 | path, &ev); |
---|
462 | CORBA_exception_free (&ev); |
---|
463 | } |
---|
464 | |
---|
465 | gtk_object_unref (GTK_OBJECT (storage)); |
---|
466 | g_free (path); |
---|
467 | g_free (pair); |
---|
468 | |
---|
469 | return FALSE; |
---|
470 | } |
---|
471 | |
---|
472 | static void |
---|
473 | async_open_folder (EStorage *storage, |
---|
474 | const char *path) |
---|
475 | { |
---|
476 | gpointer *pair = g_new (gpointer, 2); |
---|
477 | pair[0] = storage; |
---|
478 | gtk_object_ref (GTK_OBJECT (storage)); |
---|
479 | pair[1] = g_strdup (path); |
---|
480 | |
---|
481 | g_idle_add (async_open_folder_idle, pair); |
---|
482 | } |
---|
483 | |
---|
484 | |
---|
485 | /* Shared folders. */ |
---|
486 | |
---|
487 | static gboolean |
---|
488 | supports_shared_folders (EStorage *storage) |
---|
489 | { |
---|
490 | GNOME_Evolution_Storage storage_iface; |
---|
491 | CORBA_boolean has_shared_folders; |
---|
492 | CORBA_Environment ev; |
---|
493 | |
---|
494 | CORBA_exception_init (&ev); |
---|
495 | |
---|
496 | storage_iface = e_corba_storage_get_corba_objref (E_CORBA_STORAGE (storage)); |
---|
497 | g_assert (storage_iface != CORBA_OBJECT_NIL); |
---|
498 | |
---|
499 | has_shared_folders = GNOME_Evolution_Storage__get_hasSharedFolders (storage_iface, &ev); |
---|
500 | if (BONOBO_EX (&ev)) |
---|
501 | has_shared_folders = FALSE; |
---|
502 | |
---|
503 | CORBA_exception_free (&ev); |
---|
504 | |
---|
505 | return has_shared_folders; |
---|
506 | } |
---|
507 | |
---|
508 | static void |
---|
509 | async_folder_discovery_cb (BonoboListener *listener, char *event_name, |
---|
510 | CORBA_any *any, CORBA_Environment *ev, |
---|
511 | gpointer user_data) |
---|
512 | { |
---|
513 | struct async_folder_closure *closure = user_data; |
---|
514 | GNOME_Evolution_Storage_FolderResult *corba_result; |
---|
515 | EStorageDiscoveryCallback callback; |
---|
516 | EStorageResult result; |
---|
517 | char *path; |
---|
518 | |
---|
519 | corba_result = any->_value; |
---|
520 | result = e_corba_storage_corba_result_to_storage_result (corba_result->result); |
---|
521 | if (result == E_STORAGE_OK) |
---|
522 | path = corba_result->path; |
---|
523 | else |
---|
524 | path = NULL; |
---|
525 | |
---|
526 | callback = (EStorageDiscoveryCallback)closure->callback; |
---|
527 | (* callback) (closure->storage, result, path, closure->data); |
---|
528 | |
---|
529 | bonobo_object_unref (BONOBO_OBJECT (listener)); |
---|
530 | g_free (closure); |
---|
531 | } |
---|
532 | |
---|
533 | static void |
---|
534 | async_discover_shared_folder (EStorage *storage, |
---|
535 | const char *owner, |
---|
536 | const char *folder_name, |
---|
537 | EStorageDiscoveryCallback callback, |
---|
538 | void *data) |
---|
539 | { |
---|
540 | ECorbaStorage *corba_storage; |
---|
541 | ECorbaStoragePrivate *priv; |
---|
542 | BonoboListener *listener; |
---|
543 | Bonobo_Listener corba_listener; |
---|
544 | CORBA_Environment ev; |
---|
545 | struct async_folder_closure *closure; |
---|
546 | |
---|
547 | corba_storage = E_CORBA_STORAGE (storage); |
---|
548 | priv = corba_storage->priv; |
---|
549 | |
---|
550 | closure = g_new (struct async_folder_closure, 1); |
---|
551 | closure->callback = (EStorageResultCallback)callback; |
---|
552 | closure->storage = storage; |
---|
553 | closure->data = data; |
---|
554 | listener = bonobo_listener_new (async_folder_discovery_cb, closure); |
---|
555 | corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener)); |
---|
556 | |
---|
557 | CORBA_exception_init (&ev); |
---|
558 | GNOME_Evolution_Storage_asyncDiscoverSharedFolder (priv->storage_interface, |
---|
559 | owner, folder_name, |
---|
560 | corba_listener, &ev); |
---|
561 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
562 | (* callback) (storage, E_STORAGE_GENERICERROR, NULL, data); |
---|
563 | bonobo_object_unref (BONOBO_OBJECT (listener)); |
---|
564 | g_free (closure); |
---|
565 | } |
---|
566 | CORBA_exception_free (&ev); |
---|
567 | } |
---|
568 | |
---|
569 | static void |
---|
570 | cancel_discover_shared_folder (EStorage *storage, |
---|
571 | const char *owner, |
---|
572 | const char *folder_name) |
---|
573 | { |
---|
574 | ECorbaStorage *corba_storage; |
---|
575 | ECorbaStoragePrivate *priv; |
---|
576 | CORBA_Environment ev; |
---|
577 | |
---|
578 | corba_storage = E_CORBA_STORAGE (storage); |
---|
579 | priv = corba_storage->priv; |
---|
580 | |
---|
581 | CORBA_exception_init (&ev); |
---|
582 | GNOME_Evolution_Storage_cancelDiscoverSharedFolder (priv->storage_interface, |
---|
583 | owner, folder_name, &ev); |
---|
584 | if (BONOBO_EX (&ev)) |
---|
585 | g_warning ("Error invoking cancelDiscoverSharedFolder -- %s", BONOBO_EX_ID (&ev)); |
---|
586 | CORBA_exception_free (&ev); |
---|
587 | } |
---|
588 | |
---|
589 | static void |
---|
590 | async_remove_shared_folder (EStorage *storage, |
---|
591 | const char *path, |
---|
592 | EStorageResultCallback callback, |
---|
593 | void *data) |
---|
594 | { |
---|
595 | ECorbaStorage *corba_storage; |
---|
596 | ECorbaStoragePrivate *priv; |
---|
597 | BonoboListener *listener; |
---|
598 | Bonobo_Listener corba_listener; |
---|
599 | CORBA_Environment ev; |
---|
600 | struct async_folder_closure *closure; |
---|
601 | |
---|
602 | corba_storage = E_CORBA_STORAGE (storage); |
---|
603 | priv = corba_storage->priv; |
---|
604 | |
---|
605 | closure = g_new (struct async_folder_closure, 1); |
---|
606 | closure->callback = callback; |
---|
607 | closure->storage = storage; |
---|
608 | closure->data = data; |
---|
609 | listener = bonobo_listener_new (async_folder_cb, closure); |
---|
610 | corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener)); |
---|
611 | |
---|
612 | CORBA_exception_init (&ev); |
---|
613 | GNOME_Evolution_Storage_asyncRemoveSharedFolder (priv->storage_interface, |
---|
614 | path, corba_listener, |
---|
615 | &ev); |
---|
616 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
617 | (* callback) (storage, E_STORAGE_GENERICERROR, data); |
---|
618 | bonobo_object_unref (BONOBO_OBJECT (listener)); |
---|
619 | g_free (closure); |
---|
620 | } |
---|
621 | CORBA_exception_free (&ev); |
---|
622 | } |
---|
623 | |
---|
624 | |
---|
625 | static void |
---|
626 | corba_class_init (void) |
---|
627 | { |
---|
628 | POA_GNOME_Evolution_StorageListener__vepv *vepv; |
---|
629 | POA_GNOME_Evolution_StorageListener__epv *epv; |
---|
630 | PortableServer_ServantBase__epv *base_epv; |
---|
631 | |
---|
632 | base_epv = g_new0 (PortableServer_ServantBase__epv, 1); |
---|
633 | base_epv->_private = NULL; |
---|
634 | base_epv->finalize = NULL; |
---|
635 | base_epv->default_POA = NULL; |
---|
636 | |
---|
637 | epv = g_new0 (POA_GNOME_Evolution_StorageListener__epv, 1); |
---|
638 | epv->notifyFolderCreated = impl_StorageListener_notifyFolderCreated; |
---|
639 | epv->notifyFolderUpdated = impl_StorageListener_notifyFolderUpdated; |
---|
640 | epv->notifyFolderRemoved = impl_StorageListener_notifyFolderRemoved; |
---|
641 | epv->notifyHasSubfolders = impl_StorageListener_notifyHasSubfolders; |
---|
642 | |
---|
643 | vepv = &storage_listener_vepv; |
---|
644 | vepv->_base_epv = base_epv; |
---|
645 | vepv->GNOME_Evolution_StorageListener_epv = epv; |
---|
646 | } |
---|
647 | |
---|
648 | static void |
---|
649 | class_init (ECorbaStorageClass *klass) |
---|
650 | { |
---|
651 | GtkObjectClass *object_class; |
---|
652 | EStorageClass *storage_class; |
---|
653 | |
---|
654 | object_class = GTK_OBJECT_CLASS (klass); |
---|
655 | object_class->destroy = destroy; |
---|
656 | |
---|
657 | storage_class = E_STORAGE_CLASS (klass); |
---|
658 | storage_class->async_create_folder = async_create_folder; |
---|
659 | storage_class->async_remove_folder = async_remove_folder; |
---|
660 | storage_class->async_xfer_folder = async_xfer_folder; |
---|
661 | storage_class->async_open_folder = async_open_folder; |
---|
662 | storage_class->supports_shared_folders = supports_shared_folders; |
---|
663 | storage_class->async_discover_shared_folder = async_discover_shared_folder; |
---|
664 | storage_class->cancel_discover_shared_folder = cancel_discover_shared_folder; |
---|
665 | storage_class->async_remove_shared_folder = async_remove_shared_folder; |
---|
666 | |
---|
667 | corba_class_init (); |
---|
668 | |
---|
669 | parent_class = gtk_type_class (PARENT_TYPE); |
---|
670 | } |
---|
671 | |
---|
672 | static void |
---|
673 | init (ECorbaStorage *corba_storage) |
---|
674 | { |
---|
675 | ECorbaStoragePrivate *priv; |
---|
676 | |
---|
677 | priv = g_new (ECorbaStoragePrivate, 1); |
---|
678 | priv->storage_interface = CORBA_OBJECT_NIL; |
---|
679 | |
---|
680 | corba_storage->priv = priv; |
---|
681 | } |
---|
682 | |
---|
683 | |
---|
684 | /* FIXME: OK to have a boolean construct function? */ |
---|
685 | void |
---|
686 | e_corba_storage_construct (ECorbaStorage *corba_storage, |
---|
687 | const GNOME_Evolution_Storage storage_interface, |
---|
688 | const char *name) |
---|
689 | { |
---|
690 | ECorbaStoragePrivate *priv; |
---|
691 | CORBA_Environment ev; |
---|
692 | EFolder *root_folder; |
---|
693 | |
---|
694 | g_return_if_fail (corba_storage != NULL); |
---|
695 | g_return_if_fail (E_IS_CORBA_STORAGE (corba_storage)); |
---|
696 | g_return_if_fail (storage_interface != CORBA_OBJECT_NIL); |
---|
697 | g_return_if_fail (name != NULL); |
---|
698 | |
---|
699 | /* FIXME: Need separate name and display name. */ |
---|
700 | root_folder = e_folder_new (name, "noselect", ""); |
---|
701 | e_storage_construct (E_STORAGE (corba_storage), name, root_folder); |
---|
702 | |
---|
703 | priv = corba_storage->priv; |
---|
704 | |
---|
705 | CORBA_exception_init (&ev); |
---|
706 | |
---|
707 | Bonobo_Unknown_ref (storage_interface, &ev); |
---|
708 | if (ev._major != CORBA_NO_EXCEPTION) |
---|
709 | g_warning ("e_corba_storage_construct() -- Cannot reference Bonobo object"); |
---|
710 | else |
---|
711 | priv->storage_interface = CORBA_Object_duplicate (storage_interface, &ev); |
---|
712 | |
---|
713 | CORBA_exception_free (&ev); |
---|
714 | |
---|
715 | setup_storage_listener (corba_storage); |
---|
716 | } |
---|
717 | |
---|
718 | EStorage * |
---|
719 | e_corba_storage_new (const GNOME_Evolution_Storage storage_interface, |
---|
720 | const char *name) |
---|
721 | { |
---|
722 | EStorage *new; |
---|
723 | |
---|
724 | g_return_val_if_fail (storage_interface != CORBA_OBJECT_NIL, NULL); |
---|
725 | g_return_val_if_fail (name != NULL, NULL); |
---|
726 | |
---|
727 | new = gtk_type_new (e_corba_storage_get_type ()); |
---|
728 | |
---|
729 | e_corba_storage_construct (E_CORBA_STORAGE (new), |
---|
730 | storage_interface, name); |
---|
731 | |
---|
732 | return new; |
---|
733 | } |
---|
734 | |
---|
735 | |
---|
736 | const GNOME_Evolution_StorageListener |
---|
737 | e_corba_storage_get_StorageListener (ECorbaStorage *corba_storage) |
---|
738 | { |
---|
739 | g_return_val_if_fail (corba_storage != NULL, NULL); |
---|
740 | g_return_val_if_fail (E_IS_CORBA_STORAGE (corba_storage), NULL); |
---|
741 | |
---|
742 | return corba_storage->priv->storage_listener_interface; |
---|
743 | } |
---|
744 | |
---|
745 | GNOME_Evolution_Storage |
---|
746 | e_corba_storage_get_corba_objref (ECorbaStorage *corba_storage) |
---|
747 | { |
---|
748 | g_return_val_if_fail (corba_storage != NULL, CORBA_OBJECT_NIL); |
---|
749 | g_return_val_if_fail (E_IS_CORBA_STORAGE (corba_storage), CORBA_OBJECT_NIL); |
---|
750 | |
---|
751 | return corba_storage->priv->storage_interface; |
---|
752 | } |
---|
753 | |
---|
754 | |
---|
755 | GSList * |
---|
756 | e_corba_storage_get_folder_property_items (ECorbaStorage *corba_storage) |
---|
757 | { |
---|
758 | GNOME_Evolution_Storage_FolderPropertyItemList *corba_items; |
---|
759 | CORBA_Environment ev; |
---|
760 | GSList *list; |
---|
761 | int i; |
---|
762 | |
---|
763 | g_return_val_if_fail (E_IS_CORBA_STORAGE (corba_storage), NULL); |
---|
764 | |
---|
765 | CORBA_exception_init (&ev); |
---|
766 | |
---|
767 | corba_items = GNOME_Evolution_Storage__get_folderPropertyItems (corba_storage->priv->storage_interface, |
---|
768 | &ev); |
---|
769 | |
---|
770 | if (BONOBO_EX (&ev)) { |
---|
771 | CORBA_exception_free (&ev); |
---|
772 | return NULL; |
---|
773 | } |
---|
774 | |
---|
775 | list = NULL; |
---|
776 | for (i = 0; i < corba_items->_length; i ++) { |
---|
777 | ECorbaStoragePropertyItem *item; |
---|
778 | |
---|
779 | item = g_new (ECorbaStoragePropertyItem, 1); |
---|
780 | item->label = g_strdup (corba_items->_buffer[i].label); |
---|
781 | item->tooltip = g_strdup (corba_items->_buffer[i].tooltip); |
---|
782 | item->icon = NULL; /* We don't care for now -- FIXME */ |
---|
783 | |
---|
784 | list = g_slist_prepend (list, item); |
---|
785 | } |
---|
786 | list = g_slist_reverse (list); |
---|
787 | |
---|
788 | CORBA_free (corba_items); |
---|
789 | CORBA_exception_free (&ev); |
---|
790 | |
---|
791 | return list; |
---|
792 | } |
---|
793 | |
---|
794 | void |
---|
795 | e_corba_storage_free_property_items_list (GSList *list) |
---|
796 | { |
---|
797 | GSList *p; |
---|
798 | |
---|
799 | for (p = list; p != NULL; p = p->next) { |
---|
800 | ECorbaStoragePropertyItem *item; |
---|
801 | |
---|
802 | item = (ECorbaStoragePropertyItem *) p->data; |
---|
803 | |
---|
804 | if (item->icon != NULL) |
---|
805 | gdk_pixbuf_unref (item->icon); |
---|
806 | g_free (item->label); |
---|
807 | g_free (item->tooltip); |
---|
808 | g_free (item); |
---|
809 | } |
---|
810 | |
---|
811 | g_slist_free (list); |
---|
812 | } |
---|
813 | |
---|
814 | void |
---|
815 | e_corba_storage_show_folder_properties (ECorbaStorage *corba_storage, |
---|
816 | const char *path, |
---|
817 | int property_item_id, |
---|
818 | GdkWindow *parent_window) |
---|
819 | { |
---|
820 | CORBA_Environment ev; |
---|
821 | |
---|
822 | g_return_if_fail (E_IS_CORBA_STORAGE (corba_storage)); |
---|
823 | g_return_if_fail (path != NULL && path[0] == E_PATH_SEPARATOR); |
---|
824 | |
---|
825 | CORBA_exception_init (&ev); |
---|
826 | |
---|
827 | GNOME_Evolution_Storage_showFolderProperties (corba_storage->priv->storage_interface, |
---|
828 | path, property_item_id, |
---|
829 | GDK_WINDOW_XWINDOW (parent_window), |
---|
830 | &ev); |
---|
831 | if (BONOBO_EX (&ev)) |
---|
832 | g_warning ("Error in Storage::showFolderProperties -- %s", BONOBO_EX_ID (&ev)); |
---|
833 | |
---|
834 | CORBA_exception_free (&ev); |
---|
835 | } |
---|
836 | |
---|
837 | EStorageResult |
---|
838 | e_corba_storage_corba_result_to_storage_result (GNOME_Evolution_Storage_Result corba_result) |
---|
839 | { |
---|
840 | switch (corba_result) { |
---|
841 | case GNOME_Evolution_Storage_OK: |
---|
842 | return E_STORAGE_OK; |
---|
843 | case GNOME_Evolution_Storage_UNSUPPORTED_OPERATION: |
---|
844 | return E_STORAGE_UNSUPPORTEDOPERATION; |
---|
845 | case GNOME_Evolution_Storage_UNSUPPORTED_TYPE: |
---|
846 | return E_STORAGE_UNSUPPORTEDTYPE; |
---|
847 | case GNOME_Evolution_Storage_INVALID_URI: |
---|
848 | return E_STORAGE_INVALIDNAME; |
---|
849 | case GNOME_Evolution_Storage_ALREADY_EXISTS: |
---|
850 | return E_STORAGE_EXISTS; |
---|
851 | case GNOME_Evolution_Storage_DOES_NOT_EXIST: |
---|
852 | return E_STORAGE_NOTFOUND; |
---|
853 | case GNOME_Evolution_Storage_PERMISSION_DENIED: |
---|
854 | return E_STORAGE_PERMISSIONDENIED; |
---|
855 | case GNOME_Evolution_Storage_NO_SPACE: |
---|
856 | return E_STORAGE_NOSPACE; |
---|
857 | case GNOME_Evolution_Storage_NOT_EMPTY: |
---|
858 | return E_STORAGE_NOTEMPTY; |
---|
859 | case GNOME_Evolution_Storage_NOT_ONLINE: |
---|
860 | return E_STORAGE_NOTONLINE; |
---|
861 | case GNOME_Evolution_Storage_GENERIC_ERROR: |
---|
862 | default: |
---|
863 | return E_STORAGE_GENERICERROR; |
---|
864 | } |
---|
865 | } |
---|
866 | |
---|
867 | |
---|
868 | E_MAKE_TYPE (e_corba_storage, "ECorbaStorage", ECorbaStorage, class_init, init, PARENT_TYPE) |
---|