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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* e-card-cursor.c: Implements card cursors.
*
* Author:
* Christopher James Lahey <clahey@helixcode.com.
*/
#include <config.h>
#include <gtk/gtk.h>
#include "addressbook.h"
#include "e-card-cursor.h"
struct _ECardCursorPrivate {
GNOME_Evolution_Addressbook_CardCursor corba_cursor;
};
/*
* A pointer to our parent object class
*/
static GtkObjectClass *parent_class;
/*
* Implemented GtkObject::destroy
*/
static void
e_card_cursor_destroy (GtkObject *object)
{
ECardCursor *cursor = E_CARD_CURSOR (object);
CORBA_Environment ev;
CORBA_exception_init (&ev);
GNOME_Evolution_Addressbook_CardCursor_unref( cursor->priv->corba_cursor, &ev );
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning("e_card_cursor_destroy: Exception unreffing "
"corba cursor.\n");
CORBA_exception_free (&ev);
CORBA_exception_init (&ev);
}
CORBA_Object_release (cursor->priv->corba_cursor, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning("e_card_cursor_destroy: Exception releasing "
"corba cursor.\n");
}
CORBA_exception_free (&ev);
if ( cursor->priv )
g_free ( cursor->priv );
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
/**
* e_card_cursor_get_length:
* @cursor: the #ECardCursor whose length is being queried
*
* Returns: the number of items the cursor references, or -1 there's
* an error.
*/
long
e_card_cursor_get_length (ECardCursor *cursor)
{
if ( cursor->priv->corba_cursor != CORBA_OBJECT_NIL ) {
CORBA_Environment ev;
long ret_val;
CORBA_exception_init (&ev);
ret_val = GNOME_Evolution_Addressbook_CardCursor_count (cursor->priv->corba_cursor, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning("e_card_cursor_get_length: Exception during "
"get_length corba call.\n");
ret_val = -1;
}
CORBA_exception_free (&ev);
return ret_val;
}
else
return -1;
}
/**
* e_card_cursor_get_nth:
* @cursor: an #ECardCursor object
* @n: the index of the item requested
*
* Gets an #ECard based on an index.
*
* Returns: a new #ECard on success, or %NULL on failure.
*/
ECard *
e_card_cursor_get_nth (ECardCursor *cursor,
const long n)
{
if ( cursor->priv->corba_cursor != CORBA_OBJECT_NIL ) {
CORBA_Environment en;
CORBA_char *vcard;
ECard *card;
CORBA_exception_init (&en);
vcard = GNOME_Evolution_Addressbook_CardCursor_getNth(cursor->priv->corba_cursor, n, &en);
if (en._major != CORBA_NO_EXCEPTION) {
g_warning("e_card_cursor_get_nth: Exception during "
"get_nth corba call.\n");
}
CORBA_exception_free (&en);
card = e_card_new (vcard);
CORBA_free(vcard);
return card;
}
else
return e_card_new("");
}
static void
e_card_cursor_class_init (ECardCursorClass *klass)
{
GtkObjectClass *object_class = (GtkObjectClass *) klass;
parent_class = gtk_type_class (gtk_object_get_type ());
object_class->destroy = e_card_cursor_destroy;
}
static void
e_card_cursor_init (ECardCursor *cursor)
{
cursor->priv = g_new(ECardCursorPrivate, 1);
cursor->priv->corba_cursor = CORBA_OBJECT_NIL;
}
GtkType
e_card_cursor_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"ECardCursor",
sizeof (ECardCursor),
sizeof (ECardCursorClass),
(GtkClassInitFunc) e_card_cursor_class_init,
(GtkObjectInitFunc) e_card_cursor_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gtk_object_get_type (), &info);
}
return type;
}
/**
* e_card_cursor_construct:
* @cursor: an #ECardCursor object
* @corba_cursor: an #GNOME_Evolution_Addressbook_CardCursor
*
* Wraps an #GNOME_Evolution_Addressbook_CardCursor object inside the #ECardCursor
* @cursor object.
*
* Returns: a new #ECardCursor on success, or %NULL on failure.
*/
ECardCursor *
e_card_cursor_construct (ECardCursor *cursor,
GNOME_Evolution_Addressbook_CardCursor corba_cursor)
{
CORBA_Environment ev;
g_return_val_if_fail (cursor != NULL, NULL);
g_return_val_if_fail (E_IS_CARD_CURSOR (cursor), NULL);
g_return_val_if_fail (corba_cursor != CORBA_OBJECT_NIL, NULL);
CORBA_exception_init (&ev);
/*
* Initialize cursor
*/
cursor->priv->corba_cursor = CORBA_Object_duplicate(corba_cursor, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning("e_card_cursor_construct: Exception duplicating "
"corba cursor.\n");
CORBA_exception_free (&ev);
CORBA_exception_init (&ev);
}
GNOME_Evolution_Addressbook_CardCursor_ref(cursor->priv->corba_cursor, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning("e_card_cursor_construct: Exception reffing "
"corba cursor.\n");
}
CORBA_exception_free (&ev);
/*
* Success: return the GtkType we were given
*/
return cursor;
}
/**
* e_card_cursor_new:
* @cursor: the #GNOME_Evolution_Addressbook_CardCursor to be wrapped
*
* Creates a new #ECardCursor, which wraps an #GNOME_Evolution_Addressbook_CardCursor
* object.
*
* Returns: a new #ECardCursor on success, or %NULL on failure.
*/
ECardCursor *
e_card_cursor_new (GNOME_Evolution_Addressbook_CardCursor corba_cursor)
{
ECardCursor *cursor;
cursor = gtk_type_new (e_card_cursor_get_type ());
return e_card_cursor_construct (cursor,
corba_cursor);
}
|