From 14ba91eaa9a94411457cc396a4c7c5e39e63a00a Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Sat, 17 Feb 2007 13:36:44 +0000 Subject: A few more bookmark code tweaks. Also improves how the bookmark selection screen is displayed on Archos players. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12350 a1c6a512-1295-4272-9138-f99709370657 --- apps/bookmark.c | 104 +++++++++++++------------------------------------ apps/gui/gwps-common.c | 36 +++++------------ apps/gui/gwps-common.h | 1 - apps/misc.c | 21 ++++++++++ apps/misc.h | 9 +++++ apps/screens.c | 3 +- 6 files changed, 67 insertions(+), 107 deletions(-) (limited to 'apps') diff --git a/apps/bookmark.c b/apps/bookmark.c index 0bcdb131ca..1352b2a708 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c @@ -225,10 +225,8 @@ static bool write_bookmark(bool create_bookmark_file) } } - if (success) - gui_syncsplash(HZ, true, str(LANG_BOOKMARK_CREATE_SUCCESS)); - else - gui_syncsplash(HZ, true, str(LANG_BOOKMARK_CREATE_FAILURE)); + gui_syncsplash(HZ, true, str(success ? LANG_BOOKMARK_CREATE_SUCCESS + : LANG_BOOKMARK_CREATE_FAILURE)); return true; } @@ -380,11 +378,6 @@ bool bookmark_autoload(const char* file) fd = open(global_bookmark_file_name, O_RDONLY); if(fd<0) return false; - if(-1 == lseek(fd, 0, SEEK_END)) - { - close(fd); - return false; - } close(fd); if(global_settings.autoloadbookmark == BOOKMARK_YES) { @@ -555,16 +548,9 @@ static char* select_bookmark(const char* bookmark_file_name) case ACTION_BMS_SELECT: /* User wants to use this bookmark */ #ifdef HAVE_LCD_BITMAP - if (global_settings.statusbar) - { - FOR_NB_SCREENS(i) - screens[i].setmargins(0, STATUSBAR_HEIGHT); - } - else - { - FOR_NB_SCREENS(i) - screens[i].setmargins(0, 0); - } + FOR_NB_SCREENS(i) + screens[i].setmargins(0, global_settings.statusbar + ? STATUSBAR_HEIGHT : 0); #endif action_signalscreenchange(); return bookmark; @@ -674,8 +660,8 @@ static void display_bookmark(const char* bookmark, long ms = 0; int repeat_mode = 0; bool playlist_shuffle = false; - int len; char *dot; + char time_buf[32]; int i; /* getting the index and the time into the file */ @@ -712,49 +698,34 @@ static void display_bookmark(const char* bookmark, statusbar_icon_shuffle(); /* File Name */ - len=strlen(global_filename); - if (len>3) - dot=strrchr(global_filename + len - 4, '.'); - else - dot=NULL; + dot = strrchr(global_filename, '.'); + if (dot) *dot='\0'; + FOR_NB_SCREENS(i) screens[i].puts_scroll(0, 0, (unsigned char *)global_filename); + if (dot) *dot='.'; /* bookmark number */ - snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %2d/%2d", + snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %d/%d", str(LANG_BOOKMARK_SELECT_BOOKMARK_TEXT), bookmark_id + 1, bookmark_count); FOR_NB_SCREENS(i) screens[i].puts_scroll(0, 1, (unsigned char *)global_temp_buffer); /* bookmark resume index */ - snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %2d", + snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %d", str(LANG_BOOKMARK_SELECT_INDEX_TEXT), resume_index+1); FOR_NB_SCREENS(i) screens[i].puts_scroll(0, 2, (unsigned char *)global_temp_buffer); /* elapsed time*/ - if ( ms < 3600000 ) - { - snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %ld:%02d", - str(LANG_BOOKMARK_SELECT_TIME_TEXT), - ms / 60000, - (unsigned int)(ms % 60000) / 1000); - /* unsigned int: hinting for 16bits archs */ - } - else - { - snprintf(global_temp_buffer, sizeof(global_temp_buffer), - "%s: %ld:%02ld:%02d", - str(LANG_BOOKMARK_SELECT_TIME_TEXT), - ms / 3600000, - ms % 3600000 / 60000, - (unsigned int)(ms % 60000) / 1000); - } + format_time(time_buf, sizeof(time_buf), ms); + snprintf(global_temp_buffer, sizeof(global_temp_buffer), "%s: %s", + str(LANG_BOOKMARK_SELECT_TIME_TEXT), time_buf); FOR_NB_SCREENS(i) screens[i].puts_scroll(0, 3, (unsigned char *)global_temp_buffer); @@ -764,35 +735,21 @@ static void display_bookmark(const char* bookmark, screens[i].puts_scroll(0, 4, str(LANG_BOOKMARK_SELECT_PLAY)); screens[i].puts_scroll(0, 5, str(LANG_BOOKMARK_SELECT_EXIT)); screens[i].puts_scroll(0, 6, str(LANG_BOOKMARK_SELECT_DELETE)); + screens[i].update(); } #else - (void)bookmark_id; - len=strlen(global_filename); - if (len>3) - dot=strrchr(global_filename+len-4,'.'); - else - dot=NULL; + dot = strrchr(global_filename, '.'); + if (dot) *dot='\0'; - if ( ms < 3600000 ) - { - snprintf(global_temp_buffer, sizeof(global_temp_buffer), - "%2d, %ld:%02ld, %s,", - (bookmark_count+1), - ms / 60000, - ms % 60000 / 1000, - global_filename); - } - else - { - snprintf(global_temp_buffer, sizeof(global_temp_buffer), - "%2d, %ld:%02ld:%02ld, %s,", - (bookmark_count+1), - ms / 60000, - ms % 3600000 / 60000, - ms % 60000 / 1000, - global_filename); - } + + format_time(time_buf, sizeof(time_buf), ms); + snprintf(global_temp_buffer, sizeof(global_temp_buffer), + "%d/%d, %s, %s", (bookmark_id + 1), bookmark_count, + time_buf, global_filename); + + if (dot) + *dot='.'; gui_syncstatusbar_draw(&statusbars, false); @@ -801,13 +758,6 @@ static void display_bookmark(const char* bookmark, screens[i].puts_scroll(0,0,global_temp_buffer); screens[i].puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER)); } - if (dot) - *dot='.'; -#endif - -#ifdef HAVE_LCD_BITMAP - FOR_NB_SCREENS(i) - screens[i].update(); #endif } @@ -1047,7 +997,7 @@ static bool generate_bookmark_file_name(const char *in) } /* ----------------------------------------------------------------------- */ -/* Returns the bookmark name for the current playlist */ +/* Returns true if a bookmark file exists for the current playlist */ /* ----------------------------------------------------------------------- */ bool bookmark_exist(void) { diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 2037ad57a5..d533e33f9c 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -371,24 +371,6 @@ static void gui_wps_statusbar_draw(struct gui_wps *wps, bool force) gui_statusbar_draw((wps)->statusbar, (force)) #endif -/* Format time into buf. - * - * buf - buffer to format to. - * buf_size - size of buffer. - * time - time to format, in milliseconds. - */ -void gui_wps_format_time(char* buf, int buf_size, long time) -{ - if ( time < 3600000 ) { - snprintf(buf, buf_size, "%d:%02d", - (int) (time % 3600000 / 60000), (int) (time % 60000 / 1000)); - } else { - snprintf(buf, buf_size, "%d:%02d:%02d", - (int) (time / 3600000), (int) (time % 3600000 / 60000), - (int) (time % 60000 / 1000)); - } -} - /* Extract a part from a path. * * buf - buffer extract part to. @@ -688,20 +670,20 @@ static char* get_tag(struct wps_data* wps_data, case 'c': /* Current Time in Song */ *flags |= WPS_REFRESH_DYNAMIC; - gui_wps_format_time(buf, buf_size, - id3->elapsed + wps_state.ff_rewind_count); + format_time(buf, buf_size, + id3->elapsed + wps_state.ff_rewind_count); return buf; case 'r': /* Remaining Time in Song */ *flags |= WPS_REFRESH_DYNAMIC; - gui_wps_format_time(buf, buf_size, - id3->length - id3->elapsed - - wps_state.ff_rewind_count); + format_time(buf, buf_size, + id3->length - id3->elapsed - + wps_state.ff_rewind_count); return buf; case 't': /* Total Time */ *flags |= WPS_REFRESH_STATIC; - gui_wps_format_time(buf, buf_size, id3->length); + format_time(buf, buf_size, id3->length); return buf; #ifdef HAVE_LCD_BITMAP @@ -835,8 +817,8 @@ static char* get_tag(struct wps_data* wps_data, } else { - gui_wps_format_time(buf, buf_size, \ - get_sleep_timer() * 1000); + format_time(buf, buf_size, \ + get_sleep_timer() * 1000); return buf; } } @@ -2252,7 +2234,7 @@ static void draw_player_fullbar(struct gui_wps *gwps, char* buf, int buf_size) time=(state->id3->elapsed + state->ff_rewind_count); memset(timestr, 0, sizeof(timestr)); - gui_wps_format_time(timestr, sizeof(timestr), time); + format_time(timestr, sizeof(timestr), time); for(lcd_char_pos=0; lcd_char_pos<6; lcd_char_pos++) { digits[lcd_char_pos] = map_fullbar_char(timestr[lcd_char_pos]); } diff --git a/apps/gui/gwps-common.h b/apps/gui/gwps-common.h index b4d6df589a..77bec83951 100644 --- a/apps/gui/gwps-common.h +++ b/apps/gui/gwps-common.h @@ -23,7 +23,6 @@ #include "gwps.h" -void gui_wps_format_time(char* buf, int buf_size, long time); void fade(bool fade_in); void gui_wps_format(struct wps_data *data); bool gui_wps_refresh(struct gui_wps *gwps, int ffwd_offset, diff --git a/apps/misc.c b/apps/misc.c index 8487da0d98..d072d4f881 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -186,6 +186,27 @@ char *create_numbered_filename(char *buffer, const char *path, return buffer; } +/* Format time into buf. + * + * buf - buffer to format to. + * buf_size - size of buffer. + * t - time to format, in milliseconds. + */ +void format_time(char* buf, int buf_size, long t) +{ + if ( t < 3600000 ) + { + snprintf(buf, buf_size, "%d:%02d", + (int) (t / 60000), (int) (t % 60000 / 1000)); + } + else + { + snprintf(buf, buf_size, "%d:%02d:%02d", + (int) (t / 3600000), (int) (t % 3600000 / 60000), + (int) (t % 60000 / 1000)); + } +} + #ifdef CONFIG_RTC /* Create a filename with a date+time part. It is allowed that buffer and path point to the same memory location, diff --git a/apps/misc.h b/apps/misc.h index f273631030..f127d6acbf 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -49,6 +49,15 @@ char *output_dyn_value(char *buf, int buf_size, int value, char *create_numbered_filename(char *buffer, const char *path, const char *prefix, const char *suffix, int numberlen IF_CNFN_NUM_(, int *num)); + +/* Format time into buf. + * + * buf - buffer to format to. + * buf_size - size of buffer. + * t - time to format, in milliseconds. + */ +void format_time(char* buf, int buf_size, long t); + #ifdef CONFIG_RTC /* Create a filename with a date+time part. It is allowed that buffer and path point to the same memory location, diff --git a/apps/screens.c b/apps/screens.c index 26f083da47..29b6f1dd76 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -49,7 +49,6 @@ #include "debug.h" #include "led.h" #include "sound.h" -#include "gwps-common.h" #include "splash.h" #include "statusbar.h" #include "screen_access.h" @@ -1197,7 +1196,7 @@ static char * id3_get_info(int selected_item, void* data, char *buffer) } break; case 8:/*LANG_ID3_LENGTH*/ - gui_wps_format_time(buffer, MAX_PATH, id3->length); + format_time(buffer, MAX_PATH, id3->length); info=buffer; break; case 9:/*LANG_ID3_PLAYLIST*/ -- cgit v1.2.3