1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#!/usr/bin/perl
use strict;
use warnings;
use QtCore4;
use QtGui4;
sub method1
{
print "Method 1:\n";
my $reply = Qt::DBusConnection::sessionBus()->interface()->registeredServiceNames();
if ( !$reply->isValid ) {
print 'Error:' . $reply->message() . "\n";
exit 1;
}
foreach my $name ( @{$reply->value()} ) {
print "$name\n";
}
}
sub method2
{
print "Method 2:\n";
my $bus = Qt::DBusConnection::sessionBus();
my $dbus_iface = Qt::DBusInterface('org.freedesktop.DBus', '/org/freedesktop/DBus',
'org.freedesktop.DBus', $bus);
print
'("',
join( '", "', @{$dbus_iface->call('ListNames')->arguments()->[0]->value()} ),
"\")\n";
}
sub method3
{
print "Method 3:\n";
print
'("',
join( '", "', @{Qt::DBusConnection::sessionBus()->interface()->registeredServiceNames()->value()} ),
"\")\n";
}
sub main
{
my $app = Qt::CoreApplication(\@ARGV);
if (!Qt::DBusConnection::sessionBus()->isConnected()) {
print STDERR "Cannot connect to the D-Bus session bus.\n" .
"To start it, run:\n" .
"\teval \`dbus-launch --auto-syntax\`\n";
return 1;
}
method1();
method2();
method3();
return 0;
}
exit main();
|