Changeset 65687 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Feb 8, 2017 4:04:22 PM (8 years ago)
- 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 393 393 : m_pActionAddNetworkNAT(0), m_pActionDelNetworkNAT(0), m_pActionEditNetworkNAT(0) 394 394 , m_pActionAddNetworkHost(0), m_pActionDelNetworkHost(0), m_pActionEditNetworkHost(0) 395 , m_fChanged(false)396 395 { 397 396 /* Apply UI decorations: */ … … 517 516 UISettingsPageGlobal::fetchData(data); 518 517 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()) 527 528 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); 529 533 530 534 /* Upload properties & settings to data: */ … … 534 538 void UIGlobalSettingsNetwork::getFromCache() 535 539 { 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) 538 545 createTreeItemNetworkNAT(network); 539 546 m_pTreeNetworkNAT->sortByColumn(1, Qt::AscendingOrder); 540 547 m_pTreeNetworkNAT->setCurrentItem(m_pTreeNetworkNAT->topLevelItem(0)); 541 548 sltHandleCurrentItemChangeNetworkNAT(); 542 foreach (const UIDataSettingsGlobalNetworkHost &network, m_cache.m_networksHost)549 foreach (const UIDataSettingsGlobalNetworkHost &network, oldData.m_networksHost) 543 550 createTreeItemNetworkHost(network); 544 551 m_pTreeNetworkHost->sortByColumn(0, Qt::AscendingOrder); … … 552 559 void UIGlobalSettingsNetwork::putToCache() 553 560 { 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(); 556 566 for (int iNetworkIndex = 0; iNetworkIndex < m_pTreeNetworkNAT->topLevelItemCount(); ++iNetworkIndex) 557 567 { … … 559 569 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(iNetworkIndex)); 560 570 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(); 564 574 for (int iNetworkIndex = 0; iNetworkIndex < m_pTreeNetworkHost->topLevelItemCount(); ++iNetworkIndex) 565 575 { … … 567 577 UIItemNetworkHost *pItem = static_cast<UIItemNetworkHost*>(m_pTreeNetworkHost->topLevelItem(iNetworkIndex)); 568 578 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); 571 584 } 572 585 573 586 void UIGlobalSettingsNetwork::saveFromCacheTo(QVariant &data) 574 587 { 575 /* Ensure settings were changed: */576 if (!m_fChanged)577 return;578 579 588 /* Fetch data to properties & settings: */ 580 589 UISettingsPageGlobal::fetchData(data); 581 590 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 } 587 601 588 602 /* Upload properties & settings to data: */ … … 783 797 pItem->fetchNetworkData(data); 784 798 sltHandleCurrentItemChangeNetworkNAT(); 785 m_fChanged = true;786 799 /* Revalidate: */ 787 800 revalidate(); … … 797 810 /* Update item data: */ 798 811 pItem->updateData(); 799 m_fChanged = true;800 812 } 801 813 … … 887 899 pItem->fetchNetworkData(data); 888 900 sltHandleCurrentItemChangeNetworkHost(); 889 m_fChanged = true;890 901 /* Revalidate: */ 891 902 revalidate(); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.h
r65680 r65687 29 29 30 30 31 /** Global settings: Network page: NAT network cachestructure. */31 /** Global settings: Network page: NAT network data structure. */ 32 32 struct UIDataSettingsGlobalNetworkNAT 33 33 { 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 36 49 { 37 50 return true … … 47 60 ; 48 61 } 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); } 49 67 50 68 /** Holds whether this network enabled. */ … … 69 87 70 88 71 /** Global settings: Network page: Host interface cachestructure. */89 /** Global settings: Network page: Host interface data structure. */ 72 90 struct UIDataSettingsGlobalNetworkHostInterface 73 91 { 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 76 105 { 77 106 return true … … 85 114 ; 86 115 } 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); } 87 121 88 122 /** Holds host interface name. */ … … 103 137 104 138 105 /** Global settings: Network page: DHCP server cachestructure. */139 /** Global settings: Network page: DHCP server data structure. */ 106 140 struct UIDataSettingsGlobalNetworkDHCPServer 107 141 { 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 110 153 { 111 154 return true … … 117 160 ; 118 161 } 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); } 119 167 120 168 /** Holds whether DHCP server enabled. */ … … 131 179 132 180 133 /** Global settings: Network page: Host network cachestructure. */181 /** Global settings: Network page: Host network data structure. */ 134 182 struct UIDataSettingsGlobalNetworkHost 135 183 { 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 138 192 { 139 193 return true … … 142 196 ; 143 197 } 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); } 144 203 145 204 /** Holds the host interface data. */ … … 150 209 151 210 152 /** Global settings: Network page cache structure. */ 153 struct UISettingsCacheGlobalNetwork 154 { 211 /** Global settings: Network page data structure. */ 212 struct 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 155 234 /** Holds the NAT network data. */ 156 235 QList<UIDataSettingsGlobalNetworkNAT> m_networksNAT; … … 158 237 QList<UIDataSettingsGlobalNetworkHost> m_networksHost; 159 238 }; 239 typedef UISettingsCache<UIDataSettingsGlobalNetwork> UISettingsCacheGlobalNetwork; 160 240 161 241 … … 244 324 QAction *m_pActionEditNetworkHost; 245 325 246 /* Variable: Editness flag: */247 bool m_fChanged;248 249 326 /* Variable: Cache: */ 250 327 UISettingsCacheGlobalNetwork m_cache;
Note:
See TracChangeset
for help on using the changeset viewer.