00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "detectlinux.h"
00022
00023 #include "inputthread.h"
00024 #include "detectlinuxprivate.h"
00025
00026 #include <core/debughelper.h>
00027
00028 #include <QtCore/QDir>
00029 #include <QtCore/QCoreApplication>
00030 #include <QtGui/QMessageBox>
00031 #include <QtCore/QDebug>
00032
00033
00034
00035 using namespace GluonInput;
00036
00037 DetectLinux::DetectLinux( QObject* parent )
00038 : Detect( parent )
00039 , d( new DetectLinuxPrivate )
00040 {
00041 }
00042
00043 DetectLinux::~DetectLinux()
00044 {
00045
00046
00047
00048
00049
00050 }
00051
00052 void DetectLinux::detectDevices()
00053 {
00054 DetectLinux* detect = this;
00055 detect->clear();
00056 QDir event( "/dev/input/by-path/" );
00057 QStringList readableInputFiles;
00058 QStringList unreadableInputFiles;
00059 QString file;
00060 QFileInfoList inputFileInfoList;
00061 QList<struct input_id> processedInputs;
00062 bool processed;
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 inputFileInfoList = event.entryInfoList( QDir::Files );
00073 foreach( QFileInfo inputFileInfo, inputFileInfoList )
00074 {
00075 file = inputFileInfo.filePath();
00076 if( access( file.toUtf8(), R_OK ) != -1 )
00077 readableInputFiles.append( file );
00078 else
00079 unreadableInputFiles.append( file );
00080 }
00081
00082 foreach( const QString & name, readableInputFiles )
00083 {
00084 InputDevice* device = 0;
00085 InputThread* thread = new InputThread( name );
00086 if( !thread->error() )
00087 {
00088 switch( thread->deviceType() )
00089 {
00090 case GluonInput::KeyboardDevice:
00091 device = new Keyboard( thread );
00092 detect->addKeyboard( static_cast<Keyboard*>( device ) );
00093 break;
00094
00095 case GluonInput::MouseDevice:
00096 device = new Mouse( thread );
00097 detect->addMouse( static_cast<Mouse*>( device ) );
00098 break;
00099
00100 case GluonInput::TouchpadDevice:
00101 device = new Mouse( thread );
00102 detect->addMouse( static_cast<Mouse*>( device ) );
00103 break;
00104
00105 case GluonInput::JoystickDevice:
00106 device = new Joystick( thread );
00107 detect->addJoystick( static_cast<Joystick*>( device ) );
00108 break;
00109
00110 case GluonInput::TouchDevice:
00111 device = new Touch( thread );
00112 detect->addTouch( static_cast<Touch*>( device ) );
00113 break;
00114
00115 case GluonInput::UnknownDevice:
00116 device = new InputDevice( thread );
00117 detect->addUnknown( device );
00118 break;
00119 }
00120
00121 processedInputs.append(thread->device_info());
00122 detect->addInput( device );
00123 }
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 }
00228
00229 void DetectLinux::setAllEnabled( bool enable )
00230 {
00231 foreach( InputDevice * input, inputList() )
00232 {
00233 input->setEnabled( enable );
00234 }
00235 }
00236
00237 void DetectLinux::clear()
00238 {
00239 d->inputList.clear();
00240 d->keyboardList.clear();
00241 d->mouseList.clear();
00242 d->joystickList.clear();
00243 d->touchList.clear();
00244 d->unknownList.clear();
00245 }
00246
00247 void DetectLinux::addInput( InputDevice* i )
00248 {
00249 d->inputList.append( i );
00250 }
00251
00252 void DetectLinux::addKeyboard( Keyboard* keyboard )
00253 {
00254 d->keyboardList.append( keyboard );
00255 }
00256
00257 void DetectLinux::addMouse( Mouse* mouse )
00258 {
00259 d->mouseList.append( mouse );
00260 }
00261
00262 void DetectLinux::addJoystick( Joystick* joystick )
00263 {
00264 d->joystickList.append( joystick );
00265 }
00266
00267 void DetectLinux::addTouch( Touch* touch )
00268 {
00269 d->touchList.append( touch );
00270 }
00271
00272 void DetectLinux::addUnknown( InputDevice* i )
00273 {
00274 d->unknownList.append( i );
00275 }
00276
00277 QList<InputDevice*> DetectLinux::inputList()
00278 {
00279 return d->inputList;
00280 }
00281
00282 QList<Keyboard*> DetectLinux::keyboardList()
00283 {
00284 return d->keyboardList;
00285 }
00286
00287 QList<Mouse*> DetectLinux::mouseList()
00288 {
00289 return d->mouseList;
00290 }
00291
00292 QList<Joystick*> DetectLinux::joystickList()
00293 {
00294 return d->joystickList;
00295 }
00296
00297 QList<Touch*> DetectLinux::touchList()
00298 {
00299 return d->touchList;
00300 }
00301
00302 QList<InputDevice*> DetectLinux::unknownDeviceList()
00303 {
00304 return d->unknownList;
00305 }
00306
00307 #include "detectlinux.moc"