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

« back to all changes in this revision

Viewing changes to .pc/01_fix_ftbfs_kwarning_call.diff/src/keymon/device.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) 2009 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 "device.h"
23
 
 
24
 
// KDE
25
 
#include <kdebug.h>
26
 
 
27
 
// Qt
28
 
#include <QtCore/QSocketNotifier>
29
 
#include <QtCore/QMetaType>
30
 
#include <QtCore/QDir>
31
 
 
32
 
 
33
 
// C
34
 
#include <linux/input.h>
35
 
#include <fcntl.h>
36
 
#include <unistd.h>
37
 
 
38
 
 
39
 
 
40
 
namespace KeyMon {
41
 
 
42
 
 
43
 
Device::Device(QObject *parent, const QString &file)
44
 
    : QObject(parent)
45
 
{
46
 
 
47
 
    qRegisterMetaType<KeyMon::Event>("KeyMon::Event");
48
 
 
49
 
    m_socketNotifier = 0;
50
 
    int fd = open(file.toLatin1(), O_RDONLY|O_NONBLOCK);
51
 
    if (fd == -1) {
52
 
        kWarning() << "open failed!";
53
 
        m_error = true;
54
 
        return;
55
 
    }
56
 
    m_error = false;
57
 
 
58
 
    m_socketNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
59
 
    connect(m_socketNotifier, SIGNAL(activated(int)), this, SLOT(readEvents()));
60
 
 
61
 
}
62
 
 
63
 
 
64
 
Device::~Device()
65
 
{
66
 
 
67
 
    if (m_socketNotifier) {
68
 
        delete m_socketNotifier;
69
 
    }
70
 
 
71
 
}
72
 
 
73
 
 
74
 
bool Device::error() const
75
 
{
76
 
 
77
 
    return m_error;
78
 
 
79
 
}
80
 
 
81
 
 
82
 
QList<DeviceData> Device::getDeviceList()
83
 
{
84
 
 
85
 
    QList<DeviceData> deviceList;
86
 
    QDir input("/dev/input");
87
 
    if (!input.exists()) {
88
 
        kWarning() << "/dev/input: no such directory!";
89
 
        return deviceList;
90
 
    }
91
 
 
92
 
    QStringList files = input.entryList(QDir::System);
93
 
    const QRegExp rx("^event[0-9]+$");
94
 
 
95
 
    foreach (const QString &file, files) {
96
 
        if (rx.exactMatch(file)) {                        
97
 
            const DeviceData device = getDevice(file);
98
 
            if (!device.first.isEmpty() && !device.second.isEmpty()) {
99
 
                deviceList.append(device);
100
 
            }
101
 
        }
102
 
    }
103
 
    return deviceList;
104
 
 
105
 
}
106
 
 
107
 
 
108
 
DeviceData Device::getDevice(const QString &file)
109
 
{
110
 
 
111
 
    QString path = file;
112
 
    DeviceData device;
113
 
    int fd;
114
 
 
115
 
    if (!path.startsWith(QLatin1Char('/'))) {
116
 
        path.prepend("/dev/input/");
117
 
    }
118
 
 
119
 
    if ((fd = open (path.toLatin1(), O_RDONLY)) == -1) {
120
 
        kWarning() << path << ": open failed!";
121
 
    } else {
122
 
        char buff[32];
123
 
        ioctl(fd, EVIOCGNAME(sizeof(buff)), buff);
124
 
 
125
 
        device.first = QString(buff);
126
 
    }
127
 
    device.second = path;
128
 
 
129
 
    return device;
130
 
 
131
 
}
132
 
 
133
 
 
134
 
void Device::readEvents()
135
 
{
136
 
 
137
 
    int fd = m_socketNotifier->socket();
138
 
    for (;;) {
139
 
        struct input_event ev;
140
 
        int bytesRead = read(fd, &ev, sizeof(ev));
141
 
        if (bytesRead <= 0) {
142
 
            break;
143
 
        }
144
 
        if (bytesRead != sizeof(ev)) {
145
 
            kWarning("Internal error!");
146
 
            return;
147
 
        }
148
 
 
149
 
        const bool pressed = (ev.value == 1);
150
 
        KeyMon::Event::Key key;
151
 
        switch(ev.code)
152
 
        {
153
 
        case BTN_LEFT:
154
 
            key = KeyMon::Event::LeftButton;
155
 
            break;
156
 
        case BTN_RIGHT:
157
 
            key = KeyMon::Event::RightButton;
158
 
            break;
159
 
        case BTN_MIDDLE:
160
 
            key = KeyMon::Event::MiddleButton;
161
 
            break;
162
 
        case BTN_EXTRA:
163
 
            key = KeyMon::Event::SpecialButton1;
164
 
            break;
165
 
        case BTN_SIDE:
166
 
            key = KeyMon::Event::SpecialButton2;
167
 
            break;
168
 
        case REL_WHEEL:
169
 
            if (pressed) {
170
 
                key = KeyMon::Event::WheelUp;
171
 
            } else {
172
 
                key = KeyMon::Event::WheelDown;
173
 
            }
174
 
            break;
175
 
            default:
176
 
            key = KeyMon::Event::NoButton;
177
 
            break;
178
 
        };
179
 
 
180
 
        if (key != KeyMon::Event::NoButton) {
181
 
            KeyMon::Event sEvent;
182
 
            sEvent.key = key;
183
 
            sEvent.pressed = pressed;
184
 
            emit buttonPressed(sEvent);
185
 
        }
186
 
    }
187
 
 
188
 
}
189
 
 
190
 
 
191
 
}; // Namespace KeyMon
192
 
 
193
 
 
194
 
#include "device.moc"