Changeset 36929 in vbox
- Timestamp:
- May 3, 2011 12:45:50 PM (14 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.cpp
r36519 r36929 68 68 void UIMachineSettingsSerial::polishTab() 69 69 { 70 ulong uIRQ, uIOBase; 71 bool fStd = vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), uIRQ, uIOBase); 72 KPortMode mode = vboxGlobal().toPortMode(mCbMode->currentText()); 73 70 74 mGbSerial->setEnabled(m_pParent->isMachineOffline()); 71 75 mLbNumber->setEnabled(m_pParent->isMachineOffline()); 72 76 mCbNumber->setEnabled(m_pParent->isMachineOffline()); 73 77 mLbIRQ->setEnabled(m_pParent->isMachineOffline()); 74 mLeIRQ->setEnabled( m_pParent->isMachineOffline());78 mLeIRQ->setEnabled(!fStd && m_pParent->isMachineOffline()); 75 79 mLbIOPort->setEnabled(m_pParent->isMachineOffline()); 76 mLeIOPort->setEnabled( m_pParent->isMachineOffline());80 mLeIOPort->setEnabled(!fStd && m_pParent->isMachineOffline()); 77 81 mLbMode->setEnabled(m_pParent->isMachineOffline()); 78 82 mCbMode->setEnabled(m_pParent->isMachineOffline()); 79 mCbPipe->setEnabled(m _pParent->isMachineOffline());83 mCbPipe->setEnabled(mode == KPortMode_HostPipe && m_pParent->isMachineOffline()); 80 84 mLbPath->setEnabled(m_pParent->isMachineOffline()); 81 mLePath->setEnabled(m_pParent->isMachineOffline()); 82 } 83 84 void UIMachineSettingsSerial::fetchPortData(const UISerialPortData &data) 85 { 86 /* Load port slot number: */ 87 m_iSlot = data.m_iSlot; 88 89 /* Fetch port data: */ 90 mGbSerial->setChecked(data.m_fPortEnabled); 91 mCbNumber->setCurrentIndex(mCbNumber->findText(vboxGlobal().toCOMPortName(data.m_uIRQ, data.m_uIOBase))); 92 mLeIRQ->setText(QString::number(data.m_uIRQ)); 93 mLeIOPort->setText("0x" + QString::number(data.m_uIOBase, 16).toUpper()); 94 mCbMode->setCurrentIndex(mCbMode->findText(vboxGlobal().toString(data.m_hostMode))); 95 mCbPipe->setChecked(data.m_fServer); 96 mLePath->setText(data.m_strPath); 85 mLePath->setEnabled(mode != KPortMode_Disconnected && m_pParent->isMachineOffline()); 86 } 87 88 void UIMachineSettingsSerial::fetchPortData(const UICacheSettingsMachineSerialPort &portCache) 89 { 90 /* Get port data: */ 91 const UIDataSettingsMachineSerialPort &portData = portCache.base(); 92 93 /* Load port number: */ 94 m_iSlot = portData.m_iSlot; 95 96 /* Load port data: */ 97 mGbSerial->setChecked(portData.m_fPortEnabled); 98 mCbNumber->setCurrentIndex(mCbNumber->findText(vboxGlobal().toCOMPortName(portData.m_uIRQ, portData.m_uIOBase))); 99 mLeIRQ->setText(QString::number(portData.m_uIRQ)); 100 mLeIOPort->setText("0x" + QString::number(portData.m_uIOBase, 16).toUpper()); 101 mCbMode->setCurrentIndex(mCbMode->findText(vboxGlobal().toString(portData.m_hostMode))); 102 mCbPipe->setChecked(portData.m_fServer); 103 mLePath->setText(portData.m_strPath); 97 104 98 105 /* Ensure everything is up-to-date */ … … 100 107 } 101 108 102 void UIMachineSettingsSerial::uploadPortData(UISerialPortData &data) 103 { 104 /* Upload port data: */ 105 data.m_fPortEnabled = mGbSerial->isChecked(); 106 data.m_uIRQ = mLeIRQ->text().toULong(NULL, 0); 107 data.m_uIOBase = mLeIOPort->text().toULong (NULL, 0); 108 data.m_fServer = mCbPipe->isChecked(); 109 data.m_hostMode = vboxGlobal().toPortMode(mCbMode->currentText()); 110 data.m_strPath = QDir::toNativeSeparators(mLePath->text()); 109 void UIMachineSettingsSerial::uploadPortData(UICacheSettingsMachineSerialPort &portCache) 110 { 111 /* Prepare port data: */ 112 UIDataSettingsMachineSerialPort portData = portCache.base(); 113 114 /* Save port data: */ 115 portData.m_fPortEnabled = mGbSerial->isChecked(); 116 portData.m_uIRQ = mLeIRQ->text().toULong(NULL, 0); 117 portData.m_uIOBase = mLeIOPort->text().toULong (NULL, 0); 118 portData.m_fServer = mCbPipe->isChecked(); 119 portData.m_hostMode = vboxGlobal().toPortMode(mCbMode->currentText()); 120 portData.m_strPath = QDir::toNativeSeparators(mLePath->text()); 121 122 /* Cache port data to port cache: */ 123 portCache.cacheCurrentData(portData); 111 124 } 112 125 … … 206 219 layout->addWidget (mTabWidget); 207 220 208 /* Load port data: */221 /* How many ports to display: */ 209 222 ulong uCount = vboxGlobal().virtualBox().GetSystemProperties().GetSerialPortCount(); 210 /* A pply internal variables data to QWidget(s): */211 for (ulong iSlot = 0; iSlot < uCount; ++iSlot)212 { 213 /* Creating port 'spage: */223 /* Add corresponding tab pages to parent tab widget: */ 224 for (ulong uPort = 0; uPort < uCount; ++uPort) 225 { 226 /* Creating port page: */ 214 227 UIMachineSettingsSerial *pPage = new UIMachineSettingsSerial(this); 215 216 /* Attach port's page to Tab Widget: */217 228 mTabWidget->addTab(pPage, pPage->pageTitle()); 218 219 } 220 221 /* Applying language settings */ 222 retranslateUi(); 229 } 223 230 } 224 231 … … 230 237 UISettingsPageMachine::fetchData(data); 231 238 232 /* Load port data: */ 233 ulong uCount = vboxGlobal().virtualBox().GetSystemProperties().GetSerialPortCount(); 234 for (ulong uSlot = 0; uSlot < uCount; ++uSlot) 235 { 236 /* Get port: */ 237 const CSerialPort &port = m_machine.GetSerialPort(uSlot); 238 239 /* Prepare port's data container: */ 240 UISerialPortData data; 241 242 /* Load options: */ 243 data.m_iSlot = uSlot; 244 data.m_fPortEnabled = port.GetEnabled(); 245 data.m_uIRQ = port.GetIRQ(); 246 data.m_uIOBase = port.GetIOBase(); 247 data.m_hostMode = port.GetHostMode(); 248 data.m_fServer = port.GetServer(); 249 data.m_strPath = port.GetPath(); 250 251 /* Append adapter's data container: */ 252 m_cache.m_items << data; 239 /* For each serial port: */ 240 for (int iSlot = 0; iSlot < mTabWidget->count(); ++iSlot) 241 { 242 /* Prepare port data: */ 243 UIDataSettingsMachineSerialPort portData; 244 245 /* Check if port is valid: */ 246 const CSerialPort &port = m_machine.GetSerialPort(iSlot); 247 if (!port.isNull()) 248 { 249 /* Gather options: */ 250 portData.m_iSlot = iSlot; 251 portData.m_fPortEnabled = port.GetEnabled(); 252 portData.m_uIRQ = port.GetIRQ(); 253 portData.m_uIOBase = port.GetIOBase(); 254 portData.m_hostMode = port.GetHostMode(); 255 portData.m_fServer = port.GetServer(); 256 portData.m_strPath = port.GetPath(); 257 } 258 259 /* Cache port data: */ 260 m_cache.child(iSlot).cacheInitialData(portData); 253 261 } 254 262 … … 261 269 void UIMachineSettingsSerialPage::getFromCache() 262 270 { 271 /* Setup tab order: */ 263 272 Assert(firstWidget()); 264 273 setTabOrder(firstWidget(), mTabWidget->focusProxy()); 265 274 QWidget *pLastFocusWidget = mTabWidget->focusProxy(); 266 275 267 ulong uCount = qMin(mTabWidget->count(), m_cache.m_items.size()); 268 /* Apply internal variables data to QWidget(s): */ 269 for (ulong iSlot = 0; iSlot < uCount; ++iSlot) 270 { 271 /* Getting adapter's page: */ 272 UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iSlot)); 273 274 /* Loading port's data into page: */ 275 pPage->fetchPortData(m_cache.m_items[iSlot]); 276 /* For each serial port: */ 277 for (int iPort = 0; iPort < mTabWidget->count(); ++iPort) 278 { 279 /* Get port page: */ 280 UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iPort)); 281 282 /* Load port data to page: */ 283 pPage->fetchPortData(m_cache.child(iPort)); 276 284 277 285 /* Setup page validation: */ … … 293 301 void UIMachineSettingsSerialPage::putToCache() 294 302 { 295 /* Gather internal variables data from QWidget(s): */296 for (int i Slot = 0; iSlot < m_cache.m_items.size(); ++iSlot)297 { 298 /* Getting adapter'spage: */299 UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(i Slot));300 301 /* Loading Adapter's data from page: */302 pPage->uploadPortData(m_cache. m_items[iSlot]);303 /* For each serial port: */ 304 for (int iPort = 0; iPort < mTabWidget->count(); ++iPort) 305 { 306 /* Getting port page: */ 307 UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iPort)); 308 309 /* Gather & cache port data: */ 310 pPage->uploadPortData(m_cache.child(iPort)); 303 311 } 304 312 } … … 311 319 UISettingsPageMachine::fetchData(data); 312 320 313 if (isMachineOffline()) 314 { 315 /* Gather corresponding values from internal variables: */ 316 for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot) 321 /* Check if ports data was changed: */ 322 if (m_cache.wasChanged()) 323 { 324 /* For each serial port: */ 325 for (int iPort = 0; iPort < mTabWidget->count(); ++iPort) 317 326 { 318 /* Get adapter: */ 319 CSerialPort port = m_machine.GetSerialPort(iSlot); 320 321 /* Get cached data for this slot: */ 322 const UISerialPortData &data = m_cache.m_items[iSlot]; 323 324 /* Save options: */ 325 port.SetEnabled(data.m_fPortEnabled); 326 port.SetIRQ(data.m_uIRQ); 327 port.SetIOBase(data.m_uIOBase); 328 port.SetServer(data.m_fServer); 329 port.SetPath(data.m_strPath); 330 /* This *must* be last. The host mode will be changed to disconnected if 331 * some of the necessary settings above will not meet the requirements for 332 * the selected mode. */ 333 port.SetHostMode(data.m_hostMode); 327 /* Check if port data was changed: */ 328 const UICacheSettingsMachineSerialPort &portCache = m_cache.child(iPort); 329 if (portCache.wasChanged()) 330 { 331 /* Check if port still valid: */ 332 CSerialPort port = m_machine.GetSerialPort(iPort); 333 if (!port.isNull()) 334 { 335 /* Get port data: */ 336 const UIDataSettingsMachineSerialPort &portData = portCache.data(); 337 338 /* Store adapter data: */ 339 if (isMachineOffline()) 340 { 341 port.SetEnabled(portData.m_fPortEnabled); 342 port.SetIRQ(portData.m_uIRQ); 343 port.SetIOBase(portData.m_uIOBase); 344 port.SetServer(portData.m_fServer); 345 port.SetPath(portData.m_strPath); 346 /* This *must* be last. The host mode will be changed to disconnected if 347 * some of the necessary settings above will not meet the requirements for 348 * the selected mode. */ 349 port.SetHostMode(portData.m_hostMode); 350 } 351 } 352 } 334 353 } 335 354 } … … 416 435 { 417 436 /* Get the count of serial port tabs: */ 418 for (int i TabIndex = 0; iTabIndex < mTabWidget->count(); ++iTabIndex)419 { 420 mTabWidget->setTabEnabled(i TabIndex,437 for (int iPort = 0; iPort < mTabWidget->count(); ++iPort) 438 { 439 mTabWidget->setTabEnabled(iPort, 421 440 isMachineOffline() || 422 (isMachineInValidMode() && m_cache.m_items[iTabIndex].m_fPortEnabled)); 423 UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iTabIndex)); 424 Assert(pTab); 441 (isMachineInValidMode() && m_cache.child(iPort).base().m_fPortEnabled)); 442 UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iPort)); 425 443 pTab->polishTab(); 426 444 } -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.h
r36357 r36929 28 28 class QITabWidget; 29 29 30 /* Machine settings / Networkpage / Port data: */31 struct UI SerialPortData30 /* Machine settings / Serial page / Port data: */ 31 struct UIDataSettingsMachineSerialPort 32 32 { 33 /* Default constructor: */ 34 UIDataSettingsMachineSerialPort() 35 : m_iSlot(-1) 36 , m_fPortEnabled(false) 37 , m_uIRQ(0) 38 , m_uIOBase(0) 39 , m_hostMode(KPortMode_Disconnected) 40 , m_fServer(false) 41 , m_strPath(QString()) {} 42 /* Functions: */ 43 bool equal(const UIDataSettingsMachineSerialPort &other) const 44 { 45 return (m_iSlot == other.m_iSlot) && 46 (m_fPortEnabled == other.m_fPortEnabled) && 47 (m_uIRQ == other.m_uIRQ) && 48 (m_uIOBase == other.m_uIOBase) && 49 (m_hostMode == other.m_hostMode) && 50 (m_fServer == other.m_fServer) && 51 (m_strPath == other.m_strPath); 52 } 53 /* Operators: */ 54 bool operator==(const UIDataSettingsMachineSerialPort &other) const { return equal(other); } 55 bool operator!=(const UIDataSettingsMachineSerialPort &other) const { return !equal(other); } 56 /* Variables: */ 33 57 int m_iSlot; 34 58 bool m_fPortEnabled; … … 39 63 QString m_strPath; 40 64 }; 65 typedef UISettingsCache<UIDataSettingsMachineSerialPort> UICacheSettingsMachineSerialPort; 41 66 42 /* Machine settings / Serial page / Cache: */43 struct UI SettingsCacheMachineSerial67 /* Machine settings / Serial page / Ports data: */ 68 struct UIDataSettingsMachineSerial 44 69 { 45 QList<UISerialPortData> m_items; 70 /* Default constructor: */ 71 UIDataSettingsMachineSerial() {} 72 /* Operators: */ 73 bool operator==(const UIDataSettingsMachineSerial& /* other */) const { return true; } 74 bool operator!=(const UIDataSettingsMachineSerial& /* other */) const { return false; } 46 75 }; 76 typedef UISettingsCachePool<UIDataSettingsMachineSerial, UICacheSettingsMachineSerialPort> UICacheSettingsMachineSerial; 47 77 48 78 class UIMachineSettingsSerial : public QIWithRetranslateUI<QWidget>, … … 57 87 void polishTab(); 58 88 59 void fetchPortData(const UI SerialPortData&data);60 void uploadPortData(UI SerialPortData&data);89 void fetchPortData(const UICacheSettingsMachineSerialPort &data); 90 void uploadPortData(UICacheSettingsMachineSerialPort &data); 61 91 62 92 void setValidator (QIWidgetValidator *aVal); … … 122 152 123 153 /* Cache: */ 124 UI SettingsCacheMachineSerial m_cache;154 UICacheSettingsMachineSerial m_cache; 125 155 }; 126 156
Note:
See TracChangeset
for help on using the changeset viewer.