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 ****************************************************************************/
42 #include "playlist_viewer.h"
45 #include "filetypes.h"
51 #include "menus/exported_menus.h"
52 #ifdef HAVE_LCD_BITMAP
55 #include "sound_menu.h"
56 #include "playlist_menu.h"
57 #include "playlist_catalog.h"
62 #include "statusbar-skinned.h"
63 #include "pitchscreen.h"
65 #include "filefuncs.h"
66 #include "shortcuts.h"
69 static const 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
,
95 bookmark_menu_callback
, Icon_Bookmark
);
96 MENUITEM_FUNCTION(bookmark_load_menu_item
, 0,
97 ID2P(LANG_BOOKMARK_MENU_LIST
),
98 bookmark_load_menu
, NULL
,
99 bookmark_menu_callback
, Icon_Bookmark
);
100 MAKE_ONPLAYMENU(bookmark_menu
, ID2P(LANG_BOOKMARK_MENU
),
101 bookmark_menu_callback
, Icon_Bookmark
,
102 &bookmark_create_menu_item
, &bookmark_load_menu_item
);
103 static int bookmark_menu_callback(int action
,
104 const struct menu_item_ex
*this_item
)
108 case ACTION_REQUEST_MENUITEM
:
109 /* hide create bookmark option if bookmarking isn't currently possible (no track playing, queued tracks...) */
110 if (this_item
== &bookmark_create_menu_item
)
112 if (!bookmark_is_bookmarkable_state())
113 return ACTION_EXIT_MENUITEM
;
115 /* hide loading bookmarks menu if no bookmarks exist */
116 else if (this_item
== &bookmark_load_menu_item
)
118 if (!bookmark_exists())
119 return ACTION_EXIT_MENUITEM
;
121 /* hide the bookmark menu if bookmarks can't be loaded or created */
122 else if (!bookmark_is_bookmarkable_state() && !bookmark_exists())
123 return ACTION_EXIT_MENUITEM
;
125 #ifdef HAVE_LCD_CHARCELLS
126 case ACTION_ENTER_MENUITEM
:
127 status_set_param(true);
130 case ACTION_EXIT_MENUITEM
:
131 #ifdef HAVE_LCD_CHARCELLS
132 status_set_param(false);
140 /* CONTEXT_WPS playlist options */
141 static bool shuffle_playlist(void)
143 playlist_sort(NULL
, true);
144 playlist_randomise(NULL
, current_tick
, true);
148 static bool save_playlist(void)
150 save_playlist_screen(NULL
);
154 extern struct menu_item_ex view_cur_playlist
; /* from playlist_menu.c */
155 MENUITEM_FUNCTION(search_playlist_item
, 0, ID2P(LANG_SEARCH_IN_PLAYLIST
),
156 search_playlist
, NULL
, NULL
, Icon_Playlist
);
157 MENUITEM_FUNCTION(playlist_save_item
, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST
),
158 save_playlist
, NULL
, NULL
, Icon_Playlist
);
159 MENUITEM_FUNCTION(reshuffle_item
, 0, ID2P(LANG_SHUFFLE_PLAYLIST
),
160 shuffle_playlist
, NULL
, NULL
, Icon_Playlist
);
161 MAKE_ONPLAYMENU( wps_playlist_menu
, ID2P(LANG_PLAYLIST
),
163 &view_cur_playlist
, &search_playlist_item
,
164 &playlist_save_item
, &reshuffle_item
167 /* CONTEXT_[TREE|ID3DB] playlist options */
168 static bool add_to_playlist(int position
, bool queue
)
170 bool new_playlist
= !(audio_status() & AUDIO_STATUS_PLAY
);
171 const char *lines
[] = {
172 ID2P(LANG_RECURSE_DIRECTORY_QUESTION
),
175 const struct text_message message
={lines
, 2};
177 splash(0, ID2P(LANG_WAIT
));
180 playlist_create(NULL
, NULL
);
182 /* always set seed before inserting shuffled */
183 if (position
== PLAYLIST_INSERT_SHUFFLED
||
184 position
== PLAYLIST_INSERT_LAST_SHUFFLED
)
187 if (position
== PLAYLIST_INSERT_LAST_SHUFFLED
)
188 playlist_set_last_shuffled_start();
192 if (context
== CONTEXT_ID3DB
)
194 tagtree_insert_selection_playlist(position
, queue
);
199 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_AUDIO
)
200 playlist_insert_track(NULL
, selected_file
, position
, queue
, true);
201 else if (selected_file_attr
& ATTR_DIRECTORY
)
203 bool recurse
= false;
205 if (global_settings
.recursive_dir_insert
!= RECURSE_ASK
)
206 recurse
= (bool)global_settings
.recursive_dir_insert
;
209 /* Ask if user wants to recurse directory */
210 recurse
= (gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
);
213 playlist_insert_directory(NULL
, selected_file
, position
, queue
,
216 else if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)
217 playlist_insert_playlist(NULL
, selected_file
, position
, queue
);
220 if (new_playlist
&& (playlist_amount() > 0))
222 /* nothing is currently playing so begin playing what we just
224 if (global_settings
.playlist_shuffle
)
225 playlist_shuffle(current_tick
, -1);
227 onplay_result
= ONPLAY_START_PLAY
;
233 static bool view_playlist(void)
235 bool was_playing
= audio_status() & AUDIO_STATUS_PLAY
;
238 result
= playlist_viewer_ex(selected_file
);
240 if (!was_playing
&& (audio_status() & AUDIO_STATUS_PLAY
) &&
241 onplay_result
== ONPLAY_OK
)
242 /* playlist was started from viewer */
243 onplay_result
= ONPLAY_START_PLAY
;
248 static int playlist_insert_func(void *param
)
250 if (((intptr_t)param
== PLAYLIST_REPLACE
) && !warn_on_pl_erase())
252 add_to_playlist((intptr_t)param
, false);
256 static int playlist_queue_func(void *param
)
258 add_to_playlist((intptr_t)param
, true);
262 static int treeplaylist_wplayback_callback(int action
,
263 const struct menu_item_ex
* this_item
)
268 case ACTION_REQUEST_MENUITEM
:
269 if (audio_status() & AUDIO_STATUS_PLAY
)
272 return ACTION_EXIT_MENUITEM
;
278 static int treeplaylist_callback(int action
,
279 const struct menu_item_ex
*this_item
);
282 MENUITEM_FUNCTION(i_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT
),
283 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
,
284 NULL
, Icon_Playlist
);
285 MENUITEM_FUNCTION(i_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_FIRST
),
286 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
287 treeplaylist_wplayback_callback
, Icon_Playlist
);
288 MENUITEM_FUNCTION(i_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_INSERT_LAST
),
289 playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
290 treeplaylist_wplayback_callback
, Icon_Playlist
);
291 MENUITEM_FUNCTION(i_shuf_pl_item
, MENU_FUNC_USEPARAM
,
292 ID2P(LANG_INSERT_SHUFFLED
), playlist_insert_func
,
293 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
294 treeplaylist_callback
, Icon_Playlist
);
295 MENUITEM_FUNCTION(i_last_shuf_pl_item
, MENU_FUNC_USEPARAM
,
296 ID2P(LANG_INSERT_LAST_SHUFFLED
), playlist_insert_func
,
297 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED
,
298 treeplaylist_callback
, Icon_Playlist
);
300 MENUITEM_FUNCTION(q_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE
),
301 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT
,
302 treeplaylist_wplayback_callback
, Icon_Playlist
);
303 MENUITEM_FUNCTION(q_first_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_FIRST
),
304 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_FIRST
,
305 treeplaylist_wplayback_callback
, Icon_Playlist
);
306 MENUITEM_FUNCTION(q_last_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_QUEUE_LAST
),
307 playlist_queue_func
, (intptr_t*)PLAYLIST_INSERT_LAST
,
308 treeplaylist_wplayback_callback
, Icon_Playlist
);
309 MENUITEM_FUNCTION(q_shuf_pl_item
, MENU_FUNC_USEPARAM
,
310 ID2P(LANG_QUEUE_SHUFFLED
), playlist_queue_func
,
311 (intptr_t*)PLAYLIST_INSERT_SHUFFLED
,
312 treeplaylist_wplayback_callback
, Icon_Playlist
);
313 MENUITEM_FUNCTION(q_last_shuf_pl_item
, MENU_FUNC_USEPARAM
,
314 ID2P(LANG_QUEUE_LAST_SHUFFLED
), playlist_queue_func
,
315 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED
,
316 treeplaylist_callback
, Icon_Playlist
);
317 /* replace playlist */
318 MENUITEM_FUNCTION(replace_pl_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_REPLACE
),
319 playlist_insert_func
, (intptr_t*)PLAYLIST_REPLACE
,
320 treeplaylist_wplayback_callback
, Icon_Playlist
);
323 MENUITEM_FUNCTION(view_playlist_item
, 0, ID2P(LANG_VIEW
),
325 treeplaylist_callback
, Icon_Playlist
);
327 MAKE_ONPLAYMENU( tree_playlist_menu
, ID2P(LANG_CURRENT_PLAYLIST
),
328 treeplaylist_callback
, Icon_Playlist
,
334 &i_pl_item
, &i_first_pl_item
, &i_last_pl_item
,
335 &i_shuf_pl_item
, &i_last_shuf_pl_item
,
338 &q_pl_item
, &q_first_pl_item
, &q_last_pl_item
,
339 &q_shuf_pl_item
, &q_last_shuf_pl_item
,
344 static int treeplaylist_callback(int action
,
345 const struct menu_item_ex
*this_item
)
349 case ACTION_REQUEST_MENUITEM
:
350 if (this_item
== &tree_playlist_menu
)
352 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
354 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)||
355 (selected_file_attr
& ATTR_DIRECTORY
))
360 else if (this_item
== &view_playlist_item
)
362 if ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
&&
363 context
== CONTEXT_TREE
)
368 else if (this_item
== &i_shuf_pl_item
)
370 if ((audio_status() & AUDIO_STATUS_PLAY
) ||
371 (selected_file_attr
& ATTR_DIRECTORY
) ||
372 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
))
377 else if (this_item
== &i_last_shuf_pl_item
||
378 this_item
== &q_last_shuf_pl_item
)
380 if ((playlist_amount() > 0) &&
381 (audio_status() & AUDIO_STATUS_PLAY
) &&
382 ((selected_file_attr
& ATTR_DIRECTORY
) ||
383 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
)))
388 return ACTION_EXIT_MENUITEM
;
394 void onplay_show_playlist_menu(char* path
)
396 selected_file
= path
;
397 if (dir_exists(path
))
398 selected_file_attr
= ATTR_DIRECTORY
;
400 selected_file_attr
= filetype_get_attr(path
);
401 do_menu(&tree_playlist_menu
, NULL
, NULL
, false);
404 /* playlist catalog options */
405 static bool cat_add_to_a_playlist(void)
407 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
411 static bool cat_add_to_a_new_playlist(void)
413 return catalog_add_to_a_playlist(selected_file
, selected_file_attr
,
416 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
417 static bool set_catalogdir(void)
419 catalog_set_directory(selected_file
);
423 MENUITEM_FUNCTION(set_catalogdir_item
, 0, ID2P(LANG_SET_AS_PLAYLISTCAT_DIR
),
424 set_catalogdir
, NULL
, clipboard_callback
, Icon_Playlist
);
426 static int cat_playlist_callback(int action
,
427 const struct menu_item_ex
*this_item
);
428 MENUITEM_FUNCTION(cat_add_to_list
, 0, ID2P(LANG_CATALOG_ADD_TO
),
429 cat_add_to_a_playlist
, 0, NULL
, Icon_Playlist
);
430 MENUITEM_FUNCTION(cat_add_to_new
, 0, ID2P(LANG_CATALOG_ADD_TO_NEW
),
431 cat_add_to_a_new_playlist
, 0, NULL
, Icon_Playlist
);
432 MAKE_ONPLAYMENU(cat_playlist_menu
, ID2P(LANG_CATALOG
),
433 cat_playlist_callback
, Icon_Playlist
,
434 &cat_add_to_list
, &cat_add_to_new
, &set_catalogdir_item
);
436 void onplay_show_playlist_cat_menu(char* track_name
)
438 selected_file
= track_name
;
439 selected_file_attr
= FILE_ATTR_AUDIO
;
440 do_menu(&cat_playlist_menu
, NULL
, NULL
, false);
443 static int cat_playlist_callback(int action
,
444 const struct menu_item_ex
*this_item
)
447 if (!selected_file
||
448 (((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
) &&
449 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_M3U
) &&
450 ((selected_file_attr
& ATTR_DIRECTORY
) == 0)))
452 return ACTION_EXIT_MENUITEM
;
455 if (context
== CONTEXT_ID3DB
&&
456 ((selected_file_attr
& FILE_ATTR_MASK
) != FILE_ATTR_AUDIO
))
458 return ACTION_EXIT_MENUITEM
;
464 case ACTION_REQUEST_MENUITEM
:
465 if ((audio_status() & AUDIO_STATUS_PLAY
) || context
!= CONTEXT_WPS
)
470 return ACTION_EXIT_MENUITEM
;
476 #ifdef HAVE_LCD_BITMAP
477 static void draw_slider(void)
482 int slider_height
= 2*screens
[i
].getcharheight();
483 viewport_set_defaults(&vp
, i
);
484 screens
[i
].set_viewport(&vp
);
485 show_busy_slider(&screens
[i
], 1, vp
.height
- slider_height
,
486 vp
.width
-2, slider_height
-1);
487 screens
[i
].update_viewport();
488 screens
[i
].set_viewport(NULL
);
492 #define draw_slider()
495 /* helper function to remove a non-empty directory */
496 static int remove_dir(char* dirname
, int len
)
500 int dirlen
= strlen(dirname
);
502 dir
= opendir(dirname
);
504 return -1; /* open error */
508 struct dirent
* entry
;
509 /* walk through the directory content */
510 entry
= readdir(dir
);
513 struct dirinfo info
= dir_get_info(dir
, entry
);
514 dirname
[dirlen
] ='\0';
515 /* inform the user which dir we're deleting */
518 /* append name to current directory */
519 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
520 if (info
.attribute
& ATTR_DIRECTORY
)
521 { /* remove a subdirectory */
522 if (!strcmp((char *)entry
->d_name
, ".") ||
523 !strcmp((char *)entry
->d_name
, ".."))
524 continue; /* skip these */
526 result
= remove_dir(dirname
, len
); /* recursion */
528 break; /* or better continue, delete what we can? */
531 { /* remove a file */
533 result
= remove(dirname
);
535 if(ACTION_STD_CANCEL
== get_action(CONTEXT_STD
,TIMEOUT_NOBLOCK
))
537 splash(HZ
, ID2P(LANG_CANCEL
));
545 { /* remove the now empty directory */
546 dirname
[dirlen
] = '\0'; /* terminate to original length */
548 result
= rmdir(dirname
);
555 /* share code for file and directory deletion, saves space */
556 static bool delete_file_dir(void)
558 char file_to_delete
[MAX_PATH
];
559 strcpy(file_to_delete
, selected_file
);
561 const char *lines
[]={
562 ID2P(LANG_REALLY_DELETE
),
565 const char *yes_lines
[]={
570 const struct text_message message
={lines
, 2};
571 const struct text_message yes_message
={yes_lines
, 2};
573 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)!=YESNO_YES
)
576 splash(0, str(LANG_DELETING
));
579 if (selected_file_attr
& ATTR_DIRECTORY
) /* true if directory */
581 char pathname
[MAX_PATH
]; /* space to go deep */
583 strlcpy(pathname
, file_to_delete
, sizeof(pathname
));
584 res
= remove_dir(pathname
, sizeof(pathname
));
588 res
= remove(file_to_delete
);
591 onplay_result
= ONPLAY_RELOAD_DIR
;
596 static bool rename_file(void)
598 char newname
[MAX_PATH
];
599 char* ptr
= strrchr(selected_file
, '/') + 1;
600 int pathlen
= (ptr
- selected_file
);
601 strlcpy(newname
, selected_file
, sizeof(newname
));
602 if (!kbd_input(newname
+ pathlen
, (sizeof newname
)-pathlen
)) {
603 if (!strlen(newname
+ pathlen
) ||
604 (rename(selected_file
, newname
) < 0)) {
605 cond_talk_ids_fq(LANG_RENAME
, LANG_FAILED
);
606 splashf(HZ
*2, "%s %s", str(LANG_RENAME
), str(LANG_FAILED
));
609 onplay_result
= ONPLAY_RELOAD_DIR
;
615 static bool create_dir(void)
617 char dirname
[MAX_PATH
];
622 cwd
= getcwd(NULL
, 0);
623 memset(dirname
, 0, sizeof dirname
);
625 snprintf(dirname
, sizeof dirname
, "%s/", cwd
[1] ? cwd
: "");
627 pathlen
= strlen(dirname
);
628 rc
= kbd_input(dirname
+ pathlen
, (sizeof dirname
)-pathlen
);
634 cond_talk_ids_fq(LANG_CREATE_DIR
, LANG_FAILED
);
635 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_CREATE_DIR
),
638 onplay_result
= ONPLAY_RELOAD_DIR
;
644 /* Store the current selection in the clipboard */
645 static bool clipboard_clip(bool copy
)
647 clipboard_selection
[0] = 0;
648 strlcpy(clipboard_selection
, selected_file
, sizeof(clipboard_selection
));
649 clipboard_selection_attr
= selected_file_attr
;
650 clipboard_is_copy
= copy
;
655 static bool clipboard_cut(void)
657 return clipboard_clip(false);
660 static bool clipboard_copy(void)
662 return clipboard_clip(true);
665 /* Paste a file to a new directory. Will overwrite always. */
666 static bool clipboard_pastefile(const char *src
, const char *target
, bool copy
)
668 int src_fd
, target_fd
;
670 ssize_t size
, bytesread
, byteswritten
;
675 /* See if we can get the plugin buffer for the file copy buffer */
676 buffer
= (char *) plugin_get_buffer(&buffersize
);
677 if (buffer
== NULL
|| buffersize
< 512) {
678 /* Not large enough, try for a disk sector worth of stack
681 buffer
= (char *) __builtin_alloca(buffersize
);
684 if (buffer
== NULL
) {
688 buffersize
&= ~0x1ff; /* Round buffer size to multiple of sector
691 src_fd
= open(src
, O_RDONLY
);
694 target_fd
= creat(target
, 0666);
696 if (target_fd
>= 0) {
699 size
= filesize(src_fd
);
706 bytesread
= read(src_fd
, buffer
, buffersize
);
708 if (bytesread
== -1) {
715 while(bytesread
> 0) {
716 byteswritten
= write(target_fd
, buffer
, bytesread
);
718 if (byteswritten
< 0) {
724 bytesread
-= byteswritten
;
731 /* Copy failed. Cleanup. */
740 result
= rename(src
, target
) == 0;
741 #ifdef HAVE_MULTIVOLUME
743 if (errno
== EXDEV
) {
744 /* Failed because cross volume rename doesn't work. Copy
746 result
= clipboard_pastefile(src
, target
, true);
749 result
= remove(src
) == 0;
759 /* Paste a directory to a new location. Designed to be called by
761 static bool clipboard_pastedirectory(char *src
, int srclen
, char *target
,
762 int targetlen
, bool copy
)
765 int srcdirlen
= strlen(src
);
766 int targetdirlen
= strlen(target
);
769 if (!file_exists(target
)) {
771 /* Just move the directory */
772 result
= rename(src
, target
) == 0;
774 #ifdef HAVE_MULTIVOLUME
775 if (!result
&& errno
== EXDEV
) {
776 /* Try a copy as we're going across devices */
777 result
= clipboard_pastedirectory(src
, srclen
, target
,
780 /* If it worked, remove the source directory */
782 remove_dir(src
, srclen
);
788 /* Make a directory to copy things to */
789 result
= mkdir(target
) == 0;
793 /* Check if something went wrong already */
798 srcdir
= opendir(src
);
803 /* This loop will exit as soon as there's a problem */
806 struct dirent
* entry
;
807 /* walk through the directory content */
808 entry
= readdir(srcdir
);
812 struct dirinfo info
= dir_get_info(srcdir
, entry
);
813 /* append name to current directory */
814 snprintf(src
+srcdirlen
, srclen
-srcdirlen
, "/%s", entry
->d_name
);
815 snprintf(target
+targetdirlen
, targetlen
-targetdirlen
, "/%s",
818 DEBUGF("Copy %s to %s\n", src
, target
);
820 if (info
.attribute
& ATTR_DIRECTORY
)
821 { /* copy/move a subdirectory */
822 if (!strcmp((char *)entry
->d_name
, ".") ||
823 !strcmp((char *)entry
->d_name
, ".."))
824 continue; /* skip these */
826 result
= clipboard_pastedirectory(src
, srclen
, target
, targetlen
,
827 copy
); /* recursion */
830 { /* copy/move a file */
832 result
= clipboard_pastefile(src
, target
, copy
);
839 src
[srcdirlen
] = '\0'; /* terminate to original length */
840 target
[targetdirlen
] = '\0'; /* terminate to original length */
846 /* Paste the clipboard to the current directory */
847 static bool clipboard_paste(void)
849 char target
[MAX_PATH
];
853 static const char *lines
[]={ID2P(LANG_REALLY_OVERWRITE
)};
854 static const struct text_message message
={lines
, 1};
856 /* Get the name of the current directory */
857 cwd
= getcwd(NULL
, 0);
859 /* Figure out the name of the selection */
860 nameptr
= strrchr(clipboard_selection
, '/');
862 /* Final target is current directory plus name of selection */
863 snprintf(target
, sizeof(target
), "%s%s", cwd
[1] ? cwd
: "", nameptr
);
865 /* If the target existed but they choose not to overwite, exit */
866 if (file_exists(target
) &&
867 (gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)) {
871 if (clipboard_is_copy
) {
872 splash(0, ID2P(LANG_COPYING
));
876 splash(0, ID2P(LANG_MOVING
));
879 /* Now figure out what we're doing */
881 if (clipboard_selection_attr
& ATTR_DIRECTORY
) {
882 /* Recursion. Set up external stack */
883 char srcpath
[MAX_PATH
];
884 char targetpath
[MAX_PATH
];
885 if (!strncmp(clipboard_selection
, target
, strlen(clipboard_selection
)))
887 /* Do not allow the user to paste a directory into a dir they are
893 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
894 strlcpy(targetpath
, target
, sizeof(targetpath
));
896 success
= clipboard_pastedirectory(srcpath
, sizeof(srcpath
),
897 target
, sizeof(targetpath
), clipboard_is_copy
);
899 if (success
&& !clipboard_is_copy
)
901 strlcpy(srcpath
, clipboard_selection
, sizeof(srcpath
));
902 remove_dir(srcpath
, sizeof(srcpath
));
906 success
= clipboard_pastefile(clipboard_selection
, target
,
913 /* Reset everything */
914 clipboard_selection
[0] = 0;
915 clipboard_selection_attr
= 0;
916 clipboard_is_copy
= false;
918 /* Force reload of the current directory */
919 onplay_result
= ONPLAY_RELOAD_DIR
;
921 cond_talk_ids_fq(LANG_PASTE
, LANG_FAILED
);
922 splashf(HZ
, (unsigned char *)"%s %s", str(LANG_PASTE
),
930 static int set_rating_inline(void)
932 struct mp3entry
* id3
= audio_current_track();
933 if (id3
&& id3
->tagcache_idx
&& global_settings
.runtimedb
)
935 set_int_ex(str(LANG_MENU_SET_RATING
), "", UNIT_INT
, (void*)(&id3
->rating
),
936 NULL
, 1, 0, 10, NULL
, NULL
);
937 tagcache_update_numeric(id3
->tagcache_idx
-1, tag_rating
, id3
->rating
);
940 splash(HZ
*2, ID2P(LANG_ID3_NO_INFO
));
943 static int ratingitem_callback(int action
,const struct menu_item_ex
*this_item
)
948 case ACTION_REQUEST_MENUITEM
:
949 if (!selected_file
|| !global_settings
.runtimedb
||
950 !tagcache_is_usable())
951 return ACTION_EXIT_MENUITEM
;
956 MENUITEM_FUNCTION(rating_item
, 0, ID2P(LANG_MENU_SET_RATING
),
957 set_rating_inline
, NULL
,
958 ratingitem_callback
, Icon_Questionmark
);
960 #ifdef HAVE_PICTUREFLOW_INTEGRATION
961 MENUITEM_RETURNVALUE(pictureflow_item
, ID2P(LANG_ONPLAY_PICTUREFLOW
),
962 GO_TO_PICTUREFLOW
, NULL
, Icon_NOICON
);
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
);
993 static int browse_id3_wrapper(void)
997 return GO_TO_PREVIOUS
;
1000 /* CONTEXT_WPS items */
1001 MENUITEM_FUNCTION(browse_id3_item
, MENU_FUNC_CHECK_RETVAL
, ID2P(LANG_MENU_SHOW_ID3_INFO
),
1002 browse_id3_wrapper
, NULL
, NULL
, Icon_NOICON
);
1003 #ifdef HAVE_PITCHCONTROL
1004 MENUITEM_FUNCTION(pitch_screen_item
, 0, ID2P(LANG_PITCH
),
1005 gui_syncpitchscreen_run
, NULL
, NULL
, Icon_Audio
);
1008 /* CONTEXT_[TREE|ID3DB] items */
1009 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
);
1010 MENUITEM_FUNCTION(rename_file_item
, 0, ID2P(LANG_RENAME
),
1011 rename_file
, NULL
, clipboard_callback
, Icon_NOICON
);
1012 MENUITEM_FUNCTION(clipboard_cut_item
, 0, ID2P(LANG_CUT
),
1013 clipboard_cut
, NULL
, clipboard_callback
, Icon_NOICON
);
1014 MENUITEM_FUNCTION(clipboard_copy_item
, 0, ID2P(LANG_COPY
),
1015 clipboard_copy
, NULL
, clipboard_callback
, Icon_NOICON
);
1016 MENUITEM_FUNCTION(clipboard_paste_item
, 0, ID2P(LANG_PASTE
),
1017 clipboard_paste
, NULL
, clipboard_callback
, Icon_NOICON
);
1018 MENUITEM_FUNCTION(delete_file_item
, 0, ID2P(LANG_DELETE
),
1019 delete_file_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1020 MENUITEM_FUNCTION(delete_dir_item
, 0, ID2P(LANG_DELETE_DIR
),
1021 delete_file_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1022 MENUITEM_FUNCTION(create_dir_item
, 0, ID2P(LANG_CREATE_DIR
),
1023 create_dir
, NULL
, clipboard_callback
, Icon_NOICON
);
1026 static bool list_viewers(void)
1028 int ret
= filetype_list_viewers(selected_file
);
1029 if (ret
== PLUGIN_USB_CONNECTED
)
1030 onplay_result
= ONPLAY_RELOAD_DIR
;
1034 static bool onplay_load_plugin(void *param
)
1036 int ret
= filetype_load_plugin((const char*)param
, selected_file
);
1037 if (ret
== PLUGIN_USB_CONNECTED
)
1038 onplay_result
= ONPLAY_RELOAD_DIR
;
1042 MENUITEM_FUNCTION(list_viewers_item
, 0, ID2P(LANG_ONPLAY_OPEN_WITH
),
1043 list_viewers
, NULL
, clipboard_callback
, Icon_NOICON
);
1044 MENUITEM_FUNCTION(properties_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_PROPERTIES
),
1045 onplay_load_plugin
, (void *)"properties",
1046 clipboard_callback
, Icon_NOICON
);
1047 static bool onplay_add_to_shortcuts(void)
1049 shortcuts_add(SHORTCUT_BROWSER
, selected_file
);
1052 MENUITEM_FUNCTION(add_to_faves_item
, 0, ID2P(LANG_ADD_TO_FAVES
),
1053 onplay_add_to_shortcuts
, NULL
,
1054 clipboard_callback
, Icon_NOICON
);
1057 static bool set_backdrop(void)
1059 strlcpy(global_settings
.backdrop_file
, selected_file
,
1060 sizeof(global_settings
.backdrop_file
));
1062 skin_backdrop_load_setting();
1063 skin_backdrop_show(sb_get_backdrop(SCREEN_MAIN
));
1066 MENUITEM_FUNCTION(set_backdrop_item
, 0, ID2P(LANG_SET_AS_BACKDROP
),
1067 set_backdrop
, NULL
, clipboard_callback
, Icon_NOICON
);
1069 #ifdef HAVE_RECORDING
1070 static bool set_recdir(void)
1072 strlcpy(global_settings
.rec_directory
, selected_file
,
1073 sizeof(global_settings
.rec_directory
));
1077 MENUITEM_FUNCTION(set_recdir_item
, 0, ID2P(LANG_SET_AS_REC_DIR
),
1078 set_recdir
, NULL
, clipboard_callback
, Icon_Recording
);
1080 static bool set_startdir(void)
1082 snprintf(global_settings
.start_directory
,
1083 sizeof(global_settings
.start_directory
),
1084 "%s/", selected_file
);
1088 MENUITEM_FUNCTION(set_startdir_item
, 0, ID2P(LANG_SET_AS_START_DIR
),
1089 set_startdir
, NULL
, clipboard_callback
, Icon_file_view_menu
);
1091 static int clipboard_callback(int action
,const struct menu_item_ex
*this_item
)
1095 case ACTION_REQUEST_MENUITEM
:
1096 #ifdef HAVE_MULTIVOLUME
1097 if ((selected_file_attr
& FAT_ATTR_VOLUME
) &&
1098 (this_item
== &rename_file_item
||
1099 this_item
== &delete_dir_item
||
1100 this_item
== &clipboard_cut_item
) )
1101 return ACTION_EXIT_MENUITEM
;
1102 /* no rename+delete for volumes */
1103 if ((selected_file_attr
& ATTR_VOLUME
) &&
1104 (this_item
== &delete_file_item
||
1105 this_item
== &list_viewers_item
))
1106 return ACTION_EXIT_MENUITEM
;
1108 #ifdef HAVE_TAGCACHE
1109 if (context
== CONTEXT_ID3DB
)
1111 if (((selected_file_attr
& FILE_ATTR_MASK
) ==
1113 this_item
== &properties_item
)
1115 return ACTION_EXIT_MENUITEM
;
1118 if (this_item
== &clipboard_paste_item
)
1119 { /* visible if there is something to paste */
1120 return (clipboard_selection
[0] != 0) ?
1121 action
: ACTION_EXIT_MENUITEM
;
1123 else if (this_item
== &create_dir_item
)
1125 /* always visible */
1128 else if (selected_file
)
1130 /* requires an actual file */
1131 if (this_item
== &rename_file_item
||
1132 this_item
== &clipboard_cut_item
||
1133 this_item
== &clipboard_copy_item
||
1134 this_item
== &properties_item
||
1135 this_item
== &add_to_faves_item
)
1139 else if ((selected_file_attr
& ATTR_DIRECTORY
))
1141 /* only for directories */
1142 if (this_item
== &delete_dir_item
||
1143 this_item
== &set_startdir_item
||
1144 this_item
== &set_catalogdir_item
1145 #ifdef HAVE_RECORDING
1146 || this_item
== &set_recdir_item
1151 else if (this_item
== &delete_file_item
||
1152 this_item
== &list_viewers_item
)
1154 /* only for files */
1158 else if (this_item
== &set_backdrop_item
)
1160 char *suffix
= strrchr(selected_file
, '.');
1163 if (strcasecmp(suffix
, ".bmp") == 0)
1171 return ACTION_EXIT_MENUITEM
;
1177 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
);
1178 /* used when onplay() is called in the CONTEXT_WPS context */
1179 MAKE_ONPLAYMENU( wps_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1180 onplaymenu_callback
, Icon_Audio
,
1181 &wps_playlist_menu
, &cat_playlist_menu
,
1182 &sound_settings
, &playback_settings
,
1183 #ifdef HAVE_TAGCACHE
1187 #ifdef HAVE_PICTUREFLOW_INTEGRATION
1190 &browse_id3_item
, &list_viewers_item
,
1191 &delete_file_item
, &view_cue_item
,
1192 #ifdef HAVE_PITCHCONTROL
1196 /* used when onplay() is not called in the CONTEXT_WPS context */
1197 MAKE_ONPLAYMENU( tree_onplay_menu
, ID2P(LANG_ONPLAY_MENU_TITLE
),
1198 onplaymenu_callback
, Icon_file_view_menu
,
1199 &tree_playlist_menu
, &cat_playlist_menu
,
1200 &rename_file_item
, &clipboard_cut_item
, &clipboard_copy_item
,
1201 &clipboard_paste_item
, &delete_file_item
, &delete_dir_item
,
1205 &list_viewers_item
, &create_dir_item
, &properties_item
,
1206 #ifdef HAVE_RECORDING
1209 &set_startdir_item
, &add_to_faves_item
,
1211 static int onplaymenu_callback(int action
,const struct menu_item_ex
*this_item
)
1215 case ACTION_TREE_STOP
:
1216 if (this_item
== &wps_onplay_menu
)
1218 list_stop_handler();
1219 return ACTION_STD_CANCEL
;
1222 case ACTION_EXIT_MENUITEM
:
1223 return ACTION_EXIT_AFTER_THIS_MENUITEM
;
1230 /* direct function calls, no need for menu callbacks */
1231 static bool delete_item(void)
1233 #ifdef HAVE_MULTIVOLUME
1234 /* no delete for volumes */
1235 if ((selected_file_attr
& FAT_ATTR_VOLUME
) ||
1236 (selected_file_attr
& ATTR_VOLUME
))
1239 return delete_file_dir();
1242 static bool open_with(void)
1244 /* only open files */
1245 if (selected_file_attr
& ATTR_DIRECTORY
)
1247 #ifdef HAVE_MULTIVOLUME
1248 if (selected_file_attr
& ATTR_VOLUME
)
1251 return list_viewers();
1254 static int playlist_insert_shuffled(void)
1256 if ((audio_status() & AUDIO_STATUS_PLAY
) ||
1257 (selected_file_attr
& ATTR_DIRECTORY
) ||
1258 ((selected_file_attr
& FILE_ATTR_MASK
) == FILE_ATTR_M3U
))
1260 playlist_insert_func((intptr_t*)PLAYLIST_INSERT_SHUFFLED
);
1261 return ONPLAY_START_PLAY
;
1264 return ONPLAY_RELOAD_DIR
;
1267 struct hotkey_assignment
{
1268 int action
; /* hotkey_action */
1269 int lang_id
; /* Language ID */
1270 struct menu_func func
; /* Function to run if this entry is selected */
1271 int return_code
; /* What to return after the function is run */
1274 #define HOTKEY_FUNC(func, param) {{(void *)func}, param}
1276 /* Any desired hotkey functions go here, in the enum in onplay.h,
1277 and in the settings menu in settings_list.c. The order here
1278 is not important. */
1279 static struct hotkey_assignment hotkey_items
[] = {
1280 { HOTKEY_VIEW_PLAYLIST
, LANG_VIEW_DYNAMIC_PLAYLIST
,
1281 HOTKEY_FUNC(NULL
, NULL
),
1283 { HOTKEY_SHOW_TRACK_INFO
, LANG_MENU_SHOW_ID3_INFO
,
1284 HOTKEY_FUNC(browse_id3
, NULL
),
1285 ONPLAY_RELOAD_DIR
},
1286 #ifdef HAVE_PITCHCONTROL
1287 { HOTKEY_PITCHSCREEN
, LANG_PITCH
,
1288 HOTKEY_FUNC(gui_syncpitchscreen_run
, NULL
),
1289 ONPLAY_RELOAD_DIR
},
1291 { HOTKEY_OPEN_WITH
, LANG_ONPLAY_OPEN_WITH
,
1292 HOTKEY_FUNC(open_with
, NULL
),
1293 ONPLAY_RELOAD_DIR
},
1294 { HOTKEY_DELETE
, LANG_DELETE
,
1295 HOTKEY_FUNC(delete_item
, NULL
),
1296 ONPLAY_RELOAD_DIR
},
1297 { HOTKEY_INSERT
, LANG_INSERT
,
1298 HOTKEY_FUNC(playlist_insert_func
, (intptr_t*)PLAYLIST_INSERT
),
1299 ONPLAY_RELOAD_DIR
},
1300 { HOTKEY_INSERT_SHUFFLED
, LANG_INSERT_SHUFFLED
,
1301 HOTKEY_FUNC(playlist_insert_shuffled
, NULL
),
1302 ONPLAY_RELOAD_DIR
},
1303 #ifdef HAVE_PICTUREFLOW_INTEGRATION
1304 { HOTKEY_PICTUREFLOW
, LANG_ONPLAY_PICTUREFLOW
,
1305 HOTKEY_FUNC(NULL
, NULL
),
1306 ONPLAY_PICTUREFLOW
},
1310 /* Return the language ID for this action */
1311 int get_hotkey_lang_id(int action
)
1313 int i
= ARRAYLEN(hotkey_items
);
1316 if (hotkey_items
[i
].action
== action
)
1317 return hotkey_items
[i
].lang_id
;
1323 /* Execute the hotkey function, if listed */
1324 static int execute_hotkey(bool is_wps
)
1326 int i
= ARRAYLEN(hotkey_items
);
1327 struct hotkey_assignment
*this_item
;
1328 const int action
= (is_wps
? global_settings
.hotkey_wps
:
1329 global_settings
.hotkey_tree
);
1331 /* search assignment struct for a match for the hotkey setting */
1334 this_item
= &hotkey_items
[i
];
1335 if (this_item
->action
== action
)
1337 /* run the associated function (with optional param), if any */
1338 const struct menu_func func
= this_item
->func
;
1339 int func_return
= ONPLAY_RELOAD_DIR
;
1340 if (func
.function
!= NULL
)
1342 if (func
.param
!= NULL
)
1343 func_return
= (*func
.function_w_param
)(func
.param
);
1345 func_return
= (*func
.function
)();
1347 /* return with the associated code */
1348 const int return_code
= this_item
->return_code
;
1349 /* ONPLAY_OK here means to use the function return code */
1350 if (return_code
== ONPLAY_OK
)
1356 /* no valid hotkey set, ignore hotkey */
1357 return ONPLAY_RELOAD_DIR
;
1361 int onplay(char* file
, int attr
, int from
, bool hotkey
)
1363 const struct menu_item_ex
*menu
;
1364 onplay_result
= ONPLAY_OK
;
1366 selected_file
= file
;
1367 selected_file_attr
= attr
;
1371 return execute_hotkey(context
== CONTEXT_WPS
);
1376 push_current_activity(ACTIVITY_CONTEXTMENU
);
1377 if (context
== CONTEXT_WPS
)
1378 menu
= &wps_onplay_menu
;
1380 menu
= &tree_onplay_menu
;
1381 menu_selection
= do_menu(menu
, NULL
, NULL
, false);
1382 pop_current_activity();
1384 switch (menu_selection
)
1387 return ONPLAY_START_PLAY
;
1389 case GO_TO_MAINMENU
:
1390 return ONPLAY_MAINMENU
;
1391 case GO_TO_PLAYLIST_VIEWER
:
1392 return ONPLAY_PLAYLIST
;
1393 #ifdef HAVE_PICTUREFLOW_INTEGRATION
1394 case GO_TO_PICTUREFLOW
:
1395 return ONPLAY_PICTUREFLOW
;
1398 return onplay_result
;