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##__}};
87 /* ----------------------------------------------------------------------- */
88 /* Displays the bookmark menu options for the user to decide. This is an */
89 /* interface function. */
90 /* ----------------------------------------------------------------------- */
92 static int bookmark_menu_callback(int action
,
93 const struct menu_item_ex
*this_item
);
94 MENUITEM_FUNCTION(bookmark_create_menu_item
, 0,
95 ID2P(LANG_BOOKMARK_MENU_CREATE
),
96 bookmark_create_menu
, NULL
, NULL
, Icon_Bookmark
);
97 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
98 ID2P(LANG_BOOKMARK_MENU_LIST
),
99 bookmark_load_menu
, NULL
,
100 bookmark_menu_callback
, Icon_Bookmark
);
101 MAKE_MENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
), bookmark_menu_callback
,
102 Icon_Bookmark
, &bookmark_create_menu_item
, &bookmark_load_menu_item
);
103 static int bookmark_menu_callback(int action
,
104 const struct menu_item_ex
*this_item
)
109 case ACTION_REQUEST_MENUITEM
:
110 if (this_item
== &bookmark_load_menu_item
)
112 if (bookmark_exist() == 0)
113 return ACTION_EXIT_MENUITEM
;
115 /* hide the bookmark menu if there is no playback */
116 else if ((audio_status() & AUDIO_STATUS_PLAY
) == 0)
117 return ACTION_EXIT_MENUITEM
;
119 #ifdef HAVE_LCD_CHARCELLS
120 case ACTION_ENTER_MENUITEM
:
121 status_set_param(true);
124 case ACTION_EXIT_MENUITEM
:
125 #ifdef HAVE_LCD_CHARCELLS
126 status_set_param(false);
134 static bool list_viewers(void)
136 int ret
= filetype_list_viewers(selected_file
);
137 if (ret
== PLUGIN_USB_CONNECTED
)
138 onplay_result
= ONPLAY_RELOAD_DIR
;
142 static bool shuffle_playlist(void)
144 playlist_sort(NULL
, true);
145 playlist_randomise(NULL
, current_tick
, true);
150 static bool save_playlist(void)
152 save_playlist_screen(NULL
);
156 static bool add_to_playlist(int position
, bool queue
)
158 bool new_playlist
= !(audio_status() & AUDIO_STATUS_PLAY
);
160 ID2P(LANG_RECURSE_DIRECTORY_QUESTION
),
163 struct text_message message
={lines
, 2};
165 gui_syncsplash(0, ID2P(LANG_WAIT
));
168 playlist_create(NULL
, NULL
);
170 /* always set seed before inserting shuffled */
171 if (position
== PLAYLIST_INSERT_SHUFFLED
)
175 if (context
== CONTEXT_ID3DB
)
177 tagtree_insert_selection_playlist(position
, queue
);
182 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_AUDIO
)
183 playlist_insert_track(NULL
, selected_file
, position
, queue
, true);
184 else if (selected_file_attr
& ATTR_DIRECTORY
)
186 bool recurse
= false;
188 if (global_settings
.recursive_dir_insert
!= RECURSE_ASK
)
189 recurse
= (bool)global_settings
.recursive_dir_insert
;
192 /* Ask if user wants to recurse directory */
193 recurse
= (gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
);
196 playlist_insert_directory(NULL
, selected_file
, position
, queue
,
199 else if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)
200 playlist_insert_playlist(NULL
, selected_file
, position
, queue
);
203 if (new_playlist
&& (playlist_amount() > 0))
205 /* nothing is currently playing so begin playing what we just
207 if (global_settings
.playlist_shuffle
)
208 playlist_shuffle(current_tick
, -1);
210 gui_syncstatusbar_draw(&statusbars
, false);
211 onplay_result
= ONPLAY_START_PLAY
;
217 static bool view_playlist(void)
219 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
222 result
= playlist_viewer_ex(selected_file
);
224 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
225 onplay_result
== ONPLAY_OK
)
226 /* playlist was started from viewer */
227 onplay_result
= ONPLAY_START_PLAY
;
232 static bool cat_add_to_a_playlist(void)
234 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
238 static bool cat_add_to_a_new_playlist(void)
240 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
, true);
244 static int cat_playlist_callback(int action
,
245 const struct menu_item_ex
*this_item
);
246 MENUITEM_FUNCTION(cat_view_lists
, 0, ID2P(LANG_CATALOG_VIEW
),
247 catalog_view_playlists
, 0, cat_playlist_callback
,
249 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
250 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
251 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
252 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
253 MAKE_MENU( cat_playlist_menu
, ID2P(LANG_CATALOG
), cat_playlist_callback
,
254 Icon_Playlist
, &cat_view_lists
,
255 &cat_add_to_list
, &cat_add_to_new
);
257 static int cat_playlist_callback(int action
,
258 const struct menu_item_ex
*this_item
)
262 case ACTION_REQUEST_MENUITEM
:
263 if (this_item
== &cat_view_lists
)
265 if (context
== CONTEXT_WPS
)
268 else if (selected_file
&& /* set before calling this menu,
270 ((audio_status() & AUDIO_STATUS_PLAY
&&
271 context
== CONTEXT_WPS
) ||
272 context
== CONTEXT_TREE
))
277 return ACTION_EXIT_MENUITEM
;
284 /* CONTEXT_WPS playlist options */
285 MENUITEM_FUNCTION(playlist_viewer_item
, 0,
286 ID2P(LANG_VIEW_DYNAMIC_PLAYLIST
), playlist_viewer
,
287 NULL
, NULL
, Icon_Playlist
);
288 MENUITEM_FUNCTION(search_playlist_item
, 0,
289 ID2P(LANG_SEARCH_IN_PLAYLIST
), search_playlist
,
290 NULL
, NULL
, Icon_Playlist
);
291 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
292 save_playlist
, NULL
, NULL
, Icon_Playlist
);
293 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
294 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
295 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
297 &playlist_viewer_item
, &search_playlist_item
,
298 &playlist_save_item
, &reshuffle_item
301 /* CONTEXT_[TREE|ID3DB] playlist options */
302 static int playlist_insert_func(void *param
)
304 add_to_playlist((intptr_t)param
, false);
307 static int playlist_queue_func(void *param
)
309 add_to_playlist((intptr_t)param
, true);
312 static int treeplaylist_wplayback_callback(int action
,
313 const struct menu_item_ex
*
319 case ACTION_REQUEST_MENUITEM
:
320 if (audio_status() & AUDIO_STATUS_PLAY
)
323 return ACTION_EXIT_MENUITEM
;
329 static int treeplaylist_callback(int action
,
330 const struct menu_item_ex
*this_item
);
333 MENUITEM_FUNCTION(i_pl_item_no_play
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
334 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
335 treeplaylist_callback
, Icon_Playlist
);
336 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
337 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
338 treeplaylist_wplayback_callback
, Icon_Playlist
);
339 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
340 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
341 treeplaylist_wplayback_callback
, Icon_Playlist
);
342 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
343 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
344 treeplaylist_wplayback_callback
, Icon_Playlist
);
345 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
346 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
347 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
, treeplaylist_callback
,
350 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
351 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
352 treeplaylist_wplayback_callback
, Icon_Playlist
);
353 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
354 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
355 treeplaylist_wplayback_callback
, Icon_Playlist
);
356 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
357 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
358 treeplaylist_wplayback_callback
, Icon_Playlist
);
359 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
360 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
361 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
362 treeplaylist_wplayback_callback
, Icon_Playlist
);
363 /* replace playlist */
364 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
365 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
366 treeplaylist_wplayback_callback
, Icon_Playlist
);
369 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
371 treeplaylist_callback
, Icon_Playlist
);
373 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_PLAYLIST
),
374 treeplaylist_callback
, Icon_Playlist
,
380 &i_pl_item_no_play
, &i_pl_item
, &i_first_pl_item
,
381 &i_last_pl_item
, &i_shuf_pl_item
,
384 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
390 static int treeplaylist_callback(int action
,
391 const struct menu_item_ex
*this_item
)
396 case ACTION_REQUEST_MENUITEM
:
397 if (this_item
== &tree_playlist_menu
)
399 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
401 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
402 (selected_file_attr
& ATTR_DIRECTORY
))
407 return ACTION_EXIT_MENUITEM
;
409 else if (this_item
== &view_playlist_item
)
411 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
412 context
== CONTEXT_TREE
)
415 return ACTION_EXIT_MENUITEM
;
417 else if (this_item
== &i_pl_item_no_play
)
419 if (!(audio_status() & AUDIO_STATUS_PLAY
))
424 return ACTION_EXIT_MENUITEM
;
426 else if (this_item
== &i_shuf_pl_item
)
429 if (audio_status() & AUDIO_STATUS_PLAY
)
433 else if ((this_item
== &i_shuf_pl_item
) &&
434 ((selected_file_attr
& ATTR_DIRECTORY
) ||
435 ((selected_file_attr
& FILE_ATTR_MASK
) ==
440 return ACTION_EXIT_MENUITEM
;
447 /* helper function to remove a non-empty directory */
448 static int remove_dir(char* dirname
, int len
)
452 int dirlen
= strlen(dirname
);
455 dir
= opendir(dirname
);
457 return -1; /* open error */
461 struct dirent
* entry
;
462 /* walk through the directory content */
463 entry
= readdir(dir
);
467 dirname
[dirlen
] ='\0';
469 screens
[i
].puts(0,1,dirname
);
471 /* append name to current directory */
472 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
473 if (entry
->attribute
& ATTR_DIRECTORY
)
474 { /* remove a subdirectory */
475 if (!strcmp((char *)entry
->d_name
, ".") ||
476 !strcmp((char *)entry
->d_name
, ".."))
477 continue; /* skip these */
479 /* inform the user which dir we're deleting */
481 result
= remove_dir(dirname
, len
); /* recursion */
483 break; /* or better continue, delete what we can? */
486 { /* remove a file */
487 #ifdef HAVE_LCD_BITMAP
490 show_busy_slider(&screens
[i
], 2, 3*screens
[i
].char_height
,
491 LCD_WIDTH
-4, screens
[i
].char_height
);
494 result
= remove(dirname
);
496 #ifdef HAVE_LCD_BITMAP
500 if(ACTION_STD_CANCEL
== get_action(CONTEXT_STD
,TIMEOUT_NOBLOCK
))
502 gui_syncsplash(HZ
, ID2P(LANG_CANCEL
));
510 { /* remove the now empty directory */
511 dirname
[dirlen
] = '\0'; /* terminate to original length */
513 result
= rmdir(dirname
);
520 /* share code for file and directory deletion, saves space */
521 static bool delete_handler(bool is_dir
)
524 ID2P(LANG_REALLY_DELETE
),
532 struct text_message message
={lines
, 2};
533 struct text_message yes_message
={yes_lines
, 2};
535 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
538 gui_syncsplash(0, str(LANG_DELETING
));
543 char pathname
[MAX_PATH
]; /* space to go deep */
545 strncpy(pathname
, selected_file
, sizeof pathname
);
546 res
= remove_dir(pathname
, sizeof(pathname
));
550 res
= remove(selected_file
);
553 onplay_result
= ONPLAY_RELOAD_DIR
;
559 static bool delete_file(void)
561 return delete_handler(false);
564 static bool delete_dir(void)
566 return delete_handler(true);
570 static bool set_backdrop(void)
573 if(load_main_backdrop(selected_file
)) {
574 gui_syncsplash(HZ
, str(LANG_BACKDROP_LOADED
));
575 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
577 show_main_backdrop();
580 gui_syncsplash(HZ
, str(LANG_BACKDROP_FAILED
));
586 static bool rename_file(void)
588 char newname
[MAX_PATH
];
589 char* ptr
= strrchr(selected_file
, '/') + 1;
590 int pathlen
= (ptr
- selected_file
);
591 strncpy(newname
, selected_file
, sizeof newname
);
592 if (!kbd_input(newname
+ pathlen
, (sizeof newname
)-pathlen
)) {
593 if (!strlen(newname
+ pathlen
) ||
594 (rename(selected_file
, newname
) < 0)) {
596 lcd_puts(0,0,str(LANG_RENAME
));
597 lcd_puts(0,1,str(LANG_FAILED
));
599 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
603 onplay_result
= ONPLAY_RELOAD_DIR
;
609 static bool create_dir(void)
611 char dirname
[MAX_PATH
];
616 cwd
= getcwd(NULL
, 0);
617 memset(dirname
, 0, sizeof dirname
);
619 snprintf(dirname
, sizeof dirname
, "%s/",
622 pathlen
= strlen(dirname
);
623 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
629 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
630 gui_syncsplash(HZ
, (unsigned char *)"%s %s",
631 str(LANG_CREATE_DIR
), str(LANG_FAILED
));
633 onplay_result
= ONPLAY_RELOAD_DIR
;
639 static bool properties(void)
641 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("properties",
643 onplay_result
= ONPLAY_RELOAD_DIR
;
647 /* Store the current selection in the clipboard */
648 static bool clipboard_clip(bool copy
)
650 clipboard_selection
[0] = 0;
651 strncpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
652 clipboard_selection_attr
= selected_file_attr
;
653 clipboard_is_copy
= copy
;
658 static bool clipboard_cut(void)
660 return clipboard_clip(false);
663 static bool clipboard_copy(void)
665 return clipboard_clip(true);
668 #ifdef HAVE_LCD_BITMAP
669 static inline void draw_slider(void)
674 show_busy_slider(&screens
[i
], 2, LCD_HEIGHT
/4,
675 LCD_WIDTH
-4, screens
[i
].char_height
);
680 #define draw_slider()
683 /* Paste a file to a new directory. Will overwrite always. */
684 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
686 int src_fd
, target_fd
;
688 ssize_t size
, bytesread
, byteswritten
;
693 /* See if we can get the plugin buffer for the file copy buffer */
694 buffer
= (char *) plugin_get_buffer(&buffersize
);
695 if (buffer
== NULL
|| buffersize
< 512) {
696 /* Not large enough, try for a disk sector worth of stack
699 buffer
= (char *) __builtin_alloca(buffersize
);
702 if (buffer
== NULL
) {
706 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
709 src_fd
= open(src
, O_RDONLY
);
712 target_fd
= creat(target
);
714 if (target_fd
>= 0) {
717 size
= filesize(src_fd
);
724 bytesread
= read(src_fd
, buffer
, buffersize
);
726 if (bytesread
== -1) {
733 while(bytesread
> 0) {
734 byteswritten
= write(target_fd
, buffer
, bytesread
);
736 if (byteswritten
== -1) {
742 bytesread
-= byteswritten
;
749 /* Copy failed. Cleanup. */
758 result
= rename(src
, target
) == 0;
759 #ifdef HAVE_MULTIVOLUME
761 if (errno
== EXDEV
) {
762 /* Failed because cross volume rename doesn't work. Copy
764 result
= clipboard_pastefile(src
, target
, true);
767 result
= remove(src
) == 0;
777 /* Paste a directory to a new location. Designed to be called by
779 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
780 int targetlen
, bool copy
)
783 int srcdirlen
= strlen(src
);
784 int targetdirlen
= strlen(target
);
788 /* Check if the target exists */
789 fd
= open(target
, O_RDONLY
);
794 /* Just move the directory */
795 result
= rename(src
, target
) == 0;
797 #ifdef HAVE_MULTIVOLUME
798 if (!result
&& errno
== EXDEV
) {
799 /* Try a copy as we're going across devices */
800 result
= clipboard_pastedirectory(src
, srclen
, target
,
803 /* If it worked, remove the source directory */
805 remove_dir(src
, srclen
);
811 /* Make a directory to copy things to */
812 result
= mkdir(target
) == 0;
816 /* Check if something went wrong already */
821 srcdir
= opendir(src
);
826 /* This loop will exit as soon as there's a problem */
829 struct dirent
* entry
;
830 /* walk through the directory content */
831 entry
= readdir(srcdir
);
835 /* append name to current directory */
836 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
837 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
840 DEBUGF("Copy %s to %s\n", src
, target
);
842 if (entry
->attribute
& ATTR_DIRECTORY
)
843 { /* copy/move a subdirectory */
844 if (!strcmp((char *)entry
->d_name
, ".") ||
845 !strcmp((char *)entry
->d_name
, ".."))
846 continue; /* skip these */
848 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
849 copy
); /* recursion */
852 { /* copy/move a file */
853 result
= clipboard_pastefile(src
, target
, copy
);
860 src
[srcdirlen
] = '\0'; /* terminate to original length */
861 target
[targetdirlen
] = '\0'; /* terminate to original length */
867 /* Paste the clipboard to the current directory */
868 static bool clipboard_paste(void)
870 char target
[MAX_PATH
];
875 unsigned char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
876 struct text_message message
={(char **)lines
, 1};
878 /* Get the name of the current directory */
879 cwd
= getcwd(NULL
, 0);
881 /* Figure out the name of the selection */
882 nameptr
= strrchr(clipboard_selection
, '/');
884 /* Final target is current directory plus name of selection */
885 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
887 /* Check if we're going to overwrite */
888 target_fd
= open(target
, O_RDONLY
);
891 /* If the target existed but they choose not to overwite, exit */
892 if (target_fd
>= 0 &&
893 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
897 if (clipboard_is_copy
) {
898 gui_syncsplash(0, ID2P(LANG_COPYING
));
902 gui_syncsplash(0, ID2P(LANG_MOVING
));
905 /* Now figure out what we're doing */
907 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
908 /* Recursion. Set up external stack */
909 char srcpath
[MAX_PATH
];
910 char targetpath
[MAX_PATH
];
911 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
913 /* Do not allow the user to paste a directory into a dir they are
919 strncpy(srcpath
, clipboard_selection
, sizeof srcpath
);
920 strncpy(targetpath
, target
, sizeof targetpath
);
922 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
923 target
, sizeof(targetpath
), clipboard_is_copy
);
926 success
= clipboard_pastefile(clipboard_selection
, target
,
933 /* Reset everything */
934 clipboard_selection
[0] = 0;
935 clipboard_selection_attr
= 0;
936 clipboard_is_copy
= false;
938 /* Force reload of the current directory */
939 onplay_result
= ONPLAY_RELOAD_DIR
;
941 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
942 gui_syncsplash(HZ
, (unsigned char *)"%s %s",
943 str(LANG_PASTE
), str(LANG_FAILED
));
949 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
951 static int set_rating_inline(void)
953 struct mp3entry
* id3
= audio_current_track();
954 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
956 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
957 NULL
, 1, 0, 10, NULL
, NULL
);
958 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
961 gui_syncsplash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
964 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
969 case ACTION_REQUEST_MENUITEM
:
970 if (!selected_file
|| !global_settings
.runtimedb
)
971 return ACTION_EXIT_MENUITEM
;
976 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
977 set_rating_inline
, NULL
,
978 ratingitem_callback
, Icon_Questionmark
);
981 static bool view_cue(void)
983 struct mp3entry
* id3
= audio_current_track();
984 if(id3
&& cuesheet_is_enabled() && id3
->cuesheet_type
)
986 browse_cuesheet(curr_cue
);
990 static int view_cue_item_callback(int action
,
991 const struct menu_item_ex
*this_item
)
994 struct mp3entry
* id3
= audio_current_track();
997 case ACTION_REQUEST_MENUITEM
:
998 if (!selected_file
|| !cuesheet_is_enabled()
999 || !id3
|| !id3
->cuesheet_type
)
1000 return ACTION_EXIT_MENUITEM
;
1005 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
1006 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
1008 /* CONTEXT_WPS items */
1009 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
1010 browse_id3
, NULL
, NULL
, Icon_NOICON
);
1011 #ifdef HAVE_PITCHSCREEN
1012 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
1013 pitch_screen
, NULL
, NULL
, Icon_Audio
);
1015 #if CONFIG_CODEC == SWCODEC
1016 MENUITEM_FUNCTION(eq_menu_graphical_item
, 0, ID2P(LANG_EQUALIZER_GRAPHICAL
),
1017 eq_menu_graphical
, NULL
, NULL
, Icon_Audio
);
1018 MENUITEM_FUNCTION(eq_browse_presets_item
, 0, ID2P(LANG_EQUALIZER_BROWSE
),
1019 eq_browse_presets
, NULL
, NULL
, Icon_Audio
);
1022 /* CONTEXT_[TREE|ID3DB] items */
1023 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
1024 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
1025 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1026 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
1027 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
1028 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
1029 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
1030 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
1031 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
1032 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
1033 delete_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1034 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
1035 delete_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1036 MENUITEM_FUNCTION(properties_item
, 0, ID2P(LANG_PROPERTIES
),
1037 properties
, NULL
, clipboard_callback
, Icon_NOICON
);
1038 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
1039 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1040 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1041 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1043 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1044 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1046 #ifdef HAVE_RECORDING
1047 static bool set_recdir(void)
1049 strncpy(global_settings
.rec_directory
,
1050 selected_file
, MAX_FILENAME
+1);
1054 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1055 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1057 static bool add_to_faves(void)
1059 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("shortcuts_append",
1061 onplay_result
= ONPLAY_RELOAD_DIR
;
1064 MENUITEM_FUNCTION(add_to_faves_item
, 0, ID2P(LANG_ADD_TO_FAVES
),
1065 add_to_faves
, NULL
, clipboard_callback
, Icon_NOICON
);
1068 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1072 case ACTION_REQUEST_MENUITEM
:
1073 if (context
== CONTEXT_ID3DB
)
1074 return ACTION_EXIT_MENUITEM
;
1075 if (this_item
== &clipboard_paste_item
)
1076 { /* visible if there is something to paste */
1077 return (clipboard_selection
[0] != 0) ?
1078 action
: ACTION_EXIT_MENUITEM
;
1080 else if ((this_item
== &create_dir_item
) ||
1081 (this_item
== &properties_item
) ||
1082 (this_item
== &rename_file_item
) ||
1083 (this_item
== &clipboard_cut_item
) ||
1084 (this_item
== &clipboard_copy_item
) ||
1085 (this_item
== &add_to_faves_item
)
1088 /* always visible */
1092 else if (this_item
== &set_backdrop_item
)
1096 char *suffix
= strrchr(selected_file
, '.');
1099 if (strcasecmp(suffix
, ".bmp") == 0)
1105 return ACTION_EXIT_MENUITEM
;
1108 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1110 if ((this_item
== &delete_dir_item
)
1113 #ifdef HAVE_RECORDING
1114 else if (this_item
== &set_recdir_item
)
1118 else if (selected_file
1119 #ifdef HAVE_MULTIVOLUME
1120 /* no rename+delete for volumes */
1121 && !(selected_file_attr
& ATTR_VOLUME
)
1125 if ((this_item
== &delete_file_item
) ||
1126 (this_item
== &list_viewers_item
))
1131 return ACTION_EXIT_MENUITEM
;
1136 /* used when onplay() is called in the CONTEXT_WPS context */
1139 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1140 onplaymenu_callback
, Icon_Audio
,
1141 &sound_settings
, &wps_playlist_menu
, &cat_playlist_menu
,
1142 #ifdef HAVE_TAGCACHE
1145 &bookmark_menu
, &browse_id3_item
, &delete_file_item
, &view_cue_item
,
1146 #ifdef HAVE_PITCHSCREEN
1149 #if CONFIG_CODEC == SWCODEC
1150 &eq_menu_graphical_item
, &eq_browse_presets_item
,
1153 /* used when onplay() is not called in the CONTEXT_WPS context */
1154 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1155 onplaymenu_callback
, Icon_file_view_menu
,
1156 &tree_playlist_menu
, &cat_playlist_menu
,
1157 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1158 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1162 &list_viewers_item
, &create_dir_item
, &properties_item
,
1163 #ifdef HAVE_RECORDING
1168 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1173 case ACTION_TREE_STOP
:
1174 if (this_item
== &wps_onplay_menu
)
1176 list_stop_handler();
1177 return ACTION_STD_CANCEL
;
1180 case ACTION_EXIT_MENUITEM
:
1181 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1186 int onplay(char* file
, int attr
, int from
)
1188 const struct menu_item_ex
*menu
;
1189 onplay_result
= ONPLAY_OK
;
1191 selected_file
= file
;
1192 selected_file_attr
= attr
;
1193 if (context
== CONTEXT_WPS
)
1194 menu
= &wps_onplay_menu
;
1196 menu
= &tree_onplay_menu
;
1197 switch (do_menu(menu
, NULL
, NULL
, false))
1200 return ONPLAY_START_PLAY
;
1202 case GO_TO_MAINMENU
:
1203 return ONPLAY_MAINMENU
;
1205 return context
== CONTEXT_WPS
? ONPLAY_OK
: ONPLAY_RELOAD_DIR
;