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