#!/usr/bin/perl

# (C) Till Kamppeter - Code under GPL (www.gnu.org).

# Easy starting of xojpanel with auto-detection of available devices.

# Read the HPOJ config directory and search for configured devices. Check
# whether they have a display and start "xojpanel" for the devices
# with display.

if (open HPOJCONFIG, ("ls -1 /etc/ptal |")) {
    while (my $line = <HPOJCONFIG>) {
	chomp $line;
	my $ptaldevice = $line;
	# Has the device a display? Check it by trying to read it with
	# the command line tool
	open LCD, ("ptal-hp $ptaldevice display 2>&1 |") or next;
	my $lcdcontent = join('', <LCD>);
	close LCD;
	next if ($lcdcontent =~ /^\s*\(unavailable\)\s*$/m);
	# Start xojpanel for this device
	system("xojpanel $ptaldevice >/dev/null 2>&1 &");
    }
    close HPOJCONFIG;
}
