# HG changeset patch # User Christophe Lincoln # Date 1330697411 -3600 # Node ID b52c1a1105e20553d8e1aec5d5437391799e77ca # Parent ab830ecf3a8a9ad2412cf1489d543fd79dc5bb46 new tazpkg-notify, use notification menu and autoclose if nothing to do diff -r ab830ecf3a8a -r b52c1a1105e2 tazpkg-notify --- a/tazpkg-notify Fri Mar 02 11:21:19 2012 +0100 +++ b/tazpkg-notify Fri Mar 02 15:10:11 2012 +0100 @@ -12,183 +12,84 @@ # Authors : Christophe Lincoln # -. /etc/slitaz/tazpkg.conf -LOCALSTATE="/var/lib/tazpkg" - -# Include gettext helper script. +# I18n . /usr/bin/gettext.sh - -# Export package name for gettext. TEXTDOMAIN='tazpkg-notify' export TEXTDOMAIN -up=$(cat $LOCALSTATE/packages.up | wc -l) -rel=$(cat /etc/slitaz-release) +fifo=/tmp/$(basename $0).fifo +panel="http://tazpanel:82/pkgs.cgi" +db="/var/lib/tazpkg" +doc="/usr/share/doc/tazpkg/tazpkg.html" +installed=$(ls $db/installed | wc -l) +text="$(gettext "Installed packages") $installed" +[ -f "$db/packages.list" ] && mtime=$(find $db/packages.list -mtime +10;) +[ -f "$db/packages.up" ] && up=$(cat $db/packages.up | wc -l) -# Kill the notification icon after user pressed on it. -kill_notification() { - for p in `ps | grep "yad --notification" | awk '{print $1}'` - do - kill -9 $p 2>/dev/null - done +# Notification icon +listen() { + # Manage the I/O redirection from SHell + rm -f $fifo && mkfifo $fifo + # Attach a file descriptor + exec 3<> $fifo + # Notification icon + yad --notification --listen --image="tazpkg" \ + --text="Checking packages lists - $text" <&3 + # Clean-up + rm -f $fifo } -# Message for up -up_msg() { - eval_gettext "There are \$up upgradeable packages for your SliTaz \$rel -You should upgrade your system to get all the latest fixes -and improvements from the SliTaz contributors" +# Notication menu (right click) +menu() { + cat << EOT +menu:\ +$(gettext "My packages")!tazweb $panel?list!tazpkg|\ +$(gettext "Recharge lists")!tazweb $panel?recharge!tazpkg-up|\ +$(gettext "Check upgrade")!tazweb $panel?up!tazpkg-up|\ +$(gettext "TazPKG SHell")!terminal -e tazpkg shell!xterm|\ +$(gettext "TazPKG manual")!tazweb $doc!text-html|\ +$(gettext "Close notification")!quit!gtk-close +EOT } -# Message for list older than 10 days -old_list_msg() { - eval_gettext "Your SliTaz \$rel packages list is older than 10 days -You should recharge the list to check for updates" -} - -# Message if packages.list is missing -no_list_msg() { - eval_gettext "No packages list found on your SliTaz \$rel system -You will need to recharge the list of mirrored packages -if you want to install packages or upgrade your system" -} - -# -# Main GUI box for up packages -# -up_main() { - yad --text --width=400 \ - --geometry="$NOTIFY_GEOM" \ - --undecorated \ - --title="TazPKG Notification" \ - --image="tazpkg-up" \ - --image-on-top \ - --on-top \ - --text="`up_msg`" \ - --button="`gettext \"Upgrade:2\"`" \ - --button="gtk-close:1" -} - -# Notification icon for up packages -up_notify() { - yad --notification \ - --image=tazpkg \ - --text="`up_msg`" \ - --command="tazpkg-notify upgrade" -} - -# Main up function -up() { - # Store box results - main=`up_main` - ret=$? - kill_notification - # Deal with --button values - case $ret in - 1) exit 0 ;; - 2) tazweb http://tazpanel:82/pkgs.cgi?up & ;; - *) continue ;; - esac -} - -# -# Main GUI box for missing packages.list -# -old_list_main() { - yad --text --width=400 \ - --geometry="$NOTIFY_GEOM" \ - --undecorated \ - --title "TazPKG Notification" \ - --image="tazpkg-up" \ - --image-on-top \ - --on-top \ - --text "`old_list_msg`" \ - --button="`gettext \"Recharge now:2\"`" \ - --button="gtk-close:1" -} - -# Notification icon if no packages.list -old_list_notify() { - yad --notification \ - --image=tazpkg \ - --text="`old_list_msg`" \ - --command="tazpkg-notify no-list" -} - -# Main missing packages.list function -old_list() { - # Store box results - main=$(old_list_main) - ret=$? - kill_notification - # Deal with --button values - case $ret in - 1) exit 0 ;; - 2) tazweb http://tazpanel:82/pkgs.cgi?recharge & ;; - *) continue ;; - esac -} - -# -# Main GUI box for missing packages.list -# -no_list_main() { - yad --text --width=400 \ - --geometry="$NOTIFY_GEOM" \ - --undecorated \ - --show-uri \ - --title="TazPKG Notification" \ - --image="tazpkg-up" \ - --image-on-top \ - --on-top \ - --text "`no_list_msg`" \ - --button="`gettext \"Recharge now:2\"`" \ - --button="gtk-close:1" -} - -# Notification icon if no packages.list -no_list_notify() { - yad --notification \ - --image=tazpkg \ - --text="`no_list_msg`" \ - --command="tazpkg-notify no-list" -} - -# Main missing packages.list function -no_list() { - # Store box results - main=$(no_list_main) - ret=$? - kill_notification - # Deal with --button values - case $ret in - 1) exit 0 ;; - 2) tazweb http://tazpanel:82/pkgs.cgi?recharge & ;; - *) continue ;; - esac -} - -# -# Script commands -# - case $1 in - upgrade) - up ;; - old-list) - old_list ;; - no-list) - no_list ;; + usage|help|*-h) + gettext "Usage:"; echo " $(basename $0)" ;; *) - # Sleep first to let tazpkg upgrade on boot finish. Check if - # any upgrades, then for an old list and then if any lists at all - # (live or first boot) + # Sleep before displaying the notification icon and + # sleep to let user read the tooltips. + sleep 4 + listen & + sleep 2 + menu > $fifo + sleep 6 + # Missing packages list + if [ ! -f $db/packages.list ]; then + tooltip=$(eval_gettext \ + "No packages list found - \$text") + echo "action:tazweb $panel?recharge" > $fifo + echo "tooltip:$tooltip" > $fifo + echo "icon:tazpkg-up" > $fifo && exit 0 + fi + # Too old packages list + if [ "$mtime" ]; then + tooltip=$(gettext "Your packages list is older than 10 days") + echo "action:tazweb $panel?recharge" > $fifo + echo "tooltip:$tooltip" > $fifo + echo "icon:tazpkg-up" > $fifo && exit 0 + fi + # Avalaible upgrades + if [ "$up" -gt 0 ]; then + tooltip=$(eval_gettext \ + "There are \$up upgradeable packages") + echo "action:tazweb $panel?up" > $fifo + echo "tooltip:$tooltip" > $fifo + echo "icon:tazpkg-up" > $fifo && exit 0 + fi + # Nothing to do, close notification + tooltip=$(eval_gettext "System is up to date - \$text") + echo "tooltip:$tooltip" > $fifo sleep 10 - [ "$up" -gt 0 ] && up_notify && exit 0 - mtime=$(find /var/lib/tazpkg/packages.list -mtime +10;) - [ "$mtime" ] && old_list_notify && exit 0 - [ ! -f $LOCALSTATE/packages.list ] && no_list_notify \ - && exit 0 ;; + echo "quit" > $fifo ;; esac - -exit 0 +exit 0 diff -r ab830ecf3a8a -r b52c1a1105e2 tazpkg.conf --- a/tazpkg.conf Fri Mar 02 11:21:19 2012 +0100 +++ b/tazpkg.conf Fri Mar 02 15:10:11 2012 +0100 @@ -6,6 +6,3 @@ # Path to Tazpkg log file. LOG="/var/log/tazpkg.log" - -# The geometry of the desktop notification -NOTIFY_GEOM="360x80-0+24"