evolution-3.6.4/modules/calendar/e-cal-shell-view-memopad.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-cal-shell-view-memopad.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-cal-shell-view-memopad.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-cal-shell-view-memopad.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 "e-cal-shell-view-private.h"
 27 
 28 /* Much of this file is based on e-memo-shell-view-actions.c. */
 29 
 30 static void
 31 action_calendar_memopad_forward_cb (GtkAction *action,
 32                                     ECalShellView *cal_shell_view)
 33 {
 34 	ECalShellContent *cal_shell_content;
 35 	EShell *shell;
 36 	EShellView *shell_view;
 37 	EShellWindow *shell_window;
 38 	ESourceRegistry *registry;
 39 	EMemoTable *memo_table;
 40 	ECalModelComponent *comp_data;
 41 	ECalComponent *comp;
 42 	icalcomponent *clone;
 43 	GSList *list;
 44 
 45 	shell_view = E_SHELL_VIEW (cal_shell_view);
 46 	shell_window = e_shell_view_get_shell_window (shell_view);
 47 	shell = e_shell_window_get_shell (shell_window);
 48 
 49 	registry = e_shell_get_registry (shell);
 50 
 51 	cal_shell_content = cal_shell_view->priv->cal_shell_content;
 52 	memo_table = e_cal_shell_content_get_memo_table (cal_shell_content);
 53 
 54 	list = e_memo_table_get_selected (memo_table);
 55 	g_return_if_fail (list != NULL);
 56 	comp_data = list->data;
 57 	g_slist_free (list);
 58 
 59 	/* XXX We only forward the first selected memo. */
 60 	comp = e_cal_component_new ();
 61 	clone = icalcomponent_new_clone (comp_data->icalcomp);
 62 	e_cal_component_set_icalcomponent (comp, clone);
 63 
 64 	itip_send_comp (
 65 		registry, E_CAL_COMPONENT_METHOD_PUBLISH, comp,
 66 		comp_data->client, NULL, NULL, NULL, TRUE, FALSE);
 67 
 68 	g_object_unref (comp);
 69 }
 70 
 71 static void
 72 action_calendar_memopad_new_cb (GtkAction *action,
 73                                 ECalShellView *cal_shell_view)
 74 {
 75 	EShell *shell;
 76 	EShellView *shell_view;
 77 	EShellWindow *shell_window;
 78 	ECalShellContent *cal_shell_content;
 79 	EMemoTable *memo_table;
 80 	ECalModelComponent *comp_data;
 81 	ECalClient *client;
 82 	ECalComponent *comp;
 83 	CompEditor *editor;
 84 	GSList *list;
 85 
 86 	shell_view = E_SHELL_VIEW (cal_shell_view);
 87 	shell_window = e_shell_view_get_shell_window (shell_view);
 88 	shell = e_shell_window_get_shell (shell_window);
 89 
 90 	cal_shell_content = cal_shell_view->priv->cal_shell_content;
 91 	memo_table = e_cal_shell_content_get_memo_table (cal_shell_content);
 92 
 93 	list = e_memo_table_get_selected (memo_table);
 94 	g_return_if_fail (list != NULL);
 95 	comp_data = list->data;
 96 	g_slist_free (list);
 97 
 98 	client = comp_data->client;
 99 	comp = cal_comp_memo_new_with_defaults (client);
100 	cal_comp_update_time_by_active_window (comp, shell);
101 	editor = memo_editor_new (client, shell, COMP_EDITOR_NEW_ITEM);
102 	comp_editor_edit_comp (editor, comp);
103 
104 	gtk_window_present (GTK_WINDOW (editor));
105 
106 	g_object_unref (comp);
107 }
108 
109 static void
110 action_calendar_memopad_open_cb (GtkAction *action,
111                                  ECalShellView *cal_shell_view)
112 {
113 	ECalShellContent *cal_shell_content;
114 	EMemoTable *memo_table;
115 	ECalModelComponent *comp_data;
116 	GSList *list;
117 
118 	cal_shell_content = cal_shell_view->priv->cal_shell_content;
119 	memo_table = e_cal_shell_content_get_memo_table (cal_shell_content);
120 
121 	list = e_memo_table_get_selected (memo_table);
122 	g_return_if_fail (list != NULL);
123 	comp_data = list->data;
124 	g_slist_free (list);
125 
126 	/* XXX We only open the first selected memo. */
127 	e_cal_shell_view_memopad_open_memo (cal_shell_view, comp_data);
128 }
129 
130 static void
131 action_calendar_memopad_open_url_cb (GtkAction *action,
132                                      ECalShellView *cal_shell_view)
133 {
134 	EShellView *shell_view;
135 	EShellWindow *shell_window;
136 	ECalShellContent *cal_shell_content;
137 	EMemoTable *memo_table;
138 	ECalModelComponent *comp_data;
139 	icalproperty *prop;
140 	const gchar *uri;
141 	GSList *list;
142 
143 	shell_view = E_SHELL_VIEW (cal_shell_view);
144 	shell_window = e_shell_view_get_shell_window (shell_view);
145 
146 	cal_shell_content = cal_shell_view->priv->cal_shell_content;
147 	memo_table = e_cal_shell_content_get_memo_table (cal_shell_content);
148 
149 	list = e_memo_table_get_selected (memo_table);
150 	g_return_if_fail (list != NULL);
151 	comp_data = list->data;
152 	g_slist_free (list);
153 
154 	/* XXX We only open the URI of the first selected memo. */
155 	prop = icalcomponent_get_first_property (
156 		comp_data->icalcomp, ICAL_URL_PROPERTY);
157 	g_return_if_fail (prop != NULL);
158 
159 	uri = icalproperty_get_url (prop);
160 	e_show_uri (GTK_WINDOW (shell_window), uri);
161 }
162 
163 static void
164 action_calendar_memopad_print_cb (GtkAction *action,
165                                   ECalShellView *cal_shell_view)
166 {
167 	ECalShellContent *cal_shell_content;
168 	EMemoTable *memo_table;
169 	ECalModelComponent *comp_data;
170 	ECalComponent *comp;
171 	ECalModel *model;
172 	icalcomponent *clone;
173 	GSList *list;
174 
175 	cal_shell_content = cal_shell_view->priv->cal_shell_content;
176 	memo_table = e_cal_shell_content_get_memo_table (cal_shell_content);
177 	model = e_memo_table_get_model (memo_table);
178 
179 	list = e_memo_table_get_selected (memo_table);
180 	g_return_if_fail (list != NULL);
181 	comp_data = list->data;
182 	g_slist_free (list);
183 
184 	/* XXX We only print the first selected memo. */
185 	comp = e_cal_component_new ();
186 	clone = icalcomponent_new_clone (comp_data->icalcomp);
187 	e_cal_component_set_icalcomponent (comp, clone);
188 
189 	print_comp (
190 		comp, comp_data->client,
191 		e_cal_model_get_timezone (model),
192 		e_cal_model_get_use_24_hour_format (model),
193 		GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
194 
195 	g_object_unref (comp);
196 }
197 
198 static void
199 action_calendar_memopad_save_as_cb (GtkAction *action,
200                                     ECalShellView *cal_shell_view)
201 {
202 	EShell *shell;
203 	EShellView *shell_view;
204 	EShellWindow *shell_window;
205 	EShellBackend *shell_backend;
206 	ECalShellContent *cal_shell_content;
207 	EMemoTable *memo_table;
208 	ECalModelComponent *comp_data;
209 	EActivity *activity;
210 	GSList *list;
211 	GFile *file;
212 	gchar *string;
213 
214 	shell_view = E_SHELL_VIEW (cal_shell_view);
215 	shell_window = e_shell_view_get_shell_window (shell_view);
216 	shell_backend = e_shell_view_get_shell_backend (shell_view);
217 	shell = e_shell_window_get_shell (shell_window);
218 
219 	cal_shell_content = cal_shell_view->priv->cal_shell_content;
220 	memo_table = e_cal_shell_content_get_memo_table (cal_shell_content);
221 
222 	list = e_memo_table_get_selected (memo_table);
223 	g_return_if_fail (list != NULL);
224 	comp_data = list->data;
225 	g_slist_free (list);
226 
227 	/* Translators: Default filename part saving a memo to a file when
228 	 * no summary is filed, the '.ics' extension is concatenated to it. */
229 	string = icalcomp_suggest_filename (comp_data->icalcomp, _("memo"));
230 	file = e_shell_run_save_dialog (
231 		shell, _("Save as iCalendar"), string,
232 		"*.ics:text/calendar", NULL, NULL);
233 	g_free (string);
234 	if (file == NULL)
235 		return;
236 
237 	/* XXX We only save the first selected memo. */
238 	string = e_cal_client_get_component_as_string (
239 		comp_data->client, comp_data->icalcomp);
240 	if (string == NULL) {
241 		g_warning ("Could not convert memo to a string.");
242 		g_object_unref (file);
243 		return;
244 	}
245 
246 	/* XXX No callback means errors are discarded. */
247 	activity = e_file_replace_contents_async (
248 		file, string, strlen (string), NULL, FALSE,
249 		G_FILE_CREATE_NONE, (GAsyncReadyCallback) NULL, NULL);
250 	e_shell_backend_add_activity (shell_backend, activity);
251 
252 	/* Free the string when the activity is finalized. */
253 	g_object_set_data_full (
254 		G_OBJECT (activity),
255 		"file-content", string,
256 		(GDestroyNotify) g_free);
257 
258 	g_object_unref (file);
259 }
260 
261 static GtkActionEntry calendar_memopad_entries[] = {
262 
263 	{ "calendar-memopad-forward",
264 	  "mail-forward",
265 	  N_("_Forward as iCalendar..."),
266 	  NULL,
267 	  NULL,  /* XXX Add a tooltip! */
268 	  G_CALLBACK (action_calendar_memopad_forward_cb) },
269 
270 	{ "calendar-memopad-new",
271 	  "stock_insert-note",
272 	  N_("New _Memo"),
273 	  NULL,
274 	  N_("Create a new memo"),
275 	  G_CALLBACK (action_calendar_memopad_new_cb) },
276 
277 	{ "calendar-memopad-open",
278 	  GTK_STOCK_OPEN,
279 	  N_("_Open Memo"),
280 	  NULL,
281 	  N_("View the selected memo"),
282 	  G_CALLBACK (action_calendar_memopad_open_cb) },
283 
284 	{ "calendar-memopad-open-url",
285 	  "applications-internet",
286 	  N_("Open _Web Page"),
287 	  NULL,
288 	  NULL,  /* XXX Add a tooltip! */
289 	  G_CALLBACK (action_calendar_memopad_open_url_cb) },
290 };
291 
292 static GtkActionEntry lockdown_printing_entries[] = {
293 
294 	{ "calendar-memopad-print",
295 	  GTK_STOCK_PRINT,
296 	  NULL,
297 	  NULL,
298 	  N_("Print the selected memo"),
299 	  G_CALLBACK (action_calendar_memopad_print_cb) }
300 };
301 
302 static GtkActionEntry lockdown_save_to_disk_entries[] = {
303 
304 	{ "calendar-memopad-save-as",
305 	  GTK_STOCK_SAVE_AS,
306 	  N_("_Save as iCalendar..."),
307 	  NULL,
308 	  NULL,  /* XXX Add a tooltip! */
309 	  G_CALLBACK (action_calendar_memopad_save_as_cb) }
310 };
311 
312 void
313 e_cal_shell_view_memopad_actions_init (ECalShellView *cal_shell_view)
314 {
315 	EShellView *shell_view;
316 	EShellWindow *shell_window;
317 	GtkActionGroup *action_group;
318 
319 	shell_view = E_SHELL_VIEW (cal_shell_view);
320 	shell_window = e_shell_view_get_shell_window (shell_view);
321 
322 	/* Calendar Actions */
323 	action_group = ACTION_GROUP (CALENDAR);
324 	gtk_action_group_add_actions (
325 		action_group, calendar_memopad_entries,
326 		G_N_ELEMENTS (calendar_memopad_entries), cal_shell_view);
327 
328 	/* Lockdown Printing Actions */
329 	action_group = ACTION_GROUP (LOCKDOWN_PRINTING);
330 	gtk_action_group_add_actions (
331 		action_group, lockdown_printing_entries,
332 		G_N_ELEMENTS (lockdown_printing_entries), cal_shell_view);
333 
334 	/* Lockdown Save-to-Disk Actions */
335 	action_group = ACTION_GROUP (LOCKDOWN_SAVE_TO_DISK);
336 	gtk_action_group_add_actions (
337 		action_group, lockdown_save_to_disk_entries,
338 		G_N_ELEMENTS (lockdown_save_to_disk_entries), cal_shell_view);
339 }
340 
341 void
342 e_cal_shell_view_memopad_actions_update (ECalShellView *cal_shell_view)
343 {
344 	ECalShellContent *cal_shell_content;
345 	EShellWindow *shell_window;
346 	EShellView *shell_view;
347 	EMemoTable *memo_table;
348 	GtkAction *action;
349 	GSList *list, *iter;
350 	gboolean editable = TRUE;
351 	gboolean has_url = FALSE;
352 	gboolean sensitive;
353 	gint n_selected;
354 
355 	shell_view = E_SHELL_VIEW (cal_shell_view);
356 	shell_window = e_shell_view_get_shell_window (shell_view);
357 
358 	cal_shell_content = cal_shell_view->priv->cal_shell_content;
359 	memo_table = e_cal_shell_content_get_memo_table (cal_shell_content);
360 
361 	n_selected = e_table_selected_count (E_TABLE (memo_table));
362 
363 	list = e_memo_table_get_selected (memo_table);
364 	for (iter = list; iter != NULL; iter = iter->next) {
365 		ECalModelComponent *comp_data = iter->data;
366 		icalproperty *prop;
367 		gboolean read_only;
368 
369 		read_only = e_client_is_readonly (E_CLIENT (comp_data->client));
370 		editable &= !read_only;
371 
372 		prop = icalcomponent_get_first_property (
373 			comp_data->icalcomp, ICAL_URL_PROPERTY);
374 		has_url |= (prop != NULL);
375 	}
376 	g_slist_free (list);
377 
378 	action = ACTION (CALENDAR_MEMOPAD_FORWARD);
379 	sensitive = (n_selected == 1);
380 	gtk_action_set_sensitive (action, sensitive);
381 
382 	action = ACTION (CALENDAR_MEMOPAD_OPEN);
383 	sensitive = (n_selected == 1);
384 	gtk_action_set_sensitive (action, sensitive);
385 
386 	action = ACTION (CALENDAR_MEMOPAD_OPEN_URL);
387 	sensitive = (n_selected == 1) && has_url;
388 	gtk_action_set_sensitive (action, sensitive);
389 
390 	action = ACTION (CALENDAR_MEMOPAD_PRINT);
391 	sensitive = (n_selected == 1);
392 	gtk_action_set_sensitive (action, sensitive);
393 
394 	action = ACTION (CALENDAR_MEMOPAD_SAVE_AS);
395 	sensitive = (n_selected == 1);
396 	gtk_action_set_sensitive (action, sensitive);
397 }
398 
399 void
400 e_cal_shell_view_memopad_open_memo (ECalShellView *cal_shell_view,
401                                     ECalModelComponent *comp_data)
402 {
403 	EShell *shell;
404 	EShellView *shell_view;
405 	EShellWindow *shell_window;
406 	ESourceRegistry *registry;
407 	CompEditor *editor;
408 	CompEditorFlags flags = 0;
409 	ECalComponent *comp;
410 	icalcomponent *clone;
411 	const gchar *uid;
412 
413 	g_return_if_fail (E_IS_CAL_SHELL_VIEW (cal_shell_view));
414 	g_return_if_fail (E_IS_CAL_MODEL_COMPONENT (comp_data));
415 
416 	shell_view = E_SHELL_VIEW (cal_shell_view);
417 	shell_window = e_shell_view_get_shell_window (shell_view);
418 	shell = e_shell_window_get_shell (shell_window);
419 
420 	registry = e_shell_get_registry (shell);
421 
422 	uid = icalcomponent_get_uid (comp_data->icalcomp);
423 	editor = comp_editor_find_instance (uid);
424 
425 	if (editor != NULL)
426 		goto exit;
427 
428 	comp = e_cal_component_new ();
429 	clone = icalcomponent_new_clone (comp_data->icalcomp);
430 	e_cal_component_set_icalcomponent (comp, clone);
431 
432 	if (e_cal_component_has_organizer (comp))
433 		flags |= COMP_EDITOR_IS_SHARED;
434 
435 	if (itip_organizer_is_user (registry, comp, comp_data->client))
436 		flags |= COMP_EDITOR_USER_ORG;
437 
438 	editor = memo_editor_new (comp_data->client, shell, flags);
439 	comp_editor_edit_comp (editor, comp);
440 
441 	g_object_unref (comp);
442 
443 exit:
444 	gtk_window_present (GTK_WINDOW (editor));
445 }
446 
447 void
448 e_cal_shell_view_memopad_set_status_message (ECalShellView *cal_shell_view,
449                                              const gchar *status_message,
450                                              gdouble percent)
451 {
452 	EActivity *activity;
453 	EShellView *shell_view;
454 	EShellBackend *shell_backend;
455 
456 	g_return_if_fail (E_IS_CAL_SHELL_VIEW (cal_shell_view));
457 
458 	shell_view = E_SHELL_VIEW (cal_shell_view);
459 	shell_backend = e_shell_view_get_shell_backend (shell_view);
460 
461 	activity = cal_shell_view->priv->memopad_activity;
462 
463 	if (status_message == NULL || *status_message == '\0') {
464 		if (activity != NULL) {
465 			e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
466 			g_object_unref (activity);
467 			activity = NULL;
468 		}
469 
470 	} else if (activity == NULL) {
471 		activity = e_activity_new ();
472 		e_activity_set_percent (activity, percent);
473 		e_activity_set_text (activity, status_message);
474 		e_shell_backend_add_activity (shell_backend, activity);
475 
476 	} else {
477 		e_activity_set_percent (activity, percent);
478 		e_activity_set_text (activity, status_message);
479 	}
480 
481 	cal_shell_view->priv->memopad_activity = activity;
482 }