slitaz-tools view tazbox/tazbox @ rev 1010

tazbox: hide locale missing error message
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jan 25 09:33:18 2017 +0100 (2017-01-25)
parents d65882212dbd
children 86fbc888a1f6
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 # logout functions with auto-confirmation
145 logout_confirm() {
146 timeout=5
147 case $1 in
148 exit) action="$(_n 'Closing the X session...')"; icon='system-log-out';;
149 reboot) action="$(_n 'Rebooting the system...')"; icon='system-reboot';;
150 halt) action="$(_n 'Shutting down the system...')"; icon='system-shutdown';;
151 *) exit;;
152 esac
153 warning="$(_ 'Selected action will be executed automatically in %s seconds.' "$timeout")"
154 yad --title="$(_n 'SliTaz Logout')" --window-icon="$icon" \
155 --on-top --center --width='300' --image="$icon" --image-on-top \
156 --text="<b>$action</b>\n\n$warning" \
157 --timeout $timeout --timeout-indicator=bottom \
158 --button "gtk-cancel:252"
159 [ "$?" -ne 252 ] || exit 0
160 }
163 # make logout menu in the right edge of LXPanel
165 mkmenu() {
166 # (re)make the menu button with the user log name
167 dd="$HOME/.local/share/desktop-directories"; mkdir -p "$dd"
168 echo -e "[Desktop Entry]\nType=Directory\nName=$(whoami)" > "$dd/user.directory"
170 # check the panel config file existence, copy from default config if needed
171 panels=$(find $HOME/.config/lxpanel -type f -name panel 2>/dev/null)
172 if [ -z "$panels" ]; then
173 mkdir -p "$HOME/.config/lxpanel"
174 cp -a /etc/skel/.config/lxpanel/* "$HOME/.config/lxpanel"
175 fi
177 for panel in $panels; do
178 conf=$(tr '\n' '`' < $panel | sed 's|Plugin|\n&|g') # each plugin on its own line
179 if fgrep -q 'user.directory' "$panel"; then
180 # if menu already exists - shrink it to '@@@'
181 newconf=$(echo "$conf" | sed 's|.*user\.directory.*$|@@@|')
182 else
183 # otherwise add '@@@' before the last line (last line is the space)
184 newconf=$(echo "$conf" | tac | sed '2i@@@' | tac)
185 fi
186 menu=$(cat <<EOT
187 Plugin {
188 type = menu
189 Config {
190 name=user.directory
191 image=avatar-default
192 tintcolor=#33230D
193 item {
194 image=system-log-out-panel
195 name=$(_ 'Close X session')
196 action=tazbox logout exit
197 }
198 item {
199 image=system-reboot-panel
200 name=$(_ 'Reboot system')
201 action=tazbox logout reboot
202 }
203 item {
204 image=system-shutdown-panel
205 name=$(_ 'Shutdown system')
206 action=tazbox logout halt
207 }
208 }
209 }
211 EOT
212 )
213 # rebuild the menu: change '@@@' to the menu content
214 echo "$newconf" | \
215 awk -vmenu="$menu" '{if ($1=="@@@") {printf ("%s\n\n", menu)} else {print}}' | \
216 tr '`' '\n' > $panel
217 done
218 }
221 # generate keymap list
223 gen_kmap_list() {
224 echo > $tmp
225 cd /usr/share/kbd/keymaps/i386
226 # we first need a list to sort and then use \n for Yad list.
227 for i in $(find -type f | sed '/include/d; s|./||'); do
228 echo "$(basename $i .map.gz)|$(dirname $i)" >> $tmp
229 done
230 }
233 # Initial Config functions
235 setup_main() {
236 icon='preferences-desktop-locale'
237 gen_kmap_list
238 locale=$(ls -1 $db 2> /dev/null | grep ^[a-z][a-z]_[A-Z][A-Z] | tr "\n" "!")
239 keymap=$(cat $tmp | sort | tr "\n" "!")
240 timezone=$(find $zi -type f | sed s,$zi,,g | grep -v -F '.tab' | tr "\n" "!")
241 yad --title="$(_n 'SliTaz Initial Setup')" --window-icon=$icon \
242 --width='500' \
243 --image="$icon" --image-on-top \
244 --text="<big>$(_n 'Here you can set your preferences \n for <b>locale, keymap and timezone</b>.')</big>" \
245 --form \
246 --field "$(_n 'Locale'):CB" $locale \
247 --field "$(_n 'Keymap'):CB" $keymap \
248 --field "$(_n 'Timezone'):CB" $timezone
249 }
252 setup() {
253 choices=$(setup_main)
254 locale=$( echo $choices | cut -d'|' -f1)
255 keymap=$( echo $choices | cut -d'|' -f2)
256 timezone=$(echo $choices | cut -d'|' -f3)
257 [ -n "$locale" ] && tazlocale init $locale
258 [ -n "$keymap" ] && tazkeymap init $keymap
259 [ -n "$timezone" ] && echo $timezone > /etc/TZ
260 }
263 #
264 # Locale functions
265 #
267 locale_main() {
268 icon='preferences-desktop-locale'
269 for locale in $(ls -1 $db 2> /dev/null | grep '[a-z]_[A-Z]'); do
270 desc=$(fgrep -m1 title $db/$locale | cut -d'"' -f2)
271 ll_CC=${locale%%@*}
272 echo -e "${ll_CC##*_}\n$locale\n$desc"
273 done | \
274 yad --title="$(_n 'SliTaz locale')" --window-icon="$icon" \
275 --width='600' --height='380' --sticky --on-top --center \
276 --image="$icon" --image-on-top \
277 --text="<b>$(_n 'Language configuration')</b> \
278 \n\n$(_ 'Tip: manage locales list by installing/removing locale packages.')" \
279 --list --column="$(_n 'Flag'):IMG" --column $(_n 'Name') \
280 --column $(_n 'Description') \
281 --print-column='2' --separator='' \
282 --button="$(_n 'Manage')!document-properties:2" \
283 --button="gtk-cancel:1" --button="gtk-ok:0"
284 }
287 locale() {
288 locale=$(locale_main)
289 # Deal with --button values
290 case $? in
291 2) tazbox manage_i18n main ;;
292 1) exit 0 ;;
293 *) continue ;;
294 esac
295 # System language configuration.
296 if [ "$locale" ]; then
297 tazlocale $locale
298 tazbox notify "$(_ 'Locale was set to %s' "$locale")" \
299 preferences-desktop-locale 3
300 fi
301 }
304 # Keymap functions
306 keymap_main() {
307 icon='preferences-desktop-keyboard'
308 gen_kmap_list
309 for i in $(sort $tmp); do
310 echo "$i" | tr '|' '\n'
311 done | \
312 yad --title="$(_ 'SliTaz keymap')" --window-icon=$icon \
313 --width=500 --height=380 --sticky --on-top --center \
314 --image=$icon --image-on-top \
315 --text="<b>$(_n 'Keyboard configuration')</b>" \
316 --list --column $(_n 'Keymap') --column $(_n 'Type') \
317 --print-column=1 --separator=''
318 rm -f $tmp
319 }
322 keymap() {
323 keymap=$(keymap_main)
324 # Deal with --button values
325 [ "$?" -eq 1 ] && exit 0
326 # System keymap configuration
327 [ -n "$keymap" ] && tazkeymap $keymap
328 }
331 # Free GeoIP service
332 # Response: IP,CountryCode,CountryName, ...
334 geoip() {
335 # freegeoip.net can be in the blocked hosts list. Return only correct answer or nothing
336 [ ! -e $csv ] && wget -q -T3 -O - http://freegeoip.net/csv/ 2&>/dev/null | \
337 grep '[0-9.]*,.*,.*,.*,.*,.*,.*,.*,[0-9.]*,[0-9.]*' > $csv
338 [ -e $csv ] && cut -d, -f2 $csv
339 }
342 #
343 # TZ functions
344 #
347 # list of all existing available locations for country
349 tz_list() {
350 find $zi | \
351 grep -E "$(awk -F$'\t' -vv="$1" '{if ($1 == v || $2 ~ v) print $2}' $ztab | tr ' ' '|')" | \
352 grep -v -E "posix|right" | \
353 sed 's|.*/||g' | sort
354 }
357 # ask for confirmation only if we have what to choose
359 tz_suggest() {
360 CountryCode=$(geoip)
361 if [ -n "$CountryCode" ]; then
362 if [ -n "$(tz_list $CountryCode)" ]; then
363 CountryName=$(cut -d, -f3 $csv)
364 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
365 --on-top --center \
366 --image="$CountryCode" --image-on-top \
367 --text="$(_ 'Suggested location:') <b>$CountryName</b>\n
368 $(_ 'Are you agreed?')" \
369 --button='gtk-yes:0' --button='gtk-no:1'
370 [ "$?" -eq 0 ] && echo $CountryCode
371 fi
372 fi
373 }
376 tz_select() {
377 case x$1 in
378 x)
379 # first pass - country
380 tmpcc=$(mktemp)
382 for tzfile in $(find $zi -type f -regex '.*info/[ABCEIMP].*'); do
383 grep -m1 $(basename $tzfile) $ztab
384 done | cut -d$'\t' -f1 | sort -u > $tmpcc
386 for CC in $(cat $tmpcc); do
387 cat << EOT
388 $CC
389 $CC
390 $(grep -m1 "$CC " ${zi}iso3166.tab | cut -d$'\t' -f2 | sed 's|\&|&amp;|g')
391 EOT
392 done | \
393 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
394 --width='500' --height='380' --on-top --center \
395 --image="$icon" --image-on-top \
396 --text="<b>$(_ 'TimeZone Configuration')</b> \
397 \n$(_ 'Select country and press "Forward" or manually select timezone file.') \
398 \n\n$(_ 'Tip: manage timezones list by installing/removing locale packages.')" \
399 --list \
400 --column="$(_n 'Flag'):IMG" --column=$(_n 'Code') --column=$(_n 'Country') \
401 --button="$(_n 'Manage')!document-properties:4" \
402 --button="$(_n 'Manual')!gtk-index:2" \
403 --button="gtk-go-forward:0" \
404 --button="gtk-cancel:1" --always-print-result \
405 --print-column='2' --separator=''
406 ;;
407 xindex)
408 # manual selection of file with timezone info
409 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
410 --width='500' --on-top --center \
411 --image="$icon" --image-on-top \
412 --text="<b>$(_ 'TimeZone Configuration')</b>\n$(_ 'Select time zone')" \
413 --form --field=":FL" ${zi}UTC --separator='' | \
414 sed "s|$zi||"
415 ;;
416 *)
417 # second pass - city/place
418 list=$(tz_list $1)
419 icon="$1"
420 if [ $(echo "$list" | wc -l) != 1 ]; then
421 echo "$list" | \
422 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
423 --width='500' --height='380' --on-top --center \
424 --image="$icon" --image-on-top \
425 --text="<b>$(_ 'TimeZone Configuration')</b>\n$(_ 'Select location')" \
426 --list --column $(_n 'Location/City') --separator=''
427 else
428 echo $list
429 fi
430 ;;
431 esac
432 }
435 tz() {
436 icon='preferences-system-time'
437 arg=$(tz_suggest)
439 timezone=$(tz_select $arg)
440 case $? in
441 1) exit 0 ;;
442 0)
443 [ -n "$timezone" ] && timezone=$(tz_select "$timezone")
444 [ -z "$timezone" ] && exit 0
445 timezone=$(find $zi -name $timezone | grep -v -E "posix|right" | \
446 sed "s|$zi||")
447 ;;
448 2) timezone=$(tz_select "index") ;;
449 4) tazbox manage_i18n main;;
450 esac
452 [ -z "$timezone" ] && exit 0
453 echo $timezone > /etc/TZ
454 export TZ=$timezone
455 tazbox notify "$(_ 'TimeZone was set to %s' "$timezone")" $icon 3
456 rm -f $tmpcc
457 }
460 #
461 # Manage i18n packages
462 #
465 # if installed
467 if_installed() {
468 [ -d "$INSTALLED/$1" ]
469 }
472 # get package's description, install flag and sizes
474 desc_etc() {
475 if grep -q "^$1"$'\t' "$PKGS_DB/installed.info"; then
476 echo 'TRUE' >> $PKGS_LIST; echo $1 >> $ORIG_LIST
477 else
478 echo 'FALSE' >> $PKGS_LIST
479 fi
480 awk -F$'\t' -vp="$1" '
481 ($1==p){
482 split($7, s, " ");
483 printf "%s\n%s\n%s\n%s\n", $1, $4, s[1], s[2];
484 }' "$PKGS_DB/packages.info" >> $PKGS_LIST
485 }
488 # remove temp
490 rm_temp() {
491 rm -f $PKGS_LIST $ORIG_LIST $ANSWER $NEW_LIST $LIST1 $LIST2
492 }
495 # install/remove locale packages
497 manage_i18n() {
498 PKGS_LIST=$(mktemp)
499 ORIG_LIST=$(mktemp)
500 ANSWER=$(mktemp)
501 NEW_LIST=$(mktemp)
502 LIST1=$(mktemp)
503 LIST2=$(mktemp)
504 PINFO="$PKGS_DB/packages.info"
506 if [ ! -e "$PINFO" ]; then
507 icon='dialog-warning'
508 yad --title="$(_n 'Manage locale packages')" --window-icon="$icon" \
509 --width='400' --on-top --center \
510 --image="$icon" --image-on-top \
511 --text="$(_n 'Please, recharge packages database.')" \
512 --button="$(_n 'Recharge list')!view-refresh:2" \
513 --button="gtk-cancel:1"
515 case "$?" in
516 1) rm_temp; return;;
517 2) tazbox recharge;;
518 esac
519 fi
521 tazbox notify "$(_ 'Please wait')" appointment-soon &
523 for i in $(awk -F$'\t' '$1~/^locale-[a-z_A-Z]+$/{print $1}' $PINFO); do
524 desc_etc $i
525 done
527 if [ "$1" != 'main' ]; then
528 for i in $(awk -F$'\t' '$1~/^locale-[a-z_A-Z]+-extra$/{print $1}' $PINFO); do
529 desc_etc $i
530 done
532 if if_installed libQtCore; then
533 for i in $(awk -F$'\t' '$1~/^qt-locale/{print $1}' $PINFO); do
534 desc_etc $i
535 done
536 fi
538 if if_installed razorqt; then
539 for i in $(awk -F$'\t' '$1~/^razorqt-locale/{print $1}' $PINFO); do
540 desc_etc $i
541 done
542 fi
544 if if_installed firefox; then
545 for i in $(awk -F$'\t' '$1~/^firefox-langpack/{print $1}' $PINFO); do
546 desc_etc $i
547 done
548 fi
550 if if_installed thunderbird; then
551 for i in $(awk -F$'\t' '$1~/^thunderbird-langpack/{print $1}' $PINFO); do
552 desc_etc $i
553 done
554 fi
556 if if_installed squirrelmail; then
557 for i in $(awk -F$'\t' '$1~/^squirrelmail-[a-z][a-z][_-]/{print $1}' $PINFO); do
558 desc_etc $i
559 done
560 fi
562 if if_installed aspell; then
563 for i in $(awk -F$'\t' '$1~/^aspell-[a-z][a-z]_?[A-Z]?[A-Z]?$/{print $1}' $PINFO); do
564 desc_etc $i
565 done
566 fi
568 OTHER_LOCALE="gnome-commander|-i18n gnome-vfs|-i18n gpa|-langpack \
569 gucharmap|-i18n lxterminal|-locales lyx|-locales rox-filer|-locales \
570 ufraw|-locales qupzilla|-locales"
571 for i in $OTHER_LOCALE; do
572 if if_installed ${i%%|*}; then desc_etc ${i/|/}; fi
573 done
574 fi
576 icon='preferences-desktop-locale'
577 cat $PKGS_LIST | \
578 {
579 yad --title="$(_n 'Manage locale packages')" --window-icon="$icon" \
580 --width='600' --height='400' --on-top --center \
581 --image="$icon" --image-on-top \
582 --text="$(_n 'Check only locale packages you need and press "Install/Remove".')" \
583 --list --multiple --ellipsize='END' --expand-column='3' \
584 --column="$(_n 'Inst.'):CHK" --column="$(_n 'Package Name'):TEXT" \
585 --column="$(_n 'Description'):TEXT" --column="$(_n 'Size'):TEXT" \
586 --column="$(_n 'Installed'):TEXT" \
587 --button="$(_n 'Recharge list')!view-refresh:4" \
588 --button="$(_n 'Install/Remove')!gtk-execute:2" \
589 --button="gtk-cancel:1" \
590 --print-all
591 } > $ANSWER
593 case "$?" in
594 1) rm_temp; exit 0;;
595 4) tazbox recharge; rm_temp; tazbox manage_i18n; exit 0;;
596 esac
598 grep -e 'TRUE' $ANSWER | cut -d'|' -f2 > $NEW_LIST
600 # check difference between ORIG_LIST and NEW_LIST
601 sort -o $LIST1 $ORIG_LIST
602 sort -o $LIST2 $NEW_LIST
603 DIFF=$(diff $LIST1 $LIST2 | sed '/---/d;/+++/d;/@@/d')
604 if [ -z "$DIFF" ]; then rm_temp; exit 0; fi
606 # output log to gtk window
607 title="$(_n 'TazPkg log')"; icon='system-software-update'; opts='--tail'
608 {
609 for pkg in $(echo "$DIFF" | grep -e '^-' | sed 's|^-||g'); do
610 _ 'REMOVE: %s' "$pkg"
611 yes | tazpkg -r $pkg --output='raw'
612 done
613 for pkg in $(echo "$DIFF" | grep -e '^+' | sed 's|^+||g'); do
614 _ 'INSTALL: %s' "$pkg"
615 tazpkg -gi $pkg --output='raw'
616 done
617 echo -e "\n\n$(_n 'Done!')\n"
618 } | output_command
619 rm_temp
620 }
624 # New file functions
626 newfile_main() {
627 icon='document-new'
628 yad --title="$(_n 'New file')" --window-icon="$icon" \
629 --width='460' --height='160' --on-top --center \
630 --image="$icon" --image-on-top \
631 --icon="$icon" \
632 --text="<b>$(_n 'Create a new file or folder on your desktop')</b>" \
633 --entry --entry-label="$(_n 'File name')" \
634 --ricon='edit-clear' \
635 --always-print-result \
636 --button="$(_n 'SHell script')!application-x-shellscript:4" \
637 --button="$(_n 'Folder')!folder:3" \
638 --button="$(_n 'File')!empty:2" \
639 --button='gtk-cancel:1'
640 }
643 newfile() {
644 file=$(newfile_main)
645 ret=$?
646 [ -z "$file" ] && exit 0
647 case $ret in
648 4)
649 cat > "$HOME/Desktop/$file" << EOT
650 #!/bin/sh
651 #
653 EOT
654 chmod +x "$HOME/Desktop/$file" ;;
655 3) mkdir -p "$HOME/Desktop/$file" ;;
656 2) touch "$HOME/Desktop/$file" ;;
657 1) exit 0 ;;
658 esac
659 }
662 # All applications
664 all_apps() {
665 icon='user-bookmarks'
666 yad --title="$(_n 'All Applications')" --window-icon="$icon" \
667 --width='400' --height='400' \
668 --icons --compact \
669 --read-dir='/usr/share/applications' \
670 --button='gtk-close:0'
671 }
674 # Ask root permissions for system settings
676 ask_root() {
677 if [ "$(id -u)" -ne 0 ]; then
678 exec tazbox su $0 $@
679 exit 0
680 fi
681 }
684 vnc_main() {
685 icon='video-display'
686 yad --title="$(_n 'Framebuffer VNC viewer')" --window-icon="$icon" \
687 --width='250' --height='160' --on-top --center \
688 --image="$icon" --image-on-top --icon="$icon" \
689 --form \
690 --text="<b>$(_n 'Remote display connection')</b>" "localhost 5900" \
691 --field="$(_n 'VNC Server')" \
692 --field="$(_n 'Via a SSH tunnel'):CHK" \
693 --always-print-result \
694 --button="$(_n 'On this console'):1" \
695 --button="$(_n 'In a new console'):0"
696 }
699 video() {
700 icon='video-x-generic'
702 # Get switchs
703 tazwebargs="--notoolbar"
704 while true ; do
705 case "$1" in
706 --fullscreen) tazwebargs="$tazwebargs --kiosk"
707 dpmstimeout=$(xset q | grep timeout | cut -d' ' -f5) ;;
708 --loop) loop="loop" ;;
709 *) break
710 esac
711 shift
712 done
714 # Get filename
715 [ "$1" ] && file="$PWD/$(basename "$1")"
716 [ "${1:0:1}" == "/" ] && file="$1"
717 [ -s "$file" ] || file="$(yad --file --width='600' --height='500' --add-preview \
718 --window-icon $icon --title "$(_ 'Select the video file')" --center \
719 --file-filter="$(_ 'All video files')|*.mp4 *.m4v *.webm *.ogg *.ogv *.flv *.avi *.3gp" \
720 --file-filter="$(_ 'All files')|*")"
721 [ -s "$file" ] || return
723 # Extra parameters
724 text=
725 attr='autoplay="true"'
726 for i in jpg jpeg ; do
727 [ -s "${file%.*}.$i" ] &&
728 attr="poster=\"file://${file%.*}.$i\"" && break
729 done
730 IFS=$'\n'
731 for i in ${file%.*}_${LANG%%[._]*}.vtt ${file%.*}.vtt ; do
732 [ -s $i ] && text="
733 <track kind=\"captions\" src=\"file://$i\" srclang=\"${LANG%%[._]*}\" default>"
734 done
736 # Build the html5 page
737 tmp=/tmp/video-player-$$.html
738 cat > $tmp <<EOT
739 <html>
740 <head>
741 <meta charset="UTF-8">
742 <title>$(basename "$file")</title>
743 <style>
744 body{background:#000;margin:0}
745 a{color:#29F}
746 div{color:#FFF;position:absolute;bottom:2em;left:0;right:0;text-align:center}
747 </style>
748 </head>
749 <body>
750 <video width="100%" height="100%" src="file://$file" controls $attr$loop>$text
751 <div>$(_ 'Unsupported video file format.')<br>
752 $(IFS=$'\n'; _ 'Retry with %s, %s, %s, %s, %s or %s.' \
753 $(printf '<a href="http://127.0.0.1:82/user/pkgs.cgi?info=%s">%s</a>\n' \
754 vlc VLC gnome-mplayer 'GNOME MPlayer' mplayer MPlayer gxine gxine xine-ui xine ffplay ffplay))
755 </div>
756 </video>
757 </body>
758 </html>
759 EOT
760 unset IFS
761 [ -n "$dpmstimeout" ] && xset dpms 0 0 0 s 0 0
762 tazweb $tazwebargs file://$tmp || browser file://$tmp
763 [ -n "$dpmstimeout" ] && xset dpms $dpmstimeout $dpmstimeout $dpmstimeout s $dpmstimeout $dpmstimeout
764 rm -f $tmp
765 }
768 newvt()
769 {
770 ask_root newvt $@ || return
771 openvt -sw $@
772 deallocvt
773 }
776 vnc() {
777 server=$(vnc_main)
778 status=$?
779 # Deal with --button values
780 [ "$server" ] || return
781 case "$server" in
782 *TRUE\|) fbvnc=sshfbvnc ;;
783 *) fbvnc=fbvnc ;;
784 esac
785 case "$status" in
786 1) $fbvnc ${server%%|*} ;;
787 0) newvt $fbvnc ${server%%|*} ;;
788 esac
789 }
792 #
793 # Commands
794 #
796 case "$1" in
797 su)
798 shift
799 # Don't show dialog if we are root
800 [ "$(id -u)" -eq 0 ] && exec "$@"
801 SU_CMD="$@"
802 SUBOX_CONF="$HOME/.config/slitaz/subox.conf"
804 # Check if a password has been saved before launching main dialog
805 if [ -s "$SUBOX_CONF" ]; then
806 PASSWD="$(cat $SUBOX_CONF)"
807 CHECKED='TRUE'
808 fi
810 # Display the main dialog (ask for password)
811 main="$(su_main "$SU_CMD")"
813 # Deal with --button values and exit if cancelled to avoid erasing
814 # saved password.
815 [ "$?" -eq 1 ] && exit 0
817 # Save or erase Autosaved password
818 if [ $(echo "$main" | cut -d"|" -f2) == 'TRUE' ]; then
819 echo "$main" | cut -d"|" -f1 > $SUBOX_CONF
820 chmod 0600 $SUBOX_CONF
821 else
822 cat /dev/null > $SUBOX_CONF
823 fi
825 # Try to login & execute. If password is wrong execute error dialog
826 SU_CMD_QUOTED="$(echo "$SU_CMD" | sed 's|&|\\&|g')"
827 echo $main | cut -d"|" -f1 | su -c "$SU_CMD_QUOTED &" || su_error
828 ;;
830 logout)
831 # Logout window with actions
832 if [ -n "$2" ]; then
833 answer="$2"
834 logout_confirm $answer
835 else
836 logout_main; answer=$?
837 fi
839 # Deal with --button values
840 # DE and WM started with a custom -session script should export
841 # XDG_CURRENT_DESKTOP
842 case $answer in
843 4|exit)
844 case $XDG_CURRENT_DESKTOP in
845 LXDE)
846 [ -n "$_LXSESSION_PID" ] && kill $_LXSESSION_PID
847 [ "$DESKTOP_SESSION" == 'compiz' ] && killall compiz
848 openbox --exit ;;
849 openbox) openbox --exit ;;
850 compiz) killall compiz ;;
851 *)
852 # Try to kill other WM that dont set XDG var.
853 jwm -exit 2>/dev/null ;;
854 esac ;;
855 3|reboot)
856 reboot || reboot -f ;;
857 2|halt)
858 poweroff ;;
859 esac
860 ;;
862 out)
863 # Pipe a command into a GTK window
864 sed 's|\[.m||g; s|\[[0-9][0-9]*G| |g' | output_command
865 ;;
867 out-dl)
868 # A tiny GTK window for Busybox wget output
869 url="$2"; opts='--tail --button=gtk-cancel:1'
870 icon='folder-download'; title="$(_ 'Downloading...')"
871 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
872 busybox wget -c -P $DOWNLOADS $url 2>&1 | output_command
873 cancel_dl
874 ;;
876 locale)
877 ask_root $@ && locale
878 ;;
880 keymap)
881 ask_root $@ && keymap
882 ;;
884 tz)
885 ask_root $@ && tz
886 ;;
888 manage_i18n)
889 ask_root $@ && manage_i18n $2
890 ;;
892 recharge)
893 ask_root $@; opts='--on-top'; output=raw tazpkg recharge | output_command
894 ;;
896 setup)
897 ask_root $@ && setup
898 ;;
900 new-file)
901 newfile
902 ;;
904 all-apps)
905 all_apps
906 ;;
908 notify|-n)
909 # On screen notification box.
910 icon="$3"
911 time="$4"
912 [ -z "$icon" ] && icon='dialog-information'
913 [ -z "$time" ] && time='4'
914 yad --width='520' --height='80' --timeout="$time" --timeout-indicator='right' \
915 --on-top --center --no-buttons --borders='12' --undecorated \
916 --skip-taskbar --image="$icon" --image-on-top --text="<b>$2</b>"
917 ;;
919 tazapps)
920 # Default applications configuration script. System wide config file
921 # is /etc/slitaz/applications.conf and each user can have personal
922 # settings. System wide for root and personal config for user.
923 export CONFIG="$HOME/.config/slitaz/applications.conf"
924 if [ "$(id -u)" -eq 0 ]; then
925 [ ! -f $CONFIG ] || mv -f $CONFIG /etc/slitaz/applications.conf
926 export CONFIG='/etc/slitaz/applications.conf'
927 fi
929 for a in FILE_MANAGERS BROWSERS EDITORS TERMINALS WINDOW_MANAGERS; do
930 eval $(expr $a=$(echo $(LC_ALL=C tazx get-applist ${a%%S} \
931 only-installed yad) | sed 's/ /!/g ; s/!!//g; s/ //g'))
932 done
934 # Missing file was created by slitaz_apps_conf function from tazx
935 . $CONFIG
937 icon='preferences-desktop-default-applications'
938 eval $(yad --title="$(_n 'SliTaz default applications')" \
939 --window-icon="$icon" --image="$icon" --image-on-top \
940 --text="<b>$(_n 'SliTaz default applications configuration')</b>" \
941 --form \
942 --field="$(_n 'File manager:'):CBE" "$FILE_MANAGERS" \
943 --field="$(_n 'Web browser:'):CBE" "$BROWSERS" \
944 --field="$(_n 'Text editor:'):CBE" "$EDITORS" \
945 --field="$(_n 'Terminal:'):CBE" "$TERMINALS" \
946 --field="$(_n 'Window manager:'):CBE" "$WINDOW_MANAGERS" | \
947 awk -F'|' '{printf "FILE_MANAGER=\"%s\"\nBROWSER=\"%s\"\nEDITOR=\"%s\"\
948 TERMINAL=\"%s\"\nWINDOW_MANAGER=\"%s\"\n", $1, $2, $3, $4, $5}')
950 sed '/FILE_MANAGER=/s|"\([^"]*\)"|"'$FILE_MANAGER'"|; \
951 /BROWSER=/s|"\([^"]*\)"|"'$BROWSER'"|; \
952 /EDITOR=/s|"\([^"]*\)"|"'$EDITOR'"|; \
953 /TERMINAL=/s|"\([^"]*\)"|"'$TERMINAL'"|; \
954 /WINDOW_MANAGER=/s|"\([^"]*\)"|"'$WINDOW_MANAGER'"|' \
955 -i $CONFIG
956 ;;
958 gpl)
959 yad --title='GNU General Public License' --window-icon='text-x-copying' \
960 --geometry='650x500' \
961 --image='/usr/share/pixmaps/gpl3.png' --image-on-top \
962 --center \
963 --text-info \
964 --fontname='monospace' \
965 --button 'OK' < /usr/share/licenses/gpl.txt
966 ;;
968 vnc)
969 vnc
970 ;;
972 video)
973 shift
974 video "$@"
975 ;;
977 newvt)
978 $@
979 ;;
981 mkmenu) $@ ;;
983 *)
984 usage
985 ;;
986 esac
988 exit 0