No issues found
1 /*
2 * e-task-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-task-shell-view-private.h"
28
29 static void
30 action_gal_save_custom_view_cb (GtkAction *action,
31 ETaskShellView *task_shell_view)
32 {
33 ETaskShellContent *task_shell_content;
34 EShellView *shell_view;
35 GalViewInstance *view_instance;
36
37 /* All shell views respond to the activation of this action,
38 * which is defined by EShellWindow. But only the currently
39 * active shell view proceeds with saving the custom view. */
40 shell_view = E_SHELL_VIEW (task_shell_view);
41 if (!e_shell_view_is_active (shell_view))
42 return;
43
44 task_shell_content = task_shell_view->priv->task_shell_content;
45 view_instance = e_task_shell_content_get_view_instance (task_shell_content);
46 gal_view_instance_save_as (view_instance);
47 }
48
49 static void
50 action_task_assign_cb (GtkAction *action,
51 ETaskShellView *task_shell_view)
52 {
53 ETaskShellContent *task_shell_content;
54 ECalModelComponent *comp_data;
55 ETaskTable *task_table;
56 GSList *list;
57
58 task_shell_content = task_shell_view->priv->task_shell_content;
59 task_table = e_task_shell_content_get_task_table (task_shell_content);
60
61 list = e_task_table_get_selected (task_table);
62 g_return_if_fail (list != NULL);
63 comp_data = list->data;
64 g_slist_free (list);
65
66 /* XXX We only open the first selected task. */
67 e_task_shell_view_open_task (task_shell_view, comp_data);
68
69 /* FIXME Need to actually assign the task. */
70 }
71
72 static void
73 action_task_delete_cb (GtkAction *action,
74 ETaskShellView *task_shell_view)
75 {
76 ETaskShellContent *task_shell_content;
77 ETaskTable *task_table;
78
79 task_shell_content = task_shell_view->priv->task_shell_content;
80 task_table = e_task_shell_content_get_task_table (task_shell_content);
81
82 e_selectable_delete_selection (E_SELECTABLE (task_table));
83 }
84
85 static void
86 action_task_find_cb (GtkAction *action,
87 ETaskShellView *task_shell_view)
88 {
89 ETaskShellContent *task_shell_content;
90 EPreviewPane *preview_pane;
91
92 task_shell_content = task_shell_view->priv->task_shell_content;
93 preview_pane = e_task_shell_content_get_preview_pane (task_shell_content);
94
95 e_preview_pane_show_search_bar (preview_pane);
96 }
97
98 static void
99 action_task_forward_cb (GtkAction *action,
100 ETaskShellView *task_shell_view)
101 {
102 ETaskShellContent *task_shell_content;
103 EShell *shell;
104 EShellView *shell_view;
105 EShellWindow *shell_window;
106 ESourceRegistry *registry;
107 ECalModelComponent *comp_data;
108 ETaskTable *task_table;
109 ECalComponent *comp;
110 icalcomponent *clone;
111 GSList *list;
112
113 shell_view = E_SHELL_VIEW (task_shell_view);
114 shell_window = e_shell_view_get_shell_window (shell_view);
115 shell = e_shell_window_get_shell (shell_window);
116
117 registry = e_shell_get_registry (shell);
118
119 task_shell_content = task_shell_view->priv->task_shell_content;
120 task_table = e_task_shell_content_get_task_table (task_shell_content);
121
122 list = e_task_table_get_selected (task_table);
123 g_return_if_fail (list != NULL);
124 comp_data = list->data;
125 g_slist_free (list);
126
127 /* XXX We only forward the first selected task. */
128 comp = e_cal_component_new ();
129 clone = icalcomponent_new_clone (comp_data->icalcomp);
130 e_cal_component_set_icalcomponent (comp, clone);
131
132 itip_send_comp (
133 registry, E_CAL_COMPONENT_METHOD_PUBLISH, comp,
134 comp_data->client, NULL, NULL, NULL, TRUE, FALSE);
135
136 g_object_unref (comp);
137 }
138
139 static void
140 action_task_list_copy_cb (GtkAction *action,
141 ETaskShellView *task_shell_view)
142 {
143 ETaskShellSidebar *task_shell_sidebar;
144 EShell *shell;
145 EShellView *shell_view;
146 EShellWindow *shell_window;
147 ESourceRegistry *registry;
148 ESourceSelector *selector;
149 ESource *source;
150
151 shell_view = E_SHELL_VIEW (task_shell_view);
152 shell_window = e_shell_view_get_shell_window (shell_view);
153 shell = e_shell_window_get_shell (shell_window);
154
155 registry = e_shell_get_registry (shell);
156
157 task_shell_sidebar = task_shell_view->priv->task_shell_sidebar;
158 selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
159 source = e_source_selector_ref_primary_selection (selector);
160 g_return_if_fail (source != NULL);
161
162 copy_source_dialog (
163 GTK_WINDOW (shell_window), registry,
164 source, E_CAL_CLIENT_SOURCE_TYPE_TASKS);
165
166 g_object_unref (source);
167 }
168
169 static void
170 action_task_list_delete_cb (GtkAction *action,
171 ETaskShellView *task_shell_view)
172 {
173 ETaskShellSidebar *task_shell_sidebar;
174 EShellWindow *shell_window;
175 EShellView *shell_view;
176 ESource *source;
177 ESourceSelector *selector;
178 gint response;
179
180 shell_view = E_SHELL_VIEW (task_shell_view);
181 shell_window = e_shell_view_get_shell_window (shell_view);
182
183 task_shell_sidebar = task_shell_view->priv->task_shell_sidebar;
184 selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
185
186 source = e_source_selector_ref_primary_selection (selector);
187 g_return_if_fail (source != NULL);
188
189 if (e_source_get_remote_deletable (source)) {
190 response = e_alert_run_dialog_for_args (
191 GTK_WINDOW (shell_window),
192 "calendar:prompt-delete-remote-task-list",
193 e_source_get_display_name (source), NULL);
194
195 if (response == GTK_RESPONSE_YES)
196 e_shell_view_remote_delete_source (shell_view, source);
197
198 } else {
199 response = e_alert_run_dialog_for_args (
200 GTK_WINDOW (shell_window),
201 "calendar:prompt-delete-task-list",
202 e_source_get_display_name (source), NULL);
203
204 if (response == GTK_RESPONSE_YES)
205 e_shell_view_remove_source (shell_view, source);
206 }
207
208 g_object_unref (source);
209 }
210
211 static void
212 action_task_list_new_cb (GtkAction *action,
213 ETaskShellView *task_shell_view)
214 {
215 EShell *shell;
216 EShellView *shell_view;
217 EShellWindow *shell_window;
218 ESourceRegistry *registry;
219 ECalClientSourceType source_type;
220 GtkWidget *config;
221 GtkWidget *dialog;
222 const gchar *icon_name;
223
224 shell_view = E_SHELL_VIEW (task_shell_view);
225 shell_window = e_shell_view_get_shell_window (shell_view);
226 shell = e_shell_window_get_shell (shell_window);
227
228 registry = e_shell_get_registry (shell);
229 source_type = E_CAL_CLIENT_SOURCE_TYPE_TASKS;
230 config = e_cal_source_config_new (registry, NULL, source_type);
231
232 dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
233
234 gtk_window_set_transient_for (
235 GTK_WINDOW (dialog), GTK_WINDOW (shell_window));
236
237 icon_name = gtk_action_get_icon_name (action);
238 gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name);
239
240 gtk_window_set_title (GTK_WINDOW (dialog), _("New Task List"));
241
242 gtk_widget_show (dialog);
243 }
244
245 static void
246 action_task_list_print_cb (GtkAction *action,
247 ETaskShellView *task_shell_view)
248 {
249 ETaskShellContent *task_shell_content;
250 ETaskTable *task_table;
251
252 task_shell_content = task_shell_view->priv->task_shell_content;
253 task_table = e_task_shell_content_get_task_table (task_shell_content);
254
255 print_table (
256 E_TABLE (task_table), _("Print Tasks"), _("Tasks"),
257 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
258 }
259
260 static void
261 action_task_list_print_preview_cb (GtkAction *action,
262 ETaskShellView *task_shell_view)
263 {
264 ETaskShellContent *task_shell_content;
265 ETaskTable *task_table;
266
267 task_shell_content = task_shell_view->priv->task_shell_content;
268 task_table = e_task_shell_content_get_task_table (task_shell_content);
269
270 print_table (
271 E_TABLE (task_table), _("Print Tasks"), _("Tasks"),
272 GTK_PRINT_OPERATION_ACTION_PREVIEW);
273 }
274
275 static void
276 action_task_list_properties_cb (GtkAction *action,
277 ETaskShellView *task_shell_view)
278 {
279 EShellView *shell_view;
280 EShellWindow *shell_window;
281 ETaskShellSidebar *task_shell_sidebar;
282 ECalClientSourceType source_type;
283 ESource *source;
284 ESourceSelector *selector;
285 ESourceRegistry *registry;
286 GtkWidget *config;
287 GtkWidget *dialog;
288 const gchar *icon_name;
289
290 shell_view = E_SHELL_VIEW (task_shell_view);
291 shell_window = e_shell_view_get_shell_window (shell_view);
292
293 task_shell_sidebar = task_shell_view->priv->task_shell_sidebar;
294 selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
295 source = e_source_selector_ref_primary_selection (selector);
296 g_return_if_fail (source != NULL);
297
298 source_type = E_CAL_CLIENT_SOURCE_TYPE_TASKS;
299 registry = e_source_selector_get_registry (selector);
300 config = e_cal_source_config_new (registry, source, source_type);
301
302 g_object_unref (source);
303
304 dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
305
306 gtk_window_set_transient_for (
307 GTK_WINDOW (dialog), GTK_WINDOW (shell_window));
308
309 icon_name = gtk_action_get_icon_name (action);
310 gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name);
311
312 gtk_window_set_title (GTK_WINDOW (dialog), _("Task List Properties"));
313
314 gtk_widget_show (dialog);
315 }
316
317 static void
318 action_task_list_refresh_cb (GtkAction *action,
319 ETaskShellView *task_shell_view)
320 {
321 ETaskShellContent *task_shell_content;
322 ETaskShellSidebar *task_shell_sidebar;
323 ESourceSelector *selector;
324 ECalClient *client;
325 ECalModel *model;
326 ESource *source;
327 GError *error = NULL;
328
329 task_shell_content = task_shell_view->priv->task_shell_content;
330 task_shell_sidebar = task_shell_view->priv->task_shell_sidebar;
331
332 model = e_task_shell_content_get_task_model (task_shell_content);
333 selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
334
335 source = e_source_selector_ref_primary_selection (selector);
336 g_return_if_fail (source != NULL);
337
338 client = e_cal_model_get_client_for_source (model, source);
339 if (client == NULL) {
340 g_object_unref (source);
341 return;
342 }
343
344 g_return_if_fail (e_client_check_refresh_supported (E_CLIENT (client)));
345
346 e_client_refresh_sync (E_CLIENT (client), NULL, &error);
347
348 if (error != NULL) {
349 g_warning (
350 "%s: Failed to refresh '%s', %s",
351 G_STRFUNC, e_source_get_display_name (source),
352 error->message);
353 g_error_free (error);
354 }
355
356 g_object_unref (source);
357 }
358
359 static void
360 action_task_list_rename_cb (GtkAction *action,
361 ETaskShellView *task_shell_view)
362 {
363 ETaskShellSidebar *task_shell_sidebar;
364 ESourceSelector *selector;
365
366 task_shell_sidebar = task_shell_view->priv->task_shell_sidebar;
367 selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
368
369 e_source_selector_edit_primary_selection (selector);
370 }
371
372 static void
373 action_task_list_select_one_cb (GtkAction *action,
374 ETaskShellView *task_shell_view)
375 {
376 ETaskShellSidebar *task_shell_sidebar;
377 ESourceSelector *selector;
378 ESource *primary;
379
380 task_shell_sidebar = task_shell_view->priv->task_shell_sidebar;
381 selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
382
383 primary = e_source_selector_ref_primary_selection (selector);
384 g_return_if_fail (primary != NULL);
385
386 e_source_selector_select_exclusive (selector, primary);
387
388 g_object_unref (primary);
389 }
390
391 static void
392 action_task_mark_complete_cb (GtkAction *action,
393 ETaskShellView *task_shell_view)
394 {
395 ETaskShellContent *task_shell_content;
396 ETaskTable *task_table;
397 ECalModel *model;
398 GSList *list, *iter;
399
400 task_shell_content = task_shell_view->priv->task_shell_content;
401 task_table = e_task_shell_content_get_task_table (task_shell_content);
402 list = e_task_table_get_selected (task_table);
403 model = e_task_table_get_model (task_table);
404
405 for (iter = list; iter != NULL; iter = iter->next) {
406 ECalModelComponent *comp_data = iter->data;
407 e_cal_model_tasks_mark_comp_complete (
408 E_CAL_MODEL_TASKS (model), comp_data);
409 }
410
411 g_slist_free (list);
412 }
413
414 static void
415 action_task_mark_incomplete_cb (GtkAction *action,
416 ETaskShellView *task_shell_view)
417 {
418 ETaskShellContent *task_shell_content;
419 ETaskTable *task_table;
420 ECalModel *model;
421 GSList *list, *iter;
422
423 task_shell_content = task_shell_view->priv->task_shell_content;
424 task_table = e_task_shell_content_get_task_table (task_shell_content);
425 list = e_task_table_get_selected (task_table);
426 model = e_task_table_get_model (task_table);
427
428 for (iter = list; iter != NULL; iter = iter->next) {
429 ECalModelComponent *comp_data = iter->data;
430 e_cal_model_tasks_mark_comp_incomplete (
431 E_CAL_MODEL_TASKS (model), comp_data);
432 }
433
434 g_slist_free (list);
435 }
436
437 static void
438 action_task_new_cb (GtkAction *action,
439 ETaskShellView *task_shell_view)
440 {
441 EShell *shell;
442 EShellView *shell_view;
443 EShellWindow *shell_window;
444 ETaskShellContent *task_shell_content;
445 ETaskTable *task_table;
446 ECalClient *client;
447 ECalComponent *comp;
448 CompEditor *editor;
449 GSList *list;
450
451 shell_view = E_SHELL_VIEW (task_shell_view);
452 shell_window = e_shell_view_get_shell_window (shell_view);
453 shell = e_shell_window_get_shell (shell_window);
454
455 task_shell_content = task_shell_view->priv->task_shell_content;
456 task_table = e_task_shell_content_get_task_table (task_shell_content);
457
458 list = e_task_table_get_selected (task_table);
459 if (list == NULL) {
460 ECalModel *model;
461
462 model = e_task_table_get_model (task_table);
463 client = e_cal_model_get_default_client (model);
464 } else {
465 ECalModelComponent *comp_data;
466
467 comp_data = list->data;
468 client = comp_data->client;
469 g_slist_free (list);
470 }
471
472 g_return_if_fail (client != NULL);
473
474 editor = task_editor_new (client, shell, COMP_EDITOR_NEW_ITEM);
475 comp = cal_comp_task_new_with_defaults (client);
476 comp_editor_edit_comp (editor, comp);
477
478 gtk_window_present (GTK_WINDOW (editor));
479
480 g_object_unref (comp);
481 }
482
483 static void
484 action_task_open_cb (GtkAction *action,
485 ETaskShellView *task_shell_view)
486 {
487 ETaskShellContent *task_shell_content;
488 ECalModelComponent *comp_data;
489 ETaskTable *task_table;
490 GSList *list;
491
492 task_shell_content = task_shell_view->priv->task_shell_content;
493 task_table = e_task_shell_content_get_task_table (task_shell_content);
494
495 list = e_task_table_get_selected (task_table);
496 g_return_if_fail (list != NULL);
497 comp_data = list->data;
498 g_slist_free (list);
499
500 /* XXX We only open the first selected task. */
501 e_task_shell_view_open_task (task_shell_view, comp_data);
502 }
503
504 static void
505 action_task_open_url_cb (GtkAction *action,
506 ETaskShellView *task_shell_view)
507 {
508 EShellView *shell_view;
509 EShellWindow *shell_window;
510 ETaskShellContent *task_shell_content;
511 ECalModelComponent *comp_data;
512 ETaskTable *task_table;
513 icalproperty *prop;
514 const gchar *uri;
515 GSList *list;
516
517 shell_view = E_SHELL_VIEW (task_shell_view);
518 shell_window = e_shell_view_get_shell_window (shell_view);
519
520 task_shell_content = task_shell_view->priv->task_shell_content;
521 task_table = e_task_shell_content_get_task_table (task_shell_content);
522
523 list = e_task_table_get_selected (task_table);
524 g_return_if_fail (list != NULL);
525 comp_data = list->data;
526
527 /* XXX We only open the URI of the first selected task. */
528 prop = icalcomponent_get_first_property (
529 comp_data->icalcomp, ICAL_URL_PROPERTY);
530 g_return_if_fail (prop != NULL);
531
532 uri = icalproperty_get_url (prop);
533 e_show_uri (GTK_WINDOW (shell_window), uri);
534 }
535
536 static void
537 action_task_preview_cb (GtkToggleAction *action,
538 ETaskShellView *task_shell_view)
539 {
540 ETaskShellContent *task_shell_content;
541 gboolean visible;
542
543 task_shell_content = task_shell_view->priv->task_shell_content;
544 visible = gtk_toggle_action_get_active (action);
545 e_task_shell_content_set_preview_visible (task_shell_content, visible);
546 }
547
548 static void
549 action_task_print_cb (GtkAction *action,
550 ETaskShellView *task_shell_view)
551 {
552 ETaskShellContent *task_shell_content;
553 ECalModelComponent *comp_data;
554 ECalComponent *comp;
555 ECalModel *model;
556 ETaskTable *task_table;
557 icalcomponent *clone;
558 GSList *list;
559
560 task_shell_content = task_shell_view->priv->task_shell_content;
561 task_table = e_task_shell_content_get_task_table (task_shell_content);
562 model = e_task_table_get_model (task_table);
563
564 list = e_task_table_get_selected (task_table);
565 g_return_if_fail (list != NULL);
566 comp_data = list->data;
567 g_slist_free (list);
568
569 /* XXX We only print the first selected task. */
570 comp = e_cal_component_new ();
571 clone = icalcomponent_new_clone (comp_data->icalcomp);
572 e_cal_component_set_icalcomponent (comp, clone);
573
574 print_comp (
575 comp, comp_data->client,
576 e_cal_model_get_timezone (model),
577 e_cal_model_get_use_24_hour_format (model),
578 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
579
580 g_object_unref (comp);
581 }
582
583 static void
584 action_task_purge_cb (GtkAction *action,
585 ETaskShellView *task_shell_view)
586 {
587 EShellView *shell_view;
588 EShellWindow *shell_window;
589 GtkWidget *content_area;
590 GtkWidget *dialog;
591 GtkWidget *widget;
592 gboolean active;
593 gint response;
594
595 shell_view = E_SHELL_VIEW (task_shell_view);
596 shell_window = e_shell_view_get_shell_window (shell_view);
597
598 if (!e_task_shell_view_get_confirm_purge (task_shell_view))
599 goto purge;
600
601 /* XXX This needs reworked. The dialog looks like ass. */
602
603 dialog = gtk_message_dialog_new (
604 GTK_WINDOW (shell_window),
605 GTK_DIALOG_DESTROY_WITH_PARENT,
606 GTK_MESSAGE_WARNING,
607 GTK_BUTTONS_YES_NO,
608 "%s", _("This operation will permanently erase all tasks "
609 "marked as completed. If you continue, you will not be able "
610 "to recover these tasks.\n\nReally erase these tasks?"));
611
612 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);
613
614 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
615 widget = gtk_check_button_new_with_label (_("Do not ask me again"));
616 gtk_box_pack_start (GTK_BOX (content_area), widget, TRUE, TRUE, 6);
617 gtk_widget_show (widget);
618
619 response = gtk_dialog_run (GTK_DIALOG (dialog));
620 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
621 gtk_widget_destroy (dialog);
622
623 if (response != GTK_RESPONSE_YES)
624 return;
625
626 if (active)
627 e_task_shell_view_set_confirm_purge (task_shell_view, FALSE);
628
629 purge:
630 e_task_shell_view_delete_completed (task_shell_view);
631 }
632
633 static void
634 action_task_save_as_cb (GtkAction *action,
635 ETaskShellView *task_shell_view)
636 {
637 EShell *shell;
638 EShellView *shell_view;
639 EShellWindow *shell_window;
640 EShellBackend *shell_backend;
641 ETaskShellContent *task_shell_content;
642 ECalModelComponent *comp_data;
643 ETaskTable *task_table;
644 EActivity *activity;
645 GSList *list;
646 GFile *file;
647 gchar *string;
648
649 shell_view = E_SHELL_VIEW (task_shell_view);
650 shell_window = e_shell_view_get_shell_window (shell_view);
651 shell_backend = e_shell_view_get_shell_backend (shell_view);
652 shell = e_shell_window_get_shell (shell_window);
653
654 task_shell_content = task_shell_view->priv->task_shell_content;
655 task_table = e_task_shell_content_get_task_table (task_shell_content);
656
657 list = e_task_table_get_selected (task_table);
658 g_return_if_fail (list != NULL);
659 comp_data = list->data;
660 g_slist_free (list);
661
662 /* Translators: Default filename part saving a task to a file when
663 * no summary is filed, the '.ics' extension is concatenated to it */
664 string = icalcomp_suggest_filename (comp_data->icalcomp, _("task"));
665 file = e_shell_run_save_dialog (
666 shell, _("Save as iCalendar"), string,
667 "*.ics:text/calendar", NULL, NULL);
668 g_free (string);
669 if (file == NULL)
670 return;
671
672 /* XXX We only save the first selected task. */
673 string = e_cal_client_get_component_as_string (
674 comp_data->client, comp_data->icalcomp);
675 if (string == NULL) {
676 g_warning ("Could not convert task to a string");
677 g_object_unref (file);
678 return;
679 }
680
681 /* XXX No callback means errors are discarded. */
682 activity = e_file_replace_contents_async (
683 file, string, strlen (string), NULL, FALSE,
684 G_FILE_CREATE_NONE, (GAsyncReadyCallback) NULL, NULL);
685 e_shell_backend_add_activity (shell_backend, activity);
686
687 /* Free the string when the activity is finalized. */
688 g_object_set_data_full (
689 G_OBJECT (activity),
690 "file-content", string,
691 (GDestroyNotify) g_free);
692
693 g_object_unref (file);
694 }
695
696 static void
697 action_task_view_cb (GtkRadioAction *action,
698 GtkRadioAction *current,
699 ETaskShellView *task_shell_view)
700 {
701 ETaskShellContent *task_shell_content;
702 GtkOrientable *orientable;
703 GtkOrientation orientation;
704
705 task_shell_content = task_shell_view->priv->task_shell_content;
706 orientable = GTK_ORIENTABLE (task_shell_content);
707
708 switch (gtk_radio_action_get_current_value (action)) {
709 case 0:
710 orientation = GTK_ORIENTATION_VERTICAL;
711 break;
712 case 1:
713 orientation = GTK_ORIENTATION_HORIZONTAL;
714 break;
715 default:
716 g_return_if_reached ();
717 }
718
719 gtk_orientable_set_orientation (orientable, orientation);
720 }
721
722 static GtkActionEntry task_entries[] = {
723
724 { "task-assign",
725 NULL,
726 N_("_Assign Task"),
727 NULL,
728 NULL, /* XXX Add a tooltip! */
729 G_CALLBACK (action_task_assign_cb) },
730
731 { "task-delete",
732 GTK_STOCK_DELETE,
733 N_("_Delete Task"),
734 NULL,
735 N_("Delete selected tasks"),
736 G_CALLBACK (action_task_delete_cb) },
737
738 { "task-find",
739 GTK_STOCK_FIND,
740 N_("_Find in Task..."),
741 "<Shift><Control>f",
742 N_("Search for text in the displayed task"),
743 G_CALLBACK (action_task_find_cb) },
744
745 { "task-forward",
746 "mail-forward",
747 N_("_Forward as iCalendar..."),
748 "<Control>f",
749 NULL, /* XXX Add a tooltip! */
750 G_CALLBACK (action_task_forward_cb) },
751
752 { "task-list-copy",
753 GTK_STOCK_COPY,
754 N_("Copy..."),
755 NULL,
756 NULL, /* XXX Add a tooltip! */
757 G_CALLBACK (action_task_list_copy_cb) },
758
759 { "task-list-delete",
760 GTK_STOCK_DELETE,
761 N_("D_elete Task List"),
762 NULL,
763 N_("Delete the selected task list"),
764 G_CALLBACK (action_task_list_delete_cb) },
765
766 { "task-list-new",
767 "stock_todo",
768 N_("_New Task List"),
769 NULL,
770 N_("Create a new task list"),
771 G_CALLBACK (action_task_list_new_cb) },
772
773 { "task-list-properties",
774 GTK_STOCK_PROPERTIES,
775 NULL,
776 NULL,
777 NULL, /* XXX Add a tooltip! */
778 G_CALLBACK (action_task_list_properties_cb) },
779
780 { "task-list-refresh",
781 GTK_STOCK_REFRESH,
782 N_("Re_fresh"),
783 NULL,
784 N_("Refresh the selected task list"),
785 G_CALLBACK (action_task_list_refresh_cb) },
786
787 { "task-list-rename",
788 NULL,
789 N_("_Rename..."),
790 "F2",
791 N_("Rename the selected task list"),
792 G_CALLBACK (action_task_list_rename_cb) },
793
794 { "task-list-select-one",
795 "stock_check-filled",
796 N_("Show _Only This Task List"),
797 NULL,
798 NULL, /* XXX Add a tooltip! */
799 G_CALLBACK (action_task_list_select_one_cb) },
800
801 { "task-mark-complete",
802 NULL,
803 N_("_Mark as Complete"),
804 "<Control>k",
805 N_("Mark selected tasks as complete"),
806 G_CALLBACK (action_task_mark_complete_cb) },
807
808 { "task-mark-incomplete",
809 NULL,
810 N_("Mar_k as Incomplete"),
811 NULL,
812 N_("Mark selected tasks as incomplete"),
813 G_CALLBACK (action_task_mark_incomplete_cb) },
814
815 { "task-new",
816 "stock_task",
817 N_("New _Task"),
818 NULL,
819 N_("Create a new task"),
820 G_CALLBACK (action_task_new_cb) },
821
822 { "task-open",
823 GTK_STOCK_OPEN,
824 N_("_Open Task"),
825 "<Control>o",
826 N_("View the selected task"),
827 G_CALLBACK (action_task_open_cb) },
828
829 { "task-open-url",
830 "applications-internet",
831 N_("Open _Web Page"),
832 NULL,
833 NULL, /* XXX Add a tooltip! */
834 G_CALLBACK (action_task_open_url_cb) },
835
836 { "task-purge",
837 NULL,
838 N_("Purg_e"),
839 "<Control>e",
840 N_("Delete completed tasks"),
841 G_CALLBACK (action_task_purge_cb) },
842
843 /*** Menus ***/
844
845 { "task-actions-menu",
846 NULL,
847 N_("_Actions"),
848 NULL,
849 NULL,
850 NULL },
851
852 { "task-preview-menu",
853 NULL,
854 N_("_Preview"),
855 NULL,
856 NULL,
857 NULL }
858 };
859
860 static EPopupActionEntry task_popup_entries[] = {
861
862 { "task-list-popup-copy",
863 NULL,
864 "task-list-copy" },
865
866 { "task-list-popup-delete",
867 N_("_Delete"),
868 "task-list-delete" },
869
870 { "task-list-popup-properties",
871 NULL,
872 "task-list-properties" },
873
874 { "task-list-popup-refresh",
875 NULL,
876 "task-list-refresh" },
877
878 { "task-list-popup-rename",
879 NULL,
880 "task-list-rename" },
881
882 { "task-list-popup-select-one",
883 NULL,
884 "task-list-select-one" },
885
886 { "task-popup-assign",
887 NULL,
888 "task-assign" },
889
890 { "task-popup-forward",
891 NULL,
892 "task-forward" },
893
894 { "task-popup-mark-complete",
895 NULL,
896 "task-mark-complete" },
897
898 { "task-popup-mark-incomplete",
899 NULL,
900 "task-mark-incomplete" },
901
902 { "task-popup-open",
903 NULL,
904 "task-open" },
905
906 { "task-popup-open-url",
907 NULL,
908 "task-open-url" }
909 };
910
911 static GtkToggleActionEntry task_toggle_entries[] = {
912
913 { "task-preview",
914 NULL,
915 N_("Task _Preview"),
916 "<Control>m",
917 N_("Show task preview pane"),
918 G_CALLBACK (action_task_preview_cb),
919 TRUE }
920 };
921
922 static GtkRadioActionEntry task_view_entries[] = {
923
924 /* This action represents the inital active memo view.
925 * It should not be visible in the UI, nor should it be
926 * possible to switch to it from another shell view. */
927 { "task-view-initial",
928 NULL,
929 NULL,
930 NULL,
931 NULL,
932 -1 },
933
934 { "task-view-classic",
935 NULL,
936 N_("_Classic View"),
937 NULL,
938 N_("Show task preview below the task list"),
939 0 },
940
941 { "task-view-vertical",
942 NULL,
943 N_("_Vertical View"),
944 NULL,
945 N_("Show task preview alongside the task list"),
946 1 }
947 };
948
949 static GtkRadioActionEntry task_filter_entries[] = {
950
951 { "task-filter-active-tasks",
952 NULL,
953 N_("Active Tasks"),
954 NULL,
955 NULL, /* XXX Add a tooltip! */
956 TASK_FILTER_ACTIVE_TASKS },
957
958 { "task-filter-any-category",
959 NULL,
960 N_("Any Category"),
961 NULL,
962 NULL, /* XXX Add a tooltip! */
963 TASK_FILTER_ANY_CATEGORY },
964
965 { "task-filter-completed-tasks",
966 NULL,
967 N_("Completed Tasks"),
968 NULL,
969 NULL, /* XXX Add a tooltip! */
970 TASK_FILTER_COMPLETED_TASKS },
971
972 { "task-filter-next-7-days-tasks",
973 NULL,
974 N_("Next 7 Days' Tasks"),
975 NULL,
976 NULL, /* XXX Add a tooltip! */
977 TASK_FILTER_NEXT_7_DAYS_TASKS },
978
979 { "task-filter-overdue-tasks",
980 NULL,
981 N_("Overdue Tasks"),
982 NULL,
983 NULL, /* XXX Add a tooltip! */
984 TASK_FILTER_OVERDUE_TASKS },
985
986 { "task-filter-tasks-with-attachments",
987 NULL,
988 N_("Tasks with Attachments"),
989 NULL,
990 NULL, /* XXX Add a tooltip! */
991 TASK_FILTER_TASKS_WITH_ATTACHMENTS },
992
993 { "task-filter-unmatched",
994 NULL,
995 N_("Unmatched"),
996 NULL,
997 NULL, /* XXX Add a tooltip! */
998 TASK_FILTER_UNMATCHED }
999 };
1000
1001 static GtkRadioActionEntry task_search_entries[] = {
1002
1003 { "task-search-advanced-hidden",
1004 NULL,
1005 N_("Advanced Search"),
1006 NULL,
1007 NULL,
1008 TASK_SEARCH_ADVANCED },
1009
1010 { "task-search-any-field-contains",
1011 NULL,
1012 N_("Any field contains"),
1013 NULL,
1014 NULL, /* XXX Add a tooltip! */
1015 TASK_SEARCH_ANY_FIELD_CONTAINS },
1016
1017 { "task-search-description-contains",
1018 NULL,
1019 N_("Description contains"),
1020 NULL,
1021 NULL, /* XXX Add a tooltip! */
1022 TASK_SEARCH_DESCRIPTION_CONTAINS },
1023
1024 { "task-search-summary-contains",
1025 NULL,
1026 N_("Summary contains"),
1027 NULL,
1028 NULL, /* XXX Add a tooltip! */
1029 TASK_SEARCH_SUMMARY_CONTAINS }
1030 };
1031
1032 static GtkActionEntry lockdown_printing_entries[] = {
1033
1034 { "task-list-print",
1035 GTK_STOCK_PRINT,
1036 NULL,
1037 "<Control>p",
1038 N_("Print the list of tasks"),
1039 G_CALLBACK (action_task_list_print_cb) },
1040
1041 { "task-list-print-preview",
1042 GTK_STOCK_PRINT_PREVIEW,
1043 NULL,
1044 NULL,
1045 N_("Preview the list of tasks to be printed"),
1046 G_CALLBACK (action_task_list_print_preview_cb) },
1047
1048 { "task-print",
1049 GTK_STOCK_PRINT,
1050 NULL,
1051 NULL,
1052 N_("Print the selected task"),
1053 G_CALLBACK (action_task_print_cb) }
1054 };
1055
1056 static EPopupActionEntry lockdown_printing_popup_entries[] = {
1057
1058 { "task-popup-print",
1059 NULL,
1060 "task-print" }
1061 };
1062
1063 static GtkActionEntry lockdown_save_to_disk_entries[] = {
1064
1065 { "task-save-as",
1066 GTK_STOCK_SAVE_AS,
1067 N_("_Save as iCalendar..."),
1068 NULL,
1069 NULL, /* XXX Add a tooltip! */
1070 G_CALLBACK (action_task_save_as_cb) }
1071 };
1072
1073 static EPopupActionEntry lockdown_save_to_disk_popup_entries[] = {
1074
1075 { "task-popup-save-as",
1076 NULL,
1077 "task-save-as" },
1078 };
1079
1080 void
1081 e_task_shell_view_actions_init (ETaskShellView *task_shell_view)
1082 {
1083 ETaskShellContent *task_shell_content;
1084 EShellView *shell_view;
1085 EShellWindow *shell_window;
1086 EShellSearchbar *searchbar;
1087 EPreviewPane *preview_pane;
1088 EWebView *web_view;
1089 GtkActionGroup *action_group;
1090 GSettings *settings;
1091 GtkAction *action;
1092
1093 shell_view = E_SHELL_VIEW (task_shell_view);
1094 shell_window = e_shell_view_get_shell_window (shell_view);
1095
1096 task_shell_content = task_shell_view->priv->task_shell_content;
1097 searchbar = e_task_shell_content_get_searchbar (task_shell_content);
1098 preview_pane = e_task_shell_content_get_preview_pane (task_shell_content);
1099 web_view = e_preview_pane_get_web_view (preview_pane);
1100
1101 /* Task Actions */
1102 action_group = ACTION_GROUP (TASKS);
1103 gtk_action_group_add_actions (
1104 action_group, task_entries,
1105 G_N_ELEMENTS (task_entries), task_shell_view);
1106 e_action_group_add_popup_actions (
1107 action_group, task_popup_entries,
1108 G_N_ELEMENTS (task_popup_entries));
1109 gtk_action_group_add_toggle_actions (
1110 action_group, task_toggle_entries,
1111 G_N_ELEMENTS (task_toggle_entries), task_shell_view);
1112 gtk_action_group_add_radio_actions (
1113 action_group, task_view_entries,
1114 G_N_ELEMENTS (task_view_entries), -1,
1115 G_CALLBACK (action_task_view_cb), task_shell_view);
1116 gtk_action_group_add_radio_actions (
1117 action_group, task_search_entries,
1118 G_N_ELEMENTS (task_search_entries),
1119 -1, NULL, NULL);
1120
1121 /* Advanced Search Action */
1122 action = ACTION (TASK_SEARCH_ADVANCED_HIDDEN);
1123 gtk_action_set_visible (action, FALSE);
1124 e_shell_searchbar_set_search_option (
1125 searchbar, GTK_RADIO_ACTION (action));
1126
1127 /* Lockdown Printing Actions */
1128 action_group = ACTION_GROUP (LOCKDOWN_PRINTING);
1129 gtk_action_group_add_actions (
1130 action_group, lockdown_printing_entries,
1131 G_N_ELEMENTS (lockdown_printing_entries),
1132 task_shell_view);
1133 e_action_group_add_popup_actions (
1134 action_group, lockdown_printing_popup_entries,
1135 G_N_ELEMENTS (lockdown_printing_popup_entries));
1136
1137 /* Lockdown Save-to-Disk Actions */
1138 action_group = ACTION_GROUP (LOCKDOWN_SAVE_TO_DISK);
1139 gtk_action_group_add_actions (
1140 action_group, lockdown_save_to_disk_entries,
1141 G_N_ELEMENTS (lockdown_save_to_disk_entries),
1142 task_shell_view);
1143 e_action_group_add_popup_actions (
1144 action_group, lockdown_save_to_disk_popup_entries,
1145 G_N_ELEMENTS (lockdown_save_to_disk_popup_entries));
1146
1147 /* Bind GObject properties to settings keys. */
1148
1149 settings = g_settings_new ("org.gnome.evolution.calendar");
1150
1151 g_settings_bind (
1152 settings, "show-task-preview",
1153 ACTION (TASK_PREVIEW), "active",
1154 G_SETTINGS_BIND_DEFAULT);
1155
1156 g_settings_bind (
1157 settings, "task-layout",
1158 ACTION (TASK_VIEW_VERTICAL), "current-value",
1159 G_SETTINGS_BIND_DEFAULT);
1160
1161 g_object_unref (settings);
1162
1163 /* Fine tuning. */
1164
1165 g_signal_connect (
1166 ACTION (GAL_SAVE_CUSTOM_VIEW), "activate",
1167 G_CALLBACK (action_gal_save_custom_view_cb), task_shell_view);
1168
1169 g_object_bind_property (
1170 ACTION (TASK_PREVIEW), "active",
1171 ACTION (TASK_VIEW_CLASSIC), "sensitive",
1172 G_BINDING_SYNC_CREATE);
1173
1174 g_object_bind_property (
1175 ACTION (TASK_PREVIEW), "active",
1176 ACTION (TASK_VIEW_VERTICAL), "sensitive",
1177 G_BINDING_SYNC_CREATE);
1178
1179 e_web_view_set_open_proxy (web_view, ACTION (TASK_OPEN));
1180 e_web_view_set_print_proxy (web_view, ACTION (TASK_PRINT));
1181 e_web_view_set_save_as_proxy (web_view, ACTION (TASK_SAVE_AS));
1182 }
1183
1184 void
1185 e_task_shell_view_update_search_filter (ETaskShellView *task_shell_view)
1186 {
1187 ETaskShellContent *task_shell_content;
1188 EShellView *shell_view;
1189 EShellWindow *shell_window;
1190 EShellSearchbar *searchbar;
1191 EActionComboBox *combo_box;
1192 GtkActionGroup *action_group;
1193 GtkRadioAction *radio_action;
1194 GList *list, *iter;
1195 GSList *group;
1196 gint ii;
1197
1198 shell_view = E_SHELL_VIEW (task_shell_view);
1199 shell_window = e_shell_view_get_shell_window (shell_view);
1200
1201 action_group = ACTION_GROUP (TASKS_FILTER);
1202 e_action_group_remove_all_actions (action_group);
1203
1204 /* Add the standard filter actions. No callback is needed
1205 * because changes in the EActionComboBox are detected and
1206 * handled by EShellSearchbar. */
1207 gtk_action_group_add_radio_actions (
1208 action_group, task_filter_entries,
1209 G_N_ELEMENTS (task_filter_entries),
1210 TASK_FILTER_ANY_CATEGORY, NULL, NULL);
1211
1212 /* Retrieve the radio group from an action we just added. */
1213 list = gtk_action_group_list_actions (action_group);
1214 radio_action = GTK_RADIO_ACTION (list->data);
1215 group = gtk_radio_action_get_group (radio_action);
1216 g_list_free (list);
1217
1218 /* Build the category actions. */
1219
1220 list = e_util_get_searchable_categories ();
1221 for (iter = list, ii = 0; iter != NULL; iter = iter->next, ii++) {
1222 const gchar *category_name = iter->data;
1223 const gchar *filename;
1224 GtkAction *action;
1225 gchar *action_name;
1226
1227 action_name = g_strdup_printf (
1228 "task-filter-category-%d", ii);
1229 radio_action = gtk_radio_action_new (
1230 action_name, category_name, NULL, NULL, ii);
1231 g_free (action_name);
1232
1233 /* Convert the category icon file to a themed icon name. */
1234 filename = e_categories_get_icon_file_for (category_name);
1235 if (filename != NULL && *filename != '\0') {
1236 gchar *basename;
1237 gchar *cp;
1238
1239 basename = g_path_get_basename (filename);
1240
1241 /* Lose the file extension. */
1242 if ((cp = strrchr (basename, '.')) != NULL)
1243 *cp = '\0';
1244
1245 g_object_set (
1246 radio_action, "icon-name", basename, NULL);
1247
1248 g_free (basename);
1249 }
1250
1251 gtk_radio_action_set_group (radio_action, group);
1252 group = gtk_radio_action_get_group (radio_action);
1253
1254 /* The action group takes ownership of the action. */
1255 action = GTK_ACTION (radio_action);
1256 gtk_action_group_add_action (action_group, action);
1257 g_object_unref (radio_action);
1258 }
1259 g_list_free (list);
1260
1261 task_shell_content = task_shell_view->priv->task_shell_content;
1262 searchbar = e_task_shell_content_get_searchbar (task_shell_content);
1263 combo_box = e_shell_searchbar_get_filter_combo_box (searchbar);
1264
1265 e_shell_view_block_execute_search (shell_view);
1266
1267 /* Use any action in the group; doesn't matter which. */
1268 e_action_combo_box_set_action (combo_box, radio_action);
1269
1270 ii = TASK_FILTER_UNMATCHED;
1271 e_action_combo_box_add_separator_after (combo_box, ii);
1272
1273 ii = TASK_FILTER_TASKS_WITH_ATTACHMENTS;
1274 e_action_combo_box_add_separator_after (combo_box, ii);
1275
1276 e_shell_view_unblock_execute_search (shell_view);
1277 }