2
* Copyright 2013 Canonical Ltd.
5
* Charles Kerr <charles.kerr@canonical.com>
7
* This program is free software: you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 3, as published
9
* by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranties of
13
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
* PURPOSE. See the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "planner-mock.h"
24
struct _IndicatorDatetimePlannerMockPriv
26
gboolean is_configured;
29
typedef IndicatorDatetimePlannerMockPriv priv_t;
31
G_DEFINE_TYPE (IndicatorDatetimePlannerMock,
32
indicator_datetime_planner_mock,
33
INDICATOR_TYPE_DATETIME_PLANNER)
36
**** IndicatorDatetimePlanner virtual funcs
40
my_get_appointments (IndicatorDatetimePlanner * planner,
41
GDateTime * begin_datetime,
42
GDateTime * end_datetime G_GNUC_UNUSED,
43
GAsyncReadyCallback callback,
47
GSList * appointments;
48
struct IndicatorDatetimeAppt * appt;
49
struct IndicatorDatetimeAppt * prev;
51
task = g_task_new (planner, NULL, callback, user_data);
54
*** Build the appointments list
59
/* add a daily appointment that occurs at the beginning of the next minute */
60
appt = g_slice_new0 (struct IndicatorDatetimeAppt);
61
appt->is_daily = TRUE;
62
appt->begin = g_date_time_add_seconds (begin_datetime, 60-g_date_time_get_seconds(begin_datetime));
63
appt->end = g_date_time_add_minutes (appt->begin, 1);
64
appt->color = g_strdup ("#00FF00");
65
appt->is_event = TRUE;
66
appt->summary = g_strdup ("Daily alarm");
67
appt->uid = g_strdup ("this uid isn't very random.");
68
appt->has_alarms = TRUE;
69
appt->url = g_strdup ("alarm:///some-alarm-info-goes-here");
70
appointments = g_slist_prepend (appointments, appt);
73
/* and add one for a minute later that has an alarm uri */
74
appt = g_slice_new0 (struct IndicatorDatetimeAppt);
75
appt->is_daily = TRUE;
76
appt->begin = g_date_time_add_minutes (prev->end, 1);
77
appt->end = g_date_time_add_minutes (appt->begin, 1);
78
appt->color = g_strdup ("#0000FF");
79
appt->is_event = TRUE;
80
appt->summary = g_strdup ("Second Daily alarm");
81
appt->uid = g_strdup ("this uid isn't very random either.");
82
appt->has_alarms = FALSE;
83
appointments = g_slist_prepend (appointments, appt);
86
g_task_return_pointer (task, appointments, NULL);
87
g_object_unref (task);
91
my_get_appointments_finish (IndicatorDatetimePlanner * self G_GNUC_UNUSED,
95
return g_task_propagate_pointer (G_TASK(res), error);
99
my_is_configured (IndicatorDatetimePlanner * planner)
101
IndicatorDatetimePlannerMock * self;
102
self = INDICATOR_DATETIME_PLANNER_MOCK (planner);
103
return self->priv->is_configured;
107
my_activate (IndicatorDatetimePlanner * self G_GNUC_UNUSED)
109
g_message ("%s %s", G_STRLOC, G_STRFUNC);
113
my_activate_time (IndicatorDatetimePlanner * self G_GNUC_UNUSED,
114
GDateTime * activate_time)
116
gchar * str = g_date_time_format (activate_time, "%F %T");
117
g_message ("%s %s: %s", G_STRLOC, G_STRFUNC, str);
122
**** GObject virtual funcs
126
my_dispose (GObject * o)
128
G_OBJECT_CLASS (indicator_datetime_planner_mock_parent_class)->dispose (o);
136
indicator_datetime_planner_mock_class_init (IndicatorDatetimePlannerMockClass * klass)
138
GObjectClass * object_class;
139
IndicatorDatetimePlannerClass * planner_class;
141
object_class = G_OBJECT_CLASS (klass);
142
object_class->dispose = my_dispose;
144
planner_class = INDICATOR_DATETIME_PLANNER_CLASS (klass);
145
planner_class->is_configured = my_is_configured;
146
planner_class->activate = my_activate;
147
planner_class->activate_time = my_activate_time;
148
planner_class->get_appointments = my_get_appointments;
149
planner_class->get_appointments_finish = my_get_appointments_finish;
151
g_type_class_add_private (klass, sizeof (IndicatorDatetimePlannerMockPriv));
155
indicator_datetime_planner_mock_init (IndicatorDatetimePlannerMock * self)
159
p = G_TYPE_INSTANCE_GET_PRIVATE (self,
160
INDICATOR_TYPE_DATETIME_PLANNER_MOCK,
161
IndicatorDatetimePlannerMockPriv);
163
p->is_configured = TRUE;
172
IndicatorDatetimePlanner *
173
indicator_datetime_planner_mock_new (void)
175
gpointer o = g_object_new (INDICATOR_TYPE_DATETIME_PLANNER_MOCK, NULL);
177
return INDICATOR_DATETIME_PLANNER (o);