1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
44 #include "playlist_viewer.h"
47 #include "filetypes.h"
53 #include "menus/exported_menus.h"
54 #ifdef HAVE_LCD_BITMAP
57 #include "sound_menu.h"
58 #include "playlist_menu.h"
59 #include "playlist_catalog.h"
64 #include "statusbar-skinned.h"
65 #include "pitchscreen.h"
69 static char* selected_file
= NULL
;
70 static int selected_file_attr
= 0;
71 static int onplay_result
= ONPLAY_OK
;
72 static char clipboard_selection
[MAX_PATH
];
73 static int clipboard_selection_attr
= 0;
74 static bool clipboard_is_copy
= false;
76 /* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */
77 #define MAKE_ONPLAYMENU( name, str, callback, icon, ... ) \
78 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
79 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
80 static const struct menu_item_ex name = \
81 {MT_MENU|MENU_HAS_DESC|MENU_EXITAFTERTHISMENU| \
82 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
83 { (void*)name##_},{.callback_and_desc = & name##__}};
85 /* ----------------------------------------------------------------------- */
86 /* Displays the bookmark menu options for the user to decide. This is an */
87 /* interface function. */
88 /* ----------------------------------------------------------------------- */
90 static int bookmark_menu_callback(int action
,
91 const struct menu_item_ex
*this_item
);
92 MENUITEM_FUNCTION(bookmark_create_menu_item
, 0,
93 ID2P(LANG_BOOKMARK_MENU_CREATE
),
94 bookmark_create_menu
, NULL
, NULL
, Icon_Bookmark
);
95 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
96 ID2P(LANG_BOOKMARK_MENU_LIST
),
97 bookmark_load_menu
, NULL
,
98 bookmark_menu_callback
, Icon_Bookmark
);
99 MAKE_ONPLAYMENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
),
100 bookmark_menu_callback
, Icon_Bookmark
,
101 &bookmark_create_menu_item
, &bookmark_load_menu_item
);
102 static int bookmark_menu_callback(int action
,
103 const struct menu_item_ex
*this_item
)
107 case ACTION_REQUEST_MENUITEM
:
108 if (this_item
== &bookmark_load_menu_item
)
110 if (bookmark_exist() == 0)
111 return ACTION_EXIT_MENUITEM
;
113 /* hide the bookmark menu if there is no playback */
114 else if ((audio_status() & AUDIO_STATUS_PLAY
) == 0)
115 return ACTION_EXIT_MENUITEM
;
117 #ifdef HAVE_LCD_CHARCELLS
118 case ACTION_ENTER_MENUITEM
:
119 status_set_param(true);
122 case ACTION_EXIT_MENUITEM
:
123 #ifdef HAVE_LCD_CHARCELLS
124 status_set_param(false);
132 /* CONTEXT_WPS playlist options */
133 static bool shuffle_playlist(void)
135 playlist_sort(NULL
, true);
136 playlist_randomise(NULL
, current_tick
, true);
141 static bool save_playlist(void)
143 save_playlist_screen(NULL
);
147 MENUITEM_FUNCTION(playlist_viewer_item
, 0, ID2P(LANG_VIEW_DYNAMIC_PLAYLIST
),
148 playlist_viewer
, NULL
, NULL
, Icon_Playlist
);
149 MENUITEM_FUNCTION(search_playlist_item
, 0, ID2P(LANG_SEARCH_IN_PLAYLIST
),
150 search_playlist
, NULL
, NULL
, Icon_Playlist
);
151 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
152 save_playlist
, NULL
, NULL
, Icon_Playlist
);
153 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
154 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
155 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
157 &playlist_viewer_item
, &search_playlist_item
,
158 &playlist_save_item
, &reshuffle_item
161 /* CONTEXT_[TREE|ID3DB] playlist options */
162 static bool add_to_playlist(int position
, bool queue
)
164 bool new_playlist
= !(audio_status() & AUDIO_STATUS_PLAY
);
165 const char *lines
[] = {
166 ID2P(LANG_RECURSE_DIRECTORY_QUESTION
),
169 const struct text_message message
={lines
, 2};
171 splash(0, ID2P(LANG_WAIT
));
174 playlist_create(NULL
, NULL
);
176 /* always set seed before inserting shuffled */
177 if (position
== PLAYLIST_INSERT_SHUFFLED
||
178 position
== PLAYLIST_INSERT_LAST_SHUFFLED
)
181 if (position
== PLAYLIST_INSERT_LAST_SHUFFLED
)
182 playlist_set_last_shuffled_start();
186 if (context
== CONTEXT_ID3DB
)
188 tagtree_insert_selection_playlist(position
, queue
);
193 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_AUDIO
)
194 playlist_insert_track(NULL
, selected_file
, position
, queue
, true);
195 else if (selected_file_attr
& ATTR_DIRECTORY
)
197 bool recurse
= false;
199 if (global_settings
.recursive_dir_insert
!= RECURSE_ASK
)
200 recurse
= (bool)global_settings
.recursive_dir_insert
;
203 /* Ask if user wants to recurse directory */
204 recurse
= (gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
);
207 playlist_insert_directory(NULL
, selected_file
, position
, queue
,
210 else if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)
211 playlist_insert_playlist(NULL
, selected_file
, position
, queue
);
214 if (new_playlist
&& (playlist_amount() > 0))
216 /* nothing is currently playing so begin playing what we just
218 if (global_settings
.playlist_shuffle
)
219 playlist_shuffle(current_tick
, -1);
221 onplay_result
= ONPLAY_START_PLAY
;
227 static bool view_playlist(void)
229 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
232 result
= playlist_viewer_ex(selected_file
);
234 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
235 onplay_result
== ONPLAY_OK
)
236 /* playlist was started from viewer */
237 onplay_result
= ONPLAY_START_PLAY
;
242 static int playlist_insert_func(void *param
)
244 if (((intptr_t)param
== PLAYLIST_REPLACE
) && !warn_on_pl_erase())
246 add_to_playlist((intptr_t)param
, false);
250 static int playlist_queue_func(void *param
)
252 add_to_playlist((intptr_t)param
, true);
256 static int treeplaylist_wplayback_callback(int action
,
257 const struct menu_item_ex
* this_item
)
262 case ACTION_REQUEST_MENUITEM
:
263 if (audio_status() & AUDIO_STATUS_PLAY
)
266 return ACTION_EXIT_MENUITEM
;
272 static int treeplaylist_callback(int action
,
273 const struct menu_item_ex
*this_item
);
276 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
277 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
278 NULL
, Icon_Playlist
);
279 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
280 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
281 treeplaylist_wplayback_callback
, Icon_Playlist
);
282 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
283 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
284 treeplaylist_wplayback_callback
, Icon_Playlist
);
285 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
286 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
287 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
288 treeplaylist_callback
, Icon_Playlist
);
289 MENUITEM_FUNCTION(i_last_shuf_pl_item
, MENU_FUNC_USEPARAM
,
290 ID2P(LANG_INSERT_LAST_SHUFFLED
), playlist_insert_func
,
291 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED
,
292 treeplaylist_callback
, Icon_Playlist
);
294 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
295 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
296 treeplaylist_wplayback_callback
, Icon_Playlist
);
297 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
298 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
299 treeplaylist_wplayback_callback
, Icon_Playlist
);
300 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
301 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
302 treeplaylist_wplayback_callback
, Icon_Playlist
);
303 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
304 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
305 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
306 treeplaylist_wplayback_callback
, Icon_Playlist
);
307 MENUITEM_FUNCTION(q_last_shuf_pl_item
, MENU_FUNC_USEPARAM
,
308 ID2P(LANG_QUEUE_LAST_SHUFFLED
), playlist_queue_func
,
309 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED
,
310 treeplaylist_callback
, Icon_Playlist
);
311 /* replace playlist */
312 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
313 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
314 treeplaylist_wplayback_callback
, Icon_Playlist
);
317 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
319 treeplaylist_callback
, Icon_Playlist
);
321 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_PLAYLIST
),
322 treeplaylist_callback
, Icon_Playlist
,
328 &i_pl_item
, &i_first_pl_item
, &i_last_pl_item
,
329 &i_shuf_pl_item
, &i_last_shuf_pl_item
,
332 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
333 &q_shuf_pl_item
, &q_last_shuf_pl_item
,
338 static int treeplaylist_callback(int action
,
339 const struct menu_item_ex
*this_item
)
343 case ACTION_REQUEST_MENUITEM
:
344 if (this_item
== &tree_playlist_menu
)
346 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
348 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
349 (selected_file_attr
& ATTR_DIRECTORY
))
354 else if (this_item
== &view_playlist_item
)
356 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
357 context
== CONTEXT_TREE
)
362 else if (this_item
== &i_shuf_pl_item
)
364 if ((audio_status() & AUDIO_STATUS_PLAY
) ||
365 (selected_file_attr
& ATTR_DIRECTORY
) ||
366 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
))
371 else if (this_item
== &i_last_shuf_pl_item
||
372 this_item
== &q_last_shuf_pl_item
)
374 if ((playlist_amount() > 0) &&
375 (audio_status() & AUDIO_STATUS_PLAY
) &&
376 ((selected_file_attr
& ATTR_DIRECTORY
) ||
377 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)))
382 return ACTION_EXIT_MENUITEM
;
389 /* playlist catalog options */
390 static bool cat_add_to_a_playlist(void)
392 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
396 static bool cat_add_to_a_new_playlist(void)
398 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
402 static int cat_playlist_callback(int action
,
403 const struct menu_item_ex
*this_item
);
404 MENUITEM_FUNCTION(cat_view_lists
, 0, ID2P(LANG_CATALOG_VIEW
),
405 catalog_view_playlists
, 0,
406 cat_playlist_callback
, Icon_Playlist
);
407 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
408 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
409 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
410 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
411 MAKE_ONPLAYMENU(cat_playlist_menu
, ID2P(LANG_CATALOG
),
412 cat_playlist_callback
, Icon_Playlist
,
413 &cat_view_lists
, &cat_add_to_list
, &cat_add_to_new
);
415 static int cat_playlist_callback(int action
,
416 const struct menu_item_ex
*this_item
)
418 if (!selected_file
||
419 (((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
) &&
420 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_M3U
) &&
421 ((selected_file_attr
& ATTR_DIRECTORY
) == 0)))
423 return ACTION_EXIT_MENUITEM
;
428 case ACTION_REQUEST_MENUITEM
:
429 if (this_item
== &cat_view_lists
)
433 else if (((audio_status() & AUDIO_STATUS_PLAY
&&
434 context
== CONTEXT_WPS
) ||
435 context
== CONTEXT_TREE
))
440 return ACTION_EXIT_MENUITEM
;
446 #ifdef HAVE_LCD_BITMAP
447 static void draw_slider(void)
453 int slider_height
= 2*screens
[i
].getcharheight();
454 viewport_set_defaults(&vp
, i
);
455 screens
[i
].set_viewport(&vp
);
456 show_busy_slider(&screens
[i
], 1, vp
.height
- slider_height
,
457 vp
.width
-2, slider_height
-1);
458 screens
[i
].update_viewport();
459 screens
[i
].set_viewport(NULL
);
463 #define draw_slider()
466 /* helper function to remove a non-empty directory */
467 static int remove_dir(char* dirname
, int len
)
471 int dirlen
= strlen(dirname
);
473 dir
= opendir(dirname
);
475 return -1; /* open error */
479 struct dirent
* entry
;
480 /* walk through the directory content */
481 entry
= readdir(dir
);
485 dirname
[dirlen
] ='\0';
486 /* inform the user which dir we're deleting */
489 /* append name to current directory */
490 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
491 if (entry
->attribute
& ATTR_DIRECTORY
)
492 { /* remove a subdirectory */
493 if (!strcmp((char *)entry
->d_name
, ".") ||
494 !strcmp((char *)entry
->d_name
, ".."))
495 continue; /* skip these */
497 result
= remove_dir(dirname
, len
); /* recursion */
499 break; /* or better continue, delete what we can? */
502 { /* remove a file */
504 result
= remove(dirname
);
506 if(ACTION_STD_CANCEL
== get_action(CONTEXT_STD
,TIMEOUT_NOBLOCK
))
508 splash(HZ
, ID2P(LANG_CANCEL
));
516 { /* remove the now empty directory */
517 dirname
[dirlen
] = '\0'; /* terminate to original length */
519 result
= rmdir(dirname
);
526 /* share code for file and directory deletion, saves space */
527 static bool delete_handler(bool is_dir
)
529 char file_to_delete
[MAX_PATH
];
530 strcpy(file_to_delete
, selected_file
);
532 const char *lines
[]={
533 ID2P(LANG_REALLY_DELETE
),
536 const char *yes_lines
[]={
541 const struct text_message message
={lines
, 2};
542 const struct text_message yes_message
={yes_lines
, 2};
544 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
547 splash(0, str(LANG_DELETING
));
552 char pathname
[MAX_PATH
]; /* space to go deep */
554 strlcpy(pathname
, file_to_delete
, sizeof(pathname
));
555 res
= remove_dir(pathname
, sizeof(pathname
));
559 res
= remove(file_to_delete
);
562 onplay_result
= ONPLAY_RELOAD_DIR
;
567 static bool delete_file(void)
569 return delete_handler(false);
572 static bool delete_dir(void)
574 return delete_handler(true);
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/", cwd
[1] ? cwd
: "");
608 pathlen
= strlen(dirname
);
609 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
615 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
616 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_CREATE_DIR
),
619 onplay_result
= ONPLAY_RELOAD_DIR
;
625 /* Store the current selection in the clipboard */
626 static bool clipboard_clip(bool copy
)
628 clipboard_selection
[0] = 0;
629 strlcpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
630 clipboard_selection_attr
= selected_file_attr
;
631 clipboard_is_copy
= copy
;
636 static bool clipboard_cut(void)
638 return clipboard_clip(false);
641 static bool clipboard_copy(void)
643 return clipboard_clip(true);
646 /* Paste a file to a new directory. Will overwrite always. */
647 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
649 int src_fd
, target_fd
;
651 ssize_t size
, bytesread
, byteswritten
;
656 /* See if we can get the plugin buffer for the file copy buffer */
657 buffer
= (char *) plugin_get_buffer(&buffersize
);
658 if (buffer
== NULL
|| buffersize
< 512) {
659 /* Not large enough, try for a disk sector worth of stack
662 buffer
= (char *) __builtin_alloca(buffersize
);
665 if (buffer
== NULL
) {
669 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
672 src_fd
= open(src
, O_RDONLY
);
675 target_fd
= creat(target
);
677 if (target_fd
>= 0) {
680 size
= filesize(src_fd
);
687 bytesread
= read(src_fd
, buffer
, buffersize
);
689 if (bytesread
== -1) {
696 while(bytesread
> 0) {
697 byteswritten
= write(target_fd
, buffer
, bytesread
);
699 if (byteswritten
< 0) {
705 bytesread
-= byteswritten
;
712 /* Copy failed. Cleanup. */
721 result
= rename(src
, target
) == 0;
722 #ifdef HAVE_MULTIVOLUME
724 if (errno
== EXDEV
) {
725 /* Failed because cross volume rename doesn't work. Copy
727 result
= clipboard_pastefile(src
, target
, true);
730 result
= remove(src
) == 0;
740 /* Paste a directory to a new location. Designed to be called by
742 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
743 int targetlen
, bool copy
)
746 int srcdirlen
= strlen(src
);
747 int targetdirlen
= strlen(target
);
750 if (!file_exists(target
)) {
752 /* Just move the directory */
753 result
= rename(src
, target
) == 0;
755 #ifdef HAVE_MULTIVOLUME
756 if (!result
&& errno
== EXDEV
) {
757 /* Try a copy as we're going across devices */
758 result
= clipboard_pastedirectory(src
, srclen
, target
,
761 /* If it worked, remove the source directory */
763 remove_dir(src
, srclen
);
769 /* Make a directory to copy things to */
770 result
= mkdir(target
) == 0;
774 /* Check if something went wrong already */
779 srcdir
= opendir(src
);
784 /* This loop will exit as soon as there's a problem */
787 struct dirent
* entry
;
788 /* walk through the directory content */
789 entry
= readdir(srcdir
);
793 /* append name to current directory */
794 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
795 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
798 DEBUGF("Copy %s to %s\n", src
, target
);
800 if (entry
->attribute
& ATTR_DIRECTORY
)
801 { /* copy/move a subdirectory */
802 if (!strcmp((char *)entry
->d_name
, ".") ||
803 !strcmp((char *)entry
->d_name
, ".."))
804 continue; /* skip these */
806 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
807 copy
); /* recursion */
810 { /* copy/move a file */
812 result
= clipboard_pastefile(src
, target
, copy
);
819 src
[srcdirlen
] = '\0'; /* terminate to original length */
820 target
[targetdirlen
] = '\0'; /* terminate to original length */
826 /* Paste the clipboard to the current directory */
827 static bool clipboard_paste(void)
829 char target
[MAX_PATH
];
833 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
834 static const struct text_message message
={lines
, 1};
836 /* Get the name of the current directory */
837 cwd
= getcwd(NULL
, 0);
839 /* Figure out the name of the selection */
840 nameptr
= strrchr(clipboard_selection
, '/');
842 /* Final target is current directory plus name of selection */
843 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
845 /* If the target existed but they choose not to overwite, exit */
846 if (file_exists(target
) &&
847 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
851 if (clipboard_is_copy
) {
852 splash(0, ID2P(LANG_COPYING
));
856 splash(0, ID2P(LANG_MOVING
));
859 /* Now figure out what we're doing */
861 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
862 /* Recursion. Set up external stack */
863 char srcpath
[MAX_PATH
];
864 char targetpath
[MAX_PATH
];
865 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
867 /* Do not allow the user to paste a directory into a dir they are
873 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
874 strlcpy(targetpath
, target
, sizeof(targetpath
));
876 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
877 target
, sizeof(targetpath
), clipboard_is_copy
);
879 if (success
&& !clipboard_is_copy
)
881 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
882 remove_dir(srcpath
, sizeof(srcpath
));
886 success
= clipboard_pastefile(clipboard_selection
, target
,
893 /* Reset everything */
894 clipboard_selection
[0] = 0;
895 clipboard_selection_attr
= 0;
896 clipboard_is_copy
= false;
898 /* Force reload of the current directory */
899 onplay_result
= ONPLAY_RELOAD_DIR
;
901 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
902 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_PASTE
),
910 static int set_rating_inline(void)
912 struct mp3entry
* id3
= audio_current_track();
913 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
915 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
916 NULL
, 1, 0, 10, NULL
, NULL
);
917 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
920 splash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
923 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
928 case ACTION_REQUEST_MENUITEM
:
929 if (!selected_file
|| !global_settings
.runtimedb
||
930 !tagcache_is_usable())
931 return ACTION_EXIT_MENUITEM
;
936 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
937 set_rating_inline
, NULL
,
938 ratingitem_callback
, Icon_Questionmark
);
941 static bool view_cue(void)
943 struct mp3entry
* id3
= audio_current_track();
944 if(id3
&& id3
->cuesheet
)
946 browse_cuesheet(id3
->cuesheet
);
950 static int view_cue_item_callback(int action
,
951 const struct menu_item_ex
*this_item
)
954 struct mp3entry
* id3
= audio_current_track();
957 case ACTION_REQUEST_MENUITEM
:
959 || !id3
|| !id3
->cuesheet
)
960 return ACTION_EXIT_MENUITEM
;
965 MENUITEM_FUNCTION(view_cue_item
, 0, ID2P(LANG_BROWSE_CUESHEET
),
966 view_cue
, NULL
, view_cue_item_callback
, Icon_NOICON
);
968 /* CONTEXT_WPS items */
969 MENUITEM_FUNCTION(browse_id3_item
, 0, ID2P(LANG_MENU_SHOW_ID3_INFO
),
970 browse_id3
, NULL
, NULL
, Icon_NOICON
);
971 #ifdef HAVE_PITCHSCREEN
972 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
973 gui_syncpitchscreen_run
, NULL
, NULL
, Icon_Audio
);
976 /* CONTEXT_[TREE|ID3DB] items */
977 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
978 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
979 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
980 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
981 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
982 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
983 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
984 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
985 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
986 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
987 delete_file
, NULL
, clipboard_callback
, Icon_NOICON
);
988 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
989 delete_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
990 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
991 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
994 static bool list_viewers(void)
996 int ret
= filetype_list_viewers(selected_file
);
997 if (ret
== PLUGIN_USB_CONNECTED
)
998 onplay_result
= ONPLAY_RELOAD_DIR
;
1002 static bool onplay_load_plugin(void *param
)
1004 int ret
= filetype_load_plugin((const char*)param
, selected_file
);
1005 if (ret
== PLUGIN_USB_CONNECTED
)
1006 onplay_result
= ONPLAY_RELOAD_DIR
;
1010 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1011 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1012 MENUITEM_FUNCTION(properties_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_PROPERTIES
),
1013 onplay_load_plugin
, (void *)"properties",
1014 clipboard_callback
, Icon_NOICON
);
1015 MENUITEM_FUNCTION(add_to_faves_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_ADD_TO_FAVES
),
1016 onplay_load_plugin
, (void *)"shortcuts_append",
1017 clipboard_callback
, Icon_NOICON
);
1020 static bool set_backdrop(void)
1022 /* load the image */
1023 if(sb_set_backdrop(SCREEN_MAIN
, selected_file
)) {
1024 splash(HZ
, str(LANG_BACKDROP_LOADED
));
1025 set_file(selected_file
, (char *)global_settings
.backdrop_file
,
1029 splash(HZ
, str(LANG_BACKDROP_FAILED
));
1034 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1035 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1037 #ifdef HAVE_RECORDING
1038 static bool set_recdir(void)
1040 strlcpy(global_settings
.rec_directory
, selected_file
, MAX_FILENAME
+1);
1044 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1045 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1048 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1052 case ACTION_REQUEST_MENUITEM
:
1053 #ifdef HAVE_MULTIVOLUME
1054 if ((selected_file_attr
& FAT_ATTR_VOLUME
) &&
1055 (this_item
== &rename_file_item
||
1056 this_item
== &delete_dir_item
||
1057 this_item
== &clipboard_cut_item
) )
1058 return ACTION_EXIT_MENUITEM
;
1059 /* no rename+delete for volumes */
1060 if ((selected_file_attr
& ATTR_VOLUME
) &&
1061 (this_item
== &delete_file_item
||
1062 this_item
== &list_viewers_item
))
1063 return ACTION_EXIT_MENUITEM
;
1065 #ifdef HAVE_TAGCACHE
1066 if (context
== CONTEXT_ID3DB
)
1067 return ACTION_EXIT_MENUITEM
;
1069 if (this_item
== &clipboard_paste_item
)
1070 { /* visible if there is something to paste */
1071 return (clipboard_selection
[0] != 0) ?
1072 action
: ACTION_EXIT_MENUITEM
;
1074 else if (this_item
== &create_dir_item
)
1076 /* always visible */
1079 else if (selected_file
)
1081 /* requires an actual file */
1082 if (this_item
== &rename_file_item
||
1083 this_item
== &clipboard_cut_item
||
1084 this_item
== &clipboard_copy_item
||
1085 this_item
== &properties_item
||
1086 this_item
== &add_to_faves_item
)
1090 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1092 /* only for directories */
1093 if (this_item
== &delete_dir_item
1094 #ifdef HAVE_RECORDING
1095 || this_item
== &set_recdir_item
1100 else if (this_item
== &delete_file_item
||
1101 this_item
== &list_viewers_item
)
1103 /* only for files */
1107 else if (this_item
== &set_backdrop_item
)
1109 char *suffix
= strrchr(selected_file
, '.');
1112 if (strcasecmp(suffix
, ".bmp") == 0)
1120 return ACTION_EXIT_MENUITEM
;
1126 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
1127 /* 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
)
1160 case ACTION_TREE_STOP
:
1161 if (this_item
== &wps_onplay_menu
)
1163 list_stop_handler();
1164 return ACTION_STD_CANCEL
;
1167 case ACTION_EXIT_MENUITEM
:
1168 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1173 int onplay(char* file
, int attr
, int from
)
1175 const struct menu_item_ex
*menu
;
1176 onplay_result
= ONPLAY_OK
;
1178 selected_file
= file
;
1179 selected_file_attr
= attr
;
1180 if (context
== CONTEXT_WPS
)
1181 menu
= &wps_onplay_menu
;
1183 menu
= &tree_onplay_menu
;
1184 switch (do_menu(menu
, NULL
, NULL
, false))
1187 return ONPLAY_START_PLAY
;
1189 case GO_TO_MAINMENU
:
1190 return ONPLAY_MAINMENU
;
1192 return onplay_result
;