File: Assistant.pm

package info (click to toggle)
qt4-perl 4.8.4-1.3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 8,752 kB
  • ctags: 8,157
  • sloc: perl: 42,963; cpp: 28,039; makefile: 160; xml: 98; sh: 4
file content (85 lines) | stat: -rw-r--r-- 1,813 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
package Assistant;

use strict;
use warnings;
use QtCore4;
use QtGui4;

sub proc() {
    return shift->{proc};
}

sub new
{
    my ($class) = @_;
    my $self = {
        proc => undef
    };
    return bless $self, $class;
}

# [0]
sub DESTROY
{
    my ($self) = @_;
    if (defined $self->proc() && $self->proc()->state() == Qt::Process::Running()) {
        $self->proc()->terminate();
        $self->proc()->waitForFinished(3000);
    }
    $self->{proc} = undef;
}
# [0]

# [1]
sub showDocumentation
{
    my ($self, $page) = @_;
    if (!$self->startAssistant()) {
        return;
    }

    my $ba = Qt::ByteArray('SetSource ');
    $ba->append('qthelp://com.trolltech.examples.simpletextviewer/doc/');
    $ba->append($page);
    $ba->append("\0", 1);

    $self->proc->write($ba);
}
# [1]

# [2]
sub startAssistant
{
    my ($self) = @_;
    if (!defined $self->proc) {
        $self->{proc} = Qt::Process();
    }

    if ($self->proc->state() != Qt::Process::Running()) {
        my $app = Qt::LibraryInfo::location(Qt::LibraryInfo::BinariesPath()) . chr(Qt::Dir::separator()->toAscii());
#if !defined(Q_OS_MAC)
        $app .= 'assistant';
#else
        # TODO
        #app += Qt::Latin1String('Assistant.app/Contents/MacOS/Assistant');
#endif

        my $args = [
            '-collectionFile',
            Qt::LibraryInfo::location(Qt::LibraryInfo::ExamplesPath())
            . '/help/simpletextviewer/documentation/simpletextviewer.qhc',
            '-enableRemoteControl' ];

        $self->proc->start($app, $args);

        if (!$self->proc->waitForStarted()) {
            Qt::MessageBox::critical(undef, Qt::Object::tr('Simple Text Viewer'),
                sprintf Qt::Object::tr('Unable to launch Qt Assistant (%s)'), $app);
            return 0;
        }
    }
    return 1;
}
# [2]

1;