Added persistence of last .wps, .fnt and .lng file played in /.rockbox
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2535 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/main.c b/apps/main.c
index 15bb73e..d51b606 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -47,6 +47,7 @@
#include "sprintf.h"
#include "font.h"
#include "language.h"
+#include "wps-display.h"
char appsversion[]=APPSVERSION;
@@ -68,6 +69,7 @@
show_logo();
settings_reset();
settings_load();
+ wps_load(ROCKBOX_DIR "/default.wps", false);
font_load(ROCKBOX_DIR "/default.fnt");
lang_load(ROCKBOX_DIR "/default.lng");
sleep(HZ/2);
@@ -147,6 +149,7 @@
}
settings_load();
+ wps_load(ROCKBOX_DIR "/default.wps", false);
font_load(ROCKBOX_DIR "/default.fnt");
lang_load(ROCKBOX_DIR "/default.lng");
diff --git a/apps/settings.c b/apps/settings.c
index 067cc3e..f03c1e8 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -45,8 +45,9 @@
#include "icons.h"
#include "font.h"
#endif
-
#include "lang.h"
+#include "language.h"
+#include "wps-display.h"
struct user_settings global_settings;
char rockboxdir[] = ROCKBOX_DIR; /* config/font/data file directory */
@@ -112,6 +113,9 @@
Rest of config block, only saved to disk:
+0xB8 (char[20]) WPS file
+0xCC (char[20]) Lang file
+0xE0 (char[20]) Font file
0xF4 (int) Playlist first index
0xF8 (int) Playlist shuffle seed
0xFC (char[260]) Resume playlist (path/to/dir or path/to/playlist.m3u)
@@ -313,6 +317,9 @@
memcpy(&config_block[0x24], &global_settings.total_uptime, 4);
+ strncpy(&config_block[0xb8], global_settings.wps_file, MAX_FILENAME);
+ strncpy(&config_block[0xcc], global_settings.lang_file, MAX_FILENAME);
+ strncpy(&config_block[0xe0], global_settings.font_file, MAX_FILENAME);
memcpy(&config_block[0xF4], &global_settings.resume_first_index, 4);
memcpy(&config_block[0xF8], &global_settings.resume_seed, 4);
@@ -345,6 +352,8 @@
void settings_apply(void)
{
+ char buf[64];
+
mpeg_sound_set(SOUND_BASS, global_settings.bass);
mpeg_sound_set(SOUND_TREBLE, global_settings.treble);
mpeg_sound_set(SOUND_BALANCE, global_settings.balance);
@@ -367,6 +376,24 @@
#ifdef HAVE_CHARGE_CTRL
charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
#endif
+
+ if ( global_settings.wps_file[0] ) {
+ snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.wps",
+ global_settings.wps_file);
+ wps_load(buf, false);
+ }
+#ifdef HAVE_LCD_BITMAP
+ if ( global_settings.font_file[0] ) {
+ snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.fnt",
+ global_settings.font_file);
+ font_load(buf);
+ }
+#endif
+ if ( global_settings.lang_file[0] ) {
+ snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.lng",
+ global_settings.lang_file);
+ lang_load(buf);
+ }
}
/*
@@ -473,6 +500,9 @@
memcpy(&global_settings.resume_first_index, &config_block[0xF4], 4);
memcpy(&global_settings.resume_seed, &config_block[0xF8], 4);
+ strncpy(global_settings.wps_file, &config_block[0xb8], MAX_FILENAME);
+ strncpy(global_settings.lang_file, &config_block[0xcc], MAX_FILENAME);
+ strncpy(global_settings.font_file, &config_block[0xe0], MAX_FILENAME);
strncpy(global_settings.resume_file, &config_block[0xFC], MAX_PATH);
global_settings.resume_file[MAX_PATH]=0;
}
diff --git a/apps/settings.h b/apps/settings.h
index f5609fe..c2f5c92 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -25,6 +25,8 @@
#define ROCKBOX_DIR "/.rockbox"
+#define MAX_FILENAME 20
+
/* data structures */
#define RESUME_OFF 0
@@ -75,6 +77,9 @@
int resume_seed; /* random seed for playlist shuffle */
int resume_first_index; /* first index of playlist */
unsigned char resume_file[MAX_PATH+1]; /* playlist name (or dir) */
+ unsigned char font_file[MAX_FILENAME+1]; /* last font */
+ unsigned char wps_file[MAX_FILENAME+1]; /* last wps */
+ unsigned char lang_file[MAX_FILENAME+1]; /* last language */
/* misc options */
diff --git a/apps/tree.c b/apps/tree.c
index e5c515f..6e52942 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -658,6 +658,26 @@
}
#endif
+static void storefile(char* filename, char* setting, int maxlen)
+{
+ int len = strlen(filename);
+ int extlen = 0;
+ char* ptr = filename + len;
+
+ while (*ptr != '.') {
+ extlen++;
+ ptr--;
+ }
+
+ if (strcmp(ROCKBOX_DIR, currdir) || (len > maxlen-extlen))
+ return;
+
+ strncpy(setting, filename, len-extlen);
+ setting[len-extlen]=0;
+
+ settings_save();
+}
+
bool dirbrowse(char *root)
{
int numentries=0;
@@ -771,6 +791,7 @@
int seed = current_tick;
bool play = false;
int start_index=0;
+
lcd_stop_scroll();
switch ( file->attr & TREE_ATTR_MASK ) {
case TREE_ATTR_M3U:
@@ -802,7 +823,9 @@
case TREE_ATTR_WPS:
snprintf(buf, sizeof buf, "%s/%s",
currdir, file->name);
- wps_load_custom(buf);
+ wps_load(buf,true);
+ storefile(file->name, global_settings.wps_file,
+ MAX_FILENAME);
restore = true;
break;
@@ -824,6 +847,10 @@
snprintf(buf, sizeof buf, "%s/%s",
currdir, file->name);
if(!lang_load(buf)) {
+ storefile(file->name,
+ global_settings.lang_file,
+ MAX_FILENAME);
+
lcd_clear_display();
#ifdef HAVE_LCD_CHARCELLS
lcd_puts(0, 0, str(LANG_LANGUAGE_LOADED));
@@ -849,6 +876,9 @@
snprintf(buf, sizeof buf, "%s/%s",
currdir, file->name);
font_load(buf);
+ storefile(file->name, global_settings.font_file,
+ MAX_FILENAME);
+
lcd_getstringsize("A", &fw, &fh);
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
/* make sure cursor is on screen */
diff --git a/apps/wps-display.c b/apps/wps-display.c
index 3f94a09..b629a06 100644
--- a/apps/wps-display.c
+++ b/apps/wps-display.c
@@ -111,20 +111,13 @@
}
}
-bool wps_load_custom(char* file)
+bool wps_load(char* file, bool display)
{
char buffer[FORMAT_BUFFER_SIZE];
int fd;
- bool special = true;
wps_loaded = true;
- /* default wps file? */
- if (!file) {
- file = WPS_CONFIG;
- special = false;
- }
-
fd = open(file, O_RDONLY);
if (-1 != fd)
@@ -139,7 +132,7 @@
close(fd);
- if ( special ) {
+ if ( display ) {
int i;
lcd_clear_display();
#ifdef HAVE_LCD_BITMAP
@@ -640,8 +633,6 @@
else
{
if (!wps_loaded) {
- wps_load_custom(NULL);
-
if ( !format_buffer[0] ) {
#ifdef HAVE_LCD_BITMAP
wps_format("%s%fp\n"
diff --git a/apps/wps-display.h b/apps/wps-display.h
index a62817e..439660e 100644
--- a/apps/wps-display.h
+++ b/apps/wps-display.h
@@ -24,7 +24,7 @@
bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_scroll);
void wps_display(struct mp3entry* id3);
-bool wps_load_custom(char* file);
+bool wps_load(char* file, bool display);
#ifdef HAVE_LCD_CHARCELLS
bool draw_player_progress(struct mp3entry* id3, int ff_rewind_count);
diff --git a/firmware/font.c b/firmware/font.c
index 72c7085..6f5156c 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -125,8 +125,6 @@
char copyright[256+1];
struct font* pf = &font_ui;
- memset(pf, 0, sizeof(struct font));
-
/* open and read entire font file*/
fd = open(path, O_RDONLY|O_BINARY);
if (fd < 0) {
@@ -134,6 +132,8 @@
return NULL;
}
+ memset(pf, 0, sizeof(struct font));
+
/* currently, font loading replaces earlier font allocation*/
freeptr = (unsigned char *)(((int)mbuf + 3) & ~3);