1 /* Evolution calendar - Live search query listener convenience object
3 * Copyright (C) 2001 Ximian, Inc.
5 * Author: Federico Mena-Quintero <federico@ximian.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2 of the GNU Lesser General Public
9 * License as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "e-cal-marshal.h"
26 #include "e-cal-view-listener.h"
30 /* Private part of the CalViewListener structure */
32 struct _ECalViewListenerPrivate {
46 static guint signals[LAST_SIGNAL] = { 0 };
48 static BonoboObjectClass *parent_class;
50 /* CORBA method implementations */
51 /* FIXME This is duplicated from cal-listener.c */
52 static ECalendarStatus
53 convert_status (const GNOME_Evolution_Calendar_CallStatus status)
56 case GNOME_Evolution_Calendar_Success:
57 return E_CALENDAR_STATUS_OK;
58 case GNOME_Evolution_Calendar_RepositoryOffline:
59 return E_CALENDAR_STATUS_REPOSITORY_OFFLINE;
60 case GNOME_Evolution_Calendar_PermissionDenied:
61 return E_CALENDAR_STATUS_PERMISSION_DENIED;
62 case GNOME_Evolution_Calendar_ObjectNotFound:
63 return E_CALENDAR_STATUS_OBJECT_NOT_FOUND;
64 case GNOME_Evolution_Calendar_ObjectIdAlreadyExists:
65 return E_CALENDAR_STATUS_OBJECT_ID_ALREADY_EXISTS;
66 case GNOME_Evolution_Calendar_AuthenticationFailed:
67 return E_CALENDAR_STATUS_AUTHENTICATION_FAILED;
68 case GNOME_Evolution_Calendar_AuthenticationRequired:
69 return E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED;
70 case GNOME_Evolution_Calendar_UnknownUser:
71 return E_CALENDAR_STATUS_UNKNOWN_USER;
72 case GNOME_Evolution_Calendar_OtherError:
74 return E_CALENDAR_STATUS_OTHER_ERROR;
78 /* FIXME This is duplicated from cal-listener.c */
80 build_object_list (const GNOME_Evolution_Calendar_stringlist *seq)
86 for (i = 0; i < seq->_length; i++) {
89 comp = icalcomponent_new_from_string (seq->_buffer[i]);
93 list = g_list_prepend (list, comp);
100 build_id_list (const GNOME_Evolution_Calendar_CalObjIDSeq *seq)
106 for (i = 0; i < seq->_length; i++) {
107 GNOME_Evolution_Calendar_CalObjID *corba_id;
110 corba_id = &seq->_buffer[i];
111 id = g_new (ECalComponentId, 1);
113 id->uid = g_strdup (corba_id->uid);
114 id->rid = g_strdup (corba_id->rid);
116 list = g_list_prepend (list, id);
123 impl_notifyObjectsAdded (PortableServer_Servant servant,
124 const GNOME_Evolution_Calendar_stringlist *objects,
125 CORBA_Environment *ev)
127 ECalViewListener *ql;
128 ECalViewListenerPrivate *priv;
129 GList *object_list, *l;
131 ql = E_CAL_VIEW_LISTENER (bonobo_object_from_servant (servant));
134 object_list = build_object_list (objects);
136 g_signal_emit (G_OBJECT (ql), signals[OBJECTS_ADDED], 0, object_list);
138 for (l = object_list; l; l = l->next)
139 icalcomponent_free (l->data);
140 g_list_free (object_list);
144 impl_notifyObjectsModified (PortableServer_Servant servant,
145 const GNOME_Evolution_Calendar_stringlist *objects,
146 CORBA_Environment *ev)
148 ECalViewListener *ql;
149 ECalViewListenerPrivate *priv;
150 GList *object_list, *l;
152 ql = E_CAL_VIEW_LISTENER (bonobo_object_from_servant (servant));
155 object_list = build_object_list (objects);
157 g_signal_emit (G_OBJECT (ql), signals[OBJECTS_MODIFIED], 0, object_list);
159 for (l = object_list; l; l = l->next)
160 icalcomponent_free (l->data);
161 g_list_free (object_list);
165 impl_notifyObjectsRemoved (PortableServer_Servant servant,
166 const GNOME_Evolution_Calendar_CalObjIDSeq *ids,
167 CORBA_Environment *ev)
169 ECalViewListener *ql;
170 ECalViewListenerPrivate *priv;
173 ql = E_CAL_VIEW_LISTENER (bonobo_object_from_servant (servant));
176 id_list = build_id_list (ids);
178 g_signal_emit (G_OBJECT (ql), signals[OBJECTS_REMOVED], 0, id_list);
180 for (l = id_list; l; l = l->next)
181 e_cal_component_free_id (l->data);
182 g_list_free (id_list);
186 impl_notifyQueryProgress (PortableServer_Servant servant,
187 const CORBA_char *message,
188 const CORBA_short percent,
189 CORBA_Environment *ev)
191 ECalViewListener *ql;
192 ECalViewListenerPrivate *priv;
194 ql = E_CAL_VIEW_LISTENER (bonobo_object_from_servant (servant));
197 g_signal_emit (G_OBJECT (ql), signals[VIEW_PROGRESS], 0, message, percent);
201 impl_notifyQueryDone (PortableServer_Servant servant,
202 const GNOME_Evolution_Calendar_CallStatus status,
203 CORBA_Environment *ev)
205 ECalViewListener *ql;
206 ECalViewListenerPrivate *priv;
208 ql = E_CAL_VIEW_LISTENER (bonobo_object_from_servant (servant));
211 g_signal_emit (G_OBJECT (ql), signals[VIEW_DONE], 0, convert_status (status));
214 /* Object initialization function for the live search query listener */
216 e_cal_view_listener_init (ECalViewListener *ql, ECalViewListenerClass *class)
218 ECalViewListenerPrivate *priv;
220 priv = g_new0 (ECalViewListenerPrivate, 1);
224 /* Finalize handler for the live search query listener */
226 e_cal_view_listener_finalize (GObject *object)
228 ECalViewListener *ql;
229 ECalViewListenerPrivate *priv;
231 g_return_if_fail (object != NULL);
232 g_return_if_fail (E_IS_CAL_VIEW_LISTENER (object));
234 ql = E_CAL_VIEW_LISTENER (object);
239 if (G_OBJECT_CLASS (parent_class)->finalize)
240 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
243 /* Class initialization function for the live search query listener */
245 e_cal_view_listener_class_init (ECalViewListenerClass *klass)
247 GObjectClass *object_class;
249 object_class = (GObjectClass *) klass;
251 parent_class = g_type_class_peek_parent (klass);
253 object_class->finalize = e_cal_view_listener_finalize;
255 klass->epv.notifyObjectsAdded = impl_notifyObjectsAdded;
256 klass->epv.notifyObjectsModified = impl_notifyObjectsModified;
257 klass->epv.notifyObjectsRemoved = impl_notifyObjectsRemoved;
258 klass->epv.notifyQueryProgress = impl_notifyQueryProgress;
259 klass->epv.notifyQueryDone = impl_notifyQueryDone;
261 signals[OBJECTS_ADDED] =
262 g_signal_new ("objects_added",
263 G_TYPE_FROM_CLASS (klass),
265 G_STRUCT_OFFSET (ECalViewListenerClass, objects_added),
267 g_cclosure_marshal_VOID__POINTER,
268 G_TYPE_NONE, 1, G_TYPE_POINTER);
269 signals[OBJECTS_MODIFIED] =
270 g_signal_new ("objects_modified",
271 G_TYPE_FROM_CLASS (klass),
273 G_STRUCT_OFFSET (ECalViewListenerClass, objects_modified),
275 g_cclosure_marshal_VOID__POINTER,
276 G_TYPE_NONE, 1, G_TYPE_POINTER);
277 signals[OBJECTS_REMOVED] =
278 g_signal_new ("objects_removed",
279 G_TYPE_FROM_CLASS (klass),
281 G_STRUCT_OFFSET (ECalViewListenerClass, objects_removed),
283 g_cclosure_marshal_VOID__POINTER,
284 G_TYPE_NONE, 1, G_TYPE_POINTER);
285 signals[VIEW_PROGRESS] =
286 g_signal_new ("view_progress",
287 G_TYPE_FROM_CLASS (klass),
289 G_STRUCT_OFFSET (ECalViewListenerClass, view_progress),
291 e_cal_marshal_VOID__STRING_INT,
292 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT);
294 g_signal_new ("view_done",
295 G_TYPE_FROM_CLASS (klass),
297 G_STRUCT_OFFSET (ECalViewListenerClass, view_done),
299 g_cclosure_marshal_VOID__INT,
300 G_TYPE_NONE, 1, G_TYPE_INT);
303 BONOBO_TYPE_FUNC_FULL (ECalViewListener,
304 GNOME_Evolution_Calendar_CalViewListener,
306 e_cal_view_listener);
309 * e_cal_view_listener_new:
311 * Creates a new ECalViewListener object.
313 * Return value: the newly created ECalViewListener.
316 e_cal_view_listener_new (void)
318 ECalViewListener *ql;
320 ql = g_object_new (E_TYPE_CAL_VIEW_LISTENER, NULL);