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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* Evolution calendar - Delegate selector dialog
*
* Copyright (C) 2001 Ximian, Inc.
*
* Authors: Damon Chaplin <damon@ximian.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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.
*/
#include <config.h>
#include <liboaf/liboaf.h>
#include <bonobo/bonobo-control.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-widget.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkcombo.h>
#include <gtk/gtkentry.h>
#include <gtk/gtklabel.h>
#include <gnome.h>
#include <ical.h>
#include <glade/glade.h>
#include <widgets/misc/e-map.h>
#include <e-destination.h>
#include "Evolution-Addressbook-SelectNames.h"
#include "e-delegate-dialog.h"
struct _EDelegateDialogPrivate {
char *name;
char *address;
/* Glade XML data */
GladeXML *xml;
/* Widgets from the Glade file */
GtkWidget *app;
GtkWidget *hbox;
GtkWidget *addressbook;
GNOME_Evolution_Addressbook_SelectNames corba_select_names;
GtkWidget *entry;
};
#define SELECT_NAMES_OAFID "OAFIID:GNOME_Evolution_Addressbook_SelectNames"
static const char *section_name = "Delegate To";
static void e_delegate_dialog_class_init (EDelegateDialogClass *class);
static void e_delegate_dialog_init (EDelegateDialog *edd);
static void e_delegate_dialog_destroy (GtkObject *object);
static gboolean get_widgets (EDelegateDialog *edd);
static void addressbook_clicked_cb (GtkWidget *widget, gpointer data);
static GtkObjectClass *parent_class;
GtkType
e_delegate_dialog_get_type (void)
{
static GtkType e_delegate_dialog_type = 0;
if (!e_delegate_dialog_type) {
static const GtkTypeInfo e_delegate_dialog_info = {
"EDelegateDialog",
sizeof (EDelegateDialog),
sizeof (EDelegateDialogClass),
(GtkClassInitFunc) e_delegate_dialog_class_init,
(GtkObjectInitFunc) e_delegate_dialog_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
e_delegate_dialog_type = gtk_type_unique (GTK_TYPE_OBJECT,
&e_delegate_dialog_info);
}
return e_delegate_dialog_type;
}
/* Class initialization function for the event editor */
static void
e_delegate_dialog_class_init (EDelegateDialogClass *class)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass *) class;
parent_class = gtk_type_class (GTK_TYPE_OBJECT);
object_class->destroy = e_delegate_dialog_destroy;
}
/* Object initialization function for the event editor */
static void
e_delegate_dialog_init (EDelegateDialog *edd)
{
EDelegateDialogPrivate *priv;
priv = g_new0 (EDelegateDialogPrivate, 1);
edd->priv = priv;
priv->address = NULL;
}
/* Destroy handler for the event editor */
static void
e_delegate_dialog_destroy (GtkObject *object)
{
EDelegateDialog *edd;
EDelegateDialogPrivate *priv;
GtkWidget *dialog;
g_return_if_fail (object != NULL);
g_return_if_fail (E_IS_DELEGATE_DIALOG (object));
edd = E_DELEGATE_DIALOG (object);
priv = edd->priv;
/* Destroy the actual dialog. */
dialog = e_delegate_dialog_get_toplevel (edd);
gtk_widget_destroy (dialog);
g_free (priv->address);
priv->address = NULL;
g_free (priv);
edd->priv = NULL;
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
EDelegateDialog *
e_delegate_dialog_construct (EDelegateDialog *edd, const char *name, const char *address)
{
EDelegateDialogPrivate *priv;
EDestination *dest;
EDestination *destv[2] = {NULL, NULL};
Bonobo_Control corba_control;
CORBA_Environment ev;
g_return_val_if_fail (edd != NULL, NULL);
g_return_val_if_fail (E_IS_DELEGATE_DIALOG (edd), NULL);
priv = edd->priv;
/* Load the content widgets */
priv->xml = glade_xml_new (EVOLUTION_GLADEDIR "/e-delegate-dialog.glade",
NULL);
if (!priv->xml) {
g_message ("e_delegate_dialog_construct(): Could not load the Glade XML file!");
goto error;
}
if (!get_widgets (edd)) {
g_message ("e_delegate_dialog_construct(): Could not find all widgets in the XML file!");
goto error;
}
CORBA_exception_init (&ev);
priv->corba_select_names = oaf_activate_from_id (SELECT_NAMES_OAFID, 0, NULL, &ev);
GNOME_Evolution_Addressbook_SelectNames_addSectionWithLimit (priv->corba_select_names,
section_name,
section_name,
1, &ev);
if (BONOBO_EX (&ev)) {
g_message ("e_delegate_dialog_construct(): Unable to add section!");
goto error;
}
corba_control = GNOME_Evolution_Addressbook_SelectNames_getEntryBySection (priv->corba_select_names,
section_name, &ev);
if (BONOBO_EX (&ev)) {
g_message ("e_delegate_dialog_construct(): Unable to get addressbook entry!");
goto error;
}
CORBA_exception_free (&ev);
priv->entry = bonobo_widget_new_control_from_objref (corba_control, CORBA_OBJECT_NIL);
gtk_widget_show (priv->entry);
gtk_box_pack_start (GTK_BOX (priv->hbox), priv->entry, TRUE, TRUE, 0);
dest = e_destination_new ();
destv[0] = dest;
if (name != NULL && *name)
e_destination_set_name (dest, name);
if (address != NULL && *address)
e_destination_set_email (dest, address);
bonobo_widget_set_property (BONOBO_WIDGET (priv->entry), "destinations", e_destination_exportv (destv), NULL);
gtk_object_unref (GTK_OBJECT (dest));
gtk_signal_connect (GTK_OBJECT (priv->addressbook), "clicked",
GTK_SIGNAL_FUNC (addressbook_clicked_cb), edd);
return edd;
error:
gtk_object_unref (GTK_OBJECT (edd));
return NULL;
}
static gboolean
get_widgets (EDelegateDialog *edd)
{
EDelegateDialogPrivate *priv;
priv = edd->priv;
#define GW(name) glade_xml_get_widget (priv->xml, name)
priv->app = GW ("delegate-dialog");
priv->hbox = GW ("delegate-hbox");
priv->addressbook = GW ("addressbook");
return (priv->app
&& priv->hbox
&& priv->addressbook);
}
static void
addressbook_clicked_cb (GtkWidget *widget, gpointer data)
{
EDelegateDialog *edd = data;
EDelegateDialogPrivate *priv;
CORBA_Environment ev;
priv = edd->priv;
CORBA_exception_init (&ev);
GNOME_Evolution_Addressbook_SelectNames_activateDialog (priv->corba_select_names, section_name, &ev);
CORBA_exception_free (&ev);
}
/**
* e_delegate_dialog_new:
*
* Creates a new event editor dialog.
*
* Return value: A newly-created event editor dialog, or NULL if the event
* editor could not be created.
**/
EDelegateDialog *
e_delegate_dialog_new (const char *name, const char *address)
{
EDelegateDialog *edd;
edd = E_DELEGATE_DIALOG (gtk_type_new (E_TYPE_DELEGATE_DIALOG));
return e_delegate_dialog_construct (E_DELEGATE_DIALOG (edd), name, address);
}
char *
e_delegate_dialog_get_delegate (EDelegateDialog *edd)
{
EDelegateDialogPrivate *priv;
EDestination **destv;
char *string = NULL;
g_return_val_if_fail (edd != NULL, NULL);
g_return_val_if_fail (E_IS_DELEGATE_DIALOG (edd), NULL);
priv = edd->priv;
bonobo_widget_get_property (BONOBO_WIDGET (priv->entry), "destinations", &string, NULL);
destv = e_destination_importv (string);
if (destv && destv[0] != NULL) {
g_free (priv->address);
priv->address = g_strdup (e_destination_get_email (destv[0]));
g_free (destv);
}
g_free (string);
return g_strdup (priv->address);
}
char *
e_delegate_dialog_get_delegate_name (EDelegateDialog *edd)
{
EDelegateDialogPrivate *priv;
EDestination **destv;
char *string = NULL;
g_return_val_if_fail (edd != NULL, NULL);
g_return_val_if_fail (E_IS_DELEGATE_DIALOG (edd), NULL);
priv = edd->priv;
bonobo_widget_get_property (BONOBO_WIDGET (priv->entry), "destinations", &string, NULL);
destv = e_destination_importv (string);
g_message ("importv: [%s]", string);
if (destv && destv[0] != NULL) {
g_free (priv->name);
priv->name = g_strdup (e_destination_get_name (destv[0]));
g_free (destv);
}
g_free (string);
return g_strdup (priv->name);
}
GtkWidget*
e_delegate_dialog_get_toplevel (EDelegateDialog *edd)
{
EDelegateDialogPrivate *priv;
g_return_val_if_fail (edd != NULL, NULL);
g_return_val_if_fail (E_IS_DELEGATE_DIALOG (edd), NULL);
priv = edd->priv;
return priv->app;
}
|