From 8137489e2b967e40c15005c8a4c09903a8a24fc4 Mon Sep 17 00:00:00 2001 From: Steve Bavin Date: Wed, 7 Mar 2007 19:56:15 +0000 Subject: Lead user through database initialisation git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12678 a1c6a512-1295-4272-9138-f99709370657 --- apps/lang/english.lang | 22 ++++++++++++++++++ apps/main.c | 6 +++-- apps/menus/settings_menu.c | 17 ++++++++++++-- apps/root_menu.c | 56 +++++++++++++++++++++++++++++++++++++++++++--- apps/tagcache.c | 10 ++++----- apps/tagcache.h | 2 +- 6 files changed, 100 insertions(+), 13 deletions(-) diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 55838f2b39..9cbcb70404 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -10701,3 +10701,25 @@ *: "Alarm Wake up Screen" + + id: LANG_BUILDING_DATABASE + desc: splash database building progress + user: + + *: "Building database... %d found (OFF for menu)" + h100,h120,h300: "Building database... %d found (STOP for menu)" + ipod*: "Building database... %d found (PLAY/PAUSE for menu)" + x5: "Building database... %d found (Long PLAY for menu)" + h10: "Building database... %d found (PREV for menu)" + + + *: "Building database... %d found (OFF for menu)" + h100,h120,h300: "Building database... %d found (STOP for menu)" + ipod*: "Building database... %d found (PLAY/PAUSE for menu)" + x5: "Building database... %d found (Long PLAY for menu)" + h10: "Building database... %d found (PREV for menu)" + + + *: "" + + diff --git a/apps/main.c b/apps/main.c index a1ea75fdc3..fe397c737c 100644 --- a/apps/main.c +++ b/apps/main.c @@ -207,10 +207,12 @@ static void init_tagcache(void) { #ifdef HAVE_LCD_BITMAP gui_syncsplash(0, true, "%s [%d/%d]", - str(LANG_TAGCACHE_INIT), ret, 7); + str(LANG_TAGCACHE_INIT), ret, + tagcache_get_max_commit_step()); #else lcd_double_height(false); - snprintf(buf, sizeof(buf), " TC [%d/%d]", ret, 7); + snprintf(buf, sizeof(buf), " TC [%d/%d]", ret, + tagcache_get_max_commit_step()); lcd_puts(0, 1, buf); #endif clear = true; diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index a58792b308..dd9ad731bb 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -45,14 +45,27 @@ /***********************************/ /* TAGCACHE MENU */ #ifdef HAVE_TAGCACHE + +static void tagcache_rebuild_with_splash(void) +{ + tagcache_rebuild(); + gui_syncsplash(HZ*2, true, str(LANG_TAGCACHE_FORCE_UPDATE_SPLASH)); +} + +static void tagcache_update_with_splash(void) +{ + tagcache_update(); + gui_syncsplash(HZ*2, true, str(LANG_TAGCACHE_FORCE_UPDATE_SPLASH)); +} + #ifdef HAVE_TC_RAMCACHE MENUITEM_SETTING(tagcache_ram, &global_settings.tagcache_ram, NULL); #endif MENUITEM_SETTING(tagcache_autoupdate, &global_settings.tagcache_autoupdate, NULL); MENUITEM_FUNCTION(tc_init, ID2P(LANG_TAGCACHE_FORCE_UPDATE), - (int(*)(void))tagcache_rebuild, NULL, Icon_NOICON); + (int(*)(void))tagcache_rebuild_with_splash, NULL, Icon_NOICON); MENUITEM_FUNCTION(tc_update, ID2P(LANG_TAGCACHE_UPDATE), - (int(*)(void))tagcache_update, NULL, Icon_NOICON); + (int(*)(void))tagcache_update_with_splash, NULL, Icon_NOICON); MENUITEM_SETTING(runtimedb, &global_settings.runtimedb, NULL); MENUITEM_FUNCTION(tc_export, ID2P(LANG_TAGCACHE_EXPORT), (int(*)(void))tagtree_export, NULL, Icon_NOICON); diff --git a/apps/root_menu.c b/apps/root_menu.c index c234614bc6..0dbf179d9e 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c @@ -61,6 +61,9 @@ #ifdef HAVE_RTC_ALARM #include "rtc.h" #endif +#ifdef HAVE_TAGCACHE +#include "tagcache.h" +#endif struct root_items { int (*function)(void* param); @@ -99,11 +102,58 @@ static int browser(void* param) break; #ifdef HAVE_TAGCACHE case GO_TO_DBBROWSER: - if ((last_screen != GO_TO_ROOT) && !tagcache_is_usable()) + if (!tagcache_is_usable()) { - gui_syncsplash(HZ, true, str(LANG_TAGCACHE_BUSY)); - return GO_TO_PREVIOUS; + /* Re-init if required */ + struct tagcache_stat *stat = tagcache_get_stat(); + if (!stat->ready && !stat->commit_delayed && stat->processed_entries == 0) + { + /* Prompt the user */ + char *lines[]={str(LANG_TAGCACHE_BUSY), str(LANG_TAGCACHE_FORCE_UPDATE)}; + struct text_message message={lines, 2}; + if(gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO) + return GO_TO_PREVIOUS; + int i; + FOR_NB_SCREENS(i) + screens[i].clear_display(); + + /* Start initialisation */ + tagcache_rebuild(); + } + + /* Now display progress until it's ready or the user exits */ + while(!tagcache_is_usable()) + { + gui_syncstatusbar_draw(&statusbars, false); + stat = tagcache_get_stat(); + + /* Maybe just needs to reboot due to delayed commit */ + if (stat->commit_delayed) + { + gui_syncsplash(HZ*2, true, str(LANG_PLEASE_REBOOT)); + break; + } + + /* Display building progress */ + if (stat->commit_step > 0) + { + gui_syncsplash(0, true, "%s [%d/%d]", + str(LANG_TAGCACHE_INIT), stat->commit_step, + tagcache_get_max_commit_step()); + } + else + { + gui_syncsplash(0, true, str(LANG_BUILDING_DATABASE), + stat->processed_entries); + } + + /* Allow user to exit */ + if (action_userabort(HZ/2)) + break; + } } + if (!tagcache_is_usable()) + return GO_TO_PREVIOUS; filter = SHOW_ID3DB; tc->dirlevel = last_db_dirlevel; break; diff --git a/apps/tagcache.c b/apps/tagcache.c index bcff803d18..a899ff91fd 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -3904,16 +3904,12 @@ bool tagcache_update(void) return false; queue_post(&tagcache_queue, Q_UPDATE, 0); - gui_syncsplash(HZ*2, true, str(LANG_TAGCACHE_FORCE_UPDATE_SPLASH)); - return false; } -bool tagcache_rebuild(void) +bool tagcache_rebuild() { queue_post(&tagcache_queue, Q_REBUILD, 0); - gui_syncsplash(HZ*2, true, str(LANG_TAGCACHE_FORCE_UPDATE_SPLASH)); - return false; } @@ -3974,4 +3970,8 @@ int tagcache_get_commit_step(void) { return tc_stat.commit_step; } +int tagcache_get_max_commit_step(void) +{ + return 8; /* To be written, better hard-coded here than in the UI */ +} diff --git a/apps/tagcache.h b/apps/tagcache.h index 7e9a42dfa7..c8d52308ce 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -187,6 +187,6 @@ void tagcache_start_scan(void); void tagcache_stop_scan(void); bool tagcache_update(void); bool tagcache_rebuild(void); - +int tagcache_get_max_commit_step(void); #endif #endif -- cgit v1.2.3