00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (C) 2010 Kim Jung Nissen <jungnissen@gmail.com> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 #include "inputmanager.h" 00020 00021 #include "inputmanagerprivate.h" 00022 #include "gluondevices.h" 00023 00024 #ifdef Q_WS_X11 00025 #include "detectlinux.h" 00026 #endif 00027 00028 #ifdef Q_WS_MAC 00029 #include "detectmac.h" 00030 #endif 00031 00032 #ifdef Q_WS_WIN 00033 #include "detectwin.h" 00034 #endif 00035 00036 #include <QtCore/QCoreApplication> 00037 #include <QtGui/QMessageBox> 00038 #include <QtCore/QDebug> 00039 00040 using namespace GluonInput; 00041 00042 template<> InputManager* GluonCore::Singleton<InputManager>::m_instance = 0; 00043 00044 InputManager::InputManager() 00045 : d( new InputManagerPrivate ) 00046 { 00047 init(); 00048 } 00049 00050 InputManager::~InputManager() 00051 { 00052 } 00053 00054 void InputManager::init() 00055 { 00056 QObject* parent = QCoreApplication::instance(); 00057 if( !parent ) 00058 { 00059 qDebug() << "No QCoreApplication instance found, the InputManager instance may be leaked when leaving"; 00060 } 00061 00062 #ifdef Q_WS_X11 00063 d->m_detect = new DetectLinux( parent ); 00064 #endif 00065 00066 #ifdef Q_WS_MAC 00067 d->m_detect = new DetectMac( parent ); 00068 #endif 00069 00070 #ifdef Q_WS_WIN 00071 d->m_detect = new DetectWin( parent ); 00072 #endif 00073 if( d->m_detect ) 00074 { 00075 d->m_detect->detectDevices(); 00076 } 00077 else 00078 { 00079 qDebug() << "Instance not created, fail!"; 00080 } 00081 } 00082 00083 void InputManager::detectDevices() 00084 { 00085 d->m_detect->detectDevices(); 00086 } 00087 00088 void InputManager::setAllEnabled( bool enable ) 00089 { 00090 d->m_detect->setAllEnabled( enable ); 00091 } 00092 00093 unsigned int InputManager::deviceCount() 00094 { 00095 return inputList().size(); 00096 } 00097 00098 unsigned int InputManager::keyboardCount() 00099 { 00100 return d->m_detect->keyboardList().size(); 00101 } 00102 00103 unsigned int InputManager::mouseCount() 00104 { 00105 return d->m_detect->mouseList().size(); 00106 } 00107 00108 unsigned int InputManager::joystickCount() 00109 { 00110 return d->m_detect->joystickList().size(); 00111 } 00112 00113 unsigned int InputManager::touchCount() 00114 { 00115 return d->m_detect->touchList().size(); 00116 } 00117 00118 unsigned int InputManager::unknownDeviceCount() 00119 { 00120 return d->m_detect->unknownDeviceList().size(); 00121 } 00122 00123 QList<Keyboard*> InputManager::keyboardList() 00124 { 00125 return d->m_detect->keyboardList(); 00126 } 00127 00128 QList<Mouse*> InputManager::mouseList() 00129 { 00130 return d->m_detect->mouseList(); 00131 } 00132 00133 QList<Joystick*> InputManager::joystickList() 00134 { 00135 return d->m_detect->joystickList(); 00136 } 00137 00138 QList<Touch*> InputManager::touchList() 00139 { 00140 return d->m_detect->touchList(); 00141 } 00142 00143 QList<InputDevice*> InputManager::unknownDeviceList() 00144 { 00145 return d->m_detect->unknownDeviceList(); 00146 } 00147 00148 InputList InputManager::inputList() 00149 { 00150 return d->m_detect->inputList(); 00151 } 00152 00153 Keyboard* InputManager::keyboard( int id ) 00154 { 00155 if( !d->m_detect->keyboardList().isEmpty() ) 00156 { 00157 return d->m_detect->keyboardList().at( id ); 00158 } 00159 return 0; 00160 } 00161 00162 Mouse* InputManager::mouse( int id ) 00163 { 00164 if( !d->m_detect->mouseList().isEmpty() ) 00165 { 00166 return d->m_detect->mouseList().at( id ); 00167 } 00168 return 0; 00169 } 00170 00171 Joystick* InputManager::joystick( int id ) 00172 { 00173 if( !d->m_detect->joystickList().isEmpty() ) 00174 { 00175 return d->m_detect->joystickList().at( id ); 00176 } 00177 return 0; 00178 } 00179 00180 Touch* InputManager::touch( int id ) 00181 { 00182 if( !d->m_detect->touchList().isEmpty() ) 00183 { 00184 return d->m_detect->touchList().at( id ); 00185 } 00186 return 0; 00187 } 00188 00189 InputDevice* InputManager::input( int id ) 00190 { 00191 if( !d->m_detect->inputList().isEmpty() ) 00192 { 00193 return d->m_detect->inputList().at( id ); 00194 } 00195 return 0; 00196 } 00197 00198 #include "inputmanager.moc"