1
/***************************************************************************
2
* Copyright (C) 2010 by Kai Dombrowe <just89@gmx.de> *
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. *
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. *
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
***************************************************************************/
22
#include "keyboardkeypage.h"
23
#include "keymonmanager.h"
24
#include "../keyboard/keyboardkey.h"
29
#include <kmessagebox.h>
32
#include <QtCore/QTimer>
33
#include <QtGui/QKeyEvent>
36
KeyboardKeyPage::KeyboardKeyPage(const QString &device, QWidget *parent)
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()));
52
registerField("KeyCode*", keyCode);
53
registerField("Text*", keyText);
55
statusLabel->setText(i18n("Click on \"%1\"", startButton->text()));
60
KeyboardKeyPage::~KeyboardKeyPage()
68
void KeyboardKeyPage::initializePage()
76
void KeyboardKeyPage::start()
79
if (m_device.isEmpty()) {
80
statusLabel->setText(i18n("Please select a device."));
84
statusLabel->setText(i18n("Please wait..."));
86
startButton->setDisabled(true);
90
keyCodeLabel->clear();
92
if (!KeyMonManager::self()->start(QStringList() << m_device)) {
93
statusLabel->setText(i18n("An error occurd: %1", KeyMonManager::self()->error()));
96
statusLabel->setText(i18n("Wait for authentication!"));
102
void KeyboardKeyPage::startGrab()
105
statusLabel->setText(i18n("Press a key!"));
112
void KeyboardKeyPage::stop()
117
startButton->setDisabled(false);
118
KeyMonManager::self()->stop();
123
void KeyboardKeyPage::keyEvent(const KeyMon::Event &event)
127
m_key = event.keyCode;
133
void KeyboardKeyPage::keymonStopped()
137
if (!KeyMonManager::self()->error().isEmpty()) {
138
statusLabel->setText(i18n("An error occurd: %1", KeyMonManager::self()->error()));
144
void KeyboardKeyPage::keyPressEvent(QKeyEvent *event)
148
QWizardPage::keyPressEvent(event);
149
} else { // don`t close the dialog if the user presses Esc
156
void KeyboardKeyPage::keyReleaseEvent(QKeyEvent *event)
160
QWizardPage::keyReleaseEvent(event);
166
kDebug() << "key:" << m_key;
168
keyCode->setValue(m_key);
170
KeyboardKey key = KeyboardKey::eventToKey(event);
172
keyLabel->setText(key.text());
173
keyText->setText(key.text());
174
keyCodeLabel->setText(QString::number(m_key));
176
statusLabel->setText(i18n("Success!"));
178
statusLabel->setText(i18n("Grab failed!\n"
179
"Perhaps you have selected the wrong device."));
187
#include "keyboardkeypage.moc"