source: trunk/third/evolution/shell/evolution-shell-component-client.c @ 18142

Revision 18142, 28.0 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18141, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* evolution-shell-component-client.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 <glib.h>
28#include <gtk/gtksignal.h>
29#include <gtk/gtktypeutils.h>
30
31#include <liboaf/liboaf.h>
32
33#include <bonobo/bonobo-main.h>
34#include <bonobo/bonobo-widget.h>
35
36#include <gal/util/e-util.h>
37
38#include "evolution-shell-component-client.h"
39
40
41char *evolution_debug_log;
42
43#define PARENT_TYPE BONOBO_OBJECT_CLIENT_TYPE
44static BonoboObjectClass *parent_class = NULL;
45
46struct _EvolutionShellComponentClientPrivate {
47        char *id;
48
49        EvolutionShellComponentClientCallback callback;
50        void *callback_data;
51
52        GNOME_Evolution_ShellComponentListener listener_interface;
53        PortableServer_Servant listener_servant;
54
55        GNOME_Evolution_ShellComponentDnd_SourceFolder dnd_source_folder_interface;
56        GNOME_Evolution_ShellComponentDnd_DestinationFolder dnd_destination_folder_interface;
57        GNOME_Evolution_Offline offline_interface;
58};
59
60
61#define RETURN_ERROR_IF_FAIL(cond) \
62        g_return_val_if_fail ((cond), EVOLUTION_SHELL_COMPONENT_INVALIDARG)
63
64
65/* Utility functions.  */
66
67static EvolutionShellComponentResult
68corba_exception_to_result (const CORBA_Environment *ev)
69{
70        if (ev->_major == CORBA_NO_EXCEPTION)
71                return EVOLUTION_SHELL_COMPONENT_OK;
72
73        if (ev->_major == CORBA_USER_EXCEPTION) {
74                if (strcmp (ev->_repo_id, ex_GNOME_Evolution_ShellComponent_AlreadyOwned) == 0)
75                        return EVOLUTION_SHELL_COMPONENT_ALREADYOWNED;
76                if (strcmp (ev->_repo_id, ex_GNOME_Evolution_ShellComponent_OldOwnerHasDied) == 0)
77                        return EVOLUTION_SHELL_COMPONENT_OLDOWNERHASDIED;
78                if (strcmp (ev->_repo_id, ex_GNOME_Evolution_ShellComponent_NotOwned) == 0)
79                        return EVOLUTION_SHELL_COMPONENT_NOTOWNED;
80                if (strcmp (ev->_repo_id, ex_GNOME_Evolution_ShellComponent_NotFound) == 0)
81                        return EVOLUTION_SHELL_COMPONENT_NOTFOUND;
82                if (strcmp (ev->_repo_id, ex_GNOME_Evolution_ShellComponent_UnsupportedType) == 0)
83                        return EVOLUTION_SHELL_COMPONENT_UNSUPPORTEDTYPE;
84                if (strcmp (ev->_repo_id, ex_GNOME_Evolution_ShellComponent_InternalError) == 0)
85                        return EVOLUTION_SHELL_COMPONENT_INTERNALERROR;
86                if (strcmp (ev->_repo_id, ex_GNOME_Evolution_ShellComponent_Busy) == 0)
87                        return EVOLUTION_SHELL_COMPONENT_BUSY;
88                if (strcmp (ev->_repo_id, ex_GNOME_Evolution_ShellComponent_UnsupportedSchema) == 0)
89                        return EVOLUTION_SHELL_COMPONENT_UNSUPPORTEDSCHEMA;
90
91                return EVOLUTION_SHELL_COMPONENT_UNKNOWNERROR;
92        } else {
93                /* FIXME maybe we need something more specific here.  */
94                return EVOLUTION_SHELL_COMPONENT_CORBAERROR;
95        }
96}
97
98static EvolutionShellComponentResult
99shell_component_result_from_corba_exception (const CORBA_Environment *ev)
100{
101        if (ev->_major == CORBA_NO_EXCEPTION)
102                return EVOLUTION_SHELL_COMPONENT_OK;
103        if (ev->_major == CORBA_SYSTEM_EXCEPTION)
104                return EVOLUTION_SHELL_COMPONENT_CORBAERROR;
105        return EVOLUTION_SHELL_COMPONENT_CORBAERROR; /* FIXME? */
106}
107
108
109/* CORBA listener interface implementation.  */
110
111static PortableServer_ServantBase__epv            ShellComponentListener_base_epv;
112static POA_GNOME_Evolution_ShellComponentListener__epv  ShellComponentListener_epv;
113static POA_GNOME_Evolution_ShellComponentListener__vepv ShellComponentListener_vepv;
114static gboolean ShellComponentListener_vepv_initialized = FALSE;
115
116static void ShellComponentListener_vepv_initialize (void);
117static void dispatch_callback (EvolutionShellComponentClient *shell_component_client,
118                               EvolutionShellComponentResult result);
119
120struct _ShellComponentListenerServant {
121        POA_GNOME_Evolution_ShellComponentListener servant;
122        EvolutionShellComponentClient *component_client;
123};
124typedef struct _ShellComponentListenerServant ShellComponentListenerServant;
125
126static PortableServer_Servant *
127create_ShellComponentListener_servant (EvolutionShellComponentClient *component_client)
128{
129        ShellComponentListenerServant *servant;
130
131        if (! ShellComponentListener_vepv_initialized)
132                ShellComponentListener_vepv_initialize ();
133
134        servant = g_new0 (ShellComponentListenerServant, 1);
135        servant->servant.vepv     = &ShellComponentListener_vepv;
136        servant->component_client = component_client;
137
138        return (PortableServer_Servant) servant;
139}
140
141static void
142free_ShellComponentListener_servant (PortableServer_Servant servant)
143{
144        g_free (servant);
145}
146
147static EvolutionShellComponentClient *
148component_client_from_ShellComponentListener_servant (PortableServer_Servant servant)
149{
150        ShellComponentListenerServant *listener_servant;
151
152        listener_servant = (ShellComponentListenerServant *) servant;
153        return listener_servant->component_client;
154}
155
156static EvolutionShellComponentResult
157result_from_async_corba_result (GNOME_Evolution_ShellComponentListener_Result async_corba_result)
158{
159        switch (async_corba_result) {
160        case GNOME_Evolution_ShellComponentListener_OK:
161                return EVOLUTION_SHELL_COMPONENT_OK;
162        case GNOME_Evolution_ShellComponentListener_CANCEL:
163                return EVOLUTION_SHELL_COMPONENT_CANCEL;
164        case GNOME_Evolution_ShellComponentListener_UNSUPPORTED_OPERATION:
165                return EVOLUTION_SHELL_COMPONENT_UNSUPPORTEDOPERATION;
166        case GNOME_Evolution_ShellComponentListener_EXISTS:
167                return EVOLUTION_SHELL_COMPONENT_EXISTS;
168        case GNOME_Evolution_ShellComponentListener_INVALID_URI:
169                return EVOLUTION_SHELL_COMPONENT_INVALIDURI;
170        case GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED:
171                return EVOLUTION_SHELL_COMPONENT_PERMISSIONDENIED;
172        case GNOME_Evolution_ShellComponentListener_HAS_SUBFOLDERS:
173                return EVOLUTION_SHELL_COMPONENT_HASSUBFOLDERS;
174        case GNOME_Evolution_ShellComponentListener_NO_SPACE:
175                return EVOLUTION_SHELL_COMPONENT_NOSPACE;
176        default:
177                return EVOLUTION_SHELL_COMPONENT_UNKNOWNERROR;
178        }
179}
180
181static void
182impl_ShellComponentListener_report_result (PortableServer_Servant servant,
183                                           const GNOME_Evolution_ShellComponentListener_Result result,
184                                           CORBA_Environment *ev)
185{
186        EvolutionShellComponentClient *component_client;
187
188        component_client = component_client_from_ShellComponentListener_servant (servant);
189        dispatch_callback (component_client, result_from_async_corba_result (result));
190}
191
192static void
193ShellComponentListener_vepv_initialize (void)
194{
195        ShellComponentListener_base_epv._private = NULL;
196        ShellComponentListener_base_epv.finalize = NULL;
197        ShellComponentListener_base_epv.default_POA = NULL;
198
199        ShellComponentListener_epv.notifyResult = impl_ShellComponentListener_report_result;
200
201        ShellComponentListener_vepv._base_epv = & ShellComponentListener_base_epv;
202        ShellComponentListener_vepv.GNOME_Evolution_ShellComponentListener_epv = & ShellComponentListener_epv;
203
204        ShellComponentListener_vepv_initialized = TRUE;
205}
206
207static void
208create_listener_interface (EvolutionShellComponentClient *shell_component_client)
209{
210        EvolutionShellComponentClientPrivate *priv;
211        PortableServer_Servant listener_servant;
212        GNOME_Evolution_ShellComponentListener corba_interface;
213        CORBA_Environment ev;
214
215        priv = shell_component_client->priv;
216
217        listener_servant = create_ShellComponentListener_servant (shell_component_client);
218
219        CORBA_exception_init (&ev);
220
221        POA_GNOME_Evolution_ShellComponentListener__init (listener_servant, &ev);
222        if (ev._major != CORBA_NO_EXCEPTION) {
223                free_ShellComponentListener_servant (listener_servant);
224                return;
225        }
226
227        CORBA_free (PortableServer_POA_activate_object (bonobo_poa (), listener_servant, &ev));
228
229        corba_interface = PortableServer_POA_servant_to_reference (bonobo_poa (), listener_servant, &ev);
230        if (ev._major != CORBA_NO_EXCEPTION) {
231                corba_interface = CORBA_OBJECT_NIL;
232                free_ShellComponentListener_servant (listener_servant);
233        }
234
235        CORBA_exception_free (&ev);
236
237        priv->listener_servant   = listener_servant;
238        priv->listener_interface = corba_interface;
239}
240
241static void
242destroy_listener_interface (EvolutionShellComponentClient *client)
243{
244        EvolutionShellComponentClientPrivate *priv;
245        CORBA_Environment ev;
246        PortableServer_ObjectId *oid;
247
248        priv = client->priv;
249        CORBA_exception_init (&ev);
250
251        oid = PortableServer_POA_servant_to_id (bonobo_poa (), priv->listener_servant, &ev);
252        PortableServer_POA_deactivate_object (bonobo_poa (), oid, &ev);
253        POA_GNOME_Evolution_ShellComponentListener__fini (priv->listener_servant, &ev);
254        CORBA_free (oid);
255
256        CORBA_Object_release (priv->listener_interface, &ev);
257        free_ShellComponentListener_servant (priv->listener_servant);
258
259        CORBA_exception_free (&ev);
260}
261
262static void
263dispatch_callback (EvolutionShellComponentClient *shell_component_client,
264                   EvolutionShellComponentResult result)
265{
266        EvolutionShellComponentClientPrivate *priv;
267        EvolutionShellComponentClientCallback callback;
268        void *callback_data;
269
270        priv = shell_component_client->priv;
271
272        g_return_if_fail (priv->callback != NULL);
273        g_return_if_fail (priv->listener_servant != NULL);
274
275        /* Notice that we destroy the interface and reset the callback information before
276           dispatching the callback so that the callback can generate another request.  */
277
278        destroy_listener_interface (shell_component_client);
279
280        priv->listener_servant   = NULL;
281        priv->listener_interface = CORBA_OBJECT_NIL;
282
283        callback      = priv->callback;
284        callback_data = priv->callback_data;
285
286        priv->callback      = NULL;
287        priv->callback_data = NULL;
288
289        (* callback) (shell_component_client, result, callback_data);
290}
291
292
293/* GtkObject methods.  */
294
295static void
296impl_destroy (GtkObject *object)
297{
298        EvolutionShellComponentClient *shell_component_client;
299        EvolutionShellComponentClientPrivate *priv;
300        CORBA_Environment ev;
301
302        shell_component_client = EVOLUTION_SHELL_COMPONENT_CLIENT (object);
303        priv = shell_component_client->priv;
304
305        g_free (priv->id);
306
307        if (priv->callback != NULL)
308                dispatch_callback (shell_component_client, EVOLUTION_SHELL_COMPONENT_INTERRUPTED);
309
310        CORBA_exception_init (&ev);
311
312        if (priv->dnd_source_folder_interface != CORBA_OBJECT_NIL) {
313                Bonobo_Unknown_unref (priv->dnd_source_folder_interface, &ev);
314                CORBA_Object_release (priv->dnd_source_folder_interface, &ev);
315        }
316
317        if (priv->dnd_destination_folder_interface != CORBA_OBJECT_NIL) {
318                Bonobo_Unknown_unref (priv->dnd_destination_folder_interface, &ev);
319                CORBA_Object_release (priv->dnd_destination_folder_interface, &ev);
320        }
321
322        if (priv->offline_interface != CORBA_OBJECT_NIL) {
323                Bonobo_Unknown_unref (priv->offline_interface, &ev);
324                CORBA_Object_release (priv->offline_interface, &ev);
325        }
326
327        if (priv->listener_interface != CORBA_OBJECT_NIL)
328                destroy_listener_interface (shell_component_client);
329
330        CORBA_exception_free (&ev);
331
332        g_free (priv);
333
334        (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
335}
336
337
338static void
339class_init (EvolutionShellComponentClientClass *klass)
340{
341        GtkObjectClass *object_class;
342
343        object_class = GTK_OBJECT_CLASS (klass);
344        parent_class = gtk_type_class (PARENT_TYPE);
345
346        object_class->destroy = impl_destroy;
347}
348
349static void
350init (EvolutionShellComponentClient *shell_component_client)
351{
352        EvolutionShellComponentClientPrivate *priv;
353
354        priv = g_new (EvolutionShellComponentClientPrivate, 1);
355
356        priv->id                               = NULL;
357
358        priv->listener_interface               = CORBA_OBJECT_NIL;
359        priv->listener_servant                 = NULL;
360
361        priv->callback                         = NULL;
362        priv->callback_data                    = NULL;
363
364        priv->dnd_source_folder_interface      = CORBA_OBJECT_NIL;
365        priv->dnd_destination_folder_interface = CORBA_OBJECT_NIL;
366        priv->offline_interface                = CORBA_OBJECT_NIL;
367
368        shell_component_client->priv = priv;
369}
370
371
372/* Construction.  */
373
374void
375evolution_shell_component_client_construct (EvolutionShellComponentClient *shell_component_client,
376                                            const char *id,
377                                            CORBA_Object corba_object)
378{
379        EvolutionShellComponentClientPrivate *priv;
380
381        g_return_if_fail (shell_component_client != NULL);
382        g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
383        g_return_if_fail (corba_object != CORBA_OBJECT_NIL);
384
385        priv = shell_component_client->priv;
386        priv->id = g_strdup (id);
387
388        bonobo_object_client_construct (BONOBO_OBJECT_CLIENT (shell_component_client),
389                                        corba_object);
390}
391
392EvolutionShellComponentClient *
393evolution_shell_component_client_new (const char *id,
394                                      CORBA_Environment *ev)
395{
396        EvolutionShellComponentClient *new;
397        CORBA_Object corba_object;
398        CORBA_Environment *local_ev;
399        CORBA_Environment static_ev;
400
401        g_return_val_if_fail (id != NULL, NULL);
402
403        CORBA_exception_init (&static_ev);
404
405        if (ev == NULL)
406                local_ev = &static_ev;
407        else
408                local_ev = ev;
409
410        corba_object = oaf_activate_from_id ((char *) id, 0, NULL, ev);
411        if (ev->_major != CORBA_NO_EXCEPTION || corba_object == NULL) {
412                CORBA_exception_free (&static_ev);
413                return NULL;
414        }
415
416        CORBA_exception_free (&static_ev);
417
418        new = gtk_type_new (evolution_shell_component_client_get_type ());
419        evolution_shell_component_client_construct (new, id, corba_object);
420
421        return new;
422}
423
424
425/* Properties.  */
426
427const char *
428evolution_shell_component_client_get_id (EvolutionShellComponentClient *shell_component_client)
429{
430        EvolutionShellComponentClientPrivate *priv;
431
432        g_return_val_if_fail (shell_component_client != NULL, NULL);
433        g_return_val_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client), NULL);
434
435        priv = shell_component_client->priv;
436
437        return priv->id;
438}
439
440
441/* Querying DnD interfaces.  */
442
443GNOME_Evolution_ShellComponentDnd_SourceFolder
444evolution_shell_component_client_get_dnd_source_interface (EvolutionShellComponentClient *shell_component_client)
445{
446        EvolutionShellComponentClientPrivate *priv;
447        GNOME_Evolution_ShellComponentDnd_SourceFolder interface;
448        CORBA_Environment ev;
449
450        g_return_val_if_fail (shell_component_client != NULL, CORBA_OBJECT_NIL);
451        g_return_val_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client), CORBA_OBJECT_NIL);
452
453        priv = shell_component_client->priv;
454
455        if (priv->dnd_source_folder_interface != CORBA_OBJECT_NIL)
456                return priv->dnd_source_folder_interface;
457
458        CORBA_exception_init (&ev);
459
460        interface = Bonobo_Unknown_queryInterface (bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client)),
461                                                   "IDL:GNOME/Evolution/ShellComponentDnd/SourceFolder:1.0",
462                                                   &ev);
463
464        if (ev._major != CORBA_NO_EXCEPTION)
465                interface = CORBA_OBJECT_NIL;
466
467        CORBA_exception_free (&ev);
468
469        priv->dnd_source_folder_interface = interface;
470        return interface;
471}
472
473GNOME_Evolution_ShellComponentDnd_DestinationFolder
474evolution_shell_component_client_get_dnd_destination_interface (EvolutionShellComponentClient *shell_component_client)
475{
476        EvolutionShellComponentClientPrivate *priv;
477        GNOME_Evolution_ShellComponentDnd_DestinationFolder interface;
478        CORBA_Environment ev;
479
480        g_return_val_if_fail (shell_component_client != NULL, CORBA_OBJECT_NIL);
481        g_return_val_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client), CORBA_OBJECT_NIL);
482
483        priv = shell_component_client->priv;
484
485        if (priv->dnd_destination_folder_interface != CORBA_OBJECT_NIL)
486                return priv->dnd_destination_folder_interface;
487
488        CORBA_exception_init (&ev);
489
490        interface = Bonobo_Unknown_queryInterface (bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client)),
491                                                   "IDL:GNOME/Evolution/ShellComponentDnd/DestinationFolder:1.0",
492                                                   &ev);
493
494        if (ev._major != CORBA_NO_EXCEPTION)
495                interface = CORBA_OBJECT_NIL;
496
497        CORBA_exception_free (&ev);
498
499        priv->dnd_destination_folder_interface = interface;
500        return interface;
501}
502
503
504/* Querying the offline interface.  */
505
506GNOME_Evolution_Offline
507evolution_shell_component_client_get_offline_interface (EvolutionShellComponentClient *shell_component_client)
508{
509        EvolutionShellComponentClientPrivate *priv;
510        GNOME_Evolution_Offline interface;
511        CORBA_Environment ev;
512
513        priv = shell_component_client->priv;
514
515        if (priv->offline_interface != CORBA_OBJECT_NIL)
516                return priv->offline_interface;
517
518        CORBA_exception_init (&ev);
519
520        interface = Bonobo_Unknown_queryInterface (bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client)),
521                                                   "IDL:GNOME/Evolution/Offline:1.0",
522                                                   &ev);
523
524        if (ev._major != CORBA_NO_EXCEPTION)
525                interface = CORBA_OBJECT_NIL;
526
527        CORBA_exception_free (&ev);
528
529        priv->offline_interface = interface;
530        return interface;
531}
532
533
534/* Synchronous operations.  */
535
536EvolutionShellComponentResult
537evolution_shell_component_client_set_owner (EvolutionShellComponentClient *shell_component_client,
538                                            GNOME_Evolution_Shell shell,
539                                            const char *evolution_homedir)
540{
541        EvolutionShellComponentResult result;
542        CORBA_Environment ev;
543
544        RETURN_ERROR_IF_FAIL (shell_component_client != NULL);
545        RETURN_ERROR_IF_FAIL (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
546        RETURN_ERROR_IF_FAIL (shell != CORBA_OBJECT_NIL);
547
548        CORBA_exception_init (&ev);
549
550        GNOME_Evolution_ShellComponent_setOwner (bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client)),
551                                            shell, evolution_homedir, &ev);
552
553        result = corba_exception_to_result (&ev);
554
555        if (result == EVOLUTION_SHELL_COMPONENT_OK && evolution_debug_log)
556                GNOME_Evolution_ShellComponent_debug (bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client)), evolution_debug_log, &ev);
557
558        CORBA_exception_free (&ev);
559
560        return result;
561}
562
563EvolutionShellComponentResult
564evolution_shell_component_client_unset_owner (EvolutionShellComponentClient *shell_component_client,
565                                              GNOME_Evolution_Shell shell)
566{
567        EvolutionShellComponentResult result;
568        GNOME_Evolution_ShellComponent corba_component;
569        CORBA_Environment ev;
570
571        RETURN_ERROR_IF_FAIL (shell_component_client != NULL);
572        RETURN_ERROR_IF_FAIL (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
573        RETURN_ERROR_IF_FAIL (shell != CORBA_OBJECT_NIL);
574
575        CORBA_exception_init (&ev);
576
577        corba_component = bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client));
578
579        GNOME_Evolution_ShellComponent_unsetOwner (corba_component, &ev);
580
581        result = corba_exception_to_result (&ev);
582
583        CORBA_exception_free (&ev);
584
585        return result;
586}
587
588EvolutionShellComponentResult
589evolution_shell_component_client_create_view (EvolutionShellComponentClient *shell_component_client,
590                                              BonoboUIComponent *uih,
591                                              const char *physical_uri,
592                                              const char *type_string,
593                                              const char *view_info,
594                                              BonoboControl **control_return)
595{
596        EvolutionShellComponentResult result;
597        CORBA_Environment ev;
598        GNOME_Evolution_ShellComponent corba_component;
599        Bonobo_Control corba_control;
600
601        RETURN_ERROR_IF_FAIL (shell_component_client != NULL);
602        RETURN_ERROR_IF_FAIL (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
603        RETURN_ERROR_IF_FAIL (uih != NULL);
604        RETURN_ERROR_IF_FAIL (BONOBO_IS_UI_COMPONENT (uih));
605        RETURN_ERROR_IF_FAIL (physical_uri != NULL);
606        RETURN_ERROR_IF_FAIL (type_string != NULL);
607        RETURN_ERROR_IF_FAIL (view_info != NULL);
608        RETURN_ERROR_IF_FAIL (control_return != NULL);
609
610        CORBA_exception_init (&ev);
611
612        corba_component = bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client));
613        corba_control = GNOME_Evolution_ShellComponent_createView (corba_component, physical_uri, type_string, view_info, &ev);
614
615        result = corba_exception_to_result (&ev);
616
617        if (result != EVOLUTION_SHELL_COMPONENT_OK) {
618                *control_return = NULL;
619        } else {
620                Bonobo_UIContainer corba_uih;
621
622                corba_uih = bonobo_object_corba_objref (BONOBO_OBJECT (uih));
623                *control_return = BONOBO_CONTROL (bonobo_widget_new_control_from_objref (corba_control,
624                                                                                         corba_uih));
625        }
626
627        CORBA_exception_free (&ev);
628
629        return result;
630}
631
632EvolutionShellComponentResult
633evolution_shell_component_client_handle_external_uri  (EvolutionShellComponentClient *shell_component_client,
634                                                       const char *uri)
635{
636        GNOME_Evolution_ShellComponent corba_component;
637        CORBA_Environment ev;
638        EvolutionShellComponentResult result;
639
640        RETURN_ERROR_IF_FAIL (shell_component_client != NULL);
641        RETURN_ERROR_IF_FAIL (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
642        RETURN_ERROR_IF_FAIL (uri != NULL);
643
644        CORBA_exception_init (&ev);
645
646        corba_component = bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client));
647        GNOME_Evolution_ShellComponent_handleExternalURI (corba_component, uri, &ev);
648
649        result = corba_exception_to_result (&ev);
650
651        CORBA_exception_free (&ev);
652
653        return result;
654}
655
656
657/* Asyncronous operations.  */
658
659void
660evolution_shell_component_client_async_create_folder (EvolutionShellComponentClient *shell_component_client,
661                                                      const char *physical_uri,
662                                                      const char *type,
663                                                      EvolutionShellComponentClientCallback callback,
664                                                      void *data)
665{
666        EvolutionShellComponentClientPrivate *priv;
667        GNOME_Evolution_ShellComponent corba_shell_component;
668        CORBA_Environment ev;
669
670        g_return_if_fail (shell_component_client != NULL);
671        g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
672        g_return_if_fail (physical_uri != NULL);
673        g_return_if_fail (type != NULL);
674        g_return_if_fail (callback != NULL);
675
676        priv = shell_component_client->priv;
677
678        if (priv->callback != NULL) {
679                (* callback) (shell_component_client, EVOLUTION_SHELL_COMPONENT_BUSY, data);
680                return;
681        }
682
683        create_listener_interface (shell_component_client);
684
685        CORBA_exception_init (&ev);
686
687        corba_shell_component = bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client));
688
689        priv->callback      = callback;
690        priv->callback_data = data;
691
692        GNOME_Evolution_ShellComponent_createFolderAsync (corba_shell_component,
693                                                          priv->listener_interface,
694                                                          physical_uri, type,
695                                                          &ev);
696
697        if (ev._major != CORBA_NO_EXCEPTION && priv->callback != NULL) {
698                (* callback) (shell_component_client,
699                              shell_component_result_from_corba_exception (&ev),
700                              data);
701                priv->callback = NULL;
702                priv->callback_data = NULL;
703        }
704
705        CORBA_exception_free (&ev);
706}
707
708void
709evolution_shell_component_client_async_remove_folder (EvolutionShellComponentClient *shell_component_client,
710                                                      const char *physical_uri,
711                                                      const char *type,
712                                                      EvolutionShellComponentClientCallback callback,
713                                                      void *data)
714{
715        EvolutionShellComponentClientPrivate *priv;
716        GNOME_Evolution_ShellComponent corba_shell_component;
717        CORBA_Environment ev;
718
719        g_return_if_fail (shell_component_client != NULL);
720        g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
721        g_return_if_fail (physical_uri != NULL);
722        g_return_if_fail (callback != NULL);
723
724        priv = shell_component_client->priv;
725
726        if (priv->callback != NULL) {
727                (* callback) (shell_component_client, EVOLUTION_SHELL_COMPONENT_BUSY, data);
728                return;
729        }
730
731        create_listener_interface (shell_component_client);
732
733        CORBA_exception_init (&ev);
734
735        corba_shell_component = bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client));
736
737        priv->callback = callback;
738        priv->callback_data = data;
739
740        GNOME_Evolution_ShellComponent_removeFolderAsync (corba_shell_component,
741                                                          priv->listener_interface,
742                                                          physical_uri,
743                                                          type,
744                                                          &ev);
745
746        if (ev._major != CORBA_NO_EXCEPTION && priv->callback != NULL) {
747                (* callback) (shell_component_client,
748                              shell_component_result_from_corba_exception (&ev),
749                              data);
750                priv->callback = NULL;
751                priv->callback_data = NULL;
752        }
753
754        CORBA_exception_free (&ev);
755}
756
757void
758evolution_shell_component_client_async_xfer_folder (EvolutionShellComponentClient *shell_component_client,
759                                                    const char *source_physical_uri,
760                                                    const char *destination_physical_uri,
761                                                    const char *type,
762                                                    gboolean remove_source,
763                                                    EvolutionShellComponentClientCallback callback,
764                                                    void *data)
765{
766        EvolutionShellComponentClientPrivate *priv;
767        GNOME_Evolution_ShellComponent corba_shell_component;
768        CORBA_Environment ev;
769       
770        g_return_if_fail (shell_component_client != NULL);
771        g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
772        g_return_if_fail (source_physical_uri != NULL);
773        g_return_if_fail (destination_physical_uri != NULL);
774        g_return_if_fail (data != NULL);
775
776        priv = shell_component_client->priv;
777
778        if (priv->callback != NULL) {
779                (* callback) (shell_component_client, EVOLUTION_SHELL_COMPONENT_BUSY, data);
780                return;
781        }
782
783        create_listener_interface (shell_component_client);
784
785        CORBA_exception_init (&ev);
786
787        corba_shell_component = bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client));
788
789        priv->callback      = callback;
790        priv->callback_data = data;
791
792        GNOME_Evolution_ShellComponent_xferFolderAsync (corba_shell_component,
793                                                        priv->listener_interface,
794                                                        source_physical_uri,
795                                                        destination_physical_uri,
796                                                        type,
797                                                        remove_source,
798                                                        &ev);
799
800        if (ev._major != CORBA_NO_EXCEPTION && priv->callback != NULL) {
801                (* callback) (shell_component_client,
802                              shell_component_result_from_corba_exception (&ev),
803                              data);
804                priv->callback = NULL;
805                priv->callback_data = NULL;
806        }
807
808        CORBA_exception_free (&ev);
809}
810
811void
812evolution_shell_component_client_populate_folder_context_menu (EvolutionShellComponentClient *shell_component_client,
813                                                               BonoboUIContainer *container,
814                                                               const char *physical_uri,
815                                                               const char *type)
816{
817        Bonobo_UIContainer corba_container;
818        EvolutionShellComponentClientPrivate *priv;
819        GNOME_Evolution_ShellComponent corba_shell_component;
820        CORBA_Environment ev;
821
822        g_return_if_fail (shell_component_client != NULL);
823        g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
824        g_return_if_fail (physical_uri != NULL);
825        g_return_if_fail (type != NULL);
826
827        priv = shell_component_client->priv;
828
829        CORBA_exception_init (&ev);
830
831        corba_shell_component = bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client));
832        corba_container = bonobo_object_corba_objref (BONOBO_OBJECT (container));
833
834        GNOME_Evolution_ShellComponent_populateFolderContextMenu (corba_shell_component,
835                                                                  corba_container,
836                                                                  physical_uri,
837                                                                  type,
838                                                                  &ev);
839
840        CORBA_exception_free (&ev);
841}
842
843void
844evolution_shell_component_client_unpopulate_folder_context_menu (EvolutionShellComponentClient *shell_component_client,
845                                                                 BonoboUIContainer *container,
846                                                                 const char *physical_uri,
847                                                                 const char *type)
848{
849        Bonobo_UIContainer corba_container;
850        EvolutionShellComponentClientPrivate *priv;
851        GNOME_Evolution_ShellComponent corba_shell_component;
852        CORBA_Environment ev;
853
854        g_return_if_fail (shell_component_client != NULL);
855        g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
856        g_return_if_fail (physical_uri != NULL);
857        g_return_if_fail (type != NULL);
858
859        priv = shell_component_client->priv;
860
861        CORBA_exception_init (&ev);
862
863        corba_shell_component = bonobo_object_corba_objref (BONOBO_OBJECT (shell_component_client));
864        corba_container = bonobo_object_corba_objref (BONOBO_OBJECT (container));
865
866        GNOME_Evolution_ShellComponent_unpopulateFolderContextMenu (corba_shell_component,
867                                                                  corba_container,
868                                                                  physical_uri,
869                                                                  type,
870                                                                  &ev);
871
872        CORBA_exception_free (&ev);
873}
874
875
876void
877evolution_shell_component_client_request_quit (EvolutionShellComponentClient *shell_component_client,
878                                               EvolutionShellComponentClientCallback callback,
879                                               void *data)
880{
881        EvolutionShellComponentClientPrivate *priv;
882        GNOME_Evolution_ShellComponent corba_shell_component;
883        CORBA_Environment ev;
884
885        g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
886        g_return_if_fail (callback != NULL);
887
888        priv = shell_component_client->priv;
889
890        if (priv->callback != NULL) {
891                (* callback) (shell_component_client, EVOLUTION_SHELL_COMPONENT_BUSY, data);
892                return;
893        }
894
895        create_listener_interface (shell_component_client);
896
897        CORBA_exception_init (&ev);
898
899        corba_shell_component = BONOBO_OBJREF (shell_component_client);
900
901        priv->callback = callback;
902        priv->callback_data = data;
903
904        GNOME_Evolution_ShellComponent_requestQuit (corba_shell_component, priv->listener_interface, &ev);
905
906        if (ev._major != CORBA_NO_EXCEPTION && priv->callback != NULL) {
907                (* callback) (shell_component_client,
908                              shell_component_result_from_corba_exception (&ev),
909                              data);
910                priv->callback = NULL;
911                priv->callback_data = NULL;
912        }
913
914        CORBA_exception_free (&ev);
915}
916
917
918E_MAKE_TYPE (evolution_shell_component_client, "EvolutionShellComponentClient",
919             EvolutionShellComponentClient, class_init, init, PARENT_TYPE)
Note: See TracBrowser for help on using the repository browser.