35 #include <glib-object.h>
36 #include "gnc-dense-cal.h"
37 #include "gnc-dense-cal-model.h"
38 #include "gnc-dense-cal-store.h"
39 #include "Recurrence.h"
47 gdcs_end_type end_type;
59 GObjectClass parent_class;
62 static GObjectClass *parent_class = NULL;
66 static void gnc_dense_cal_store_finalize(GObject *obj);
68 static GList* gdcs_get_contained(GncDenseCalModel *model);
69 static gchar* gdcs_get_name(GncDenseCalModel *model, guint tag);
70 static gchar* gdcs_get_info(GncDenseCalModel *model, guint tag);
71 static gint gdcs_get_instance_count(GncDenseCalModel *model, guint tag);
72 static void gdcs_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
77 GObjectClass *object_class = G_OBJECT_CLASS(klass);
78 parent_class = g_type_class_peek_parent(klass);
80 object_class->finalize = gnc_dense_cal_store_finalize;
84 gnc_dense_cal_store_iface_init(gpointer g_iface, gpointer iface_data)
87 iface->get_contained = gdcs_get_contained;
88 iface->get_name = gdcs_get_name;
89 iface->get_info = gdcs_get_info;
90 iface->get_instance_count = gdcs_get_instance_count;
91 iface->get_instance = gdcs_get_instance;
95 gnc_dense_cal_store_get_type(
void)
97 static GType type = 0;
100 static const GTypeInfo info =
105 (GClassInitFunc)gnc_dense_cal_store_class_init,
112 static const GInterfaceInfo iDenseCalModelInfo =
114 (GInterfaceInitFunc)gnc_dense_cal_store_iface_init,
118 type = g_type_register_static(G_TYPE_OBJECT,
"GncDenseCalStore", &info, 0);
119 g_type_add_interface_static(type,
120 GNC_TYPE_DENSE_CAL_MODEL,
121 &iDenseCalModelInfo);
127 gnc_dense_cal_store_new(
int num_marks)
130 model->num_marks = num_marks;
131 model->cal_marks = g_new0(GDate*, num_marks);
134 for (i = 0; i < model->num_marks; i++)
136 model->cal_marks[i] = g_date_new();
139 model->num_real_marks = 0;
140 g_date_clear(&model->start_date, 1);
142 model->end_type = NEVER_END;
143 g_date_clear(&model->end_date, 1);
145 model->n_occurrences = 0;
152 model->num_real_marks = 0;
153 g_signal_emit_by_name(model,
"update", GUINT_TO_POINTER(1));
159 if (model->name != NULL)
163 model->name = g_strdup(name);
170 if (model->info != NULL)
174 model->info = g_strdup(info);
179 gdcs_generic_update_recurrences(
GncDenseCalStore *trans, GDate *start, GList *recurrences)
187 g_date_subtract_days(&date, 1);
188 recurrenceListNextInstance(recurrences, &date, &next);
191 while ((i < trans->num_marks)
192 && g_date_valid(&next)
194 && ((trans->end_type == NEVER_END)
195 || (trans->end_type == END_ON_DATE
196 && g_date_compare(&next, &trans->end_date) <= 0)
197 || (trans->end_type == END_AFTER_N_OCCS
198 && i < trans->n_occurrences)))
200 *trans->cal_marks[i++] = next;
202 recurrenceListNextInstance(recurrences, &date, &next);
204 trans->num_real_marks = i;
210 g_signal_emit_by_name(trans,
"update", GUINT_TO_POINTER(1));
214 gnc_dense_cal_store_update_recurrences_no_end(
GncDenseCalStore *model, GDate *start, GList *recurrences)
216 model->end_type = NEVER_END;
217 gdcs_generic_update_recurrences(model, start, recurrences);
221 gnc_dense_cal_store_update_recurrences_count_end(
GncDenseCalStore *model, GDate *start, GList *recurrences,
int num_occur)
223 model->end_type = END_AFTER_N_OCCS;
224 model->n_occurrences = num_occur;
225 gdcs_generic_update_recurrences(model, start, recurrences);
229 gnc_dense_cal_store_update_recurrences_date_end(
GncDenseCalStore *model, GDate *start, GList *recurrences, GDate *end_date)
231 model->end_type = END_ON_DATE;
232 model->end_date = *end_date;
233 gdcs_generic_update_recurrences(model, start, recurrences);
237 gdcs_get_contained(GncDenseCalModel *model)
240 rtn = g_list_append(rtn, GUINT_TO_POINTER(1));
245 gdcs_get_name(GncDenseCalModel *model, guint tag)
253 gdcs_get_info(GncDenseCalModel *model, guint tag)
257 return g_strdup(mdl->info);
261 gdcs_get_instance_count(GncDenseCalModel *model, guint tag)
265 return mdl->num_real_marks;
269 gdcs_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date)
274 *date = *mdl->cal_marks[instance_index];
278 gnc_dense_cal_store_finalize(GObject *obj)
282 g_return_if_fail(obj != NULL);
284 store = GNC_DENSE_CAL_STORE(obj);
286 if (store->name != NULL)
292 if (store->info != NULL)
298 for (i = 0; i < store->num_marks; i++)
300 g_free(store->cal_marks[i]);
301 store->cal_marks[i] = NULL;
303 if (store->cal_marks != NULL)
305 g_free(store->cal_marks);
306 store->cal_marks = NULL;
309 G_OBJECT_CLASS(parent_class)->finalize(obj);
void gnc_gdate_set_today(GDate *gd)