evolution-3.6.4/calendar/gui/e-cal-model-memos.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-cal-model-memos.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-cal-model-memos.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  * Evolution memos - Data model for ETable
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  *
 18  * Authors:
 19  *		Rodrigo Moya <rodrigo@ximian.com>
 20  *      Nathan Owens <pianocomp81@yahoo.com>
 21  *
 22  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 23  *
 24  */
 25 
 26 #ifdef HAVE_CONFIG_H
 27 #include <config.h>
 28 #endif
 29 
 30 #include <string.h>
 31 #include <glib/gi18n.h>
 32 #include "e-cal-model-memos.h"
 33 #include "e-cell-date-edit-text.h"
 34 #include "misc.h"
 35 
 36 #define d(x) (x)
 37 
 38 static gint ecmm_column_count (ETableModel *etm);
 39 static gpointer ecmm_value_at (ETableModel *etm, gint col, gint row);
 40 static void ecmm_set_value_at (ETableModel *etm, gint col, gint row, gconstpointer value);
 41 static gboolean ecmm_is_cell_editable (ETableModel *etm, gint col, gint row);
 42 static gpointer ecmm_duplicate_value (ETableModel *etm, gint col, gconstpointer value);
 43 static void ecmm_free_value (ETableModel *etm, gint col, gpointer value);
 44 static gpointer ecmm_initialize_value (ETableModel *etm, gint col);
 45 static gboolean ecmm_value_is_empty (ETableModel *etm, gint col, gconstpointer value);
 46 static gchar *ecmm_value_to_string (ETableModel *etm, gint col, gconstpointer value);
 47 
 48 static void ecmm_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data,
 49 					    ETableModel *source_model, gint row);
 50 
 51 G_DEFINE_TYPE (ECalModelMemos, e_cal_model_memos, E_TYPE_CAL_MODEL)
 52 
 53 static void
 54 e_cal_model_memos_class_init (ECalModelMemosClass *class)
 55 {
 56 	ETableModelClass *etm_class = E_TABLE_MODEL_CLASS (class);
 57 	ECalModelClass *model_class = E_CAL_MODEL_CLASS (class);
 58 
 59 	etm_class->column_count = ecmm_column_count;
 60 	etm_class->value_at = ecmm_value_at;
 61 	etm_class->set_value_at = ecmm_set_value_at;
 62 	etm_class->is_cell_editable = ecmm_is_cell_editable;
 63 	etm_class->duplicate_value = ecmm_duplicate_value;
 64 	etm_class->free_value = ecmm_free_value;
 65 	etm_class->initialize_value = ecmm_initialize_value;
 66 	etm_class->value_is_empty = ecmm_value_is_empty;
 67 	etm_class->value_to_string = ecmm_value_to_string;
 68 
 69 	model_class->fill_component_from_model = ecmm_fill_component_from_model;
 70 }
 71 
 72 static void
 73 e_cal_model_memos_init (ECalModelMemos *model)
 74 {
 75 	e_cal_model_set_component_kind (E_CAL_MODEL (model), ICAL_VJOURNAL_COMPONENT);
 76 }
 77 
 78 /* ETableModel methods */
 79 static gint
 80 ecmm_column_count (ETableModel *etm)
 81 {
 82 	return E_CAL_MODEL_MEMOS_FIELD_LAST;
 83 }
 84 
 85 static gpointer
 86 ecmm_value_at (ETableModel *etm,
 87                gint col,
 88                gint row)
 89 {
 90 	ECalModelComponent *comp_data;
 91 	ECalModelMemos *model = (ECalModelMemos *) etm;
 92 
 93 	g_return_val_if_fail (E_IS_CAL_MODEL_MEMOS (model), NULL);
 94 
 95 	g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_MEMOS_FIELD_LAST, NULL);
 96 	g_return_val_if_fail (row >= 0 && row < e_table_model_row_count (etm), NULL);
 97 
 98 	if (col < E_CAL_MODEL_FIELD_LAST)
 99 		return E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->value_at (etm, col, row);
100 
101 	comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), row);
102 	if (!comp_data)
103 		return (gpointer) "";
104 
105 	return (gpointer) "";
106 }
107 
108 static void
109 ecmm_set_value_at (ETableModel *etm,
110                    gint col,
111                    gint row,
112                    gconstpointer value)
113 {
114 	ECalModelComponent *comp_data;
115 	ECalModelMemos *model = (ECalModelMemos *) etm;
116 	GError *error = NULL;
117 
118 	g_return_if_fail (E_IS_CAL_MODEL_MEMOS (model));
119 	g_return_if_fail (col >= 0 && col < E_CAL_MODEL_MEMOS_FIELD_LAST);
120 	g_return_if_fail (row >= 0 && row < e_table_model_row_count (etm));
121 
122 	if (col < E_CAL_MODEL_FIELD_LAST) {
123 		E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->set_value_at (etm, col, row, value);
124 		return;
125 	}
126 
127 	comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), row);
128 	if (!comp_data) {
129 		g_warning ("couldn't get component data: row == %d", row);
130 		return;
131 	}
132 
133 	/* TODO ask about mod type */
134 	e_cal_client_modify_object_sync (
135 		comp_data->client, comp_data->icalcomp,
136 		CALOBJ_MOD_ALL, NULL, &error);
137 
138 	if (error != NULL) {
139 		g_warning (
140 			G_STRLOC ": Could not modify the object! %s",
141 			error->message);
142 
143 		/* TODO Show error dialog */
144 		g_error_free (error);
145 	}
146 }
147 
148 static gboolean
149 ecmm_is_cell_editable (ETableModel *etm,
150                        gint col,
151                        gint row)
152 {
153 	ECalModelMemos *model = (ECalModelMemos *) etm;
154 	gboolean retval = FALSE;
155 
156 	g_return_val_if_fail (E_IS_CAL_MODEL_MEMOS (model), FALSE);
157 	g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_MEMOS_FIELD_LAST, FALSE);
158 	g_return_val_if_fail (row >= -1 || (row >= 0 && row < e_table_model_row_count (etm)), FALSE);
159 
160 	if (!e_cal_model_test_row_editable (E_CAL_MODEL (etm), row))
161 		return FALSE;
162 
163 	if (col < E_CAL_MODEL_FIELD_LAST)
164 		retval = E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->is_cell_editable (etm, col, row);
165 
166 	return retval;
167 }
168 
169 static gpointer
170 ecmm_duplicate_value (ETableModel *etm,
171                       gint col,
172                       gconstpointer value)
173 {
174 	g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_MEMOS_FIELD_LAST, NULL);
175 
176 	if (col < E_CAL_MODEL_FIELD_LAST)
177 		return E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->duplicate_value (etm, col, value);
178 
179 	return NULL;
180 }
181 
182 static void
183 ecmm_free_value (ETableModel *etm,
184                  gint col,
185                  gpointer value)
186 {
187 	g_return_if_fail (col >= 0 && col < E_CAL_MODEL_MEMOS_FIELD_LAST);
188 
189 	if (col < E_CAL_MODEL_FIELD_LAST) {
190 		E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->free_value (etm, col, value);
191 		return;
192 	}
193 }
194 
195 static gpointer
196 ecmm_initialize_value (ETableModel *etm,
197                        gint col)
198 {
199 	g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_MEMOS_FIELD_LAST, NULL);
200 
201 	if (col < E_CAL_MODEL_FIELD_LAST)
202 		return E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->initialize_value (etm, col);
203 
204 	return NULL;
205 }
206 
207 static gboolean
208 ecmm_value_is_empty (ETableModel *etm,
209                      gint col,
210                      gconstpointer value)
211 {
212 	g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_MEMOS_FIELD_LAST, TRUE);
213 
214 	if (col < E_CAL_MODEL_FIELD_LAST)
215 		return E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->value_is_empty (etm, col, value);
216 
217 	return TRUE;
218 }
219 
220 static gchar *
221 ecmm_value_to_string (ETableModel *etm,
222                       gint col,
223                       gconstpointer value)
224 {
225 	g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_MEMOS_FIELD_LAST, g_strdup (""));
226 
227 	if (col < E_CAL_MODEL_FIELD_LAST)
228 		return E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->value_to_string (etm, col, value);
229 
230 	return g_strdup ("");
231 }
232 
233 /* ECalModel class methods */
234 
235 static void
236 ecmm_fill_component_from_model (ECalModel *model,
237                                 ECalModelComponent *comp_data,
238                                 ETableModel *source_model,
239                                 gint row)
240 {
241 	icaltimetype start;
242 	g_return_if_fail (E_IS_CAL_MODEL_MEMOS (model));
243 	g_return_if_fail (comp_data != NULL);
244 	g_return_if_fail (E_IS_TABLE_MODEL (source_model));
245 
246 	start = icalcomponent_get_dtstart (comp_data->icalcomp);
247 	if (icaltime_compare_date_only (start, icaltime_null_time ()) == 0) {
248 		start = icaltime_today ();
249 		icalcomponent_set_dtstart (comp_data->icalcomp, start);
250 	}
251 
252 }
253 
254 /**
255  * e_cal_model_memos_new
256  */
257 ECalModel *
258 e_cal_model_memos_new (ESourceRegistry *registry)
259 {
260 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
261 
262 	return g_object_new (
263 		E_TYPE_CAL_MODEL_MEMOS,
264 		"registry", registry, NULL);
265 }