~kubuntu-members/perlkde/4.11

« back to all changes in this revision

Viewing changes to qtgui/examples/dbus/listnames/listnames.pl

  • Committer: Arno Rehn
  • Date: 2011-01-06 17:49:41 UTC
  • Revision ID: git-v1:ada9e4b459cf6fabd0f3b9b164387469cb19d9bc
A patch by Ian Monroe and myself to modularize the repository.
See README.MODULARIZATION for details.

svn path=/trunk/KDE/kdebindings/perl/; revision=1212365

Show diffs side-by-side

added added

removed removed

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