4

I'm trying to port this code from wget + zenity to wget + kdialog.
The code with zenity:

#!/bin/bash

# Start wget | zenity
# Note the & at the end of the pipe, this allows the script to continue with wget running in the background

wget http://www.zezeniaonline.com/download/downloadlinux 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --title="Downloading File..." 

#Start a loop testing if zenity is running, and if not kill wget
RUNNING=0
while [ $RUNNING -eq 0 ]
do
if [ -z "$(pidof zenity)" ]
then
  pkill wget
  RUNNING=1
fi
done

The Zenity Code Works perfectly

Zenity + Wget Download Progress

I need to do the same but with kdialog. I'm tried first with the follow code:

#!/bin/bash

# Start wget | kdialog

wget http://www.zezeniaonline.com/download/downloadlinux 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | kdialog --progressbar " " --title="Downloading File..." 

#Start a loop testing if zenity is running, and if not kill wget
RUNNING=0
while [ $RUNNING -eq 0 ]
do
if [ -z "$(pidof kdialog)" ]
then
  pkill wget
  RUNNING=1
fi
done

that don't work at all

#!/bin/bash 
# Start wget | kdialog

wget --progress=dot http://www.zezeniaonline.com/download/downloadlinux 2>&1 | fgrep --line-buffered '%' \ | sed -u -r 's:.* ([0-9]+)% .*:\1:' | kdialog --title "Installation" --progressbar " " &

#Start a loop testing if kdialog is running, and if not kill wget
RUNNING=0
while [ $RUNNING -eq 0 ]
do
if [ -z "$(pidof kdialog)" ]
then
  pkill wget
  RUNNING=1
fi
done

But the follow errors. Yes its downloading, but the "progress" are not "progressing" in the "kdialog"

KDialog are not progressing

  • I found this sites 1 2 I hope some of that codes works for me – inukaze Nov 22 '14 at 4:37
  • 1
    If you found a solution, could you please post it as an answer instead of in the question? – muru Dec 4 '14 at 9:09
  • Yes , man , that its the idea , share the solution , for the users need that information , and in case i need saw the info again XD . – inukaze Dec 5 '14 at 3:27
  • @muru : see my answer , that code works , with kdialog. – inukaze Dec 5 '14 at 5:14
1

Here there is my own solution, I have modified a little my old tutorial on my website linked on this page:

this code will try to download my master repository on github

    link="https://github.com/nowardev/kde-peace-settings/archive/master.zip" #my own github stuff 
    a=$(kdialog --progressbar "W-Get will  download: Nowardev GitHub Master stuff " 100);sleep 2
    qdbus $a  showCancelButton true

    while read line ;do
    read -r p t <<< "$line"
    echo $p 
    echo $t 
    qdbus $a Set org.kde.kdialog.ProgressDialog value $p

        while [[  $(qdbus  $a wasCancelled) != "false" ]] ; do
            echo "KILLING THE PROCESS AND KDIALOG"
            qdbus $a  org.kde.kdialog.ProgressDialog.close 

            exit
        done


qdbus $a org.kde.kdialog.ProgressDialog.setLabelText "W-Get will  download: Nowardev GitHub Master stuff  time left : $t" 


done< <(wget "$link" 2>&1 |mawk -W interactive '{ gsub(/\%/," "); print int($7)" "$9 }')
2

Im trying to adapt that source code , this code works , well i just need adapt the parts i really need.

#!/bin/bash

kde_download() {
arch=$(uname -m)

case "$arch" in
    x86)    arch="x86"  ;;
    i?86)   arch="x86"  ;;
    amd64)  arch="amd64"    ;;
    x86_64) arch="amd64"    ;;
    * ) echo "Your Arch '$arch' -> Its not supported."  ;;
esac

ThisDIR="$PWD"
TempDir="/tmp"
TITLE="Team Speak 3 Linux Client"
TS3DIR="/opt/TeamSpeak3/Client"
version=$(curl -s http://dl.4players.de/ts/releases/ |   grep -Po '(?<=href=")[0-9]+(\.[0-9]+){2,3}(?=/")' |   sort -Vr | head -1)
URLICON="https://dl.dropboxusercontent.com/u/3164499/Linux/Iconos/TeamSpeak3.png"
TS3FILE="TeamSpeak3-Client-linux_$arch-$version.run"
TS3CURL="http://dl.4players.de/ts/releases/$version"
TS3CF="http://dl.4players.de/ts/releases/$version/TeamSpeak3-Client-linux_$arch-$version.run"
TARGET="/opt/Utilidades/Prueba"
J=0

# download with output to dialog progress bar
KDIALOG="`kdialog --title "$TITLE" --progressbar "Downloading:<br>$TS3FILE<br>into<br>$TARGET"`"
if grep "^org.kde.kdialog" <<< "$KDIALOG" > /dev/null; then


# KDE4 kdialog and dbus control
autoclose="qdbus $KDIALOG org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog autoClose true"
showcancel="qdbus $KDIALOG org.kde.kdialog.ProgressDialog.showCancelButton false"
setprogress="qdbus $KDIALOG org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value"
manualclose="qdbus $KDIALOG org.kde.kdialog.ProgressDialog.close"
wascancelled="qdbus $KDIALOG org.kde.kdialog.ProgressDialog.wasCancelled"


else
# KDE3 kdialog and dcop control
# cut beginning
KDIALOG="${KDIALOG//DCOPRef\(/}"
# cut end
KDIALOG="${KDIALOG//,ProgressDialog\)/}"
autoclose="dcop $KDIALOG ProgressDialog setAutoClose true"
setprogress="dcop $KDIALOG ProgressDialog setProgress"
showcancel="dcop $KDIALOG ProgressDialog showCancelButton false"
manualclose="dcop $KDIALOG ProgressDialog close"
wascancelled="dcop $KDIALOG ProgressDialog wasCancelled"
fi
    $autoclose
    $showcancel
    cd "$TempDir"
    ( wget "$TS3CF" -o /dev/stdout | while read I ; do
    I="${I//*.......... .......... .......... .......... .......... /}"
    I="${I%%%*}"

    # report changes only
    if [ "$I" ] && [ "$J" != "$I" ]; then
    $setprogress $I
    J="$I"
    fi
    done ; $manualclose ; cd "$ThisDIR" ) &

pid="$!"

while [ -d "/proc/$pid/" ]; do
    if [ "`$wascancelled`" = true ]; then
    kill $pid
    kill `ps aux | grep "wget $TS3FILE -o /dev/stdout" | grep -v grep | tr -s ' ' ' ' | cut -f2 -d\ `
    $manualclose
        if [ "$?" != 0 ]; then
        echo "Installation interrupted."
        exit 255
        fi
    fi
sleep 1
done
wait
}

kde_download

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.