File: complexpong.pl

package info (click to toggle)
qt4-perl 4.8.4-1.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,636 kB
  • ctags: 8,100
  • sloc: perl: 42,963; cpp: 28,039; makefile: 160; xml: 98; sh: 4
file content (94 lines) | stat: -rwxr-xr-x 1,995 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/perl

package Pong;

use strict;
use warnings;

use QtCore4;
use QtGui4;
use QtDBus4;
use QtCore4::isa qw( Qt::DBusAbstractAdaptor );
use QtCore4::classinfo
    'D-Bus Interface' => 'com.trolltech.QtDBus.ComplexPong.Pong';

use QtCore4::signals
    aboutToQuit => [];
use QtCore4::slots
    'QDBusVariant query' => ['const QString&'],
    'QString value' => [],
    setValue => ['QString'],
    quit => [];

sub NEW {
    shift->SUPER::NEW( @_ );
}

# the property
sub value() {
    return this->{m_value};
}

sub setValue {
    my ($newValue) = @_;
    this->{m_value} = $newValue;
}

sub quit {
    Qt::Timer::singleShot(0, Qt::Application::instance(), SLOT 'quit()');
}

sub query {
    my ( $query ) = @_;
    my $q = lc $query;
    if ($q eq 'hello') {
        return Qt::DBusVariant(Qt::String('World'));
    }
    if ($q eq 'ping') {
        return Qt::DBusVariant(Qt::String('Pong'));
    }
    if ($q =~ m/the answer to life, the universe and everything/) {
        return Qt::DBusVariant(Qt::Int(42));
    }
    if ($q =~ m/unladen swallow/) {
        if ($q =~ m/european/) {
            return Qt::DBusVariant(Qt::Int(11.0));
        }
        return Qt::DBusVariant(Qt::String('african or european?'));
    }

    return Qt::DBusVariant(Qt::String('Sorry, I don\'t know the answer'));
}

1;

package main;

use strict;
use warnings;

use QtCore4;
use QtGui4;
use QtDBus4;
use PingCommon qw( SERVICE_NAME );
use Pong;

sub main {
    my $app = Qt::Application( \@ARGV );

    my $obj = Qt::Object();
    my $pong = Pong($obj);
    $pong->connect($app, SIGNAL 'aboutToQuit()', SIGNAL 'aboutToQuit()' );
    $pong->setValue(Qt::Variant(Qt::String('initial value')));
    Qt::DBusConnection::sessionBus()->registerObject('/', $obj);

    if (!Qt::DBusConnection::sessionBus()->registerService(SERVICE_NAME)) {
        printf STDERR "%s\n",
                Qt::DBusConnection::sessionBus()->lastError()->message();
        exit 1;
    }
    
    exit $app->exec();
}

main();