slitaz-tools view lib/gui_functions @ rev 697

Added tag 4.7 for changeset 83491d0ac7b1
author Christophe Lincoln <pankso@slitaz.org>
date Thu Mar 01 15:56:00 2012 +0100 (2012-03-01)
parents
children
line source
1 #!/bin/sh
2 #
3 #
4 # Tab display engine
5 #
6 ######################################################
8 use_tab()
9 {
10 local tmp=''
11 case "$2" in
12 header|body)
13 $1 | while read exe name call; do
14 case "$exe" in
15 \#*) continue;;
16 /*) [ -e $exe ] || continue;;
17 *) which $exe > /dev/null || continue
18 esac
19 if [ "$2" == "header" ]; then
20 echo -n "$tmp$name"
21 tmp='|'
22 else
23 $call
24 fi
25 done
26 ;;
27 *)
28 tmp=$(use_tab $1 header)
29 echo "$tmp" | grep -q \| && cat <<EOT
30 <notebook labels="$tmp">
31 EOT
32 [ -n "$tmp" ] && cat <<EOT
33 $(use_tab $1 body)
34 EOT
35 echo "$tmp" | grep -q \| && cat <<EOT
36 </notebook>
37 EOT
38 ;;
39 esac
40 }
42 #
43 # GUI functions
44 #
45 ############################################################
47 xterm="xterm -fa MiscFixed -fs 11"
48 helpbutton()
49 {
50 local label;
51 label="<label>$3</label>"
52 [ -n "$3" ] || label=""
53 cat << EOT
54 <button>
55 <input file icon="help"></input>$label
56 <action>$xterm -geometry $2 -title "$1 help (q to quit)" -e "( echo ; $(which $1) --help 2>&1 ) | less"</action>
57 </button>
58 EOT
59 }
61 editbutton()
62 {
63 cat << EOT
64 <button>
65 <input file icon="accessories-text-editor"></input>
66 <action type="lauch">leafpad $1</action>
67 </button>
68 EOT
69 }
71 manbutton()
72 {
73 cat << EOT
74 <button>
75 <input file icon="browser"></input>
76 <label>man</label>
77 <action>$xterm -geometry 80x24 -title "$2 man (q to quit)" -e ". /etc/profile; man $1 $2"</action>
78 </button>
79 EOT
80 }
82 helpdaemon()
83 {
84 cat << EOT
85 <hbox>
86 <text use-markup="true">
87 <label>"<b>$3</b>"</label>
88 </text>
89 <entry editable="false">
90 EOT
91 eval tmp=\$$3
92 [ -n "$tmp" ] && cat << EOT
93 <default>$tmp</default>
94 EOT
95 cat << EOT
96 <variable>$4</variable>
97 </entry>
98 EOT
99 [ -n "$6" ] || cat << EOT
100 $(helpbutton $1 $2)
101 EOT
102 [ -n "$5" ] && cat << EOT
103 $(manbutton $5 $1)
104 EOT
105 cat << EOT
106 $(editbutton /etc/daemons.conf)
107 </hbox>
108 EOT
109 }
111 datafile()
112 {
113 cat << EOT
114 <hbox>
115 <text use-markup="true">
116 <label>"<b>$3</b>"</label>
117 </text>
118 <entry editable="false">
119 EOT
120 [ -n "$1" ] && cat << EOT
121 <default>$1</default>
122 EOT
123 cat << EOT
124 <variable>$2</variable>
125 </entry>
126 EOT
127 [ -n "$4" ] && cat << EOT
128 $(manbutton $4)
129 EOT
130 cat << EOT
131 $(editbutton \$$2)
132 </hbox>
133 EOT
134 }
136 configfile()
137 {
138 datafile "$1" $2 'Configuration:' "$3"
139 }
141 BROWSER=''
142 for i in firefox opera dillo midori netsurf links ; do
143 which $i > /dev/null && BROWSER="$i" && break
144 done
145 case "$BROWSER" in
146 links) BROWSER="links -g ";;
147 esac
149 webbutton()
150 {
151 [ -f "/var/lib/tazpkg/installed/$1/receipt" ] &&
152 [ -n "$BROWSER" ] && cat << EOT
153 <button>
154 <input file icon="browser"></input>
155 <label>web</label>
156 <action>. /var/lib/tazpkg/installed/$1/receipt ; $BROWSER \$WEB_SITE &</action>
157 </button>
158 EOT
159 }
161 wikibutton()
162 {
163 [ -n "$BROWSER" ] && cat <<EOT
164 <button>
165 <input file icon="browser"></input>
166 <label>Wiki</label>
167 <action>$BROWSER $1 &</action>
168 </button>
169 EOT
170 }
172 startstopdaemon()
173 {
174 local pkg
175 pkg=$1
176 [ -n "$2" ] && pkg=$2
177 if [ ! -d /var/lib/tazpkg/installed/${pkg} ]; then
178 installbox $pkg
179 fi
180 webbutton $pkg
181 cat << EOT
182 <button>
183 <label>Start</label>
184 <input file icon="forward"></input>
185 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)$1 \?\\(.*\\)\\"/RUN_DAEMONS=\\"\1\2\\"/" /etc/rcS.conf</action>
186 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)\\"/RUN_DAEMONS=\\"$1 \1\\"/" /etc/rcS.conf</action>
187 <action>/etc/init.d/$1 start</action>
188 </button>
189 <button>
190 <label>Stop</label>
191 <input file icon="stop"></input>
192 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)$1 \?\\(.*\\)\\"/RUN_DAEMONS=\\"\1\2\\"/" /etc/rcS.conf</action>
193 <action>/etc/init.d/$1 stop</action>
194 </button>
195 EOT
196 }
198 installbox()
199 {
200 cat << EOT
201 <hbox>
203 <button>
204 <input file icon="go-jump"></input>
205 <label>Install</label>
206 <action>$xterm -geometry 80x17 -title "$1 install" -e "yes y | tazpkg get-install $1 ; echo -e \"----\n\nENTER to continue...\" && read close"</action>
207 <action type="exit">restart</action>
208 </button>
209 </hbox>
210 EOT
211 }