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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* Evolution calendar - Commands for the calendar GUI control
*
* Copyright (C) 1998 The Free Software Foundation
* Copyright (C) 2000 Ximian, Inc.
* Copyright (C) 2000 Ximian, Inc.
*
* Authors: Miguel de Icaza <miguel@ximian.com>
* Federico Mena-Quintero <federico@ximian.com>
* Seth Alves <alves@hungry.com>
*
* 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.
*/
#include <config.h>
#include <pwd.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtkfilesel.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-util.h>
#include <libgnomeui/gnome-dialog-util.h>
#include <libgnomeui/gnome-messagebox.h>
#include <libgnomeui/gnome-stock.h>
#include <libgnome/gnome-util.h>
#include <libgnome/gnome-i18n.h>
#include <bonobo/bonobo-ui-util.h>
#include <cal-util/timeutil.h>
#include "shell/Evolution.h"
#include "calendar-commands.h"
#include "calendar-config.h"
#include "gnome-cal.h"
#include "goto.h"
#include "print.h"
#include "dialogs/cal-prefs-dialog.h"
#include "itip-utils.h"
#include "evolution-shell-component-utils.h"
/* A list of all of the calendars started */
static GList *all_calendars = NULL;
/* We have one global preferences dialog. */
static CalPrefsDialog *preferences_dialog = NULL;
/* Callback for the new appointment command */
static void
new_appointment_cb (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
gnome_calendar_new_appointment (gcal);
}
static void
new_event_cb (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
time_t dtstart, dtend;
gcal = GNOME_CALENDAR (data);
gnome_calendar_get_current_time_range (gcal, &dtstart, &dtend);
gnome_calendar_new_appointment_for (gcal, dtstart, dtend, TRUE);
}
/* Prints the calendar at its current view and time range */
static void
print (GnomeCalendar *gcal, gboolean preview)
{
time_t start;
GnomeCalendarViewType view_type;
PrintView print_view;
gnome_calendar_get_current_time_range (gcal, &start, NULL);
view_type = gnome_calendar_get_view (gcal);
switch (view_type) {
case GNOME_CAL_DAY_VIEW:
print_view = PRINT_VIEW_DAY;
break;
case GNOME_CAL_WORK_WEEK_VIEW:
case GNOME_CAL_WEEK_VIEW:
print_view = PRINT_VIEW_WEEK;
break;
case GNOME_CAL_MONTH_VIEW:
print_view = PRINT_VIEW_MONTH;
break;
default:
g_assert_not_reached ();
return;
}
print_calendar (gcal, preview, start, print_view);
}
/* File/Print callback */
static void
file_print_cb (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
print (gcal, FALSE);
}
static void
file_print_preview_cb (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
print (gcal, TRUE);
}
/* This iterates over each calendar telling them to update their config
settings. */
void
update_all_config_settings (void)
{
GList *l;
for (l = all_calendars; l; l = l->next)
gnome_calendar_update_config_settings (GNOME_CALENDAR (l->data), FALSE);
}
/* Sets a clock cursor for the specified calendar window */
static void
set_clock_cursor (GnomeCalendar *gcal)
{
GdkCursor *cursor;
cursor = gdk_cursor_new (GDK_WATCH);
gdk_window_set_cursor (GTK_WIDGET (gcal)->window, cursor);
gdk_cursor_destroy (cursor);
gdk_flush ();
}
/* Resets the normal cursor for the specified calendar window */
static void
set_normal_cursor (GnomeCalendar *gcal)
{
gdk_window_set_cursor (GTK_WIDGET (gcal)->window, NULL);
gdk_flush ();
}
static void
previous_clicked (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
set_clock_cursor (gcal);
gnome_calendar_previous (gcal);
set_normal_cursor (gcal);
}
static void
next_clicked (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
set_clock_cursor (gcal);
gnome_calendar_next (gcal);
set_normal_cursor (gcal);
}
void
calendar_goto_today (GnomeCalendar *gcal)
{
set_clock_cursor (gcal);
gnome_calendar_goto_today (gcal);
set_normal_cursor (gcal);
}
static void
today_clicked (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
calendar_goto_today (gcal);
}
static void
goto_clicked (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
goto_dialog (gcal);
}
static void
show_day_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
gnome_calendar_set_view (gcal, GNOME_CAL_DAY_VIEW, FALSE, TRUE);
}
static void
show_work_week_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
gnome_calendar_set_view (gcal, GNOME_CAL_WORK_WEEK_VIEW, FALSE, TRUE);
}
static void
show_week_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
gnome_calendar_set_view (gcal, GNOME_CAL_WEEK_VIEW, FALSE, TRUE);
}
static void
show_month_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
gnome_calendar_set_view (gcal, GNOME_CAL_MONTH_VIEW, FALSE, TRUE);
}
static void
settings_cmd (BonoboUIComponent *uic, gpointer data, const char *path)
{
if (!preferences_dialog)
preferences_dialog = cal_prefs_dialog_new (CAL_PREFS_DIALOG_PAGE_CALENDAR);
else
cal_prefs_dialog_show (preferences_dialog, CAL_PREFS_DIALOG_PAGE_CALENDAR);
}
static void
cut_event_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
set_clock_cursor (gcal);
gnome_calendar_cut_clipboard (gcal);
set_normal_cursor (gcal);
}
static void
copy_event_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
set_clock_cursor (gcal);
gnome_calendar_copy_clipboard (gcal);
set_normal_cursor (gcal);
}
static void
paste_event_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path)
{
GnomeCalendar *gcal;
gcal = GNOME_CALENDAR (data);
set_clock_cursor (gcal);
gnome_calendar_paste_clipboard (gcal);
set_normal_cursor (gcal);
}
static void
publish_freebusy_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path)
{
GnomeCalendar *gcal;
CalClient *client;
CalClientGetStatus status;
CalComponent *comp;
time_t start, end;
gcal = GNOME_CALENDAR (data);
gnome_calendar_get_current_time_range (gcal, &start, &end);
client = gnome_calendar_get_cal_client (gcal);
status = cal_client_get_free_busy (client, start, end, &comp);
if (status == CAL_CLIENT_GET_SUCCESS)
itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, comp);
}
/* Does a queryInterface on the control's parent control frame for the ShellView interface */
static GNOME_Evolution_ShellView
get_shell_view_interface (BonoboControl *control)
{
Bonobo_ControlFrame control_frame;
GNOME_Evolution_ShellView shell_view;
CORBA_Environment ev;
control_frame = bonobo_control_get_control_frame (control);
g_assert (control_frame != CORBA_OBJECT_NIL);
CORBA_exception_init (&ev);
shell_view = Bonobo_Unknown_queryInterface (control_frame,
"IDL:GNOME/Evolution/ShellView:1.0",
&ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_message ("get_shell_view_interface(): "
"Could not queryInterface() on the control frame");
shell_view = CORBA_OBJECT_NIL;
goto out;
}
CORBA_exception_free (&ev);
out:
return shell_view;
}
/* Displays the currently displayed time range in the folder bar label on the
shell view, according to which view we are showing. */
void
calendar_set_folder_bar_label (GnomeCalendar *gcal, BonoboControl *control)
{
icaltimezone *zone;
struct icaltimetype start_tt, end_tt;
time_t start_time, end_time;
struct tm start_tm, end_tm;
char buffer[512], end_buffer[256];
GnomeCalendarViewType view;
gnome_calendar_get_visible_time_range (gcal, &start_time, &end_time);
zone = gnome_calendar_get_timezone (gcal);
start_tt = icaltime_from_timet_with_zone (start_time, FALSE, zone);
start_tm.tm_year = start_tt.year - 1900;
start_tm.tm_mon = start_tt.month - 1;
start_tm.tm_mday = start_tt.day;
start_tm.tm_hour = start_tt.hour;
start_tm.tm_min = start_tt.minute;
start_tm.tm_sec = start_tt.second;
start_tm.tm_isdst = -1;
start_tm.tm_wday = time_day_of_week (start_tt.day, start_tt.month - 1,
start_tt.year);
/* Take one off end_time so we don't get an extra day. */
end_tt = icaltime_from_timet_with_zone (end_time - 1, FALSE, zone);
end_tm.tm_year = end_tt.year - 1900;
end_tm.tm_mon = end_tt.month - 1;
end_tm.tm_mday = end_tt.day;
end_tm.tm_hour = end_tt.hour;
end_tm.tm_min = end_tt.minute;
end_tm.tm_sec = end_tt.second;
end_tm.tm_isdst = -1;
end_tm.tm_wday = time_day_of_week (end_tt.day, end_tt.month - 1,
end_tt.year);
view = gnome_calendar_get_view (gcal);
switch (view) {
case GNOME_CAL_DAY_VIEW:
case GNOME_CAL_WORK_WEEK_VIEW:
case GNOME_CAL_WEEK_VIEW:
if (start_tm.tm_year == end_tm.tm_year
&& start_tm.tm_mon == end_tm.tm_mon
&& start_tm.tm_mday == end_tm.tm_mday) {
strftime (buffer, sizeof (buffer),
_("%A %d %B %Y"), &start_tm);
} else if (start_tm.tm_year == end_tm.tm_year) {
strftime (buffer, sizeof (buffer),
_("%a %d %b"), &start_tm);
strftime (end_buffer, sizeof (end_buffer),
_("%a %d %b %Y"), &end_tm);
strcat (buffer, " - ");
strcat (buffer, end_buffer);
} else {
strftime (buffer, sizeof (buffer),
_("%a %d %b %Y"), &start_tm);
strftime (end_buffer, sizeof (end_buffer),
_("%a %d %b %Y"), &end_tm);
strcat (buffer, " - ");
strcat (buffer, end_buffer);
}
break;
case GNOME_CAL_MONTH_VIEW:
if (start_tm.tm_year == end_tm.tm_year) {
if (start_tm.tm_mon == end_tm.tm_mon) {
strftime (buffer, sizeof (buffer),
_("%d"), &start_tm);
strftime (end_buffer, sizeof (end_buffer),
_("%d %B %Y"), &end_tm);
strcat (buffer, " - ");
strcat (buffer, end_buffer);
} else {
strftime (buffer, sizeof (buffer),
_("%d %B"), &start_tm);
strftime (end_buffer, sizeof (end_buffer),
_("%d %B %Y"), &end_tm);
strcat (buffer, " - ");
strcat (buffer, end_buffer);
}
} else {
strftime (buffer, sizeof (buffer),
_("%d %B %Y"), &start_tm);
strftime (end_buffer, sizeof (end_buffer),
_("%d %B %Y"), &end_tm);
strcat (buffer, " - ");
strcat (buffer, end_buffer);
}
break;
default:
g_assert_not_reached ();
}
control_util_set_folder_bar_label (control, buffer);
}
void
control_util_set_folder_bar_label (BonoboControl *control, char *label)
{
GNOME_Evolution_ShellView shell_view;
CORBA_Environment ev;
shell_view = get_shell_view_interface (control);
if (shell_view == CORBA_OBJECT_NIL)
return;
CORBA_exception_init (&ev);
GNOME_Evolution_ShellView_setFolderBarLabel (shell_view, label, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
g_message ("control_util_set_folder_bar_label(): Could not set the folder bar label");
CORBA_exception_free (&ev);
}
static BonoboUIVerb verbs [] = {
BONOBO_UI_VERB ("CalendarPrint", file_print_cb),
BONOBO_UI_VERB ("CalendarPrintPreview", file_print_preview_cb),
BONOBO_UI_VERB ("CalendarNewAppointment", new_appointment_cb),
BONOBO_UI_VERB ("CalendarNewEvent", new_event_cb),
BONOBO_UI_VERB ("CalendarSettings", settings_cmd),
BONOBO_UI_VERB ("CutEvent", cut_event_cmd),
BONOBO_UI_VERB ("CopyEvent", copy_event_cmd),
BONOBO_UI_VERB ("PasteEvent", paste_event_cmd),
BONOBO_UI_VERB ("CalendarPrev", previous_clicked),
BONOBO_UI_VERB ("CalendarToday", today_clicked),
BONOBO_UI_VERB ("CalendarNext", next_clicked),
BONOBO_UI_VERB ("CalendarGoto", goto_clicked),
BONOBO_UI_VERB ("ShowDayView", show_day_view_clicked),
BONOBO_UI_VERB ("ShowWorkWeekView", show_work_week_view_clicked),
BONOBO_UI_VERB ("ShowWeekView", show_week_view_clicked),
BONOBO_UI_VERB ("ShowMonthView", show_month_view_clicked),
BONOBO_UI_VERB ("PublishFreeBusy", publish_freebusy_cmd),
BONOBO_UI_VERB_END
};
static EPixmap pixmaps [] =
{
E_PIXMAP ("/menu/File/New/NewFirstItem/NewAppointment", "new_appointment.xpm"),
E_PIXMAP ("/menu/File/Print/Print", "print.xpm"),
E_PIXMAP ("/menu/File/Print/PrintPreview", "print-preview.xpm"),
E_PIXMAP ("/menu/ComponentActionsPlaceholder/Actions/NewAppointment", "new_appointment.xpm"),
E_PIXMAP ("/menu/ComponentToolsPlaceholder/Tools/CalendarSettings", "configure_16_calendar.xpm"),
E_PIXMAP ("/Toolbar/New", "buttons/new_appointment.png"),
E_PIXMAP ("/Toolbar/Print", "buttons/print.png"),
E_PIXMAP ("/Toolbar/Prev", "buttons/arrow-left-24.png"),
E_PIXMAP ("/Toolbar/Next", "buttons/arrow-right-24.png"),
E_PIXMAP ("/Toolbar/DayView", "buttons/dayview.xpm"),
E_PIXMAP ("/Toolbar/WorkWeekView", "buttons/workweekview.xpm"),
E_PIXMAP ("/Toolbar/WeekView", "buttons/weekview.xpm"),
E_PIXMAP ("/Toolbar/MonthView", "buttons/monthview.xpm"),
E_PIXMAP_END
};
void
calendar_control_activate (BonoboControl *control,
GnomeCalendar *gcal)
{
Bonobo_UIContainer remote_uih;
BonoboUIComponent *uic;
uic = bonobo_control_get_ui_component (control);
g_assert (uic != NULL);
remote_uih = bonobo_control_get_remote_ui_container (control);
bonobo_ui_component_set_container (uic, remote_uih);
bonobo_object_release_unref (remote_uih, NULL);
bonobo_ui_component_add_verb_list_with_data (uic, verbs, gcal);
bonobo_ui_component_freeze (uic, NULL);
bonobo_ui_util_set_ui (uic, EVOLUTION_DATADIR,
"evolution-calendar.xml",
"evolution-calendar");
e_pixmaps_update (uic, pixmaps);
gnome_calendar_setup_view_menus (gcal, uic);
bonobo_ui_component_thaw (uic, NULL);
/* Show the dialog for setting the timezone if the user hasn't chosen
a default timezone already. */
calendar_config_check_timezone_set ();
calendar_set_folder_bar_label (gcal, control);
}
void
calendar_control_deactivate (BonoboControl *control, GnomeCalendar *gcal)
{
BonoboUIComponent *uic = bonobo_control_get_ui_component (control);
g_assert (uic != NULL);
gnome_calendar_discard_view_menus (gcal);
bonobo_ui_component_rm (uic, "/", NULL);
bonobo_ui_component_unset_container (uic);
}
/* Removes a calendar from our list of all calendars when it is destroyed. */
static void
on_calendar_destroyed (GnomeCalendar *gcal)
{
all_calendars = g_list_remove (all_calendars, gcal);
}
GnomeCalendar *
new_calendar (void)
{
GtkWidget *gcal;
gcal = gnome_calendar_new ();
if (!gcal) {
gnome_warning_dialog (_("Could not create the calendar view. Please check your "
"ORBit and OAF setup."));
return NULL;
}
gtk_signal_connect (GTK_OBJECT (gcal), "destroy",
GTK_SIGNAL_FUNC (on_calendar_destroyed), NULL);
all_calendars = g_list_prepend (all_calendars, gcal);
return GNOME_CALENDAR (gcal);
}
|