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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-activity-handler.c
*
* Copyright (C) 2001 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* 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.
*
* Author: Ettore Perazzoli <ettore@ximian.com>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "e-activity-handler.h"
#include <gtk/gtksignal.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gal/util/e-util.h>
#define PARENT_TYPE bonobo_x_object_get_type ()
static BonoboXObjectClass *parent_class = NULL;
#define ICON_SIZE 16
struct _ActivityInfo {
GdkPixbuf *icon_pixbuf;
GNOME_Evolution_Activity_ActivityId id;
CORBA_char *information;
CORBA_boolean cancellable;
Bonobo_Listener event_listener;
CORBA_float progress;
};
typedef struct _ActivityInfo ActivityInfo;
struct _EActivityHandlerPrivate {
GNOME_Evolution_Activity_ActivityId next_activity_id;
GList *activity_infos;
GSList *task_bars;
};
/* Utility functions. */
static GdkPixbuf *
create_gdk_pixbuf_from_corba_icon (const GNOME_Evolution_Icon *icon)
{
GdkPixbuf *pixbuf;
GdkPixbuf *scaled_pixbuf;
unsigned char *p;
int src_offset;
int i, j;
int rowstride;
int total_width;
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, icon->hasAlpha, 8, icon->width, icon->height);
if (icon->hasAlpha)
total_width = 4 * icon->width;
else
total_width = 3 * icon->width;
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
src_offset = 0;
p = gdk_pixbuf_get_pixels (pixbuf);
for (i = 0; i < icon->height; i++) {
for (j = 0; j < total_width; j++)
p[j] = icon->rgba_data._buffer[src_offset ++];
p += rowstride;
}
if (icon->width == ICON_SIZE && icon->height == ICON_SIZE)
return pixbuf;
scaled_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, icon->hasAlpha, 8, ICON_SIZE, ICON_SIZE);
gdk_pixbuf_scale (pixbuf, scaled_pixbuf,
0, 0, ICON_SIZE, ICON_SIZE,
0, 0, (double) ICON_SIZE / icon->width, (double) ICON_SIZE / icon->height,
GDK_INTERP_HYPER);
gdk_pixbuf_unref (pixbuf);
return scaled_pixbuf;
}
static unsigned int
get_new_activity_id (EActivityHandler *activity_handler)
{
EActivityHandlerPrivate *priv;
priv = activity_handler->priv;
return priv->next_activity_id ++;
}
static GList *
lookup_activity (GList *list,
GNOME_Evolution_Activity_ActivityId activity_id,
int *order_number_return)
{
GList *p;
int i;
for (p = list, i = 0; p != NULL; p = p->next, i ++) {
ActivityInfo *activity_info;
activity_info = (ActivityInfo *) p->data;
if (activity_info->id == activity_id) {
*order_number_return = i;
return p;
}
}
*order_number_return = -1;
return NULL;
}
/* Creating and destroying ActivityInfos. */
static ActivityInfo *
activity_info_new (GNOME_Evolution_Activity_ActivityId id,
GdkPixbuf *icon,
const CORBA_char *information,
CORBA_boolean cancellable,
const Bonobo_Listener event_listener)
{
ActivityInfo *info;
CORBA_Environment ev;
CORBA_exception_init (&ev);
info = g_new (ActivityInfo, 1);
info->id = id;
info->icon_pixbuf = gdk_pixbuf_ref (icon);
info->information = CORBA_string_dup (information);
info->cancellable = cancellable;
info->event_listener = CORBA_Object_duplicate (event_listener, &ev);
info->progress = -1.0; /* (Unknown) */
CORBA_exception_free (&ev);
return info;
}
static void
activity_info_free (ActivityInfo *info)
{
CORBA_Environment ev;
CORBA_exception_init (&ev);
CORBA_free (info->information);
CORBA_Object_release (info->event_listener, &ev);
g_free (info);
CORBA_exception_free (&ev);
}
static ETaskWidget *
task_widget_new_from_activity_info (ActivityInfo *activity_info)
{
GtkWidget *widget;
widget = e_task_widget_new (activity_info->icon_pixbuf, activity_info->information);
gtk_widget_show (widget);
return E_TASK_WIDGET (widget);
}
/* Task Bar handling. */
static void
setup_task_bar (EActivityHandler *activity_handler,
ETaskBar *task_bar)
{
EActivityHandlerPrivate *priv;
GList *p;
priv = activity_handler->priv;
for (p = g_list_last (priv->activity_infos); p != NULL; p = p->prev) {
e_task_bar_prepend_task (task_bar,
task_widget_new_from_activity_info ((ActivityInfo *) p->data));
}
}
static void
task_bar_destroy_callback (GtkObject *task_bar_object,
void *data)
{
ETaskBar *task_bar;
EActivityHandler *activity_handler;
EActivityHandlerPrivate *priv;
task_bar = E_TASK_BAR (task_bar_object);
activity_handler = E_ACTIVITY_HANDLER (data);
priv = activity_handler->priv;
priv->task_bars = g_slist_remove (priv->task_bars, task_bar);
}
/* GtkObject methods. */
static void
impl_destroy (GtkObject *object)
{
EActivityHandler *handler;
EActivityHandlerPrivate *priv;
GList *p;
handler = E_ACTIVITY_HANDLER (object);
priv = handler->priv;
for (p = priv->activity_infos; p != NULL; p = p->next) {
ActivityInfo *info;
info = (ActivityInfo *) p->data;
activity_info_free (info);
}
g_free (priv);
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
/* CORBA methods. */
static void
impl_operationStarted (PortableServer_Servant servant,
const CORBA_char *component_id,
const GNOME_Evolution_AnimatedIcon *icon,
const CORBA_char *information,
const CORBA_boolean cancellable,
const Bonobo_Listener event_listener,
GNOME_Evolution_Activity_ActivityId *activity_id_return,
CORBA_boolean *suggest_display_return,
CORBA_Environment *ev)
{
EActivityHandler *activity_handler;
EActivityHandlerPrivate *priv;
ActivityInfo *activity_info;
GdkPixbuf *icon_pixbuf;
unsigned int activity_id;
GSList *p;
activity_handler = E_ACTIVITY_HANDLER (bonobo_object_from_servant (servant));
priv = activity_handler->priv;
if (icon->_length == 0) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Activity_InvalidIcon, NULL);
return;
}
if (icon->_length > 1)
g_warning ("Animated icons are not supported for activities (yet).");
icon_pixbuf = create_gdk_pixbuf_from_corba_icon (icon->_buffer);
activity_id = get_new_activity_id (activity_handler);
activity_info = activity_info_new (activity_id, icon_pixbuf, information, cancellable, event_listener);
for (p = priv->task_bars; p != NULL; p = p->next)
e_task_bar_prepend_task (E_TASK_BAR (p->data),
task_widget_new_from_activity_info (activity_info));
priv->activity_infos = g_list_prepend (priv->activity_infos, activity_info);
*activity_id_return = activity_id;
}
static void
impl_operationProgressing (PortableServer_Servant servant,
const GNOME_Evolution_Activity_ActivityId activity_id,
const CORBA_char *information,
const CORBA_float progress,
CORBA_Environment *ev)
{
EActivityHandler *activity_handler;
EActivityHandlerPrivate *priv;
ActivityInfo *activity_info;
GList *p;
GSList *sp;
int order_number;
/* FIXME? The complexity in this function sucks. */
activity_handler = E_ACTIVITY_HANDLER (bonobo_object_from_servant (servant));
priv = activity_handler->priv;
p = lookup_activity (priv->activity_infos, activity_id, &order_number);
if (p == NULL) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Activity_IdNotFound, NULL);
return;
}
activity_info = (ActivityInfo *) p->data;
CORBA_free (activity_info->information);
activity_info->information = CORBA_string_dup (information);
activity_info->progress = progress;
for (sp = priv->task_bars; sp != NULL; sp = sp->next) {
ETaskBar *task_bar;
ETaskWidget *task_widget;
task_bar = E_TASK_BAR (sp->data);
task_widget = e_task_bar_get_task_widget (task_bar, order_number);
e_task_widget_update (task_widget, information, progress);
}
}
static void
impl_operationFinished (PortableServer_Servant servant,
const GNOME_Evolution_Activity_ActivityId activity_id,
CORBA_Environment *ev)
{
EActivityHandler *activity_handler;
EActivityHandlerPrivate *priv;
GList *p;
GSList *sp;
int order_number;
activity_handler = E_ACTIVITY_HANDLER (bonobo_object_from_servant (servant));
priv = activity_handler->priv;
p = lookup_activity (priv->activity_infos, activity_id, &order_number);
activity_info_free ((ActivityInfo *) p->data);
priv->activity_infos = g_list_remove_link (priv->activity_infos, p);
for (sp = priv->task_bars; sp != NULL; sp = sp->next) {
ETaskBar *task_bar;
task_bar = E_TASK_BAR (sp->data);
e_task_bar_remove_task (task_bar, order_number);
}
}
static GNOME_Evolution_Activity_DialogAction
impl_requestDialog (PortableServer_Servant servant,
const GNOME_Evolution_Activity_ActivityId activity_id,
const GNOME_Evolution_Activity_DialogType dialog_type,
CORBA_Environment *ev)
{
/* FIXME implement. */
g_warning ("Evolution::Activity::requestDialog not implemented");
return GNOME_Evolution_Activity_DIALOG_ACTION_DISPLAY;
}
/* GTK+ type stuff. */
static void
class_init (GtkObjectClass *object_class)
{
EActivityHandlerClass *handler_class;
parent_class = gtk_type_class (PARENT_TYPE);
object_class->destroy = impl_destroy;
handler_class = E_ACTIVITY_HANDLER_CLASS (object_class);
handler_class->epv.operationStarted = impl_operationStarted;
handler_class->epv.operationProgressing = impl_operationProgressing;
handler_class->epv.operationFinished = impl_operationFinished;
handler_class->epv.requestDialog = impl_requestDialog;
}
static void
init (EActivityHandler *activity_handler)
{
EActivityHandlerPrivate *priv;
priv = g_new (EActivityHandlerPrivate, 1);
priv->next_activity_id = 0;
priv->activity_infos = NULL;
priv->task_bars = NULL;
activity_handler->priv = priv;
}
void
e_activity_handler_construct (EActivityHandler *activity_handler)
{
g_return_if_fail (activity_handler != NULL);
g_return_if_fail (E_IS_ACTIVITY_HANDLER (activity_handler));
/* Nothing to do here. */
}
EActivityHandler *
e_activity_handler_new (void)
{
EActivityHandler *activity_handler;
activity_handler = gtk_type_new (e_activity_handler_get_type ());
e_activity_handler_construct (activity_handler);
return activity_handler;
}
void
e_activity_handler_attach_task_bar (EActivityHandler *activity_handler,
ETaskBar *task_bar)
{
EActivityHandlerPrivate *priv;
g_return_if_fail (activity_handler != NULL);
g_return_if_fail (E_IS_ACTIVITY_HANDLER (activity_handler));
g_return_if_fail (task_bar != NULL);
g_return_if_fail (E_IS_TASK_BAR (task_bar));
priv = activity_handler->priv;
gtk_signal_connect_while_alive (GTK_OBJECT (task_bar), "destroy",
GTK_SIGNAL_FUNC (task_bar_destroy_callback), activity_handler,
GTK_OBJECT (activity_handler));
priv->task_bars = g_slist_prepend (priv->task_bars, task_bar);
setup_task_bar (activity_handler, task_bar);
}
E_MAKE_X_TYPE (e_activity_handler, "EActivityHandler", EActivityHandler, class_init, init, PARENT_TYPE,
POA_GNOME_Evolution_Activity__init,
GTK_STRUCT_OFFSET (EActivityHandlerClass, epv))
|