if a proxy is set, pre-fill the proxy setting dialog with the old value.
[Rockbox.git] / apps / alarm_menu.c
blob83ca65304b9ebe6690df583e7083326bdbd36fb7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2003 Uwe Freese
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
21 #ifdef HAVE_RTC_ALARM
23 #include <stdbool.h>
25 #include "lcd.h"
26 #include "action.h"
27 #include "kernel.h"
28 #include "sprintf.h"
29 #include <string.h>
30 #include "settings.h"
31 #include "power.h"
32 #include "icons.h"
33 #include "rtc.h"
34 #include "misc.h"
35 #include "screens.h"
37 #include "lang.h"
38 #include "power.h"
39 #include "alarm_menu.h"
40 #include "backlight.h"
42 #include "splash.h"
43 #include "statusbar.h"
44 #include "textarea.h"
46 bool alarm_screen(void)
48 int h, m;
49 bool done=false;
50 char buf[32];
51 struct tm *tm;
52 int togo;
53 int button;
54 int i;
55 bool update = true;
58 rtc_get_alarm(&h, &m);
60 /* After a battery change the RTC values are out of range */
61 if (m > 60 || h > 24) {
62 m = 0;
63 h = 12;
64 } else {
65 m = m / 5 * 5; /* 5 min accuracy should be enough */
68 while(!done) {
69 if(update)
71 FOR_NB_SCREENS(i)
73 screens[i].setmargins(0, 0);
74 gui_textarea_clear(&screens[i]);
75 screens[i].puts(0, 3, str(LANG_ALARM_MOD_KEYS));
77 update = false;
80 snprintf(buf, 32, str(LANG_ALARM_MOD_TIME), h, m);
81 FOR_NB_SCREENS(i)
83 screens[i].puts(0, 1, buf);
84 gui_textarea_update(&screens[i]);
86 button = get_action(CONTEXT_SETTINGS,HZ);
88 switch(button) {
89 case ACTION_STD_OK:
90 /* prevent that an alarm occurs in the shutdown procedure */
91 /* accept alarms only if they are in 2 minutes or more */
92 tm = get_time();
93 togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
94 if (togo > 1) {
95 rtc_init();
96 rtc_set_alarm(h,m);
97 rtc_enable_alarm(true);
98 gui_syncsplash(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
99 togo / 60, togo % 60);
100 done = true;
101 } else {
102 gui_syncsplash(HZ, str(LANG_ALARM_MOD_ERROR));
103 update = true;
105 break;
107 /* inc(m) */
108 case ACTION_SETTINGS_INC:
109 case ACTION_SETTINGS_INCREPEAT:
110 m += 5;
111 if (m == 60) {
112 h += 1;
113 m = 0;
115 if (h == 24)
116 h = 0;
117 break;
119 /* dec(m) */
120 case ACTION_SETTINGS_DEC:
121 case ACTION_SETTINGS_DECREPEAT:
122 m -= 5;
123 if (m == -5) {
124 h -= 1;
125 m = 55;
127 if (h == -1)
128 h = 23;
129 break;
131 /* inc(h) */
132 case ACTION_STD_NEXT:
133 case ACTION_STD_NEXTREPEAT:
134 h = (h+1) % 24;
135 break;
137 /* dec(h) */
138 case ACTION_STD_PREV:
139 case ACTION_STD_PREVREPEAT:
140 h = (h+23) % 24;
141 break;
143 case ACTION_STD_CANCEL:
144 rtc_enable_alarm(false);
145 gui_syncsplash(HZ*2, str(LANG_ALARM_MOD_DISABLE));
146 done = true;
147 break;
149 case ACTION_NONE:
150 gui_syncstatusbar_draw(&statusbars, false);
151 break;
153 default:
154 if(default_event_handler(button) == SYS_USB_CONNECTED)
156 rtc_enable_alarm(false);
157 return true;
159 break;
162 action_signalscreenchange();
163 return false;
166 #endif /* HAVE_RTC_ALARM */