VirtualBox

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


Ignore:
Timestamp:
Apr 20, 2017 10:46:27 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114671
Message:

FE/Qt: Global preferences: Network page: Reworking caching, saving and error-checking (step 2), this one about port forwarding (s.a. r114657).

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

Legend:

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

    r66614 r66623  
    7979    QString newName() const { return m_strNewName; }
    8080
     81    /** Returns IPv4 port forwarding rules. */
     82    const UIPortForwardingDataList &ipv4rules() const { return m_ipv4rules; }
     83    /** Defines IPv4 port forwarding rules. */
     84    void setIpv4rules(const UIPortForwardingDataList &ipv4rules) { m_ipv4rules = ipv4rules; }
     85    /** Returns IPv6 port forwarding rules. */
     86    const UIPortForwardingDataList &ipv6rules() const { return m_ipv6rules; }
     87    /** Defines IPv6 port forwarding rules. */
     88    void setIpv6rules(const UIPortForwardingDataList &ipv6rules) { m_ipv6rules = ipv6rules; }
     89
    8190protected:
    8291
    8392    /** Returns default text. */
    8493    virtual QString defaultText() const /* override */;
     94
     95private:
     96
     97    /** Holds IPv4 port forwarding rules. */
     98    UIPortForwardingDataList m_ipv4rules;
     99    /** Holds IPv6 port forwarding rules. */
     100    UIPortForwardingDataList m_ipv6rules;
    85101};
    86102
     
    415431    /* Load old network data from the cache: */
    416432    for (int i = 0; i < m_pCache->childCount1(); ++i)
    417         createTreeWidgetItemForNetworkNAT(m_pCache->child1(i).base());
     433        createTreeWidgetItemForNetworkNAT(m_pCache->child1(i));
    418434    m_pTreeNetworkNAT->sortByColumn(1, Qt::AscendingOrder);
    419435    m_pTreeNetworkNAT->setCurrentItem(m_pTreeNetworkNAT->topLevelItem(0));
    420436    sltHandleCurrentItemChangeNetworkNAT();
    421437    for (int i = 0; i < m_pCache->childCount2(); ++i)
    422         createTreeWidgetItemForNetworkHost(m_pCache->child2(i).base());
     438        createTreeWidgetItemForNetworkHost(m_pCache->child2(i));
    423439    m_pTreeNetworkHost->sortByColumn(0, Qt::AscendingOrder);
    424440    m_pTreeNetworkHost->setCurrentItem(m_pTreeNetworkHost->topLevelItem(0));
     
    439455        const UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(i));
    440456        m_pCache->child1(pItem->m_strName).cacheCurrentData(*pItem);
     457        foreach (const UIDataPortForwardingRule &rule, pItem->ipv4rules())
     458            m_pCache->child1(pItem->m_strName).child1(rule.name).cacheCurrentData(rule);
     459        foreach (const UIDataPortForwardingRule &rule, pItem->ipv6rules())
     460            m_pCache->child1(pItem->m_strName).child2(rule.name).cacheCurrentData(rule);
    441461    }
    442462    for (int i = 0; i < m_pTreeNetworkHost->topLevelItemCount(); ++i)
     
    610630    const QString strCacheKey = network.GetNetworkName();
    611631    loadToCacheFromNetworkNAT(network, m_pCache->child1(strCacheKey));
    612     createTreeWidgetItemForNetworkNAT(m_pCache->child1(strCacheKey).base(), true);
     632    createTreeWidgetItemForNetworkNAT(m_pCache->child1(strCacheKey), true);
    613633    m_pTreeNetworkNAT->sortByColumn(1, Qt::AscendingOrder);
    614634}
     
    622642    /* Edit current item data: */
    623643    UIDataSettingsGlobalNetworkNAT data = *pItem;
    624     UIGlobalSettingsNetworkDetailsNAT details(this, data);
     644    UIPortForwardingDataList ipv4rules = pItem->ipv4rules();
     645    UIPortForwardingDataList ipv6rules = pItem->ipv6rules();
     646    UIGlobalSettingsNetworkDetailsNAT details(this, data, ipv4rules, ipv6rules);
    625647    if (details.exec() == QDialog::Accepted)
    626648    {
    627649        /* Put data back: */
    628650        pItem->UIDataSettingsGlobalNetworkNAT::operator=(data);
     651        pItem->setIpv4rules(ipv4rules);
     652        pItem->setIpv6rules(ipv6rules);
    629653        pItem->updateFields();
    630654        sltHandleCurrentItemChangeNetworkNAT();
     
    727751    const QString strCacheKey = iface.GetName();
    728752    loadToCacheFromNetworkHost(iface, m_pCache->child2(strCacheKey));
    729     createTreeWidgetItemForNetworkHost(m_pCache->child2(strCacheKey).base(), true);
     753    createTreeWidgetItemForNetworkHost(m_pCache->child2(strCacheKey), true);
    730754    m_pTreeNetworkHost->sortByColumn(0, Qt::AscendingOrder);
    731755}
     
    10371061        if (rules.size() != 6)
    10381062            continue;
    1039         oldNATData.m_ipv4rules << UIDataPortForwardingRule(rules[0],
    1040                                                            gpConverter->fromInternalString<KNATProtocol>(rules[1]),
    1041                                                            QString(rules[2]).remove('[').remove(']'),
    1042                                                            rules[3].toUInt(),
    1043                                                            QString(rules[4]).remove('[').remove(']'),
    1044                                                            rules[5].toUInt());
     1063        cache.child1(rules.at(0)).cacheInitialData(UIDataPortForwardingRule(rules.at(0),
     1064                                                                            gpConverter->fromInternalString<KNATProtocol>(rules.at(1)),
     1065                                                                            QString(rules.at(2)).remove('[').remove(']'),
     1066                                                                            rules.at(3).toUInt(),
     1067                                                                            QString(rules.at(4)).remove('[').remove(']'),
     1068                                                                            rules.at(5).toUInt()));
    10451069    }
    10461070
     
    10651089        if (rules.size() != 6)
    10661090            continue;
    1067         oldNATData.m_ipv6rules << UIDataPortForwardingRule(rules[0],
    1068                                                            gpConverter->fromInternalString<KNATProtocol>(rules[1]),
    1069                                                            QString(rules[2]).remove('[').remove(']'),
    1070                                                            rules[3].toUInt(),
    1071                                                            QString(rules[4]).remove('[').remove(']'),
    1072                                                            rules[5].toUInt());
     1091        cache.child2(rules.at(0)).cacheInitialData(UIDataPortForwardingRule(rules.at(0),
     1092                                                                            gpConverter->fromInternalString<KNATProtocol>(rules.at(1)),
     1093                                                                            QString(rules.at(2)).remove('[').remove(']'),
     1094                                                                            rules.at(3).toUInt(),
     1095                                                                            QString(rules.at(4)).remove('[').remove(']'),
     1096                                                                            rules.at(5).toUInt()));
    10731097    }
    10741098
     
    11531177
    11541178            /* Save IPv4 forwarding rules: */
    1155             if (fSuccess && newNatData.m_ipv4rules != oldNatData.m_ipv4rules)
    1156             {
    1157                 for (int i = 0; fSuccess && i < ipv4rules.size(); ++i)
     1179            for (int i = 0; fSuccess && i < cache.childCount1(); ++i)
     1180            {
     1181                /* Get rule cache: */
     1182                const UISettingsCachePortForwardingRule &ruleCache = cache.child1(i);
     1183
     1184                /* Remove rule marked for 'remove' or 'update': */
     1185                if (ruleCache.wasRemoved() || ruleCache.wasUpdated())
    11581186                {
    1159                     const QString &strOldRule = ipv4rules.at(i);
    11601187                    comNetwork.RemovePortForwardRule(false,
    1161                                                      strOldRule.section(':', 0, 0));
     1188                                                     ruleCache.base().name);
    11621189                    fSuccess = comNetwork.isOk();
    11631190                }
    1164                 for (int i = 0; fSuccess && i < newNatData.m_ipv4rules.size(); ++i)
     1191            }
     1192            for (int i = 0; fSuccess && i < cache.childCount1(); ++i)
     1193            {
     1194                /* Get rule cache: */
     1195                const UISettingsCachePortForwardingRule &ruleCache = cache.child1(i);
     1196
     1197                /* Create rule marked for 'create' or 'update': */
     1198                if (ruleCache.wasCreated() || ruleCache.wasUpdated())
    11651199                {
    1166                     const UIDataPortForwardingRule &newRule = newNatData.m_ipv4rules.at(i);
    11671200                    comNetwork.AddPortForwardRule(false,
    1168                                                   newRule.name, newRule.protocol,
    1169                                                   newRule.hostIp, newRule.hostPort.value(),
    1170                                                   newRule.guestIp, newRule.guestPort.value());
     1201                                                  ruleCache.data().name, ruleCache.data().protocol,
     1202                                                  ruleCache.data().hostIp, ruleCache.data().hostPort.value(),
     1203                                                  ruleCache.data().guestIp, ruleCache.data().guestPort.value());
    11711204                    fSuccess = comNetwork.isOk();
    11721205                }
     
    11741207
    11751208            /* Save IPv6 forwarding rules: */
    1176             if (fSuccess && newNatData.m_ipv6rules != oldNatData.m_ipv6rules)
    1177             {
    1178                 for (int i = 0; fSuccess && i < ipv6rules.size(); ++i)
     1209            for (int i = 0; fSuccess && i < cache.childCount2(); ++i)
     1210            {
     1211                /* Get rule cache: */
     1212                const UISettingsCachePortForwardingRule &ruleCache = cache.child2(i);
     1213
     1214                /* Remove rule marked for 'remove' or 'update': */
     1215                if (ruleCache.wasRemoved() || ruleCache.wasUpdated())
    11791216                {
    1180                     const QString &strOldRule = ipv6rules.at(i);
    11811217                    comNetwork.RemovePortForwardRule(true,
    1182                                                      strOldRule.section(':', 0, 0));
     1218                                                     ruleCache.base().name);
    11831219                    fSuccess = comNetwork.isOk();
    11841220                }
    1185                 for (int i = 0; fSuccess && i < newNatData.m_ipv6rules.size(); ++i)
     1221            }
     1222            for (int i = 0; fSuccess && i < cache.childCount2(); ++i)
     1223            {
     1224                /* Get rule cache: */
     1225                const UISettingsCachePortForwardingRule &ruleCache = cache.child2(i);
     1226
     1227                /* Create rule marked for 'create' or 'update': */
     1228                if (ruleCache.wasCreated() || ruleCache.wasUpdated())
    11861229                {
    1187                     const UIDataPortForwardingRule &newRule = newNatData.m_ipv6rules.at(i);
    11881230                    comNetwork.AddPortForwardRule(true,
    1189                                                   newRule.name, newRule.protocol,
    1190                                                   newRule.hostIp, newRule.hostPort.value(),
    1191                                                   newRule.guestIp, newRule.guestPort.value());
     1231                                                  ruleCache.data().name, ruleCache.data().protocol,
     1232                                                  ruleCache.data().hostIp, ruleCache.data().hostPort.value(),
     1233                                                  ruleCache.data().guestIp, ruleCache.data().guestPort.value());
    11921234                    fSuccess = comNetwork.isOk();
    11931235                }
     
    12031245}
    12041246
    1205 void UIGlobalSettingsNetwork::createTreeWidgetItemForNetworkNAT(const UIDataSettingsGlobalNetworkNAT &data, bool fChooseItem)
     1247void UIGlobalSettingsNetwork::createTreeWidgetItemForNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache, bool fChooseItem)
    12061248{
    12071249    /* Add new item to the tree: */
    12081250    UIItemNetworkNAT *pItem = new UIItemNetworkNAT;
    1209     pItem->UIDataSettingsGlobalNetworkNAT::operator=(data);
     1251    pItem->UIDataSettingsGlobalNetworkNAT::operator=(cache.base());
     1252    UIPortForwardingDataList ipv4rules;
     1253    UIPortForwardingDataList ipv6rules;
     1254    for (int i = 0; i < cache.childCount1(); ++i)
     1255        ipv4rules << cache.child1(i).base();
     1256    for (int i = 0; i < cache.childCount2(); ++i)
     1257        ipv6rules << cache.child2(i).base();
     1258    pItem->setIpv4rules(ipv4rules);
     1259    pItem->setIpv6rules(ipv6rules);
    12101260    pItem->updateFields();
    12111261    m_pTreeNetworkNAT->addTopLevelItem(pItem);
     
    13761426}
    13771427
    1378 void UIGlobalSettingsNetwork::createTreeWidgetItemForNetworkHost(const UIDataSettingsGlobalNetworkHost &data, bool fChooseItem)
     1428void UIGlobalSettingsNetwork::createTreeWidgetItemForNetworkHost(const UISettingsCacheGlobalNetworkHost &cache, bool fChooseItem)
    13791429{
    13801430    /* Add new item to the tree: */
    13811431    UIItemNetworkHost *pItem = new UIItemNetworkHost;
    1382     pItem->UIDataSettingsGlobalNetworkHost::operator=(data);
     1432    pItem->UIDataSettingsGlobalNetworkHost::operator=(cache.base());
    13831433    pItem->updateFields();
    13841434    m_pTreeNetworkHost->addTopLevelItem(pItem);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.h

    r66614 r66623  
    2222#include "UISettingsPage.h"
    2323#include "UIGlobalSettingsNetwork.gen.h"
     24#include "UIPortForwardingTable.h"
    2425
    2526/* Forward declarations: */
     
    2930struct UIDataSettingsGlobalNetworkNAT;
    3031struct UIDataSettingsGlobalNetworkHost;
    31 typedef UISettingsCache<UIDataSettingsGlobalNetworkNAT> UISettingsCacheGlobalNetworkNAT;
     32typedef UISettingsCache<UIDataPortForwardingRule> UISettingsCachePortForwardingRule;
     33typedef UISettingsCachePoolOfTwo<UIDataSettingsGlobalNetworkNAT, UISettingsCachePortForwardingRule, UISettingsCachePortForwardingRule> UISettingsCacheGlobalNetworkNAT;
    3234typedef UISettingsCache<UIDataSettingsGlobalNetworkHost> UISettingsCacheGlobalNetworkHost;
    3335typedef UISettingsCachePoolOfTwo<UIDataSettingsGlobalNetwork, UISettingsCacheGlobalNetworkNAT, UISettingsCacheGlobalNetworkHost> UISettingsCacheGlobalNetwork;
     
    119121    bool saveDataNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache);
    120122    /** Creates a new item in the NAT network tree on the basis of passed @a data, @a fChooseItem if requested. */
    121     void createTreeWidgetItemForNetworkNAT(const UIDataSettingsGlobalNetworkNAT &data, bool fChooseItem = false);
     123    void createTreeWidgetItemForNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache, bool fChooseItem = false);
    122124    /** Removes existing @a pItem from the NAT network tree. */
    123125    void removeTreeWidgetItemOfNetworkNAT(UIItemNetworkNAT *pItem);
     
    128130    bool saveDataNetworkHost(const UISettingsCacheGlobalNetworkHost &cache);
    129131    /** Creates a new item in the host network tree on the basis of passed @a data, @a fChooseItem if requested. */
    130     void createTreeWidgetItemForNetworkHost(const UIDataSettingsGlobalNetworkHost &data, bool fChooseItem = false);
     132    void createTreeWidgetItemForNetworkHost(const UISettingsCacheGlobalNetworkHost &cache, bool fChooseItem = false);
    131133    /** Removes existing @a pItem from the host network tree. */
    132134    void removeTreeWidgetItemOfNetworkHost(UIItemNetworkHost *pItem);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetworkDetailsNAT.cpp

    r65629 r66623  
    3131
    3232
    33 UIGlobalSettingsNetworkDetailsNAT::UIGlobalSettingsNetworkDetailsNAT(QWidget *pParent, UIDataSettingsGlobalNetworkNAT &data)
     33UIGlobalSettingsNetworkDetailsNAT::UIGlobalSettingsNetworkDetailsNAT(QWidget *pParent,
     34                                                                     UIDataSettingsGlobalNetworkNAT &data,
     35                                                                     UIPortForwardingDataList &ipv4rules,
     36                                                                     UIPortForwardingDataList &ipv6rules)
    3437    : QIWithRetranslateUI2<QIDialog>(pParent)
    3538    , m_data(data)
     39    , m_ipv4rules(ipv4rules)
     40    , m_ipv6rules(ipv6rules)
    3641{
    3742    /* Apply UI decorations: */
     
    7176{
    7277    /* Open dialog to edit port-forwarding rules: */
    73     UIGlobalSettingsPortForwardingDlg dlg(this, m_data.m_ipv4rules, m_data.m_ipv6rules);
     78    UIGlobalSettingsPortForwardingDlg dlg(this, m_ipv4rules, m_ipv6rules);
    7479    if (dlg.exec() == QDialog::Accepted)
    7580    {
    76         m_data.m_ipv4rules = dlg.ipv4rules();
    77         m_data.m_ipv6rules = dlg.ipv6rules();
     81        m_ipv4rules = dlg.ipv4rules();
     82        m_ipv6rules = dlg.ipv6rules();
    7883    }
    7984}
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetworkDetailsNAT.h

    r66562 r66623  
    3838        , m_fSupportsIPv6(false)
    3939        , m_fAdvertiseDefaultIPv6Route(false)
    40         , m_ipv4rules(QList<UIDataPortForwardingRule>())
    41         , m_ipv6rules(QList<UIDataPortForwardingRule>())
    4240    {}
    4341
     
    5351               && (m_fSupportsIPv6 == other.m_fSupportsIPv6)
    5452               && (m_fAdvertiseDefaultIPv6Route == other.m_fAdvertiseDefaultIPv6Route)
    55                && (m_ipv4rules == other.m_ipv4rules)
    56                && (m_ipv6rules == other.m_ipv6rules)
    5753               ;
    5854    }
     
    7773    /** Holds whether this network advertised as default IPv6 route. */
    7874    bool m_fAdvertiseDefaultIPv6Route;
    79     /** Holds IPv4 port forwarding rules. */
    80     UIPortForwardingDataList m_ipv4rules;
    81     /** Holds IPv6 port forwarding rules. */
    82     UIPortForwardingDataList m_ipv6rules;
    8375};
    8476
     
    9284
    9385    /* Constructor: */
    94     UIGlobalSettingsNetworkDetailsNAT(QWidget *pParent, UIDataSettingsGlobalNetworkNAT &data);
     86    UIGlobalSettingsNetworkDetailsNAT(QWidget *pParent, UIDataSettingsGlobalNetworkNAT &data, UIPortForwardingDataList &ipv4rules, UIPortForwardingDataList &ipv6rules);
    9587
    9688protected:
     
    118110    /* Variable: External data reference: */
    119111    UIDataSettingsGlobalNetworkNAT &m_data;
     112
     113    /** Holds IPv4 port forwarding rules. */
     114    UIPortForwardingDataList &m_ipv4rules;
     115    /** Holds IPv6 port forwarding rules. */
     116    UIPortForwardingDataList &m_ipv6rules;
    120117};
    121118
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette