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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Authors:
* Chris Lahey <clahey@helixcode.com>
*
* Copyright (C) 2000 Helix Code, Inc.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include "e-select-names-manager.h"
#include "e-select-names-model.h"
#include "e-select-names-text-model.h"
#include "e-select-names.h"
#include <gal/e-text/e-entry.h>
/* Object argument IDs */
enum {
ARG_0,
ARG_CARD,
};
typedef struct {
char *id;
char *title;
ESelectNamesModel *model;
} ESelectNamesManagerSection;
typedef struct {
char *id;
EEntry *entry;
} ESelectNamesManagerEntry;
static void e_select_names_manager_init (ESelectNamesManager *manager);
static void e_select_names_manager_class_init (ESelectNamesManagerClass *klass);
static void e_select_names_manager_destroy (GtkObject *object);
static void e_select_names_manager_set_arg (GtkObject *object, GtkArg *arg, guint arg_id);
static void e_select_names_manager_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
/**
* e_select_names_manager_get_type:
* @void:
*
* Registers the &ESelectNamesManager class if necessary, and returns the type ID
* associated to it.
*
* Return value: The type ID of the &ESelectNamesManager class.
**/
GtkType
e_select_names_manager_get_type (void)
{
static GtkType manager_type = 0;
if (!manager_type) {
GtkTypeInfo manager_info = {
"ESelectNamesManager",
sizeof (ESelectNamesManager),
sizeof (ESelectNamesManagerClass),
(GtkClassInitFunc) e_select_names_manager_class_init,
(GtkObjectInitFunc) e_select_names_manager_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
manager_type = gtk_type_unique (gtk_object_get_type (), &manager_info);
}
return manager_type;
}
/**
* e_select_names_manager_new:
* @VCard: a string in vCard format
*
* Returns: a new #ESelectNamesManager that wraps the @VCard.
*/
ESelectNamesManager *
e_select_names_manager_new (void)
{
ESelectNamesManager *manager = E_SELECT_NAMES_MANAGER(gtk_type_new(e_select_names_manager_get_type()));
return manager;
}
static void
e_select_names_manager_class_init (ESelectNamesManagerClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS(klass);
gtk_object_add_arg_type ("ESelectNamesManager::card",
GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD);
object_class->destroy = e_select_names_manager_destroy;
object_class->get_arg = e_select_names_manager_get_arg;
object_class->set_arg = e_select_names_manager_set_arg;
}
/*
* ESelectNamesManager lifecycle management and vcard loading/saving.
*/
static void
e_select_names_manager_destroy (GtkObject *object)
{
ESelectNamesManager *manager;
manager = E_SELECT_NAMES_MANAGER (object);
gtk_object_unref(GTK_OBJECT(manager->sections));
gtk_object_unref(GTK_OBJECT(manager->entries));
}
/* Set_arg handler for the manager */
static void
e_select_names_manager_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
ESelectNamesManager *manager;
manager = E_SELECT_NAMES_MANAGER (object);
switch (arg_id) {
case ARG_CARD:
break;
default:
return;
}
}
/* Get_arg handler for the manager */
static void
e_select_names_manager_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
ESelectNamesManager *manager;
manager = E_SELECT_NAMES_MANAGER (object);
switch (arg_id) {
case ARG_CARD:
break;
default:
arg->type = GTK_TYPE_INVALID;
break;
}
}
static void *
section_copy(const void *sec, void *data)
{
const ESelectNamesManagerSection *section = sec;
ESelectNamesManagerSection *newsec;
newsec = g_new(ESelectNamesManagerSection, 1);
newsec->id = g_strdup(section->id);
newsec->title = g_strdup(section->title);
newsec->model = section->model;
if (newsec->model)
gtk_object_ref(GTK_OBJECT(newsec->model));
return newsec;
}
static void
section_free(void *sec, void *data)
{
ESelectNamesManagerSection *section = sec;
g_free(section->id);
g_free(section->title);
if (section->model)
gtk_object_unref(GTK_OBJECT(section->model));
g_free(section);
}
static void *
entry_copy(const void *ent, void *data)
{
const ESelectNamesManagerEntry *entry = ent;
ESelectNamesManagerEntry *newent;
newent = g_new(ESelectNamesManagerEntry, 1);
newent->id = g_strdup(entry->id);
newent->entry = entry->entry;
if (newent->entry)
gtk_object_ref(GTK_OBJECT(newent->entry));
return newent;
}
static void
entry_free(void *ent, void *data)
{
ESelectNamesManagerEntry *entry = ent;
g_free(entry->id);
if (entry->entry)
gtk_object_unref(GTK_OBJECT(entry->entry));
g_free(entry);
}
/**
* e_select_names_manager_init:
*/
static void
e_select_names_manager_init (ESelectNamesManager *manager)
{
manager->sections = e_list_new(section_copy, section_free, manager);
manager->entries = e_list_new(entry_copy, entry_free, manager);
}
void e_select_names_manager_add_section (ESelectNamesManager *manager,
const char *id,
const char *title)
{
ESelectNamesManagerSection *section;
section = g_new(ESelectNamesManagerSection, 1);
section->id = g_strdup(id);
section->title = g_strdup(title);
section->model = e_select_names_model_new();
e_list_append(manager->sections, section);
section_free(section, manager);
}
static void
entry_destroyed(EEntry *entry, ESelectNamesManager *manager)
{
if(!GTK_OBJECT_DESTROYED(manager)) {
EIterator *iterator = e_list_get_iterator(manager->entries);
for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
const ESelectNamesManagerEntry *this_entry = e_iterator_get(iterator);
if(entry == this_entry->entry) {
e_iterator_delete(iterator);
break;
}
}
}
gtk_object_unref(GTK_OBJECT(manager));
}
GtkWidget *e_select_names_manager_create_entry (ESelectNamesManager *manager,
const char *id)
{
ETextModel *model;
EIterator *iterator;
iterator = e_list_get_iterator(manager->sections);
for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
const ESelectNamesManagerSection *section = e_iterator_get(iterator);
if (!strcmp(section->id, id)) {
ESelectNamesManagerEntry *entry;
EEntry *eentry;
eentry = E_ENTRY(e_entry_new());
entry = g_new(ESelectNamesManagerEntry, 1);
entry->entry = eentry;
entry->id = (char *)id;
model = e_select_names_text_model_new(section->model);
e_list_append(manager->entries, entry);
g_free(entry);
gtk_object_set(GTK_OBJECT(eentry),
"model", model,
"editable", TRUE,
"use_ellipsis", TRUE,
NULL);
gtk_signal_connect(GTK_OBJECT(eentry), "destroy",
GTK_SIGNAL_FUNC(entry_destroyed), manager);
gtk_object_ref(GTK_OBJECT(manager));
return GTK_WIDGET(eentry);
}
}
return NULL;
}
static void
e_select_names_clicked(ESelectNames *dialog, gint button, ESelectNamesManager *manager)
{
switch(button) {
case 0: {
EList *list = manager->sections;
EIterator *iterator = e_list_get_iterator(list);
for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
ESelectNamesManagerSection *section = (void *) e_iterator_get(iterator);
ESelectNamesModel *source = e_select_names_get_source(dialog, section->id);
if (section->model)
gtk_object_unref(GTK_OBJECT(section->model));
section->model = source;
/* Don't ref because get_source returns a conceptual ref_count of 1. */
}
gtk_object_unref(GTK_OBJECT(iterator));
list = manager->entries;
iterator = e_list_get_iterator(list);
for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
ESelectNamesManagerEntry *entry = (void *) e_iterator_get(iterator);
ESelectNamesModel *source = e_select_names_get_source(dialog, entry->id);
if (source) {
ETextModel *model = e_select_names_text_model_new(source);
if (model) {
gtk_object_set(GTK_OBJECT(entry->entry),
"model", model,
NULL);
gtk_object_unref(GTK_OBJECT(source));
}
gtk_object_unref(GTK_OBJECT(model));
}
}
gtk_object_unref(GTK_OBJECT(iterator));
break;
}
}
gnome_dialog_close(GNOME_DIALOG(dialog));
}
void e_select_names_manager_activate_dialog (ESelectNamesManager *manager,
const char *id)
{
ESelectNames *names = E_SELECT_NAMES(e_select_names_new());
EIterator *iterator;
iterator = e_list_get_iterator(manager->sections);
for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
const ESelectNamesManagerSection *section = e_iterator_get(iterator);
ESelectNamesModel *newmodel = e_select_names_model_duplicate(section->model);
e_select_names_add_section(names, section->id, section->title, newmodel);
gtk_object_unref(GTK_OBJECT(newmodel));
}
gtk_signal_connect(GTK_OBJECT(names), "clicked",
GTK_SIGNAL_FUNC(e_select_names_clicked), manager);
gtk_widget_show(GTK_WIDGET(names));
}
/* Of type ECard */
EList *e_select_names_manager_get_cards (ESelectNamesManager *manager,
const char *id)
{
EIterator *iterator;
iterator = e_list_get_iterator(manager->sections);
for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
const ESelectNamesManagerSection *section = e_iterator_get(iterator);
if (!strcmp(section->id, id)) {
return e_select_names_model_get_cards(section->model);
}
}
return NULL;
}
|