File: RemoteControl.pm

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 (159 lines) | stat: -rw-r--r-- 3,998 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package RemoteControl;

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

use Ui_RemoteControlClass;

use QtCore4::isa qw( Qt::MainWindow );

use QtCore4::slots
    on_launchButton_clicked => [],
    on_actionQuit_triggered => [],
    on_indexButton_clicked => [],
    on_identifierButton_clicked => [],
    on_urlButton_clicked => [],
    on_syncContentsButton_clicked => [],
    on_contentsCheckBox_toggled => ['bool'],
    on_indexCheckBox_toggled => ['bool'],
    on_bookmarksCheckBox_toggled => ['bool'],
    helpViewerClosed => [],
    sendCommand => ['const QString &'];

sub NEW
{
    my ($class, $parent, $flags) = @_;
    $class->SUPER::NEW($parent, $flags);

    this->{ui} = Ui_RemoteControlClass->setupUi(this);
    this->connect(this->{ui}->indexLineEdit, SIGNAL 'returnPressed()',
        this, SLOT 'on_indexButton_clicked()');
    this->connect(this->{ui}->identifierLineEdit, SIGNAL 'returnPressed()',
        this, SLOT 'on_identifierButton_clicked()');
    this->connect(this->{ui}->urlLineEdit, SIGNAL 'returnPressed()',
        this, SLOT 'on_urlButton_clicked()');

    my $rc = 'qthelp://com.trolltech.qt.' .
             451 .
             '/qdoc/index.html';
                     #<< (QT_VERSION >> 16) << ((QT_VERSION >> 8) & 0xFF)
                     #<< (QT_VERSION & 0xFF)

    this->{ui}->startUrlLineEdit->setText($rc);

    this->{process} = Qt::Process(this);
    this->connect(this->{process}, SIGNAL 'finished(int, QProcess::ExitStatus)',
        this, SLOT 'helpViewerClosed()');
}

sub ON_DESTROY
{
    if (this->{process}->state() == Qt::Process::Running()) {
        this->{process}->terminate();
        this->{process}->waitForFinished(3000);
    }
}

sub on_actionQuit_triggered()
{
    this->close();
}

sub on_launchButton_clicked
{
    if (this->{process}->state() == Qt::Process::Running()) {
        return;
    }

    my $app = Qt::LibraryInfo::location(Qt::LibraryInfo::BinariesPath())
            . chr Qt::Dir::separator()->toLatin1();
    $app .= 'assistant';


    this->{ui}->contentsCheckBox->setChecked(1);
    this->{ui}->indexCheckBox->setChecked(1);
    this->{ui}->bookmarksCheckBox->setChecked(1);

    my @args = ('-enableRemoteControl');
    this->{process}->start($app, \@args);
    if (!this->{process}->waitForStarted()) {
        Qt::MessageBox::critical(this, this->tr('Remote Control'),
            sprintf this->tr('Could not start Qt Assistant from %s.'), $app);
        return;
    }

    if (this->{ui}->startUrlLineEdit->text()) {
        this->sendCommand('SetSource '
            . this->{ui}->startUrlLineEdit->text());
    }
        
    this->{ui}->launchButton->setEnabled(0);
    this->{ui}->startUrlLineEdit->setEnabled(0);
    this->{ui}->actionGroupBox->setEnabled(1);
}

sub sendCommand
{
    my ($cmd) = @_;
    if (this->{process}->state() != Qt::Process::Running()) {
        return;
    }
    $cmd = Qt::ByteArray( $cmd );
    $cmd->append( "\0", 1 );
    this->{process}->write($cmd);
}

sub on_indexButton_clicked
{
    this->sendCommand('ActivateKeyword '
        . this->{ui}->indexLineEdit->text());
}

sub on_identifierButton_clicked
{
    this->sendCommand('ActivateIdentifier '
        . this->{ui}->identifierLineEdit->text());
}

sub on_urlButton_clicked
{
    this->sendCommand('SetSource '
        . this->{ui}->urlLineEdit->text());
}

sub on_syncContentsButton_clicked
{
    this->sendCommand('SyncContents');
}

sub on_contentsCheckBox_toggled
{
    my ($checked) = @_;
    this->sendCommand($checked ?
        'Show Contents' : 'Hide Contents');
}

sub on_indexCheckBox_toggled
{
    my ($checked) = @_;
    this->sendCommand($checked ?
        'Show Index' : 'Hide Index');
}

sub on_bookmarksCheckBox_toggled
{
    my ($checked) = @_;
    this->sendCommand($checked ?
        'Show Bookmarks' : 'Hide Bookmarks');
}

sub helpViewerClosed
{
    this->{ui}->launchButton->setEnabled(1);
    this->{ui}->startUrlLineEdit->setEnabled(1);
    this->{ui}->actionGroupBox->setEnabled(0);
}

1;