/** @brief For error template */
char *dcgi_error_string;
-/** @brief Locate a track by ID */
-static struct queue_entry *findtrack(const char *id) {
- struct queue_entry *q;
-
- dcgi_lookup(DCGI_PLAYING);
- if(dcgi_playing && !strcmp(dcgi_playing->id, id))
- return dcgi_playing;
- dcgi_lookup(DCGI_QUEUE);
- for(q = dcgi_queue; q; q = q->next)
- if(!strcmp(q->id, id))
- return q;
- dcgi_lookup(DCGI_RECENT);
- for(q = dcgi_recent; q; q = q->next)
- if(!strcmp(q->id, id))
- return q;
- return NULL;
-}
-
/** @brief Return @p i as a string */
static const char *make_index(int i) {
char *s;
char *s;
if(track[0] != '/') {
- struct queue_entry *q = findtrack(track);
+ struct queue_entry *q = dcgi_findtrack(track);
if(q)
track = q->track;
char **args,
struct sink *output,
void attribute((unused)) *u) {
- struct queue_entry *q = findtrack(args[0]);
+ struct queue_entry *q = dcgi_findtrack(args[0]);
if(q && q->submitter)
return sink_writes(output, cgi_sgmlquote(q->submitter)) < 0 ? -1 : 0;
char **args,
struct sink *output,
void attribute((unused)) *u) {
- struct queue_entry *q = findtrack(args[0]);
+ struct queue_entry *q = dcgi_findtrack(args[0]);
const struct tm *w = 0;
if(q) {
name = args[0];
else {
/* Track identified by queue ID */
- if(!(q = findtrack(args[0])))
+ if(!(q = dcgi_findtrack(args[0])))
return 0;
if(q->state == playing_started || q->state == playing_paused)
if(sink_printf(output, "%ld:%02ld/", q->sofar / 60, q->sofar % 60) < 0)
char **args,
struct sink *output,
void attribute((unused)) *u) {
- struct queue_entry *q = findtrack(args[0]);
+ struct queue_entry *q = dcgi_findtrack(args[0]);
/* TODO would be better to reject recent */
if(!q || !dcgi_client)
(dcgi_rights, disorder_user(dcgi_client), q));
}
-/* @movable{ID}
+/* @movable{ID}{DIR}
*
* Expands to "true" if track ID is movable and "false" otherwise.
+ *
+ * DIR (which is optional) should be a non-zero integer. If it is negative
+ * then the intended move is down (later in the queue), if it is positive then
+ * the intended move is up (earlier in the queue). The first track is not
+ * movable up and the last track not movable down.
*/
-static int exp_movable(int attribute((unused)) nargs,
+static int exp_movable(int nargs,
char **args,
struct sink *output,
void attribute((unused)) *u) {
- struct queue_entry *q = findtrack(args[0]);
+ struct queue_entry *q = dcgi_findtrack(args[0]);
/* TODO would be better to recent playing/recent */
if(!q || !dcgi_client)
return mx_bool_result(output, 0);
+ if(nargs > 1) {
+ const long dir = atoi(args[1]);
+
+ if(dir > 0 && q == dcgi_queue)
+ return mx_bool_result(output, 0);
+ if(dir < 0 && q->next == 0)
+ return mx_bool_result(output, 0);
+ }
dcgi_lookup(DCGI_RIGHTS);
return mx_bool_result(output,
- right_movable(dcgi_rights, disorder_user(dcgi_client), q));
+ right_movable(dcgi_rights,
+ disorder_user(dcgi_client),
+ q));
}
/* @playing{TEMPLATE}
char **args,
struct sink *output,
void attribute((unused)) *u) {
- struct queue_entry *q = findtrack(args[0]);
+ struct queue_entry *q = dcgi_findtrack(args[0]);
if(q)
return sink_writes(output, playing_states[q->state]) < 0 ? -1 : 0;
char attribute((unused)) **args,
struct sink *output,
void attribute((unused)) *u) {
- return sink_writes(output, cgi_sgmlquote(dcgi_error_string)) < 0 ? -1 : 0;
+ return sink_writes(output, dcgi_error_string) < 0 ? -1 : 0;
+}
+
+/* @image{NAME}
+ *
+ * Expands to the URL of the image called NAME.
+ *
+ * Firstly if there is a label called images.NAME then the image stem will be
+ * the value of that label. Otherwise the stem will be NAME.png.
+ *
+ * If the label url.static exists then it will give the base URL for images.
+ * Otherwise the base url will be /disorder/.
+ */
+static int exp_image(int attribute((unused)) nargs,
+ char **args,
+ struct sink *output,
+ void attribute((unused)) *u) {
+ const char *url, *stem;
+ char *labelname;
+
+ /* Compute the stem */
+ byte_xasprintf(&labelname, "images.%s", args[0]);
+ if(option_label_exists(labelname))
+ stem = option_label(labelname);
+ else
+ byte_xasprintf((char **)&stem, "%s.png", args[0]);
+ /* If the stem looks like it's reasonalby complete, use that */
+ if(stem[0] == '/'
+ || !strncmp(stem, "http:", 5)
+ || !strncmp(stem, "https:", 6))
+ url = stem;
+ else {
+ /* Compute the URL */
+ if(option_label_exists("url.static"))
+ byte_xasprintf((char **)&url, "%s/%s",
+ option_label("url.static"), stem);
+ else
+ /* Default base is /disorder */
+ byte_xasprintf((char **)&url, "/disorder/%s", stem);
+ }
+ return sink_writes(output, cgi_sgmlquote(url)) < 0 ? -1 : 0;
}
/** @brief Register DisOrder-specific expansions */
mx_register("arg", 1, 1, exp_arg);
mx_register("enabled", 0, 0, exp_enabled);
mx_register("error", 0, 0, exp_error);
+ mx_register("image", 1, 1, exp_image);
mx_register("isnew", 0, 0, exp_isnew);
mx_register("isplaying", 0, 0, exp_isplaying);
mx_register("isplaying", 0, 0, exp_isqueue);