aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-cal-model-memos.c
blob: 7f05fbee47db6badb950fd0af6767bc010922eac (plain) (blame)
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
268
/*
 * 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; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the 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)

struct _ECalModelMemosPrivate {
    gint dummy;
};

static void e_cal_model_memos_finalize (GObject *object);

static gint ecmm_column_count (ETableModel *etm);
static gpointer ecmm_value_at (ETableModel *etm, gint col, gint row);
static void ecmm_set_value_at (ETableModel *etm, gint col, gint row, gconstpointer value);
static gboolean ecmm_is_cell_editable (ETableModel *etm, gint col, gint row);
static gpointer ecmm_duplicate_value (ETableModel *etm, gint col, gconstpointer value);
static void ecmm_free_value (ETableModel *etm, gint col, gpointer value);
static gpointer ecmm_initialize_value (ETableModel *etm, gint col);
static gboolean ecmm_value_is_empty (ETableModel *etm, gint col, gconstpointer value);
static gchar *ecmm_value_to_string (ETableModel *etm, gint col, gconstpointer value);

static void ecmm_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data,
                        ETableModel *source_model, gint row);

G_DEFINE_TYPE (ECalModelMemos, e_cal_model_memos, E_TYPE_CAL_MODEL)

static void
e_cal_model_memos_class_init (ECalModelMemosClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    ETableModelClass *etm_class = E_TABLE_MODEL_CLASS (klass);
    ECalModelClass *model_class = E_CAL_MODEL_CLASS (klass);

    object_class->finalize = e_cal_model_memos_finalize;

    etm_class->column_count = ecmm_column_count;
    etm_class->value_at = ecmm_value_at;
    etm_class->set_value_at = ecmm_set_value_at;
    etm_class->is_cell_editable = ecmm_is_cell_editable;
    etm_class->duplicate_value = ecmm_duplicate_value;
    etm_class->free_value = ecmm_free_value;
    etm_class->initialize_value = ecmm_initialize_value;
    etm_class->value_is_empty = ecmm_value_is_empty;
    etm_class->value_to_string = ecmm_value_to_string;

    model_class->fill_component_from_model = ecmm_fill_component_from_model;
}

static void
e_cal_model_memos_init (ECalModelMemos *model)
{
    ECalModelMemosPrivate *priv;

    priv = g_new0 (ECalModelMemosPrivate, 1);
    model->priv = priv;

    e_cal_model_set_component_kind (E_CAL_MODEL (model), ICAL_VJOURNAL_COMPONENT);
}

static void
e_cal_model_memos_finalize (GObject *object)
{
    ECalModelMemosPrivate *priv;
    ECalModelMemos *model = (ECalModelMemos *) object;

    g_return_if_fail (E_IS_CAL_MODEL_MEMOS (model));

    priv = model->priv;
    if (priv) {
        g_free (priv);
        model->priv = NULL;
    }

    if (G_OBJECT_CLASS (e_cal_model_memos_parent_class)->finalize)
        G_OBJECT_CLASS (e_cal_model_memos_parent_class)->finalize (object);
}

/* ETableModel methods */
static int
ecmm_column_count (ETableModel *etm)
{
    return E_CAL_MODEL_MEMOS_FIELD_LAST;
}

static gpointer
ecmm_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 E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->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
ecmm_set_value_at (ETableModel *etm, gint col, gint row, gconstpointer value)
{
    ECalModelComponent *comp_data;
    ECalModelMemos *model = (ECalModelMemos *) etm;

    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) {
        E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->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 */
    if (!e_cal_modify_object (comp_data->client, comp_data->icalcomp, CALOBJ_MOD_ALL, NULL)) {
        g_warning (G_STRLOC ": Could not modify the object!");

        /* TODO Show error dialog */
    }
}

static gboolean
ecmm_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 = E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->is_cell_editable (etm, col, row);

    return retval;
}

static gpointer
ecmm_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 E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->duplicate_value (etm, col, value);

    return NULL;
}

static void
ecmm_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) {
        E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->free_value (etm, col, value);
        return;
    }
}

static gpointer
ecmm_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 E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->initialize_value (etm, col);

    return NULL;
}

static gboolean
ecmm_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 E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->value_is_empty (etm, col, value);

    return TRUE;
}

static gchar *
ecmm_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 E_TABLE_MODEL_CLASS (e_cal_model_memos_parent_class)->value_to_string (etm, col, value);

    return g_strdup ("");
}

/* ECalModel class methods */

static void
ecmm_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);
    }

}

/**
 * e_cal_model_memos_new
 */
ECalModel *
e_cal_model_memos_new (void)
{
    return g_object_new (E_TYPE_CAL_MODEL_MEMOS, NULL);
}