~ps-jenkins/indicator-datetime/latestsnapshot-13.10.0+13.10.20131023.2-0ubuntu1

« back to all changes in this revision

Viewing changes to src/planner-mock.c

  • Committer: Tarmac
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2013-10-22 22:35:31 UTC
  • mfrom: (278.1.1 indicator-datetime)
  • Revision ID: tarmac-20131022223531-rn7zr7smbnlki2ak
Revert revision 277 which appears to be more feature than bugfix applicable for SRU.

Approved by PS Jenkins bot, Ted Gould.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2013 Canonical Ltd.
3
 
 *
4
 
 * Authors:
5
 
 *   Charles Kerr <charles.kerr@canonical.com>
6
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
 
22
 
#include "planner-mock.h"
23
 
 
24
 
struct _IndicatorDatetimePlannerMockPriv
25
 
{
26
 
  gboolean is_configured;
27
 
};
28
 
 
29
 
typedef IndicatorDatetimePlannerMockPriv priv_t;
30
 
 
31
 
G_DEFINE_TYPE (IndicatorDatetimePlannerMock,
32
 
               indicator_datetime_planner_mock,
33
 
               INDICATOR_TYPE_DATETIME_PLANNER)
34
 
 
35
 
/***
36
 
****  IndicatorDatetimePlanner virtual funcs
37
 
***/
38
 
 
39
 
static void
40
 
my_get_appointments (IndicatorDatetimePlanner  * planner,
41
 
                     GDateTime                 * begin_datetime,
42
 
                     GDateTime                 * end_datetime    G_GNUC_UNUSED,
43
 
                     GAsyncReadyCallback         callback,
44
 
                     gpointer                    user_data)
45
 
{
46
 
  GTask * task;
47
 
  GSList * appointments;
48
 
  struct IndicatorDatetimeAppt * appt;
49
 
  struct IndicatorDatetimeAppt * prev;
50
 
 
51
 
  task = g_task_new (planner, NULL, callback, user_data);
52
 
 
53
 
  /**
54
 
  ***  Build the appointments list
55
 
  **/
56
 
 
57
 
  appointments = NULL;
58
 
 
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);
71
 
  prev = appt;
72
 
 
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);
84
 
 
85
 
  /* done */
86
 
  g_task_return_pointer (task, appointments, NULL);
87
 
  g_object_unref (task);
88
 
}
89
 
 
90
 
static GSList *
91
 
my_get_appointments_finish (IndicatorDatetimePlanner  * self  G_GNUC_UNUSED,
92
 
                            GAsyncResult              * res,
93
 
                            GError                   ** error)
94
 
{
95
 
  return g_task_propagate_pointer (G_TASK(res), error);
96
 
}
97
 
 
98
 
static gboolean
99
 
my_is_configured (IndicatorDatetimePlanner * planner)
100
 
{
101
 
  IndicatorDatetimePlannerMock * self;
102
 
  self = INDICATOR_DATETIME_PLANNER_MOCK (planner);
103
 
  return self->priv->is_configured;
104
 
}
105
 
 
106
 
static void
107
 
my_activate (IndicatorDatetimePlanner * self G_GNUC_UNUSED)
108
 
{
109
 
  g_message ("%s %s", G_STRLOC, G_STRFUNC);
110
 
}
111
 
 
112
 
static void
113
 
my_activate_time (IndicatorDatetimePlanner * self G_GNUC_UNUSED,
114
 
                  GDateTime                * activate_time)
115
 
{
116
 
  gchar * str = g_date_time_format (activate_time, "%F %T");
117
 
  g_message ("%s %s: %s", G_STRLOC, G_STRFUNC, str);
118
 
  g_free (str);
119
 
}
120
 
 
121
 
/***
122
 
****  GObject virtual funcs
123
 
***/
124
 
 
125
 
static void
126
 
my_dispose (GObject * o)
127
 
{
128
 
  G_OBJECT_CLASS (indicator_datetime_planner_mock_parent_class)->dispose (o);
129
 
}
130
 
 
131
 
/***
132
 
****  Instantiation
133
 
***/
134
 
 
135
 
static void
136
 
indicator_datetime_planner_mock_class_init (IndicatorDatetimePlannerMockClass * klass)
137
 
{
138
 
  GObjectClass * object_class;
139
 
  IndicatorDatetimePlannerClass * planner_class;
140
 
 
141
 
  object_class = G_OBJECT_CLASS (klass);
142
 
  object_class->dispose = my_dispose;
143
 
 
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;
150
 
 
151
 
  g_type_class_add_private (klass, sizeof (IndicatorDatetimePlannerMockPriv));
152
 
}
153
 
 
154
 
static void
155
 
indicator_datetime_planner_mock_init (IndicatorDatetimePlannerMock * self)
156
 
{
157
 
  priv_t * p;
158
 
 
159
 
  p = G_TYPE_INSTANCE_GET_PRIVATE (self,
160
 
                                   INDICATOR_TYPE_DATETIME_PLANNER_MOCK,
161
 
                                   IndicatorDatetimePlannerMockPriv);
162
 
 
163
 
  p->is_configured = TRUE;
164
 
 
165
 
  self->priv = p;
166
 
}
167
 
 
168
 
/***
169
 
****  Public
170
 
***/
171
 
 
172
 
IndicatorDatetimePlanner *
173
 
indicator_datetime_planner_mock_new (void)
174
 
{
175
 
  gpointer o = g_object_new (INDICATOR_TYPE_DATETIME_PLANNER_MOCK, NULL);
176
 
 
177
 
  return INDICATOR_DATETIME_PLANNER (o);
178
 
}