Changeset 66366 in vbox
- Timestamp:
- Mar 30, 2017 2:06:55 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 114309
- 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
r66345 r66366 90 90 { 91 91 /** Constructs data. */ 92 UIDataSettingsMachineSerial() {} 92 UIDataSettingsMachineSerial() 93 : m_ports(QList<UIDataSettingsMachineSerialPort>()) 94 {} 93 95 94 96 /** Returns whether the @a other passed data is equal to this one. */ 95 bool operator==(const UIDataSettingsMachineSerial & /* other */) const { return true; } 97 bool equal(const UIDataSettingsMachineSerial &other) const 98 { 99 return true 100 && (m_ports == other.m_ports) 101 ; 102 } 103 104 /** Returns whether the @a other passed data is equal to this one. */ 105 bool operator==(const UIDataSettingsMachineSerial &other) const { return equal(other); } 96 106 /** Returns whether the @a other passed data is different from this one. */ 97 bool operator!=(const UIDataSettingsMachineSerial & /* other */) const { return false; } 107 bool operator!=(const UIDataSettingsMachineSerial &other) const { return !equal(other); } 108 109 /** Holds the port list. */ 110 QList<UIDataSettingsMachineSerialPort> m_ports; 98 111 }; 99 112 … … 111 124 void polishTab(); 112 125 113 void fetchPortData(const UISettingsCacheMachineSerialPort &data);114 void uploadPortData(UISettingsCacheMachineSerialPort &data);115 116 QWidget * setOrderAfter (QWidget *aAfter);126 void loadPortData(const UIDataSettingsMachineSerialPort &portData); 127 void savePortData(UIDataSettingsMachineSerialPort &portData); 128 129 QWidget *setOrderAfter(QWidget *pAfter); 117 130 118 131 QString pageTitle() const; … … 125 138 private slots: 126 139 127 void mGbSerialToggled (bool aOn);128 void mCbNumberActivated (const QString &aText);129 void mCbModeActivated (const QString &aText);140 void sltGbSerialToggled(bool fOn); 141 void sltCbNumberActivated(const QString &strText); 142 void sltCbModeActivated(const QString &strText); 130 143 131 144 private: … … 144 157 145 158 UIMachineSettingsSerial::UIMachineSettingsSerial(UIMachineSettingsSerialPage *pParent) 146 : QIWithRetranslateUI<QWidget> 159 : QIWithRetranslateUI<QWidget>(0) 147 160 , m_pParent(pParent) 148 161 , m_iSlot(-1) 149 162 { 150 /* Apply UI decorations */151 Ui::UIMachineSettingsSerial::setupUi 152 153 /* Setup validation */154 mLeIRQ->setValidator (new QIULongValidator(0, 255, this));155 mLeIOPort->setValidator (new QIULongValidator(0, 0xFFFF, this));156 mLePath->setValidator (new QRegExpValidator (QRegExp(".+"), this));157 158 /* Setup constraints */159 mLeIRQ->setFixedWidth (mLeIRQ->fontMetrics().width("8888"));160 mLeIOPort->setFixedWidth (mLeIOPort->fontMetrics().width("8888888"));161 162 /* Set initial values */163 /* Apply UI decorations: */ 164 Ui::UIMachineSettingsSerial::setupUi(this); 165 166 /* Setup validation: */ 167 mLeIRQ->setValidator(new QIULongValidator(0, 255, this)); 168 mLeIOPort->setValidator(new QIULongValidator(0, 0xFFFF, this)); 169 mLePath->setValidator(new QRegExpValidator(QRegExp(".+"), this)); 170 171 /* Setup constraints: */ 172 mLeIRQ->setFixedWidth(mLeIRQ->fontMetrics().width("8888")); 173 mLeIOPort->setFixedWidth(mLeIOPort->fontMetrics().width("8888888")); 174 175 /* Set initial values: */ 163 176 /* Note: If you change one of the following don't forget retranslateUi. */ 164 mCbNumber->insertItem (0, vboxGlobal().toCOMPortName(0, 0));165 mCbNumber->insertItems 166 167 mCbMode->addItem 168 mCbMode->addItem 169 mCbMode->addItem 170 mCbMode->addItem 171 mCbMode->addItem 172 173 /* Setup connections */174 connect (mGbSerial, SIGNAL (toggled(bool)),175 this, SLOT (mGbSerialToggled(bool)));176 connect (mCbNumber, SIGNAL (activated(const QString &)),177 this, SLOT (mCbNumberActivated(const QString &)));178 connect (mCbMode, SIGNAL (activated(const QString &)),179 this, SLOT (mCbModeActivated(const QString &)));177 mCbNumber->insertItem(0, vboxGlobal().toCOMPortName(0, 0)); 178 mCbNumber->insertItems(0, vboxGlobal().COMPortNames()); 179 180 mCbMode->addItem(""); /* KPortMode_Disconnected */ 181 mCbMode->addItem(""); /* KPortMode_HostPipe */ 182 mCbMode->addItem(""); /* KPortMode_HostDevice */ 183 mCbMode->addItem(""); /* KPortMode_RawFile */ 184 mCbMode->addItem(""); /* KPortMode_TCP */ 185 186 /* Setup connections: */ 187 connect(mGbSerial, SIGNAL(toggled(bool)), 188 this, SLOT(sltGbSerialToggled(bool))); 189 connect(mCbNumber, SIGNAL(activated(const QString &)), 190 this, SLOT(sltCbNumberActivated(const QString &))); 191 connect(mCbMode, SIGNAL(activated(const QString &)), 192 this, SLOT(sltCbModeActivated(const QString &))); 180 193 181 194 /* Prepare validation: */ 182 195 prepareValidation(); 183 196 184 /* Apply ing language settings*/197 /* Apply language settings: */ 185 198 retranslateUi(); 186 199 } … … 188 201 void UIMachineSettingsSerial::polishTab() 189 202 { 203 /* Polish port page: */ 190 204 ulong uIRQ, uIOBase; 191 bool fStd = vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), uIRQ, uIOBase); 192 KPortMode mode = gpConverter->fromString<KPortMode>(mCbMode->currentText()); 193 205 const bool fStd = vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), uIRQ, uIOBase); 206 const KPortMode enmMode = gpConverter->fromString<KPortMode>(mCbMode->currentText()); 194 207 mGbSerial->setEnabled(m_pParent->isMachineOffline()); 195 208 mLbNumber->setEnabled(m_pParent->isMachineOffline()); … … 201 214 mLbMode->setEnabled(m_pParent->isMachineOffline()); 202 215 mCbMode->setEnabled(m_pParent->isMachineOffline()); 203 mCbPipe->setEnabled( (mode == KPortMode_HostPipe || mode == KPortMode_TCP)204 && m_pParent->isMachineOffline());216 mCbPipe->setEnabled( (enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP) 217 && m_pParent->isMachineOffline()); 205 218 mLbPath->setEnabled(m_pParent->isMachineOffline()); 206 mLePath->setEnabled(mode != KPortMode_Disconnected && m_pParent->isMachineOffline()); 207 } 208 209 void UIMachineSettingsSerial::fetchPortData(const UISettingsCacheMachineSerialPort &portCache) 210 { 211 /* Get port data: */ 212 const UIDataSettingsMachineSerialPort &portData = portCache.base(); 213 219 mLePath->setEnabled(enmMode != KPortMode_Disconnected && m_pParent->isMachineOffline()); 220 } 221 222 void UIMachineSettingsSerial::loadPortData(const UIDataSettingsMachineSerialPort &portData) 223 { 214 224 /* Load port number: */ 215 225 m_iSlot = portData.m_iSlot; … … 225 235 226 236 /* Ensure everything is up-to-date */ 227 mGbSerialToggled(mGbSerial->isChecked()); 228 } 229 230 void UIMachineSettingsSerial::uploadPortData(UISettingsCacheMachineSerialPort &portCache) 231 { 232 /* Prepare port data: */ 233 UIDataSettingsMachineSerialPort portData = portCache.base(); 234 237 sltGbSerialToggled(mGbSerial->isChecked()); 238 } 239 240 void UIMachineSettingsSerial::savePortData(UIDataSettingsMachineSerialPort &portData) 241 { 235 242 /* Save port data: */ 236 243 portData.m_fPortEnabled = mGbSerial->isChecked(); 237 244 portData.m_uIRQ = mLeIRQ->text().toULong(NULL, 0); 238 portData.m_uIOBase = mLeIOPort->text().toULong 245 portData.m_uIOBase = mLeIOPort->text().toULong(NULL, 0); 239 246 portData.m_fServer = !mCbPipe->isChecked(); 240 247 portData.m_hostMode = gpConverter->fromString<KPortMode>(mCbMode->currentText()); 241 248 portData.m_strPath = QDir::toNativeSeparators(mLePath->text()); 242 243 /* Cache port data to port cache: */ 244 portCache.cacheCurrentData(portData); 245 } 246 247 QWidget* UIMachineSettingsSerial::setOrderAfter (QWidget *aAfter) 248 { 249 setTabOrder (aAfter, mGbSerial); 250 setTabOrder (mGbSerial, mCbNumber); 251 setTabOrder (mCbNumber, mLeIRQ); 252 setTabOrder (mLeIRQ, mLeIOPort); 253 setTabOrder (mLeIOPort, mCbMode); 254 setTabOrder (mCbMode, mCbPipe); 255 setTabOrder (mCbPipe, mLePath); 249 } 250 251 QWidget *UIMachineSettingsSerial::setOrderAfter(QWidget *pAfter) 252 { 253 setTabOrder(pAfter, mGbSerial); 254 setTabOrder(mGbSerial, mCbNumber); 255 setTabOrder(mCbNumber, mLeIRQ); 256 setTabOrder(mLeIRQ, mLeIOPort); 257 setTabOrder(mLeIOPort, mCbMode); 258 setTabOrder(mCbMode, mCbPipe); 259 setTabOrder(mCbPipe, mLePath); 256 260 return mLePath; 257 261 } … … 265 269 { 266 270 ulong a, b; 267 return !vboxGlobal().toCOMPortNumbers 271 return !vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), a, b); 268 272 } 269 273 270 274 void UIMachineSettingsSerial::retranslateUi() 271 275 { 272 /* Translate uic generated strings */273 Ui::UIMachineSettingsSerial::retranslateUi 274 275 mCbNumber->setItemText (mCbNumber->count() - 1, vboxGlobal().toCOMPortName(0, 0));276 277 mCbMode->setItemText (4, gpConverter->toString(KPortMode_TCP));278 mCbMode->setItemText (3, gpConverter->toString(KPortMode_RawFile));279 mCbMode->setItemText (2, gpConverter->toString(KPortMode_HostDevice));280 mCbMode->setItemText (1, gpConverter->toString(KPortMode_HostPipe));281 mCbMode->setItemText (0, gpConverter->toString(KPortMode_Disconnected));282 } 283 284 void UIMachineSettingsSerial:: mGbSerialToggled (bool aOn)285 { 286 if ( aOn)287 { 288 mCbNumberActivated(mCbNumber->currentText());289 mCbModeActivated(mCbMode->currentText());276 /* Translate uic generated strings: */ 277 Ui::UIMachineSettingsSerial::retranslateUi(this); 278 279 mCbNumber->setItemText(mCbNumber->count() - 1, vboxGlobal().toCOMPortName(0, 0)); 280 281 mCbMode->setItemText(4, gpConverter->toString(KPortMode_TCP)); 282 mCbMode->setItemText(3, gpConverter->toString(KPortMode_RawFile)); 283 mCbMode->setItemText(2, gpConverter->toString(KPortMode_HostDevice)); 284 mCbMode->setItemText(1, gpConverter->toString(KPortMode_HostPipe)); 285 mCbMode->setItemText(0, gpConverter->toString(KPortMode_Disconnected)); 286 } 287 288 void UIMachineSettingsSerial::sltGbSerialToggled(bool fOn) 289 { 290 if (fOn) 291 { 292 sltCbNumberActivated(mCbNumber->currentText()); 293 sltCbModeActivated(mCbMode->currentText()); 290 294 } 291 295 … … 294 298 } 295 299 296 void UIMachineSettingsSerial:: mCbNumberActivated (const QString &aText)297 { 298 ulong IRQ,IOBase;299 bool std = vboxGlobal().toCOMPortNumbers (aText, IRQ,IOBase);300 301 mLeIRQ->setEnabled (!std);302 mLeIOPort->setEnabled (!std);303 if ( std)304 { 305 mLeIRQ->setText (QString::number (IRQ));306 mLeIOPort->setText ("0x" + QString::number (IOBase, 16).toUpper());300 void UIMachineSettingsSerial::sltCbNumberActivated(const QString &strText) 301 { 302 ulong uIRQ, uIOBase; 303 bool fStd = vboxGlobal().toCOMPortNumbers(strText, uIRQ, uIOBase); 304 305 mLeIRQ->setEnabled(!fStd); 306 mLeIOPort->setEnabled(!fStd); 307 if (fStd) 308 { 309 mLeIRQ->setText(QString::number(uIRQ)); 310 mLeIOPort->setText("0x" + QString::number(uIOBase, 16).toUpper()); 307 311 } 308 312 … … 311 315 } 312 316 313 void UIMachineSettingsSerial:: mCbModeActivated (const QString &aText)314 { 315 KPortMode mode = gpConverter->fromString<KPortMode> (aText);316 mCbPipe->setEnabled (mode == KPortMode_HostPipe || mode == KPortMode_TCP);317 mLePath->setEnabled (mode != KPortMode_Disconnected);317 void UIMachineSettingsSerial::sltCbModeActivated(const QString &strText) 318 { 319 KPortMode enmMode = gpConverter->fromString<KPortMode>(strText); 320 mCbPipe->setEnabled(enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP); 321 mLePath->setEnabled(enmMode != KPortMode_Disconnected); 318 322 319 323 /* Revalidate: */ … … 361 365 m_pCache->clear(); 362 366 367 /* Prepare initial data: */ 368 UIDataSettingsMachineSerial initialData; 369 363 370 /* For each serial port: */ 364 371 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 365 372 { 366 373 /* Prepare port data: */ 367 UIDataSettingsMachineSerialPort portData;374 UIDataSettingsMachineSerialPort initialPortData; 368 375 369 376 /* Check if port is valid: */ … … 372 379 { 373 380 /* Gather options: */ 374 portData.m_iSlot = iSlot;375 portData.m_fPortEnabled = port.GetEnabled();376 portData.m_uIRQ = port.GetIRQ();377 portData.m_uIOBase = port.GetIOBase();378 portData.m_hostMode = port.GetHostMode();379 portData.m_fServer = port.GetServer();380 portData.m_strPath = port.GetPath();381 initialPortData.m_iSlot = iSlot; 382 initialPortData.m_fPortEnabled = port.GetEnabled(); 383 initialPortData.m_uIRQ = port.GetIRQ(); 384 initialPortData.m_uIOBase = port.GetIOBase(); 385 initialPortData.m_hostMode = port.GetHostMode(); 386 initialPortData.m_fServer = port.GetServer(); 387 initialPortData.m_strPath = port.GetPath(); 381 388 } 382 389 383 /* Cache port data: */ 384 m_pCache->child(iSlot).cacheInitialData(portData); 385 } 390 /* Append initial port data: */ 391 initialData.m_ports << initialPortData; 392 } 393 394 /* Cache initial data: */ 395 m_pCache->cacheInitialData(initialData); 386 396 387 397 /* Upload machine to data: */ … … 392 402 { 393 403 /* Setup tab order: */ 394 Assert (firstWidget());404 AssertPtrReturnVoid(firstWidget()); 395 405 setTabOrder(firstWidget(), m_pTabWidget->focusProxy()); 396 406 QWidget *pLastFocusWidget = m_pTabWidget->focusProxy(); … … 403 413 404 414 /* Load port data to page: */ 405 pPage-> fetchPortData(m_pCache->child(iPort));415 pPage->loadPortData(m_pCache->base().m_ports.at(iPort)); 406 416 407 417 /* Setup tab order: */ … … 421 431 void UIMachineSettingsSerialPage::putToCache() 422 432 { 433 /* Prepare current data: */ 434 UIDataSettingsMachineSerial currentData; 435 423 436 /* For each serial port: */ 424 437 for (int iPort = 0; iPort < m_pTabWidget->count(); ++iPort) 425 438 { 426 439 /* Getting port page: */ 427 UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iPort)); 428 429 /* Gather & cache port data: */ 430 pPage->uploadPortData(m_pCache->child(iPort)); 431 } 440 UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iPort)); 441 442 /* Prepare current port data: */ 443 UIDataSettingsMachineSerialPort currentPortData; 444 445 /* Gather current port data: */ 446 pTab->savePortData(currentPortData); 447 448 /* Cache current port data: */ 449 currentData.m_ports << currentPortData; 450 } 451 452 /* Cache current data: */ 453 m_pCache->cacheCurrentData(currentData); 432 454 } 433 455 … … 444 466 { 445 467 /* Check if port data was changed: */ 446 const UISettingsCacheMachineSerialPort &portCache = m_pCache->child(iPort); 447 if (portCache.wasChanged()) 468 const UIDataSettingsMachineSerialPort &initialPortData = m_pCache->base().m_ports.at(iPort); 469 const UIDataSettingsMachineSerialPort ¤tPortData = m_pCache->data().m_ports.at(iPort); 470 if (currentPortData != initialPortData) 448 471 { 449 472 /* Check if port still valid: */ … … 451 474 if (!port.isNull()) 452 475 { 453 /* Get port data: */454 const UIDataSettingsMachineSerialPort &portData = portCache.data();455 456 476 /* Store adapter data: */ 457 477 if (isMachineOffline()) 458 478 { 459 port.SetEnabled(portData.m_fPortEnabled); 460 port.SetIRQ(portData.m_uIRQ); 461 port.SetIOBase(portData.m_uIOBase); 462 port.SetServer(portData.m_fServer); 463 port.SetPath(portData.m_strPath); 479 /* Whether the port is enabled: */ 480 if ( port.isOk() 481 && currentPortData.m_fPortEnabled != initialPortData.m_fPortEnabled) 482 port.SetEnabled(currentPortData.m_fPortEnabled); 483 /* Port IRQ: */ 484 if ( port.isOk() 485 && currentPortData.m_uIRQ != initialPortData.m_uIRQ) 486 port.SetIRQ(currentPortData.m_uIRQ); 487 /* Port IO base: */ 488 if ( port.isOk() 489 && currentPortData.m_uIOBase != initialPortData.m_uIOBase) 490 port.SetIOBase(currentPortData.m_uIOBase); 491 /* Whether the port is server: */ 492 if ( port.isOk() 493 && currentPortData.m_fServer != initialPortData.m_fServer) 494 port.SetServer(currentPortData.m_fServer); 495 /* Port path: */ 496 if ( port.isOk() 497 && currentPortData.m_strPath != initialPortData.m_strPath) 498 port.SetPath(currentPortData.m_strPath); 464 499 /* This *must* be last. The host mode will be changed to disconnected if 465 500 * some of the necessary settings above will not meet the requirements for 466 501 * the selected mode. */ 467 port.SetHostMode(portData.m_hostMode); 502 if ( port.isOk() 503 && currentPortData.m_hostMode != initialPortData.m_hostMode) 504 port.SetHostMode(currentPortData.m_hostMode); 468 505 } 469 506 } … … 565 602 { 566 603 m_pTabWidget->setTabEnabled(iPort, 567 isMachineOffline() ||568 (isMachineInValidMode() && m_pCache->child(iPort).base().m_fPortEnabled));604 isMachineOffline() || 605 (isMachineInValidMode() && m_pCache->base().m_ports.at(iPort).m_fPortEnabled)); 569 606 UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iPort)); 570 607 pTab->polishTab(); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.h
r66345 r66366 27 27 class UIMachineSettingsSerialPage; 28 28 struct UIDataSettingsMachineSerial; 29 struct UIDataSettingsMachineSerialPort; 30 typedef UISettingsCache<UIDataSettingsMachineSerialPort> UISettingsCacheMachineSerialPort; 31 typedef UISettingsCachePool<UIDataSettingsMachineSerial, UISettingsCacheMachineSerialPort> UISettingsCacheMachineSerial; 29 typedef UISettingsCache<UIDataSettingsMachineSerial> UISettingsCacheMachineSerial; 32 30 33 31
Note:
See TracChangeset
for help on using the changeset viewer.