4 * This library is free software you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * SECTION: e-source-alarms
20 * @include: libedataserver/libedataserver.h
21 * @short_description: #ESource extension for alarm state
23 * The #ESourceAlarms extension tracks alarm state for a calendar.
25 * Access the extension as follows:
28 * #include <libedataserver/libedataserver.h>
30 * ESourceAlarms *extension;
32 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_ALARMS);
36 #include "e-source-alarms.h"
38 #define E_SOURCE_ALARMS_GET_PRIVATE(obj) \
39 (G_TYPE_INSTANCE_GET_PRIVATE \
40 ((obj), E_TYPE_SOURCE_ALARMS, ESourceAlarmsPrivate))
42 struct _ESourceAlarmsPrivate {
57 E_TYPE_SOURCE_EXTENSION)
60 source_alarms_set_property (GObject *object,
65 switch (property_id) {
67 e_source_alarms_set_include_me (
68 E_SOURCE_ALARMS (object),
69 g_value_get_boolean (value));
72 case PROP_LAST_NOTIFIED:
73 e_source_alarms_set_last_notified (
74 E_SOURCE_ALARMS (object),
75 g_value_get_string (value));
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
83 source_alarms_get_property (GObject *object,
88 switch (property_id) {
92 e_source_alarms_get_include_me (
93 E_SOURCE_ALARMS (object)));
96 case PROP_LAST_NOTIFIED:
99 e_source_alarms_dup_last_notified (
100 E_SOURCE_ALARMS (object)));
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108 source_alarms_finalize (GObject *object)
110 ESourceAlarmsPrivate *priv;
112 priv = E_SOURCE_ALARMS_GET_PRIVATE (object);
114 g_mutex_clear (&priv->property_lock);
116 g_free (priv->last_notified);
118 /* Chain up to parent's finalize() method. */
119 G_OBJECT_CLASS (e_source_alarms_parent_class)->finalize (object);
123 e_source_alarms_class_init (ESourceAlarmsClass *class)
125 GObjectClass *object_class;
126 ESourceExtensionClass *extension_class;
128 g_type_class_add_private (class, sizeof (ESourceAlarmsPrivate));
130 object_class = G_OBJECT_CLASS (class);
131 object_class->set_property = source_alarms_set_property;
132 object_class->get_property = source_alarms_get_property;
133 object_class->finalize = source_alarms_finalize;
135 extension_class = E_SOURCE_EXTENSION_CLASS (class);
136 extension_class->name = E_SOURCE_EXTENSION_ALARMS;
138 g_object_class_install_property (
141 g_param_spec_boolean (
144 "Include this source in alarm notifications",
148 G_PARAM_STATIC_STRINGS |
149 E_SOURCE_PARAM_SETTING));
151 g_object_class_install_property (
154 g_param_spec_string (
157 "Last alarm notification (in ISO 8601 format)",
161 G_PARAM_STATIC_STRINGS |
162 E_SOURCE_PARAM_SETTING));
166 e_source_alarms_init (ESourceAlarms *extension)
168 extension->priv = E_SOURCE_ALARMS_GET_PRIVATE (extension);
169 g_mutex_init (&extension->priv->property_lock);
173 * e_source_alarms_get_include_me:
174 * @extension: an #ESourceAlarms
176 * Returns whether the user should be alerted about upcoming appointments
177 * in the calendar described by the #ESource to which @extension belongs.
179 * Alarm daemons such as evolution-alarm-notify can use this property to
180 * decide which calendars to query for upcoming appointments.
182 * Returns: whether to show alarms for upcoming appointments
187 e_source_alarms_get_include_me (ESourceAlarms *extension)
189 g_return_val_if_fail (E_IS_SOURCE_ALARMS (extension), FALSE);
191 return extension->priv->include_me;
195 * e_source_alarms_set_include_me:
196 * @extension: an #ESourceAlarms
197 * @include_me: whether to show alarms for upcoming appointments
199 * Sets whether the user should be alerted about upcoming appointments in
200 * the calendar described by the #ESource to which @extension belongs.
202 * Alarm daemons such as evolution-alarm-notify can use this property to
203 * decide which calendars to query for upcoming appointments.
208 e_source_alarms_set_include_me (ESourceAlarms *extension,
211 g_return_if_fail (E_IS_SOURCE_ALARMS (extension));
213 if (extension->priv->include_me == include_me)
216 extension->priv->include_me = include_me;
218 g_object_notify (G_OBJECT (extension), "include-me");
222 * e_source_alarms_get_last_notified:
223 * @extension: an #ESourceAlarms
225 * Returns an ISO 8601 formatted timestamp of when the user was last
226 * alerted about an upcoming appointment in the calendar described by
227 * the #ESource to which @extension belongs. If no valid timestamp
228 * has been set, the function will return %NULL.
230 * Returns: an ISO 8601 timestamp, or %NULL
235 e_source_alarms_get_last_notified (ESourceAlarms *extension)
237 g_return_val_if_fail (E_IS_SOURCE_ALARMS (extension), NULL);
239 return extension->priv->last_notified;
243 * e_source_alarms_dup_last_notified:
244 * @extension: an #ESourceAlarms
246 * Thread-safe variation of e_source_alarms_get_last_notified().
247 * Use this function when accessing @extension from multiple threads.
249 * The returned string should be freed with g_free() when no longer needed.
251 * Returns: a newly-allocated copy of #ESourceAlarms:last-notified
256 e_source_alarms_dup_last_notified (ESourceAlarms *extension)
258 const gchar *protected;
261 g_return_val_if_fail (E_IS_SOURCE_ALARMS (extension), NULL);
263 g_mutex_lock (&extension->priv->property_lock);
265 protected = e_source_alarms_get_last_notified (extension);
266 duplicate = g_strdup (protected);
268 g_mutex_unlock (&extension->priv->property_lock);
274 * e_source_alarms_set_last_notified:
275 * @extension: an #ESourceAlarms
276 * @last_notified: (allow-none): an ISO 8601 timestamp, or %NULL
278 * Sets an ISO 8601 formatted timestamp of when the user was last
279 * alerted about an upcoming appointment in the calendar described
280 * by the #ESource to which @extension belongs.
282 * If @last_notified is non-%NULL, the function will validate the
283 * timestamp before setting the #ESourceAlarms:last-notified property.
284 * Invalid timestamps are discarded with a runtime warning.
286 * Generally, this function should only be called by an alarm daemon
287 * such as evolution-alarm-notify.
292 e_source_alarms_set_last_notified (ESourceAlarms *extension,
293 const gchar *last_notified)
295 g_return_if_fail (E_IS_SOURCE_ALARMS (extension));
297 if (last_notified && !*last_notified)
298 last_notified = NULL;
300 if (last_notified != NULL) {
303 if (!g_time_val_from_iso8601 (last_notified, &time_val)) {
305 "%s: Invalid timestamp: '%s'",
306 G_STRFUNC, last_notified);
311 g_mutex_lock (&extension->priv->property_lock);
313 if (g_strcmp0 (extension->priv->last_notified, last_notified) == 0) {
314 g_mutex_unlock (&extension->priv->property_lock);
318 g_free (extension->priv->last_notified);
319 extension->priv->last_notified = g_strdup (last_notified);
321 g_mutex_unlock (&extension->priv->property_lock);
323 g_object_notify (G_OBJECT (extension), "last-notified");