summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-10-08 15:42:40 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-10-08 15:42:40 +0000
commitdea31222b8318cd992f97cfe81b9c2239233f884 (patch)
treed7a0d7fcc0b34249322964d55b3cc6f6b2e7d3bd
parentb9d6830eddfa460d573f8af2020d17a9431dc056 (diff)
downloadrockbox-dea31222b8318cd992f97cfe81b9c2239233f884.tar.gz
rockbox-dea31222b8318cd992f97cfe81b9c2239233f884.zip
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
-rw-r--r--apps/main.c3
-rw-r--r--apps/settings.c32
-rw-r--r--apps/settings.h5
-rw-r--r--apps/tree.c32
-rw-r--r--apps/wps-display.c13
-rw-r--r--apps/wps-display.h2
-rw-r--r--firmware/font.c4
7 files changed, 75 insertions, 16 deletions
diff --git a/apps/main.c b/apps/main.c
index 15bb73e971..d51b606d86 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -47,6 +47,7 @@
47#include "sprintf.h" 47#include "sprintf.h"
48#include "font.h" 48#include "font.h"
49#include "language.h" 49#include "language.h"
50#include "wps-display.h"
50 51
51char appsversion[]=APPSVERSION; 52char appsversion[]=APPSVERSION;
52 53
@@ -68,6 +69,7 @@ void init(void)
68 show_logo(); 69 show_logo();
69 settings_reset(); 70 settings_reset();
70 settings_load(); 71 settings_load();
72 wps_load(ROCKBOX_DIR "/default.wps", false);
71 font_load(ROCKBOX_DIR "/default.fnt"); 73 font_load(ROCKBOX_DIR "/default.fnt");
72 lang_load(ROCKBOX_DIR "/default.lng"); 74 lang_load(ROCKBOX_DIR "/default.lng");
73 sleep(HZ/2); 75 sleep(HZ/2);
@@ -147,6 +149,7 @@ void init(void)
147 } 149 }
148 150
149 settings_load(); 151 settings_load();
152 wps_load(ROCKBOX_DIR "/default.wps", false);
150 font_load(ROCKBOX_DIR "/default.fnt"); 153 font_load(ROCKBOX_DIR "/default.fnt");
151 lang_load(ROCKBOX_DIR "/default.lng"); 154 lang_load(ROCKBOX_DIR "/default.lng");
152 155
diff --git a/apps/settings.c b/apps/settings.c
index 067cc3eae4..f03c1e888b 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -45,8 +45,9 @@
45#include "icons.h" 45#include "icons.h"
46#include "font.h" 46#include "font.h"
47#endif 47#endif
48
49#include "lang.h" 48#include "lang.h"
49#include "language.h"
50#include "wps-display.h"
50 51
51struct user_settings global_settings; 52struct user_settings global_settings;
52char rockboxdir[] = ROCKBOX_DIR; /* config/font/data file directory */ 53char rockboxdir[] = ROCKBOX_DIR; /* config/font/data file directory */
@@ -112,6 +113,9 @@ modified unless the header & checksum test fails.
112 113
113Rest of config block, only saved to disk: 114Rest of config block, only saved to disk:
114 115
1160xB8 (char[20]) WPS file
1170xCC (char[20]) Lang file
1180xE0 (char[20]) Font file
1150xF4 (int) Playlist first index 1190xF4 (int) Playlist first index
1160xF8 (int) Playlist shuffle seed 1200xF8 (int) Playlist shuffle seed
1170xFC (char[260]) Resume playlist (path/to/dir or path/to/playlist.m3u) 1210xFC (char[260]) Resume playlist (path/to/dir or path/to/playlist.m3u)
@@ -313,6 +317,9 @@ int settings_save( void )
313 317
314 memcpy(&config_block[0x24], &global_settings.total_uptime, 4); 318 memcpy(&config_block[0x24], &global_settings.total_uptime, 4);
315 319
320 strncpy(&config_block[0xb8], global_settings.wps_file, MAX_FILENAME);
321 strncpy(&config_block[0xcc], global_settings.lang_file, MAX_FILENAME);
322 strncpy(&config_block[0xe0], global_settings.font_file, MAX_FILENAME);
316 memcpy(&config_block[0xF4], &global_settings.resume_first_index, 4); 323 memcpy(&config_block[0xF4], &global_settings.resume_first_index, 4);
317 memcpy(&config_block[0xF8], &global_settings.resume_seed, 4); 324 memcpy(&config_block[0xF8], &global_settings.resume_seed, 4);
318 325
@@ -345,6 +352,8 @@ int settings_save( void )
345 352
346void settings_apply(void) 353void settings_apply(void)
347{ 354{
355 char buf[64];
356
348 mpeg_sound_set(SOUND_BASS, global_settings.bass); 357 mpeg_sound_set(SOUND_BASS, global_settings.bass);
349 mpeg_sound_set(SOUND_TREBLE, global_settings.treble); 358 mpeg_sound_set(SOUND_TREBLE, global_settings.treble);
350 mpeg_sound_set(SOUND_BALANCE, global_settings.balance); 359 mpeg_sound_set(SOUND_BALANCE, global_settings.balance);
@@ -367,6 +376,24 @@ void settings_apply(void)
367#ifdef HAVE_CHARGE_CTRL 376#ifdef HAVE_CHARGE_CTRL
368 charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI; 377 charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
369#endif 378#endif
379
380 if ( global_settings.wps_file[0] ) {
381 snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.wps",
382 global_settings.wps_file);
383 wps_load(buf, false);
384 }
385#ifdef HAVE_LCD_BITMAP
386 if ( global_settings.font_file[0] ) {
387 snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.fnt",
388 global_settings.font_file);
389 font_load(buf);
390 }
391#endif
392 if ( global_settings.lang_file[0] ) {
393 snprintf(buf, sizeof buf, ROCKBOX_DIR "/%s.lng",
394 global_settings.lang_file);
395 lang_load(buf);
396 }
370} 397}
371 398
372/* 399/*
@@ -473,6 +500,9 @@ void settings_load(void)
473 memcpy(&global_settings.resume_first_index, &config_block[0xF4], 4); 500 memcpy(&global_settings.resume_first_index, &config_block[0xF4], 4);
474 memcpy(&global_settings.resume_seed, &config_block[0xF8], 4); 501 memcpy(&global_settings.resume_seed, &config_block[0xF8], 4);
475 502
503 strncpy(global_settings.wps_file, &config_block[0xb8], MAX_FILENAME);
504 strncpy(global_settings.lang_file, &config_block[0xcc], MAX_FILENAME);
505 strncpy(global_settings.font_file, &config_block[0xe0], MAX_FILENAME);
476 strncpy(global_settings.resume_file, &config_block[0xFC], MAX_PATH); 506 strncpy(global_settings.resume_file, &config_block[0xFC], MAX_PATH);
477 global_settings.resume_file[MAX_PATH]=0; 507 global_settings.resume_file[MAX_PATH]=0;
478 } 508 }
diff --git a/apps/settings.h b/apps/settings.h
index f5609fe75c..c2f5c925fb 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -25,6 +25,8 @@
25 25
26#define ROCKBOX_DIR "/.rockbox" 26#define ROCKBOX_DIR "/.rockbox"
27 27
28#define MAX_FILENAME 20
29
28/* data structures */ 30/* data structures */
29 31
30#define RESUME_OFF 0 32#define RESUME_OFF 0
@@ -75,6 +77,9 @@ struct user_settings
75 int resume_seed; /* random seed for playlist shuffle */ 77 int resume_seed; /* random seed for playlist shuffle */
76 int resume_first_index; /* first index of playlist */ 78 int resume_first_index; /* first index of playlist */
77 unsigned char resume_file[MAX_PATH+1]; /* playlist name (or dir) */ 79 unsigned char resume_file[MAX_PATH+1]; /* playlist name (or dir) */
80 unsigned char font_file[MAX_FILENAME+1]; /* last font */
81 unsigned char wps_file[MAX_FILENAME+1]; /* last wps */
82 unsigned char lang_file[MAX_FILENAME+1]; /* last language */
78 83
79 /* misc options */ 84 /* misc options */
80 85
diff --git a/apps/tree.c b/apps/tree.c
index e5c515f06b..6e52942b45 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -658,6 +658,26 @@ bool pageupdown(int* ds, int* dc, int numentries, int tree_max_on_screen )
658} 658}
659#endif 659#endif
660 660
661static void storefile(char* filename, char* setting, int maxlen)
662{
663 int len = strlen(filename);
664 int extlen = 0;
665 char* ptr = filename + len;
666
667 while (*ptr != '.') {
668 extlen++;
669 ptr--;
670 }
671
672 if (strcmp(ROCKBOX_DIR, currdir) || (len > maxlen-extlen))
673 return;
674
675 strncpy(setting, filename, len-extlen);
676 setting[len-extlen]=0;
677
678 settings_save();
679}
680
661bool dirbrowse(char *root) 681bool dirbrowse(char *root)
662{ 682{
663 int numentries=0; 683 int numentries=0;
@@ -771,6 +791,7 @@ bool dirbrowse(char *root)
771 int seed = current_tick; 791 int seed = current_tick;
772 bool play = false; 792 bool play = false;
773 int start_index=0; 793 int start_index=0;
794
774 lcd_stop_scroll(); 795 lcd_stop_scroll();
775 switch ( file->attr & TREE_ATTR_MASK ) { 796 switch ( file->attr & TREE_ATTR_MASK ) {
776 case TREE_ATTR_M3U: 797 case TREE_ATTR_M3U:
@@ -802,7 +823,9 @@ bool dirbrowse(char *root)
802 case TREE_ATTR_WPS: 823 case TREE_ATTR_WPS:
803 snprintf(buf, sizeof buf, "%s/%s", 824 snprintf(buf, sizeof buf, "%s/%s",
804 currdir, file->name); 825 currdir, file->name);
805 wps_load_custom(buf); 826 wps_load(buf,true);
827 storefile(file->name, global_settings.wps_file,
828 MAX_FILENAME);
806 restore = true; 829 restore = true;
807 break; 830 break;
808 831
@@ -824,6 +847,10 @@ bool dirbrowse(char *root)
824 snprintf(buf, sizeof buf, "%s/%s", 847 snprintf(buf, sizeof buf, "%s/%s",
825 currdir, file->name); 848 currdir, file->name);
826 if(!lang_load(buf)) { 849 if(!lang_load(buf)) {
850 storefile(file->name,
851 global_settings.lang_file,
852 MAX_FILENAME);
853
827 lcd_clear_display(); 854 lcd_clear_display();
828#ifdef HAVE_LCD_CHARCELLS 855#ifdef HAVE_LCD_CHARCELLS
829 lcd_puts(0, 0, str(LANG_LANGUAGE_LOADED)); 856 lcd_puts(0, 0, str(LANG_LANGUAGE_LOADED));
@@ -849,6 +876,9 @@ bool dirbrowse(char *root)
849 snprintf(buf, sizeof buf, "%s/%s", 876 snprintf(buf, sizeof buf, "%s/%s",
850 currdir, file->name); 877 currdir, file->name);
851 font_load(buf); 878 font_load(buf);
879 storefile(file->name, global_settings.font_file,
880 MAX_FILENAME);
881
852 lcd_getstringsize("A", &fw, &fh); 882 lcd_getstringsize("A", &fw, &fh);
853 tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh; 883 tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
854 /* make sure cursor is on screen */ 884 /* make sure cursor is on screen */
diff --git a/apps/wps-display.c b/apps/wps-display.c
index 3f94a09b9e..b629a06c4e 100644
--- a/apps/wps-display.c
+++ b/apps/wps-display.c
@@ -111,20 +111,13 @@ static void wps_format(char* fmt)
111 } 111 }
112} 112}
113 113
114bool wps_load_custom(char* file) 114bool wps_load(char* file, bool display)
115{ 115{
116 char buffer[FORMAT_BUFFER_SIZE]; 116 char buffer[FORMAT_BUFFER_SIZE];
117 int fd; 117 int fd;
118 bool special = true;
119 118
120 wps_loaded = true; 119 wps_loaded = true;
121 120
122 /* default wps file? */
123 if (!file) {
124 file = WPS_CONFIG;
125 special = false;
126 }
127
128 fd = open(file, O_RDONLY); 121 fd = open(file, O_RDONLY);
129 122
130 if (-1 != fd) 123 if (-1 != fd)
@@ -139,7 +132,7 @@ bool wps_load_custom(char* file)
139 132
140 close(fd); 133 close(fd);
141 134
142 if ( special ) { 135 if ( display ) {
143 int i; 136 int i;
144 lcd_clear_display(); 137 lcd_clear_display();
145#ifdef HAVE_LCD_BITMAP 138#ifdef HAVE_LCD_BITMAP
@@ -640,8 +633,6 @@ void wps_display(struct mp3entry* id3)
640 else 633 else
641 { 634 {
642 if (!wps_loaded) { 635 if (!wps_loaded) {
643 wps_load_custom(NULL);
644
645 if ( !format_buffer[0] ) { 636 if ( !format_buffer[0] ) {
646#ifdef HAVE_LCD_BITMAP 637#ifdef HAVE_LCD_BITMAP
647 wps_format("%s%fp\n" 638 wps_format("%s%fp\n"
diff --git a/apps/wps-display.h b/apps/wps-display.h
index a62817edad..439660e831 100644
--- a/apps/wps-display.h
+++ b/apps/wps-display.h
@@ -24,7 +24,7 @@
24 24
25bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_scroll); 25bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_scroll);
26void wps_display(struct mp3entry* id3); 26void wps_display(struct mp3entry* id3);
27bool wps_load_custom(char* file); 27bool wps_load(char* file, bool display);
28 28
29#ifdef HAVE_LCD_CHARCELLS 29#ifdef HAVE_LCD_CHARCELLS
30bool draw_player_progress(struct mp3entry* id3, int ff_rewind_count); 30bool draw_player_progress(struct mp3entry* id3, int ff_rewind_count);
diff --git a/firmware/font.c b/firmware/font.c
index 72c7085b7a..6f5156cc73 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -125,8 +125,6 @@ struct font* font_load(char *path)
125 char copyright[256+1]; 125 char copyright[256+1];
126 struct font* pf = &font_ui; 126 struct font* pf = &font_ui;
127 127
128 memset(pf, 0, sizeof(struct font));
129
130 /* open and read entire font file*/ 128 /* open and read entire font file*/
131 fd = open(path, O_RDONLY|O_BINARY); 129 fd = open(path, O_RDONLY|O_BINARY);
132 if (fd < 0) { 130 if (fd < 0) {
@@ -134,6 +132,8 @@ struct font* font_load(char *path)
134 return NULL; 132 return NULL;
135 } 133 }
136 134
135 memset(pf, 0, sizeof(struct font));
136
137 /* currently, font loading replaces earlier font allocation*/ 137 /* currently, font loading replaces earlier font allocation*/
138 freeptr = (unsigned char *)(((int)mbuf + 3) & ~3); 138 freeptr = (unsigned char *)(((int)mbuf + 3) & ~3);
139 139