slitaz-tools view tazbox/tazbox @ rev 994

tazbox/video: add 3gp files
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 04 13:59:25 2016 +0200 (2016-06-04)
parents 9c65d6b2f381
children bcfa8533c73f
line source
1 #!/bin/sh
2 #
3 # SliTaz tiny GUI boxes for the desktop (su, logout, locale, etc)
4 # and as usual, please: KISS
5 #
6 # Copyright (C) 2011-2015 SliTaz GNU/Linux - GNU GPL v3
7 # - Christophe Lincoln <pankso@slitaz.org>
8 # - Aleksej Bobylev <al.bobylev@gmail.com>
9 #
11 . /lib/libtaz.sh
12 export TEXTDOMAIN='tazbox' # i18n
15 # Get SliTaz settings
17 . /etc/slitaz/slitaz.conf
20 # download dir (may be in a config file)
22 DOWNLOADS="$HOME/Downloads"
25 # some constants to be used inside functions
27 tmp='/tmp/keymap.list'
28 db='/usr/share/i18n/locales'
29 zi='/usr/share/zoneinfo/'
30 ztab="${zi}zone-mini.tab"
31 csv='/tmp/freegeoip.csv'
34 #
35 # Functions
36 #
38 usage() {
39 newline; _ 'SliTaz tiny GUI boxes for the desktop'
41 newline; boldify $(_ 'Usage:')
42 echo " $(basename $0) [$(_n 'command')]"
44 newline; boldify $(_ 'Commands:')
45 optlist "\
46 usage $(_ 'Display this short help usage')
47 su $(_ 'Execute a command as super-user')
48 logout $(_ 'Desktop logout box with actions')
49 out $(_ 'Pipe a command output into a GTK window')
50 out-dl $(_ 'Pipe wget output into a GTK window')
51 locale $(_ 'Configure system language (root)')
52 keymap $(_ 'Configure system keymap (root)')
53 tz $(_ 'Configure system timezone (root)')
54 setup $(_ 'System initial setup (locale, keymap & timezone)')
55 new-file $(_ 'Create a new file or folder on the desktop')
56 all-apps $(_ 'Display icons of all installed applications')
57 notify $(_ 'Notify user with a desktop centered box')
58 tazapps $(_ 'Configure SliTaz default applications')
59 vnc $(_ 'Launch a framebuffer VNC viewer')"
60 newline
61 }
64 # try to find icon in .desktop files
66 find_icon() {
67 local_desktop=$(find $HOME/.local/share/applications \
68 -name ${1##*/}.desktop 2&>/dev/null | head -n1)
69 system_desktop=$(find /usr/share/applications \
70 -name ${1##*/}.desktop 2&>/dev/null | head -n1)
71 desktop="${local_desktop:-$system_desktop}"
72 [ -n "$desktop" ] && cat $desktop | sed '/\[Desktop\ Entry\]/,/^\[/!d' | \
73 sed '/^Icon=/!d' | head -n1 | cut -d= -f2
74 }
77 # su frontend GUIs
79 su_main() {
80 CMD1="${1%% *}"; CMD2="$(echo "${1#* }" | sed 's|&|&amp;|g')"
81 : ${icon=$(find_icon $CMD1)}
82 icon="${icon:-dialog-password}"
84 yad --title="$(_n 'SliTaz admin password')" --window-icon=$icon \
85 --width=520 --on-top --center \
86 --image=$icon --image-on-top \
87 --text="$(_n 'Please enter root password (default root) to execute:')\n
88 <span foreground=\"red\"><tt><b>$CMD1</b> $CMD2</tt></span>\n" \
89 --form \
90 --field="$(_n 'Password:'):H" $PASSWD \
91 --field="$(_n 'Autosave password'):CHK" $CHECKED
92 }
95 su_error() {
96 icon='dialog-error'
97 yad --title="$(_n 'Error')" --window-icon=$icon \
98 --width=320 --on-top --center \
99 --image=$icon --image-on-top \
100 --text="\n<b>$(_n 'Error: wrong password!')</b>\n" \
101 --button="gtk-close:1"
102 }
105 # user may press cancel on download.
107 cancel_dl() {
108 if [ "$?" -eq 1 ]; then
109 _ "CANCEL"
110 rm -f $DOWNLOADS/$(basename $url)
111 fi
112 }
115 # output a command in a GTK window
117 output_command() {
118 : ${title=$(_n 'TazBox Output')}
119 : ${icon=dialog-information}
121 yad --title="$title" --window-icon="$icon" \
122 --geometry='600x220+0-24' --fore='#ffffff' --back='#000000' \
123 --text-info --fontname=monospace --wrap $opts \
124 --button='gtk-close:1'
125 }
128 # logout GUI function
130 logout_main() {
131 icon='/usr/share/pixmaps/slitaz-icon.png'
132 yad --title="$(_n 'SliTaz Logout')" --window-icon="$icon" \
133 --on-top --center --height='130' \
134 --image="$icon" --image-on-top \
135 --text="<b>$(_n 'SliTaz Logout - Please choose an action:')</b>" \
136 --always-print-result \
137 --button "$(_n 'Close X session')!system-log-out:4" \
138 --button "$(_n 'Reboot system')!system-reboot:3" \
139 --button "$(_n 'Shutdown system')!system-shutdown:2"
140 }
143 # generate keymap list
145 gen_kmap_list() {
146 echo > $tmp
147 cd /usr/share/kbd/keymaps/i386
148 # we first need a list to sort and then use \n for Yad list.
149 for i in $(find -type f | sed '/include/d; s|./||'); do
150 echo "$(basename $i .map.gz)|$(dirname $i)" >> $tmp
151 done
152 }
155 # Initial Config functions
157 setup_main() {
158 icon='preferences-desktop-locale'
159 gen_kmap_list
160 locale=$(ls -1 $db | grep ^[a-z][a-z]_[A-Z][A-Z] | tr "\n" "!")
161 keymap=$(cat $tmp | sort | tr "\n" "!")
162 timezone=$(find $zi -type f | sed s,$zi,,g | grep -v -F '.tab' | tr "\n" "!")
163 yad --title="$(_n 'SliTaz Initial Setup')" --window-icon=$icon \
164 --width='500' \
165 --image="$icon" --image-on-top \
166 --text="<big>$(_n 'Here you can set your preferences \n for <b>locale, keymap and timezone</b>.')</big>" \
167 --form \
168 --field "$(_n 'Locale'):CB" $locale \
169 --field "$(_n 'Keymap'):CB" $keymap \
170 --field "$(_n 'Timezone'):CB" $timezone
171 }
174 setup() {
175 choices=$(setup_main)
176 locale=$( echo $choices | cut -d'|' -f1)
177 keymap=$( echo $choices | cut -d'|' -f2)
178 timezone=$(echo $choices | cut -d'|' -f3)
179 [ -n "$locale" ] && tazlocale init $locale
180 [ -n "$keymap" ] && tazkeymap init $keymap
181 [ -n "$timezone" ] && echo $timezone > /etc/TZ
182 }
185 #
186 # Locale functions
187 #
189 locale_main() {
190 icon='preferences-desktop-locale'
191 for locale in $(ls -1 $db | grep '[a-z]_[A-Z]'); do
192 desc=$(fgrep -m1 title $db/$locale | cut -d'"' -f2)
193 ll_CC=${locale%%@*}
194 echo -e "${ll_CC##*_}\n$locale\n$desc"
195 done | \
196 yad --title="$(_n 'SliTaz locale')" --window-icon="$icon" \
197 --width='600' --height='380' --sticky --on-top --center \
198 --image="$icon" --image-on-top \
199 --text="<b>$(_n 'Language configuration')</b> \
200 \n\n$(_ 'Tip: manage locales list by installing/removing locale packages.')" \
201 --list --column="$(_n 'Flag'):IMG" --column $(_n 'Name') \
202 --column $(_n 'Description') \
203 --print-column='2' --separator='' \
204 --button="$(_n 'Manage')!document-properties:2" \
205 --button="gtk-cancel:1" --button="gtk-ok:0"
206 }
209 locale() {
210 locale=$(locale_main)
211 # Deal with --button values
212 case $? in
213 2) tazbox manage_i18n main ;;
214 1) exit 0 ;;
215 *) continue ;;
216 esac
217 # System language configuration.
218 if [ "$locale" ]; then
219 tazlocale $locale
220 tazbox notify "$(_ 'Locale was set to %s' "$locale")" \
221 preferences-desktop-locale 3
222 fi
223 }
226 # Keymap functions
228 keymap_main() {
229 icon='preferences-desktop-keyboard'
230 gen_kmap_list
231 for i in $(sort $tmp); do
232 echo "$i" | tr '|' '\n'
233 done | \
234 yad --title="$(_ 'SliTaz keymap')" --window-icon=$icon \
235 --width=500 --height=380 --sticky --on-top --center \
236 --image=$icon --image-on-top \
237 --text="<b>$(_n 'Keyboard configuration')</b>" \
238 --list --column $(_n 'Keymap') --column $(_n 'Type') \
239 --print-column=1 --separator=''
240 rm -f $tmp
241 }
244 keymap() {
245 keymap=$(keymap_main)
246 # Deal with --button values
247 [ "$?" -eq 1 ] && exit 0
248 # System keymap configuration
249 [ -n "$keymap" ] && tazkeymap $keymap
250 }
253 # Free GeoIP service
254 # Response: IP,CountryCode,CountryName, ...
256 geoip() {
257 # freegeoip.net can be in the blocked hosts list. Return only correct answer or nothing
258 [ ! -e $csv ] && wget -q -T3 -O - http://freegeoip.net/csv/ 2&>/dev/null | \
259 grep '[0-9.]*,.*,.*,.*,.*,.*,.*,.*,[0-9.]*,[0-9.]*' > $csv
260 [ -e $csv ] && cut -d, -f2 $csv
261 }
264 #
265 # TZ functions
266 #
269 # list of all existing available locations for country
271 tz_list() {
272 find $zi | \
273 grep -E "$(awk -F$'\t' -vv="$1" '{if ($1 == v || $2 ~ v) print $2}' $ztab | tr ' ' '|')" | \
274 grep -v -E "posix|right" | \
275 sed 's|.*/||g' | sort
276 }
279 # ask for confirmation only if we have what to choose
281 tz_suggest() {
282 CountryCode=$(geoip)
283 if [ -n "$CountryCode" ]; then
284 if [ -n "$(tz_list $CountryCode)" ]; then
285 CountryName=$(cut -d, -f3 $csv)
286 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
287 --on-top --center \
288 --image="$CountryCode" --image-on-top \
289 --text="$(_ 'Suggested location:') <b>$CountryName</b>\n
290 $(_ 'Are you agreed?')" \
291 --button='gtk-yes:0' --button='gtk-no:1'
292 [ "$?" -eq 0 ] && echo $CountryCode
293 fi
294 fi
295 }
298 tz_select() {
299 case x$1 in
300 x)
301 # first pass - country
302 tmpcc=$(mktemp)
304 for tzfile in $(find $zi -type f -regex '.*info/[ABCEIMP].*'); do
305 grep -m1 $(basename $tzfile) $ztab
306 done | cut -d$'\t' -f1 | sort -u > $tmpcc
308 for CC in $(cat $tmpcc); do
309 cat << EOT
310 $CC
311 $CC
312 $(grep -m1 "$CC " ${zi}iso3166.tab | cut -d$'\t' -f2 | sed 's|\&|&amp;|g')
313 EOT
314 done | \
315 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
316 --width='500' --height='380' --on-top --center \
317 --image="$icon" --image-on-top \
318 --text="<b>$(_ 'TimeZone Configuration')</b> \
319 \n$(_ 'Select country and press "Forward" or manually select timezone file.') \
320 \n\n$(_ 'Tip: manage timezones list by installing/removing locale packages.')" \
321 --list \
322 --column="$(_n 'Flag'):IMG" --column=$(_n 'Code') --column=$(_n 'Country') \
323 --button="$(_n 'Manage')!document-properties:4" \
324 --button="$(_n 'Manual')!gtk-index:2" \
325 --button="gtk-go-forward:0" \
326 --button="gtk-cancel:1" --always-print-result \
327 --print-column='2' --separator=''
328 ;;
329 xindex)
330 # manual selection of file with timezone info
331 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
332 --width='500' --on-top --center \
333 --image="$icon" --image-on-top \
334 --text="<b>$(_ 'TimeZone Configuration')</b>\n$(_ 'Select time zone')" \
335 --form --field=":FL" ${zi}UTC --separator='' | \
336 sed "s|$zi||"
337 ;;
338 *)
339 # second pass - city/place
340 list=$(tz_list $1)
341 icon="$1"
342 if [ $(echo "$list" | wc -l) != 1 ]; then
343 echo "$list" | \
344 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
345 --width='500' --height='380' --on-top --center \
346 --image="$icon" --image-on-top \
347 --text="<b>$(_ 'TimeZone Configuration')</b>\n$(_ 'Select location')" \
348 --list --column $(_n 'Location/City') --separator=''
349 else
350 echo $list
351 fi
352 ;;
353 esac
354 }
357 tz() {
358 icon='preferences-system-time'
359 arg=$(tz_suggest)
361 timezone=$(tz_select $arg)
362 case $? in
363 1) exit 0 ;;
364 0)
365 [ -n "$timezone" ] && timezone=$(tz_select "$timezone")
366 [ -z "$timezone" ] && exit 0
367 timezone=$(find $zi -name $timezone | grep -v -E "posix|right" | \
368 sed "s|$zi||")
369 ;;
370 2) timezone=$(tz_select "index") ;;
371 4) tazbox manage_i18n main;;
372 esac
374 [ -z "$timezone" ] && exit 0
375 echo $timezone > /etc/TZ
376 export TZ=$timezone
377 tazbox notify "$(_ 'TimeZone was set to %s' "$timezone")" $icon 3
378 rm -f $tmpcc
379 }
382 #
383 # Manage i18n packages
384 #
387 # if installed
389 if_installed() {
390 [ -d "$INSTALLED/$1" ]
391 }
394 # get package's description, install flag and sizes
396 desc_etc() {
397 if grep -q "^$1"$'\t' "$PKGS_DB/installed.info"; then
398 echo 'TRUE' >> $PKGS_LIST; echo $1 >> $ORIG_LIST
399 else
400 echo 'FALSE' >> $PKGS_LIST
401 fi
402 awk -F$'\t' -vp="$1" '
403 ($1==p){
404 split($7, s, " ");
405 printf "%s\n%s\n%s\n%s\n", $1, $4, s[1], s[2];
406 }' "$PKGS_DB/packages.info" >> $PKGS_LIST
407 }
410 # remove temp
412 rm_temp() {
413 rm -f $PKGS_LIST $ORIG_LIST $ANSWER $NEW_LIST $LIST1 $LIST2
414 }
417 # install/remove locale packages
419 manage_i18n() {
420 PKGS_LIST=$(mktemp)
421 ORIG_LIST=$(mktemp)
422 ANSWER=$(mktemp)
423 NEW_LIST=$(mktemp)
424 LIST1=$(mktemp)
425 LIST2=$(mktemp)
426 PINFO="$PKGS_DB/packages.info"
428 if [ ! -e "$PINFO" ]; then
429 icon='dialog-warning'
430 yad --title="$(_n 'Manage locale packages')" --window-icon="$icon" \
431 --width='400' --on-top --center \
432 --image="$icon" --image-on-top \
433 --text="$(_n 'Please, recharge packages database.')" \
434 --button="$(_n 'Recharge list')!view-refresh:2" \
435 --button="gtk-cancel:1"
437 case "$?" in
438 1) rm_temp; return;;
439 2) tazbox recharge;;
440 esac
441 fi
443 tazbox notify "$(_ 'Please wait')" appointment-soon &
445 for i in $(awk -F$'\t' '$1~/^locale-[a-z_A-Z]+$/{print $1}' $PINFO); do
446 desc_etc $i
447 done
449 if [ "$1" != 'main' ]; then
450 for i in $(awk -F$'\t' '$1~/^locale-[a-z_A-Z]+-extra$/{print $1}' $PINFO); do
451 desc_etc $i
452 done
454 if if_installed libQtCore; then
455 for i in $(awk -F$'\t' '$1~/^qt-locale/{print $1}' $PINFO); do
456 desc_etc $i
457 done
458 fi
460 if if_installed razorqt; then
461 for i in $(awk -F$'\t' '$1~/^razorqt-locale/{print $1}' $PINFO); do
462 desc_etc $i
463 done
464 fi
466 if if_installed firefox; then
467 for i in $(awk -F$'\t' '$1~/^firefox-langpack/{print $1}' $PINFO); do
468 desc_etc $i
469 done
470 fi
472 if if_installed thunderbird; then
473 for i in $(awk -F$'\t' '$1~/^thunderbird-langpack/{print $1}' $PINFO); do
474 desc_etc $i
475 done
476 fi
478 if if_installed squirrelmail; then
479 for i in $(awk -F$'\t' '$1~/^squirrelmail-[a-z][a-z][_-]/{print $1}' $PINFO); do
480 desc_etc $i
481 done
482 fi
484 if if_installed aspell; then
485 for i in $(awk -F$'\t' '$1~/^aspell-[a-z][a-z]_?[A-Z]?[A-Z]?$/{print $1}' $PINFO); do
486 desc_etc $i
487 done
488 fi
490 OTHER_LOCALE="gnome-commander|-i18n gnome-vfs|-i18n gpa|-langpack \
491 gucharmap|-i18n lxterminal|-locales lyx|-locales rox-filer|-locales \
492 ufraw|-locales qupzilla|-locales"
493 for i in $OTHER_LOCALE; do
494 if if_installed ${i%%|*}; then desc_etc ${i/|/}; fi
495 done
496 fi
498 icon='preferences-desktop-locale'
499 cat $PKGS_LIST | \
500 {
501 yad --title="$(_n 'Manage locale packages')" --window-icon="$icon" \
502 --width='600' --height='400' --on-top --center \
503 --image="$icon" --image-on-top \
504 --text="$(_n 'Check only locale packages you need and press "Install/Remove".')" \
505 --list --multiple --ellipsize='END' --expand-column='3' \
506 --column="$(_n 'Inst.'):CHK" --column="$(_n 'Package Name'):TEXT" \
507 --column="$(_n 'Description'):TEXT" --column="$(_n 'Size'):TEXT" \
508 --column="$(_n 'Installed'):TEXT" \
509 --button="$(_n 'Recharge list')!view-refresh:4" \
510 --button="$(_n 'Install/Remove')!gtk-execute:2" \
511 --button="gtk-cancel:1" \
512 --print-all
513 } > $ANSWER
515 case "$?" in
516 1) rm_temp; exit 0;;
517 4) tazbox recharge; rm_temp; tazbox manage_i18n; exit 0;;
518 esac
520 grep -e 'TRUE' $ANSWER | cut -d'|' -f2 > $NEW_LIST
522 # check difference between ORIG_LIST and NEW_LIST
523 sort -o $LIST1 $ORIG_LIST
524 sort -o $LIST2 $NEW_LIST
525 DIFF=$(diff $LIST1 $LIST2 | sed '/---/d;/+++/d;/@@/d')
526 if [ -z "$DIFF" ]; then rm_temp; exit 0; fi
528 # output log to gtk window
529 title="$(_n 'TazPkg log')"; icon='system-software-update'; opts='--tail'
530 {
531 for pkg in $(echo "$DIFF" | grep -e '^-' | sed 's|^-||g'); do
532 _ 'REMOVE: %s' "$pkg"
533 yes | tazpkg -r $pkg --output='raw'
534 done
535 for pkg in $(echo "$DIFF" | grep -e '^+' | sed 's|^+||g'); do
536 _ 'INSTALL: %s' "$pkg"
537 tazpkg -gi $pkg --output='raw'
538 done
539 echo -e "\n\n$(_n 'Done!')\n"
540 } | output_command
541 rm_temp
542 }
546 # New file functions
548 newfile_main() {
549 icon='document-new'
550 yad --title="$(_n 'New file')" --window-icon="$icon" \
551 --width='460' --height='160' --on-top --center \
552 --image="$icon" --image-on-top \
553 --icon="$icon" \
554 --text="<b>$(_n 'Create a new file or folder on your desktop')</b>" \
555 --entry --entry-label="$(_n 'File name')" \
556 --ricon='edit-clear' \
557 --always-print-result \
558 --button="$(_n 'SHell script')!application-x-shellscript:4" \
559 --button="$(_n 'Folder')!folder:3" \
560 --button="$(_n 'File')!empty:2" \
561 --button='gtk-cancel:1'
562 }
565 newfile() {
566 file=$(newfile_main)
567 ret=$?
568 [ -z "$file" ] && exit 0
569 case $ret in
570 4)
571 cat > "$HOME/Desktop/$file" << EOT
572 #!/bin/sh
573 #
575 EOT
576 chmod +x "$HOME/Desktop/$file" ;;
577 3) mkdir -p "$HOME/Desktop/$file" ;;
578 2) touch "$HOME/Desktop/$file" ;;
579 1) exit 0 ;;
580 esac
581 }
584 # All applications
586 all_apps() {
587 icon='user-bookmarks'
588 yad --title="$(_n 'All Applications')" --window-icon="$icon" \
589 --width='400' --height='400' \
590 --icons --compact \
591 --read-dir='/usr/share/applications' \
592 --button='gtk-close:0'
593 }
596 # Ask root permissions for system settings
598 ask_root() {
599 if [ "$(id -u)" -ne 0 ]; then
600 exec tazbox su $0 $@
601 exit 0
602 fi
603 }
606 vnc_main() {
607 icon='video-display'
608 yad --title="$(_n 'Framebuffer VNC viewer')" --window-icon="$icon" \
609 --width='250' --height='160' --on-top --center \
610 --image="$icon" --image-on-top --icon="$icon" \
611 --form \
612 --text="<b>$(_n 'Remote display connection')</b>" "localhost 5900" \
613 --field="$(_n 'VNC Server')" \
614 --field="$(_n 'Via a SSH tunnel'):CHK" \
615 --always-print-result \
616 --button="$(_n 'On this console'):1" \
617 --button="$(_n 'In a new console'):0"
618 }
621 video() {
622 icon='video-x-generic'
624 # Get switchs
625 tazwebargs="--notoolbar"
626 while true ; do
627 case "$1" in
628 --fullscreen) tazwebargs="$tazwebargs --kiosk"
629 dpmstimeout=$(xset q | grep timeout | cut -d' ' -f5) ;;
630 --loop) loop="loop" ;;
631 *) break
632 esac
633 shift
634 done
636 # Get filename
637 [ "$1" ] && file="$PWD/$(basename "$1")"
638 [ "${1:0:1}" == "/" ] && file="$1"
639 [ -s "$file" ] || file="$(yad --file --width='600' --height='500' --add-preview \
640 --window-icon $icon --title "$(_ 'Select the video file')" --center \
641 --file-filter="$(_ 'All video files')|*.mp4 *.m4v *.webm *.ogg *.ogv *.flv *.avi *.3gp" \
642 --file-filter="$(_ 'All files')|*")"
643 [ -s "$file" ] || return
645 # Extra parameters
646 text=
647 attr='autoplay="true"'
648 for i in jpg jpeg ; do
649 [ -s "${file%.*}.$i" ] &&
650 attr="poster=\"file://${file%.*}.$i\"" && break
651 done
652 IFS=$'\n'
653 for i in ${file%.*}_${LANG%%[._]*}.vtt ${file%.*}.vtt ; do
654 [ -s $i ] && text="
655 <track kind=\"captions\" src=\"file://$i\" srclang=\"${LANG%%[._]*}\" default>"
656 done
658 # Build the html5 page
659 tmp=/tmp/video-player-$$.html
660 cat > $tmp <<EOT
661 <html>
662 <head>
663 <meta charset="UTF-8">
664 <title>$(basename "$file")</title>
665 <style>
666 body{background:#000;color:#FFF;margin:0}
667 a{color:#29F}
668 div{position:absolute;bottom:2em;left:0;right:0;text-align:center}
669 </style>
670 </head>
671 <body>
672 <video width="100%" height="100%" src="file://$file" controls $attr$loop>$text
673 <div>$(_ 'Unsupported video file format.')<br>
674 $(IFS=$'\n'; _ 'Retry with %s, %s, %s, %s, %s or %s.' \
675 $(printf '<a href="http://127.0.0.1:82/user/pkgs.cgi?info=%s">%s</a>\n' \
676 vlc VLC gnome-mplayer 'GNOME MPlayer' mplayer MPlayer gxine gxine xine-ui xine ffplay ffplay))
677 </div>
678 </video>
679 </body>
680 </html>
681 EOT
682 unset IFS
683 [ -n "$dpmstimeout" ] && xset dpms 0 0 0 s 0 0
684 tazweb $tazwebargs file://$tmp || browser file://$tmp
685 [ -n "$dpmstimeout" ] && xset dpms $dpmstimeout $dpmstimeout $dpmstimeout s $dpmstimeout $dpmstimeout
686 rm -f $tmp
687 }
690 newvt()
691 {
692 ask_root newvt $@ || return
693 openvt -sw $@
694 deallocvt
695 }
698 vnc() {
699 server=$(vnc_main)
700 status=$?
701 # Deal with --button values
702 [ "$server" ] || return
703 case "$server" in
704 *TRUE\|) fbvnc=sshfbvnc ;;
705 *) fbvnc=fbvnc ;;
706 esac
707 case "$status" in
708 1) $fbvnc ${server%%|*} ;;
709 0) newvt $fbvnc ${server%%|*} ;;
710 esac
711 }
714 #
715 # Commands
716 #
718 case "$1" in
719 su)
720 shift
721 # Don't show dialog if we are root
722 [ "$(id -u)" -eq 0 ] && exec "$@"
723 SU_CMD="$@"
724 SUBOX_CONF="$HOME/.config/slitaz/subox.conf"
726 # Check if a password has been saved before launching main dialog
727 if [ -s "$SUBOX_CONF" ]; then
728 PASSWD="$(cat $SUBOX_CONF)"
729 CHECKED='TRUE'
730 fi
732 # Display the main dialog (ask for password)
733 main="$(su_main "$SU_CMD")"
735 # Deal with --button values and exit if cancelled to avoid erasing
736 # saved password.
737 [ "$?" -eq 1 ] && exit 0
739 # Save or erase Autosaved password
740 if [ $(echo "$main" | cut -d"|" -f2) == 'TRUE' ]; then
741 echo "$main" | cut -d"|" -f1 > $SUBOX_CONF
742 chmod 0600 $SUBOX_CONF
743 else
744 cat /dev/null > $SUBOX_CONF
745 fi
747 # Try to login & execute. If password is wrong execute error dialog
748 SU_CMD_QUOTED="$(echo "$SU_CMD" | sed 's|&|\\&|g')"
749 echo $main | cut -d"|" -f1 | su -c "$SU_CMD_QUOTED &" || su_error
750 ;;
752 logout)
753 # Logout window with actions
754 if [ -n "$oldstyle" ]; then
755 answer=$(logout_oldstyle)
756 else
757 logout_main; answer=$?
758 fi
760 # Deal with --button values
761 # DE and WM started with a custom -session script should export
762 # XDG_CURRENT_DESKTOP
763 case $answer in
764 4|*exit)
765 case $XDG_CURRENT_DESKTOP in
766 LXDE)
767 [ -n "$_LXSESSION_PID" ] && kill $_LXSESSION_PID
768 [ "$DESKTOP_SESSION" == 'compiz' ] && killall compiz
769 openbox --exit ;;
770 openbox) openbox --exit ;;
771 compiz) killall compiz ;;
772 *)
773 # Try to kill other WM that dont set XDG var.
774 jwm -exit 2>/dev/null ;;
775 esac ;;
776 3|*reboot)
777 reboot || reboot -f ;;
778 2|*halt)
779 poweroff ;;
780 esac
781 ;;
783 out)
784 # Pipe a command into a GTK window
785 sed 's|\[.m||g; s|\[[0-9][0-9]*G| |g' | output_command
786 ;;
788 out-dl)
789 # A tiny GTK window for Busybox wget output
790 url="$2"; opts='--tail --button=gtk-cancel:1'
791 icon='folder-download'; title="$(_ 'Downloading...')"
792 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
793 busybox wget -c -P $DOWNLOADS $url 2>&1 | output_command
794 cancel_dl
795 ;;
797 locale)
798 ask_root $@ && locale
799 ;;
801 keymap)
802 ask_root $@ && keymap
803 ;;
805 tz)
806 ask_root $@ && tz
807 ;;
809 manage_i18n)
810 ask_root $@ && manage_i18n $2
811 ;;
813 recharge)
814 ask_root $@; opts='--on-top'; output=raw tazpkg recharge | output_command
815 ;;
817 setup)
818 ask_root $@ && setup
819 ;;
821 new-file)
822 newfile
823 ;;
825 all-apps)
826 all_apps
827 ;;
829 notify|-n)
830 # On screen notification box.
831 icon="$3"
832 time="$4"
833 [ -z "$icon" ] && icon='dialog-information'
834 [ -z "$time" ] && time='4'
835 yad --width='520' --height='80' --timeout="$time" --timeout-indicator='right' \
836 --on-top --center --no-buttons --borders='12' --undecorated \
837 --skip-taskbar --image="$icon" --image-on-top --text="<b>$2</b>"
838 ;;
840 tazapps)
841 # Default applications configuration script. System wide config file
842 # is /etc/slitaz/applications.conf and each user can have personal
843 # settings. System wide for root and personal config for user.
844 export CONFIG="$HOME/.config/slitaz/applications.conf"
845 if [ "$(id -u)" -eq 0 ]; then
846 [ ! -f $CONFIG ] || mv -f $CONFIG /etc/slitaz/applications.conf
847 export CONFIG='/etc/slitaz/applications.conf'
848 fi
850 for a in FILE_MANAGERS BROWSERS EDITORS TERMINALS WINDOW_MANAGERS; do
851 eval $(expr $a=$(echo $(LC_ALL=C tazx get-applist ${a%%S} \
852 only-installed yad) | sed 's/ /!/g ; s/!!//g; s/ //g'))
853 done
855 # Missing file was created by slitaz_apps_conf function from tazx
856 . $CONFIG
858 icon='preferences-desktop-default-applications'
859 eval $(yad --title="$(_n 'SliTaz default applications')" \
860 --window-icon="$icon" --image="$icon" --image-on-top \
861 --text="<b>$(_n 'SliTaz default applications configuration')</b>" \
862 --form \
863 --field="$(_n 'File manager:'):CBE" "$FILE_MANAGERS" \
864 --field="$(_n 'Web browser:'):CBE" "$BROWSERS" \
865 --field="$(_n 'Text editor:'):CBE" "$EDITORS" \
866 --field="$(_n 'Terminal:'):CBE" "$TERMINALS" \
867 --field="$(_n 'Window manager:'):CBE" "$WINDOW_MANAGERS" | \
868 awk -F'|' '{printf "FILE_MANAGER=\"%s\"\nBROWSER=\"%s\"\nEDITOR=\"%s\"\
869 TERMINAL=\"%s\"\nWINDOW_MANAGER=\"%s\"\n", $1, $2, $3, $4, $5}')
871 sed '/FILE_MANAGER=/s|"\([^"]*\)"|"'$FILE_MANAGER'"|; \
872 /BROWSER=/s|"\([^"]*\)"|"'$BROWSER'"|; \
873 /EDITOR=/s|"\([^"]*\)"|"'$EDITOR'"|; \
874 /TERMINAL=/s|"\([^"]*\)"|"'$TERMINAL'"|; \
875 /WINDOW_MANAGER=/s|"\([^"]*\)"|"'$WINDOW_MANAGER'"|' \
876 -i $CONFIG
877 ;;
879 gpl)
880 yad --title='GNU General Public License' --window-icon='text-x-copying' \
881 --geometry='650x500' \
882 --image='/usr/share/pixmaps/gpl3.png' --image-on-top \
883 --center \
884 --text-info \
885 --fontname='monospace' \
886 --button 'OK' < /usr/share/licenses/gpl.txt
887 ;;
889 vnc)
890 vnc
891 ;;
893 video)
894 shift
895 video "$@"
896 ;;
898 newvt)
899 $@
900 ;;
902 *)
903 usage
904 ;;
905 esac
907 exit 0