slitaz-tools annotate tinyutils/tazdialog @ rev 207
tazdialog: more utf8->ascii convertions
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun May 25 14:53:28 2008 +0000 (2008-05-25) |
parents | 39e31613e665 |
children | 654fef5d705a |
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@190 | 14 if [ -z "$XAUTHORITY" ]; then |
pascal@190 | 15 [ -n "$TEXTDIALOG" ] || TEXTDIALOG="dialog" |
pascal@190 | 16 export DIALOG=$TEXTDIALOG |
pascal@190 | 17 $TEXTDIALOG "$@" |
pascal@190 | 18 return $? |
pascal@190 | 19 else |
pascal@190 | 20 title="" |
pascal@190 | 21 backtitle="" |
pascal@190 | 22 lines="10" |
pascal@190 | 23 cols="10" |
pankso@192 | 24 [ -n "$ICON" ] || ICON="applications-other" |
pascal@190 | 25 buttonok="" |
pascal@190 | 26 buttoncancel="" |
pascal@190 | 27 buttonextra="" |
pascal@190 | 28 yeslabel="ok" |
pascal@190 | 29 nolabel="cancel" |
pascal@190 | 30 extralabel="rename" |
pascal@190 | 31 gauge="" |
pascal@190 | 32 inputbox="" |
pascal@190 | 33 default="" |
pascal@190 | 34 buttonhelp="" |
pascal@190 | 35 checklist="" |
pascal@190 | 36 menu="" |
pascal@190 | 37 textbox="" |
pascal@199 | 38 radiolist="" |
pascal@199 | 39 fselect="" |
pascal@190 | 40 while [ -n "$1" ]; do |
pascal@190 | 41 case "$1" in |
pascal@190 | 42 --title) title="$2"; shift 2;; |
pascal@190 | 43 --backtitle) backtitle="$2"; shift 2;; |
pascal@190 | 44 --clear|--colors) shift;; |
pascal@190 | 45 --yes-label) yeslabel="$2"; shift 2;; |
pascal@190 | 46 --no-label) nolabel="$2"; shift 2;; |
pascal@190 | 47 --extra-label) extralabel="$2"; shift 2;; |
pankso@192 | 48 --extra-button) buttonextra="1"; shift;; |
pascal@190 | 49 --help-button) buttonhelp="1"; shift;; |
pascal@190 | 50 --msgbox) msgbox="$2"; lines="$3"; cols="$4" |
pascal@190 | 51 buttonok="1"; break;; |
pascal@190 | 52 --yesno) msgbox="$2"; lines="$3"; cols="$4" |
pascal@190 | 53 buttonok="1"; buttoncancel="1"; break;; |
pascal@190 | 54 --gauge) msgbox="$2"; lines="$3"; cols="$4" |
pascal@190 | 55 percent="$5"; gauge="1"; break;; |
pascal@207 | 56 --inputbox) msgbox="$2"; lines="$3"; cols="$4"; default="$5" |
pascal@207 | 57 buttonok="1"; buttoncancel="1"; inputbox="1"; break;; |
pascal@190 | 58 --checklist) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5" |
pascal@199 | 59 buttonok="1"; checklist="1"; shift 5; break;; |
pascal@190 | 60 --menu) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5" |
pascal@190 | 61 buttonok="1"; buttoncancel="1" |
pascal@199 | 62 menu="1"; shift 5; break;; |
pascal@190 | 63 --textbox) textbox="$2"; lines="$3"; cols="$4" |
pascal@190 | 64 buttonok="1"; break;; |
pascal@199 | 65 --radiolist) textbox="$2"; lines="$3"; cols="$4"; inlines="$5" |
pascal@199 | 66 buttonok="1"; buttoncancel="1" |
pascal@199 | 67 radiolist="1"; shift 5; break;; |
pascal@199 | 68 --fselect) fselect="$2"; lines="$3"; cols="$4" |
pascal@199 | 69 buttonok="1"; buttoncancel="1"; break;; |
pascal@190 | 70 *) echo "Unknown arg $1"; return 255;; |
pascal@190 | 71 esac |
pascal@190 | 72 done |
pascal@190 | 73 fi |
pascal@190 | 74 msgbox="$(toutf8 "$msgbox")" |
pascal@190 | 75 textbox="$(toutf8 "$textbox")" |
pascal@207 | 76 title="$(toutf8 "$title")" |
pascal@207 | 77 backtitle="$(toutf8 "$backtitle")" |
pascal@207 | 78 yeslabel="$(toutf8 "$yeslabel")" |
pascal@207 | 79 nolabel="$(toutf8 "$nolabel")" |
pascal@207 | 80 extralabel="$(toutf8 "$extralabel")" |
pascal@207 | 81 default="$(toutf8 "$default")" |
pascal@190 | 82 BOX="<window" |
pascal@190 | 83 [ -n "$backtitle" ] && BOX="$BOX title=\"$backtitle\"" |
pascal@190 | 84 [ -n "$ICON" ] && BOX="$BOX icon-name=\"$ICON\"" |
pascal@199 | 85 BOX="$BOX> |
pascal@199 | 86 <vbox> |
pascal@199 | 87 " |
pascal@199 | 88 [ -n "$title" ] && BOX="$BOX <text use-markup=\"true\" width-chars=\"44\"> |
pascal@199 | 89 <label>\"<b>$title</b>\" </label> |
pascal@199 | 90 </text> |
pascal@199 | 91 " |
pascal@199 | 92 [ -n "$msgbox" ] && BOX="$BOX <text wrap=\"true\" use-markup=\"true\"> |
pascal@199 | 93 <label> \"$msgbox\" </label> |
pascal@199 | 94 </text> |
pascal@199 | 95 " |
pascal@199 | 96 [ -n "$gauge" ] && BOX="$BOX <progressbar> |
pascal@199 | 97 <input>while read data; do echo \$data; done</input> |
pascal@199 | 98 <action type=\"exit\">0</action> |
pascal@199 | 99 </progressbar> |
pascal@199 | 100 " |
pascal@199 | 101 [ -n "$default" ] && default="<default>$default</default> |
pascal@199 | 102 " |
pascal@199 | 103 [ -n "$inputbox" ] && BOX="$BOX <entry> |
pascal@199 | 104 $default<variable>OUTPUT</variable> |
pascal@199 | 105 </entry> |
pascal@199 | 106 " |
pascal@190 | 107 #[ -n "$textbox" ] && BOX="$BOX <text><input file width-chars=\"$cols\" \ |
pascal@190 | 108 #height=\"$lines\" wrap=\"true\">$textbox</input></text>" |
pascal@199 | 109 [ -n "$textbox" ] && BOX="$BOX <text> |
pascal@199 | 110 <input file wrap=\"true\">$textbox</input> |
pascal@199 | 111 </text> |
pascal@199 | 112 " |
pascal@199 | 113 [ -n "$menu" ] && BOX="$BOX <list> |
pascal@199 | 114 $(while [ -n "$1" ]; do |
pascal@199 | 115 echo " <item>$1 $2</item> |
pascal@199 | 116 " |
pascal@190 | 117 shift 2 |
pascal@199 | 118 done) <variable>LIST</variable> |
pascal@199 | 119 </list> |
pascal@199 | 120 " |
pascal@199 | 121 [ -n "$radiolist" ] && BOX="$BOX$( |
pascal@199 | 122 i=0; while [ -n "$1" ]; do |
pascal@190 | 123 [ "$3" = "on" ] && c=" active=\"true\"" || c="" |
pascal@199 | 124 echo " <radiobutton$c> |
pascal@199 | 125 <label>$1 $2</label> |
pascal@199 | 126 <variable>CHECK$i</variable> |
pascal@199 | 127 </radiobutton> |
pascal@199 | 128 " |
pascal@190 | 129 i=$(($i+1)) |
pascal@190 | 130 shift 3 |
pascal@190 | 131 done)" |
pascal@199 | 132 [ -n "$checklist" ] && BOX="$BOX $( |
pascal@199 | 133 i=0; while [ -n "$1" ]; do |
pascal@199 | 134 [ "$3" = "on" ] && c=" active=\"true\"" || c="" |
pascal@199 | 135 echo " <checkbox$c> |
pascal@199 | 136 <label>$1 $2</label> |
pascal@199 | 137 <variable>CHECK$i</variable> |
pascal@199 | 138 </checkbox> |
pascal@199 | 139 " |
pascal@199 | 140 i=$(($i+1)) |
pascal@199 | 141 shift 3 |
pascal@199 | 142 done)" |
pascal@199 | 143 [ -n "$fselect" ] && BOX="$BOX <hbox> |
pascal@199 | 144 <entry> |
pascal@199 | 145 <variable>OUTPUT</variable> |
pascal@199 | 146 </entry> |
pascal@199 | 147 <button> |
pascal@199 | 148 <input file stock=\"gtk-open\"></input> |
pascal@199 | 149 <variable>FILE_BROWSE</variable> |
pascal@199 | 150 <action type=\"fileselect\">OUTPUT</action> |
pascal@199 | 151 </button> |
pascal@199 | 152 </hbox> |
pascal@199 | 153 " |
pascal@199 | 154 [ "$yeslabel" = "ok" ] && yeslabel="" || yeslabel=" |
pascal@199 | 155 <label>$yeslabel</label>" |
pascal@199 | 156 [ "$nolabel" = "cancel" ] && nolabel="" || nolabel=" |
pascal@199 | 157 <label>$nolabel</label>" |
pascal@190 | 158 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX <hbox>" |
pascal@199 | 159 [ -n "$buttonok" ] && BOX="$BOX <button ok>$yeslabel |
pascal@199 | 160 <action type=\"exit\">0</action> |
pascal@199 | 161 </button> |
pascal@199 | 162 " |
pascal@199 | 163 [ -n "$buttonextra" ] && BOX="$BOX <button> |
pascal@199 | 164 <label>$extralabel</label> |
pascal@199 | 165 <input file icon=\"forward\"> </input> |
pascal@199 | 166 <action type=\"exit\">3</action> |
pascal@199 | 167 </button> |
pascal@199 | 168 " |
pascal@199 | 169 [ -n "$buttoncancel" ] && BOX="$BOX <button cancel>$nolabel |
pascal@199 | 170 <action type=\"exit\">1</action> |
pascal@199 | 171 </button> |
pascal@199 | 172 " |
pascal@199 | 173 [ -n "$buttonhelp" ] && BOX="$BOX <button help> |
pascal@199 | 174 <action type=\"exit\">2</action> |
pascal@199 | 175 </button> |
pascal@199 | 176 " |
pascal@199 | 177 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX </hbox> |
pascal@199 | 178 " |
pascal@199 | 179 BOX="$BOX </vbox> |
pascal@199 | 180 </window> |
pascal@199 | 181 " |
pascal@190 | 182 export BOX |
pascal@190 | 183 status=$(if [ -n "$gauge" ]; then |
pascal@207 | 184 ([ -n "$percent" ] && echo $percent |
pascal@207 | 185 while read line; do |
pascal@190 | 186 case "$line" in |
pascal@190 | 187 [0-9]*) echo $line;; |
pascal@190 | 188 *);; |
pascal@190 | 189 esac |
pascal@190 | 190 done ; echo 100) | gtkdialog --center --program=BOX |
pascal@190 | 191 else |
pascal@190 | 192 gtkdialog --center --program=BOX |
pascal@190 | 193 fi 2> /dev/null | while read line; do |
pascal@190 | 194 case "$line" in |
pascal@190 | 195 *OUTPUT*) eval $line |
pascal@190 | 196 echo "$OUTPUT" 1>&2 ;; |
pascal@190 | 197 *CHECK*true*) line=${line%=*}; line=${line#CHECK} |
pascal@199 | 198 [ $line -eq 0 ] || shift $((3 * $line)) |
pascal@199 | 199 echo -n "\"$1\" " 1>&2;; |
pascal@190 | 200 *LIST=*) eval $line; set -- $LIST |
pascal@190 | 201 echo "$1" 1>&2 ;; |
pascal@190 | 202 *EXIT*abort*) echo 255;; |
pascal@190 | 203 *EXIT*) eval $line |
pascal@190 | 204 echo $EXIT ;; |
pascal@190 | 205 esac |
pascal@190 | 206 done) |
pascal@190 | 207 exit $status |