slitaz-tools annotate lib/gui_functions @ rev 461

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