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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* The Evolution addressbook client object.
*
* Author:
* Nat Friedman (nat@ximian.com)
*
* Copyright 1999, 2000, Ximian, Inc.
*/
#include <config.h>
#include "addressbook.h"
#include "e-card-cursor.h"
#include "e-book-view-listener.h"
#include "e-book-view.h"
#include "e-book.h"
#include "e-book-marshal.h"
static GObjectClass *parent_class;
struct _EBookViewPrivate {
GNOME_Evolution_Addressbook_BookView corba_book_view;
EBook *book;
EBookViewListener *listener;
int responses_queued_id;
};
enum {
CARD_CHANGED,
CARD_REMOVED,
CARD_ADDED,
SEQUENCE_COMPLETE,
STATUS_MESSAGE,
LAST_SIGNAL
};
static guint e_book_view_signals [LAST_SIGNAL];
static void
add_book_iterator (gpointer data, gpointer closure)
{
ECard *card = E_CARD (data);
EBook *book = E_BOOK (closure);
e_card_set_book (card, book);
}
static void
e_book_view_do_added_event (EBookView *book_view,
EBookViewListenerResponse *resp)
{
if (book_view->priv->book)
g_list_foreach (resp->cards, add_book_iterator, book_view->priv->book);
g_signal_emit (book_view, e_book_view_signals [CARD_ADDED], 0,
resp->cards);
g_list_foreach (resp->cards, (GFunc) g_object_unref, NULL);
g_list_free (resp->cards);
}
static void
e_book_view_do_modified_event (EBookView *book_view,
EBookViewListenerResponse *resp)
{
if (book_view->priv->book)
g_list_foreach (resp->cards, add_book_iterator, book_view->priv->book);
g_signal_emit (book_view, e_book_view_signals [CARD_CHANGED], 0,
resp->cards);
g_list_foreach (resp->cards, (GFunc) g_object_unref, NULL);
g_list_free (resp->cards);
}
static void
e_book_view_do_removed_event (EBookView *book_view,
EBookViewListenerResponse *resp)
{
g_signal_emit (book_view, e_book_view_signals [CARD_REMOVED], 0,
resp->id);
g_free(resp->id);
}
static void
e_book_view_do_complete_event (EBookView *book_view,
EBookViewListenerResponse *resp)
{
g_signal_emit (book_view, e_book_view_signals [SEQUENCE_COMPLETE], 0,
resp->status);
}
static void
e_book_view_do_status_message_event (EBookView *book_view,
EBookViewListenerResponse *resp)
{
g_signal_emit (book_view, e_book_view_signals [STATUS_MESSAGE], 0,
resp->message);
g_free(resp->message);
}
/*
* Reading notices out of the EBookViewListener's queue.
*/
static void
e_book_view_check_listener_queue (EBookViewListener *listener, EBookView *book_view)
{
EBookViewListenerResponse *resp;
resp = e_book_view_listener_pop_response (listener);
if (resp == NULL)
return;
switch (resp->op) {
case CardAddedEvent:
e_book_view_do_added_event (book_view, resp);
break;
case CardModifiedEvent:
e_book_view_do_modified_event (book_view, resp);
break;
case CardRemovedEvent:
e_book_view_do_removed_event (book_view, resp);
break;
case SequenceCompleteEvent:
e_book_view_do_complete_event (book_view, resp);
break;
case StatusMessageEvent:
e_book_view_do_status_message_event (book_view, resp);
break;
default:
g_error ("EBookView: Unknown operation %d in listener queue!\n",
resp->op);
break;
}
g_free (resp);
}
static gboolean
e_book_view_construct (EBookView *book_view, GNOME_Evolution_Addressbook_BookView corba_book_view, EBookViewListener *listener)
{
CORBA_Environment ev;
g_return_val_if_fail (book_view != NULL, FALSE);
g_return_val_if_fail (E_IS_BOOK_VIEW (book_view), FALSE);
/*
* Copy in the corba_book_view.
*/
CORBA_exception_init (&ev);
book_view->priv->corba_book_view = bonobo_object_dup_ref(corba_book_view, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning ("e_book_view_construct: Exception duplicating corba_book_view.\n");
CORBA_exception_free (&ev);
book_view->priv->corba_book_view = NULL;
return FALSE;
}
CORBA_exception_free (&ev);
/*
* Create our local BookListener interface.
*/
book_view->priv->listener = listener;
book_view->priv->responses_queued_id = g_signal_connect (book_view->priv->listener, "responses_queued",
G_CALLBACK (e_book_view_check_listener_queue), book_view);
bonobo_object_ref(BONOBO_OBJECT(book_view->priv->listener));
return TRUE;
}
/**
* e_book_view_new:
*/
EBookView *
e_book_view_new (GNOME_Evolution_Addressbook_BookView corba_book_view, EBookViewListener *listener)
{
EBookView *book_view;
book_view = g_object_new (E_TYPE_BOOK_VIEW, NULL);
if (! e_book_view_construct (book_view, corba_book_view, listener)) {
g_object_unref (book_view);
return NULL;
}
return book_view;
}
void
e_book_view_set_book (EBookView *book_view, EBook *book)
{
g_return_if_fail (book_view && E_IS_BOOK_VIEW (book_view));
g_return_if_fail (book && E_IS_BOOK (book));
g_return_if_fail (book_view->priv->book == NULL);
book_view->priv->book = book;
g_object_ref (book);
}
void
e_book_view_stop (EBookView *book_view)
{
g_return_if_fail (book_view && E_IS_BOOK_VIEW (book_view));
if (book_view->priv->listener)
e_book_view_listener_stop (book_view->priv->listener);
}
static void
e_book_view_init (EBookView *book_view)
{
book_view->priv = g_new0 (EBookViewPrivate, 1);
book_view->priv->book = NULL;
book_view->priv->corba_book_view = CORBA_OBJECT_NIL;
book_view->priv->listener = NULL;
book_view->priv->responses_queued_id = 0;
}
static void
e_book_view_dispose (GObject *object)
{
EBookView *book_view = E_BOOK_VIEW (object);
CORBA_Environment ev;
if (book_view->priv) {
if (book_view->priv->book) {
g_object_unref (book_view->priv->book);
}
if (book_view->priv->corba_book_view) {
CORBA_exception_init (&ev);
bonobo_object_release_unref (book_view->priv->corba_book_view, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning ("EBookView: Exception while releasing BookView\n");
}
CORBA_exception_free (&ev);
}
if (book_view->priv->listener) {
if (book_view->priv->responses_queued_id)
g_signal_handler_disconnect(book_view->priv->listener,
book_view->priv->responses_queued_id);
e_book_view_listener_stop (book_view->priv->listener);
bonobo_object_unref (BONOBO_OBJECT(book_view->priv->listener));
}
g_free (book_view->priv);
book_view->priv = NULL;
}
G_OBJECT_CLASS(parent_class)->dispose (object);
}
static void
e_book_view_class_init (EBookViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_ref (G_TYPE_OBJECT);
e_book_view_signals [CARD_CHANGED] =
g_signal_new ("card_changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EBookViewClass, card_changed),
NULL, NULL,
e_book_marshal_NONE__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
e_book_view_signals [CARD_ADDED] =
g_signal_new ("card_added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EBookViewClass, card_added),
NULL, NULL,
e_book_marshal_NONE__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
e_book_view_signals [CARD_REMOVED] =
g_signal_new ("card_removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EBookViewClass, card_removed),
NULL, NULL,
e_book_marshal_NONE__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
e_book_view_signals [SEQUENCE_COMPLETE] =
g_signal_new ("sequence_complete",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EBookViewClass, sequence_complete),
NULL, NULL,
e_book_marshal_NONE__INT,
G_TYPE_NONE, 1,
G_TYPE_INT);
e_book_view_signals [STATUS_MESSAGE] =
g_signal_new ("status_message",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EBookViewClass, status_message),
NULL, NULL,
e_book_marshal_NONE__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
object_class->dispose = e_book_view_dispose;
}
/**
* e_book_view_get_type:
*/
GType
e_book_view_get_type (void)
{
static GType type = 0;
if (! type) {
GTypeInfo info = {
sizeof (EBookViewClass),
NULL, /* base_class_init */
NULL, /* base_class_finalize */
(GClassInitFunc) e_book_view_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (EBookView),
0, /* n_preallocs */
(GInstanceInitFunc) e_book_view_init
};
type = g_type_register_static (G_TYPE_OBJECT, "EBookView", &info, 0);
}
return type;
}
|