2003-03-12 20:21:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2002 Björn Stenberg
|
2003-03-12 20:21:30 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2003-03-12 20:21:30 +00:00
|
|
|
*
|
|
|
|
* 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 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"
|
2008-10-15 06:38:51 +00:00
|
|
|
#include "metadata.h"
|
2003-04-01 20:58:31 +00:00
|
|
|
#include "screens.h"
|
2003-03-24 13:17:43 +00:00
|
|
|
#include "tree.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
#include "settings.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"
|
2007-04-30 13:41:33 +00:00
|
|
|
#include "menus/exported_menus.h"
|
2005-06-23 01:31:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "icons.h"
|
|
|
|
#endif
|
2005-06-24 22:33:42 +00:00
|
|
|
#include "sound_menu.h"
|
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
|
2007-05-14 17:34:52 +00:00
|
|
|
#include "cuesheet.h"
|
2010-01-29 07:52:13 +00:00
|
|
|
#include "statusbar-skinned.h"
|
2008-10-05 13:01:54 +00:00
|
|
|
#include "pitchscreen.h"
|
2009-08-23 15:06:11 +00:00
|
|
|
#include "viewport.h"
|
2007-04-25 22:08:00 +00:00
|
|
|
|
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
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
/* redefine MAKE_MENU so the MENU_EXITAFTERTHISMENU flag can be added easily */
|
|
|
|
#define MAKE_ONPLAYMENU( name, str, callback, icon, ... ) \
|
|
|
|
static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
|
|
|
|
static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
|
2007-11-04 12:40:18 +00:00
|
|
|
static const struct menu_item_ex name = \
|
2007-04-30 13:41:33 +00:00
|
|
|
{MT_MENU|MENU_HAS_DESC|MENU_EXITAFTERTHISMENU| \
|
|
|
|
MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
|
|
|
|
{ (void*)name##_},{.callback_and_desc = & name##__}};
|
2010-02-14 12:42:32 +00:00
|
|
|
|
2005-06-23 01:31:26 +00:00
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
/* Displays the bookmark menu options for the user to decide. This is an */
|
|
|
|
/* interface function. */
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
2007-05-15 23:30:30 +00:00
|
|
|
static int bookmark_menu_callback(int action,
|
|
|
|
const struct menu_item_ex *this_item);
|
2010-02-14 12:42:32 +00:00
|
|
|
MENUITEM_FUNCTION(bookmark_create_menu_item, 0,
|
|
|
|
ID2P(LANG_BOOKMARK_MENU_CREATE),
|
2007-04-30 13:41:33 +00:00
|
|
|
bookmark_create_menu, NULL, NULL, Icon_Bookmark);
|
2010-02-14 12:42:32 +00:00
|
|
|
MENUITEM_FUNCTION(bookmark_load_menu_item, 0,
|
|
|
|
ID2P(LANG_BOOKMARK_MENU_LIST),
|
|
|
|
bookmark_load_menu, NULL,
|
2007-04-30 13:41:33 +00:00
|
|
|
bookmark_menu_callback, Icon_Bookmark);
|
2010-02-14 12:42:32 +00:00
|
|
|
MAKE_ONPLAYMENU(bookmark_menu, ID2P(LANG_BOOKMARK_MENU),
|
|
|
|
bookmark_menu_callback, Icon_Bookmark,
|
|
|
|
&bookmark_create_menu_item, &bookmark_load_menu_item);
|
2007-05-15 23:30:30 +00:00
|
|
|
static int bookmark_menu_callback(int action,
|
|
|
|
const struct menu_item_ex *this_item)
|
2007-04-30 13:41:33 +00:00
|
|
|
{
|
|
|
|
switch (action)
|
2005-06-23 01:31:26 +00:00
|
|
|
{
|
2007-04-30 13:41:33 +00:00
|
|
|
case ACTION_REQUEST_MENUITEM:
|
|
|
|
if (this_item == &bookmark_load_menu_item)
|
|
|
|
{
|
|
|
|
if (bookmark_exist() == 0)
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
}
|
|
|
|
/* hide the bookmark menu if there is no playback */
|
|
|
|
else if ((audio_status() & AUDIO_STATUS_PLAY) == 0)
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
break;
|
2005-06-23 01:31:26 +00:00
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
2007-04-30 13:41:33 +00:00
|
|
|
case ACTION_ENTER_MENUITEM:
|
|
|
|
status_set_param(true);
|
|
|
|
break;
|
2005-06-23 01:31:26 +00:00
|
|
|
#endif
|
2007-04-30 13:41:33 +00:00
|
|
|
case ACTION_EXIT_MENUITEM:
|
2005-06-23 01:31:26 +00:00
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
2007-04-30 13:41:33 +00:00
|
|
|
status_set_param(false);
|
2005-06-23 01:31:26 +00:00
|
|
|
#endif
|
2007-04-30 13:41:33 +00:00
|
|
|
settings_save();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return action;
|
2005-06-23 01:31:26 +00:00
|
|
|
}
|
|
|
|
|
2010-02-14 12:42:32 +00:00
|
|
|
/* CONTEXT_WPS playlist options */
|
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
|
|
|
|
2010-02-20 19:06:39 +00:00
|
|
|
extern struct menu_item_ex view_cur_playlist; /* from playlist_menu.c */
|
2010-02-14 12:42:32 +00:00
|
|
|
MENUITEM_FUNCTION(search_playlist_item, 0, ID2P(LANG_SEARCH_IN_PLAYLIST),
|
|
|
|
search_playlist, NULL, NULL, Icon_Playlist);
|
|
|
|
MENUITEM_FUNCTION(playlist_save_item, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST),
|
|
|
|
save_playlist, NULL, NULL, Icon_Playlist);
|
|
|
|
MENUITEM_FUNCTION(reshuffle_item, 0, ID2P(LANG_SHUFFLE_PLAYLIST),
|
|
|
|
shuffle_playlist, NULL, NULL, Icon_Playlist);
|
|
|
|
MAKE_ONPLAYMENU( wps_playlist_menu, ID2P(LANG_PLAYLIST),
|
|
|
|
NULL, Icon_Playlist,
|
2010-02-20 19:06:39 +00:00
|
|
|
&view_cur_playlist, &search_playlist_item,
|
2010-02-14 12:42:32 +00:00
|
|
|
&playlist_save_item, &reshuffle_item
|
|
|
|
);
|
|
|
|
|
|
|
|
/* CONTEXT_[TREE|ID3DB] playlist options */
|
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);
|
2008-04-26 09:30:24 +00:00
|
|
|
const char *lines[] = {
|
2007-08-06 13:08:36 +00:00
|
|
|
ID2P(LANG_RECURSE_DIRECTORY_QUESTION),
|
2006-03-21 11:11:31 +00:00
|
|
|
selected_file
|
|
|
|
};
|
2008-04-26 09:30:24 +00:00
|
|
|
const struct text_message message={lines, 2};
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, ID2P(LANG_WAIT));
|
2010-02-14 12:42:32 +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 */
|
2009-11-01 14:25:38 +00:00
|
|
|
if (position == PLAYLIST_INSERT_SHUFFLED ||
|
|
|
|
position == PLAYLIST_INSERT_LAST_SHUFFLED)
|
2009-10-28 22:27:38 +00:00
|
|
|
{
|
2006-09-15 23:51:21 +00:00
|
|
|
srand(current_tick);
|
2009-11-01 14:25:38 +00:00
|
|
|
if (position == PLAYLIST_INSERT_LAST_SHUFFLED)
|
|
|
|
playlist_set_last_shuffled_start();
|
2009-10-28 22:27:38 +00:00
|
|
|
}
|
2006-09-15 23:51:21 +00:00
|
|
|
|
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;
|
2010-02-14 12:42:32 +00:00
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
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);
|
|
|
|
}
|
Fix playlist "Insert" a bit.
If insert was used to create a new playlist (e.g. inserting without audio playing), the insert position wasn't updated. Thus, the playlist created was in reversed order (except for the first song).
This was the reason "Insert last" was actually used as Insert in this case. BUT, this one doesn't update the insert position eiterh, but the order of the songs is fine, at least (due to appending).
Now, insert always updates the insert position properly, so that the aforementioned bugs are fixed. Insert is always used now.
Other impact: If you create a playlist using insert, every subsequent insert will append songs at the end of the playlist,if you start playback pressing select on songs, every subsequent insert will insert after the current track.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20241 a1c6a512-1295-4272-9138-f99709370657
2009-03-08 17:18:18 +00:00
|
|
|
|
2006-07-25 07:41:00 +00:00
|
|
|
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
|
|
|
}
|
2010-02-14 12:42:32 +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);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
static int playlist_insert_func(void *param)
|
|
|
|
{
|
2009-12-18 05:53:29 +00:00
|
|
|
if (((intptr_t)param == PLAYLIST_REPLACE) && !warn_on_pl_erase())
|
|
|
|
return 0;
|
2007-04-30 13:41:33 +00:00
|
|
|
add_to_playlist((intptr_t)param, false);
|
|
|
|
return 0;
|
2006-07-18 13:54:12 +00:00
|
|
|
}
|
2010-02-14 12:42:32 +00:00
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
static int playlist_queue_func(void *param)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2007-04-30 13:41:33 +00:00
|
|
|
add_to_playlist((intptr_t)param, true);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-02-14 12:42:32 +00:00
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
static int treeplaylist_wplayback_callback(int action,
|
2010-02-14 12:42:32 +00:00
|
|
|
const struct menu_item_ex* this_item)
|
2007-04-30 13:41:33 +00:00
|
|
|
{
|
|
|
|
(void)this_item;
|
|
|
|
switch (action)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2007-04-30 13:41:33 +00:00
|
|
|
case ACTION_REQUEST_MENUITEM:
|
|
|
|
if (audio_status() & AUDIO_STATUS_PLAY)
|
|
|
|
return action;
|
2010-02-14 12:42:32 +00:00
|
|
|
else
|
2007-04-30 13:41:33 +00:00
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
break;
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
2007-04-30 13:41:33 +00:00
|
|
|
return action;
|
|
|
|
}
|
2006-03-22 02:18:44 +00:00
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
static int treeplaylist_callback(int action,
|
|
|
|
const struct menu_item_ex *this_item);
|
|
|
|
|
|
|
|
/* insert items */
|
2010-05-09 02:02:51 +00:00
|
|
|
MENUITEM_FUNCTION(i_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT),
|
2007-04-30 13:41:33 +00:00
|
|
|
playlist_insert_func, (intptr_t*)PLAYLIST_INSERT,
|
2010-02-15 13:04:09 +00:00
|
|
|
NULL, Icon_Playlist);
|
2007-05-01 10:43:30 +00:00
|
|
|
MENUITEM_FUNCTION(i_first_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_FIRST),
|
2007-04-30 13:41:33 +00:00
|
|
|
playlist_insert_func, (intptr_t*)PLAYLIST_INSERT_FIRST,
|
|
|
|
treeplaylist_wplayback_callback, Icon_Playlist);
|
2007-05-01 10:43:30 +00:00
|
|
|
MENUITEM_FUNCTION(i_last_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_LAST),
|
2007-04-30 13:41:33 +00:00
|
|
|
playlist_insert_func, (intptr_t*)PLAYLIST_INSERT_LAST,
|
|
|
|
treeplaylist_wplayback_callback, Icon_Playlist);
|
2007-05-15 23:30:30 +00:00
|
|
|
MENUITEM_FUNCTION(i_shuf_pl_item, MENU_FUNC_USEPARAM,
|
|
|
|
ID2P(LANG_INSERT_SHUFFLED), playlist_insert_func,
|
2010-02-14 12:42:32 +00:00
|
|
|
(intptr_t*)PLAYLIST_INSERT_SHUFFLED,
|
|
|
|
treeplaylist_callback, Icon_Playlist);
|
2009-10-28 22:27:38 +00:00
|
|
|
MENUITEM_FUNCTION(i_last_shuf_pl_item, MENU_FUNC_USEPARAM,
|
|
|
|
ID2P(LANG_INSERT_LAST_SHUFFLED), playlist_insert_func,
|
2010-02-14 12:42:32 +00:00
|
|
|
(intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED,
|
|
|
|
treeplaylist_callback, Icon_Playlist);
|
2007-04-30 13:41:33 +00:00
|
|
|
/* queue items */
|
2007-05-01 10:43:30 +00:00
|
|
|
MENUITEM_FUNCTION(q_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE),
|
2007-04-30 13:41:33 +00:00
|
|
|
playlist_queue_func, (intptr_t*)PLAYLIST_INSERT,
|
|
|
|
treeplaylist_wplayback_callback, Icon_Playlist);
|
2007-05-01 10:43:30 +00:00
|
|
|
MENUITEM_FUNCTION(q_first_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_FIRST),
|
2007-04-30 13:41:33 +00:00
|
|
|
playlist_queue_func, (intptr_t*)PLAYLIST_INSERT_FIRST,
|
|
|
|
treeplaylist_wplayback_callback, Icon_Playlist);
|
2007-05-01 10:43:30 +00:00
|
|
|
MENUITEM_FUNCTION(q_last_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_LAST),
|
2007-04-30 13:41:33 +00:00
|
|
|
playlist_queue_func, (intptr_t*)PLAYLIST_INSERT_LAST,
|
|
|
|
treeplaylist_wplayback_callback, Icon_Playlist);
|
2007-05-15 23:30:30 +00:00
|
|
|
MENUITEM_FUNCTION(q_shuf_pl_item, MENU_FUNC_USEPARAM,
|
|
|
|
ID2P(LANG_QUEUE_SHUFFLED), playlist_queue_func,
|
|
|
|
(intptr_t*)PLAYLIST_INSERT_SHUFFLED,
|
2007-04-30 13:41:33 +00:00
|
|
|
treeplaylist_wplayback_callback, Icon_Playlist);
|
2009-10-28 22:27:38 +00:00
|
|
|
MENUITEM_FUNCTION(q_last_shuf_pl_item, MENU_FUNC_USEPARAM,
|
|
|
|
ID2P(LANG_QUEUE_LAST_SHUFFLED), playlist_queue_func,
|
|
|
|
(intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED,
|
|
|
|
treeplaylist_callback, Icon_Playlist);
|
2007-04-30 13:41:33 +00:00
|
|
|
/* replace playlist */
|
2007-05-01 10:43:30 +00:00
|
|
|
MENUITEM_FUNCTION(replace_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_REPLACE),
|
2007-04-30 13:41:33 +00:00
|
|
|
playlist_insert_func, (intptr_t*)PLAYLIST_REPLACE,
|
|
|
|
treeplaylist_wplayback_callback, Icon_Playlist);
|
|
|
|
|
2010-02-14 12:42:32 +00:00
|
|
|
/* others */
|
2007-04-30 13:41:33 +00:00
|
|
|
MENUITEM_FUNCTION(view_playlist_item, 0, ID2P(LANG_VIEW),
|
|
|
|
view_playlist, NULL,
|
|
|
|
treeplaylist_callback, Icon_Playlist);
|
|
|
|
|
2010-02-14 12:42:32 +00:00
|
|
|
MAKE_ONPLAYMENU( tree_playlist_menu, ID2P(LANG_PLAYLIST),
|
2007-05-15 23:30:30 +00:00
|
|
|
treeplaylist_callback, Icon_Playlist,
|
|
|
|
|
|
|
|
/* view */
|
|
|
|
&view_playlist_item,
|
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
/* insert */
|
2010-02-14 12:42:32 +00:00
|
|
|
&i_pl_item, &i_first_pl_item, &i_last_pl_item,
|
|
|
|
&i_shuf_pl_item, &i_last_shuf_pl_item,
|
2007-04-30 13:41:33 +00:00
|
|
|
/* queue */
|
2010-02-14 12:42:32 +00:00
|
|
|
|
2007-05-15 23:30:30 +00:00
|
|
|
&q_pl_item, &q_first_pl_item, &q_last_pl_item,
|
2010-02-14 12:42:32 +00:00
|
|
|
&q_shuf_pl_item, &q_last_shuf_pl_item,
|
2007-05-15 23:30:30 +00:00
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
/* replace */
|
|
|
|
&replace_pl_item
|
|
|
|
);
|
|
|
|
static int treeplaylist_callback(int action,
|
|
|
|
const struct menu_item_ex *this_item)
|
|
|
|
{
|
|
|
|
switch (action)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2007-04-30 13:41:33 +00:00
|
|
|
case ACTION_REQUEST_MENUITEM:
|
|
|
|
if (this_item == &tree_playlist_menu)
|
2006-04-19 02:22:23 +00:00
|
|
|
{
|
2010-02-14 12:42:32 +00:00
|
|
|
if (((selected_file_attr & FILE_ATTR_MASK) ==
|
2007-05-15 23:30:30 +00:00
|
|
|
FILE_ATTR_AUDIO) ||
|
2007-05-03 01:10:52 +00:00
|
|
|
((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)||
|
|
|
|
(selected_file_attr & ATTR_DIRECTORY))
|
2007-04-30 13:41:33 +00:00
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
2006-04-19 02:22:23 +00:00
|
|
|
}
|
2007-04-30 13:41:33 +00:00
|
|
|
else if (this_item == &view_playlist_item)
|
|
|
|
{
|
|
|
|
if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U &&
|
|
|
|
context == CONTEXT_TREE)
|
2010-02-14 12:42:32 +00:00
|
|
|
{
|
2007-04-30 13:41:33 +00:00
|
|
|
return action;
|
2010-02-14 12:42:32 +00:00
|
|
|
}
|
2007-04-30 13:41:33 +00:00
|
|
|
}
|
|
|
|
else if (this_item == &i_shuf_pl_item)
|
|
|
|
{
|
2010-02-14 12:42:32 +00:00
|
|
|
if ((audio_status() & AUDIO_STATUS_PLAY) ||
|
|
|
|
(selected_file_attr & ATTR_DIRECTORY) ||
|
|
|
|
((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U))
|
2007-04-30 13:41:33 +00:00
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
}
|
2009-11-01 14:25:38 +00:00
|
|
|
else if (this_item == &i_last_shuf_pl_item ||
|
2010-02-14 12:42:32 +00:00
|
|
|
this_item == &q_last_shuf_pl_item)
|
2009-10-28 22:27:38 +00:00
|
|
|
{
|
2009-11-01 14:25:38 +00:00
|
|
|
if ((playlist_amount() > 0) &&
|
|
|
|
(audio_status() & AUDIO_STATUS_PLAY) &&
|
|
|
|
((selected_file_attr & ATTR_DIRECTORY) ||
|
|
|
|
((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)))
|
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
2009-10-28 22:27:38 +00:00
|
|
|
}
|
2010-02-15 13:04:09 +00:00
|
|
|
return ACTION_EXIT_MENUITEM;
|
2007-04-30 13:41:33 +00:00
|
|
|
break;
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
2007-04-30 13:41:33 +00:00
|
|
|
return action;
|
2003-03-12 20:21:30 +00:00
|
|
|
}
|
|
|
|
|
2010-02-14 12:42:32 +00:00
|
|
|
|
|
|
|
/* playlist catalog options */
|
|
|
|
static bool cat_add_to_a_playlist(void)
|
|
|
|
{
|
|
|
|
return catalog_add_to_a_playlist(selected_file, selected_file_attr,
|
|
|
|
false, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool cat_add_to_a_new_playlist(void)
|
|
|
|
{
|
|
|
|
return catalog_add_to_a_playlist(selected_file, selected_file_attr,
|
|
|
|
true, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cat_playlist_callback(int action,
|
|
|
|
const struct menu_item_ex *this_item);
|
|
|
|
MENUITEM_FUNCTION(cat_view_lists, 0, ID2P(LANG_CATALOG_VIEW),
|
|
|
|
catalog_view_playlists, 0,
|
|
|
|
cat_playlist_callback, Icon_Playlist);
|
|
|
|
MENUITEM_FUNCTION(cat_add_to_list, 0, ID2P(LANG_CATALOG_ADD_TO),
|
|
|
|
cat_add_to_a_playlist, 0, NULL, Icon_Playlist);
|
|
|
|
MENUITEM_FUNCTION(cat_add_to_new, 0, ID2P(LANG_CATALOG_ADD_TO_NEW),
|
|
|
|
cat_add_to_a_new_playlist, 0, NULL, Icon_Playlist);
|
|
|
|
MAKE_ONPLAYMENU(cat_playlist_menu, ID2P(LANG_CATALOG),
|
|
|
|
cat_playlist_callback, Icon_Playlist,
|
|
|
|
&cat_view_lists, &cat_add_to_list, &cat_add_to_new);
|
|
|
|
|
|
|
|
static int cat_playlist_callback(int action,
|
|
|
|
const struct menu_item_ex *this_item)
|
|
|
|
{
|
2010-02-15 13:04:09 +00:00
|
|
|
if (!selected_file ||
|
|
|
|
(((selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) &&
|
|
|
|
((selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) &&
|
|
|
|
((selected_file_attr & ATTR_DIRECTORY) == 0)))
|
2010-02-14 12:42:32 +00:00
|
|
|
{
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
}
|
2010-02-21 12:01:14 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
if (context == CONTEXT_ID3DB &&
|
|
|
|
((selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO))
|
|
|
|
{
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
}
|
|
|
|
#endif
|
2010-02-14 12:42:32 +00:00
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case ACTION_REQUEST_MENUITEM:
|
|
|
|
if (this_item == &cat_view_lists)
|
|
|
|
{
|
2010-02-15 13:04:09 +00:00
|
|
|
return action;
|
2010-02-14 12:42:32 +00:00
|
|
|
}
|
2010-02-21 12:01:14 +00:00
|
|
|
else if ((audio_status() & AUDIO_STATUS_PLAY) ||
|
|
|
|
context != CONTEXT_WPS)
|
2010-02-14 12:42:32 +00:00
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static void draw_slider(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
struct viewport vp;
|
|
|
|
int slider_height = 2*screens[i].getcharheight();
|
|
|
|
viewport_set_defaults(&vp, i);
|
|
|
|
screens[i].set_viewport(&vp);
|
|
|
|
show_busy_slider(&screens[i], 1, vp.height - slider_height,
|
|
|
|
vp.width-2, slider_height-1);
|
|
|
|
screens[i].update_viewport();
|
|
|
|
screens[i].set_viewport(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define draw_slider()
|
|
|
|
#endif
|
|
|
|
|
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-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';
|
2010-02-14 12:42:32 +00:00
|
|
|
/* inform the user which dir we're deleting */
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, dirname);
|
2010-02-14 12:42:32 +00:00
|
|
|
|
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 */
|
|
|
|
|
|
|
|
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 */
|
2010-02-14 12:42:32 +00:00
|
|
|
draw_slider();
|
2004-04-08 06:38:56 +00:00
|
|
|
result = remove(dirname);
|
|
|
|
}
|
2006-12-14 22:43:16 +00:00
|
|
|
if(ACTION_STD_CANCEL == get_action(CONTEXT_STD,TIMEOUT_NOBLOCK))
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ, ID2P(LANG_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 */
|
2010-04-01 03:14:44 +00:00
|
|
|
static bool delete_file_dir(void)
|
2003-03-12 20:21:30 +00:00
|
|
|
{
|
2008-05-13 13:49:50 +00:00
|
|
|
char file_to_delete[MAX_PATH];
|
|
|
|
strcpy(file_to_delete, selected_file);
|
|
|
|
|
2008-04-26 09:30:24 +00:00
|
|
|
const char *lines[]={
|
2007-08-06 13:08:36 +00:00
|
|
|
ID2P(LANG_REALLY_DELETE),
|
2008-05-13 13:49:50 +00:00
|
|
|
file_to_delete
|
2005-11-22 22:19:08 +00:00
|
|
|
};
|
2008-04-26 09:30:24 +00:00
|
|
|
const char *yes_lines[]={
|
2008-09-11 20:13:02 +00:00
|
|
|
ID2P(LANG_DELETING),
|
2008-05-13 13:49:50 +00:00
|
|
|
file_to_delete
|
2005-11-22 22:19:08 +00:00
|
|
|
};
|
|
|
|
|
2008-11-30 12:33:58 +00:00
|
|
|
const struct text_message message={lines, 2};
|
|
|
|
const struct text_message yes_message={yes_lines, 2};
|
2007-05-20 10:04:39 +00:00
|
|
|
|
2005-11-22 22:19:08 +00:00
|
|
|
if(gui_syncyesno_run(&message, &yes_message, NULL)!=YESNO_YES)
|
|
|
|
return false;
|
2010-02-14 12:42:32 +00:00
|
|
|
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, str(LANG_DELETING));
|
2007-05-20 10:04:39 +00:00
|
|
|
|
2004-04-08 06:38:56 +00:00
|
|
|
int res;
|
2010-04-01 03:14:44 +00:00
|
|
|
if (selected_file_attr & ATTR_DIRECTORY) /* true if directory */
|
2005-11-22 22:19:08 +00:00
|
|
|
{
|
|
|
|
char pathname[MAX_PATH]; /* space to go deep */
|
2006-12-27 02:37:12 +00:00
|
|
|
cpu_boost(true);
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(pathname, file_to_delete, sizeof(pathname));
|
2005-11-22 22:19:08 +00:00
|
|
|
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
|
2008-05-13 13:49:50 +00:00
|
|
|
res = remove(file_to_delete);
|
2003-03-12 20:21:30 +00:00
|
|
|
|
2008-05-13 13:49:50 +00:00
|
|
|
if (!res)
|
2005-11-22 22:19:08 +00:00
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
2008-05-13 13:49:50 +00:00
|
|
|
|
2010-01-01 22:47:25 +00:00
|
|
|
return (res == 0);
|
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);
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(newname, selected_file, sizeof(newname));
|
2003-03-12 20:21:30 +00:00
|
|
|
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)) {
|
2007-08-06 13:08:36 +00:00
|
|
|
cond_talk_ids_fq(LANG_RENAME, LANG_FAILED);
|
2009-08-23 15:22:50 +00:00
|
|
|
splashf(HZ*2, "%s %s", str(LANG_RENAME), str(LANG_FAILED));
|
2003-03-12 20:21:30 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2010-02-14 12:42:32 +00:00
|
|
|
snprintf(dirname, sizeof dirname, "%s/", cwd[1] ? cwd : "");
|
2004-03-11 10:43:53 +00:00
|
|
|
|
|
|
|
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-08-06 13:08:36 +00:00
|
|
|
cond_talk_ids_fq(LANG_CREATE_DIR, LANG_FAILED);
|
2008-08-15 08:27:39 +00:00
|
|
|
splashf(HZ, (unsigned char *)"%s %s", str(LANG_CREATE_DIR),
|
|
|
|
str(LANG_FAILED));
|
2004-03-11 10:43:53 +00:00
|
|
|
} else {
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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;
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(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) {
|
2007-05-15 23:30:30 +00:00
|
|
|
/* Not large enough, try for a disk sector worth of stack
|
|
|
|
instead */
|
2006-03-20 11:46:06 +00:00
|
|
|
buffersize = 512;
|
|
|
|
buffer = (char *) __builtin_alloca(buffersize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-05-15 23:30:30 +00:00
|
|
|
buffersize &= ~0x1ff; /* Round buffer size to multiple of sector
|
|
|
|
size */
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
|
|
src_fd = open(src, O_RDONLY);
|
|
|
|
|
2006-03-22 02:18:44 +00:00
|
|
|
if (src_fd >= 0) {
|
2010-05-06 17:35:04 +00:00
|
|
|
target_fd = creat(target, 0666);
|
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);
|
|
|
|
|
2009-02-26 22:55:04 +00:00
|
|
|
if (byteswritten < 0) {
|
2006-03-20 11:46:06 +00:00
|
|
|
result = false;
|
|
|
|
size = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesread -= byteswritten;
|
2007-08-05 10:25:00 +00:00
|
|
|
draw_slider();
|
2006-03-20 11:46:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2007-05-15 23:30:30 +00:00
|
|
|
/* Failed because cross volume rename doesn't work. Copy
|
|
|
|
instead */
|
2006-03-20 11:46:06 +00:00
|
|
|
result = clipboard_pastefile(src, target, true);
|
|
|
|
|
|
|
|
if (result) {
|
2007-08-22 00:05:29 +00:00
|
|
|
result = remove(src) == 0;
|
2006-03-20 11:46:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-05-15 23:30:30 +00:00
|
|
|
/* 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)
|
2006-03-20 11:46:06 +00:00
|
|
|
{
|
|
|
|
DIR *srcdir;
|
|
|
|
int srcdirlen = strlen(src);
|
|
|
|
int targetdirlen = strlen(target);
|
|
|
|
bool result = true;
|
|
|
|
|
2008-04-16 19:51:43 +00:00
|
|
|
if (!file_exists(target)) {
|
2006-03-20 11:46:06 +00:00
|
|
|
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 */
|
2007-05-15 23:30:30 +00:00
|
|
|
result = clipboard_pastedirectory(src, srclen, target,
|
|
|
|
targetlen, true);
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
|
|
/* 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);
|
2007-05-15 23:30:30 +00:00
|
|
|
snprintf(target+targetdirlen, targetlen-targetdirlen, "/%s",
|
|
|
|
entry->d_name);
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2007-05-15 23:30:30 +00:00
|
|
|
result = clipboard_pastedirectory(src, srclen, target, targetlen,
|
|
|
|
copy); /* recursion */
|
2006-03-20 11:46:06 +00:00
|
|
|
}
|
2006-03-22 02:18:44 +00:00
|
|
|
else
|
2006-03-20 11:46:06 +00:00
|
|
|
{ /* copy/move a file */
|
2010-02-14 12:42:32 +00:00
|
|
|
draw_slider();
|
2006-03-20 11:46:06 +00:00
|
|
|
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;
|
|
|
|
|
2008-04-26 09:30:24 +00:00
|
|
|
static const char *lines[]={ID2P(LANG_REALLY_OVERWRITE)};
|
|
|
|
static const struct text_message message={lines, 1};
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
/* If the target existed but they choose not to overwite, exit */
|
2008-04-16 19:51:43 +00:00
|
|
|
if (file_exists(target) &&
|
2006-03-20 11:46:06 +00:00
|
|
|
(gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-05-20 10:04:39 +00:00
|
|
|
if (clipboard_is_copy) {
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, ID2P(LANG_COPYING));
|
2007-05-20 10:04:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, ID2P(LANG_MOVING));
|
2007-05-20 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 11:46:06 +00:00
|
|
|
/* Now figure out what we're doing */
|
2007-05-20 10:04:39 +00:00
|
|
|
cpu_boost(true);
|
2006-03-20 11:46:06 +00:00
|
|
|
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)))
|
|
|
|
{
|
2007-05-15 23:30:30 +00:00
|
|
|
/* Do not allow the user to paste a directory into a dir they are
|
|
|
|
copying */
|
2007-02-27 10:06:55 +00:00
|
|
|
success = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(srcpath, clipboard_selection, sizeof(srcpath));
|
|
|
|
strlcpy(targetpath, target, sizeof(targetpath));
|
2010-02-14 12:42:32 +00:00
|
|
|
|
2007-02-27 10:06:55 +00:00
|
|
|
success = clipboard_pastedirectory(srcpath, sizeof(srcpath),
|
|
|
|
target, sizeof(targetpath), clipboard_is_copy);
|
2008-12-01 11:31:22 +00:00
|
|
|
|
|
|
|
if (success && !clipboard_is_copy)
|
|
|
|
{
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(srcpath, clipboard_selection, sizeof(srcpath));
|
2008-12-01 11:31:22 +00:00
|
|
|
remove_dir(srcpath, sizeof(srcpath));
|
|
|
|
}
|
2007-02-27 10:06:55 +00:00
|
|
|
}
|
2006-03-20 11:46:06 +00:00
|
|
|
} else {
|
2007-05-15 23:30:30 +00:00
|
|
|
success = clipboard_pastefile(clipboard_selection, target,
|
|
|
|
clipboard_is_copy);
|
2006-03-20 11:46:06 +00:00
|
|
|
}
|
2007-05-20 10:04:39 +00:00
|
|
|
cpu_boost(false);
|
2006-03-20 11:46:06 +00:00
|
|
|
|
|
|
|
/* 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-08-06 13:08:36 +00:00
|
|
|
cond_talk_ids_fq(LANG_PASTE, LANG_FAILED);
|
2008-08-15 08:27:39 +00:00
|
|
|
splashf(HZ, (unsigned char *)"%s %s", str(LANG_PASTE),
|
|
|
|
str(LANG_FAILED));
|
2006-03-20 11:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-26 23:10:40 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2007-11-08 14:00:36 +00:00
|
|
|
static int set_rating_inline(void)
|
2007-03-26 15:08:59 +00:00
|
|
|
{
|
|
|
|
struct mp3entry* id3 = audio_current_track();
|
2010-02-14 12:42:32 +00:00
|
|
|
if (id3 && id3->tagcache_idx && global_settings.runtimedb)
|
2007-07-21 17:35:19 +00:00
|
|
|
{
|
2007-11-08 14:00:36 +00:00
|
|
|
set_int_ex(str(LANG_MENU_SET_RATING), "", UNIT_INT, (void*)(&id3->rating),
|
|
|
|
NULL, 1, 0, 10, NULL, NULL);
|
2008-02-12 18:51:10 +00:00
|
|
|
tagcache_update_numeric(id3->tagcache_idx-1, tag_rating, id3->rating);
|
2007-04-30 13:41:33 +00:00
|
|
|
}
|
2007-11-08 14:00:36 +00:00
|
|
|
else
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_ID3_NO_INFO));
|
2007-11-08 14:00:36 +00:00
|
|
|
return 0;
|
2007-04-30 13:41:33 +00:00
|
|
|
}
|
2007-11-08 16:31:44 +00:00
|
|
|
static int ratingitem_callback(int action,const struct menu_item_ex *this_item)
|
|
|
|
{
|
|
|
|
(void)this_item;
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case ACTION_REQUEST_MENUITEM:
|
2008-12-21 09:58:11 +00:00
|
|
|
if (!selected_file || !global_settings.runtimedb ||
|
|
|
|
!tagcache_is_usable())
|
2007-11-08 16:31:44 +00:00
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
2010-02-14 12:42:32 +00:00
|
|
|
MENUITEM_FUNCTION(rating_item, 0, ID2P(LANG_MENU_SET_RATING),
|
|
|
|
set_rating_inline, NULL,
|
2007-11-08 16:31:44 +00:00
|
|
|
ratingitem_callback, Icon_Questionmark);
|
2007-03-26 23:10:40 +00:00
|
|
|
#endif
|
2006-03-22 02:18:44 +00:00
|
|
|
|
2007-05-14 17:34:52 +00:00
|
|
|
static bool view_cue(void)
|
|
|
|
{
|
|
|
|
struct mp3entry* id3 = audio_current_track();
|
2009-07-20 05:18:18 +00:00
|
|
|
if(id3 && id3->cuesheet)
|
2007-05-14 17:34:52 +00:00
|
|
|
{
|
2009-07-20 05:18:18 +00:00
|
|
|
browse_cuesheet(id3->cuesheet);
|
2007-05-14 17:34:52 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-15 23:30:30 +00:00
|
|
|
static int view_cue_item_callback(int action,
|
|
|
|
const struct menu_item_ex *this_item)
|
2007-05-14 17:34:52 +00:00
|
|
|
{
|
|
|
|
(void)this_item;
|
|
|
|
struct mp3entry* id3 = audio_current_track();
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case ACTION_REQUEST_MENUITEM:
|
2009-07-20 05:18:18 +00:00
|
|
|
if (!selected_file
|
|
|
|
|| !id3 || !id3->cuesheet)
|
2007-05-14 17:34:52 +00:00
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
MENUITEM_FUNCTION(view_cue_item, 0, ID2P(LANG_BROWSE_CUESHEET),
|
|
|
|
view_cue, NULL, view_cue_item_callback, Icon_NOICON);
|
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
/* CONTEXT_WPS items */
|
2010-05-09 02:02:51 +00:00
|
|
|
MENUITEM_FUNCTION(browse_id3_item, 0, ID2P(LANG_MENU_SHOW_ID3_INFO),
|
2007-04-30 13:41:33 +00:00
|
|
|
browse_id3, NULL, NULL, Icon_NOICON);
|
|
|
|
#ifdef HAVE_PITCHSCREEN
|
2010-05-09 02:02:51 +00:00
|
|
|
MENUITEM_FUNCTION(pitch_screen_item, 0, ID2P(LANG_PITCH),
|
2008-10-05 13:01:54 +00:00
|
|
|
gui_syncpitchscreen_run, NULL, NULL, Icon_Audio);
|
2007-04-30 13:41:33 +00:00
|
|
|
#endif
|
2008-05-04 13:47:58 +00:00
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
/* CONTEXT_[TREE|ID3DB] items */
|
|
|
|
static int clipboard_callback(int action,const struct menu_item_ex *this_item);
|
|
|
|
MENUITEM_FUNCTION(rename_file_item, 0, ID2P(LANG_RENAME),
|
|
|
|
rename_file, NULL, clipboard_callback, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(clipboard_cut_item, 0, ID2P(LANG_CUT),
|
|
|
|
clipboard_cut, NULL, clipboard_callback, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(clipboard_copy_item, 0, ID2P(LANG_COPY),
|
|
|
|
clipboard_copy, NULL, clipboard_callback, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(clipboard_paste_item, 0, ID2P(LANG_PASTE),
|
|
|
|
clipboard_paste, NULL, clipboard_callback, Icon_NOICON);
|
2010-05-09 02:02:51 +00:00
|
|
|
MENUITEM_FUNCTION(delete_file_item, 0, ID2P(LANG_DELETE),
|
2010-04-01 03:14:44 +00:00
|
|
|
delete_file_dir, NULL, clipboard_callback, Icon_NOICON);
|
2010-05-09 02:02:51 +00:00
|
|
|
MENUITEM_FUNCTION(delete_dir_item, 0, ID2P(LANG_DELETE_DIR),
|
2010-04-01 03:14:44 +00:00
|
|
|
delete_file_dir, NULL, clipboard_callback, Icon_NOICON);
|
2007-04-30 13:41:33 +00:00
|
|
|
MENUITEM_FUNCTION(create_dir_item, 0, ID2P(LANG_CREATE_DIR),
|
|
|
|
create_dir, NULL, clipboard_callback, Icon_NOICON);
|
2010-02-14 12:42:32 +00:00
|
|
|
|
|
|
|
/* other items */
|
|
|
|
static bool list_viewers(void)
|
|
|
|
{
|
|
|
|
int ret = filetype_list_viewers(selected_file);
|
|
|
|
if (ret == PLUGIN_USB_CONNECTED)
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool onplay_load_plugin(void *param)
|
|
|
|
{
|
|
|
|
int ret = filetype_load_plugin((const char*)param, selected_file);
|
|
|
|
if (ret == PLUGIN_USB_CONNECTED)
|
|
|
|
onplay_result = ONPLAY_RELOAD_DIR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-09 02:02:51 +00:00
|
|
|
MENUITEM_FUNCTION(list_viewers_item, 0, ID2P(LANG_ONPLAY_OPEN_WITH),
|
2007-04-30 13:41:33 +00:00
|
|
|
list_viewers, NULL, clipboard_callback, Icon_NOICON);
|
2010-02-14 12:42:32 +00:00
|
|
|
MENUITEM_FUNCTION(properties_item, MENU_FUNC_USEPARAM, ID2P(LANG_PROPERTIES),
|
|
|
|
onplay_load_plugin, (void *)"properties",
|
|
|
|
clipboard_callback, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(add_to_faves_item, MENU_FUNC_USEPARAM, ID2P(LANG_ADD_TO_FAVES),
|
|
|
|
onplay_load_plugin, (void *)"shortcuts_append",
|
|
|
|
clipboard_callback, Icon_NOICON);
|
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
#if LCD_DEPTH > 1
|
2010-02-14 12:42:32 +00:00
|
|
|
static bool set_backdrop(void)
|
|
|
|
{
|
|
|
|
/* load the image */
|
|
|
|
if(sb_set_backdrop(SCREEN_MAIN, selected_file)) {
|
|
|
|
splash(HZ, str(LANG_BACKDROP_LOADED));
|
|
|
|
set_file(selected_file, (char *)global_settings.backdrop_file,
|
|
|
|
MAX_FILENAME);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
splash(HZ, str(LANG_BACKDROP_FAILED));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-04-30 13:41:33 +00:00
|
|
|
MENUITEM_FUNCTION(set_backdrop_item, 0, ID2P(LANG_SET_AS_BACKDROP),
|
|
|
|
set_backdrop, NULL, clipboard_callback, Icon_NOICON);
|
2005-01-04 22:12:02 +00:00
|
|
|
#endif
|
2007-07-10 07:41:37 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
static bool set_recdir(void)
|
|
|
|
{
|
2010-02-15 13:04:09 +00:00
|
|
|
strlcpy(global_settings.rec_directory, selected_file, MAX_FILENAME+1);
|
2008-02-10 18:28:59 +00:00
|
|
|
settings_save();
|
2007-07-10 07:41:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MENUITEM_FUNCTION(set_recdir_item, 0, ID2P(LANG_SET_AS_REC_DIR),
|
|
|
|
set_recdir, NULL, clipboard_callback, Icon_Recording);
|
|
|
|
#endif
|
2006-03-20 11:46:06 +00:00
|
|
|
|
2007-04-30 13:41:33 +00:00
|
|
|
static int clipboard_callback(int action,const struct menu_item_ex *this_item)
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case ACTION_REQUEST_MENUITEM:
|
2008-04-21 14:52:42 +00:00
|
|
|
#ifdef HAVE_MULTIVOLUME
|
|
|
|
if ((selected_file_attr & FAT_ATTR_VOLUME) &&
|
|
|
|
(this_item == &rename_file_item ||
|
|
|
|
this_item == &delete_dir_item ||
|
|
|
|
this_item == &clipboard_cut_item) )
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
2010-02-15 13:04:09 +00:00
|
|
|
/* no rename+delete for volumes */
|
|
|
|
if ((selected_file_attr & ATTR_VOLUME) &&
|
|
|
|
(this_item == &delete_file_item ||
|
|
|
|
this_item == &list_viewers_item))
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
2008-04-21 14:52:42 +00:00
|
|
|
#endif
|
2010-02-15 13:04:09 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2007-04-30 13:41:33 +00:00
|
|
|
if (context == CONTEXT_ID3DB)
|
2010-02-21 12:01:14 +00:00
|
|
|
{
|
|
|
|
if (((selected_file_attr & FILE_ATTR_MASK) ==
|
|
|
|
FILE_ATTR_AUDIO) &&
|
|
|
|
this_item == &properties_item)
|
|
|
|
return action;
|
2007-04-30 13:41:33 +00:00
|
|
|
return ACTION_EXIT_MENUITEM;
|
2010-02-21 12:01:14 +00:00
|
|
|
}
|
2010-02-15 13:04:09 +00:00
|
|
|
#endif
|
2007-04-30 13:41:33 +00:00
|
|
|
if (this_item == &clipboard_paste_item)
|
|
|
|
{ /* visible if there is something to paste */
|
|
|
|
return (clipboard_selection[0] != 0) ?
|
|
|
|
action : ACTION_EXIT_MENUITEM;
|
2005-06-23 01:31:26 +00:00
|
|
|
}
|
2010-02-14 12:42:32 +00:00
|
|
|
else if (this_item == &create_dir_item)
|
2008-04-09 13:50:33 +00:00
|
|
|
{
|
|
|
|
/* always visible */
|
|
|
|
return action;
|
|
|
|
}
|
2010-02-15 13:04:09 +00:00
|
|
|
else if (selected_file)
|
2005-01-04 22:12:02 +00:00
|
|
|
{
|
2010-02-14 12:42:32 +00:00
|
|
|
/* requires an actual file */
|
2010-02-15 13:04:09 +00:00
|
|
|
if (this_item == &rename_file_item ||
|
|
|
|
this_item == &clipboard_cut_item ||
|
|
|
|
this_item == &clipboard_copy_item ||
|
|
|
|
this_item == &properties_item ||
|
|
|
|
this_item == &add_to_faves_item)
|
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
else if ((selected_file_attr & ATTR_DIRECTORY))
|
|
|
|
{
|
|
|
|
/* only for directories */
|
|
|
|
if (this_item == &delete_dir_item
|
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
|| this_item == &set_recdir_item
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
else if (this_item == &delete_file_item ||
|
|
|
|
this_item == &list_viewers_item)
|
|
|
|
{
|
|
|
|
/* only for files */
|
|
|
|
return action;
|
|
|
|
}
|
2006-11-13 00:45:21 +00:00
|
|
|
#if LCD_DEPTH > 1
|
2010-02-15 13:04:09 +00:00
|
|
|
else if (this_item == &set_backdrop_item)
|
2006-03-20 11:46:06 +00:00
|
|
|
{
|
2007-04-30 13:41:33 +00:00
|
|
|
char *suffix = strrchr(selected_file, '.');
|
|
|
|
if (suffix)
|
2006-03-20 11:46:06 +00:00
|
|
|
{
|
2007-04-30 13:41:33 +00:00
|
|
|
if (strcasecmp(suffix, ".bmp") == 0)
|
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
2006-02-02 20:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-30 13:41:33 +00:00
|
|
|
#endif
|
2005-01-04 22:12:02 +00:00
|
|
|
}
|
2007-04-30 13:41:33 +00:00
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
break;
|
2005-06-23 01:31:26 +00:00
|
|
|
}
|
2007-04-30 13:41:33 +00:00
|
|
|
return action;
|
|
|
|
}
|
2006-11-30 22:29:48 +00:00
|
|
|
|
2010-02-14 12:42:32 +00:00
|
|
|
static int onplaymenu_callback(int action,const struct menu_item_ex *this_item);
|
|
|
|
/* used when onplay() is called in the CONTEXT_WPS context */
|
|
|
|
MAKE_ONPLAYMENU( wps_onplay_menu, ID2P(LANG_ONPLAY_MENU_TITLE),
|
2007-04-30 13:41:33 +00:00
|
|
|
onplaymenu_callback, Icon_Audio,
|
2008-05-22 16:28:20 +00:00
|
|
|
&wps_playlist_menu, &cat_playlist_menu,
|
|
|
|
&sound_settings, &playback_settings,
|
2007-04-30 13:41:33 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2010-02-14 12:42:32 +00:00
|
|
|
&rating_item,
|
2007-04-30 13:41:33 +00:00
|
|
|
#endif
|
2008-05-22 16:28:20 +00:00
|
|
|
&bookmark_menu, &browse_id3_item, &list_viewers_item,
|
|
|
|
&delete_file_item, &view_cue_item,
|
2006-08-16 13:25:45 +00:00
|
|
|
#ifdef HAVE_PITCHSCREEN
|
2007-04-30 13:41:33 +00:00
|
|
|
&pitch_screen_item,
|
2006-03-22 02:44:18 +00:00
|
|
|
#endif
|
2007-04-30 13:41:33 +00:00
|
|
|
);
|
|
|
|
/* used when onplay() is not called in the CONTEXT_WPS context */
|
2010-02-14 12:42:32 +00:00
|
|
|
MAKE_ONPLAYMENU( tree_onplay_menu, ID2P(LANG_ONPLAY_MENU_TITLE),
|
2007-04-30 13:41:33 +00:00
|
|
|
onplaymenu_callback, Icon_file_view_menu,
|
|
|
|
&tree_playlist_menu, &cat_playlist_menu,
|
|
|
|
&rename_file_item, &clipboard_cut_item, &clipboard_copy_item,
|
|
|
|
&clipboard_paste_item, &delete_file_item, &delete_dir_item,
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
&set_backdrop_item,
|
|
|
|
#endif
|
2007-07-10 07:41:37 +00:00
|
|
|
&list_viewers_item, &create_dir_item, &properties_item,
|
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
&set_recdir_item,
|
|
|
|
#endif
|
2007-08-05 12:14:07 +00:00
|
|
|
&add_to_faves_item,
|
2007-04-30 13:41:33 +00:00
|
|
|
);
|
2007-11-04 12:40:18 +00:00
|
|
|
static int onplaymenu_callback(int action,const struct menu_item_ex *this_item)
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case ACTION_TREE_STOP:
|
|
|
|
if (this_item == &wps_onplay_menu)
|
|
|
|
{
|
|
|
|
list_stop_handler();
|
|
|
|
return ACTION_STD_CANCEL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACTION_EXIT_MENUITEM:
|
|
|
|
return ACTION_EXIT_AFTER_THIS_MENUITEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
2010-04-01 03:14:44 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_HOTKEY
|
|
|
|
/* direct function calls, no need for menu callbacks */
|
|
|
|
static bool delete_item(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_MULTIVOLUME
|
|
|
|
/* no delete for volumes */
|
|
|
|
if ((selected_file_attr & FAT_ATTR_VOLUME) ||
|
|
|
|
(selected_file_attr & ATTR_VOLUME))
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
return delete_file_dir();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool open_with(void)
|
|
|
|
{
|
|
|
|
/* only open files */
|
|
|
|
if (selected_file_attr & ATTR_DIRECTORY)
|
|
|
|
return false;
|
|
|
|
#ifdef HAVE_MULTIVOLUME
|
|
|
|
if (selected_file_attr & ATTR_VOLUME)
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
return list_viewers();
|
|
|
|
}
|
|
|
|
|
2010-05-11 13:40:25 +00:00
|
|
|
static int playlist_insert_shuffled(void)
|
|
|
|
{
|
|
|
|
if ((audio_status() & AUDIO_STATUS_PLAY) ||
|
|
|
|
(selected_file_attr & ATTR_DIRECTORY) ||
|
|
|
|
((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U))
|
|
|
|
{
|
|
|
|
playlist_insert_func((intptr_t*)PLAYLIST_INSERT_SHUFFLED);
|
|
|
|
return ONPLAY_START_PLAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ONPLAY_RELOAD_DIR;
|
|
|
|
}
|
|
|
|
|
2010-04-10 19:43:47 +00:00
|
|
|
struct hotkey_assignment {
|
2010-05-11 04:41:15 +00:00
|
|
|
int action; /* hotkey_action */
|
|
|
|
int lang_id; /* Language ID */
|
2010-04-10 20:31:01 +00:00
|
|
|
struct menu_func func; /* Function to run if this entry is selected */
|
|
|
|
int return_code; /* What to return after the function is run */
|
2010-04-10 19:43:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define HOTKEY_FUNC(func, param) {{(void *)func}, param}
|
|
|
|
|
2010-05-09 02:02:51 +00:00
|
|
|
/* Any desired hotkey functions go here, in the enum in onplay.h,
|
|
|
|
and in the settings menu in settings_list.c. The order here
|
|
|
|
is not important. */
|
2010-04-01 03:14:44 +00:00
|
|
|
static struct hotkey_assignment hotkey_items[] = {
|
2010-05-11 04:41:15 +00:00
|
|
|
{ HOTKEY_VIEW_PLAYLIST, LANG_VIEW_DYNAMIC_PLAYLIST,
|
2010-04-01 03:14:44 +00:00
|
|
|
HOTKEY_FUNC(NULL, NULL),
|
2010-05-11 04:41:15 +00:00
|
|
|
ONPLAY_PLAYLIST },
|
|
|
|
{ HOTKEY_SHOW_TRACK_INFO, LANG_MENU_SHOW_ID3_INFO,
|
2010-04-01 03:14:44 +00:00
|
|
|
HOTKEY_FUNC(browse_id3, NULL),
|
2010-05-11 04:41:15 +00:00
|
|
|
ONPLAY_RELOAD_DIR },
|
2010-04-01 03:14:44 +00:00
|
|
|
#ifdef HAVE_PITCHSCREEN
|
2010-05-11 04:41:15 +00:00
|
|
|
{ HOTKEY_PITCHSCREEN, LANG_PITCH,
|
2010-04-01 03:14:44 +00:00
|
|
|
HOTKEY_FUNC(gui_syncpitchscreen_run, NULL),
|
2010-05-11 04:41:15 +00:00
|
|
|
ONPLAY_RELOAD_DIR },
|
2010-04-01 03:14:44 +00:00
|
|
|
#endif
|
2010-05-11 04:41:15 +00:00
|
|
|
{ HOTKEY_OPEN_WITH, LANG_ONPLAY_OPEN_WITH,
|
2010-04-01 03:14:44 +00:00
|
|
|
HOTKEY_FUNC(open_with, NULL),
|
2010-05-11 04:41:15 +00:00
|
|
|
ONPLAY_RELOAD_DIR },
|
|
|
|
{ HOTKEY_DELETE, LANG_DELETE,
|
2010-04-01 03:14:44 +00:00
|
|
|
HOTKEY_FUNC(delete_item, NULL),
|
2010-05-11 04:41:15 +00:00
|
|
|
ONPLAY_RELOAD_DIR },
|
|
|
|
{ HOTKEY_INSERT, LANG_INSERT,
|
2010-04-01 03:14:44 +00:00
|
|
|
HOTKEY_FUNC(playlist_insert_func, (intptr_t*)PLAYLIST_INSERT),
|
2010-05-11 04:41:15 +00:00
|
|
|
ONPLAY_START_PLAY },
|
2010-05-11 13:40:25 +00:00
|
|
|
{ HOTKEY_INSERT_SHUFFLED, LANG_INSERT_SHUFFLED,
|
|
|
|
HOTKEY_FUNC(playlist_insert_shuffled, NULL),
|
|
|
|
ONPLAY_OK },
|
2010-04-01 03:14:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int num_hotkey_items = sizeof(hotkey_items) / sizeof(hotkey_items[0]);
|
|
|
|
|
2010-05-11 04:41:15 +00:00
|
|
|
/* Return the language ID for this action */
|
|
|
|
int get_hotkey_lang_id(int action)
|
2010-04-08 01:43:50 +00:00
|
|
|
{
|
2010-05-11 04:41:15 +00:00
|
|
|
int i = num_hotkey_items;
|
|
|
|
while (i--)
|
2010-04-08 01:43:50 +00:00
|
|
|
{
|
2010-05-11 04:41:15 +00:00
|
|
|
if (hotkey_items[i].action == action)
|
2010-05-09 02:02:51 +00:00
|
|
|
return hotkey_items[i].lang_id;
|
2010-04-08 01:43:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-09 02:02:51 +00:00
|
|
|
return LANG_OFF;
|
2010-04-08 01:43:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 04:41:15 +00:00
|
|
|
/* Execute the hotkey function, if listed */
|
2010-04-01 03:14:44 +00:00
|
|
|
static int execute_hotkey(bool is_wps)
|
|
|
|
{
|
2010-05-11 04:41:15 +00:00
|
|
|
int i = num_hotkey_items;
|
2010-04-01 03:14:44 +00:00
|
|
|
struct hotkey_assignment *this_item;
|
2010-05-11 04:41:15 +00:00
|
|
|
const int action = (is_wps ? global_settings.hotkey_wps :
|
2010-04-01 03:14:44 +00:00
|
|
|
global_settings.hotkey_tree);
|
|
|
|
|
|
|
|
/* search assignment struct for a match for the hotkey setting */
|
2010-05-11 04:41:15 +00:00
|
|
|
while (i--)
|
2010-04-01 03:14:44 +00:00
|
|
|
{
|
|
|
|
this_item = &hotkey_items[i];
|
2010-05-11 04:41:15 +00:00
|
|
|
if (this_item->action == action)
|
2010-04-01 03:14:44 +00:00
|
|
|
{
|
|
|
|
/* run the associated function (with optional param), if any */
|
|
|
|
const struct menu_func func = this_item->func;
|
2010-05-11 13:40:25 +00:00
|
|
|
int func_return;
|
2010-04-01 03:14:44 +00:00
|
|
|
if (func.function != NULL)
|
|
|
|
{
|
|
|
|
if (func.param != NULL)
|
2010-05-11 13:40:25 +00:00
|
|
|
func_return = (*func.function_w_param)(func.param);
|
2010-04-01 03:14:44 +00:00
|
|
|
else
|
2010-05-11 13:40:25 +00:00
|
|
|
func_return = (*func.function)();
|
2010-04-01 03:14:44 +00:00
|
|
|
}
|
|
|
|
/* return with the associated code */
|
2010-05-11 13:40:25 +00:00
|
|
|
const int return_code = this_item->return_code;
|
|
|
|
/* ONPLAY_OK here means to use the function return code */
|
|
|
|
if (return_code == ONPLAY_OK)
|
|
|
|
return func_return;
|
|
|
|
return return_code;
|
2010-04-01 03:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-09 02:02:51 +00:00
|
|
|
/* no valid hotkey set, ignore hotkey */
|
2010-04-01 03:14:44 +00:00
|
|
|
return ONPLAY_RELOAD_DIR;
|
|
|
|
}
|
|
|
|
#endif /* HOTKEY */
|
|
|
|
|
|
|
|
int onplay(char* file, int attr, int from, bool hotkey)
|
2007-04-30 13:41:33 +00:00
|
|
|
{
|
2007-11-08 14:00:36 +00:00
|
|
|
const struct menu_item_ex *menu;
|
2007-04-30 13:41:33 +00:00
|
|
|
onplay_result = ONPLAY_OK;
|
|
|
|
context = from;
|
|
|
|
selected_file = file;
|
|
|
|
selected_file_attr = attr;
|
2010-04-08 14:34:14 +00:00
|
|
|
int menu_selection;
|
2010-04-01 03:14:44 +00:00
|
|
|
#ifdef HAVE_HOTKEY
|
|
|
|
if (hotkey)
|
|
|
|
return execute_hotkey(context == CONTEXT_WPS);
|
|
|
|
#else
|
|
|
|
(void)hotkey;
|
|
|
|
#endif
|
2007-04-30 13:41:33 +00:00
|
|
|
if (context == CONTEXT_WPS)
|
2007-11-08 14:00:36 +00:00
|
|
|
menu = &wps_onplay_menu;
|
2007-04-30 13:41:33 +00:00
|
|
|
else
|
2007-11-08 14:00:36 +00:00
|
|
|
menu = &tree_onplay_menu;
|
2010-04-08 14:34:14 +00:00
|
|
|
menu_selection = do_menu(menu, NULL, NULL, false);
|
|
|
|
switch (menu_selection)
|
|
|
|
{
|
2007-04-30 13:41:33 +00:00
|
|
|
case GO_TO_WPS:
|
|
|
|
return ONPLAY_START_PLAY;
|
|
|
|
case GO_TO_ROOT:
|
|
|
|
case GO_TO_MAINMENU:
|
|
|
|
return ONPLAY_MAINMENU;
|
2010-02-20 19:06:39 +00:00
|
|
|
case GO_TO_PLAYLIST_VIEWER:
|
|
|
|
return ONPLAY_PLAYLIST;
|
2007-04-30 13:41:33 +00:00
|
|
|
default:
|
2010-02-15 13:04:09 +00:00
|
|
|
return onplay_result;
|
2007-04-30 13:41:33 +00:00
|
|
|
}
|
2003-03-12 20:21:30 +00:00
|
|
|
}
|