slitaz-tools view tazbox/tazbox @ rev 1019

tazbox mkmenu: do not add logout menu to LXPanel, only translate it if exists
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Apr 11 02:37:37 2017 +0300 (2017-04-11)
parents 86fbc888a1f6
children 13e9412db15f
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 ssh $(_ 'Open a remote terminal')
61 newline
62 }
65 # try to find icon in .desktop files
67 find_icon() {
68 local_desktop=$(find $HOME/.local/share/applications \
69 -name ${1##*/}.desktop 2&>/dev/null | head -n1)
70 system_desktop=$(find /usr/share/applications \
71 -name ${1##*/}.desktop 2&>/dev/null | head -n1)
72 desktop="${local_desktop:-$system_desktop}"
73 [ -n "$desktop" ] && cat $desktop | sed '/\[Desktop\ Entry\]/,/^\[/!d' | \
74 sed '/^Icon=/!d' | head -n1 | cut -d= -f2
75 }
78 # su frontend GUIs
80 su_main() {
81 CMD1="${1%% *}"; CMD2="$(echo "${1#* }" | sed 's|&|&amp;|g')"
82 : ${icon=$(find_icon $CMD1)}
83 icon="${icon:-dialog-password}"
85 yad --title="$(_n 'SliTaz admin password')" --window-icon=$icon \
86 --width=520 --on-top --center \
87 --image=$icon --image-on-top \
88 --text="$(_n 'Please enter root password (default root) to execute:')\n
89 <span foreground=\"red\"><tt><b>$CMD1</b> $CMD2</tt></span>\n" \
90 --form \
91 --field="$(_n 'Password:'):H" $PASSWD \
92 --field="$(_n 'Autosave password'):CHK" $CHECKED
93 }
96 su_error() {
97 icon='dialog-error'
98 yad --title="$(_n 'Error')" --window-icon=$icon \
99 --width=320 --on-top --center \
100 --image=$icon --image-on-top \
101 --text="\n<b>$(_n 'Error: wrong password!')</b>\n" \
102 --button="gtk-close:1"
103 }
106 # user may press cancel on download.
108 cancel_dl() {
109 if [ "$?" -eq 1 ]; then
110 _ "CANCEL"
111 rm -f $DOWNLOADS/$(basename $url)
112 fi
113 }
116 # output a command in a GTK window
118 output_command() {
119 : ${title=$(_n 'TazBox Output')}
120 : ${icon=dialog-information}
122 yad --title="$title" --window-icon="$icon" \
123 --geometry='600x220+0-24' --fore='#ffffff' --back='#000000' \
124 --text-info --fontname=monospace --wrap $opts \
125 --button='gtk-close:1'
126 }
129 # logout GUI function
131 logout_main() {
132 icon='/usr/share/pixmaps/slitaz-icon.png'
133 yad --title="$(_n 'SliTaz Logout')" --window-icon="$icon" \
134 --on-top --center --height='130' \
135 --image="$icon" --image-on-top \
136 --text="<b>$(_n 'SliTaz Logout - Please choose an action:')</b>" \
137 --always-print-result \
138 --button "$(_n 'Close X session')!system-log-out:4" \
139 --button "$(_n 'Reboot system')!system-reboot:3" \
140 --button "$(_n 'Shutdown system')!system-shutdown:2"
141 }
144 # logout functions with auto-confirmation
146 logout_confirm() {
147 timeout=5
148 case $1 in
149 exit) action="$(_n 'Closing the X session...')"; icon='system-log-out';;
150 reboot) action="$(_n 'Rebooting the system...')"; icon='system-reboot';;
151 halt) action="$(_n 'Shutting down the system...')"; icon='system-shutdown';;
152 *) exit;;
153 esac
154 warning="$(_ 'Selected action will be executed automatically in %s seconds.' "$timeout")"
155 yad --title="$(_n 'SliTaz Logout')" --window-icon="$icon" \
156 --on-top --center --width='300' --image="$icon" --image-on-top \
157 --text="<b>$action</b>\n\n$warning" \
158 --timeout $timeout --timeout-indicator=bottom \
159 --button "gtk-cancel:252"
160 [ "$?" -ne 252 ] || exit 0
161 }
164 # make logout menu in the right edge of LXPanel
166 mkmenu() {
167 # (re)make the menu button with the user log name
168 dd="$HOME/.local/share/desktop-directories"; mkdir -p "$dd"
169 echo -e "[Desktop Entry]\nType=Directory\nName=$(whoami)" > "$dd/user.directory"
171 # check the panel config file existence, copy from default config if needed
172 panels=$(find $HOME/.config/lxpanel -type f -name panel 2>/dev/null)
173 if [ -z "$panels" ]; then
174 mkdir -p "$HOME/.config/lxpanel"
175 cp -a /etc/skel/.config/lxpanel/* "$HOME/.config/lxpanel"
176 fi
178 for panel in $panels; do
179 conf=$(tr '\n' '`' < $panel | sed 's|Plugin|\n&|g') # each plugin on its own line
180 if fgrep -q 'user.directory' "$panel"; then
181 # if menu already exists - shrink it to '@@@'
182 newconf=$(echo "$conf" | sed 's|.*user\.directory.*$|@@@|')
183 else
184 # otherwise do nothing
185 newconf="$conf"
186 fi
187 menu=$(cat <<EOT
188 Plugin {
189 type = menu
190 Config {
191 name=user.directory
192 image=avatar-default
193 tintcolor=#33230D
194 item {
195 image=system-log-out-panel
196 name=$(_ 'Close X session')
197 action=tazbox logout exit
198 }
199 item {
200 image=system-reboot-panel
201 name=$(_ 'Reboot system')
202 action=tazbox logout reboot
203 }
204 item {
205 image=system-shutdown-panel
206 name=$(_ 'Shutdown system')
207 action=tazbox logout halt
208 }
209 }
210 }
212 EOT
213 )
214 # rebuild the menu: change '@@@' to the menu content
215 echo "$newconf" | \
216 awk -vmenu="$menu" '{if ($1=="@@@") {printf ("%s\n\n", menu)} else {print}}' | \
217 tr '`' '\n' > $panel
218 done
219 }
222 # generate keymap list
224 gen_kmap_list() {
225 echo > $tmp
226 cd /usr/share/kbd/keymaps/i386
227 # we first need a list to sort and then use \n for Yad list.
228 for i in $(find -type f | sed '/include/d; s|./||'); do
229 echo "$(basename $i .map.gz)|$(dirname $i)" >> $tmp
230 done
231 }
234 # Initial Config functions
236 setup_main() {
237 icon='preferences-desktop-locale'
238 gen_kmap_list
239 locale=$(ls -1 $db 2> /dev/null | grep ^[a-z][a-z]_[A-Z][A-Z] | tr "\n" "!")
240 keymap=$(cat $tmp | sort | tr "\n" "!")
241 timezone=$(find $zi -type f | sed s,$zi,,g | grep -v -F '.tab' | tr "\n" "!")
242 yad --title="$(_n 'SliTaz Initial Setup')" --window-icon=$icon \
243 --width='500' \
244 --image="$icon" --image-on-top \
245 --text="<big>$(_n 'Here you can set your preferences \n for <b>locale, keymap and timezone</b>.')</big>" \
246 --form \
247 --field "$(_n 'Locale'):CB" $locale \
248 --field "$(_n 'Keymap'):CB" $keymap \
249 --field "$(_n 'Timezone'):CB" $timezone
250 }
253 setup() {
254 choices=$(setup_main)
255 locale=$( echo $choices | cut -d'|' -f1)
256 keymap=$( echo $choices | cut -d'|' -f2)
257 timezone=$(echo $choices | cut -d'|' -f3)
258 [ -n "$locale" ] && tazlocale init $locale
259 [ -n "$keymap" ] && tazkeymap init $keymap
260 [ -n "$timezone" ] && echo $timezone > /etc/TZ
261 }
264 #
265 # Locale functions
266 #
268 locale_main() {
269 icon='preferences-desktop-locale'
270 for locale in $(ls -1 $db 2> /dev/null | grep '[a-z]_[A-Z]'); do
271 desc=$(fgrep -m1 title $db/$locale | cut -d'"' -f2)
272 ll_CC=${locale%%@*}
273 echo -e "${ll_CC##*_}\n$locale\n$desc"
274 done | \
275 yad --title="$(_n 'SliTaz locale')" --window-icon="$icon" \
276 --width='600' --height='380' --sticky --on-top --center \
277 --image="$icon" --image-on-top \
278 --text="<b>$(_n 'Language configuration')</b> \
279 \n\n$(_ 'Tip: manage locales list by installing/removing locale packages.')" \
280 --list --column="$(_n 'Flag'):IMG" --column $(_n 'Name') \
281 --column $(_n 'Description') \
282 --print-column='2' --separator='' \
283 --button="$(_n 'Manage')!document-properties:2" \
284 --button="gtk-cancel:1" --button="gtk-ok:0"
285 }
288 locale() {
289 locale=$(locale_main)
290 # Deal with --button values
291 case $? in
292 2) tazbox manage_i18n main ;;
293 1) exit 0 ;;
294 *) continue ;;
295 esac
296 # System language configuration.
297 if [ "$locale" ]; then
298 tazlocale $locale
299 tazbox notify "$(_ 'Locale was set to %s' "$locale")" \
300 preferences-desktop-locale 3
301 fi
302 }
305 # Keymap functions
307 keymap_main() {
308 icon='preferences-desktop-keyboard'
309 gen_kmap_list
310 for i in $(sort $tmp); do
311 echo "$i" | tr '|' '\n'
312 done | \
313 yad --title="$(_ 'SliTaz keymap')" --window-icon=$icon \
314 --width=500 --height=380 --sticky --on-top --center \
315 --image=$icon --image-on-top \
316 --text="<b>$(_n 'Keyboard configuration')</b>" \
317 --list --column $(_n 'Keymap') --column $(_n 'Type') \
318 --print-column=1 --separator=''
319 rm -f $tmp
320 }
323 keymap() {
324 keymap=$(keymap_main)
325 # Deal with --button values
326 [ "$?" -eq 1 ] && exit 0
327 # System keymap configuration
328 [ -n "$keymap" ] && tazkeymap $keymap
329 }
332 # Free GeoIP service
333 # Response: IP,CountryCode,CountryName, ...
335 geoip() {
336 # freegeoip.net can be in the blocked hosts list. Return only correct answer or nothing
337 [ ! -e $csv ] && wget -q -T3 -O - http://freegeoip.net/csv/ 2&>/dev/null | \
338 grep '[0-9.]*,.*,.*,.*,.*,.*,.*,.*,[0-9.]*,[0-9.]*' > $csv
339 [ -e $csv ] && cut -d, -f2 $csv
340 }
343 #
344 # TZ functions
345 #
348 # list of all existing available locations for country
350 tz_list() {
351 find $zi | \
352 grep -E "$(awk -F$'\t' -vv="$1" '{if ($1 == v || $2 ~ v) print $2}' $ztab | tr ' ' '|')" | \
353 grep -v -E "posix|right" | \
354 sed 's|.*/||g' | sort
355 }
358 # ask for confirmation only if we have what to choose
360 tz_suggest() {
361 CountryCode=$(geoip)
362 if [ -n "$CountryCode" ]; then
363 if [ -n "$(tz_list $CountryCode)" ]; then
364 CountryName=$(cut -d, -f3 $csv)
365 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
366 --on-top --center \
367 --image="$CountryCode" --image-on-top \
368 --text="$(_ 'Suggested location:') <b>$CountryName</b>\n
369 $(_ 'Are you agreed?')" \
370 --button='gtk-yes:0' --button='gtk-no:1'
371 [ "$?" -eq 0 ] && echo $CountryCode
372 fi
373 fi
374 }
377 tz_select() {
378 case x$1 in
379 x)
380 # first pass - country
381 tmpcc=$(mktemp)
383 for tzfile in $(find $zi -type f -regex '.*info/[ABCEIMP].*'); do
384 grep -m1 $(basename $tzfile) $ztab
385 done | cut -d$'\t' -f1 | sort -u > $tmpcc
387 for CC in $(cat $tmpcc); do
388 cat << EOT
389 $CC
390 $CC
391 $(grep -m1 "$CC " ${zi}iso3166.tab | cut -d$'\t' -f2 | sed 's|\&|&amp;|g')
392 EOT
393 done | \
394 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
395 --width='500' --height='380' --on-top --center \
396 --image="$icon" --image-on-top \
397 --text="<b>$(_ 'TimeZone Configuration')</b> \
398 \n$(_ 'Select country and press "Forward" or manually select timezone file.') \
399 \n\n$(_ 'Tip: manage timezones list by installing/removing locale packages.')" \
400 --list \
401 --column="$(_n 'Flag'):IMG" --column=$(_n 'Code') --column=$(_n 'Country') \
402 --button="$(_n 'Manage')!document-properties:4" \
403 --button="$(_n 'Manual')!gtk-index:2" \
404 --button="gtk-go-forward:0" \
405 --button="gtk-cancel:1" --always-print-result \
406 --print-column='2' --separator=''
407 ;;
408 xindex)
409 # manual selection of file with timezone info
410 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
411 --width='500' --on-top --center \
412 --image="$icon" --image-on-top \
413 --text="<b>$(_ 'TimeZone Configuration')</b>\n$(_ 'Select time zone')" \
414 --form --field=":FL" ${zi}UTC --separator='' | \
415 sed "s|$zi||"
416 ;;
417 *)
418 # second pass - city/place
419 list=$(tz_list $1)
420 icon="$1"
421 if [ $(echo "$list" | wc -l) != 1 ]; then
422 echo "$list" | \
423 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
424 --width='500' --height='380' --on-top --center \
425 --image="$icon" --image-on-top \
426 --text="<b>$(_ 'TimeZone Configuration')</b>\n$(_ 'Select location')" \
427 --list --column $(_n 'Location/City') --separator=''
428 else
429 echo $list
430 fi
431 ;;
432 esac
433 }
436 tz() {
437 icon='preferences-system-time'
438 arg=$(tz_suggest)
440 timezone=$(tz_select $arg)
441 case $? in
442 1) exit 0 ;;
443 0)
444 [ -n "$timezone" ] && timezone=$(tz_select "$timezone")
445 [ -z "$timezone" ] && exit 0
446 timezone=$(find $zi -name $timezone | grep -v -E "posix|right" | \
447 sed "s|$zi||")
448 ;;
449 2) timezone=$(tz_select "index") ;;
450 4) tazbox manage_i18n main;;
451 esac
453 [ -z "$timezone" ] && exit 0
454 echo $timezone > /etc/TZ
455 export TZ=$timezone
456 tazbox notify "$(_ 'TimeZone was set to %s' "$timezone")" $icon 3
457 rm -f $tmpcc
458 }
461 #
462 # Manage i18n packages
463 #
466 # if installed
468 if_installed() {
469 [ -d "$INSTALLED/$1" ]
470 }
473 # get package's description, install flag and sizes
475 desc_etc() {
476 if grep -q "^$1"$'\t' "$PKGS_DB/installed.info"; then
477 echo 'TRUE' >> $PKGS_LIST; echo $1 >> $ORIG_LIST
478 else
479 echo 'FALSE' >> $PKGS_LIST
480 fi
481 awk -F$'\t' -vp="$1" '
482 ($1==p){
483 split($7, s, " ");
484 printf "%s\n%s\n%s\n%s\n", $1, $4, s[1], s[2];
485 }' "$PKGS_DB/packages.info" >> $PKGS_LIST
486 }
489 # remove temp
491 rm_temp() {
492 rm -f $PKGS_LIST $ORIG_LIST $ANSWER $NEW_LIST $LIST1 $LIST2
493 }
496 # install/remove locale packages
498 manage_i18n() {
499 PKGS_LIST=$(mktemp)
500 ORIG_LIST=$(mktemp)
501 ANSWER=$(mktemp)
502 NEW_LIST=$(mktemp)
503 LIST1=$(mktemp)
504 LIST2=$(mktemp)
505 PINFO="$PKGS_DB/packages.info"
507 if [ ! -e "$PINFO" ]; then
508 icon='dialog-warning'
509 yad --title="$(_n 'Manage locale packages')" --window-icon="$icon" \
510 --width='400' --on-top --center \
511 --image="$icon" --image-on-top \
512 --text="$(_n 'Please, recharge packages database.')" \
513 --button="$(_n 'Recharge list')!view-refresh:2" \
514 --button="gtk-cancel:1"
516 case "$?" in
517 1) rm_temp; return;;
518 2) tazbox recharge;;
519 esac
520 fi
522 tazbox notify "$(_ 'Please wait')" appointment-soon &
524 for i in $(awk -F$'\t' '$1~/^locale-[a-z_A-Z]+$/{print $1}' $PINFO); do
525 desc_etc $i
526 done
528 if [ "$1" != 'main' ]; then
529 for i in $(awk -F$'\t' '$1~/^locale-[a-z_A-Z]+-extra$/{print $1}' $PINFO); do
530 desc_etc $i
531 done
533 if if_installed libQtCore; then
534 for i in $(awk -F$'\t' '$1~/^qt-locale/{print $1}' $PINFO); do
535 desc_etc $i
536 done
537 fi
539 if if_installed razorqt; then
540 for i in $(awk -F$'\t' '$1~/^razorqt-locale/{print $1}' $PINFO); do
541 desc_etc $i
542 done
543 fi
545 if if_installed firefox; then
546 for i in $(awk -F$'\t' '$1~/^firefox-langpack/{print $1}' $PINFO); do
547 desc_etc $i
548 done
549 fi
551 if if_installed thunderbird; then
552 for i in $(awk -F$'\t' '$1~/^thunderbird-langpack/{print $1}' $PINFO); do
553 desc_etc $i
554 done
555 fi
557 if if_installed squirrelmail; then
558 for i in $(awk -F$'\t' '$1~/^squirrelmail-[a-z][a-z][_-]/{print $1}' $PINFO); do
559 desc_etc $i
560 done
561 fi
563 if if_installed aspell; then
564 for i in $(awk -F$'\t' '$1~/^aspell-[a-z][a-z]_?[A-Z]?[A-Z]?$/{print $1}' $PINFO); do
565 desc_etc $i
566 done
567 fi
569 OTHER_LOCALE="gnome-commander|-i18n gnome-vfs|-i18n gpa|-langpack \
570 gucharmap|-i18n lxterminal|-locales lyx|-locales rox-filer|-locales \
571 ufraw|-locales qupzilla|-locales"
572 for i in $OTHER_LOCALE; do
573 if if_installed ${i%%|*}; then desc_etc ${i/|/}; fi
574 done
575 fi
577 icon='preferences-desktop-locale'
578 cat $PKGS_LIST | \
579 {
580 yad --title="$(_n 'Manage locale packages')" --window-icon="$icon" \
581 --width='600' --height='400' --on-top --center \
582 --image="$icon" --image-on-top \
583 --text="$(_n 'Check only locale packages you need and press "Install/Remove".')" \
584 --list --multiple --ellipsize='END' --expand-column='3' \
585 --column="$(_n 'Inst.'):CHK" --column="$(_n 'Package Name'):TEXT" \
586 --column="$(_n 'Description'):TEXT" --column="$(_n 'Size'):TEXT" \
587 --column="$(_n 'Installed'):TEXT" \
588 --button="$(_n 'Recharge list')!view-refresh:4" \
589 --button="$(_n 'Install/Remove')!gtk-execute:2" \
590 --button="gtk-cancel:1" \
591 --print-all
592 } > $ANSWER
594 case "$?" in
595 1) rm_temp; exit 0;;
596 4) tazbox recharge; rm_temp; tazbox manage_i18n; exit 0;;
597 esac
599 grep -e 'TRUE' $ANSWER | cut -d'|' -f2 > $NEW_LIST
601 # check difference between ORIG_LIST and NEW_LIST
602 sort -o $LIST1 $ORIG_LIST
603 sort -o $LIST2 $NEW_LIST
604 DIFF=$(diff $LIST1 $LIST2 | sed '/---/d;/+++/d;/@@/d')
605 if [ -z "$DIFF" ]; then rm_temp; exit 0; fi
607 # output log to gtk window
608 title="$(_n 'TazPkg log')"; icon='system-software-update'; opts='--tail'
609 {
610 for pkg in $(echo "$DIFF" | grep -e '^-' | sed 's|^-||g'); do
611 _ 'REMOVE: %s' "$pkg"
612 yes | tazpkg -r $pkg --output='raw'
613 done
614 for pkg in $(echo "$DIFF" | grep -e '^+' | sed 's|^+||g'); do
615 _ 'INSTALL: %s' "$pkg"
616 tazpkg -gi $pkg --output='raw'
617 done
618 echo -e "\n\n$(_n 'Done!')\n"
619 } | output_command
620 rm_temp
621 }
625 # New file functions
627 newfile_main() {
628 icon='document-new'
629 yad --title="$(_n 'New file')" --window-icon="$icon" \
630 --width='460' --height='160' --on-top --center \
631 --image="$icon" --image-on-top \
632 --icon="$icon" \
633 --text="<b>$(_n 'Create a new file or folder on your desktop')</b>" \
634 --entry --entry-label="$(_n 'File name')" \
635 --ricon='edit-clear' \
636 --always-print-result \
637 --button="$(_n 'SHell script')!application-x-shellscript:4" \
638 --button="$(_n 'Folder')!folder:3" \
639 --button="$(_n 'File')!empty:2" \
640 --button='gtk-cancel:1'
641 }
644 newfile() {
645 file=$(newfile_main)
646 ret=$?
647 [ -z "$file" ] && exit 0
648 case $ret in
649 4)
650 cat > "$HOME/Desktop/$file" << EOT
651 #!/bin/sh
652 #
654 EOT
655 chmod +x "$HOME/Desktop/$file" ;;
656 3) mkdir -p "$HOME/Desktop/$file" ;;
657 2) touch "$HOME/Desktop/$file" ;;
658 1) exit 0 ;;
659 esac
660 }
663 # All applications
665 all_apps() {
666 icon='user-bookmarks'
667 yad --title="$(_n 'All Applications')" --window-icon="$icon" \
668 --width='400' --height='400' \
669 --icons --compact \
670 --read-dir='/usr/share/applications' \
671 --button='gtk-close:0'
672 }
675 # Ask root permissions for system settings
677 ask_root() {
678 if [ "$(id -u)" -ne 0 ]; then
679 exec tazbox su $0 $@
680 exit 0
681 fi
682 }
685 vnc_main() {
686 icon='video-display'
687 yad --title="$(_n 'Framebuffer VNC viewer')" --window-icon="$icon" \
688 --width='250' --height='160' --on-top --center \
689 --image="$icon" --image-on-top --icon="$icon" \
690 --form \
691 --text="<b>$(_n 'Remote display connection')</b>" "localhost 5900" \
692 --field="$(_n 'VNC Server')" \
693 --field="$(_n 'Via a SSH tunnel'):CHK" \
694 --always-print-result \
695 --button="$(_n 'On this console'):1" \
696 --button="$(_n 'In a new console'):0"
697 }
700 ssh_main() {
701 icon='xterm'
702 yad --title="$(_n 'SSH connection')" --window-icon="$icon" \
703 --width='250' --height='180' --on-top --center \
704 --image="$icon" --image-on-top --icon="$icon" \
705 --form \
706 --text="<b>$(_n 'Remote terminal connection')</b>" "user@host" \
707 --field="$(_n 'SSH Server')" \
708 --field="$(_n 'Password'):H" \
709 --field="$(_n 'Prefer sakura'):CHK" \
710 --always-print-result
711 }
714 video() {
715 icon='video-x-generic'
717 # Get switchs
718 tazwebargs="--notoolbar"
719 while true ; do
720 case "$1" in
721 --fullscreen) tazwebargs="$tazwebargs --kiosk"
722 dpmstimeout=$(xset q | grep timeout | cut -d' ' -f5) ;;
723 --loop) loop="loop" ;;
724 *) break
725 esac
726 shift
727 done
729 # Get filename
730 [ "$1" ] && file="$PWD/$(basename "$1")"
731 [ "${1:0:1}" == "/" ] && file="$1"
732 [ -s "$file" ] || file="$(yad --file --width='600' --height='500' --add-preview \
733 --window-icon $icon --title "$(_ 'Select the video file')" --center \
734 --file-filter="$(_ 'All video files')|*.mp4 *.m4v *.webm *.ogg *.ogv *.flv *.avi *.3gp" \
735 --file-filter="$(_ 'All files')|*")"
736 [ -s "$file" ] || return
738 # Extra parameters
739 text=
740 attr='autoplay="true"'
741 for i in jpg jpeg ; do
742 [ -s "${file%.*}.$i" ] &&
743 attr="poster=\"file://${file%.*}.$i\"" && break
744 done
745 IFS=$'\n'
746 for i in ${file%.*}_${LANG%%[._]*}.vtt ${file%.*}.vtt ; do
747 [ -s $i ] && text="
748 <track kind=\"captions\" src=\"file://$i\" srclang=\"${LANG%%[._]*}\" default>"
749 done
751 # Build the html5 page
752 tmp=/tmp/video-player-$$.html
753 cat > $tmp <<EOT
754 <html>
755 <head>
756 <meta charset="UTF-8">
757 <title>$(basename "$file")</title>
758 <style>
759 body{background:#000;margin:0}
760 a{color:#29F}
761 div{color:#FFF;position:absolute;bottom:2em;left:0;right:0;text-align:center}
762 </style>
763 </head>
764 <body>
765 <video width="100%" height="100%" src="file://$file" controls $attr$loop>$text
766 <div>$(_ 'Unsupported video file format.')<br>
767 $(IFS=$'\n'; _ 'Retry with %s, %s, %s, %s, %s or %s.' \
768 $(printf '<a href="http://127.0.0.1:82/user/pkgs.cgi?info=%s">%s</a>\n' \
769 vlc VLC gnome-mplayer 'GNOME MPlayer' mplayer MPlayer gxine gxine xine-ui xine ffplay ffplay))
770 </div>
771 </video>
772 </body>
773 </html>
774 EOT
775 unset IFS
776 [ -n "$dpmstimeout" ] && xset dpms 0 0 0 s 0 0
777 tazweb $tazwebargs file://$tmp || browser file://$tmp
778 [ -n "$dpmstimeout" ] && xset dpms $dpmstimeout $dpmstimeout $dpmstimeout s $dpmstimeout $dpmstimeout
779 rm -f $tmp
780 }
783 newvt()
784 {
785 ask_root newvt $@ || return
786 openvt -sw $@
787 deallocvt
788 }
791 vnc() {
792 server=$(vnc_main)
793 status=$?
794 # Deal with --button values
795 [ "$server" ] || return
796 case "$server" in
797 *TRUE\|) fbvnc=sshfbvnc ;;
798 *) fbvnc=fbvnc ;;
799 esac
800 case "$status" in
801 1) $fbvnc ${server%%|*} ;;
802 0) newvt $fbvnc ${server%%|*} ;;
803 esac
804 }
807 ssh() {
808 IFS='|'; set -- $(ssh_main) ; unset IFS
809 [ "$3" == "TRUE" ] && export TERM=sakura
810 [ -n "$2" ] && export DROPBEAR_PASSWORD="$2"
811 sshx $1
812 }
815 #
816 # Commands
817 #
819 case "$1" in
820 su)
821 shift
822 # Don't show dialog if we are root
823 [ "$(id -u)" -eq 0 ] && exec "$@"
824 SU_CMD="$@"
825 SUBOX_CONF="$HOME/.config/slitaz/subox.conf"
827 # Check if a password has been saved before launching main dialog
828 if [ -s "$SUBOX_CONF" ]; then
829 PASSWD="$(cat $SUBOX_CONF)"
830 CHECKED='TRUE'
831 fi
833 # Display the main dialog (ask for password)
834 main="$(su_main "$SU_CMD")"
836 # Deal with --button values and exit if cancelled to avoid erasing
837 # saved password.
838 [ "$?" -eq 1 ] && exit 0
840 # Save or erase Autosaved password
841 if [ $(echo "$main" | cut -d"|" -f2) == 'TRUE' ]; then
842 echo "$main" | cut -d"|" -f1 > $SUBOX_CONF
843 chmod 0600 $SUBOX_CONF
844 else
845 cat /dev/null > $SUBOX_CONF
846 fi
848 # Try to login & execute. If password is wrong execute error dialog
849 SU_CMD_QUOTED="$(echo "$SU_CMD" | sed 's|&|\\&|g')"
850 echo $main | cut -d"|" -f1 | su -c "$SU_CMD_QUOTED &" || su_error
851 ;;
853 logout)
854 # Logout window with actions
855 if [ -n "$2" ]; then
856 answer="$2"
857 logout_confirm $answer
858 else
859 logout_main; answer=$?
860 fi
862 # Deal with --button values
863 # DE and WM started with a custom -session script should export
864 # XDG_CURRENT_DESKTOP
865 case $answer in
866 4|exit)
867 case $XDG_CURRENT_DESKTOP in
868 LXDE)
869 [ -n "$_LXSESSION_PID" ] && kill $_LXSESSION_PID
870 [ "$DESKTOP_SESSION" == 'compiz' ] && killall compiz
871 openbox --exit ;;
872 openbox) openbox --exit ;;
873 compiz) killall compiz ;;
874 *)
875 # Try to kill other WM that dont set XDG var.
876 jwm -exit 2>/dev/null ;;
877 esac ;;
878 3|reboot)
879 reboot || reboot -f ;;
880 2|halt)
881 poweroff ;;
882 esac
883 ;;
885 out)
886 # Pipe a command into a GTK window
887 sed 's|\[.m||g; s|\[[0-9][0-9]*G| |g' | output_command
888 ;;
890 out-dl)
891 # A tiny GTK window for Busybox wget output
892 url="$2"; opts='--tail --button=gtk-cancel:1'
893 icon='folder-download'; title="$(_ 'Downloading...')"
894 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
895 busybox wget -c -P $DOWNLOADS $url 2>&1 | output_command
896 cancel_dl
897 ;;
899 locale)
900 ask_root $@ && locale
901 ;;
903 keymap)
904 ask_root $@ && keymap
905 ;;
907 tz)
908 ask_root $@ && tz
909 ;;
911 manage_i18n)
912 ask_root $@ && manage_i18n $2
913 ;;
915 recharge)
916 ask_root $@; opts='--on-top'; output=raw tazpkg recharge | output_command
917 ;;
919 setup)
920 ask_root $@ && setup
921 ;;
923 new-file)
924 newfile
925 ;;
927 all-apps)
928 all_apps
929 ;;
931 notify|-n)
932 # On screen notification box.
933 icon="$3"
934 time="$4"
935 [ -z "$icon" ] && icon='dialog-information'
936 [ -z "$time" ] && time='4'
937 yad --width='520' --height='80' --timeout="$time" --timeout-indicator='right' \
938 --on-top --center --no-buttons --borders='12' --undecorated \
939 --skip-taskbar --image="$icon" --image-on-top --text="<b>$2</b>"
940 ;;
942 tazapps)
943 # Default applications configuration script. System wide config file
944 # is /etc/slitaz/applications.conf and each user can have personal
945 # settings. System wide for root and personal config for user.
946 export CONFIG="$HOME/.config/slitaz/applications.conf"
947 if [ "$(id -u)" -eq 0 ]; then
948 [ ! -f $CONFIG ] || mv -f $CONFIG /etc/slitaz/applications.conf
949 export CONFIG='/etc/slitaz/applications.conf'
950 fi
952 for a in FILE_MANAGERS BROWSERS EDITORS TERMINALS WINDOW_MANAGERS; do
953 eval $(expr $a=$(echo $(LC_ALL=C tazx get-applist ${a%%S} \
954 only-installed yad) | sed 's/ /!/g ; s/!!//g; s/ //g'))
955 done
957 # Missing file was created by slitaz_apps_conf function from tazx
958 . $CONFIG
960 icon='preferences-desktop-default-applications'
961 eval $(yad --title="$(_n 'SliTaz default applications')" \
962 --window-icon="$icon" --image="$icon" --image-on-top \
963 --text="<b>$(_n 'SliTaz default applications configuration')</b>" \
964 --form \
965 --field="$(_n 'File manager:'):CBE" "$FILE_MANAGERS" \
966 --field="$(_n 'Web browser:'):CBE" "$BROWSERS" \
967 --field="$(_n 'Text editor:'):CBE" "$EDITORS" \
968 --field="$(_n 'Terminal:'):CBE" "$TERMINALS" \
969 --field="$(_n 'Window manager:'):CBE" "$WINDOW_MANAGERS" | \
970 awk -F'|' '{printf "FILE_MANAGER=\"%s\"\nBROWSER=\"%s\"\nEDITOR=\"%s\"\
971 TERMINAL=\"%s\"\nWINDOW_MANAGER=\"%s\"\n", $1, $2, $3, $4, $5}')
973 sed '/FILE_MANAGER=/s|"\([^"]*\)"|"'$FILE_MANAGER'"|; \
974 /BROWSER=/s|"\([^"]*\)"|"'$BROWSER'"|; \
975 /EDITOR=/s|"\([^"]*\)"|"'$EDITOR'"|; \
976 /TERMINAL=/s|"\([^"]*\)"|"'$TERMINAL'"|; \
977 /WINDOW_MANAGER=/s|"\([^"]*\)"|"'$WINDOW_MANAGER'"|' \
978 -i $CONFIG
979 ;;
981 gpl)
982 yad --title='GNU General Public License' --window-icon='text-x-copying' \
983 --geometry='650x500' \
984 --image='/usr/share/pixmaps/gpl3.png' --image-on-top \
985 --center \
986 --text-info \
987 --fontname='monospace' \
988 --button 'OK' < /usr/share/licenses/gpl.txt
989 ;;
991 ssh)
992 ssh
993 ;;
995 vnc)
996 vnc
997 ;;
999 video)
1000 shift
1001 video "$@"
1002 ;;
1004 newvt)
1005 $@
1006 ;;
1008 mkmenu) $@ ;;
1010 *)
1011 usage
1012 ;;
1013 esac
1015 exit 0