2011-11-15 13:22:02 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Jonathan Gordon
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
2015-05-18 19:51:56 +00:00
|
|
|
#include <dir.h>
|
2011-11-15 13:22:02 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
2011-12-06 12:07:44 +00:00
|
|
|
#include "powermgmt.h"
|
|
|
|
#include "power.h"
|
2011-11-15 13:22:02 +00:00
|
|
|
#include "action.h"
|
|
|
|
#include "ata_idle_notify.h"
|
|
|
|
#include "debug_menu.h"
|
|
|
|
#include "core_alloc.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "settings_list.h"
|
2021-04-10 14:42:38 +00:00
|
|
|
#include "string-extra.h"
|
2011-11-15 13:22:02 +00:00
|
|
|
#include "lang.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "misc.h"
|
2020-08-01 02:45:10 +00:00
|
|
|
#include "open_plugin.h"
|
2011-11-15 13:22:02 +00:00
|
|
|
#include "tree.h"
|
|
|
|
#include "splash.h"
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
#include "pathfuncs.h"
|
2011-11-15 13:22:02 +00:00
|
|
|
#include "filetypes.h"
|
|
|
|
#include "shortcuts.h"
|
|
|
|
#include "onplay.h"
|
2011-12-06 12:07:44 +00:00
|
|
|
#include "screens.h"
|
2011-12-11 10:27:14 +00:00
|
|
|
#include "talk.h"
|
2012-07-26 07:51:51 +00:00
|
|
|
#include "yesno.h"
|
2021-11-19 04:11:13 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
#include "playback.h"
|
|
|
|
#endif
|
2011-11-15 13:22:02 +00:00
|
|
|
|
|
|
|
#define MAX_SHORTCUT_NAME 32
|
|
|
|
#define SHORTCUTS_FILENAME ROCKBOX_DIR "/shortcuts.txt"
|
2011-12-05 19:35:27 +00:00
|
|
|
static const char * const type_strings[SHORTCUT_TYPE_COUNT] = {
|
2011-11-15 13:22:02 +00:00
|
|
|
[SHORTCUT_SETTING] = "setting",
|
|
|
|
[SHORTCUT_FILE] = "file",
|
|
|
|
[SHORTCUT_DEBUGITEM] = "debug",
|
|
|
|
[SHORTCUT_BROWSER] = "browse",
|
|
|
|
[SHORTCUT_PLAYLISTMENU] = "playlist menu",
|
|
|
|
[SHORTCUT_SEPARATOR] = "separator",
|
2011-12-06 12:02:49 +00:00
|
|
|
[SHORTCUT_SHUTDOWN] = "shutdown",
|
2011-12-08 10:23:46 +00:00
|
|
|
[SHORTCUT_TIME] = "time",
|
2011-11-15 13:22:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct shortcut {
|
|
|
|
enum shortcut_type type;
|
|
|
|
char name[MAX_SHORTCUT_NAME];
|
2011-12-11 10:27:14 +00:00
|
|
|
char talk_clip[MAX_PATH];
|
2011-11-15 13:22:02 +00:00
|
|
|
int icon;
|
|
|
|
union {
|
|
|
|
char path[MAX_PATH];
|
|
|
|
const struct settings_list *setting;
|
2011-12-08 10:23:46 +00:00
|
|
|
struct {
|
|
|
|
#if CONFIG_RTC
|
|
|
|
bool talktime;
|
|
|
|
#endif
|
|
|
|
int sleep_timeout;
|
|
|
|
} timedata;
|
2011-11-15 13:22:02 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
#define SHORTCUTS_PER_HANDLE 32
|
|
|
|
struct shortcut_handle {
|
|
|
|
struct shortcut shortcuts[SHORTCUTS_PER_HANDLE];
|
|
|
|
int next_handle;
|
|
|
|
};
|
|
|
|
static int first_handle = 0;
|
|
|
|
static int shortcut_count = 0;
|
|
|
|
|
2015-01-02 00:06:06 +00:00
|
|
|
static int buflib_move_lock;
|
|
|
|
static int move_callback(int handle, void *current, void *new)
|
|
|
|
{
|
|
|
|
(void)handle;
|
|
|
|
(void)current;
|
|
|
|
(void)new;
|
|
|
|
|
|
|
|
if (buflib_move_lock > 0)
|
|
|
|
return BUFLIB_CB_CANNOT_MOVE;
|
|
|
|
|
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
|
|
|
static struct buflib_callbacks shortcut_ops = {
|
|
|
|
.move_callback = move_callback,
|
|
|
|
};
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
static void reset_shortcuts(void)
|
|
|
|
{
|
|
|
|
int current_handle = first_handle;
|
|
|
|
struct shortcut_handle *h = NULL;
|
|
|
|
while (current_handle > 0)
|
|
|
|
{
|
|
|
|
int next;
|
|
|
|
h = core_get_data(current_handle);
|
|
|
|
next = h->next_handle;
|
|
|
|
core_free(current_handle);
|
|
|
|
current_handle = next;
|
|
|
|
}
|
|
|
|
first_handle = 0;
|
|
|
|
shortcut_count = 0;
|
2015-01-02 00:06:06 +00:00
|
|
|
}
|
2011-11-15 13:22:02 +00:00
|
|
|
|
|
|
|
static struct shortcut* get_shortcut(int index)
|
|
|
|
{
|
|
|
|
int handle_count, handle_index;
|
|
|
|
int current_handle = first_handle;
|
|
|
|
struct shortcut_handle *h = NULL;
|
2015-01-02 00:06:06 +00:00
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
if (first_handle == 0)
|
|
|
|
{
|
2015-01-02 00:06:06 +00:00
|
|
|
first_handle = core_alloc_ex("shortcuts_head",
|
|
|
|
sizeof(struct shortcut_handle), &shortcut_ops);
|
2011-11-15 13:22:02 +00:00
|
|
|
if (first_handle <= 0)
|
|
|
|
return NULL;
|
|
|
|
h = core_get_data(first_handle);
|
|
|
|
h->next_handle = 0;
|
|
|
|
current_handle = first_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
handle_count = index/SHORTCUTS_PER_HANDLE + 1;
|
|
|
|
handle_index = index%SHORTCUTS_PER_HANDLE;
|
|
|
|
do {
|
|
|
|
h = core_get_data(current_handle);
|
|
|
|
current_handle = h->next_handle;
|
|
|
|
handle_count--;
|
|
|
|
} while (handle_count > 0 && current_handle > 0);
|
|
|
|
if (handle_count > 0 && handle_index == 0)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
snprintf(buf, sizeof buf, "shortcuts_%d", index/SHORTCUTS_PER_HANDLE);
|
2015-01-02 00:06:06 +00:00
|
|
|
/* prevent invalidation of 'h' during compaction */
|
|
|
|
++buflib_move_lock;
|
|
|
|
h->next_handle = core_alloc_ex(buf, sizeof(struct shortcut_handle), &shortcut_ops);
|
|
|
|
--buflib_move_lock;
|
2011-11-15 13:22:02 +00:00
|
|
|
if (h->next_handle <= 0)
|
|
|
|
return NULL;
|
|
|
|
h = core_get_data(h->next_handle);
|
|
|
|
h->next_handle = 0;
|
|
|
|
}
|
|
|
|
return &h->shortcuts[handle_index];
|
|
|
|
}
|
|
|
|
|
2012-07-26 07:51:51 +00:00
|
|
|
static void remove_shortcut(int index)
|
|
|
|
{
|
|
|
|
int this = index, next = index + 1;
|
|
|
|
struct shortcut *prev = get_shortcut(this);
|
|
|
|
|
|
|
|
while (next <= shortcut_count)
|
|
|
|
{
|
|
|
|
struct shortcut *sc = get_shortcut(next);
|
|
|
|
memcpy(prev, sc, sizeof(struct shortcut));
|
|
|
|
next++;
|
|
|
|
prev = sc;
|
|
|
|
}
|
|
|
|
shortcut_count--;
|
|
|
|
}
|
|
|
|
|
2011-12-05 19:23:46 +00:00
|
|
|
static bool verify_shortcut(struct shortcut* sc)
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
switch (sc->type)
|
|
|
|
{
|
|
|
|
case SHORTCUT_UNDEFINED:
|
|
|
|
return false;
|
|
|
|
case SHORTCUT_BROWSER:
|
|
|
|
case SHORTCUT_FILE:
|
|
|
|
case SHORTCUT_PLAYLISTMENU:
|
2012-01-01 11:34:00 +00:00
|
|
|
return sc->u.path[0] != '\0';
|
2011-11-15 13:22:02 +00:00
|
|
|
case SHORTCUT_SETTING:
|
|
|
|
return sc->u.setting != NULL;
|
2011-12-08 10:23:46 +00:00
|
|
|
case SHORTCUT_TIME:
|
2012-01-01 11:34:00 +00:00
|
|
|
return sc->name[0] != '\0';
|
2011-11-15 13:22:02 +00:00
|
|
|
case SHORTCUT_DEBUGITEM:
|
|
|
|
case SHORTCUT_SEPARATOR:
|
2011-12-06 12:02:49 +00:00
|
|
|
case SHORTCUT_SHUTDOWN:
|
2011-11-15 13:22:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_shortcut(struct shortcut* sc)
|
|
|
|
{
|
|
|
|
sc->type = SHORTCUT_UNDEFINED;
|
|
|
|
sc->name[0] = '\0';
|
|
|
|
sc->u.path[0] = '\0';
|
2011-12-11 10:27:14 +00:00
|
|
|
sc->talk_clip[0] = '\0';
|
2011-11-15 13:22:02 +00:00
|
|
|
sc->icon = Icon_NOICON;
|
2011-12-05 19:23:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
static int first_idx_to_writeback = -1;
|
2012-07-26 07:51:51 +00:00
|
|
|
static bool overwrite_shortcuts = false;
|
2014-03-14 22:15:16 +00:00
|
|
|
static void shortcuts_ata_idle_callback(void)
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
int current_idx = first_idx_to_writeback;
|
2012-07-26 07:51:51 +00:00
|
|
|
int append = overwrite_shortcuts ? O_TRUNC : O_APPEND;
|
2015-01-02 00:06:06 +00:00
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
if (first_idx_to_writeback < 0)
|
|
|
|
return;
|
2012-07-26 07:51:51 +00:00
|
|
|
fd = open(SHORTCUTS_FILENAME, append|O_RDWR|O_CREAT, 0644);
|
2011-11-15 13:22:02 +00:00
|
|
|
if (fd < 0)
|
|
|
|
return;
|
2015-01-02 00:06:06 +00:00
|
|
|
|
|
|
|
/* ensure pointer returned by get_shortcut()
|
|
|
|
survives the yield() of write() */
|
|
|
|
++buflib_move_lock;
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
while (current_idx < shortcut_count)
|
|
|
|
{
|
|
|
|
struct shortcut* sc = get_shortcut(current_idx++);
|
2011-12-05 19:35:27 +00:00
|
|
|
const char *type;
|
2011-11-15 13:22:02 +00:00
|
|
|
int len;
|
|
|
|
if (!sc)
|
|
|
|
break;
|
|
|
|
type = type_strings[sc->type];
|
|
|
|
len = snprintf(buf, MAX_PATH, "[shortcut]\ntype: %s\ndata: ", type);
|
|
|
|
write(fd, buf, len);
|
|
|
|
if (sc->type == SHORTCUT_SETTING)
|
|
|
|
write(fd, sc->u.setting->cfg_name, strlen(sc->u.setting->cfg_name));
|
2021-11-10 18:56:19 +00:00
|
|
|
else if (sc->type == SHORTCUT_TIME)
|
|
|
|
{
|
|
|
|
#if CONFIG_RTC
|
|
|
|
if (sc->u.timedata.talktime)
|
|
|
|
write(fd, "talk", 4);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
write(fd, "sleep ", 6);
|
|
|
|
len = snprintf(buf, MAX_PATH, "%d", sc->u.timedata.sleep_timeout);
|
|
|
|
write(fd, buf, len);
|
|
|
|
}
|
|
|
|
}
|
2011-11-15 13:22:02 +00:00
|
|
|
else
|
|
|
|
write(fd, sc->u.path, strlen(sc->u.path));
|
2018-12-10 18:04:55 +00:00
|
|
|
|
|
|
|
/* write name:, icon:, talkclip: */
|
|
|
|
len = snprintf(buf, MAX_PATH, "\nname: %s\nicon: %d\ntalkclip: ",
|
|
|
|
sc->name, sc->icon);
|
|
|
|
write(fd, buf, len);
|
|
|
|
write(fd, sc->talk_clip, strlen(sc->talk_clip));
|
2011-11-15 13:22:02 +00:00
|
|
|
write(fd, "\n\n", 2);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
if (first_idx_to_writeback == 0)
|
|
|
|
{
|
|
|
|
/* reload all shortcuts because we appended to the shortcuts file which
|
|
|
|
* has not been read yet.
|
|
|
|
*/
|
|
|
|
reset_shortcuts();
|
|
|
|
shortcuts_init();
|
2011-12-08 10:23:46 +00:00
|
|
|
}
|
2015-01-02 00:06:06 +00:00
|
|
|
--buflib_move_lock;
|
2011-11-15 13:22:02 +00:00
|
|
|
first_idx_to_writeback = -1;
|
|
|
|
}
|
2011-12-05 19:23:46 +00:00
|
|
|
|
|
|
|
void shortcuts_add(enum shortcut_type type, const char* value)
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
struct shortcut* sc = get_shortcut(shortcut_count++);
|
|
|
|
if (!sc)
|
|
|
|
return;
|
|
|
|
init_shortcut(sc);
|
|
|
|
sc->type = type;
|
|
|
|
if (type == SHORTCUT_SETTING)
|
|
|
|
sc->u.setting = (void*)value;
|
|
|
|
else
|
|
|
|
strlcpy(sc->u.path, value, MAX_PATH);
|
2012-07-26 07:51:51 +00:00
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
if (first_idx_to_writeback < 0)
|
|
|
|
first_idx_to_writeback = shortcut_count - 1;
|
2012-07-26 07:51:51 +00:00
|
|
|
overwrite_shortcuts = false;
|
2011-11-15 13:22:02 +00:00
|
|
|
register_storage_idle_func(shortcuts_ata_idle_callback);
|
|
|
|
}
|
|
|
|
|
2011-12-20 20:35:28 +00:00
|
|
|
static int readline_cb(int n, char *buf, void *parameters)
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
(void)n;
|
|
|
|
(void)parameters;
|
|
|
|
struct shortcut **param = (struct shortcut**)parameters;
|
|
|
|
struct shortcut* sc = *param;
|
|
|
|
char *name, *value;
|
|
|
|
|
|
|
|
if (!strcasecmp(skip_whitespace(buf), "[shortcut]"))
|
|
|
|
{
|
|
|
|
if (sc && verify_shortcut(sc))
|
|
|
|
shortcut_count++;
|
|
|
|
sc = get_shortcut(shortcut_count);
|
|
|
|
if (!sc)
|
|
|
|
return 1;
|
|
|
|
init_shortcut(sc);
|
|
|
|
*param = sc;
|
|
|
|
}
|
|
|
|
else if (sc && settings_parseline(buf, &name, &value))
|
|
|
|
{
|
2022-03-13 18:31:02 +00:00
|
|
|
static const char *nm_options[] = {"type", "name", "data",
|
|
|
|
"icon", "talkclip", NULL};
|
|
|
|
int nm_op = string_option(name, nm_options, false);
|
|
|
|
|
|
|
|
if (nm_op == 0) /*type*/
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
int t = 0;
|
|
|
|
for (t=0; t<SHORTCUT_TYPE_COUNT && sc->type == SHORTCUT_UNDEFINED; t++)
|
|
|
|
if (!strcmp(value, type_strings[t]))
|
|
|
|
sc->type = t;
|
|
|
|
}
|
2022-03-13 18:31:02 +00:00
|
|
|
else if (nm_op == 1) /*name*/
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
strlcpy(sc->name, value, MAX_SHORTCUT_NAME);
|
|
|
|
}
|
2022-03-13 18:31:02 +00:00
|
|
|
else if (nm_op == 2) /*data*/
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
switch (sc->type)
|
|
|
|
{
|
|
|
|
case SHORTCUT_UNDEFINED:
|
|
|
|
case SHORTCUT_TYPE_COUNT:
|
|
|
|
*param = NULL;
|
|
|
|
break;
|
|
|
|
case SHORTCUT_BROWSER:
|
|
|
|
case SHORTCUT_FILE:
|
|
|
|
case SHORTCUT_DEBUGITEM:
|
|
|
|
case SHORTCUT_PLAYLISTMENU:
|
|
|
|
strlcpy(sc->u.path, value, MAX_PATH);
|
|
|
|
break;
|
|
|
|
case SHORTCUT_SETTING:
|
|
|
|
sc->u.setting = find_setting_by_cfgname(value, NULL);
|
|
|
|
break;
|
2011-12-08 10:23:46 +00:00
|
|
|
case SHORTCUT_TIME:
|
|
|
|
#if CONFIG_RTC
|
2011-12-08 10:27:30 +00:00
|
|
|
sc->u.timedata.talktime = false;
|
2011-12-08 10:23:46 +00:00
|
|
|
if (!strcasecmp(value, "talk"))
|
|
|
|
sc->u.timedata.talktime = true;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (!strncasecmp(value, "sleep ", strlen("sleep ")))
|
|
|
|
sc->u.timedata.sleep_timeout = atoi(&value[strlen("sleep ")]);
|
|
|
|
else
|
|
|
|
sc->type = SHORTCUT_UNDEFINED; /* error */
|
|
|
|
break;
|
2011-11-15 13:22:02 +00:00
|
|
|
case SHORTCUT_SEPARATOR:
|
2011-12-06 12:02:49 +00:00
|
|
|
case SHORTCUT_SHUTDOWN:
|
2011-11-15 13:22:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-03-13 18:31:02 +00:00
|
|
|
else if (nm_op == 3) /*icon*/
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
if (!strcmp(value, "filetype") && sc->type != SHORTCUT_SETTING && sc->u.path[0])
|
|
|
|
{
|
|
|
|
sc->icon = filetype_get_icon(filetype_get_attr(sc->u.path));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc->icon = atoi(value);
|
|
|
|
}
|
|
|
|
}
|
2022-03-13 18:31:02 +00:00
|
|
|
else if (nm_op == 4) /*talkclip*/
|
2011-12-11 10:27:14 +00:00
|
|
|
{
|
|
|
|
strlcpy(sc->talk_clip, value, MAX_PATH);
|
|
|
|
}
|
2011-11-15 13:22:02 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-05 19:23:46 +00:00
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
void shortcuts_init(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char buf[512];
|
|
|
|
struct shortcut *param = NULL;
|
|
|
|
struct shortcut_handle *h;
|
|
|
|
shortcut_count = 0;
|
|
|
|
fd = open_utf8(SHORTCUTS_FILENAME, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
2015-01-02 00:06:06 +00:00
|
|
|
first_handle = core_alloc_ex("shortcuts_head", sizeof(struct shortcut_handle), &shortcut_ops);
|
2021-07-25 13:50:31 +00:00
|
|
|
if (first_handle <= 0) {
|
|
|
|
close(fd);
|
2011-11-15 13:22:02 +00:00
|
|
|
return;
|
2021-07-25 13:50:31 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
h = core_get_data(first_handle);
|
|
|
|
h->next_handle = 0;
|
2015-01-02 00:06:06 +00:00
|
|
|
|
|
|
|
/* we enter readline_cb() multiple times with a buffer
|
|
|
|
obtained when we encounter a "[shortcut]" section.
|
|
|
|
fast_readline() might yield() -> protect buffer */
|
|
|
|
++buflib_move_lock;
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
fast_readline(fd, buf, sizeof buf, ¶m, readline_cb);
|
|
|
|
close(fd);
|
|
|
|
if (param && verify_shortcut(param))
|
|
|
|
shortcut_count++;
|
2015-01-02 00:06:06 +00:00
|
|
|
|
|
|
|
/* invalidate at scope end since "param" contains
|
|
|
|
the shortcut pointer */
|
|
|
|
--buflib_move_lock;
|
2011-11-15 13:22:02 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 19:23:46 +00:00
|
|
|
static const char * shortcut_menu_get_name(int selected_item, void * data,
|
|
|
|
char * buffer, size_t buffer_len)
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
struct shortcut *sc = get_shortcut(selected_item);
|
|
|
|
if (!sc)
|
|
|
|
return "";
|
|
|
|
if (sc->type == SHORTCUT_SETTING)
|
|
|
|
return sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id));
|
2011-12-08 10:23:46 +00:00
|
|
|
else if (sc->type == SHORTCUT_SEPARATOR || sc->type == SHORTCUT_TIME)
|
2011-11-15 13:22:02 +00:00
|
|
|
return sc->name;
|
2011-12-06 12:02:49 +00:00
|
|
|
else if (sc->type == SHORTCUT_SHUTDOWN && sc->name[0] == '\0')
|
|
|
|
{
|
|
|
|
/* No translation support as only soft_shutdown has LANG_SHUTDOWN defined */
|
|
|
|
return type_strings[SHORTCUT_SHUTDOWN];
|
|
|
|
}
|
2021-03-07 15:07:49 +00:00
|
|
|
else if (sc->type == SHORTCUT_BROWSER && (sc->u.path)[0] != '\0')
|
|
|
|
{
|
|
|
|
char* pos;
|
|
|
|
if (path_basename(sc->u.path, (const char **)&pos) > 0)
|
|
|
|
{
|
|
|
|
if (snprintf(buffer, buffer_len, "%s (%s)", pos, sc->u.path) < (int)buffer_len)
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
return sc->name[0] ? sc->name : sc->u.path;
|
|
|
|
}
|
|
|
|
|
2011-12-05 19:23:46 +00:00
|
|
|
static int shortcut_menu_get_action(int action, struct gui_synclist *lists)
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
(void)lists;
|
|
|
|
if (action == ACTION_STD_OK)
|
|
|
|
return ACTION_STD_CANCEL;
|
2021-03-09 02:59:04 +00:00
|
|
|
else if (action == ACTION_STD_QUICKSCREEN && action != ACTION_STD_CONTEXT)
|
|
|
|
return ACTION_STD_CANCEL;
|
2012-07-26 07:51:51 +00:00
|
|
|
else if (action == ACTION_STD_CONTEXT)
|
|
|
|
{
|
|
|
|
int selection = gui_synclist_get_sel_pos(lists);
|
|
|
|
|
|
|
|
if (!yesno_pop(ID2P(LANG_REALLY_DELETE)))
|
2021-12-20 19:12:03 +00:00
|
|
|
{
|
|
|
|
gui_synclist_set_title(lists, lists->title, lists->title_icon);
|
2012-07-26 07:51:51 +00:00
|
|
|
return ACTION_REDRAW;
|
2021-12-20 19:12:03 +00:00
|
|
|
}
|
2012-07-26 07:51:51 +00:00
|
|
|
|
|
|
|
remove_shortcut(selection);
|
|
|
|
gui_synclist_set_nb_items(lists, shortcut_count);
|
2021-12-20 19:12:03 +00:00
|
|
|
gui_synclist_set_title(lists, lists->title, lists->title_icon);
|
2012-07-26 07:51:51 +00:00
|
|
|
if (selection >= shortcut_count)
|
|
|
|
gui_synclist_select_item(lists, shortcut_count - 1);
|
|
|
|
first_idx_to_writeback = 0;
|
|
|
|
overwrite_shortcuts = true;
|
2014-03-14 22:15:16 +00:00
|
|
|
shortcuts_ata_idle_callback();
|
2012-07-26 07:51:51 +00:00
|
|
|
if (shortcut_count == 0)
|
|
|
|
return ACTION_STD_CANCEL;
|
|
|
|
return ACTION_REDRAW;
|
|
|
|
}
|
2011-11-15 13:22:02 +00:00
|
|
|
return action;
|
|
|
|
}
|
2011-12-05 19:23:46 +00:00
|
|
|
|
|
|
|
static enum themable_icons shortcut_menu_get_icon(int selected_item, void * data)
|
2011-11-15 13:22:02 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
2021-03-09 13:21:20 +00:00
|
|
|
int icon;
|
2011-11-15 13:22:02 +00:00
|
|
|
struct shortcut *sc = get_shortcut(selected_item);
|
|
|
|
if (!sc)
|
|
|
|
return Icon_NOICON;
|
|
|
|
if (sc->icon == Icon_NOICON)
|
|
|
|
{
|
2021-03-09 13:21:20 +00:00
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
switch (sc->type)
|
|
|
|
{
|
|
|
|
case SHORTCUT_FILE:
|
|
|
|
return filetype_get_icon(filetype_get_attr(sc->u.path));
|
|
|
|
case SHORTCUT_BROWSER:
|
2021-03-09 13:21:20 +00:00
|
|
|
icon = filetype_get_icon(filetype_get_attr(sc->u.path));
|
|
|
|
if (icon <= 0)
|
|
|
|
icon = Icon_Folder;
|
|
|
|
return icon;
|
2011-11-15 13:22:02 +00:00
|
|
|
case SHORTCUT_SETTING:
|
|
|
|
return Icon_Menu_setting;
|
|
|
|
case SHORTCUT_DEBUGITEM:
|
|
|
|
return Icon_Menu_functioncall;
|
|
|
|
case SHORTCUT_PLAYLISTMENU:
|
|
|
|
return Icon_Playlist;
|
2011-12-06 12:02:49 +00:00
|
|
|
case SHORTCUT_SHUTDOWN:
|
|
|
|
return Icon_System_menu;
|
2011-12-08 10:23:46 +00:00
|
|
|
case SHORTCUT_TIME:
|
|
|
|
return Icon_Menu_functioncall;
|
2011-11-15 13:22:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sc->icon;
|
|
|
|
}
|
|
|
|
|
2011-12-20 20:35:28 +00:00
|
|
|
static int shortcut_menu_speak_item(int selected_item, void * data)
|
2011-12-11 10:27:14 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
struct shortcut *sc = get_shortcut(selected_item);
|
2015-05-18 19:51:56 +00:00
|
|
|
if (sc)
|
|
|
|
{
|
|
|
|
if (sc->talk_clip[0])
|
|
|
|
{
|
|
|
|
talk_file(NULL, NULL, sc->talk_clip, NULL, NULL, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (sc->type)
|
|
|
|
{
|
|
|
|
case SHORTCUT_BROWSER:
|
|
|
|
{
|
|
|
|
static char path[MAX_PATH];
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent* entry;
|
|
|
|
char* filename = strrchr(sc->u.path, PATH_SEPCH) + 1;
|
|
|
|
if (*filename != '\0')
|
|
|
|
{
|
|
|
|
int dirlen = (filename - sc->u.path);
|
|
|
|
strlcpy(path, sc->u.path, dirlen + 1);
|
|
|
|
dir = opendir(path);
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
while (0 != (entry = readdir(dir)))
|
|
|
|
{
|
|
|
|
if (!strcmp(entry->d_name, filename))
|
|
|
|
{
|
|
|
|
struct dirinfo info = dir_get_info(dir, entry);
|
|
|
|
if (info.attribute & ATTR_DIRECTORY)
|
|
|
|
talk_dir_or_spell(sc->u.path, NULL, false);
|
|
|
|
else talk_file_or_spell(path, filename, NULL, false);
|
2021-04-07 21:02:34 +00:00
|
|
|
closedir(dir);
|
2015-05-18 19:51:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2021-04-07 21:02:34 +00:00
|
|
|
closedir(dir);
|
2015-05-18 19:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
talk_dir_or_spell(sc->u.path, NULL, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
talk_spell(sc->u.path, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHORTCUT_FILE:
|
|
|
|
case SHORTCUT_PLAYLISTMENU:
|
|
|
|
talk_file_or_spell(NULL, sc->u.path, NULL, false);
|
|
|
|
break;
|
|
|
|
case SHORTCUT_SETTING:
|
|
|
|
talk_id(sc->u.setting->lang_id, false);
|
|
|
|
break;
|
|
|
|
#if CONFIG_RTC
|
|
|
|
case SHORTCUT_TIME:
|
|
|
|
talk_id(LANG_TIME_MENU, false);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case SHORTCUT_SHUTDOWN:
|
|
|
|
if (!sc->name[0])
|
|
|
|
{
|
|
|
|
talk_spell(type_strings[SHORTCUT_SHUTDOWN], false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
talk_spell(sc->name[0] ? sc->name : sc->u.path, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-11 10:27:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-08 10:23:46 +00:00
|
|
|
void talk_timedate(void);
|
|
|
|
const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
|
|
|
|
int value, const char* unit);
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
int do_shortcut_menu(void *ignored)
|
|
|
|
{
|
|
|
|
(void)ignored;
|
|
|
|
struct simplelist_info list;
|
|
|
|
struct shortcut *sc;
|
|
|
|
int done = GO_TO_PREVIOUS;
|
|
|
|
if (first_handle == 0)
|
|
|
|
shortcuts_init();
|
|
|
|
simplelist_info_init(&list, P2STR(ID2P(LANG_SHORTCUTS)), shortcut_count, NULL);
|
|
|
|
list.get_name = shortcut_menu_get_name;
|
|
|
|
list.action_callback = shortcut_menu_get_action;
|
2011-11-27 10:10:26 +00:00
|
|
|
if (global_settings.show_icons)
|
|
|
|
list.get_icon = shortcut_menu_get_icon;
|
2011-11-15 13:22:02 +00:00
|
|
|
list.title_icon = Icon_Bookmark;
|
2011-12-11 10:27:14 +00:00
|
|
|
if (global_settings.talk_menu)
|
|
|
|
list.get_talk = shortcut_menu_speak_item;
|
2011-11-15 13:22:02 +00:00
|
|
|
|
2012-03-27 13:45:42 +00:00
|
|
|
if (shortcut_count == 0)
|
|
|
|
{
|
|
|
|
splash(HZ, str(LANG_NO_FILES));
|
|
|
|
return GO_TO_PREVIOUS;
|
|
|
|
}
|
2011-11-15 13:22:02 +00:00
|
|
|
push_current_activity(ACTIVITY_SHORTCUTSMENU);
|
2011-12-08 10:23:46 +00:00
|
|
|
|
2015-01-02 00:06:06 +00:00
|
|
|
/* prevent buffer moves while the menu is active.
|
|
|
|
Playing talk files or other I/O actions call yield() */
|
|
|
|
++buflib_move_lock;
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
while (done == GO_TO_PREVIOUS)
|
|
|
|
{
|
2021-11-10 18:56:19 +00:00
|
|
|
list.count = shortcut_count;
|
2011-11-15 13:22:02 +00:00
|
|
|
if (simplelist_show_list(&list))
|
|
|
|
break; /* some error happened?! */
|
|
|
|
if (list.selection == -1)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc = get_shortcut(list.selection);
|
|
|
|
if (!sc)
|
|
|
|
continue;
|
2021-03-09 14:48:10 +00:00
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
switch (sc->type)
|
|
|
|
{
|
|
|
|
case SHORTCUT_PLAYLISTMENU:
|
|
|
|
if (!file_exists(sc->u.path))
|
|
|
|
{
|
|
|
|
splash(HZ, ID2P(LANG_NO_FILES));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-29 19:24:51 +00:00
|
|
|
onplay_show_playlist_menu(sc->u.path, NULL);
|
2011-11-15 13:22:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHORTCUT_FILE:
|
|
|
|
if (!file_exists(sc->u.path))
|
|
|
|
{
|
|
|
|
splash(HZ, ID2P(LANG_NO_FILES));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* else fall through */
|
|
|
|
case SHORTCUT_BROWSER:
|
|
|
|
{
|
2020-08-01 02:45:10 +00:00
|
|
|
if(open_plugin_add_path(ID2P(LANG_SHORTCUTS), sc->u.path, NULL) != 0)
|
|
|
|
{
|
|
|
|
done = GO_TO_PLUGIN;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-15 13:22:02 +00:00
|
|
|
struct browse_context browse;
|
|
|
|
browse_context_init(&browse, global_settings.dirfilter, 0,
|
|
|
|
NULL, NOICON, sc->u.path, NULL);
|
|
|
|
if (sc->type == SHORTCUT_FILE)
|
|
|
|
browse.flags |= BROWSE_RUNFILE;
|
|
|
|
done = rockbox_browse(&browse);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHORTCUT_SETTING:
|
2021-11-19 16:55:10 +00:00
|
|
|
{
|
|
|
|
int old_sleeptimer_duration = global_settings.sleeptimer_duration;
|
2021-11-19 04:11:13 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
int old_album_art = global_settings.album_art;
|
|
|
|
#endif
|
2011-11-15 13:22:02 +00:00
|
|
|
do_setting_screen(sc->u.setting,
|
|
|
|
sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)),NULL);
|
2021-11-19 16:55:10 +00:00
|
|
|
|
2021-11-19 04:11:13 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
if (old_album_art != global_settings.album_art)
|
|
|
|
set_albumart_mode(global_settings.album_art);
|
|
|
|
#endif
|
2021-11-19 16:55:10 +00:00
|
|
|
if (old_sleeptimer_duration != global_settings.sleeptimer_duration &&
|
|
|
|
get_sleep_timer())
|
|
|
|
set_sleeptimer_duration(global_settings.sleeptimer_duration);
|
2011-11-15 13:22:02 +00:00
|
|
|
break;
|
2021-11-19 16:55:10 +00:00
|
|
|
}
|
2011-11-15 13:22:02 +00:00
|
|
|
case SHORTCUT_DEBUGITEM:
|
|
|
|
run_debug_screen(sc->u.path);
|
|
|
|
break;
|
2011-12-06 12:02:49 +00:00
|
|
|
case SHORTCUT_SHUTDOWN:
|
|
|
|
#if CONFIG_CHARGING
|
|
|
|
if (charger_inserted())
|
|
|
|
charging_splash();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
sys_poweroff();
|
|
|
|
break;
|
2011-12-08 10:23:46 +00:00
|
|
|
case SHORTCUT_TIME:
|
|
|
|
#if CONFIG_RTC
|
2011-12-29 21:30:28 +00:00
|
|
|
if (sc->u.timedata.talktime) {
|
2011-12-08 10:23:46 +00:00
|
|
|
talk_timedate();
|
2011-12-29 21:30:28 +00:00
|
|
|
talk_force_enqueue_next();
|
|
|
|
} else
|
2011-12-08 10:23:46 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
char timer_buf[10];
|
2012-10-05 19:30:13 +00:00
|
|
|
set_sleeptimer_duration(sc->u.timedata.sleep_timeout);
|
2021-11-19 16:55:10 +00:00
|
|
|
splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER),
|
2011-12-08 10:23:46 +00:00
|
|
|
sleep_timer_formatter(timer_buf, sizeof(timer_buf),
|
|
|
|
sc->u.timedata.sleep_timeout, NULL));
|
|
|
|
}
|
|
|
|
break;
|
2011-11-15 13:22:02 +00:00
|
|
|
case SHORTCUT_UNDEFINED:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pop_current_activity();
|
2015-01-02 00:06:06 +00:00
|
|
|
--buflib_move_lock;
|
|
|
|
|
2011-11-15 13:22:02 +00:00
|
|
|
return done;
|
|
|
|
}
|