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 "statusbar.h"
46 #include "playlist_viewer.h"
49 #include "filetypes.h"
55 #include "menus/exported_menus.h"
56 #ifdef HAVE_LCD_BITMAP
59 #include "sound_menu.h"
60 #include "playlist_menu.h"
61 #include "playlist_catalog.h"
67 #include "pitchscreen.h"
70 static char* selected_file
= NULL
;
71 static int selected_file_attr
= 0;
72 static int onplay_result
= ONPLAY_OK
;
73 static char clipboard_selection
[MAX_PATH
];
74 static int clipboard_selection_attr
= 0;
75 static bool clipboard_is_copy
= false;
77 /* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */
78 #define MAKE_ONPLAYMENU( name, str, callback, icon, ... ) \
79 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
80 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
81 static const struct menu_item_ex name = \
82 {MT_MENU|MENU_HAS_DESC|MENU_EXITAFTERTHISMENU| \
83 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
84 { (void*)name##_},{.callback_and_desc = & name##__}};
86 #ifdef HAVE_LCD_BITMAP
87 static void draw_slider(void);
91 /* ----------------------------------------------------------------------- */
92 /* Displays the bookmark menu options for the user to decide. This is an */
93 /* interface function. */
94 /* ----------------------------------------------------------------------- */
96 static int bookmark_menu_callback(int action
,
97 const struct menu_item_ex
*this_item
);
98 MENUITEM_FUNCTION(bookmark_create_menu_item
, 0,
99 ID2P(LANG_BOOKMARK_MENU_CREATE
),
100 bookmark_create_menu
, NULL
, NULL
, Icon_Bookmark
);
101 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
102 ID2P(LANG_BOOKMARK_MENU_LIST
),
103 bookmark_load_menu
, NULL
,
104 bookmark_menu_callback
, Icon_Bookmark
);
105 MAKE_ONPLAYMENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
), bookmark_menu_callback
,
106 Icon_Bookmark
, &bookmark_create_menu_item
,
107 &bookmark_load_menu_item
);
108 static int bookmark_menu_callback(int action
,
109 const struct menu_item_ex
*this_item
)
114 case ACTION_REQUEST_MENUITEM
:
115 if (this_item
== &bookmark_load_menu_item
)
117 if (bookmark_exist() == 0)
118 return ACTION_EXIT_MENUITEM
;
120 /* hide the bookmark menu if there is no playback */
121 else if ((audio_status() & AUDIO_STATUS_PLAY
) == 0)
122 return ACTION_EXIT_MENUITEM
;
124 #ifdef HAVE_LCD_CHARCELLS
125 case ACTION_ENTER_MENUITEM
:
126 status_set_param(true);
129 case ACTION_EXIT_MENUITEM
:
130 #ifdef HAVE_LCD_CHARCELLS
131 status_set_param(false);
139 static bool list_viewers(void)
141 int ret
= filetype_list_viewers(selected_file
);
142 if (ret
== PLUGIN_USB_CONNECTED
)
143 onplay_result
= ONPLAY_RELOAD_DIR
;
147 static bool shuffle_playlist(void)
149 playlist_sort(NULL
, true);
150 playlist_randomise(NULL
, current_tick
, true);
155 static bool save_playlist(void)
157 save_playlist_screen(NULL
);
161 static bool add_to_playlist(int position
, bool queue
)
163 bool new_playlist
= !(audio_status() & AUDIO_STATUS_PLAY
);
164 const char *lines
[] = {
165 ID2P(LANG_RECURSE_DIRECTORY_QUESTION
),
168 const struct text_message message
={lines
, 2};
170 splash(0, ID2P(LANG_WAIT
));
173 playlist_create(NULL
, NULL
);
175 /* always set seed before inserting shuffled */
176 if (position
== PLAYLIST_INSERT_SHUFFLED
)
180 if (context
== CONTEXT_ID3DB
)
182 tagtree_insert_selection_playlist(position
, queue
);
187 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_AUDIO
)
188 playlist_insert_track(NULL
, selected_file
, position
, queue
, true);
189 else if (selected_file_attr
& ATTR_DIRECTORY
)
191 bool recurse
= false;
193 if (global_settings
.recursive_dir_insert
!= RECURSE_ASK
)
194 recurse
= (bool)global_settings
.recursive_dir_insert
;
197 /* Ask if user wants to recurse directory */
198 recurse
= (gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
);
201 playlist_insert_directory(NULL
, selected_file
, position
, queue
,
204 else if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)
205 playlist_insert_playlist(NULL
, selected_file
, position
, queue
);
208 if (new_playlist
&& (playlist_amount() > 0))
210 /* nothing is currently playing so begin playing what we just
212 if (global_settings
.playlist_shuffle
)
213 playlist_shuffle(current_tick
, -1);
215 onplay_result
= ONPLAY_START_PLAY
;
221 static bool view_playlist(void)
223 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
226 result
= playlist_viewer_ex(selected_file
);
228 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
229 onplay_result
== ONPLAY_OK
)
230 /* playlist was started from viewer */
231 onplay_result
= ONPLAY_START_PLAY
;
236 static bool cat_add_to_a_playlist(void)
238 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
242 static bool cat_add_to_a_new_playlist(void)
244 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
249 static int cat_playlist_callback(int action
,
250 const struct menu_item_ex
*this_item
);
251 MENUITEM_FUNCTION(cat_view_lists
, 0, ID2P(LANG_CATALOG_VIEW
),
252 catalog_view_playlists
, 0, cat_playlist_callback
,
254 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
255 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
256 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
257 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
258 MAKE_ONPLAYMENU(cat_playlist_menu
, ID2P(LANG_CATALOG
), cat_playlist_callback
,
259 Icon_Playlist
, &cat_view_lists
, &cat_add_to_list
,
262 static int cat_playlist_callback(int action
,
263 const struct menu_item_ex
*this_item
)
265 if (((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
) &&
266 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_M3U
) &&
267 ((selected_file_attr
& ATTR_DIRECTORY
) == 0))
269 return ACTION_EXIT_MENUITEM
;
274 case ACTION_REQUEST_MENUITEM
:
275 if (this_item
== &cat_view_lists
)
277 if (context
== CONTEXT_WPS
)
280 else if (selected_file
&& /* set before calling this menu,
282 ((audio_status() & AUDIO_STATUS_PLAY
&&
283 context
== CONTEXT_WPS
) ||
284 context
== CONTEXT_TREE
))
289 return ACTION_EXIT_MENUITEM
;
296 /* CONTEXT_WPS playlist options */
297 MENUITEM_FUNCTION(playlist_viewer_item
, 0,
298 ID2P(LANG_VIEW_DYNAMIC_PLAYLIST
), playlist_viewer
,
299 NULL
, NULL
, Icon_Playlist
);
300 MENUITEM_FUNCTION(search_playlist_item
, 0,
301 ID2P(LANG_SEARCH_IN_PLAYLIST
), search_playlist
,
302 NULL
, NULL
, Icon_Playlist
);
303 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
304 save_playlist
, NULL
, NULL
, Icon_Playlist
);
305 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
306 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
307 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
309 &playlist_viewer_item
, &search_playlist_item
,
310 &playlist_save_item
, &reshuffle_item
313 /* CONTEXT_[TREE|ID3DB] playlist options */
314 static int playlist_insert_func(void *param
)
316 add_to_playlist((intptr_t)param
, false);
319 static int playlist_queue_func(void *param
)
321 add_to_playlist((intptr_t)param
, true);
324 static int treeplaylist_wplayback_callback(int action
,
325 const struct menu_item_ex
*
331 case ACTION_REQUEST_MENUITEM
:
332 if (audio_status() & AUDIO_STATUS_PLAY
)
335 return ACTION_EXIT_MENUITEM
;
341 static int treeplaylist_callback(int action
,
342 const struct menu_item_ex
*this_item
);
345 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
346 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
347 treeplaylist_callback
, Icon_Playlist
);
348 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
349 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
350 treeplaylist_wplayback_callback
, Icon_Playlist
);
351 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
352 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
353 treeplaylist_wplayback_callback
, Icon_Playlist
);
354 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
355 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
356 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
, treeplaylist_callback
,
359 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
360 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
361 treeplaylist_wplayback_callback
, Icon_Playlist
);
362 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
363 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
364 treeplaylist_wplayback_callback
, Icon_Playlist
);
365 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
366 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
367 treeplaylist_wplayback_callback
, Icon_Playlist
);
368 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
369 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
370 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
371 treeplaylist_wplayback_callback
, Icon_Playlist
);
372 /* replace playlist */
373 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
374 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
375 treeplaylist_wplayback_callback
, Icon_Playlist
);
378 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
380 treeplaylist_callback
, Icon_Playlist
);
382 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_PLAYLIST
),
383 treeplaylist_callback
, Icon_Playlist
,
389 &i_pl_item
, &i_first_pl_item
,
390 &i_last_pl_item
, &i_shuf_pl_item
,
393 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
399 static int treeplaylist_callback(int action
,
400 const struct menu_item_ex
*this_item
)
405 case ACTION_REQUEST_MENUITEM
:
406 if (this_item
== &tree_playlist_menu
)
408 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
410 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
411 (selected_file_attr
& ATTR_DIRECTORY
))
416 return ACTION_EXIT_MENUITEM
;
418 else if (this_item
== &view_playlist_item
)
420 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
421 context
== CONTEXT_TREE
)
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
);
454 dir
= opendir(dirname
);
456 return -1; /* open error */
460 struct dirent
* entry
;
461 /* walk through the directory content */
462 entry
= readdir(dir
);
466 dirname
[dirlen
] ='\0';
469 /* append name to current directory */
470 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
471 if (entry
->attribute
& ATTR_DIRECTORY
)
472 { /* remove a subdirectory */
473 if (!strcmp((char *)entry
->d_name
, ".") ||
474 !strcmp((char *)entry
->d_name
, ".."))
475 continue; /* skip these */
477 /* inform the user which dir we're deleting */
479 result
= remove_dir(dirname
, len
); /* recursion */
481 break; /* or better continue, delete what we can? */
484 { /* remove a file */
486 result
= remove(dirname
);
488 if(ACTION_STD_CANCEL
== get_action(CONTEXT_STD
,TIMEOUT_NOBLOCK
))
490 splash(HZ
, ID2P(LANG_CANCEL
));
498 { /* remove the now empty directory */
499 dirname
[dirlen
] = '\0'; /* terminate to original length */
501 result
= rmdir(dirname
);
508 /* share code for file and directory deletion, saves space */
509 static bool delete_handler(bool is_dir
)
511 char file_to_delete
[MAX_PATH
];
512 strcpy(file_to_delete
, selected_file
);
514 const char *lines
[]={
515 ID2P(LANG_REALLY_DELETE
),
518 const char *yes_lines
[]={
523 const struct text_message message
={lines
, 2};
524 const struct text_message yes_message
={yes_lines
, 2};
526 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
529 splash(0, str(LANG_DELETING
));
534 char pathname
[MAX_PATH
]; /* space to go deep */
536 strncpy(pathname
, file_to_delete
, sizeof pathname
);
537 res
= remove_dir(pathname
, sizeof(pathname
));
541 res
= remove(file_to_delete
);
544 onplay_result
= ONPLAY_RELOAD_DIR
;
550 static bool delete_file(void)
552 return delete_handler(false);
555 static bool delete_dir(void)
557 return delete_handler(true);
561 static bool set_backdrop(void)
564 if(load_main_backdrop(selected_file
)) {
565 splash(HZ
, str(LANG_BACKDROP_LOADED
));
566 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
568 show_main_backdrop();
571 splash(HZ
, str(LANG_BACKDROP_FAILED
));
577 static bool rename_file(void)
579 char newname
[MAX_PATH
];
580 char* ptr
= strrchr(selected_file
, '/') + 1;
581 int pathlen
= (ptr
- selected_file
);
582 strncpy(newname
, selected_file
, sizeof newname
);
583 if (!kbd_input(newname
+ pathlen
, (sizeof newname
)-pathlen
)) {
584 if (!strlen(newname
+ pathlen
) ||
585 (rename(selected_file
, newname
) < 0)) {
587 lcd_puts(0,0,str(LANG_RENAME
));
588 lcd_puts(0,1,str(LANG_FAILED
));
590 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
594 onplay_result
= ONPLAY_RELOAD_DIR
;
600 static bool create_dir(void)
602 char dirname
[MAX_PATH
];
607 cwd
= getcwd(NULL
, 0);
608 memset(dirname
, 0, sizeof dirname
);
610 snprintf(dirname
, sizeof dirname
, "%s/",
613 pathlen
= strlen(dirname
);
614 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
620 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
621 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_CREATE_DIR
),
624 onplay_result
= ONPLAY_RELOAD_DIR
;
630 static bool properties(void)
632 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("properties",
634 onplay_result
= ONPLAY_RELOAD_DIR
;
638 /* Store the current selection in the clipboard */
639 static bool clipboard_clip(bool copy
)
641 clipboard_selection
[0] = 0;
642 strncpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
643 clipboard_selection_attr
= selected_file_attr
;
644 clipboard_is_copy
= copy
;
649 static bool clipboard_cut(void)
651 return clipboard_clip(false);
654 static bool clipboard_copy(void)
656 return clipboard_clip(true);
659 #ifdef HAVE_LCD_BITMAP
660 static void draw_slider(void)
665 show_busy_slider(&screens
[i
], 1,
666 LCD_HEIGHT
-2*screens
[i
].getcharheight(),
667 LCD_WIDTH
-2, 2*screens
[i
].getcharheight()-1);
673 /* Paste a file to a new directory. Will overwrite always. */
674 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
676 int src_fd
, target_fd
;
678 ssize_t size
, bytesread
, byteswritten
;
683 /* See if we can get the plugin buffer for the file copy buffer */
684 buffer
= (char *) plugin_get_buffer(&buffersize
);
685 if (buffer
== NULL
|| buffersize
< 512) {
686 /* Not large enough, try for a disk sector worth of stack
689 buffer
= (char *) __builtin_alloca(buffersize
);
692 if (buffer
== NULL
) {
696 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
699 src_fd
= open(src
, O_RDONLY
);
702 target_fd
= creat(target
);
704 if (target_fd
>= 0) {
707 size
= filesize(src_fd
);
714 bytesread
= read(src_fd
, buffer
, buffersize
);
716 if (bytesread
== -1) {
723 while(bytesread
> 0) {
724 byteswritten
= write(target_fd
, buffer
, bytesread
);
726 if (byteswritten
< 0) {
732 bytesread
-= byteswritten
;
739 /* Copy failed. Cleanup. */
748 result
= rename(src
, target
) == 0;
749 #ifdef HAVE_MULTIVOLUME
751 if (errno
== EXDEV
) {
752 /* Failed because cross volume rename doesn't work. Copy
754 result
= clipboard_pastefile(src
, target
, true);
757 result
= remove(src
) == 0;
767 /* Paste a directory to a new location. Designed to be called by
769 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
770 int targetlen
, bool copy
)
773 int srcdirlen
= strlen(src
);
774 int targetdirlen
= strlen(target
);
777 if (!file_exists(target
)) {
779 /* Just move the directory */
780 result
= rename(src
, target
) == 0;
782 #ifdef HAVE_MULTIVOLUME
783 if (!result
&& errno
== EXDEV
) {
784 /* Try a copy as we're going across devices */
785 result
= clipboard_pastedirectory(src
, srclen
, target
,
788 /* If it worked, remove the source directory */
790 remove_dir(src
, srclen
);
796 /* Make a directory to copy things to */
797 result
= mkdir(target
) == 0;
801 /* Check if something went wrong already */
806 srcdir
= opendir(src
);
811 /* This loop will exit as soon as there's a problem */
814 struct dirent
* entry
;
815 /* walk through the directory content */
816 entry
= readdir(srcdir
);
820 /* append name to current directory */
821 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
822 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
825 DEBUGF("Copy %s to %s\n", src
, target
);
827 if (entry
->attribute
& ATTR_DIRECTORY
)
828 { /* copy/move a subdirectory */
829 if (!strcmp((char *)entry
->d_name
, ".") ||
830 !strcmp((char *)entry
->d_name
, ".."))
831 continue; /* skip these */
833 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
834 copy
); /* recursion */
837 { /* copy/move a file */
838 result
= clipboard_pastefile(src
, target
, copy
);
845 src
[srcdirlen
] = '\0'; /* terminate to original length */
846 target
[targetdirlen
] = '\0'; /* terminate to original length */
852 /* Paste the clipboard to the current directory */
853 static bool clipboard_paste(void)
855 char target
[MAX_PATH
];
859 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
860 static const struct text_message message
={lines
, 1};
862 /* Get the name of the current directory */
863 cwd
= getcwd(NULL
, 0);
865 /* Figure out the name of the selection */
866 nameptr
= strrchr(clipboard_selection
, '/');
868 /* Final target is current directory plus name of selection */
869 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
871 /* If the target existed but they choose not to overwite, exit */
872 if (file_exists(target
) &&
873 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
877 if (clipboard_is_copy
) {
878 splash(0, ID2P(LANG_COPYING
));
882 splash(0, ID2P(LANG_MOVING
));
885 /* Now figure out what we're doing */
887 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
888 /* Recursion. Set up external stack */
889 char srcpath
[MAX_PATH
];
890 char targetpath
[MAX_PATH
];
891 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
893 /* Do not allow the user to paste a directory into a dir they are
899 strncpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
900 strncpy(targetpath
, target
, sizeof(targetpath
));
902 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
903 target
, sizeof(targetpath
), clipboard_is_copy
);
905 if (success
&& !clipboard_is_copy
)
907 strncpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
908 remove_dir(srcpath
, sizeof(srcpath
));
912 success
= clipboard_pastefile(clipboard_selection
, target
,
919 /* Reset everything */
920 clipboard_selection
[0] = 0;
921 clipboard_selection_attr
= 0;
922 clipboard_is_copy
= false;
924 /* Force reload of the current directory */
925 onplay_result
= ONPLAY_RELOAD_DIR
;
927 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
928 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_PASTE
),
935 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
937 static int set_rating_inline(void)
939 struct mp3entry
* id3
= audio_current_track();
940 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
942 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
943 NULL
, 1, 0, 10, NULL
, NULL
);
944 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
947 splash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
950 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
955 case ACTION_REQUEST_MENUITEM
:
956 if (!selected_file
|| !global_settings
.runtimedb
||
957 !tagcache_is_usable())
958 return ACTION_EXIT_MENUITEM
;
963 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
964 set_rating_inline
, NULL
,
965 ratingitem_callback
, Icon_Questionmark
);
968 static bool view_cue(void)
970 struct mp3entry
* id3
= audio_current_track();
971 if(id3
&& cuesheet_is_enabled() && id3
->cuesheet_type
)
973 browse_cuesheet(curr_cue
);
977 static int view_cue_item_callback(int action
,
978 const struct menu_item_ex
*this_item
)
981 struct mp3entry
* id3
= audio_current_track();
984 case ACTION_REQUEST_MENUITEM
:
985 if (!selected_file
|| !cuesheet_is_enabled()
986 || !id3
|| !id3
->cuesheet_type
)
987 return ACTION_EXIT_MENUITEM
;
992 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
993 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
995 /* CONTEXT_WPS items */
996 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
997 browse_id3
, NULL
, NULL
, Icon_NOICON
);
998 #ifdef HAVE_PITCHSCREEN
999 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
1000 gui_syncpitchscreen_run
, NULL
, NULL
, Icon_Audio
);
1003 /* CONTEXT_[TREE|ID3DB] items */
1004 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
1005 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
1006 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1007 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
1008 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
1009 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
1010 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
1011 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
1012 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
1013 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
1014 delete_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1015 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
1016 delete_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1017 MENUITEM_FUNCTION(properties_item
, 0, ID2P(LANG_PROPERTIES
),
1018 properties
, NULL
, clipboard_callback
, Icon_NOICON
);
1019 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
1020 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1021 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1022 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1024 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1025 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1027 #ifdef HAVE_RECORDING
1028 static bool set_recdir(void)
1030 strncpy(global_settings
.rec_directory
,
1031 selected_file
, MAX_FILENAME
+1);
1035 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1036 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1038 static bool add_to_faves(void)
1040 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("shortcuts_append",
1042 onplay_result
= ONPLAY_RELOAD_DIR
;
1045 MENUITEM_FUNCTION(add_to_faves_item
, 0, ID2P(LANG_ADD_TO_FAVES
),
1046 add_to_faves
, NULL
, clipboard_callback
, Icon_NOICON
);
1049 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1053 case ACTION_REQUEST_MENUITEM
:
1054 #ifdef HAVE_MULTIVOLUME
1055 if ((selected_file_attr
& FAT_ATTR_VOLUME
) &&
1056 (this_item
== &rename_file_item
||
1057 this_item
== &delete_dir_item
||
1058 this_item
== &clipboard_cut_item
) )
1059 return ACTION_EXIT_MENUITEM
;
1061 if (context
== CONTEXT_ID3DB
)
1062 return ACTION_EXIT_MENUITEM
;
1063 if (this_item
== &clipboard_paste_item
)
1064 { /* visible if there is something to paste */
1065 return (clipboard_selection
[0] != 0) ?
1066 action
: ACTION_EXIT_MENUITEM
;
1068 else if (this_item
== &create_dir_item
)
1070 /* always visible */
1073 else if ((this_item
== &properties_item
) ||
1074 (this_item
== &rename_file_item
) ||
1075 (this_item
== &clipboard_cut_item
) ||
1076 (this_item
== &clipboard_copy_item
) ||
1077 (this_item
== &add_to_faves_item
)
1080 /* requires an actual file */
1081 return (selected_file
) ? action
: ACTION_EXIT_MENUITEM
;
1084 else if (this_item
== &set_backdrop_item
)
1088 char *suffix
= strrchr(selected_file
, '.');
1091 if (strcasecmp(suffix
, ".bmp") == 0)
1097 return ACTION_EXIT_MENUITEM
;
1100 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1102 if ((this_item
== &delete_dir_item
)
1105 #ifdef HAVE_RECORDING
1106 else if (this_item
== &set_recdir_item
)
1110 else if (selected_file
1111 #ifdef HAVE_MULTIVOLUME
1112 /* no rename+delete for volumes */
1113 && !(selected_file_attr
& ATTR_VOLUME
)
1117 if ((this_item
== &delete_file_item
) ||
1118 (this_item
== &list_viewers_item
))
1123 return ACTION_EXIT_MENUITEM
;
1128 /* used when onplay() is called in the CONTEXT_WPS context */
1131 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1132 onplaymenu_callback
, Icon_Audio
,
1133 &wps_playlist_menu
, &cat_playlist_menu
,
1134 &sound_settings
, &playback_settings
,
1135 #ifdef HAVE_TAGCACHE
1138 &bookmark_menu
, &browse_id3_item
, &list_viewers_item
,
1139 &delete_file_item
, &view_cue_item
,
1140 #ifdef HAVE_PITCHSCREEN
1144 /* used when onplay() is not called in the CONTEXT_WPS context */
1145 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1146 onplaymenu_callback
, Icon_file_view_menu
,
1147 &tree_playlist_menu
, &cat_playlist_menu
,
1148 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1149 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1153 &list_viewers_item
, &create_dir_item
, &properties_item
,
1154 #ifdef HAVE_RECORDING
1159 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1164 case ACTION_TREE_STOP
:
1165 if (this_item
== &wps_onplay_menu
)
1167 list_stop_handler();
1168 return ACTION_STD_CANCEL
;
1171 case ACTION_EXIT_MENUITEM
:
1172 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1177 int onplay(char* file
, int attr
, int from
)
1179 const struct menu_item_ex
*menu
;
1180 onplay_result
= ONPLAY_OK
;
1182 selected_file
= file
;
1183 selected_file_attr
= attr
;
1184 if (context
== CONTEXT_WPS
)
1185 menu
= &wps_onplay_menu
;
1187 menu
= &tree_onplay_menu
;
1188 switch (do_menu(menu
, NULL
, NULL
, false))
1191 return ONPLAY_START_PLAY
;
1193 case GO_TO_MAINMENU
:
1194 return ONPLAY_MAINMENU
;
1196 return context
== CONTEXT_WPS
? ONPLAY_OK
: ONPLAY_RELOAD_DIR
;