evolution-3.6.4/widgets/table/e-tree-memory-callbacks.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-tree-memory-callbacks.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-tree-memory-callbacks.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  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		Chris Lahey <clahey@ximian.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include <gtk/gtk.h>
 29 
 30 #include "e-util/e-util.h"
 31 
 32 #include "e-tree-memory-callbacks.h"
 33 
 34 G_DEFINE_TYPE (ETreeMemoryCallbacks, e_tree_memory_callbacks, E_TYPE_TREE_MEMORY)
 35 
 36 static GdkPixbuf *
 37 etmc_icon_at (ETreeModel *etm,
 38               ETreePath node)
 39 {
 40 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
 41 
 42 	return etmc->icon_at (etm, node, etmc->model_data);
 43 }
 44 
 45 static gint
 46 etmc_column_count (ETreeModel *etm)
 47 {
 48 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
 49 
 50 	if (etmc->column_count)
 51 		return etmc->column_count (etm, etmc->model_data);
 52 	else
 53 		return 0;
 54 }
 55 
 56 static gboolean
 57 etmc_has_save_id (ETreeModel *etm)
 58 {
 59 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
 60 
 61 	if (etmc->has_save_id)
 62 		return etmc->has_save_id (etm, etmc->model_data);
 63 	else
 64 		return FALSE;
 65 }
 66 
 67 static gchar *
 68 etmc_get_save_id (ETreeModel *etm,
 69                   ETreePath node)
 70 {
 71 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
 72 
 73 	if (etmc->get_save_id)
 74 		return etmc->get_save_id (etm, node, etmc->model_data);
 75 	else
 76 		return NULL;
 77 }
 78 
 79 static gboolean
 80 etmc_has_get_node_by_id (ETreeModel *etm)
 81 {
 82 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
 83 
 84 	if (etmc->has_get_node_by_id)
 85 		return etmc->has_get_node_by_id (etm, etmc->model_data);
 86 	else
 87 		return FALSE;
 88 }
 89 
 90 static ETreePath
 91 etmc_get_node_by_id (ETreeModel *etm,
 92                      const gchar *save_id)
 93 {
 94 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
 95 
 96 	if (etmc->get_node_by_id)
 97 		return etmc->get_node_by_id (etm, save_id, etmc->model_data);
 98 	else
 99 		return NULL;
100 }
101 
102 static gpointer
103 etmc_sort_value_at (ETreeModel *etm,
104                     ETreePath node,
105                     gint col)
106 {
107 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
108 
109 	if (etmc->sort_value_at)
110 		return etmc->sort_value_at (etm, node, col, etmc->model_data);
111 	else
112 		return etmc->value_at (etm, node, col, etmc->model_data);
113 }
114 
115 static gpointer
116 etmc_value_at (ETreeModel *etm,
117                ETreePath node,
118                gint col)
119 {
120 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
121 
122 	return etmc->value_at (etm, node, col, etmc->model_data);
123 }
124 
125 static void
126 etmc_set_value_at (ETreeModel *etm,
127                    ETreePath node,
128                    gint col,
129                    gconstpointer val)
130 {
131 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
132 
133 	etmc->set_value_at (etm, node, col, val, etmc->model_data);
134 }
135 
136 static gboolean
137 etmc_is_editable (ETreeModel *etm,
138                   ETreePath node,
139                   gint col)
140 {
141 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
142 
143 	return etmc->is_editable (etm, node, col, etmc->model_data);
144 }
145 
146 /* The default for etmc_duplicate_value is to return the raw value. */
147 static gpointer
148 etmc_duplicate_value (ETreeModel *etm,
149                       gint col,
150                       gconstpointer value)
151 {
152 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
153 
154 	if (etmc->duplicate_value)
155 		return etmc->duplicate_value (etm, col, value, etmc->model_data);
156 	else
157 		return (gpointer) value;
158 }
159 
160 static void
161 etmc_free_value (ETreeModel *etm,
162                  gint col,
163                  gpointer value)
164 {
165 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
166 
167 	if (etmc->free_value)
168 		etmc->free_value (etm, col, value, etmc->model_data);
169 }
170 
171 static gpointer
172 etmc_initialize_value (ETreeModel *etm,
173                        gint col)
174 {
175 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
176 
177 	if (etmc->initialize_value)
178 		return etmc->initialize_value (etm, col, etmc->model_data);
179 	else
180 		return NULL;
181 }
182 
183 static gboolean
184 etmc_value_is_empty (ETreeModel *etm,
185                      gint col,
186                      gconstpointer value)
187 {
188 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
189 
190 	if (etmc->value_is_empty)
191 		return etmc->value_is_empty (etm, col, value, etmc->model_data);
192 	else
193 		return FALSE;
194 }
195 
196 static gchar *
197 etmc_value_to_string (ETreeModel *etm,
198                       gint col,
199                       gconstpointer value)
200 {
201 	ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm);
202 
203 	if (etmc->value_to_string)
204 		return etmc->value_to_string (etm, col, value, etmc->model_data);
205 	else
206 		return g_strdup ("");
207 }
208 
209 static void
210 e_tree_memory_callbacks_class_init (ETreeMemoryCallbacksClass *class)
211 {
212 	ETreeModelClass *model_class        = E_TREE_MODEL_CLASS (class);
213 
214 	model_class->icon_at            = etmc_icon_at;
215 
216 	model_class->column_count       = etmc_column_count;
217 
218 	model_class->has_save_id        = etmc_has_save_id;
219 	model_class->get_save_id        = etmc_get_save_id;
220 
221 	model_class->has_get_node_by_id = etmc_has_get_node_by_id;
222 	model_class->get_node_by_id     = etmc_get_node_by_id;
223 
224 	model_class->sort_value_at	= etmc_sort_value_at;
225 	model_class->value_at           = etmc_value_at;
226 	model_class->set_value_at       = etmc_set_value_at;
227 	model_class->is_editable        = etmc_is_editable;
228 
229 	model_class->duplicate_value    = etmc_duplicate_value;
230 	model_class->free_value         = etmc_free_value;
231 	model_class->initialize_value   = etmc_initialize_value;
232 	model_class->value_is_empty     = etmc_value_is_empty;
233 	model_class->value_to_string    = etmc_value_to_string;
234 }
235 
236 static void
237 e_tree_memory_callbacks_init (ETreeMemoryCallbacks *etmc)
238 {
239 	/* nothing to do */
240 }
241 
242 /**
243  * e_tree_memory_callbacks_new:
244  *
245  * This initializes a new ETreeMemoryCallbacksModel object.
246  * ETreeMemoryCallbacksModel is an implementaiton of the somewhat
247  * abstract class ETreeMemory.  The ETreeMemoryCallbacksModel is
248  * designed to allow people to easily create ETreeMemorys without
249  * having to create a new GType derived from ETreeMemory every time
250  * they need one.
251  *
252  * Instead, ETreeMemoryCallbacksModel uses a setup based in callback functions, every
253  * callback function signature mimics the signature of each ETreeModel method
254  * and passes the extra @data pointer to each one of the method to provide them
255  * with any context they might want to use.
256  *
257  * ETreeMemoryCallbacks is to ETreeMemory as ETableSimple is to ETableModel.
258  *
259  * Return value: An ETreeMemoryCallbacks object (which is also an
260  * ETreeMemory and thus an ETreeModel object).
261  *
262  */
263 ETreeModel *
264 e_tree_memory_callbacks_new (ETreeMemoryCallbacksIconAtFn icon_at,
265 
266                              ETreeMemoryCallbacksColumnCountFn column_count,
267 
268                              ETreeMemoryCallbacksHasSaveIdFn has_save_id,
269                              ETreeMemoryCallbacksGetSaveIdFn get_save_id,
270 
271                              ETreeMemoryCallbacksHasGetNodeByIdFn has_get_node_by_id,
272                              ETreeMemoryCallbacksGetNodeByIdFn get_node_by_id,
273 
274                              ETreeMemoryCallbacksValueAtFn sort_value_at,
275                              ETreeMemoryCallbacksValueAtFn value_at,
276                              ETreeMemoryCallbacksSetValueAtFn set_value_at,
277                              ETreeMemoryCallbacksIsEditableFn is_editable,
278 
279                              ETreeMemoryCallbacksDuplicateValueFn duplicate_value,
280                              ETreeMemoryCallbacksFreeValueFn free_value,
281                              ETreeMemoryCallbacksInitializeValueFn initialize_value,
282                              ETreeMemoryCallbacksValueIsEmptyFn value_is_empty,
283                              ETreeMemoryCallbacksValueToStringFn value_to_string,
284 
285                              gpointer model_data)
286 {
287 	ETreeMemoryCallbacks *etmc;
288 
289 	etmc = g_object_new (E_TYPE_TREE_MEMORY_CALLBACKS, NULL);
290 
291 	etmc->icon_at            = icon_at;
292 
293 	etmc->column_count       = column_count;
294 
295 	etmc->has_save_id        = has_save_id;
296 	etmc->get_save_id        = get_save_id;
297 
298 	etmc->has_get_node_by_id = has_get_node_by_id;
299 	etmc->get_node_by_id     = get_node_by_id;
300 
301 	etmc->sort_value_at	 = sort_value_at;
302 	etmc->value_at           = value_at;
303 	etmc->set_value_at       = set_value_at;
304 	etmc->is_editable        = is_editable;
305 
306 	etmc->duplicate_value    = duplicate_value;
307 	etmc->free_value         = free_value;
308 	etmc->initialize_value   = initialize_value;
309 	etmc->value_is_empty     = value_is_empty;
310 	etmc->value_to_string    = value_to_string;
311 
312 	etmc->model_data         = model_data;
313 
314 	return (ETreeModel *) etmc;
315 }