Ticket #10069: mythinputmanager-2009-09-29.diff
File mythinputmanager-2009-09-29.diff, 17.2 KB (added by , 13 years ago) |
---|
-
mythtv/libs/libmythbase/mythdirs.cpp
diff --git a/mythtv/libs/libmythbase/mythdirs.cpp b/mythtv/libs/libmythbase/mythdirs.cpp index 9e43148..305a4e1 100644
a b static QString themedir = QString::null; 16 16 static QString pluginsdir = QString::null; 17 17 static QString translationsdir = QString::null; 18 18 static QString filtersdir = QString::null; 19 static QString inputsdir = QString::null; 20 19 21 20 22 void InitializeMythDirs(void) 21 23 { … … void InitializeMythDirs(void) 69 71 pluginsdir = libdir + "plugins/"; 70 72 translationsdir = sharedir + "i18n/"; 71 73 filtersdir = libdir + "filters/"; 74 inputsdir = libdir + "inputevents/"; 72 75 } 73 76 74 77 QString GetInstallPrefix(void) { return installprefix; } … … QString GetThemesParentDir(void) { return themedir; } 79 82 QString GetPluginsDir(void) { return pluginsdir; } 80 83 QString GetTranslationsDir(void) { return translationsdir; } 81 84 QString GetFiltersDir(void) { return filtersdir; } 85 QString GetInputsDir(void) { return inputsdir; } 82 86 83 87 // These defines provide portability for different 84 88 // plugin file names. -
mythtv/libs/libmythbase/mythdirs.h
diff --git a/mythtv/libs/libmythbase/mythdirs.h b/mythtv/libs/libmythbase/mythdirs.h index 34b1047..855b69d 100644
a b 14 14 MBASE_PUBLIC QString GetPluginsDir(void); 15 15 MBASE_PUBLIC QString GetTranslationsDir(void); 16 16 MBASE_PUBLIC QString GetFiltersDir(void); 17 MBASE_PUBLIC QString GetInputsDir(void); 17 18 18 19 MBASE_PUBLIC QString GetPluginsNameFilter(void); 19 20 MBASE_PUBLIC QString FindPluginName(const QString &plugname); -
mythtv/libs/libmythui/libmythui.pro
diff --git a/mythtv/libs/libmythui/libmythui.pro b/mythtv/libs/libmythui/libmythui.pro index 32b839e..92f3965 100644
a b HEADERS += mythgenerictree.h mythuibuttontree.h mythuiutils.h 30 30 HEADERS += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h 31 31 HEADERS += mythrender_base.h mythfontmanager.h mythuieditbar.h 32 32 HEADERS += mythdisplay.h mythuivideo.h mythudplistener.h 33 HEADERS += mythuiexp.h 33 HEADERS += mythuiexp.h mythinputmanager.h mythinputinterface.h 34 34 35 35 SOURCES = mythmainwindow.cpp mythpainter.cpp mythimage.cpp mythrect.cpp 36 36 SOURCES += myththemebase.cpp mythpainter_qimage.cpp mythpainter_yuva.cpp … … SOURCES += mythgenerictree.cpp mythuibuttontree.cpp mythuiutils.cpp 48 48 SOURCES += mythvirtualkeyboard.cpp mythuishape.cpp mythuiguidegrid.cpp 49 49 SOURCES += mythfontmanager.cpp mythuieditbar.cpp 50 50 SOURCES += mythdisplay.cpp mythuivideo.cpp mythudplistener.cpp 51 SOURCES += mythinputmanager.cpp 51 52 52 53 53 54 inc.path = $${PREFIX}/include/mythtv/libmythui/ -
new file mythtv/libs/libmythui/mythinputinterface.h
diff --git a/mythtv/libs/libmythui/mythinputinterface.h b/mythtv/libs/libmythui/mythinputinterface.h new file mode 100755 index 0000000..4ea9b7a
- + 1 #ifndef MYTHINPUTINTERFACE_H 2 #define MYTHINPUTINTERFACE_H 3 4 #include <QtPlugin> 5 #include <QKeyEvent> 6 7 /** 8 * \file 9 * This is the only file a plugin need to include, a plugin should normally not be link with libmythui 10 */ 11 12 class MythInputInterface; 13 14 /** 15 * \brief Interface accessible from a input plugin. 16 */ 17 class MythInputManagerInterface : public QObject 18 { 19 Q_OBJECT 20 public: 21 MythInputManagerInterface():QObject(){}; 22 23 /** 24 * \brief an event need to be send to MythMainWindow 25 */ 26 virtual void onKeyPressed(const QKeyEvent &keyEvent)=0; 27 28 29 /** 30 * \brief get a string setting 31 */ 32 virtual QString getSetting(const MythInputInterface * input, const QString &key)=0; 33 /** 34 * \brief get a string setting with a default value 35 */ 36 virtual QString getSetting(const MythInputInterface * input, const QString &key, const QString &defaultval)=0; 37 /** 38 * \brief save a string setting 39 */ 40 virtual bool saveSetting(const MythInputInterface * input, const QString &key, const QString &newValue)=0; 41 42 /** 43 * \brief get a integer setting 44 */ 45 virtual int getNumSetting(const MythInputInterface * input, const QString &key)=0; 46 /** 47 * \brief get a integer setting with a default value 48 */ 49 virtual int getNumSetting(const MythInputInterface * input, const QString &key, int defaultval)=0; 50 /** 51 * \brief save an integer setting 52 */ 53 virtual bool saveNumSetting(const MythInputInterface * input, const QString &key, int newValue)=0; 54 55 /** 56 * \brief get a float setting 57 */ 58 virtual double getFloatSetting(const MythInputInterface * input, const QString &key)=0; 59 /** 60 * \brief get a float setting with a default value 61 */ 62 virtual double getFloatSetting(const MythInputInterface * input, const QString &key, double defaultval)=0; 63 /** 64 * \brief save an float setting 65 */ 66 virtual bool saveFloatSetting(const MythInputInterface * input, const QString &key, double newValue)=0; 67 68 public slots: 69 /* helper methods so a plugin can log using myth without to link with myth*/ 70 virtual void logDebug(const QString &msg)=0; 71 virtual void logInfo(const QString &msg)=0; 72 virtual void logWarning(const QString &msg)=0; 73 virtual void logError(const QString &msg)=0; 74 }; 75 76 /** 77 * \defgroup MythUI_Input_Plugin Input plugins 78 * \ingroup MythUI_Input 79 * \brief Access to a particular user input device. 80 * 81 * Read a device and produce events QKeyEvent and send them to the input manager 82 */ 83 84 /** 85 * \interface MythInputInterface 86 * \brief This is the interface an input plugin should implement. 87 * \ingroup MythUI_Input 88 */ 89 class MythInputInterface 90 { 91 92 public: 93 virtual ~MythInputInterface(){}; 94 95 /** 96 * \brief start the input plugin. 97 */ 98 virtual void start()=0; 99 100 /** 101 * \brief stop the input plugin. 102 * 103 * When a input is stopped it should stopped calling onKeyPressed. 104 * Any socket or thread should be stopped too. 105 */ 106 virtual void stop()=0; 107 108 /** 109 * \brief name of the plugin 110 */ 111 virtual const QString name() const=0; 112 113 /** 114 * \brief human readable description 115 */ 116 virtual const QString description() const=0; 117 118 /** 119 * \brief set the input manager 120 * The input manager is where the QKeyEvent need to be sent using \fn MythInputManagerInterface::onKeyPressed 121 */ 122 virtual void setInputManager(MythInputManagerInterface * inputManager)=0; 123 124 }; 125 126 Q_DECLARE_INTERFACE(MythInputInterface, "org.mythtv.MythInputInterface/1.0"); 127 128 #endif // MYTHINPUTINTERFACE_H 129 -
new file mythtv/libs/libmythui/mythinputmanager.cpp
diff --git a/mythtv/libs/libmythui/mythinputmanager.cpp b/mythtv/libs/libmythui/mythinputmanager.cpp new file mode 100755 index 0000000..38cbfa4
- + 1 #include "mythinputmanager.h" 2 3 4 //Qt 5 #include <QPluginLoader> 6 #include <QString> 7 #include <QCoreApplication> 8 #include <QDir> 9 //Myth 10 #include "mythinputinterface.h" 11 #include "mythlogging.h" 12 #include "mythdb.h" 13 #include "mythdirs.h" 14 15 16 17 18 19 /** 20 * \class MythInputManager 21 * \brief This class provide a single entry point to access the different Input available. 22 * 23 * The Input Manager is a singleton class which allow to start() and stop() all 24 * the inputs in one go. 25 * We can also reload the configuration at any point by calling the restart() method. 26 * \ingroup MythUI_Input 27 */ 28 29 MythInputManager * MythInputManager::m_mythInputManager = NULL; 30 31 MythInputManager::MythInputManager(QObject * mainWindow) 32 :MythInputManagerInterface(), 33 m_mainWindow(mainWindow), 34 m_lockedInputs(false) 35 { 36 QDir FiltDir(GetInputsDir()); 37 38 FiltDir.setFilter(QDir::Files | QDir::Readable); 39 if (FiltDir.exists()) 40 { 41 QStringList LibList = FiltDir.entryList(); 42 for (QStringList::iterator i = LibList.begin(); i != LibList.end(); 43 ++i) 44 { 45 QString path = FiltDir.filePath(*i); 46 if (path.length() <= 1) 47 continue; 48 49 LOG(VB_GUI, LOG_INFO, 50 QString("MythInputManager: Loading input plugin '%1'").arg(path)); 51 52 if (!loadPlugin(path)) 53 { 54 LOG(VB_GUI, LOG_ERR, 55 QString("MythInputManager: Failed to load input plugin: %1").arg(path)); 56 } 57 } 58 } 59 else 60 LOG(VB_GUI, LOG_ERR, 61 "MythInputManager: plugin directory '" + FiltDir.absolutePath() + "' doesn't exist?"); 62 } 63 64 const QString MythInputManager::getSettingKey(const MythInputInterface * input, const QString &key)const 65 { 66 //to ensure that to plugin does not override other plugin settings 67 if (input==NULL) 68 { 69 LOG(VB_GUI, LOG_ERR,QString("MythInputManager::getSettingKey: an input parameter is NULL")); 70 return QString(""); 71 } 72 return QString("inputmanager.%1.%2").arg(input->name()).arg(key); 73 } 74 75 76 void MythInputManager::lockInputDevices(bool locked) 77 { 78 m_lockedInputs=locked; 79 } 80 81 bool MythInputManager::loadPlugin(QString fileName) 82 { 83 QPluginLoader pluginLoader(fileName); 84 QObject *plugin = pluginLoader.instance(); 85 MythInputInterface * inputPlugin; 86 if (plugin) 87 { 88 inputPlugin = qobject_cast<MythInputInterface *>(plugin); 89 if (inputPlugin) 90 { 91 m_inputs[inputPlugin->name()]=inputPlugin; 92 m_inputs[inputPlugin->name()]->setInputManager(this); 93 LOG(VB_GUI, LOG_INFO, QString("MythInputManager::loadPlugin(%1): success").arg(inputPlugin->name())); 94 return true; 95 } 96 else 97 { 98 LOG(VB_GUI, LOG_ERR, QString("MythInputManager::loadPlugin(%1): wrong interface").arg(fileName)); 99 } 100 } 101 else 102 { 103 LOG(VB_GUI, LOG_ERR, pluginLoader.errorString ()); 104 LOG(VB_GUI, LOG_ERR, QString("MythInputManager::loadPlugin(%1): can not load").arg(fileName)); 105 } 106 return false; 107 } 108 109 MythInputManager::~MythInputManager() 110 { 111 stop(); 112 } 113 114 /** 115 * \brief start all the inputs. 116 * 117 * The input manager will start the input manager which previously register to it. 118 */ 119 void MythInputManager::start() 120 { 121 LOG(VB_GUI, LOG_ERR, "MythInputManager::start()"); 122 MythInputInterface *input; 123 foreach (input , m_inputs) 124 input->start(); 125 } 126 127 /** 128 * \brief stop all the inputs 129 */ 130 void MythInputManager::stop() 131 { 132 LOG(VB_GUI, LOG_ERR, "MythInputManager::stop()"); 133 MythInputInterface *input; 134 foreach (input , m_inputs) 135 input->stop(); 136 } 137 138 /* The following method are the implementation of MythInputManagerInterface */ 139 140 QString MythInputManager::getSetting(const MythInputInterface * input, const QString &key) 141 { 142 return GetMythDB()->GetSettingOnHost(getSettingKey(input,key), 143 GetMythDB()->GetHostName()); 144 } 145 QString MythInputManager::getSetting(const MythInputInterface * input, const QString &key, const QString &defaultval) 146 { 147 return GetMythDB()->GetSettingOnHost(getSettingKey(input,key), 148 GetMythDB()->GetHostName(),defaultval); 149 } 150 151 bool MythInputManager::saveSetting(const MythInputInterface * input, const QString &key, const QString &newValue) 152 { 153 return GetMythDB()->SaveSettingOnHost(getSettingKey(input,key),newValue, 154 GetMythDB()->GetHostName()); 155 } 156 157 int MythInputManager::getNumSetting(const MythInputInterface * input, const QString &key) 158 { 159 return GetMythDB()->GetNumSettingOnHost(getSettingKey(input,key), 160 GetMythDB()->GetHostName()); 161 } 162 int MythInputManager::getNumSetting(const MythInputInterface * input, const QString &key, int defaultval) 163 { 164 return GetMythDB()->GetNumSettingOnHost(getSettingKey(input,key), 165 GetMythDB()->GetHostName(), defaultval); 166 } 167 168 bool MythInputManager::saveNumSetting(const MythInputInterface * input, const QString &key, int newValue) 169 { 170 QString val = QString::number(newValue); 171 return saveSetting(input,key,val); 172 } 173 174 double MythInputManager::getFloatSetting(const MythInputInterface * input, const QString &key) 175 { 176 return GetMythDB()->GetFloatSettingOnHost(getSettingKey(input,key), 177 GetMythDB()->GetHostName()); 178 } 179 180 double MythInputManager::getFloatSetting(const MythInputInterface * input, const QString &key, double defaultval) 181 { 182 return GetMythDB()->GetFloatSettingOnHost(getSettingKey(input,key), 183 GetMythDB()->GetHostName(), defaultval); 184 } 185 186 bool MythInputManager::saveFloatSetting(const MythInputInterface * input, const QString &key, double newValue) 187 { 188 QString val = QString::number(newValue); 189 return saveSetting(input,key,val); 190 } 191 192 void MythInputManager::onKeyPressed(const QKeyEvent &keyEvent) 193 { 194 LOG(VB_GUI, LOG_ERR, "MythInputManager::onKeyPressed: receive keyPress"); 195 if (!m_lockedInputs) 196 { 197 QKeyEvent * event = new QKeyEvent(keyEvent); 198 QCoreApplication::postEvent(m_mainWindow, event); 199 } 200 } 201 202 void MythInputManager::logDebug(const QString &msg) 203 { 204 LOG(VB_GUI, LOG_DEBUG, QString("MythInputManager: %1").arg(msg)); 205 } 206 207 void MythInputManager::logInfo(const QString &msg) 208 { 209 LOG(VB_GUI, LOG_INFO, QString("MythInputManager: %1").arg(msg)); 210 } 211 212 void MythInputManager::logWarning(const QString &msg) 213 { 214 LOG(VB_GUI, LOG_WARNING, QString("MythInputManager: %1").arg(msg)); 215 } 216 217 void MythInputManager::logError(const QString &msg) 218 { 219 LOG(VB_GUI, LOG_ERR, QString("MythInputManager: %1").arg(msg)); 220 } 221 222 223 224 225 226 -
new file mythtv/libs/libmythui/mythinputmanager.h
diff --git a/mythtv/libs/libmythui/mythinputmanager.h b/mythtv/libs/libmythui/mythinputmanager.h new file mode 100755 index 0000000..9201784
- + 1 #ifndef MYTHINPUTMANAGER_H 2 #define MYTHINPUTMANAGER_H 3 4 #include <QObject> 5 #include <QMap> 6 #include <QHash> 7 #include <QString> 8 #include <QMutex> 9 #include <QMutexLocker> 10 #include <QKeyEvent> 11 #include "mythinputinterface.h" 12 13 class MythMainWindow; 14 15 16 class MythInputManager : public MythInputManagerInterface 17 { 18 public: 19 MythInputManager(QObject * mainWindow); 20 ~MythInputManager(); 21 22 void start(); 23 void restart(); 24 void stop(); 25 26 const MythInputInterface * getInputByName(const QString &inputName); 27 QList<const MythInputInterface*> inputs(); 28 29 void lockInputDevices(bool locked); 30 31 /* MythInputManagerInterface*/ 32 QString getSetting(const MythInputInterface * input, const QString &key); 33 QString getSetting(const MythInputInterface * input, const QString &key, const QString &defaultval); 34 bool saveSetting(const MythInputInterface * input, const QString &key, const QString &newValue); 35 36 int getNumSetting(const MythInputInterface * input, const QString &key); 37 int getNumSetting(const MythInputInterface * input, const QString &key, int defaultval); 38 bool saveNumSetting(const MythInputInterface * input, const QString &key, int newValue); 39 40 double getFloatSetting(const MythInputInterface * input, const QString &key); 41 double getFloatSetting(const MythInputInterface * input, const QString &key, double defaultval); 42 bool saveFloatSetting(const MythInputInterface * input, const QString &key, double newValue); 43 44 void onKeyPressed(const QKeyEvent &keyEvent); 45 46 void logDebug(const QString &); 47 void logInfo(const QString &); 48 void logWarning(const QString &); 49 void logError(const QString &); 50 /* MythInputManagerInterface end */ 51 private: 52 const QString getSettingKey(const MythInputInterface * input, const QString &key)const; 53 bool loadPlugin(QString filename); 54 static MythInputManager * m_mythInputManager; 55 56 QObject *m_mainWindow; 57 QMap<QString, MythInputInterface*> m_inputs; 58 59 bool m_lockedInputs; 60 61 }; 62 63 64 #endif // MYTHINPUTMANAGER_H -
mythtv/libs/libmythui/mythmainwindow.cpp
diff --git a/mythtv/libs/libmythui/mythmainwindow.cpp b/mythtv/libs/libmythui/mythmainwindow.cpp index e69e4fd..fb3ae51 100644
a b using namespace std; 52 52 #include "lircevent.h" 53 53 #include "mythudplistener.h" 54 54 #include "mythrender_base.h" 55 #include "mythinputmanager.h" 55 56 56 57 #ifdef USING_APPLEREMOTE 57 58 #include "AppleRemoteListener.h" … … class MythMainWindowPrivate 173 174 174 175 m_udpListener(NULL), 175 176 176 m_pendingUpdate(false) 177 m_pendingUpdate(false), 178 m_inputManager(NULL) 177 179 { 180 178 181 } 179 182 180 183 int TranslateKeyNum(QKeyEvent *e); … … class MythMainWindowPrivate 256 259 MythUDPListener *m_udpListener; 257 260 258 261 bool m_pendingUpdate; 262 MythInputManager * m_inputManager; 259 263 }; 260 264 261 265 // Make keynum in QKeyEvent be equivalent to what's in QKeySequence … … MythMainWindow::MythMainWindow(const bool useDB) 423 427 d->lircThread = NULL; 424 428 StartLIRC(); 425 429 430 d->m_inputManager = new MythInputManager(this); 431 d->m_inputManager->start(); 432 433 426 434 #ifdef USE_JOYSTICK_MENU 427 435 d->ignore_joystick_keys = false; 428 436 … … MythMainWindow::~MythMainWindow() 495 503 d->lircThread = NULL; 496 504 } 497 505 #endif 506 if (d->m_inputManager) 507 { 508 delete d->m_inputManager; 509 } 510 498 511 499 512 #ifdef USE_JOYSTICK_MENU 500 513 if (d->joystickThread) … … void MythMainWindow::LockInputDevices( bool locked ) 2432 2445 else 2433 2446 LOG(VB_GENERAL, LOG_INFO, "Unlocking input devices"); 2434 2447 2448 d->m_inputManager->lockInputDevices(locked); 2449 2435 2450 #ifdef USE_LIRC 2436 2451 d->ignore_lirc_keys = locked; 2437 2452 #endif