summaryrefslogtreecommitdiffstats
path: root/apps/gui/skin_engine/skin_tokens.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/skin_engine/skin_tokens.c')
-rw-r--r--apps/gui/skin_engine/skin_tokens.c75
1 files changed, 31 insertions, 44 deletions
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c
index a0de45d3e3..12277aa0ea 100644
--- a/apps/gui/skin_engine/skin_tokens.c
+++ b/apps/gui/skin_engine/skin_tokens.c
@@ -66,11 +66,10 @@
#include "fixedpoint.h"
#endif
#include "list.h"
+#include "wps.h"
#define NOINLINE __attribute__ ((noinline))
-extern struct wps_state wps_state;
-
static const char* get_codectype(const struct mp3entry* id3)
{
if (id3 && id3->codectype < AFMT_NUM_CODECS) {
@@ -88,6 +87,7 @@ static const char* get_codectype(const struct mp3entry* id3)
* level - what to extract. 0 is file name, 1 is parent of file, 2 is
* parent of parent, etc.
*
+ * path does not need to be absolute, ignores multiple slashes
* Returns buf if the desired level was found, NULL otherwise.
*/
char* get_dir(char* buf, int buf_size, const char* path, int level)
@@ -95,7 +95,7 @@ char* get_dir(char* buf, int buf_size, const char* path, int level)
const char* sep;
const char* last_sep;
int len;
-
+ buf[0] = '\0';
sep = path + strlen(path);
last_sep = sep;
@@ -106,16 +106,20 @@ char* get_dir(char* buf, int buf_size, const char* path, int level)
if (!level)
break;
- level--;
last_sep = sep - 1;
+ if (*last_sep != '/') /* ignore multiple separators */
+ level--;
}
}
- if (level || (last_sep <= sep))
+ if (level || (last_sep <= sep)) /* level was not found */
return NULL;
- len = MIN(last_sep - sep, buf_size - 1);
- strlcpy(buf, sep + 1, len + 1);
+ if (sep == path && *sep != '/') /* for paths without leading separator */
+ sep = path - 1;
+
+ len = MIN((last_sep - sep), buf_size - 1);
+ strmemccpy(buf, sep + 1, len + 1);
return buf;
}
@@ -228,7 +232,7 @@ static const char* get_filename_token(struct wps_token *token, char* filename,
const char *get_id3_token(struct wps_token *token, struct mp3entry *id3,
char *filename, char *buf, int buf_size, int limit, int *intval)
{
- struct wps_state *state = &wps_state;
+ struct wps_state *state = get_wps_state();
if (id3)
{
unsigned long length = id3->length;
@@ -540,7 +544,7 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
static struct mp3entry* get_mp3entry_from_offset(int offset, char **filename)
{
struct mp3entry* pid3 = NULL;
- struct wps_state *state = skin_get_global_state();
+ struct wps_state *state = get_wps_state();
struct cuesheet *cue = state->id3 ? state->id3->cuesheet : NULL;
const char *fname = NULL;
if (cue && cue->curr_track_idx + offset < cue->track_count)
@@ -678,7 +682,7 @@ const char *get_token_value(struct gui_wps *gwps,
return NULL;
struct wps_data *data = gwps->data;
- struct wps_state *state = skin_get_global_state();
+ struct wps_state *state = get_wps_state();
struct mp3entry *id3; /* Think very carefully about using this.
maybe get_id3_token() is the better place? */
const char *out_text = NULL;
@@ -821,7 +825,8 @@ const char *get_token_value(struct gui_wps *gwps,
return (char*)SKINOFFSETTOPTR(get_skin_buffer(data), token->value.data);
case SKIN_TOKEN_TRANSLATEDSTRING:
- return (char*)P2STR(ID2P(token->value.i));
+ return token->value.i < LANG_LAST_INDEX_IN_ARRAY ?
+ (char*)P2STR(ID2P(token->value.i)) : "<ERR>";
case SKIN_TOKEN_PLAYLIST_ENTRIES:
numeric_ret = playlist_amount();
@@ -1039,37 +1044,19 @@ const char *get_token_value(struct gui_wps *gwps,
case SKIN_TOKEN_PLAYBACK_STATUS:
{
int status = current_playmode();
- /* music */
- int mode = 1; /* stop */
- if (status == STATUS_PLAY)
- mode = 2; /* play */
- if (state->is_fading ||
- (status == STATUS_PAUSE && !status_get_ffmode()))
- mode = 3; /* pause */
- else
- { /* ff / rwd */
- if (status_get_ffmode() == STATUS_FASTFORWARD)
- mode = 4;
- if (status_get_ffmode() == STATUS_FASTBACKWARD)
- mode = 5;
+ switch (status) {
+ case STATUS_STOP:
+ numeric_ret = 1;
+ break;
+ case STATUS_PLAY:
+ numeric_ret = 2;
+ break;
+ default:
+ numeric_ret = status + 1;
+ break;
}
-#ifdef HAVE_RECORDING
- /* recording */
- if (status == STATUS_RECORD)
- mode = 6;
- else if (status == STATUS_RECORD_PAUSE)
- mode = 7;
-#endif
-#if CONFIG_TUNER
- /* radio */
- if (status == STATUS_RADIO)
- mode = 8;
- else if (status == STATUS_RADIO_PAUSE)
- mode = 9;
-#endif
- numeric_ret = mode;
- snprintf(buf, buf_size, "%d", mode-1);
+ snprintf(buf, buf_size, "%d", numeric_ret-1);
numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
}
@@ -1366,7 +1353,7 @@ const char *get_token_value(struct gui_wps *gwps,
case SKIN_TOKEN_LASTTOUCH:
{
#ifdef HAVE_TOUCHSCREEN
- unsigned int last_touch = touchscreen_last_touch();
+ long last_touch = touchscreen_last_touch();
char *skin_base = get_skin_buffer(data);
struct touchregion_lastpress *data = SKINOFFSETTOPTR(skin_base, token->value.data);
if (!data) return NULL;
@@ -1374,7 +1361,7 @@ const char *get_token_value(struct gui_wps *gwps,
if (region)
last_touch = region->last_press;
- if (last_touch != 0xffff &&
+ if (last_touch != -1 &&
TIME_BEFORE(current_tick, data->timeout + last_touch))
return "t";
#endif
@@ -1389,7 +1376,7 @@ const char *get_token_value(struct gui_wps *gwps,
case SKIN_TOKEN_SETTING:
{
- const struct settings_list *s = settings+token->value.i;
+ const struct settings_list *s = token->value.xdata;
if (intval)
{
/* Handle contionals */
@@ -1460,7 +1447,7 @@ const char *get_token_value(struct gui_wps *gwps,
goto gtv_ret_numeric_tag_info;
}
}
- cfg_to_string(token->value.i,buf,buf_size);
+ cfg_to_string(s, buf, buf_size);
numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
}