1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
43 #include "statusbar.h"
44 #include "playlist_viewer.h"
47 #include "filetypes.h"
53 #include "menus/exported_menus.h"
54 #ifdef HAVE_LCD_BITMAP
57 #include "sound_menu.h"
58 #if CONFIG_CODEC == SWCODEC
59 #include "menus/eq_menu.h"
61 #include "playlist_menu.h"
62 #include "playlist_catalog.h"
70 static char* selected_file
= NULL
;
71 static int selected_file_attr
= 0;
72 static int onplay_result
= ONPLAY_OK
;
73 static char clipboard_selection
[MAX_PATH
];
74 static int clipboard_selection_attr
= 0;
75 static bool clipboard_is_copy
= false;
77 /* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */
78 #define MAKE_ONPLAYMENU( name, str, callback, icon, ... ) \
79 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
80 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
81 static const struct menu_item_ex name = \
82 {MT_MENU|MENU_HAS_DESC|MENU_EXITAFTERTHISMENU| \
83 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
84 { (void*)name##_},{.callback_and_desc = & name##__}};
86 #ifdef HAVE_LCD_BITMAP
87 static void draw_slider(void);
91 /* ----------------------------------------------------------------------- */
92 /* Displays the bookmark menu options for the user to decide. This is an */
93 /* interface function. */
94 /* ----------------------------------------------------------------------- */
96 static int bookmark_menu_callback(int action
,
97 const struct menu_item_ex
*this_item
);
98 MENUITEM_FUNCTION(bookmark_create_menu_item
, 0,
99 ID2P(LANG_BOOKMARK_MENU_CREATE
),
100 bookmark_create_menu
, NULL
, NULL
, Icon_Bookmark
);
101 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
102 ID2P(LANG_BOOKMARK_MENU_LIST
),
103 bookmark_load_menu
, NULL
,
104 bookmark_menu_callback
, Icon_Bookmark
);
105 MAKE_MENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
), bookmark_menu_callback
,
106 Icon_Bookmark
, &bookmark_create_menu_item
, &bookmark_load_menu_item
);
107 static int bookmark_menu_callback(int action
,
108 const struct menu_item_ex
*this_item
)
113 case ACTION_REQUEST_MENUITEM
:
114 if (this_item
== &bookmark_load_menu_item
)
116 if (bookmark_exist() == 0)
117 return ACTION_EXIT_MENUITEM
;
119 /* hide the bookmark menu if there is no playback */
120 else if ((audio_status() & AUDIO_STATUS_PLAY
) == 0)
121 return ACTION_EXIT_MENUITEM
;
123 #ifdef HAVE_LCD_CHARCELLS
124 case ACTION_ENTER_MENUITEM
:
125 status_set_param(true);
128 case ACTION_EXIT_MENUITEM
:
129 #ifdef HAVE_LCD_CHARCELLS
130 status_set_param(false);
138 static bool list_viewers(void)
140 int ret
= filetype_list_viewers(selected_file
);
141 if (ret
== PLUGIN_USB_CONNECTED
)
142 onplay_result
= ONPLAY_RELOAD_DIR
;
146 static bool shuffle_playlist(void)
148 playlist_sort(NULL
, true);
149 playlist_randomise(NULL
, current_tick
, true);
154 static bool save_playlist(void)
156 save_playlist_screen(NULL
);
160 static bool add_to_playlist(int position
, bool queue
)
162 bool new_playlist
= !(audio_status() & AUDIO_STATUS_PLAY
);
163 const char *lines
[] = {
164 ID2P(LANG_RECURSE_DIRECTORY_QUESTION
),
167 const struct text_message message
={lines
, 2};
169 gui_syncsplash(0, ID2P(LANG_WAIT
));
172 playlist_create(NULL
, NULL
);
174 /* always set seed before inserting shuffled */
175 if (position
== PLAYLIST_INSERT_SHUFFLED
)
179 if (context
== CONTEXT_ID3DB
)
181 tagtree_insert_selection_playlist(position
, queue
);
186 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_AUDIO
)
187 playlist_insert_track(NULL
, selected_file
, position
, queue
, true);
188 else if (selected_file_attr
& ATTR_DIRECTORY
)
190 bool recurse
= false;
192 if (global_settings
.recursive_dir_insert
!= RECURSE_ASK
)
193 recurse
= (bool)global_settings
.recursive_dir_insert
;
196 /* Ask if user wants to recurse directory */
197 recurse
= (gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
);
200 playlist_insert_directory(NULL
, selected_file
, position
, queue
,
203 else if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)
204 playlist_insert_playlist(NULL
, selected_file
, position
, queue
);
207 if (new_playlist
&& (playlist_amount() > 0))
209 /* nothing is currently playing so begin playing what we just
211 if (global_settings
.playlist_shuffle
)
212 playlist_shuffle(current_tick
, -1);
214 gui_syncstatusbar_draw(&statusbars
, false);
215 onplay_result
= ONPLAY_START_PLAY
;
221 static bool view_playlist(void)
223 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
226 result
= playlist_viewer_ex(selected_file
);
228 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
229 onplay_result
== ONPLAY_OK
)
230 /* playlist was started from viewer */
231 onplay_result
= ONPLAY_START_PLAY
;
236 static bool cat_add_to_a_playlist(void)
238 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
242 static bool cat_add_to_a_new_playlist(void)
244 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
249 static int cat_playlist_callback(int action
,
250 const struct menu_item_ex
*this_item
);
251 MENUITEM_FUNCTION(cat_view_lists
, 0, ID2P(LANG_CATALOG_VIEW
),
252 catalog_view_playlists
, 0, cat_playlist_callback
,
254 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
255 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
256 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
257 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
258 MAKE_MENU( cat_playlist_menu
, ID2P(LANG_CATALOG
), cat_playlist_callback
,
259 Icon_Playlist
, &cat_view_lists
,
260 &cat_add_to_list
, &cat_add_to_new
);
262 static int cat_playlist_callback(int action
,
263 const struct menu_item_ex
*this_item
)
265 if (((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
) &&
266 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_M3U
) &&
267 ((selected_file_attr
& ATTR_DIRECTORY
) == 0))
269 return ACTION_EXIT_MENUITEM
;
274 case ACTION_REQUEST_MENUITEM
:
275 if (this_item
== &cat_view_lists
)
277 if (context
== CONTEXT_WPS
)
280 else if (selected_file
&& /* set before calling this menu,
282 ((audio_status() & AUDIO_STATUS_PLAY
&&
283 context
== CONTEXT_WPS
) ||
284 context
== CONTEXT_TREE
))
289 return ACTION_EXIT_MENUITEM
;
296 /* CONTEXT_WPS playlist options */
297 MENUITEM_FUNCTION(playlist_viewer_item
, 0,
298 ID2P(LANG_VIEW_DYNAMIC_PLAYLIST
), playlist_viewer
,
299 NULL
, NULL
, Icon_Playlist
);
300 MENUITEM_FUNCTION(search_playlist_item
, 0,
301 ID2P(LANG_SEARCH_IN_PLAYLIST
), search_playlist
,
302 NULL
, NULL
, Icon_Playlist
);
303 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
304 save_playlist
, NULL
, NULL
, Icon_Playlist
);
305 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
306 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
307 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
309 &playlist_viewer_item
, &search_playlist_item
,
310 &playlist_save_item
, &reshuffle_item
313 /* CONTEXT_[TREE|ID3DB] playlist options */
314 static int playlist_insert_func(void *param
)
316 add_to_playlist((intptr_t)param
, false);
319 static int playlist_queue_func(void *param
)
321 add_to_playlist((intptr_t)param
, true);
324 static int treeplaylist_wplayback_callback(int action
,
325 const struct menu_item_ex
*
331 case ACTION_REQUEST_MENUITEM
:
332 if (audio_status() & AUDIO_STATUS_PLAY
)
335 return ACTION_EXIT_MENUITEM
;
341 static int treeplaylist_callback(int action
,
342 const struct menu_item_ex
*this_item
);
345 MENUITEM_FUNCTION(i_pl_item_no_play
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
346 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
347 treeplaylist_callback
, Icon_Playlist
);
348 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
349 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
350 treeplaylist_wplayback_callback
, Icon_Playlist
);
351 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
352 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
353 treeplaylist_wplayback_callback
, Icon_Playlist
);
354 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
355 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
356 treeplaylist_wplayback_callback
, Icon_Playlist
);
357 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
358 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
359 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
, treeplaylist_callback
,
362 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
363 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
364 treeplaylist_wplayback_callback
, Icon_Playlist
);
365 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
366 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
367 treeplaylist_wplayback_callback
, Icon_Playlist
);
368 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
369 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
370 treeplaylist_wplayback_callback
, Icon_Playlist
);
371 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
372 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
373 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
374 treeplaylist_wplayback_callback
, Icon_Playlist
);
375 /* replace playlist */
376 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
377 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
378 treeplaylist_wplayback_callback
, Icon_Playlist
);
381 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
383 treeplaylist_callback
, Icon_Playlist
);
385 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_PLAYLIST
),
386 treeplaylist_callback
, Icon_Playlist
,
392 &i_pl_item_no_play
, &i_pl_item
, &i_first_pl_item
,
393 &i_last_pl_item
, &i_shuf_pl_item
,
396 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
402 static int treeplaylist_callback(int action
,
403 const struct menu_item_ex
*this_item
)
408 case ACTION_REQUEST_MENUITEM
:
409 if (this_item
== &tree_playlist_menu
)
411 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
413 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
414 (selected_file_attr
& ATTR_DIRECTORY
))
419 return ACTION_EXIT_MENUITEM
;
421 else if (this_item
== &view_playlist_item
)
423 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
424 context
== CONTEXT_TREE
)
427 return ACTION_EXIT_MENUITEM
;
429 else if (this_item
== &i_pl_item_no_play
)
431 if (!(audio_status() & AUDIO_STATUS_PLAY
))
436 return ACTION_EXIT_MENUITEM
;
438 else if (this_item
== &i_shuf_pl_item
)
441 if (audio_status() & AUDIO_STATUS_PLAY
)
445 else if ((this_item
== &i_shuf_pl_item
) &&
446 ((selected_file_attr
& ATTR_DIRECTORY
) ||
447 ((selected_file_attr
& FILE_ATTR_MASK
) ==
452 return ACTION_EXIT_MENUITEM
;
459 /* helper function to remove a non-empty directory */
460 static int remove_dir(char* dirname
, int len
)
464 int dirlen
= strlen(dirname
);
467 dir
= opendir(dirname
);
469 return -1; /* open error */
473 struct dirent
* entry
;
474 /* walk through the directory content */
475 entry
= readdir(dir
);
479 dirname
[dirlen
] ='\0';
481 screens
[i
].puts(0,1,dirname
);
485 /* append name to current directory */
486 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
487 if (entry
->attribute
& ATTR_DIRECTORY
)
488 { /* remove a subdirectory */
489 if (!strcmp((char *)entry
->d_name
, ".") ||
490 !strcmp((char *)entry
->d_name
, ".."))
491 continue; /* skip these */
493 /* inform the user which dir we're deleting */
495 result
= remove_dir(dirname
, len
); /* recursion */
497 break; /* or better continue, delete what we can? */
500 { /* remove a file */
502 result
= remove(dirname
);
504 if(ACTION_STD_CANCEL
== get_action(CONTEXT_STD
,TIMEOUT_NOBLOCK
))
506 gui_syncsplash(HZ
, ID2P(LANG_CANCEL
));
514 { /* remove the now empty directory */
515 dirname
[dirlen
] = '\0'; /* terminate to original length */
517 result
= rmdir(dirname
);
524 /* share code for file and directory deletion, saves space */
525 static bool delete_handler(bool is_dir
)
527 const char *lines
[]={
528 ID2P(LANG_REALLY_DELETE
),
531 const char *yes_lines
[]={
536 struct text_message message
={lines
, 2};
537 struct text_message yes_message
={yes_lines
, 2};
539 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
542 gui_syncsplash(0, str(LANG_DELETING
));
547 char pathname
[MAX_PATH
]; /* space to go deep */
549 strncpy(pathname
, selected_file
, sizeof pathname
);
550 res
= remove_dir(pathname
, sizeof(pathname
));
554 res
= remove(selected_file
);
557 onplay_result
= ONPLAY_RELOAD_DIR
;
563 static bool delete_file(void)
565 return delete_handler(false);
568 static bool delete_dir(void)
570 return delete_handler(true);
574 static bool set_backdrop(void)
577 if(load_main_backdrop(selected_file
)) {
578 gui_syncsplash(HZ
, str(LANG_BACKDROP_LOADED
));
579 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
581 show_main_backdrop();
584 gui_syncsplash(HZ
, str(LANG_BACKDROP_FAILED
));
590 static bool rename_file(void)
592 char newname
[MAX_PATH
];
593 char* ptr
= strrchr(selected_file
, '/') + 1;
594 int pathlen
= (ptr
- selected_file
);
595 strncpy(newname
, selected_file
, sizeof newname
);
596 if (!kbd_input(newname
+ pathlen
, (sizeof newname
)-pathlen
)) {
597 if (!strlen(newname
+ pathlen
) ||
598 (rename(selected_file
, newname
) < 0)) {
600 lcd_puts(0,0,str(LANG_RENAME
));
601 lcd_puts(0,1,str(LANG_FAILED
));
603 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
607 onplay_result
= ONPLAY_RELOAD_DIR
;
613 static bool create_dir(void)
615 char dirname
[MAX_PATH
];
620 cwd
= getcwd(NULL
, 0);
621 memset(dirname
, 0, sizeof dirname
);
623 snprintf(dirname
, sizeof dirname
, "%s/",
626 pathlen
= strlen(dirname
);
627 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
633 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
634 gui_syncsplash(HZ
, (unsigned char *)"%s %s",
635 str(LANG_CREATE_DIR
), str(LANG_FAILED
));
637 onplay_result
= ONPLAY_RELOAD_DIR
;
643 static bool properties(void)
645 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("properties",
647 onplay_result
= ONPLAY_RELOAD_DIR
;
651 /* Store the current selection in the clipboard */
652 static bool clipboard_clip(bool copy
)
654 clipboard_selection
[0] = 0;
655 strncpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
656 clipboard_selection_attr
= selected_file_attr
;
657 clipboard_is_copy
= copy
;
662 static bool clipboard_cut(void)
664 return clipboard_clip(false);
667 static bool clipboard_copy(void)
669 return clipboard_clip(true);
672 #ifdef HAVE_LCD_BITMAP
673 static void draw_slider(void)
678 show_busy_slider(&screens
[i
], 1, LCD_HEIGHT
-2*screens
[i
].char_height
,
679 LCD_WIDTH
-2, 2*screens
[i
].char_height
-1);
685 /* Paste a file to a new directory. Will overwrite always. */
686 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
688 int src_fd
, target_fd
;
690 ssize_t size
, bytesread
, byteswritten
;
695 /* See if we can get the plugin buffer for the file copy buffer */
696 buffer
= (char *) plugin_get_buffer(&buffersize
);
697 if (buffer
== NULL
|| buffersize
< 512) {
698 /* Not large enough, try for a disk sector worth of stack
701 buffer
= (char *) __builtin_alloca(buffersize
);
704 if (buffer
== NULL
) {
708 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
711 src_fd
= open(src
, O_RDONLY
);
714 target_fd
= creat(target
);
716 if (target_fd
>= 0) {
719 size
= filesize(src_fd
);
726 bytesread
= read(src_fd
, buffer
, buffersize
);
728 if (bytesread
== -1) {
735 while(bytesread
> 0) {
736 byteswritten
= write(target_fd
, buffer
, bytesread
);
738 if (byteswritten
== -1) {
744 bytesread
-= byteswritten
;
751 /* Copy failed. Cleanup. */
760 result
= rename(src
, target
) == 0;
761 #ifdef HAVE_MULTIVOLUME
763 if (errno
== EXDEV
) {
764 /* Failed because cross volume rename doesn't work. Copy
766 result
= clipboard_pastefile(src
, target
, true);
769 result
= remove(src
) == 0;
779 /* Paste a directory to a new location. Designed to be called by
781 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
782 int targetlen
, bool copy
)
785 int srcdirlen
= strlen(src
);
786 int targetdirlen
= strlen(target
);
789 if (!file_exists(target
)) {
791 /* Just move the directory */
792 result
= rename(src
, target
) == 0;
794 #ifdef HAVE_MULTIVOLUME
795 if (!result
&& errno
== EXDEV
) {
796 /* Try a copy as we're going across devices */
797 result
= clipboard_pastedirectory(src
, srclen
, target
,
800 /* If it worked, remove the source directory */
802 remove_dir(src
, srclen
);
808 /* Make a directory to copy things to */
809 result
= mkdir(target
) == 0;
813 /* Check if something went wrong already */
818 srcdir
= opendir(src
);
823 /* This loop will exit as soon as there's a problem */
826 struct dirent
* entry
;
827 /* walk through the directory content */
828 entry
= readdir(srcdir
);
832 /* append name to current directory */
833 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
834 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
837 DEBUGF("Copy %s to %s\n", src
, target
);
839 if (entry
->attribute
& ATTR_DIRECTORY
)
840 { /* copy/move a subdirectory */
841 if (!strcmp((char *)entry
->d_name
, ".") ||
842 !strcmp((char *)entry
->d_name
, ".."))
843 continue; /* skip these */
845 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
846 copy
); /* recursion */
849 { /* copy/move a file */
850 result
= clipboard_pastefile(src
, target
, copy
);
857 src
[srcdirlen
] = '\0'; /* terminate to original length */
858 target
[targetdirlen
] = '\0'; /* terminate to original length */
864 /* Paste the clipboard to the current directory */
865 static bool clipboard_paste(void)
867 char target
[MAX_PATH
];
871 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
872 static const struct text_message message
={lines
, 1};
874 /* Get the name of the current directory */
875 cwd
= getcwd(NULL
, 0);
877 /* Figure out the name of the selection */
878 nameptr
= strrchr(clipboard_selection
, '/');
880 /* Final target is current directory plus name of selection */
881 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
883 /* If the target existed but they choose not to overwite, exit */
884 if (file_exists(target
) &&
885 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
889 if (clipboard_is_copy
) {
890 gui_syncsplash(0, ID2P(LANG_COPYING
));
894 gui_syncsplash(0, ID2P(LANG_MOVING
));
897 /* Now figure out what we're doing */
899 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
900 /* Recursion. Set up external stack */
901 char srcpath
[MAX_PATH
];
902 char targetpath
[MAX_PATH
];
903 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
905 /* Do not allow the user to paste a directory into a dir they are
911 strncpy(srcpath
, clipboard_selection
, sizeof srcpath
);
912 strncpy(targetpath
, target
, sizeof targetpath
);
914 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
915 target
, sizeof(targetpath
), clipboard_is_copy
);
918 success
= clipboard_pastefile(clipboard_selection
, target
,
925 /* Reset everything */
926 clipboard_selection
[0] = 0;
927 clipboard_selection_attr
= 0;
928 clipboard_is_copy
= false;
930 /* Force reload of the current directory */
931 onplay_result
= ONPLAY_RELOAD_DIR
;
933 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
934 gui_syncsplash(HZ
, (unsigned char *)"%s %s",
935 str(LANG_PASTE
), str(LANG_FAILED
));
941 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
943 static int set_rating_inline(void)
945 struct mp3entry
* id3
= audio_current_track();
946 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
948 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
949 NULL
, 1, 0, 10, NULL
, NULL
);
950 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
953 gui_syncsplash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
956 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
961 case ACTION_REQUEST_MENUITEM
:
962 if (!selected_file
|| !global_settings
.runtimedb
)
963 return ACTION_EXIT_MENUITEM
;
968 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
969 set_rating_inline
, NULL
,
970 ratingitem_callback
, Icon_Questionmark
);
973 static bool view_cue(void)
975 struct mp3entry
* id3
= audio_current_track();
976 if(id3
&& cuesheet_is_enabled() && id3
->cuesheet_type
)
978 browse_cuesheet(curr_cue
);
982 static int view_cue_item_callback(int action
,
983 const struct menu_item_ex
*this_item
)
986 struct mp3entry
* id3
= audio_current_track();
989 case ACTION_REQUEST_MENUITEM
:
990 if (!selected_file
|| !cuesheet_is_enabled()
991 || !id3
|| !id3
->cuesheet_type
)
992 return ACTION_EXIT_MENUITEM
;
997 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
998 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
1000 /* CONTEXT_WPS items */
1001 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
1002 browse_id3
, NULL
, NULL
, Icon_NOICON
);
1003 #ifdef HAVE_PITCHSCREEN
1004 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
1005 pitch_screen
, NULL
, NULL
, Icon_Audio
);
1007 #if CONFIG_CODEC == SWCODEC
1008 MENUITEM_FUNCTION(eq_menu_graphical_item
, 0, ID2P(LANG_EQUALIZER_GRAPHICAL
),
1009 eq_menu_graphical
, NULL
, NULL
, Icon_Audio
);
1010 MENUITEM_FUNCTION(eq_browse_presets_item
, 0, ID2P(LANG_EQUALIZER_BROWSE
),
1011 eq_browse_presets
, NULL
, NULL
, Icon_Audio
);
1014 /* study mode setting toggling */
1016 static char* study_mode_toggle_get_name(int selected_item
, void * data
,
1019 (void)selected_item
;
1021 snprintf(buffer
, MAX_PATH
,
1022 global_settings
.study_mode
? str(LANG_DISABLE_STUDY_MODE
)
1023 : str(LANG_ENABLE_STUDY_MODE
));
1027 static int study_mode_toggle_speak_item(int selected_item
, void * data
)
1029 (void)selected_item
;
1031 talk_id(global_settings
.study_mode
? LANG_DISABLE_STUDY_MODE
1032 : LANG_ENABLE_STUDY_MODE
, false);
1036 static int toggle_study_mode(void * param
)
1039 global_settings
.study_mode
^= 1;
1043 MENUITEM_FUNCTION_DYNTEXT(study_mode_toggle
, 0,
1044 toggle_study_mode
, NULL
,
1045 study_mode_toggle_get_name
,
1046 study_mode_toggle_speak_item
,
1047 NULL
, NULL
, Icon_NOICON
);
1049 /* CONTEXT_[TREE|ID3DB] items */
1050 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
1051 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
1052 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1053 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
1054 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
1055 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
1056 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
1057 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
1058 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
1059 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
1060 delete_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1061 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
1062 delete_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1063 MENUITEM_FUNCTION(properties_item
, 0, ID2P(LANG_PROPERTIES
),
1064 properties
, NULL
, clipboard_callback
, Icon_NOICON
);
1065 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
1066 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1067 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1068 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1070 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1071 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1073 #ifdef HAVE_RECORDING
1074 static bool set_recdir(void)
1076 strncpy(global_settings
.rec_directory
,
1077 selected_file
, MAX_FILENAME
+1);
1081 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1082 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1084 static bool add_to_faves(void)
1086 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("shortcuts_append",
1088 onplay_result
= ONPLAY_RELOAD_DIR
;
1091 MENUITEM_FUNCTION(add_to_faves_item
, 0, ID2P(LANG_ADD_TO_FAVES
),
1092 add_to_faves
, NULL
, clipboard_callback
, Icon_NOICON
);
1095 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1099 case ACTION_REQUEST_MENUITEM
:
1100 #ifdef HAVE_MULTIVOLUME
1101 if ((selected_file_attr
& FAT_ATTR_VOLUME
) &&
1102 (this_item
== &rename_file_item
||
1103 this_item
== &delete_dir_item
||
1104 this_item
== &clipboard_cut_item
) )
1105 return ACTION_EXIT_MENUITEM
;
1107 if (context
== CONTEXT_ID3DB
)
1108 return ACTION_EXIT_MENUITEM
;
1109 if (this_item
== &clipboard_paste_item
)
1110 { /* visible if there is something to paste */
1111 return (clipboard_selection
[0] != 0) ?
1112 action
: ACTION_EXIT_MENUITEM
;
1114 else if (this_item
== &create_dir_item
)
1116 /* always visible */
1119 else if ((this_item
== &properties_item
) ||
1120 (this_item
== &rename_file_item
) ||
1121 (this_item
== &clipboard_cut_item
) ||
1122 (this_item
== &clipboard_copy_item
) ||
1123 (this_item
== &add_to_faves_item
)
1126 /* requires an actual file */
1127 return (selected_file
) ? action
: ACTION_EXIT_MENUITEM
;
1130 else if (this_item
== &set_backdrop_item
)
1134 char *suffix
= strrchr(selected_file
, '.');
1137 if (strcasecmp(suffix
, ".bmp") == 0)
1143 return ACTION_EXIT_MENUITEM
;
1146 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1148 if ((this_item
== &delete_dir_item
)
1151 #ifdef HAVE_RECORDING
1152 else if (this_item
== &set_recdir_item
)
1156 else if (selected_file
1157 #ifdef HAVE_MULTIVOLUME
1158 /* no rename+delete for volumes */
1159 && !(selected_file_attr
& ATTR_VOLUME
)
1163 if ((this_item
== &delete_file_item
) ||
1164 (this_item
== &list_viewers_item
))
1169 return ACTION_EXIT_MENUITEM
;
1174 /* used when onplay() is called in the CONTEXT_WPS context */
1177 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1178 onplaymenu_callback
, Icon_Audio
,
1179 &sound_settings
, &wps_playlist_menu
, &cat_playlist_menu
,
1180 #ifdef HAVE_TAGCACHE
1183 &bookmark_menu
, &browse_id3_item
, &delete_file_item
, &view_cue_item
,
1184 #ifdef HAVE_PITCHSCREEN
1187 #if CONFIG_CODEC == SWCODEC
1188 &eq_menu_graphical_item
, &eq_browse_presets_item
,
1192 /* used when onplay() is not called in the CONTEXT_WPS context */
1193 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1194 onplaymenu_callback
, Icon_file_view_menu
,
1195 &tree_playlist_menu
, &cat_playlist_menu
,
1196 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1197 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1201 &list_viewers_item
, &create_dir_item
, &properties_item
,
1202 #ifdef HAVE_RECORDING
1207 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1212 case ACTION_TREE_STOP
:
1213 if (this_item
== &wps_onplay_menu
)
1215 list_stop_handler();
1216 return ACTION_STD_CANCEL
;
1219 case ACTION_EXIT_MENUITEM
:
1220 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1225 int onplay(char* file
, int attr
, int from
)
1227 const struct menu_item_ex
*menu
;
1228 onplay_result
= ONPLAY_OK
;
1230 selected_file
= file
;
1231 selected_file_attr
= attr
;
1232 if (context
== CONTEXT_WPS
)
1233 menu
= &wps_onplay_menu
;
1235 menu
= &tree_onplay_menu
;
1236 switch (do_menu(menu
, NULL
, NULL
, false))
1239 return ONPLAY_START_PLAY
;
1241 case GO_TO_MAINMENU
:
1242 return ONPLAY_MAINMENU
;
1244 return context
== CONTEXT_WPS
? ONPLAY_OK
: ONPLAY_RELOAD_DIR
;