slitaz-tools annotate oldstuff/tazdialog @ rev 837

Add slitaz-config and same size for tazkeymap, tazlocale, tazx
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 17 22:23:32 2014 +0100 (2014-03-17)
parents 507c5860528f
children
rev   line source
pascal@190 1 #!/bin/sh
pascal@190 2 # tazdialog - SliTaz GNU/Linux dialog wrapper to gtkdialog.
pascal@190 3 #
pascal@190 4 # (C) 2008 SliTaz - GNU General Public License v3.
pascal@190 5 #
pascal@190 6 # Author : Pascal Bellard <pascal.bellard@slitaz.org>
pascal@190 7 #
pascal@190 8
pascal@190 9 toutf8()
pascal@190 10 {
pascal@190 11 echo -e $1 | sed -e 's/\\Z.//g' | tr 'àâäçéèêëîïûü' 'aaaceeeeiiuu'
pascal@190 12 }
pascal@190 13
pascal@249 14 fake_gauge()
pascal@249 15 {
pascal@249 16 [ -n "$percent" ] && echo $percent
pascal@249 17 while read line; do
pascal@249 18 case "$line" in
pascal@249 19 [0-9]*) echo $line;;
pascal@249 20 *);;
pascal@249 21 esac
pascal@249 22 done
pascal@249 23 echo 100
pascal@249 24 }
pascal@249 25
pascal@249 26 fake_dialog()
pascal@249 27 {
pascal@249 28 if [ -n "$gauge" ]; then
pascal@249 29 fake_gauge | gtkdialog --center --program=BOX
pascal@249 30 else
pascal@249 31 gtkdialog --center --program=BOX
pascal@249 32 fi 2> /dev/null | while read line; do
pascal@249 33 case "$line" in
pascal@249 34 *OUTPUT*) eval $line
pascal@249 35 echo "$OUTPUT" 1>&2 ;;
pascal@249 36 *CHECK*true*) line=${line%=*}; line=${line#CHECK}
pascal@249 37 [ $line -eq 0 ] || shift $((3 * $line))
pascal@249 38 echo -n "\"$1\" " 1>&2;;
pascal@249 39 *LIST=*) eval $line; set -- $LIST
pascal@249 40 echo "$1" 1>&2 ;;
pascal@249 41 *EXIT*abort*) echo 255;;
pascal@249 42 *EXIT*) eval $line
pascal@249 43 echo $EXIT ;;
pascal@249 44 esac
pascal@249 45 done
pascal@249 46 }
pascal@249 47
pascal@190 48 if [ -z "$XAUTHORITY" ]; then
pascal@190 49 [ -n "$TEXTDIALOG" ] || TEXTDIALOG="dialog"
pascal@190 50 export DIALOG=$TEXTDIALOG
pascal@243 51 exec $TEXTDIALOG "$@"
pascal@190 52 else
pascal@190 53 title=""
pascal@190 54 backtitle=""
pascal@190 55 lines="10"
pascal@190 56 cols="10"
pankso@192 57 [ -n "$ICON" ] || ICON="applications-other"
pascal@190 58 buttonok=""
pascal@190 59 buttoncancel=""
pascal@190 60 buttonextra=""
pascal@190 61 yeslabel="ok"
pascal@190 62 nolabel="cancel"
pascal@190 63 extralabel="rename"
pascal@190 64 gauge=""
pascal@190 65 inputbox=""
pascal@190 66 default=""
pascal@190 67 buttonhelp=""
pascal@190 68 checklist=""
pascal@190 69 menu=""
pascal@190 70 textbox=""
pascal@199 71 radiolist=""
pascal@199 72 fselect=""
pascal@190 73 while [ -n "$1" ]; do
pascal@190 74 case "$1" in
pascal@190 75 --title) title="$2"; shift 2;;
pascal@190 76 --backtitle) backtitle="$2"; shift 2;;
pascal@190 77 --clear|--colors) shift;;
pascal@190 78 --yes-label) yeslabel="$2"; shift 2;;
pascal@190 79 --no-label) nolabel="$2"; shift 2;;
pascal@190 80 --extra-label) extralabel="$2"; shift 2;;
pankso@192 81 --extra-button) buttonextra="1"; shift;;
pascal@190 82 --help-button) buttonhelp="1"; shift;;
pascal@190 83 --msgbox) msgbox="$2"; lines="$3"; cols="$4"
pascal@190 84 buttonok="1"; break;;
pascal@190 85 --yesno) msgbox="$2"; lines="$3"; cols="$4"
pascal@190 86 buttonok="1"; buttoncancel="1"; break;;
pascal@190 87 --gauge) msgbox="$2"; lines="$3"; cols="$4"
pascal@190 88 percent="$5"; gauge="1"; break;;
pascal@207 89 --inputbox) msgbox="$2"; lines="$3"; cols="$4"; default="$5"
pascal@207 90 buttonok="1"; buttoncancel="1"; inputbox="1"; break;;
pascal@190 91 --checklist) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5"
pascal@199 92 buttonok="1"; checklist="1"; shift 5; break;;
pascal@190 93 --menu) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5"
pascal@190 94 buttonok="1"; buttoncancel="1"
pascal@199 95 menu="1"; shift 5; break;;
pascal@190 96 --textbox) textbox="$2"; lines="$3"; cols="$4"
pascal@190 97 buttonok="1"; break;;
pascal@199 98 --radiolist) textbox="$2"; lines="$3"; cols="$4"; inlines="$5"
pascal@199 99 buttonok="1"; buttoncancel="1"
pascal@199 100 radiolist="1"; shift 5; break;;
pascal@199 101 --fselect) fselect="$2"; lines="$3"; cols="$4"
pascal@199 102 buttonok="1"; buttoncancel="1"; break;;
pascal@250 103 *) echo "Unknown arg $1"; exit 255;;
pascal@190 104 esac
pascal@190 105 done
pascal@190 106 fi
pascal@190 107 msgbox="$(toutf8 "$msgbox")"
pascal@190 108 textbox="$(toutf8 "$textbox")"
pascal@207 109 title="$(toutf8 "$title")"
pascal@207 110 backtitle="$(toutf8 "$backtitle")"
pascal@207 111 yeslabel="$(toutf8 "$yeslabel")"
pascal@207 112 nolabel="$(toutf8 "$nolabel")"
pascal@207 113 extralabel="$(toutf8 "$extralabel")"
pascal@207 114 default="$(toutf8 "$default")"
pascal@190 115 BOX="<window"
pascal@190 116 [ -n "$backtitle" ] && BOX="$BOX title=\"$backtitle\""
pascal@190 117 [ -n "$ICON" ] && BOX="$BOX icon-name=\"$ICON\""
pascal@199 118 BOX="$BOX>
pascal@199 119 <vbox>
pascal@199 120 "
pascal@199 121 [ -n "$title" ] && BOX="$BOX <text use-markup=\"true\" width-chars=\"44\">
pascal@199 122 <label>\"<b>$title</b>\" </label>
pascal@199 123 </text>
pascal@199 124 "
pascal@199 125 [ -n "$msgbox" ] && BOX="$BOX <text wrap=\"true\" use-markup=\"true\">
pascal@199 126 <label> \"$msgbox\" </label>
pascal@199 127 </text>
pascal@199 128 "
pascal@199 129 [ -n "$gauge" ] && BOX="$BOX <progressbar>
pascal@199 130 <input>while read data; do echo \$data; done</input>
pascal@199 131 <action type=\"exit\">0</action>
pascal@199 132 </progressbar>
pascal@199 133 "
pascal@199 134 [ -n "$default" ] && default="<default>$default</default>
pascal@199 135 "
pascal@199 136 [ -n "$inputbox" ] && BOX="$BOX <entry>
pascal@199 137 $default<variable>OUTPUT</variable>
pascal@199 138 </entry>
pascal@199 139 "
pascal@190 140 #[ -n "$textbox" ] && BOX="$BOX <text><input file width-chars=\"$cols\" \
pascal@190 141 #height=\"$lines\" wrap=\"true\">$textbox</input></text>"
pascal@199 142 [ -n "$textbox" ] && BOX="$BOX <text>
pascal@199 143 <input file wrap=\"true\">$textbox</input>
pascal@199 144 </text>
pascal@199 145 "
pascal@199 146 [ -n "$menu" ] && BOX="$BOX <list>
pascal@199 147 $(while [ -n "$1" ]; do
pascal@199 148 echo " <item>$1 $2</item>
pascal@199 149 "
pascal@190 150 shift 2
pascal@199 151 done) <variable>LIST</variable>
pascal@199 152 </list>
pascal@199 153 "
pascal@199 154 [ -n "$radiolist" ] && BOX="$BOX$(
pascal@199 155 i=0; while [ -n "$1" ]; do
pascal@190 156 [ "$3" = "on" ] && c=" active=\"true\"" || c=""
pascal@199 157 echo " <radiobutton$c>
pascal@199 158 <label>$1 $2</label>
pascal@199 159 <variable>CHECK$i</variable>
pascal@199 160 </radiobutton>
pascal@199 161 "
pascal@190 162 i=$(($i+1))
pascal@190 163 shift 3
pascal@190 164 done)"
pascal@199 165 [ -n "$checklist" ] && BOX="$BOX $(
pascal@199 166 i=0; while [ -n "$1" ]; do
pascal@199 167 [ "$3" = "on" ] && c=" active=\"true\"" || c=""
pascal@199 168 echo " <checkbox$c>
pascal@199 169 <label>$1 $2</label>
pascal@199 170 <variable>CHECK$i</variable>
pascal@199 171 </checkbox>
pascal@199 172 "
pascal@199 173 i=$(($i+1))
pascal@199 174 shift 3
pascal@199 175 done)"
pascal@199 176 [ -n "$fselect" ] && BOX="$BOX <hbox>
pascal@199 177 <entry>
pascal@199 178 <variable>OUTPUT</variable>
pascal@199 179 </entry>
pascal@199 180 <button>
pascal@199 181 <input file stock=\"gtk-open\"></input>
pascal@199 182 <variable>FILE_BROWSE</variable>
pascal@199 183 <action type=\"fileselect\">OUTPUT</action>
pascal@199 184 </button>
pascal@199 185 </hbox>
pascal@199 186 "
pascal@199 187 [ "$yeslabel" = "ok" ] && yeslabel="" || yeslabel="
pascal@199 188 <label>$yeslabel</label>"
pascal@199 189 [ "$nolabel" = "cancel" ] && nolabel="" || nolabel="
pascal@199 190 <label>$nolabel</label>"
pascal@190 191 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX <hbox>"
pascal@199 192 [ -n "$buttonok" ] && BOX="$BOX <button ok>$yeslabel
pascal@199 193 <action type=\"exit\">0</action>
pascal@199 194 </button>
pascal@199 195 "
pascal@199 196 [ -n "$buttonextra" ] && BOX="$BOX <button>
pascal@199 197 <label>$extralabel</label>
pascal@199 198 <input file icon=\"forward\"> </input>
pascal@199 199 <action type=\"exit\">3</action>
pascal@199 200 </button>
pascal@199 201 "
pascal@199 202 [ -n "$buttoncancel" ] && BOX="$BOX <button cancel>$nolabel
pascal@199 203 <action type=\"exit\">1</action>
pascal@199 204 </button>
pascal@199 205 "
pascal@199 206 [ -n "$buttonhelp" ] && BOX="$BOX <button help>
pascal@199 207 <action type=\"exit\">2</action>
pascal@199 208 </button>
pascal@199 209 "
pascal@199 210 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX </hbox>
pascal@199 211 "
pascal@199 212 BOX="$BOX </vbox>
pascal@199 213 </window>
pascal@199 214 "
pascal@190 215 export BOX
pascal@249 216 exit $(fake_dialog)