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 ****************************************************************************/
43 #include "playlist_viewer.h"
46 #include "filetypes.h"
52 #include "menus/exported_menus.h"
53 #ifdef HAVE_LCD_BITMAP
56 #include "sound_menu.h"
57 #include "playlist_menu.h"
58 #include "playlist_catalog.h"
63 #include "statusbar-skinned.h"
64 #include "pitchscreen.h"
68 static char* selected_file
= NULL
;
69 static int selected_file_attr
= 0;
70 static int onplay_result
= ONPLAY_OK
;
71 static char clipboard_selection
[MAX_PATH
];
72 static int clipboard_selection_attr
= 0;
73 static bool clipboard_is_copy
= false;
75 /* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */
76 #define MAKE_ONPLAYMENU( name, str, callback, icon, ... ) \
77 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
78 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
79 static const struct menu_item_ex name = \
80 {MT_MENU|MENU_HAS_DESC|MENU_EXITAFTERTHISMENU| \
81 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
82 { (void*)name##_},{.callback_and_desc = & name##__}};
84 /* ----------------------------------------------------------------------- */
85 /* Displays the bookmark menu options for the user to decide. This is an */
86 /* interface function. */
87 /* ----------------------------------------------------------------------- */
89 static int bookmark_menu_callback(int action
,
90 const struct menu_item_ex
*this_item
);
91 MENUITEM_FUNCTION(bookmark_create_menu_item
, 0,
92 ID2P(LANG_BOOKMARK_MENU_CREATE
),
93 bookmark_create_menu
, NULL
, NULL
, Icon_Bookmark
);
94 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
95 ID2P(LANG_BOOKMARK_MENU_LIST
),
96 bookmark_load_menu
, NULL
,
97 bookmark_menu_callback
, Icon_Bookmark
);
98 MAKE_ONPLAYMENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
),
99 bookmark_menu_callback
, Icon_Bookmark
,
100 &bookmark_create_menu_item
, &bookmark_load_menu_item
);
101 static int bookmark_menu_callback(int action
,
102 const struct menu_item_ex
*this_item
)
106 case ACTION_REQUEST_MENUITEM
:
107 if (this_item
== &bookmark_load_menu_item
)
109 if (bookmark_exist() == 0)
110 return ACTION_EXIT_MENUITEM
;
112 /* hide the bookmark menu if there is no playback */
113 else if ((audio_status() & AUDIO_STATUS_PLAY
) == 0)
114 return ACTION_EXIT_MENUITEM
;
116 #ifdef HAVE_LCD_CHARCELLS
117 case ACTION_ENTER_MENUITEM
:
118 status_set_param(true);
121 case ACTION_EXIT_MENUITEM
:
122 #ifdef HAVE_LCD_CHARCELLS
123 status_set_param(false);
131 /* CONTEXT_WPS playlist options */
132 static bool shuffle_playlist(void)
134 playlist_sort(NULL
, true);
135 playlist_randomise(NULL
, current_tick
, true);
139 static bool save_playlist(void)
141 save_playlist_screen(NULL
);
145 extern struct menu_item_ex view_cur_playlist
; /* from playlist_menu.c */
146 MENUITEM_FUNCTION(search_playlist_item
, 0, ID2P(LANG_SEARCH_IN_PLAYLIST
),
147 search_playlist
, NULL
, NULL
, Icon_Playlist
);
148 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
149 save_playlist
, NULL
, NULL
, Icon_Playlist
);
150 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
151 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
152 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
154 &view_cur_playlist
, &search_playlist_item
,
155 &playlist_save_item
, &reshuffle_item
158 /* CONTEXT_[TREE|ID3DB] playlist options */
159 static bool add_to_playlist(int position
, bool queue
)
161 bool new_playlist
= !(audio_status() & AUDIO_STATUS_PLAY
);
162 const char *lines
[] = {
163 ID2P(LANG_RECURSE_DIRECTORY_QUESTION
),
166 const struct text_message message
={lines
, 2};
168 splash(0, ID2P(LANG_WAIT
));
171 playlist_create(NULL
, NULL
);
173 /* always set seed before inserting shuffled */
174 if (position
== PLAYLIST_INSERT_SHUFFLED
||
175 position
== PLAYLIST_INSERT_LAST_SHUFFLED
)
178 if (position
== PLAYLIST_INSERT_LAST_SHUFFLED
)
179 playlist_set_last_shuffled_start();
183 if (context
== CONTEXT_ID3DB
)
185 tagtree_insert_selection_playlist(position
, queue
);
190 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_AUDIO
)
191 playlist_insert_track(NULL
, selected_file
, position
, queue
, true);
192 else if (selected_file_attr
& ATTR_DIRECTORY
)
194 bool recurse
= false;
196 if (global_settings
.recursive_dir_insert
!= RECURSE_ASK
)
197 recurse
= (bool)global_settings
.recursive_dir_insert
;
200 /* Ask if user wants to recurse directory */
201 recurse
= (gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
);
204 playlist_insert_directory(NULL
, selected_file
, position
, queue
,
207 else if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)
208 playlist_insert_playlist(NULL
, selected_file
, position
, queue
);
211 if (new_playlist
&& (playlist_amount() > 0))
213 /* nothing is currently playing so begin playing what we just
215 if (global_settings
.playlist_shuffle
)
216 playlist_shuffle(current_tick
, -1);
218 onplay_result
= ONPLAY_START_PLAY
;
224 static bool view_playlist(void)
226 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
229 result
= playlist_viewer_ex(selected_file
);
231 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
232 onplay_result
== ONPLAY_OK
)
233 /* playlist was started from viewer */
234 onplay_result
= ONPLAY_START_PLAY
;
239 static int playlist_insert_func(void *param
)
241 if (((intptr_t)param
== PLAYLIST_REPLACE
) && !warn_on_pl_erase())
243 add_to_playlist((intptr_t)param
, false);
247 static int playlist_queue_func(void *param
)
249 add_to_playlist((intptr_t)param
, true);
253 static int treeplaylist_wplayback_callback(int action
,
254 const struct menu_item_ex
* this_item
)
259 case ACTION_REQUEST_MENUITEM
:
260 if (audio_status() & AUDIO_STATUS_PLAY
)
263 return ACTION_EXIT_MENUITEM
;
269 static int treeplaylist_callback(int action
,
270 const struct menu_item_ex
*this_item
);
273 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
274 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
275 NULL
, Icon_Playlist
);
276 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
277 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
278 treeplaylist_wplayback_callback
, Icon_Playlist
);
279 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
280 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
281 treeplaylist_wplayback_callback
, Icon_Playlist
);
282 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
283 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
284 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
285 treeplaylist_callback
, Icon_Playlist
);
286 MENUITEM_FUNCTION(i_last_shuf_pl_item
, MENU_FUNC_USEPARAM
,
287 ID2P(LANG_INSERT_LAST_SHUFFLED
), playlist_insert_func
,
288 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED
,
289 treeplaylist_callback
, Icon_Playlist
);
291 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
292 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
293 treeplaylist_wplayback_callback
, Icon_Playlist
);
294 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
295 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
296 treeplaylist_wplayback_callback
, Icon_Playlist
);
297 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
298 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
299 treeplaylist_wplayback_callback
, Icon_Playlist
);
300 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
301 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
302 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
303 treeplaylist_wplayback_callback
, Icon_Playlist
);
304 MENUITEM_FUNCTION(q_last_shuf_pl_item
, MENU_FUNC_USEPARAM
,
305 ID2P(LANG_QUEUE_LAST_SHUFFLED
), playlist_queue_func
,
306 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED
,
307 treeplaylist_callback
, Icon_Playlist
);
308 /* replace playlist */
309 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
310 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
311 treeplaylist_wplayback_callback
, Icon_Playlist
);
314 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
316 treeplaylist_callback
, Icon_Playlist
);
318 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_PLAYLIST
),
319 treeplaylist_callback
, Icon_Playlist
,
325 &i_pl_item
, &i_first_pl_item
, &i_last_pl_item
,
326 &i_shuf_pl_item
, &i_last_shuf_pl_item
,
329 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
330 &q_shuf_pl_item
, &q_last_shuf_pl_item
,
335 static int treeplaylist_callback(int action
,
336 const struct menu_item_ex
*this_item
)
340 case ACTION_REQUEST_MENUITEM
:
341 if (this_item
== &tree_playlist_menu
)
343 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
345 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
346 (selected_file_attr
& ATTR_DIRECTORY
))
351 else if (this_item
== &view_playlist_item
)
353 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
354 context
== CONTEXT_TREE
)
359 else if (this_item
== &i_shuf_pl_item
)
361 if ((audio_status() & AUDIO_STATUS_PLAY
) ||
362 (selected_file_attr
& ATTR_DIRECTORY
) ||
363 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
))
368 else if (this_item
== &i_last_shuf_pl_item
||
369 this_item
== &q_last_shuf_pl_item
)
371 if ((playlist_amount() > 0) &&
372 (audio_status() & AUDIO_STATUS_PLAY
) &&
373 ((selected_file_attr
& ATTR_DIRECTORY
) ||
374 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)))
379 return ACTION_EXIT_MENUITEM
;
386 /* playlist catalog options */
387 static bool cat_add_to_a_playlist(void)
389 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
393 static bool cat_add_to_a_new_playlist(void)
395 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
399 static int cat_playlist_callback(int action
,
400 const struct menu_item_ex
*this_item
);
401 MENUITEM_FUNCTION(cat_view_lists
, 0, ID2P(LANG_CATALOG_VIEW
),
402 catalog_view_playlists
, 0,
403 cat_playlist_callback
, Icon_Playlist
);
404 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
405 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
406 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
407 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
408 MAKE_ONPLAYMENU(cat_playlist_menu
, ID2P(LANG_CATALOG
),
409 cat_playlist_callback
, Icon_Playlist
,
410 &cat_view_lists
, &cat_add_to_list
, &cat_add_to_new
);
412 static int cat_playlist_callback(int action
,
413 const struct menu_item_ex
*this_item
)
415 if (!selected_file
||
416 (((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
) &&
417 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_M3U
) &&
418 ((selected_file_attr
& ATTR_DIRECTORY
) == 0)))
420 return ACTION_EXIT_MENUITEM
;
423 if (context
== CONTEXT_ID3DB
&&
424 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
))
426 return ACTION_EXIT_MENUITEM
;
432 case ACTION_REQUEST_MENUITEM
:
433 if (this_item
== &cat_view_lists
)
437 else if ((audio_status() & AUDIO_STATUS_PLAY
) ||
438 context
!= CONTEXT_WPS
)
443 return ACTION_EXIT_MENUITEM
;
449 #ifdef HAVE_LCD_BITMAP
450 static void draw_slider(void)
456 int slider_height
= 2*screens
[i
].getcharheight();
457 viewport_set_defaults(&vp
, i
);
458 screens
[i
].set_viewport(&vp
);
459 show_busy_slider(&screens
[i
], 1, vp
.height
- slider_height
,
460 vp
.width
-2, slider_height
-1);
461 screens
[i
].update_viewport();
462 screens
[i
].set_viewport(NULL
);
466 #define draw_slider()
469 /* helper function to remove a non-empty directory */
470 static int remove_dir(char* dirname
, int len
)
474 int dirlen
= strlen(dirname
);
476 dir
= opendir(dirname
);
478 return -1; /* open error */
482 struct dirent
* entry
;
483 /* walk through the directory content */
484 entry
= readdir(dir
);
488 dirname
[dirlen
] ='\0';
489 /* inform the user which dir we're deleting */
492 /* append name to current directory */
493 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
494 if (entry
->attribute
& ATTR_DIRECTORY
)
495 { /* remove a subdirectory */
496 if (!strcmp((char *)entry
->d_name
, ".") ||
497 !strcmp((char *)entry
->d_name
, ".."))
498 continue; /* skip these */
500 result
= remove_dir(dirname
, len
); /* recursion */
502 break; /* or better continue, delete what we can? */
505 { /* remove a file */
507 result
= remove(dirname
);
509 if(ACTION_STD_CANCEL
== get_action(CONTEXT_STD
,TIMEOUT_NOBLOCK
))
511 splash(HZ
, ID2P(LANG_CANCEL
));
519 { /* remove the now empty directory */
520 dirname
[dirlen
] = '\0'; /* terminate to original length */
522 result
= rmdir(dirname
);
529 /* share code for file and directory deletion, saves space */
530 static bool delete_file_dir(void)
532 char file_to_delete
[MAX_PATH
];
533 strcpy(file_to_delete
, selected_file
);
535 const char *lines
[]={
536 ID2P(LANG_REALLY_DELETE
),
539 const char *yes_lines
[]={
544 const struct text_message message
={lines
, 2};
545 const struct text_message yes_message
={yes_lines
, 2};
547 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
550 splash(0, str(LANG_DELETING
));
553 if (selected_file_attr
& ATTR_DIRECTORY
) /* true if directory */
555 char pathname
[MAX_PATH
]; /* space to go deep */
557 strlcpy(pathname
, file_to_delete
, sizeof(pathname
));
558 res
= remove_dir(pathname
, sizeof(pathname
));
562 res
= remove(file_to_delete
);
565 onplay_result
= ONPLAY_RELOAD_DIR
;
570 static bool rename_file(void)
572 char newname
[MAX_PATH
];
573 char* ptr
= strrchr(selected_file
, '/') + 1;
574 int pathlen
= (ptr
- selected_file
);
575 strlcpy(newname
, selected_file
, sizeof(newname
));
576 if (!kbd_input(newname
+ pathlen
, (sizeof newname
)-pathlen
)) {
577 if (!strlen(newname
+ pathlen
) ||
578 (rename(selected_file
, newname
) < 0)) {
579 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
580 splashf(HZ
*2, "%s %s", str(LANG_RENAME
), str(LANG_FAILED
));
583 onplay_result
= ONPLAY_RELOAD_DIR
;
589 static bool create_dir(void)
591 char dirname
[MAX_PATH
];
596 cwd
= getcwd(NULL
, 0);
597 memset(dirname
, 0, sizeof dirname
);
599 snprintf(dirname
, sizeof dirname
, "%s/", cwd
[1] ? cwd
: "");
601 pathlen
= strlen(dirname
);
602 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
608 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
609 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_CREATE_DIR
),
612 onplay_result
= ONPLAY_RELOAD_DIR
;
618 /* Store the current selection in the clipboard */
619 static bool clipboard_clip(bool copy
)
621 clipboard_selection
[0] = 0;
622 strlcpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
623 clipboard_selection_attr
= selected_file_attr
;
624 clipboard_is_copy
= copy
;
629 static bool clipboard_cut(void)
631 return clipboard_clip(false);
634 static bool clipboard_copy(void)
636 return clipboard_clip(true);
639 /* Paste a file to a new directory. Will overwrite always. */
640 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
642 int src_fd
, target_fd
;
644 ssize_t size
, bytesread
, byteswritten
;
649 /* See if we can get the plugin buffer for the file copy buffer */
650 buffer
= (char *) plugin_get_buffer(&buffersize
);
651 if (buffer
== NULL
|| buffersize
< 512) {
652 /* Not large enough, try for a disk sector worth of stack
655 buffer
= (char *) __builtin_alloca(buffersize
);
658 if (buffer
== NULL
) {
662 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
665 src_fd
= open(src
, O_RDONLY
);
668 target_fd
= creat(target
, 0666);
670 if (target_fd
>= 0) {
673 size
= filesize(src_fd
);
680 bytesread
= read(src_fd
, buffer
, buffersize
);
682 if (bytesread
== -1) {
689 while(bytesread
> 0) {
690 byteswritten
= write(target_fd
, buffer
, bytesread
);
692 if (byteswritten
< 0) {
698 bytesread
-= byteswritten
;
705 /* Copy failed. Cleanup. */
714 result
= rename(src
, target
) == 0;
715 #ifdef HAVE_MULTIVOLUME
717 if (errno
== EXDEV
) {
718 /* Failed because cross volume rename doesn't work. Copy
720 result
= clipboard_pastefile(src
, target
, true);
723 result
= remove(src
) == 0;
733 /* Paste a directory to a new location. Designed to be called by
735 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
736 int targetlen
, bool copy
)
739 int srcdirlen
= strlen(src
);
740 int targetdirlen
= strlen(target
);
743 if (!file_exists(target
)) {
745 /* Just move the directory */
746 result
= rename(src
, target
) == 0;
748 #ifdef HAVE_MULTIVOLUME
749 if (!result
&& errno
== EXDEV
) {
750 /* Try a copy as we're going across devices */
751 result
= clipboard_pastedirectory(src
, srclen
, target
,
754 /* If it worked, remove the source directory */
756 remove_dir(src
, srclen
);
762 /* Make a directory to copy things to */
763 result
= mkdir(target
) == 0;
767 /* Check if something went wrong already */
772 srcdir
= opendir(src
);
777 /* This loop will exit as soon as there's a problem */
780 struct dirent
* entry
;
781 /* walk through the directory content */
782 entry
= readdir(srcdir
);
786 /* append name to current directory */
787 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
788 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
791 DEBUGF("Copy %s to %s\n", src
, target
);
793 if (entry
->attribute
& ATTR_DIRECTORY
)
794 { /* copy/move a subdirectory */
795 if (!strcmp((char *)entry
->d_name
, ".") ||
796 !strcmp((char *)entry
->d_name
, ".."))
797 continue; /* skip these */
799 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
800 copy
); /* recursion */
803 { /* copy/move a file */
805 result
= clipboard_pastefile(src
, target
, copy
);
812 src
[srcdirlen
] = '\0'; /* terminate to original length */
813 target
[targetdirlen
] = '\0'; /* terminate to original length */
819 /* Paste the clipboard to the current directory */
820 static bool clipboard_paste(void)
822 char target
[MAX_PATH
];
826 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
827 static const struct text_message message
={lines
, 1};
829 /* Get the name of the current directory */
830 cwd
= getcwd(NULL
, 0);
832 /* Figure out the name of the selection */
833 nameptr
= strrchr(clipboard_selection
, '/');
835 /* Final target is current directory plus name of selection */
836 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
838 /* If the target existed but they choose not to overwite, exit */
839 if (file_exists(target
) &&
840 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
844 if (clipboard_is_copy
) {
845 splash(0, ID2P(LANG_COPYING
));
849 splash(0, ID2P(LANG_MOVING
));
852 /* Now figure out what we're doing */
854 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
855 /* Recursion. Set up external stack */
856 char srcpath
[MAX_PATH
];
857 char targetpath
[MAX_PATH
];
858 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
860 /* Do not allow the user to paste a directory into a dir they are
866 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
867 strlcpy(targetpath
, target
, sizeof(targetpath
));
869 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
870 target
, sizeof(targetpath
), clipboard_is_copy
);
872 if (success
&& !clipboard_is_copy
)
874 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
875 remove_dir(srcpath
, sizeof(srcpath
));
879 success
= clipboard_pastefile(clipboard_selection
, target
,
886 /* Reset everything */
887 clipboard_selection
[0] = 0;
888 clipboard_selection_attr
= 0;
889 clipboard_is_copy
= false;
891 /* Force reload of the current directory */
892 onplay_result
= ONPLAY_RELOAD_DIR
;
894 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
895 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_PASTE
),
903 static int set_rating_inline(void)
905 struct mp3entry
* id3
= audio_current_track();
906 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
908 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
909 NULL
, 1, 0, 10, NULL
, NULL
);
910 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
913 splash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
916 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
921 case ACTION_REQUEST_MENUITEM
:
922 if (!selected_file
|| !global_settings
.runtimedb
||
923 !tagcache_is_usable())
924 return ACTION_EXIT_MENUITEM
;
929 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
930 set_rating_inline
, NULL
,
931 ratingitem_callback
, Icon_Questionmark
);
934 static bool view_cue(void)
936 struct mp3entry
* id3
= audio_current_track();
937 if(id3
&& id3
->cuesheet
)
939 browse_cuesheet(id3
->cuesheet
);
943 static int view_cue_item_callback(int action
,
944 const struct menu_item_ex
*this_item
)
947 struct mp3entry
* id3
= audio_current_track();
950 case ACTION_REQUEST_MENUITEM
:
952 || !id3
|| !id3
->cuesheet
)
953 return ACTION_EXIT_MENUITEM
;
958 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
959 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
961 /* CONTEXT_WPS items */
962 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
963 browse_id3
, NULL
, NULL
, Icon_NOICON
);
964 #ifdef HAVE_PITCHSCREEN
965 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
966 gui_syncpitchscreen_run
, NULL
, NULL
, Icon_Audio
);
969 /* CONTEXT_[TREE|ID3DB] items */
970 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
971 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
972 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
973 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
974 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
975 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
976 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
977 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
978 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
979 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
980 delete_file_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
981 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
982 delete_file_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
983 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
984 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
987 static bool list_viewers(void)
989 int ret
= filetype_list_viewers(selected_file
);
990 if (ret
== PLUGIN_USB_CONNECTED
)
991 onplay_result
= ONPLAY_RELOAD_DIR
;
995 static bool onplay_load_plugin(void *param
)
997 int ret
= filetype_load_plugin((const char*)param
, selected_file
);
998 if (ret
== PLUGIN_USB_CONNECTED
)
999 onplay_result
= ONPLAY_RELOAD_DIR
;
1003 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1004 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1005 MENUITEM_FUNCTION(properties_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_PROPERTIES
),
1006 onplay_load_plugin
, (void *)"properties",
1007 clipboard_callback
, Icon_NOICON
);
1008 MENUITEM_FUNCTION(add_to_faves_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_ADD_TO_FAVES
),
1009 onplay_load_plugin
, (void *)"shortcuts_append",
1010 clipboard_callback
, Icon_NOICON
);
1013 static bool set_backdrop(void)
1015 /* load the image */
1016 if(sb_set_backdrop(SCREEN_MAIN
, selected_file
)) {
1017 splash(HZ
, str(LANG_BACKDROP_LOADED
));
1018 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
1022 splash(HZ
, str(LANG_BACKDROP_FAILED
));
1027 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1028 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1030 #ifdef HAVE_RECORDING
1031 static bool set_recdir(void)
1033 strlcpy(global_settings
.rec_directory
, selected_file
, MAX_FILENAME
+1);
1037 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1038 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1041 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1045 case ACTION_REQUEST_MENUITEM
:
1046 #ifdef HAVE_MULTIVOLUME
1047 if ((selected_file_attr
& FAT_ATTR_VOLUME
) &&
1048 (this_item
== &rename_file_item
||
1049 this_item
== &delete_dir_item
||
1050 this_item
== &clipboard_cut_item
) )
1051 return ACTION_EXIT_MENUITEM
;
1052 /* no rename+delete for volumes */
1053 if ((selected_file_attr
& ATTR_VOLUME
) &&
1054 (this_item
== &delete_file_item
||
1055 this_item
== &list_viewers_item
))
1056 return ACTION_EXIT_MENUITEM
;
1058 #ifdef HAVE_TAGCACHE
1059 if (context
== CONTEXT_ID3DB
)
1061 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
1063 this_item
== &properties_item
)
1065 return ACTION_EXIT_MENUITEM
;
1068 if (this_item
== &clipboard_paste_item
)
1069 { /* visible if there is something to paste */
1070 return (clipboard_selection
[0] != 0) ?
1071 action
: ACTION_EXIT_MENUITEM
;
1073 else if (this_item
== &create_dir_item
)
1075 /* always visible */
1078 else if (selected_file
)
1080 /* requires an actual file */
1081 if (this_item
== &rename_file_item
||
1082 this_item
== &clipboard_cut_item
||
1083 this_item
== &clipboard_copy_item
||
1084 this_item
== &properties_item
||
1085 this_item
== &add_to_faves_item
)
1089 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1091 /* only for directories */
1092 if (this_item
== &delete_dir_item
1093 #ifdef HAVE_RECORDING
1094 || this_item
== &set_recdir_item
1099 else if (this_item
== &delete_file_item
||
1100 this_item
== &list_viewers_item
)
1102 /* only for files */
1106 else if (this_item
== &set_backdrop_item
)
1108 char *suffix
= strrchr(selected_file
, '.');
1111 if (strcasecmp(suffix
, ".bmp") == 0)
1119 return ACTION_EXIT_MENUITEM
;
1125 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
1126 /* used when onplay() is called in the CONTEXT_WPS context */
1127 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1128 onplaymenu_callback
, Icon_Audio
,
1129 &wps_playlist_menu
, &cat_playlist_menu
,
1130 &sound_settings
, &playback_settings
,
1131 #ifdef HAVE_TAGCACHE
1134 &bookmark_menu
, &browse_id3_item
, &list_viewers_item
,
1135 &delete_file_item
, &view_cue_item
,
1136 #ifdef HAVE_PITCHSCREEN
1140 /* used when onplay() is not called in the CONTEXT_WPS context */
1141 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1142 onplaymenu_callback
, Icon_file_view_menu
,
1143 &tree_playlist_menu
, &cat_playlist_menu
,
1144 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1145 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1149 &list_viewers_item
, &create_dir_item
, &properties_item
,
1150 #ifdef HAVE_RECORDING
1155 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1159 case ACTION_TREE_STOP
:
1160 if (this_item
== &wps_onplay_menu
)
1162 list_stop_handler();
1163 return ACTION_STD_CANCEL
;
1166 case ACTION_EXIT_MENUITEM
:
1167 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1174 /* direct function calls, no need for menu callbacks */
1175 static bool delete_item(void)
1177 #ifdef HAVE_MULTIVOLUME
1178 /* no delete for volumes */
1179 if ((selected_file_attr
& FAT_ATTR_VOLUME
) ||
1180 (selected_file_attr
& ATTR_VOLUME
))
1183 return delete_file_dir();
1186 static bool open_with(void)
1188 /* only open files */
1189 if (selected_file_attr
& ATTR_DIRECTORY
)
1191 #ifdef HAVE_MULTIVOLUME
1192 if (selected_file_attr
& ATTR_VOLUME
)
1195 return list_viewers();
1198 #define HOTKEY_ACTION_MASK 0x0FF /* Mask to apply to get the action (enum) */
1199 #define HOTKEY_CTX_WPS 0x100 /* Mask to apply to check whether it's for WPS */
1200 #define HOTKEY_CTX_TREE 0x200 /* Mask to apply to check whether it's for the tree */
1202 struct hotkey_assignment
{
1203 int item
; /* Bit or'd hotkey_action and HOTKEY_CTX_x */
1204 struct menu_func func
; /* Function to run if this entry is selected */
1205 int return_code
; /* What to return after the function is run */
1206 int lang_id
; /* Language ID */
1209 #define HOTKEY_FUNC(func, param) {{(void *)func}, param}
1211 /* Any desired hotkey functions go here, in the enum in onplay.h,
1212 and in the settings menu in settings_list.c. The order here
1213 is not important. */
1214 static struct hotkey_assignment hotkey_items
[] = {
1215 { HOTKEY_VIEW_PLAYLIST
| HOTKEY_CTX_WPS
,
1216 HOTKEY_FUNC(NULL
, NULL
),
1217 ONPLAY_PLAYLIST
, LANG_VIEW_DYNAMIC_PLAYLIST
},
1218 { HOTKEY_SHOW_TRACK_INFO
| HOTKEY_CTX_WPS
,
1219 HOTKEY_FUNC(browse_id3
, NULL
),
1220 ONPLAY_RELOAD_DIR
, LANG_MENU_SHOW_ID3_INFO
},
1221 #ifdef HAVE_PITCHSCREEN
1222 { HOTKEY_PITCHSCREEN
| HOTKEY_CTX_WPS
,
1223 HOTKEY_FUNC(gui_syncpitchscreen_run
, NULL
),
1224 ONPLAY_RELOAD_DIR
, LANG_PITCH
},
1226 { HOTKEY_OPEN_WITH
| HOTKEY_CTX_WPS
| HOTKEY_CTX_TREE
,
1227 HOTKEY_FUNC(open_with
, NULL
),
1228 ONPLAY_RELOAD_DIR
, LANG_ONPLAY_OPEN_WITH
},
1229 { HOTKEY_DELETE
| HOTKEY_CTX_WPS
| HOTKEY_CTX_TREE
,
1230 HOTKEY_FUNC(delete_item
, NULL
),
1231 ONPLAY_RELOAD_DIR
, LANG_DELETE
},
1232 { HOTKEY_DELETE
| HOTKEY_CTX_TREE
,
1233 HOTKEY_FUNC(delete_item
, NULL
),
1234 ONPLAY_RELOAD_DIR
, LANG_DELETE
},
1235 { HOTKEY_INSERT
| HOTKEY_CTX_TREE
,
1236 HOTKEY_FUNC(playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
),
1237 ONPLAY_START_PLAY
, LANG_INSERT
},
1240 static const int num_hotkey_items
= sizeof(hotkey_items
) / sizeof(hotkey_items
[0]);
1242 /* Return the language ID for the input function */
1243 int get_hotkey_lang_id(int hk_func
)
1246 for (i
= 0; i
< num_hotkey_items
; i
++)
1248 if ((hotkey_items
[i
].item
& HOTKEY_ACTION_MASK
) == hk_func
)
1249 return hotkey_items
[i
].lang_id
;
1255 /* Execute the hotkey function, if listed for this screen */
1256 static int execute_hotkey(bool is_wps
)
1259 struct hotkey_assignment
*this_item
;
1260 const int context
= is_wps
? HOTKEY_CTX_WPS
: HOTKEY_CTX_TREE
;
1261 const int this_hotkey
= (is_wps
? global_settings
.hotkey_wps
:
1262 global_settings
.hotkey_tree
);
1264 /* search assignment struct for a match for the hotkey setting */
1265 for (i
= 0; i
< num_hotkey_items
; i
++)
1267 this_item
= &hotkey_items
[i
];
1268 if ((this_item
->item
& context
) &&
1269 ((this_item
->item
& HOTKEY_ACTION_MASK
) == this_hotkey
))
1271 /* run the associated function (with optional param), if any */
1272 const struct menu_func func
= this_item
->func
;
1273 if (func
.function
!= NULL
)
1275 if (func
.param
!= NULL
)
1276 (*func
.function_w_param
)(func
.param
);
1280 /* return with the associated code */
1281 return this_item
->return_code
;
1285 /* no valid hotkey set, ignore hotkey */
1286 return ONPLAY_RELOAD_DIR
;
1290 int onplay(char* file
, int attr
, int from
, bool hotkey
)
1292 const struct menu_item_ex
*menu
;
1293 onplay_result
= ONPLAY_OK
;
1295 selected_file
= file
;
1296 selected_file_attr
= attr
;
1300 return execute_hotkey(context
== CONTEXT_WPS
);
1304 if (context
== CONTEXT_WPS
)
1305 menu
= &wps_onplay_menu
;
1307 menu
= &tree_onplay_menu
;
1308 menu_selection
= do_menu(menu
, NULL
, NULL
, false);
1309 switch (menu_selection
)
1312 return ONPLAY_START_PLAY
;
1314 case GO_TO_MAINMENU
:
1315 return ONPLAY_MAINMENU
;
1316 case GO_TO_PLAYLIST_VIEWER
:
1317 return ONPLAY_PLAYLIST
;
1319 return onplay_result
;