summaryrefslogtreecommitdiff
path: root/apps/bookmark.c
diff options
context:
space:
mode:
authorOsborne Jacobs <ozziejacks@gmail.com>2012-03-11 00:47:28 -0500
committerJonathan Gordon <rockbox@jdgordon.info>2012-03-12 08:54:02 +0100
commitfb30d013729f5dc8f256b6d5269f65e4b864d47c (patch)
tree7332e12902aa1b8cb92a4d83e61b9b23fcd34b85 /apps/bookmark.c
parent16a95618de709caeca45a34f2649d6cfd6a66d5f (diff)
downloadrockbox-fb30d013729f5dc8f256b6d5269f65e4b864d47c.tar.gz
rockbox-fb30d013729f5dc8f256b6d5269f65e4b864d47c.zip
Fix minor bookmark problems/Enhance bookmark functions
This fix: -fixes when the bookmark menu and submenus are displayed and hidden in the context menu. -'Create Bookmark' should be hidden when tracks are queued in the playlist or nothing is currently playing (previously it was never hidden) -'List Bookmarks' should be hidden if and only if no bookmark file exists for the current playlist (previously it was hidden if tracks were queued or nothing was playing neither of which hinder loading bookmarks) -'Bookmarks' main menu should be hidden if both 'Create Bookmarks' and 'List Bookmarks' submenus are hidden -fixes a problem where the 'Bookmark Error' message was not always displayed on bookmarking failure -adds BOOKMARK_USB_CONNECTED return value to the bookmark functions to distinguish if the bookmark list was exited due to a USB connection. -fixes other minor logic problems in the bookmarking functions Change-Id: If6394b2e77f027773a7c94ffdcb52dbb15e2922b Reviewed-on: http://gerrit.rockbox.org/177 Reviewed-by: Osborne Jacobs <ozziejacks@gmail.com> Tested-by: Osborne Jacobs <ozziejacks@gmail.com> Reviewed-by: Jonathan Gordon <rockbox@jdgordon.info>
Diffstat (limited to 'apps/bookmark.c')
-rw-r--r--apps/bookmark.c141
1 files changed, 87 insertions, 54 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c
index cce8ef88bf..e0325b38d4 100644
--- a/apps/bookmark.c
+++ b/apps/bookmark.c
@@ -93,8 +93,7 @@ static const char* get_bookmark_info(int list_index,
93 void* data, 93 void* data,
94 char *buffer, 94 char *buffer,
95 size_t buffer_len); 95 size_t buffer_len);
96static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resume); 96static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume, char** selected_bookmark);
97static bool is_bookmarkable_state(void);
98static bool write_bookmark(bool create_bookmark_file, const char *bookmark); 97static bool write_bookmark(bool create_bookmark_file, const char *bookmark);
99static int get_bookmark_count(const char* bookmark_file_name); 98static int get_bookmark_count(const char* bookmark_file_name);
100 99
@@ -109,37 +108,38 @@ static char global_bookmark[MAX_BOOKMARK_SIZE];
109static char global_filename[MAX_PATH]; 108static char global_filename[MAX_PATH];
110 109
111/* ----------------------------------------------------------------------- */ 110/* ----------------------------------------------------------------------- */
112/* This is the interface function from the main menu. */ 111/* This is an interface function from the context menu. */
112/* Returns true on successful bookmark creation. */
113/* ----------------------------------------------------------------------- */ 113/* ----------------------------------------------------------------------- */
114bool bookmark_create_menu(void) 114bool bookmark_create_menu(void)
115{ 115{
116 write_bookmark(true, create_bookmark()); 116 return write_bookmark(true, create_bookmark());
117 return false;
118} 117}
119 118
120/* ----------------------------------------------------------------------- */ 119/* ----------------------------------------------------------------------- */
121/* This function acts as the load interface from the main menu */ 120/* This function acts as the load interface from the context menu. */
122/* This function determines the bookmark file name and then loads that file*/ 121/* This function determines the bookmark file name and then loads that file*/
123/* for the user. The user can then select a bookmark to load. */ 122/* for the user. The user can then select or delete previous bookmarks. */
124/* If no file/directory is currently playing, the menu item does not work. */ 123/* This function returns BOOKMARK_SUCCESS on the selection of a track to */
124/* resume, BOOKMARK_FAIL if the menu is exited without a selection and */
125/* BOOKMARK_USB_CONNECTED if the menu is forced to exit due to a USB */
126/* connection. */
125/* ----------------------------------------------------------------------- */ 127/* ----------------------------------------------------------------------- */
126bool bookmark_load_menu(void) 128int bookmark_load_menu(void)
127{ 129{
128 bool ret = false; 130 char* bookmark;
131 int ret = BOOKMARK_FAIL;
129 132
130 push_current_activity(ACTIVITY_BOOKMARKSLIST); 133 push_current_activity(ACTIVITY_BOOKMARKSLIST);
131 if (is_bookmarkable_state()) 134
132 { 135 char* name = playlist_get_name(NULL, global_temp_buffer,
133 char* name = playlist_get_name(NULL, global_temp_buffer,
134 sizeof(global_temp_buffer)); 136 sizeof(global_temp_buffer));
135 if (generate_bookmark_file_name(name)) 137 if (generate_bookmark_file_name(name))
138 {
139 ret = select_bookmark(global_bookmark_file_name, false, &bookmark);
140 if (bookmark != NULL)
136 { 141 {
137 char* bookmark = select_bookmark(global_bookmark_file_name, false); 142 ret = play_bookmark(bookmark) ? BOOKMARK_SUCCESS : BOOKMARK_FAIL;
138
139 if (bookmark != NULL)
140 {
141 ret = play_bookmark(bookmark);
142 }
143 } 143 }
144 } 144 }
145 145
@@ -150,6 +150,7 @@ bool bookmark_load_menu(void)
150/* ----------------------------------------------------------------------- */ 150/* ----------------------------------------------------------------------- */
151/* Gives the user a list of the Most Recent Bookmarks. This is an */ 151/* Gives the user a list of the Most Recent Bookmarks. This is an */
152/* interface function */ 152/* interface function */
153/* Returns true on the successful selection of a recent bookmark. */
153/* ----------------------------------------------------------------------- */ 154/* ----------------------------------------------------------------------- */
154bool bookmark_mrb_load() 155bool bookmark_mrb_load()
155{ 156{
@@ -157,7 +158,7 @@ bool bookmark_mrb_load()
157 bool ret = false; 158 bool ret = false;
158 159
159 push_current_activity(ACTIVITY_BOOKMARKSLIST); 160 push_current_activity(ACTIVITY_BOOKMARKSLIST);
160 bookmark = select_bookmark(RECENT_BOOKMARK_FILE, false); 161 select_bookmark(RECENT_BOOKMARK_FILE, false, &bookmark);
161 if (bookmark != NULL) 162 if (bookmark != NULL)
162 { 163 {
163 ret = play_bookmark(bookmark); 164 ret = play_bookmark(bookmark);
@@ -170,13 +171,14 @@ bool bookmark_mrb_load()
170/* ----------------------------------------------------------------------- */ 171/* ----------------------------------------------------------------------- */
171/* This function handles an autobookmark creation. This is an interface */ 172/* This function handles an autobookmark creation. This is an interface */
172/* function. */ 173/* function. */
174/* Returns true on successful bookmark creation. */
173/* ----------------------------------------------------------------------- */ 175/* ----------------------------------------------------------------------- */
174bool bookmark_autobookmark(bool prompt_ok) 176bool bookmark_autobookmark(bool prompt_ok)
175{ 177{
176 char* bookmark; 178 char* bookmark;
177 bool update; 179 bool update;
178 180
179 if (!is_bookmarkable_state()) 181 if (!bookmark_is_bookmarkable_state())
180 return false; 182 return false;
181 183
182 audio_pause(); /* first pause playback */ 184 audio_pause(); /* first pause playback */
@@ -229,36 +231,50 @@ bool bookmark_autobookmark(bool prompt_ok)
229/* This file will contain N number of bookmarks in the following format: */ 231/* This file will contain N number of bookmarks in the following format: */
230/* resume_index*resume_offset*resume_seed*resume_first_index* */ 232/* resume_index*resume_offset*resume_seed*resume_first_index* */
231/* resume_file*milliseconds*MP3 Title* */ 233/* resume_file*milliseconds*MP3 Title* */
234/* Returns true on successful bookmark write. */
235/* Returns false if any part of the bookmarking process fails. It is */
236/* possible that a bookmark is successfully added to the most recent */
237/* bookmark list but fails to be added to the bookmark file or vice versa. */
232/* ------------------------------------------------------------------------*/ 238/* ------------------------------------------------------------------------*/
233static bool write_bookmark(bool create_bookmark_file, const char *bookmark) 239static bool write_bookmark(bool create_bookmark_file, const char *bookmark)
234{ 240{
235 bool success=false; 241 bool ret=true;
236 if (!bookmark)
237 return false; /* something didn't happen correctly, do nothing */
238 242
239 if (global_settings.usemrb) 243 if (!bookmark)
240 success = add_bookmark(RECENT_BOOKMARK_FILE, bookmark, true); 244 {
245 ret = false; /* something didn't happen correctly, do nothing */
246 }
247 else
248 {
249 if (global_settings.usemrb)
250 ret = add_bookmark(RECENT_BOOKMARK_FILE, bookmark, true);
241 251
242 252
243 /* writing the bookmark */ 253 /* writing the bookmark */
244 if (create_bookmark_file) 254 if (create_bookmark_file)
245 {
246 char* name = playlist_get_name(NULL, global_temp_buffer,
247 sizeof(global_temp_buffer));
248 if (generate_bookmark_file_name(name))
249 { 255 {
250 success = add_bookmark(global_bookmark_file_name, bookmark, false); 256 char* name = playlist_get_name(NULL, global_temp_buffer,
257 sizeof(global_temp_buffer));
258 if (generate_bookmark_file_name(name))
259 {
260 ret = ret & add_bookmark(global_bookmark_file_name, bookmark, false);
261 }
262 else
263 {
264 ret = false; /* generating bookmark file failed */
265 }
251 } 266 }
252 } 267 }
253 268
254 splash(HZ, success ? ID2P(LANG_BOOKMARK_CREATE_SUCCESS) 269 splash(HZ, ret ? ID2P(LANG_BOOKMARK_CREATE_SUCCESS)
255 : ID2P(LANG_BOOKMARK_CREATE_FAILURE)); 270 : ID2P(LANG_BOOKMARK_CREATE_FAILURE));
256 271
257 return true; 272 return ret;
258} 273}
259 274
260/* ----------------------------------------------------------------------- */ 275/* ----------------------------------------------------------------------- */
261/* This function adds a bookmark to a file. */ 276/* This function adds a bookmark to a file. */
277/* Returns true on successful bookmark add. */
262/* ------------------------------------------------------------------------*/ 278/* ------------------------------------------------------------------------*/
263static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, 279static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
264 bool most_recent) 280 bool most_recent)
@@ -330,13 +346,14 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
330/* ----------------------------------------------------------------------- */ 346/* ----------------------------------------------------------------------- */
331/* This function takes the system resume data and formats it into a valid */ 347/* This function takes the system resume data and formats it into a valid */
332/* bookmark. */ 348/* bookmark. */
349/* Returns not NULL on successful bookmark format. */
333/* ----------------------------------------------------------------------- */ 350/* ----------------------------------------------------------------------- */
334static char* create_bookmark() 351static char* create_bookmark()
335{ 352{
336 int resume_index = 0; 353 int resume_index = 0;
337 char *file; 354 char *file;
338 355
339 if (!is_bookmarkable_state()) 356 if (!bookmark_is_bookmarkable_state())
340 return NULL; /* something didn't happen correctly, do nothing */ 357 return NULL; /* something didn't happen correctly, do nothing */
341 358
342 /* grab the currently playing track */ 359 /* grab the currently playing track */
@@ -395,9 +412,12 @@ static char* create_bookmark()
395/* ----------------------------------------------------------------------- */ 412/* ----------------------------------------------------------------------- */
396/* This function will determine if an autoload is necessary. This is an */ 413/* This function will determine if an autoload is necessary. This is an */
397/* interface function. */ 414/* interface function. */
415/* Returns true on bookmark load or bookmark selection. */
398/* ------------------------------------------------------------------------*/ 416/* ------------------------------------------------------------------------*/
399bool bookmark_autoload(const char* file) 417bool bookmark_autoload(const char* file)
400{ 418{
419 char* bookmark;
420
401 if(global_settings.autoloadbookmark == BOOKMARK_NO) 421 if(global_settings.autoloadbookmark == BOOKMARK_NO)
402 return false; 422 return false;
403 423
@@ -416,7 +436,7 @@ bool bookmark_autoload(const char* file)
416 } 436 }
417 else 437 else
418 { 438 {
419 char* bookmark = select_bookmark(global_bookmark_file_name, true); 439 select_bookmark(global_bookmark_file_name, true, &bookmark);
420 440
421 if (bookmark != NULL) 441 if (bookmark != NULL)
422 { 442 {
@@ -439,6 +459,7 @@ bool bookmark_autoload(const char* file)
439/* ----------------------------------------------------------------------- */ 459/* ----------------------------------------------------------------------- */
440/* This function loads the bookmark information into the resume memory. */ 460/* This function loads the bookmark information into the resume memory. */
441/* This is an interface function. */ 461/* This is an interface function. */
462/* Returns true on successful bookmark load. */
442/* ------------------------------------------------------------------------*/ 463/* ------------------------------------------------------------------------*/
443bool bookmark_load(const char* file, bool autoload) 464bool bookmark_load(const char* file, bool autoload)
444{ 465{
@@ -458,7 +479,7 @@ bool bookmark_load(const char* file, bool autoload)
458 else 479 else
459 { 480 {
460 /* This is not an auto-load, so list the bookmarks */ 481 /* This is not an auto-load, so list the bookmarks */
461 bookmark = select_bookmark(file, false); 482 select_bookmark(file, false, &bookmark);
462 } 483 }
463 484
464 if (bookmark != NULL) 485 if (bookmark != NULL)
@@ -672,10 +693,15 @@ static int bookmark_list_voice_cb(int list_index, void* data)
672} 693}
673 694
674/* ----------------------------------------------------------------------- */ 695/* ----------------------------------------------------------------------- */
675/* This displays a the bookmarks in a file and allows the user to */ 696/* This displays the bookmarks in a file and allows the user to */
676/* select one to play. */ 697/* select one to play. */
698/* *selected_bookmark contains a non NULL value on successful bookmark */
699/* selection. */
700/* Returns BOOKMARK_SUCCESS on successful bookmark selection, BOOKMARK_FAIL*/
701/* if no selection was made and BOOKMARK_USB_CONNECTED if the selection */
702/* menu is forced to exit due to a USB connection. */
677/* ------------------------------------------------------------------------*/ 703/* ------------------------------------------------------------------------*/
678static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resume) 704static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume, char** selected_bookmark)
679{ 705{
680 struct bookmark_list* bookmarks; 706 struct bookmark_list* bookmarks;
681 struct gui_synclist list; 707 struct gui_synclist list;
@@ -684,6 +710,7 @@ static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resu
684 size_t size; 710 size_t size;
685 bool exit = false; 711 bool exit = false;
686 bool refresh = true; 712 bool refresh = true;
713 int ret = BOOKMARK_FAIL;
687 714
688 bookmarks = plugin_get_buffer(&size); 715 bookmarks = plugin_get_buffer(&size);
689 bookmarks->buffer_size = size; 716 bookmarks->buffer_size = size;
@@ -711,7 +738,8 @@ static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resu
711 /* No more bookmarks, delete file and exit */ 738 /* No more bookmarks, delete file and exit */
712 splash(HZ, ID2P(LANG_BOOKMARK_LOAD_EMPTY)); 739 splash(HZ, ID2P(LANG_BOOKMARK_LOAD_EMPTY));
713 remove(bookmark_file_name); 740 remove(bookmark_file_name);
714 return NULL; 741 *selected_bookmark = NULL;
742 return BOOKMARK_FAIL;
715 } 743 }
716 744
717 if (bookmarks->show_dont_resume) 745 if (bookmarks->show_dont_resume)
@@ -771,7 +799,8 @@ static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resu
771 if (item >= 0) 799 if (item >= 0)
772 { 800 {
773 talk_shutup(); 801 talk_shutup();
774 return bookmarks->items[item - bookmarks->start]; 802 *selected_bookmark = bookmarks->items[item - bookmarks->start];
803 return BOOKMARK_SUCCESS;
775 } 804 }
776 805
777 /* Else fall through */ 806 /* Else fall through */
@@ -806,6 +835,7 @@ static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resu
806 default: 835 default:
807 if (default_event_handler(action) == SYS_USB_CONNECTED) 836 if (default_event_handler(action) == SYS_USB_CONNECTED)
808 { 837 {
838 ret = BOOKMARK_USB_CONNECTED;
809 exit = true; 839 exit = true;
810 } 840 }
811 841
@@ -814,12 +844,14 @@ static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resu
814 } 844 }
815 845
816 talk_shutup(); 846 talk_shutup();
817 return NULL; 847 *selected_bookmark = NULL;
848 return ret;
818} 849}
819 850
820/* ----------------------------------------------------------------------- */ 851/* ----------------------------------------------------------------------- */
821/* This function takes a location in a bookmark file and deletes that */ 852/* This function takes a location in a bookmark file and deletes that */
822/* bookmark. */ 853/* bookmark. */
854/* Returns true on successful bookmark deletion. */
823/* ------------------------------------------------------------------------*/ 855/* ------------------------------------------------------------------------*/
824static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id) 856static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id)
825{ 857{
@@ -919,6 +951,7 @@ static void say_bookmark(const char* bookmark,
919 951
920/* ----------------------------------------------------------------------- */ 952/* ----------------------------------------------------------------------- */
921/* This function parses a bookmark and then plays it. */ 953/* This function parses a bookmark and then plays it. */
954/* Returns true on successful bookmark play. */
922/* ------------------------------------------------------------------------*/ 955/* ------------------------------------------------------------------------*/
923static bool play_bookmark(const char* bookmark) 956static bool play_bookmark(const char* bookmark)
924{ 957{
@@ -976,6 +1009,7 @@ static const char* long_token(const char* s, long* dest)
976/* This function takes a bookmark and parses it. This function also */ 1009/* This function takes a bookmark and parses it. This function also */
977/* validates the bookmark. The parse_filenames flag indicates whether */ 1010/* validates the bookmark. The parse_filenames flag indicates whether */
978/* the filename tokens are to be extracted. */ 1011/* the filename tokens are to be extracted. */
1012/* Returns true on successful bookmark parse. */
979/* ----------------------------------------------------------------------- */ 1013/* ----------------------------------------------------------------------- */
980static bool parse_bookmark(const char *bookmark, const bool parse_filenames) 1014static bool parse_bookmark(const char *bookmark, const bool parse_filenames)
981{ 1015{
@@ -1042,6 +1076,7 @@ static bool parse_bookmark(const char *bookmark, const bool parse_filenames)
1042/* Changing this function could result in how the bookmarks are stored. */ 1076/* Changing this function could result in how the bookmarks are stored. */
1043/* it would be here that the centralized/decentralized bookmark code */ 1077/* it would be here that the centralized/decentralized bookmark code */
1044/* could be placed. */ 1078/* could be placed. */
1079/* Always returns true */
1045/* ----------------------------------------------------------------------- */ 1080/* ----------------------------------------------------------------------- */
1046static bool generate_bookmark_file_name(const char *in) 1081static bool generate_bookmark_file_name(const char *in)
1047{ 1082{
@@ -1074,30 +1109,28 @@ static bool generate_bookmark_file_name(const char *in)
1074} 1109}
1075 1110
1076/* ----------------------------------------------------------------------- */ 1111/* ----------------------------------------------------------------------- */
1077/* Returns true if a bookmark file exists for the current playlist */ 1112/* Returns true if a bookmark file exists for the current playlist. */
1113/* This is an interface function. */
1078/* ----------------------------------------------------------------------- */ 1114/* ----------------------------------------------------------------------- */
1079bool bookmark_exists(void) 1115bool bookmark_exists(void)
1080{ 1116{
1081 bool exist=false; 1117 bool exist=false;
1082 1118
1083 if(is_bookmarkable_state()) 1119 char* name = playlist_get_name(NULL, global_temp_buffer,
1120 sizeof(global_temp_buffer));
1121 if (generate_bookmark_file_name(name))
1084 { 1122 {
1085 char* name = playlist_get_name(NULL, global_temp_buffer, 1123 exist = file_exists(global_bookmark_file_name);
1086 sizeof(global_temp_buffer));
1087 if (generate_bookmark_file_name(name))
1088 {
1089 exist = file_exists(global_bookmark_file_name);
1090 }
1091 } 1124 }
1092
1093 return exist; 1125 return exist;
1094} 1126}
1095 1127
1096/* ----------------------------------------------------------------------- */ 1128/* ----------------------------------------------------------------------- */
1097/* Checks the current state of the system and returns true if it is in a */ 1129/* Checks the current state of the system and returns true if it is in a */
1098/* bookmarkable state. */ 1130/* bookmarkable state. */
1131/* This is an interface funtion. */
1099/* ----------------------------------------------------------------------- */ 1132/* ----------------------------------------------------------------------- */
1100static bool is_bookmarkable_state(void) 1133bool bookmark_is_bookmarkable_state(void)
1101{ 1134{
1102 int resume_index = 0; 1135 int resume_index = 0;
1103 1136