VirtualBox

Ignore:
Timestamp:
Feb 8, 2017 4:04:22 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Global preferences: Network page: Integrate settings caching.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.cpp

    r65678 r65687  
    393393    : m_pActionAddNetworkNAT(0), m_pActionDelNetworkNAT(0), m_pActionEditNetworkNAT(0)
    394394    , m_pActionAddNetworkHost(0), m_pActionDelNetworkHost(0), m_pActionEditNetworkHost(0)
    395     , m_fChanged(false)
    396395{
    397396    /* Apply UI decorations: */
     
    517516    UISettingsPageGlobal::fetchData(data);
    518517
    519     /* Load to cache: */
    520     m_cache.m_networksNAT.clear();
    521     const CNATNetworkVector &networks = vboxGlobal().virtualBox().GetNATNetworks();
    522     foreach (const CNATNetwork &network, networks)
    523         m_cache.m_networksNAT << generateDataNetworkNAT(network);
    524     m_cache.m_networksHost.clear();
    525     const CHostNetworkInterfaceVector &interfaces = vboxGlobal().host().GetNetworkInterfaces();
    526     foreach (const CHostNetworkInterface &iface, interfaces)
     518    /* Clear cache initially: */
     519    m_cache.clear();
     520
     521    /* Prepare old data: */
     522    UIDataSettingsGlobalNetwork oldData;
     523
     524    /* Gather old data: */
     525    foreach (const CNATNetwork &network, vboxGlobal().virtualBox().GetNATNetworks())
     526        oldData.m_networksNAT << generateDataNetworkNAT(network);
     527    foreach (const CHostNetworkInterface &iface, vboxGlobal().host().GetNetworkInterfaces())
    527528        if (iface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)
    528             m_cache.m_networksHost << generateDataNetworkHost(iface);
     529            oldData.m_networksHost << generateDataNetworkHost(iface);
     530
     531    /* Cache old data: */
     532    m_cache.cacheInitialData(oldData);
    529533
    530534    /* Upload properties & settings to data: */
     
    534538void UIGlobalSettingsNetwork::getFromCache()
    535539{
    536     /* Fetch from cache: */
    537     foreach (const UIDataSettingsGlobalNetworkNAT &network, m_cache.m_networksNAT)
     540    /* Get old data from cache: */
     541    const UIDataSettingsGlobalNetwork &oldData = m_cache.base();
     542
     543    /* Load old data from cache: */
     544    foreach (const UIDataSettingsGlobalNetworkNAT &network, oldData.m_networksNAT)
    538545        createTreeItemNetworkNAT(network);
    539546    m_pTreeNetworkNAT->sortByColumn(1, Qt::AscendingOrder);
    540547    m_pTreeNetworkNAT->setCurrentItem(m_pTreeNetworkNAT->topLevelItem(0));
    541548    sltHandleCurrentItemChangeNetworkNAT();
    542     foreach (const UIDataSettingsGlobalNetworkHost &network, m_cache.m_networksHost)
     549    foreach (const UIDataSettingsGlobalNetworkHost &network, oldData.m_networksHost)
    543550        createTreeItemNetworkHost(network);
    544551    m_pTreeNetworkHost->sortByColumn(0, Qt::AscendingOrder);
     
    552559void UIGlobalSettingsNetwork::putToCache()
    553560{
    554     /* Upload to cache: */
    555     m_cache.m_networksNAT.clear();
     561    /* Prepare new data: */
     562    UIDataSettingsGlobalNetwork newData = m_cache.base();
     563
     564    /* Gather new data: */
     565    newData.m_networksNAT.clear();
    556566    for (int iNetworkIndex = 0; iNetworkIndex < m_pTreeNetworkNAT->topLevelItemCount(); ++iNetworkIndex)
    557567    {
     
    559569        UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(iNetworkIndex));
    560570        pItem->uploadNetworkData(data);
    561         m_cache.m_networksNAT << data;
    562     }
    563     m_cache.m_networksHost.clear();
     571        newData.m_networksNAT << data;
     572    }
     573    newData.m_networksHost.clear();
    564574    for (int iNetworkIndex = 0; iNetworkIndex < m_pTreeNetworkHost->topLevelItemCount(); ++iNetworkIndex)
    565575    {
     
    567577        UIItemNetworkHost *pItem = static_cast<UIItemNetworkHost*>(m_pTreeNetworkHost->topLevelItem(iNetworkIndex));
    568578        pItem->uploadNetworkData(data);
    569         m_cache.m_networksHost << data;
    570     }
     579        newData.m_networksHost << data;
     580    }
     581
     582    /* Cache new data: */
     583    m_cache.cacheCurrentData(newData);
    571584}
    572585
    573586void UIGlobalSettingsNetwork::saveFromCacheTo(QVariant &data)
    574587{
    575     /* Ensure settings were changed: */
    576     if (!m_fChanged)
    577         return;
    578 
    579588    /* Fetch data to properties & settings: */
    580589    UISettingsPageGlobal::fetchData(data);
    581590
    582     /* Save from cache: */
    583     foreach (const UIDataSettingsGlobalNetworkNAT &data, m_cache.m_networksNAT)
    584         saveCacheItemNetworkNAT(data);
    585     foreach (const UIDataSettingsGlobalNetworkHost &data, m_cache.m_networksHost)
    586         saveCacheItemNetworkHost(data);
     591    /* Save new data from cache: */
     592    if (m_cache.wasChanged())
     593    {
     594        if (m_cache.data().m_networksNAT != m_cache.base().m_networksNAT)
     595            foreach (const UIDataSettingsGlobalNetworkNAT &data, m_cache.data().m_networksNAT)
     596                saveCacheItemNetworkNAT(data);
     597        if (m_cache.data().m_networksHost != m_cache.base().m_networksHost)
     598            foreach (const UIDataSettingsGlobalNetworkHost &data, m_cache.data().m_networksHost)
     599                saveCacheItemNetworkHost(data);
     600    }
    587601
    588602    /* Upload properties & settings to data: */
     
    783797        pItem->fetchNetworkData(data);
    784798        sltHandleCurrentItemChangeNetworkNAT();
    785         m_fChanged = true;
    786799        /* Revalidate: */
    787800        revalidate();
     
    797810    /* Update item data: */
    798811    pItem->updateData();
    799     m_fChanged = true;
    800812}
    801813
     
    887899        pItem->fetchNetworkData(data);
    888900        sltHandleCurrentItemChangeNetworkHost();
    889         m_fChanged = true;
    890901        /* Revalidate: */
    891902        revalidate();
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.h

    r65680 r65687  
    2929
    3030
    31 /** Global settings: Network page: NAT network cache structure. */
     31/** Global settings: Network page: NAT network data structure. */
    3232struct UIDataSettingsGlobalNetworkNAT
    3333{
    34     /** Returns whether the @a other passed data is equal to this one. */
    35     bool operator==(const UIDataSettingsGlobalNetworkNAT &other) const
     34    /** Constructs data. */
     35    UIDataSettingsGlobalNetworkNAT()
     36        : m_fEnabled(false)
     37        , m_strName(QString())
     38        , m_strNewName(QString())
     39        , m_strCIDR(QString())
     40        , m_fSupportsDHCP(false)
     41        , m_fSupportsIPv6(false)
     42        , m_fAdvertiseDefaultIPv6Route(false)
     43        , m_ipv4rules(QList<UIPortForwardingData>())
     44        , m_ipv6rules(QList<UIPortForwardingData>())
     45    {}
     46
     47    /** Returns whether the @a other passed data is equal to this one. */
     48    bool equal(const UIDataSettingsGlobalNetworkNAT &other) const
    3649    {
    3750        return true
     
    4760               ;
    4861    }
     62
     63    /** Returns whether the @a other passed data is equal to this one. */
     64    bool operator==(const UIDataSettingsGlobalNetworkNAT &other) const { return equal(other); }
     65    /** Returns whether the @a other passed data is different from this one. */
     66    bool operator!=(const UIDataSettingsGlobalNetworkNAT &other) const { return !equal(other); }
    4967
    5068    /** Holds whether this network enabled. */
     
    6987
    7088
    71 /** Global settings: Network page: Host interface cache structure. */
     89/** Global settings: Network page: Host interface data structure. */
    7290struct UIDataSettingsGlobalNetworkHostInterface
    7391{
    74     /** Returns whether the @a other passed data is equal to this one. */
    75     bool operator==(const UIDataSettingsGlobalNetworkHostInterface &other) const
     92    /** Constructs data. */
     93    UIDataSettingsGlobalNetworkHostInterface()
     94        : m_strName(QString())
     95        , m_fDhcpClientEnabled(false)
     96        , m_strInterfaceAddress(QString())
     97        , m_strInterfaceMask(QString())
     98        , m_fIpv6Supported(false)
     99        , m_strInterfaceAddress6(QString())
     100        , m_strInterfaceMaskLength6(QString())
     101    {}
     102
     103    /** Returns whether the @a other passed data is equal to this one. */
     104    bool equal(const UIDataSettingsGlobalNetworkHostInterface &other) const
    76105    {
    77106        return true
     
    85114               ;
    86115    }
     116
     117    /** Returns whether the @a other passed data is equal to this one. */
     118    bool operator==(const UIDataSettingsGlobalNetworkHostInterface &other) const { return equal(other); }
     119    /** Returns whether the @a other passed data is different from this one. */
     120    bool operator!=(const UIDataSettingsGlobalNetworkHostInterface &other) const { return !equal(other); }
    87121
    88122    /** Holds host interface name. */
     
    103137
    104138
    105 /** Global settings: Network page: DHCP server cache structure. */
     139/** Global settings: Network page: DHCP server data structure. */
    106140struct UIDataSettingsGlobalNetworkDHCPServer
    107141{
    108     /** Returns whether the @a other passed data is equal to this one. */
    109     bool operator==(const UIDataSettingsGlobalNetworkDHCPServer &other) const
     142    /** Constructs data. */
     143    UIDataSettingsGlobalNetworkDHCPServer()
     144        : m_fDhcpServerEnabled(false)
     145        , m_strDhcpServerAddress(QString())
     146        , m_strDhcpServerMask(QString())
     147        , m_strDhcpLowerAddress(QString())
     148        , m_strDhcpUpperAddress(QString())
     149    {}
     150
     151    /** Returns whether the @a other passed data is equal to this one. */
     152    bool equal(const UIDataSettingsGlobalNetworkDHCPServer &other) const
    110153    {
    111154        return true
     
    117160               ;
    118161    }
     162
     163    /** Returns whether the @a other passed data is equal to this one. */
     164    bool operator==(const UIDataSettingsGlobalNetworkDHCPServer &other) const { return equal(other); }
     165    /** Returns whether the @a other passed data is different from this one. */
     166    bool operator!=(const UIDataSettingsGlobalNetworkDHCPServer &other) const { return !equal(other); }
    119167
    120168    /** Holds whether DHCP server enabled. */
     
    131179
    132180
    133 /** Global settings: Network page: Host network cache structure. */
     181/** Global settings: Network page: Host network data structure. */
    134182struct UIDataSettingsGlobalNetworkHost
    135183{
    136     /** Returns whether the @a other passed data is equal to this one. */
    137     bool operator==(const UIDataSettingsGlobalNetworkHost &other) const
     184    /** Constructs data. */
     185    UIDataSettingsGlobalNetworkHost()
     186        : m_interface(UIDataSettingsGlobalNetworkHostInterface())
     187        , m_dhcpserver(UIDataSettingsGlobalNetworkDHCPServer())
     188    {}
     189
     190    /** Returns whether the @a other passed data is equal to this one. */
     191    bool equal(const UIDataSettingsGlobalNetworkHost &other) const
    138192    {
    139193        return true
     
    142196               ;
    143197    }
     198
     199    /** Returns whether the @a other passed data is equal to this one. */
     200    bool operator==(const UIDataSettingsGlobalNetworkHost &other) const { return equal(other); }
     201    /** Returns whether the @a other passed data is different from this one. */
     202    bool operator!=(const UIDataSettingsGlobalNetworkHost &other) const { return !equal(other); }
    144203
    145204    /** Holds the host interface data. */
     
    150209
    151210
    152 /** Global settings: Network page cache structure. */
    153 struct UISettingsCacheGlobalNetwork
    154 {
     211/** Global settings: Network page data structure. */
     212struct UIDataSettingsGlobalNetwork
     213{
     214    /** Constructs data. */
     215    UIDataSettingsGlobalNetwork()
     216        : m_networksNAT(QList<UIDataSettingsGlobalNetworkNAT>())
     217        , m_networksHost(QList<UIDataSettingsGlobalNetworkHost>())
     218    {}
     219
     220    /** Returns whether the @a other passed data is equal to this one. */
     221    bool equal(const UIDataSettingsGlobalNetwork &other) const
     222    {
     223        return true
     224               && (m_networksNAT == other.m_networksNAT)
     225               && (m_networksHost == other.m_networksHost)
     226               ;
     227    }
     228
     229    /** Returns whether the @a other passed data is equal to this one. */
     230    bool operator==(const UIDataSettingsGlobalNetwork &other) const { return equal(other); }
     231    /** Returns whether the @a other passed data is different from this one. */
     232    bool operator!=(const UIDataSettingsGlobalNetwork &other) const { return !equal(other); }
     233
    155234    /** Holds the NAT network data. */
    156235    QList<UIDataSettingsGlobalNetworkNAT> m_networksNAT;
     
    158237    QList<UIDataSettingsGlobalNetworkHost> m_networksHost;
    159238};
     239typedef UISettingsCache<UIDataSettingsGlobalNetwork> UISettingsCacheGlobalNetwork;
    160240
    161241
     
    244324    QAction *m_pActionEditNetworkHost;
    245325
    246     /* Variable: Editness flag: */
    247     bool m_fChanged;
    248 
    249326    /* Variable: Cache: */
    250327    UISettingsCacheGlobalNetwork m_cache;
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