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

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found ea-minicard.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found ea-minicard.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 <glib/gi18n.h>
 29 #include "ea-minicard.h"
 30 #include "ea-minicard-view.h"
 31 #include "e-minicard.h"
 32 
 33 static const gchar * action_name[] = {
 34 	N_("Open")
 35 };
 36 
 37 static const gchar *
 38 		ea_minicard_get_name		(AtkObject *accessible);
 39 static const gchar *
 40 		ea_minicard_get_description	(AtkObject *accessible);
 41 
 42 static void	ea_minicard_class_init		(EaMinicardClass *klass);
 43 
 44 static gint	ea_minicard_get_n_children	(AtkObject *obj);
 45 static AtkObject *
 46 		ea_minicard_ref_child		(AtkObject *obj,
 47 						 gint i);
 48 
 49 static AtkStateSet *
 50 		ea_minicard_ref_state_set	(AtkObject *obj);
 51 
 52 static void	atk_action_interface_init	(AtkActionIface *iface);
 53 static gboolean	atk_action_interface_do_action	(AtkAction *iface,
 54 						 gint i);
 55 static gint	atk_action_interface_get_n_action
 56 						(AtkAction *iface);
 57 static const gchar *
 58 		atk_action_interface_get_description
 59 						(AtkAction *iface,
 60 						 gint i);
 61 static const gchar *
 62 		atk_action_interface_get_name	(AtkAction *iface,
 63 						 gint i);
 64 
 65 static gpointer parent_class = NULL;
 66 
 67 GType
 68 ea_minicard_get_type (void)
 69 {
 70 	static GType type = 0;
 71 	AtkObjectFactory *factory;
 72 	GTypeQuery query;
 73 	GType derived_atk_type;
 74 
 75 	if (!type) {
 76 		static  GTypeInfo tinfo =  {
 77 			sizeof (EaMinicardClass),
 78 			(GBaseInitFunc) NULL,  /* base_init */
 79 			(GBaseFinalizeFunc) NULL,  /* base_finalize */
 80 			(GClassInitFunc) ea_minicard_class_init,
 81 			(GClassFinalizeFunc) NULL, /* class_finalize */
 82 			NULL,	/* class_data */
 83 			sizeof (EaMinicard),
 84 			0,	/* n_preallocs */
 85 			(GInstanceInitFunc) NULL, /* instance init */
 86 			NULL	/* value table */
 87 		};
 88 
 89 		static const GInterfaceInfo atk_action_info = {
 90 			(GInterfaceInitFunc) atk_action_interface_init,
 91 			(GInterfaceFinalizeFunc) NULL,
 92 			NULL
 93 		};
 94 
 95 		/*
 96 		 * Figure out the size of the class and instance
 97 		 * we are run-time deriving from (GailWidget, in this case)
 98 		 */
 99 
100 		factory = atk_registry_get_factory (
101 			atk_get_default_registry (),
102 			GNOME_TYPE_CANVAS_GROUP);
103 		derived_atk_type = atk_object_factory_get_accessible_type (factory);
104 		g_type_query (derived_atk_type, &query);
105 
106 		tinfo.class_size = query.class_size;
107 		tinfo.instance_size = query.instance_size;
108 
109 		type = g_type_register_static (
110 			derived_atk_type,
111 			"EaMinicard", &tinfo, 0);
112 		g_type_add_interface_static (
113 			type, ATK_TYPE_ACTION,
114 			&atk_action_info);
115 	}
116 
117 	return type;
118 }
119 
120 static void
121 ea_minicard_class_init (EaMinicardClass *klass)
122 {
123 	AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
124 
125 	parent_class = g_type_class_peek_parent (klass);
126 
127 	class->get_name = ea_minicard_get_name;
128 	class->get_description = ea_minicard_get_description;
129 	class->ref_state_set = ea_minicard_ref_state_set;
130 	class->get_n_children = ea_minicard_get_n_children;
131 	class->ref_child = ea_minicard_ref_child;
132 }
133 
134 /*
135  *  we access the main content of current minicard, including
136  *  header text, label(field, field name)
137  */
138 static const gchar *
139 ea_minicard_get_name (AtkObject *accessible)
140 {
141 #define BUFFERSIZE 500
142 
143 	static gchar name[BUFFERSIZE];
144 	GString *new_str = g_string_new (NULL);
145 	gchar *string;
146 	EMinicard *card;
147 
148 	g_return_val_if_fail (EA_IS_MINICARD (accessible), NULL);
149 	memset (name, '\0', BUFFERSIZE);
150 
151 	card = E_MINICARD (
152 		atk_gobject_accessible_get_object (
153 		ATK_GOBJECT_ACCESSIBLE (accessible)));
154 	if (!card)
155 		return NULL;
156 
157 	g_object_get (card->header_text, "text", &string, NULL);
158 
159 	if (e_contact_get (card->contact, E_CONTACT_IS_LIST))
160 		g_string_append (new_str, _("Contact List: "));
161 	else    g_string_append (new_str, _("Contact: "));
162 
163 	/* get header of current card */
164 	g_string_append (new_str, string);
165 	g_free (string);
166 
167 	/* if there exist no enough space for remain info, return */
168 	if (new_str->len >= BUFFERSIZE) {
169 		strncpy (name, new_str->str, BUFFERSIZE);
170 		return name;
171 	}
172 
173 	strcpy (name, new_str->str);
174 	g_string_free (new_str, TRUE);
175 
176 	ATK_OBJECT_CLASS (parent_class)->set_name (accessible, name);
177 
178 	return accessible->name;
179 }
180 
181 static const gchar *
182 ea_minicard_get_description (AtkObject *accessible)
183 {
184 	if (accessible->description)
185 		return accessible->description;
186 
187 	return _("evolution minicard");
188 }
189 
190 AtkObject *
191 ea_minicard_new (GObject *obj)
192 {
193 	GObject *object;
194 	AtkObject *accessible;
195 
196 	g_return_val_if_fail (obj != NULL, NULL);
197 	g_return_val_if_fail (E_IS_MINICARD (obj), NULL);
198 
199 	object = g_object_new (EA_TYPE_MINICARD, NULL);
200 	accessible = ATK_OBJECT (object);
201 	atk_object_initialize (accessible, obj);
202 
203 	accessible->role = ATK_ROLE_PANEL;
204 	return accessible;
205 }
206 
207 static AtkStateSet *
208 ea_minicard_ref_state_set (AtkObject *obj)
209 {
210 	AtkStateSet *state_set = NULL;
211 	GObject *gobj = NULL;
212 
213 	state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (obj);
214 	if (!state_set)
215 		state_set = atk_state_set_new ();
216 
217 	gobj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (obj));
218 	if (!gobj)
219 		return state_set;
220 
221 	atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
222 	atk_state_set_add_state (state_set, ATK_STATE_ENABLED);
223 	atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE);
224 	atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
225 
226 	return state_set;
227 }
228 
229 static gint
230 ea_minicard_get_n_children (AtkObject *accessible)
231 {
232 	return 0;
233 }
234 
235 static AtkObject *
236 ea_minicard_ref_child (AtkObject *accessible,
237                        gint index)
238 {
239 	return NULL;
240 }
241 
242 static void
243 atk_action_interface_init (AtkActionIface *iface)
244 {
245 	g_return_if_fail (iface != NULL);
246 
247 	iface->do_action = atk_action_interface_do_action;
248 	iface->get_n_actions = atk_action_interface_get_n_action;
249 	iface->get_description = atk_action_interface_get_description;
250 	iface->get_name = atk_action_interface_get_name;
251 }
252 
253 static gboolean
254 atk_action_interface_do_action (AtkAction *iface,
255                                 gint i)
256 {
257 	EMinicard *minicard = NULL;
258 
259 	minicard = E_MINICARD (
260 		atk_gobject_accessible_get_object (
261 		ATK_GOBJECT_ACCESSIBLE (iface)));
262 	if (minicard == NULL)
263 		return FALSE;
264 
265 	if (i >= G_N_ELEMENTS (action_name) || i < 0)
266 		return FALSE;
267 
268 	switch (i) {
269 		/* open card */
270 		case 0:
271 			e_minicard_activate_editor (minicard);
272 			break;
273 		default:
274 			return FALSE;
275 	}
276 
277 	return TRUE;
278 }
279 
280 static gint
281 atk_action_interface_get_n_action (AtkAction *iface)
282 {
283 	return G_N_ELEMENTS (action_name);
284 }
285 
286 static const gchar *
287 atk_action_interface_get_description (AtkAction *iface,
288                                       gint i)
289 {
290 	return atk_action_interface_get_name (iface, i);
291 }
292 
293 static const gchar *
294 atk_action_interface_get_name (AtkAction *iface,
295                                gint i)
296 {
297 	if (i >= G_N_ELEMENTS (action_name) || i < 0)
298 		return NULL;
299 
300 	return action_name[i];
301 }