source: trunk/third/evolution/shell/evolution-storage-set-view-listener.c @ 18142

Revision 18142, 8.2 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-storage-set-view-listener.c
3 *
4 * Copyright (C) 2000  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 <gtk/gtksignal.h>
28#include <bonobo/bonobo-main.h>
29#include <gal/util/e-util.h>
30
31#include "evolution-storage-set-view-listener.h"
32
33
34#define PARENT_TYPE gtk_object_get_type ()
35static GtkObjectClass *parent_class = NULL;
36
37struct _EvolutionStorageSetViewListenerPrivate {
38        GNOME_Evolution_StorageSetViewListener corba_listener;
39        EvolutionStorageSetViewListenerServant *servant;
40};
41
42enum {
43        FOLDER_SELECTED,
44        FOLDER_TOGGLED,
45        LAST_SIGNAL
46};
47static guint signals[LAST_SIGNAL] = { 0 };
48
49
50/* Evolution::StorageSetViewListener implementation.  */
51
52static POA_GNOME_Evolution_StorageSetViewListener__vepv my_GNOME_Evolution_StorageSetViewListener_vepv;
53
54static EvolutionStorageSetViewListener *
55gtk_object_from_servant (PortableServer_Servant servant)
56{
57        EvolutionStorageSetViewListenerServant *my_servant;
58
59        my_servant = (EvolutionStorageSetViewListenerServant *) servant;
60        return my_servant->gtk_object;
61}
62
63static void
64impl_GNOME_Evolution_StorageSetViewListener_notifyFolderSelected (PortableServer_Servant servant,
65                                                       const CORBA_char *uri,
66                                                       CORBA_Environment *ev)
67{
68        EvolutionStorageSetViewListener *listener;
69
70        listener = gtk_object_from_servant (servant);
71
72        gtk_signal_emit (GTK_OBJECT (listener), signals[FOLDER_SELECTED], uri);
73}
74
75static void
76impl_GNOME_Evolution_StorageSetViewListener_notifyFolderToggled (PortableServer_Servant servant,
77                                                                 CORBA_Environment *ev)
78{
79        EvolutionStorageSetViewListener *listener;
80
81        listener = gtk_object_from_servant (servant);
82
83        gtk_signal_emit (GTK_OBJECT (listener), signals[FOLDER_TOGGLED]);
84}
85
86static EvolutionStorageSetViewListenerServant *
87create_servant (EvolutionStorageSetViewListener *listener)
88{
89        EvolutionStorageSetViewListenerServant *servant;
90        POA_GNOME_Evolution_StorageSetViewListener *corba_servant;
91        CORBA_Environment ev;
92
93        CORBA_exception_init (&ev);
94
95        servant = g_new0 (EvolutionStorageSetViewListenerServant, 1);
96        corba_servant = (POA_GNOME_Evolution_StorageSetViewListener *) servant;
97
98        corba_servant->vepv = &my_GNOME_Evolution_StorageSetViewListener_vepv;
99        POA_GNOME_Evolution_StorageSetViewListener__init ((PortableServer_Servant) corba_servant, &ev);
100        if (ev._major != CORBA_NO_EXCEPTION) {
101                g_free (servant);
102                CORBA_exception_free (&ev);
103                return NULL;
104        }
105
106        servant->gtk_object = listener;
107
108        CORBA_exception_free (&ev);
109
110        return servant;
111}
112
113static GNOME_Evolution_StorageSetViewListener
114activate_servant (EvolutionStorageSetViewListener *listener,
115                  POA_GNOME_Evolution_StorageSetViewListener *servant)
116{
117        GNOME_Evolution_StorageSetViewListener corba_object;
118        CORBA_Environment ev;
119
120        CORBA_exception_init (&ev);
121
122        CORBA_free (PortableServer_POA_activate_object (bonobo_poa (), servant, &ev));
123
124        corba_object = PortableServer_POA_servant_to_reference (bonobo_poa(), servant, &ev);
125
126        if (ev._major == CORBA_NO_EXCEPTION && ! CORBA_Object_is_nil (corba_object, &ev)) {
127                CORBA_exception_free (&ev);
128                return corba_object;
129        }
130
131        CORBA_exception_free (&ev);
132
133        return CORBA_OBJECT_NIL;
134}
135
136
137static void
138impl_destroy (GtkObject *object)
139{
140        EvolutionStorageSetViewListener *listener;
141        EvolutionStorageSetViewListenerPrivate *priv;
142        CORBA_Environment ev;
143
144        listener = EVOLUTION_STORAGE_SET_VIEW_LISTENER (object);
145        priv = listener->priv;
146
147        CORBA_exception_init (&ev);
148
149        if (priv->corba_listener != CORBA_OBJECT_NIL)
150                CORBA_Object_release (priv->corba_listener, &ev);
151
152        if (priv->servant != NULL) {
153                PortableServer_ObjectId *object_id;
154
155                object_id = PortableServer_POA_servant_to_id (bonobo_poa(), priv->servant, &ev);
156                PortableServer_POA_deactivate_object (bonobo_poa (), object_id, &ev);
157                CORBA_free (object_id);
158
159                POA_GNOME_Evolution_StorageSetViewListener__fini (priv->servant, &ev);
160        }
161
162        CORBA_exception_free (&ev);
163
164        g_free (priv);
165
166        if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
167                (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
168}
169
170
171static void
172corba_class_init (void)
173{
174        POA_GNOME_Evolution_StorageSetViewListener__vepv *vepv;
175        POA_GNOME_Evolution_StorageSetViewListener__epv *epv;
176        PortableServer_ServantBase__epv *base_epv;
177
178        base_epv = g_new0 (PortableServer_ServantBase__epv, 1);
179        base_epv->_private    = NULL;
180        base_epv->finalize    = NULL;
181        base_epv->default_POA = NULL;
182
183        epv = g_new0 (POA_GNOME_Evolution_StorageSetViewListener__epv, 1);
184        epv->notifyFolderSelected  = impl_GNOME_Evolution_StorageSetViewListener_notifyFolderSelected;
185        epv->notifyFolderToggled = impl_GNOME_Evolution_StorageSetViewListener_notifyFolderToggled;
186       
187        vepv = & my_GNOME_Evolution_StorageSetViewListener_vepv;
188        vepv->_base_epv                            = base_epv;
189        vepv->GNOME_Evolution_StorageSetViewListener_epv = epv;
190}
191
192static void
193class_init (EvolutionStorageSetViewListenerClass *klass)
194{
195        GtkObjectClass *object_class;
196
197        object_class = GTK_OBJECT_CLASS (klass);
198        object_class->destroy = impl_destroy;
199
200        parent_class = gtk_type_class (gtk_object_get_type ());
201
202        signals[FOLDER_SELECTED] = gtk_signal_new ("folder_selected",
203                                                   GTK_RUN_FIRST,
204                                                   object_class->type,
205                                                   GTK_SIGNAL_OFFSET (EvolutionStorageSetViewListenerClass, folder_selected),
206                                                   gtk_marshal_NONE__STRING,
207                                                   GTK_TYPE_NONE, 1,
208                                                   GTK_TYPE_STRING);
209        signals[FOLDER_TOGGLED] = gtk_signal_new ("folder_toggled",
210                                                  GTK_RUN_FIRST,
211                                                  object_class->type,
212                                                  GTK_SIGNAL_OFFSET (EvolutionStorageSetViewListenerClass, folder_toggled),
213                                                  gtk_marshal_NONE__NONE,
214                                                  GTK_TYPE_NONE, 0);
215
216        gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
217
218        corba_class_init ();
219}
220
221static void
222init (EvolutionStorageSetViewListener *storage_set_view_listener)
223{
224        EvolutionStorageSetViewListenerPrivate *priv;
225
226        priv = g_new (EvolutionStorageSetViewListenerPrivate, 1);
227        priv->corba_listener = CORBA_OBJECT_NIL;
228
229        storage_set_view_listener->priv = priv;
230}
231
232
233void
234evolution_storage_set_view_listener_construct (EvolutionStorageSetViewListener *listener,
235                                               GNOME_Evolution_StorageSetViewListener corba_listener)
236{
237        EvolutionStorageSetViewListenerPrivate *priv;
238
239        g_return_if_fail (listener != NULL);
240        g_return_if_fail (EVOLUTION_IS_STORAGE_SET_VIEW_LISTENER (listener));
241        g_return_if_fail (corba_listener != CORBA_OBJECT_NIL);
242
243        priv = listener->priv;
244
245        g_return_if_fail (priv->corba_listener == CORBA_OBJECT_NIL);
246
247        priv->corba_listener = corba_listener;
248
249        GTK_OBJECT_UNSET_FLAGS (GTK_OBJECT (listener), GTK_FLOATING);
250}
251
252EvolutionStorageSetViewListener *
253evolution_storage_set_view_listener_new (void)
254{
255        EvolutionStorageSetViewListener *new;
256        EvolutionStorageSetViewListenerPrivate *priv;
257        GNOME_Evolution_StorageSetViewListener corba_listener;
258
259        new = gtk_type_new (evolution_storage_set_view_listener_get_type ());
260        priv = new->priv;
261
262        priv->servant = create_servant (new);
263        corba_listener = activate_servant (new, (POA_GNOME_Evolution_StorageSetViewListener *) priv->servant);
264
265        evolution_storage_set_view_listener_construct (new, corba_listener);
266
267        return new;
268}
269
270GNOME_Evolution_StorageSetViewListener
271evolution_storage_set_view_listener_corba_objref (EvolutionStorageSetViewListener *listener)
272{
273        EvolutionStorageSetViewListenerPrivate *priv;
274
275        g_return_val_if_fail (listener != NULL, CORBA_OBJECT_NIL);
276        g_return_val_if_fail (EVOLUTION_IS_STORAGE_SET_VIEW_LISTENER (listener), CORBA_OBJECT_NIL);
277
278        priv = listener->priv;
279        return priv->corba_listener;
280}
281
282
283E_MAKE_TYPE (evolution_storage_set_view_listener, "EvolutionStorageSetViewListener", EvolutionStorageSetViewListener,
284             class_init, init, PARENT_TYPE)
Note: See TracBrowser for help on using the repository browser.