No issues found
1 /*
2 * e-cal-shell-view-actions.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 *
18 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
19 *
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "libevolution-utils/e-alert-dialog.h"
27 #include "e-cal-shell-view-private.h"
28
29 /* This is for radio action groups whose value is persistent. We
30 * initialize it to a bogus value to ensure a "changed" signal is
31 * emitted when a valid value is restored. */
32 #define BOGUS_INITIAL_VALUE G_MININT
33
34 static void
35 action_calendar_copy_cb (GtkAction *action,
36 ECalShellView *cal_shell_view)
37 {
38 ECalShellSidebar *cal_shell_sidebar;
39 EShell *shell;
40 EShellView *shell_view;
41 EShellWindow *shell_window;
42 ESourceRegistry *registry;
43 ESourceSelector *selector;
44 ESource *source;
45
46 shell_view = E_SHELL_VIEW (cal_shell_view);
47 shell_window = e_shell_view_get_shell_window (shell_view);
48 shell = e_shell_window_get_shell (shell_window);
49
50 registry = e_shell_get_registry (shell);
51
52 cal_shell_sidebar = cal_shell_view->priv->cal_shell_sidebar;
53 selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
54 source = e_source_selector_ref_primary_selection (selector);
55 g_return_if_fail (source != NULL);
56
57 copy_source_dialog (
58 GTK_WINDOW (shell_window), registry,
59 source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS);
60
61 g_object_unref (source);
62 }
63
64 static void
65 action_calendar_delete_cb (GtkAction *action,
66 ECalShellView *cal_shell_view)
67 {
68 ECalShellSidebar *cal_shell_sidebar;
69 EShellWindow *shell_window;
70 EShellView *shell_view;
71 ESource *source;
72 ESourceSelector *selector;
73 gint response;
74
75 shell_view = E_SHELL_VIEW (cal_shell_view);
76 shell_window = e_shell_view_get_shell_window (shell_view);
77
78 cal_shell_sidebar = cal_shell_view->priv->cal_shell_sidebar;
79 selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
80
81 source = e_source_selector_ref_primary_selection (selector);
82 g_return_if_fail (source != NULL);
83
84 if (e_source_get_remote_deletable (source)) {
85 response = e_alert_run_dialog_for_args (
86 GTK_WINDOW (shell_window),
87 "calendar:prompt-delete-remote-calendar",
88 e_source_get_display_name (source), NULL);
89
90 if (response == GTK_RESPONSE_YES)
91 e_shell_view_remote_delete_source (shell_view, source);
92
93 } else {
94 response = e_alert_run_dialog_for_args (
95 GTK_WINDOW (shell_window),
96 "calendar:prompt-delete-calendar",
97 e_source_get_display_name (source), NULL);
98
99 if (response == GTK_RESPONSE_YES)
100 e_shell_view_remove_source (shell_view, source);
101 }
102
103 g_object_unref (source);
104 }
105
106 static void
107 action_calendar_go_back_cb (GtkAction *action,
108 ECalShellView *cal_shell_view)
109 {
110 ECalShellContent *cal_shell_content;
111 GnomeCalendar *calendar;
112
113 cal_shell_content = cal_shell_view->priv->cal_shell_content;
114 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
115
116 gnome_calendar_previous (calendar);
117 }
118
119 static void
120 action_calendar_go_forward_cb (GtkAction *action,
121 ECalShellView *cal_shell_view)
122 {
123 ECalShellContent *cal_shell_content;
124 GnomeCalendar *calendar;
125
126 cal_shell_content = cal_shell_view->priv->cal_shell_content;
127 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
128
129 gnome_calendar_next (calendar);
130 }
131
132 static void
133 action_calendar_go_today_cb (GtkAction *action,
134 ECalShellView *cal_shell_view)
135 {
136 ECalShellContent *cal_shell_content;
137 GnomeCalendar *calendar;
138
139 cal_shell_content = cal_shell_view->priv->cal_shell_content;
140 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
141
142 gnome_calendar_goto_today (calendar);
143 }
144
145 static void
146 action_calendar_jump_to_cb (GtkAction *action,
147 ECalShellView *cal_shell_view)
148 {
149 ECalShellContent *cal_shell_content;
150 EShellWindow *shell_window;
151 EShellView *shell_view;
152 GnomeCalendar *calendar;
153
154 shell_view = E_SHELL_VIEW (cal_shell_view);
155 shell_window = e_shell_view_get_shell_window (shell_view);
156
157 cal_shell_content = cal_shell_view->priv->cal_shell_content;
158 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
159
160 goto_dialog (GTK_WINDOW (shell_window), calendar);
161 }
162
163 static void
164 action_calendar_new_cb (GtkAction *action,
165 ECalShellView *cal_shell_view)
166 {
167 EShell *shell;
168 EShellView *shell_view;
169 EShellWindow *shell_window;
170 ESourceRegistry *registry;
171 ECalClientSourceType source_type;
172 GtkWidget *config;
173 GtkWidget *dialog;
174 const gchar *icon_name;
175
176 shell_view = E_SHELL_VIEW (cal_shell_view);
177 shell_window = e_shell_view_get_shell_window (shell_view);
178 shell = e_shell_window_get_shell (shell_window);
179
180 registry = e_shell_get_registry (shell);
181 source_type = E_CAL_CLIENT_SOURCE_TYPE_EVENTS;
182 config = e_cal_source_config_new (registry, NULL, source_type);
183
184 dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
185
186 gtk_window_set_transient_for (
187 GTK_WINDOW (dialog), GTK_WINDOW (shell_window));
188
189 icon_name = gtk_action_get_icon_name (action);
190 gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name);
191
192 gtk_window_set_title (GTK_WINDOW (dialog), _("New Calendar"));
193
194 gtk_widget_show (dialog);
195 }
196
197 static void
198 action_calendar_print_cb (GtkAction *action,
199 ECalShellView *cal_shell_view)
200 {
201 ECalShellContent *cal_shell_content;
202 GnomeCalendarViewType view_type;
203 GnomeCalendar *calendar;
204 ECalendarView *view;
205 GtkPrintOperationAction print_action;
206
207 cal_shell_content = cal_shell_view->priv->cal_shell_content;
208 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
209 view_type = gnome_calendar_get_view (calendar);
210 view = gnome_calendar_get_calendar_view (calendar, view_type);
211 print_action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG;
212
213 if (E_IS_CAL_LIST_VIEW (view)) {
214 ETable *table;
215
216 table = E_CAL_LIST_VIEW (view)->table;
217 print_table (table, _("Print"), _("Calendar"), print_action);
218 } else {
219 time_t start;
220
221 gnome_calendar_get_current_time_range (calendar, &start, NULL);
222 print_calendar (calendar, print_action, start);
223 }
224 }
225
226 static void
227 action_calendar_print_preview_cb (GtkAction *action,
228 ECalShellView *cal_shell_view)
229 {
230 ECalShellContent *cal_shell_content;
231 GnomeCalendarViewType view_type;
232 GnomeCalendar *calendar;
233 ECalendarView *view;
234 GtkPrintOperationAction print_action;
235
236 cal_shell_content = cal_shell_view->priv->cal_shell_content;
237 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
238 view_type = gnome_calendar_get_view (calendar);
239 view = gnome_calendar_get_calendar_view (calendar, view_type);
240 print_action = GTK_PRINT_OPERATION_ACTION_PREVIEW;
241
242 if (E_IS_CAL_LIST_VIEW (view)) {
243 ETable *table;
244
245 table = E_CAL_LIST_VIEW (view)->table;
246 print_table (table, _("Print"), _("Calendar"), print_action);
247 } else {
248 time_t start;
249
250 gnome_calendar_get_current_time_range (calendar, &start, NULL);
251 print_calendar (calendar, print_action, start);
252 }
253 }
254
255 static void
256 action_calendar_properties_cb (GtkAction *action,
257 ECalShellView *cal_shell_view)
258 {
259 EShellView *shell_view;
260 EShellWindow *shell_window;
261 ECalShellSidebar *cal_shell_sidebar;
262 ECalClientSourceType source_type;
263 ESource *source;
264 ESourceSelector *selector;
265 ESourceRegistry *registry;
266 GtkWidget *config;
267 GtkWidget *dialog;
268 const gchar *icon_name;
269
270 shell_view = E_SHELL_VIEW (cal_shell_view);
271 shell_window = e_shell_view_get_shell_window (shell_view);
272
273 cal_shell_sidebar = cal_shell_view->priv->cal_shell_sidebar;
274 selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
275 source = e_source_selector_ref_primary_selection (selector);
276 g_return_if_fail (source != NULL);
277
278 source_type = E_CAL_CLIENT_SOURCE_TYPE_EVENTS;
279 registry = e_source_selector_get_registry (selector);
280 config = e_cal_source_config_new (registry, source, source_type);
281
282 g_object_unref (source);
283
284 dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
285
286 gtk_window_set_transient_for (
287 GTK_WINDOW (dialog), GTK_WINDOW (shell_window));
288
289 icon_name = gtk_action_get_icon_name (action);
290 gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name);
291
292 gtk_window_set_title (GTK_WINDOW (dialog), _("Calendar Properties"));
293
294 gtk_widget_show (dialog);
295 }
296
297 static void
298 action_calendar_purge_cb (GtkAction *action,
299 ECalShellView *cal_shell_view)
300 {
301 EShellView *shell_view;
302 EShellWindow *shell_window;
303 ECalShellContent *cal_shell_content;
304 GnomeCalendar *calendar;
305 GtkSpinButton *spin_button;
306 GtkWidget *container;
307 GtkWidget *dialog;
308 GtkWidget *widget;
309 gint days;
310 time_t tt;
311
312 shell_view = E_SHELL_VIEW (cal_shell_view);
313 shell_window = e_shell_view_get_shell_window (shell_view);
314
315 cal_shell_content = cal_shell_view->priv->cal_shell_content;
316 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
317
318 dialog = gtk_message_dialog_new (
319 GTK_WINDOW (shell_window),
320 GTK_DIALOG_DESTROY_WITH_PARENT,
321 GTK_MESSAGE_WARNING,
322 GTK_BUTTONS_OK_CANCEL,
323 _("This operation will permanently erase all events older "
324 "than the selected amount of time. If you continue, you "
325 "will not be able to recover these events."));
326
327 gtk_dialog_set_default_response (
328 GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
329
330 container = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
331
332 widget = gtk_hbox_new (FALSE, 6);
333 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, FALSE, 6);
334 gtk_widget_show (widget);
335
336 container = widget;
337
338 /* Translators: This is the first part of the sentence:
339 * "Purge events older than <<spin-button>> days" */
340 widget = gtk_label_new (_("Purge events older than"));
341 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, FALSE, 6);
342 gtk_widget_show (widget);
343
344 widget = gtk_spin_button_new_with_range (0.0, 1000.0, 1.0);
345 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), 60.0);
346 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 6);
347 gtk_widget_show (widget);
348
349 spin_button = GTK_SPIN_BUTTON (widget);
350
351 /* Translators: This is the last part of the sentence:
352 * "Purge events older than <<spin-button>> days" */
353 widget = gtk_label_new (_("days"));
354 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, FALSE, 6);
355 gtk_widget_show (widget);
356
357 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
358 goto exit;
359
360 days = gtk_spin_button_get_value_as_int (spin_button);
361
362 tt = time (NULL);
363 tt -= (days * (24 * 3600));
364
365 gnome_calendar_purge (calendar, tt);
366
367 exit:
368 gtk_widget_destroy (dialog);
369 }
370
371 static void
372 action_calendar_refresh_cb (GtkAction *action,
373 ECalShellView *cal_shell_view)
374 {
375 ECalShellContent *cal_shell_content;
376 ECalShellSidebar *cal_shell_sidebar;
377 ESourceSelector *selector;
378 ECalClient *client;
379 ECalModel *model;
380 ESource *source;
381 GError *error = NULL;
382
383 cal_shell_content = cal_shell_view->priv->cal_shell_content;
384 cal_shell_sidebar = cal_shell_view->priv->cal_shell_sidebar;
385
386 model = e_cal_shell_content_get_model (cal_shell_content);
387 selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
388
389 source = e_source_selector_ref_primary_selection (selector);
390 g_return_if_fail (source != NULL);
391
392 client = e_cal_model_get_client_for_source (model, source);
393 if (client == NULL) {
394 g_object_unref (source);
395 return;
396 }
397
398 g_return_if_fail (e_client_check_refresh_supported (E_CLIENT (client)));
399
400 e_client_refresh_sync (E_CLIENT (client), NULL, &error);
401
402 if (error != NULL) {
403 g_warning (
404 "%s: Failed to refresh '%s', %s",
405 G_STRFUNC, e_source_get_display_name (source),
406 error->message);
407 g_error_free (error);
408 }
409
410 g_object_unref (source);
411 }
412
413 static void
414 action_calendar_rename_cb (GtkAction *action,
415 ECalShellView *cal_shell_view)
416 {
417 ECalShellSidebar *cal_shell_sidebar;
418 ESourceSelector *selector;
419
420 cal_shell_sidebar = cal_shell_view->priv->cal_shell_sidebar;
421 selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
422
423 e_source_selector_edit_primary_selection (selector);
424 }
425
426 static void
427 action_calendar_search_next_cb (GtkAction *action,
428 ECalShellView *cal_shell_view)
429 {
430 e_cal_shell_view_search_events (cal_shell_view, TRUE);
431 }
432
433 static void
434 action_calendar_search_prev_cb (GtkAction *action,
435 ECalShellView *cal_shell_view)
436 {
437 e_cal_shell_view_search_events (cal_shell_view, FALSE);
438 }
439
440 static void
441 action_calendar_search_stop_cb (GtkAction *action,
442 ECalShellView *cal_shell_view)
443 {
444 e_cal_shell_view_search_stop (cal_shell_view);
445 }
446
447 static void
448 action_calendar_select_one_cb (GtkAction *action,
449 ECalShellView *cal_shell_view)
450 {
451 ECalShellSidebar *cal_shell_sidebar;
452 ESourceSelector *selector;
453 ESource *primary;
454
455 cal_shell_sidebar = cal_shell_view->priv->cal_shell_sidebar;
456 selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
457
458 primary = e_source_selector_ref_primary_selection (selector);
459 g_return_if_fail (primary != NULL);
460
461 e_source_selector_select_exclusive (selector, primary);
462
463 g_object_unref (primary);
464 }
465
466 static void
467 action_calendar_view_cb (GtkRadioAction *action,
468 GtkRadioAction *current,
469 ECalShellView *cal_shell_view)
470 {
471 EShellView *shell_view;
472 GnomeCalendarViewType view_type;
473 const gchar *view_id;
474
475 shell_view = E_SHELL_VIEW (cal_shell_view);
476 view_type = gtk_radio_action_get_current_value (action);
477
478 switch (view_type) {
479 case GNOME_CAL_DAY_VIEW:
480 view_id = "Day_View";
481 break;
482
483 case GNOME_CAL_WORK_WEEK_VIEW:
484 view_id = "Work_Week_View";
485 break;
486
487 case GNOME_CAL_WEEK_VIEW:
488 view_id = "Week_View";
489 break;
490
491 case GNOME_CAL_MONTH_VIEW:
492 view_id = "Month_View";
493 break;
494
495 case GNOME_CAL_LIST_VIEW:
496 view_id = "List_View";
497 break;
498
499 default:
500 g_return_if_reached ();
501 }
502
503 e_shell_view_set_view_id (shell_view, view_id);
504 }
505
506 static void
507 action_event_all_day_new_cb (GtkAction *action,
508 ECalShellView *cal_shell_view)
509 {
510 ECalShellContent *cal_shell_content;
511 GnomeCalendarViewType view_type;
512 ECalendarView *calendar_view;
513 GnomeCalendar *calendar;
514
515 /* These are just for readability. */
516 gboolean all_day = TRUE;
517 gboolean meeting = FALSE;
518 gboolean no_past_date = FALSE;
519
520 cal_shell_content = cal_shell_view->priv->cal_shell_content;
521 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
522 view_type = gnome_calendar_get_view (calendar);
523 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
524
525 e_calendar_view_new_appointment_full (
526 calendar_view, all_day, meeting, no_past_date);
527 }
528
529 static void
530 action_event_copy_cb (GtkAction *action,
531 ECalShellView *cal_shell_view)
532 {
533 EShellView *shell_view;
534 EShellWindow *shell_window;
535 ECalShellContent *cal_shell_content;
536 GnomeCalendarViewType view_type;
537 GnomeCalendar *calendar;
538 ECalendarView *calendar_view;
539 ESource *source_source = NULL;
540 ESource *destination_source = NULL;
541 ESourceRegistry *registry;
542 ECalClient *destination_client = NULL;
543 GList *selected, *iter;
544 GError *error = NULL;
545
546 shell_view = E_SHELL_VIEW (cal_shell_view);
547 shell_window = e_shell_view_get_shell_window (shell_view);
548
549 cal_shell_content = cal_shell_view->priv->cal_shell_content;
550 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
551 registry = gnome_calendar_get_registry (calendar);
552
553 view_type = gnome_calendar_get_view (calendar);
554 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
555
556 selected = e_calendar_view_get_selected_events (calendar_view);
557 g_return_if_fail (selected != NULL);
558
559 if (selected->data) {
560 ECalendarViewEvent *event = selected->data;
561
562 if (is_comp_data_valid (event) && event->comp_data->client)
563 source_source = e_client_get_source (
564 E_CLIENT (event->comp_data->client));
565 }
566
567 /* Get a destination source from the user. */
568 destination_source = select_source_dialog (
569 GTK_WINDOW (shell_window), registry,
570 E_CAL_CLIENT_SOURCE_TYPE_EVENTS, source_source);
571 if (destination_source == NULL)
572 return;
573
574 /* Open the destination calendar. */
575 destination_client = e_cal_client_new (
576 destination_source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
577 if (destination_client == NULL)
578 goto exit;
579
580 e_client_open_sync (E_CLIENT (destination_client), FALSE, NULL, &error);
581
582 if (error != NULL) {
583 g_warning (
584 "%s: Failed to open destination client: %s",
585 G_STRFUNC, error->message);
586 g_error_free (error);
587 goto exit;
588 }
589
590 e_cal_shell_view_set_status_message (
591 cal_shell_view, _("Copying Items"), -1.0);
592
593 for (iter = selected; iter != NULL; iter = iter->next) {
594 ECalendarViewEvent *event = iter->data;
595 gboolean remove = FALSE;
596
597 e_cal_shell_view_transfer_item_to (
598 cal_shell_view, event, destination_client, remove);
599 }
600
601 e_cal_shell_view_set_status_message (cal_shell_view, NULL, -1.0);
602
603 exit:
604 if (destination_client != NULL)
605 g_object_unref (destination_client);
606 if (destination_source != NULL)
607 g_object_unref (destination_source);
608 g_list_free (selected);
609 }
610
611 static void
612 action_event_delegate_cb (GtkAction *action,
613 ECalShellView *cal_shell_view)
614 {
615 ESourceRegistry *registry;
616 ECalShellContent *cal_shell_content;
617 GnomeCalendarViewType view_type;
618 GnomeCalendar *calendar;
619 ECalendarView *calendar_view;
620 ECalendarViewEvent *event;
621 ECalComponent *component;
622 ECalClient *client;
623 ECalModel *model;
624 GList *selected;
625 icalcomponent *clone;
626 icalproperty *property;
627 gboolean found = FALSE;
628 gchar *attendee;
629
630 cal_shell_content = cal_shell_view->priv->cal_shell_content;
631 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
632 view_type = gnome_calendar_get_view (calendar);
633 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
634
635 selected = e_calendar_view_get_selected_events (calendar_view);
636 g_return_if_fail (g_list_length (selected) == 1);
637
638 model = e_calendar_view_get_model (calendar_view);
639 registry = e_cal_model_get_registry (model);
640
641 event = selected->data;
642
643 if (!is_comp_data_valid (event))
644 return;
645
646 client = event->comp_data->client;
647 clone = icalcomponent_new_clone (event->comp_data->icalcomp);
648
649 /* Set the attendee status for the delegate. */
650
651 component = e_cal_component_new ();
652 e_cal_component_set_icalcomponent (
653 component, icalcomponent_new_clone (clone));
654
655 attendee = itip_get_comp_attendee (
656 registry, component, client);
657 property = icalcomponent_get_first_property (
658 clone, ICAL_ATTENDEE_PROPERTY);
659
660 while (property != NULL) {
661 const gchar *candidate;
662
663 candidate = icalproperty_get_attendee (property);
664 candidate = itip_strip_mailto (candidate);
665
666 if (g_ascii_strcasecmp (candidate, attendee) == 0) {
667 icalparameter *parameter;
668
669 parameter = icalparameter_new_role (
670 ICAL_ROLE_NONPARTICIPANT);
671 icalproperty_set_parameter (property, parameter);
672
673 parameter = icalparameter_new_partstat (
674 ICAL_PARTSTAT_DELEGATED);
675 icalproperty_set_parameter (property, parameter);
676
677 found = TRUE;
678 break;
679 }
680
681 property = icalcomponent_get_next_property (
682 clone, ICAL_ATTENDEE_PROPERTY);
683 }
684
685 /* If the attendee is not already in the component, add it. */
686 if (!found) {
687 icalparameter *parameter;
688 gchar *address;
689
690 address = g_strdup_printf ("MAILTO:%s", attendee);
691
692 property = icalproperty_new_attendee (address);
693 icalcomponent_add_property (clone, property);
694
695 parameter = icalparameter_new_role (ICAL_ROLE_NONPARTICIPANT);
696 icalproperty_add_parameter (property, parameter);
697
698 parameter = icalparameter_new_cutype (ICAL_CUTYPE_INDIVIDUAL);
699 icalproperty_add_parameter (property, parameter);
700
701 parameter = icalparameter_new_rsvp (ICAL_RSVP_TRUE);
702 icalproperty_add_parameter (property, parameter);
703
704 g_free (address);
705 }
706
707 g_free (attendee);
708 g_object_unref (component);
709
710 e_calendar_view_open_event_with_flags (
711 calendar_view, event->comp_data->client, clone,
712 COMP_EDITOR_MEETING | COMP_EDITOR_DELEGATE);
713
714 icalcomponent_free (clone);
715 g_list_free (selected);
716 }
717
718 static void
719 action_event_delete_cb (GtkAction *action,
720 ECalShellView *cal_shell_view)
721 {
722 ECalShellContent *cal_shell_content;
723 GnomeCalendar *calendar;
724 GnomeCalendarViewType view_type;
725 ECalendarView *calendar_view;
726
727 cal_shell_content = cal_shell_view->priv->cal_shell_content;
728 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
729
730 view_type = gnome_calendar_get_view (calendar);
731 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
732
733 e_selectable_delete_selection (E_SELECTABLE (calendar_view));
734 }
735
736 static void
737 action_event_delete_occurrence_cb (GtkAction *action,
738 ECalShellView *cal_shell_view)
739 {
740 ECalShellContent *cal_shell_content;
741 GnomeCalendar *calendar;
742 GnomeCalendarViewType view_type;
743 ECalendarView *calendar_view;
744
745 cal_shell_content = cal_shell_view->priv->cal_shell_content;
746 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
747
748 view_type = gnome_calendar_get_view (calendar);
749 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
750
751 e_calendar_view_delete_selected_occurrence (calendar_view);
752 }
753
754 static void
755 action_event_forward_cb (GtkAction *action,
756 ECalShellView *cal_shell_view)
757 {
758 ECalShellContent *cal_shell_content;
759 GnomeCalendarViewType view_type;
760 ECalendarView *calendar_view;
761 GnomeCalendar *calendar;
762 ESourceRegistry *registry;
763 ECalendarViewEvent *event;
764 ECalComponent *component;
765 ECalClient *client;
766 icalcomponent *icalcomp;
767 GList *selected;
768
769 cal_shell_content = cal_shell_view->priv->cal_shell_content;
770 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
771 registry = gnome_calendar_get_registry (calendar);
772
773 view_type = gnome_calendar_get_view (calendar);
774 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
775
776 selected = e_calendar_view_get_selected_events (calendar_view);
777 g_return_if_fail (g_list_length (selected) == 1);
778
779 event = selected->data;
780
781 if (!is_comp_data_valid (event))
782 return;
783
784 client = event->comp_data->client;
785 icalcomp = event->comp_data->icalcomp;
786
787 component = e_cal_component_new ();
788
789 e_cal_component_set_icalcomponent (
790 component, icalcomponent_new_clone (icalcomp));
791 itip_send_comp (
792 registry, E_CAL_COMPONENT_METHOD_PUBLISH,
793 component, client, NULL, NULL, NULL, TRUE, FALSE);
794
795 g_object_unref (component);
796
797 g_list_free (selected);
798 }
799
800 static void
801 action_event_meeting_new_cb (GtkAction *action,
802 ECalShellView *cal_shell_view)
803 {
804 ECalShellContent *cal_shell_content;
805 GnomeCalendarViewType view_type;
806 ECalendarView *calendar_view;
807 GnomeCalendar *calendar;
808
809 /* These are just for readability. */
810 gboolean all_day = FALSE;
811 gboolean meeting = TRUE;
812 gboolean no_past_date = FALSE;
813
814 cal_shell_content = cal_shell_view->priv->cal_shell_content;
815 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
816 view_type = gnome_calendar_get_view (calendar);
817 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
818
819 e_calendar_view_new_appointment_full (
820 calendar_view, all_day, meeting, no_past_date);
821 }
822
823 static void
824 action_event_move_cb (GtkAction *action,
825 ECalShellView *cal_shell_view)
826 {
827 EShellView *shell_view;
828 EShellWindow *shell_window;
829 ECalShellContent *cal_shell_content;
830 GnomeCalendarViewType view_type;
831 GnomeCalendar *calendar;
832 ECalendarView *calendar_view;
833 ESource *source_source = NULL;
834 ESource *destination_source = NULL;
835 ESourceRegistry *registry;
836 ECalClient *destination_client = NULL;
837 GList *selected, *iter;
838 GError *error = NULL;
839
840 shell_view = E_SHELL_VIEW (cal_shell_view);
841 shell_window = e_shell_view_get_shell_window (shell_view);
842
843 cal_shell_content = cal_shell_view->priv->cal_shell_content;
844 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
845 registry = gnome_calendar_get_registry (calendar);
846
847 view_type = gnome_calendar_get_view (calendar);
848 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
849
850 selected = e_calendar_view_get_selected_events (calendar_view);
851 g_return_if_fail (selected != NULL);
852
853 if (selected->data) {
854 ECalendarViewEvent *event = selected->data;
855
856 if (is_comp_data_valid (event) && event->comp_data->client)
857 source_source = e_client_get_source (
858 E_CLIENT (event->comp_data->client));
859 }
860
861 /* Get a destination source from the user. */
862 destination_source = select_source_dialog (
863 GTK_WINDOW (shell_window), registry,
864 E_CAL_CLIENT_SOURCE_TYPE_EVENTS, source_source);
865 if (destination_source == NULL)
866 return;
867
868 /* Open the destination calendar. */
869 destination_client = e_cal_client_new (
870 destination_source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
871 if (destination_client == NULL)
872 goto exit;
873
874 e_client_open_sync (E_CLIENT (destination_client), FALSE, NULL, &error);
875
876 if (error != NULL) {
877 g_warning (
878 "%s: Failed to open destination client: %s",
879 G_STRFUNC, error->message);
880 g_clear_error (&error);
881 goto exit;
882 }
883
884 e_cal_shell_view_set_status_message (
885 cal_shell_view, _("Moving Items"), -1.0);
886
887 for (iter = selected; iter != NULL; iter = iter->next) {
888 ECalendarViewEvent *event = iter->data;
889 gboolean remove = TRUE;
890
891 e_cal_shell_view_transfer_item_to (
892 cal_shell_view, event, destination_client, remove);
893 }
894
895 e_cal_shell_view_set_status_message (cal_shell_view, NULL, -1.0);
896
897 exit:
898 if (destination_client != NULL)
899 g_object_unref (destination_client);
900 if (destination_source != NULL)
901 g_object_unref (destination_source);
902 g_list_free (selected);
903 }
904
905 static void
906 action_event_new_cb (GtkAction *action,
907 ECalShellView *cal_shell_view)
908 {
909 ECalShellContent *cal_shell_content;
910 GnomeCalendarViewType view_type;
911 ECalendarView *calendar_view;
912 GnomeCalendar *calendar;
913
914 cal_shell_content = cal_shell_view->priv->cal_shell_content;
915 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
916 view_type = gnome_calendar_get_view (calendar);
917 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
918
919 e_calendar_view_new_appointment (calendar_view);
920 }
921
922 static void
923 action_event_occurrence_movable_cb (GtkAction *action,
924 ECalShellView *cal_shell_view)
925 {
926 ECalShellContent *cal_shell_content;
927 GnomeCalendarViewType view_type;
928 GnomeCalendar *calendar;
929 ECalModel *model;
930 ECalendarView *calendar_view;
931 ECalendarViewEvent *event;
932 ECalComponent *exception_component;
933 ECalComponent *recurring_component;
934 ECalComponentDateTime date;
935 ECalComponentId *id;
936 ECalClient *client;
937 icalcomponent *icalcomp;
938 icaltimetype itt;
939 icaltimezone *timezone;
940 GList *selected;
941 gchar *uid;
942
943 cal_shell_content = cal_shell_view->priv->cal_shell_content;
944 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
945 view_type = gnome_calendar_get_view (calendar);
946 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
947
948 model = e_calendar_view_get_model (calendar_view);
949 timezone = e_cal_model_get_timezone (model);
950
951 selected = e_calendar_view_get_selected_events (calendar_view);
952 g_return_if_fail (g_list_length (selected) == 1);
953
954 event = selected->data;
955
956 if (!is_comp_data_valid (event))
957 return;
958
959 client = event->comp_data->client;
960 icalcomp = event->comp_data->icalcomp;
961
962 /* For the recurring object, we add an exception
963 * to get rid of the instance. */
964
965 recurring_component = e_cal_component_new ();
966 e_cal_component_set_icalcomponent (
967 recurring_component, icalcomponent_new_clone (icalcomp));
968 id = e_cal_component_get_id (recurring_component);
969
970 /* For the unrecurred instance, we duplicate the original object,
971 * create a new UID for it, get rid of the recurrence rules, and
972 * set the start and end times to the instance times. */
973
974 exception_component = e_cal_component_new ();
975 e_cal_component_set_icalcomponent (
976 exception_component, icalcomponent_new_clone (icalcomp));
977
978 uid = e_cal_component_gen_uid ();
979 e_cal_component_set_uid (exception_component, uid);
980 g_free (uid);
981
982 e_cal_component_set_recurid (exception_component, NULL);
983 e_cal_component_set_rdate_list (exception_component, NULL);
984 e_cal_component_set_rrule_list (exception_component, NULL);
985 e_cal_component_set_exdate_list (exception_component, NULL);
986 e_cal_component_set_exrule_list (exception_component, NULL);
987
988 date.value = &itt;
989 date.tzid = icaltimezone_get_tzid (timezone);
990 *date.value = icaltime_from_timet_with_zone (
991 event->comp_data->instance_start, FALSE, timezone);
992 cal_comp_set_dtstart_with_oldzone (client, exception_component, &date);
993 *date.value = icaltime_from_timet_with_zone (
994 event->comp_data->instance_end, FALSE, timezone);
995 cal_comp_set_dtstart_with_oldzone (client, exception_component, &date);
996 e_cal_component_commit_sequence (exception_component);
997
998 /* Now update both ECalComponents. Note that we do this last
999 * since at present the updates happend synchronously so our
1000 * event may disappear. */
1001
1002 e_cal_client_remove_object_sync (
1003 client, id->uid, id->rid, CALOBJ_MOD_THIS, NULL, NULL);
1004
1005 e_cal_component_free_id (id);
1006 g_object_unref (recurring_component);
1007
1008 icalcomp = e_cal_component_get_icalcomponent (exception_component);
1009 if (e_cal_client_create_object_sync (client, icalcomp, &uid, NULL, NULL))
1010 g_free (uid);
1011
1012 g_object_unref (exception_component);
1013
1014 g_list_free (selected);
1015 }
1016
1017 static void
1018 action_event_open_cb (GtkAction *action,
1019 ECalShellView *cal_shell_view)
1020 {
1021 ECalShellContent *cal_shell_content;
1022 GnomeCalendarViewType view_type;
1023 GnomeCalendar *calendar;
1024 ECalendarView *view;
1025
1026 cal_shell_content = cal_shell_view->priv->cal_shell_content;
1027 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
1028 view_type = gnome_calendar_get_view (calendar);
1029 view = gnome_calendar_get_calendar_view (calendar, view_type);
1030
1031 e_calendar_view_open_event (view);
1032 }
1033
1034 static void
1035 action_event_print_cb (GtkAction *action,
1036 ECalShellView *cal_shell_view)
1037 {
1038 ECalShellContent *cal_shell_content;
1039 GnomeCalendarViewType view_type;
1040 GnomeCalendar *calendar;
1041 ECalendarView *calendar_view;
1042 ECalendarViewEvent *event;
1043 ECalComponent *component;
1044 ECalModel *model;
1045 ECalClient *client;
1046 icalcomponent *icalcomp;
1047 GList *selected;
1048
1049 cal_shell_content = cal_shell_view->priv->cal_shell_content;
1050 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
1051 view_type = gnome_calendar_get_view (calendar);
1052 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
1053 model = e_calendar_view_get_model (calendar_view);
1054
1055 selected = e_calendar_view_get_selected_events (calendar_view);
1056 g_return_if_fail (g_list_length (selected) == 1);
1057
1058 event = selected->data;
1059
1060 if (!is_comp_data_valid (event))
1061 return;
1062
1063 client = event->comp_data->client;
1064 icalcomp = event->comp_data->icalcomp;
1065
1066 component = e_cal_component_new ();
1067
1068 e_cal_component_set_icalcomponent (
1069 component, icalcomponent_new_clone (icalcomp));
1070 print_comp (
1071 component, client,
1072 e_cal_model_get_timezone (model),
1073 e_cal_model_get_use_24_hour_format (model),
1074 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
1075
1076 g_object_unref (component);
1077
1078 g_list_free (selected);
1079 }
1080
1081 static void
1082 action_event_reply_cb (GtkAction *action,
1083 ECalShellView *cal_shell_view)
1084 {
1085 ECalShellContent *cal_shell_content;
1086 GnomeCalendarViewType view_type;
1087 ECalendarView *calendar_view;
1088 GnomeCalendar *calendar;
1089 ECalendarViewEvent *event;
1090 ECalComponent *component;
1091 ECalClient *client;
1092 ESourceRegistry *registry;
1093 icalcomponent *icalcomp;
1094 GList *selected;
1095 gboolean reply_all = FALSE;
1096
1097 cal_shell_content = cal_shell_view->priv->cal_shell_content;
1098 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
1099 registry = gnome_calendar_get_registry (calendar);
1100
1101 view_type = gnome_calendar_get_view (calendar);
1102 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
1103
1104 selected = e_calendar_view_get_selected_events (calendar_view);
1105 g_return_if_fail (g_list_length (selected) == 1);
1106
1107 event = selected->data;
1108
1109 if (!is_comp_data_valid (event))
1110 return;
1111
1112 client = event->comp_data->client;
1113 icalcomp = event->comp_data->icalcomp;
1114
1115 component = e_cal_component_new ();
1116
1117 e_cal_component_set_icalcomponent (
1118 component, icalcomponent_new_clone (icalcomp));
1119 reply_to_calendar_comp (
1120 registry, E_CAL_COMPONENT_METHOD_REPLY,
1121 component, client, reply_all, NULL, NULL);
1122
1123 g_object_unref (component);
1124
1125 g_list_free (selected);
1126 }
1127
1128 static void
1129 action_event_reply_all_cb (GtkAction *action,
1130 ECalShellView *cal_shell_view)
1131 {
1132 ECalShellContent *cal_shell_content;
1133 GnomeCalendarViewType view_type;
1134 ECalendarView *calendar_view;
1135 GnomeCalendar *calendar;
1136 ECalendarViewEvent *event;
1137 ECalComponent *component;
1138 ECalClient *client;
1139 ESourceRegistry *registry;
1140 icalcomponent *icalcomp;
1141 GList *selected;
1142 gboolean reply_all = TRUE;
1143
1144 cal_shell_content = cal_shell_view->priv->cal_shell_content;
1145 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
1146 registry = gnome_calendar_get_registry (calendar);
1147
1148 view_type = gnome_calendar_get_view (calendar);
1149 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
1150
1151 selected = e_calendar_view_get_selected_events (calendar_view);
1152 g_return_if_fail (g_list_length (selected) == 1);
1153
1154 event = selected->data;
1155
1156 if (!is_comp_data_valid (event))
1157 return;
1158
1159 client = event->comp_data->client;
1160 icalcomp = event->comp_data->icalcomp;
1161
1162 component = e_cal_component_new ();
1163
1164 e_cal_component_set_icalcomponent (
1165 component, icalcomponent_new_clone (icalcomp));
1166 reply_to_calendar_comp (
1167 registry, E_CAL_COMPONENT_METHOD_REPLY,
1168 component, client, reply_all, NULL, NULL);
1169
1170 g_object_unref (component);
1171
1172 g_list_free (selected);
1173 }
1174
1175 static void
1176 action_event_save_as_cb (GtkAction *action,
1177 ECalShellView *cal_shell_view)
1178 {
1179 EShell *shell;
1180 EShellView *shell_view;
1181 EShellWindow *shell_window;
1182 EShellBackend *shell_backend;
1183 ECalShellContent *cal_shell_content;
1184 GnomeCalendarViewType view_type;
1185 GnomeCalendar *calendar;
1186 ECalendarView *calendar_view;
1187 ECalendarViewEvent *event;
1188 ECalClient *client;
1189 icalcomponent *icalcomp;
1190 EActivity *activity;
1191 GList *selected;
1192 GFile *file;
1193 gchar *string = NULL;
1194
1195 shell_view = E_SHELL_VIEW (cal_shell_view);
1196 shell_window = e_shell_view_get_shell_window (shell_view);
1197 shell_backend = e_shell_view_get_shell_backend (shell_view);
1198 shell = e_shell_window_get_shell (shell_window);
1199
1200 cal_shell_content = cal_shell_view->priv->cal_shell_content;
1201 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
1202 view_type = gnome_calendar_get_view (calendar);
1203 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
1204
1205 selected = e_calendar_view_get_selected_events (calendar_view);
1206 g_return_if_fail (g_list_length (selected) == 1);
1207
1208 event = selected->data;
1209
1210 if (!is_comp_data_valid (event))
1211 return;
1212
1213 client = event->comp_data->client;
1214 icalcomp = event->comp_data->icalcomp;
1215
1216 /* Translators: Default filename part saving an event to a file when
1217 * no summary is filed, the '.ics' extension is concatenated to it. */
1218 string = icalcomp_suggest_filename (icalcomp, _("event"));
1219 file = e_shell_run_save_dialog (
1220 shell, _("Save as iCalendar"), string,
1221 "*.ics:text/calendar", NULL, NULL);
1222 g_free (string);
1223 if (file == NULL)
1224 return;
1225
1226 string = e_cal_client_get_component_as_string (client, icalcomp);
1227 if (string == NULL) {
1228 g_warning ("Could not convert item to a string");
1229 goto exit;
1230 }
1231
1232 /* XXX No callbacks means errors are discarded. */
1233 activity = e_file_replace_contents_async (
1234 file, string, strlen (string), NULL, FALSE,
1235 G_FILE_CREATE_NONE, (GAsyncReadyCallback) NULL, NULL);
1236 e_shell_backend_add_activity (shell_backend, activity);
1237
1238 /* Free the string when the activity is finalized. */
1239 g_object_set_data_full (
1240 G_OBJECT (activity),
1241 "file-content", string,
1242 (GDestroyNotify) g_free);
1243
1244 exit:
1245 g_object_unref (file);
1246
1247 g_list_free (selected);
1248 }
1249
1250 static void
1251 edit_event_as (ECalShellView *cal_shell_view,
1252 gboolean as_meeting)
1253 {
1254 ECalShellContent *cal_shell_content;
1255 GnomeCalendarViewType view_type;
1256 GnomeCalendar *calendar;
1257 ECalendarView *calendar_view;
1258 ECalendarViewEvent *event;
1259 ECalClient *client;
1260 icalcomponent *icalcomp;
1261 GList *selected;
1262
1263 cal_shell_content = cal_shell_view->priv->cal_shell_content;
1264 calendar = e_cal_shell_content_get_calendar (cal_shell_content);
1265 view_type = gnome_calendar_get_view (calendar);
1266 calendar_view = gnome_calendar_get_calendar_view (calendar, view_type);
1267
1268 selected = e_calendar_view_get_selected_events (calendar_view);
1269 g_return_if_fail (g_list_length (selected) == 1);
1270
1271 event = selected->data;
1272
1273 if (!is_comp_data_valid (event))
1274 return;
1275
1276 client = event->comp_data->client;
1277 icalcomp = event->comp_data->icalcomp;
1278
1279 if (!as_meeting && icalcomp) {
1280 /* remove organizer and all attendees */
1281 icalproperty *prop;
1282
1283 /* do it on a copy, as user can cancel changes */
1284 icalcomp = icalcomponent_new_clone (icalcomp);
1285
1286 prop = icalcomponent_get_first_property (
1287 icalcomp, ICAL_ATTENDEE_PROPERTY);
1288 while (prop != NULL) {
1289 icalcomponent_remove_property (icalcomp, prop);
1290 icalproperty_free (prop);
1291
1292 prop = icalcomponent_get_first_property (
1293 icalcomp, ICAL_ATTENDEE_PROPERTY);
1294 }
1295
1296 prop = icalcomponent_get_first_property (
1297 icalcomp, ICAL_ORGANIZER_PROPERTY);
1298 while (prop != NULL) {
1299 icalcomponent_remove_property (icalcomp, prop);
1300 icalproperty_free (prop);
1301
1302 prop = icalcomponent_get_first_property (
1303 icalcomp, ICAL_ORGANIZER_PROPERTY);
1304 }
1305 }
1306
1307 e_calendar_view_edit_appointment (
1308 calendar_view, client, icalcomp, as_meeting ?
1309 EDIT_EVENT_FORCE_MEETING : EDIT_EVENT_FORCE_APPOINTMENT);
1310
1311 if (!as_meeting && icalcomp) {
1312 icalcomponent_free (icalcomp);
1313 }
1314
1315 g_list_free (selected);
1316 }
1317
1318 static void
1319 action_event_schedule_cb (GtkAction *action,
1320 ECalShellView *cal_shell_view)
1321 {
1322 edit_event_as (cal_shell_view, TRUE);
1323 }
1324
1325 static void
1326 quit_calendar_cb (GtkAction *action,
1327 ECalShellView *cal_shell_view)
1328 {
1329 EShellView *shell_view;
1330 EShellWindow *shell_window;
1331 GdkWindow *window;
1332 GdkEvent *event;
1333
1334 shell_view = E_SHELL_VIEW (cal_shell_view);
1335 shell_window = e_shell_view_get_shell_window (shell_view);
1336
1337 /* Synthesize a delete_event on this window. */
1338 event = gdk_event_new (GDK_DELETE);
1339 window = gtk_widget_get_window (GTK_WIDGET (shell_window));
1340 event->any.window = g_object_ref (window);
1341 event->any.send_event = TRUE;
1342 gtk_main_do_event (event);
1343 gdk_event_free (event);
1344
1345 }
1346
1347 static void
1348 action_event_schedule_appointment_cb (GtkAction *action,
1349 ECalShellView *cal_shell_view)
1350 {
1351 edit_event_as (cal_shell_view, FALSE);
1352 }
1353
1354 static void
1355 action_gal_save_custom_view_cb (GtkAction *action,
1356 ECalShellView *cal_shell_view)
1357 {
1358 ECalShellContent *cal_shell_content;
1359 EShellView *shell_view;
1360 GalViewInstance *view_instance;
1361
1362 /* All shell views respond to the activation of this action,
1363 * which is defined by EShellWindow. But only the currently
1364 * active shell view proceeds with saving the custom view. */
1365 shell_view = E_SHELL_VIEW (cal_shell_view);
1366 if (!e_shell_view_is_active (shell_view))
1367 return;
1368
1369 cal_shell_content = cal_shell_view->priv->cal_shell_content;
1370 view_instance = e_cal_shell_content_get_view_instance (cal_shell_content);
1371 gal_view_instance_save_as (view_instance);
1372 }
1373
1374 static GtkActionEntry calendar_entries[] = {
1375
1376 { "calendar-copy",
1377 GTK_STOCK_COPY,
1378 N_("_Copy..."),
1379 NULL,
1380 NULL, /* XXX Add a tooltip! */
1381 G_CALLBACK (action_calendar_copy_cb) },
1382
1383 { "calendar-delete",
1384 GTK_STOCK_DELETE,
1385 N_("D_elete Calendar"),
1386 NULL,
1387 N_("Delete the selected calendar"),
1388 G_CALLBACK (action_calendar_delete_cb) },
1389
1390 { "calendar-go-back",
1391 GTK_STOCK_GO_BACK,
1392 N_("Previous"),
1393 NULL,
1394 N_("Go Back"),
1395 G_CALLBACK (action_calendar_go_back_cb) },
1396
1397 { "calendar-go-forward",
1398 GTK_STOCK_GO_FORWARD,
1399 N_("Next"),
1400 NULL,
1401 N_("Go Forward"),
1402 G_CALLBACK (action_calendar_go_forward_cb) },
1403
1404 { "calendar-go-today",
1405 "go-today",
1406 N_("Select _Today"),
1407 "<Control>t",
1408 N_("Select today"),
1409 G_CALLBACK (action_calendar_go_today_cb) },
1410
1411 { "calendar-jump-to",
1412 GTK_STOCK_JUMP_TO,
1413 N_("Select _Date"),
1414 "<Control>g",
1415 N_("Select a specific date"),
1416 G_CALLBACK (action_calendar_jump_to_cb) },
1417
1418 { "calendar-new",
1419 "x-office-calendar",
1420 N_("_New Calendar"),
1421 NULL,
1422 N_("Create a new calendar"),
1423 G_CALLBACK (action_calendar_new_cb) },
1424
1425 { "calendar-properties",
1426 GTK_STOCK_PROPERTIES,
1427 NULL,
1428 NULL,
1429 NULL, /* XXX Add a tooltip! */
1430 G_CALLBACK (action_calendar_properties_cb) },
1431
1432 { "calendar-purge",
1433 NULL,
1434 N_("Purg_e"),
1435 "<Control>e",
1436 N_("Purge old appointments and meetings"),
1437 G_CALLBACK (action_calendar_purge_cb) },
1438
1439 { "calendar-refresh",
1440 GTK_STOCK_REFRESH,
1441 N_("Re_fresh"),
1442 NULL,
1443 N_("Refresh the selected calendar"),
1444 G_CALLBACK (action_calendar_refresh_cb) },
1445
1446 { "calendar-rename",
1447 NULL,
1448 N_("_Rename..."),
1449 "F2",
1450 N_("Rename the selected calendar"),
1451 G_CALLBACK (action_calendar_rename_cb) },
1452
1453 { "calendar-search-next",
1454 GTK_STOCK_GO_FORWARD,
1455 N_("Find _next"),
1456 "<Control><Shift>n",
1457 N_("Find next occurrence of the current search string"),
1458 G_CALLBACK (action_calendar_search_next_cb) },
1459
1460 { "calendar-search-prev",
1461 GTK_STOCK_GO_BACK,
1462 N_("Find _previous"),
1463 "<Control><Shift>p",
1464 N_("Find previous occurrence of the current search string"),
1465 G_CALLBACK (action_calendar_search_prev_cb) },
1466
1467 { "calendar-search-stop",
1468 GTK_STOCK_STOP,
1469 N_("Stop _running search"),
1470 NULL,
1471 N_("Stop currently running search"),
1472 G_CALLBACK (action_calendar_search_stop_cb) },
1473
1474 { "calendar-select-one",
1475 "stock_check-filled",
1476 N_("Show _Only This Calendar"),
1477 NULL,
1478 NULL, /* XXX Add a tooltip! */
1479 G_CALLBACK (action_calendar_select_one_cb) },
1480
1481 { "event-copy",
1482 NULL,
1483 N_("Cop_y to Calendar..."),
1484 NULL,
1485 NULL, /* XXX Add a tooltip! */
1486 G_CALLBACK (action_event_copy_cb) },
1487
1488 { "event-delegate",
1489 NULL,
1490 N_("_Delegate Meeting..."),
1491 NULL,
1492 NULL, /* XXX Add a tooltip! */
1493 G_CALLBACK (action_event_delegate_cb) },
1494
1495 { "event-delete",
1496 GTK_STOCK_DELETE,
1497 N_("_Delete Appointment"),
1498 "<Control>d",
1499 N_("Delete selected appointments"),
1500 G_CALLBACK (action_event_delete_cb) },
1501
1502 { "event-delete-occurrence",
1503 GTK_STOCK_DELETE,
1504 N_("Delete This _Occurrence"),
1505 NULL,
1506 N_("Delete this occurrence"),
1507 G_CALLBACK (action_event_delete_occurrence_cb) },
1508
1509 { "event-delete-occurrence-all",
1510 GTK_STOCK_DELETE,
1511 N_("Delete All Occ_urrences"),
1512 NULL,
1513 N_("Delete all occurrences"),
1514 G_CALLBACK (action_event_delete_cb) },
1515
1516 { "event-all-day-new",
1517 "stock_new-24h-appointment",
1518 N_("New All Day _Event..."),
1519 NULL,
1520 N_("Create a new all day event"),
1521 G_CALLBACK (action_event_all_day_new_cb) },
1522
1523 { "event-forward",
1524 "mail-forward",
1525 N_("_Forward as iCalendar..."),
1526 NULL,
1527 NULL, /* XXX Add a tooltip! */
1528 G_CALLBACK (action_event_forward_cb) },
1529
1530 { "event-meeting-new",
1531 "stock_new-meeting",
1532 N_("New _Meeting..."),
1533 NULL,
1534 N_("Create a new meeting"),
1535 G_CALLBACK (action_event_meeting_new_cb) },
1536
1537 { "event-move",
1538 NULL,
1539 N_("Mo_ve to Calendar..."),
1540 NULL,
1541 NULL, /* XXX Add a tooltip! */
1542 G_CALLBACK (action_event_move_cb) },
1543
1544 { "event-new",
1545 "appointment-new",
1546 N_("New _Appointment..."),
1547 NULL,
1548 N_("Create a new appointment"),
1549 G_CALLBACK (action_event_new_cb) },
1550
1551 { "event-occurrence-movable",
1552 NULL,
1553 N_("Make this Occurrence _Movable"),
1554 NULL,
1555 NULL, /* XXX Add a tooltip! */
1556 G_CALLBACK (action_event_occurrence_movable_cb) },
1557
1558 { "event-open",
1559 GTK_STOCK_OPEN,
1560 N_("_Open Appointment"),
1561 "<Control>o",
1562 N_("View the current appointment"),
1563 G_CALLBACK (action_event_open_cb) },
1564
1565 { "event-reply",
1566 "mail-reply-sender",
1567 N_("_Reply"),
1568 NULL,
1569 NULL, /* XXX Add a tooltip! */
1570 G_CALLBACK (action_event_reply_cb) },
1571
1572 { "event-reply-all",
1573 "mail-reply-all",
1574 N_("Reply to _All"),
1575 NULL,
1576 NULL, /* XXX Add a tooltip! */
1577 G_CALLBACK (action_event_reply_all_cb) },
1578
1579 { "event-schedule",
1580 NULL,
1581 N_("_Schedule Meeting..."),
1582 NULL,
1583 N_("Converts an appointment to a meeting"),
1584 G_CALLBACK (action_event_schedule_cb) },
1585
1586 { "event-schedule-appointment",
1587 NULL,
1588 N_("Conv_ert to Appointment..."),
1589 NULL,
1590 N_("Converts a meeting to an appointment"),
1591 G_CALLBACK (action_event_schedule_appointment_cb) },
1592
1593 { "quit-calendar",
1594 GTK_STOCK_CLOSE,
1595 N_("Quit"),
1596 NULL,
1597 NULL, /* XXX Add a tooltip! */
1598 G_CALLBACK (quit_calendar_cb) },
1599
1600 /*** Menus ***/
1601
1602 { "calendar-actions-menu",
1603 NULL,
1604 N_("_Actions"),
1605 NULL,
1606 NULL,
1607 NULL }
1608 };
1609
1610 static EPopupActionEntry calendar_popup_entries[] = {
1611
1612 /* FIXME No equivalent main menu items for the any of the calendar
1613 * popup menu items and for many of the event popup menu items.
1614 * This is an accessibility issue. */
1615
1616 { "calendar-popup-copy",
1617 NULL,
1618 "calendar-copy" },
1619
1620 { "calendar-popup-delete",
1621 N_("_Delete"),
1622 "calendar-delete" },
1623
1624 { "calendar-popup-go-today",
1625 NULL,
1626 "calendar-go-today" },
1627
1628 { "calendar-popup-jump-to",
1629 NULL,
1630 "calendar-jump-to" },
1631
1632 { "calendar-popup-properties",
1633 NULL,
1634 "calendar-properties" },
1635
1636 { "calendar-popup-refresh",
1637 NULL,
1638 "calendar-refresh" },
1639
1640 { "calendar-popup-rename",
1641 NULL,
1642 "calendar-rename" },
1643
1644 { "calendar-popup-select-one",
1645 NULL,
1646 "calendar-select-one" },
1647
1648 { "event-popup-copy",
1649 NULL,
1650 "event-copy" },
1651
1652 { "event-popup-delegate",
1653 NULL,
1654 "event-delegate" },
1655
1656 { "event-popup-delete",
1657 NULL,
1658 "event-delete" },
1659
1660 { "event-popup-delete-occurrence",
1661 NULL,
1662 "event-delete-occurrence" },
1663
1664 { "event-popup-delete-occurrence-all",
1665 NULL,
1666 "event-delete-occurrence-all" },
1667
1668 { "event-popup-forward",
1669 NULL,
1670 "event-forward" },
1671
1672 { "event-popup-move",
1673 NULL,
1674 "event-move" },
1675
1676 { "event-popup-occurrence-movable",
1677 NULL,
1678 "event-occurrence-movable" },
1679
1680 { "event-popup-open",
1681 NULL,
1682 "event-open" },
1683
1684 { "event-popup-reply",
1685 NULL,
1686 "event-reply" },
1687
1688 { "event-popup-reply-all",
1689 NULL,
1690 "event-reply-all" },
1691
1692 { "event-popup-schedule",
1693 NULL,
1694 "event-schedule" },
1695
1696 { "event-popup-schedule-appointment",
1697 NULL,
1698 "event-schedule-appointment" }
1699 };
1700
1701 static GtkRadioActionEntry calendar_view_entries[] = {
1702
1703 /* This action represents the initial calendar view.
1704 * It should not be visible in the UI, nor should it be
1705 * possible to switch to it from another calendar view. */
1706 { "calendar-view-initial",
1707 NULL,
1708 NULL,
1709 NULL,
1710 NULL,
1711 BOGUS_INITIAL_VALUE },
1712
1713 { "calendar-view-day",
1714 "view-calendar-day",
1715 N_("Day"),
1716 NULL,
1717 N_("Show one day"),
1718 GNOME_CAL_DAY_VIEW },
1719
1720 { "calendar-view-list",
1721 "view-calendar-list",
1722 N_("List"),
1723 NULL,
1724 N_("Show as list"),
1725 GNOME_CAL_LIST_VIEW },
1726
1727 { "calendar-view-month",
1728 "view-calendar-month",
1729 N_("Month"),
1730 NULL,
1731 N_("Show one month"),
1732 GNOME_CAL_MONTH_VIEW },
1733
1734 { "calendar-view-week",
1735 "view-calendar-week",
1736 N_("Week"),
1737 NULL,
1738 N_("Show one week"),
1739 GNOME_CAL_WEEK_VIEW },
1740
1741 { "calendar-view-workweek",
1742 "view-calendar-workweek",
1743 N_("Work Week"),
1744 NULL,
1745 N_("Show one work week"),
1746 GNOME_CAL_WORK_WEEK_VIEW }
1747 };
1748
1749 static GtkRadioActionEntry calendar_filter_entries[] = {
1750
1751 { "calendar-filter-active-appointments",
1752 NULL,
1753 N_("Active Appointments"),
1754 NULL,
1755 NULL, /* XXX Add a tooltip! */
1756 CALENDAR_FILTER_ACTIVE_APPOINTMENTS },
1757
1758 { "calendar-filter-any-category",
1759 NULL,
1760 N_("Any Category"),
1761 NULL,
1762 NULL, /* XXX Add a tooltip! */
1763 CALENDAR_FILTER_ANY_CATEGORY },
1764
1765 { "calendar-filter-next-7-days-appointments",
1766 NULL,
1767 N_("Next 7 Days' Appointments"),
1768 NULL,
1769 NULL, /* XXX Add a tooltip! */
1770 CALENDAR_FILTER_NEXT_7_DAYS_APPOINTMENTS },
1771
1772 { "calendar-filter-occurs-less-than-5-times",
1773 NULL,
1774 N_("Occurs Less Than 5 Times"),
1775 NULL,
1776 NULL, /* XXX Add a tooltip! */
1777 CALENDAR_FILTER_OCCURS_LESS_THAN_5_TIMES },
1778
1779 { "calendar-filter-unmatched",
1780 NULL,
1781 N_("Unmatched"),
1782 NULL,
1783 NULL, /* XXX Add a tooltip! */
1784 CALENDAR_FILTER_UNMATCHED }
1785 };
1786
1787 static GtkRadioActionEntry calendar_search_entries[] = {
1788
1789 { "calendar-search-advanced-hidden",
1790 NULL,
1791 N_("Advanced Search"),
1792 NULL,
1793 NULL,
1794 CALENDAR_SEARCH_ADVANCED },
1795
1796 { "calendar-search-any-field-contains",
1797 NULL,
1798 N_("Any field contains"),
1799 NULL,
1800 NULL, /* XXX Add a tooltip! */
1801 CALENDAR_SEARCH_ANY_FIELD_CONTAINS },
1802
1803 { "calendar-search-description-contains",
1804 NULL,
1805 N_("Description contains"),
1806 NULL,
1807 NULL, /* XXX Add a tooltip! */
1808 CALENDAR_SEARCH_DESCRIPTION_CONTAINS },
1809
1810 { "calendar-search-summary-contains",
1811 NULL,
1812 N_("Summary contains"),
1813 NULL,
1814 NULL, /* XXX Add a tooltip! */
1815 CALENDAR_SEARCH_SUMMARY_CONTAINS }
1816 };
1817
1818 static GtkActionEntry lockdown_printing_entries[] = {
1819
1820 { "calendar-print",
1821 GTK_STOCK_PRINT,
1822 NULL,
1823 "<Control>p",
1824 N_("Print this calendar"),
1825 G_CALLBACK (action_calendar_print_cb) },
1826
1827 { "calendar-print-preview",
1828 GTK_STOCK_PRINT_PREVIEW,
1829 NULL,
1830 NULL,
1831 N_("Preview the calendar to be printed"),
1832 G_CALLBACK (action_calendar_print_preview_cb) },
1833
1834 { "event-print",
1835 GTK_STOCK_PRINT,
1836 NULL,
1837 NULL,
1838 NULL, /* XXX Add a tooltip! */
1839 G_CALLBACK (action_event_print_cb) }
1840 };
1841
1842 static EPopupActionEntry lockdown_printing_popup_entries[] = {
1843
1844 { "event-popup-print",
1845 NULL,
1846 "event-print" }
1847 };
1848
1849 static GtkActionEntry lockdown_save_to_disk_entries[] = {
1850
1851 { "event-save-as",
1852 GTK_STOCK_SAVE_AS,
1853 N_("_Save as iCalendar..."),
1854 NULL,
1855 NULL, /* XXX Add a tooltip! */
1856 G_CALLBACK (action_event_save_as_cb) },
1857 };
1858
1859 static EPopupActionEntry lockdown_save_to_disk_popup_entries[] = {
1860
1861 { "event-popup-save-as",
1862 NULL,
1863 "event-save-as" },
1864 };
1865
1866 void
1867 e_cal_shell_view_actions_init (ECalShellView *cal_shell_view)
1868 {
1869 ECalShellContent *cal_shell_content;
1870 EShellView *shell_view;
1871 EShellWindow *shell_window;
1872 EShellSearchbar *searchbar;
1873 GtkActionGroup *action_group;
1874 GtkAction *action;
1875
1876 shell_view = E_SHELL_VIEW (cal_shell_view);
1877 shell_window = e_shell_view_get_shell_window (shell_view);
1878
1879 cal_shell_content = cal_shell_view->priv->cal_shell_content;
1880 searchbar = e_cal_shell_content_get_searchbar (cal_shell_content);
1881
1882 /* Calendar Actions */
1883 action_group = ACTION_GROUP (CALENDAR);
1884 gtk_action_group_add_actions (
1885 action_group, calendar_entries,
1886 G_N_ELEMENTS (calendar_entries), cal_shell_view);
1887 e_action_group_add_popup_actions (
1888 action_group, calendar_popup_entries,
1889 G_N_ELEMENTS (calendar_popup_entries));
1890 gtk_action_group_add_radio_actions (
1891 action_group, calendar_view_entries,
1892 G_N_ELEMENTS (calendar_view_entries), BOGUS_INITIAL_VALUE,
1893 G_CALLBACK (action_calendar_view_cb), cal_shell_view);
1894 gtk_action_group_add_radio_actions (
1895 action_group, calendar_search_entries,
1896 G_N_ELEMENTS (calendar_search_entries),
1897 -1, NULL, NULL);
1898
1899 /* Advanced Search Action */
1900 action = ACTION (CALENDAR_SEARCH_ADVANCED_HIDDEN);
1901 gtk_action_set_visible (action, FALSE);
1902 if (searchbar)
1903 e_shell_searchbar_set_search_option (
1904 searchbar, GTK_RADIO_ACTION (action));
1905
1906 /* Lockdown Printing Actions */
1907 action_group = ACTION_GROUP (LOCKDOWN_PRINTING);
1908 gtk_action_group_add_actions (
1909 action_group, lockdown_printing_entries,
1910 G_N_ELEMENTS (lockdown_printing_entries), cal_shell_view);
1911 e_action_group_add_popup_actions (
1912 action_group, lockdown_printing_popup_entries,
1913 G_N_ELEMENTS (lockdown_printing_popup_entries));
1914
1915 /* Lockdown Save-to-Disk Actions */
1916 action_group = ACTION_GROUP (LOCKDOWN_SAVE_TO_DISK);
1917 gtk_action_group_add_actions (
1918 action_group, lockdown_save_to_disk_entries,
1919 G_N_ELEMENTS (lockdown_save_to_disk_entries), cal_shell_view);
1920 e_action_group_add_popup_actions (
1921 action_group, lockdown_save_to_disk_popup_entries,
1922 G_N_ELEMENTS (lockdown_save_to_disk_popup_entries));
1923
1924 /* Fine tuning. */
1925
1926 action = ACTION (CALENDAR_GO_TODAY);
1927 gtk_action_set_short_label (action, _("Today"));
1928
1929 action = ACTION (CALENDAR_JUMP_TO);
1930 gtk_action_set_short_label (action, _("Go To"));
1931
1932 action = ACTION (CALENDAR_VIEW_DAY);
1933 gtk_action_set_is_important (action, TRUE);
1934
1935 action = ACTION (CALENDAR_VIEW_LIST);
1936 gtk_action_set_is_important (action, TRUE);
1937
1938 action = ACTION (CALENDAR_VIEW_MONTH);
1939 gtk_action_set_is_important (action, TRUE);
1940
1941 action = ACTION (CALENDAR_VIEW_WEEK);
1942 gtk_action_set_is_important (action, TRUE);
1943
1944 action = ACTION (CALENDAR_VIEW_WORKWEEK);
1945 gtk_action_set_is_important (action, TRUE);
1946
1947 g_signal_connect (
1948 ACTION (GAL_SAVE_CUSTOM_VIEW), "activate",
1949 G_CALLBACK (action_gal_save_custom_view_cb), cal_shell_view);
1950
1951 /* Initialize the memo and task pad actions. */
1952 e_cal_shell_view_memopad_actions_init (cal_shell_view);
1953 e_cal_shell_view_taskpad_actions_init (cal_shell_view);
1954 }
1955
1956 void
1957 e_cal_shell_view_update_search_filter (ECalShellView *cal_shell_view)
1958 {
1959 ECalShellContent *cal_shell_content;
1960 EShellView *shell_view;
1961 EShellWindow *shell_window;
1962 EShellSearchbar *searchbar;
1963 EActionComboBox *combo_box;
1964 GtkActionGroup *action_group;
1965 GtkRadioAction *radio_action;
1966 GList *list, *iter;
1967 GSList *group;
1968 gint ii;
1969
1970 shell_view = E_SHELL_VIEW (cal_shell_view);
1971 shell_window = e_shell_view_get_shell_window (shell_view);
1972
1973 action_group = ACTION_GROUP (CALENDAR_FILTER);
1974 e_action_group_remove_all_actions (action_group);
1975
1976 /* Add the standard filter actions. No callback is needed
1977 * because changes in the EActionComboBox are detected and
1978 * handled by EShellSearchbar. */
1979 gtk_action_group_add_radio_actions (
1980 action_group, calendar_filter_entries,
1981 G_N_ELEMENTS (calendar_filter_entries),
1982 CALENDAR_FILTER_ANY_CATEGORY, NULL, NULL);
1983
1984 /* Retrieve the radio group from an action we just added. */
1985 list = gtk_action_group_list_actions (action_group);
1986 radio_action = GTK_RADIO_ACTION (list->data);
1987 group = gtk_radio_action_get_group (radio_action);
1988 g_list_free (list);
1989
1990 /* Build the category actions. */
1991
1992 list = e_util_get_searchable_categories ();
1993 for (iter = list, ii = 0; iter != NULL; iter = iter->next, ii++) {
1994 const gchar *category_name = iter->data;
1995 const gchar *filename;
1996 GtkAction *action;
1997 gchar *action_name;
1998
1999 action_name = g_strdup_printf (
2000 "calendar-filter-category-%d", ii);
2001 radio_action = gtk_radio_action_new (
2002 action_name, category_name, NULL, NULL, ii);
2003 g_free (action_name);
2004
2005 /* Convert the category icon file to a themed icon name. */
2006 filename = e_categories_get_icon_file_for (category_name);
2007 if (filename != NULL && *filename != '\0') {
2008 gchar *basename;
2009 gchar *cp;
2010
2011 basename = g_path_get_basename (filename);
2012
2013 /* Lose the file extension. */
2014 if ((cp = strrchr (basename, '.')) != NULL)
2015 *cp = '\0';
2016
2017 g_object_set (
2018 radio_action, "icon-name", basename, NULL);
2019
2020 g_free (basename);
2021 }
2022
2023 gtk_radio_action_set_group (radio_action, group);
2024 group = gtk_radio_action_get_group (radio_action);
2025
2026 /* The action group takes ownership of the action. */
2027 action = GTK_ACTION (radio_action);
2028 gtk_action_group_add_action (action_group, action);
2029 g_object_unref (radio_action);
2030 }
2031 g_list_free (list);
2032
2033 cal_shell_content = cal_shell_view->priv->cal_shell_content;
2034 searchbar = e_cal_shell_content_get_searchbar (cal_shell_content);
2035 if (searchbar) {
2036 combo_box = e_shell_searchbar_get_filter_combo_box (searchbar);
2037
2038 e_shell_view_block_execute_search (shell_view);
2039
2040 /* Use any action in the group; doesn't matter which. */
2041 e_action_combo_box_set_action (combo_box, radio_action);
2042
2043 ii = CALENDAR_FILTER_UNMATCHED;
2044 e_action_combo_box_add_separator_after (combo_box, ii);
2045
2046 ii = CALENDAR_FILTER_OCCURS_LESS_THAN_5_TIMES;
2047 e_action_combo_box_add_separator_after (combo_box, ii);
2048
2049 e_shell_view_unblock_execute_search (shell_view);
2050 }
2051 }