2
* alarm.h -- Core alarm functionality
4
* Copyright (C) 2007-2008 Johannes H. Jensen <joh@pseudoberries.com>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* Johannes H. Jensen <joh@pseudoberries.com>
27
#include <glib-object.h>
28
#include <gconf/gconf-client.h>
38
#define TYPE_ALARM (alarm_get_type())
40
#define ALARM(object) \
41
(G_TYPE_CHECK_INSTANCE_CAST((object), TYPE_ALARM, Alarm))
43
#define ALARM_CLASS(klass) \
44
(G_TYPE_CHECK_CLASS_CAST((klass), TYPE_ALARM, AlarmClass))
46
#define IS_ALARM(object) \
47
(G_TYPE_CHECK_INSTANCE_TYPE((object), TYPE_ALARM))
49
#define IS_ALARM_CLASS(klass) \
50
(G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_ALARM))
52
#define ALARM_GET_CLASS(object) \
53
(G_TYPE_INSTANCE_GET_CLASS((object), TYPE_ALARM, AlarmClass))
56
* Structure definitions
60
ALARM_TYPE_INVALID = 0,
61
ALARM_TYPE_CLOCK, /* Alarm at specific time */
62
ALARM_TYPE_TIMER /* Alarm in X mins */
66
ALARM_REPEAT_NONE = 0,
67
ALARM_REPEAT_SUN = 1 << 0,
68
ALARM_REPEAT_MON = 1 << 1,
69
ALARM_REPEAT_TUE = 1 << 2,
70
ALARM_REPEAT_WED = 1 << 3,
71
ALARM_REPEAT_THU = 1 << 4,
72
ALARM_REPEAT_FRI = 1 << 5,
73
ALARM_REPEAT_SAT = 1 << 6,
76
#define ALARM_REPEAT_WEEKDAYS (ALARM_REPEAT_MON | ALARM_REPEAT_TUE | ALARM_REPEAT_WED | ALARM_REPEAT_THU | ALARM_REPEAT_FRI)
77
#define ALARM_REPEAT_WEEKENDS (ALARM_REPEAT_SAT | ALARM_REPEAT_SUN)
78
#define ALARM_REPEAT_ALL (ALARM_REPEAT_WEEKDAYS | ALARM_REPEAT_WEEKENDS)
81
ALARM_NOTIFY_INVALID = 0,
82
ALARM_NOTIFY_SOUND, /* Notification by sound */
83
ALARM_NOTIFY_COMMAND, /* Notification by command */
86
typedef struct _Alarm Alarm;
87
typedef struct _AlarmClass AlarmClass;
92
gchar *gconf_dir; /* GConf directory */
93
gint id; /* Alarm ID */
95
/* GConf mapped values */
97
time_t time; /* Time for alarm */
98
time_t timestamp; /* UNIX timestamp (local time) for running alarms */
104
AlarmNotifyType notify_type;
108
gboolean notify_bubble;
115
void (*alarm)(Alarm *alarm); /* Alarm triggered! */
116
void (*error)(Alarm *alarm, GError *err); /* An error occured */
117
void (*player_changed)(Alarm *alarm, MediaPlayerState state); /* Media player state changed */
123
#define ALARM_ERROR alarm_error_quark ()
127
ALARM_ERROR_PLAY, /* Error playing sound */
128
ALARM_ERROR_COMMAND /* Error launching command */
133
* Failsafe defaults for the GConf-mapped properties for
134
* use when the schema isn't found or doesn't provide
137
#define ALARM_DEFAULT_TYPE ALARM_TYPE_CLOCK
138
#define ALARM_DEFAULT_TIME 0
139
#define ALARM_DEFAULT_TIMESTAMP 0
140
#define ALARM_DEFAULT_ACTIVE FALSE
141
#define ALARM_DEFAULT_MESSAGE "Alarm!"
142
#define ALARM_DEFAULT_REPEAT ALARM_REPEAT_NONE
143
#define ALARM_DEFAULT_SNOOZE 0
144
#define ALARM_DEFAULT_NOTIFY_TYPE ALARM_NOTIFY_SOUND
145
#define ALARM_DEFAULT_SOUND_FILE "" // Should default to first in stock sound list
146
#define ALARM_DEFAULT_SOUND_LOOP TRUE
147
#define ALARM_DEFAULT_COMMAND "" // Should default to first in app list
148
#define ALARM_DEFAULT_NOTIFY_BUBBLE TRUE
153
#define ALARM_GCONF_DIR_PREFIX "alarm"
154
#define ALARM_GCONF_SCHEMA_DIR "/schemas/apps/alarm_clock/alarm"
157
* Player backoff timeout.
158
* We will stop the player automatically after 20 minutes.
160
#define ALARM_SOUND_TIMEOUT (60 * 20)
163
* Function prototypes.
166
/* used by ALARM_TYPE */
168
alarm_get_type (void);
171
alarm_new (const gchar *gconf_dir, gint id);
174
alarm_gen_id_dir (const gchar *gconf_dir);
177
alarm_gen_id (Alarm *alarm);
180
alarm_gconf_get_dir (Alarm *alarm);
183
alarm_gconf_dir_get_id (const gchar *dir);
186
alarm_gconf_get_full_key (Alarm *alarm, const gchar *key);
190
alarm_type_to_string (AlarmType type);
193
alarm_type_from_string (const gchar *type);
197
alarm_notify_type_to_string (AlarmNotifyType type);
200
alarm_notify_type_from_string (const gchar *type);
203
alarm_get_list (const gchar *gconf_dir);
206
alarm_signal_connect_list (GList *instances,
207
const gchar *detailed_signal,
212
alarm_trigger (Alarm *alarm);
215
alarm_set_enabled (Alarm *alarm, gboolean enabled);
218
alarm_enable (Alarm *alarm);
221
alarm_clear (Alarm *alarm);
224
alarm_disable (Alarm *alarm);
227
alarm_delete (Alarm *alarm);
230
alarm_snooze (Alarm *alarm);
233
alarm_set_time (Alarm *alarm, guint hour, guint minute, guint second);
236
alarm_update_timestamp (Alarm *alarm);
239
alarm_update_timestamp_full (Alarm *alarm, gboolean include_today);
242
alarm_error_quark (void);
245
alarm_error_trigger (Alarm *alarm, AlarmErrorCode code, const gchar *msg);
248
alarm_get_time (Alarm *alarm);
251
alarm_get_remain (Alarm *alarm);
253
const gchar *alarm_repeat_to_string (AlarmRepeat repeat);
254
AlarmRepeat alarm_repeat_from_string (const gchar *str);
255
AlarmRepeat alarm_repeat_from_list (GSList *list);
256
GSList *alarm_repeat_to_list (AlarmRepeat repeat);
257
gint alarm_wday_distance (gint wday1, gint wday2);
258
gboolean alarm_should_repeat (Alarm *alarm);