slitaz-tools view tazbox/tazbox @ rev 980
make pot & make msgmerge
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue May 24 22:30:28 2016 +0200 (2016-05-24) |
parents | 928b4d1e7a97 |
children | 0b2140279749 |
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|&|&|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|\&|&|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 filename
625 [ "$1" ] && file="$PWD/$(basename "$1")"
626 [ -s "$file" ] || file="$(yad --file --width='500' --height='400' \
627 --window-icon $icon --title "$(_ "Select the video file")" --center)"
629 # Extra parameters
630 text=
631 attr='autoplay="true"'
632 for i in png jpg jpeg ; do
633 [ -s ${file%.*}.$i ] &&
634 attr="poster=\"file://${file%.*}.$i\"" && break
635 done
636 for i in ${file%.*}_${LANG%.*}.vtt ${file%.*}_${LANG%_*}.vtt \
637 ${file%.*}.vtt ; do
638 [ -s $i ] && text="
639 <track kind=\"captions\" src=\"file://$i\" srclang=\"${LANG%_*}\" default>"
640 done
642 # Build the html5 page
643 tmp=/tmp/video-player-$$.html
644 cat > $tmp <<EOT
645 <html>
646 <head>
647 <title>$(basename "$file")</title>
648 </head>
649 <body>
650 <video src="file://$file" controls $attr>$text
651 Unsupported video file format
652 </video>
653 </body>
654 </html>
655 EOT
657 tazweb --notoolbar file://$tmp || browser file://$tmp
658 rm -f $tmp
659 }
662 newvt()
663 {
664 ask_root newvt $@ || return
665 openvt -sw $@
666 deallocvt
667 }
670 vnc() {
671 server=$(vnc_main)
672 status=$?
673 # Deal with --button values
674 [ "$server" ] || return
675 case "$server" in
676 *TRUE\|) fbvnc=sshfbvnc ;;
677 *) fbvnc=fbvnc ;;
678 esac
679 case "$status" in
680 1) $fbvnc ${server%%|*} ;;
681 0) newvt $fbvnc ${server%%|*} ;;
682 esac
683 }
686 #
687 # Commands
688 #
690 case "$1" in
691 su)
692 shift
693 # Don't show dialog if we are root
694 [ "$(id -u)" -eq 0 ] && exec "$@"
695 SU_CMD="$@"
696 SUBOX_CONF="$HOME/.config/slitaz/subox.conf"
698 # Check if a password has been saved before launching main dialog
699 if [ -s "$SUBOX_CONF" ]; then
700 PASSWD="$(cat $SUBOX_CONF)"
701 CHECKED='TRUE'
702 fi
704 # Display the main dialog (ask for password)
705 main="$(su_main "$SU_CMD")"
707 # Deal with --button values and exit if cancelled to avoid erasing
708 # saved password.
709 [ "$?" -eq 1 ] && exit 0
711 # Save or erase Autosaved password
712 if [ $(echo "$main" | cut -d"|" -f2) == 'TRUE' ]; then
713 echo "$main" | cut -d"|" -f1 > $SUBOX_CONF
714 chmod 0600 $SUBOX_CONF
715 else
716 cat /dev/null > $SUBOX_CONF
717 fi
719 # Try to login & execute. If password is wrong execute error dialog
720 SU_CMD_QUOTED="$(echo "$SU_CMD" | sed 's|&|\\&|g')"
721 echo $main | cut -d"|" -f1 | su -c "$SU_CMD_QUOTED &" || su_error
722 ;;
724 logout)
725 # Logout window with actions
726 if [ -n "$oldstyle" ]; then
727 answer=$(logout_oldstyle)
728 else
729 logout_main; answer=$?
730 fi
732 # Deal with --button values
733 # DE and WM started with a custom -session script should export
734 # XDG_CURRENT_DESKTOP
735 case $answer in
736 4|*exit)
737 case $XDG_CURRENT_DESKTOP in
738 LXDE)
739 [ -n "$_LXSESSION_PID" ] && kill $_LXSESSION_PID
740 [ "$DESKTOP_SESSION" == 'compiz' ] && killall compiz
741 openbox --exit ;;
742 openbox) openbox --exit ;;
743 compiz) killall compiz ;;
744 *)
745 # Try to kill other WM that dont set XDG var.
746 jwm -exit 2>/dev/null ;;
747 esac ;;
748 3|*reboot)
749 reboot || reboot -f ;;
750 2|*halt)
751 poweroff ;;
752 esac
753 ;;
755 out)
756 # Pipe a command into a GTK window
757 sed 's|\[.m||g; s|\[[0-9][0-9]*G| |g' | output_command
758 ;;
760 out-dl)
761 # A tiny GTK window for Busybox wget output
762 url="$2"; opts='--tail --button=gtk-cancel:1'
763 icon='folder-download'; title="$(_ 'Downloading...')"
764 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
765 busybox wget -c -P $DOWNLOADS $url 2>&1 | output_command
766 cancel_dl
767 ;;
769 locale)
770 ask_root $@ && locale
771 ;;
773 keymap)
774 ask_root $@ && keymap
775 ;;
777 tz)
778 ask_root $@ && tz
779 ;;
781 manage_i18n)
782 ask_root $@ && manage_i18n $2
783 ;;
785 recharge)
786 ask_root $@; opts='--on-top'; output=raw tazpkg recharge | output_command
787 ;;
789 setup)
790 ask_root $@ && setup
791 ;;
793 new-file)
794 newfile
795 ;;
797 all-apps)
798 all_apps
799 ;;
801 notify|-n)
802 # On screen notification box.
803 icon="$3"
804 time="$4"
805 [ -z "$icon" ] && icon='dialog-information'
806 [ -z "$time" ] && time='4'
807 yad --width='520' --height='80' --timeout="$time" --timeout-indicator='right' \
808 --on-top --center --no-buttons --borders='12' --undecorated \
809 --skip-taskbar --image="$icon" --image-on-top --text="<b>$2</b>"
810 ;;
812 tazapps)
813 # Default applications configuration script. System wide config file
814 # is /etc/slitaz/applications.conf and each user can have personal
815 # settings. System wide for root and personal config for user.
816 export CONFIG="$HOME/.config/slitaz/applications.conf"
817 if [ "$(id -u)" -eq 0 ]; then
818 [ ! -f $CONFIG ] || mv -f $CONFIG /etc/slitaz/applications.conf
819 export CONFIG='/etc/slitaz/applications.conf'
820 fi
822 for a in FILE_MANAGERS BROWSERS EDITORS TERMINALS WINDOW_MANAGERS; do
823 eval $(expr $a=$(echo $(LC_ALL=C tazx get-applist ${a%%S} \
824 only-installed yad) | sed 's/ /!/g ; s/!!//g; s/ //g'))
825 done
827 # Missing file was created by slitaz_apps_conf function from tazx
828 . $CONFIG
830 icon='preferences-desktop-default-applications'
831 eval $(yad --title="$(_n 'SliTaz default applications')" \
832 --window-icon="$icon" --image="$icon" --image-on-top \
833 --text="<b>$(_n 'SliTaz default applications configuration')</b>" \
834 --form \
835 --field="$(_n 'File manager:'):CBE" "$FILE_MANAGERS" \
836 --field="$(_n 'Web browser:'):CBE" "$BROWSERS" \
837 --field="$(_n 'Text editor:'):CBE" "$EDITORS" \
838 --field="$(_n 'Terminal:'):CBE" "$TERMINALS" \
839 --field="$(_n 'Window manager:'):CBE" "$WINDOW_MANAGERS" | \
840 awk -F'|' '{printf "FILE_MANAGER=\"%s\"\nBROWSER=\"%s\"\nEDITOR=\"%s\"\
841 TERMINAL=\"%s\"\nWINDOW_MANAGER=\"%s\"\n", $1, $2, $3, $4, $5}')
843 sed '/FILE_MANAGER=/s|"\([^"]*\)"|"'$FILE_MANAGER'"|; \
844 /BROWSER=/s|"\([^"]*\)"|"'$BROWSER'"|; \
845 /EDITOR=/s|"\([^"]*\)"|"'$EDITOR'"|; \
846 /TERMINAL=/s|"\([^"]*\)"|"'$TERMINAL'"|; \
847 /WINDOW_MANAGER=/s|"\([^"]*\)"|"'$WINDOW_MANAGER'"|' \
848 -i $CONFIG
849 ;;
851 gpl)
852 yad --title='GNU General Public License' --window-icon='text-x-copying' \
853 --geometry='650x500' \
854 --image='/usr/share/pixmaps/gpl3.png' --image-on-top \
855 --center \
856 --text-info \
857 --fontname='monospace' \
858 --button 'OK' < /usr/share/licenses/gpl.txt
859 ;;
861 vnc)
862 vnc
863 ;;
865 video)
866 video "$@"
867 ;;
869 newvt)
870 $@
871 ;;
873 *)
874 usage
875 ;;
876 esac
878 exit 0