blob: 4c181593db3076e2be1c2a349a526cf318cde7a8 [file] [log] [blame]
Björn Stenbergf80d8a702002-06-27 00:20:00 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Steve Bavincd88e2a2008-03-25 15:24:03 +000010 * Copyright (C) 2002 by Stuart Martin
Björn Stenberg6b25f792002-07-15 11:02:12 +000011 * RTC config saving code (C) 2002 by hessu@hes.iki.fi
Björn Stenbergf80d8a702002-06-27 00:20:00 +000012 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000013 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
Björn Stenbergf80d8a702002-06-27 00:20:00 +000017 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
Björn Stenbergf80d8a702002-06-27 00:20:00 +000022#include <stdio.h>
Jörg Hohensohn44171b92004-06-18 20:41:59 +000023#include <stddef.h>
Jonathan Gordon4718a1e2007-02-08 04:33:41 +000024#include <stdlib.h>
Jean-Philippe Bernardy00cf0da2005-02-15 15:30:19 +000025#include <limits.h>
Jens Arnoldfb7368e2006-03-03 01:12:50 +000026#include "inttypes.h"
Björn Stenbergf80d8a702002-06-27 00:20:00 +000027#include "config.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000028#include "action.h"
Jonathan Gordonb2e50902007-01-23 13:40:44 +000029#include "crc32.h"
Björn Stenbergf80d8a702002-06-27 00:20:00 +000030#include "settings.h"
Björn Stenbergf80d8a702002-06-27 00:20:00 +000031#include "debug.h"
Justin Heinerb5025a82002-08-31 04:58:35 +000032#include "usb.h"
33#include "backlight.h"
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +000034#include "audio.h"
Jens Arnold61a25502005-09-11 12:07:13 +000035#include "mpeg.h"
Jörg Hohensohn42ffbf92004-03-15 08:27:51 +000036#include "talk.h"
Björn Stenberg6b25f792002-07-15 11:02:12 +000037#include "string.h"
Jonathan Gordon2062f632007-01-29 13:44:22 +000038#include "rtc.h"
Jonathan Gordon7bb8b302007-01-29 13:58:35 +000039#include "power.h"
Jonathan Gordonf1841522006-11-08 01:55:26 +000040#include "ata_idle_notify.h"
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000041#include "screens.h"
Björn Stenberg0e6088f2002-10-02 16:33:26 +000042#include "ctype.h"
43#include "file.h"
Linus Nielsen Feltzingc843ba42002-10-29 12:16:36 +000044#include "system.h"
Linus Nielsen Feltzing75b41a82003-05-04 02:04:31 +000045#include "misc.h"
Markus Braun5e4c1d22002-08-20 19:37:00 +000046#ifdef HAVE_LCD_BITMAP
47#include "icons.h"
Daniel Stenberg93b231c2002-09-12 13:33:59 +000048#include "font.h"
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +000049#include "peakmeter.h"
Markus Braun5e4c1d22002-08-20 19:37:00 +000050#endif
Björn Stenberg505eca72002-09-18 14:08:05 +000051#include "lang.h"
Björn Stenbergdea31222002-10-08 15:42:40 +000052#include "language.h"
Christi Scarborough4c0b83f2005-11-17 20:14:59 +000053#include "gwps.h"
Björn Stenbergae22de22002-12-02 16:07:56 +000054#include "powermgmt.h"
Daniel Stenberg79a6cb62003-02-15 00:03:23 +000055#include "sprintf.h"
Björn Stenbergc5aaab42003-03-10 16:31:02 +000056#include "keyboard.h"
Björn Stenberga6b8bdf2003-04-25 10:33:38 +000057#include "version.h"
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000058#include "sound.h"
Marcoen Hirschbergb0fee172005-12-06 13:27:15 +000059#include "rbunicode.h"
Miika Pekkarinenab78b042005-10-07 17:38:05 +000060#include "dircache.h"
Kevin Ferrarecbbdc952005-11-04 07:18:36 +000061#include "statusbar.h"
Kevin Ferrare9ccca4a2005-11-04 17:25:29 +000062#include "splash.h"
Tomas Salfischberger7fa39df2006-01-22 01:42:05 +000063#include "list.h"
Jonathan Gordonb2e50902007-01-23 13:40:44 +000064#include "settings_list.h"
Brandon Low488de5e2007-06-17 21:29:24 +000065#include "filetypes.h"
Steve Bavincd88e2a2008-03-25 15:24:03 +000066#include "option_select.h"
Dave Chapmand9e5b672006-02-02 20:42:56 +000067#include "backdrop.h"
Miika Pekkarinenab78b042005-10-07 17:38:05 +000068
Jonathan Gordon844583c2007-02-18 02:16:03 +000069#if CONFIG_TUNER
Hristo Kovachev009853f2006-04-02 12:23:08 +000070#include "radio.h"
71#endif
72
Jens Arnoldd6c05452005-08-29 21:15:27 +000073#if CONFIG_CODEC == MAS3507D
Linus Nielsen Feltzing54a7e202003-11-04 00:18:19 +000074void dac_line_in(bool enable);
Linus Nielsen Feltzingc22b4112003-11-03 23:36:36 +000075#endif
Björn Stenbergf80d8a702002-06-27 00:20:00 +000076struct user_settings global_settings;
Michael Sevakis0f175322007-02-08 10:36:49 +000077struct system_status global_status;
Michael Sevakiseed62f12007-02-07 04:24:21 +000078
Jens Arnoldd6c05452005-08-29 21:15:27 +000079#if CONFIG_CODEC == SWCODEC
Magnus Holmgren4b711c22005-09-24 15:22:48 +000080#include "dsp.h"
Steve Bavinc9df8fd2008-03-28 11:24:24 +000081#include "playback.h"
Michael Sevakis0f5cb942006-11-06 18:07:30 +000082#ifdef HAVE_RECORDING
83#include "enc_config.h"
Linus Nielsen Feltzing6271b2b2005-06-09 09:47:00 +000084#endif
Michael Sevakis0f5cb942006-11-06 18:07:30 +000085#endif /* CONFIG_CODEC == SWCODEC */
Björn Stenberg6c33c512004-09-19 21:58:37 +000086
Jonathan Gordonb2e50902007-01-23 13:40:44 +000087#define NVRAM_BLOCK_SIZE 44
Björn Stenbergcd7691d2002-08-13 17:16:09 +000088
Linus Nielsen Feltzingbb572c42002-09-27 09:31:31 +000089#ifdef HAVE_LCD_BITMAP
90#define MAX_LINES 10
91#else
92#define MAX_LINES 2
93#endif
94
Christian Gmeiner7c1879b2005-04-15 12:08:49 +000095#ifdef HAVE_REMOTE_LCD
96#include "lcd-remote.h"
97#endif
98
Jörg Hohensohn44171b92004-06-18 20:41:59 +000099long lasttime = 0;
Jörg Hohensohn44171b92004-06-18 20:41:59 +0000100
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000101/** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000102/* NVRAM is set out as
103[0] 'R'
104[1] 'b'
105[2] version
106[3] stored variable count
107[4-7] crc32 checksum
108[8-NVRAM_BLOCK_SIZE] data
Jörg Hohensohn44171b92004-06-18 20:41:59 +0000109*/
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000110#define NVRAM_DATA_START 8
111#define NVRAM_FILE ROCKBOX_DIR "/nvram.bin"
112static char nvram_buffer[NVRAM_BLOCK_SIZE];
Jörg Hohensohn44171b92004-06-18 20:41:59 +0000113
Steve Bavin135cc752008-03-28 12:51:33 +0000114static bool read_nvram_data(char* buf, int max_len)
Jörg Hohensohn44171b92004-06-18 20:41:59 +0000115{
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000116 unsigned crc32 = 0xffffffff;
117 int var_count = 0, i = 0, buf_pos = 0;
118#ifndef HAVE_RTC_RAM
119 int fd = open(NVRAM_FILE,O_RDONLY);
120 if (fd < 0)
121 return false;
122 memset(buf,0,max_len);
123 if (read(fd,buf,max_len) < 8) /* min is 8 bytes,magic, ver, vars, crc32 */
124 return false;
125 close(fd);
Zakk Roberts8bdd92b2006-03-30 05:56:19 +0000126#else
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000127 memset(buf,0,max_len);
128 /* read rtc block */
129 for (i=0; i < max_len; i++ )
130 buf[i] = rtc_read(0x14+i);
Jens Arnold2993ae62005-12-07 23:07:07 +0000131#endif
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000132 /* check magic, version */
133 if ((buf[0] != 'R') || (buf[1] != 'b')
134 || (buf[2] != NVRAM_CONFIG_VERSION))
135 return false;
136 /* check crc32 */
137 crc32 = crc_32(&buf[NVRAM_DATA_START],
138 max_len-NVRAM_DATA_START-1,0xffffffff);
139 if (memcmp(&crc32,&buf[4],4))
140 return false;
141 /* all good, so read in the settings */
142 var_count = buf[3];
143 buf_pos = NVRAM_DATA_START;
Jonathan Gordon7cb80a22007-08-12 07:22:38 +0000144 for(i=0; i<nb_settings; i++)
Michael Sevakis4fc717a2006-08-28 22:38:41 +0000145 {
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000146 int nvram_bytes = (settings[i].flags&F_NVRAM_BYTES_MASK)
147 >>F_NVRAM_MASK_SHIFT;
148 if (nvram_bytes)
149 {
Jonathan Gordon7cb80a22007-08-12 07:22:38 +0000150 if ((var_count>0) && (buf_pos<max_len))
151 {
152 memcpy(settings[i].setting,&buf[buf_pos],nvram_bytes);
153 buf_pos += nvram_bytes;
154 var_count--;
155 }
156 else /* should only happen when new items are added to the end */
157 {
158 memcpy(settings[i].setting, &settings[i].default_val, nvram_bytes);
159 }
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000160 }
161 }
162 return true;
Jörg Hohensohn44171b92004-06-18 20:41:59 +0000163}
Steve Bavin135cc752008-03-28 12:51:33 +0000164static bool write_nvram_data(char* buf, int max_len)
Jörg Hohensohn44171b92004-06-18 20:41:59 +0000165{
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000166 unsigned crc32 = 0xffffffff;
167 int i = 0, buf_pos = 0;
168 char var_count = 0;
169#ifndef HAVE_RTC_RAM
170 int fd;
171#endif
172 memset(buf,0,max_len);
173 /* magic, version */
174 buf[0] = 'R'; buf[1] = 'b';
175 buf[2] = NVRAM_CONFIG_VERSION;
176 buf_pos = NVRAM_DATA_START;
177 for(i=0; (i<nb_settings) && (buf_pos<max_len); i++)
178 {
179 int nvram_bytes = (settings[i].flags&F_NVRAM_BYTES_MASK)
180 >>F_NVRAM_MASK_SHIFT;
181 if (nvram_bytes)
182 {
183 memcpy(&buf[buf_pos],settings[i].setting,nvram_bytes);
184 buf_pos += nvram_bytes;
185 var_count++;
186 }
187 }
188 /* count and crc32 */
189 buf[3] = var_count;
190 crc32 = crc_32(&buf[NVRAM_DATA_START],
191 max_len-NVRAM_DATA_START-1,0xffffffff);
192 memcpy(&buf[4],&crc32,4);
193#ifndef HAVE_RTC_RAM
194 fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY);
195 if (fd >= 0)
196 {
197 int len = write(fd,buf,max_len);
198 close(fd);
199 if (len < 8)
200 return false;
201 }
202#else
203 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
204 that it would write a number of bytes at a time since the RTC chip
205 supports that, but this will have to do for now 8-) */
206 for (i=0; i < NVRAM_BLOCK_SIZE; i++ ) {
207 int r = rtc_write(0x14+i, buf[i]);
Steve Bavin799e9482008-04-07 17:19:53 +0000208 if (r)
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000209 return false;
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000210 }
211#endif
212 return true;
Jörg Hohensohn44171b92004-06-18 20:41:59 +0000213}
Björn Stenberg6b25f792002-07-15 11:02:12 +0000214
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000215/** Reading from a config file **/
216/*
217 * load settings from disk or RTC RAM
218 */
Steve Bavin135cc752008-03-28 12:51:33 +0000219void settings_load(int which)
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000220{
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000221 if (which&SETTINGS_RTC)
222 read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
223 if (which&SETTINGS_HD)
224 {
225 settings_load_config(CONFIGFILE,false);
226 settings_load_config(FIXEDSETTINGSFILE,false);
227 }
228}
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000229
Steve Bavin135cc752008-03-28 12:51:33 +0000230static bool cfg_string_to_int(int setting_id, int* out, const char* str)
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000231{
232 const char* start = settings[setting_id].cfg_vals;
233 char* end = NULL;
234 char temp[MAX_PATH];
235 int count = 0;
236 while (1)
237 {
238 end = strchr(start, ',');
239 if (!end)
240 {
241 if (!strcmp(str, start))
242 {
243 *out = count;
244 return true;
245 }
246 else return false;
247 }
248 strncpy(temp, start, end-start);
249 temp[end-start] = '\0';
250 if (!strcmp(str, temp))
251 {
252 *out = count;
253 return true;
254 }
255 start = end +1;
256 count++;
257 }
258 return false;
259}
260
Steve Bavin135cc752008-03-28 12:51:33 +0000261bool settings_load_config(const char* file, bool apply)
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000262{
263 int fd;
264 char line[128];
265 char* name;
266 char* value;
267 int i;
268 fd = open(file, O_RDONLY);
269 if (fd < 0)
270 return false;
Jonathan Gordon01583362008-03-25 12:42:47 +0000271
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000272 while (read_line(fd, line, sizeof line) > 0)
273 {
274 if (!settings_parseline(line, &name, &value))
275 continue;
276 for(i=0; i<nb_settings; i++)
277 {
278 if (settings[i].cfg_name == NULL)
279 continue;
280 if (!strcasecmp(name,settings[i].cfg_name))
281 {
282 switch (settings[i].flags&F_T_MASK)
283 {
284 case F_T_INT:
285 case F_T_UINT:
286#ifdef HAVE_LCD_COLOR
287 if (settings[i].flags&F_RGB)
Dave Chapmane92d2c52008-03-21 13:41:35 +0000288 hex_to_rgb(value, (int*)settings[i].setting);
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000289 else
290#endif
291 if (settings[i].cfg_vals == NULL)
292 {
293 *(int*)settings[i].setting = atoi(value);
294 }
295 else
296 {
Jens Arnoldd490f442007-11-25 17:36:21 +0000297 int temp, *v = (int*)settings[i].setting;
298 bool found = cfg_string_to_int(i, &temp, value);
299 if (found)
300 {
301 if (settings[i].flags&F_TABLE_SETTING)
302 *v = settings[i].table_setting->values[temp];
303 else
304 *v = temp;
305 }
306 else
307 *v = atoi(value);
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000308 }
309 break;
310 case F_T_BOOL:
311 {
312 int temp;
313 if (cfg_string_to_int(i,&temp,value))
314 *(bool*)settings[i].setting = (temp==0?false:true);
315 break;
316 }
317 case F_T_CHARPTR:
318 case F_T_UCHARPTR:
319 {
320 char storage[MAX_PATH];
321 if (settings[i].filename_setting->prefix)
322 {
323 int len = strlen(settings[i].filename_setting->prefix);
Jonathan Gordon332b3242007-02-12 02:36:32 +0000324 if (!strncasecmp(value,
325 settings[i].filename_setting->prefix,
326 len))
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000327 {
328 strncpy(storage,&value[len],MAX_PATH);
329 }
330 else strncpy(storage,value,MAX_PATH);
331 }
332 else strncpy(storage,value,MAX_PATH);
333 if (settings[i].filename_setting->suffix)
334 {
335 char *s = strcasestr(storage,settings[i].filename_setting->suffix);
336 if (s) *s = '\0';
337 }
338 strncpy((char*)settings[i].setting,storage,
339 settings[i].filename_setting->max_len);
340 ((char*)settings[i].setting)
341 [settings[i].filename_setting->max_len-1] = '\0';
342 break;
343 }
344 }
345 break;
346 } /* if (!strcmp(name,settings[i].cfg_name)) */
347 } /* for(...) */
348 } /* while(...) */
349
350 close(fd);
351 settings_save();
352 if (apply)
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000353 settings_apply(true);
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000354 return true;
355}
356
357/** Writing to a config file and saving settings **/
Dave Chapman603f87f2006-02-26 02:48:05 +0000358
Steve Bavin135cc752008-03-28 12:51:33 +0000359bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len)
Jonathan Gordonbc60af12007-01-29 12:32:56 +0000360{
Jens Arnoldd490f442007-11-25 17:36:21 +0000361 int flags = settings[setting_id].flags;
Jonathan Gordonbc60af12007-01-29 12:32:56 +0000362 const char* start = settings[setting_id].cfg_vals;
363 char* end = NULL;
364 int count = 0;
Jens Arnoldd490f442007-11-25 17:36:21 +0000365
366 if ((flags&F_T_MASK)==F_T_INT &&
367 flags&F_TABLE_SETTING)
368 {
369 const int *value = settings[setting_id].table_setting->values;
370 while (start)
371 {
372 end = strchr(start,',');
373 if (value[count] == val)
374 {
375 if (end == NULL)
376 strncpy(buf, start, buf_len);
377 else
378 {
379 int len = (buf_len > (end-start))? end-start: buf_len;
380 strncpy(buf, start, len);
381 buf[len] = '\0';
382 }
383 return true;
384 }
385 count++;
386
387 if (end)
388 start = end+1;
389 else
390 break;
391 }
392 return false;
393 }
394
Jonathan Gordonbc60af12007-01-29 12:32:56 +0000395 while (count < val)
396 {
397 start = strchr(start,',');
398 if (!start)
399 return false;
400 count++;
401 start++;
402 }
403 end = strchr(start,',');
404 if (end == NULL)
Jonathan Gordonfe3cfcc2007-02-08 10:28:42 +0000405 strncpy(buf, start, buf_len);
Jonathan Gordonbc60af12007-01-29 12:32:56 +0000406 else
407 {
Jonathan Gordonfe3cfcc2007-02-08 10:28:42 +0000408 int len = (buf_len > (end-start))? end-start: buf_len;
409 strncpy(buf, start, len);
410 buf[len] = '\0';
Jonathan Gordonbc60af12007-01-29 12:32:56 +0000411 }
412 return true;
413}
Steve Bavincd88e2a2008-03-25 15:24:03 +0000414
415
Steve Bavin135cc752008-03-28 12:51:33 +0000416static bool is_changed(int setting_id)
Jonathan Gordonf0d28612007-02-01 13:57:14 +0000417{
Linus Nielsen Feltzing750fa4a2007-02-16 10:20:30 +0000418 const struct settings_list *setting = &settings[setting_id];
419 switch (setting->flags&F_T_MASK)
420 {
421 case F_T_INT:
422 case F_T_UINT:
423 if (setting->flags&F_DEF_ISFUNC)
424 {
425 if (*(int*)setting->setting == setting->default_val.func())
426 return false;
427 }
428 else if (setting->flags&F_T_SOUND)
429 {
430 if (*(int*)setting->setting ==
431 sound_default(setting->sound_setting->setting))
432 return false;
433 }
434 else if (*(int*)setting->setting == setting->default_val.int_)
435 return false;
436 break;
437 case F_T_BOOL:
438 if (*(bool*)setting->setting == setting->default_val.bool_)
439 return false;
440 break;
441 case F_T_CHARPTR:
442 case F_T_UCHARPTR:
443 if (!strcmp((char*)setting->setting, setting->default_val.charptr))
444 return false;
445 break;
446 }
447 return true;
Jonathan Gordonf0d28612007-02-01 13:57:14 +0000448}
Jonathan Gordonb7588832007-01-25 07:19:45 +0000449
Steve Bavin135cc752008-03-28 12:51:33 +0000450static bool settings_write_config(const char* filename, int options)
Björn Stenbergf80d8a702002-06-27 00:20:00 +0000451{
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000452 int i;
453 int fd;
Jonathan Gordon46f7f7d2007-01-24 03:47:25 +0000454 char value[MAX_PATH];
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000455 fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY);
456 if (fd < 0)
457 return false;
Jonathan Gordon4d238c12008-01-10 06:46:04 +0000458#if CONFIG_TUNER
459 bool statusbar = global_settings.statusbar;
460 if (global_status.statusbar_forced != 0 && statusbar)
461 global_settings.statusbar = false;
462#endif
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000463 fdprintf(fd, "# .cfg file created by rockbox %s - "
464 "http://www.rockbox.org\r\n\r\n", appsversion);
465 for(i=0; i<nb_settings; i++)
466 {
467 if (settings[i].cfg_name == NULL)
468 continue;
Jonathan Gordonbc60af12007-01-29 12:32:56 +0000469 value[0] = '\0';
Linus Nielsen Feltzing750fa4a2007-02-16 10:20:30 +0000470
Jens Arnoldfcd52cf2008-02-23 11:06:19 +0000471 switch (options)
472 {
473 case SETTINGS_SAVE_CHANGED:
474 if (!is_changed(i))
475 continue;
476 break;
477 case SETTINGS_SAVE_SOUND:
478 if ((settings[i].flags&F_SOUNDSETTING) == 0)
479 continue;
480 break;
481 case SETTINGS_SAVE_THEME:
482 if ((settings[i].flags&F_THEMESETTING) == 0)
483 continue;
484 break;
Jonathan Gordon9adf0562007-05-29 04:39:11 +0000485#ifdef HAVE_RECORDING
Jens Arnoldfcd52cf2008-02-23 11:06:19 +0000486 case SETTINGS_SAVE_RECPRESETS:
487 if ((settings[i].flags&F_RECSETTING) == 0)
488 continue;
489 break;
Jonathan Gordon9adf0562007-05-29 04:39:11 +0000490#endif
Dan Everton5886efa2007-12-07 10:59:07 +0000491#if CONFIG_CODEC == SWCODEC
Jens Arnoldfcd52cf2008-02-23 11:06:19 +0000492 case SETTINGS_SAVE_EQPRESET:
493 if ((settings[i].flags&F_EQSETTING) == 0)
494 continue;
495 break;
Dan Everton5886efa2007-12-07 10:59:07 +0000496#endif
Jens Arnoldfcd52cf2008-02-23 11:06:19 +0000497 }
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000498 switch (settings[i].flags&F_T_MASK)
499 {
500 case F_T_INT:
501 case F_T_UINT:
502#ifdef HAVE_LCD_COLOR
503 if (settings[i].flags&F_RGB)
504 {
505 int colour = *(int*)settings[i].setting;
506 snprintf(value,MAX_PATH,"%02x%02x%02x",
507 (int)RGB_UNPACK_RED(colour),
508 (int)RGB_UNPACK_GREEN(colour),
509 (int)RGB_UNPACK_BLUE(colour));
510 }
511 else
512#endif
Magnus Holmgrenc23f5652007-01-23 19:54:09 +0000513 if (settings[i].cfg_vals == NULL)
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000514 {
515 snprintf(value,MAX_PATH,"%d",*(int*)settings[i].setting);
516 }
517 else
518 {
Jens Arnoldd490f442007-11-25 17:36:21 +0000519 if (cfg_int_to_string(i, *(int*)settings[i].setting,
520 value, MAX_PATH) == false)
521 {
522 snprintf(value,MAX_PATH,"%d",*(int*)settings[i].setting);
523 }
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000524 }
525 break;
526 case F_T_BOOL:
Jonathan Gordonbc60af12007-01-29 12:32:56 +0000527 cfg_int_to_string(i,
Jonathan Gordonfe3cfcc2007-02-08 10:28:42 +0000528 *(bool*)settings[i].setting==false?0:1, value, MAX_PATH);
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000529 break;
530 case F_T_CHARPTR:
531 case F_T_UCHARPTR:
Jens Arnolddb70f8d2008-02-23 10:17:31 +0000532 if (((char*)settings[i].setting)[0]
533 && settings[i].filename_setting->prefix)
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000534 {
535 snprintf(value,MAX_PATH,"%s%s%s",
536 settings[i].filename_setting->prefix,
537 (char*)settings[i].setting,
538 settings[i].filename_setting->suffix);
539 }
540 else strncpy(value,(char*)settings[i].setting,
541 settings[i].filename_setting->max_len);
542 break;
543 } /* switch () */
Jens Arnolddb70f8d2008-02-23 10:17:31 +0000544 fdprintf(fd,"%s: %s\r\n",settings[i].cfg_name,value);
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000545 } /* for(...) */
546 close(fd);
Jonathan Gordon4d238c12008-01-10 06:46:04 +0000547#if CONFIG_TUNER
548 global_settings.statusbar = statusbar;
549#endif
Jonathan Gordonf1841522006-11-08 01:55:26 +0000550 return true;
551}
Jonathan Gordon228d62d2007-01-24 02:19:22 +0000552#ifndef HAVE_RTC_RAM
553static bool flush_global_status_callback(void)
554{
555 return write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
556}
557#endif
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000558static bool flush_config_block_callback(void)
Björn Stenberg6b25f792002-07-15 11:02:12 +0000559{
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000560 bool r1, r2;
561 r1 = write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
Jonathan Gordonf0d28612007-02-01 13:57:14 +0000562 r2 = settings_write_config(CONFIGFILE, SETTINGS_SAVE_CHANGED);
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000563 return r1 || r2;
Jens Arnoldc12e87d2004-09-28 18:09:10 +0000564}
Jörg Hohensohn44171b92004-06-18 20:41:59 +0000565
Björn Stenberg6b25f792002-07-15 11:02:12 +0000566/*
567 * persist all runtime user settings to disk or RTC RAM
568 */
Jonathan Gordon228d62d2007-01-24 02:19:22 +0000569static void update_runtime(void)
Björn Stenberg6b25f792002-07-15 11:02:12 +0000570{
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000571 int elapsed_secs;
Dave Chapmand9e5b672006-02-02 20:42:56 +0000572
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000573 elapsed_secs = (current_tick - lasttime) / HZ;
Jonathan Gordon228d62d2007-01-24 02:19:22 +0000574 global_status.runtime += elapsed_secs;
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000575 lasttime += (elapsed_secs * HZ);
576
Jonathan Gordon228d62d2007-01-24 02:19:22 +0000577 if ( global_status.runtime > global_status.topruntime )
578 global_status.topruntime = global_status.runtime;
579}
580
Steve Bavincd88e2a2008-03-25 15:24:03 +0000581void status_save(void)
Jonathan Gordon228d62d2007-01-24 02:19:22 +0000582{
583 update_runtime();
584#ifdef HAVE_RTC_RAM
585 /* this will be done in the ata_callback if
586 target doesnt have rtc ram */
587 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
588#else
589 register_ata_idle_func(flush_global_status_callback);
590#endif
591}
592
Steve Bavincd88e2a2008-03-25 15:24:03 +0000593int settings_save(void)
Jonathan Gordon228d62d2007-01-24 02:19:22 +0000594{
595 update_runtime();
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000596#ifdef HAVE_RTC_RAM
597 /* this will be done in the ata_callback if
598 target doesnt have rtc ram */
599 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
600#endif
Miika Pekkarinen19c6e662008-03-16 13:55:16 +0000601 register_ata_idle_func(flush_config_block_callback);
Linus Nielsen Feltzingd0abfe82002-07-28 16:09:44 +0000602 return 0;
Björn Stenbergf80d8a702002-06-27 00:20:00 +0000603}
Steve Bavincd88e2a2008-03-25 15:24:03 +0000604
Steve Bavin135cc752008-03-28 12:51:33 +0000605bool settings_save_config(int options)
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000606{
607 char filename[MAX_PATH];
Jonathan Gordon9adf0562007-05-29 04:39:11 +0000608 char *folder;
609 switch (options)
610 {
611 case SETTINGS_SAVE_THEME:
612 folder = THEME_DIR;
613 break;
614#ifdef HAVE_RECORDING
615 case SETTINGS_SAVE_RECPRESETS:
616 folder = RECPRESETS_DIR;
617 break;
618#endif
Dan Everton5886efa2007-12-07 10:59:07 +0000619#if CONFIG_CODEC == SWCODEC
620 case SETTINGS_SAVE_EQPRESET:
621 folder = EQS_DIR;
622 break;
623#endif
Jonathan Gordonb8bc45d2007-12-24 22:35:31 +0000624 case SETTINGS_SAVE_SOUND:
Jonathan Gordon9adf0562007-05-29 04:39:11 +0000625 default:
626 folder = ROCKBOX_DIR;
627 }
628 create_numbered_filename(filename, folder, "config", ".cfg", 2
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000629 IF_CNFN_NUM_(, NULL));
630
631 /* allow user to modify filename */
632 while (true) {
633 if (!kbd_input(filename, sizeof filename)) {
634 break;
635 }
636 else {
Nils Wallménius5b769362007-08-06 13:08:36 +0000637 gui_syncsplash(HZ, ID2P(LANG_CANCEL));
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000638 return false;
639 }
640 }
641
Jonathan Gordonf0d28612007-02-01 13:57:14 +0000642 if (settings_write_config(filename, options))
Nils Wallménius5b769362007-08-06 13:08:36 +0000643 gui_syncsplash(HZ, ID2P(LANG_SETTINGS_SAVED));
Linus Nielsen Feltzing750fa4a2007-02-16 10:20:30 +0000644 else
Nils Wallménius5b769362007-08-06 13:08:36 +0000645 gui_syncsplash(HZ, ID2P(LANG_FAILED));
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000646 return true;
647}
648
649/** Apply and Reset settings **/
650
Björn Stenbergf80d8a702002-06-27 00:20:00 +0000651
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +0000652#ifdef HAVE_LCD_BITMAP
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000653/*
Kevin Ferrarecbbdc952005-11-04 07:18:36 +0000654 * Applies the range infos stored in global_settings to
655 * the peak meter.
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +0000656 */
657void settings_apply_pm_range(void)
658{
659 int pm_min, pm_max;
660
661 /* depending on the scale mode (dBfs or percent) the values
662 of global_settings.peak_meter_dbfs have different meanings */
Kevin Ferrarecbbdc952005-11-04 07:18:36 +0000663 if (global_settings.peak_meter_dbfs)
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +0000664 {
665 /* convert to dBfs * 100 */
666 pm_min = -(((int)global_settings.peak_meter_min) * 100);
667 pm_max = -(((int)global_settings.peak_meter_max) * 100);
668 }
Kevin Ferrarecbbdc952005-11-04 07:18:36 +0000669 else
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +0000670 {
671 /* percent is stored directly -> no conversion */
672 pm_min = global_settings.peak_meter_min;
673 pm_max = global_settings.peak_meter_max;
674 }
675
676 /* apply the range */
677 peak_meter_init_range(global_settings.peak_meter_dbfs, pm_min, pm_max);
678}
679#endif /* HAVE_LCD_BITMAP */
680
Linus Nielsen Feltzing7bade1a2004-07-06 12:17:14 +0000681void sound_settings_apply(void)
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000682{
Thom Johansen99b27422007-03-07 19:11:16 +0000683#if CONFIG_CODEC == SWCODEC
Thom Johansena7fabf02007-02-26 00:41:26 +0000684 sound_set_dsp_callback(dsp_callback);
685#endif
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000686 sound_set(SOUND_BASS, global_settings.bass);
687 sound_set(SOUND_TREBLE, global_settings.treble);
688 sound_set(SOUND_BALANCE, global_settings.balance);
689 sound_set(SOUND_VOLUME, global_settings.volume);
690 sound_set(SOUND_CHANNELS, global_settings.channel_config);
691 sound_set(SOUND_STEREO_WIDTH, global_settings.stereo_width);
Jens Arnoldd6c05452005-08-29 21:15:27 +0000692#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000693 sound_set(SOUND_LOUDNESS, global_settings.loudness);
694 sound_set(SOUND_AVC, global_settings.avc);
695 sound_set(SOUND_MDB_STRENGTH, global_settings.mdb_strength);
696 sound_set(SOUND_MDB_HARMONICS, global_settings.mdb_harmonics);
697 sound_set(SOUND_MDB_CENTER, global_settings.mdb_center);
698 sound_set(SOUND_MDB_SHAPE, global_settings.mdb_shape);
699 sound_set(SOUND_MDB_ENABLE, global_settings.mdb_enable);
700 sound_set(SOUND_SUPERBASS, global_settings.superbass);
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000701#endif
Steve Bavinc47172a2007-02-01 11:08:35 +0000702
Dan Evertond7e1f772007-11-24 07:51:00 +0000703#ifdef HAVE_WM8758
704 sound_set(SOUND_BASS_CUTOFF, global_settings.bass_cutoff);
705 sound_set(SOUND_TREBLE_CUTOFF, global_settings.treble_cutoff);
706#endif
707
Steve Bavinc47172a2007-02-01 11:08:35 +0000708#ifdef HAVE_USB_POWER
Jonathan Gordon9a6f4192007-02-18 05:32:06 +0000709#if CONFIG_CHARGING
Steve Bavinc47172a2007-02-01 11:08:35 +0000710 usb_charging_enable(global_settings.usb_charging);
711#endif
712#endif
Linus Nielsen Feltzing7bade1a2004-07-06 12:17:14 +0000713}
714
Steve Bavin135cc752008-03-28 12:51:33 +0000715void settings_apply(bool read_disk)
Linus Nielsen Feltzing7bade1a2004-07-06 12:17:14 +0000716{
717 char buf[64];
Dan Everton5519d822006-02-17 21:55:11 +0000718#if CONFIG_CODEC == SWCODEC
Dan Everton5a1d77d2006-02-17 19:56:22 +0000719 int i;
Dan Everton5519d822006-02-17 21:55:11 +0000720#endif
Linus Nielsen Feltzing7bade1a2004-07-06 12:17:14 +0000721
722 sound_settings_apply();
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000723
Nils Wallménius0bfa3e72007-08-01 08:50:44 +0000724#ifndef HAVE_FLASH_STORAGE
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000725 audio_set_buffer_margin(global_settings.buffer_margin);
Nils Wallménius0bfa3e72007-08-01 08:50:44 +0000726#endif
Kevin Ferrarecbbdc952005-11-04 07:18:36 +0000727
Rani Hodcc839a22006-07-31 19:13:21 +0000728#ifdef HAVE_LCD_CONTRAST
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000729 lcd_set_contrast(global_settings.contrast);
Jens Arnold9051afa2006-07-25 11:15:50 +0000730#endif
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000731 lcd_scroll_speed(global_settings.scroll_speed);
Christian Gmeiner7c1879b2005-04-15 12:08:49 +0000732#ifdef HAVE_REMOTE_LCD
Jens Arnoldbd1bb5f2005-06-17 21:43:00 +0000733 lcd_remote_set_contrast(global_settings.remote_contrast);
734 lcd_remote_set_invert_display(global_settings.remote_invert);
735 lcd_remote_set_flip(global_settings.remote_flip_display);
Marcoen Hirschberga86919a2006-05-22 16:40:41 +0000736 lcd_remote_scroll_speed(global_settings.remote_scroll_speed);
737 lcd_remote_scroll_step(global_settings.remote_scroll_step);
Jonathan Gordon282b3902007-02-21 13:34:45 +0000738 lcd_remote_scroll_delay(global_settings.remote_scroll_delay);
Dave Chapmane5ee9a22006-07-22 13:47:11 +0000739 lcd_remote_bidir_scroll(global_settings.remote_bidir_limit);
Miika Pekkarinen93d8ca52005-11-19 09:26:02 +0000740#ifdef HAVE_REMOTE_LCD_TICKING
Miika Pekkarinenf9234b32005-11-19 08:05:03 +0000741 lcd_remote_emireduce(global_settings.remote_reduce_ticking);
Miika Pekkarinen93d8ca52005-11-19 09:26:02 +0000742#endif
Christian Gmeiner7477c092005-05-30 00:00:22 +0000743 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
Jonathan Gordon9a6f4192007-02-18 05:32:06 +0000744#if CONFIG_CHARGING
Jens Arnolda6d409d2005-11-23 20:12:33 +0000745 remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged);
746#endif
Michael Sevakis3d2e10b2006-09-10 02:00:40 +0000747#ifdef HAS_REMOTE_BUTTON_HOLD
748 remote_backlight_set_on_button_hold(global_settings.remote_backlight_on_button_hold);
Jens Arnoldbd1bb5f2005-06-17 21:43:00 +0000749#endif
Michael Sevakis3d2e10b2006-09-10 02:00:40 +0000750#endif /* HAVE_REMOTE_LCD */
Karl Kurbjun2ac037d2007-05-14 04:44:55 +0000751#ifdef HAVE_BACKLIGHT_BRIGHTNESS
752 backlight_set_brightness(global_settings.brightness);
753#endif
Jens Arnold47bf6c52007-04-12 22:12:13 +0000754#ifdef HAVE_BACKLIGHT
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000755 backlight_set_timeout(global_settings.backlight_timeout);
Jonathan Gordon9a6f4192007-02-18 05:32:06 +0000756#if CONFIG_CHARGING
Jens Arnolda6d409d2005-11-23 20:12:33 +0000757 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
Jens Arnoldb51f7df2005-11-21 23:55:39 +0000758#endif
Thom Johansen3c7278f2006-03-19 17:42:58 +0000759#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
Jens Arnold61b9d342005-06-20 17:03:09 +0000760 backlight_set_fade_in(global_settings.backlight_fade_in);
761 backlight_set_fade_out(global_settings.backlight_fade_out);
762#endif
Jens Arnoldb51f7df2005-11-21 23:55:39 +0000763#endif
Karl Kurbjun6f95ab72007-05-08 06:45:38 +0000764#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
765 buttonlight_set_brightness(global_settings.buttonlight_brightness);
766#endif
Karl Kurbjun2ac037d2007-05-14 04:44:55 +0000767#ifdef HAVE_BUTTON_LIGHT
Jens Arnold5f1ec302007-10-07 15:02:02 +0000768 buttonlight_set_timeout(global_settings.buttonlight_timeout);
Hristo Kovachev9b83c6c2005-12-22 10:43:36 +0000769#endif
Nils Wallménius0bfa3e72007-08-01 08:50:44 +0000770#ifndef HAVE_FLASH_STORAGE
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000771 ata_spindown(global_settings.disk_spindown);
Nils Wallménius0bfa3e72007-08-01 08:50:44 +0000772#endif
Jens Arnold8051a0b2005-11-06 23:12:11 +0000773#if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
Linus Nielsen Feltzingc22b4112003-11-03 23:36:36 +0000774 dac_line_in(global_settings.line_in);
775#endif
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000776 set_poweroff_timeout(global_settings.poweroff);
Björn Stenbergdea31222002-10-08 15:42:40 +0000777
Uwe Freese0bf70e62002-12-16 22:58:48 +0000778 set_battery_capacity(global_settings.battery_capacity);
Jens Arnold91846a12005-01-30 16:25:46 +0000779#if BATTERY_TYPES_COUNT > 1
780 set_battery_type(global_settings.battery_type);
781#endif
Uwe Freese0bf70e62002-12-16 22:58:48 +0000782
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +0000783#ifdef HAVE_LCD_BITMAP
Björn Stenbergb1079202003-02-27 14:22:30 +0000784 lcd_set_invert_display(global_settings.invert);
Jörg Hohensohna5e1d062003-12-20 10:00:37 +0000785 lcd_set_flip(global_settings.flip_display);
786 button_set_flip(global_settings.flip_display);
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000787 lcd_update(); /* refresh after flipping the screen */
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +0000788 settings_apply_pm_range();
789 peak_meter_init_times(
Kevin Ferrarecbbdc952005-11-04 07:18:36 +0000790 global_settings.peak_meter_release, global_settings.peak_meter_hold,
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +0000791 global_settings.peak_meter_clip_hold);
792#endif
793
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000794 if (read_disk)
795 {
Jonathan Gordon5a169bb2008-06-23 06:04:17 +0000796
797#ifdef HAVE_LCD_BITMAP
798 /* fonts need to be loaded before the WPS */
799 if ( global_settings.font_file[0]) {
800 snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
801 global_settings.font_file);
802 font_load(buf);
803 }
804 else
805 font_reset();
806
807 if ( global_settings.kbd_file[0]) {
808 snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.kbd",
809 global_settings.kbd_file);
810 load_kbd(buf);
811 }
812 else
813 load_kbd(NULL);
814#endif
Jens Arnold02978732006-11-13 00:45:21 +0000815#if LCD_DEPTH > 1
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000816 unload_wps_backdrop();
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000817#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000818#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000819 unload_remote_wps_backdrop();
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000820#endif
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000821 if ( global_settings.wps_file[0] &&
822 global_settings.wps_file[0] != 0xff ) {
823 snprintf(buf, sizeof buf, WPS_DIR "/%s.wps",
824 global_settings.wps_file);
Dave Chapmand02c79c2008-03-21 19:38:00 +0000825 wps_data_load(gui_wps[0].data, &screens[0], buf, true);
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000826 }
827 else
828 {
829 wps_data_init(gui_wps[0].data);
Nicolas Pennequin2a2b8d82007-04-25 13:09:56 +0000830#ifdef HAVE_REMOTE_LCD
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000831 gui_wps[0].data->remote_wps = false;
Nicolas Pennequin2a2b8d82007-04-25 13:09:56 +0000832#endif
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000833 }
Christi Scarborough4c0b83f2005-11-17 20:14:59 +0000834
Jens Arnold02978732006-11-13 00:45:21 +0000835#if LCD_DEPTH > 1
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000836 if ( global_settings.backdrop_file[0] &&
837 global_settings.backdrop_file[0] != 0xff ) {
838 snprintf(buf, sizeof buf, BACKDROP_DIR "/%s.bmp",
839 global_settings.backdrop_file);
840 load_main_backdrop(buf);
841 } else {
842 unload_main_backdrop();
843 }
844 show_main_backdrop();
Greg Whitee4ef26c2007-01-17 09:49:42 +0000845#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000846#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000847 show_remote_main_backdrop();
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000848#endif
Greg Whitee4ef26c2007-01-17 09:49:42 +0000849
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000850#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
851 if ( global_settings.rwps_file[0]) {
852 snprintf(buf, sizeof buf, WPS_DIR "/%s.rwps",
853 global_settings.rwps_file);
Dave Chapmand02c79c2008-03-21 19:38:00 +0000854 wps_data_load(gui_wps[1].data, &screens[1], buf, true);
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000855 }
856 else
857 {
858 wps_data_init(gui_wps[1].data);
859 gui_wps[1].data->remote_wps = true;
860 }
861#endif
Jonathan Gordone1ba7f72008-03-06 07:03:14 +0000862 if ( global_settings.lang_file[0]) {
863 snprintf(buf, sizeof buf, LANG_DIR "/%s.lng",
864 global_settings.lang_file);
865 lang_load(buf);
866 talk_init(); /* use voice of same language */
867 }
868 /* load the icon set */
869 icons_init();
870
871#ifdef HAVE_LCD_COLOR
872 if (global_settings.colors_file[0])
873 read_color_theme_file();
874#endif
875 }
876
Jens Arnold02978732006-11-13 00:45:21 +0000877#ifdef HAVE_LCD_COLOR
Dave Chapman603f87f2006-02-26 02:48:05 +0000878 screens[SCREEN_MAIN].set_foreground(global_settings.fg_color);
879 screens[SCREEN_MAIN].set_background(global_settings.bg_color);
Nicolas Pennequinf3b015f2007-09-27 15:42:55 +0000880 screens[SCREEN_MAIN].set_selector_start(global_settings.lss_color);
881 screens[SCREEN_MAIN].set_selector_end(global_settings.lse_color);
882 screens[SCREEN_MAIN].set_selector_text(global_settings.lst_color);
Dave Chapmand9e5b672006-02-02 20:42:56 +0000883#endif
884
Jonathan Gordond6a5f622008-03-06 07:54:19 +0000885#ifdef HAVE_LCD_BITMAP
Björn Stenberga2e98c12002-12-12 15:20:37 +0000886 lcd_scroll_step(global_settings.scroll_step);
Tomas Salfischberger7fa39df2006-01-22 01:42:05 +0000887 gui_list_screen_scroll_step(global_settings.screen_scroll_step);
888 gui_list_screen_scroll_out_of_view(global_settings.offset_out_of_view);
Kjell Ericson53f156a2003-05-22 06:42:14 +0000889#else
890 lcd_jump_scroll(global_settings.jump_scroll);
Jonathan Gordon282b3902007-02-21 13:34:45 +0000891 lcd_jump_scroll_delay(global_settings.jump_scroll_delay);
Björn Stenbergdea31222002-10-08 15:42:40 +0000892#endif
Björn Stenbergf0d02aa2003-02-12 09:07:48 +0000893 lcd_bidir_scroll(global_settings.bidir_limit);
Jonathan Gordon282b3902007-02-21 13:34:45 +0000894 lcd_scroll_delay(global_settings.scroll_delay);
Björn Stenberg227253c2002-10-09 23:13:25 +0000895
Linus Nielsen Feltzing6271b2b2005-06-09 09:47:00 +0000896
Marcoen Hirschbergb0fee172005-12-06 13:27:15 +0000897 set_codepage(global_settings.default_codepage);
898
Jens Arnoldd6c05452005-08-29 21:15:27 +0000899#if CONFIG_CODEC == SWCODEC
Miika Pekkarinen90161c92005-07-22 16:46:27 +0000900 audio_set_crossfade(global_settings.crossfade);
Michael Sevakisd4e904b2007-02-24 17:06:36 +0000901 dsp_set_replaygain();
Marcoen Hirschberge13fad32005-11-14 21:56:56 +0000902 dsp_set_crossfeed(global_settings.crossfeed);
Thom Johansen8238b492006-04-11 13:49:05 +0000903 dsp_set_crossfeed_direct_gain(global_settings.crossfeed_direct_gain);
904 dsp_set_crossfeed_cross_params(global_settings.crossfeed_cross_gain,
Thom Johansen8e6e2902007-03-07 15:06:33 +0000905 global_settings.crossfeed_hf_attenuation,
Thom Johansen8238b492006-04-11 13:49:05 +0000906 global_settings.crossfeed_hf_cutoff);
Dan Everton91db3682006-03-27 21:20:35 +0000907
Dan Evertonfc47f142007-04-11 09:13:13 +0000908 /* Configure software equalizer, hardware eq is handled in audio_init() */
Dan Evertondaebff82006-03-28 21:19:30 +0000909 dsp_set_eq(global_settings.eq_enabled);
Zakk Roberts8bdd92b2006-03-30 05:56:19 +0000910 dsp_set_eq_precut(global_settings.eq_precut);
Dan Everton5a1d77d2006-02-17 19:56:22 +0000911 for(i = 0; i < 5; i++) {
Dan Evertondaebff82006-03-28 21:19:30 +0000912 dsp_set_eq_coefs(i);
Dan Everton5a1d77d2006-02-17 19:56:22 +0000913 }
Thom Johansen35477002006-10-27 20:41:33 +0000914
915 dsp_dither_enable(global_settings.dithering_enabled);
Linus Nielsen Feltzing6271b2b2005-06-09 09:47:00 +0000916#endif
Linus Nielsen Feltzing8782bc82005-07-01 09:42:39 +0000917
918#ifdef HAVE_SPDIF_POWER
919 spdif_power_enable(global_settings.spdif_enable);
920#endif
Björn Stenbergda5fb182006-03-24 13:47:24 +0000921
Jens Arnold47bf6c52007-04-12 22:12:13 +0000922#ifdef HAVE_BACKLIGHT
Björn Stenbergda5fb182006-03-24 13:47:24 +0000923 set_backlight_filter_keypress(global_settings.bl_filter_first_keypress);
Hristo Kovacheva70c6b92006-03-25 19:16:45 +0000924#ifdef HAVE_REMOTE_LCD
925 set_remote_backlight_filter_keypress(global_settings.remote_bl_filter_first_keypress);
926#endif
Rani Hodc9f59e62006-08-08 22:03:56 +0000927#ifdef HAS_BUTTON_HOLD
928 backlight_set_on_button_hold(global_settings.backlight_on_button_hold);
Björn Stenbergda5fb182006-03-24 13:47:24 +0000929#endif
Michael Sevakis009cebe2008-05-14 19:29:25 +0000930#ifdef HAVE_LCD_SLEEP_SETTING
Rani Hodc9f59e62006-08-08 22:03:56 +0000931 lcd_set_sleep_after_backlight_off(global_settings.lcd_sleep_after_backlight_off);
932#endif
Jens Arnold47bf6c52007-04-12 22:12:13 +0000933#endif /* HAVE_BACKLIGHT */
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000934
Michael Sevakisc541e042008-05-29 21:27:44 +0000935#ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
936 touchpad_set_sensitivity(global_settings.touchpad_sensitivity);
937#endif
938
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000939 /* This should stay last */
940#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
941 enc_global_settings_apply();
942#endif
Jonathan Gordonbe185a12008-03-26 09:05:42 +0000943 list_init_viewports(NULL);
Linus Nielsen Feltzing40ffbb12002-10-03 09:31:01 +0000944}
945
Björn Stenbergc5aaab42003-03-10 16:31:02 +0000946
Björn Stenbergf80d8a702002-06-27 00:20:00 +0000947/*
Kevin Ferrarecbbdc952005-11-04 07:18:36 +0000948 * reset all settings to their default value
Björn Stenbergf80d8a702002-06-27 00:20:00 +0000949 */
Stéphane Doyonb2aa86a2008-04-20 14:12:28 +0000950void reset_setting(const struct settings_list *setting, void *var)
951{
952 switch (setting->flags&F_T_MASK)
953 {
954 case F_T_INT:
955 case F_T_UINT:
956 if (setting->flags&F_DEF_ISFUNC)
957 *(int*)var = setting->default_val.func();
958 else if (setting->flags&F_T_SOUND)
959 *(int*)var = sound_default(setting->sound_setting->setting);
960 else *(int*)var = setting->default_val.int_;
961 break;
962 case F_T_BOOL:
963 *(bool*)var = setting->default_val.bool_;
964 break;
965 case F_T_CHARPTR:
966 case F_T_UCHARPTR:
967 strncpy((char*)var, setting->default_val.charptr,
968 setting->filename_setting->max_len);
969 break;
970 }
971}
972
973void settings_reset(void)
Steve Bavincd88e2a2008-03-25 15:24:03 +0000974{
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000975 int i;
Jonathan Gordon01583362008-03-25 12:42:47 +0000976
Jonathan Gordonb2e50902007-01-23 13:40:44 +0000977 for(i=0; i<nb_settings; i++)
Stéphane Doyonb2aa86a2008-04-20 14:12:28 +0000978 reset_setting(&settings[i], settings[i].setting);
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000979#if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
980 enc_global_settings_reset();
981#endif
Björn Stenbergf80d8a702002-06-27 00:20:00 +0000982}
Björn Stenberg60b356e2002-06-27 01:08:11 +0000983
Jonathan Gordon41bd24e2007-01-29 13:18:57 +0000984/** Changing setting values **/
Steve Bavincd88e2a2008-03-25 15:24:03 +0000985const struct settings_list* find_setting(const void* variable, int *id)
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000986{
987 int i;
988 for(i=0;i<nb_settings;i++)
989 {
990 if (settings[i].setting == variable)
Jonathan Gordonfe3cfcc2007-02-08 10:28:42 +0000991 {
992 if (id)
993 *id = i;
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000994 return &settings[i];
Jonathan Gordonfe3cfcc2007-02-08 10:28:42 +0000995 }
Jonathan Gordon4718a1e2007-02-08 04:33:41 +0000996 }
997 return NULL;
998}
Paul Loudenf7c938a2008-02-05 09:09:38 +0000999
Steve Bavincd88e2a2008-03-25 15:24:03 +00001000bool set_bool(const char* string, const bool* variable )
Björn Stenberg60b356e2002-06-27 01:08:11 +00001001{
Jens Arnold49608082005-10-16 11:15:51 +00001002 return set_bool_options(string, variable,
Daniel Stenbergf981ea92005-12-05 22:44:42 +00001003 (char *)STR(LANG_SET_BOOL_YES),
1004 (char *)STR(LANG_SET_BOOL_NO),
1005 NULL);
Björn Stenberg26712d52003-06-05 11:11:10 +00001006}
1007
Björn Stenberg60b356e2002-06-27 01:08:11 +00001008
Steve Bavincd88e2a2008-03-25 15:24:03 +00001009bool set_bool_options(const char* string, const bool* variable,
Steve Bavin135cc752008-03-28 12:51:33 +00001010 const char* yes_str, int yes_voice,
1011 const char* no_str, int no_voice,
Jörg Hohensohn42ffbf92004-03-15 08:27:51 +00001012 void (*function)(bool))
Eric Linenbergc5b645b2002-09-05 04:42:12 +00001013{
Daniel Stenbergf981ea92005-12-05 22:44:42 +00001014 struct opt_items names[] = {
Steve Bavincd88e2a2008-03-25 15:24:03 +00001015 {(unsigned const char *)no_str, no_voice},
1016 {(unsigned const char *)yes_str, yes_voice}
Daniel Stenbergf981ea92005-12-05 22:44:42 +00001017 };
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001018 bool result;
1019
Kevin Ferrarecbbdc952005-11-04 07:18:36 +00001020 result = set_option(string, variable, BOOL, names, 2,
Jonathan Gordona5278fa2007-07-11 05:41:23 +00001021 (void (*)(int))function);
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001022 return result;
Björn Stenberg60b356e2002-06-27 01:08:11 +00001023}
1024
Daniel Stenbergf981ea92005-12-05 22:44:42 +00001025bool set_int(const unsigned char* string,
Jens Arnold8fb33612004-08-18 01:09:31 +00001026 const char* unit,
Steve Bavin135cc752008-03-28 12:51:33 +00001027 int voice_unit,
Steve Bavincd88e2a2008-03-25 15:24:03 +00001028 const int* variable,
Björn Stenberg60b356e2002-06-27 01:08:11 +00001029 void (*function)(int),
Steve Bavin135cc752008-03-28 12:51:33 +00001030 int step,
1031 int min,
1032 int max,
Nils Wallménius9b591832007-08-19 10:22:46 +00001033 void (*formatter)(char*, size_t, int, const char*) )
Björn Stenberg60b356e2002-06-27 01:08:11 +00001034{
Jonathan Gordonfb628312007-02-12 14:22:35 +00001035 return set_int_ex(string, unit, voice_unit, variable, function,
1036 step, min, max, formatter, NULL);
Björn Stenberg60b356e2002-06-27 01:08:11 +00001037}
Björn Stenberg26712d52003-06-05 11:11:10 +00001038
Steve Bavincd88e2a2008-03-25 15:24:03 +00001039bool set_int_ex(const unsigned char* string,
1040 const char* unit,
Steve Bavin135cc752008-03-28 12:51:33 +00001041 int voice_unit,
Steve Bavincd88e2a2008-03-25 15:24:03 +00001042 const int* variable,
1043 void (*function)(int),
Steve Bavin135cc752008-03-28 12:51:33 +00001044 int step,
1045 int min,
1046 int max,
Steve Bavincd88e2a2008-03-25 15:24:03 +00001047 void (*formatter)(char*, size_t, int, const char*),
1048 int32_t (*get_talk_id)(int, int))
1049{
1050 (void)unit;
1051 struct settings_list item;
1052 struct int_setting data = {
1053 function, voice_unit, min, max, step,
1054 formatter, get_talk_id
1055 };
1056 item.int_setting = &data;
1057 item.flags = F_INT_SETTING|F_T_INT;
1058 item.lang_id = -1;
1059 item.cfg_vals = (char*)string;
1060 item.setting = (void *)variable;
Jonathan Gordonfe9dca32008-04-23 11:07:40 +00001061 return option_screen(&item, NULL, false, NULL);
Steve Bavincd88e2a2008-03-25 15:24:03 +00001062}
Markus Braun3181f682002-08-09 12:38:45 +00001063
Jonathan Gordon41bd24e2007-01-29 13:18:57 +00001064
Steve Bavincd88e2a2008-03-25 15:24:03 +00001065static const struct opt_items *set_option_options;
1066static void set_option_formatter(char* buf, size_t size, int item, const char* unit)
1067{
1068 (void)unit;
1069 const unsigned char *text = set_option_options[item].string;
1070 snprintf(buf, size, "%s", P2STR(text));
1071}
1072static int32_t set_option_get_talk_id(int value, int unit)
1073{
1074 (void)unit;
1075 return set_option_options[value].voice_id;
1076}
Steve Bavin135cc752008-03-28 12:51:33 +00001077bool set_option(const char* string, const void* variable, enum optiontype type,
Steve Bavincd88e2a2008-03-25 15:24:03 +00001078 const struct opt_items* options,
Steve Bavin135cc752008-03-28 12:51:33 +00001079 int numoptions, void (*function)(int))
Steve Bavincd88e2a2008-03-25 15:24:03 +00001080{
1081 int temp;
1082 struct settings_list item;
1083 struct int_setting data = {
1084 function, UNIT_INT, 0, numoptions-1, 1,
1085 set_option_formatter, set_option_get_talk_id
1086 };
1087 set_option_options = options;
1088 item.int_setting = &data;
1089 item.flags = F_INT_SETTING|F_T_INT;
1090 item.lang_id = -1;
1091 item.cfg_vals = (char*)string;
1092 item.setting = &temp;
1093 if (type == BOOL)
1094 temp = *(bool*)variable? 1: 0;
1095 else
1096 temp = *(int*)variable;
Jonathan Gordonfe9dca32008-04-23 11:07:40 +00001097 if (!option_screen(&item, NULL, false, NULL))
Steve Bavincd88e2a2008-03-25 15:24:03 +00001098 {
1099 if (type == BOOL)
1100 *(bool*)variable = (temp == 1? true: false);
1101 else
1102 *(int*)variable = temp;
1103 return false;
1104 }
1105 return true;
1106}
1107
1108
Steve Bavin135cc752008-03-28 12:51:33 +00001109void set_file(const char* filename, char* setting, int maxlen)
Jonathan Gordon41bd24e2007-01-29 13:18:57 +00001110{
1111 char* fptr = strrchr(filename,'/');
1112 int len;
1113 int extlen = 0;
1114 char* ptr;
1115
1116 if (!fptr)
1117 return;
1118
1119 *fptr = 0;
1120 fptr++;
1121
1122 len = strlen(fptr);
1123 ptr = fptr + len;
1124 while ((*ptr != '.') && (ptr != fptr)) {
1125 extlen++;
1126 ptr--;
1127 }
1128 if(ptr == fptr) extlen = 0;
1129
1130 if (strncasecmp(ROCKBOX_DIR, filename ,strlen(ROCKBOX_DIR)) ||
1131 (len-extlen > maxlen))
1132 return;
1133
1134 strncpy(setting, fptr, len-extlen);
1135 setting[len-extlen]=0;
1136
1137 settings_save();
1138}
1139