add HAVE_DISK_STORAGE, and use that instead of HAVE_FLASH_STORAGE when checking for...
[kugel-rb.git] / apps / plugins / clock / clock_settings.c
blob44a6f164a762ee18e07727ba9fe5d0b5263cebb8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $
10 * Copyright (C) 2007 Copyright Kévin Ferrare based on Zakk Roberts's work
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "clock.h"
23 #include "clock_bitmaps.h"
24 #include "clock_draw.h"
25 #include "clock_settings.h"
26 #include "picture.h"
28 static int max_skin[]={
29 [ANALOG]=2,
30 [BINARY]=3,
31 [DIGITAL]=2,
34 enum message{
35 MESSAGE_LOADING,
36 MESSAGE_LOADED,
37 MESSAGE_ERRLOAD,
38 MESSAGE_SAVING,
39 MESSAGE_SAVED,
40 MESSAGE_ERRSAVE
43 enum settings_file_status{
44 LOADED, ERRLOAD,
45 SAVED, ERRSAVE
48 struct clock_settings clock_settings;
50 /* The settings as they exist on the hard disk, so that
51 * we can know at saving time if changes have been made */
52 struct clock_settings hdd_clock_settings;
54 bool settings_needs_saving(struct clock_settings* settings){
55 return(rb->memcmp(settings, &hdd_clock_settings, sizeof(*settings)));
58 void clock_settings_reset(struct clock_settings* settings){
59 settings->mode = ANALOG;
60 int i;
61 for(i=0;i<NB_CLOCK_MODES;i++){
62 settings->skin[i]=0;
64 settings->general.hour_format = H12;
65 settings->general.date_format = EUROPEAN;
66 settings->general.show_counter = true;
67 settings->general.save_settings = true;
68 settings->general.idle_poweroff=true;
69 settings->general.backlight = ROCKBOX_SETTING;
71 settings->analog.show_date = false;
72 settings->analog.show_seconds = true;
73 settings->analog.show_border = true;
75 settings->digital.show_seconds = true;
76 settings->digital.blinkcolon = false;
77 apply_backlight_setting(settings->general.backlight);
80 void apply_backlight_setting(int backlight_setting)
82 if(backlight_setting == ALWAS_OFF)
83 rb->backlight_set_timeout(-1);
84 else if(backlight_setting == ROCKBOX_SETTING)
85 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
86 else if(backlight_setting == ALWAYS_ON)
87 rb->backlight_set_timeout(0);
90 void clock_settings_skin_next(struct clock_settings* settings){
91 settings->skin[settings->mode]++;
92 if(settings->skin[settings->mode]>=max_skin[settings->mode])
93 settings->skin[settings->mode]=0;
96 void clock_settings_skin_previous(struct clock_settings* settings){
97 settings->skin[settings->mode]--;
98 if(settings->skin[settings->mode]<0)
99 settings->skin[settings->mode]=max_skin[settings->mode]-1;
102 enum settings_file_status clock_settings_load(struct clock_settings* settings,
103 char* filename){
104 int fd = rb->open(filename, O_RDONLY);
105 if(fd >= 0){ /* does file exist? */
106 /* basic consistency check */
107 if(rb->filesize(fd) == sizeof(*settings)){
108 rb->read(fd, settings, sizeof(*settings));
109 rb->close(fd);
110 apply_backlight_setting(settings->general.backlight);
111 rb->memcpy(&hdd_clock_settings, settings, sizeof(*settings));
112 return(LOADED);
115 /* Initializes the settings with default values at least */
116 clock_settings_reset(settings);
117 return(ERRLOAD);
120 enum settings_file_status clock_settings_save(struct clock_settings* settings,
121 char* filename){
122 int fd = rb->creat(filename);
123 if(fd >= 0){ /* does file exist? */
124 rb->write (fd, settings, sizeof(*settings));
125 rb->close(fd);
126 return(SAVED);
128 return(ERRSAVE);
131 void draw_logo(struct screen* display){
132 #ifdef HAVE_LCD_COLOR
133 if(display->is_color){
134 display->set_foreground(LCD_BLACK);
135 display->set_background(LCD_RGBPACK(180,200,230));
137 #endif
139 const struct picture* logo = &(logos[display->screen_type]);
140 display->clear_display();
141 picture_draw(display, logo, 0, 0);
144 void draw_message(struct screen* display, int msg, int y){
145 const struct picture* message = &(messages[display->screen_type]);
146 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
147 display->fillrect(0, display->getheight()-message->height,
148 display->getwidth(), message->height);
149 display->set_drawmode(DRMODE_SOLID);
150 vertical_picture_draw_sprite(display, message, msg,
151 0, display->getheight()-(message->height*y));
154 void load_settings(void){
155 int i;
156 struct screen* display;
157 FOR_NB_SCREENS(i){
158 display=rb->screens[i];
159 display->clear_display();
160 draw_logo(display);
161 draw_message(display, MESSAGE_LOADING, 1);
162 display->update();
165 enum settings_file_status load_status=
166 clock_settings_load(&clock_settings, settings_filename);
168 FOR_NB_SCREENS(i){
169 display=rb->screens[i];
170 if(load_status==LOADED)
171 draw_message(display, MESSAGE_LOADED, 1);
172 else
173 draw_message(display, MESSAGE_ERRLOAD, 1);
174 display->update();
176 rb->ata_sleep();
177 rb->sleep(HZ);
180 void save_settings(void){
181 int i;
182 struct screen* display;
183 if(!settings_needs_saving(&clock_settings))
184 return;
186 FOR_NB_SCREENS(i){
187 display=rb->screens[i];
188 display->clear_display();
189 draw_logo(display);
191 draw_message(display, MESSAGE_SAVING, 1);
193 display->update();
195 enum settings_file_status load_status=
196 clock_settings_save(&clock_settings, settings_filename);
198 FOR_NB_SCREENS(i){
199 display=rb->screens[i];
201 if(load_status==SAVED)
202 draw_message(display, MESSAGE_SAVED, 1);
203 else
204 draw_message(display, MESSAGE_ERRSAVE, 1);
205 display->update();
207 rb->sleep(HZ);
210 void save_settings_wo_gui(void){
211 clock_settings_save(&clock_settings, settings_filename);