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 ****************************************************************************/
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"
64 #include "statusbar-skinned.h"
65 #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 /* ----------------------------------------------------------------------- */
86 /* Displays the bookmark menu options for the user to decide. This is an */
87 /* interface function. */
88 /* ----------------------------------------------------------------------- */
90 static int bookmark_menu_callback(int action
,
91 const struct menu_item_ex
*this_item
);
92 MENUITEM_FUNCTION(bookmark_create_menu_item
, 0,
93 ID2P(LANG_BOOKMARK_MENU_CREATE
),
94 bookmark_create_menu
, NULL
, NULL
, Icon_Bookmark
);
95 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
96 ID2P(LANG_BOOKMARK_MENU_LIST
),
97 bookmark_load_menu
, NULL
,
98 bookmark_menu_callback
, Icon_Bookmark
);
99 MAKE_ONPLAYMENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
),
100 bookmark_menu_callback
, Icon_Bookmark
,
101 &bookmark_create_menu_item
, &bookmark_load_menu_item
);
102 static int bookmark_menu_callback(int action
,
103 const struct menu_item_ex
*this_item
)
107 case ACTION_REQUEST_MENUITEM
:
108 if (this_item
== &bookmark_load_menu_item
)
110 if (bookmark_exist() == 0)
111 return ACTION_EXIT_MENUITEM
;
113 /* hide the bookmark menu if there is no playback */
114 else if ((audio_status() & AUDIO_STATUS_PLAY
) == 0)
115 return ACTION_EXIT_MENUITEM
;
117 #ifdef HAVE_LCD_CHARCELLS
118 case ACTION_ENTER_MENUITEM
:
119 status_set_param(true);
122 case ACTION_EXIT_MENUITEM
:
123 #ifdef HAVE_LCD_CHARCELLS
124 status_set_param(false);
132 /* CONTEXT_WPS playlist options */
133 static bool shuffle_playlist(void)
135 playlist_sort(NULL
, true);
136 playlist_randomise(NULL
, current_tick
, true);
140 static bool save_playlist(void)
142 save_playlist_screen(NULL
);
146 extern struct menu_item_ex view_cur_playlist
; /* from playlist_menu.c */
147 MENUITEM_FUNCTION(search_playlist_item
, 0, ID2P(LANG_SEARCH_IN_PLAYLIST
),
148 search_playlist
, NULL
, NULL
, Icon_Playlist
);
149 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
150 save_playlist
, NULL
, NULL
, Icon_Playlist
);
151 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
152 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
153 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
155 &view_cur_playlist
, &search_playlist_item
,
156 &playlist_save_item
, &reshuffle_item
159 /* CONTEXT_[TREE|ID3DB] playlist options */
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
||
176 position
== PLAYLIST_INSERT_LAST_SHUFFLED
)
179 if (position
== PLAYLIST_INSERT_LAST_SHUFFLED
)
180 playlist_set_last_shuffled_start();
184 if (context
== CONTEXT_ID3DB
)
186 tagtree_insert_selection_playlist(position
, queue
);
191 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_AUDIO
)
192 playlist_insert_track(NULL
, selected_file
, position
, queue
, true);
193 else if (selected_file_attr
& ATTR_DIRECTORY
)
195 bool recurse
= false;
197 if (global_settings
.recursive_dir_insert
!= RECURSE_ASK
)
198 recurse
= (bool)global_settings
.recursive_dir_insert
;
201 /* Ask if user wants to recurse directory */
202 recurse
= (gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
);
205 playlist_insert_directory(NULL
, selected_file
, position
, queue
,
208 else if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)
209 playlist_insert_playlist(NULL
, selected_file
, position
, queue
);
212 if (new_playlist
&& (playlist_amount() > 0))
214 /* nothing is currently playing so begin playing what we just
216 if (global_settings
.playlist_shuffle
)
217 playlist_shuffle(current_tick
, -1);
219 onplay_result
= ONPLAY_START_PLAY
;
225 static bool view_playlist(void)
227 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
230 result
= playlist_viewer_ex(selected_file
);
232 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
233 onplay_result
== ONPLAY_OK
)
234 /* playlist was started from viewer */
235 onplay_result
= ONPLAY_START_PLAY
;
240 static int playlist_insert_func(void *param
)
242 if (((intptr_t)param
== PLAYLIST_REPLACE
) && !warn_on_pl_erase())
244 add_to_playlist((intptr_t)param
, false);
248 static int playlist_queue_func(void *param
)
250 add_to_playlist((intptr_t)param
, true);
254 static int treeplaylist_wplayback_callback(int action
,
255 const struct menu_item_ex
* this_item
)
260 case ACTION_REQUEST_MENUITEM
:
261 if (audio_status() & AUDIO_STATUS_PLAY
)
264 return ACTION_EXIT_MENUITEM
;
270 static int treeplaylist_callback(int action
,
271 const struct menu_item_ex
*this_item
);
274 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
275 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
276 NULL
, Icon_Playlist
);
277 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
278 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
279 treeplaylist_wplayback_callback
, Icon_Playlist
);
280 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
281 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
282 treeplaylist_wplayback_callback
, Icon_Playlist
);
283 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
284 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
285 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
286 treeplaylist_callback
, Icon_Playlist
);
287 MENUITEM_FUNCTION(i_last_shuf_pl_item
, MENU_FUNC_USEPARAM
,
288 ID2P(LANG_INSERT_LAST_SHUFFLED
), playlist_insert_func
,
289 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED
,
290 treeplaylist_callback
, Icon_Playlist
);
292 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
293 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
294 treeplaylist_wplayback_callback
, Icon_Playlist
);
295 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
296 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
297 treeplaylist_wplayback_callback
, Icon_Playlist
);
298 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
299 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
300 treeplaylist_wplayback_callback
, Icon_Playlist
);
301 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
302 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
303 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
304 treeplaylist_wplayback_callback
, Icon_Playlist
);
305 MENUITEM_FUNCTION(q_last_shuf_pl_item
, MENU_FUNC_USEPARAM
,
306 ID2P(LANG_QUEUE_LAST_SHUFFLED
), playlist_queue_func
,
307 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED
,
308 treeplaylist_callback
, Icon_Playlist
);
309 /* replace playlist */
310 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
311 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
312 treeplaylist_wplayback_callback
, Icon_Playlist
);
315 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
317 treeplaylist_callback
, Icon_Playlist
);
319 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_PLAYLIST
),
320 treeplaylist_callback
, Icon_Playlist
,
326 &i_pl_item
, &i_first_pl_item
, &i_last_pl_item
,
327 &i_shuf_pl_item
, &i_last_shuf_pl_item
,
330 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
331 &q_shuf_pl_item
, &q_last_shuf_pl_item
,
336 static int treeplaylist_callback(int action
,
337 const struct menu_item_ex
*this_item
)
341 case ACTION_REQUEST_MENUITEM
:
342 if (this_item
== &tree_playlist_menu
)
344 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
346 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
347 (selected_file_attr
& ATTR_DIRECTORY
))
352 else if (this_item
== &view_playlist_item
)
354 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
355 context
== CONTEXT_TREE
)
360 else if (this_item
== &i_shuf_pl_item
)
362 if ((audio_status() & AUDIO_STATUS_PLAY
) ||
363 (selected_file_attr
& ATTR_DIRECTORY
) ||
364 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
))
369 else if (this_item
== &i_last_shuf_pl_item
||
370 this_item
== &q_last_shuf_pl_item
)
372 if ((playlist_amount() > 0) &&
373 (audio_status() & AUDIO_STATUS_PLAY
) &&
374 ((selected_file_attr
& ATTR_DIRECTORY
) ||
375 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)))
380 return ACTION_EXIT_MENUITEM
;
387 /* playlist catalog options */
388 static bool cat_add_to_a_playlist(void)
390 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
394 static bool cat_add_to_a_new_playlist(void)
396 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
400 static int cat_playlist_callback(int action
,
401 const struct menu_item_ex
*this_item
);
402 MENUITEM_FUNCTION(cat_view_lists
, 0, ID2P(LANG_CATALOG_VIEW
),
403 catalog_view_playlists
, 0,
404 cat_playlist_callback
, Icon_Playlist
);
405 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
406 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
407 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
408 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
409 MAKE_ONPLAYMENU(cat_playlist_menu
, ID2P(LANG_CATALOG
),
410 cat_playlist_callback
, Icon_Playlist
,
411 &cat_view_lists
, &cat_add_to_list
, &cat_add_to_new
);
413 static int cat_playlist_callback(int action
,
414 const struct menu_item_ex
*this_item
)
416 if (!selected_file
||
417 (((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
) &&
418 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_M3U
) &&
419 ((selected_file_attr
& ATTR_DIRECTORY
) == 0)))
421 return ACTION_EXIT_MENUITEM
;
426 case ACTION_REQUEST_MENUITEM
:
427 if (this_item
== &cat_view_lists
)
431 else if (((audio_status() & AUDIO_STATUS_PLAY
&&
432 context
== CONTEXT_WPS
) ||
433 context
== CONTEXT_TREE
))
438 return ACTION_EXIT_MENUITEM
;
444 #ifdef HAVE_LCD_BITMAP
445 static void draw_slider(void)
451 int slider_height
= 2*screens
[i
].getcharheight();
452 viewport_set_defaults(&vp
, i
);
453 screens
[i
].set_viewport(&vp
);
454 show_busy_slider(&screens
[i
], 1, vp
.height
- slider_height
,
455 vp
.width
-2, slider_height
-1);
456 screens
[i
].update_viewport();
457 screens
[i
].set_viewport(NULL
);
461 #define draw_slider()
464 /* helper function to remove a non-empty directory */
465 static int remove_dir(char* dirname
, int len
)
469 int dirlen
= strlen(dirname
);
471 dir
= opendir(dirname
);
473 return -1; /* open error */
477 struct dirent
* entry
;
478 /* walk through the directory content */
479 entry
= readdir(dir
);
483 dirname
[dirlen
] ='\0';
484 /* inform the user which dir we're deleting */
487 /* append name to current directory */
488 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
489 if (entry
->attribute
& ATTR_DIRECTORY
)
490 { /* remove a subdirectory */
491 if (!strcmp((char *)entry
->d_name
, ".") ||
492 !strcmp((char *)entry
->d_name
, ".."))
493 continue; /* skip these */
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 splash(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 char file_to_delete
[MAX_PATH
];
528 strcpy(file_to_delete
, selected_file
);
530 const char *lines
[]={
531 ID2P(LANG_REALLY_DELETE
),
534 const char *yes_lines
[]={
539 const struct text_message message
={lines
, 2};
540 const struct text_message yes_message
={yes_lines
, 2};
542 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
545 splash(0, str(LANG_DELETING
));
550 char pathname
[MAX_PATH
]; /* space to go deep */
552 strlcpy(pathname
, file_to_delete
, sizeof(pathname
));
553 res
= remove_dir(pathname
, sizeof(pathname
));
557 res
= remove(file_to_delete
);
560 onplay_result
= ONPLAY_RELOAD_DIR
;
565 static bool delete_file(void)
567 return delete_handler(false);
570 static bool delete_dir(void)
572 return delete_handler(true);
575 static bool rename_file(void)
577 char newname
[MAX_PATH
];
578 char* ptr
= strrchr(selected_file
, '/') + 1;
579 int pathlen
= (ptr
- selected_file
);
580 strlcpy(newname
, selected_file
, sizeof(newname
));
581 if (!kbd_input(newname
+ pathlen
, (sizeof newname
)-pathlen
)) {
582 if (!strlen(newname
+ pathlen
) ||
583 (rename(selected_file
, newname
) < 0)) {
584 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
585 splashf(HZ
*2, "%s %s", str(LANG_RENAME
), str(LANG_FAILED
));
588 onplay_result
= ONPLAY_RELOAD_DIR
;
594 static bool create_dir(void)
596 char dirname
[MAX_PATH
];
601 cwd
= getcwd(NULL
, 0);
602 memset(dirname
, 0, sizeof dirname
);
604 snprintf(dirname
, sizeof dirname
, "%s/", cwd
[1] ? cwd
: "");
606 pathlen
= strlen(dirname
);
607 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
613 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
614 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_CREATE_DIR
),
617 onplay_result
= ONPLAY_RELOAD_DIR
;
623 /* Store the current selection in the clipboard */
624 static bool clipboard_clip(bool copy
)
626 clipboard_selection
[0] = 0;
627 strlcpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
628 clipboard_selection_attr
= selected_file_attr
;
629 clipboard_is_copy
= copy
;
634 static bool clipboard_cut(void)
636 return clipboard_clip(false);
639 static bool clipboard_copy(void)
641 return clipboard_clip(true);
644 /* Paste a file to a new directory. Will overwrite always. */
645 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
647 int src_fd
, target_fd
;
649 ssize_t size
, bytesread
, byteswritten
;
654 /* See if we can get the plugin buffer for the file copy buffer */
655 buffer
= (char *) plugin_get_buffer(&buffersize
);
656 if (buffer
== NULL
|| buffersize
< 512) {
657 /* Not large enough, try for a disk sector worth of stack
660 buffer
= (char *) __builtin_alloca(buffersize
);
663 if (buffer
== NULL
) {
667 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
670 src_fd
= open(src
, O_RDONLY
);
673 target_fd
= creat(target
);
675 if (target_fd
>= 0) {
678 size
= filesize(src_fd
);
685 bytesread
= read(src_fd
, buffer
, buffersize
);
687 if (bytesread
== -1) {
694 while(bytesread
> 0) {
695 byteswritten
= write(target_fd
, buffer
, bytesread
);
697 if (byteswritten
< 0) {
703 bytesread
-= byteswritten
;
710 /* Copy failed. Cleanup. */
719 result
= rename(src
, target
) == 0;
720 #ifdef HAVE_MULTIVOLUME
722 if (errno
== EXDEV
) {
723 /* Failed because cross volume rename doesn't work. Copy
725 result
= clipboard_pastefile(src
, target
, true);
728 result
= remove(src
) == 0;
738 /* Paste a directory to a new location. Designed to be called by
740 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
741 int targetlen
, bool copy
)
744 int srcdirlen
= strlen(src
);
745 int targetdirlen
= strlen(target
);
748 if (!file_exists(target
)) {
750 /* Just move the directory */
751 result
= rename(src
, target
) == 0;
753 #ifdef HAVE_MULTIVOLUME
754 if (!result
&& errno
== EXDEV
) {
755 /* Try a copy as we're going across devices */
756 result
= clipboard_pastedirectory(src
, srclen
, target
,
759 /* If it worked, remove the source directory */
761 remove_dir(src
, srclen
);
767 /* Make a directory to copy things to */
768 result
= mkdir(target
) == 0;
772 /* Check if something went wrong already */
777 srcdir
= opendir(src
);
782 /* This loop will exit as soon as there's a problem */
785 struct dirent
* entry
;
786 /* walk through the directory content */
787 entry
= readdir(srcdir
);
791 /* append name to current directory */
792 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
793 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
796 DEBUGF("Copy %s to %s\n", src
, target
);
798 if (entry
->attribute
& ATTR_DIRECTORY
)
799 { /* copy/move a subdirectory */
800 if (!strcmp((char *)entry
->d_name
, ".") ||
801 !strcmp((char *)entry
->d_name
, ".."))
802 continue; /* skip these */
804 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
805 copy
); /* recursion */
808 { /* copy/move a file */
810 result
= clipboard_pastefile(src
, target
, copy
);
817 src
[srcdirlen
] = '\0'; /* terminate to original length */
818 target
[targetdirlen
] = '\0'; /* terminate to original length */
824 /* Paste the clipboard to the current directory */
825 static bool clipboard_paste(void)
827 char target
[MAX_PATH
];
831 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
832 static const struct text_message message
={lines
, 1};
834 /* Get the name of the current directory */
835 cwd
= getcwd(NULL
, 0);
837 /* Figure out the name of the selection */
838 nameptr
= strrchr(clipboard_selection
, '/');
840 /* Final target is current directory plus name of selection */
841 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
843 /* If the target existed but they choose not to overwite, exit */
844 if (file_exists(target
) &&
845 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
849 if (clipboard_is_copy
) {
850 splash(0, ID2P(LANG_COPYING
));
854 splash(0, ID2P(LANG_MOVING
));
857 /* Now figure out what we're doing */
859 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
860 /* Recursion. Set up external stack */
861 char srcpath
[MAX_PATH
];
862 char targetpath
[MAX_PATH
];
863 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
865 /* Do not allow the user to paste a directory into a dir they are
871 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
872 strlcpy(targetpath
, target
, sizeof(targetpath
));
874 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
875 target
, sizeof(targetpath
), clipboard_is_copy
);
877 if (success
&& !clipboard_is_copy
)
879 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
880 remove_dir(srcpath
, sizeof(srcpath
));
884 success
= clipboard_pastefile(clipboard_selection
, target
,
891 /* Reset everything */
892 clipboard_selection
[0] = 0;
893 clipboard_selection_attr
= 0;
894 clipboard_is_copy
= false;
896 /* Force reload of the current directory */
897 onplay_result
= ONPLAY_RELOAD_DIR
;
899 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
900 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_PASTE
),
908 static int set_rating_inline(void)
910 struct mp3entry
* id3
= audio_current_track();
911 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
913 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
914 NULL
, 1, 0, 10, NULL
, NULL
);
915 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
918 splash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
921 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
926 case ACTION_REQUEST_MENUITEM
:
927 if (!selected_file
|| !global_settings
.runtimedb
||
928 !tagcache_is_usable())
929 return ACTION_EXIT_MENUITEM
;
934 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
935 set_rating_inline
, NULL
,
936 ratingitem_callback
, Icon_Questionmark
);
939 static bool view_cue(void)
941 struct mp3entry
* id3
= audio_current_track();
942 if(id3
&& id3
->cuesheet
)
944 browse_cuesheet(id3
->cuesheet
);
948 static int view_cue_item_callback(int action
,
949 const struct menu_item_ex
*this_item
)
952 struct mp3entry
* id3
= audio_current_track();
955 case ACTION_REQUEST_MENUITEM
:
957 || !id3
|| !id3
->cuesheet
)
958 return ACTION_EXIT_MENUITEM
;
963 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
964 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
966 /* CONTEXT_WPS items */
967 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
968 browse_id3
, NULL
, NULL
, Icon_NOICON
);
969 #ifdef HAVE_PITCHSCREEN
970 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
971 gui_syncpitchscreen_run
, NULL
, NULL
, Icon_Audio
);
974 /* CONTEXT_[TREE|ID3DB] items */
975 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
976 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
977 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
978 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
979 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
980 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
981 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
982 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
983 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
984 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
985 delete_file
, NULL
, clipboard_callback
, Icon_NOICON
);
986 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
987 delete_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
988 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
989 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
992 static bool list_viewers(void)
994 int ret
= filetype_list_viewers(selected_file
);
995 if (ret
== PLUGIN_USB_CONNECTED
)
996 onplay_result
= ONPLAY_RELOAD_DIR
;
1000 static bool onplay_load_plugin(void *param
)
1002 int ret
= filetype_load_plugin((const char*)param
, selected_file
);
1003 if (ret
== PLUGIN_USB_CONNECTED
)
1004 onplay_result
= ONPLAY_RELOAD_DIR
;
1008 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1009 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1010 MENUITEM_FUNCTION(properties_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_PROPERTIES
),
1011 onplay_load_plugin
, (void *)"properties",
1012 clipboard_callback
, Icon_NOICON
);
1013 MENUITEM_FUNCTION(add_to_faves_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_ADD_TO_FAVES
),
1014 onplay_load_plugin
, (void *)"shortcuts_append",
1015 clipboard_callback
, Icon_NOICON
);
1018 static bool set_backdrop(void)
1020 /* load the image */
1021 if(sb_set_backdrop(SCREEN_MAIN
, selected_file
)) {
1022 splash(HZ
, str(LANG_BACKDROP_LOADED
));
1023 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
1027 splash(HZ
, str(LANG_BACKDROP_FAILED
));
1032 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1033 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1035 #ifdef HAVE_RECORDING
1036 static bool set_recdir(void)
1038 strlcpy(global_settings
.rec_directory
, selected_file
, MAX_FILENAME
+1);
1042 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1043 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1046 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1050 case ACTION_REQUEST_MENUITEM
:
1051 #ifdef HAVE_MULTIVOLUME
1052 if ((selected_file_attr
& FAT_ATTR_VOLUME
) &&
1053 (this_item
== &rename_file_item
||
1054 this_item
== &delete_dir_item
||
1055 this_item
== &clipboard_cut_item
) )
1056 return ACTION_EXIT_MENUITEM
;
1057 /* no rename+delete for volumes */
1058 if ((selected_file_attr
& ATTR_VOLUME
) &&
1059 (this_item
== &delete_file_item
||
1060 this_item
== &list_viewers_item
))
1061 return ACTION_EXIT_MENUITEM
;
1063 #ifdef HAVE_TAGCACHE
1064 if (context
== CONTEXT_ID3DB
)
1065 return ACTION_EXIT_MENUITEM
;
1067 if (this_item
== &clipboard_paste_item
)
1068 { /* visible if there is something to paste */
1069 return (clipboard_selection
[0] != 0) ?
1070 action
: ACTION_EXIT_MENUITEM
;
1072 else if (this_item
== &create_dir_item
)
1074 /* always visible */
1077 else if (selected_file
)
1079 /* requires an actual file */
1080 if (this_item
== &rename_file_item
||
1081 this_item
== &clipboard_cut_item
||
1082 this_item
== &clipboard_copy_item
||
1083 this_item
== &properties_item
||
1084 this_item
== &add_to_faves_item
)
1088 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1090 /* only for directories */
1091 if (this_item
== &delete_dir_item
1092 #ifdef HAVE_RECORDING
1093 || this_item
== &set_recdir_item
1098 else if (this_item
== &delete_file_item
||
1099 this_item
== &list_viewers_item
)
1101 /* only for files */
1105 else if (this_item
== &set_backdrop_item
)
1107 char *suffix
= strrchr(selected_file
, '.');
1110 if (strcasecmp(suffix
, ".bmp") == 0)
1118 return ACTION_EXIT_MENUITEM
;
1124 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
1125 /* used when onplay() is called in the CONTEXT_WPS context */
1126 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1127 onplaymenu_callback
, Icon_Audio
,
1128 &wps_playlist_menu
, &cat_playlist_menu
,
1129 &sound_settings
, &playback_settings
,
1130 #ifdef HAVE_TAGCACHE
1133 &bookmark_menu
, &browse_id3_item
, &list_viewers_item
,
1134 &delete_file_item
, &view_cue_item
,
1135 #ifdef HAVE_PITCHSCREEN
1139 /* used when onplay() is not called in the CONTEXT_WPS context */
1140 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1141 onplaymenu_callback
, Icon_file_view_menu
,
1142 &tree_playlist_menu
, &cat_playlist_menu
,
1143 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1144 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1148 &list_viewers_item
, &create_dir_item
, &properties_item
,
1149 #ifdef HAVE_RECORDING
1154 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1158 case ACTION_TREE_STOP
:
1159 if (this_item
== &wps_onplay_menu
)
1161 list_stop_handler();
1162 return ACTION_STD_CANCEL
;
1165 case ACTION_EXIT_MENUITEM
:
1166 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1171 int onplay(char* file
, int attr
, int from
)
1173 const struct menu_item_ex
*menu
;
1174 onplay_result
= ONPLAY_OK
;
1176 selected_file
= file
;
1177 selected_file_attr
= attr
;
1178 if (context
== CONTEXT_WPS
)
1179 menu
= &wps_onplay_menu
;
1181 menu
= &tree_onplay_menu
;
1182 switch (do_menu(menu
, NULL
, NULL
, false))
1185 return ONPLAY_START_PLAY
;
1187 case GO_TO_MAINMENU
:
1188 return ONPLAY_MAINMENU
;
1189 case GO_TO_PLAYLIST_VIEWER
:
1190 return ONPLAY_PLAYLIST
;
1192 return onplay_result
;