~ubuntu-branches/ubuntu/wily/almanah/wily-proposed

« back to all changes in this revision

Viewing changes to src/widgets/calendar.c

  • Committer: Package Import Robot
  • Author(s): Angel Abad
  • Date: 2012-10-29 10:14:18 UTC
  • mfrom: (1.4.1) (10.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20121029101418-k2c27xb0aku22zeg
Tags: 0.10.0-1~exp1
* Imported Upstream version 0.10.0
* debian/control:
  - Bump evolution Build-Depends ( >=3.6.0)
  - debian/control: Depends on evolution-common (>= 3.6.0)
* Bump Standards-Version to 3.9.4 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "calendar.h"
24
24
#include "storage-manager.h"
25
 
#include "main.h"
26
25
 
 
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);
32
34
 
33
35
struct _AlmanahCalendarPrivate {
 
36
        AlmanahStorageManager *storage_manager;
 
37
        gulong entry_added_signal;
 
38
        gulong entry_removed_signal;
 
39
 
34
40
        gboolean *important_days;
35
41
};
36
42
 
 
43
enum {
 
44
        PROP_STORAGE_MANAGER = 1,
 
45
};
 
46
 
37
47
G_DEFINE_TYPE (AlmanahCalendar, almanah_calendar, GTK_TYPE_CALENDAR)
38
48
 
39
49
static void
44
54
 
45
55
        g_type_class_add_private (klass, sizeof (AlmanahCalendarPrivate));
46
56
 
 
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;
48
61
 
49
62
        calendar_class->month_changed = almanah_calendar_month_changed;
 
63
 
 
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));
50
69
}
51
70
 
52
71
static void
54
73
{
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);
57
 
 
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);
 
76
}
 
77
 
 
78
static void
 
79
dispose (GObject *object)
 
80
{
 
81
        AlmanahCalendarPrivate *priv = ALMANAH_CALENDAR (object)->priv;
 
82
 
 
83
        if (priv->storage_manager != NULL)
 
84
                g_object_unref (priv->storage_manager);
 
85
        priv->storage_manager = NULL;
 
86
 
 
87
        /* Chain up to the parent class */
 
88
        G_OBJECT_CLASS (almanah_calendar_parent_class)->dispose (object);
61
89
}
62
90
 
63
91
static void
72
100
}
73
101
 
74
102
static void
 
103
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 
104
{
 
105
        AlmanahCalendarPrivate *priv = ALMANAH_CALENDAR (object)->priv;
 
106
 
 
107
        switch (property_id) {
 
108
                case PROP_STORAGE_MANAGER:
 
109
                        g_value_set_object (value, priv->storage_manager);
 
110
                        break;
 
111
                default:
 
112
                        /* We don't have any other property... */
 
113
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
114
                        break;
 
115
        }
 
116
}
 
117
 
 
118
static void
 
119
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 
120
{
 
121
        AlmanahCalendar *self = ALMANAH_CALENDAR (object);
 
122
 
 
123
        switch (property_id) {
 
124
                case PROP_STORAGE_MANAGER:
 
125
                        almanah_calendar_set_storage_manager (self, g_value_get_object (value));
 
126
                        break;
 
127
                default:
 
128
                        /* We don't have any other property... */
 
129
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
130
                        break;
 
131
        }
 
132
}
 
133
 
 
134
static void
75
135
almanah_calendar_month_changed (GtkCalendar *calendar)
76
136
{
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);
83
143
        month++;
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);
85
145
 
86
146
        gtk_calendar_clear_marks (calendar);
87
147
        for (i = 0; i < num_days; i++) {
95
155
 
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);
99
159
}
100
160
 
101
161
static gchar *
147
207
}
148
208
 
149
209
GtkWidget *
150
 
almanah_calendar_new (void)
151
 
{
152
 
        return g_object_new (ALMANAH_TYPE_CALENDAR, NULL);
 
210
almanah_calendar_new (AlmanahStorageManager *storage_manager)
 
211
{
 
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);
 
214
}
 
215
 
 
216
AlmanahStorageManager *
 
217
almanah_calendar_get_storage_manager (AlmanahCalendar *self)
 
218
{
 
219
        g_return_val_if_fail (ALMANAH_IS_CALENDAR (self), NULL);
 
220
        return self->priv->storage_manager;
 
221
}
 
222
 
 
223
void
 
224
almanah_calendar_set_storage_manager (AlmanahCalendar *self, AlmanahStorageManager *storage_manager)
 
225
{
 
226
        AlmanahCalendarPrivate *priv = self->priv;
 
227
 
 
228
        g_return_if_fail (ALMANAH_IS_CALENDAR (self));
 
229
        g_return_if_fail (storage_manager == NULL || ALMANAH_IS_STORAGE_MANAGER (storage_manager));
 
230
 
 
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);
 
234
 
 
235
                g_object_unref (priv->storage_manager);
 
236
        }
 
237
 
 
238
        priv->storage_manager = storage_manager;
 
239
 
 
240
        if (priv->storage_manager != NULL) {
 
241
                g_object_ref (priv->storage_manager);
 
242
 
 
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);
 
246
        }
153
247
}
154
248
 
155
249
void