VirtualBox

Changeset 60182 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 24, 2016 3:13:06 PM (9 years ago)
Author:
vboxsync
Message:

GUI/UIExtraDataManager: Look both machine and global extra data for simple feature checks like "GUI/HidLedsSync".

  • Adds a extraDataStringUnion() method for getting extra data union style.
  • Modifies isFeatureRestricted() and isFeatureAllowed() to use extraDataStringUnion() to retrieve the value.

This change allows deployments to use VBoxManage (or similar) to do global
configuration of what used to be VM specific settings. For example the
following will disable keyboard LED synchronization (Windows + OS X)
for all VMs:

VBoxManage setextradata global GUI/HidLedsSync false

Location:
trunk/src/VBox/Frontends/VirtualBox/src/extradata
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r59985 r60182  
    19651965        hotloadMachineExtraDataMap(strID);
    19661966
    1967     /* Read-only access corresponding map: */
     1967    /* Make a read-only copy of the corresponding map: */
    19681968    const ExtraDataMap data = m_data.value(strID);
    19691969
     
    19741974    /* Returns corresponding value: */
    19751975    return data[strKey];
     1976}
     1977
     1978QString UIExtraDataManager::extraDataStringUnion(const QString &strKey, const QString &strID)
     1979{
     1980    /* Machine extra-data first: */
     1981    if (strID != GlobalID)
     1982    {
     1983        MapOfExtraDataMaps::const_iterator itMap = m_data.constFind(strID);
     1984
     1985        /* Hot-load machine extra-data map if necessary: */
     1986        if (itMap == m_data.constEnd())
     1987        {
     1988            hotloadMachineExtraDataMap(strID);
     1989            itMap = m_data.constFind(strID);
     1990        }
     1991        if (itMap != m_data.constEnd())
     1992        {
     1993            /* Return string if present in the map: */
     1994            ExtraDataMap::const_iterator itValue = itMap->constFind(strKey);
     1995            if (itValue != itMap->constEnd())
     1996                return *itValue;
     1997        }
     1998    }
     1999
     2000    /* Global extra-data: */
     2001    MapOfExtraDataMaps::const_iterator itMap = m_data.constFind(GlobalID);
     2002    if (itMap != m_data.constEnd())
     2003    {
     2004        ExtraDataMap::const_iterator itValue = itMap->constFind(strKey);
     2005        if (itValue != itMap->constEnd())
     2006            return *itValue;
     2007    }
     2008
     2009    /* Not found, return null string: */
     2010    return QString();
    19762011}
    19772012
     
    40444079bool UIExtraDataManager::isFeatureAllowed(const QString &strKey, const QString &strID /* = GlobalID */)
    40454080{
    4046     /* Hot-load machine extra-data map if necessary: */
    4047     if (strID != GlobalID && !m_data.contains(strID))
    4048         hotloadMachineExtraDataMap(strID);
    4049 
    4050     /* Read-only access corresponding map: */
    4051     const ExtraDataMap data = m_data.value(strID);
    4052 
    4053     /* 'false' if value was not set: */
    4054     if (!data.contains(strKey))
     4081    /* Get the value. Return 'false' if not found: */
     4082    const QString strValue = extraDataStringUnion(strKey, strID);
     4083    if (strValue.isNull())
    40554084        return false;
    40564085
    40574086    /* Check corresponding value: */
    4058     const QString &strValue = data[strKey];
    40594087    return    strValue.compare("true", Qt::CaseInsensitive) == 0
    40604088           || strValue.compare("yes", Qt::CaseInsensitive) == 0
     
    40654093bool UIExtraDataManager::isFeatureRestricted(const QString &strKey, const QString &strID /* = GlobalID */)
    40664094{
    4067     /* Hot-load machine extra-data map if necessary: */
    4068     if (strID != GlobalID && !m_data.contains(strID))
    4069         hotloadMachineExtraDataMap(strID);
    4070 
    4071     /* Read-only access corresponding map: */
    4072     const ExtraDataMap data = m_data.value(strID);
    4073 
    4074     /* 'false' if value was not set: */
    4075     if (!data.contains(strKey))
     4095    /* Get the value. Return 'false' if not found: */
     4096    const QString strValue = extraDataStringUnion(strKey, strID);
     4097    if (strValue.isNull())
    40764098        return false;
    40774099
    40784100    /* Check corresponding value: */
    4079     const QString &strValue = data[strKey];
    40804101    return    strValue.compare("false", Qt::CaseInsensitive) == 0
    40814102           || strValue.compare("no", Qt::CaseInsensitive) == 0
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r58689 r60182  
    592592#endif /* DEBUG */
    593593
     594    /**
     595     * Retrieves an extra-data key from both machine and global sources.
     596     *
     597     * If @a strID isn't #GlobalID, this will first check the extra-data associated
     598     * with the machine given by @a strID then fallback on the global extra-data.
     599     *
     600     * @returns String value if found, null string if not.
     601     * @param   strKey      The extra-data key to get.
     602     * @param   strID       Machine UUID or #GlobalID.
     603     * @param   strValue    Where to return the value when found.
     604     */
     605    QString extraDataStringUnion(const QString &strKey, const QString &strID);
    594606    /** Determines whether feature corresponding to passed @a strKey is allowed.
    595       * If valid @a strID is set => applies to machine extra-data, otherwise => to global one. */
     607     *  If valid @a strID is set => applies to machine extra-data and global,
     608     *  otherwise => only to global one. */
    596609    bool isFeatureAllowed(const QString &strKey, const QString &strID = GlobalID);
    597610    /** Determines whether feature corresponding to passed @a strKey is restricted.
    598       * If valid @a strID is set => applies to machine extra-data, otherwise => to global one. */
     611     *  If valid @a strID is set => applies to machine extra-data and global,
     612     *  otherwise => only to global one. */
    599613    bool isFeatureRestricted(const QString &strKey, const QString &strID = GlobalID);
    600614
     
    616630    UIExtraDataEventHandler *m_pHandler;
    617631
     632    /** Maps of extra data maps.  The index is a UUID string. */
     633    typedef QMap<QString, ExtraDataMap> MapOfExtraDataMaps;
    618634    /** Holds extra-data map instance. */
    619     QMap<QString, ExtraDataMap> m_data;
     635    MapOfExtraDataMaps m_data;
    620636
    621637#ifdef DEBUG
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