diff options
author | Christian Soffke <christian.soffke@gmail.com> | 2023-01-10 18:50:05 +0100 |
---|---|---|
committer | Christian Soffke <christian.soffke@gmail.com> | 2023-01-19 15:56:35 -0500 |
commit | 32f365bf3cdcaadb22087041bfc44574737b557d (patch) | |
tree | eff68bbaa18d6b1ff8e2d0fd581c461412a55ad6 /apps/plugins | |
parent | 4d53d1b52b858d4a1e90fc74fb93cda957d00cb4 (diff) | |
download | rockbox-32f365bf3cdcaadb22087041bfc44574737b557d.tar.gz rockbox-32f365bf3cdcaadb22087041bfc44574737b557d.zip |
database: make parent tables work with plugin
Enables the use of PictureFlow and the Properties plugin
with parent tables of ALLSUBENTRIES, such as an album
or album artist, instead of individual tracks.
Change-Id: I18c4779ed116a48c732ae32b9629e7e0d93ce7c8
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/properties.c | 94 |
1 files changed, 66 insertions, 28 deletions
diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c index 46cf818fb4..7dacda3579 100644 --- a/apps/plugins/properties.c +++ b/apps/plugins/properties.c | |||
@@ -19,6 +19,11 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "plugin.h" | 21 | #include "plugin.h" |
22 | #include "lib/id3.h" | ||
23 | |||
24 | #ifdef HAVE_TAGCACHE | ||
25 | #include "lib/mul_id3.h" | ||
26 | #endif | ||
22 | 27 | ||
23 | #if !defined(ARRAY_SIZE) | 28 | #if !defined(ARRAY_SIZE) |
24 | #define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0])) | 29 | #define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0])) |
@@ -35,12 +40,16 @@ struct dir_stats { | |||
35 | enum props_types { | 40 | enum props_types { |
36 | PROPS_FILE = 0, | 41 | PROPS_FILE = 0, |
37 | PROPS_ID3, | 42 | PROPS_ID3, |
43 | PROPS_MUL_ID3, | ||
38 | PROPS_DIR | 44 | PROPS_DIR |
39 | }; | 45 | }; |
40 | 46 | ||
41 | static int props_type = PROPS_FILE; | 47 | static int props_type = PROPS_FILE; |
42 | 48 | ||
43 | static struct mp3entry id3; | 49 | static struct mp3entry id3; |
50 | #ifdef HAVE_TAGCACHE | ||
51 | static int mul_id3_count; | ||
52 | #endif | ||
44 | 53 | ||
45 | static char str_filename[MAX_PATH]; | 54 | static char str_filename[MAX_PATH]; |
46 | static char str_dirname[MAX_PATH]; | 55 | static char str_dirname[MAX_PATH]; |
@@ -118,14 +127,8 @@ static bool file_properties(const char* selected_file) | |||
118 | rb->snprintf(str_time, sizeof str_time, "%02d:%02d:%02d", | 127 | rb->snprintf(str_time, sizeof str_time, "%02d:%02d:%02d", |
119 | tm.tm_hour, tm.tm_min, tm.tm_sec); | 128 | tm.tm_hour, tm.tm_min, tm.tm_sec); |
120 | 129 | ||
121 | int fd = rb->open(selected_file, O_RDONLY); | 130 | if (retrieve_id3(&id3, selected_file, false)) |
122 | if (fd >= 0) | 131 | props_type = PROPS_ID3; |
123 | { | ||
124 | if (rb->get_metadata(&id3, fd, selected_file)) | ||
125 | props_type = PROPS_ID3; | ||
126 | |||
127 | rb->close(fd); | ||
128 | } | ||
129 | found = true; | 132 | found = true; |
130 | break; | 133 | break; |
131 | } | 134 | } |
@@ -369,6 +372,19 @@ static bool determine_file_or_dir(void) | |||
369 | return false; | 372 | return false; |
370 | } | 373 | } |
371 | 374 | ||
375 | #ifdef HAVE_TAGCACHE | ||
376 | bool mul_id3_add(const char *file_name) | ||
377 | { | ||
378 | if (!retrieve_id3(&id3, file_name, false)) | ||
379 | return false; | ||
380 | |||
381 | collect_id3(&id3, mul_id3_count == 0); | ||
382 | mul_id3_count++; | ||
383 | |||
384 | return true; | ||
385 | } | ||
386 | #endif | ||
387 | |||
372 | enum plugin_status plugin_start(const void* parameter) | 388 | enum plugin_status plugin_start(const void* parameter) |
373 | { | 389 | { |
374 | static struct dir_stats stats = | 390 | static struct dir_stats stats = |
@@ -380,40 +396,62 @@ enum plugin_status plugin_start(const void* parameter) | |||
380 | }; | 396 | }; |
381 | 397 | ||
382 | const char *file = parameter; | 398 | const char *file = parameter; |
383 | if(!parameter || (file[0] != '/')) return PLUGIN_ERROR; | 399 | if(!parameter) |
400 | return PLUGIN_ERROR; | ||
384 | 401 | ||
385 | #ifdef HAVE_TOUCHSCREEN | 402 | #ifdef HAVE_TOUCHSCREEN |
386 | rb->touchscreen_set_mode(rb->global_settings->touch_mode); | 403 | rb->touchscreen_set_mode(rb->global_settings->touch_mode); |
387 | #endif | 404 | #endif |
388 | 405 | ||
389 | const char* file_name = rb->strrchr(file, '/') + 1; | 406 | #ifdef HAVE_TAGCACHE |
390 | int dirlen = (file_name - file); | 407 | if (!rb->strcmp(file, MAKE_ACT_STR(ACTIVITY_DATABASEBROWSER))) /* db table selected */ |
408 | { | ||
409 | props_type = PROPS_MUL_ID3; | ||
410 | init_mul_id3(); | ||
411 | mul_id3_count = 0; | ||
391 | 412 | ||
392 | rb->strlcpy(str_dirname, file, dirlen + 1); | 413 | if (!rb->tagtree_subentries_do_action(&mul_id3_add) || mul_id3_count == 0) |
393 | rb->snprintf(str_filename, sizeof str_filename, "%s", file+dirlen); | 414 | return PLUGIN_ERROR; |
394 | 415 | ||
395 | if(!determine_file_or_dir()) | 416 | if (mul_id3_count > 1) /* otherwise, the retrieved id3 can be used as-is */ |
396 | { | 417 | write_id3_mul_tracks(&id3); |
397 | /* weird: we couldn't find the entry. This Should Never Happen (TM) */ | ||
398 | rb->splashf(0, "File/Dir not found: %s", file); | ||
399 | rb->action_userabort(TIMEOUT_BLOCK); | ||
400 | return PLUGIN_OK; | ||
401 | } | 418 | } |
402 | 419 | else | |
403 | /* get the info depending on its_a_dir */ | 420 | #endif |
404 | if(!(props_type == PROPS_DIR ? dir_properties(file, &stats) : file_properties(file))) | 421 | if (file[0] == '/') /* single track selected */ |
405 | { | 422 | { |
406 | /* something went wrong (to do: tell user what it was (nesting,...) */ | 423 | const char* file_name = rb->strrchr(file, '/') + 1; |
407 | rb->splash(0, ID2P(LANG_PROPERTIES_FAIL)); | 424 | int dirlen = (file_name - file); |
408 | rb->action_userabort(TIMEOUT_BLOCK); | 425 | |
409 | return PLUGIN_OK; | 426 | rb->strlcpy(str_dirname, file, dirlen + 1); |
427 | rb->snprintf(str_filename, sizeof str_filename, "%s", file+dirlen); | ||
428 | |||
429 | if(!determine_file_or_dir()) | ||
430 | { | ||
431 | /* weird: we couldn't find the entry. This Should Never Happen (TM) */ | ||
432 | rb->splashf(0, "File/Dir not found: %s", file); | ||
433 | rb->action_userabort(TIMEOUT_BLOCK); | ||
434 | return PLUGIN_OK; | ||
435 | } | ||
436 | |||
437 | /* get the info depending on its_a_dir */ | ||
438 | if(!(props_type == PROPS_DIR ? dir_properties(file, &stats) : file_properties(file))) | ||
439 | { | ||
440 | /* something went wrong (to do: tell user what it was (nesting,...) */ | ||
441 | rb->splash(0, ID2P(LANG_PROPERTIES_FAIL)); | ||
442 | rb->action_userabort(TIMEOUT_BLOCK); | ||
443 | return PLUGIN_OK; | ||
444 | } | ||
410 | } | 445 | } |
446 | else | ||
447 | return PLUGIN_ERROR; | ||
411 | 448 | ||
412 | FOR_NB_SCREENS(i) | 449 | FOR_NB_SCREENS(i) |
413 | rb->viewportmanager_theme_enable(i, true, NULL); | 450 | rb->viewportmanager_theme_enable(i, true, NULL); |
414 | 451 | ||
415 | bool usb = props_type == PROPS_ID3 ? rb->browse_id3(&id3, 0, 0, &tm) : | 452 | bool usb = props_type == PROPS_ID3 ? rb->browse_id3(&id3, 0, 0, &tm) : |
416 | browse_file_or_dir(&stats); | 453 | (props_type == PROPS_MUL_ID3 ? rb->browse_id3(&id3, 0, 0, NULL) : |
454 | browse_file_or_dir(&stats)); | ||
417 | 455 | ||
418 | FOR_NB_SCREENS(i) | 456 | FOR_NB_SCREENS(i) |
419 | rb->viewportmanager_theme_undo(i, false); | 457 | rb->viewportmanager_theme_undo(i, false); |