1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
45 #include "playlist_viewer.h"
48 #include "filetypes.h"
54 #include "menus/exported_menus.h"
55 #ifdef HAVE_LCD_BITMAP
58 #include "sound_menu.h"
59 #include "playlist_menu.h"
60 #include "playlist_catalog.h"
66 #include "pitchscreen.h"
69 static char* selected_file
= NULL
;
70 static int selected_file_attr
= 0;
71 static int onplay_result
= ONPLAY_OK
;
72 static char clipboard_selection
[MAX_PATH
];
73 static int clipboard_selection_attr
= 0;
74 static bool clipboard_is_copy
= false;
76 /* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */
77 #define MAKE_ONPLAYMENU( name, str, callback, icon, ... ) \
78 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
79 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
80 static const struct menu_item_ex name = \
81 {MT_MENU|MENU_HAS_DESC|MENU_EXITAFTERTHISMENU| \
82 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
83 { (void*)name##_},{.callback_and_desc = & name##__}};
85 #ifdef HAVE_LCD_BITMAP
86 static void draw_slider(void);
90 /* ----------------------------------------------------------------------- */
91 /* Displays the bookmark menu options for the user to decide. This is an */
92 /* interface function. */
93 /* ----------------------------------------------------------------------- */
95 static int bookmark_menu_callback(int action
,
96 const struct menu_item_ex
*this_item
);
97 MENUITEM_FUNCTION(bookmark_create_menu_item
, 0,
98 ID2P(LANG_BOOKMARK_MENU_CREATE
),
99 bookmark_create_menu
, NULL
, NULL
, Icon_Bookmark
);
100 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
101 ID2P(LANG_BOOKMARK_MENU_LIST
),
102 bookmark_load_menu
, NULL
,
103 bookmark_menu_callback
, Icon_Bookmark
);
104 MAKE_ONPLAYMENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
), bookmark_menu_callback
,
105 Icon_Bookmark
, &bookmark_create_menu_item
,
106 &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 splash(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 onplay_result
= ONPLAY_START_PLAY
;
220 static bool view_playlist(void)
222 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
225 result
= playlist_viewer_ex(selected_file
);
227 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
228 onplay_result
== ONPLAY_OK
)
229 /* playlist was started from viewer */
230 onplay_result
= ONPLAY_START_PLAY
;
235 static bool cat_add_to_a_playlist(void)
237 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
241 static bool cat_add_to_a_new_playlist(void)
243 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
248 static int cat_playlist_callback(int action
,
249 const struct menu_item_ex
*this_item
);
250 MENUITEM_FUNCTION(cat_view_lists
, 0, ID2P(LANG_CATALOG_VIEW
),
251 catalog_view_playlists
, 0, cat_playlist_callback
,
253 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
254 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
255 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
256 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
257 MAKE_ONPLAYMENU(cat_playlist_menu
, ID2P(LANG_CATALOG
), cat_playlist_callback
,
258 Icon_Playlist
, &cat_view_lists
, &cat_add_to_list
,
261 static int cat_playlist_callback(int action
,
262 const struct menu_item_ex
*this_item
)
264 if (((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
) &&
265 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_M3U
) &&
266 ((selected_file_attr
& ATTR_DIRECTORY
) == 0))
268 return ACTION_EXIT_MENUITEM
;
273 case ACTION_REQUEST_MENUITEM
:
274 if (this_item
== &cat_view_lists
)
276 if (context
== CONTEXT_WPS
)
279 else if (selected_file
&& /* set before calling this menu,
281 ((audio_status() & AUDIO_STATUS_PLAY
&&
282 context
== CONTEXT_WPS
) ||
283 context
== CONTEXT_TREE
))
288 return ACTION_EXIT_MENUITEM
;
295 /* CONTEXT_WPS playlist options */
296 MENUITEM_FUNCTION(playlist_viewer_item
, 0,
297 ID2P(LANG_VIEW_DYNAMIC_PLAYLIST
), playlist_viewer
,
298 NULL
, NULL
, Icon_Playlist
);
299 MENUITEM_FUNCTION(search_playlist_item
, 0,
300 ID2P(LANG_SEARCH_IN_PLAYLIST
), search_playlist
,
301 NULL
, NULL
, Icon_Playlist
);
302 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
303 save_playlist
, NULL
, NULL
, Icon_Playlist
);
304 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
305 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
306 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
308 &playlist_viewer_item
, &search_playlist_item
,
309 &playlist_save_item
, &reshuffle_item
312 /* CONTEXT_[TREE|ID3DB] playlist options */
313 static int playlist_insert_func(void *param
)
315 add_to_playlist((intptr_t)param
, false);
318 static int playlist_queue_func(void *param
)
320 add_to_playlist((intptr_t)param
, true);
323 static int treeplaylist_wplayback_callback(int action
,
324 const struct menu_item_ex
*
330 case ACTION_REQUEST_MENUITEM
:
331 if (audio_status() & AUDIO_STATUS_PLAY
)
334 return ACTION_EXIT_MENUITEM
;
340 static int treeplaylist_callback(int action
,
341 const struct menu_item_ex
*this_item
);
344 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
345 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
346 treeplaylist_callback
, Icon_Playlist
);
347 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
348 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
349 treeplaylist_wplayback_callback
, Icon_Playlist
);
350 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
351 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
352 treeplaylist_wplayback_callback
, Icon_Playlist
);
353 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
354 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
355 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
, treeplaylist_callback
,
358 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
359 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
360 treeplaylist_wplayback_callback
, Icon_Playlist
);
361 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
362 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
363 treeplaylist_wplayback_callback
, Icon_Playlist
);
364 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
365 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
366 treeplaylist_wplayback_callback
, Icon_Playlist
);
367 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
368 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
369 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
370 treeplaylist_wplayback_callback
, Icon_Playlist
);
371 /* replace playlist */
372 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
373 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
374 treeplaylist_wplayback_callback
, Icon_Playlist
);
377 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
379 treeplaylist_callback
, Icon_Playlist
);
381 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_PLAYLIST
),
382 treeplaylist_callback
, Icon_Playlist
,
388 &i_pl_item
, &i_first_pl_item
,
389 &i_last_pl_item
, &i_shuf_pl_item
,
392 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
398 static int treeplaylist_callback(int action
,
399 const struct menu_item_ex
*this_item
)
404 case ACTION_REQUEST_MENUITEM
:
405 if (this_item
== &tree_playlist_menu
)
407 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
409 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
410 (selected_file_attr
& ATTR_DIRECTORY
))
415 return ACTION_EXIT_MENUITEM
;
417 else if (this_item
== &view_playlist_item
)
419 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
420 context
== CONTEXT_TREE
)
423 return ACTION_EXIT_MENUITEM
;
425 else if (this_item
== &i_shuf_pl_item
)
428 if (audio_status() & AUDIO_STATUS_PLAY
)
432 else if ((this_item
== &i_shuf_pl_item
) &&
433 ((selected_file_attr
& ATTR_DIRECTORY
) ||
434 ((selected_file_attr
& FILE_ATTR_MASK
) ==
439 return ACTION_EXIT_MENUITEM
;
446 /* helper function to remove a non-empty directory */
447 static int remove_dir(char* dirname
, int len
)
451 int dirlen
= strlen(dirname
);
453 dir
= opendir(dirname
);
455 return -1; /* open error */
459 struct dirent
* entry
;
460 /* walk through the directory content */
461 entry
= readdir(dir
);
465 dirname
[dirlen
] ='\0';
468 /* append name to current directory */
469 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
470 if (entry
->attribute
& ATTR_DIRECTORY
)
471 { /* remove a subdirectory */
472 if (!strcmp((char *)entry
->d_name
, ".") ||
473 !strcmp((char *)entry
->d_name
, ".."))
474 continue; /* skip these */
476 /* inform the user which dir we're deleting */
478 result
= remove_dir(dirname
, len
); /* recursion */
480 break; /* or better continue, delete what we can? */
483 { /* remove a file */
485 result
= remove(dirname
);
487 if(ACTION_STD_CANCEL
== get_action(CONTEXT_STD
,TIMEOUT_NOBLOCK
))
489 splash(HZ
, ID2P(LANG_CANCEL
));
497 { /* remove the now empty directory */
498 dirname
[dirlen
] = '\0'; /* terminate to original length */
500 result
= rmdir(dirname
);
507 /* share code for file and directory deletion, saves space */
508 static bool delete_handler(bool is_dir
)
510 char file_to_delete
[MAX_PATH
];
511 strcpy(file_to_delete
, selected_file
);
513 const char *lines
[]={
514 ID2P(LANG_REALLY_DELETE
),
517 const char *yes_lines
[]={
522 const struct text_message message
={lines
, 2};
523 const struct text_message yes_message
={yes_lines
, 2};
525 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
528 splash(0, str(LANG_DELETING
));
533 char pathname
[MAX_PATH
]; /* space to go deep */
535 strlcpy(pathname
, file_to_delete
, sizeof(pathname
));
536 res
= remove_dir(pathname
, sizeof(pathname
));
540 res
= remove(file_to_delete
);
543 onplay_result
= ONPLAY_RELOAD_DIR
;
549 static bool delete_file(void)
551 return delete_handler(false);
554 static bool delete_dir(void)
556 return delete_handler(true);
560 static bool set_backdrop(void)
563 if(backdrop_load(BACKDROP_MAIN
, selected_file
)) {
564 splash(HZ
, str(LANG_BACKDROP_LOADED
));
565 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
567 backdrop_show(BACKDROP_MAIN
);
570 splash(HZ
, str(LANG_BACKDROP_FAILED
));
576 static bool rename_file(void)
578 char newname
[MAX_PATH
];
579 char* ptr
= strrchr(selected_file
, '/') + 1;
580 int pathlen
= (ptr
- selected_file
);
581 strlcpy(newname
, selected_file
, sizeof(newname
));
582 if (!kbd_input(newname
+ pathlen
, (sizeof newname
)-pathlen
)) {
583 if (!strlen(newname
+ pathlen
) ||
584 (rename(selected_file
, newname
) < 0)) {
586 lcd_puts(0,0,str(LANG_RENAME
));
587 lcd_puts(0,1,str(LANG_FAILED
));
589 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
593 onplay_result
= ONPLAY_RELOAD_DIR
;
599 static bool create_dir(void)
601 char dirname
[MAX_PATH
];
606 cwd
= getcwd(NULL
, 0);
607 memset(dirname
, 0, sizeof dirname
);
609 snprintf(dirname
, sizeof dirname
, "%s/",
612 pathlen
= strlen(dirname
);
613 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
619 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
620 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_CREATE_DIR
),
623 onplay_result
= ONPLAY_RELOAD_DIR
;
629 static bool properties(void)
631 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("properties",
633 onplay_result
= ONPLAY_RELOAD_DIR
;
637 /* Store the current selection in the clipboard */
638 static bool clipboard_clip(bool copy
)
640 clipboard_selection
[0] = 0;
641 strlcpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
642 clipboard_selection_attr
= selected_file_attr
;
643 clipboard_is_copy
= copy
;
648 static bool clipboard_cut(void)
650 return clipboard_clip(false);
653 static bool clipboard_copy(void)
655 return clipboard_clip(true);
658 #ifdef HAVE_LCD_BITMAP
659 static void draw_slider(void)
664 show_busy_slider(&screens
[i
], 1,
665 LCD_HEIGHT
-2*screens
[i
].getcharheight(),
666 LCD_WIDTH
-2, 2*screens
[i
].getcharheight()-1);
672 /* Paste a file to a new directory. Will overwrite always. */
673 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
675 int src_fd
, target_fd
;
677 ssize_t size
, bytesread
, byteswritten
;
682 /* See if we can get the plugin buffer for the file copy buffer */
683 buffer
= (char *) plugin_get_buffer(&buffersize
);
684 if (buffer
== NULL
|| buffersize
< 512) {
685 /* Not large enough, try for a disk sector worth of stack
688 buffer
= (char *) __builtin_alloca(buffersize
);
691 if (buffer
== NULL
) {
695 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
698 src_fd
= open(src
, O_RDONLY
);
701 target_fd
= creat(target
);
703 if (target_fd
>= 0) {
706 size
= filesize(src_fd
);
713 bytesread
= read(src_fd
, buffer
, buffersize
);
715 if (bytesread
== -1) {
722 while(bytesread
> 0) {
723 byteswritten
= write(target_fd
, buffer
, bytesread
);
725 if (byteswritten
< 0) {
731 bytesread
-= byteswritten
;
738 /* Copy failed. Cleanup. */
747 result
= rename(src
, target
) == 0;
748 #ifdef HAVE_MULTIVOLUME
750 if (errno
== EXDEV
) {
751 /* Failed because cross volume rename doesn't work. Copy
753 result
= clipboard_pastefile(src
, target
, true);
756 result
= remove(src
) == 0;
766 /* Paste a directory to a new location. Designed to be called by
768 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
769 int targetlen
, bool copy
)
772 int srcdirlen
= strlen(src
);
773 int targetdirlen
= strlen(target
);
776 if (!file_exists(target
)) {
778 /* Just move the directory */
779 result
= rename(src
, target
) == 0;
781 #ifdef HAVE_MULTIVOLUME
782 if (!result
&& errno
== EXDEV
) {
783 /* Try a copy as we're going across devices */
784 result
= clipboard_pastedirectory(src
, srclen
, target
,
787 /* If it worked, remove the source directory */
789 remove_dir(src
, srclen
);
795 /* Make a directory to copy things to */
796 result
= mkdir(target
) == 0;
800 /* Check if something went wrong already */
805 srcdir
= opendir(src
);
810 /* This loop will exit as soon as there's a problem */
813 struct dirent
* entry
;
814 /* walk through the directory content */
815 entry
= readdir(srcdir
);
819 /* append name to current directory */
820 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
821 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
824 DEBUGF("Copy %s to %s\n", src
, target
);
826 if (entry
->attribute
& ATTR_DIRECTORY
)
827 { /* copy/move a subdirectory */
828 if (!strcmp((char *)entry
->d_name
, ".") ||
829 !strcmp((char *)entry
->d_name
, ".."))
830 continue; /* skip these */
832 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
833 copy
); /* recursion */
836 { /* copy/move a file */
837 result
= clipboard_pastefile(src
, target
, copy
);
844 src
[srcdirlen
] = '\0'; /* terminate to original length */
845 target
[targetdirlen
] = '\0'; /* terminate to original length */
851 /* Paste the clipboard to the current directory */
852 static bool clipboard_paste(void)
854 char target
[MAX_PATH
];
858 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
859 static const struct text_message message
={lines
, 1};
861 /* Get the name of the current directory */
862 cwd
= getcwd(NULL
, 0);
864 /* Figure out the name of the selection */
865 nameptr
= strrchr(clipboard_selection
, '/');
867 /* Final target is current directory plus name of selection */
868 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
870 /* If the target existed but they choose not to overwite, exit */
871 if (file_exists(target
) &&
872 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
876 if (clipboard_is_copy
) {
877 splash(0, ID2P(LANG_COPYING
));
881 splash(0, ID2P(LANG_MOVING
));
884 /* Now figure out what we're doing */
886 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
887 /* Recursion. Set up external stack */
888 char srcpath
[MAX_PATH
];
889 char targetpath
[MAX_PATH
];
890 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
892 /* Do not allow the user to paste a directory into a dir they are
898 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
899 strlcpy(targetpath
, target
, sizeof(targetpath
));
901 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
902 target
, sizeof(targetpath
), clipboard_is_copy
);
904 if (success
&& !clipboard_is_copy
)
906 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
907 remove_dir(srcpath
, sizeof(srcpath
));
911 success
= clipboard_pastefile(clipboard_selection
, target
,
918 /* Reset everything */
919 clipboard_selection
[0] = 0;
920 clipboard_selection_attr
= 0;
921 clipboard_is_copy
= false;
923 /* Force reload of the current directory */
924 onplay_result
= ONPLAY_RELOAD_DIR
;
926 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
927 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_PASTE
),
934 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
936 static int set_rating_inline(void)
938 struct mp3entry
* id3
= audio_current_track();
939 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
941 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
942 NULL
, 1, 0, 10, NULL
, NULL
);
943 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
946 splash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
949 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
954 case ACTION_REQUEST_MENUITEM
:
955 if (!selected_file
|| !global_settings
.runtimedb
||
956 !tagcache_is_usable())
957 return ACTION_EXIT_MENUITEM
;
962 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
963 set_rating_inline
, NULL
,
964 ratingitem_callback
, Icon_Questionmark
);
967 static bool view_cue(void)
969 struct mp3entry
* id3
= audio_current_track();
970 if(id3
&& id3
->cuesheet
)
972 browse_cuesheet(id3
->cuesheet
);
976 static int view_cue_item_callback(int action
,
977 const struct menu_item_ex
*this_item
)
980 struct mp3entry
* id3
= audio_current_track();
983 case ACTION_REQUEST_MENUITEM
:
985 || !id3
|| !id3
->cuesheet
)
986 return ACTION_EXIT_MENUITEM
;
991 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
992 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
994 /* CONTEXT_WPS items */
995 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
996 browse_id3
, NULL
, NULL
, Icon_NOICON
);
997 #ifdef HAVE_PITCHSCREEN
998 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
999 gui_syncpitchscreen_run
, NULL
, NULL
, Icon_Audio
);
1002 /* CONTEXT_[TREE|ID3DB] items */
1003 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
1004 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
1005 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1006 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
1007 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
1008 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
1009 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
1010 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
1011 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
1012 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
1013 delete_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1014 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
1015 delete_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1016 MENUITEM_FUNCTION(properties_item
, 0, ID2P(LANG_PROPERTIES
),
1017 properties
, NULL
, clipboard_callback
, Icon_NOICON
);
1018 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
1019 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1020 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1021 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1023 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1024 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1026 #ifdef HAVE_RECORDING
1027 static bool set_recdir(void)
1029 strlcpy(global_settings
.rec_directory
,
1030 selected_file
, MAX_FILENAME
+1);
1034 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1035 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1037 static bool add_to_faves(void)
1039 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("shortcuts_append",
1041 onplay_result
= ONPLAY_RELOAD_DIR
;
1044 MENUITEM_FUNCTION(add_to_faves_item
, 0, ID2P(LANG_ADD_TO_FAVES
),
1045 add_to_faves
, NULL
, clipboard_callback
, Icon_NOICON
);
1048 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1052 case ACTION_REQUEST_MENUITEM
:
1053 #ifdef HAVE_MULTIVOLUME
1054 if ((selected_file_attr
& FAT_ATTR_VOLUME
) &&
1055 (this_item
== &rename_file_item
||
1056 this_item
== &delete_dir_item
||
1057 this_item
== &clipboard_cut_item
) )
1058 return ACTION_EXIT_MENUITEM
;
1060 if (context
== CONTEXT_ID3DB
)
1061 return ACTION_EXIT_MENUITEM
;
1062 if (this_item
== &clipboard_paste_item
)
1063 { /* visible if there is something to paste */
1064 return (clipboard_selection
[0] != 0) ?
1065 action
: ACTION_EXIT_MENUITEM
;
1067 else if (this_item
== &create_dir_item
)
1069 /* always visible */
1072 else if ((this_item
== &properties_item
) ||
1073 (this_item
== &rename_file_item
) ||
1074 (this_item
== &clipboard_cut_item
) ||
1075 (this_item
== &clipboard_copy_item
) ||
1076 (this_item
== &add_to_faves_item
)
1079 /* requires an actual file */
1080 return (selected_file
) ? action
: ACTION_EXIT_MENUITEM
;
1083 else if (this_item
== &set_backdrop_item
)
1087 char *suffix
= strrchr(selected_file
, '.');
1090 if (strcasecmp(suffix
, ".bmp") == 0)
1096 return ACTION_EXIT_MENUITEM
;
1099 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1101 if ((this_item
== &delete_dir_item
)
1104 #ifdef HAVE_RECORDING
1105 else if (this_item
== &set_recdir_item
)
1109 else if (selected_file
1110 #ifdef HAVE_MULTIVOLUME
1111 /* no rename+delete for volumes */
1112 && !(selected_file_attr
& ATTR_VOLUME
)
1116 if ((this_item
== &delete_file_item
) ||
1117 (this_item
== &list_viewers_item
))
1122 return ACTION_EXIT_MENUITEM
;
1127 /* used when onplay() is called in the CONTEXT_WPS context */
1130 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1131 onplaymenu_callback
, Icon_Audio
,
1132 &wps_playlist_menu
, &cat_playlist_menu
,
1133 &sound_settings
, &playback_settings
,
1134 #ifdef HAVE_TAGCACHE
1137 &bookmark_menu
, &browse_id3_item
, &list_viewers_item
,
1138 &delete_file_item
, &view_cue_item
,
1139 #ifdef HAVE_PITCHSCREEN
1143 /* used when onplay() is not called in the CONTEXT_WPS context */
1144 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1145 onplaymenu_callback
, Icon_file_view_menu
,
1146 &tree_playlist_menu
, &cat_playlist_menu
,
1147 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1148 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1152 &list_viewers_item
, &create_dir_item
, &properties_item
,
1153 #ifdef HAVE_RECORDING
1158 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1163 case ACTION_TREE_STOP
:
1164 if (this_item
== &wps_onplay_menu
)
1166 list_stop_handler();
1167 return ACTION_STD_CANCEL
;
1170 case ACTION_EXIT_MENUITEM
:
1171 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1176 int onplay(char* file
, int attr
, int from
)
1178 const struct menu_item_ex
*menu
;
1179 onplay_result
= ONPLAY_OK
;
1181 selected_file
= file
;
1182 selected_file_attr
= attr
;
1183 if (context
== CONTEXT_WPS
)
1184 menu
= &wps_onplay_menu
;
1186 menu
= &tree_onplay_menu
;
1187 switch (do_menu(menu
, NULL
, NULL
, false))
1190 return ONPLAY_START_PLAY
;
1192 case GO_TO_MAINMENU
:
1193 return ONPLAY_MAINMENU
;
1195 return context
== CONTEXT_WPS
? ONPLAY_OK
: ONPLAY_RELOAD_DIR
;