# HG changeset patch # User Aleksej Bobylev # Date 1449574700 -7200 # Node ID a01cde2b84e4c122cea41c5ae581754d427e78b5 # Parent 694b20d6963ce8fa42b11c84d65617e18985441b Allow many file choosers on a page; allow file filtering based on MIME type; fix working in Firefox diff -r 694b20d6963c -r a01cde2b84e4 index.cgi --- a/index.cgi Mon Dec 07 02:36:31 2015 +0200 +++ b/index.cgi Tue Dec 08 13:38:20 2015 +0200 @@ -73,12 +73,14 @@ case "$(GET do)" in *-selection) # display Yad file/dir picker (AJAX) - if [ "$(GET do)" == "dir-selection" ]; then + if [ "$(GET do)" == 'dir-selection' ]; then title="$(_ 'Choose directory')" - extra="--directory" + extra='--directory' + icon='folder' else title="$(_ 'Choose file')" - extra="" + extra='' + icon='text-plain' fi while read name arg ; do case "$(GET do)" in @@ -89,21 +91,45 @@ multiple --multiple preview --add-preview EOT + + if [ -n "$(GET type)" ]; then + # Get description and file pattern: yad can select only allowed file types + # For example, type='application/x-cd-image' + # Note, here implemented simplified code: not use mimetype aliases and generic icons + mimefile="/usr/share/mime/$(GET type).xml" + if [ -f "$mimefile" ]; then + if [ -n "$LANG" ]; then + # Localized description + desc="$(sed -n "s|^.*xml:lang=\"${LANG%%_*}\">\(.*\)<.*|\1|p" $mimefile)" + fi + if [ -z "$LANG" -o -z "$desc" ]; then + # Default (English) description + desc="$(sed -n "s|^.*\(.*\)<.*|\1|p" $mimefile)" + fi + # File pattern(s), for example, "*.iso\n*.iso9660" + pattern=$(sed -n 's|^.*pattern=\"\(.*\)\".*|\1|p' $mimefile) + extra="$extra --file-filter='$desc|$(echo $pattern)'" + fi + icon="$(echo $(GET type) | tr '/' '-')" + fi + header cd ${HOME:-/} if [ -r $HOME/.Xauthority ]; then - cat < -EOT + XAUTHORITY="$HOME/.Xauthority" else - cat < -EOT + XAUTHORITY='/var/run/slim.auth' fi + + # Problem with inline quoting in the yad option --file-filter + # Save temp script into file and execute it + tempsh="$(mktemp)" + echo "DISPLAY=':0.0' XAUTHORITY=\"$XAUTHORITY\" \ +yad --file-selection --on-top --mouse $extra --width=500 --height=350 \ +--title=\"$title\" --window-icon=\"$icon\"" > "$tempsh" + echo "" + rm "$tempsh" + exit 0 ;; esac diff -r 694b20d6963c -r a01cde2b84e4 lib/libtazpanel --- a/lib/libtazpanel Mon Dec 07 02:36:31 2015 +0200 +++ b/lib/libtazpanel Tue Dec 08 13:38:20 2015 +0200 @@ -411,17 +411,21 @@ # The html 'file' object does not return the full path. Ajax helps on localhost. file_chooser() { + # 1: name; 2: [predefined value]; 3: [button icon]; 4: [MIME type] + id="input$RANDOM" cat < - EOT } dir_chooser() { + # 1: name; 2: [predefined value]; 3: [button icon] + id="input$RANDOM" cat < - EOT }