VirtualBox

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


Ignore:
Timestamp:
Sep 20, 2023 7:25:00 AM (15 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10523 Adding a separate class to manage os guest types.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r101157 r101183  
    14051405        src/globals/UIErrorString.cpp \
    14061406        src/globals/UIExtension.cpp \
     1407        src/globals/UIGuestOSTypeII.cpp \
    14071408        src/globals/UIIconPool.cpp \
    14081409        src/globals/UIImageTools.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r101035 r101183  
    6363#include "UIConverter.h"
    6464#include "UIDesktopWidgetWatchdog.h"
     65#include "UIGuestOSTypeII.h"
    6566#include "UIExtraDataDefs.h"
    6667#include "UIExtraDataManager.h"
     
    214215    , m_fWrappersValid(false)
    215216    , m_fVBoxSVCAvailable(true)
     217    , m_pGuestOSTypeManager(new UIGuestOSTypeManager)
    216218    , m_pThreadPool(0)
    217219    , m_pThreadPoolCloud(0)
     
    224226UICommon::~UICommon()
    225227{
     228    delete m_pGuestOSTypeManager;
    226229    /* Unassign instance: */
    227230    s_pInstance = 0;
     
    30143017            {
    30153018                const CGuestOSType os = guestOSTypes.at(i);
     3019                //printf("%s -- %s -- %s\n", qPrintable(os.GetId()), qPrintable(os.GetVariant()), qPrintable(os.GetDescription()));
    30163020                const QString strFamilyID = os.GetFamilyId();
    30173021                const QString strFamilyDescription = os.GetFamilyDescription();
     
    30263030        }
    30273031    }
    3028 
     3032    if (m_pGuestOSTypeManager)
     3033        m_pGuestOSTypeManager->reCacheGuestOSTypes(guestOSTypes);
    30293034    /* Mark wrappers valid: */
    30303035    m_fWrappersValid = true;
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h

    r100064 r101183  
    6767class CUSBDevice;
    6868class UIActionPool;
     69class UIGuestOSTypeManager;
    6970class UIMedium;
    7071class UIMediumEnumerator;
     
    751752        /** Holds the guest OS types for each family ID. */
    752753        QList<QList<CGuestOSType> >  m_guestOSTypes;
     754        UIGuestOSTypeManager *m_pGuestOSTypeManager;
    753755    /** @} */
    754756
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIGuestOSTypeII.cpp

    r101147 r101183  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIVersion class implementation.
     3 * VBox Qt GUI - UIGuestOSTypeII class implementation.
    44 */
    55
     
    2626 */
    2727
    28 /* Qt includes: */
    29 #include <QStringList>
    30 
    3128/* GUI includes: */
    32 #include "UIVersion.h"
    33 
    34 /* Other VBox includes: */
    35 #include <iprt/string.h>
     29#include "UIGuestOSTypeII.h"
    3630
    3731
    38 UIVersion::UIVersion()
    39     : m_x(-1)
    40     , m_y(-1)
    41     , m_z(-1)
     32void UIGuestOSTypeManager::reCacheGuestOSTypes(const CGuestOSTypeVector &guestOSTypes)
     33{
     34    m_guestOSTypes.clear();
     35    m_guestOSFamilyIds.clear();
     36    m_guestOSTypesPerFamily.clear();
     37    QList<CGuestOSType> otherOSTypes;
     38    foreach (const CGuestOSType &comType, guestOSTypes)
     39    {
     40        if (comType.GetFamilyId().contains("other", Qt::CaseInsensitive))
     41        {
     42            otherOSTypes << comType;
     43            continue;
     44        }
     45        addGuestOSType(comType);
     46    }
     47    /* Add OS types with family other to the end of the lists: */
     48    foreach (const CGuestOSType &comType, otherOSTypes)
     49        addGuestOSType(comType);
     50
     51    for (int i = 0; i < m_guestOSTypes.size(); ++i)
     52    {
     53        QList<int> &indexList = m_guestOSTypesPerFamily[m_guestOSTypes[i].getFamilyId()];
     54        indexList << i;
     55    }
     56
     57    // foreach (const QString &strFamilyId, m_guestOSFamilyIds)
     58    // {
     59    //     printf(" ----family---%s\n", qPrintable(strFamilyId));
     60    //     const QList<int> &indices = m_guestOSTypesPerFamily[strFamilyId];
     61    //     if (!m_guestOSTypesPerFamily.contains(strFamilyId))
     62    //     {
     63    //         printf("\t-----empty\n");
     64    //         continue;
     65    //     }
     66    //     for (int i = 0; i < indices.size(); ++i)
     67    //     {
     68    //         if (indices[i] >= 0 && indices[i] < m_guestOSTypes.size())
     69    //         {
     70    //             //printf("\t%s %s\n", qPrintable(m_guestOSTypes[indices[i]].getDescription()), qPrintable(m_guestOSTypes[indices[i]].getVariant()));
     71    //         }
     72    //     }
     73    // }
     74}
     75
     76void UIGuestOSTypeManager::addGuestOSType(const CGuestOSType &comType)
     77{
     78    m_guestOSTypes << UIGuestOSTypeII(comType);
     79    const QString &strFamilyId = m_guestOSTypes.last().getFamilyId();
     80    if (!m_guestOSFamilyIds.contains(strFamilyId))
     81        m_guestOSFamilyIds << strFamilyId;
     82}
     83
     84UIGuestOSTypeII::UIGuestOSTypeII(const CGuestOSType &comGuestOSType)
     85    : m_comGuestOSType(comGuestOSType)
    4286{
    4387}
    4488
    45 UIVersion::UIVersion(const QString &strFullVersionInfo)
    46     : m_x(-1)
    47     , m_y(-1)
    48     , m_z(-1)
     89const QString &UIGuestOSTypeII::getFamilyId()
    4990{
    50     const QStringList fullVersionInfo = strFullVersionInfo.split('_');
    51     if (fullVersionInfo.size() > 0)
    52     {
    53         const QStringList versionIndexes = fullVersionInfo.at(0).split('.');
    54         if (versionIndexes.size() > 0)
    55             m_x = versionIndexes[0].toInt();
    56         if (versionIndexes.size() > 1)
    57             m_y = versionIndexes[1].toInt();
    58         if (versionIndexes.size() > 2)
    59             m_z = versionIndexes[2].toInt();
    60     }
    61     if (fullVersionInfo.size() > 1)
    62         m_strPostfix = fullVersionInfo.at(1);
     91    if (m_strFamilyId.isEmpty() && m_comGuestOSType.isOk())
     92        m_strFamilyId = m_comGuestOSType.GetFamilyId();
     93    return m_strFamilyId;
    6394}
    6495
    65 bool UIVersion::isValid() const
     96const QString &UIGuestOSTypeII::getFamilyDescription()
    6697{
    67     return    (m_x != -1)
    68            && (m_y != -1)
    69            && (m_z != -1);
     98    if (m_strFamilyDescription.isEmpty() && m_comGuestOSType.isOk())
     99        m_strFamilyDescription = m_comGuestOSType.GetFamilyDescription();
     100    return m_strFamilyDescription;
    70101}
    71102
    72 bool UIVersion::equal(const UIVersion &other) const
     103const QString &UIGuestOSTypeII::getId()
    73104{
    74     return    (m_x == other.m_x)
    75            && (m_y == other.m_y)
    76            && (m_z == other.m_z)
    77            && (m_strPostfix == other.m_strPostfix);
     105    if (m_strId.isEmpty() && m_comGuestOSType.isOk())
     106        m_strId = m_comGuestOSType.GetId();
     107    return m_strId;
    78108}
    79109
    80 bool UIVersion::operator<(const UIVersion &other) const
     110const QString &UIGuestOSTypeII::getVariant()
    81111{
    82     return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) < 0;
     112    if (m_strVariant.isEmpty() && m_comGuestOSType.isOk())
     113        m_strVariant = m_comGuestOSType.GetVariant();
     114    return m_strVariant;
    83115}
    84116
    85 bool UIVersion::operator<=(const UIVersion &other) const
     117const QString &UIGuestOSTypeII::getDescription()
    86118{
    87     return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) <= 0;
     119    if (m_strDescription.isEmpty() && m_comGuestOSType.isOk())
     120        m_strDescription = m_comGuestOSType.GetDescription();
     121    return m_strDescription;
    88122}
    89 
    90 bool UIVersion::operator>(const UIVersion &other) const
    91 {
    92     return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) > 0;
    93 }
    94 
    95 bool UIVersion::operator>=(const UIVersion &other) const
    96 {
    97     return RTStrVersionCompare(toString().toUtf8().constData(), other.toString().toUtf8().constData()) >= 0;
    98 }
    99 
    100 QString UIVersion::toString() const
    101 {
    102     return m_strPostfix.isEmpty() ? QString("%1.%2.%3").arg(m_x).arg(m_y).arg(m_z)
    103                                   : QString("%1.%2.%3_%4").arg(m_x).arg(m_y).arg(m_z).arg(m_strPostfix);
    104 }
    105 
    106 UIVersion UIVersion::effectiveReleasedVersion() const
    107 {
    108     /* First, we just copy the current one: */
    109     UIVersion version = *this;
    110 
    111     /* If this version being developed: */
    112     if (version.z() % 2 == 1)
    113     {
    114         /* If this version being developed on release branch (we guess the right one): */
    115         if (version.z() < 97)
    116             version.setZ(version.z() - 1);
    117         /* If this version being developed on trunk (we use hardcoded one for now): */
    118         else
    119             version.setZ(8); /* Current .z for 6.0.z */
    120     }
    121 
    122     /* Finally, we just return that we have:  */
    123     return version;
    124 }
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIGuestOSTypeII.h

    r101147 r101183  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIVersion class declaration.
     3 * VBox Qt GUI - UIGuestOSTypeII class declaration.
    44 */
    55
     
    2626 */
    2727
    28 #ifndef FEQT_INCLUDED_SRC_globals_UIVersion_h
    29 #define FEQT_INCLUDED_SRC_globals_UIVersion_h
     28#ifndef FEQT_INCLUDED_SRC_globals_UIGuestOSTypeII_h
     29#define FEQT_INCLUDED_SRC_globals_UIGuestOSTypeII_h
    3030#ifndef RT_WITHOUT_PRAGMA_ONCE
    3131# pragma once
     
    3333
    3434/* Qt includes: */
     35#include <QList>
     36#include <QMap>
    3537#include <QString>
    3638
    37 /** Represents VirtualBox version wrapper. */
    38 class UIVersion
     39/* COM includes: */
     40#include "COMEnums.h"
     41#include "CGuestOSType.h"
     42
     43
     44class UIGuestOSTypeII;
     45
     46class UIGuestOSTypeManager
     47{
     48
     49public:
     50
     51    void reCacheGuestOSTypes(const CGuestOSTypeVector &guestOSTypes);
     52
     53private:
     54
     55    void addGuestOSType(const CGuestOSType &comType);
     56
     57    QList<UIGuestOSTypeII> m_guestOSTypes;
     58    QStringList m_guestOSFamilyIds;
     59    /* Key is family id (linux, windows, etc) and value is the list of indices to m_guestOSTypes. */
     60    QMap<QString, QList<int> > m_guestOSTypesPerFamily;
     61    /* Key is variant (debian, ubuntu, ) and value is the list of indices to m_guestOSTypes. */
     62    QMap<QString, QList<int> > m_guestOSTypesPerVariant;
     63};
     64
     65/** A wrapper around CGuestOSType. */
     66class SHARED_LIBRARY_STUFF UIGuestOSTypeII
    3967{
    4068public:
    4169
    42     /** Constructs default object. */
    43     UIVersion();
    44     /** Constructs object based on parsed @a strFullVersionInfo. */
    45     UIVersion(const QString &strFullVersionInfo);
    4670
    47     /** Returns whether this object is valid. */
    48     bool isValid() const;
     71    UIGuestOSTypeII(const CGuestOSType &comGuestOSType);
    4972
    50     /** Returns whether this object is equal to @a other. */
    51     bool equal(const UIVersion &other) const;
    52     /** Checks whether this object is equal to @a other. */
    53     bool operator==(const UIVersion &other) const { return equal(other); }
    54     /** Checks whether this object is NOT equal to @a other. */
    55     bool operator!=(const UIVersion &other) const { return !equal(other); }
     73    const QString &getFamilyId();
     74    const QString &getFamilyDescription();
     75    const QString &getId();
     76    const QString &getVariant();
     77    const QString &getDescription();
    5678
    57     /** Checks whether this object is less than @a other. */
    58     bool operator<(const UIVersion &other) const;
    59     /** Checks whether this object is less or equal than @a other. */
    60     bool operator<=(const UIVersion &other) const;
    61     /** Checks whether this object is greater than @a other. */
    62     bool operator>(const UIVersion &other) const;
    63     /** Checks whether this object is greater or equal than @a other. */
    64     bool operator>=(const UIVersion &other) const;
    65 
    66     /** Returns object string representation. */
    67     QString toString() const;
    68 
    69     /** Returns the object X value. */
    70     int x() const { return m_x; }
    71     /** Returns the object Y value. */
    72     int y() const { return m_y; }
    73     /** Returns the object Z value. */
    74     int z() const { return m_z; }
    75     /** Returns the object postfix. */
    76     QString postfix() const { return m_strPostfix; }
    77 
    78     /** Defines the object @a x value. */
    79     void setX(int x) { m_x = x; }
    80     /** Defines the object @a y value. */
    81     void setY(int y) { m_y = y; }
    82     /** Defines the object @a z value. */
    83     void setZ(int z) { m_z = z; }
    84     /** Defines the object @a strPostfix. */
    85     void setPostfix(const QString &strPostfix) { m_strPostfix = strPostfix; }
    86 
    87     /** Returns effective released version guessed or hardcoded for this one version.
    88       * This can be even the version itself. */
    89     UIVersion effectiveReleasedVersion() const;
    9079
    9180private:
    9281
    93     /** Holds the object X value. */
    94     int  m_x;
    95     /** Holds the object Y value. */
    96     int  m_y;
    97     /** Holds the object Z value. */
    98     int  m_z;
     82    /** @name CGuestOSType properties. Cached here for a faster access.
     83      * @{ */
     84        QString m_strFamilyId;
     85        QString m_strFamilyDescription;
     86        QString m_strId;
     87        QString m_strVariant;
     88        QString m_strDescription;
     89    /** @} */
    9990
    100     /** Holds the object postfix. */
    101     QString  m_strPostfix;
     91    CGuestOSType m_comGuestOSType;
     92
    10293};
    10394
    104 #endif /* !FEQT_INCLUDED_SRC_globals_UIVersion_h */
     95#endif /* !FEQT_INCLUDED_SRC_globals_UIGuestOSTypeII_h */
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