"Trash Metal" should be "Thrash Metal". Reported as FS#6503, checked against Winamp.
[Rockbox.git] / apps / onplay.c
blob5e7d1e0fe2e1a7fca7218ec7920245328516ee10
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <errno.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <stdbool.h>
25 #include "debug.h"
26 #include "sprintf.h"
27 #include "lcd.h"
28 #include "dir.h"
29 #include "file.h"
30 #include "audio.h"
31 #include "menu.h"
32 #include "lang.h"
33 #include "playlist.h"
34 #include "button.h"
35 #include "kernel.h"
36 #include "keyboard.h"
37 #include "mp3data.h"
38 #include "id3.h"
39 #include "screens.h"
40 #include "tree.h"
41 #include "buffer.h"
42 #include "settings.h"
43 #include "statusbar.h"
44 #include "playlist_viewer.h"
45 #include "talk.h"
46 #include "onplay.h"
47 #include "filetypes.h"
48 #include "plugin.h"
49 #include "bookmark.h"
50 #include "action.h"
51 #include "splash.h"
52 #include "yesno.h"
53 #if LCD_DEPTH > 1
54 #include "backdrop.h"
55 #endif
56 #ifdef HAVE_LCD_BITMAP
57 #include "icons.h"
58 #endif
59 #include "main_menu.h"
60 #include "sound_menu.h"
61 #if CONFIG_CODEC == SWCODEC
62 #include "eq_menu.h"
63 #endif
64 #include "playlist_menu.h"
65 #include "playlist_catalog.h"
66 #ifdef HAVE_TAGCACHE
67 #include "tagtree.h"
68 #endif
70 static int context;
71 static char* selected_file = NULL;
72 static int selected_file_attr = 0;
73 static int onplay_result = ONPLAY_OK;
74 static char clipboard_selection[MAX_PATH];
75 static int clipboard_selection_attr = 0;
76 static bool clipboard_is_copy = false;
78 /* For playlist options */
79 struct playlist_args {
80 int position;
81 bool queue;
84 /* ----------------------------------------------------------------------- */
85 /* Displays the bookmark menu options for the user to decide. This is an */
86 /* interface function. */
87 /* ----------------------------------------------------------------------- */
88 static bool bookmark_menu(void)
90 int i,m;
91 bool result;
92 struct menu_item items[3];
94 i=0;
96 if ((audio_status() & AUDIO_STATUS_PLAY))
98 items[i].desc = ID2P(LANG_BOOKMARK_MENU_CREATE);
99 items[i].function = bookmark_create_menu;
100 i++;
102 if (bookmark_exist())
104 items[i].desc = ID2P(LANG_BOOKMARK_MENU_LIST);
105 items[i].function = bookmark_load_menu;
106 i++;
110 m=menu_init( items, i, NULL, NULL, NULL, NULL );
112 #ifdef HAVE_LCD_CHARCELLS
113 status_set_param(true);
114 #endif
115 result = menu_run(m);
116 #ifdef HAVE_LCD_CHARCELLS
117 status_set_param(false);
118 #endif
119 menu_exit(m);
121 settings_save();
123 return result;
126 static bool list_viewers(void)
128 struct menu_item menu[16];
129 int m, i, result;
130 int ret = 0;
132 i=filetype_load_menu(menu,sizeof(menu)/sizeof(*menu));
133 if (i)
135 m = menu_init( menu, i, NULL, NULL, NULL, NULL );
136 result = menu_show(m);
137 menu_exit(m);
138 if (result >= 0)
139 ret = filetype_load_plugin((char *)menu[result].desc,selected_file);
141 else
143 /* FIX: translation! */
144 gui_syncsplash(HZ*2, true, (unsigned char *)"No viewers found");
147 if (ret == PLUGIN_USB_CONNECTED)
148 onplay_result = ONPLAY_RELOAD_DIR;
150 return false;
153 static bool shuffle_playlist(void)
155 playlist_sort(NULL, true);
156 playlist_randomise(NULL, current_tick, true);
158 return false;
161 static bool save_playlist(void)
163 save_playlist_screen(NULL);
164 return false;
167 static bool add_to_playlist(int position, bool queue)
169 bool new_playlist = !(audio_status() & AUDIO_STATUS_PLAY);
170 char *lines[] = {
171 (char *)str(LANG_RECURSE_DIRECTORY_QUESTION),
172 selected_file
174 struct text_message message={lines, 2};
176 gui_syncsplash(0, true, str(LANG_WAIT));
178 if (new_playlist)
179 playlist_create(NULL, NULL);
181 /* always set seed before inserting shuffled */
182 if (position == PLAYLIST_INSERT_SHUFFLED)
183 srand(current_tick);
185 #ifdef HAVE_TAGCACHE
186 if (context == CONTEXT_ID3DB)
188 tagtree_insert_selection_playlist(position, queue);
190 else
191 #endif
193 if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA)
194 playlist_insert_track(NULL, selected_file, position, queue, true);
195 else if (selected_file_attr & ATTR_DIRECTORY)
197 bool recurse = false;
199 if (global_settings.recursive_dir_insert != RECURSE_ASK)
200 recurse = (bool)global_settings.recursive_dir_insert;
201 else
203 /* Ask if user wants to recurse directory */
204 recurse = (gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES);
207 playlist_insert_directory(NULL, selected_file, position, queue,
208 recurse);
210 else if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_M3U)
211 playlist_insert_playlist(NULL, selected_file, position, queue);
214 if (new_playlist && (playlist_amount() > 0))
216 /* nothing is currently playing so begin playing what we just
217 inserted */
218 if (global_settings.playlist_shuffle)
219 playlist_shuffle(current_tick, -1);
220 playlist_start(0,0);
221 gui_syncstatusbar_draw(&statusbars, false);
222 onplay_result = ONPLAY_START_PLAY;
225 return false;
228 static bool view_playlist(void)
230 bool was_playing = audio_status() & AUDIO_STATUS_PLAY;
231 bool result;
233 result = playlist_viewer_ex(selected_file);
235 if (!was_playing && (audio_status() & AUDIO_STATUS_PLAY) &&
236 onplay_result == ONPLAY_OK)
237 /* playlist was started from viewer */
238 onplay_result = ONPLAY_START_PLAY;
240 return result;
243 static bool cat_add_to_a_playlist(void)
245 return catalog_add_to_a_playlist(selected_file, selected_file_attr,
246 false);
249 static bool cat_add_to_a_new_playlist(void)
251 return catalog_add_to_a_playlist(selected_file, selected_file_attr, true);
254 static bool cat_playlist_options(void)
256 struct menu_item items[3];
257 int m, i=0, result;
258 bool ret = false;
260 if ((audio_status() & AUDIO_STATUS_PLAY && context == CONTEXT_WPS) ||
261 context == CONTEXT_TREE)
263 if (context == CONTEXT_WPS)
265 items[i].desc = ID2P(LANG_CATALOG_VIEW);
266 items[i].function = catalog_view_playlists;
267 i++;
270 items[i].desc = ID2P(LANG_CATALOG_ADD_TO);
271 items[i].function = cat_add_to_a_playlist;
272 i++;
273 items[i].desc = ID2P(LANG_CATALOG_ADD_TO_NEW);
274 items[i].function = cat_add_to_a_new_playlist;
275 i++;
278 m = menu_init( items, i, NULL, NULL, NULL, NULL );
279 result = menu_show(m);
280 if(result >= 0)
281 ret = items[result].function();
282 menu_exit(m);
284 return ret;
287 /* Sub-menu for playlist options */
288 static bool playlist_options(void)
290 struct menu_item items[13];
291 struct playlist_args args[13]; /* increase these 2 if you add entries! */
292 int m, i=0, pstart=0, result;
293 bool ret = false;
295 if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_M3U &&
296 context == CONTEXT_TREE)
298 items[i].desc = ID2P(LANG_VIEW);
299 items[i].function = view_playlist;
300 i++;
301 pstart++;
304 if (audio_status() & AUDIO_STATUS_PLAY &&
305 context == CONTEXT_WPS)
307 items[i].desc = ID2P(LANG_VIEW_DYNAMIC_PLAYLIST);
308 items[i].function = playlist_viewer;
309 i++;
310 pstart++;
312 items[i].desc = ID2P(LANG_SEARCH_IN_PLAYLIST);
313 items[i].function = search_playlist;
314 i++;
315 pstart++;
317 items[i].desc = ID2P(LANG_SAVE_DYNAMIC_PLAYLIST);
318 items[i].function = save_playlist;
319 i++;
320 pstart++;
322 items[i].desc = ID2P(LANG_SHUFFLE_PLAYLIST);
323 items[i].function = shuffle_playlist;
324 i++;
325 pstart++;
328 if (context == CONTEXT_TREE || context == CONTEXT_ID3DB)
330 if (audio_status() & AUDIO_STATUS_PLAY)
332 items[i].desc = ID2P(LANG_INSERT);
333 args[i].position = PLAYLIST_INSERT;
334 args[i].queue = false;
335 i++;
337 items[i].desc = ID2P(LANG_INSERT_FIRST);
338 args[i].position = PLAYLIST_INSERT_FIRST;
339 args[i].queue = false;
340 i++;
342 items[i].desc = ID2P(LANG_INSERT_LAST);
343 args[i].position = PLAYLIST_INSERT_LAST;
344 args[i].queue = false;
345 i++;
347 items[i].desc = ID2P(LANG_INSERT_SHUFFLED);
348 args[i].position = PLAYLIST_INSERT_SHUFFLED;
349 args[i].queue = false;
350 i++;
352 items[i].desc = ID2P(LANG_QUEUE);
353 args[i].position = PLAYLIST_INSERT;
354 args[i].queue = true;
355 i++;
357 items[i].desc = ID2P(LANG_QUEUE_FIRST);
358 args[i].position = PLAYLIST_INSERT_FIRST;
359 args[i].queue = true;
360 i++;
362 items[i].desc = ID2P(LANG_QUEUE_LAST);
363 args[i].position = PLAYLIST_INSERT_LAST;
364 args[i].queue = true;
365 i++;
367 items[i].desc = ID2P(LANG_QUEUE_SHUFFLED);
368 args[i].position = PLAYLIST_INSERT_SHUFFLED;
369 args[i].queue = true;
370 i++;
372 items[i].desc = ID2P(LANG_REPLACE);
373 args[i].position = PLAYLIST_REPLACE;
374 args[i].queue = false;
375 i++;
377 else if (((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) ||
378 (selected_file_attr & ATTR_DIRECTORY))
380 items[i].desc = ID2P(LANG_INSERT);
381 args[i].position = PLAYLIST_INSERT_LAST;
382 args[i].queue = false;
383 i++;
385 if (selected_file_attr & ATTR_DIRECTORY)
387 items[i].desc = ID2P(LANG_INSERT_SHUFFLED);
388 args[i].position = PLAYLIST_INSERT_SHUFFLED;
389 args[i].queue = false;
390 i++;
395 m = menu_init( items, i, NULL, NULL, NULL, NULL );
396 result = menu_show(m);
397 if (result >= 0 && result < pstart)
398 ret = items[result].function();
399 else if (result >= pstart)
400 ret = add_to_playlist(args[result].position, args[result].queue);
401 menu_exit(m);
403 return ret;
407 /* helper function to remove a non-empty directory */
408 static int remove_dir(char* dirname, int len)
410 int result = 0;
411 DIR* dir;
412 int dirlen = strlen(dirname);
413 int i;
415 dir = opendir(dirname);
416 if (!dir)
417 return -1; /* open error */
419 while(true)
421 struct dirent* entry;
422 /* walk through the directory content */
423 entry = readdir(dir);
424 if (!entry)
425 break;
427 dirname[dirlen] ='\0';
428 FOR_NB_SCREENS(i)
429 screens[i].puts(0,1,dirname);
431 /* append name to current directory */
432 snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
433 if (entry->attribute & ATTR_DIRECTORY)
434 { /* remove a subdirectory */
435 if (!strcmp((char *)entry->d_name, ".") ||
436 !strcmp((char *)entry->d_name, ".."))
437 continue; /* skip these */
439 /* inform the user which dir we're deleting */
441 result = remove_dir(dirname, len); /* recursion */
442 if (result)
443 break; /* or better continue, delete what we can? */
445 else
446 { /* remove a file */
447 FOR_NB_SCREENS(i)
448 screens[i].puts_scroll(0,2,entry->d_name);
449 result = remove(dirname);
451 #ifdef HAVE_LCD_BITMAP
452 FOR_NB_SCREENS(i)
453 screens[i].update();
454 #endif
455 if(ACTION_STD_CANCEL == get_action(CONTEXT_STD,TIMEOUT_NOBLOCK))
457 gui_syncsplash(HZ, true, str(LANG_MENU_SETTING_CANCEL));
458 result = -1;
459 break;
462 closedir(dir);
464 if (!result)
465 { /* remove the now empty directory */
466 dirname[dirlen] = '\0'; /* terminate to original length */
468 result = rmdir(dirname);
471 return result;
475 /* share code for file and directory deletion, saves space */
476 static bool delete_handler(bool is_dir)
478 char *lines[]={
479 (char *)str(LANG_REALLY_DELETE),
480 selected_file
482 char *yes_lines[]={
483 (char *)str(LANG_DELETED),
484 selected_file
487 struct text_message message={lines, 2};
488 struct text_message yes_message={yes_lines, 2};
489 if(gui_syncyesno_run(&message, &yes_message, NULL)!=YESNO_YES)
490 return false;
491 int res;
492 if (is_dir)
494 char pathname[MAX_PATH]; /* space to go deep */
495 cpu_boost(true);
496 strncpy(pathname, selected_file, sizeof pathname);
497 res = remove_dir(pathname, sizeof(pathname));
498 cpu_boost(false);
500 else
501 res = remove(selected_file);
503 if (!res) {
504 onplay_result = ONPLAY_RELOAD_DIR;
506 return false;
510 static bool delete_file(void)
512 return delete_handler(false);
515 static bool delete_dir(void)
517 return delete_handler(true);
520 #if LCD_DEPTH > 1
521 static bool set_backdrop(void)
523 /* load the image */
524 if(load_main_backdrop(selected_file)) {
525 gui_syncsplash(HZ, true, str(LANG_BACKDROP_LOADED));
526 set_file(selected_file, (char *)global_settings.backdrop_file, MAX_FILENAME);
527 show_main_backdrop();
528 return true;
529 } else {
530 gui_syncsplash(HZ, true, str(LANG_BACKDROP_FAILED));
531 return false;
534 #endif
536 static bool rename_file(void)
538 char newname[MAX_PATH];
539 char* ptr = strrchr(selected_file, '/') + 1;
540 int pathlen = (ptr - selected_file);
541 strncpy(newname, selected_file, sizeof newname);
542 if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
543 if (!strlen(newname + pathlen) ||
544 (rename(selected_file, newname) < 0)) {
545 lcd_clear_display();
546 lcd_puts(0,0,str(LANG_RENAME));
547 lcd_puts(0,1,str(LANG_FAILED));
548 lcd_update();
549 sleep(HZ*2);
551 else
552 onplay_result = ONPLAY_RELOAD_DIR;
555 return false;
558 static bool create_dir(void)
560 char dirname[MAX_PATH];
561 char *cwd;
562 int rc;
563 int pathlen;
565 cwd = getcwd(NULL, 0);
566 memset(dirname, 0, sizeof dirname);
568 snprintf(dirname, sizeof dirname, "%s/",
569 cwd[1] ? cwd : "");
571 pathlen = strlen(dirname);
572 rc = kbd_input(dirname + pathlen, (sizeof dirname)-pathlen);
573 if (rc < 0)
574 return false;
576 rc = mkdir(dirname, 0);
577 if (rc < 0) {
578 gui_syncsplash(HZ, true, (unsigned char *)"%s %s",
579 str(LANG_CREATE_DIR), str(LANG_FAILED));
580 } else {
581 onplay_result = ONPLAY_RELOAD_DIR;
584 return true;
587 static bool properties(void)
589 if(PLUGIN_USB_CONNECTED == filetype_load_plugin("properties",
590 selected_file))
591 onplay_result = ONPLAY_RELOAD_DIR;
592 return false;
595 /* Store the current selection in the clipboard */
596 static bool clipboard_clip(bool copy)
598 clipboard_selection[0] = 0;
599 strncpy(clipboard_selection, selected_file, MAX_PATH);
600 clipboard_selection_attr = selected_file_attr;
601 clipboard_is_copy = copy;
603 return true;
606 static bool clipboard_cut(void)
608 return clipboard_clip(false);
611 static bool clipboard_copy(void)
613 return clipboard_clip(true);
616 /* Paste a file to a new directory. Will overwrite always. */
617 static bool clipboard_pastefile(const char *src, const char *target, bool copy)
619 int src_fd, target_fd, buffersize, size, bytesread, byteswritten;
620 char *buffer;
621 bool result = false;
623 if (copy) {
624 /* See if we can get the plugin buffer for the file copy buffer */
625 buffer = (char *) plugin_get_buffer(&buffersize);
626 if (buffer == NULL || buffersize < 512) {
627 /* Not large enough, try for a disk sector worth of stack instead */
628 buffersize = 512;
629 buffer = (char *) __builtin_alloca(buffersize);
632 if (buffer == NULL) {
633 return false;
636 buffersize &= ~0x1ff; /* Round buffer size to multiple of sector size */
638 src_fd = open(src, O_RDONLY);
640 if (src_fd >= 0) {
641 target_fd = creat(target, O_WRONLY);
643 if (target_fd >= 0) {
644 result = true;
646 size = filesize(src_fd);
648 if (size == -1) {
649 result = false;
652 while(size > 0) {
653 bytesread = read(src_fd, buffer, buffersize);
655 if (bytesread == -1) {
656 result = false;
657 break;
660 size -= bytesread;
662 while(bytesread > 0) {
663 byteswritten = write(target_fd, buffer, bytesread);
665 if (byteswritten == -1) {
666 result = false;
667 size = 0;
668 break;
671 bytesread -= byteswritten;
675 close(target_fd);
677 /* Copy failed. Cleanup. */
678 if (!result) {
679 remove(target);
683 close(src_fd);
685 } else {
686 result = rename(src, target) == 0;
687 #ifdef HAVE_MULTIVOLUME
688 if (!result) {
689 if (errno == EXDEV) {
690 /* Failed because cross volume rename doesn't work. Copy instead */
691 result = clipboard_pastefile(src, target, true);
693 if (result) {
694 result = remove(src);
698 #endif
701 return result;
704 /* Paste a directory to a new location. Designed to be called by clipboard_paste */
705 static bool clipboard_pastedirectory(char *src, int srclen, char *target, int targetlen, bool copy)
707 DIR *srcdir;
708 int srcdirlen = strlen(src);
709 int targetdirlen = strlen(target);
710 int fd;
711 bool result = true;
713 /* Check if the target exists */
714 fd = open(target, O_RDONLY);
715 close(fd);
717 if (fd < 0) {
718 if (!copy) {
719 /* Just move the directory */
720 result = rename(src, target) == 0;
722 #ifdef HAVE_MULTIVOLUME
723 if (!result && errno == EXDEV) {
724 /* Try a copy as we're going across devices */
725 result = clipboard_pastedirectory(src, srclen, target, targetlen, true);
727 /* If it worked, remove the source directory */
728 if (result) {
729 remove_dir(src, srclen);
732 #endif
733 return result;
734 } else {
735 /* Make a directory to copy things to */
736 result = mkdir(target, 0) == 0;
740 /* Check if something went wrong already */
741 if (!result) {
742 return result;
745 srcdir = opendir(src);
746 if (!srcdir) {
747 return false;
750 /* This loop will exit as soon as there's a problem */
751 while(result)
753 struct dirent* entry;
754 /* walk through the directory content */
755 entry = readdir(srcdir);
756 if (!entry)
757 break;
759 /* append name to current directory */
760 snprintf(src+srcdirlen, srclen-srcdirlen, "/%s", entry->d_name);
761 snprintf(target+targetdirlen, targetlen-targetdirlen, "/%s", entry->d_name);
763 DEBUGF("Copy %s to %s\n", src, target);
765 if (entry->attribute & ATTR_DIRECTORY)
766 { /* copy/move a subdirectory */
767 if (!strcmp((char *)entry->d_name, ".") ||
768 !strcmp((char *)entry->d_name, ".."))
769 continue; /* skip these */
771 result = clipboard_pastedirectory(src, srclen, target, targetlen, copy); /* recursion */
773 else
774 { /* copy/move a file */
775 result = clipboard_pastefile(src, target, copy);
779 closedir(srcdir);
781 if (result) {
782 src[srcdirlen] = '\0'; /* terminate to original length */
783 target[targetdirlen] = '\0'; /* terminate to original length */
786 return result;
789 /* Paste the clipboard to the current directory */
790 static bool clipboard_paste(void)
792 char target[MAX_PATH];
793 char *cwd, *nameptr;
794 bool success;
795 int target_fd;
797 unsigned char *lines[]={str(LANG_REALLY_OVERWRITE)};
798 struct text_message message={(char **)lines, 1};
800 /* Get the name of the current directory */
801 cwd = getcwd(NULL, 0);
802 snprintf(target, sizeof target, "%s", cwd[1] ? cwd : "");
804 /* Figure out the name of the selection */
805 nameptr = strrchr(clipboard_selection, '/');
807 /* Paste the name on to the current directory to give us our final target */
808 strcat(target, nameptr);
810 /* Check if we're going to overwrite */
811 target_fd = open(target, O_RDONLY);
812 close(target_fd);
814 /* If the target existed but they choose not to overwite, exit */
815 if (target_fd >= 0 &&
816 (gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO)) {
817 return false;
820 /* Now figure out what we're doing */
821 if (clipboard_selection_attr & ATTR_DIRECTORY) {
822 /* Recursion. Set up external stack */
823 char srcpath[MAX_PATH];
824 char targetpath[MAX_PATH];
826 strncpy(srcpath, clipboard_selection, sizeof srcpath);
827 strncpy(targetpath, target, sizeof targetpath);
829 success = clipboard_pastedirectory(srcpath, sizeof(srcpath), target, sizeof(targetpath), clipboard_is_copy);
830 } else {
831 success = clipboard_pastefile(clipboard_selection, target, clipboard_is_copy);
834 /* Did it work? */
835 if (success) {
836 /* Reset everything */
837 clipboard_selection[0] = 0;
838 clipboard_selection_attr = 0;
839 clipboard_is_copy = false;
841 /* Force reload of the current directory */
842 onplay_result = ONPLAY_RELOAD_DIR;
843 } else {
844 gui_syncsplash(HZ, true, (unsigned char *)"%s %s",
845 str(LANG_PASTE), str(LANG_FAILED));
848 return true;
851 static bool exit_to_main;
853 /* catch MENU_EXIT_MENU within context menu to call the main menu afterwards */
854 static int onplay_callback(int key, int menu)
856 (void)menu;
858 if (key == ACTION_STD_MENU)
859 exit_to_main = true;
861 return key;
864 int onplay(char* file, int attr, int from)
866 #if CONFIG_CODEC == SWCODEC
867 struct menu_item items[14]; /* increase this if you add entries! */
868 #else
869 struct menu_item items[12];
870 #endif
871 int m, i=0, result;
872 #if LCD_DEPTH > 1
873 char *suffix;
874 #endif
876 onplay_result = ONPLAY_OK;
877 context=from;
878 exit_to_main = false;
879 selected_file = file;
880 selected_file_attr = attr;
882 if (context == CONTEXT_WPS)
884 items[i].desc = ID2P(LANG_SOUND_SETTINGS);
885 items[i].function = sound_menu;
886 i++;
889 if (context == CONTEXT_WPS ||
890 context == CONTEXT_TREE ||
891 context == CONTEXT_ID3DB)
893 items[i].desc = ID2P(LANG_PLAYLIST);
894 items[i].function = playlist_options;
895 i++;
896 items[i].desc = ID2P(LANG_CATALOG);
897 items[i].function = cat_playlist_options;
898 i++;
901 if (context == CONTEXT_WPS)
903 items[i].desc = ID2P(LANG_BOOKMARK_MENU);
904 items[i].function = bookmark_menu;
905 i++;
908 if (file)
910 if (context == CONTEXT_WPS)
912 items[i].desc = ID2P(LANG_MENU_SHOW_ID3_INFO);
913 items[i].function = browse_id3;
914 i++;
915 /* if(rundb_initialized)
917 items[i].desc = ID2P(LANG_MENU_SET_RATING);
918 items[i].function = set_rating;
919 i++;
923 #ifdef HAVE_MULTIVOLUME
924 if (!(attr & ATTR_VOLUME)) /* no rename+delete for volumes */
925 #endif
927 if (context == CONTEXT_TREE)
929 items[i].desc = ID2P(LANG_RENAME);
930 items[i].function = rename_file;
931 i++;
933 items[i].desc = ID2P(LANG_CUT);
934 items[i].function = clipboard_cut;
935 i++;
937 items[i].desc = ID2P(LANG_COPY);
938 items[i].function = clipboard_copy;
939 i++;
941 if (clipboard_selection[0] != 0) /* Something in the clipboard? */
943 items[i].desc = ID2P(LANG_PASTE);
944 items[i].function = clipboard_paste;
945 i++;
949 if (!(attr & ATTR_DIRECTORY) && context == CONTEXT_TREE)
951 items[i].desc = ID2P(LANG_DELETE);
952 items[i].function = delete_file;
953 i++;
955 #if LCD_DEPTH > 1
956 suffix = strrchr(file, '.');
957 if (suffix)
959 if (strcasecmp(suffix, ".bmp") == 0)
961 items[i].desc = ID2P(LANG_SET_AS_BACKDROP);
962 items[i].function = set_backdrop;
963 i++;
966 #endif
968 else
970 if (context == CONTEXT_TREE)
972 items[i].desc = ID2P(LANG_DELETE_DIR);
973 items[i].function = delete_dir;
974 i++;
979 if (!(attr & ATTR_DIRECTORY))
981 items[i].desc = ID2P(LANG_ONPLAY_OPEN_WITH);
982 items[i].function = list_viewers;
983 i++;
986 else
988 if (strlen(clipboard_selection) != 0)
990 items[i].desc = ID2P(LANG_PASTE);
991 items[i].function = clipboard_paste;
992 i++;
996 if (context == CONTEXT_TREE)
998 items[i].desc = ID2P(LANG_CREATE_DIR);
999 items[i].function = create_dir;
1000 i++;
1002 items[i].desc = ID2P(LANG_PROPERTIES);
1003 items[i].function = properties;
1004 i++;
1007 if (context == CONTEXT_WPS)
1009 #ifdef HAVE_PITCHSCREEN
1010 /* Pitch screen access */
1011 items[i].desc = ID2P(LANG_PITCH);
1012 items[i].function = pitch_screen;
1013 i++;
1014 #endif
1015 #if CONFIG_CODEC == SWCODEC
1016 /* Equalizer menu items */
1017 items[i].desc = ID2P(LANG_EQUALIZER_GRAPHICAL);
1018 items[i].function = eq_menu_graphical;
1019 i++;
1020 items[i].desc = ID2P(LANG_EQUALIZER_BROWSE);
1021 items[i].function = eq_browse_presets;
1022 i++;
1023 #endif
1026 /* DIY menu handling, since we want to exit after selection */
1027 if (i)
1029 m = menu_init( items, i, onplay_callback, NULL, NULL, NULL );
1030 result = menu_show(m);
1031 if (result >= 0)
1032 items[result].function();
1033 menu_exit(m);
1035 if (exit_to_main)
1036 result = main_menu();
1038 #ifdef HAVE_LCD_BITMAP
1039 if (global_settings.statusbar)
1040 lcd_setmargins(0, STATUSBAR_HEIGHT);
1041 else
1042 lcd_setmargins(0, 0);
1043 #endif
1046 return onplay_result;