evolution-3.6.4/addressbook/gui/widgets/e-minicard-view-widget.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-minicard-view-widget.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-minicard-view-widget.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  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Chris Lahey <clahey@ximian.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <gtk/gtk.h>
 28 #include <misc/e-canvas-background.h>
 29 #include <misc/e-canvas.h>
 30 #include <glib/gi18n.h>
 31 
 32 #include "e-util/e-util.h"
 33 #include "e-minicard-view-widget.h"
 34 
 35 static void	e_minicard_view_widget_set_property
 36 						(GObject *object,
 37 						 guint property_id,
 38 						 const GValue *value,
 39 						 GParamSpec *pspec);
 40 static void	e_minicard_view_widget_get_property
 41 						(GObject *object,
 42 						 guint property_id,
 43 						 GValue *value,
 44 						 GParamSpec *pspec);
 45 static void	e_minicard_view_widget_dispose	(GObject *object);
 46 static void	e_minicard_view_widget_reflow	(ECanvas *canvas);
 47 static void	e_minicard_view_widget_size_allocate
 48 						(GtkWidget *widget,
 49 						 GtkAllocation *allocation);
 50 static void	e_minicard_view_widget_style_set
 51 						(GtkWidget *widget,
 52 						 GtkStyle *previous_style);
 53 static void	e_minicard_view_widget_realize	(GtkWidget *widget);
 54 static gboolean	e_minicard_view_widget_real_focus_in_event
 55 						(GtkWidget *widget,
 56 						 GdkEventFocus *event);
 57 
 58 enum {
 59 	PROP_0,
 60 	PROP_CLIENT,
 61 	PROP_QUERY,
 62 	PROP_EDITABLE,
 63 	PROP_COLUMN_WIDTH
 64 };
 65 
 66 enum {
 67 	CREATE_CONTACT,
 68 	CREATE_CONTACT_LIST,
 69 	SELECTION_CHANGE,
 70 	COLUMN_WIDTH_CHANGED,
 71 	RIGHT_CLICK,
 72 	LAST_SIGNAL
 73 };
 74 
 75 static guint signals[LAST_SIGNAL] = {0, };
 76 
 77 G_DEFINE_TYPE (
 78 	EMinicardViewWidget,
 79 	e_minicard_view_widget,
 80 	E_TYPE_CANVAS)
 81 
 82 static void
 83 e_minicard_view_widget_class_init (EMinicardViewWidgetClass *class)
 84 {
 85 	GObjectClass *object_class;
 86 	GtkWidgetClass *widget_class;
 87 	ECanvasClass *canvas_class;
 88 
 89 	object_class = G_OBJECT_CLASS (class);
 90 	object_class->set_property = e_minicard_view_widget_set_property;
 91 	object_class->get_property = e_minicard_view_widget_get_property;
 92 	object_class->dispose = e_minicard_view_widget_dispose;
 93 
 94 	widget_class = GTK_WIDGET_CLASS (class);
 95 	widget_class->style_set = e_minicard_view_widget_style_set;
 96 	widget_class->realize = e_minicard_view_widget_realize;
 97 	widget_class->size_allocate = e_minicard_view_widget_size_allocate;
 98 	widget_class->focus_in_event = e_minicard_view_widget_real_focus_in_event;
 99 
100 	canvas_class = E_CANVAS_CLASS (class);
101 	canvas_class->reflow = e_minicard_view_widget_reflow;
102 
103 	class->selection_change = NULL;
104 	class->column_width_changed = NULL;
105 	class->right_click = NULL;
106 
107 	g_object_class_install_property (
108 		object_class,
109 		PROP_CLIENT,
110 		g_param_spec_object (
111 			"client",
112 			"EBookClient",
113 			NULL,
114 			E_TYPE_BOOK_CLIENT,
115 			G_PARAM_READWRITE));
116 
117 	g_object_class_install_property (
118 		object_class,
119 		PROP_QUERY,
120 		g_param_spec_string (
121 			"query",
122 			"Query",
123 			NULL,
124 			NULL,
125 			G_PARAM_READWRITE));
126 
127 	g_object_class_install_property (
128 		object_class,
129 		PROP_EDITABLE,
130 		g_param_spec_boolean (
131 			"editable",
132 			"Editable",
133 			NULL,
134 			FALSE,
135 			G_PARAM_READWRITE));
136 
137 	g_object_class_install_property (
138 		object_class,
139 		PROP_COLUMN_WIDTH,
140 		g_param_spec_double (
141 			"column_width",
142 			"Column Width",
143 			NULL,
144 			0.0, G_MAXDOUBLE, 225.0,
145 			G_PARAM_READWRITE));
146 
147 	signals[CREATE_CONTACT] = g_signal_new (
148 		"create-contact",
149 		G_OBJECT_CLASS_TYPE (object_class),
150 		G_SIGNAL_RUN_LAST,
151 		G_STRUCT_OFFSET (EMinicardViewWidgetClass, create_contact),
152 		NULL, NULL,
153 		g_cclosure_marshal_VOID__VOID,
154 		G_TYPE_NONE, 0);
155 
156 	signals[CREATE_CONTACT_LIST] = g_signal_new (
157 		"create-contact-list",
158 		G_OBJECT_CLASS_TYPE (object_class),
159 		G_SIGNAL_RUN_LAST,
160 		G_STRUCT_OFFSET (EMinicardViewWidgetClass, create_contact_list),
161 		NULL, NULL,
162 		g_cclosure_marshal_VOID__VOID,
163 		G_TYPE_NONE, 0);
164 
165 	signals[SELECTION_CHANGE] = g_signal_new (
166 		"selection_change",
167 		G_OBJECT_CLASS_TYPE (object_class),
168 		G_SIGNAL_RUN_LAST,
169 		G_STRUCT_OFFSET (EMinicardViewWidgetClass, selection_change),
170 		NULL, NULL,
171 		g_cclosure_marshal_VOID__VOID,
172 		G_TYPE_NONE, 0);
173 
174 	signals[COLUMN_WIDTH_CHANGED] = g_signal_new (
175 		"column_width_changed",
176 		G_OBJECT_CLASS_TYPE (object_class),
177 		G_SIGNAL_RUN_LAST,
178 		G_STRUCT_OFFSET (EMinicardViewWidgetClass, column_width_changed),
179 		NULL, NULL,
180 		g_cclosure_marshal_VOID__DOUBLE,
181 		G_TYPE_NONE, 1,
182 		G_TYPE_DOUBLE);
183 
184 	signals[RIGHT_CLICK] = g_signal_new (
185 		"right_click",
186 		G_OBJECT_CLASS_TYPE (object_class),
187 		G_SIGNAL_RUN_LAST,
188 		G_STRUCT_OFFSET (EMinicardViewWidgetClass, right_click),
189 		NULL, NULL,
190 		e_marshal_INT__POINTER,
191 		G_TYPE_INT, 1,
192 		G_TYPE_POINTER);
193 }
194 
195 static void
196 e_minicard_view_widget_init (EMinicardViewWidget *view)
197 {
198 	view->emv = NULL;
199 
200 	view->book_client = NULL;
201 	view->query = NULL;
202 	view->editable = FALSE;
203 	view->column_width = 225;
204 }
205 
206 GtkWidget *
207 e_minicard_view_widget_new (EAddressbookReflowAdapter *adapter)
208 {
209 	EMinicardViewWidget *widget;
210 
211 	widget = g_object_new (E_TYPE_MINICARD_VIEW_WIDGET, NULL);
212 
213 	widget->adapter = g_object_ref (adapter);
214 
215 	return GTK_WIDGET (widget);
216 }
217 
218 static void
219 e_minicard_view_widget_set_property (GObject *object,
220                                      guint property_id,
221                                      const GValue *value,
222                                      GParamSpec *pspec)
223 {
224 	EMinicardViewWidget *emvw;
225 
226 	emvw = E_MINICARD_VIEW_WIDGET (object);
227 
228 	switch (property_id) {
229 	case PROP_CLIENT:
230 		if (emvw->book_client)
231 			g_object_unref (emvw->book_client);
232 		if (g_value_get_object (value)) {
233 			emvw->book_client = E_BOOK_CLIENT (g_value_get_object (value));
234 			if (emvw->book_client)
235 				g_object_ref (emvw->book_client);
236 		} else
237 			emvw->book_client = NULL;
238 		if (emvw->emv)
239 			g_object_set (
240 				emvw->emv,
241 				"client", emvw->book_client,
242 				NULL);
243 		break;
244 	case PROP_QUERY:
245 		emvw->query = g_strdup (g_value_get_string (value));
246 		if (emvw->emv)
247 			g_object_set (
248 				emvw->emv,
249 				"query", emvw->query,
250 				NULL);
251 		break;
252 	case PROP_EDITABLE:
253 		emvw->editable = g_value_get_boolean (value);
254 		if (emvw->emv)
255 			g_object_set (
256 				emvw->emv,
257 				"editable", emvw->editable,
258 				NULL);
259 		break;
260 	case PROP_COLUMN_WIDTH:
261 		emvw->column_width = g_value_get_double (value);
262 		if (emvw->emv) {
263 			g_object_set (
264 				emvw->emv,
265 				"column_width", emvw->column_width,
266 				NULL);
267 		}
268 		break;
269 	default:
270 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
271 		break;
272 	}
273 }
274 
275 static void
276 e_minicard_view_widget_get_property (GObject *object,
277                                      guint property_id,
278                                      GValue *value,
279                                      GParamSpec *pspec)
280 {
281 	EMinicardViewWidget *emvw;
282 
283 	emvw = E_MINICARD_VIEW_WIDGET (object);
284 
285 	switch (property_id) {
286 	case PROP_CLIENT:
287 		g_value_set_object (value, emvw->book_client);
288 		break;
289 	case PROP_QUERY:
290 		g_value_set_string (value, emvw->query);
291 		break;
292 	case PROP_EDITABLE:
293 		g_value_set_boolean (value, emvw->editable);
294 		break;
295 	case PROP_COLUMN_WIDTH:
296 		g_value_set_double (value, emvw->column_width);
297 		break;
298 	default:
299 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
300 		break;
301 	}
302 }
303 
304 static void
305 e_minicard_view_widget_dispose (GObject *object)
306 {
307 	EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET (object);
308 
309 	if (view->book_client) {
310 		g_object_unref (view->book_client);
311 		view->book_client = NULL;
312 	}
313 	if (view->query) {
314 		g_free (view->query);
315 		view->query = NULL;
316 	}
317 
318 	if (view->adapter) {
319 		g_object_unref (view->adapter);
320 		view->adapter = NULL;
321 	}
322 
323 	/* Chain up to parent's dispose() method. */
324 	G_OBJECT_CLASS (e_minicard_view_widget_parent_class)->dispose (object);
325 }
326 
327 static void
328 selection_change (ESelectionModel *esm,
329                   EMinicardViewWidget *widget)
330 {
331 	g_signal_emit (widget, signals[SELECTION_CHANGE], 0);
332 }
333 
334 static void
335 selection_row_change (ESelectionModel *esm,
336                       gint row,
337                       EMinicardViewWidget *widget)
338 {
339 	selection_change (esm, widget);
340 }
341 
342 static void
343 column_width_changed (ESelectionModel *esm,
344                       gdouble width,
345                       EMinicardViewWidget *widget)
346 {
347 	g_signal_emit (widget, signals[COLUMN_WIDTH_CHANGED], 0, width);
348 }
349 
350 static void
351 create_contact (EMinicardView *view,
352                 EMinicardViewWidget *widget)
353 {
354 	g_signal_emit (widget, signals[CREATE_CONTACT], 0);
355 }
356 
357 static void
358 create_contact_list (EMinicardView *view,
359                      EMinicardViewWidget *widget)
360 {
361 	g_signal_emit (widget, signals[CREATE_CONTACT_LIST], 0);
362 }
363 
364 static guint
365 right_click (EMinicardView *view,
366              GdkEvent *event,
367              EMinicardViewWidget *widget)
368 {
369 	guint ret_val;
370 
371 	g_signal_emit (widget, signals[RIGHT_CLICK], 0, event, &ret_val);
372 
373 	return ret_val;
374 }
375 
376 static void
377 e_minicard_view_widget_style_set (GtkWidget *widget,
378                                   GtkStyle *previous_style)
379 {
380 	EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET (widget);
381 	GtkStyle *style;
382 
383 	style = gtk_widget_get_style (widget);
384 
385 	if (view->background)
386 		gnome_canvas_item_set (
387 			view->background, "fill_color_gdk",
388 			&style->base[GTK_STATE_NORMAL], NULL);
389 
390 	GTK_WIDGET_CLASS (e_minicard_view_widget_parent_class)->
391 		style_set (widget, previous_style);
392 }
393 
394 static void
395 e_minicard_view_widget_realize (GtkWidget *widget)
396 {
397 	EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET (widget);
398 	GtkStyle *style = gtk_widget_get_style (widget);
399 
400 	view->background = gnome_canvas_item_new (
401 		gnome_canvas_root (GNOME_CANVAS (view)),
402 		e_canvas_background_get_type (),
403 		"fill_color_gdk", &style->base[GTK_STATE_NORMAL],
404 		NULL);
405 
406 	view->emv = gnome_canvas_item_new (
407 		gnome_canvas_root (GNOME_CANVAS (view)),
408 		e_minicard_view_get_type (),
409 		"height", (gdouble) 100,
410 		"minimum_width", (gdouble) 100,
411 		"adapter", view->adapter,
412 		"column_width", view->column_width,
413 		NULL);
414 
415 	g_signal_connect (
416 		E_REFLOW (view->emv)->selection,
417 		"selection_changed",
418 		G_CALLBACK (selection_change), view);
419 	g_signal_connect (
420 		E_REFLOW (view->emv)->selection,
421 		"selection_row_changed",
422 		G_CALLBACK (selection_row_change), view);
423 	g_signal_connect (
424 		view->emv, "column_width_changed",
425 		G_CALLBACK (column_width_changed), view);
426 	g_signal_connect (
427 		view->emv, "create-contact",
428 		G_CALLBACK (create_contact), view);
429 	g_signal_connect (
430 		view->emv, "create-contact-list",
431 		G_CALLBACK (create_contact_list), view);
432 	g_signal_connect (
433 		view->emv, "right_click",
434 		G_CALLBACK (right_click), view);
435 
436 	GTK_WIDGET_CLASS (e_minicard_view_widget_parent_class)->
437 		realize (widget);
438 }
439 
440 static void
441 e_minicard_view_widget_size_allocate (GtkWidget *widget,
442                                       GtkAllocation *allocation)
443 {
444 	GTK_WIDGET_CLASS (e_minicard_view_widget_parent_class)->
445 		size_allocate (widget, allocation);
446 
447 	if (gtk_widget_get_realized (widget)) {
448 		gdouble width;
449 		EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET (widget);
450 
451 		gnome_canvas_item_set (
452 			view->emv, "height",
453 			(gdouble) allocation->height, NULL);
454 		gnome_canvas_item_set (
455 			view->emv, "minimum_width",
456 			(gdouble) allocation->width, NULL);
457 		g_object_get (view->emv, "width", &width, NULL);
458 		width = MAX (width, allocation->width);
459 		gnome_canvas_set_scroll_region (
460 			GNOME_CANVAS (view), 0, 0,
461 			width - 1, allocation->height - 1);
462 	}
463 }
464 
465 static void
466 e_minicard_view_widget_reflow (ECanvas *canvas)
467 {
468 	gdouble width;
469 	EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET (canvas);
470 	GtkAllocation allocation;
471 
472 	E_CANVAS_CLASS (e_minicard_view_widget_parent_class)->reflow (canvas);
473 
474 	g_object_get (view->emv, "width", &width, NULL);
475 	gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
476 
477 	gnome_canvas_set_scroll_region (
478 		GNOME_CANVAS (canvas), 0, 0,
479 		MAX (width, allocation.width) - 1,
480 		allocation.height - 1);
481 }
482 
483 ESelectionModel *
484 e_minicard_view_widget_get_selection_model (EMinicardViewWidget *view)
485 {
486 	if (view->emv)
487 		return E_SELECTION_MODEL (E_REFLOW (view->emv)->selection);
488 	else
489 		return NULL;
490 }
491 
492 EMinicardView *
493 e_minicard_view_widget_get_view (EMinicardViewWidget *view)
494 {
495 	if (view->emv)
496 		return E_MINICARD_VIEW (view->emv);
497 	else
498 		return NULL;
499 }
500 
501 static gboolean
502 e_minicard_view_widget_real_focus_in_event (GtkWidget *widget,
503                                             GdkEventFocus *event)
504 {
505 	GnomeCanvas *canvas;
506 	EMinicardViewWidget *view;
507 
508 	canvas = GNOME_CANVAS (widget);
509 	view = E_MINICARD_VIEW_WIDGET (widget);
510 
511 	if (!canvas->focused_item) {
512 		EReflow *reflow = E_REFLOW (view->emv);
513 		if (reflow->count) {
514 			gint unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), 0);
515 
516 			if (unsorted != -1)
517 				canvas->focused_item = reflow->items[unsorted];
518 		}
519 	}
520 
521 	return GTK_WIDGET_CLASS (e_minicard_view_widget_parent_class)->
522 		focus_in_event (widget, event);
523 }