VirtualBox

Ignore:
Timestamp:
Jan 22, 2020 11:20:36 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9611: UIMachineSettingsSerial: Get rid of hardcoded port modes, instead acquire these modes through CSystemProperties interface; Besides that, using more modern Qt approach to cache enum data directly without casting it to int or string.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.cpp

    r80736 r82820  
    122122    void sltGbSerialToggled(bool fOn);
    123123    void sltCbNumberActivated(const QString &strText);
    124     void sltCbModeActivated(const QString &strText);
     124    /** Handles port mode change to item with certain @a iIndex. */
     125    void sltHandlePortModeChange(int iIndex);
    125126
    126127private:
     
    129130    void prepareValidation();
    130131
     132    /** Populates combo-boxes. */
     133    void populateComboboxes();
     134
     135    /** Holds the parent page reference. */
    131136    UIMachineSettingsSerialPage *m_pParent;
    132     int m_iSlot;
     137
     138    /** Holds the port slot number. */
     139    int        m_iSlot;
     140    /** Holds the port mode. */
     141    KPortMode  m_enmPortMode;
    133142};
    134143
     
    142151    , m_pParent(pParent)
    143152    , m_iSlot(-1)
     153    , m_enmPortMode(KPortMode_Max)
    144154{
    145155    /* Apply UI decorations: */
     
    159169    mCbNumber->insertItem(0, uiCommon().toCOMPortName(0, 0));
    160170    mCbNumber->insertItems(0, uiCommon().COMPortNames());
    161 
    162     mCbMode->addItem(""); /* KPortMode_Disconnected */
    163     mCbMode->addItem(""); /* KPortMode_HostPipe */
    164     mCbMode->addItem(""); /* KPortMode_HostDevice */
    165     mCbMode->addItem(""); /* KPortMode_RawFile */
    166     mCbMode->addItem(""); /* KPortMode_TCP */
    167171
    168172    /* Setup connections: */
     
    171175    connect(mCbNumber, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::activated),
    172176            this, &UIMachineSettingsSerial::sltCbNumberActivated);
    173     connect(mCbMode, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::activated),
    174             this, &UIMachineSettingsSerial::sltCbModeActivated);
     177    connect(mCbMode, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
     178            this, &UIMachineSettingsSerial::sltHandlePortModeChange);
    175179
    176180    /* Prepare validation: */
     
    186190    ulong uIRQ, uIOBase;
    187191    const bool fStd = uiCommon().toCOMPortNumbers(mCbNumber->currentText(), uIRQ, uIOBase);
    188     const KPortMode enmMode = gpConverter->fromString<KPortMode>(mCbMode->currentText());
     192    const KPortMode enmMode = mCbMode->currentData().value<KPortMode>();
    189193    mGbSerial->setEnabled(m_pParent->isMachineOffline());
    190194    mLbNumber->setEnabled(m_pParent->isMachineOffline());
     
    198202    mCbPipe->setEnabled(   (enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP)
    199203                        && m_pParent->isMachineOffline());
    200     mLbPath->setEnabled(m_pParent->isMachineOffline());
    201     mLePath->setEnabled(enmMode != KPortMode_Disconnected && m_pParent->isMachineOffline());
     204    mLbPath->setEnabled(   enmMode != KPortMode_Disconnected
     205                        && m_pParent->isMachineOffline());
     206    mLePath->setEnabled(   enmMode != KPortMode_Disconnected
     207                        && m_pParent->isMachineOffline());
    202208}
    203209
     
    212218    mLeIRQ->setText(QString::number(portData.m_uIRQ));
    213219    mLeIOPort->setText("0x" + QString::number(portData.m_uIOBase, 16).toUpper());
    214     mCbMode->setCurrentIndex(mCbMode->findText(gpConverter->toString(portData.m_hostMode)));
     220    m_enmPortMode = portData.m_hostMode;
    215221    mCbPipe->setChecked(!portData.m_fServer);
    216222    mLePath->setText(portData.m_strPath);
    217223
     224    /* Repopulate combo-boxes content: */
     225    populateComboboxes();
    218226    /* Ensure everything is up-to-date */
    219227    sltGbSerialToggled(mGbSerial->isChecked());
     
    227235    portData.m_uIOBase = mLeIOPort->text().toULong(NULL, 0);
    228236    portData.m_fServer = !mCbPipe->isChecked();
    229     portData.m_hostMode = gpConverter->fromString<KPortMode>(mCbMode->currentText());
     237    portData.m_hostMode = mCbMode->currentData().value<KPortMode>();
    230238    portData.m_strPath = QDir::toNativeSeparators(mLePath->text());
    231239}
     
    261269    mCbNumber->setItemText(mCbNumber->count() - 1, uiCommon().toCOMPortName(0, 0));
    262270
    263     mCbMode->setItemText(4, gpConverter->toString(KPortMode_TCP));
    264     mCbMode->setItemText(3, gpConverter->toString(KPortMode_RawFile));
    265     mCbMode->setItemText(2, gpConverter->toString(KPortMode_HostDevice));
    266     mCbMode->setItemText(1, gpConverter->toString(KPortMode_HostPipe));
    267     mCbMode->setItemText(0, gpConverter->toString(KPortMode_Disconnected));
     271    /* Translate combo-boxes content: */
     272    populateComboboxes();
    268273}
    269274
     
    273278    {
    274279        sltCbNumberActivated(mCbNumber->currentText());
    275         sltCbModeActivated(mCbMode->currentText());
     280        sltHandlePortModeChange(mCbMode->currentIndex());
    276281    }
    277282
     
    297302}
    298303
    299 void UIMachineSettingsSerial::sltCbModeActivated(const QString &strText)
    300 {
    301     KPortMode enmMode = gpConverter->fromString<KPortMode>(strText);
     304void UIMachineSettingsSerial::sltHandlePortModeChange(int iIndex)
     305{
     306    const KPortMode enmMode = mCbMode->itemData(iIndex).value<KPortMode>();
    302307    mCbPipe->setEnabled(enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP);
    303308    mLePath->setEnabled(enmMode != KPortMode_Disconnected);
     309    mLbPath->setEnabled(enmMode != KPortMode_Disconnected);
    304310
    305311    /* Revalidate: */
     
    313319    connect(mLeIOPort, &QLineEdit::textChanged, m_pParent, &UIMachineSettingsSerialPage::revalidate);
    314320    connect(mLePath, &QLineEdit::textChanged, m_pParent, &UIMachineSettingsSerialPage::revalidate);
     321}
     322
     323void UIMachineSettingsSerial::populateComboboxes()
     324{
     325    /* Port mode: */
     326    {
     327        /* Clear the port mode combo-box: */
     328        mCbMode->clear();
     329
     330        /* Load currently supported port moded: */
     331        CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
     332        QVector<KPortMode> supportedModes = comProperties.GetSupportedPortModes();
     333        /* Take currently requested mode into account if it's sane: */
     334        if (!supportedModes.contains(m_enmPortMode) && m_enmPortMode != KPortMode_Max)
     335            supportedModes.prepend(m_enmPortMode);
     336
     337        /* Populate port modes: */
     338        int iPortModeIndex = 0;
     339        foreach (const KPortMode &enmMode, supportedModes)
     340        {
     341            mCbMode->insertItem(iPortModeIndex, gpConverter->toString(enmMode));
     342            mCbMode->setItemData(iPortModeIndex, QVariant::fromValue(enmMode));
     343            mCbMode->setItemData(iPortModeIndex, mCbMode->itemText(iPortModeIndex), Qt::ToolTipRole);
     344            ++iPortModeIndex;
     345        }
     346
     347        /* Choose requested port mode: */
     348        const int iIndex = mCbMode->findData(m_enmPortMode);
     349        mCbMode->setCurrentIndex(iIndex != -1 ? iIndex : 0);
     350    }
    315351}
    316352
     
    493529        ports << pair;
    494530
    495         const KPortMode enmMode = gpConverter->fromString<KPortMode>(pPage->mCbMode->currentText());
     531        const KPortMode enmMode = pPage->mCbMode->currentData().value<KPortMode>();
    496532        if (enmMode != KPortMode_Disconnected)
    497533        {
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