tazpkg diff tazpkg-notify @ rev 925

Add de.po (thanks HGT)
author Paul Issott <paul@slitaz.org>
date Fri Sep 23 21:27:01 2016 +0100 (2016-09-23)
parents 688494ca8f5f
children 50421cb50644
line diff
     1.1 --- a/tazpkg-notify	Mon Nov 23 04:52:58 2015 +0200
     1.2 +++ b/tazpkg-notify	Fri Sep 23 21:27:01 2016 +0100
     1.3 @@ -21,7 +21,9 @@
     1.4  
     1.5  fifo=/tmp/$(basename $0).fifo
     1.6  doc="file:///usr/share/doc/tazpkg/tazpkg.html"
     1.7 -tp='http://127.0.0.1:82/user/pkgs.cgi'
     1.8 +alias notify=/usr/libexec/tazpkg-notification
     1.9 +cmd_recharge='tazbox su tazpanel pkgs#recharge'
    1.10 +cmd_up='tazbox su tazpanel pkgs#up'
    1.11  
    1.12  installed=$(wc -l < "$PKGS_DB/installed.info")
    1.13  text="$(_p \
    1.14 @@ -33,50 +35,16 @@
    1.15  up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(wc -l < "$PKGS_DB/packages.up")
    1.16  
    1.17  
    1.18 -# Standard notification, if available
    1.19 -
    1.20 -notify() {
    1.21 -	if [ -n "$(which notify-send)" ]; then
    1.22 -		case $2 in
    1.23 -			info) icon='dialog-information'; urgency='normal';;
    1.24 -			*)    icon='dialog-warning';     urgency='critical';;
    1.25 -		esac
    1.26 -		notify-send -i $icon -u $urgency 'TazPkg' "$1" &
    1.27 -	fi
    1.28 +set_yad_action() {
    1.29 +	echo -e "action:$1\ntooltip:$2\nicon:software-update-urgent" > $fifo
    1.30  }
    1.31  
    1.32  
    1.33 -# Notification icon
    1.34 -
    1.35 -listen() {
    1.36 -	# Manage the I/O redirection from SHell
    1.37 -	rm -f $fifo; mkfifo $fifo
    1.38 -
    1.39 -	# Attach a file descriptor
    1.40 -	exec 3<> $fifo
    1.41 -
    1.42 -	# Notification icon
    1.43 -	tooltip="$(_ 'Checking packages lists - %s' "$text")"
    1.44 -	notify "$tooltip" 'info' &
    1.45 -	yad --notification --listen --image='software-update-available' --text="$tooltip" <&3
    1.46 -
    1.47 +quit() {
    1.48 +	echo "quit" > $fifo
    1.49  	# Clean-up
    1.50  	rm -f $fifo
    1.51 -}
    1.52 -
    1.53 -
    1.54 -# Notification menu (right click)
    1.55 -
    1.56 -menu() {
    1.57 -	cat << EOT
    1.58 -menu:\
    1.59 -$(_n 'My packages'       )!tazpanel pkgs#list!package-x-generic|\
    1.60 -$(_n 'Recharge lists'    )!tazbox su tazpanel pkgs#recharge!system-software-update|\
    1.61 -$(_n 'Check upgrade'     )!tazbox su tazpanel pkgs#up!system-software-install|\
    1.62 -$(_n 'TazPkg SHell'      )!terminal -e tazpkg shell!utilities-terminal|\
    1.63 -$(_n 'TazPkg manual'     )!tazweb --notoolbar $doc!slitaz-doc|\
    1.64 -$(_n 'Close notification')!quit!gtk-close
    1.65 -EOT
    1.66 +	exit 0
    1.67  }
    1.68  
    1.69  
    1.70 @@ -85,33 +53,40 @@
    1.71  		_n "Usage:"; echo " $(basename $0)"
    1.72  		;;
    1.73  	*)
    1.74 -		# Sleep before displaying the notification icon and
    1.75 -		# sleep to let user read the tooltips.
    1.76 +		# Sleep before displaying the notification icon
    1.77  		sleep 4
    1.78 -		listen &
    1.79 -		sleep 2
    1.80 -		menu > $fifo
    1.81 -		sleep 6
    1.82 +		# Manage the I/O redirection from shell
    1.83 +		rm -f $fifo; mkfifo $fifo
    1.84 +		# Attach a file descriptor
    1.85 +		exec 3<> $fifo
    1.86 +		# Notification icon
    1.87 +		yad --notification --listen --image='software-update-available' <&3 &
    1.88 +
    1.89 +		# Notification menu (right click)
    1.90 +		cat > $fifo << EOT
    1.91 +menu:\
    1.92 +$(_n 'My packages'       )!tazpanel pkgs#list!package-x-generic|\
    1.93 +$(_n 'Recharge lists'    )!$cmd_recharge!system-software-update|\
    1.94 +$(_n 'Check upgrade'     )!$cmd_up!system-software-install|\
    1.95 +$(_n 'TazPkg SHell'      )!terminal -e tazpkg shell!utilities-terminal|\
    1.96 +$(_n 'TazPkg manual'     )!tazweb --notoolbar $doc!slitaz-doc|\
    1.97 +$(_n 'Close notification')!quit!gtk-close
    1.98 +EOT
    1.99  
   1.100  		# Missing packages list
   1.101  		if [ ! -f "$PKGS_DB/packages.info" ]; then
   1.102 -			tooltip="$(_ 'No packages list found - %s' "$text")"
   1.103 -			notify "$tooltip\n<a href=\"$tp?recharge\">$(_n 'Recharge lists')</a>" &
   1.104 -			(echo "action:tazbox su tazpanel pkgs#recharge"
   1.105 -			 echo "tooltip:$tooltip"
   1.106 -			 echo "icon:software-update-urgent") > $fifo
   1.107 -			exit 0
   1.108 +			tooltip="$(_ 'No packages list found')"
   1.109 +			set_yad_action "$cmd_recharge" "$tooltip"
   1.110 +			[ "$(notify "$tooltip" '1' "$(_n 'Recharge lists')")" == '1' ] && $cmd_recharge
   1.111 +			quit
   1.112  		fi
   1.113  
   1.114  		# Too old packages list
   1.115  		if [ -n "$mtime" ]; then
   1.116  			tooltip="$(_ 'Your packages list is older than 10 days')"
   1.117 -			notify "$tooltip\n<a href=\"$tp?recharge\">$(_n 'Recharge lists')</a>" &
   1.118 -			(echo "action:tazbox su tazpanel pkgs#recharge"
   1.119 -			 echo "action:quit"
   1.120 -			 echo "tooltip:$tooltip"
   1.121 -			 echo "icon:software-update-urgent") > $fifo
   1.122 -			exit 0
   1.123 +			set_yad_action "$cmd_recharge" "$tooltip"
   1.124 +			[ "$(notify "$tooltip" '1' "$(_n 'Recharge lists')")" == '1' ] && $cmd_recharge
   1.125 +			quit
   1.126  		fi
   1.127  
   1.128  		# Available upgrades
   1.129 @@ -120,19 +95,21 @@
   1.130  				'There is %s upgradeable package' \
   1.131  				'There are %s upgradeable packages' "$up" \
   1.132  				"<b>$up</b>")"
   1.133 -			notify "$tooltip\n<a href=\"$tp?up\">$(_n 'Check upgrade')</a>" &
   1.134 -			(echo "action:tazbox su tazpanel pkgs#up"
   1.135 -			 echo "tooltip:$tooltip"
   1.136 -			 echo "icon:software-update-urgent") > $fifo
   1.137 -			exit 0
   1.138 +			set_yad_action "$cmd_up" "$tooltip"
   1.139 +			[ "$(notify "$tooltip" '1' "$(_n 'Check upgrade')")" == '1' ] && $cmd_up
   1.140 +			quit
   1.141  		fi
   1.142  
   1.143  		# Nothing to do, close notification
   1.144 -		tooltip="$(_ 'System is up to date - %s' "$text")"
   1.145 -		notify "$tooltip" 'info' &
   1.146 -		echo "tooltip:$tooltip" > $fifo
   1.147 +		tooltip="$(_ 'System is up to date')"
   1.148 +		echo "tooltip:$tooltip\n$text" > $fifo
   1.149 +		answer=$(notify "$tooltip"$'\n'"$text" '0' "$(_n 'Recharge lists')" "$(_n 'Check upgrade')")
   1.150 +		case "$answer" in
   1.151 +			1) $cmd_recharge;;
   1.152 +			2) $cmd_up;;
   1.153 +		esac
   1.154  		sleep 10
   1.155 -		echo "quit" > $fifo
   1.156 +		quit
   1.157  		;;
   1.158  esac
   1.159 -exit 0
   1.160 +quit