This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KDialog progress bar implementation

Tags: None
(comma "," separated)
User avatar
sadi
Registered Member
Posts
24
Karma
0
OS

KDialog progress bar implementation

Fri Jul 09, 2021 10:28 am
I'm trying to use kdialog progress bar in a script but it seems my elementary scripting skills are failing me.
I would settle for a pulsating progress bar as in zenity which is much easier to implement, but unfortunately it seems KDialog doesn't have this feature.
I would appreciate any help in getting this work properly.

Code: Select all
#!/usr/bin/env bash
#DEPENDS: speedtest-cli
progress=$(kdialog --title "Internet Speed Test" --progressbar "Checking internet connection...");
qdbus $progress Set "" maximum 4 > /dev/null;
connection="$(ping -W 2 -c 1 google.com | grep -c "statistics")"
if [[ "$connection" -gt 0 ]]; then
   qdbus $progress Set "" value 1 > /dev/null;
   qdbus $progress setLabelText "Connection confirmed, starting speed tests..." > /dev/null;
   tmpfile="$(mktemp -t speedtest.XXXXXX)"
   qdbus $progress Set "" value 2 > /dev/null;
   qdbus $progress setLabelText "Running speed tests..." > /dev/null;
   speedtest-cli > "$tmpfile"
   qdbus $progress Set "" value 3 > /dev/null;
   qdbus $progress setLabelText "Acquiring test results..." > /dev/null;
   if [[ -z "$tmpfile" ]]; then
      qdbus $progress Set "" value 4 > /dev/null;
      qdbus $progress setLabelText "Network Error!" > /dev/null;
      qdbus $progress close > /dev/null;
   else
      qdbus $progress Set "" value 4 > /dev/null;
      qdbus $progress setLabelText "Tests completed!" > /dev/null;
      qdbus $progress close > /dev/null;
      source="$(grep "Testing from " < "$tmpfile" | sed -e "s/&/&amp;/g" | sed -e "s/Testing from //g" -e "s/\.\.\.//g")"
      target="$(grep "Hosted by " < "$tmpfile" | sed -e "s/&/&amp;/g" | sed -e "s/Hosted by //g" -e "s/: .\+$//g")"
      ping="$(grep "Hosted by " < "$tmpfile" |  awk -F ": " '{print $2}')"
      download="$(grep "Download: " < "$tmpfile" | sed -e "s/Download: //g")"
      upload="$(grep "Upload: " < "$tmpfile" | sed -e "s/Upload: //g")"
      kdialog --title "Internet Speed Test Results" --msgbox "<br>Source: <b>$source</b><br>Target: <b>$target</b><br>Ping: <b>$ping</b><br>Download: <b>$download</b><br>Upload: <b>$upload</b>"
      rm -f "$tmpfile"
   fi
else
   qdbus $progress Set "" value 4 > /dev/null;
   qdbus $progress setLabelText "No Internet Connection!" > /dev/null;
   qdbus $progress close > /dev/null;
fi


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]