VirtualBox

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


Ignore:
Timestamp:
Sep 27, 2023 9:17:00 AM (16 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10523. Refactoring UIGuestOSTypeSelectionButton to adjust the new guest os type structure.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIGuestOSType.h

    r101278 r101285  
    4444
    4545
    46 
     46/** A wrapper and manager class for Guest OS types (IGuestOSType). Logically we structure os types into families
     47  *  e.g. Window, Linux etc. Some families have so-called variants which for Linux corresponds to distros, while some
     48  *  families have no variant. Under variants (and when no variant exists direcly under family) we have guest os
     49  *  types, e.g. Debian12_x64 etc. */
    4750class SHARED_LIBRARY_STUFF UIGuestOSTypeManager
    4851{
     
    5053public:
    5154
     55    /* A list of all OS families. 'first' of each pair is famil Id and 'second' is family description. */
    5256    typedef QVector<QPair<QString, QString> > UIGuestOSTypeFamilyInfo;
    5357    typedef QVector<QPair<QString, QString> > UIGuestOSTypeInfo;
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIGuestOSTypeSelectionButton.cpp

    r98103 r101285  
    3333/* GUI includes */
    3434#include "UICommon.h"
     35#include "UIGuestOSType.h"
    3536#include "UIGuestOSTypeSelectionButton.h"
    3637#include "UIIconPool.h"
    3738
     39/* Other VBox includes: */
     40#include "iprt/assert.h"
    3841
    3942UIGuestOSTypeSelectionButton::UIGuestOSTypeSelectionButton(QWidget *pParent)
     
    7679void UIGuestOSTypeSelectionButton::setOSTypeId(const QString &strOSTypeId)
    7780{
     81    if (m_strOSTypeId == strOSTypeId)
     82        return;
     83    const UIGuestOSTypeManager *pManager = uiCommon().guestOSTypeManager();
     84    AssertReturnVoid(pManager);
     85
    7886    m_strOSTypeId = strOSTypeId;
    79     CGuestOSType enmType = uiCommon().vmGuestOSType(strOSTypeId);
    8087
    8188#ifndef VBOX_WS_MAC
    8289    /* Looks ugly on the Mac: */
    83     setIcon(generalIconPool().guestOSTypePixmapDefault(enmType.GetId()));
     90    setIcon(generalIconPool().guestOSTypePixmapDefault(m_strOSTypeId));
    8491#endif
    8592
    86     setText(enmType.GetDescription());
     93    setText(pManager->getDescription(m_strOSTypeId));
    8794}
    8895
     
    9299}
    93100
     101void UIGuestOSTypeSelectionButton::createOSTypeMenu(const UIGuestOSTypeManager::UIGuestOSTypeInfo &typeList, QMenu *pMenu)
     102{
     103    for (int j = 0; j < typeList.size(); ++j)
     104    {
     105        const QPair<QString, QString> &typeInfo = typeList[j];
     106        QAction *pAction = pMenu->addAction(generalIconPool().guestOSTypePixmapDefault(typeInfo.first), typeInfo.second);
     107        connect(pAction, &QAction::triggered,
     108                m_pSignalMapper, static_cast<void(QSignalMapper::*)(void)>(&QSignalMapper::map));
     109        m_pSignalMapper->setMapping(pAction, typeInfo.first);
     110    }
     111}
     112
    94113void UIGuestOSTypeSelectionButton::populateMenu()
    95114{
    96     /* Clea initially: */
     115    /* Clear initially: */
    97116    m_pMainMenu->clear();
    98117
    99     /* Create a list of all possible OS types: */
    100     foreach(const QString &strFamilyId, uiCommon().vmGuestOSFamilyIDs())
     118    const UIGuestOSTypeManager *pManager = uiCommon().guestOSTypeManager();
     119    AssertReturnVoid(pManager);
     120    UIGuestOSTypeManager::UIGuestOSTypeFamilyInfo familyList = pManager->getFamilies();
     121
     122    for (int i = 0; i < familyList.size(); ++i)
    101123    {
    102         QMenu *pSubMenu = m_pMainMenu->addMenu(uiCommon().vmGuestOSFamilyDescription(strFamilyId));
    103         foreach (const CGuestOSType &comType, uiCommon().vmGuestOSTypeList(strFamilyId))
     124        const QPair<QString, QString> &familyInfo = familyList[i];
     125        QMenu *pSubMenu = m_pMainMenu->addMenu(familyInfo.second);
     126        QStringList variantList = pManager->getVariantListForFamilyId(familyInfo.first);
     127
     128        if (variantList.isEmpty())
     129            createOSTypeMenu(pManager->getTypeListForFamilyId(familyInfo.first), pSubMenu);
     130        else
    104131        {
    105             QAction *pAction = pSubMenu->addAction(generalIconPool().guestOSTypePixmapDefault(comType.GetId()),
    106                                                    comType.GetDescription());
    107             connect(pAction, &QAction::triggered,
    108                     m_pSignalMapper, static_cast<void(QSignalMapper::*)(void)>(&QSignalMapper::map));
    109             m_pSignalMapper->setMapping(pAction, comType.GetId());
     132            foreach (const QString &strVariant, variantList)
     133                createOSTypeMenu(pManager->getTypeListForVariant(strVariant), pSubMenu->addMenu(strVariant));
    110134        }
    111135    }
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIGuestOSTypeSelectionButton.h

    r98103 r101285  
    7272    /** Populates menu. */
    7373    void populateMenu();
    74 
     74    /** A help fundtion for populateMenu(). @p is the list of os type and @p pMenu is the menu to populate. */
     75    void createOSTypeMenu(const QVector<QPair<QString, QString> > &typeList, QMenu *pMenu);
    7576    /** Holds the current guest OS type ID. */
    7677    QString  m_strOSTypeId;
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