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 #include "playlist_menu.h"
59 #include "playlist_catalog.h"
67 static char* selected_file
= NULL
;
68 static int selected_file_attr
= 0;
69 static int onplay_result
= ONPLAY_OK
;
70 static char clipboard_selection
[MAX_PATH
];
71 static int clipboard_selection_attr
= 0;
72 static bool clipboard_is_copy
= false;
74 /* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */
75 #define MAKE_ONPLAYMENU( name, str, callback, icon, ... ) \
76 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
77 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
78 static const struct menu_item_ex name = \
79 {MT_MENU|MENU_HAS_DESC|MENU_EXITAFTERTHISMENU| \
80 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
81 { (void*)name##_},{.callback_and_desc = & name##__}};
83 #ifdef HAVE_LCD_BITMAP
84 static void draw_slider(void);
88 /* ----------------------------------------------------------------------- */
89 /* Displays the bookmark menu options for the user to decide. This is an */
90 /* interface function. */
91 /* ----------------------------------------------------------------------- */
93 static int bookmark_menu_callback(int action
,
94 const struct menu_item_ex
*this_item
);
95 MENUITEM_FUNCTION(bookmark_create_menu_item
, 0,
96 ID2P(LANG_BOOKMARK_MENU_CREATE
),
97 bookmark_create_menu
, NULL
, NULL
, Icon_Bookmark
);
98 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
99 ID2P(LANG_BOOKMARK_MENU_LIST
),
100 bookmark_load_menu
, NULL
,
101 bookmark_menu_callback
, Icon_Bookmark
);
102 MAKE_ONPLAYMENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
), bookmark_menu_callback
,
103 Icon_Bookmark
, &bookmark_create_menu_item
,
104 &bookmark_load_menu_item
);
105 static int bookmark_menu_callback(int action
,
106 const struct menu_item_ex
*this_item
)
111 case ACTION_REQUEST_MENUITEM
:
112 if (this_item
== &bookmark_load_menu_item
)
114 if (bookmark_exist() == 0)
115 return ACTION_EXIT_MENUITEM
;
117 /* hide the bookmark menu if there is no playback */
118 else if ((audio_status() & AUDIO_STATUS_PLAY
) == 0)
119 return ACTION_EXIT_MENUITEM
;
121 #ifdef HAVE_LCD_CHARCELLS
122 case ACTION_ENTER_MENUITEM
:
123 status_set_param(true);
126 case ACTION_EXIT_MENUITEM
:
127 #ifdef HAVE_LCD_CHARCELLS
128 status_set_param(false);
136 static bool list_viewers(void)
138 int ret
= filetype_list_viewers(selected_file
);
139 if (ret
== PLUGIN_USB_CONNECTED
)
140 onplay_result
= ONPLAY_RELOAD_DIR
;
144 static bool shuffle_playlist(void)
146 playlist_sort(NULL
, true);
147 playlist_randomise(NULL
, current_tick
, true);
152 static bool save_playlist(void)
154 save_playlist_screen(NULL
);
158 static bool add_to_playlist(int position
, bool queue
)
160 bool new_playlist
= !(audio_status() & AUDIO_STATUS_PLAY
);
161 const char *lines
[] = {
162 ID2P(LANG_RECURSE_DIRECTORY_QUESTION
),
165 const struct text_message message
={lines
, 2};
167 gui_syncsplash(0, ID2P(LANG_WAIT
));
170 playlist_create(NULL
, NULL
);
172 /* always set seed before inserting shuffled */
173 if (position
== PLAYLIST_INSERT_SHUFFLED
)
177 if (context
== CONTEXT_ID3DB
)
179 tagtree_insert_selection_playlist(position
, queue
);
184 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_AUDIO
)
185 playlist_insert_track(NULL
, selected_file
, position
, queue
, true);
186 else if (selected_file_attr
& ATTR_DIRECTORY
)
188 bool recurse
= false;
190 if (global_settings
.recursive_dir_insert
!= RECURSE_ASK
)
191 recurse
= (bool)global_settings
.recursive_dir_insert
;
194 /* Ask if user wants to recurse directory */
195 recurse
= (gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
);
198 playlist_insert_directory(NULL
, selected_file
, position
, queue
,
201 else if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)
202 playlist_insert_playlist(NULL
, selected_file
, position
, queue
);
205 if (new_playlist
&& (playlist_amount() > 0))
207 /* nothing is currently playing so begin playing what we just
209 if (global_settings
.playlist_shuffle
)
210 playlist_shuffle(current_tick
, -1);
212 gui_syncstatusbar_draw(&statusbars
, false);
213 onplay_result
= ONPLAY_START_PLAY
;
219 static bool view_playlist(void)
221 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
224 result
= playlist_viewer_ex(selected_file
);
226 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
227 onplay_result
== ONPLAY_OK
)
228 /* playlist was started from viewer */
229 onplay_result
= ONPLAY_START_PLAY
;
234 static bool cat_add_to_a_playlist(void)
236 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
240 static bool cat_add_to_a_new_playlist(void)
242 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
247 static int cat_playlist_callback(int action
,
248 const struct menu_item_ex
*this_item
);
249 MENUITEM_FUNCTION(cat_view_lists
, 0, ID2P(LANG_CATALOG_VIEW
),
250 catalog_view_playlists
, 0, cat_playlist_callback
,
252 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
253 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
254 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
255 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
256 MAKE_ONPLAYMENU(cat_playlist_menu
, ID2P(LANG_CATALOG
), cat_playlist_callback
,
257 Icon_Playlist
, &cat_view_lists
, &cat_add_to_list
,
260 static int cat_playlist_callback(int action
,
261 const struct menu_item_ex
*this_item
)
263 if (((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
) &&
264 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_M3U
) &&
265 ((selected_file_attr
& ATTR_DIRECTORY
) == 0))
267 return ACTION_EXIT_MENUITEM
;
272 case ACTION_REQUEST_MENUITEM
:
273 if (this_item
== &cat_view_lists
)
275 if (context
== CONTEXT_WPS
)
278 else if (selected_file
&& /* set before calling this menu,
280 ((audio_status() & AUDIO_STATUS_PLAY
&&
281 context
== CONTEXT_WPS
) ||
282 context
== CONTEXT_TREE
))
287 return ACTION_EXIT_MENUITEM
;
294 /* CONTEXT_WPS playlist options */
295 MENUITEM_FUNCTION(playlist_viewer_item
, 0,
296 ID2P(LANG_VIEW_DYNAMIC_PLAYLIST
), playlist_viewer
,
297 NULL
, NULL
, Icon_Playlist
);
298 MENUITEM_FUNCTION(search_playlist_item
, 0,
299 ID2P(LANG_SEARCH_IN_PLAYLIST
), search_playlist
,
300 NULL
, NULL
, Icon_Playlist
);
301 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
302 save_playlist
, NULL
, NULL
, Icon_Playlist
);
303 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
304 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
305 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
307 &playlist_viewer_item
, &search_playlist_item
,
308 &playlist_save_item
, &reshuffle_item
311 /* CONTEXT_[TREE|ID3DB] playlist options */
312 static int playlist_insert_func(void *param
)
314 add_to_playlist((intptr_t)param
, false);
317 static int playlist_queue_func(void *param
)
319 add_to_playlist((intptr_t)param
, true);
322 static int treeplaylist_wplayback_callback(int action
,
323 const struct menu_item_ex
*
329 case ACTION_REQUEST_MENUITEM
:
330 if (audio_status() & AUDIO_STATUS_PLAY
)
333 return ACTION_EXIT_MENUITEM
;
339 static int treeplaylist_callback(int action
,
340 const struct menu_item_ex
*this_item
);
343 MENUITEM_FUNCTION(i_pl_item_no_play
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
344 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
345 treeplaylist_callback
, Icon_Playlist
);
346 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
347 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
348 treeplaylist_wplayback_callback
, Icon_Playlist
);
349 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
350 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
351 treeplaylist_wplayback_callback
, Icon_Playlist
);
352 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
353 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
354 treeplaylist_wplayback_callback
, Icon_Playlist
);
355 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
356 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
357 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
, treeplaylist_callback
,
360 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
361 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
362 treeplaylist_wplayback_callback
, Icon_Playlist
);
363 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
364 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
365 treeplaylist_wplayback_callback
, Icon_Playlist
);
366 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
367 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
368 treeplaylist_wplayback_callback
, Icon_Playlist
);
369 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
370 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
371 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
372 treeplaylist_wplayback_callback
, Icon_Playlist
);
373 /* replace playlist */
374 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
375 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
376 treeplaylist_wplayback_callback
, Icon_Playlist
);
379 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
381 treeplaylist_callback
, Icon_Playlist
);
383 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_PLAYLIST
),
384 treeplaylist_callback
, Icon_Playlist
,
390 &i_pl_item_no_play
, &i_pl_item
, &i_first_pl_item
,
391 &i_last_pl_item
, &i_shuf_pl_item
,
394 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
400 static int treeplaylist_callback(int action
,
401 const struct menu_item_ex
*this_item
)
406 case ACTION_REQUEST_MENUITEM
:
407 if (this_item
== &tree_playlist_menu
)
409 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
411 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
412 (selected_file_attr
& ATTR_DIRECTORY
))
417 return ACTION_EXIT_MENUITEM
;
419 else if (this_item
== &view_playlist_item
)
421 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
422 context
== CONTEXT_TREE
)
425 return ACTION_EXIT_MENUITEM
;
427 else if (this_item
== &i_pl_item_no_play
)
429 if (!(audio_status() & AUDIO_STATUS_PLAY
))
434 return ACTION_EXIT_MENUITEM
;
436 else if (this_item
== &i_shuf_pl_item
)
439 if (audio_status() & AUDIO_STATUS_PLAY
)
443 else if ((this_item
== &i_shuf_pl_item
) &&
444 ((selected_file_attr
& ATTR_DIRECTORY
) ||
445 ((selected_file_attr
& FILE_ATTR_MASK
) ==
450 return ACTION_EXIT_MENUITEM
;
457 /* helper function to remove a non-empty directory */
458 static int remove_dir(char* dirname
, int len
)
462 int dirlen
= strlen(dirname
);
464 dir
= opendir(dirname
);
466 return -1; /* open error */
470 struct dirent
* entry
;
471 /* walk through the directory content */
472 entry
= readdir(dir
);
476 dirname
[dirlen
] ='\0';
477 gui_syncsplash(0, dirname
);
479 /* append name to current directory */
480 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
481 if (entry
->attribute
& ATTR_DIRECTORY
)
482 { /* remove a subdirectory */
483 if (!strcmp((char *)entry
->d_name
, ".") ||
484 !strcmp((char *)entry
->d_name
, ".."))
485 continue; /* skip these */
487 /* inform the user which dir we're deleting */
489 result
= remove_dir(dirname
, len
); /* recursion */
491 break; /* or better continue, delete what we can? */
494 { /* remove a file */
496 result
= remove(dirname
);
498 if(ACTION_STD_CANCEL
== get_action(CONTEXT_STD
,TIMEOUT_NOBLOCK
))
500 gui_syncsplash(HZ
, ID2P(LANG_CANCEL
));
508 { /* remove the now empty directory */
509 dirname
[dirlen
] = '\0'; /* terminate to original length */
511 result
= rmdir(dirname
);
518 /* share code for file and directory deletion, saves space */
519 static bool delete_handler(bool is_dir
)
521 char file_to_delete
[MAX_PATH
];
522 strcpy(file_to_delete
, selected_file
);
524 const char *lines
[]={
525 ID2P(LANG_REALLY_DELETE
),
528 const char *yes_lines
[]={
533 struct text_message message
={lines
, 2};
534 struct text_message yes_message
={yes_lines
, 2};
536 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
539 gui_syncsplash(0, str(LANG_DELETING
));
544 char pathname
[MAX_PATH
]; /* space to go deep */
546 strncpy(pathname
, file_to_delete
, sizeof pathname
);
547 res
= remove_dir(pathname
, sizeof(pathname
));
551 res
= remove(file_to_delete
);
554 onplay_result
= ONPLAY_RELOAD_DIR
;
560 static bool delete_file(void)
562 return delete_handler(false);
565 static bool delete_dir(void)
567 return delete_handler(true);
571 static bool set_backdrop(void)
574 if(load_main_backdrop(selected_file
)) {
575 gui_syncsplash(HZ
, str(LANG_BACKDROP_LOADED
));
576 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
578 show_main_backdrop();
581 gui_syncsplash(HZ
, str(LANG_BACKDROP_FAILED
));
587 static bool rename_file(void)
589 char newname
[MAX_PATH
];
590 char* ptr
= strrchr(selected_file
, '/') + 1;
591 int pathlen
= (ptr
- selected_file
);
592 strncpy(newname
, selected_file
, sizeof newname
);
593 if (!kbd_input(newname
+ pathlen
, (sizeof newname
)-pathlen
)) {
594 if (!strlen(newname
+ pathlen
) ||
595 (rename(selected_file
, newname
) < 0)) {
597 lcd_puts(0,0,str(LANG_RENAME
));
598 lcd_puts(0,1,str(LANG_FAILED
));
600 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
604 onplay_result
= ONPLAY_RELOAD_DIR
;
610 static bool create_dir(void)
612 char dirname
[MAX_PATH
];
617 cwd
= getcwd(NULL
, 0);
618 memset(dirname
, 0, sizeof dirname
);
620 snprintf(dirname
, sizeof dirname
, "%s/",
623 pathlen
= strlen(dirname
);
624 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
630 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
631 gui_syncsplash(HZ
, (unsigned char *)"%s %s",
632 str(LANG_CREATE_DIR
), str(LANG_FAILED
));
634 onplay_result
= ONPLAY_RELOAD_DIR
;
640 static bool properties(void)
642 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("properties",
644 onplay_result
= ONPLAY_RELOAD_DIR
;
648 /* Store the current selection in the clipboard */
649 static bool clipboard_clip(bool copy
)
651 clipboard_selection
[0] = 0;
652 strncpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
653 clipboard_selection_attr
= selected_file_attr
;
654 clipboard_is_copy
= copy
;
659 static bool clipboard_cut(void)
661 return clipboard_clip(false);
664 static bool clipboard_copy(void)
666 return clipboard_clip(true);
669 #ifdef HAVE_LCD_BITMAP
670 static void draw_slider(void)
675 show_busy_slider(&screens
[i
], 1, LCD_HEIGHT
-2*screens
[i
].char_height
,
676 LCD_WIDTH
-2, 2*screens
[i
].char_height
-1);
682 /* Paste a file to a new directory. Will overwrite always. */
683 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
685 int src_fd
, target_fd
;
687 ssize_t size
, bytesread
, byteswritten
;
692 /* See if we can get the plugin buffer for the file copy buffer */
693 buffer
= (char *) plugin_get_buffer(&buffersize
);
694 if (buffer
== NULL
|| buffersize
< 512) {
695 /* Not large enough, try for a disk sector worth of stack
698 buffer
= (char *) __builtin_alloca(buffersize
);
701 if (buffer
== NULL
) {
705 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
708 src_fd
= open(src
, O_RDONLY
);
711 target_fd
= creat(target
);
713 if (target_fd
>= 0) {
716 size
= filesize(src_fd
);
723 bytesread
= read(src_fd
, buffer
, buffersize
);
725 if (bytesread
== -1) {
732 while(bytesread
> 0) {
733 byteswritten
= write(target_fd
, buffer
, bytesread
);
735 if (byteswritten
== -1) {
741 bytesread
-= byteswritten
;
748 /* Copy failed. Cleanup. */
757 result
= rename(src
, target
) == 0;
758 #ifdef HAVE_MULTIVOLUME
760 if (errno
== EXDEV
) {
761 /* Failed because cross volume rename doesn't work. Copy
763 result
= clipboard_pastefile(src
, target
, true);
766 result
= remove(src
) == 0;
776 /* Paste a directory to a new location. Designed to be called by
778 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
779 int targetlen
, bool copy
)
782 int srcdirlen
= strlen(src
);
783 int targetdirlen
= strlen(target
);
786 if (!file_exists(target
)) {
788 /* Just move the directory */
789 result
= rename(src
, target
) == 0;
791 #ifdef HAVE_MULTIVOLUME
792 if (!result
&& errno
== EXDEV
) {
793 /* Try a copy as we're going across devices */
794 result
= clipboard_pastedirectory(src
, srclen
, target
,
797 /* If it worked, remove the source directory */
799 remove_dir(src
, srclen
);
805 /* Make a directory to copy things to */
806 result
= mkdir(target
) == 0;
810 /* Check if something went wrong already */
815 srcdir
= opendir(src
);
820 /* This loop will exit as soon as there's a problem */
823 struct dirent
* entry
;
824 /* walk through the directory content */
825 entry
= readdir(srcdir
);
829 /* append name to current directory */
830 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
831 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
834 DEBUGF("Copy %s to %s\n", src
, target
);
836 if (entry
->attribute
& ATTR_DIRECTORY
)
837 { /* copy/move a subdirectory */
838 if (!strcmp((char *)entry
->d_name
, ".") ||
839 !strcmp((char *)entry
->d_name
, ".."))
840 continue; /* skip these */
842 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
843 copy
); /* recursion */
846 { /* copy/move a file */
847 result
= clipboard_pastefile(src
, target
, copy
);
854 src
[srcdirlen
] = '\0'; /* terminate to original length */
855 target
[targetdirlen
] = '\0'; /* terminate to original length */
861 /* Paste the clipboard to the current directory */
862 static bool clipboard_paste(void)
864 char target
[MAX_PATH
];
868 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
869 static const struct text_message message
={lines
, 1};
871 /* Get the name of the current directory */
872 cwd
= getcwd(NULL
, 0);
874 /* Figure out the name of the selection */
875 nameptr
= strrchr(clipboard_selection
, '/');
877 /* Final target is current directory plus name of selection */
878 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
880 /* If the target existed but they choose not to overwite, exit */
881 if (file_exists(target
) &&
882 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
886 if (clipboard_is_copy
) {
887 gui_syncsplash(0, ID2P(LANG_COPYING
));
891 gui_syncsplash(0, ID2P(LANG_MOVING
));
894 /* Now figure out what we're doing */
896 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
897 /* Recursion. Set up external stack */
898 char srcpath
[MAX_PATH
];
899 char targetpath
[MAX_PATH
];
900 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
902 /* Do not allow the user to paste a directory into a dir they are
908 strncpy(srcpath
, clipboard_selection
, sizeof srcpath
);
909 strncpy(targetpath
, target
, sizeof targetpath
);
911 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
912 target
, sizeof(targetpath
), clipboard_is_copy
);
915 success
= clipboard_pastefile(clipboard_selection
, target
,
922 /* Reset everything */
923 clipboard_selection
[0] = 0;
924 clipboard_selection_attr
= 0;
925 clipboard_is_copy
= false;
927 /* Force reload of the current directory */
928 onplay_result
= ONPLAY_RELOAD_DIR
;
930 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
931 gui_syncsplash(HZ
, (unsigned char *)"%s %s",
932 str(LANG_PASTE
), str(LANG_FAILED
));
938 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
940 static int set_rating_inline(void)
942 struct mp3entry
* id3
= audio_current_track();
943 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
945 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
946 NULL
, 1, 0, 10, NULL
, NULL
);
947 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
950 gui_syncsplash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
953 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
958 case ACTION_REQUEST_MENUITEM
:
959 if (!selected_file
|| !global_settings
.runtimedb
)
960 return ACTION_EXIT_MENUITEM
;
965 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
966 set_rating_inline
, NULL
,
967 ratingitem_callback
, Icon_Questionmark
);
970 static bool view_cue(void)
972 struct mp3entry
* id3
= audio_current_track();
973 if(id3
&& cuesheet_is_enabled() && id3
->cuesheet_type
)
975 browse_cuesheet(curr_cue
);
979 static int view_cue_item_callback(int action
,
980 const struct menu_item_ex
*this_item
)
983 struct mp3entry
* id3
= audio_current_track();
986 case ACTION_REQUEST_MENUITEM
:
987 if (!selected_file
|| !cuesheet_is_enabled()
988 || !id3
|| !id3
->cuesheet_type
)
989 return ACTION_EXIT_MENUITEM
;
994 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
995 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
997 /* CONTEXT_WPS items */
998 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
999 browse_id3
, NULL
, NULL
, Icon_NOICON
);
1000 #ifdef HAVE_PITCHSCREEN
1001 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
1002 pitch_screen
, NULL
, NULL
, Icon_Audio
);
1005 /* CONTEXT_[TREE|ID3DB] items */
1006 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
1007 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
1008 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1009 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
1010 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
1011 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
1012 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
1013 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
1014 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
1015 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
1016 delete_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1017 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
1018 delete_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1019 MENUITEM_FUNCTION(properties_item
, 0, ID2P(LANG_PROPERTIES
),
1020 properties
, NULL
, clipboard_callback
, Icon_NOICON
);
1021 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
1022 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1023 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1024 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1026 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1027 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1029 #ifdef HAVE_RECORDING
1030 static bool set_recdir(void)
1032 strncpy(global_settings
.rec_directory
,
1033 selected_file
, MAX_FILENAME
+1);
1037 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1038 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1040 static bool add_to_faves(void)
1042 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("shortcuts_append",
1044 onplay_result
= ONPLAY_RELOAD_DIR
;
1047 MENUITEM_FUNCTION(add_to_faves_item
, 0, ID2P(LANG_ADD_TO_FAVES
),
1048 add_to_faves
, NULL
, clipboard_callback
, Icon_NOICON
);
1051 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1055 case ACTION_REQUEST_MENUITEM
:
1056 #ifdef HAVE_MULTIVOLUME
1057 if ((selected_file_attr
& FAT_ATTR_VOLUME
) &&
1058 (this_item
== &rename_file_item
||
1059 this_item
== &delete_dir_item
||
1060 this_item
== &clipboard_cut_item
) )
1061 return ACTION_EXIT_MENUITEM
;
1063 if (context
== CONTEXT_ID3DB
)
1064 return ACTION_EXIT_MENUITEM
;
1065 if (this_item
== &clipboard_paste_item
)
1066 { /* visible if there is something to paste */
1067 return (clipboard_selection
[0] != 0) ?
1068 action
: ACTION_EXIT_MENUITEM
;
1070 else if (this_item
== &create_dir_item
)
1072 /* always visible */
1075 else if ((this_item
== &properties_item
) ||
1076 (this_item
== &rename_file_item
) ||
1077 (this_item
== &clipboard_cut_item
) ||
1078 (this_item
== &clipboard_copy_item
) ||
1079 (this_item
== &add_to_faves_item
)
1082 /* requires an actual file */
1083 return (selected_file
) ? action
: ACTION_EXIT_MENUITEM
;
1086 else if (this_item
== &set_backdrop_item
)
1090 char *suffix
= strrchr(selected_file
, '.');
1093 if (strcasecmp(suffix
, ".bmp") == 0)
1099 return ACTION_EXIT_MENUITEM
;
1102 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1104 if ((this_item
== &delete_dir_item
)
1107 #ifdef HAVE_RECORDING
1108 else if (this_item
== &set_recdir_item
)
1112 else if (selected_file
1113 #ifdef HAVE_MULTIVOLUME
1114 /* no rename+delete for volumes */
1115 && !(selected_file_attr
& ATTR_VOLUME
)
1119 if ((this_item
== &delete_file_item
) ||
1120 (this_item
== &list_viewers_item
))
1125 return ACTION_EXIT_MENUITEM
;
1130 /* used when onplay() is called in the CONTEXT_WPS context */
1133 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1134 onplaymenu_callback
, Icon_Audio
,
1135 &wps_playlist_menu
, &cat_playlist_menu
,
1136 &sound_settings
, &playback_settings
,
1137 #ifdef HAVE_TAGCACHE
1140 &bookmark_menu
, &browse_id3_item
, &list_viewers_item
,
1141 &delete_file_item
, &view_cue_item
,
1142 #ifdef HAVE_PITCHSCREEN
1146 /* used when onplay() is not called in the CONTEXT_WPS context */
1147 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1148 onplaymenu_callback
, Icon_file_view_menu
,
1149 &tree_playlist_menu
, &cat_playlist_menu
,
1150 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1151 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1155 &list_viewers_item
, &create_dir_item
, &properties_item
,
1156 #ifdef HAVE_RECORDING
1161 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1166 case ACTION_TREE_STOP
:
1167 if (this_item
== &wps_onplay_menu
)
1169 list_stop_handler();
1170 return ACTION_STD_CANCEL
;
1173 case ACTION_EXIT_MENUITEM
:
1174 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1179 int onplay(char* file
, int attr
, int from
)
1181 const struct menu_item_ex
*menu
;
1182 onplay_result
= ONPLAY_OK
;
1184 selected_file
= file
;
1185 selected_file_attr
= attr
;
1186 if (context
== CONTEXT_WPS
)
1187 menu
= &wps_onplay_menu
;
1189 menu
= &tree_onplay_menu
;
1190 switch (do_menu(menu
, NULL
, NULL
, false))
1193 return ONPLAY_START_PLAY
;
1195 case GO_TO_MAINMENU
:
1196 return ONPLAY_MAINMENU
;
1198 return context
== CONTEXT_WPS
? ONPLAY_OK
: ONPLAY_RELOAD_DIR
;