1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
45 #include "playlist_viewer.h"
48 #include "filetypes.h"
54 #include "menus/exported_menus.h"
55 #ifdef HAVE_LCD_BITMAP
58 #include "sound_menu.h"
59 #include "playlist_menu.h"
60 #include "playlist_catalog.h"
66 #include "pitchscreen.h"
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 strlcpy(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(backdrop_load(BACKDROP_MAIN
, selected_file
)) {
565 splash(HZ
, str(LANG_BACKDROP_LOADED
));
566 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
568 backdrop_show(BACKDROP_MAIN
);
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 strlcpy(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)) {
586 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
587 splashf(HZ
*2, "%s %s", str(LANG_RENAME
), str(LANG_FAILED
));
590 onplay_result
= ONPLAY_RELOAD_DIR
;
596 static bool create_dir(void)
598 char dirname
[MAX_PATH
];
603 cwd
= getcwd(NULL
, 0);
604 memset(dirname
, 0, sizeof dirname
);
606 snprintf(dirname
, sizeof dirname
, "%s/",
609 pathlen
= strlen(dirname
);
610 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
616 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
617 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_CREATE_DIR
),
620 onplay_result
= ONPLAY_RELOAD_DIR
;
626 static bool properties(void)
628 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("properties",
630 onplay_result
= ONPLAY_RELOAD_DIR
;
634 /* Store the current selection in the clipboard */
635 static bool clipboard_clip(bool copy
)
637 clipboard_selection
[0] = 0;
638 strlcpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
639 clipboard_selection_attr
= selected_file_attr
;
640 clipboard_is_copy
= copy
;
645 static bool clipboard_cut(void)
647 return clipboard_clip(false);
650 static bool clipboard_copy(void)
652 return clipboard_clip(true);
655 #ifdef HAVE_LCD_BITMAP
656 static void draw_slider(void)
661 struct viewport
*vp
= &(viewport_get_current_vp())[i
];
662 show_busy_slider(&screens
[i
], vp
->x
,
663 (vp
->y
+vp
->height
)-2*screens
[i
].getcharheight(),
664 vp
->width
, 2*screens
[i
].getcharheight()-1);
670 /* Paste a file to a new directory. Will overwrite always. */
671 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
673 int src_fd
, target_fd
;
675 ssize_t size
, bytesread
, byteswritten
;
680 /* See if we can get the plugin buffer for the file copy buffer */
681 buffer
= (char *) plugin_get_buffer(&buffersize
);
682 if (buffer
== NULL
|| buffersize
< 512) {
683 /* Not large enough, try for a disk sector worth of stack
686 buffer
= (char *) __builtin_alloca(buffersize
);
689 if (buffer
== NULL
) {
693 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
696 src_fd
= open(src
, O_RDONLY
);
699 target_fd
= creat(target
);
701 if (target_fd
>= 0) {
704 size
= filesize(src_fd
);
711 bytesread
= read(src_fd
, buffer
, buffersize
);
713 if (bytesread
== -1) {
720 while(bytesread
> 0) {
721 byteswritten
= write(target_fd
, buffer
, bytesread
);
723 if (byteswritten
< 0) {
729 bytesread
-= byteswritten
;
736 /* Copy failed. Cleanup. */
745 result
= rename(src
, target
) == 0;
746 #ifdef HAVE_MULTIVOLUME
748 if (errno
== EXDEV
) {
749 /* Failed because cross volume rename doesn't work. Copy
751 result
= clipboard_pastefile(src
, target
, true);
754 result
= remove(src
) == 0;
764 /* Paste a directory to a new location. Designed to be called by
766 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
767 int targetlen
, bool copy
)
770 int srcdirlen
= strlen(src
);
771 int targetdirlen
= strlen(target
);
774 if (!file_exists(target
)) {
776 /* Just move the directory */
777 result
= rename(src
, target
) == 0;
779 #ifdef HAVE_MULTIVOLUME
780 if (!result
&& errno
== EXDEV
) {
781 /* Try a copy as we're going across devices */
782 result
= clipboard_pastedirectory(src
, srclen
, target
,
785 /* If it worked, remove the source directory */
787 remove_dir(src
, srclen
);
793 /* Make a directory to copy things to */
794 result
= mkdir(target
) == 0;
798 /* Check if something went wrong already */
803 srcdir
= opendir(src
);
808 /* This loop will exit as soon as there's a problem */
811 struct dirent
* entry
;
812 /* walk through the directory content */
813 entry
= readdir(srcdir
);
817 /* append name to current directory */
818 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
819 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
822 DEBUGF("Copy %s to %s\n", src
, target
);
824 if (entry
->attribute
& ATTR_DIRECTORY
)
825 { /* copy/move a subdirectory */
826 if (!strcmp((char *)entry
->d_name
, ".") ||
827 !strcmp((char *)entry
->d_name
, ".."))
828 continue; /* skip these */
830 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
831 copy
); /* recursion */
834 { /* copy/move a file */
835 result
= clipboard_pastefile(src
, target
, copy
);
842 src
[srcdirlen
] = '\0'; /* terminate to original length */
843 target
[targetdirlen
] = '\0'; /* terminate to original length */
849 /* Paste the clipboard to the current directory */
850 static bool clipboard_paste(void)
852 char target
[MAX_PATH
];
856 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
857 static const struct text_message message
={lines
, 1};
859 /* Get the name of the current directory */
860 cwd
= getcwd(NULL
, 0);
862 /* Figure out the name of the selection */
863 nameptr
= strrchr(clipboard_selection
, '/');
865 /* Final target is current directory plus name of selection */
866 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
868 /* If the target existed but they choose not to overwite, exit */
869 if (file_exists(target
) &&
870 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
874 if (clipboard_is_copy
) {
875 splash(0, ID2P(LANG_COPYING
));
879 splash(0, ID2P(LANG_MOVING
));
882 /* Now figure out what we're doing */
884 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
885 /* Recursion. Set up external stack */
886 char srcpath
[MAX_PATH
];
887 char targetpath
[MAX_PATH
];
888 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
890 /* Do not allow the user to paste a directory into a dir they are
896 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
897 strlcpy(targetpath
, target
, sizeof(targetpath
));
899 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
900 target
, sizeof(targetpath
), clipboard_is_copy
);
902 if (success
&& !clipboard_is_copy
)
904 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
905 remove_dir(srcpath
, sizeof(srcpath
));
909 success
= clipboard_pastefile(clipboard_selection
, target
,
916 /* Reset everything */
917 clipboard_selection
[0] = 0;
918 clipboard_selection_attr
= 0;
919 clipboard_is_copy
= false;
921 /* Force reload of the current directory */
922 onplay_result
= ONPLAY_RELOAD_DIR
;
924 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
925 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_PASTE
),
932 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
934 static int set_rating_inline(void)
936 struct mp3entry
* id3
= audio_current_track();
937 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
939 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
940 NULL
, 1, 0, 10, NULL
, NULL
);
941 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
944 splash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
947 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
952 case ACTION_REQUEST_MENUITEM
:
953 if (!selected_file
|| !global_settings
.runtimedb
||
954 !tagcache_is_usable())
955 return ACTION_EXIT_MENUITEM
;
960 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
961 set_rating_inline
, NULL
,
962 ratingitem_callback
, Icon_Questionmark
);
965 static bool view_cue(void)
967 struct mp3entry
* id3
= audio_current_track();
968 if(id3
&& id3
->cuesheet
)
970 browse_cuesheet(id3
->cuesheet
);
974 static int view_cue_item_callback(int action
,
975 const struct menu_item_ex
*this_item
)
978 struct mp3entry
* id3
= audio_current_track();
981 case ACTION_REQUEST_MENUITEM
:
983 || !id3
|| !id3
->cuesheet
)
984 return ACTION_EXIT_MENUITEM
;
989 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
990 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
992 /* CONTEXT_WPS items */
993 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
994 browse_id3
, NULL
, NULL
, Icon_NOICON
);
995 #ifdef HAVE_PITCHSCREEN
996 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
997 gui_syncpitchscreen_run
, NULL
, NULL
, Icon_Audio
);
1000 /* CONTEXT_[TREE|ID3DB] items */
1001 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
1002 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
1003 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1004 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
1005 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
1006 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
1007 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
1008 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
1009 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
1010 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
1011 delete_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1012 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
1013 delete_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1014 MENUITEM_FUNCTION(properties_item
, 0, ID2P(LANG_PROPERTIES
),
1015 properties
, NULL
, clipboard_callback
, Icon_NOICON
);
1016 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
1017 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1018 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1019 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1021 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1022 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1024 #ifdef HAVE_RECORDING
1025 static bool set_recdir(void)
1027 strlcpy(global_settings
.rec_directory
,
1028 selected_file
, MAX_FILENAME
+1);
1032 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1033 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1035 static bool add_to_faves(void)
1037 if(PLUGIN_USB_CONNECTED
== filetype_load_plugin("shortcuts_append",
1039 onplay_result
= ONPLAY_RELOAD_DIR
;
1042 MENUITEM_FUNCTION(add_to_faves_item
, 0, ID2P(LANG_ADD_TO_FAVES
),
1043 add_to_faves
, NULL
, clipboard_callback
, Icon_NOICON
);
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
;
1058 if (context
== CONTEXT_ID3DB
)
1059 return ACTION_EXIT_MENUITEM
;
1060 if (this_item
== &clipboard_paste_item
)
1061 { /* visible if there is something to paste */
1062 return (clipboard_selection
[0] != 0) ?
1063 action
: ACTION_EXIT_MENUITEM
;
1065 else if (this_item
== &create_dir_item
)
1067 /* always visible */
1070 else if ((this_item
== &properties_item
) ||
1071 (this_item
== &rename_file_item
) ||
1072 (this_item
== &clipboard_cut_item
) ||
1073 (this_item
== &clipboard_copy_item
) ||
1074 (this_item
== &add_to_faves_item
)
1077 /* requires an actual file */
1078 return (selected_file
) ? action
: ACTION_EXIT_MENUITEM
;
1081 else if (this_item
== &set_backdrop_item
)
1085 char *suffix
= strrchr(selected_file
, '.');
1088 if (strcasecmp(suffix
, ".bmp") == 0)
1094 return ACTION_EXIT_MENUITEM
;
1097 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1099 if ((this_item
== &delete_dir_item
)
1102 #ifdef HAVE_RECORDING
1103 else if (this_item
== &set_recdir_item
)
1107 else if (selected_file
1108 #ifdef HAVE_MULTIVOLUME
1109 /* no rename+delete for volumes */
1110 && !(selected_file_attr
& ATTR_VOLUME
)
1114 if ((this_item
== &delete_file_item
) ||
1115 (this_item
== &list_viewers_item
))
1120 return ACTION_EXIT_MENUITEM
;
1125 /* used when onplay() is called in the CONTEXT_WPS context */
1128 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1129 onplaymenu_callback
, Icon_Audio
,
1130 &wps_playlist_menu
, &cat_playlist_menu
,
1131 &sound_settings
, &playback_settings
,
1132 #ifdef HAVE_TAGCACHE
1135 &bookmark_menu
, &browse_id3_item
, &list_viewers_item
,
1136 &delete_file_item
, &view_cue_item
,
1137 #ifdef HAVE_PITCHSCREEN
1141 /* used when onplay() is not called in the CONTEXT_WPS context */
1142 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1143 onplaymenu_callback
, Icon_file_view_menu
,
1144 &tree_playlist_menu
, &cat_playlist_menu
,
1145 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1146 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1150 &list_viewers_item
, &create_dir_item
, &properties_item
,
1151 #ifdef HAVE_RECORDING
1156 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1161 case ACTION_TREE_STOP
:
1162 if (this_item
== &wps_onplay_menu
)
1164 list_stop_handler();
1165 return ACTION_STD_CANCEL
;
1168 case ACTION_EXIT_MENUITEM
:
1169 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1174 int onplay(char* file
, int attr
, int from
)
1176 const struct menu_item_ex
*menu
;
1177 onplay_result
= ONPLAY_OK
;
1179 selected_file
= file
;
1180 selected_file_attr
= attr
;
1181 if (context
== CONTEXT_WPS
)
1182 menu
= &wps_onplay_menu
;
1184 menu
= &tree_onplay_menu
;
1185 switch (do_menu(menu
, NULL
, NULL
, false))
1188 return ONPLAY_START_PLAY
;
1190 case GO_TO_MAINMENU
:
1191 return ONPLAY_MAINMENU
;
1193 return context
== CONTEXT_WPS
? ONPLAY_OK
: ONPLAY_RELOAD_DIR
;