2003-03-12 20:21:30 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
2007-02-28 01:36:32 +00:00
|
|
|
|
* Copyright (C) 2002 Bj<EFBFBD>rn Stenberg
|
2003-03-12 20:21:30 +00:00
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
2006-03-20 11:46:06 +00:00
|
|
|
|
#include <errno.h>
|
2003-03-12 20:21:30 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
2003-04-01 20:58:31 +00:00
|
|
|
|
#include "debug.h"
|
2003-03-12 21:40:47 +00:00
|
|
|
|
#include "sprintf.h"
|
2003-03-12 20:21:30 +00:00
|
|
|
|
#include "lcd.h"
|
|
|
|
|
#include "dir.h"
|
|
|
|
|
#include "file.h"
|
2005-04-04 12:06:29 +00:00
|
|
|
|
#include "audio.h"
|
2003-03-12 20:21:30 +00:00
|
|
|
|
#include "menu.h"
|
|
|
|
|
#include "lang.h"
|
|
|
|
|
#include "playlist.h"
|
|
|
|
|
#include "button.h"
|
|
|
|
|
#include "kernel.h"
|
|
|
|
|
#include "keyboard.h"
|
2003-04-01 20:58:31 +00:00
|
|
|
|
#include "mp3data.h"
|
|
|
|
|
#include "id3.h"
|
|
|
|
|
#include "screens.h"
|
2003-03-24 13:17:43 +00:00
|
|
|
|
#include "tree.h"
|
2003-05-09 16:01:21 +00:00
|
|
|
|
#include "buffer.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
|
#include "settings.h"
|
2005-11-20 01:02:14 +00:00
|
|
|
|
#include "statusbar.h"
|
2004-01-26 17:05:21 +00:00
|
|
|
|
#include "playlist_viewer.h"
|
2004-03-14 21:33:53 +00:00
|
|
|
|
#include "talk.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
|
#include "onplay.h"
|
2004-05-21 20:08:24 +00:00
|
|
|
|
#include "filetypes.h"
|
2004-07-13 13:57:14 +00:00
|
|
|
|
#include "plugin.h"
|
2005-06-23 01:31:26 +00:00
|
|
|
|
#include "bookmark.h"
|
|
|
|
|
#include "action.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
|
#include "splash.h"
|
2005-11-22 22:19:08 +00:00
|
|
|
|
#include "yesno.h"
|
2005-06-23 01:31:26 +00:00
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
#include "icons.h"
|
|
|
|
|
#endif
|
2005-06-23 10:11:10 +00:00
|
|
|
|
#include "main_menu.h"
|
2005-06-24 22:33:42 +00:00
|
|
|
|
#include "sound_menu.h"
|
2006-02-07 14:07:46 +00:00
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-02-19 02:14:51 +00:00
|
|
|
|
#include "menus/eq_menu.h"
|
2006-02-07 14:07:46 +00:00
|
|
|
|
#endif
|
2006-02-09 09:09:32 +00:00
|
|
|
|
#include "playlist_menu.h"
|
2006-07-18 13:54:12 +00:00
|
|
|
|
#include "playlist_catalog.h"
|
2006-10-25 10:17:57 +00:00
|
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-07-25 07:41:00 +00:00
|
|
|
|
#include "tagtree.h"
|
2006-10-25 10:17:57 +00:00
|
|
|
|
#endif
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2007-04-25 22:08:00 +00:00
|
|
|
|
#if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
|
|
|
|
|
#include "backdrop.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
|
static int context;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
static char* selected_file = NULL;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
static int selected_file_attr = 0;
|
|
|
|
|
static int onplay_result = ONPLAY_OK;
|
2006-03-20 11:46:06 +00:00
|
|
|
|
static char clipboard_selection[MAX_PATH];
|
|
|
|
|
static int clipboard_selection_attr = 0;
|
|
|
|
|
static bool clipboard_is_copy = false;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
|
/* For playlist options */
|
|
|
|
|
struct playlist_args {
|
|
|
|
|
int position;
|
|
|
|
|
bool queue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
/* Displays the bookmark menu options for the user to decide. This is an */
|
|
|
|
|
/* interface function. */
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static bool bookmark_menu(void)
|
2005-06-23 01:31:26 +00:00
|
|
|
|
{
|
|
|
|
|
int i,m;
|
|
|
|
|
bool result;
|
|
|
|
|
struct menu_item items[3];
|
|
|
|
|
|
|
|
|
|
i=0;
|
|
|
|
|
|
|
|
|
|
if ((audio_status() & AUDIO_STATUS_PLAY))
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_BOOKMARK_MENU_CREATE);
|
|
|
|
|
items[i].function = bookmark_create_menu;
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
if (bookmark_exist())
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_BOOKMARK_MENU_LIST);
|
|
|
|
|
items[i].function = bookmark_load_menu;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-08 05:52:47 +00:00
|
|
|
|
m=menu_init( items, i, NULL, str(LANG_BOOKMARK_MENU), NULL, NULL );
|
2005-06-23 01:31:26 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
|
status_set_param(true);
|
|
|
|
|
#endif
|
|
|
|
|
result = menu_run(m);
|
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
|
status_set_param(false);
|
|
|
|
|
#endif
|
|
|
|
|
menu_exit(m);
|
|
|
|
|
|
|
|
|
|
settings_save();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-21 20:08:24 +00:00
|
|
|
|
static bool list_viewers(void)
|
|
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
|
int ret = filetype_list_viewers(selected_file);
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (ret == PLUGIN_USB_CONNECTED)
|
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
2004-05-21 20:08:24 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-23 15:49:36 +00:00
|
|
|
|
static bool shuffle_playlist(void)
|
|
|
|
|
{
|
2005-06-23 16:27:15 +00:00
|
|
|
|
playlist_sort(NULL, true);
|
2006-03-22 02:18:44 +00:00
|
|
|
|
playlist_randomise(NULL, current_tick, true);
|
|
|
|
|
|
2005-06-23 15:49:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
|
static bool save_playlist(void)
|
|
|
|
|
{
|
2006-02-09 09:09:32 +00:00
|
|
|
|
save_playlist_screen(NULL);
|
2005-06-23 01:31:26 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
|
|
static bool add_to_playlist(int position, bool queue)
|
2003-03-12 20:21:30 +00:00
|
|
|
|
{
|
2005-04-04 12:06:29 +00:00
|
|
|
|
bool new_playlist = !(audio_status() & AUDIO_STATUS_PLAY);
|
2006-03-21 11:11:31 +00:00
|
|
|
|
char *lines[] = {
|
|
|
|
|
(char *)str(LANG_RECURSE_DIRECTORY_QUESTION),
|
|
|
|
|
selected_file
|
|
|
|
|
};
|
|
|
|
|
struct text_message message={lines, 2};
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
2007-03-16 21:56:08 +00:00
|
|
|
|
gui_syncsplash(0, str(LANG_WAIT));
|
2006-08-12 11:00:39 +00:00
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
if (new_playlist)
|
|
|
|
|
playlist_create(NULL, NULL);
|
|
|
|
|
|
2006-09-15 23:51:21 +00:00
|
|
|
|
/* always set seed before inserting shuffled */
|
|
|
|
|
if (position == PLAYLIST_INSERT_SHUFFLED)
|
|
|
|
|
srand(current_tick);
|
|
|
|
|
|
2006-10-25 10:17:57 +00:00
|
|
|
|
#ifdef HAVE_TAGCACHE
|
2006-07-25 07:41:00 +00:00
|
|
|
|
if (context == CONTEXT_ID3DB)
|
2003-07-02 15:54:44 +00:00
|
|
|
|
{
|
2006-07-25 07:41:00 +00:00
|
|
|
|
tagtree_insert_selection_playlist(position, queue);
|
|
|
|
|
}
|
|
|
|
|
else
|
2006-10-25 10:17:57 +00:00
|
|
|
|
#endif
|
2006-07-25 07:41:00 +00:00
|
|
|
|
{
|
2007-04-18 13:03:01 +00:00
|
|
|
|
if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO)
|
2006-08-10 09:50:45 +00:00
|
|
|
|
playlist_insert_track(NULL, selected_file, position, queue, true);
|
2006-07-25 07:41:00 +00:00
|
|
|
|
else if (selected_file_attr & ATTR_DIRECTORY)
|
2003-07-02 15:54:44 +00:00
|
|
|
|
{
|
2006-07-25 07:41:00 +00:00
|
|
|
|
bool recurse = false;
|
|
|
|
|
|
|
|
|
|
if (global_settings.recursive_dir_insert != RECURSE_ASK)
|
|
|
|
|
recurse = (bool)global_settings.recursive_dir_insert;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Ask if user wants to recurse directory */
|
|
|
|
|
recurse = (gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playlist_insert_directory(NULL, selected_file, position, queue,
|
|
|
|
|
recurse);
|
2003-07-02 15:54:44 +00:00
|
|
|
|
}
|
2007-04-18 13:03:01 +00:00
|
|
|
|
else if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)
|
2006-07-25 07:41:00 +00:00
|
|
|
|
playlist_insert_playlist(NULL, selected_file, position, queue);
|
2003-07-02 15:54:44 +00:00
|
|
|
|
}
|
2007-02-27 11:09:09 +00:00
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
if (new_playlist && (playlist_amount() > 0))
|
|
|
|
|
{
|
|
|
|
|
/* nothing is currently playing so begin playing what we just
|
|
|
|
|
inserted */
|
|
|
|
|
if (global_settings.playlist_shuffle)
|
|
|
|
|
playlist_shuffle(current_tick, -1);
|
|
|
|
|
playlist_start(0,0);
|
2005-11-20 01:02:14 +00:00
|
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
onplay_result = ONPLAY_START_PLAY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
static bool view_playlist(void)
|
|
|
|
|
{
|
2005-04-04 12:06:29 +00:00
|
|
|
|
bool was_playing = audio_status() & AUDIO_STATUS_PLAY;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
|
|
result = playlist_viewer_ex(selected_file);
|
|
|
|
|
|
2005-04-04 12:06:29 +00:00
|
|
|
|
if (!was_playing && (audio_status() & AUDIO_STATUS_PLAY) &&
|
2004-01-26 17:05:21 +00:00
|
|
|
|
onplay_result == ONPLAY_OK)
|
|
|
|
|
/* playlist was started from viewer */
|
|
|
|
|
onplay_result = ONPLAY_START_PLAY;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static bool cat_add_to_a_playlist(void)
|
2006-07-18 13:54:12 +00:00
|
|
|
|
{
|
|
|
|
|
return catalog_add_to_a_playlist(selected_file, selected_file_attr,
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static bool cat_add_to_a_new_playlist(void)
|
2006-07-18 13:54:12 +00:00
|
|
|
|
{
|
|
|
|
|
return catalog_add_to_a_playlist(selected_file, selected_file_attr, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool cat_playlist_options(void)
|
|
|
|
|
{
|
|
|
|
|
struct menu_item items[3];
|
|
|
|
|
int m, i=0, result;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if ((audio_status() & AUDIO_STATUS_PLAY && context == CONTEXT_WPS) ||
|
|
|
|
|
context == CONTEXT_TREE)
|
|
|
|
|
{
|
|
|
|
|
if (context == CONTEXT_WPS)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_CATALOG_VIEW);
|
|
|
|
|
items[i].function = catalog_view_playlists;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_CATALOG_ADD_TO);
|
|
|
|
|
items[i].function = cat_add_to_a_playlist;
|
|
|
|
|
i++;
|
|
|
|
|
items[i].desc = ID2P(LANG_CATALOG_ADD_TO_NEW);
|
|
|
|
|
items[i].function = cat_add_to_a_new_playlist;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-08 05:52:47 +00:00
|
|
|
|
m = menu_init( items, i, NULL, str(LANG_CATALOG), NULL, NULL );
|
2006-07-18 13:54:12 +00:00
|
|
|
|
result = menu_show(m);
|
|
|
|
|
if(result >= 0)
|
|
|
|
|
ret = items[result].function();
|
|
|
|
|
menu_exit(m);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
/* Sub-menu for playlist options */
|
|
|
|
|
static bool playlist_options(void)
|
|
|
|
|
{
|
2006-03-22 02:18:44 +00:00
|
|
|
|
struct menu_item items[13];
|
2006-03-04 23:53:09 +00:00
|
|
|
|
struct playlist_args args[13]; /* increase these 2 if you add entries! */
|
2004-01-26 17:05:21 +00:00
|
|
|
|
int m, i=0, pstart=0, result;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
2007-04-18 13:03:01 +00:00
|
|
|
|
if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U &&
|
2005-06-23 01:31:26 +00:00
|
|
|
|
context == CONTEXT_TREE)
|
2004-01-26 17:05:21 +00:00
|
|
|
|
{
|
2004-07-23 23:01:20 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_VIEW);
|
2004-03-16 13:44:56 +00:00
|
|
|
|
items[i].function = view_playlist;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
i++;
|
|
|
|
|
pstart++;
|
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
2005-06-24 22:10:55 +00:00
|
|
|
|
if (audio_status() & AUDIO_STATUS_PLAY &&
|
|
|
|
|
context == CONTEXT_WPS)
|
2003-07-01 21:05:43 +00:00
|
|
|
|
{
|
2005-06-23 01:31:26 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_VIEW_DYNAMIC_PLAYLIST);
|
|
|
|
|
items[i].function = playlist_viewer;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
i++;
|
2005-06-23 01:31:26 +00:00
|
|
|
|
pstart++;
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2006-03-04 23:53:09 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_SEARCH_IN_PLAYLIST);
|
|
|
|
|
items[i].function = search_playlist;
|
|
|
|
|
i++;
|
|
|
|
|
pstart++;
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_SAVE_DYNAMIC_PLAYLIST);
|
|
|
|
|
items[i].function = save_playlist;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
i++;
|
2005-06-23 01:31:26 +00:00
|
|
|
|
pstart++;
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2005-06-23 15:49:36 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_SHUFFLE_PLAYLIST);
|
|
|
|
|
items[i].function = shuffle_playlist;
|
|
|
|
|
i++;
|
2006-03-22 02:18:44 +00:00
|
|
|
|
pstart++;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
}
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2005-08-30 07:52:36 +00:00
|
|
|
|
if (context == CONTEXT_TREE || context == CONTEXT_ID3DB)
|
2003-07-01 21:05:43 +00:00
|
|
|
|
{
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (audio_status() & AUDIO_STATUS_PLAY)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_INSERT);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_INSERT_FIRST);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT_FIRST;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_INSERT_LAST);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT_LAST;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
|
|
|
|
|
2005-06-25 04:46:25 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_INSERT_SHUFFLED);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT_SHUFFLED;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_QUEUE);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT;
|
|
|
|
|
args[i].queue = true;
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_QUEUE_FIRST);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT_FIRST;
|
|
|
|
|
args[i].queue = true;
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_QUEUE_LAST);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT_LAST;
|
|
|
|
|
args[i].queue = true;
|
|
|
|
|
i++;
|
2006-01-25 08:29:12 +00:00
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_QUEUE_SHUFFLED);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT_SHUFFLED;
|
|
|
|
|
args[i].queue = true;
|
|
|
|
|
i++;
|
2006-12-26 13:31:04 +00:00
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_REPLACE);
|
|
|
|
|
args[i].position = PLAYLIST_REPLACE;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
2005-06-23 01:31:26 +00:00
|
|
|
|
}
|
2007-04-18 13:03:01 +00:00
|
|
|
|
else if (((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) ||
|
2005-06-23 01:31:26 +00:00
|
|
|
|
(selected_file_attr & ATTR_DIRECTORY))
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_INSERT);
|
2006-09-19 19:30:22 +00:00
|
|
|
|
args[i].position = PLAYLIST_INSERT_LAST;
|
2005-06-23 01:31:26 +00:00
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
2006-04-19 02:22:23 +00:00
|
|
|
|
|
|
|
|
|
if (selected_file_attr & ATTR_DIRECTORY)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_INSERT_SHUFFLED);
|
|
|
|
|
args[i].position = PLAYLIST_INSERT_SHUFFLED;
|
|
|
|
|
args[i].queue = false;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2005-06-23 01:31:26 +00:00
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-08 05:52:47 +00:00
|
|
|
|
m = menu_init( items, i, NULL, str(LANG_PLAYLIST_MENU), NULL, NULL );
|
2003-07-01 21:05:43 +00:00
|
|
|
|
result = menu_show(m);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
if (result >= 0 && result < pstart)
|
2004-03-16 13:44:56 +00:00
|
|
|
|
ret = items[result].function();
|
2004-01-26 17:05:21 +00:00
|
|
|
|
else if (result >= pstart)
|
|
|
|
|
ret = add_to_playlist(args[result].position, args[result].queue);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
menu_exit(m);
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
return ret;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-08 06:38:56 +00:00
|
|
|
|
|
|
|
|
|
/* helper function to remove a non-empty directory */
|
|
|
|
|
static int remove_dir(char* dirname, int len)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
DIR* dir;
|
|
|
|
|
int dirlen = strlen(dirname);
|
2006-12-27 02:37:12 +00:00
|
|
|
|
int i;
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2004-04-08 06:38:56 +00:00
|
|
|
|
dir = opendir(dirname);
|
|
|
|
|
if (!dir)
|
|
|
|
|
return -1; /* open error */
|
|
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
|
{
|
|
|
|
|
struct dirent* entry;
|
|
|
|
|
/* walk through the directory content */
|
|
|
|
|
entry = readdir(dir);
|
|
|
|
|
if (!entry)
|
|
|
|
|
break;
|
|
|
|
|
|
2006-12-27 02:37:12 +00:00
|
|
|
|
dirname[dirlen] ='\0';
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
|
screens[i].puts(0,1,dirname);
|
|
|
|
|
|
2004-04-08 06:38:56 +00:00
|
|
|
|
/* append name to current directory */
|
|
|
|
|
snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
|
2006-03-22 02:18:44 +00:00
|
|
|
|
if (entry->attribute & ATTR_DIRECTORY)
|
2004-04-08 06:38:56 +00:00
|
|
|
|
{ /* remove a subdirectory */
|
2005-12-05 22:44:42 +00:00
|
|
|
|
if (!strcmp((char *)entry->d_name, ".") ||
|
|
|
|
|
!strcmp((char *)entry->d_name, ".."))
|
2004-04-08 06:38:56 +00:00
|
|
|
|
continue; /* skip these */
|
|
|
|
|
|
2006-12-14 22:43:16 +00:00
|
|
|
|
/* inform the user which dir we're deleting */
|
2006-12-27 02:37:12 +00:00
|
|
|
|
|
2004-04-08 06:38:56 +00:00
|
|
|
|
result = remove_dir(dirname, len); /* recursion */
|
2006-03-22 02:18:44 +00:00
|
|
|
|
if (result)
|
2004-04-08 06:38:56 +00:00
|
|
|
|
break; /* or better continue, delete what we can? */
|
|
|
|
|
}
|
2006-03-22 02:18:44 +00:00
|
|
|
|
else
|
2004-04-08 06:38:56 +00:00
|
|
|
|
{ /* remove a file */
|
2006-12-27 02:37:12 +00:00
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
|
screens[i].puts_scroll(0,2,entry->d_name);
|
2004-04-08 06:38:56 +00:00
|
|
|
|
result = remove(dirname);
|
|
|
|
|
}
|
2006-12-27 02:37:12 +00:00
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
|
screens[i].update();
|
|
|
|
|
#endif
|
2006-12-14 22:43:16 +00:00
|
|
|
|
if(ACTION_STD_CANCEL == get_action(CONTEXT_STD,TIMEOUT_NOBLOCK))
|
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
|
gui_syncsplash(HZ, str(LANG_MENU_SETTING_CANCEL));
|
2006-12-14 22:43:16 +00:00
|
|
|
|
result = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-04-08 06:38:56 +00:00
|
|
|
|
}
|
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
|
{ /* remove the now empty directory */
|
|
|
|
|
dirname[dirlen] = '\0'; /* terminate to original length */
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2004-04-16 09:00:07 +00:00
|
|
|
|
result = rmdir(dirname);
|
2004-04-08 06:38:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* share code for file and directory deletion, saves space */
|
|
|
|
|
static bool delete_handler(bool is_dir)
|
2003-03-12 20:21:30 +00:00
|
|
|
|
{
|
2005-11-22 22:19:08 +00:00
|
|
|
|
char *lines[]={
|
2005-12-05 22:44:42 +00:00
|
|
|
|
(char *)str(LANG_REALLY_DELETE),
|
2005-11-22 22:19:08 +00:00
|
|
|
|
selected_file
|
|
|
|
|
};
|
|
|
|
|
char *yes_lines[]={
|
2005-12-05 22:44:42 +00:00
|
|
|
|
(char *)str(LANG_DELETED),
|
2005-11-22 22:19:08 +00:00
|
|
|
|
selected_file
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct text_message message={lines, 2};
|
|
|
|
|
struct text_message yes_message={yes_lines, 2};
|
|
|
|
|
if(gui_syncyesno_run(&message, &yes_message, NULL)!=YESNO_YES)
|
|
|
|
|
return false;
|
2004-04-08 06:38:56 +00:00
|
|
|
|
int res;
|
2005-11-22 22:19:08 +00:00
|
|
|
|
if (is_dir)
|
|
|
|
|
{
|
|
|
|
|
char pathname[MAX_PATH]; /* space to go deep */
|
2006-12-27 02:37:12 +00:00
|
|
|
|
cpu_boost(true);
|
2005-11-22 22:19:08 +00:00
|
|
|
|
strncpy(pathname, selected_file, sizeof pathname);
|
|
|
|
|
res = remove_dir(pathname, sizeof(pathname));
|
2006-12-27 02:37:12 +00:00
|
|
|
|
cpu_boost(false);
|
2005-11-22 22:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
res = remove(selected_file);
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2005-11-22 22:19:08 +00:00
|
|
|
|
if (!res) {
|
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-08 06:38:56 +00:00
|
|
|
|
|
|
|
|
|
static bool delete_file(void)
|
|
|
|
|
{
|
|
|
|
|
return delete_handler(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool delete_dir(void)
|
|
|
|
|
{
|
|
|
|
|
return delete_handler(true);
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-13 00:45:21 +00:00
|
|
|
|
#if LCD_DEPTH > 1
|
2006-02-02 20:42:56 +00:00
|
|
|
|
static bool set_backdrop(void)
|
|
|
|
|
{
|
|
|
|
|
/* load the image */
|
2006-05-21 11:00:02 +00:00
|
|
|
|
if(load_main_backdrop(selected_file)) {
|
2007-03-16 21:56:08 +00:00
|
|
|
|
gui_syncsplash(HZ, str(LANG_BACKDROP_LOADED));
|
2006-02-02 20:42:56 +00:00
|
|
|
|
set_file(selected_file, (char *)global_settings.backdrop_file, MAX_FILENAME);
|
2006-05-21 11:00:02 +00:00
|
|
|
|
show_main_backdrop();
|
2006-02-02 20:42:56 +00:00
|
|
|
|
return true;
|
|
|
|
|
} else {
|
2007-03-16 21:56:08 +00:00
|
|
|
|
gui_syncsplash(HZ, str(LANG_BACKDROP_FAILED));
|
2006-02-02 20:42:56 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-03-12 20:21:30 +00:00
|
|
|
|
static bool rename_file(void)
|
|
|
|
|
{
|
|
|
|
|
char newname[MAX_PATH];
|
|
|
|
|
char* ptr = strrchr(selected_file, '/') + 1;
|
|
|
|
|
int pathlen = (ptr - selected_file);
|
|
|
|
|
strncpy(newname, selected_file, sizeof newname);
|
|
|
|
|
if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
|
2005-05-13 10:35:32 +00:00
|
|
|
|
if (!strlen(newname + pathlen) ||
|
2003-03-12 20:21:30 +00:00
|
|
|
|
(rename(selected_file, newname) < 0)) {
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
lcd_puts(0,0,str(LANG_RENAME));
|
|
|
|
|
lcd_puts(0,1,str(LANG_FAILED));
|
|
|
|
|
lcd_update();
|
|
|
|
|
sleep(HZ*2);
|
|
|
|
|
}
|
|
|
|
|
else
|
2003-07-01 21:05:43 +00:00
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static bool create_dir(void)
|
2004-03-11 10:43:53 +00:00
|
|
|
|
{
|
|
|
|
|
char dirname[MAX_PATH];
|
|
|
|
|
char *cwd;
|
|
|
|
|
int rc;
|
|
|
|
|
int pathlen;
|
|
|
|
|
|
|
|
|
|
cwd = getcwd(NULL, 0);
|
|
|
|
|
memset(dirname, 0, sizeof dirname);
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2004-03-11 10:43:53 +00:00
|
|
|
|
snprintf(dirname, sizeof dirname, "%s/",
|
|
|
|
|
cwd[1] ? cwd : "");
|
|
|
|
|
|
|
|
|
|
pathlen = strlen(dirname);
|
|
|
|
|
rc = kbd_input(dirname + pathlen, (sizeof dirname)-pathlen);
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (rc < 0)
|
2004-03-11 10:43:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2007-02-03 10:28:55 +00:00
|
|
|
|
rc = mkdir(dirname);
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (rc < 0) {
|
2007-03-16 21:56:08 +00:00
|
|
|
|
gui_syncsplash(HZ, (unsigned char *)"%s %s",
|
2005-12-05 22:44:42 +00:00
|
|
|
|
str(LANG_CREATE_DIR), str(LANG_FAILED));
|
2004-03-11 10:43:53 +00:00
|
|
|
|
} else {
|
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-30 22:29:48 +00:00
|
|
|
|
static bool properties(void)
|
|
|
|
|
{
|
|
|
|
|
if(PLUGIN_USB_CONNECTED == filetype_load_plugin("properties",
|
|
|
|
|
selected_file))
|
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-20 11:46:06 +00:00
|
|
|
|
/* Store the current selection in the clipboard */
|
|
|
|
|
static bool clipboard_clip(bool copy)
|
|
|
|
|
{
|
|
|
|
|
clipboard_selection[0] = 0;
|
2007-04-12 22:38:54 +00:00
|
|
|
|
strncpy(clipboard_selection, selected_file, sizeof(clipboard_selection));
|
2006-03-20 11:46:06 +00:00
|
|
|
|
clipboard_selection_attr = selected_file_attr;
|
|
|
|
|
clipboard_is_copy = copy;
|
|
|
|
|
|
2006-03-22 02:18:44 +00:00
|
|
|
|
return true;
|
2006-03-20 11:46:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool clipboard_cut(void)
|
|
|
|
|
{
|
|
|
|
|
return clipboard_clip(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool clipboard_copy(void)
|
|
|
|
|
{
|
|
|
|
|
return clipboard_clip(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Paste a file to a new directory. Will overwrite always. */
|
|
|
|
|
static bool clipboard_pastefile(const char *src, const char *target, bool copy)
|
|
|
|
|
{
|
2007-04-21 18:38:25 +00:00
|
|
|
|
int src_fd, target_fd;
|
2007-04-21 19:20:20 +00:00
|
|
|
|
size_t buffersize;
|
|
|
|
|
ssize_t size, bytesread, byteswritten;
|
2006-03-20 11:46:06 +00:00
|
|
|
|
char *buffer;
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
if (copy) {
|
|
|
|
|
/* See if we can get the plugin buffer for the file copy buffer */
|
2007-04-21 19:20:20 +00:00
|
|
|
|
buffer = (char *) plugin_get_buffer(&buffersize);
|
2006-03-20 11:46:06 +00:00
|
|
|
|
if (buffer == NULL || buffersize < 512) {
|
|
|
|
|
/* Not large enough, try for a disk sector worth of stack instead */
|
|
|
|
|
buffersize = 512;
|
|
|
|
|
buffer = (char *) __builtin_alloca(buffersize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buffer == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffersize &= ~0x1ff; /* Round buffer size to multiple of sector size */
|
|
|
|
|
|
|
|
|
|
src_fd = open(src, O_RDONLY);
|
|
|
|
|
|
2006-03-22 02:18:44 +00:00
|
|
|
|
if (src_fd >= 0) {
|
2007-02-01 23:08:15 +00:00
|
|
|
|
target_fd = creat(target);
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
|
|
|
|
if (target_fd >= 0) {
|
|
|
|
|
result = true;
|
|
|
|
|
|
|
|
|
|
size = filesize(src_fd);
|
|
|
|
|
|
|
|
|
|
if (size == -1) {
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(size > 0) {
|
|
|
|
|
bytesread = read(src_fd, buffer, buffersize);
|
|
|
|
|
|
|
|
|
|
if (bytesread == -1) {
|
|
|
|
|
result = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size -= bytesread;
|
|
|
|
|
|
|
|
|
|
while(bytesread > 0) {
|
|
|
|
|
byteswritten = write(target_fd, buffer, bytesread);
|
|
|
|
|
|
|
|
|
|
if (byteswritten == -1) {
|
|
|
|
|
result = false;
|
|
|
|
|
size = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bytesread -= byteswritten;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(target_fd);
|
|
|
|
|
|
|
|
|
|
/* Copy failed. Cleanup. */
|
|
|
|
|
if (!result) {
|
|
|
|
|
remove(target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(src_fd);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result = rename(src, target) == 0;
|
|
|
|
|
#ifdef HAVE_MULTIVOLUME
|
|
|
|
|
if (!result) {
|
|
|
|
|
if (errno == EXDEV) {
|
|
|
|
|
/* Failed because cross volume rename doesn't work. Copy instead */
|
|
|
|
|
result = clipboard_pastefile(src, target, true);
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
result = remove(src);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Paste a directory to a new location. Designed to be called by clipboard_paste */
|
|
|
|
|
static bool clipboard_pastedirectory(char *src, int srclen, char *target, int targetlen, bool copy)
|
|
|
|
|
{
|
|
|
|
|
DIR *srcdir;
|
|
|
|
|
int srcdirlen = strlen(src);
|
|
|
|
|
int targetdirlen = strlen(target);
|
|
|
|
|
int fd;
|
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
|
|
/* Check if the target exists */
|
|
|
|
|
fd = open(target, O_RDONLY);
|
|
|
|
|
close(fd);
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2006-03-20 11:46:06 +00:00
|
|
|
|
if (fd < 0) {
|
|
|
|
|
if (!copy) {
|
|
|
|
|
/* Just move the directory */
|
|
|
|
|
result = rename(src, target) == 0;
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_MULTIVOLUME
|
|
|
|
|
if (!result && errno == EXDEV) {
|
|
|
|
|
/* Try a copy as we're going across devices */
|
|
|
|
|
result = clipboard_pastedirectory(src, srclen, target, targetlen, true);
|
|
|
|
|
|
|
|
|
|
/* If it worked, remove the source directory */
|
|
|
|
|
if (result) {
|
|
|
|
|
remove_dir(src, srclen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
/* Make a directory to copy things to */
|
2007-02-03 10:28:55 +00:00
|
|
|
|
result = mkdir(target) == 0;
|
2006-03-20 11:46:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if something went wrong already */
|
|
|
|
|
if (!result) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srcdir = opendir(src);
|
|
|
|
|
if (!srcdir) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This loop will exit as soon as there's a problem */
|
|
|
|
|
while(result)
|
|
|
|
|
{
|
|
|
|
|
struct dirent* entry;
|
|
|
|
|
/* walk through the directory content */
|
|
|
|
|
entry = readdir(srcdir);
|
|
|
|
|
if (!entry)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* append name to current directory */
|
|
|
|
|
snprintf(src+srcdirlen, srclen-srcdirlen, "/%s", entry->d_name);
|
|
|
|
|
snprintf(target+targetdirlen, targetlen-targetdirlen, "/%s", entry->d_name);
|
|
|
|
|
|
|
|
|
|
DEBUGF("Copy %s to %s\n", src, target);
|
|
|
|
|
|
2006-03-22 02:18:44 +00:00
|
|
|
|
if (entry->attribute & ATTR_DIRECTORY)
|
2006-03-20 11:46:06 +00:00
|
|
|
|
{ /* copy/move a subdirectory */
|
|
|
|
|
if (!strcmp((char *)entry->d_name, ".") ||
|
|
|
|
|
!strcmp((char *)entry->d_name, ".."))
|
|
|
|
|
continue; /* skip these */
|
|
|
|
|
|
|
|
|
|
result = clipboard_pastedirectory(src, srclen, target, targetlen, copy); /* recursion */
|
|
|
|
|
}
|
2006-03-22 02:18:44 +00:00
|
|
|
|
else
|
2006-03-20 11:46:06 +00:00
|
|
|
|
{ /* copy/move a file */
|
|
|
|
|
result = clipboard_pastefile(src, target, copy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir(srcdir);
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
src[srcdirlen] = '\0'; /* terminate to original length */
|
|
|
|
|
target[targetdirlen] = '\0'; /* terminate to original length */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Paste the clipboard to the current directory */
|
|
|
|
|
static bool clipboard_paste(void)
|
|
|
|
|
{
|
|
|
|
|
char target[MAX_PATH];
|
|
|
|
|
char *cwd, *nameptr;
|
|
|
|
|
bool success;
|
|
|
|
|
int target_fd;
|
|
|
|
|
|
|
|
|
|
unsigned char *lines[]={str(LANG_REALLY_OVERWRITE)};
|
|
|
|
|
struct text_message message={(char **)lines, 1};
|
|
|
|
|
|
|
|
|
|
/* Get the name of the current directory */
|
|
|
|
|
cwd = getcwd(NULL, 0);
|
|
|
|
|
|
|
|
|
|
/* Figure out the name of the selection */
|
|
|
|
|
nameptr = strrchr(clipboard_selection, '/');
|
|
|
|
|
|
2007-04-12 22:38:54 +00:00
|
|
|
|
/* Final target is current directory plus name of selection */
|
|
|
|
|
snprintf(target, sizeof(target), "%s%s", cwd[1] ? cwd : "", nameptr);
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
|
|
|
|
/* Check if we're going to overwrite */
|
|
|
|
|
target_fd = open(target, O_RDONLY);
|
|
|
|
|
close(target_fd);
|
|
|
|
|
|
|
|
|
|
/* If the target existed but they choose not to overwite, exit */
|
|
|
|
|
if (target_fd >= 0 &&
|
|
|
|
|
(gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now figure out what we're doing */
|
|
|
|
|
if (clipboard_selection_attr & ATTR_DIRECTORY) {
|
|
|
|
|
/* Recursion. Set up external stack */
|
|
|
|
|
char srcpath[MAX_PATH];
|
|
|
|
|
char targetpath[MAX_PATH];
|
2007-02-27 10:06:55 +00:00
|
|
|
|
if (!strncmp(clipboard_selection, target, strlen(clipboard_selection)))
|
|
|
|
|
{
|
|
|
|
|
/* Do not allow the user to paste a directory into a dir they are copying */
|
|
|
|
|
success = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strncpy(srcpath, clipboard_selection, sizeof srcpath);
|
|
|
|
|
strncpy(targetpath, target, sizeof targetpath);
|
|
|
|
|
|
|
|
|
|
success = clipboard_pastedirectory(srcpath, sizeof(srcpath),
|
|
|
|
|
target, sizeof(targetpath), clipboard_is_copy);
|
|
|
|
|
}
|
2006-03-20 11:46:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
success = clipboard_pastefile(clipboard_selection, target, clipboard_is_copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Did it work? */
|
|
|
|
|
if (success) {
|
|
|
|
|
/* Reset everything */
|
|
|
|
|
clipboard_selection[0] = 0;
|
|
|
|
|
clipboard_selection_attr = 0;
|
|
|
|
|
clipboard_is_copy = false;
|
|
|
|
|
|
|
|
|
|
/* Force reload of the current directory */
|
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
|
|
|
|
} else {
|
2007-03-16 21:56:08 +00:00
|
|
|
|
gui_syncsplash(HZ, (unsigned char *)"%s %s",
|
2006-03-22 02:18:44 +00:00
|
|
|
|
str(LANG_PASTE), str(LANG_FAILED));
|
2006-03-20 11:46:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-23 10:11:10 +00:00
|
|
|
|
static bool exit_to_main;
|
|
|
|
|
|
|
|
|
|
/* catch MENU_EXIT_MENU within context menu to call the main menu afterwards */
|
|
|
|
|
static int onplay_callback(int key, int menu)
|
|
|
|
|
{
|
|
|
|
|
(void)menu;
|
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
|
if (key == ACTION_STD_MENU)
|
2005-06-23 10:11:10 +00:00
|
|
|
|
exit_to_main = true;
|
|
|
|
|
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-26 23:10:40 +00:00
|
|
|
|
#ifdef HAVE_TAGCACHE
|
2007-03-26 15:08:59 +00:00
|
|
|
|
char rating_menu_string[32];
|
|
|
|
|
|
|
|
|
|
static void create_rating_menu(void)
|
|
|
|
|
{
|
|
|
|
|
struct mp3entry* id3 = audio_current_track();
|
|
|
|
|
if(id3)
|
|
|
|
|
snprintf(rating_menu_string, sizeof rating_menu_string,
|
|
|
|
|
"%s: %d", str(LANG_MENU_SET_RATING), id3->rating);
|
|
|
|
|
else
|
|
|
|
|
snprintf(rating_menu_string, sizeof rating_menu_string,
|
|
|
|
|
"%s: -", str(LANG_MENU_SET_RATING));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool set_rating_inline(void)
|
|
|
|
|
{
|
|
|
|
|
struct mp3entry* id3 = audio_current_track();
|
|
|
|
|
if(id3) {
|
|
|
|
|
if(id3->rating<10)
|
|
|
|
|
id3->rating++;
|
|
|
|
|
else
|
|
|
|
|
id3->rating=0;
|
|
|
|
|
}
|
|
|
|
|
create_rating_menu();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-03-26 23:10:40 +00:00
|
|
|
|
#endif
|
2007-03-26 15:08:59 +00:00
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
|
int onplay(char* file, int attr, int from)
|
2003-03-12 20:21:30 +00:00
|
|
|
|
{
|
2006-02-07 14:07:46 +00:00
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2006-07-18 13:54:12 +00:00
|
|
|
|
struct menu_item items[14]; /* increase this if you add entries! */
|
2006-02-07 14:07:46 +00:00
|
|
|
|
#else
|
2006-07-18 13:54:12 +00:00
|
|
|
|
struct menu_item items[12];
|
2006-02-07 14:07:46 +00:00
|
|
|
|
#endif
|
2003-03-12 20:21:30 +00:00
|
|
|
|
int m, i=0, result;
|
2006-11-13 00:45:21 +00:00
|
|
|
|
#if LCD_DEPTH > 1
|
2006-02-02 20:42:56 +00:00
|
|
|
|
char *suffix;
|
2006-02-02 21:39:09 +00:00
|
|
|
|
#endif
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
onplay_result = ONPLAY_OK;
|
2005-06-23 01:31:26 +00:00
|
|
|
|
context=from;
|
2005-06-23 10:11:10 +00:00
|
|
|
|
exit_to_main = false;
|
2005-06-23 01:31:26 +00:00
|
|
|
|
selected_file = file;
|
|
|
|
|
selected_file_attr = attr;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
2005-06-24 22:33:42 +00:00
|
|
|
|
if (context == CONTEXT_WPS)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_SOUND_SETTINGS);
|
|
|
|
|
items[i].function = sound_menu;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
2007-02-06 09:01:32 +00:00
|
|
|
|
if (file && (context == CONTEXT_WPS ||
|
2005-06-23 01:31:26 +00:00
|
|
|
|
context == CONTEXT_TREE ||
|
2007-02-06 09:01:32 +00:00
|
|
|
|
context == CONTEXT_ID3DB))
|
2003-04-10 21:01:22 +00:00
|
|
|
|
{
|
2005-06-24 22:10:55 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_PLAYLIST);
|
|
|
|
|
items[i].function = playlist_options;
|
|
|
|
|
i++;
|
2006-07-18 13:54:12 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_CATALOG);
|
|
|
|
|
items[i].function = cat_playlist_options;
|
|
|
|
|
i++;
|
2005-06-23 01:31:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-24 22:33:42 +00:00
|
|
|
|
if (context == CONTEXT_WPS)
|
|
|
|
|
{
|
2007-03-26 23:10:40 +00:00
|
|
|
|
#ifdef HAVE_TAGCACHE
|
2007-03-26 15:08:59 +00:00
|
|
|
|
if(file && global_settings.runtimedb)
|
|
|
|
|
{
|
|
|
|
|
create_rating_menu();
|
|
|
|
|
items[i].desc = rating_menu_string;
|
|
|
|
|
items[i].function = set_rating_inline;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2007-03-26 23:10:40 +00:00
|
|
|
|
#endif
|
2005-06-24 22:33:42 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_BOOKMARK_MENU);
|
|
|
|
|
items[i].function = bookmark_menu;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (file)
|
|
|
|
|
{
|
|
|
|
|
if (context == CONTEXT_WPS)
|
2004-03-11 10:43:53 +00:00
|
|
|
|
{
|
2005-06-23 01:31:26 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_MENU_SHOW_ID3_INFO);
|
|
|
|
|
items[i].function = browse_id3;
|
2004-03-11 10:43:53 +00:00
|
|
|
|
i++;
|
|
|
|
|
}
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2005-06-23 10:11:10 +00:00
|
|
|
|
#ifdef HAVE_MULTIVOLUME
|
2005-01-04 22:12:02 +00:00
|
|
|
|
if (!(attr & ATTR_VOLUME)) /* no rename+delete for volumes */
|
|
|
|
|
#endif
|
2004-04-08 06:38:56 +00:00
|
|
|
|
{
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (context == CONTEXT_TREE)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_RENAME);
|
|
|
|
|
items[i].function = rename_file;
|
|
|
|
|
i++;
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_CUT);
|
|
|
|
|
items[i].function = clipboard_cut;
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
items[i].desc = ID2P(LANG_COPY);
|
|
|
|
|
items[i].function = clipboard_copy;
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
if (clipboard_selection[0] != 0) /* Something in the clipboard? */
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_PASTE);
|
|
|
|
|
items[i].function = clipboard_paste;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2005-06-23 01:31:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(attr & ATTR_DIRECTORY) && context == CONTEXT_TREE)
|
2005-01-04 22:12:02 +00:00
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_DELETE);
|
|
|
|
|
items[i].function = delete_file;
|
|
|
|
|
i++;
|
2006-02-02 20:42:56 +00:00
|
|
|
|
|
2006-11-13 00:45:21 +00:00
|
|
|
|
#if LCD_DEPTH > 1
|
2006-02-02 20:42:56 +00:00
|
|
|
|
suffix = strrchr(file, '.');
|
2006-03-20 11:46:06 +00:00
|
|
|
|
if (suffix)
|
|
|
|
|
{
|
|
|
|
|
if (strcasecmp(suffix, ".bmp") == 0)
|
|
|
|
|
{
|
2006-02-02 20:42:56 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_SET_AS_BACKDROP);
|
|
|
|
|
items[i].function = set_backdrop;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2005-01-04 22:12:02 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (context == CONTEXT_TREE)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_DELETE_DIR);
|
|
|
|
|
items[i].function = delete_dir;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2005-01-04 22:12:02 +00:00
|
|
|
|
}
|
2004-04-08 06:38:56 +00:00
|
|
|
|
}
|
2004-07-30 06:24:38 +00:00
|
|
|
|
|
2006-03-13 07:33:30 +00:00
|
|
|
|
if (!(attr & ATTR_DIRECTORY))
|
2004-07-30 06:24:38 +00:00
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_ONPLAY_OPEN_WITH);
|
|
|
|
|
items[i].function = list_viewers;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2003-04-10 21:01:22 +00:00
|
|
|
|
}
|
2006-03-20 11:46:06 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (strlen(clipboard_selection) != 0)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_PASTE);
|
|
|
|
|
items[i].function = clipboard_paste;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (context == CONTEXT_TREE)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_CREATE_DIR);
|
|
|
|
|
items[i].function = create_dir;
|
|
|
|
|
i++;
|
2007-02-06 09:01:32 +00:00
|
|
|
|
if (file)
|
|
|
|
|
{
|
|
|
|
|
items[i].desc = ID2P(LANG_PROPERTIES);
|
|
|
|
|
items[i].function = properties;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2005-06-23 01:31:26 +00:00
|
|
|
|
}
|
2006-11-30 22:29:48 +00:00
|
|
|
|
|
2006-02-07 14:07:46 +00:00
|
|
|
|
if (context == CONTEXT_WPS)
|
|
|
|
|
{
|
2006-08-16 13:25:45 +00:00
|
|
|
|
#ifdef HAVE_PITCHSCREEN
|
2006-03-22 02:18:44 +00:00
|
|
|
|
/* Pitch screen access */
|
|
|
|
|
items[i].desc = ID2P(LANG_PITCH);
|
|
|
|
|
items[i].function = pitch_screen;
|
|
|
|
|
i++;
|
2006-03-22 02:44:18 +00:00
|
|
|
|
#endif
|
2006-03-22 02:18:44 +00:00
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
|
/* Equalizer menu items */
|
2006-02-07 14:07:46 +00:00
|
|
|
|
items[i].desc = ID2P(LANG_EQUALIZER_GRAPHICAL);
|
|
|
|
|
items[i].function = eq_menu_graphical;
|
|
|
|
|
i++;
|
|
|
|
|
items[i].desc = ID2P(LANG_EQUALIZER_BROWSE);
|
|
|
|
|
items[i].function = eq_browse_presets;
|
|
|
|
|
i++;
|
|
|
|
|
#endif
|
2006-03-22 02:18:44 +00:00
|
|
|
|
}
|
2006-02-07 14:07:46 +00:00
|
|
|
|
|
2003-03-12 20:21:30 +00:00
|
|
|
|
/* DIY menu handling, since we want to exit after selection */
|
2005-06-23 01:31:26 +00:00
|
|
|
|
if (i)
|
|
|
|
|
{
|
2007-04-08 05:52:47 +00:00
|
|
|
|
m = menu_init( items, i, onplay_callback,
|
|
|
|
|
str(LANG_ONPLAY_MENU_TITLE), NULL, NULL );
|
2007-03-26 23:10:40 +00:00
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
result = menu_show(m);
|
|
|
|
|
if (result >= 0)
|
|
|
|
|
items[result].function();
|
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
|
}
|
|
|
|
|
while (items[result].function == set_rating_inline);
|
|
|
|
|
#endif
|
2005-06-23 01:31:26 +00:00
|
|
|
|
menu_exit(m);
|
2006-03-22 02:18:44 +00:00
|
|
|
|
|
2005-06-23 10:11:10 +00:00
|
|
|
|
if (exit_to_main)
|
2007-03-01 11:14:46 +00:00
|
|
|
|
onplay_result = ONPLAY_MAINMENU;
|
2005-06-23 01:31:26 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
if (global_settings.statusbar)
|
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
|
else
|
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2003-03-12 20:21:30 +00:00
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
|
return onplay_result;
|
2003-03-12 20:21:30 +00:00
|
|
|
|
}
|