evolution-3.6.4/widgets/menus/gal-define-views-model.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found gal-define-views-model.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found gal-define-views-model.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 <libxml/tree.h>
 28 #include <libxml/parser.h>
 29 #include <libxml/xmlmemory.h>
 30 
 31 #include <glib/gi18n.h>
 32 #include "e-util/e-util.h"
 33 
 34 #include "gal-define-views-model.h"
 35 
 36 G_DEFINE_TYPE (GalDefineViewsModel, gal_define_views_model, E_TYPE_TABLE_MODEL)
 37 
 38 enum {
 39 	PROP_0,
 40 	PROP_EDITABLE,
 41 	PROP_COLLECTION
 42 };
 43 
 44 static void
 45 gal_define_views_model_set_property (GObject *object,
 46                                      guint property_id,
 47                                      const GValue *value,
 48                                      GParamSpec *pspec)
 49 {
 50 	GalDefineViewsModel *model;
 51 
 52 	model = GAL_DEFINE_VIEWS_MODEL (object);
 53 
 54 	switch (property_id) {
 55 		case PROP_EDITABLE:
 56 			model->editable = g_value_get_boolean (value);
 57 			return;
 58 
 59 		case PROP_COLLECTION:
 60 			e_table_model_pre_change (E_TABLE_MODEL (object));
 61 			if (g_value_get_object (value))
 62 				model->collection = GAL_VIEW_COLLECTION (
 63 					g_value_get_object (value));
 64 			else
 65 				model->collection = NULL;
 66 			e_table_model_changed (E_TABLE_MODEL (object));
 67 			return;
 68 	}
 69 
 70 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 71 }
 72 
 73 static void
 74 gal_define_views_model_get_property (GObject *object,
 75                                      guint property_id,
 76                                      GValue *value,
 77                                      GParamSpec *pspec)
 78 {
 79 	GalDefineViewsModel *model;
 80 
 81 	model = GAL_DEFINE_VIEWS_MODEL (object);
 82 
 83 	switch (property_id) {
 84 		case PROP_EDITABLE:
 85 			g_value_set_boolean (value, model->editable);
 86 			return;
 87 
 88 		case PROP_COLLECTION:
 89 			g_value_set_object (value, model->collection);
 90 			return;
 91 	}
 92 
 93 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 94 }
 95 
 96 static void
 97 gdvm_dispose (GObject *object)
 98 {
 99 	GalDefineViewsModel *model = GAL_DEFINE_VIEWS_MODEL (object);
100 
101 	if (model->collection)
102 		g_object_unref (model->collection);
103 	model->collection = NULL;
104 
105 	/* Chain up to parent's dispose() method. */
106 	G_OBJECT_CLASS (gal_define_views_model_parent_class)->dispose (object);
107 }
108 
109 /* This function returns the number of columns in our ETableModel. */
110 static gint
111 gdvm_col_count (ETableModel *etc)
112 {
113 	return 1;
114 }
115 
116 /* This function returns the number of rows in our ETableModel. */
117 static gint
118 gdvm_row_count (ETableModel *etc)
119 {
120 	GalDefineViewsModel *views = GAL_DEFINE_VIEWS_MODEL (etc);
121 	if (views->collection)
122 		return gal_view_collection_get_count (views->collection);
123 	else
124 		return 0;
125 }
126 
127 /* This function returns the value at a particular point in our ETableModel. */
128 static gpointer
129 gdvm_value_at (ETableModel *etc,
130                gint col,
131                gint row)
132 {
133 	GalDefineViewsModel *views = GAL_DEFINE_VIEWS_MODEL (etc);
134 	GalView *view;
135 	const gchar *value;
136 
137 	view = gal_view_collection_get_view (views->collection, row);
138 	value = gal_view_get_title (view);
139 
140 	return (gpointer) ((value != NULL) ? value : "");
141 }
142 
143 /* This function sets the value at a particular point in our ETableModel. */
144 static void
145 gdvm_set_value_at (ETableModel *etc,
146                    gint col,
147                    gint row,
148                    gconstpointer val)
149 {
150 	GalDefineViewsModel *views = GAL_DEFINE_VIEWS_MODEL (etc);
151 	if (views->editable) {
152 		GalView *view;
153 
154 		view = gal_view_collection_get_view (views->collection, row);
155 
156 		e_table_model_pre_change (etc);
157 		gal_view_set_title (view, val);
158 		e_table_model_cell_changed (etc, col, row);
159 	}
160 }
161 
162 /* This function returns whether a particular cell is editable. */
163 static gboolean
164 gdvm_is_cell_editable (ETableModel *etc,
165                        gint col,
166                        gint row)
167 {
168 	return GAL_DEFINE_VIEWS_MODEL (etc)->editable;
169 }
170 
171 static void
172 gdvm_append_row (ETableModel *etm,
173                  ETableModel *source,
174                  gint row)
175 {
176 }
177 
178 /* This function duplicates the value passed to it. */
179 static gpointer
180 gdvm_duplicate_value (ETableModel *etc,
181                       gint col,
182                       gconstpointer value)
183 {
184 	return g_strdup (value);
185 }
186 
187 /* This function frees the value passed to it. */
188 static void
189 gdvm_free_value (ETableModel *etc,
190                  gint col,
191                  gpointer value)
192 {
193 	g_free (value);
194 }
195 
196 static gpointer
197 gdvm_initialize_value (ETableModel *etc,
198                        gint col)
199 {
200 	return g_strdup ("");
201 }
202 
203 static gboolean
204 gdvm_value_is_empty (ETableModel *etc,
205                      gint col,
206                      gconstpointer value)
207 {
208 	return !(value && *(gchar *) value);
209 }
210 
211 static gchar *
212 gdvm_value_to_string (ETableModel *etc,
213                       gint col,
214                       gconstpointer value)
215 {
216 	return g_strdup (value);
217 }
218 
219 /**
220  * gal_define_views_model_append
221  * @model: The model to add to.
222  * @view: The view to add.
223  *
224  * Adds the given view to the gal define views model.
225  */
226 void
227 gal_define_views_model_append (GalDefineViewsModel *model,
228                                GalView *view)
229 {
230 	ETableModel *etm = E_TABLE_MODEL (model);
231 
232 	e_table_model_pre_change (etm);
233 	gal_view_collection_append (model->collection, view);
234 	e_table_model_row_inserted (
235 		etm, gal_view_collection_get_count (model->collection) - 1);
236 }
237 
238 static void
239 gal_define_views_model_class_init (GalDefineViewsModelClass *class)
240 {
241 	ETableModelClass *model_class = E_TABLE_MODEL_CLASS (class);
242 	GObjectClass *object_class = G_OBJECT_CLASS (class);
243 
244 	object_class->dispose        = gdvm_dispose;
245 	object_class->set_property   = gal_define_views_model_set_property;
246 	object_class->get_property   = gal_define_views_model_get_property;
247 
248 	g_object_class_install_property (
249 		object_class,
250 		PROP_EDITABLE,
251 		g_param_spec_boolean (
252 			"editable",
253 			"Editable",
254 			NULL,
255 			FALSE,
256 			G_PARAM_READWRITE));
257 
258 	g_object_class_install_property (
259 		object_class,
260 		PROP_COLLECTION,
261 		g_param_spec_object (
262 			"collection",
263 			"Collection",
264 			NULL,
265 			GAL_VIEW_COLLECTION_TYPE,
266 			G_PARAM_READWRITE));
267 
268 	model_class->column_count     = gdvm_col_count;
269 	model_class->row_count        = gdvm_row_count;
270 	model_class->value_at         = gdvm_value_at;
271 	model_class->set_value_at     = gdvm_set_value_at;
272 	model_class->is_cell_editable = gdvm_is_cell_editable;
273 	model_class->append_row       = gdvm_append_row;
274 	model_class->duplicate_value  = gdvm_duplicate_value;
275 	model_class->free_value       = gdvm_free_value;
276 	model_class->initialize_value = gdvm_initialize_value;
277 	model_class->value_is_empty   = gdvm_value_is_empty;
278 	model_class->value_to_string  = gdvm_value_to_string;
279 }
280 
281 static void
282 gal_define_views_model_init (GalDefineViewsModel *model)
283 {
284 	model->collection = NULL;
285 }
286 
287 /**
288  * gal_define_views_model_new
289  *
290  * Returns a new define views model.  This is a list of views as an
291  * ETable for use in the GalDefineViewsDialog.
292  *
293  * Returns: The new GalDefineViewsModel.
294  */
295 ETableModel *
296 gal_define_views_model_new (void)
297 {
298 	GalDefineViewsModel *et;
299 
300 	et = g_object_new (GAL_DEFINE_VIEWS_MODEL_TYPE, NULL);
301 
302 	return E_TABLE_MODEL (et);
303 }
304 
305 /**
306  * gal_define_views_model_get_view:
307  * @model: The GalDefineViewsModel.
308  * @n: Which view to get.
309  *
310  * Gets the nth view.
311  *
312  * Returns: The view.
313  */
314 GalView *
315 gal_define_views_model_get_view (GalDefineViewsModel *model,
316                                  gint n)
317 {
318 	return gal_view_collection_get_view (model->collection, n);
319 }
320 
321 /**
322  * gal_define_views_model_delete_view:
323  * @model: The GalDefineViewsModel.
324  * @n: Which view to delete.
325  *
326  * Deletes the nth view.
327  */
328 void
329 gal_define_views_model_delete_view (GalDefineViewsModel *model,
330                                     gint n)
331 {
332 	e_table_model_pre_change (E_TABLE_MODEL (model));
333 	gal_view_collection_delete_view (model->collection, n);
334 	e_table_model_row_deleted (E_TABLE_MODEL (model), n);
335 }
336 
337 /**
338  * gal_define_views_model_copy_view:
339  * @model: The GalDefineViewsModel.
340  * @n: Which view to copy.
341  *
342  * Copys the nth view.
343  */
344 void
345 gal_define_views_model_copy_view (GalDefineViewsModel *model,
346                                   gint n)
347 {
348 	ETableModel *etm = E_TABLE_MODEL (model);
349 	e_table_model_pre_change (etm);
350 	gal_view_collection_copy_view (model->collection, n);
351 	e_table_model_row_inserted (
352 		etm, gal_view_collection_get_count (model->collection) - 1);
353 }