1 /*
2  * e-memo-shell-view-actions.c
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, see <http://www.gnu.org/licenses/>.
15  *
16  *
17  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
18  *
19  */
20 
21 #include "evolution-config.h"
22 
23 #include "calendar/gui/e-cal-ops.h"
24 #include "calendar/gui/itip-utils.h"
25 
26 #include "e-cal-base-shell-view.h"
27 #include "e-memo-shell-view-private.h"
28 #include "e-cal-shell-view.h"
29 
30 static void
action_memo_delete_cb(GtkAction * action,EMemoShellView * memo_shell_view)31 action_memo_delete_cb (GtkAction *action,
32                        EMemoShellView *memo_shell_view)
33 {
34 	EMemoShellContent *memo_shell_content;
35 	EMemoTable *memo_table;
36 
37 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
38 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
39 
40 	e_selectable_delete_selection (E_SELECTABLE (memo_table));
41 }
42 
43 static void
action_memo_find_cb(GtkAction * action,EMemoShellView * memo_shell_view)44 action_memo_find_cb (GtkAction *action,
45                      EMemoShellView *memo_shell_view)
46 {
47 	EMemoShellContent *memo_shell_content;
48 	EPreviewPane *preview_pane;
49 
50 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
51 	preview_pane = e_memo_shell_content_get_preview_pane (memo_shell_content);
52 
53 	e_preview_pane_show_search_bar (preview_pane);
54 }
55 
56 static void
action_memo_forward_cb(GtkAction * action,EMemoShellView * memo_shell_view)57 action_memo_forward_cb (GtkAction *action,
58                         EMemoShellView *memo_shell_view)
59 {
60 	EMemoShellContent *memo_shell_content;
61 	EMemoTable *memo_table;
62 	ECalModelComponent *comp_data;
63 	ECalComponent *comp;
64 	GSList *list;
65 
66 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
67 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
68 
69 	list = e_memo_table_get_selected (memo_table);
70 	g_return_if_fail (list != NULL);
71 	comp_data = list->data;
72 	g_slist_free (list);
73 
74 	/* XXX We only forward the first selected memo. */
75 	comp = e_cal_component_new_from_icalcomponent (i_cal_component_clone (comp_data->icalcomp));
76 	g_return_if_fail (comp != NULL);
77 
78 	itip_send_component_with_model (e_memo_table_get_model (memo_table),
79 		I_CAL_METHOD_PUBLISH, comp,
80 		comp_data->client, NULL, NULL, NULL, E_ITIP_SEND_COMPONENT_FLAG_STRIP_ALARMS | E_ITIP_SEND_COMPONENT_FLAG_ENSURE_MASTER_OBJECT);
81 
82 	g_object_unref (comp);
83 }
84 
85 static void
action_memo_list_copy_cb(GtkAction * action,EShellView * shell_view)86 action_memo_list_copy_cb (GtkAction *action,
87 			  EShellView *shell_view)
88 {
89 	e_cal_base_shell_view_copy_calendar (shell_view);
90 }
91 
92 static void
action_memo_list_delete_cb(GtkAction * action,EMemoShellView * memo_shell_view)93 action_memo_list_delete_cb (GtkAction *action,
94                             EMemoShellView *memo_shell_view)
95 {
96 	ECalBaseShellSidebar *memo_shell_sidebar;
97 	EShellWindow *shell_window;
98 	EShellView *shell_view;
99 	ESource *source;
100 	ESourceSelector *selector;
101 	gint response;
102 
103 	shell_view = E_SHELL_VIEW (memo_shell_view);
104 	shell_window = e_shell_view_get_shell_window (shell_view);
105 
106 	memo_shell_sidebar = memo_shell_view->priv->memo_shell_sidebar;
107 	selector = e_cal_base_shell_sidebar_get_selector (memo_shell_sidebar);
108 
109 	source = e_source_selector_ref_primary_selection (selector);
110 	g_return_if_fail (source != NULL);
111 
112 	if (e_source_get_remote_deletable (source)) {
113 		response = e_alert_run_dialog_for_args (
114 			GTK_WINDOW (shell_window),
115 			"calendar:prompt-delete-remote-memo-list",
116 			e_source_get_display_name (source), NULL);
117 
118 		if (response == GTK_RESPONSE_YES)
119 			e_shell_view_remote_delete_source (shell_view, source);
120 
121 	} else {
122 		response = e_alert_run_dialog_for_args (
123 			GTK_WINDOW (shell_window),
124 			"calendar:prompt-delete-memo-list",
125 			e_source_get_display_name (source), NULL);
126 
127 		if (response == GTK_RESPONSE_YES)
128 			e_shell_view_remove_source (shell_view, source);
129 	}
130 
131 	g_object_unref (source);
132 }
133 
134 static void
action_memo_list_manage_groups_cb(GtkAction * action,EMemoShellView * memo_shell_view)135 action_memo_list_manage_groups_cb (GtkAction *action,
136 				   EMemoShellView *memo_shell_view)
137 {
138 	EShellView *shell_view;
139 	ESourceSelector *selector;
140 
141 	shell_view = E_SHELL_VIEW (memo_shell_view);
142 	selector = e_cal_base_shell_sidebar_get_selector (memo_shell_view->priv->memo_shell_sidebar);
143 
144 	if (e_source_selector_manage_groups (selector) &&
145 	    e_source_selector_save_groups_setup (selector, e_shell_view_get_state_key_file (shell_view)))
146 		e_shell_view_set_state_dirty (shell_view);
147 }
148 
149 static void
action_memo_list_new_cb(GtkAction * action,EMemoShellView * memo_shell_view)150 action_memo_list_new_cb (GtkAction *action,
151                          EMemoShellView *memo_shell_view)
152 {
153 	EShell *shell;
154 	EShellView *shell_view;
155 	EShellWindow *shell_window;
156 	ESourceRegistry *registry;
157 	ECalClientSourceType source_type;
158 	GtkWidget *config;
159 	GtkWidget *dialog;
160 	const gchar *icon_name;
161 
162 	shell_view = E_SHELL_VIEW (memo_shell_view);
163 	shell_window = e_shell_view_get_shell_window (shell_view);
164 	shell = e_shell_window_get_shell (shell_window);
165 
166 	registry = e_shell_get_registry (shell);
167 	source_type = E_CAL_CLIENT_SOURCE_TYPE_MEMOS;
168 	config = e_cal_source_config_new (registry, NULL, source_type);
169 
170 	e_cal_base_shell_view_preselect_source_config (shell_view, config);
171 
172 	dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
173 
174 	gtk_window_set_transient_for (
175 		GTK_WINDOW (dialog), GTK_WINDOW (shell_window));
176 
177 	icon_name = gtk_action_get_icon_name (action);
178 	gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name);
179 
180 	gtk_window_set_title (GTK_WINDOW (dialog), _("New Memo List"));
181 
182 	gtk_widget_show (dialog);
183 }
184 
185 static void
action_memo_list_print_cb(GtkAction * action,EMemoShellView * memo_shell_view)186 action_memo_list_print_cb (GtkAction *action,
187                            EMemoShellView *memo_shell_view)
188 {
189 	EMemoShellContent *memo_shell_content;
190 	EMemoTable *memo_table;
191 
192 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
193 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
194 
195 	print_table (
196 		E_TABLE (memo_table), _("Print Memos"), _("Memos"),
197 		GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
198 }
199 
200 static void
action_memo_list_print_preview_cb(GtkAction * action,EMemoShellView * memo_shell_view)201 action_memo_list_print_preview_cb (GtkAction *action,
202                                    EMemoShellView *memo_shell_view)
203 {
204 	EMemoShellContent *memo_shell_content;
205 	EMemoTable *memo_table;
206 
207 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
208 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
209 
210 	print_table (
211 		E_TABLE (memo_table), _("Print Memos"), _("Memos"),
212 		GTK_PRINT_OPERATION_ACTION_PREVIEW);
213 }
214 
215 static void
action_memo_list_properties_cb(GtkAction * action,EMemoShellView * memo_shell_view)216 action_memo_list_properties_cb (GtkAction *action,
217                                 EMemoShellView *memo_shell_view)
218 {
219 	EShellView *shell_view;
220 	EShellWindow *shell_window;
221 	ECalBaseShellSidebar *memo_shell_sidebar;
222 	ECalClientSourceType source_type;
223 	ESource *source;
224 	ESourceSelector *selector;
225 	ESourceRegistry *registry;
226 	GtkWidget *config;
227 	GtkWidget *dialog;
228 	const gchar *icon_name;
229 
230 	shell_view = E_SHELL_VIEW (memo_shell_view);
231 	shell_window = e_shell_view_get_shell_window (shell_view);
232 
233 	memo_shell_sidebar = memo_shell_view->priv->memo_shell_sidebar;
234 	selector = e_cal_base_shell_sidebar_get_selector (memo_shell_sidebar);
235 	source = e_source_selector_ref_primary_selection (selector);
236 	g_return_if_fail (source != NULL);
237 
238 	source_type = E_CAL_CLIENT_SOURCE_TYPE_MEMOS;
239 	registry = e_source_selector_get_registry (selector);
240 	config = e_cal_source_config_new (registry, source, source_type);
241 
242 	g_object_unref (source);
243 
244 	dialog = e_source_config_dialog_new (E_SOURCE_CONFIG (config));
245 
246 	gtk_window_set_transient_for (
247 		GTK_WINDOW (dialog), GTK_WINDOW (shell_window));
248 
249 	icon_name = gtk_action_get_icon_name (action);
250 	gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_name);
251 
252 	gtk_window_set_title (GTK_WINDOW (dialog), _("Memo List Properties"));
253 
254 	gtk_widget_show (dialog);
255 }
256 
257 static void
action_memo_list_refresh_cb(GtkAction * action,EMemoShellView * memo_shell_view)258 action_memo_list_refresh_cb (GtkAction *action,
259                              EMemoShellView *memo_shell_view)
260 {
261 	ECalBaseShellSidebar *memo_shell_sidebar;
262 	ESourceSelector *selector;
263 	EClient *client = NULL;
264 	ESource *source;
265 
266 	memo_shell_sidebar = memo_shell_view->priv->memo_shell_sidebar;
267 	selector = e_cal_base_shell_sidebar_get_selector (memo_shell_sidebar);
268 
269 	source = e_source_selector_ref_primary_selection (selector);
270 
271 	if (source != NULL) {
272 		client = e_client_selector_ref_cached_client (
273 			E_CLIENT_SELECTOR (selector), source);
274 		g_object_unref (source);
275 	}
276 
277 	if (client == NULL)
278 		return;
279 
280 	g_return_if_fail (e_client_check_refresh_supported (client));
281 
282 	e_cal_base_shell_view_allow_auth_prompt_and_refresh (E_SHELL_VIEW (memo_shell_view), client);
283 
284 	g_object_unref (client);
285 }
286 
287 static void
action_memo_list_refresh_backend_cb(GtkAction * action,EShellView * shell_view)288 action_memo_list_refresh_backend_cb (GtkAction *action,
289 				     EShellView *shell_view)
290 {
291 	ESource *source;
292 
293 	g_return_if_fail (E_IS_MEMO_SHELL_VIEW (shell_view));
294 
295 	source = e_cal_base_shell_view_get_clicked_source (shell_view);
296 
297 	if (source && e_source_has_extension (source, E_SOURCE_EXTENSION_COLLECTION))
298 		e_cal_base_shell_view_refresh_backend (shell_view, source);
299 }
300 
301 static void
action_memo_list_rename_cb(GtkAction * action,EMemoShellView * memo_shell_view)302 action_memo_list_rename_cb (GtkAction *action,
303                             EMemoShellView *memo_shell_view)
304 {
305 	ECalBaseShellSidebar *memo_shell_sidebar;
306 	ESourceSelector *selector;
307 
308 	memo_shell_sidebar = memo_shell_view->priv->memo_shell_sidebar;
309 	selector = e_cal_base_shell_sidebar_get_selector (memo_shell_sidebar);
310 
311 	e_source_selector_edit_primary_selection (selector);
312 }
313 
314 static void
action_memo_list_select_all_cb(GtkAction * action,EMemoShellView * memo_shell_view)315 action_memo_list_select_all_cb (GtkAction *action,
316 				EMemoShellView *memo_shell_view)
317 {
318 	ECalBaseShellSidebar *memo_shell_sidebar;
319 	ESourceSelector *selector;
320 
321 	memo_shell_sidebar = memo_shell_view->priv->memo_shell_sidebar;
322 	selector = e_cal_base_shell_sidebar_get_selector (memo_shell_sidebar);
323 
324 	e_source_selector_select_all (selector);
325 }
326 
327 static void
action_memo_list_select_one_cb(GtkAction * action,EMemoShellView * memo_shell_view)328 action_memo_list_select_one_cb (GtkAction *action,
329                                 EMemoShellView *memo_shell_view)
330 {
331 	ECalBaseShellSidebar *memo_shell_sidebar;
332 	ESourceSelector *selector;
333 	ESource *primary;
334 
335 	memo_shell_sidebar = memo_shell_view->priv->memo_shell_sidebar;
336 	selector = e_cal_base_shell_sidebar_get_selector (memo_shell_sidebar);
337 
338 	primary = e_source_selector_ref_primary_selection (selector);
339 	g_return_if_fail (primary != NULL);
340 
341 	e_source_selector_select_exclusive (selector, primary);
342 
343 	g_object_unref (primary);
344 }
345 
346 static void
action_memo_new_cb(GtkAction * action,EMemoShellView * memo_shell_view)347 action_memo_new_cb (GtkAction *action,
348                     EMemoShellView *memo_shell_view)
349 {
350 	EShellView *shell_view;
351 	EShellWindow *shell_window;
352 	EMemoShellContent *memo_shell_content;
353 	EMemoTable *memo_table;
354 	EClient *client = NULL;
355 	GSList *list;
356 
357 	shell_view = E_SHELL_VIEW (memo_shell_view);
358 	shell_window = e_shell_view_get_shell_window (shell_view);
359 
360 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
361 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
362 
363 	list = e_memo_table_get_selected (memo_table);
364 	if (list) {
365 		ECalModelComponent *comp_data;
366 
367 		comp_data = list->data;
368 		client = E_CLIENT (g_object_ref (comp_data->client));
369 		g_slist_free (list);
370 	}
371 
372 	e_cal_ops_new_component_editor (shell_window, E_CAL_CLIENT_SOURCE_TYPE_MEMOS,
373 		client ? e_source_get_uid (e_client_get_source (client)) : NULL, FALSE);
374 
375 	g_clear_object (&client);
376 }
377 
378 static void
action_memo_open_cb(GtkAction * action,EMemoShellView * memo_shell_view)379 action_memo_open_cb (GtkAction *action,
380                      EMemoShellView *memo_shell_view)
381 {
382 	EMemoShellContent *memo_shell_content;
383 	EMemoTable *memo_table;
384 	ECalModelComponent *comp_data;
385 	GSList *list;
386 
387 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
388 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
389 
390 	list = e_memo_table_get_selected (memo_table);
391 	g_return_if_fail (list != NULL);
392 	comp_data = list->data;
393 	g_slist_free (list);
394 
395 	/* XXX We only open the first selected memo. */
396 	e_memo_shell_view_open_memo (memo_shell_view, comp_data);
397 }
398 
399 static void
action_memo_open_url_cb(GtkAction * action,EMemoShellView * memo_shell_view)400 action_memo_open_url_cb (GtkAction *action,
401                          EMemoShellView *memo_shell_view)
402 {
403 	EShellView *shell_view;
404 	EShellWindow *shell_window;
405 	EMemoShellContent *memo_shell_content;
406 	EMemoTable *memo_table;
407 	ECalModelComponent *comp_data;
408 	ICalProperty *prop;
409 	const gchar *uri;
410 	GSList *list;
411 
412 	shell_view = E_SHELL_VIEW (memo_shell_view);
413 	shell_window = e_shell_view_get_shell_window (shell_view);
414 
415 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
416 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
417 
418 	list = e_memo_table_get_selected (memo_table);
419 	g_return_if_fail (list != NULL);
420 	comp_data = list->data;
421 	g_slist_free (list);
422 
423 	/* XXX We only open the URI of the first selected memo. */
424 	prop = i_cal_component_get_first_property (comp_data->icalcomp, I_CAL_URL_PROPERTY);
425 	g_return_if_fail (prop != NULL);
426 
427 	uri = i_cal_property_get_url (prop);
428 	e_show_uri (GTK_WINDOW (shell_window), uri);
429 
430 	g_object_unref (prop);
431 }
432 
433 static void
action_memo_preview_cb(GtkToggleAction * action,EMemoShellView * memo_shell_view)434 action_memo_preview_cb (GtkToggleAction *action,
435                         EMemoShellView *memo_shell_view)
436 {
437 	EMemoShellContent *memo_shell_content;
438 	gboolean visible;
439 
440 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
441 	visible = gtk_toggle_action_get_active (action);
442 	e_memo_shell_content_set_preview_visible (memo_shell_content, visible);
443 }
444 
445 static void
action_memo_print_cb(GtkAction * action,EMemoShellView * memo_shell_view)446 action_memo_print_cb (GtkAction *action,
447                       EMemoShellView *memo_shell_view)
448 {
449 	EMemoShellContent *memo_shell_content;
450 	EMemoTable *memo_table;
451 	ECalModelComponent *comp_data;
452 	ECalComponent *comp;
453 	ECalModel *model;
454 	GSList *list;
455 
456 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
457 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
458 	model = e_memo_table_get_model (memo_table);
459 
460 	list = e_memo_table_get_selected (memo_table);
461 	g_return_if_fail (list != NULL);
462 	comp_data = list->data;
463 	g_slist_free (list);
464 
465 	/* XXX We only print the first selected memo. */
466 	comp = e_cal_component_new_from_icalcomponent (i_cal_component_clone (comp_data->icalcomp));
467 
468 	print_comp (
469 		comp, comp_data->client,
470 		e_cal_model_get_timezone (model),
471 		e_cal_model_get_use_24_hour_format (model),
472 		GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
473 
474 	g_object_unref (comp);
475 }
476 
477 static void
action_memo_save_as_cb(GtkAction * action,EMemoShellView * memo_shell_view)478 action_memo_save_as_cb (GtkAction *action,
479                         EMemoShellView *memo_shell_view)
480 {
481 	EShell *shell;
482 	EShellView *shell_view;
483 	EShellWindow *shell_window;
484 	EShellBackend *shell_backend;
485 	EMemoShellContent *memo_shell_content;
486 	EMemoTable *memo_table;
487 	ECalModelComponent *comp_data;
488 	EActivity *activity;
489 	GSList *list;
490 	GFile *file;
491 	gchar *string;
492 
493 	shell_view = E_SHELL_VIEW (memo_shell_view);
494 	shell_window = e_shell_view_get_shell_window (shell_view);
495 	shell_backend = e_shell_view_get_shell_backend (shell_view);
496 	shell = e_shell_window_get_shell (shell_window);
497 
498 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
499 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
500 
501 	list = e_memo_table_get_selected (memo_table);
502 	g_return_if_fail (list != NULL);
503 	comp_data = list->data;
504 	g_slist_free (list);
505 
506 	/* Translators: Default filename part saving a memo to a file when
507 	 * no summary is filed, the '.ics' extension is concatenated to it. */
508 	string = comp_util_suggest_filename (comp_data->icalcomp, _("memo"));
509 	file = e_shell_run_save_dialog (
510 		shell, _("Save as iCalendar"), string,
511 		"*.ics:text/calendar", NULL, NULL);
512 	g_free (string);
513 	if (file == NULL)
514 		return;
515 
516 	/* XXX We only save the first selected memo. */
517 	string = e_cal_client_get_component_as_string (
518 		comp_data->client, comp_data->icalcomp);
519 	if (string == NULL) {
520 		g_warning ("Could not convert memo to a string");
521 		g_object_unref (file);
522 		return;
523 	}
524 
525 	/* XXX No callback means errors are discarded. */
526 	activity = e_file_replace_contents_async (
527 		file, string, strlen (string), NULL, FALSE,
528 		G_FILE_CREATE_NONE, (GAsyncReadyCallback) NULL, NULL);
529 	e_shell_backend_add_activity (shell_backend, activity);
530 
531 	/* Free the string when the activity is finalized. */
532 	g_object_set_data_full (
533 		G_OBJECT (activity),
534 		"file-content", string,
535 		(GDestroyNotify) g_free);
536 
537 	g_object_unref (file);
538 }
539 
540 static void
action_memo_view_cb(GtkRadioAction * action,GtkRadioAction * current,EMemoShellView * memo_shell_view)541 action_memo_view_cb (GtkRadioAction *action,
542                      GtkRadioAction *current,
543                      EMemoShellView *memo_shell_view)
544 {
545 	EMemoShellContent *memo_shell_content;
546 	GtkOrientable *orientable;
547 	GtkOrientation orientation;
548 
549 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
550 	orientable = GTK_ORIENTABLE (memo_shell_content);
551 
552 	switch (gtk_radio_action_get_current_value (action)) {
553 		case 0:
554 			orientation = GTK_ORIENTATION_VERTICAL;
555 			break;
556 		case 1:
557 			orientation = GTK_ORIENTATION_HORIZONTAL;
558 			break;
559 		default:
560 			g_return_if_reached ();
561 	}
562 
563 	gtk_orientable_set_orientation (orientable, orientation);
564 }
565 
566 static GtkActionEntry memo_entries[] = {
567 
568 	{ "memo-delete",
569 	  "edit-delete",
570 	  N_("_Delete Memo"),
571 	  NULL,
572 	  N_("Delete selected memos"),
573 	  G_CALLBACK (action_memo_delete_cb) },
574 
575 	{ "memo-find",
576 	  "edit-find",
577 	  N_("_Find in Memo…"),
578 	  "<Shift><Control>f",
579 	  N_("Search for text in the displayed memo"),
580 	  G_CALLBACK (action_memo_find_cb) },
581 
582 	{ "memo-forward",
583 	  "mail-forward",
584 	  N_("_Forward as iCalendar…"),
585 	  "<Control>f",
586 	  NULL,  /* XXX Add a tooltip! */
587 	  G_CALLBACK (action_memo_forward_cb) },
588 
589 	{ "memo-list-copy",
590 	  "edit-copy",
591 	  N_("_Copy…"),
592 	  "<Control>c",
593 	  NULL,  /* XXX Add a tooltip! */
594 	  G_CALLBACK (action_memo_list_copy_cb) },
595 
596 	{ "memo-list-delete",
597 	  "edit-delete",
598 	  N_("D_elete Memo List"),
599 	  NULL,
600 	  N_("Delete the selected memo list"),
601 	  G_CALLBACK (action_memo_list_delete_cb) },
602 
603 	{ "memo-list-manage-groups",
604 	  NULL,
605 	  N_("_Manage Memo List groups…"),
606 	  NULL,
607 	  N_("Manage Memo List groups order and visibility"),
608 	  G_CALLBACK (action_memo_list_manage_groups_cb) },
609 
610 	{ "memo-list-new",
611 	  "stock_notes",
612 	  N_("_New Memo List"),
613 	  NULL,
614 	  N_("Create a new memo list"),
615 	  G_CALLBACK (action_memo_list_new_cb) },
616 
617 	{ "memo-list-properties",
618 	  "document-properties",
619 	  N_("_Properties"),
620 	  NULL,
621 	  NULL,  /* XXX Add a tooltip! */
622 	  G_CALLBACK (action_memo_list_properties_cb) },
623 
624 	{ "memo-list-refresh",
625 	  "view-refresh",
626 	  N_("Re_fresh"),
627 	  NULL,
628 	  N_("Refresh the selected memo list"),
629 	  G_CALLBACK (action_memo_list_refresh_cb) },
630 
631 	{ "memo-list-refresh-backend",
632 	  "view-refresh",
633 	  N_("Re_fresh list of account memo lists"),
634 	  NULL,
635 	  NULL,
636 	  G_CALLBACK (action_memo_list_refresh_backend_cb) },
637 
638 	{ "memo-list-rename",
639 	  NULL,
640 	  N_("_Rename…"),
641 	  "F2",
642 	  N_("Rename the selected memo list"),
643 	  G_CALLBACK (action_memo_list_rename_cb) },
644 
645 	{ "memo-list-select-one",
646 	  "stock_check-filled",
647 	  N_("Show _Only This Memo List"),
648 	  NULL,
649 	  NULL,  /* XXX Add a tooltip! */
650 	  G_CALLBACK (action_memo_list_select_one_cb) },
651 
652 	{ "memo-list-select-all",
653 	  "stock_check-filled",
654 	  N_("Sho_w All Memo Lists"),
655 	  NULL,
656 	  NULL,  /* XXX Add a tooltip! */
657 	  G_CALLBACK (action_memo_list_select_all_cb) },
658 
659 	{ "memo-new",
660 	  "stock_insert-note",
661 	  N_("New _Memo"),
662 	  NULL,
663 	  N_("Create a new memo"),
664 	  G_CALLBACK (action_memo_new_cb) },
665 
666 	{ "memo-open",
667 	  "document-open",
668 	  N_("_Open Memo"),
669 	  "<Control>o",
670 	  N_("View the selected memo"),
671 	  G_CALLBACK (action_memo_open_cb) },
672 
673 	{ "memo-open-url",
674 	  "applications-internet",
675 	  N_("Open _Web Page"),
676 	  NULL,
677 	  NULL,  /* XXX Add a tooltip! */
678 	  G_CALLBACK (action_memo_open_url_cb) },
679 
680 	/*** Menus ***/
681 
682 	{ "memo-preview-menu",
683 	  NULL,
684 	  N_("_Preview"),
685 	  NULL,
686 	  NULL,
687 	  NULL }
688 };
689 
690 static EPopupActionEntry memo_popup_entries[] = {
691 
692 	{ "memo-list-popup-copy",
693 	  NULL,
694 	  "memo-list-copy" },
695 
696 	{ "memo-list-popup-delete",
697 	  N_("_Delete"),
698 	  "memo-list-delete" },
699 
700 	{ "memo-list-popup-manage-groups",
701 	  N_("_Manage groups…"),
702 	  "memo-list-manage-groups" },
703 
704 	{ "memo-list-popup-properties",
705 	  NULL,
706 	  "memo-list-properties" },
707 
708 	{ "memo-list-popup-refresh",
709 	  NULL,
710 	  "memo-list-refresh" },
711 
712 	{ "memo-list-popup-refresh-backend",
713 	  NULL,
714 	  "memo-list-refresh-backend" },
715 
716 	{ "memo-list-popup-rename",
717 	  NULL,
718 	  "memo-list-rename" },
719 
720 	{ "memo-list-popup-select-all",
721 	  NULL,
722 	  "memo-list-select-all" },
723 
724 	{ "memo-list-popup-select-one",
725 	  NULL,
726 	  "memo-list-select-one" },
727 
728 	{ "memo-popup-forward",
729 	  NULL,
730 	  "memo-forward" },
731 
732 	{ "memo-popup-open",
733 	  NULL,
734 	  "memo-open" },
735 
736 	{ "memo-popup-open-url",
737 	  NULL,
738 	  "memo-open-url" }
739 };
740 
741 static GtkToggleActionEntry memo_toggle_entries[] = {
742 
743 	{ "memo-preview",
744 	  NULL,
745 	  N_("Memo _Preview"),
746 	  "<Control>m",
747 	  N_("Show memo preview pane"),
748 	  G_CALLBACK (action_memo_preview_cb),
749 	  TRUE }
750 };
751 
752 static GtkRadioActionEntry memo_view_entries[] = {
753 
754 	/* This action represents the initial active memo view.
755 	 * It should not be visible in the UI, nor should it be
756 	 * possible to switch to it from another shell view. */
757 	{ "memo-view-initial",
758 	  NULL,
759 	  NULL,
760 	  NULL,
761 	  NULL,
762 	  -1 },
763 
764 	{ "memo-view-classic",
765 	  NULL,
766 	  N_("_Classic View"),
767 	  NULL,
768 	  N_("Show memo preview below the memo list"),
769 	  0 },
770 
771 	{ "memo-view-vertical",
772 	  NULL,
773 	  N_("_Vertical View"),
774 	  NULL,
775 	  N_("Show memo preview alongside the memo list"),
776 	  1 }
777 };
778 
779 static GtkRadioActionEntry memo_filter_entries[] = {
780 
781 	{ "memo-filter-any-category",
782 	  NULL,
783 	  N_("Any Category"),
784 	  NULL,
785 	  NULL,
786 	  MEMO_FILTER_ANY_CATEGORY },
787 
788 	{ "memo-filter-unmatched",
789 	  NULL,
790 	  N_("Unmatched"),
791 	  NULL,
792 	  NULL,
793 	  MEMO_FILTER_UNMATCHED }
794 };
795 
796 static GtkRadioActionEntry memo_search_entries[] = {
797 
798 	{ "memo-search-advanced-hidden",
799 	  NULL,
800 	  N_("Advanced Search"),
801 	  NULL,
802 	  NULL,
803 	  MEMO_SEARCH_ADVANCED },
804 
805 	{ "memo-search-any-field-contains",
806 	  NULL,
807 	  N_("Any field contains"),
808 	  NULL,
809 	  NULL,  /* XXX Add a tooltip! */
810 	  MEMO_SEARCH_ANY_FIELD_CONTAINS },
811 
812 	{ "memo-search-description-contains",
813 	  NULL,
814 	  N_("Description contains"),
815 	  NULL,
816 	  NULL,  /* XXX Add a tooltip! */
817 	  MEMO_SEARCH_DESCRIPTION_CONTAINS },
818 
819 	{ "memo-search-summary-contains",
820 	  NULL,
821 	  N_("Summary contains"),
822 	  NULL,
823 	  NULL,  /* XXX Add a tooltip! */
824 	  MEMO_SEARCH_SUMMARY_CONTAINS }
825 };
826 
827 static GtkActionEntry lockdown_printing_entries[] = {
828 
829 	{ "memo-list-print",
830 	  "document-print",
831 	  N_("Print…"),
832 	  "<Control>p",
833 	  N_("Print the list of memos"),
834 	  G_CALLBACK (action_memo_list_print_cb) },
835 
836 	{ "memo-list-print-preview",
837 	  "document-print-preview",
838 	  N_("Pre_view…"),
839 	  NULL,
840 	  N_("Preview the list of memos to be printed"),
841 	  G_CALLBACK (action_memo_list_print_preview_cb) },
842 
843 	{ "memo-print",
844 	  "document-print",
845 	  N_("Print…"),
846 	  NULL,
847 	  N_("Print the selected memo"),
848 	  G_CALLBACK (action_memo_print_cb) }
849 };
850 
851 static EPopupActionEntry lockdown_printing_popup_entries[] = {
852 
853 	{ "memo-popup-print",
854 	  NULL,
855 	  "memo-print" }
856 };
857 
858 static GtkActionEntry lockdown_save_to_disk_entries[] = {
859 
860 	{ "memo-save-as",
861 	  "document-save-as",
862 	  N_("_Save as iCalendar…"),
863 	  NULL,
864 	  NULL,  /* XXX Add a tooltip! */
865 	  G_CALLBACK (action_memo_save_as_cb) },
866 };
867 
868 static EPopupActionEntry lockdown_save_to_disk_popup_entries[] = {
869 
870 	{ "memo-popup-save-as",
871 	  NULL,
872 	  "memo-save-as" }
873 };
874 
875 void
e_memo_shell_view_actions_init(EMemoShellView * memo_shell_view)876 e_memo_shell_view_actions_init (EMemoShellView *memo_shell_view)
877 {
878 	EMemoShellContent *memo_shell_content;
879 	EShellView *shell_view;
880 	EShellWindow *shell_window;
881 	EShellSearchbar *searchbar;
882 	EPreviewPane *preview_pane;
883 	EWebView *web_view;
884 	GtkActionGroup *action_group;
885 	GSettings *memo_settings;
886 	GtkAction *action;
887 
888 	shell_view = E_SHELL_VIEW (memo_shell_view);
889 	shell_window = e_shell_view_get_shell_window (shell_view);
890 
891 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
892 	searchbar = e_memo_shell_content_get_searchbar (memo_shell_content);
893 	preview_pane = e_memo_shell_content_get_preview_pane (memo_shell_content);
894 	web_view = e_preview_pane_get_web_view (preview_pane);
895 
896 	/* Memo Actions */
897 	action_group = ACTION_GROUP (MEMOS);
898 	gtk_action_group_add_actions (
899 		action_group, memo_entries,
900 		G_N_ELEMENTS (memo_entries), memo_shell_view);
901 	e_action_group_add_popup_actions (
902 		action_group, memo_popup_entries,
903 		G_N_ELEMENTS (memo_popup_entries));
904 	gtk_action_group_add_toggle_actions (
905 		action_group, memo_toggle_entries,
906 		G_N_ELEMENTS (memo_toggle_entries), memo_shell_view);
907 	gtk_action_group_add_radio_actions (
908 		action_group, memo_view_entries,
909 		G_N_ELEMENTS (memo_view_entries), -1,
910 		G_CALLBACK (action_memo_view_cb), memo_shell_view);
911 	gtk_action_group_add_radio_actions (
912 		action_group, memo_search_entries,
913 		G_N_ELEMENTS (memo_search_entries),
914 		-1, NULL, NULL);
915 
916 	/* Advanced Search Action */
917 	action = ACTION (MEMO_SEARCH_ADVANCED_HIDDEN);
918 	gtk_action_set_visible (action, FALSE);
919 	e_shell_searchbar_set_search_option (
920 		searchbar, GTK_RADIO_ACTION (action));
921 
922 	/* Lockdown Printing Actions */
923 	action_group = ACTION_GROUP (LOCKDOWN_PRINTING);
924 	gtk_action_group_add_actions (
925 		action_group, lockdown_printing_entries,
926 		G_N_ELEMENTS (lockdown_printing_entries),
927 		memo_shell_view);
928 	e_action_group_add_popup_actions (
929 		action_group, lockdown_printing_popup_entries,
930 		G_N_ELEMENTS (lockdown_printing_popup_entries));
931 
932 	/* Lockdown Save-to-Disk Actions */
933 	action_group = ACTION_GROUP (LOCKDOWN_SAVE_TO_DISK);
934 	gtk_action_group_add_actions (
935 		action_group, lockdown_save_to_disk_entries,
936 		G_N_ELEMENTS (lockdown_save_to_disk_entries),
937 		memo_shell_view);
938 	e_action_group_add_popup_actions (
939 		action_group, lockdown_save_to_disk_popup_entries,
940 		G_N_ELEMENTS (lockdown_save_to_disk_popup_entries));
941 
942 	/* Bind GObject properties to settings keys. */
943 
944 	memo_settings = e_util_ref_settings ("org.gnome.evolution.calendar");
945 
946 	g_settings_bind (
947 		memo_settings, "show-memo-preview",
948 		ACTION (MEMO_PREVIEW), "active",
949 		G_SETTINGS_BIND_DEFAULT);
950 
951 	g_settings_bind (
952 		memo_settings, "memo-layout",
953 		ACTION (MEMO_VIEW_VERTICAL), "current-value",
954 		G_SETTINGS_BIND_DEFAULT);
955 
956 	g_object_unref (memo_settings);
957 
958 	/* Fine tuning. */
959 
960 	e_binding_bind_property (
961 		ACTION (MEMO_PREVIEW), "active",
962 		ACTION (MEMO_VIEW_CLASSIC), "sensitive",
963 		G_BINDING_SYNC_CREATE);
964 
965 	e_binding_bind_property (
966 		ACTION (MEMO_PREVIEW), "active",
967 		ACTION (MEMO_VIEW_VERTICAL), "sensitive",
968 		G_BINDING_SYNC_CREATE);
969 
970 	e_web_view_set_open_proxy (web_view, ACTION (MEMO_OPEN));
971 	e_web_view_set_print_proxy (web_view, ACTION (MEMO_PRINT));
972 	e_web_view_set_save_as_proxy (web_view, ACTION (MEMO_SAVE_AS));
973 }
974 
975 void
e_memo_shell_view_update_search_filter(EMemoShellView * memo_shell_view)976 e_memo_shell_view_update_search_filter (EMemoShellView *memo_shell_view)
977 {
978 	EMemoShellContent *memo_shell_content;
979 	EShellView *shell_view;
980 	EShellWindow *shell_window;
981 	EShellSearchbar *searchbar;
982 	EActionComboBox *combo_box;
983 	GtkActionGroup *action_group;
984 	GtkRadioAction *radio_action;
985 	GList *list, *iter;
986 	GSList *group;
987 	gint ii;
988 
989 	shell_view = E_SHELL_VIEW (memo_shell_view);
990 	shell_window = e_shell_view_get_shell_window (shell_view);
991 
992 	action_group = ACTION_GROUP (MEMOS_FILTER);
993 	e_action_group_remove_all_actions (action_group);
994 
995 	/* Add the standard filter actions.  No callback is needed
996 	 * because changes in the EActionComboBox are detected and
997 	 * handled by EShellSearchbar. */
998 	gtk_action_group_add_radio_actions (
999 		action_group, memo_filter_entries,
1000 		G_N_ELEMENTS (memo_filter_entries),
1001 		MEMO_FILTER_ANY_CATEGORY, NULL, NULL);
1002 
1003 	/* Retrieve the radio group from an action we just added. */
1004 	list = gtk_action_group_list_actions (action_group);
1005 	radio_action = GTK_RADIO_ACTION (list->data);
1006 	group = gtk_radio_action_get_group (radio_action);
1007 	g_list_free (list);
1008 
1009 	/* Build the category actions. */
1010 
1011 	list = e_util_dup_searchable_categories ();
1012 	for (iter = list, ii = 0; iter != NULL; iter = iter->next, ii++) {
1013 		const gchar *category_name = iter->data;
1014 		gchar *filename;
1015 		GtkAction *action;
1016 		gchar *action_name;
1017 
1018 		action_name = g_strdup_printf (
1019 			"memo-filter-category-%d", ii);
1020 		radio_action = gtk_radio_action_new (
1021 			action_name, category_name, NULL, NULL, ii);
1022 		g_free (action_name);
1023 
1024 		/* Convert the category icon file to a themed icon name. */
1025 		filename = e_categories_dup_icon_file_for (category_name);
1026 		if (filename != NULL && *filename != '\0') {
1027 			gchar *basename;
1028 			gchar *cp;
1029 
1030 			basename = g_path_get_basename (filename);
1031 
1032 			/* Lose the file extension. */
1033 			if ((cp = strrchr (basename, '.')) != NULL)
1034 				*cp = '\0';
1035 
1036 			g_object_set (
1037 				radio_action, "icon-name", basename, NULL);
1038 
1039 			g_free (basename);
1040 		}
1041 
1042 		g_free (filename);
1043 
1044 		gtk_radio_action_set_group (radio_action, group);
1045 		group = gtk_radio_action_get_group (radio_action);
1046 
1047 		/* The action group takes ownership of the action. */
1048 		action = GTK_ACTION (radio_action);
1049 		gtk_action_group_add_action (action_group, action);
1050 		g_object_unref (radio_action);
1051 	}
1052 	g_list_free_full (list, g_free);
1053 
1054 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
1055 	searchbar = e_memo_shell_content_get_searchbar (memo_shell_content);
1056 	combo_box = e_shell_searchbar_get_filter_combo_box (searchbar);
1057 
1058 	e_shell_view_block_execute_search (shell_view);
1059 
1060 	/* Use any action in the group; doesn't matter which. */
1061 	e_action_combo_box_set_action (combo_box, radio_action);
1062 
1063 	ii = MEMO_FILTER_UNMATCHED;
1064 	e_action_combo_box_add_separator_after (combo_box, ii);
1065 
1066 	e_shell_view_unblock_execute_search (shell_view);
1067 }
1068