VirtualBox

Changeset 94675 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 21, 2022 5:52:59 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
151042
Message:

FE/Qt/Ds: bugref:6899: Machine settings: Serial page accessibility improvements (part 1), large rework to sync with Network page; Small cleanup for Network page as well.

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  
    494494void UIMachineSettingsNetwork::polishTab()
    495495{
    496     if (m_pEditorNetworkSettings)
     496    if (   m_pEditorNetworkSettings
     497        && m_pParent)
    497498    {
    498499        /* General stuff: */
     
    517518void UIMachineSettingsNetwork::reloadAlternatives()
    518519{
    519     if (m_pEditorNetworkSettings)
     520    if (   m_pEditorNetworkSettings
     521        && m_pParent)
    520522    {
    521523        m_pEditorNetworkSettings->setValueNames(KNetworkAttachmentType_Bridged, m_pParent->bridgedAdapterList());
     
    805807
    806808    /* 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));
    810812        AssertPtrReturn(pTab, false);
    811813        if (!pTab->validate(messages))
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.h

    r94653 r94675  
    6565#endif
    6666
    67  public slots:
    68 
    69     /** Handles adapter alternative name change. */
    70     void sltHandleAlternativeNameChange();
    71 
    7267protected:
    7368
     
    10095private slots:
    10196
     97    /** Handles adapter alternative name change. */
     98    void sltHandleAlternativeNameChange();
    10299    /** Handles whether the advanced button is @a fExpanded. */
    103100    void sltHandleAdvancedButtonStateChange(bool fExpanded);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.cpp

    r94667 r94675  
    106106    Q_OBJECT;
    107107
     108signals:
     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
    108117public:
    109118
     119    /** Constructs tab passing @a pParent to the base-class. */
    110120    UIMachineSettingsSerial(UIMachineSettingsSerialPage *pParent);
    111121
     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. */
    112145    void polishTab();
    113146
    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 
    122147protected:
    123148
     149    /** Handles translation event. */
    124150    void retranslateUi();
    125151
    126152private slots:
    127153
    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);
    130158    /** Handles port mode change to item with certain @a iIndex. */
    131159    void sltHandlePortModeChange(int iIndex);
     
    180208        QLineEdit *m_pEditorPath;
    181209    /** @} */
    182 
    183     friend class UIMachineSettingsSerialPage;
    184210};
    185211
     
    211237}
    212238
    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 {
     239void UIMachineSettingsSerial::getPortDataFromCache(const UISettingsCacheMachineSerialPort &portCache)
     240{
     241    /* Get old data: */
     242    const UIDataSettingsMachineSerialPort &oldPortData = portCache.base();
     243
    238244    /* Load port number: */
    239     m_iSlot = portData.m_iSlot;
     245    m_iSlot = oldPortData.m_iSlot;
    240246
    241247    /* 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);
    249261
    250262    /* Repopulate combo-boxes content: */
    251263    populateComboboxes();
    252264    /* 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
     269void UIMachineSettingsSerial::putPortDataToCache(UISettingsCacheMachineSerialPort &portCache)
     270{
     271    /* Prepare new data: */
     272    UIDataSettingsMachineSerialPort newPortData;
     273
    258274    /* 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
     292bool 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
     370QWidget *UIMachineSettingsSerial::setOrderAfter(QWidget *pWidget)
     371{
     372    setTabOrder(pWidget, m_pCheckBoxPort);
    270373    setTabOrder(m_pCheckBoxPort, m_pComboNumber);
    271374    setTabOrder(m_pComboNumber, m_pLineEditIRQ);
     
    277380}
    278381
    279 QString UIMachineSettingsSerial::pageTitle() const
     382QString UIMachineSettingsSerial::tabTitle() const
    280383{
    281384    return QString(tr("Port %1", "serial ports")).arg(QString("&%1").arg(m_iSlot + 1));
    282385}
    283386
    284 bool UIMachineSettingsSerial::isUserDefined()
    285 {
    286     ulong a, b;
    287     return !UITranslator::toCOMPortNumbers(m_pComboNumber->currentText(), a, b);
     387bool UIMachineSettingsSerial::isPortEnabled() const
     388{
     389    return m_pCheckBoxPort->isChecked();
     390}
     391
     392QString UIMachineSettingsSerial::irq() const
     393{
     394    return m_pLineEditIRQ->text();
     395}
     396
     397QString UIMachineSettingsSerial::ioPort() const
     398{
     399    return m_pLineEditIOPort->text();
     400}
     401
     402QString UIMachineSettingsSerial::path() const
     403{
     404    return m_pEditorPath->text();
     405}
     406
     407void 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());
    288444}
    289445
    290446void UIMachineSettingsSerial::retranslateUi()
    291447{
    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."));
    320493
    321494    /* Translate combo-boxes content: */
     
    323496}
    324497
    325 void UIMachineSettingsSerial::sltGbSerialToggled(bool fOn)
     498void UIMachineSettingsSerial::sltHandlePortAvailabilityToggled(bool fOn)
    326499{
    327500    /* Update availability: */
    328501    m_pWidgetPortSettings->setEnabled(m_pCheckBoxPort->isChecked());
    329 
    330502    if (fOn)
    331503    {
    332         sltCbNumberActivated(m_pComboNumber->currentText());
     504        sltHandlePortStandardOptionActivated(m_pComboNumber->currentText());
    333505        sltHandlePortModeChange(m_pComboMode->currentIndex());
    334506    }
    335507
    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
     513void UIMachineSettingsSerial::sltHandlePortStandardOptionActivated(const QString &strText)
     514{
     515    /* Update availability: */
    342516    ulong uIRQ, uIOBase;
    343517    bool fStd = UITranslator::toCOMPortNumbers(strText, uIRQ, uIOBase);
    344 
    345518    m_pLineEditIRQ->setEnabled(!fStd);
    346519    m_pLineEditIOPort->setEnabled(!fStd);
     
    351524    }
    352525
    353     /* Revalidate: */
    354     m_pParent->revalidate();
     526    /* Notify validity changed: */
     527    emit sigValidityChanged();
    355528}
    356529
    357530void UIMachineSettingsSerial::sltHandlePortModeChange(int iIndex)
    358531{
     532    /* Update availability: */
    359533    const KPortMode enmMode = m_pComboMode->itemData(iIndex).value<KPortMode>();
    360534    m_pCheckBoxPipe->setEnabled(enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP);
     
    362536    m_pLabelPath->setEnabled(enmMode != KPortMode_Disconnected);
    363537
    364     /* Revalidate: */
    365     m_pParent->revalidate();
     538    /* Notify validity changed: */
     539    emit sigValidityChanged();
    366540}
    367541
     
    505679void UIMachineSettingsSerial::prepareConnections()
    506680{
    507     connect(m_pCheckBoxPort, &QCheckBox::toggled, this, &UIMachineSettingsSerial::sltGbSerialToggled);
     681    if (m_pCheckBoxPort)
     682        connect(m_pCheckBoxPort, &QCheckBox::toggled, this, &UIMachineSettingsSerial::sltHandlePortAvailabilityToggled);
    508683#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);
    511687#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);
    514691#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);
    520701}
    521702
     
    556737
    557738UIMachineSettingsSerialPage::UIMachineSettingsSerialPage()
    558     : m_pTabWidget(0)
    559     , m_pCache(0)
    560 {
    561     /* Prepare: */
     739    : m_pCache(0)
     740    , m_pTabWidget(0)
     741{
    562742    prepare();
    563743}
     
    565745UIMachineSettingsSerialPage::~UIMachineSettingsSerialPage()
    566746{
    567     /* Cleanup: */
    568747    cleanup();
    569748}
     
    587766    m_pCache->clear();
    588767
     768    /* Cache lists: */
     769    refreshPorts();
     770    refreshPaths();
     771
    589772    /* Prepare old data: */
    590773    UIDataSettingsMachineSerial oldSerialData;
    591774
    592     /* For each port: */
     775    /* For each serial port: */
    593776    for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
    594777    {
     
    641824
    642825        /* Load old data from cache: */
    643         pTab->loadPortData(m_pCache->child(iSlot).base());
     826        pTab->getPortDataFromCache(m_pCache->child(iSlot));
    644827
    645828        /* Setup tab order: */
     
    674857        AssertPtrReturnVoid(pTab);
    675858
    676         /* Prepare new data: */
    677         UIDataSettingsMachineSerialPort newPortData;
    678 
    679859        /* 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));
    684861    }
    685862
     
    702879bool UIMachineSettingsSerialPage::validate(QList<UIValidationMessage> &messages)
    703880{
     881    /* Sanity check: */
     882    if (!m_pTabWidget)
     883        return false;
     884
    704885    /* 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: */
    712889    for (int iIndex = 0; iIndex < m_pTabWidget->count(); ++iIndex)
    713890    {
    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;
    769895    }
    770896
    771897    /* Return result: */
    772     return fPass;
     898    return fValid;
    773899}
    774900
    775901void UIMachineSettingsSerialPage::retranslateUi()
    776902{
    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());
    782912    }
    783913}
     
    785915void UIMachineSettingsSerialPage::polishPage()
    786916{
    787     /* Get the count of serial port tabs: */
     917    /* Sanity check: */
     918    if (   !m_pCache
     919        || !m_pTabWidget)
     920        return;
     921
    788922    for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
    789923    {
     
    799933}
    800934
     935void UIMachineSettingsSerialPage::sltHandlePortChange()
     936{
     937    refreshPorts();
     938    revalidate();
     939}
     940
     941void UIMachineSettingsSerialPage::sltHandlePathChange()
     942{
     943    refreshPaths();
     944    revalidate();
     945}
     946
    801947void UIMachineSettingsSerialPage::prepare()
    802948{
     
    807953    /* Create main layout: */
    808954    QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
    809     AssertPtrReturnVoid(pLayoutMain);
     955    if (pLayoutMain)
    810956    {
    811957        /* Creating tab-widget: */
    812958        m_pTabWidget = new QITabWidget;
    813         AssertPtrReturnVoid(m_pTabWidget);
     959        if (m_pTabWidget)
    814960        {
    815961            /* How many ports to display: */
     
    817963
    818964            /* Create corresponding port tabs: */
    819             for (ulong uPort = 0; uPort < uCount; ++uPort)
     965            for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
    820966            {
    821967                /* Create port tab: */
    822968                UIMachineSettingsSerial *pTab = new UIMachineSettingsSerial(this);
    823                 AssertPtrReturnVoid(pTab);
     969                if (pTab)
    824970                {
     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
    825979                    /* Add tab into tab-widget: */
    826                     m_pTabWidget->addTab(pTab, pTab->pageTitle());
     980                    m_pTabWidget->addTab(pTab, pTab->tabTitle());
    827981                }
    828982            }
     
    839993    delete m_pCache;
    840994    m_pCache = 0;
     995}
     996
     997void 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
     1015void 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    }
    8411031}
    8421032
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.h

    r94333 r94675  
    4545    virtual ~UIMachineSettingsSerialPage() RT_OVERRIDE;
    4646
     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
    4752protected:
    4853
     
    7378    virtual void polishPage() RT_OVERRIDE;
    7479
     80private slots:
     81
     82    /** Handles port change. */
     83    void sltHandlePortChange();
     84    /** Handles path change. */
     85    void sltHandlePathChange();
     86
    7587private:
    7688
     
    8092    void cleanup();
    8193
     94    /** Repopulates ports. */
     95    void refreshPorts();
     96    /** Repopulates paths. */
     97    void refreshPaths();
     98
    8299    /** Saves existing data from cache. */
    83100    bool saveData();
     
    85102    bool savePortData(int iSlot);
    86103
    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;
    89108
    90109    /** Holds the page data cache instance. */
    91110    UISettingsCacheMachineSerial *m_pCache;
     111
     112    /** Holds the tab-widget instance. */
     113    QITabWidget *m_pTabWidget;
    92114};
    93115
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette