aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-client/query-listener.c
blob: 980b0a1ece8b3e1d27340eb46e45d4cc44d9134a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* Evolution calendar - Live search query listener convenience object
 *
 * Copyright (C) 2001 Ximian, Inc.
 *
 * Author: Federico Mena-Quintero <federico@ximian.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "query-listener.h"



/* Private part of the QueryListener structure */

struct _QueryListenerPrivate {
    /* Callbacks for notification and their closure data */
    QueryListenerObjUpdatedFn obj_updated_fn;
    QueryListenerObjRemovedFn obj_removed_fn;
    QueryListenerQueryDoneFn query_done_fn;
    QueryListenerEvalErrorFn eval_error_fn;
    gpointer fn_data;
};



static void query_listener_class_init (QueryListenerClass *class);
static void query_listener_init (QueryListener *ql);
static void query_listener_destroy (GtkObject *object);

static void impl_notifyObjUpdated (PortableServer_Servant servant,
                   GNOME_Evolution_Calendar_CalObjUID uid,
                   CORBA_boolean query_in_progress,
                   CORBA_long n_scanned,
                   CORBA_long total,
                   CORBA_Environment *ev);

static void impl_notifyObjRemoved (PortableServer_Servant servant,
                   GNOME_Evolution_Calendar_CalObjUID uid,
                   CORBA_Environment *ev);

static void impl_notifyQueryDone (PortableServer_Servant servant,
                  GNOME_Evolution_Calendar_QueryListener_QueryDoneStatus corba_status,
                  const CORBA_char *error_str,
                  CORBA_Environment *ev);

static void impl_notifyEvalError (PortableServer_Servant servant,
                  const CORBA_char *error_str,
                  CORBA_Environment *ev);

static BonoboXObjectClass *parent_class;



BONOBO_X_TYPE_FUNC_FULL (QueryListener,
             GNOME_Evolution_Calendar_QueryListener,
             BONOBO_X_OBJECT_TYPE,
             query_listener);

/* Class initialization function for the live search query listener */
static void
query_listener_class_init (QueryListenerClass *class)
{
    GtkObjectClass *object_class;

    object_class = (GtkObjectClass *) class;

    parent_class = gtk_type_class (BONOBO_X_OBJECT_TYPE);

    object_class->destroy = query_listener_destroy;

    class->epv.notifyObjUpdated = impl_notifyObjUpdated;
    class->epv.notifyObjRemoved = impl_notifyObjRemoved;
    class->epv.notifyQueryDone = impl_notifyQueryDone;
    class->epv.notifyEvalError = impl_notifyEvalError;
}

/* Object initialization function for the live search query listener */
static void
query_listener_init (QueryListener *ql)
{
    QueryListenerPrivate *priv;

    priv = g_new0 (QueryListenerPrivate, 1);
    ql->priv = priv;

    priv->obj_updated_fn = NULL;
    priv->obj_removed_fn = NULL;
    priv->query_done_fn = NULL;
    priv->eval_error_fn = NULL;
    priv->fn_data = NULL;
}

/* Destroy handler for the live search query listener */
static void
query_listener_destroy (GtkObject *object)
{
    QueryListener *ql;
    QueryListenerPrivate *priv;

    g_return_if_fail (object != NULL);
    g_return_if_fail (IS_QUERY_LISTENER (object));

    ql = QUERY_LISTENER (object);
    priv = ql->priv;

    priv->obj_updated_fn = NULL;
    priv->obj_removed_fn = NULL;
    priv->query_done_fn = NULL;
    priv->eval_error_fn = NULL;
    priv->fn_data = NULL;

    g_free (priv);
    ql->priv = NULL;

    if (GTK_OBJECT_CLASS (parent_class)->destroy)
        (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}



/* CORBA method implementations */

/* ::notifyObjUpdated() method */
static void
impl_notifyObjUpdated (PortableServer_Servant servant,
               GNOME_Evolution_Calendar_CalObjUID uid,
               CORBA_boolean query_in_progress,
               CORBA_long n_scanned,
               CORBA_long total,
               CORBA_Environment *ev)
{
    QueryListener *ql;
    QueryListenerPrivate *priv;

    ql = QUERY_LISTENER (bonobo_object_from_servant (servant));
    priv = ql->priv;

    g_assert (priv->obj_updated_fn != NULL);
    (* priv->obj_updated_fn) (ql, uid, query_in_progress, n_scanned, total, priv->fn_data);
}

/* ::notifyObjRemoved() method */
static void
impl_notifyObjRemoved (PortableServer_Servant servant,
               GNOME_Evolution_Calendar_CalObjUID uid,
               CORBA_Environment *ev)
{
    QueryListener *ql;
    QueryListenerPrivate *priv;

    ql = QUERY_LISTENER (bonobo_object_from_servant (servant));
    priv = ql->priv;

    g_assert (priv->obj_removed_fn != NULL);
    (* priv->obj_removed_fn) (ql, uid, priv->fn_data);
}

/* ::notifyQueryDone() method */
static void
impl_notifyQueryDone (PortableServer_Servant servant,
              GNOME_Evolution_Calendar_QueryListener_QueryDoneStatus corba_status,
              const CORBA_char *error_str,
              CORBA_Environment *ev)
{
    QueryListener *ql;
    QueryListenerPrivate *priv;

    ql = QUERY_LISTENER (bonobo_object_from_servant (servant));
    priv = ql->priv;

    g_assert (priv->query_done_fn != NULL);
    (* priv->query_done_fn) (ql, corba_status, error_str, priv->fn_data);
}

/* ::notifyEvalError() method */
static void
impl_notifyEvalError (PortableServer_Servant servant,
              const CORBA_char *error_str,
              CORBA_Environment *ev)
{
    QueryListener *ql;
    QueryListenerPrivate *priv;

    ql = QUERY_LISTENER (bonobo_object_from_servant (servant));
    priv = ql->priv;

    g_assert (priv->eval_error_fn != NULL);
    (* priv->eval_error_fn) (ql, error_str, priv->fn_data);
}



/**
 * query_listener_construct:
 * @ql: A query listener.
 * @obj_updated_fn: Callback to use when a component is updated in the query.
 * @obj_removed_fn: Callback to use when a component is removed from the query.
 * @query_done_fn: Callback to use when a query is done.
 * @eval_error_fn: Callback to use when an evaluation error happens during a query.
 * @fn_data: Closure data to pass to the callbacks.
 * 
 * Constructs a query listener by setting the callbacks it will use for
 * notification from the calendar server.
 * 
 * Return value: The same value as @ql.
 **/
QueryListener *
query_listener_construct (QueryListener *ql,
              QueryListenerObjUpdatedFn obj_updated_fn,
              QueryListenerObjRemovedFn obj_removed_fn,
              QueryListenerQueryDoneFn query_done_fn,
              QueryListenerEvalErrorFn eval_error_fn,
              gpointer fn_data)
{
    QueryListenerPrivate *priv;

    g_return_val_if_fail (ql != NULL, NULL);
    g_return_val_if_fail (IS_QUERY_LISTENER (ql), NULL);
    g_return_val_if_fail (obj_updated_fn != NULL, NULL);
    g_return_val_if_fail (obj_removed_fn != NULL, NULL);
    g_return_val_if_fail (query_done_fn != NULL, NULL);
    g_return_val_if_fail (eval_error_fn != NULL, NULL);

    priv = ql->priv;

    priv->obj_updated_fn = obj_updated_fn;
    priv->obj_removed_fn = obj_removed_fn;
    priv->query_done_fn = query_done_fn;
    priv->eval_error_fn = eval_error_fn;
    priv->fn_data = fn_data;

    return ql;
}

/**
 * query_listener_new:
 * @obj_updated_fn: Callback to use when a component is updated in the query.
 * @obj_removed_fn: Callback to use when a component is removed from the query.
 * @query_done_fn: Callback to use when a query is done.
 * @eval_error_fn: Callback to use when an evaluation error happens during a query.
 * @fn_data: Closure data to pass to the callbacks.
 * 
 * Creates a new query listener object.
 * 
 * Return value: A newly-created query listener object.
 **/
QueryListener *
query_listener_new (QueryListenerObjUpdatedFn obj_updated_fn,
            QueryListenerObjRemovedFn obj_removed_fn,
            QueryListenerQueryDoneFn query_done_fn,
            QueryListenerEvalErrorFn eval_error_fn,
            gpointer fn_data)
{
    QueryListener *ql;

    ql = gtk_type_new (QUERY_LISTENER_TYPE);

    return query_listener_construct (ql,
                     obj_updated_fn,
                     obj_removed_fn,
                     query_done_fn,
                     eval_error_fn,
                     fn_data);
}