VirtualBox

Changeset 36928 in vbox


Ignore:
Timestamp:
May 3, 2011 12:30:11 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: 4989: UISettingsCache template integrated into Network page.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.cpp

    r36519 r36928  
    3737const char *emptyItemCode = "#empty#";
    3838
    39 UIMachineSettingsNetwork::UIMachineSettingsNetwork(UIMachineSettingsNetworkPage *pParent, bool fDisableStaticControls)
     39UIMachineSettingsNetwork::UIMachineSettingsNetwork(UIMachineSettingsNetworkPage *pParent)
    4040    : QIWithRetranslateUI<QWidget>(0)
    4141    , m_pParent(pParent)
     
    9494}
    9595
    96 void UIMachineSettingsNetwork::fetchAdapterData(const UINetworkAdapterData &data)
    97 {
    98     /* Load adapter & slot number: */
    99     m_iSlot = data.m_iSlot;
    100     m_adapter = data.m_adapter;
     96void UIMachineSettingsNetwork::fetchAdapterCache(const UICacheSettingsMachineNetworkAdapter &adapterCache)
     97{
     98    /* Get adapter data: */
     99    const UIDataSettingsMachineNetworkAdapter &adapterData = adapterCache.base();
     100
     101    /* Load slot number: */
     102    m_iSlot = adapterData.m_iSlot;
    101103
    102104    /* Load adapter activity state: */
    103     mCbEnableAdapter->setChecked(data.m_fAdapterEnabled);
     105    mCbEnableAdapter->setChecked(adapterData.m_fAdapterEnabled);
    104106
    105107    /* Load attachment type: */
    106     int iAttachmentPos = m_pAttachmentTypeCombo->findData(data.m_attachmentType);
     108    int iAttachmentPos = m_pAttachmentTypeCombo->findData(adapterData.m_attachmentType);
    107109    m_pAttachmentTypeCombo->setCurrentIndex(iAttachmentPos == -1 ? 0 : iAttachmentPos);
    108110
     
    111113    {
    112114        case KNetworkAttachmentType_Bridged:
    113             m_strBrgName = data.m_strBridgedAdapterName;
     115            m_strBrgName = adapterData.m_strBridgedAdapterName;
    114116            if (m_strBrgName.isEmpty()) m_strBrgName = QString();
    115117            break;
    116118        case KNetworkAttachmentType_Internal:
    117             m_strIntName = data.m_strInternalNetworkName;
     119            m_strIntName = adapterData.m_strInternalNetworkName;
    118120            if (m_strIntName.isEmpty()) m_strIntName = QString();
    119121            break;
    120122        case KNetworkAttachmentType_HostOnly:
    121             m_strHoiName = data.m_strHostInterfaceName;
     123            m_strHoiName = adapterData.m_strHostInterfaceName;
    122124            if (m_strHoiName.isEmpty()) m_strHoiName = QString();
    123125            break;
    124126#ifdef VBOX_WITH_VDE
    125127        case KNetworkAttachmentType_VDE:
    126             mVDEName = data.m_strVDENetworkName;
     128            mVDEName = adapterData.m_strVDENetworkName;
    127129            if (mVDEName.isEmpty()) mVDEName = QString();
    128130            break;
    129 #endif
     131#endif /* VBOX_WITH_VDE */
    130132        default:
    131133            break;
     
    134136
    135137    /* Load adapter type: */
    136     int iAdapterPos = m_pAdapterTypeCombo->findData(data.m_adapterType);
     138    int iAdapterPos = m_pAdapterTypeCombo->findData(adapterData.m_adapterType);
    137139    m_pAdapterTypeCombo->setCurrentIndex(iAdapterPos == -1 ? 0 : iAdapterPos);
    138140
    139141    /* Load promiscuous mode type: */
    140     int iPromiscuousModePos = m_pPromiscuousModeCombo->findData(data.m_promiscuousMode);
     142    int iPromiscuousModePos = m_pPromiscuousModeCombo->findData(adapterData.m_promiscuousMode);
    141143    m_pPromiscuousModeCombo->setCurrentIndex(iPromiscuousModePos == -1 ? 0 : iPromiscuousModePos);
    142144
    143145    /* Other options: */
    144     m_pMACEditor->setText(data.m_strMACAddress);
    145     m_pCableConnectedCheckBox->setChecked(data.m_fCableConnected);
     146    m_pMACEditor->setText(adapterData.m_strMACAddress);
     147    m_pCableConnectedCheckBox->setChecked(adapterData.m_fCableConnected);
    146148
    147149    /* Load port forwarding rules: */
    148     m_portForwardingRules = data.m_redirects;
    149 }
    150 
    151 void UIMachineSettingsNetwork::uploadAdapterData(UINetworkAdapterData &data)
    152 {
     150    m_portForwardingRules = adapterData.m_redirects;
     151}
     152
     153void UIMachineSettingsNetwork::uploadAdapterCache(UICacheSettingsMachineNetworkAdapter &adapterCache)
     154{
     155    /* Prepare adapter data: */
     156    UIDataSettingsMachineNetworkAdapter adapterData = adapterCache.base();
     157
    153158    /* Save adapter activity state: */
    154     data.m_fAdapterEnabled = mCbEnableAdapter->isChecked();
     159    adapterData.m_fAdapterEnabled = mCbEnableAdapter->isChecked();
    155160
    156161    /* Save attachment type & alternative name: */
    157     data.m_attachmentType = attachmentType();
    158     switch (data.m_attachmentType)
     162    adapterData.m_attachmentType = attachmentType();
     163    switch (adapterData.m_attachmentType)
    159164    {
    160165        case KNetworkAttachmentType_Null:
     
    163168            break;
    164169        case KNetworkAttachmentType_Bridged:
    165             data.m_strBridgedAdapterName = alternativeName();
     170            adapterData.m_strBridgedAdapterName = alternativeName();
    166171            break;
    167172        case KNetworkAttachmentType_Internal:
    168             data.m_strInternalNetworkName = alternativeName();
     173            adapterData.m_strInternalNetworkName = alternativeName();
    169174            break;
    170175        case KNetworkAttachmentType_HostOnly:
    171             data.m_strHostInterfaceName = alternativeName();
     176            adapterData.m_strHostInterfaceName = alternativeName();
    172177            break;
    173178#ifdef VBOX_WITH_VDE
    174179        case KNetworkAttachmentType_VDE:
    175             data.m_strVDENetworkName = alternativeName();
    176             break;
    177 #endif
     180            adapterData.m_strVDENetworkName = alternativeName();
     181            break;
     182#endif /* VBOX_WITH_VDE */
    178183        default:
    179184            break;
     
    181186
    182187    /* Save adapter type: */
    183     data.m_adapterType = (KNetworkAdapterType)m_pAdapterTypeCombo->itemData(m_pAdapterTypeCombo->currentIndex()).toInt();
     188    adapterData.m_adapterType = (KNetworkAdapterType)m_pAdapterTypeCombo->itemData(m_pAdapterTypeCombo->currentIndex()).toInt();
    184189
    185190    /* Save promiscuous mode type: */
    186     data.m_promiscuousMode = (KNetworkAdapterPromiscModePolicy)m_pPromiscuousModeCombo->itemData(m_pPromiscuousModeCombo->currentIndex()).toInt();
     191    adapterData.m_promiscuousMode = (KNetworkAdapterPromiscModePolicy)m_pPromiscuousModeCombo->itemData(m_pPromiscuousModeCombo->currentIndex()).toInt();
    187192
    188193    /* Other options: */
    189     data.m_strMACAddress = m_pMACEditor->text().isEmpty() ? QString() : m_pMACEditor->text();
    190     data.m_fCableConnected = m_pCableConnectedCheckBox->isChecked();
     194    adapterData.m_strMACAddress = m_pMACEditor->text().isEmpty() ? QString() : m_pMACEditor->text();
     195    adapterData.m_fCableConnected = m_pCableConnectedCheckBox->isChecked();
    191196
    192197    /* Save port forwarding rules: */
    193     data.m_redirects = m_portForwardingRules;
     198    adapterData.m_redirects = m_portForwardingRules;
     199
     200    /* Cache adapter data: */
     201    adapterCache.cacheCurrentData(adapterData);
    194202}
    195203
     
    502510void UIMachineSettingsNetwork::sltGenerateMac()
    503511{
    504     m_adapter.SetMACAddress(QString::null);
    505     m_pMACEditor->setText(m_adapter.GetMACAddress());
     512    m_pMACEditor->setText(vboxGlobal().virtualBox().GetHost().GenerateMACAddress());
    506513}
    507514
     
    646653    /* How many adapters to display: */
    647654    ulong uCount = qMin((ULONG)4, vboxGlobal().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(KChipsetType_PIIX3));
    648     /* Add the tab pages to parent tab widget. Needed for space calculations: */
    649     for (ulong iSlot = 0; iSlot < uCount; ++iSlot)
    650     {
    651         /* Creating adapter's page: */
     655    /* Add corresponding tab pages to parent tab widget: */
     656    for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
     657    {
     658        /* Creating adapter page: */
    652659        UIMachineSettingsNetwork *pPage = new UIMachineSettingsNetwork(this);
    653         /* Attach adapter's page to Tab Widget: */
    654660        m_pTwAdapters->addTab(pPage, pPage->pageTitle());
    655661    }
     
    748754    hoiList(true);
    749755
    750     /* Load adapters data: */
    751     ulong uCount = qMin((ULONG)4, vboxGlobal().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(KChipsetType_PIIX3));
    752     for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
    753     {
    754         /* Get adapter: */
    755         const CNetworkAdapter &adapter = m_machine.GetNetworkAdapter(uSlot);
    756 
    757         /* Prepare adapter's data container: */
    758         UINetworkAdapterData data;
    759 
    760         /* Load main options: */
    761         data.m_iSlot = uSlot;
    762         data.m_adapter = adapter;
    763         data.m_fAdapterEnabled = adapter.GetEnabled();
    764         data.m_attachmentType = adapter.GetAttachmentType();
    765         switch (data.m_attachmentType)
    766         {
    767             case KNetworkAttachmentType_Bridged:
    768                 data.m_strBridgedAdapterName = adapter.GetHostInterface();
    769                 if (data.m_strBridgedAdapterName.isEmpty()) data.m_strBridgedAdapterName = QString();
    770                 break;
    771             case KNetworkAttachmentType_Internal:
    772                 data.m_strInternalNetworkName = adapter.GetInternalNetwork();
    773                 if (data.m_strInternalNetworkName.isEmpty()) data.m_strInternalNetworkName = QString();
    774                 break;
    775             case KNetworkAttachmentType_HostOnly:
    776                 data.m_strHostInterfaceName = adapter.GetHostInterface();
    777                 if (data.m_strHostInterfaceName.isEmpty()) data.m_strHostInterfaceName = QString();
    778                 break;
    779 #ifdef VBOX_WITH_VDE
    780             case KNetworkAttachmentType_VDE:
    781                 data.m_strVDENetworkName = adapter.GetVDENetwork();
    782                 if (data.m_strVDENetworkName.isEmpty()) data.m_strVDENetworkName = QString();
    783                 break;
    784 #endif
    785             default:
    786                 break;
    787         }
    788 
    789         /* Load advanced options: */
    790         data.m_adapterType = adapter.GetAdapterType();
    791         data.m_promiscuousMode = adapter.GetPromiscModePolicy();
    792         data.m_strMACAddress = adapter.GetMACAddress();
    793         data.m_fCableConnected = adapter.GetCableConnected();
    794 
    795         /* Load redirect options: */
    796         QVector<QString> redirects = adapter.GetNatDriver().GetRedirects();
    797         for (int i = 0; i < redirects.size(); ++i)
    798         {
    799             QStringList redirectData = redirects[i].split(',');
    800             AssertMsg(redirectData.size() == 6, ("Redirect rule should be composed of 6 parts!\n"));
    801             data.m_redirects << UIPortForwardingData(redirectData[0],
    802                                                      (KNATProtocol)redirectData[1].toUInt(),
    803                                                      redirectData[2],
    804                                                      redirectData[3].toUInt(),
    805                                                      redirectData[4],
    806                                                      redirectData[5].toUInt());
    807         }
    808 
    809         /* Append adapter's data container: */
    810         m_cache.m_items << data;
    811     }
    812 
    813     /* Upload machine to data: */
    814     UISettingsPageMachine::uploadData(data);
    815 }
    816 
    817 /* Load data to corresponding widgets from cache,
    818  * this task SHOULD be performed in GUI thread only: */
    819 void UIMachineSettingsNetworkPage::getFromCache()
    820 {
    821     /* Setup tab order: */
    822     Assert(firstWidget());
    823     setTabOrder(firstWidget(), m_pTwAdapters->focusProxy());
    824     QWidget *pLastFocusWidget = m_pTwAdapters->focusProxy();
    825 
    826     int uCount = qMin(m_pTwAdapters->count(), m_cache.m_items.size());
    827     for (int iSlot = 0; iSlot < uCount; ++iSlot)
    828     {
    829         UIMachineSettingsNetwork *pPage = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
    830         Assert(pPage);
    831 
    832         /* Loading adapter's data into page: */
    833         pPage->fetchAdapterData(m_cache.m_items[iSlot]);
    834 
    835         /* Setup page validation: */
    836         pPage->setValidator(m_pValidator);
    837 
    838         /* Setup tab order: */
    839         pLastFocusWidget = pPage->setOrderAfter(pLastFocusWidget);
    840     }
    841 
    842     /* Applying language settings: */
    843     retranslateUi();
    844 
    845     /* Revalidate if possible: */
    846     if (m_pValidator) m_pValidator->revalidate();
    847 }
    848 
    849 /* Save data from corresponding widgets to cache,
    850  * this task SHOULD be performed in GUI thread only: */
    851 void UIMachineSettingsNetworkPage::putToCache()
    852 {
    853     /* Gather internal variables data from QWidget(s): */
    854     for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
    855     {
    856         /* Getting adapter's page: */
    857         UIMachineSettingsNetwork *pPage = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
    858 
    859         /* Loading Adapter's data from page: */
    860         pPage->uploadAdapterData(m_cache.m_items[iSlot]);
    861     }
    862 }
    863 
    864 /* Save data from cache to corresponding external object(s),
    865  * this task COULD be performed in other than GUI thread: */
    866 void UIMachineSettingsNetworkPage::saveFromCacheTo(QVariant &data)
    867 {
    868     /* Fetch data to machine: */
    869     UISettingsPageMachine::fetchData(data);
    870 
    871     /* Gather corresponding values from internal variables: */
    872     for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
    873     {
    874         /* Get adapter: */
    875         CNetworkAdapter adapter = m_machine.GetNetworkAdapter(iSlot);
    876 
    877         /* Get cached data for this adapter: */
    878         const UINetworkAdapterData &data = m_cache.m_items[iSlot];
    879 
    880         if (isMachineOffline())
    881         {
    882             /* Basic attributes: */
    883             adapter.SetEnabled(data.m_fAdapterEnabled);
    884             adapter.SetAdapterType(data.m_adapterType);
    885             adapter.SetMACAddress(data.m_strMACAddress);
    886         }
    887         if (isMachineInValidMode())
    888         {
    889             /* Attachment type: */
    890             switch (data.m_attachmentType)
     756    /* For each network adapter: */
     757    for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
     758    {
     759        /* Prepare adapter data: */
     760        UIDataSettingsMachineNetworkAdapter adapterData;
     761
     762        /* Check if adapter is valid: */
     763        const CNetworkAdapter &adapter = m_machine.GetNetworkAdapter(iSlot);
     764        if (!adapter.isNull())
     765        {
     766            /* Gather main options: */
     767            adapterData.m_iSlot = iSlot;
     768            adapterData.m_fAdapterEnabled = adapter.GetEnabled();
     769            adapterData.m_attachmentType = adapter.GetAttachmentType();
     770            switch (adapterData.m_attachmentType)
    891771            {
    892                 case KNetworkAttachmentType_Null:
    893                     adapter.Detach();
    894                     break;
    895                 case KNetworkAttachmentType_NAT:
    896                     adapter.AttachToNAT();
    897                     break;
    898772                case KNetworkAttachmentType_Bridged:
    899                     adapter.SetHostInterface(data.m_strBridgedAdapterName);
    900                     adapter.AttachToBridgedInterface();
     773                    adapterData.m_strBridgedAdapterName = adapter.GetHostInterface();
     774                    if (adapterData.m_strBridgedAdapterName.isEmpty())
     775                        adapterData.m_strBridgedAdapterName = QString();
    901776                    break;
    902777                case KNetworkAttachmentType_Internal:
    903                     adapter.SetInternalNetwork(data.m_strInternalNetworkName);
    904                     adapter.AttachToInternalNetwork();
     778                    adapterData.m_strInternalNetworkName = adapter.GetInternalNetwork();
     779                    if (adapterData.m_strInternalNetworkName.isEmpty())
     780                        adapterData.m_strInternalNetworkName = QString();
    905781                    break;
    906782                case KNetworkAttachmentType_HostOnly:
    907                     adapter.SetHostInterface(data.m_strHostInterfaceName);
    908                     adapter.AttachToHostOnlyInterface();
     783                    adapterData.m_strHostInterfaceName = adapter.GetHostInterface();
     784                    if (adapterData.m_strHostInterfaceName.isEmpty())
     785                        adapterData.m_strHostInterfaceName = QString();
    909786                    break;
    910787#ifdef VBOX_WITH_VDE
    911788                case KNetworkAttachmentType_VDE:
    912                     adapter.SetVDENetwork(data.m_strVDENetworkName);
    913                     adapter.AttachToVDE();
     789                    adapterData.m_strVDENetworkName = adapter.GetVDENetwork();
     790                    if (adapterData.m_strVDENetworkName.isEmpty())
     791                        adapterData.m_strVDENetworkName = QString();
    914792                    break;
    915793#endif /* VBOX_WITH_VDE */
     
    917795                    break;
    918796            }
    919             /* Advanced attributes: */
    920             adapter.SetPromiscModePolicy(data.m_promiscuousMode);
    921             /* Cable connected flag: */
    922             adapter.SetCableConnected(data.m_fCableConnected);
    923             /* Redirect options: */
    924             QVector<QString> oldRedirects = adapter.GetNatDriver().GetRedirects();
    925             for (int i = 0; i < oldRedirects.size(); ++i)
    926                 adapter.GetNatDriver().RemoveRedirect(oldRedirects[i].section(',', 0, 0));
    927             UIPortForwardingDataList newRedirects = data.m_redirects;
    928             for (int i = 0; i < newRedirects.size(); ++i)
     797
     798            /* Gather advanced options: */
     799            adapterData.m_adapterType = adapter.GetAdapterType();
     800            adapterData.m_promiscuousMode = adapter.GetPromiscModePolicy();
     801            adapterData.m_strMACAddress = adapter.GetMACAddress();
     802            adapterData.m_fCableConnected = adapter.GetCableConnected();
     803
     804            /* Gather redirect options: */
     805            QVector<QString> redirects = adapter.GetNatDriver().GetRedirects();
     806            for (int i = 0; i < redirects.size(); ++i)
    929807            {
    930                 UIPortForwardingData newRedirect = newRedirects[i];
    931                 adapter.GetNatDriver().AddRedirect(newRedirect.name, newRedirect.protocol,
    932                                                    newRedirect.hostIp, newRedirect.hostPort.value(),
    933                                                    newRedirect.guestIp, newRedirect.guestPort.value());
     808                QStringList redirectData = redirects[i].split(',');
     809                AssertMsg(redirectData.size() == 6, ("Redirect rule should be composed of 6 parts!\n"));
     810                adapterData.m_redirects << UIPortForwardingData(redirectData[0],
     811                                                                (KNATProtocol)redirectData[1].toUInt(),
     812                                                                redirectData[2],
     813                                                                redirectData[3].toUInt(),
     814                                                                redirectData[4],
     815                                                                redirectData[5].toUInt());
     816            }
     817        }
     818
     819        /* Cache adapter data: */
     820        m_cache.child(iSlot).cacheInitialData(adapterData);
     821    }
     822
     823    /* Upload machine to data: */
     824    UISettingsPageMachine::uploadData(data);
     825}
     826
     827/* Load data to corresponding widgets from cache,
     828 * this task SHOULD be performed in GUI thread only: */
     829void UIMachineSettingsNetworkPage::getFromCache()
     830{
     831    /* Setup tab order: */
     832    Assert(firstWidget());
     833    setTabOrder(firstWidget(), m_pTwAdapters->focusProxy());
     834    QWidget *pLastFocusWidget = m_pTwAdapters->focusProxy();
     835
     836    /* For each network adapter: */
     837    for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
     838    {
     839        /* Get adapter page: */
     840        UIMachineSettingsNetwork *pPage = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
     841
     842        /* Load adapter data to page: */
     843        pPage->fetchAdapterCache(m_cache.child(iSlot));
     844
     845        /* Setup page validation: */
     846        pPage->setValidator(m_pValidator);
     847
     848        /* Setup tab order: */
     849        pLastFocusWidget = pPage->setOrderAfter(pLastFocusWidget);
     850    }
     851
     852    /* Applying language settings: */
     853    retranslateUi();
     854
     855    /* Revalidate if possible: */
     856    if (m_pValidator) m_pValidator->revalidate();
     857}
     858
     859/* Save data from corresponding widgets to cache,
     860 * this task SHOULD be performed in GUI thread only: */
     861void UIMachineSettingsNetworkPage::putToCache()
     862{
     863    /* For each network adapter: */
     864    for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
     865    {
     866        /* Get adapter page: */
     867        UIMachineSettingsNetwork *pPage = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
     868
     869        /* Gather & cache adapter data: */
     870        pPage->uploadAdapterCache(m_cache.child(iSlot));
     871    }
     872}
     873
     874/* Save data from cache to corresponding external object(s),
     875 * this task COULD be performed in other than GUI thread: */
     876void UIMachineSettingsNetworkPage::saveFromCacheTo(QVariant &data)
     877{
     878    /* Fetch data to machine: */
     879    UISettingsPageMachine::fetchData(data);
     880
     881    /* Check if network data was changed: */
     882    if (m_cache.wasChanged())
     883    {
     884        /* For each network adapter: */
     885        for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
     886        {
     887            /* Check if adapter data was changed: */
     888            const UICacheSettingsMachineNetworkAdapter &adapterCache = m_cache.child(iSlot);
     889            if (adapterCache.wasChanged())
     890            {
     891                /* Check if adapter still valid: */
     892                CNetworkAdapter adapter = m_machine.GetNetworkAdapter(iSlot);
     893                if (!adapter.isNull())
     894                {
     895                    /* Get adapter data from cache: */
     896                    const UIDataSettingsMachineNetworkAdapter &adapterData = adapterCache.data();
     897
     898                    /* Store adapter data: */
     899                    if (isMachineOffline())
     900                    {
     901                        /* Basic attributes: */
     902                        adapter.SetEnabled(adapterData.m_fAdapterEnabled);
     903                        adapter.SetAdapterType(adapterData.m_adapterType);
     904                        adapter.SetMACAddress(adapterData.m_strMACAddress);
     905                    }
     906                    if (isMachineInValidMode())
     907                    {
     908                        /* Attachment type: */
     909                        switch (adapterData.m_attachmentType)
     910                        {
     911                            case KNetworkAttachmentType_Null:
     912                                adapter.Detach();
     913                                break;
     914                            case KNetworkAttachmentType_NAT:
     915                                adapter.AttachToNAT();
     916                                break;
     917                            case KNetworkAttachmentType_Bridged:
     918                                adapter.SetHostInterface(adapterData.m_strBridgedAdapterName);
     919                                adapter.AttachToBridgedInterface();
     920                                break;
     921                            case KNetworkAttachmentType_Internal:
     922                                adapter.SetInternalNetwork(adapterData.m_strInternalNetworkName);
     923                                adapter.AttachToInternalNetwork();
     924                                break;
     925                            case KNetworkAttachmentType_HostOnly:
     926                                adapter.SetHostInterface(adapterData.m_strHostInterfaceName);
     927                                adapter.AttachToHostOnlyInterface();
     928                                break;
     929#ifdef VBOX_WITH_VDE
     930                            case KNetworkAttachmentType_VDE:
     931                                adapter.SetVDENetwork(adapterData.m_strVDENetworkName);
     932                                adapter.AttachToVDE();
     933                                break;
     934#endif /* VBOX_WITH_VDE */
     935                            default:
     936                                break;
     937                        }
     938                        /* Advanced attributes: */
     939                        adapter.SetPromiscModePolicy(adapterData.m_promiscuousMode);
     940                        /* Cable connected flag: */
     941                        adapter.SetCableConnected(adapterData.m_fCableConnected);
     942                        /* Redirect options: */
     943                        QVector<QString> oldRedirects = adapter.GetNatDriver().GetRedirects();
     944                        for (int i = 0; i < oldRedirects.size(); ++i)
     945                            adapter.GetNatDriver().RemoveRedirect(oldRedirects[i].section(',', 0, 0));
     946                        UIPortForwardingDataList newRedirects = adapterData.m_redirects;
     947                        for (int i = 0; i < newRedirects.size(); ++i)
     948                        {
     949                            UIPortForwardingData newRedirect = newRedirects[i];
     950                            adapter.GetNatDriver().AddRedirect(newRedirect.name, newRedirect.protocol,
     951                                                               newRedirect.hostIp, newRedirect.hostPort.value(),
     952                                                               newRedirect.guestIp, newRedirect.guestPort.value());
     953                        }
     954                    }
     955                }
    934956            }
    935957        }
     
    9881010{
    9891011    /* Get the count of network adapter tabs: */
    990     int iCount = qMin(m_pTwAdapters->count(), m_cache.m_items.size());
    991     for (int iSlot = 0; iSlot < iCount; ++iSlot)
     1012    for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
    9921013    {
    9931014        m_pTwAdapters->setTabEnabled(iSlot,
    9941015                                     isMachineOffline() ||
    995                                      (isMachineInValidMode() && m_cache.m_items[iSlot].m_fAdapterEnabled));
     1016                                     (isMachineInValidMode() && m_cache.child(iSlot).base().m_fAdapterEnabled));
    9961017        UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
    997         Assert(pTab);
    9981018        pTab->polishTab();
    9991019    }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.h

    r36357 r36928  
    3131
    3232/* Machine settings / Network page / Adapter data: */
    33 struct UINetworkAdapterData
    34 {
     33struct UIDataSettingsMachineNetworkAdapter
     34{
     35    /* Default constructor: */
     36    UIDataSettingsMachineNetworkAdapter()
     37        : m_iSlot(0)
     38        , m_fAdapterEnabled(false)
     39        , m_adapterType(KNetworkAdapterType_Null)
     40        , m_attachmentType(KNetworkAttachmentType_Null)
     41        , m_promiscuousMode(KNetworkAdapterPromiscModePolicy_Deny)
     42        , m_strBridgedAdapterName(QString())
     43        , m_strInternalNetworkName(QString())
     44        , m_strHostInterfaceName(QString())
     45#ifdef VBOX_WITH_VDE
     46        , m_strVDENetworkName(QString())
     47#endif /* VBOX_WITH_VDE */
     48        , m_strMACAddress(QString())
     49        , m_fCableConnected(false)
     50        , m_redirects(UIPortForwardingDataList()) {}
     51    /* Functions: */
     52    bool equal(const UIDataSettingsMachineNetworkAdapter &other) const
     53    {
     54        return (m_iSlot == other.m_iSlot) &&
     55               (m_fAdapterEnabled == other.m_fAdapterEnabled) &&
     56               (m_adapterType == other.m_adapterType) &&
     57               (m_attachmentType == other.m_attachmentType) &&
     58               (m_promiscuousMode == other.m_promiscuousMode) &&
     59               (m_strBridgedAdapterName == other.m_strBridgedAdapterName) &&
     60               (m_strInternalNetworkName == other.m_strInternalNetworkName) &&
     61               (m_strHostInterfaceName == other.m_strHostInterfaceName) &&
     62#ifdef VBOX_WITH_VDE
     63               (m_strVDENetworkName == other.m_strVDENetworkName) &&
     64#endif /* VBOX_WITH_VDE */
     65               (m_strMACAddress == other.m_strMACAddress) &&
     66               (m_fCableConnected == other.m_fCableConnected) &&
     67               (m_redirects == other.m_redirects);
     68    }
     69    /* Operators: */
     70    bool operator==(const UIDataSettingsMachineNetworkAdapter &other) const { return equal(other); }
     71    bool operator!=(const UIDataSettingsMachineNetworkAdapter &other) const { return !equal(other); }
     72    /* Variables: */
    3573    int m_iSlot;
    36     /* CNetworkAdapter used only for Generate MAC ability! */
    37     CNetworkAdapter m_adapter;
    3874    bool m_fAdapterEnabled;
    3975    KNetworkAdapterType m_adapterType;
     
    5086    UIPortForwardingDataList m_redirects;
    5187};
    52 
    53 /* Machine settings / Network page / Cache: */
    54 struct UISettingsCacheMachineNetwork
    55 {
    56     QList<UINetworkAdapterData> m_items;
    57 };
     88typedef UISettingsCache<UIDataSettingsMachineNetworkAdapter> UICacheSettingsMachineNetworkAdapter;
     89
     90/* Machine settings / Network page / Network data: */
     91struct UIDataSettingsMachineNetwork
     92{
     93    /* Default constructor: */
     94    UIDataSettingsMachineNetwork() {}
     95    /* Operators: */
     96    bool operator==(const UIDataSettingsMachineNetwork& /* other */) const { return true; }
     97    bool operator!=(const UIDataSettingsMachineNetwork& /* other */) const { return false; }
     98};
     99typedef UISettingsCachePool<UIDataSettingsMachineNetwork, UICacheSettingsMachineNetworkAdapter> UICacheSettingsMachineNetwork;
    58100
    59101/* Machine settings / Network page / Adapter tab: */
     
    65107public:
    66108
    67     UIMachineSettingsNetwork(UIMachineSettingsNetworkPage *pParent, bool fDisableStaticControls = false);
     109    UIMachineSettingsNetwork(UIMachineSettingsNetworkPage *pParent);
    68110
    69111    void polishTab();
    70112
    71     void fetchAdapterData(const UINetworkAdapterData &data);
    72     void uploadAdapterData(UINetworkAdapterData &data);
     113    void fetchAdapterCache(const UICacheSettingsMachineNetworkAdapter &adapterCache);
     114    void uploadAdapterCache(UICacheSettingsMachineNetworkAdapter &adapterCache);
    73115
    74116    void setValidator(QIWidgetValidator *pValidator);
     
    102144    UIMachineSettingsNetworkPage *m_pParent;
    103145    QIWidgetValidator *m_pValidator;
     146
    104147    int m_iSlot;
    105     CNetworkAdapter m_adapter;
    106 
    107148    QString m_strBrgName;
    108149    QString m_strIntName;
     
    167208
    168209    /* Cache: */
    169     UISettingsCacheMachineNetwork m_cache;
     210    UICacheSettingsMachineNetwork m_cache;
    170211};
    171212
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsPortForwardingDlg.h

    r33882 r36928  
    5959    PortData(ushort uValue) : m_uValue(uValue) {}
    6060    PortData(const PortData &other) : m_uValue(other.value()) {}
     61    bool operator==(const PortData &other) { return m_uValue == other.m_uValue; }
    6162    ushort value() const { return m_uValue; }
    6263
     
    7677        , hostIp(strHostIp), hostPort(uHostPort)
    7778        , guestIp(strGuestIp), guestPort(uGuestPort) {}
     79    bool operator==(const UIPortForwardingData &other)
     80    {
     81        return name == other.name &&
     82               protocol == other.protocol &&
     83               hostIp == other.hostIp &&
     84               hostPort == other.hostPort &&
     85               guestIp == other.guestIp &&
     86               guestPort == other.guestPort;
     87    }
    7888    NameData name;
    7989    KNATProtocol protocol;
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