00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date: 2009-07-07 16:57:15 +0200 (Di, 07 Jul 2009) $ 00006 Version: $Revision: 18019 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "QmitkInputDevicesPrefPage.h" 00019 00020 #include <QLabel> 00021 #include <QPushButton> 00022 #include <QFormLayout> 00023 #include <QCheckBox> 00024 #include <QHashIterator> 00025 #include <QMessageBox> 00026 00027 #include <berryIPreferencesService.h> 00028 #include <berryPlatform.h> 00029 00030 #include <mitkIInputDeviceRegistry.h> 00031 #include <mitkIInputDeviceDescriptor.h> 00032 #include <mitkCoreExtConstants.h> 00033 00034 00035 QmitkInputDevicesPrefPage::QmitkInputDevicesPrefPage() 00036 : m_MainControl(0) 00037 { 00038 // gets the old setting of the preferences and loads them into the preference node 00039 berry::IPreferencesService::Pointer prefService 00040 = berry::Platform::GetServiceRegistry() 00041 .GetServiceById<berry::IPreferencesService>(berry::IPreferencesService::ID); 00042 this->m_InputDevicesPrefNode = prefService->GetSystemPreferences()->Node(mitk::CoreExtConstants::INPUTDEVICE_PREFERENCES); 00043 } 00044 00045 void QmitkInputDevicesPrefPage::Init(berry::IWorkbench::Pointer ) 00046 { 00047 } 00048 00049 void QmitkInputDevicesPrefPage::CreateQtControl(QWidget* parent) 00050 { 00051 m_MainControl = new QWidget(parent); 00052 QVBoxLayout *layout = new QVBoxLayout; 00053 00054 mitk::IInputDeviceRegistry::Pointer inputDeviceRegistry = 00055 berry::Platform::GetServiceRegistry().GetServiceById<mitk::IInputDeviceRegistry>(mitk::CoreExtConstants::INPUTDEVICE_SERVICE); 00056 std::vector<mitk::IInputDeviceDescriptor::Pointer> temp(inputDeviceRegistry->GetInputDevices()); 00057 00058 for(std::vector<mitk::IInputDeviceDescriptor::Pointer>::const_iterator it = temp.begin(); it != temp.end();++it) 00059 { 00060 QCheckBox* checkBox = new QCheckBox(QString::fromStdString((*it)->GetName()),m_MainControl); 00061 layout->addWidget(checkBox); 00062 m_InputDevices.insert(checkBox,(*it)->GetID()); 00063 } 00064 00065 layout->addStretch(); 00066 m_MainControl->setLayout(layout); 00067 this->Update(); 00068 } 00069 00070 QWidget* QmitkInputDevicesPrefPage::GetQtControl() const 00071 { 00072 return m_MainControl; 00073 } 00074 00075 bool QmitkInputDevicesPrefPage::PerformOk() 00076 { 00077 bool result = true; 00078 mitk::IInputDeviceRegistry::Pointer inputDeviceRegistry = 00079 berry::Platform::GetServiceRegistry().GetServiceById<mitk::IInputDeviceRegistry>(mitk::CoreExtConstants::INPUTDEVICE_SERVICE); 00080 QHashIterator<QCheckBox*, std::string> it(m_InputDevices); 00081 while (it.hasNext()) 00082 { 00083 it.next(); 00084 mitk::IInputDeviceDescriptor::Pointer inputdevice(inputDeviceRegistry->Find(it.value())); 00085 if(it.key()->isChecked()) 00086 { 00087 result &= inputdevice->CreateInputDevice()->RegisterInputDevice(); 00088 } 00089 else 00090 { 00091 result &= inputdevice->CreateInputDevice()->UnRegisterInputDevice(); 00092 00093 // temporary fix, unclean solution: 00094 // e.g. user activates SpaceNavigator and leaves the 00095 // the wiimote deactivated, the user will get the warning 00096 // despite the fact that it has never been activated 00097 if(it.value() == "org.mitk.inputdevices.wiimote") 00098 { 00099 // until now 2010-09-06 there were some unfixed problems 00100 // with reconnecting the wiimote after disconnecting it. 00101 // It was suggested that it might have something to do 00102 // with the type of stack, that is used for the pairing. 00103 // MS-Stack for example does not work properly. 00104 QMessageBox::information(NULL,"WiiMote supportproblem", 00105 "A reconnect of the WiiMote is not yet supported! " 00106 "Please restart the application, if you want to " 00107 "activate the Wii remote/s again."); 00108 } 00109 } 00110 00111 if(result) 00112 { 00113 this->m_InputDevicesPrefNode->PutBool(it.value(),it.key()->isChecked()); 00114 } 00115 } 00116 return result; 00117 } 00118 00119 void QmitkInputDevicesPrefPage::PerformCancel() 00120 { 00121 00122 } 00123 00124 void QmitkInputDevicesPrefPage::Update() 00125 { 00126 QHashIterator<QCheckBox*, std::string> it(m_InputDevices); 00127 while (it.hasNext()) 00128 { 00129 it.next(); 00130 it.key()->setChecked(this->m_InputDevicesPrefNode->GetBool(it.value(), false)); 00131 } 00132 }