evolution-3.6.4/modules/calendar/e-memo-shell-view-private.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-memo-shell-view-private.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-memo-shell-view-private.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-memo-shell-view-private.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-util/e-util-private.h"
 27 
 28 #include "e-memo-shell-view-private.h"
 29 
 30 #include "widgets/menus/gal-view-factory-etable.h"
 31 
 32 static void
 33 memo_shell_view_model_row_appended_cb (EMemoShellView *memo_shell_view,
 34                                        ECalModel *model)
 35 {
 36 	EMemoShellSidebar *memo_shell_sidebar;
 37 	ECalClient *client;
 38 	ESource *source;
 39 
 40 	/* This is the "Click to Add" handler. */
 41 
 42 	client = e_cal_model_get_default_client (model);
 43 	source = e_client_get_source (E_CLIENT (client));
 44 
 45 	memo_shell_sidebar = memo_shell_view->priv->memo_shell_sidebar;
 46 	e_memo_shell_sidebar_add_source (memo_shell_sidebar, source);
 47 }
 48 
 49 static void
 50 memo_shell_view_table_popup_event_cb (EShellView *shell_view,
 51                                       GdkEventButton *event)
 52 {
 53 	const gchar *widget_path;
 54 
 55 	widget_path = "/memo-popup";
 56 	e_shell_view_show_popup_menu (shell_view, widget_path, event);
 57 }
 58 
 59 static void
 60 memo_shell_view_selector_client_added_cb (EMemoShellView *memo_shell_view,
 61                                           ECalClient *client)
 62 {
 63 	EMemoShellContent *memo_shell_content;
 64 	EMemoTable *memo_table;
 65 	ECalModel *model;
 66 
 67 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
 68 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
 69 	model = e_memo_table_get_model (memo_table);
 70 
 71 	e_cal_model_add_client (model, client);
 72 	e_memo_shell_view_update_timezone (memo_shell_view);
 73 }
 74 
 75 static void
 76 memo_shell_view_selector_client_removed_cb (EMemoShellView *memo_shell_view,
 77                                             ECalClient *client)
 78 {
 79 	EMemoShellContent *memo_shell_content;
 80 	EMemoTable *memo_table;
 81 	ECalModel *model;
 82 
 83 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
 84 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
 85 	model = e_memo_table_get_model (memo_table);
 86 
 87 	e_cal_model_remove_client (model, client);
 88 }
 89 
 90 static gboolean
 91 memo_shell_view_selector_popup_event_cb (EShellView *shell_view,
 92                                          ESource *primary_source,
 93                                          GdkEventButton *event)
 94 {
 95 	const gchar *widget_path;
 96 
 97 	widget_path = "/memo-list-popup";
 98 	e_shell_view_show_popup_menu (shell_view, widget_path, event);
 99 
100 	return TRUE;
101 }
102 
103 static void
104 memo_shell_view_load_view_collection (EShellViewClass *shell_view_class)
105 {
106 	GalViewCollection *collection;
107 	GalViewFactory *factory;
108 	ETableSpecification *spec;
109 	const gchar *base_dir;
110 	gchar *filename;
111 
112 	collection = shell_view_class->view_collection;
113 
114 	base_dir = EVOLUTION_ETSPECDIR;
115 	spec = e_table_specification_new ();
116 	filename = g_build_filename (base_dir, ETSPEC_FILENAME, NULL);
117 	if (!e_table_specification_load_from_file (spec, filename))
118 		g_critical (
119 			"Unable to load ETable specification file "
120 			"for memos");
121 	g_free (filename);
122 
123 	factory = gal_view_factory_etable_new (spec);
124 	gal_view_collection_add_factory (collection, factory);
125 	g_object_unref (factory);
126 	g_object_unref (spec);
127 
128 	gal_view_collection_load (collection);
129 }
130 
131 static void
132 memo_shell_view_notify_view_id_cb (EMemoShellView *memo_shell_view)
133 {
134 	EMemoShellContent *memo_shell_content;
135 	GalViewInstance *view_instance;
136 	const gchar *view_id;
137 
138 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
139 	view_instance =
140 		e_memo_shell_content_get_view_instance (memo_shell_content);
141 	view_id = e_shell_view_get_view_id (E_SHELL_VIEW (memo_shell_view));
142 
143 	/* A NULL view ID implies we're in a custom view.  But you can
144 	 * only get to a custom view via the "Define Views" dialog, which
145 	 * would have already modified the view instance appropriately.
146 	 * Furthermore, there's no way to refer to a custom view by ID
147 	 * anyway, since custom views have no IDs. */
148 	if (view_id == NULL)
149 		return;
150 
151 	gal_view_instance_set_current_view_id (view_instance, view_id);
152 }
153 
154 void
155 e_memo_shell_view_private_init (EMemoShellView *memo_shell_view,
156                                 EShellViewClass *shell_view_class)
157 {
158 	if (!gal_view_collection_loaded (shell_view_class->view_collection))
159 		memo_shell_view_load_view_collection (shell_view_class);
160 
161 	g_signal_connect (
162 		memo_shell_view, "notify::view-id",
163 		G_CALLBACK (memo_shell_view_notify_view_id_cb), NULL);
164 }
165 
166 void
167 e_memo_shell_view_private_constructed (EMemoShellView *memo_shell_view)
168 {
169 	EMemoShellViewPrivate *priv = memo_shell_view->priv;
170 	EMemoShellContent *memo_shell_content;
171 	EMemoShellSidebar *memo_shell_sidebar;
172 	EShellView *shell_view;
173 	EShellBackend *shell_backend;
174 	EShellContent *shell_content;
175 	EShellSidebar *shell_sidebar;
176 	EShellWindow *shell_window;
177 	EMemoTable *memo_table;
178 	ECalModel *model;
179 	ESourceSelector *selector;
180 
181 	shell_view = E_SHELL_VIEW (memo_shell_view);
182 	shell_backend = e_shell_view_get_shell_backend (shell_view);
183 	shell_content = e_shell_view_get_shell_content (shell_view);
184 	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
185 	shell_window = e_shell_view_get_shell_window (shell_view);
186 
187 	e_shell_window_add_action_group (shell_window, "memos");
188 	e_shell_window_add_action_group (shell_window, "memos-filter");
189 
190 	/* Cache these to avoid lots of awkward casting. */
191 	priv->memo_shell_backend = g_object_ref (shell_backend);
192 	priv->memo_shell_content = g_object_ref (shell_content);
193 	priv->memo_shell_sidebar = g_object_ref (shell_sidebar);
194 
195 	memo_shell_content = E_MEMO_SHELL_CONTENT (shell_content);
196 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
197 	model = e_memo_table_get_model (memo_table);
198 
199 	memo_shell_sidebar = E_MEMO_SHELL_SIDEBAR (shell_sidebar);
200 	selector = e_memo_shell_sidebar_get_selector (memo_shell_sidebar);
201 
202 	g_signal_connect_swapped (
203 		model, "notify::timezone",
204 		G_CALLBACK (e_memo_shell_view_update_timezone),
205 		memo_shell_view);
206 
207 	g_signal_connect_swapped (
208 		model, "row-appended",
209 		G_CALLBACK (memo_shell_view_model_row_appended_cb),
210 		memo_shell_view);
211 
212 	g_signal_connect_swapped (
213 		memo_table, "open-component",
214 		G_CALLBACK (e_memo_shell_view_open_memo),
215 		memo_shell_view);
216 
217 	g_signal_connect_swapped (
218 		memo_table, "popup-event",
219 		G_CALLBACK (memo_shell_view_table_popup_event_cb),
220 		memo_shell_view);
221 
222 	g_signal_connect_swapped (
223 		memo_table, "selection-change",
224 		G_CALLBACK (e_memo_shell_view_update_sidebar),
225 		memo_shell_view);
226 
227 	g_signal_connect_swapped (
228 		memo_table, "selection-change",
229 		G_CALLBACK (e_shell_view_update_actions),
230 		memo_shell_view);
231 
232 	g_signal_connect_swapped (
233 		memo_table, "status-message",
234 		G_CALLBACK (e_memo_shell_view_set_status_message),
235 		memo_shell_view);
236 
237 	g_signal_connect_swapped (
238 		model, "model-changed",
239 		G_CALLBACK (e_memo_shell_view_update_sidebar),
240 		memo_shell_view);
241 
242 	g_signal_connect_swapped (
243 		model, "model-rows-deleted",
244 		G_CALLBACK (e_memo_shell_view_update_sidebar),
245 		memo_shell_view);
246 
247 	g_signal_connect_swapped (
248 		model, "model-rows-inserted",
249 		G_CALLBACK (e_memo_shell_view_update_sidebar),
250 		memo_shell_view);
251 
252 	g_signal_connect_swapped (
253 		memo_shell_sidebar, "client-added",
254 		G_CALLBACK (memo_shell_view_selector_client_added_cb),
255 		memo_shell_view);
256 
257 	g_signal_connect_swapped (
258 		memo_shell_sidebar, "client-removed",
259 		G_CALLBACK (memo_shell_view_selector_client_removed_cb),
260 		memo_shell_view);
261 
262 	g_signal_connect_swapped (
263 		memo_shell_sidebar, "status-message",
264 		G_CALLBACK (e_memo_shell_view_set_status_message),
265 		memo_shell_view);
266 
267 	g_signal_connect_swapped (
268 		selector, "popup-event",
269 		G_CALLBACK (memo_shell_view_selector_popup_event_cb),
270 		memo_shell_view);
271 
272 	g_signal_connect_swapped (
273 		selector, "primary-selection-changed",
274 		G_CALLBACK (e_shell_view_update_actions),
275 		memo_shell_view);
276 
277 	e_categories_add_change_hook (
278 		(GHookFunc) e_memo_shell_view_update_search_filter,
279 		memo_shell_view);
280 
281 	/* Keep the ECalModel in sync with the sidebar. */
282 	g_object_bind_property (
283 		shell_sidebar, "default-client",
284 		model, "default-client",
285 		G_BINDING_SYNC_CREATE);
286 
287 	e_memo_shell_view_actions_init (memo_shell_view);
288 	e_memo_shell_view_update_sidebar (memo_shell_view);
289 	e_memo_shell_view_update_search_filter (memo_shell_view);
290 	e_memo_shell_view_update_timezone (memo_shell_view);
291 }
292 
293 void
294 e_memo_shell_view_private_dispose (EMemoShellView *memo_shell_view)
295 {
296 	EMemoShellViewPrivate *priv = memo_shell_view->priv;
297 
298 	DISPOSE (priv->memo_shell_backend);
299 	DISPOSE (priv->memo_shell_content);
300 	DISPOSE (priv->memo_shell_sidebar);
301 
302 	if (memo_shell_view->priv->activity != NULL) {
303 		/* XXX Activity is not cancellable. */
304 		e_activity_set_state (
305 			memo_shell_view->priv->activity,
306 			E_ACTIVITY_COMPLETED);
307 		g_object_unref (memo_shell_view->priv->activity);
308 		memo_shell_view->priv->activity = NULL;
309 	}
310 }
311 
312 void
313 e_memo_shell_view_private_finalize (EMemoShellView *memo_shell_view)
314 {
315 	/* XXX Nothing to do? */
316 }
317 
318 void
319 e_memo_shell_view_open_memo (EMemoShellView *memo_shell_view,
320                              ECalModelComponent *comp_data)
321 {
322 	EShell *shell;
323 	EShellView *shell_view;
324 	EShellWindow *shell_window;
325 	ESourceRegistry *registry;
326 	CompEditor *editor;
327 	CompEditorFlags flags = 0;
328 	ECalComponent *comp;
329 	icalcomponent *clone;
330 	const gchar *uid;
331 
332 	g_return_if_fail (E_IS_MEMO_SHELL_VIEW (memo_shell_view));
333 	g_return_if_fail (E_IS_CAL_MODEL_COMPONENT (comp_data));
334 
335 	shell_view = E_SHELL_VIEW (memo_shell_view);
336 	shell_window = e_shell_view_get_shell_window (shell_view);
337 	shell = e_shell_window_get_shell (shell_window);
338 
339 	registry = e_shell_get_registry (shell);
340 
341 	uid = icalcomponent_get_uid (comp_data->icalcomp);
342 	editor = comp_editor_find_instance (uid);
343 
344 	if (editor != NULL)
345 		goto exit;
346 
347 	comp = e_cal_component_new ();
348 	clone = icalcomponent_new_clone (comp_data->icalcomp);
349 	e_cal_component_set_icalcomponent (comp, clone);
350 
351 	if (e_cal_component_has_organizer (comp))
352 		flags |= COMP_EDITOR_IS_SHARED;
353 
354 	if (itip_organizer_is_user (registry, comp, comp_data->client))
355 		flags |= COMP_EDITOR_USER_ORG;
356 
357 	editor = memo_editor_new (comp_data->client, shell, flags);
358 	comp_editor_edit_comp (editor, comp);
359 
360 	g_object_unref (comp);
361 
362 exit:
363 	gtk_window_present (GTK_WINDOW (editor));
364 }
365 
366 void
367 e_memo_shell_view_set_status_message (EMemoShellView *memo_shell_view,
368                                       const gchar *status_message,
369                                       gdouble percent)
370 {
371 	EActivity *activity;
372 	EShellView *shell_view;
373 	EShellBackend *shell_backend;
374 
375 	g_return_if_fail (E_IS_MEMO_SHELL_VIEW (memo_shell_view));
376 
377 	activity = memo_shell_view->priv->activity;
378 	shell_view = E_SHELL_VIEW (memo_shell_view);
379 	shell_backend = e_shell_view_get_shell_backend (shell_view);
380 
381 	if (status_message == NULL || *status_message == '\0') {
382 		if (activity != NULL) {
383 			e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
384 			g_object_unref (activity);
385 			activity = NULL;
386 		}
387 
388 	} else if (activity == NULL) {
389 		activity = e_activity_new ();
390 		e_activity_set_percent (activity, percent);
391 		e_activity_set_text (activity, status_message);
392 		e_shell_backend_add_activity (shell_backend, activity);
393 
394 	} else {
395 		e_activity_set_percent (activity, percent);
396 		e_activity_set_text (activity, status_message);
397 	}
398 
399 	memo_shell_view->priv->activity = activity;
400 }
401 
402 void
403 e_memo_shell_view_update_sidebar (EMemoShellView *memo_shell_view)
404 {
405 	EMemoShellContent *memo_shell_content;
406 	EShellView *shell_view;
407 	EShellSidebar *shell_sidebar;
408 	EMemoTable *memo_table;
409 	ECalModel *model;
410 	GString *string;
411 	const gchar *format;
412 	gint n_rows;
413 	gint n_selected;
414 
415 	shell_view = E_SHELL_VIEW (memo_shell_view);
416 	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
417 
418 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
419 	memo_table = e_memo_shell_content_get_memo_table (memo_shell_content);
420 
421 	model = e_memo_table_get_model (memo_table);
422 
423 	n_rows = e_table_model_row_count (E_TABLE_MODEL (model));
424 	n_selected = e_table_selected_count (E_TABLE (memo_table));
425 
426 	string = g_string_sized_new (64);
427 
428 	format = ngettext ("%d memo", "%d memos", n_rows);
429 	g_string_append_printf (string, format, n_rows);
430 
431 	if (n_selected > 0) {
432 		format = _("%d selected");
433 		g_string_append_len (string, ", ", 2);
434 		g_string_append_printf (string, format, n_selected);
435 	}
436 
437 	e_shell_sidebar_set_secondary_text (shell_sidebar, string->str);
438 
439 	g_string_free (string, TRUE);
440 }
441 
442 void
443 e_memo_shell_view_update_timezone (EMemoShellView *memo_shell_view)
444 {
445 	EMemoShellContent *memo_shell_content;
446 	EMemoShellSidebar *memo_shell_sidebar;
447 	icaltimezone *timezone;
448 	ECalModel *model;
449 	GList *clients, *iter;
450 
451 	memo_shell_content = memo_shell_view->priv->memo_shell_content;
452 	model = e_memo_shell_content_get_memo_model (memo_shell_content);
453 	timezone = e_cal_model_get_timezone (model);
454 
455 	memo_shell_sidebar = memo_shell_view->priv->memo_shell_sidebar;
456 	clients = e_memo_shell_sidebar_get_clients (memo_shell_sidebar);
457 
458 	for (iter = clients; iter != NULL; iter = iter->next) {
459 		ECalClient *client = iter->data;
460 
461 		if (e_client_is_opened (E_CLIENT (client)))
462 			e_cal_client_set_default_timezone (client, timezone);
463 	}
464 
465 	g_list_free (clients);
466 }