1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /* evolution-storage-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-listener.h" |
---|
32 | |
---|
33 | |
---|
34 | #define PARENT_TYPE gtk_object_get_type () |
---|
35 | static GtkObjectClass *parent_class = NULL; |
---|
36 | |
---|
37 | struct _EvolutionStorageListenerPrivate { |
---|
38 | GNOME_Evolution_StorageListener corba_objref; |
---|
39 | EvolutionStorageListenerServant *servant; |
---|
40 | }; |
---|
41 | |
---|
42 | |
---|
43 | enum { |
---|
44 | DESTROYED, |
---|
45 | NEW_FOLDER, |
---|
46 | UPDATE_FOLDER, |
---|
47 | REMOVED_FOLDER, |
---|
48 | HAS_SUBFOLDERS, |
---|
49 | LAST_SIGNAL |
---|
50 | }; |
---|
51 | static guint signals[LAST_SIGNAL] = { 0 }; |
---|
52 | |
---|
53 | |
---|
54 | /* Evolution::StorageListener implementation. */ |
---|
55 | |
---|
56 | static POA_GNOME_Evolution_StorageListener__vepv my_GNOME_Evolution_StorageListener_vepv; |
---|
57 | |
---|
58 | static EvolutionStorageListener * |
---|
59 | gtk_object_from_servant (PortableServer_Servant servant) |
---|
60 | { |
---|
61 | EvolutionStorageListenerServant *my_servant; |
---|
62 | |
---|
63 | my_servant = (EvolutionStorageListenerServant *) servant; |
---|
64 | return my_servant->gtk_object; |
---|
65 | } |
---|
66 | |
---|
67 | static void |
---|
68 | impl_GNOME_Evolution_StorageListener_notifyDestroyed (PortableServer_Servant servant, |
---|
69 | CORBA_Environment *ev) |
---|
70 | { |
---|
71 | EvolutionStorageListener *listener; |
---|
72 | EvolutionStorageListenerPrivate *priv; |
---|
73 | |
---|
74 | listener = gtk_object_from_servant (servant); |
---|
75 | priv = listener->priv; |
---|
76 | |
---|
77 | gtk_signal_emit (GTK_OBJECT (listener), signals[DESTROYED]); |
---|
78 | } |
---|
79 | |
---|
80 | static void |
---|
81 | impl_GNOME_Evolution_StorageListener_notifyFolderCreated (PortableServer_Servant servant, |
---|
82 | const CORBA_char *path, |
---|
83 | const GNOME_Evolution_Folder *folder, |
---|
84 | CORBA_Environment *ev) |
---|
85 | { |
---|
86 | EvolutionStorageListener *listener; |
---|
87 | EvolutionStorageListenerPrivate *priv; |
---|
88 | |
---|
89 | listener = gtk_object_from_servant (servant); |
---|
90 | priv = listener->priv; |
---|
91 | |
---|
92 | gtk_signal_emit (GTK_OBJECT (listener), signals[NEW_FOLDER], path, folder); |
---|
93 | } |
---|
94 | |
---|
95 | static void |
---|
96 | impl_GNOME_Evolution_StorageListener_notifyFolderUpdated (PortableServer_Servant servant, |
---|
97 | const CORBA_char *path, |
---|
98 | CORBA_long unread_count, |
---|
99 | CORBA_Environment *ev) |
---|
100 | { |
---|
101 | EvolutionStorageListener *listener; |
---|
102 | EvolutionStorageListenerPrivate *priv; |
---|
103 | |
---|
104 | listener = gtk_object_from_servant (servant); |
---|
105 | priv = listener->priv; |
---|
106 | |
---|
107 | gtk_signal_emit (GTK_OBJECT (listener), signals[UPDATE_FOLDER], path, |
---|
108 | unread_count); |
---|
109 | } |
---|
110 | |
---|
111 | static void |
---|
112 | impl_GNOME_Evolution_StorageListener_notifyFolderRemoved (PortableServer_Servant servant, |
---|
113 | const CORBA_char *path, |
---|
114 | CORBA_Environment *ev) |
---|
115 | { |
---|
116 | EvolutionStorageListener *listener; |
---|
117 | EvolutionStorageListenerPrivate *priv; |
---|
118 | |
---|
119 | listener = gtk_object_from_servant (servant); |
---|
120 | priv = listener->priv; |
---|
121 | |
---|
122 | gtk_signal_emit (GTK_OBJECT (listener), signals[REMOVED_FOLDER], path); |
---|
123 | } |
---|
124 | |
---|
125 | static void |
---|
126 | impl_GNOME_Evolution_StorageListener_notifyHasSubfolders (PortableServer_Servant servant, |
---|
127 | const CORBA_char *path, |
---|
128 | const CORBA_char *message, |
---|
129 | CORBA_Environment *ev) |
---|
130 | { |
---|
131 | EvolutionStorageListener *listener; |
---|
132 | EvolutionStorageListenerPrivate *priv; |
---|
133 | |
---|
134 | listener = gtk_object_from_servant (servant); |
---|
135 | priv = listener->priv; |
---|
136 | |
---|
137 | gtk_signal_emit (GTK_OBJECT (listener), signals[HAS_SUBFOLDERS], path, message); |
---|
138 | } |
---|
139 | |
---|
140 | static EvolutionStorageListenerServant * |
---|
141 | create_servant (EvolutionStorageListener *listener) |
---|
142 | { |
---|
143 | EvolutionStorageListenerServant *servant; |
---|
144 | POA_GNOME_Evolution_StorageListener *corba_servant; |
---|
145 | CORBA_Environment ev; |
---|
146 | |
---|
147 | CORBA_exception_init (&ev); |
---|
148 | |
---|
149 | servant = g_new0 (EvolutionStorageListenerServant, 1); |
---|
150 | corba_servant = (POA_GNOME_Evolution_StorageListener *) servant; |
---|
151 | |
---|
152 | corba_servant->vepv = &my_GNOME_Evolution_StorageListener_vepv; |
---|
153 | POA_GNOME_Evolution_StorageListener__init ((PortableServer_Servant) corba_servant, &ev); |
---|
154 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
155 | g_free (servant); |
---|
156 | CORBA_exception_free (&ev); |
---|
157 | return NULL; |
---|
158 | } |
---|
159 | |
---|
160 | servant->gtk_object = listener; |
---|
161 | |
---|
162 | CORBA_exception_free (&ev); |
---|
163 | |
---|
164 | return servant; |
---|
165 | } |
---|
166 | |
---|
167 | static GNOME_Evolution_StorageListener |
---|
168 | activate_servant (EvolutionStorageListener *listener, |
---|
169 | POA_GNOME_Evolution_StorageListener *servant) |
---|
170 | { |
---|
171 | GNOME_Evolution_StorageListener corba_object; |
---|
172 | CORBA_Environment ev; |
---|
173 | |
---|
174 | CORBA_exception_init (&ev); |
---|
175 | |
---|
176 | CORBA_free (PortableServer_POA_activate_object (bonobo_poa (), servant, &ev)); |
---|
177 | |
---|
178 | corba_object = PortableServer_POA_servant_to_reference (bonobo_poa(), servant, &ev); |
---|
179 | |
---|
180 | if (ev._major == CORBA_NO_EXCEPTION && ! CORBA_Object_is_nil (corba_object, &ev)) { |
---|
181 | CORBA_exception_free (&ev); |
---|
182 | return corba_object; |
---|
183 | } |
---|
184 | |
---|
185 | CORBA_exception_free (&ev); |
---|
186 | |
---|
187 | return CORBA_OBJECT_NIL; |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | /* GtkObject methods. */ |
---|
192 | |
---|
193 | static void |
---|
194 | impl_destroy (GtkObject *object) |
---|
195 | { |
---|
196 | EvolutionStorageListener *storage_listener; |
---|
197 | EvolutionStorageListenerPrivate *priv; |
---|
198 | CORBA_Environment ev; |
---|
199 | |
---|
200 | storage_listener = EVOLUTION_STORAGE_LISTENER (object); |
---|
201 | priv = storage_listener->priv; |
---|
202 | |
---|
203 | CORBA_exception_init (&ev); |
---|
204 | |
---|
205 | if (priv->corba_objref != CORBA_OBJECT_NIL) |
---|
206 | CORBA_Object_release (priv->corba_objref, &ev); |
---|
207 | |
---|
208 | if (priv->servant != NULL) { |
---|
209 | PortableServer_ObjectId *object_id; |
---|
210 | |
---|
211 | object_id = PortableServer_POA_servant_to_id (bonobo_poa(), priv->servant, &ev); |
---|
212 | PortableServer_POA_deactivate_object (bonobo_poa (), object_id, &ev); |
---|
213 | CORBA_free (object_id); |
---|
214 | |
---|
215 | POA_GNOME_Evolution_StorageListener__fini (priv->servant, &ev); |
---|
216 | } |
---|
217 | |
---|
218 | CORBA_exception_free (&ev); |
---|
219 | |
---|
220 | g_free (priv); |
---|
221 | |
---|
222 | (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | static void |
---|
227 | corba_class_init (void) |
---|
228 | { |
---|
229 | POA_GNOME_Evolution_StorageListener__vepv *vepv; |
---|
230 | POA_GNOME_Evolution_StorageListener__epv *epv; |
---|
231 | PortableServer_ServantBase__epv *base_epv; |
---|
232 | |
---|
233 | base_epv = g_new0 (PortableServer_ServantBase__epv, 1); |
---|
234 | base_epv->_private = NULL; |
---|
235 | base_epv->finalize = NULL; |
---|
236 | base_epv->default_POA = NULL; |
---|
237 | |
---|
238 | epv = g_new0 (POA_GNOME_Evolution_StorageListener__epv, 1); |
---|
239 | epv->notifyDestroyed = impl_GNOME_Evolution_StorageListener_notifyDestroyed; |
---|
240 | epv->notifyFolderCreated = impl_GNOME_Evolution_StorageListener_notifyFolderCreated; |
---|
241 | epv->notifyFolderUpdated = impl_GNOME_Evolution_StorageListener_notifyFolderUpdated; |
---|
242 | epv->notifyFolderRemoved = impl_GNOME_Evolution_StorageListener_notifyFolderRemoved; |
---|
243 | epv->notifyHasSubfolders = impl_GNOME_Evolution_StorageListener_notifyHasSubfolders; |
---|
244 | |
---|
245 | vepv = & my_GNOME_Evolution_StorageListener_vepv; |
---|
246 | vepv->_base_epv = base_epv; |
---|
247 | vepv->GNOME_Evolution_StorageListener_epv = epv; |
---|
248 | } |
---|
249 | |
---|
250 | static void |
---|
251 | class_init (EvolutionStorageListenerClass *klass) |
---|
252 | { |
---|
253 | GtkObjectClass *object_class; |
---|
254 | |
---|
255 | parent_class = gtk_type_class (PARENT_TYPE); |
---|
256 | |
---|
257 | object_class = GTK_OBJECT_CLASS (klass); |
---|
258 | object_class->destroy = impl_destroy; |
---|
259 | |
---|
260 | signals[DESTROYED] = gtk_signal_new ("destroyed", |
---|
261 | GTK_RUN_FIRST, |
---|
262 | object_class->type, |
---|
263 | GTK_SIGNAL_OFFSET (EvolutionStorageListenerClass, destroyed), |
---|
264 | gtk_marshal_NONE__NONE, |
---|
265 | GTK_TYPE_NONE, 0); |
---|
266 | |
---|
267 | signals[NEW_FOLDER] = gtk_signal_new ("new_folder", |
---|
268 | GTK_RUN_FIRST, |
---|
269 | object_class->type, |
---|
270 | GTK_SIGNAL_OFFSET (EvolutionStorageListenerClass, new_folder), |
---|
271 | gtk_marshal_NONE__POINTER_POINTER, |
---|
272 | GTK_TYPE_NONE, 2, |
---|
273 | GTK_TYPE_STRING, |
---|
274 | GTK_TYPE_POINTER); |
---|
275 | |
---|
276 | signals[UPDATE_FOLDER] = gtk_signal_new ("update_folder", |
---|
277 | GTK_RUN_FIRST, |
---|
278 | object_class->type, |
---|
279 | GTK_SIGNAL_OFFSET (EvolutionStorageListenerClass, update_folder), |
---|
280 | gtk_marshal_NONE__POINTER_INT, |
---|
281 | GTK_TYPE_NONE, 2, |
---|
282 | GTK_TYPE_STRING, |
---|
283 | GTK_TYPE_INT); |
---|
284 | |
---|
285 | signals[REMOVED_FOLDER] = gtk_signal_new ("removed_folder", |
---|
286 | GTK_RUN_FIRST, |
---|
287 | object_class->type, |
---|
288 | GTK_SIGNAL_OFFSET (EvolutionStorageListenerClass, removed_folder), |
---|
289 | gtk_marshal_NONE__POINTER, |
---|
290 | GTK_TYPE_NONE, 1, |
---|
291 | GTK_TYPE_STRING); |
---|
292 | |
---|
293 | signals[HAS_SUBFOLDERS] = gtk_signal_new ("has_subfolders", |
---|
294 | GTK_RUN_FIRST, |
---|
295 | object_class->type, |
---|
296 | GTK_SIGNAL_OFFSET (EvolutionStorageListenerClass, has_subfolders), |
---|
297 | gtk_marshal_NONE__POINTER_POINTER, |
---|
298 | GTK_TYPE_NONE, 2, |
---|
299 | GTK_TYPE_STRING, |
---|
300 | GTK_TYPE_STRING); |
---|
301 | |
---|
302 | gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); |
---|
303 | |
---|
304 | corba_class_init (); |
---|
305 | } |
---|
306 | |
---|
307 | static void |
---|
308 | init (EvolutionStorageListener *storage_listener) |
---|
309 | { |
---|
310 | EvolutionStorageListenerPrivate *priv; |
---|
311 | |
---|
312 | priv = g_new (EvolutionStorageListenerPrivate, 1); |
---|
313 | priv->corba_objref = CORBA_OBJECT_NIL; |
---|
314 | |
---|
315 | storage_listener->priv = priv; |
---|
316 | } |
---|
317 | |
---|
318 | |
---|
319 | void |
---|
320 | evolution_storage_listener_construct (EvolutionStorageListener *listener, |
---|
321 | GNOME_Evolution_StorageListener corba_objref) |
---|
322 | { |
---|
323 | EvolutionStorageListenerPrivate *priv; |
---|
324 | |
---|
325 | g_return_if_fail (listener != NULL); |
---|
326 | g_return_if_fail (corba_objref != CORBA_OBJECT_NIL); |
---|
327 | |
---|
328 | priv = listener->priv; |
---|
329 | |
---|
330 | g_return_if_fail (priv->corba_objref == CORBA_OBJECT_NIL); |
---|
331 | |
---|
332 | priv->corba_objref = corba_objref; |
---|
333 | |
---|
334 | GTK_OBJECT_UNSET_FLAGS (GTK_OBJECT (listener), GTK_FLOATING); |
---|
335 | } |
---|
336 | |
---|
337 | EvolutionStorageListener * |
---|
338 | evolution_storage_listener_new (void) |
---|
339 | { |
---|
340 | EvolutionStorageListener *new; |
---|
341 | EvolutionStorageListenerPrivate *priv; |
---|
342 | GNOME_Evolution_StorageListener corba_objref; |
---|
343 | |
---|
344 | new = gtk_type_new (evolution_storage_listener_get_type ()); |
---|
345 | priv = new->priv; |
---|
346 | |
---|
347 | priv->servant = create_servant (new); |
---|
348 | corba_objref = activate_servant (new, (POA_GNOME_Evolution_StorageListener *) priv->servant); |
---|
349 | |
---|
350 | evolution_storage_listener_construct (new, corba_objref); |
---|
351 | |
---|
352 | return new; |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | /** |
---|
357 | * evolution_storage_listener_corba_objref: |
---|
358 | * @listener: A pointer to an EvolutionStorageListener |
---|
359 | * |
---|
360 | * Get the CORBA object reference for the interface embedded in this GTK+ |
---|
361 | * object wrapper. |
---|
362 | * |
---|
363 | * Return value: A pointer to the CORBA object reference. |
---|
364 | **/ |
---|
365 | GNOME_Evolution_StorageListener |
---|
366 | evolution_storage_listener_corba_objref (EvolutionStorageListener *listener) |
---|
367 | { |
---|
368 | EvolutionStorageListenerPrivate *priv; |
---|
369 | |
---|
370 | g_return_val_if_fail (listener != NULL, CORBA_OBJECT_NIL); |
---|
371 | g_return_val_if_fail (EVOLUTION_IS_STORAGE_LISTENER (listener), CORBA_OBJECT_NIL); |
---|
372 | |
---|
373 | priv = listener->priv; |
---|
374 | return priv->corba_objref; |
---|
375 | } |
---|
376 | |
---|
377 | |
---|
378 | E_MAKE_TYPE (evolution_storage_listener, "EvolutionStorageListener", EvolutionStorageListener, |
---|
379 | class_init, init, PARENT_TYPE) |
---|