(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) {
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 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);