evolution-3.6.4/addressbook/gui/widgets/ea-minicard-view.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found ea-minicard-view.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found ea-minicard-view.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  *		Leon Zhang < leon.zhang@sun.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 <string.h>
 28 #include <gtk/gtk.h>
 29 #include <glib/gi18n.h>
 30 #include "ea-minicard.h"
 31 #include "ea-minicard-view.h"
 32 #include "eab-gui-util.h"
 33 #include "e-addressbook-view.h"
 34 
 35 static const gchar * action_name[] = {
 36 	N_("New Contact"),
 37 	N_("New Contact List")
 38 };
 39 
 40 static const gchar * ea_minicard_view_get_name (AtkObject *accessible);
 41 static const gchar * ea_minicard_view_get_description (AtkObject *accessible);
 42 
 43 static void ea_minicard_view_class_init (EaMinicardViewClass *klass);
 44 
 45 static gint ea_minicard_view_get_n_children (AtkObject *obj);
 46 static AtkObject *ea_minicard_view_ref_child (AtkObject *obj, gint i);
 47 
 48 static AtkStateSet *ea_minicard_view_ref_state_set (AtkObject *obj);
 49 
 50 static void atk_selection_interface_init (AtkSelectionIface *iface);
 51 static gboolean selection_interface_add_selection (AtkSelection *selection,
 52 						   gint i);
 53 static gboolean selection_interface_clear_selection (AtkSelection *selection);
 54 static AtkObject * selection_interface_ref_selection (AtkSelection *selection,
 55 						     gint i);
 56 static gint selection_interface_get_selection_count (AtkSelection *selection);
 57 static gboolean selection_interface_is_child_selected (AtkSelection *selection,
 58 						       gint i);
 59 
 60 static void atk_action_interface_init (AtkActionIface *iface);
 61 static gboolean atk_action_interface_do_action (AtkAction *iface, gint i);
 62 static gint atk_action_interface_get_n_action (AtkAction *iface);
 63 static const gchar *
 64 		atk_action_interface_get_description
 65 						(AtkAction *iface,
 66 						 gint i);
 67 static const gchar *
 68 		atk_action_interface_get_name	(AtkAction *iface,
 69 						 gint i);
 70 
 71 static gpointer parent_class = NULL;
 72 
 73 GType
 74 ea_minicard_view_get_type (void)
 75 {
 76 	static GType type = 0;
 77 	AtkObjectFactory *factory;
 78 	GTypeQuery query;
 79 	GType derived_atk_type;
 80 
 81 	if (!type) {
 82 		static  GTypeInfo tinfo =  {
 83 			sizeof (EaMinicardViewClass),
 84 			(GBaseInitFunc) NULL,  /* base_init */
 85 			(GBaseFinalizeFunc) NULL,  /* base_finalize */
 86 			(GClassInitFunc) ea_minicard_view_class_init,
 87 			(GClassFinalizeFunc) NULL, /* class_finalize */
 88 			NULL,	   /* class_data */
 89 			sizeof (EaMinicardView),
 90 			0,	     /* n_preallocs */
 91 			(GInstanceInitFunc) NULL, /* instance init */
 92 			NULL /* value table */
 93 		};
 94 
 95 		static const GInterfaceInfo atk_selection_info = {
 96 			(GInterfaceInitFunc) atk_selection_interface_init,
 97 			(GInterfaceFinalizeFunc) NULL,
 98 			NULL
 99 		};
100 
101 		static const GInterfaceInfo atk_action_info = {
102 			(GInterfaceInitFunc) atk_action_interface_init,
103 			(GInterfaceFinalizeFunc) NULL,
104 			NULL
105 		};
106 
107 		/*
108 		 * Figure out the size of the class and instance
109 		 * we are run-time deriving from (GailWidget, in this case) */
110 
111 		factory = atk_registry_get_factory (
112 			atk_get_default_registry (),
113 			GNOME_TYPE_CANVAS_GROUP);
114 		derived_atk_type = atk_object_factory_get_accessible_type (factory);
115 		g_type_query (derived_atk_type, &query);
116 
117 		tinfo.class_size = query.class_size;
118 		tinfo.instance_size = query.instance_size;
119 
120 		type = g_type_register_static (
121 			derived_atk_type,
122 			"EaMinicardView", &tinfo, 0);
123 		g_type_add_interface_static (
124 			type, ATK_TYPE_SELECTION,
125 			&atk_selection_info);
126 		g_type_add_interface_static (
127 			type, ATK_TYPE_ACTION,
128 			&atk_action_info);
129 
130 	}
131 
132 	return type;
133 }
134 
135 static void
136 ea_minicard_view_class_init (EaMinicardViewClass *klass)
137 {
138 	AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
139 
140 	parent_class = g_type_class_peek_parent (klass);
141 
142 	class->get_name = ea_minicard_view_get_name;
143 	class->get_description = ea_minicard_view_get_description;
144 	class->ref_state_set = ea_minicard_view_ref_state_set;
145 	class->get_n_children = ea_minicard_view_get_n_children;
146 	class->ref_child = ea_minicard_view_ref_child;
147 }
148 
149 static const gchar *
150 ea_minicard_view_get_name (AtkObject *accessible)
151 {
152 	EReflow *reflow;
153 	gchar *string;
154 	EMinicardView *card_view;
155 	EBookClient *book_client = NULL;
156 	ESource *source;
157 	const gchar *display_name;
158 
159 	g_return_val_if_fail (EA_IS_MINICARD_VIEW (accessible), NULL);
160 
161 	reflow = E_REFLOW (atk_gobject_accessible_get_object (
162 		ATK_GOBJECT_ACCESSIBLE (accessible)));
163 
164 	if (!reflow)
165 		return NULL;
166 
167 	/* Get the current name of minicard view*/
168 	card_view = E_MINICARD_VIEW (reflow);
169 	g_object_get (card_view->adapter, "client", &book_client, NULL);
170 	g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
171 	source = e_client_get_source (E_CLIENT (book_client));
172 	display_name = e_source_get_display_name (source);
173 	if (display_name == NULL)
174 		display_name = "";
175 
176 	string = g_strdup_printf (
177 		ngettext ("current address book folder %s has %d card",
178 		"current address book folder %s has %d cards",
179 		reflow->count), display_name, reflow->count);
180 
181 	ATK_OBJECT_CLASS (parent_class)->set_name (accessible, string);
182 	g_free (string);
183 	g_object_unref (book_client);
184 	return accessible->name;
185 }
186 
187 static const gchar *
188 ea_minicard_view_get_description (AtkObject *accessible)
189 {
190 	g_return_val_if_fail (EA_IS_MINICARD_VIEW (accessible), NULL);
191 	if (accessible->description)
192 		return accessible->description;
193 
194 	return _("evolution address book");
195 }
196 
197 AtkObject *
198 ea_minicard_view_new (GObject *obj)
199 {
200 	GObject *object;
201 	AtkObject *accessible;
202 
203 	g_return_val_if_fail (E_IS_MINICARD_VIEW (obj), NULL);
204 	object = g_object_new (EA_TYPE_MINICARD_VIEW, NULL);
205 	accessible = ATK_OBJECT (object);
206 	atk_object_initialize (accessible, obj);
207 	accessible->role = ATK_ROLE_PANEL;
208 	return accessible;
209 }
210 
211 static gint
212 ea_minicard_view_get_n_children (AtkObject *accessible)
213 {
214 	EReflow *reflow;
215 
216 	gint child_num = 0;
217 
218 	g_return_val_if_fail (EA_IS_MINICARD_VIEW (accessible), -1);
219 
220 	reflow = E_REFLOW (atk_gobject_accessible_get_object (
221 		ATK_GOBJECT_ACCESSIBLE (accessible)));
222 
223 	if (!reflow)
224 		return -1;
225 
226 	child_num = reflow->count;
227 
228 	return child_num;
229 }
230 
231 static AtkStateSet *ea_minicard_view_ref_state_set (AtkObject *obj)
232 {
233 	AtkStateSet *state_set = NULL;
234 	GObject *gobj = NULL;
235 
236 	state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (obj);
237 	if (!state_set)
238 		state_set = atk_state_set_new ();
239 
240 	gobj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (obj));
241 	if (!gobj)
242 		return state_set;
243 
244 	atk_state_set_add_state (state_set, ATK_STATE_ENABLED);
245 	atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE);
246 	atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
247 
248 	return state_set;
249 }
250 
251 static AtkObject *
252 ea_minicard_view_ref_child (AtkObject *accessible,
253                             gint index)
254 {
255 	EReflow *reflow;
256 	gint child_num;
257 	AtkObject *atk_object = NULL;
258 	EMinicard *card = NULL;
259 
260 	g_return_val_if_fail (EA_IS_MINICARD_VIEW (accessible), NULL);
261 
262 	child_num = atk_object_get_n_accessible_children (accessible);
263 	if (child_num <= 0 || index < 0 || index >= child_num)
264 		return NULL;
265 
266 	reflow = E_REFLOW (atk_gobject_accessible_get_object (
267 		ATK_GOBJECT_ACCESSIBLE (accessible)));
268 	if (!reflow)
269 		return NULL;
270 	if (!reflow->items)
271 		return NULL;
272 		/* a minicard */
273 	if (index < child_num) {
274 		card = E_MINICARD (reflow->items[index]);
275 		atk_object = atk_gobject_accessible_for_object (G_OBJECT (card));
276 	} else {
277 		return NULL;
278 	}
279 
280 	g_object_ref (atk_object);
281 		return atk_object;
282 }
283 
284 /* atkselection interface */
285 
286 static void
287 atk_selection_interface_init (AtkSelectionIface *iface)
288 {
289 	g_return_if_fail (iface != NULL);
290 
291 	iface->add_selection = selection_interface_add_selection;
292 	iface->clear_selection = selection_interface_clear_selection;
293 	iface->ref_selection = selection_interface_ref_selection;
294 	iface->get_selection_count = selection_interface_get_selection_count;
295 	iface->is_child_selected = selection_interface_is_child_selected;
296 }
297 
298 static gboolean
299 selection_interface_add_selection (AtkSelection *selection,
300                                    gint i)
301 {
302 	AtkGObjectAccessible *atk_gobj= NULL;
303 	EReflow *reflow = NULL;
304 
305 	atk_gobj = ATK_GOBJECT_ACCESSIBLE (selection);
306 	reflow = E_REFLOW (atk_gobject_accessible_get_object (atk_gobj));
307 
308 	if (!reflow)
309 		return FALSE;
310 
311 	selection_interface_clear_selection (selection);
312 	e_selection_model_select_single_row (reflow->selection, i);
313 
314 	return TRUE;
315 }
316 
317 static gboolean
318 selection_interface_clear_selection (AtkSelection *selection)
319 {
320 	AtkGObjectAccessible *atk_gobj = NULL;
321 	EReflow *reflow = NULL;
322 
323 	atk_gobj = ATK_GOBJECT_ACCESSIBLE (selection);
324 	reflow = E_REFLOW (atk_gobject_accessible_get_object (atk_gobj));
325 
326 	if (!reflow)
327 		return FALSE;
328 
329 	e_selection_model_clear (reflow->selection);
330 
331 	return TRUE;
332 }
333 
334 static AtkObject *
335 selection_interface_ref_selection (AtkSelection *selection,
336                                    gint i)
337 {
338 	return ea_minicard_view_ref_child (ATK_OBJECT (selection), i);
339 }
340 
341 static gint
342 selection_interface_get_selection_count (AtkSelection *selection)
343 {
344 	AtkGObjectAccessible *atk_gobj = NULL;
345 	EReflow *reflow = NULL;
346 
347 	atk_gobj = ATK_GOBJECT_ACCESSIBLE (selection);
348 	reflow = E_REFLOW (atk_gobject_accessible_get_object (atk_gobj));
349 
350 	if (!reflow)
351 		return FALSE;
352 
353 	return e_selection_model_selected_count (reflow->selection);
354 }
355 
356 static gboolean
357 selection_interface_is_child_selected (AtkSelection *selection,
358                                        gint i)
359 {
360 	AtkGObjectAccessible *atk_gobj = NULL;
361 	EReflow *reflow = NULL;
362 
363 	atk_gobj = ATK_GOBJECT_ACCESSIBLE (selection);
364 	reflow = E_REFLOW (atk_gobject_accessible_get_object (atk_gobj));
365 
366 	if (!reflow)
367 		return FALSE;
368 
369 	return e_selection_model_is_row_selected (reflow->selection, i);
370 }
371 
372 static void atk_action_interface_init (AtkActionIface *iface)
373 {
374 	g_return_if_fail (iface != NULL);
375 
376 	iface->do_action = atk_action_interface_do_action;
377 	iface->get_n_actions = atk_action_interface_get_n_action;
378 	iface->get_description = atk_action_interface_get_description;
379 	iface->get_name = atk_action_interface_get_name;
380 }
381 
382 static gboolean
383 atk_action_interface_do_action (AtkAction *action,
384                                 gint i)
385 {
386 	gboolean return_value = TRUE;
387 	EMinicardView *card_view;
388 
389 	AtkGObjectAccessible *atk_gobj= NULL;
390 	EReflow *reflow = NULL;
391 
392 	atk_gobj = ATK_GOBJECT_ACCESSIBLE (action);
393 	reflow = E_REFLOW (atk_gobject_accessible_get_object (atk_gobj));
394 
395 	if (reflow == NULL)
396 		return FALSE;
397 
398 	card_view = E_MINICARD_VIEW (reflow);
399 
400 	switch (i) {
401 		case 0:
402 		/* New Contact */
403 			e_minicard_view_create_contact (card_view);
404 			break;
405 		case 1:
406 		/* New Contact List */
407 			e_minicard_view_create_contact_list (card_view);
408 			break;
409 		default:
410 			return_value = FALSE;
411 			break;
412 	}
413 
414 	return return_value;
415 }
416 
417 static gint
418 atk_action_interface_get_n_action (AtkAction *iface)
419 {
420 	return G_N_ELEMENTS (action_name);
421 }
422 
423 static const gchar *
424 atk_action_interface_get_description (AtkAction *iface,
425                                       gint i)
426 {
427 	return atk_action_interface_get_name (iface, i);
428 }
429 
430 static const gchar *
431 atk_action_interface_get_name (AtkAction *iface,
432                                gint i)
433 {
434 	if (i >= G_N_ELEMENTS (action_name) || i < 0)
435 		return NULL;
436 
437 	return action_name[i];
438 }