chiark / gitweb /
extended @movable expansion; more template...
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 11 May 2008 14:04:08 +0000 (15:04 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 11 May 2008 14:04:08 +0000 (15:04 +0100)
server/macros-disorder.c
templates/macros.tmpl
templates/playing.tmpl

index 6c81d56136011ffbb8a2f57984de0bb1484f8c97..8b5b486fab37fbc93f5b0e70fb01cb027f339a03 100644 (file)
@@ -265,11 +265,16 @@ static int exp_removable(int attribute((unused)) nargs,
                             (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) {
@@ -278,9 +283,19 @@ static int exp_movable(int attribute((unused)) nargs,
 
   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}
index 8714a08c00516683488ab939e763dbd44bfc64dd..7c1093866cd5b464388cc438d44ac72d9c871bce 100644 (file)
@@ -75,4 +75,19 @@ USA
                   title="@label{@what.removeverbose}"
                   alt="@label{@what.scratch}">}}
 
+@# Expand to a move button
+@#  @dir should be a direction: up, upall, down or downall
+@#  @delta should be the distance, +ve for up and -ve for down
+@# This macro calls @movable to check that the move is possible.
+@define {mmove} {id dir delta}
+        {@if{@movable{@id}{@delta}}
+            {<a class=imgbutton
+                href="@url?action=move&#38;id=@id&#38;delta=@delta@back">
+               <img class=button src="@image{@dir}"
+                    title="@label{playing.@q{@dir}verbose}"
+                    alt="@label{playing.@dir}">
+             </a>}
+            {<img class=button src="@image{no@dir}"
+                    title="@label{playing.@q{@dir}verbose}"
+                    alt="@label{playing.@dir}">}}
 }@#
index d0e000081c2bc41cd537828868d2ea8326772564..c910120bdefec9a7ed8d4e12445628249f20c1ab 100644 (file)
@@ -36,60 +36,61 @@ USA
    @ifmanage{
    <div class=mgmt>
    <p class=mgmt>
-    @if{@paused}{
+   @if{@paused}{
 @# Paused
-      <a class=button
-      href="@url?action=resume@back"
+    <a class=button
+       href="@url?action=resume@back"
        title="@label{playing.resumeverbose}">@label{playing.pause}</a>
-      </a>
-      <img width=16 height=16 class=imgbutton src="@image{enabled}">
-    }{
+    </a>
+    <img width=16 height=16 class=imgbutton src="@image{enabled}">
+   }{
 @# Not paused
-      <a class=button
-      href="@url?action=pause@back"
-       title="@label{playing.pauseverbose}">@label{playing.pause}</a>
-      </a>
-      <img width=16 height=16 class=imgbutton src="@image{disabled}">
-    }
-    @if{@random-enabled}{
+     <a class=button
+        href="@url?action=pause@back"
+        title="@label{playing.pauseverbose}">@label{playing.pause}</a>
+     </a>
+     <img width=16 height=16 class=imgbutton src="@image{disabled}">
+   }
+   @if{@random-enabled}{
 @# Random play enabled
-      <a class=button
-      href="@url?action=random-disable@back"
-       title="@label{playing.randomdisableverbose}">@label{playing.random}</a>
-      </a>
-      <img width=16 height=16 class=imgbutton src="@image{enabled}">
-    }{
+     <a class=button
+        href="@url?action=random-disable@back"
+        title="@label{playing.randomdisableverbose}">@label{playing.random}</a>
+     </a>
+     <img width=16 height=16 class=imgbutton src="@image{enabled}">
+   }{
 @# Random play disabled
-      <a class=button
-      href="@url?action=random-enable@back"
+    <a class=button
+       href="@url?action=random-enable@back"
        title="@label{playing.randomenableverbose}">@label{playing.random}</a>
-      </a>
-      <img width=16 height=16 class=imgbutton src="@image{disabled}">
-    }
-    @if{@enabled}{
+    </a>
+    <img width=16 height=16 class=imgbutton src="@image{disabled}">
+   }
+   @if{@enabled}{
 @# Play enabled
-      <a class=button
-      href="@url?action=disable@back"
-       title="@label{playing.disableverbose}">@label{playing.playing}</a>
-      </a>
-      <img width=16 height=16 class=imgbutton src="@image{enabled}">
-    }{
+     <a class=button
+        href="@url?action=disable@back"
+        title="@label{playing.disableverbose}">@label{playing.playing}</a>
+     </a>
+     <img width=16 height=16 class=imgbutton src="@image{enabled}">
+   }{
 @# Play disabled
-      <a class=button
-      href="@url?action=enable@back"
-       title="@label{playing.enableverbose}">@label{playing.playing}</a>
-      </a>
-      <img width=16 height=16 class=imgbutton src="@image{disabled}">
-    }
+     <a class=button
+        href="@url?action=enable@back"
+        title="@label{playing.enableverbose}">@label{playing.playing}</a>
+     </a>
+     <img width=16 height=16 class=imgbutton src="@image{disabled}">
+   }
 @# Volume form
-    <form class=volume action="@url" method=POST
-     enctype="multipart/form-data" accept-charset=utf-8>
-    <span class=volume>
+   <form class=volume method=POST
+         action="@url"
+         enctype="multipart/form-data" accept-charset=utf-8>
+   <span class=volume>
      @label{playing.volume}
 @# Volume up button
      @right{volume}{
        <a class=imgbutton
-        href="@url?action=volume&#38;delta=-@label{volume.resolution}@back">
+          href="@url?action=volume&#38;delta=-@label{volume.resolution}@back">
          <img class=button src="@image{down}"
               alt="@label{volume.reduce}"
               title="@label{volume.reduceverbose}">
@@ -98,14 +99,17 @@ USA
        <img class=button src="@image{nodown}">
      }
 @# Volume value widgets
-     @label{volume.left} <input size=3 name=left type=text value="@volume:left@">
-     @label{volume.right} <input size=3 name=right type=text value="@volume:right@">
+     @label{volume.left} <input size=3 name=left
+                                type=text value="@volume:left@">
+     @label{volume.right} <input size=3 name=right type
+                                 text value="@volume:right@">
      <input name=back type=hidden value="@thisurl@?back=manage">
 @# Volume set button
      @right{volume}{
        <button class=search name=submit type=submit>
-         @label{volume.set}
-       </button><input name=action type=hidden value=volume>
+          @label{volume.set}
+       </button>
+       <input name=action type=hidden value=volume>
      }
 @# Volume down button
      @right{volume}{
@@ -137,101 +141,55 @@ USA
       <th class=length>@label{heading.length}</th>
       <th class=button>&nbsp;</th>
       @ifmanage{
-      <th class=imgbutton>&nbsp;</th>
-      <th class=imgbutton>&nbsp;</th>
-      <th class=imgbutton>&nbsp;</th>
-      <th class=imgbutton>&nbsp;</th>
+       <th class=imgbutton>&nbsp;</th>
+       <th class=imgbutton>&nbsp;</th>
+       <th class=imgbutton>&nbsp;</th>
+       <th class=imgbutton>&nbsp;</th>
       }{}
      </tr>
+     @if{@isplaying}{
+       <tr class=nowplaying>
+       <td colspan=@ifmanage{11}{7}>@label{playing.now}</td>
+       </tr>
+     }
      @playing{
-     <tr class=nowplaying>
-      <td colspan=@ifmanage{11}{7}>@label{playing.now}</td>
-     </tr>
-     <tr class=playing>
-      <td class=when>@mwhen{playing}{@id}</td>
-      <td class=who>@mwho{playing}{@id}</td>
-      <td class=artist>@martist{playing}{@track}</td>
-      <td class=album>@malbum{playing}{@track}</td>
-      <td class=title>@mtitle{playing}{@track}</td>
-      <td class=length>@length{@id}</td>
-      <td class=imgbutton>@mremove{playing}{@id}</td>
-      @ifmanage{
-      <td class=imgbutton>&nbsp;</td>
-      <td class=imgbutton>&nbsp;</td>
-      <td class=imgbutton>&nbsp;</td>
-      <td class=imgbutton>&nbsp;</td>
-      }{}
-     </tr>
+       <tr class=playing>
+       <td class=when>@mwhen{playing}{@id}</td>
+       <td class=who>@mwho{playing}{@id}</td>
+       <td class=artist>@martist{playing}{@track}</td>
+       <td class=album>@malbum{playing}{@track}</td>
+       <td class=title>@mtitle{playing}{@track}</td>
+       <td class=length>@length{@id}</td>
+       <td class=imgbutton>@mremove{playing}{@id}</td>
+       @ifmanage{
+         <td class=imgbutton>&nbsp;</td>
+         <td class=imgbutton>&nbsp;</td>
+         <td class=imgbutton>&nbsp;</td>
+         <td class=imgbutton>&nbsp;</td>
+       }{}
+       </tr>
      }
      @if{@isqueue@}{
-     <tr class=next>
-      <td colspan=@ifmanage{11}{7}@>@label{playing.next}</td>
-     </tr>
+       <tr class=next>
+       <td colspan=@ifmanage{11}{7}@>@label{playing.next}</td>
+       </tr>
      }
      @queue{
-     <tr class=@parity@>
-      <td class=when>@mwhen{queue}{@id}</td>
-      <td class=who>@mwho{queue}{@id}</td>
-      <td class=artist>@martist{queue}{@track}</td>
-      <td class=album>@malbum{queue}{@track}</td>
-      <td class=title>@mtitle{queue}{@track}</td>
-      <td class=length>@length</td>
-      <td class=imgbutton>@mremove{queue}{@id}</td>
-
-      @if{@eq{@arg{action}}{manage}}{
-      @if{@or{@isfirst@}
-             {@not{@movable@}@}@}{
-     <!-- cannot move up -->
-     <td class=imgbutton>
-      <img
-       class=button src="@image{noupall}"
-       title="@label{playing.upallverbose}" alt="">
-     <td class=imgbutton>
-      <img
-       class=button src="@image{noup}"
-       title="@label{playing.upverbose}" alt="">
-         }{
-     <!-- can move up -->
-     <td class=imgbutton>
-      <a class=imgbutton
-        href="@url?action=move&#38;id=@id@&#38;delta=2147483647@back"><img
-       class=button src="@image{upall}"
-       title="@label{playing.upallverbose}"
-       alt="@label{playing.upall}"></a>
-     <td class=imgbutton>
-     <a class=imgbutton
-        href="@url?action=move&#38;id=@id@&#38;delta=1@back"><img
-       class=button src="@image{up}"
-       title="@label{playing.upverbose}" alt="@label{playing.up}"></a>
-         }
-
-      @if{@or{@islast@}
-             {@not{@movable@}@}@}{
-     <!-- cannot move down -->
-     <td class=imgbutton>
-      <img
-       class=button src="@image{nodownall}"
-       title="@label{playing.downallverbose}" alt="">
-     <td class=imgbutton>
-      <img
-       class=button src="@image{nodown}"
-       title="@label{playing.downverbose}" alt="">
-         }{
-     <!-- can move down -->
-     <td class=imgbutton>
-      <a class=imgbutton
-        href="@url?action=move&#38;id=@id@&#38;delta=-2147483647@back"><img
-       class=button src="@image{downall}"
-       title="@label{playing.downallverbose}"
-       alt="@label{playing.downall}"></a>
-     <td class=imgbutton>
-     <a class=imgbutton
-        href="@url?action=move&#38;id=@id@&#38;delta=-1@back"><img
-       class=button src="@image{down}"
-       title="@label{playing.downverbose}" alt="@label{playing.down}"></a>
-         }
-      }
-     </tr>
+       <tr class=@parity@>
+       <td class=when>@mwhen{queue}{@id}</td>
+       <td class=who>@mwho{queue}{@id}</td>
+       <td class=artist>@martist{queue}{@track}</td>
+       <td class=album>@malbum{queue}{@track}</td>
+       <td class=title>@mtitle{queue}{@track}</td>
+       <td class=length>@length</td>
+       <td class=imgbutton>@mremove{queue}{@id}</td>
+       @ifmanage{
+         <td class=imgbutton>@mmove{@id}{upall}{2147483647}</td>
+         <td class=imgbutton>@mmove{@id}{up}{1}</td>
+         <td class=imgbutton>@mmove{@id}{down}{-1}</td>
+         <td class=imgbutton>@mmove{@id}{downall}{-2147483647}</td>
+       }
+       </tr>
      }
    </table>
 }