VirtualBox

Changeset 101713 in vbox for trunk


Ignore:
Timestamp:
Nov 2, 2023 9:51:36 AM (18 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159807
Message:

FE/Qt: bugref:10543: UINameAndSystemEditor cleanup: Missing part of distribution handling, this one is really big; It's about proper combo population, chosing defaults, restoring previously selected items while switching between distributions and some stuff related to availability and NLS.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UINameAndSystemEditor.cpp

    r101712 r101713  
    109109    if (m_pLabelFamily)
    110110        m_pLabelFamily->setEnabled(fEnabled);
     111    if (m_pLabelDistribution)
     112        m_pLabelDistribution->setEnabled(fEnabled);
    111113    if (m_pLabelType)
    112114        m_pLabelType->setEnabled(fEnabled);
    113115    if (m_pComboFamily)
    114116        m_pComboFamily->setEnabled(fEnabled);
     117    if (m_pComboDistribution)
     118        m_pComboDistribution->setEnabled(fEnabled);
    115119    if (m_pComboType)
    116120        m_pComboType->setEnabled(fEnabled);
     
    256260    if (m_pLabelFamily)
    257261        iWidth = qMax(iWidth, m_pLabelFamily->width());
     262    if (m_pLabelDistribution)
     263        iWidth = qMax(iWidth, m_pLabelDistribution->width());
    258264    if (m_pLabelType)
    259265        iWidth = qMax(iWidth, m_pLabelType->width());
     
    285291        m_pComboFamily->setToolTip(tr("Selects the operating system type that "
    286292                                      "you plan to install into this virtual machine."));
     293    if (m_pComboDistribution)
     294        m_pComboDistribution->setToolTip(tr("Selects the operating system subtype that "
     295                                            "you plan to install into this virtual machine."));
    287296    if (m_pComboType)
    288297        m_pComboType->setToolTip(tr("Selects the operating system version that "
     
    303312    /* Sanity check: */
    304313    AssertPtrReturnVoid(m_pComboFamily);
    305     AssertPtrReturnVoid(m_pComboDistribution);
    306314
    307315    /* Acquire new family ID: */
     
    309317    AssertReturnVoid(!m_strFamilyId.isEmpty());
    310318
    311     m_pComboDistribution->blockSignals(true);
    312     m_pLabelDistribution->setEnabled(true);
    313 
    314     m_pComboDistribution->setEnabled(true);
    315     m_pComboDistribution->clear();
    316 
    317     const QStringList distributionList = uiCommon().guestOSTypeManager().getSubtypeListForFamilyId(m_strFamilyId);
    318 
    319     if (distributionList.isEmpty())
    320     {
    321         m_pComboDistribution->setEnabled(false);
    322         m_pLabelDistribution->setEnabled(false);
    323         /* If subtype list is empty the all the types of the family are added to typ selection combo: */
    324         populateTypeCombo(uiCommon().guestOSTypeManager().getTypeListForFamilyId(m_strFamilyId));
    325     }
    326     else
    327     {
    328         /* Populate distribution combo: */
    329         /* If family is Linux then select Oracle Linux as subtype: */
    330         int iOracleIndex = -1;
    331         foreach (const QString &strDistribution, distributionList)
    332         {
    333             m_pComboDistribution->addItem(strDistribution);
    334             if (strDistribution.contains(QRegularExpression("Oracle.*Linux")))
    335                 iOracleIndex = m_pComboDistribution->count() - 1;
    336         }
    337         if (iOracleIndex != -1)
    338             m_pComboDistribution->setCurrentIndex(iOracleIndex);
    339 
    340         populateTypeCombo(uiCommon().guestOSTypeManager().getTypeListForSubtype(m_pComboDistribution->currentText()));
    341     }
    342     m_pComboDistribution->blockSignals(false);
    343 
    344319    /* Notify listeners about this change: */
    345320    emit sigOSFamilyChanged(m_strFamilyId);
     321
     322    /* Pupulate distribution combo: */
     323    populateDistributionCombo();
    346324}
    347325
     
    351329    m_strDistribution = strDistribution;
    352330
     331    /* If distribution list is empty, all the types of the family are added to type combo: */
     332    const UIGuestOSTypeManager::UIGuestOSTypeInfo types
     333         = m_strDistribution.isEmpty()
     334         ? uiCommon().guestOSTypeManager().getTypeListForFamilyId(m_strFamilyId)
     335         : uiCommon().guestOSTypeManager().getTypeListForSubtype(m_strDistribution);
     336
     337    /* Save the most recently used item: */
     338    m_familyToDistribution[m_strFamilyId] = m_strDistribution;
     339
    353340    /* Populate type combo: */
    354     populateTypeCombo(uiCommon().guestOSTypeManager().getTypeListForSubtype(strDistribution));
     341    populateTypeCombo(types);
    355342}
    356343
     
    368355
    369356    /* Save the most recently used item: */
    370     m_currentIds[m_strFamilyId] = m_strTypeId;
    371 
    372     /* Notifies listeners about OS type change: */
     357    if (m_strDistribution.isEmpty())
     358        m_familyToType[m_strFamilyId] = m_strTypeId;
     359    else
     360        m_distributionToType[m_strDistribution] = m_strTypeId;
     361
     362    /* Notifies listeners about this change: */
    373363    emit sigOsTypeChanged();
    374364}
     
    634624}
    635625
     626void UINameAndSystemEditor::populateDistributionCombo()
     627{
     628    /* Sanity check: */
     629    AssertPtrReturnVoid(m_pComboDistribution);
     630
     631    /* Acquire a list of suitable sub-types: */
     632    const QStringList distributions = uiCommon().guestOSTypeManager().getSubtypeListForFamilyId(m_strFamilyId);
     633    m_pLabelDistribution->setEnabled(!distributions.isEmpty());
     634    m_pComboDistribution->setEnabled(!distributions.isEmpty());
     635
     636    /* Block signals initially and clear the combo: */
     637    m_pComboDistribution->blockSignals(true);
     638    m_pComboDistribution->clear();
     639
     640    /* Populate distribution combo: */
     641    m_pComboDistribution->addItems(distributions);
     642
     643    /* Unblock signals finally: */
     644    m_pComboDistribution->blockSignals(false);
     645
     646    /* Select preferred OS distribution: */
     647    selectPreferredDistribution();
     648
     649    /* Trigger distribution change handler manually: */
     650    sltDistributionChanged(m_pComboDistribution->currentText());
     651}
     652
    636653void UINameAndSystemEditor::populateTypeCombo(const UIGuestOSTypeManager::UIGuestOSTypeInfo &types)
    637654{
     
    661678}
    662679
     680void UINameAndSystemEditor::selectPreferredDistribution()
     681{
     682    /* Try to restore current distribution if possible: */
     683    if (m_familyToDistribution.contains(m_strFamilyId))
     684        m_pComboDistribution->setCurrentText(m_familyToDistribution.value(m_strFamilyId));
     685    /* Oracle Linux for Linux family: */
     686    else if (m_strFamilyId == "Linux")
     687    {
     688        const int iOracleIndex = m_pComboDistribution->findText("Oracle", Qt::MatchContains);
     689        if (iOracleIndex != -1)
     690            m_pComboDistribution->setCurrentIndex(iOracleIndex);
     691    }
     692}
     693
    663694void UINameAndSystemEditor::selectPreferredType()
    664695{
     696    /* Try to restore current type if possible: */
     697    if (   m_familyToType.contains(m_strFamilyId)
     698        || m_distributionToType.contains(m_strDistribution))
     699    {
     700        const QString strCurrentType = m_familyToType.contains(m_strFamilyId)
     701                                     ? m_familyToType.value(m_strFamilyId)
     702                                     : m_distributionToType.contains(m_strDistribution)
     703                                     ? m_distributionToType.value(m_strDistribution)
     704                                     : QString();
     705        const int iCurrentIndex = m_pComboType->findData(strCurrentType);
     706        if (iCurrentIndex != -1)
     707            m_pComboType->setCurrentIndex(iCurrentIndex);
     708    }
    665709    /* Windows 11 for Windows family: */
    666     if (m_strFamilyId == "Windows")
     710    else if (m_strFamilyId == "Windows")
    667711    {
    668712        const QString strDefaultID = GUEST_OS_ID_STR_X64("Windows11");
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UINameAndSystemEditor.h

    r101711 r101713  
    169169    /** Pupulates VM OS family combo. */
    170170    void populateFamilyCombo();
     171    /** Pupulates VM OS distribution combo. */
     172    void populateDistributionCombo();
    171173    /** Pupulates VM OS type combo.
    172174      * @param  types  Brings the list of type pairs. */
    173175    void populateTypeCombo(const QList<QPair<QString, QString> > &types);
    174176
     177    /** Selects preferred distribution. */
     178    void selectPreferredDistribution();
    175179    /** Selects preferred type. */
    176180    void selectPreferredType();
     
    199203        QString  m_strTypeId;
    200204
     205        /** Holds the currently chosen OS distributions on per-family basis. */
     206        QMap<QString, QString>  m_familyToDistribution;
    201207        /** Holds the currently chosen OS type IDs on per-family basis. */
    202         QMap<QString, QString>  m_currentIds;
     208        QMap<QString, QString>  m_familyToType;
     209        /** Holds the currently chosen OS type IDs on per-distribution basis. */
     210        QMap<QString, QString>  m_distributionToType;
    203211    /** @} */
    204212
Note: See TracChangeset for help on using the changeset viewer.

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