~ubuntu-branches/ubuntu/raring/recorditnow/raring

« back to all changes in this revision

Viewing changes to src/config/keyboardkeypage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-09 14:54:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110109145401-gyckb4airz4fio50
Tags: 0.8.1-0ubuntu1
* New upstream release. (LP: #681270)
  - Update debian/copyright.
* Build-depend on recordmydesktop.
* Add a watch file.
* Drop 01_fix_ftbfs_kwarning_call.diff, fixed upstream.
* Add 01_joschy_install_to_usr_lib.diff.
* Add 02_fix_ftbfs_no-add-needed.diff.
* Add 03_dont_install_header_files.diff.
* Replace dependency on libpolkit-qt-1-0 with policykit-1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010 by Kai Dombrowe <just89@gmx.de>                    *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 
18
 ***************************************************************************/
 
19
 
 
20
 
 
21
// own
 
22
#include "keyboardkeypage.h"
 
23
#include "keymonmanager.h"
 
24
#include "../keyboard/keyboardkey.h"
 
25
 
 
26
// KDE
 
27
#include <kauth.h>
 
28
#include <kdebug.h>
 
29
#include <kmessagebox.h>
 
30
 
 
31
// Qt
 
32
#include <QtCore/QTimer>
 
33
#include <QtGui/QKeyEvent>
 
34
 
 
35
 
 
36
KeyboardKeyPage::KeyboardKeyPage(const QString &device, QWidget *parent)
 
37
    : QWizardPage(parent)
 
38
{
 
39
 
 
40
    m_grab = false;
 
41
    m_key = -1;
 
42
    m_device = device;
 
43
 
 
44
    setupUi(this);
 
45
 
 
46
    connect(startButton, SIGNAL(clicked()), this, SLOT(start()));
 
47
    connect(KeyMonManager::self(), SIGNAL(keyEvent(KeyMon::Event)), this,
 
48
            SLOT(keyEvent(KeyMon::Event)));
 
49
    connect(KeyMonManager::self(), SIGNAL(stopped()), this, SLOT(keymonStopped()));
 
50
    connect(KeyMonManager::self(), SIGNAL(started()), this, SLOT(startGrab()));
 
51
 
 
52
    registerField("KeyCode*", keyCode);
 
53
    registerField("Text*", keyText);
 
54
 
 
55
    statusLabel->setText(i18n("Click on \"%1\"", startButton->text()));
 
56
 
 
57
}
 
58
 
 
59
 
 
60
KeyboardKeyPage::~KeyboardKeyPage()
 
61
{
 
62
 
 
63
    stop();
 
64
 
 
65
}
 
66
 
 
67
 
 
68
void KeyboardKeyPage::initializePage()
 
69
{
 
70
 
 
71
 
 
72
 
 
73
}
 
74
 
 
75
 
 
76
void KeyboardKeyPage::start()
 
77
{
 
78
 
 
79
    if (m_device.isEmpty()) {
 
80
        statusLabel->setText(i18n("Please select a device."));
 
81
        return;
 
82
    }
 
83
 
 
84
    statusLabel->setText(i18n("Please wait..."));
 
85
 
 
86
    startButton->setDisabled(true);
 
87
    m_key = -1;
 
88
 
 
89
    keyLabel->clear();
 
90
    keyCodeLabel->clear();
 
91
 
 
92
    if (!KeyMonManager::self()->start(QStringList() << m_device)) {
 
93
        statusLabel->setText(i18n("An error occurd: %1", KeyMonManager::self()->error()));
 
94
        stop();
 
95
    } else {
 
96
        statusLabel->setText(i18n("Wait for authentication!"));
 
97
    }
 
98
 
 
99
}
 
100
 
 
101
 
 
102
void KeyboardKeyPage::startGrab()
 
103
{
 
104
 
 
105
    statusLabel->setText(i18n("Press a key!"));
 
106
    grabKeyboard();
 
107
    m_grab = true;
 
108
 
 
109
}
 
110
 
 
111
 
 
112
void KeyboardKeyPage::stop()
 
113
{
 
114
 
 
115
    m_grab = false;
 
116
    releaseKeyboard();
 
117
    startButton->setDisabled(false);
 
118
    KeyMonManager::self()->stop();
 
119
    
 
120
}
 
121
 
 
122
 
 
123
void KeyboardKeyPage::keyEvent(const KeyMon::Event &event)
 
124
{
 
125
 
 
126
    if (m_grab) {
 
127
        m_key = event.keyCode;
 
128
    }
 
129
 
 
130
}
 
131
 
 
132
 
 
133
void KeyboardKeyPage::keymonStopped()
 
134
{
 
135
 
 
136
    stop();
 
137
    if (!KeyMonManager::self()->error().isEmpty()) {
 
138
        statusLabel->setText(i18n("An error occurd: %1", KeyMonManager::self()->error()));
 
139
    }
 
140
 
 
141
}
 
142
 
 
143
 
 
144
void KeyboardKeyPage::keyPressEvent(QKeyEvent *event)
 
145
{
 
146
 
 
147
    if (!m_grab) {
 
148
        QWizardPage::keyPressEvent(event);
 
149
    } else { // don`t close the dialog if the user presses Esc
 
150
        event->accept();
 
151
    }
 
152
 
 
153
}
 
154
 
 
155
 
 
156
void KeyboardKeyPage::keyReleaseEvent(QKeyEvent *event)
 
157
{
 
158
 
 
159
    if (!m_grab) {
 
160
        QWizardPage::keyReleaseEvent(event);
 
161
        return;
 
162
    }
 
163
 
 
164
    stop();
 
165
 
 
166
    kDebug() << "key:" << m_key;
 
167
    if (m_key != -1) {
 
168
        keyCode->setValue(m_key);
 
169
 
 
170
        KeyboardKey key = KeyboardKey::eventToKey(event);
 
171
 
 
172
        keyLabel->setText(key.text());
 
173
        keyText->setText(key.text());
 
174
        keyCodeLabel->setText(QString::number(m_key));
 
175
 
 
176
        statusLabel->setText(i18n("Success!"));
 
177
    } else {
 
178
        statusLabel->setText(i18n("Grab failed!\n"
 
179
                                  "Perhaps you have selected the wrong device."));
 
180
    }
 
181
 
 
182
}
 
183
 
 
184
 
 
185
 
 
186
 
 
187
#include "keyboardkeypage.moc"