~ubuntu-branches/ubuntu/wily/alarm-clock-applet/wily

« back to all changes in this revision

Viewing changes to src/alarm.h

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-05-30 23:24:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090530232427-88on1j2ily4ajxdz
Tags: upstream-0.2.6
ImportĀ upstreamĀ versionĀ 0.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * alarm.h -- Core alarm functionality
 
3
 *
 
4
 * Copyright (C) 2007-2008 Johannes H. Jensen <joh@pseudoberries.com>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 * Authors:
 
21
 *              Johannes H. Jensen <joh@pseudoberries.com>
 
22
 */
 
23
 
 
24
#ifndef ALARM_H_
 
25
#define ALARM_H_
 
26
 
 
27
#include <glib-object.h>
 
28
#include <gconf/gconf-client.h>
 
29
 
 
30
#include "player.h"
 
31
 
 
32
G_BEGIN_DECLS
 
33
 
 
34
/*
 
35
 * Utility macros
 
36
 */
 
37
 
 
38
#define TYPE_ALARM (alarm_get_type())
 
39
 
 
40
#define ALARM(object) \
 
41
  (G_TYPE_CHECK_INSTANCE_CAST((object), TYPE_ALARM, Alarm))
 
42
 
 
43
#define ALARM_CLASS(klass) \
 
44
  (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_ALARM, AlarmClass))
 
45
 
 
46
#define IS_ALARM(object) \
 
47
  (G_TYPE_CHECK_INSTANCE_TYPE((object), TYPE_ALARM))
 
48
 
 
49
#define IS_ALARM_CLASS(klass) \
 
50
  (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_ALARM))
 
51
 
 
52
#define ALARM_GET_CLASS(object) \
 
53
  (G_TYPE_INSTANCE_GET_CLASS((object), TYPE_ALARM, AlarmClass))
 
54
 
 
55
/*
 
56
 * Structure definitions
 
57
 */
 
58
 
 
59
typedef enum {
 
60
        ALARM_TYPE_INVALID = 0,
 
61
        ALARM_TYPE_CLOCK,               /* Alarm at specific time */
 
62
        ALARM_TYPE_TIMER                /* Alarm in X mins */
 
63
} AlarmType;
 
64
 
 
65
typedef enum {
 
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,
 
74
} AlarmRepeat;
 
75
 
 
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)
 
79
 
 
80
typedef enum {
 
81
        ALARM_NOTIFY_INVALID = 0,
 
82
        ALARM_NOTIFY_SOUND,             /* Notification by sound */
 
83
        ALARM_NOTIFY_COMMAND,   /* Notification by command */
 
84
} AlarmNotifyType;
 
85
 
 
86
typedef struct _Alarm Alarm;
 
87
typedef struct _AlarmClass AlarmClass;
 
88
 
 
89
struct _Alarm {
 
90
        GObject parent;
 
91
 
 
92
        gchar *gconf_dir;               /* GConf directory */
 
93
        gint id;                                /* Alarm ID */
 
94
 
 
95
        /* GConf mapped values */
 
96
        AlarmType type;
 
97
        time_t time;                    /* Time for alarm */
 
98
        time_t timestamp;               /* UNIX timestamp (local time) for running alarms */
 
99
        gboolean active;
 
100
        gchar *message;
 
101
        AlarmRepeat repeat;
 
102
        gint snooze;
 
103
 
 
104
        AlarmNotifyType notify_type;
 
105
        gchar *sound_file;
 
106
        gboolean sound_loop;
 
107
        gchar *command;
 
108
        gboolean notify_bubble;
 
109
};
 
110
 
 
111
struct _AlarmClass {
 
112
        GObjectClass parent;
 
113
 
 
114
        /* Signals */
 
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 */
 
118
};
 
119
 
 
120
/*
 
121
 * Error codes
 
122
 */
 
123
#define ALARM_ERROR             alarm_error_quark ()
 
124
 
 
125
typedef enum {
 
126
        ALARM_ERROR_NONE,
 
127
        ALARM_ERROR_PLAY,               /* Error playing sound */
 
128
        ALARM_ERROR_COMMAND             /* Error launching command */
 
129
} AlarmErrorCode;
 
130
 
 
131
 
 
132
/*
 
133
 * Failsafe defaults for the GConf-mapped properties for
 
134
 * use when the schema isn't found or doesn't provide
 
135
 * sensible defaults.
 
136
 */
 
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
 
149
 
 
150
/*
 
151
 * GConf settings
 
152
 */
 
153
#define ALARM_GCONF_DIR_PREFIX          "alarm"
 
154
#define ALARM_GCONF_SCHEMA_DIR          "/schemas/apps/alarm_clock/alarm"
 
155
 
 
156
/*
 
157
 * Player backoff timeout.
 
158
 * We will stop the player automatically after 20 minutes.
 
159
 */
 
160
#define ALARM_SOUND_TIMEOUT                     (60 * 20)
 
161
 
 
162
/*
 
163
 * Function prototypes.
 
164
 */
 
165
 
 
166
/* used by ALARM_TYPE */
 
167
GType
 
168
alarm_get_type (void);
 
169
 
 
170
Alarm *
 
171
alarm_new (const gchar *gconf_dir, gint id);
 
172
 
 
173
guint
 
174
alarm_gen_id_dir (const gchar *gconf_dir);
 
175
 
 
176
guint
 
177
alarm_gen_id (Alarm *alarm);
 
178
 
 
179
gchar *
 
180
alarm_gconf_get_dir (Alarm *alarm);
 
181
 
 
182
gint
 
183
alarm_gconf_dir_get_id (const gchar *dir);
 
184
 
 
185
gchar *
 
186
alarm_gconf_get_full_key (Alarm *alarm, const gchar *key);
 
187
 
 
188
 
 
189
const gchar *
 
190
alarm_type_to_string (AlarmType type);
 
191
 
 
192
AlarmType
 
193
alarm_type_from_string (const gchar *type);
 
194
 
 
195
 
 
196
const gchar *
 
197
alarm_notify_type_to_string (AlarmNotifyType type);
 
198
 
 
199
AlarmNotifyType
 
200
alarm_notify_type_from_string (const gchar *type);
 
201
 
 
202
GList *
 
203
alarm_get_list (const gchar *gconf_dir);
 
204
 
 
205
void
 
206
alarm_signal_connect_list (GList *instances,
 
207
                                                   const gchar *detailed_signal,
 
208
                                                   GCallback c_handler,
 
209
                                                   gpointer data);
 
210
 
 
211
void
 
212
alarm_trigger (Alarm *alarm);
 
213
 
 
214
void
 
215
alarm_set_enabled (Alarm *alarm, gboolean enabled);
 
216
 
 
217
void
 
218
alarm_enable (Alarm *alarm);
 
219
 
 
220
void
 
221
alarm_clear (Alarm *alarm);
 
222
 
 
223
void
 
224
alarm_disable (Alarm *alarm);
 
225
 
 
226
void
 
227
alarm_delete (Alarm *alarm);
 
228
 
 
229
void
 
230
alarm_snooze (Alarm *alarm);
 
231
 
 
232
void
 
233
alarm_set_time (Alarm *alarm, guint hour, guint minute, guint second);
 
234
 
 
235
void
 
236
alarm_update_timestamp (Alarm *alarm);
 
237
 
 
238
void
 
239
alarm_update_timestamp_full (Alarm *alarm, gboolean include_today);
 
240
 
 
241
GQuark
 
242
alarm_error_quark (void);
 
243
 
 
244
void
 
245
alarm_error_trigger (Alarm *alarm, AlarmErrorCode code, const gchar *msg);
 
246
 
 
247
struct tm *
 
248
alarm_get_time (Alarm *alarm);
 
249
 
 
250
struct tm *
 
251
alarm_get_remain (Alarm *alarm);
 
252
 
 
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);
 
259
 
 
260
G_END_DECLS
 
261
 
 
262
#endif /*ALARM_H_*/