Add platform file for Iaudio M5.
[Rockbox.git] / apps / onplay.c
bloba0da3ac2d95e4ead6d0d482cae527f1bebcc6c43
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 "menus/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);
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);
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;
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];
825 if (!strncmp(clipboard_selection, target, strlen(clipboard_selection)))
827 /* Do not allow the user to paste a directory into a dir they are copying */
828 success = 0;
830 else
832 strncpy(srcpath, clipboard_selection, sizeof srcpath);
833 strncpy(targetpath, target, sizeof targetpath);
835 success = clipboard_pastedirectory(srcpath, sizeof(srcpath),
836 target, sizeof(targetpath), clipboard_is_copy);
838 } else {
839 success = clipboard_pastefile(clipboard_selection, target, clipboard_is_copy);
842 /* Did it work? */
843 if (success) {
844 /* Reset everything */
845 clipboard_selection[0] = 0;
846 clipboard_selection_attr = 0;
847 clipboard_is_copy = false;
849 /* Force reload of the current directory */
850 onplay_result = ONPLAY_RELOAD_DIR;
851 } else {
852 gui_syncsplash(HZ, true, (unsigned char *)"%s %s",
853 str(LANG_PASTE), str(LANG_FAILED));
856 return true;
859 static bool exit_to_main;
861 /* catch MENU_EXIT_MENU within context menu to call the main menu afterwards */
862 static int onplay_callback(int key, int menu)
864 (void)menu;
866 if (key == ACTION_STD_MENU)
867 exit_to_main = true;
869 return key;
872 int onplay(char* file, int attr, int from)
874 #if CONFIG_CODEC == SWCODEC
875 struct menu_item items[14]; /* increase this if you add entries! */
876 #else
877 struct menu_item items[12];
878 #endif
879 int m, i=0, result;
880 #if LCD_DEPTH > 1
881 char *suffix;
882 #endif
884 onplay_result = ONPLAY_OK;
885 context=from;
886 exit_to_main = false;
887 selected_file = file;
888 selected_file_attr = attr;
890 if (context == CONTEXT_WPS)
892 items[i].desc = ID2P(LANG_SOUND_SETTINGS);
893 items[i].function = sound_menu;
894 i++;
897 if (file && (context == CONTEXT_WPS ||
898 context == CONTEXT_TREE ||
899 context == CONTEXT_ID3DB))
901 items[i].desc = ID2P(LANG_PLAYLIST);
902 items[i].function = playlist_options;
903 i++;
904 items[i].desc = ID2P(LANG_CATALOG);
905 items[i].function = cat_playlist_options;
906 i++;
909 if (context == CONTEXT_WPS)
911 items[i].desc = ID2P(LANG_BOOKMARK_MENU);
912 items[i].function = bookmark_menu;
913 i++;
916 if (file)
918 if (context == CONTEXT_WPS)
920 items[i].desc = ID2P(LANG_MENU_SHOW_ID3_INFO);
921 items[i].function = browse_id3;
922 i++;
923 /* if(rundb_initialized)
925 items[i].desc = ID2P(LANG_MENU_SET_RATING);
926 items[i].function = set_rating;
927 i++;
931 #ifdef HAVE_MULTIVOLUME
932 if (!(attr & ATTR_VOLUME)) /* no rename+delete for volumes */
933 #endif
935 if (context == CONTEXT_TREE)
937 items[i].desc = ID2P(LANG_RENAME);
938 items[i].function = rename_file;
939 i++;
941 items[i].desc = ID2P(LANG_CUT);
942 items[i].function = clipboard_cut;
943 i++;
945 items[i].desc = ID2P(LANG_COPY);
946 items[i].function = clipboard_copy;
947 i++;
949 if (clipboard_selection[0] != 0) /* Something in the clipboard? */
951 items[i].desc = ID2P(LANG_PASTE);
952 items[i].function = clipboard_paste;
953 i++;
957 if (!(attr & ATTR_DIRECTORY) && context == CONTEXT_TREE)
959 items[i].desc = ID2P(LANG_DELETE);
960 items[i].function = delete_file;
961 i++;
963 #if LCD_DEPTH > 1
964 suffix = strrchr(file, '.');
965 if (suffix)
967 if (strcasecmp(suffix, ".bmp") == 0)
969 items[i].desc = ID2P(LANG_SET_AS_BACKDROP);
970 items[i].function = set_backdrop;
971 i++;
974 #endif
976 else
978 if (context == CONTEXT_TREE)
980 items[i].desc = ID2P(LANG_DELETE_DIR);
981 items[i].function = delete_dir;
982 i++;
987 if (!(attr & ATTR_DIRECTORY))
989 items[i].desc = ID2P(LANG_ONPLAY_OPEN_WITH);
990 items[i].function = list_viewers;
991 i++;
994 else
996 if (strlen(clipboard_selection) != 0)
998 items[i].desc = ID2P(LANG_PASTE);
999 items[i].function = clipboard_paste;
1000 i++;
1004 if (context == CONTEXT_TREE)
1006 items[i].desc = ID2P(LANG_CREATE_DIR);
1007 items[i].function = create_dir;
1008 i++;
1009 if (file)
1011 items[i].desc = ID2P(LANG_PROPERTIES);
1012 items[i].function = properties;
1013 i++;
1017 if (context == CONTEXT_WPS)
1019 #ifdef HAVE_PITCHSCREEN
1020 /* Pitch screen access */
1021 items[i].desc = ID2P(LANG_PITCH);
1022 items[i].function = pitch_screen;
1023 i++;
1024 #endif
1025 #if CONFIG_CODEC == SWCODEC
1026 /* Equalizer menu items */
1027 items[i].desc = ID2P(LANG_EQUALIZER_GRAPHICAL);
1028 items[i].function = eq_menu_graphical;
1029 i++;
1030 items[i].desc = ID2P(LANG_EQUALIZER_BROWSE);
1031 items[i].function = eq_browse_presets;
1032 i++;
1033 #endif
1036 /* DIY menu handling, since we want to exit after selection */
1037 if (i)
1039 m = menu_init( items, i, onplay_callback, NULL, NULL, NULL );
1040 result = menu_show(m);
1041 if (result >= 0)
1042 items[result].function();
1043 menu_exit(m);
1045 if (exit_to_main)
1046 onplay_result = ONPLAY_MAINMENU;
1048 #ifdef HAVE_LCD_BITMAP
1049 if (global_settings.statusbar)
1050 lcd_setmargins(0, STATUSBAR_HEIGHT);
1051 else
1052 lcd_setmargins(0, 0);
1053 #endif
1056 return onplay_result;