36 #include <glib-object.h> 38 #include "gnc-dense-cal.h" 39 #include "gnc-dense-cal-model.h" 40 #include "gnc-dense-cal-store.h" 41 #include "Recurrence.h" 48 gdcs_end_type end_type;
58 static void gnc_dense_cal_store_iface_init (GncDenseCalModelInterface *iface);
59 static void gnc_dense_cal_store_finalize (GObject *obj);
61 static GList* gdcs_get_contained (GncDenseCalModel *model);
62 static gchar* gdcs_get_name (GncDenseCalModel *model, guint tag);
63 static gchar* gdcs_get_info (GncDenseCalModel *model, guint tag);
64 static gint gdcs_get_instance_count (GncDenseCalModel *model, guint tag);
65 static void gdcs_get_instance (GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
68 G_IMPLEMENT_INTERFACE(GNC_TYPE_DENSE_CAL_MODEL, gnc_dense_cal_store_iface_init))
71 gnc_dense_cal_store_class_init (GncDenseCalStoreClass *klass)
73 GObjectClass *object_class = G_OBJECT_CLASS(klass);
75 object_class->finalize = gnc_dense_cal_store_finalize;
79 gnc_dense_cal_store_init (GncDenseCalStore *
self)
84 gnc_dense_cal_store_iface_init (GncDenseCalModelInterface *iface)
86 iface->get_contained = gdcs_get_contained;
87 iface->get_name = gdcs_get_name;
88 iface->get_info = gdcs_get_info;
89 iface->get_instance_count = gdcs_get_instance_count;
90 iface->get_instance = gdcs_get_instance;
94 gnc_dense_cal_store_new (
int num_marks)
96 GncDenseCalStore *model = g_object_new (GNC_TYPE_DENSE_CAL_STORE, NULL);
97 model->num_marks = num_marks;
98 model->cal_marks = g_new0 (GDate*, num_marks);
100 for (
int i = 0; i < model->num_marks; i++)
102 model->cal_marks[i] = g_date_new();
105 model->num_real_marks = 0;
106 g_date_clear (&model->start_date, 1);
108 model->end_type = NEVER_END;
109 g_date_clear (&model->end_date, 1);
111 model->n_occurrences = 0;
116 gnc_dense_cal_store_clear (GncDenseCalStore *model)
118 model->num_real_marks = 0;
119 g_signal_emit_by_name (model,
"update", GUINT_TO_POINTER(1));
123 gnc_dense_cal_store_update_name (GncDenseCalStore *model,
const gchar *name)
125 if (model->name != NULL)
126 g_free (model->name);
128 model->name = g_strdup (name);
133 gnc_dense_cal_store_update_info (GncDenseCalStore *model,
const gchar *info)
135 if (model->info != NULL)
136 g_free (model->info);
138 model->info = g_strdup (info);
143 gdcs_generic_update_recurrences (GncDenseCalStore *trans, GDate *start, GList *recurrences)
149 recurrenceListNextInstance (recurrences, &date, &next);
151 while ((i < trans->num_marks)
152 && g_date_valid (&next)
154 && ((trans->end_type == NEVER_END)
155 || (trans->end_type == END_ON_DATE
156 && g_date_compare (&next, &trans->end_date) <= 0)
157 || (trans->end_type == END_AFTER_N_OCCS
158 && i < trans->n_occurrences)))
160 *trans->cal_marks[i++] = next;
162 recurrenceListNextInstance (recurrences, &date, &next);
164 trans->num_real_marks = i;
170 g_signal_emit_by_name (trans,
"update", GUINT_TO_POINTER(1));
174 gnc_dense_cal_store_update_recurrences_no_end (GncDenseCalStore *model,
178 model->end_type = NEVER_END;
179 gdcs_generic_update_recurrences (model, start, recurrences);
183 gnc_dense_cal_store_update_recurrences_count_end (GncDenseCalStore *model,
188 model->end_type = END_AFTER_N_OCCS;
189 model->n_occurrences = num_occur;
190 gdcs_generic_update_recurrences (model, start, recurrences);
194 gnc_dense_cal_store_update_recurrences_date_end (GncDenseCalStore *model,
199 model->end_type = END_ON_DATE;
200 model->end_date = *end_date;
201 gdcs_generic_update_recurrences (model, start, recurrences);
205 gdcs_get_contained (GncDenseCalModel *model)
208 rtn = g_list_append (rtn, GUINT_TO_POINTER(1));
213 gdcs_get_name (GncDenseCalModel *model, guint tag)
215 GncDenseCalStore *mdl = GNC_DENSE_CAL_STORE(model);
221 gdcs_get_info (GncDenseCalModel *model, guint tag)
223 GncDenseCalStore *mdl = GNC_DENSE_CAL_STORE(model);
225 return g_strdup (mdl->info);
229 gdcs_get_instance_count (GncDenseCalModel *model, guint tag)
231 GncDenseCalStore *mdl = GNC_DENSE_CAL_STORE(model);
233 return mdl->num_real_marks;
237 gdcs_get_instance (GncDenseCalModel *model, guint tag, gint instance_index, GDate *date)
239 GncDenseCalStore *mdl = GNC_DENSE_CAL_STORE(model);
242 *date = *mdl->cal_marks[instance_index];
246 gnc_dense_cal_store_finalize (GObject *obj)
248 GncDenseCalStore *store;
249 g_return_if_fail (obj != NULL);
251 store = GNC_DENSE_CAL_STORE(obj);
253 if (store->name != NULL)
255 g_free (store->name);
259 if (store->info != NULL)
261 g_free (store->info);
265 for (
int i = 0; i < store->num_marks; i++)
267 g_free (store->cal_marks[i]);
268 store->cal_marks[i] = NULL;
270 if (store->cal_marks != NULL)
272 g_free (store->cal_marks);
273 store->cal_marks = NULL;
276 G_OBJECT_CLASS(gnc_dense_cal_store_parent_class)->finalize (obj);
Date and Time handling routines.
void gnc_gdate_set_today(GDate *gd)
Set a GDate to the current day.
G_DEFINE_TYPE_WITH_CODE(GncMainWindow, gnc_main_window, GTK_TYPE_APPLICATION_WINDOW, G_IMPLEMENT_INTERFACE(GNC_TYPE_WINDOW, gnc_window_main_window_init)) static guint main_window_signals[LAST_SIGNAL]
A holding place for all the signals generated by the main window code.