23
23
#include "calendar.h"
24
24
#include "storage-manager.h"
26
static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
27
static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
28
static void dispose (GObject *object);
27
29
static void almanah_calendar_finalize (GObject *object);
28
30
static void almanah_calendar_month_changed (GtkCalendar *calendar);
29
31
static gchar *almanah_calendar_detail_func (GtkCalendar *calendar, guint year, guint month, guint day, gpointer user_data);
31
33
static void entry_removed_cb (AlmanahStorageManager *storage_manager, GDate *date, AlmanahCalendar *calendar);
33
35
struct _AlmanahCalendarPrivate {
36
AlmanahStorageManager *storage_manager;
37
gulong entry_added_signal;
38
gulong entry_removed_signal;
34
40
gboolean *important_days;
44
PROP_STORAGE_MANAGER = 1,
37
47
G_DEFINE_TYPE (AlmanahCalendar, almanah_calendar, GTK_TYPE_CALENDAR)
45
55
g_type_class_add_private (klass, sizeof (AlmanahCalendarPrivate));
57
gobject_class->get_property = get_property;
58
gobject_class->set_property = set_property;
59
gobject_class->dispose = dispose;
47
60
gobject_class->finalize = almanah_calendar_finalize;
49
62
calendar_class->month_changed = almanah_calendar_month_changed;
64
g_object_class_install_property (gobject_class, PROP_STORAGE_MANAGER,
65
g_param_spec_object ("storage-manager",
66
"Storage manager", "The storage manager whose entries should be listed.",
67
ALMANAH_TYPE_STORAGE_MANAGER,
68
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
55
74
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_CALENDAR, AlmanahCalendarPrivate);
56
75
gtk_calendar_set_detail_func (GTK_CALENDAR (self), almanah_calendar_detail_func, NULL, NULL);
58
/* Connect to signals from the storage manager so we can mark/unmark days as appropriate */
59
g_signal_connect (almanah->storage_manager, "entry-added", G_CALLBACK (entry_added_cb), self);
60
g_signal_connect (almanah->storage_manager, "entry-removed", G_CALLBACK (entry_removed_cb), self);
79
dispose (GObject *object)
81
AlmanahCalendarPrivate *priv = ALMANAH_CALENDAR (object)->priv;
83
if (priv->storage_manager != NULL)
84
g_object_unref (priv->storage_manager);
85
priv->storage_manager = NULL;
87
/* Chain up to the parent class */
88
G_OBJECT_CLASS (almanah_calendar_parent_class)->dispose (object);
103
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
105
AlmanahCalendarPrivate *priv = ALMANAH_CALENDAR (object)->priv;
107
switch (property_id) {
108
case PROP_STORAGE_MANAGER:
109
g_value_set_object (value, priv->storage_manager);
112
/* We don't have any other property... */
113
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
119
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
121
AlmanahCalendar *self = ALMANAH_CALENDAR (object);
123
switch (property_id) {
124
case PROP_STORAGE_MANAGER:
125
almanah_calendar_set_storage_manager (self, g_value_get_object (value));
128
/* We don't have any other property... */
129
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
75
135
almanah_calendar_month_changed (GtkCalendar *calendar)
77
137
AlmanahCalendarPrivate *priv = ALMANAH_CALENDAR (calendar)->priv;
81
141
/* Mark the days on the calendar which have diary entries */
82
142
gtk_calendar_get_date (calendar, &year, &month, NULL);
84
days = almanah_storage_manager_get_month_marked_days (almanah->storage_manager, year, month, &num_days);
144
days = almanah_storage_manager_get_month_marked_days (priv->storage_manager, year, month, &num_days);
86
146
gtk_calendar_clear_marks (calendar);
87
147
for (i = 0; i < num_days; i++) {
96
156
/* Cache the days which are important, so that the detail function isn't hideously slow */
97
157
g_free (priv->important_days);
98
priv->important_days = almanah_storage_manager_get_month_important_days (almanah->storage_manager, year, month, &num_days);
158
priv->important_days = almanah_storage_manager_get_month_important_days (priv->storage_manager, year, month, &num_days);
150
almanah_calendar_new (void)
152
return g_object_new (ALMANAH_TYPE_CALENDAR, NULL);
210
almanah_calendar_new (AlmanahStorageManager *storage_manager)
212
g_return_val_if_fail (ALMANAH_IS_STORAGE_MANAGER (storage_manager), NULL);
213
return g_object_new (ALMANAH_TYPE_CALENDAR, "storage-manager", storage_manager, NULL);
216
AlmanahStorageManager *
217
almanah_calendar_get_storage_manager (AlmanahCalendar *self)
219
g_return_val_if_fail (ALMANAH_IS_CALENDAR (self), NULL);
220
return self->priv->storage_manager;
224
almanah_calendar_set_storage_manager (AlmanahCalendar *self, AlmanahStorageManager *storage_manager)
226
AlmanahCalendarPrivate *priv = self->priv;
228
g_return_if_fail (ALMANAH_IS_CALENDAR (self));
229
g_return_if_fail (storage_manager == NULL || ALMANAH_IS_STORAGE_MANAGER (storage_manager));
231
if (priv->storage_manager != NULL) {
232
g_signal_handler_disconnect (priv->storage_manager, priv->entry_added_signal);
233
g_signal_handler_disconnect (priv->storage_manager, priv->entry_removed_signal);
235
g_object_unref (priv->storage_manager);
238
priv->storage_manager = storage_manager;
240
if (priv->storage_manager != NULL) {
241
g_object_ref (priv->storage_manager);
243
/* Connect to signals from the storage manager so we can mark/unmark days as appropriate */
244
priv->entry_added_signal = g_signal_connect (priv->storage_manager, "entry-added", (GCallback) entry_added_cb, self);
245
priv->entry_removed_signal = g_signal_connect (priv->storage_manager, "entry-removed", (GCallback) entry_removed_cb, self);