Changeset 94675 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Apr 21, 2022 5:52:59 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 151042
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.cpp
r94667 r94675 494 494 void UIMachineSettingsNetwork::polishTab() 495 495 { 496 if (m_pEditorNetworkSettings) 496 if ( m_pEditorNetworkSettings 497 && m_pParent) 497 498 { 498 499 /* General stuff: */ … … 517 518 void UIMachineSettingsNetwork::reloadAlternatives() 518 519 { 519 if (m_pEditorNetworkSettings) 520 if ( m_pEditorNetworkSettings 521 && m_pParent) 520 522 { 521 523 m_pEditorNetworkSettings->setValueNames(KNetworkAttachmentType_Bridged, m_pParent->bridgedAdapterList()); … … 805 807 806 808 /* Delegate validation to adapter tabs: */ 807 for (int i = 0; i < m_pTabWidget->count(); ++i)808 { 809 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTabWidget->widget(i ));809 for (int iIndex = 0; iIndex < m_pTabWidget->count(); ++iIndex) 810 { 811 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTabWidget->widget(iIndex)); 810 812 AssertPtrReturn(pTab, false); 811 813 if (!pTab->validate(messages)) -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.h
r94653 r94675 65 65 #endif 66 66 67 public slots:68 69 /** Handles adapter alternative name change. */70 void sltHandleAlternativeNameChange();71 72 67 protected: 73 68 … … 100 95 private slots: 101 96 97 /** Handles adapter alternative name change. */ 98 void sltHandleAlternativeNameChange(); 102 99 /** Handles whether the advanced button is @a fExpanded. */ 103 100 void sltHandleAdvancedButtonStateChange(bool fExpanded); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.cpp
r94667 r94675 106 106 Q_OBJECT; 107 107 108 signals: 109 110 /** Notifies about port changed. */ 111 void sigPortChanged(); 112 /** Notifies about path changed. */ 113 void sigPathChanged(); 114 /** Notifies about validity changed. */ 115 void sigValidityChanged(); 116 108 117 public: 109 118 119 /** Constructs tab passing @a pParent to the base-class. */ 110 120 UIMachineSettingsSerial(UIMachineSettingsSerialPage *pParent); 111 121 122 /** Loads port data from @a portCache. */ 123 void getPortDataFromCache(const UISettingsCacheMachineSerialPort &portCache); 124 /** Saves port data to @a portCache. */ 125 void putPortDataToCache(UISettingsCacheMachineSerialPort &portCache); 126 127 /** Performs validation, updates @a messages list if something is wrong. */ 128 bool validate(QList<UIValidationMessage> &messages); 129 130 /** Configures tab order according to passed @a pWidget. */ 131 QWidget *setOrderAfter(QWidget *pWidget); 132 133 /** Returns tab title. */ 134 QString tabTitle() const; 135 /** Returns whether port is enabled. */ 136 bool isPortEnabled() const; 137 /** Returns IRQ. */ 138 QString irq() const; 139 /** Returns IO port. */ 140 QString ioPort() const; 141 /** Returns path. */ 142 QString path() const; 143 144 /** Performs tab polishing. */ 112 145 void polishTab(); 113 146 114 void loadPortData(const UIDataSettingsMachineSerialPort &portData);115 void savePortData(UIDataSettingsMachineSerialPort &portData);116 117 QWidget *setOrderAfter(QWidget *pAfter);118 119 QString pageTitle() const;120 bool isUserDefined();121 122 147 protected: 123 148 149 /** Handles translation event. */ 124 150 void retranslateUi(); 125 151 126 152 private slots: 127 153 128 void sltGbSerialToggled(bool fOn); 129 void sltCbNumberActivated(const QString &strText); 154 /** Handles port availability being toggled to @a fOn. */ 155 void sltHandlePortAvailabilityToggled(bool fOn); 156 /** Handles port standard @a strOption being activated. */ 157 void sltHandlePortStandardOptionActivated(const QString &strOption); 130 158 /** Handles port mode change to item with certain @a iIndex. */ 131 159 void sltHandlePortModeChange(int iIndex); … … 180 208 QLineEdit *m_pEditorPath; 181 209 /** @} */ 182 183 friend class UIMachineSettingsSerialPage;184 210 }; 185 211 … … 211 237 } 212 238 213 void UIMachineSettingsSerial::polishTab() 214 { 215 /* Polish port page: */ 216 ulong uIRQ, uIOBase; 217 const bool fStd = UITranslator::toCOMPortNumbers(m_pComboNumber->currentText(), uIRQ, uIOBase); 218 const KPortMode enmMode = m_pComboMode->currentData().value<KPortMode>(); 219 m_pCheckBoxPort->setEnabled(m_pParent->isMachineOffline()); 220 m_pLabelNumber->setEnabled(m_pParent->isMachineOffline()); 221 m_pComboNumber->setEnabled(m_pParent->isMachineOffline()); 222 m_pLabelIRQ->setEnabled(m_pParent->isMachineOffline()); 223 m_pLineEditIRQ->setEnabled(!fStd && m_pParent->isMachineOffline()); 224 m_pLabelIOPort->setEnabled(m_pParent->isMachineOffline()); 225 m_pLineEditIOPort->setEnabled(!fStd && m_pParent->isMachineOffline()); 226 m_pLabelMode->setEnabled(m_pParent->isMachineOffline()); 227 m_pComboMode->setEnabled(m_pParent->isMachineOffline()); 228 m_pCheckBoxPipe->setEnabled( (enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP) 229 && m_pParent->isMachineOffline()); 230 m_pLabelPath->setEnabled( enmMode != KPortMode_Disconnected 231 && m_pParent->isMachineOffline()); 232 m_pEditorPath->setEnabled( enmMode != KPortMode_Disconnected 233 && m_pParent->isMachineOffline()); 234 } 235 236 void UIMachineSettingsSerial::loadPortData(const UIDataSettingsMachineSerialPort &portData) 237 { 239 void UIMachineSettingsSerial::getPortDataFromCache(const UISettingsCacheMachineSerialPort &portCache) 240 { 241 /* Get old data: */ 242 const UIDataSettingsMachineSerialPort &oldPortData = portCache.base(); 243 238 244 /* Load port number: */ 239 m_iSlot = portData.m_iSlot;245 m_iSlot = oldPortData.m_iSlot; 240 246 241 247 /* Load port data: */ 242 m_pCheckBoxPort->setChecked(portData.m_fPortEnabled); 243 m_pComboNumber->setCurrentIndex(m_pComboNumber->findText(UITranslator::toCOMPortName(portData.m_uIRQ, portData.m_uIOBase))); 244 m_pLineEditIRQ->setText(QString::number(portData.m_uIRQ)); 245 m_pLineEditIOPort->setText("0x" + QString::number(portData.m_uIOBase, 16).toUpper()); 246 m_enmPortMode = portData.m_hostMode; 247 m_pCheckBoxPipe->setChecked(!portData.m_fServer); 248 m_pEditorPath->setText(portData.m_strPath); 248 if (m_pCheckBoxPort) 249 m_pCheckBoxPort->setChecked(oldPortData.m_fPortEnabled); 250 if (m_pComboNumber) 251 m_pComboNumber->setCurrentIndex(m_pComboNumber->findText(UITranslator::toCOMPortName(oldPortData.m_uIRQ, oldPortData.m_uIOBase))); 252 if (m_pLineEditIRQ) 253 m_pLineEditIRQ->setText(QString::number(oldPortData.m_uIRQ)); 254 if (m_pLineEditIOPort) 255 m_pLineEditIOPort->setText("0x" + QString::number(oldPortData.m_uIOBase, 16).toUpper()); 256 m_enmPortMode = oldPortData.m_hostMode; 257 if (m_pCheckBoxPipe) 258 m_pCheckBoxPipe->setChecked(!oldPortData.m_fServer); 259 if (m_pEditorPath) 260 m_pEditorPath->setText(oldPortData.m_strPath); 249 261 250 262 /* Repopulate combo-boxes content: */ 251 263 populateComboboxes(); 252 264 /* Ensure everything is up-to-date */ 253 sltGbSerialToggled(m_pCheckBoxPort->isChecked()); 254 } 255 256 void UIMachineSettingsSerial::savePortData(UIDataSettingsMachineSerialPort &portData) 257 { 265 if (m_pCheckBoxPort) 266 sltHandlePortAvailabilityToggled(m_pCheckBoxPort->isChecked()); 267 } 268 269 void UIMachineSettingsSerial::putPortDataToCache(UISettingsCacheMachineSerialPort &portCache) 270 { 271 /* Prepare new data: */ 272 UIDataSettingsMachineSerialPort newPortData; 273 258 274 /* Save port data: */ 259 portData.m_fPortEnabled = m_pCheckBoxPort->isChecked(); 260 portData.m_uIRQ = m_pLineEditIRQ->text().toULong(NULL, 0); 261 portData.m_uIOBase = m_pLineEditIOPort->text().toULong(NULL, 0); 262 portData.m_fServer = !m_pCheckBoxPipe->isChecked(); 263 portData.m_hostMode = m_pComboMode->currentData().value<KPortMode>(); 264 portData.m_strPath = QDir::toNativeSeparators(m_pEditorPath->text()); 265 } 266 267 QWidget *UIMachineSettingsSerial::setOrderAfter(QWidget *pAfter) 268 { 269 setTabOrder(pAfter, m_pCheckBoxPort); 275 if (m_pCheckBoxPort) 276 newPortData.m_fPortEnabled = m_pCheckBoxPort->isChecked(); 277 if (m_pLineEditIRQ) 278 newPortData.m_uIRQ = m_pLineEditIRQ->text().toULong(NULL, 0); 279 if (m_pLineEditIOPort) 280 newPortData.m_uIOBase = m_pLineEditIOPort->text().toULong(NULL, 0); 281 if (m_pCheckBoxPipe) 282 newPortData.m_fServer = !m_pCheckBoxPipe->isChecked(); 283 if (m_pComboMode) 284 newPortData.m_hostMode = m_pComboMode->currentData().value<KPortMode>(); 285 if (m_pEditorPath) 286 newPortData.m_strPath = QDir::toNativeSeparators(m_pEditorPath->text()); 287 288 /* Cache new data: */ 289 portCache.cacheCurrentData(newPortData); 290 } 291 292 bool UIMachineSettingsSerial::validate(QList<UIValidationMessage> &messages) 293 { 294 /* Pass by default: */ 295 bool fPass = true; 296 297 /* Prepare message: */ 298 UIValidationMessage message; 299 message.first = UITranslator::removeAccelMark(tabTitle()); 300 301 if ( m_pCheckBoxPort 302 && m_pCheckBoxPort->isChecked()) 303 { 304 /* Check the port attribute emptiness & uniqueness: */ 305 const QString strIRQ = m_pLineEditIRQ ? m_pLineEditIRQ->text() : QString(); 306 const QString strIOPort = m_pLineEditIOPort ? m_pLineEditIOPort->text() : QString(); 307 const QPair<QString, QString> port = qMakePair(strIRQ, strIOPort); 308 309 if (strIRQ.isEmpty()) 310 { 311 message.second << UIMachineSettingsSerial::tr("No IRQ is currently specified."); 312 fPass = false; 313 } 314 if (strIOPort.isEmpty()) 315 { 316 message.second << UIMachineSettingsSerial::tr("No I/O port is currently specified."); 317 fPass = false; 318 } 319 if ( !strIRQ.isEmpty() 320 && !strIOPort.isEmpty()) 321 { 322 QVector<QPair<QString, QString> > ports; 323 if (m_pParent) 324 { 325 ports = m_pParent->ports(); 326 ports.removeAt(m_iSlot); 327 } 328 if (ports.contains(port)) 329 { 330 message.second << UIMachineSettingsSerial::tr("Two or more ports have the same settings."); 331 fPass = false; 332 } 333 } 334 335 const KPortMode enmMode = m_pComboMode->currentData().value<KPortMode>(); 336 if (enmMode != KPortMode_Disconnected) 337 { 338 const QString strPath(m_pEditorPath->text()); 339 340 if (strPath.isEmpty()) 341 { 342 message.second << UIMachineSettingsSerial::tr("No port path is currently specified."); 343 fPass = false; 344 } 345 else 346 { 347 QVector<QString> paths; 348 if (m_pParent) 349 { 350 paths = m_pParent->paths(); 351 paths.removeAt(m_iSlot); 352 } 353 if (paths.contains(strPath)) 354 { 355 message.second << UIMachineSettingsSerial::tr("There are currently duplicate port paths specified."); 356 fPass = false; 357 } 358 } 359 } 360 } 361 362 /* Serialize message: */ 363 if (!message.second.isEmpty()) 364 messages << message; 365 366 /* Return result: */ 367 return fPass; 368 } 369 370 QWidget *UIMachineSettingsSerial::setOrderAfter(QWidget *pWidget) 371 { 372 setTabOrder(pWidget, m_pCheckBoxPort); 270 373 setTabOrder(m_pCheckBoxPort, m_pComboNumber); 271 374 setTabOrder(m_pComboNumber, m_pLineEditIRQ); … … 277 380 } 278 381 279 QString UIMachineSettingsSerial:: pageTitle() const382 QString UIMachineSettingsSerial::tabTitle() const 280 383 { 281 384 return QString(tr("Port %1", "serial ports")).arg(QString("&%1").arg(m_iSlot + 1)); 282 385 } 283 386 284 bool UIMachineSettingsSerial::isUserDefined() 285 { 286 ulong a, b; 287 return !UITranslator::toCOMPortNumbers(m_pComboNumber->currentText(), a, b); 387 bool UIMachineSettingsSerial::isPortEnabled() const 388 { 389 return m_pCheckBoxPort->isChecked(); 390 } 391 392 QString UIMachineSettingsSerial::irq() const 393 { 394 return m_pLineEditIRQ->text(); 395 } 396 397 QString UIMachineSettingsSerial::ioPort() const 398 { 399 return m_pLineEditIOPort->text(); 400 } 401 402 QString UIMachineSettingsSerial::path() const 403 { 404 return m_pEditorPath->text(); 405 } 406 407 void UIMachineSettingsSerial::polishTab() 408 { 409 /* Sanity check: */ 410 if (!m_pParent) 411 return; 412 413 /* Polish port page: */ 414 ulong uIRQ, uIOBase; 415 const bool fStd = m_pComboNumber ? UITranslator::toCOMPortNumbers(m_pComboNumber->currentText(), uIRQ, uIOBase) : false; 416 const KPortMode enmMode = m_pComboMode ? m_pComboMode->currentData().value<KPortMode>() : KPortMode_Max; 417 if (m_pCheckBoxPort) 418 m_pCheckBoxPort->setEnabled(m_pParent->isMachineOffline()); 419 if (m_pLabelNumber) 420 m_pLabelNumber->setEnabled(m_pParent->isMachineOffline()); 421 if (m_pComboNumber) 422 m_pComboNumber->setEnabled(m_pParent->isMachineOffline()); 423 if (m_pLabelIRQ) 424 m_pLabelIRQ->setEnabled(m_pParent->isMachineOffline()); 425 if (m_pLineEditIRQ) 426 m_pLineEditIRQ->setEnabled(!fStd && m_pParent->isMachineOffline()); 427 if (m_pLabelIOPort) 428 m_pLabelIOPort->setEnabled(m_pParent->isMachineOffline()); 429 if (m_pLineEditIOPort) 430 m_pLineEditIOPort->setEnabled(!fStd && m_pParent->isMachineOffline()); 431 if (m_pLabelMode) 432 m_pLabelMode->setEnabled(m_pParent->isMachineOffline()); 433 if (m_pComboMode) 434 m_pComboMode->setEnabled(m_pParent->isMachineOffline()); 435 if (m_pCheckBoxPipe) 436 m_pCheckBoxPipe->setEnabled( (enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP) 437 && m_pParent->isMachineOffline()); 438 if (m_pLabelPath) 439 m_pLabelPath->setEnabled( enmMode != KPortMode_Disconnected 440 && m_pParent->isMachineOffline()); 441 if (m_pEditorPath) 442 m_pEditorPath->setEnabled( enmMode != KPortMode_Disconnected 443 && m_pParent->isMachineOffline()); 288 444 } 289 445 290 446 void UIMachineSettingsSerial::retranslateUi() 291 447 { 292 m_pCheckBoxPort->setToolTip(tr("When checked, enables the given serial port of the virtual machine.")); 293 m_pCheckBoxPort->setText(tr("&Enable Serial Port")); 294 m_pLabelNumber->setText(tr("Port &Number:")); 295 m_pComboNumber->setToolTip(tr("Selects the serial port number. You can choose one of the standard serial ports or select " 296 "<b>User-defined</b> and specify port parameters manually.")); 297 m_pLabelIRQ->setText(tr("&IRQ:")); 298 m_pLineEditIRQ->setToolTip(tr("Holds the IRQ number of this serial port. This should be a whole number between <tt>0</tt> " 299 "and <tt>255</tt>. Values greater than <tt>15</tt> may only be used if the <b>I/O APIC</b> " 300 "setting is enabled for this virtual machine.")); 301 m_pLabelIOPort->setText(tr("I/O Po&rt:")); 302 m_pLineEditIOPort->setToolTip(tr("Holds the base I/O port address of this serial port. Valid values are integer numbers in " 303 "range from <tt>0</tt> to <tt>0xFFFF</tt>.")); 304 m_pLabelMode->setText(tr("Port &Mode:")); 305 m_pComboMode->setToolTip(tr("Selects the working mode of this serial port. If you select <b>Disconnected</b>, the guest OS " 306 "will detect the serial port but will not be able to operate it.")); 307 m_pCheckBoxPipe->setToolTip(tr("When checked, the virtual machine will assume that the pipe or socket specified in the " 308 "<b>Path/Address</b> field exists and try to use it. Otherwise, the pipe or socket will be " 309 "created by the virtual machine when it starts.")); 310 m_pCheckBoxPipe->setText(tr("&Connect to existing pipe/socket")); 311 m_pLabelPath->setText(tr("&Path/Address:")); 312 m_pEditorPath->setToolTip(tr("<p>In <b>Host Pipe</b> mode: Holds the path to the serial port's pipe on the host. " 313 "Examples: \"\\\\.\\pipe\\myvbox\" or \"/tmp/myvbox\", for Windows and UNIX-like systems " 314 "respectively.</p><p>In <b>Host Device</b> mode: Holds the host serial device name. " 315 "Examples: \"COM1\" or \"/dev/ttyS0\".</p><p>In <b>Raw File</b> mode: Holds the file-path " 316 "on the host system, where the serial output will be dumped.</p><p>In <b>TCP</b> mode: Holds " 317 "the TCP \"port\" when in server mode, or \"hostname:port\" when in client mode.")); 318 319 m_pComboNumber->setItemText(m_pComboNumber->count() - 1, UITranslator::toCOMPortName(0, 0)); 448 if (m_pCheckBoxPort) 449 { 450 m_pCheckBoxPort->setText(tr("&Enable Serial Port")); 451 m_pCheckBoxPort->setToolTip(tr("When checked, enables the given serial port of the virtual machine.")); 452 } 453 if (m_pLabelNumber) 454 m_pLabelNumber->setText(tr("Port &Number:")); 455 if (m_pComboNumber) 456 { 457 m_pComboNumber->setItemText(m_pComboNumber->count() - 1, UITranslator::toCOMPortName(0, 0)); 458 m_pComboNumber->setToolTip(tr("Selects the serial port number. You can choose one of the standard serial ports or select " 459 "<b>User-defined</b> and specify port parameters manually.")); 460 } 461 if (m_pLabelIRQ) 462 m_pLabelIRQ->setText(tr("&IRQ:")); 463 if (m_pLineEditIRQ) 464 m_pLineEditIRQ->setToolTip(tr("Holds the IRQ number of this serial port. This should be a whole number between " 465 "<tt>0</tt> and <tt>255</tt>. Values greater than <tt>15</tt> may only be used if the " 466 "<b>I/O APIC</b> setting is enabled for this virtual machine.")); 467 if (m_pLabelIOPort) 468 m_pLabelIOPort->setText(tr("I/O Po&rt:")); 469 if (m_pLineEditIOPort) 470 m_pLineEditIOPort->setToolTip(tr("Holds the base I/O port address of this serial port. Valid values are integer numbers " 471 "in range from <tt>0</tt> to <tt>0xFFFF</tt>.")); 472 if (m_pLabelMode) 473 m_pLabelMode->setText(tr("Port &Mode:")); 474 if (m_pComboMode) 475 m_pComboMode->setToolTip(tr("Selects the working mode of this serial port. If you select <b>Disconnected</b>, the guest " 476 "OS will detect the serial port but will not be able to operate it.")); 477 if (m_pCheckBoxPipe) 478 { 479 m_pCheckBoxPipe->setText(tr("&Connect to existing pipe/socket")); 480 m_pCheckBoxPipe->setToolTip(tr("When checked, the virtual machine will assume that the pipe or socket specified in the " 481 "<b>Path/Address</b> field exists and try to use it. Otherwise, the pipe or socket will " 482 "be created by the virtual machine when it starts.")); 483 } 484 if (m_pLabelPath) 485 m_pLabelPath->setText(tr("&Path/Address:")); 486 if (m_pEditorPath) 487 m_pEditorPath->setToolTip(tr("<p>In <b>Host Pipe</b> mode: Holds the path to the serial port's pipe on the host. " 488 "Examples: \"\\\\.\\pipe\\myvbox\" or \"/tmp/myvbox\", for Windows and UNIX-like systems " 489 "respectively.</p><p>In <b>Host Device</b> mode: Holds the host serial device name. " 490 "Examples: \"COM1\" or \"/dev/ttyS0\".</p><p>In <b>Raw File</b> mode: Holds the file-path " 491 "on the host system, where the serial output will be dumped.</p><p>In <b>TCP</b> mode: " 492 "Holds the TCP \"port\" when in server mode, or \"hostname:port\" when in client mode.")); 320 493 321 494 /* Translate combo-boxes content: */ … … 323 496 } 324 497 325 void UIMachineSettingsSerial::slt GbSerialToggled(bool fOn)498 void UIMachineSettingsSerial::sltHandlePortAvailabilityToggled(bool fOn) 326 499 { 327 500 /* Update availability: */ 328 501 m_pWidgetPortSettings->setEnabled(m_pCheckBoxPort->isChecked()); 329 330 502 if (fOn) 331 503 { 332 slt CbNumberActivated(m_pComboNumber->currentText());504 sltHandlePortStandardOptionActivated(m_pComboNumber->currentText()); 333 505 sltHandlePortModeChange(m_pComboMode->currentIndex()); 334 506 } 335 507 336 /* Revalidate: */ 337 m_pParent->revalidate(); 338 } 339 340 void UIMachineSettingsSerial::sltCbNumberActivated(const QString &strText) 341 { 508 /* Notify port/path changed: */ 509 emit sigPortChanged(); 510 emit sigPathChanged(); 511 } 512 513 void UIMachineSettingsSerial::sltHandlePortStandardOptionActivated(const QString &strText) 514 { 515 /* Update availability: */ 342 516 ulong uIRQ, uIOBase; 343 517 bool fStd = UITranslator::toCOMPortNumbers(strText, uIRQ, uIOBase); 344 345 518 m_pLineEditIRQ->setEnabled(!fStd); 346 519 m_pLineEditIOPort->setEnabled(!fStd); … … 351 524 } 352 525 353 /* Revalidate: */354 m_pParent->revalidate();526 /* Notify validity changed: */ 527 emit sigValidityChanged(); 355 528 } 356 529 357 530 void UIMachineSettingsSerial::sltHandlePortModeChange(int iIndex) 358 531 { 532 /* Update availability: */ 359 533 const KPortMode enmMode = m_pComboMode->itemData(iIndex).value<KPortMode>(); 360 534 m_pCheckBoxPipe->setEnabled(enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP); … … 362 536 m_pLabelPath->setEnabled(enmMode != KPortMode_Disconnected); 363 537 364 /* Revalidate: */365 m_pParent->revalidate();538 /* Notify validity changed: */ 539 emit sigValidityChanged(); 366 540 } 367 541 … … 505 679 void UIMachineSettingsSerial::prepareConnections() 506 680 { 507 connect(m_pCheckBoxPort, &QCheckBox::toggled, this, &UIMachineSettingsSerial::sltGbSerialToggled); 681 if (m_pCheckBoxPort) 682 connect(m_pCheckBoxPort, &QCheckBox::toggled, this, &UIMachineSettingsSerial::sltHandlePortAvailabilityToggled); 508 683 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) 509 connect(m_pComboNumber, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::textActivated), 510 this, &UIMachineSettingsSerial::sltCbNumberActivated); 684 if (m_pComboNumber) 685 connect(m_pComboNumber, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::textActivated), 686 this, &UIMachineSettingsSerial::sltHandlePortStandardOptionActivated); 511 687 #else 512 connect(m_pComboNumber, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::activated), 513 this, &UIMachineSettingsSerial::sltCbNumberActivated); 688 if (m_pComboNumber) 689 connect(m_pComboNumber, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::activated), 690 this, &UIMachineSettingsSerial::sltHandlePortStandardOptionActivated); 514 691 #endif 515 connect(m_pLineEditIRQ, &QLineEdit::textChanged, m_pParent, &UIMachineSettingsSerialPage::revalidate); 516 connect(m_pLineEditIOPort, &QLineEdit::textChanged, m_pParent, &UIMachineSettingsSerialPage::revalidate); 517 connect(m_pComboMode, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), 518 this, &UIMachineSettingsSerial::sltHandlePortModeChange); 519 connect(m_pEditorPath, &QLineEdit::textChanged, m_pParent, &UIMachineSettingsSerialPage::revalidate); 692 if (m_pLineEditIRQ) 693 connect(m_pLineEditIRQ, &QLineEdit::textChanged, this, &UIMachineSettingsSerial::sigPortChanged); 694 if (m_pLineEditIOPort) 695 connect(m_pLineEditIOPort, &QLineEdit::textChanged, this, &UIMachineSettingsSerial::sigPortChanged); 696 if (m_pComboMode) 697 connect(m_pComboMode, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), 698 this, &UIMachineSettingsSerial::sltHandlePortModeChange); 699 if (m_pEditorPath) 700 connect(m_pEditorPath, &QLineEdit::textChanged, this, &UIMachineSettingsSerial::sigPathChanged); 520 701 } 521 702 … … 556 737 557 738 UIMachineSettingsSerialPage::UIMachineSettingsSerialPage() 558 : m_pTabWidget(0) 559 , m_pCache(0) 560 { 561 /* Prepare: */ 739 : m_pCache(0) 740 , m_pTabWidget(0) 741 { 562 742 prepare(); 563 743 } … … 565 745 UIMachineSettingsSerialPage::~UIMachineSettingsSerialPage() 566 746 { 567 /* Cleanup: */568 747 cleanup(); 569 748 } … … 587 766 m_pCache->clear(); 588 767 768 /* Cache lists: */ 769 refreshPorts(); 770 refreshPaths(); 771 589 772 /* Prepare old data: */ 590 773 UIDataSettingsMachineSerial oldSerialData; 591 774 592 /* For each port: */775 /* For each serial port: */ 593 776 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 594 777 { … … 641 824 642 825 /* Load old data from cache: */ 643 pTab-> loadPortData(m_pCache->child(iSlot).base());826 pTab->getPortDataFromCache(m_pCache->child(iSlot)); 644 827 645 828 /* Setup tab order: */ … … 674 857 AssertPtrReturnVoid(pTab); 675 858 676 /* Prepare new data: */677 UIDataSettingsMachineSerialPort newPortData;678 679 859 /* Gather new data: */ 680 pTab->savePortData(newPortData); 681 682 /* Cache new data: */ 683 m_pCache->child(iSlot).cacheCurrentData(newPortData); 860 pTab->putPortDataToCache(m_pCache->child(iSlot)); 684 861 } 685 862 … … 702 879 bool UIMachineSettingsSerialPage::validate(QList<UIValidationMessage> &messages) 703 880 { 881 /* Sanity check: */ 882 if (!m_pTabWidget) 883 return false; 884 704 885 /* Pass by default: */ 705 bool fPass = true; 706 707 /* Validation stuff: */ 708 QList<QPair<QString, QString> > ports; 709 QStringList paths; 710 711 /* Validate all the ports: */ 886 bool fValid = true; 887 888 /* Delegate validation to adapter tabs: */ 712 889 for (int iIndex = 0; iIndex < m_pTabWidget->count(); ++iIndex) 713 890 { 714 /* Get current tab/page: */ 715 QWidget *pTab = m_pTabWidget->widget(iIndex); 716 UIMachineSettingsSerial *pPage = static_cast<UIMachineSettingsSerial*>(pTab); 717 if (!pPage->m_pCheckBoxPort->isChecked()) 718 continue; 719 720 /* Prepare message: */ 721 UIValidationMessage message; 722 message.first = UITranslator::removeAccelMark(m_pTabWidget->tabText(m_pTabWidget->indexOf(pTab))); 723 724 /* Check the port attribute emptiness & uniqueness: */ 725 const QString strIRQ(pPage->m_pLineEditIRQ->text()); 726 const QString strIOPort(pPage->m_pLineEditIOPort->text()); 727 const QPair<QString, QString> pair(strIRQ, strIOPort); 728 729 if (strIRQ.isEmpty()) 730 { 731 message.second << UIMachineSettingsSerial::tr("No IRQ is currently specified."); 732 fPass = false; 733 } 734 if (strIOPort.isEmpty()) 735 { 736 message.second << UIMachineSettingsSerial::tr("No I/O port is currently specified."); 737 fPass = false; 738 } 739 if (ports.contains(pair)) 740 { 741 message.second << UIMachineSettingsSerial::tr("Two or more ports have the same settings."); 742 fPass = false; 743 } 744 745 ports << pair; 746 747 const KPortMode enmMode = pPage->m_pComboMode->currentData().value<KPortMode>(); 748 if (enmMode != KPortMode_Disconnected) 749 { 750 const QString strPath(pPage->m_pEditorPath->text()); 751 752 if (strPath.isEmpty()) 753 { 754 message.second << UIMachineSettingsSerial::tr("No port path is currently specified."); 755 fPass = false; 756 } 757 if (paths.contains(strPath)) 758 { 759 message.second << UIMachineSettingsSerial::tr("There are currently duplicate port paths specified."); 760 fPass = false; 761 } 762 763 paths << strPath; 764 } 765 766 /* Serialize message: */ 767 if (!message.second.isEmpty()) 768 messages << message; 891 UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iIndex)); 892 AssertPtrReturn(pTab, false); 893 if (!pTab->validate(messages)) 894 fValid = false; 769 895 } 770 896 771 897 /* Return result: */ 772 return f Pass;898 return fValid; 773 899 } 774 900 775 901 void UIMachineSettingsSerialPage::retranslateUi() 776 902 { 777 for (int i = 0; i < m_pTabWidget->count(); ++i) 778 { 779 UIMachineSettingsSerial *pPage = 780 static_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(i)); 781 m_pTabWidget->setTabText(i, pPage->pageTitle()); 903 /* Sanity check: */ 904 if (!m_pTabWidget) 905 return; 906 907 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 908 { 909 UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot)); 910 AssertPtrReturnVoid(pTab); 911 m_pTabWidget->setTabText(iSlot, pTab->tabTitle()); 782 912 } 783 913 } … … 785 915 void UIMachineSettingsSerialPage::polishPage() 786 916 { 787 /* Get the count of serial port tabs: */ 917 /* Sanity check: */ 918 if ( !m_pCache 919 || !m_pTabWidget) 920 return; 921 788 922 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 789 923 { … … 799 933 } 800 934 935 void UIMachineSettingsSerialPage::sltHandlePortChange() 936 { 937 refreshPorts(); 938 revalidate(); 939 } 940 941 void UIMachineSettingsSerialPage::sltHandlePathChange() 942 { 943 refreshPaths(); 944 revalidate(); 945 } 946 801 947 void UIMachineSettingsSerialPage::prepare() 802 948 { … … 807 953 /* Create main layout: */ 808 954 QVBoxLayout *pLayoutMain = new QVBoxLayout(this); 809 AssertPtrReturnVoid(pLayoutMain);955 if (pLayoutMain) 810 956 { 811 957 /* Creating tab-widget: */ 812 958 m_pTabWidget = new QITabWidget; 813 AssertPtrReturnVoid(m_pTabWidget);959 if (m_pTabWidget) 814 960 { 815 961 /* How many ports to display: */ … … 817 963 818 964 /* Create corresponding port tabs: */ 819 for (ulong u Port = 0; uPort < uCount; ++uPort)965 for (ulong uSlot = 0; uSlot < uCount; ++uSlot) 820 966 { 821 967 /* Create port tab: */ 822 968 UIMachineSettingsSerial *pTab = new UIMachineSettingsSerial(this); 823 AssertPtrReturnVoid(pTab);969 if (pTab) 824 970 { 971 /* Tab connections: */ 972 connect(pTab, &UIMachineSettingsSerial::sigPortChanged, 973 this, &UIMachineSettingsSerialPage::sltHandlePortChange); 974 connect(pTab, &UIMachineSettingsSerial::sigPathChanged, 975 this, &UIMachineSettingsSerialPage::sltHandlePathChange); 976 connect(pTab, &UIMachineSettingsSerial::sigValidityChanged, 977 this, &UIMachineSettingsSerialPage::revalidate); 978 825 979 /* Add tab into tab-widget: */ 826 m_pTabWidget->addTab(pTab, pTab-> pageTitle());980 m_pTabWidget->addTab(pTab, pTab->tabTitle()); 827 981 } 828 982 } … … 839 993 delete m_pCache; 840 994 m_pCache = 0; 995 } 996 997 void UIMachineSettingsSerialPage::refreshPorts() 998 { 999 /* Sanity check: */ 1000 if (!m_pTabWidget) 1001 return; 1002 1003 /* Reload port list: */ 1004 m_ports.clear(); 1005 m_ports.resize(m_pTabWidget->count()); 1006 /* Append port list with data from all the tabs: */ 1007 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 1008 { 1009 UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot)); 1010 AssertPtrReturnVoid(pTab); 1011 m_ports[iSlot] = pTab->isPortEnabled() ? qMakePair(pTab->irq(), pTab->ioPort()) : qMakePair(QString(), QString()); 1012 } 1013 } 1014 1015 void UIMachineSettingsSerialPage::refreshPaths() 1016 { 1017 /* Sanity check: */ 1018 if (!m_pTabWidget) 1019 return; 1020 1021 /* Reload path list: */ 1022 m_paths.clear(); 1023 m_paths.resize(m_pTabWidget->count()); 1024 /* Append path list with data from all the tabs: */ 1025 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 1026 { 1027 UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot)); 1028 AssertPtrReturnVoid(pTab); 1029 m_paths[iSlot] = pTab->isPortEnabled() ? pTab->path() : QString(); 1030 } 841 1031 } 842 1032 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.h
r94333 r94675 45 45 virtual ~UIMachineSettingsSerialPage() RT_OVERRIDE; 46 46 47 /** Returns ports. */ 48 QVector<QPair<QString, QString> > ports() const { return m_ports; } 49 /** Returns paths. */ 50 QVector<QString> paths() const { return m_paths; } 51 47 52 protected: 48 53 … … 73 78 virtual void polishPage() RT_OVERRIDE; 74 79 80 private slots: 81 82 /** Handles port change. */ 83 void sltHandlePortChange(); 84 /** Handles path change. */ 85 void sltHandlePathChange(); 86 75 87 private: 76 88 … … 80 92 void cleanup(); 81 93 94 /** Repopulates ports. */ 95 void refreshPorts(); 96 /** Repopulates paths. */ 97 void refreshPaths(); 98 82 99 /** Saves existing data from cache. */ 83 100 bool saveData(); … … 85 102 bool savePortData(int iSlot); 86 103 87 /** Holds the tab-widget instance. */ 88 QITabWidget *m_pTabWidget; 104 /** Holds the ports. */ 105 QVector<QPair<QString, QString> > m_ports; 106 /** Holds the paths. */ 107 QVector<QString> m_paths; 89 108 90 109 /** Holds the page data cache instance. */ 91 110 UISettingsCacheMachineSerial *m_pCache; 111 112 /** Holds the tab-widget instance. */ 113 QITabWidget *m_pTabWidget; 92 114 }; 93 115
Note:
See TracChangeset
for help on using the changeset viewer.