#!/usr/bin/perl
#----------------------------------------------------------------------#
# X11::GUITest (kphone_accept.pl; v1.1, 22 February  2007)
# Notes: Automatically reject kphone calls by pressing the Accept
# 	button on the incoming call dialog
#
# 	KDE 3.5 with prevent focus stealing disabled
# 	KPhone version 4.2.2
# 	X11-GUITest 0.21
#----------------------------------------------------------------------#

use strict;
use warnings;

use X11::GUITest qw/
	WaitWindowViewable
	SendKeys
	SetEventSendDelay
	SetKeySendDelay
	RaiseWindow
	SetInputFocus
/;

my @MainWin = 0;

print "$0: Script start.\n";

# Slow event sending down a little for when X server
# is busy with this and other bigger applications
SetEventSendDelay(50);
SetKeySendDelay(50);

# Wait at most 120 seconds for it to come up
(@MainWin) = WaitWindowViewable('Incoming Call:', undef, 120) or die('Could not find incoming call window!');

print "Incoming call received, rejecting call...\n";
foreach my $MainWin (@MainWin) {
        RaiseWindow($MainWin);
	SetInputFocus($MainWin);
	SendKeys('{SPC}');
}

#SendKeys('+({TAB}){SPC}');

print "$0: Script end (success).\n";

