Example of interprocess communication between KDE applications

This is a stupid toy that explains inter-process communication (IPC) in KDE, using dcop (Desktop COmmunications Protocol) in KDE3, now replaced with qdbus (dbus-daemon Inter-process Communication‎) in KDE4.

Here both examples and how to switch between kde3 and kde4.

LinVir.sh for KDE3:

#!/bin/bash
 
DATA=`echo $'\127\151\156\144\157\167\163'`
 
echo "LinVir begin"
 
kdialog --msgbox "Welcome to LinVir: the first antivirus for Linux! Click to OK to begin the search for viruses" --title "LinVir"
dcopRef=`kdialog --progressbar "Initialising ..." 4`
sleep 1.5
dcop $dcopRef setProgress 1
dcop $dcopRef setLabel "Scanning disks ..."
sleep 2
dcop $dcopRef setProgress 2
sleep 2
dcop $dcopRef setLabel "1 found | ending search"
dcop $dcopRef setProgress 3
sleep 2
dcop $dcopRef setProgress 4
sleep 2
dcop $dcopRef close
kdialog --sorry "Infected partition found. Click to OK to fix YOUR problem." -title "LinVir"
dcopRef=`kdialog --progressbar "Formatting partiton of $DATA(TM)" 4`
sleep 3
dcop $dcopRef setProgress 1
dcop $dcopRef setLabel "Deleting files, wait ..."
sleep 2.5
dcop $dcopRef setProgress 2
sleep 2
dcop $dcopRef setLabel "I'm overwriting 35 times random files on the infected partition to prevent recovery of it."
dcop $dcopRef setProgress 3
sleep 5.5
dcop $dcopRef setProgress 4
sleep 0.3
dcop $dcopRef setLabel "Final cleaning ..."
dcop $dcopRef setProgress 5
sleep 2
dcop $dcopRef close
kdialog --msgbox "Congratulations! Elimination of the partition $DATA(TM) made successfully!" --title "LinVir"

from kde3:

dcop $dcopRef setProgress 1
dcop $dcopRef setLabel "Scanning disks ..."

to kde4:

qdbus $qdbusRef Set "" value 1
qdbus $qdbusRef setLabelText "Scanning disks ..."

LinVir.sh for KDE4:

#!/bin/bash
 
DATA=`echo $'\127\151\156\144\157\167\163'`
 
echo "LinVir begin"
 
kdialog --msgbox "Welcome to LinVir: the first antivirus for Linux! Click to OK to begin the search for viruses" --title "LinVir"
qdbusRef=`kdialog --progressbar "Initialising ..." 4`
sleep 1.5
qdbus $qdbusRef Set "" value 1
qdbus $qdbusRef setLabelText "Scanning disks ..."
sleep 2
qdbus $qdbusRef Set "" value 2
sleep 2
qdbus $qdbusRef setLabelText "1 found | ending search"
qdbus $qdbusRef Set "" value 3
sleep 2
qdbus $qdbusRef Set "" value 4
sleep 2
qdbus $qdbusRef close
kdialog --sorry "Infected partition found. Click to OK to fix YOUR problem." -title "LinVir"
qdbusRef=`kdialog --progressbar "Formatting partiton of $DATA(TM)" 4`
sleep 3
qdbus $qdbusRef Set "" value 1
qdbus $qdbusRef setLabelText "Deleting files, wait ..."
sleep 2.5
qdbus $qdbusRef Set "" value 2
sleep 2
qdbus $qdbusRef setLabelText "I'm overwriting 35 times random files on the infected partition to prevent recovery of it."
qdbus $qdbusRef Set "" value 3
sleep 5.5
qdbus $qdbusRef Set "" value 4
sleep 0.3
qdbus $qdbusRef setLabelText "Final cleaning ..."
qdbus $qdbusRef Set "" value 5
sleep 2
qdbus $qdbusRef close
kdialog --msgbox "Congratulations! Elimination of the partition $DATA(TM) made successfully!" --title "LinVir"

Retrieved from "http://www.zoros.org/wiki/index.php?title=An_example_that_explains_inter-process_communication_in_KDE"