slitaz-tools diff oldstuff/tazdialog @ rev 832

tazhw: use /sys/bus/usb to find usb devices and mods
author Christophe Lincoln <pankso@slitaz.org>
date Wed Jan 29 12:05:17 2014 +0100 (2014-01-29)
parents 507c5860528f
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/oldstuff/tazdialog	Wed Jan 29 12:05:17 2014 +0100
     1.3 @@ -0,0 +1,216 @@
     1.4 +#!/bin/sh
     1.5 +# tazdialog - SliTaz GNU/Linux dialog wrapper to gtkdialog.
     1.6 +#
     1.7 +# (C) 2008 SliTaz - GNU General Public License v3.
     1.8 +#
     1.9 +# Author : Pascal Bellard <pascal.bellard@slitaz.org>
    1.10 +#
    1.11 +
    1.12 +toutf8()
    1.13 +{
    1.14 +echo -e $1 | sed -e 's/\\Z.//g' | tr 'àâäçéèêëîïûü' 'aaaceeeeiiuu'
    1.15 +}
    1.16 +
    1.17 +fake_gauge()
    1.18 +{
    1.19 +[ -n "$percent" ] && echo $percent
    1.20 +while read line; do
    1.21 +	case "$line" in
    1.22 +	[0-9]*) echo $line;;
    1.23 +	*);;
    1.24 +	esac
    1.25 +done
    1.26 +echo 100
    1.27 +}
    1.28 +
    1.29 +fake_dialog()
    1.30 +{
    1.31 +if [ -n "$gauge" ]; then
    1.32 +	fake_gauge | gtkdialog --center --program=BOX
    1.33 +else
    1.34 +	gtkdialog --center --program=BOX
    1.35 +fi 2> /dev/null | while read line; do
    1.36 +	case "$line" in
    1.37 +	*OUTPUT*) eval $line
    1.38 +		echo "$OUTPUT" 1>&2 ;;
    1.39 +	*CHECK*true*) line=${line%=*}; line=${line#CHECK}
    1.40 +		[ $line -eq 0 ] || shift $((3 * $line))
    1.41 +		echo -n "\"$1\" " 1>&2;;
    1.42 +	*LIST=*) eval $line; set -- $LIST
    1.43 +		echo "$1" 1>&2 ;;
    1.44 +	*EXIT*abort*) echo 255;;
    1.45 +	*EXIT*) eval $line
    1.46 +		echo $EXIT ;;
    1.47 +	esac
    1.48 +done
    1.49 +}
    1.50 +
    1.51 +if [ -z "$XAUTHORITY" ]; then
    1.52 +	[ -n "$TEXTDIALOG" ] || TEXTDIALOG="dialog"
    1.53 +	export DIALOG=$TEXTDIALOG
    1.54 +	exec $TEXTDIALOG "$@"
    1.55 +else
    1.56 +	title=""
    1.57 +	backtitle=""
    1.58 +	lines="10"
    1.59 +	cols="10"
    1.60 +	[ -n "$ICON" ] || ICON="applications-other"
    1.61 +	buttonok=""
    1.62 +	buttoncancel=""
    1.63 +	buttonextra=""
    1.64 +	yeslabel="ok"
    1.65 +	nolabel="cancel"
    1.66 +	extralabel="rename"
    1.67 +	gauge=""
    1.68 +	inputbox=""
    1.69 +	default=""
    1.70 +	buttonhelp=""
    1.71 +	checklist=""
    1.72 +	menu=""
    1.73 +	textbox=""
    1.74 +	radiolist=""
    1.75 +	fselect=""
    1.76 +	while [ -n "$1" ]; do
    1.77 +		case "$1" in
    1.78 +		--title) title="$2"; shift 2;;
    1.79 +		--backtitle) backtitle="$2"; shift 2;;
    1.80 +		--clear|--colors) shift;;
    1.81 +		--yes-label) yeslabel="$2"; shift 2;;
    1.82 +		--no-label) nolabel="$2"; shift 2;;
    1.83 +		--extra-label) extralabel="$2"; shift 2;;
    1.84 +		--extra-button) buttonextra="1"; shift;;
    1.85 +		--help-button) buttonhelp="1"; shift;;
    1.86 +		--msgbox) msgbox="$2"; lines="$3"; cols="$4"
    1.87 +			buttonok="1"; break;;
    1.88 +		--yesno) msgbox="$2"; lines="$3"; cols="$4"
    1.89 +			buttonok="1"; buttoncancel="1"; break;;
    1.90 +		--gauge) msgbox="$2"; lines="$3"; cols="$4"
    1.91 +			percent="$5"; gauge="1"; break;;
    1.92 +		--inputbox) msgbox="$2"; lines="$3"; cols="$4"; default="$5"
    1.93 +			buttonok="1"; buttoncancel="1"; inputbox="1"; break;;
    1.94 +		--checklist) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5"
    1.95 +			buttonok="1"; checklist="1"; shift 5; break;;
    1.96 +		--menu) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5"
    1.97 +			buttonok="1"; buttoncancel="1"
    1.98 +			menu="1"; shift 5; break;;
    1.99 +		--textbox) textbox="$2"; lines="$3"; cols="$4"
   1.100 +			buttonok="1"; break;;
   1.101 +		--radiolist) textbox="$2"; lines="$3"; cols="$4"; inlines="$5"
   1.102 +			buttonok="1"; buttoncancel="1"
   1.103 +			radiolist="1"; shift 5; break;;
   1.104 +		--fselect) fselect="$2"; lines="$3"; cols="$4"
   1.105 +			buttonok="1"; buttoncancel="1"; break;;
   1.106 +		*) echo "Unknown arg $1"; exit 255;;
   1.107 +		esac
   1.108 +	done
   1.109 +fi
   1.110 +msgbox="$(toutf8 "$msgbox")"
   1.111 +textbox="$(toutf8 "$textbox")"
   1.112 +title="$(toutf8 "$title")"
   1.113 +backtitle="$(toutf8 "$backtitle")"
   1.114 +yeslabel="$(toutf8 "$yeslabel")"
   1.115 +nolabel="$(toutf8 "$nolabel")"
   1.116 +extralabel="$(toutf8 "$extralabel")"
   1.117 +default="$(toutf8 "$default")"
   1.118 +BOX="<window"
   1.119 +[ -n "$backtitle" ] && BOX="$BOX title=\"$backtitle\""
   1.120 +[ -n "$ICON" ] && BOX="$BOX icon-name=\"$ICON\""
   1.121 +BOX="$BOX>
   1.122 + <vbox>
   1.123 +"
   1.124 +[ -n "$title" ] && BOX="$BOX  <text use-markup=\"true\" width-chars=\"44\">
   1.125 +   <label>\"<b>$title</b>\" </label>
   1.126 +  </text>
   1.127 +"
   1.128 +[ -n "$msgbox" ] && BOX="$BOX  <text wrap=\"true\" use-markup=\"true\">
   1.129 +   <label> \"$msgbox\" </label>
   1.130 +  </text>
   1.131 +"
   1.132 +[ -n "$gauge" ] && BOX="$BOX  <progressbar>
   1.133 +   <input>while read data; do echo \$data; done</input>
   1.134 +   <action type=\"exit\">0</action>
   1.135 +  </progressbar>
   1.136 +"
   1.137 +[ -n "$default" ] && default="<default>$default</default>
   1.138 +  "
   1.139 +[ -n "$inputbox" ] && BOX="$BOX  <entry>
   1.140 +  $default<variable>OUTPUT</variable>
   1.141 +  </entry>
   1.142 +"
   1.143 +#[ -n "$textbox" ] && BOX="$BOX  <text><input file width-chars=\"$cols\" \
   1.144 +#height=\"$lines\" wrap=\"true\">$textbox</input></text>"
   1.145 +[ -n "$textbox" ] && BOX="$BOX  <text>
   1.146 +   <input file wrap=\"true\">$textbox</input>
   1.147 +  </text>
   1.148 +"
   1.149 +[ -n "$menu" ] && BOX="$BOX  <list>
   1.150 +$(while [ -n "$1" ]; do
   1.151 +    echo "   <item>$1 $2</item>
   1.152 +"
   1.153 +    shift 2
   1.154 +  done)   <variable>LIST</variable>
   1.155 +  </list>
   1.156 +"
   1.157 +[ -n "$radiolist" ] && BOX="$BOX$(
   1.158 +  i=0; while [ -n "$1" ]; do
   1.159 +    [ "$3" = "on" ] && c=" active=\"true\"" || c=""
   1.160 +    echo "  <radiobutton$c>
   1.161 +   <label>$1 $2</label>
   1.162 +   <variable>CHECK$i</variable>
   1.163 +  </radiobutton>
   1.164 +"
   1.165 +    i=$(($i+1))
   1.166 +    shift 3
   1.167 +  done)"
   1.168 +[ -n "$checklist" ] && BOX="$BOX  $(
   1.169 +  i=0; while [ -n "$1" ]; do
   1.170 +    [ "$3" = "on" ] && c=" active=\"true\"" || c=""
   1.171 +    echo "  <checkbox$c>
   1.172 +   <label>$1 $2</label>
   1.173 +   <variable>CHECK$i</variable>
   1.174 +  </checkbox>
   1.175 +"
   1.176 +    i=$(($i+1))
   1.177 +    shift 3
   1.178 +  done)"
   1.179 +[ -n "$fselect" ] && BOX="$BOX  <hbox>
   1.180 +   <entry>
   1.181 +    <variable>OUTPUT</variable>
   1.182 +   </entry>
   1.183 +   <button>
   1.184 +    <input file stock=\"gtk-open\"></input>
   1.185 +    <variable>FILE_BROWSE</variable>
   1.186 +    <action type=\"fileselect\">OUTPUT</action>
   1.187 +   </button>
   1.188 +  </hbox>
   1.189 +"
   1.190 +[ "$yeslabel" = "ok" ] && yeslabel="" || yeslabel="
   1.191 +    <label>$yeslabel</label>"
   1.192 +[ "$nolabel" = "cancel" ] && nolabel="" || nolabel="
   1.193 +    <label>$nolabel</label>"
   1.194 +[ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX  <hbox>"
   1.195 +[ -n "$buttonok" ] && BOX="$BOX   <button ok>$yeslabel
   1.196 +    <action type=\"exit\">0</action>
   1.197 +   </button>
   1.198 +"
   1.199 +[ -n "$buttonextra" ] && BOX="$BOX   <button>
   1.200 +    <label>$extralabel</label>
   1.201 +    <input file icon=\"forward\"> </input>
   1.202 +    <action type=\"exit\">3</action>
   1.203 +   </button>
   1.204 +"
   1.205 +[ -n "$buttoncancel" ] && BOX="$BOX   <button cancel>$nolabel
   1.206 +    <action type=\"exit\">1</action>
   1.207 +   </button>
   1.208 +"
   1.209 +[ -n "$buttonhelp" ] && BOX="$BOX   <button help>
   1.210 +    <action type=\"exit\">2</action> 
   1.211 +   </button>
   1.212 +"
   1.213 +[ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX  </hbox>
   1.214 +"
   1.215 +BOX="$BOX </vbox>
   1.216 +</window>
   1.217 +"
   1.218 +export BOX
   1.219 +exit $(fake_dialog)