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