slitaz-tools view tazbox/tazbox @ rev 989

tazbox video: disable screensaver
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 28 14:02:15 2016 +0200 (2016-05-28)
parents 587e4c95f901
children 16d7770b4afc
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 dpmsoff=yes ;;
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='500' --height='400' \
640 --window-icon $icon --title "$(_ "Select the video file")" --center)"
641 [ -s "$file" ] || return
643 # Extra parameters
644 text=
645 attr='autoplay="true"'
646 for i in jpg jpeg ; do
647 [ -s ${file%.*}.$i ] &&
648 attr="poster=\"file://${file%.*}.$i\"" && break
649 done
650 for i in ${file%.*}_${LANG%%[._]*}.vtt ${file%.*}.vtt ; do
651 [ -s $i ] && text="
652 <track kind=\"captions\" src=\"file://$i\" srclang=\"${LANG%%[._]*}\" default>"
653 done
655 # Build the html5 page
656 tmp=/tmp/video-player-$$.html
657 cat > $tmp <<EOT
658 <html>
659 <head>
660 <title>$(basename "$file")</title>
661 <style text/css>
662 html {
663 backgound-color: black;
664 }
666 body {
667 margin: 0 0 0 0;
668 }
669 </style>
670 </head>
671 <body>
672 <video width="100%" height="100%" src="file://$file" controls $attr$loop>$text
673 Unsupported video file format.
674 Retry with <a href="http://127.0.0.1:82/user/pkgs.cgi?info=vlc">vlc</a>,
675 <a href="http://127.0.0.1:82/user/pkgs.cgi?info=gnome-mplayer">mplayer</a>,
676 <a href="http://127.0.0.1:82/user/pkgs.cgi?info=mplayer">mplayer</a>,
677 <a href="http://127.0.0.1:82/user/pkgs.cgi?info=gxine">gxine</a>,
678 <a href="http://127.0.0.1:82/user/pkgs.cgi?info=xine-ui">xine</a> or
679 <a href="http://127.0.0.1:82/user/pkgs.cgi?info=ffplay">ffplay</a>
680 </video>
681 </body>
682 </html>
683 EOT
685 [ -n "dmpsoff" ] && xset -dpms
686 tazweb $tazwebargs file://$tmp || browser file://$tmp
687 [ -n "dmpsoff" ] && xset +dpms
688 rm -f $tmp
689 }
692 newvt()
693 {
694 ask_root newvt $@ || return
695 openvt -sw $@
696 deallocvt
697 }
700 vnc() {
701 server=$(vnc_main)
702 status=$?
703 # Deal with --button values
704 [ "$server" ] || return
705 case "$server" in
706 *TRUE\|) fbvnc=sshfbvnc ;;
707 *) fbvnc=fbvnc ;;
708 esac
709 case "$status" in
710 1) $fbvnc ${server%%|*} ;;
711 0) newvt $fbvnc ${server%%|*} ;;
712 esac
713 }
716 #
717 # Commands
718 #
720 case "$1" in
721 su)
722 shift
723 # Don't show dialog if we are root
724 [ "$(id -u)" -eq 0 ] && exec "$@"
725 SU_CMD="$@"
726 SUBOX_CONF="$HOME/.config/slitaz/subox.conf"
728 # Check if a password has been saved before launching main dialog
729 if [ -s "$SUBOX_CONF" ]; then
730 PASSWD="$(cat $SUBOX_CONF)"
731 CHECKED='TRUE'
732 fi
734 # Display the main dialog (ask for password)
735 main="$(su_main "$SU_CMD")"
737 # Deal with --button values and exit if cancelled to avoid erasing
738 # saved password.
739 [ "$?" -eq 1 ] && exit 0
741 # Save or erase Autosaved password
742 if [ $(echo "$main" | cut -d"|" -f2) == 'TRUE' ]; then
743 echo "$main" | cut -d"|" -f1 > $SUBOX_CONF
744 chmod 0600 $SUBOX_CONF
745 else
746 cat /dev/null > $SUBOX_CONF
747 fi
749 # Try to login & execute. If password is wrong execute error dialog
750 SU_CMD_QUOTED="$(echo "$SU_CMD" | sed 's|&|\\&|g')"
751 echo $main | cut -d"|" -f1 | su -c "$SU_CMD_QUOTED &" || su_error
752 ;;
754 logout)
755 # Logout window with actions
756 if [ -n "$oldstyle" ]; then
757 answer=$(logout_oldstyle)
758 else
759 logout_main; answer=$?
760 fi
762 # Deal with --button values
763 # DE and WM started with a custom -session script should export
764 # XDG_CURRENT_DESKTOP
765 case $answer in
766 4|*exit)
767 case $XDG_CURRENT_DESKTOP in
768 LXDE)
769 [ -n "$_LXSESSION_PID" ] && kill $_LXSESSION_PID
770 [ "$DESKTOP_SESSION" == 'compiz' ] && killall compiz
771 openbox --exit ;;
772 openbox) openbox --exit ;;
773 compiz) killall compiz ;;
774 *)
775 # Try to kill other WM that dont set XDG var.
776 jwm -exit 2>/dev/null ;;
777 esac ;;
778 3|*reboot)
779 reboot || reboot -f ;;
780 2|*halt)
781 poweroff ;;
782 esac
783 ;;
785 out)
786 # Pipe a command into a GTK window
787 sed 's|\[.m||g; s|\[[0-9][0-9]*G| |g' | output_command
788 ;;
790 out-dl)
791 # A tiny GTK window for Busybox wget output
792 url="$2"; opts='--tail --button=gtk-cancel:1'
793 icon='folder-download'; title="$(_ 'Downloading...')"
794 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
795 busybox wget -c -P $DOWNLOADS $url 2>&1 | output_command
796 cancel_dl
797 ;;
799 locale)
800 ask_root $@ && locale
801 ;;
803 keymap)
804 ask_root $@ && keymap
805 ;;
807 tz)
808 ask_root $@ && tz
809 ;;
811 manage_i18n)
812 ask_root $@ && manage_i18n $2
813 ;;
815 recharge)
816 ask_root $@; opts='--on-top'; output=raw tazpkg recharge | output_command
817 ;;
819 setup)
820 ask_root $@ && setup
821 ;;
823 new-file)
824 newfile
825 ;;
827 all-apps)
828 all_apps
829 ;;
831 notify|-n)
832 # On screen notification box.
833 icon="$3"
834 time="$4"
835 [ -z "$icon" ] && icon='dialog-information'
836 [ -z "$time" ] && time='4'
837 yad --width='520' --height='80' --timeout="$time" --timeout-indicator='right' \
838 --on-top --center --no-buttons --borders='12' --undecorated \
839 --skip-taskbar --image="$icon" --image-on-top --text="<b>$2</b>"
840 ;;
842 tazapps)
843 # Default applications configuration script. System wide config file
844 # is /etc/slitaz/applications.conf and each user can have personal
845 # settings. System wide for root and personal config for user.
846 export CONFIG="$HOME/.config/slitaz/applications.conf"
847 if [ "$(id -u)" -eq 0 ]; then
848 [ ! -f $CONFIG ] || mv -f $CONFIG /etc/slitaz/applications.conf
849 export CONFIG='/etc/slitaz/applications.conf'
850 fi
852 for a in FILE_MANAGERS BROWSERS EDITORS TERMINALS WINDOW_MANAGERS; do
853 eval $(expr $a=$(echo $(LC_ALL=C tazx get-applist ${a%%S} \
854 only-installed yad) | sed 's/ /!/g ; s/!!//g; s/ //g'))
855 done
857 # Missing file was created by slitaz_apps_conf function from tazx
858 . $CONFIG
860 icon='preferences-desktop-default-applications'
861 eval $(yad --title="$(_n 'SliTaz default applications')" \
862 --window-icon="$icon" --image="$icon" --image-on-top \
863 --text="<b>$(_n 'SliTaz default applications configuration')</b>" \
864 --form \
865 --field="$(_n 'File manager:'):CBE" "$FILE_MANAGERS" \
866 --field="$(_n 'Web browser:'):CBE" "$BROWSERS" \
867 --field="$(_n 'Text editor:'):CBE" "$EDITORS" \
868 --field="$(_n 'Terminal:'):CBE" "$TERMINALS" \
869 --field="$(_n 'Window manager:'):CBE" "$WINDOW_MANAGERS" | \
870 awk -F'|' '{printf "FILE_MANAGER=\"%s\"\nBROWSER=\"%s\"\nEDITOR=\"%s\"\
871 TERMINAL=\"%s\"\nWINDOW_MANAGER=\"%s\"\n", $1, $2, $3, $4, $5}')
873 sed '/FILE_MANAGER=/s|"\([^"]*\)"|"'$FILE_MANAGER'"|; \
874 /BROWSER=/s|"\([^"]*\)"|"'$BROWSER'"|; \
875 /EDITOR=/s|"\([^"]*\)"|"'$EDITOR'"|; \
876 /TERMINAL=/s|"\([^"]*\)"|"'$TERMINAL'"|; \
877 /WINDOW_MANAGER=/s|"\([^"]*\)"|"'$WINDOW_MANAGER'"|' \
878 -i $CONFIG
879 ;;
881 gpl)
882 yad --title='GNU General Public License' --window-icon='text-x-copying' \
883 --geometry='650x500' \
884 --image='/usr/share/pixmaps/gpl3.png' --image-on-top \
885 --center \
886 --text-info \
887 --fontname='monospace' \
888 --button 'OK' < /usr/share/licenses/gpl.txt
889 ;;
891 vnc)
892 vnc
893 ;;
895 video)
896 shift
897 video "$@"
898 ;;
900 newvt)
901 $@
902 ;;
904 *)
905 usage
906 ;;
907 esac
909 exit 0