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
|
/*
* Author:
* Nat Friedman (nat@helixcode.com)
*
* Copyright 2000, Helix Code, Inc.
*/
#include <gtk/gtksignal.h>
#include <db.h>
#include <pas-backend-file.h>
#include <pas-book.h>
static PASBackendClass *pas_backend_file_parent_class;
struct _PASBackendFilePrivate {
GList *clients;
gboolean loaded;
};
static void
pas_backend_file_process_create_card (PASBackend *backend,
PASBook *book,
PASRequest *req)
{
pas_book_respond_create (
book, Evolution_BookListener_Success);
g_free (req->vcard);
}
static void
pas_backend_file_process_remove_card (PASBackend *backend,
PASBook *book,
PASRequest *req)
{
pas_book_respond_remove (
book, Evolution_BookListener_Success);
g_free (req->id);
}
static void
pas_backend_file_process_modify_card (PASBackend *backend,
PASBook *book,
PASRequest *req)
{
pas_book_respond_modify (
book, Evolution_BookListener_Success);
g_free (req->vcard);
}
static void
pas_backend_file_process_check_connection (PASBackend *backend,
PASBook *book,
PASRequest *req)
{
pas_book_report_connection (book, TRUE);
}
static void
pas_backend_file_process_client_requests (PASBook *book)
{
PASBackend *backend;
PASRequest *req;
backend = pas_book_get_backend (book);
req = pas_book_pop_request (book);
if (req == NULL)
return;
switch (req->op) {
case CreateCard:
pas_backend_file_process_create_card (backend, book, req);
break;
case RemoveCard:
pas_backend_file_process_remove_card (backend, book, req);
break;
case ModifyCard:
pas_backend_file_process_modify_card (backend, book, req);
case CheckConnection:
pas_backend_file_process_check_connection (backend, book, req);
break;
}
g_free (req);
}
static void
pas_backend_file_book_destroy_cb (PASBook *book)
{
PASBackendFile *backend;
backend = PAS_BACKEND_FILE (pas_book_get_backend (book));
pas_backend_remove_client (PAS_BACKEND (backend), book);
}
static char *
pas_backend_file_get_vcard (PASBook *book, const char *id)
{
return g_strdup ("blah blah blah");
}
static char *
pas_backend_file_extract_path_from_uri (const char *uri)
{
g_assert (strncasecmp (uri, "file:", 5) == 0);
return g_strdup (uri + 5);
}
static void
pas_backend_file_load_uri (PASBackend *backend,
const char *uri)
{
PASBackendFile *bf = PAS_BACKEND_FILE (backend);
char *filename;
g_assert (bf->priv->loaded == FALSE);
filename = pas_backend_file_extract_path_from_uri (uri);
}
static void
pas_backend_file_add_client (PASBackend *backend,
Evolution_BookListener listener)
{
PASBackendFile *bf;
PASBook *book;
g_assert (backend != NULL);
g_assert (PAS_IS_BACKEND_FILE (backend));
bf = PAS_BACKEND_FILE (backend);
book = pas_book_new (
backend, listener,
pas_backend_file_get_vcard);
g_assert (book != NULL);
gtk_signal_connect (GTK_OBJECT (book), "destroy",
pas_backend_file_book_destroy_cb, NULL);
gtk_signal_connect (GTK_OBJECT (book), "requests_queued",
pas_backend_file_process_client_requests, NULL);
bf->priv->clients = g_list_prepend (
bf->priv->clients, book);
if (bf->priv->loaded) {
pas_book_respond_open (
book, Evolution_BookListener_Success);
} else {
/* Open the book. */
pas_book_respond_open (
book, Evolution_BookListener_Success);
}
}
static void
pas_backend_file_remove_client (PASBackend *backend,
PASBook *book)
{
g_return_if_fail (backend != NULL);
g_return_if_fail (PAS_IS_BACKEND (backend));
g_return_if_fail (book != NULL);
g_return_if_fail (PAS_IS_BOOK (book));
g_warning ("pas_backend_file_remove_client: Unimplemented!\n");
}
static gboolean
pas_backend_file_construct (PASBackendFile *backend)
{
g_assert (backend != NULL);
g_assert (PAS_IS_BACKEND_FILE (backend));
if (! pas_backend_construct (PAS_BACKEND (backend)))
return FALSE;
return TRUE;
}
/**
* pas_backend_file_new:
*/
PASBackend *
pas_backend_file_new (void)
{
PASBackendFile *backend;
backend = gtk_type_new (pas_backend_file_get_type ());
if (! pas_backend_file_construct (backend)) {
gtk_object_unref (GTK_OBJECT (backend));
return NULL;
}
return PAS_BACKEND (backend);
}
static void
pas_backend_file_destroy (GtkObject *object)
{
GTK_OBJECT_CLASS (pas_backend_file_parent_class)->destroy (object);
}
static void
pas_backend_file_class_init (PASBackendFileClass *klass)
{
GtkObjectClass *object_class = (GtkObjectClass *) klass;
PASBackendClass *parent_class;
pas_backend_file_parent_class = gtk_type_class (pas_backend_get_type ());
parent_class = PAS_BACKEND_CLASS (klass);
/* Set the virtual methods. */
parent_class->load_uri = pas_backend_file_load_uri;
parent_class->add_client = pas_backend_file_add_client;
parent_class->remove_client = pas_backend_file_remove_client;
object_class->destroy = pas_backend_file_destroy;
}
static void
pas_backend_file_init (PASBackendFile *backend)
{
PASBackendFilePrivate *priv;
priv = g_new0 (PASBackendFilePrivate, 1);
priv->loaded = FALSE;
priv->clients = NULL;
backend->priv = priv;
}
/**
* pas_backend_file_get_type:
*/
GtkType
pas_backend_file_get_type (void)
{
static GtkType type = 0;
if (! type) {
GtkTypeInfo info = {
"PASBackendFile",
sizeof (PASBackendFile),
sizeof (PASBackendFileClass),
(GtkClassInitFunc) pas_backend_file_class_init,
(GtkObjectInitFunc) pas_backend_file_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (pas_backend_get_type (), &info);
}
return type;
}
|