4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
20 * SECTION: e-source-alarms
21 * @include: libedataserver/e-source-alarms.h
22 * @short_description: #ESource extension for alarm state
24 * The #ESourceAlarms extension tracks alarm state for a calendar.
26 * Access the extension as follows:
29 * #include <libedataserver/e-source-alarms.h>
31 * ESourceAlarms *extension;
33 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_ALARMS);
37 #include "e-source-alarms.h"
39 #define E_SOURCE_ALARMS_GET_PRIVATE(obj) \
40 (G_TYPE_INSTANCE_GET_PRIVATE \
41 ((obj), E_TYPE_SOURCE_ALARMS, ESourceAlarmsPrivate))
43 struct _ESourceAlarmsPrivate {
44 GMutex *property_lock;
58 E_TYPE_SOURCE_EXTENSION)
61 source_alarms_set_property (GObject *object,
66 switch (property_id) {
68 e_source_alarms_set_include_me (
69 E_SOURCE_ALARMS (object),
70 g_value_get_boolean (value));
73 case PROP_LAST_NOTIFIED:
74 e_source_alarms_set_last_notified (
75 E_SOURCE_ALARMS (object),
76 g_value_get_string (value));
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
84 source_alarms_get_property (GObject *object,
89 switch (property_id) {
93 e_source_alarms_get_include_me (
94 E_SOURCE_ALARMS (object)));
97 case PROP_LAST_NOTIFIED:
100 e_source_alarms_dup_last_notified (
101 E_SOURCE_ALARMS (object)));
105 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
109 source_alarms_finalize (GObject *object)
111 ESourceAlarmsPrivate *priv;
113 priv = E_SOURCE_ALARMS_GET_PRIVATE (object);
115 g_mutex_free (priv->property_lock);
117 g_free (priv->last_notified);
119 /* Chain up to parent's finalize() method. */
120 G_OBJECT_CLASS (e_source_alarms_parent_class)->finalize (object);
124 e_source_alarms_class_init (ESourceAlarmsClass *class)
126 GObjectClass *object_class;
127 ESourceExtensionClass *extension_class;
129 g_type_class_add_private (class, sizeof (ESourceAlarmsPrivate));
131 object_class = G_OBJECT_CLASS (class);
132 object_class->set_property = source_alarms_set_property;
133 object_class->get_property = source_alarms_get_property;
134 object_class->finalize = source_alarms_finalize;
136 extension_class = E_SOURCE_EXTENSION_CLASS (class);
137 extension_class->name = E_SOURCE_EXTENSION_ALARMS;
139 g_object_class_install_property (
142 g_param_spec_boolean (
145 "Include this source in alarm notifications",
149 G_PARAM_STATIC_STRINGS |
150 E_SOURCE_PARAM_SETTING));
152 g_object_class_install_property (
155 g_param_spec_string (
158 "Last alarm notification (in ISO 8601 format)",
162 G_PARAM_STATIC_STRINGS |
163 E_SOURCE_PARAM_SETTING));
167 e_source_alarms_init (ESourceAlarms *extension)
169 extension->priv = E_SOURCE_ALARMS_GET_PRIVATE (extension);
170 extension->priv->property_lock = g_mutex_new ();
174 * e_source_alarms_get_include_me:
175 * @extension: an #ESourceAlarms
177 * Returns whether the user should be alerted about upcoming appointments
178 * in the calendar described by the #ESource to which @extension belongs.
180 * Alarm daemons such as evolution-alarm-notify can use this property to
181 * decide which calendars to query for upcoming appointments.
183 * Returns: whether to show alarms for upcoming appointments
188 e_source_alarms_get_include_me (ESourceAlarms *extension)
190 g_return_val_if_fail (E_IS_SOURCE_ALARMS (extension), FALSE);
192 return extension->priv->include_me;
196 * e_source_alarms_set_include_me:
197 * @extension: an #ESourceAlarms
198 * @include_me: whether to show alarms for upcoming appointments
200 * Sets whether the user should be alerted about upcoming appointments in
201 * the calendar described by the #ESource to which @extension belongs.
203 * Alarm daemons such as evolution-alarm-notify can use this property to
204 * decide which calendars to query for upcoming appointments.
209 e_source_alarms_set_include_me (ESourceAlarms *extension,
212 g_return_if_fail (E_IS_SOURCE_ALARMS (extension));
214 extension->priv->include_me = include_me;
216 g_object_notify (G_OBJECT (extension), "include-me");
220 * e_source_alarms_get_last_notified:
221 * @extension: an #ESourceAlarms
223 * Returns an ISO 8601 formatted timestamp of when the user was last
224 * alerted about an upcoming appointment in the calendar described by
225 * the #ESource to which @extension belongs. If no valid timestamp
226 * has been set, the function will return %NULL.
228 * Returns: an ISO 8601 timestamp, or %NULL
233 e_source_alarms_get_last_notified (ESourceAlarms *extension)
235 g_return_val_if_fail (E_IS_SOURCE_ALARMS (extension), NULL);
237 return extension->priv->last_notified;
241 * e_source_alarms_dup_last_notified:
242 * @extension: an #ESourceAlarms
244 * Thread-safe variation of e_source_alarms_get_last_notified().
245 * Use this function when accessing @extension from multiple threads.
247 * The returned string should be freed with g_free() when no longer needed.
249 * Returns: a newly-allocated copy of #ESourceAlarms:last-notified
254 e_source_alarms_dup_last_notified (ESourceAlarms *extension)
256 const gchar *protected;
259 g_return_val_if_fail (E_IS_SOURCE_ALARMS (extension), NULL);
261 g_mutex_lock (extension->priv->property_lock);
263 protected = e_source_alarms_get_last_notified (extension);
264 duplicate = g_strdup (protected);
266 g_mutex_unlock (extension->priv->property_lock);
272 * e_source_alarms_set_last_notified:
273 * @extension: an #ESourceAlarms
274 * @last_notified: (allow-none): an ISO 8601 timestamp, or %NULL
276 * Sets an ISO 8601 formatted timestamp of when the user was last
277 * alerted about an upcoming appointment in the calendar described
278 * by the #ESource to which @extension belongs.
280 * If @last_notified is non-%NULL, the function will validate the
281 * timestamp before setting the #ESourceAlarms:last-notified property.
282 * Invalid timestamps are discarded with a runtime warning.
284 * Generally, this function should only be called by an alarm daemon
285 * such as evolution-alarm-notify.
290 e_source_alarms_set_last_notified (ESourceAlarms *extension,
291 const gchar *last_notified)
293 g_return_if_fail (E_IS_SOURCE_ALARMS (extension));
295 if (last_notified != NULL) {
298 if (!g_time_val_from_iso8601 (last_notified, &time_val)) {
299 g_warning ("Invalid timestamp: %s", last_notified);
304 g_mutex_lock (extension->priv->property_lock);
306 g_free (extension->priv->last_notified);
307 extension->priv->last_notified = g_strdup (last_notified);
309 g_mutex_unlock (extension->priv->property_lock);
311 g_object_notify (G_OBJECT (extension), "last-notified");