Changeset 66440 in vbox
- Timestamp:
- Apr 5, 2017 2:00:35 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.cpp
r66375 r66440 1038 1038 refreshNATNetworkList(); 1039 1039 1040 /* Prepare initialdata: */1041 UIDataSettingsMachineNetwork initialData;1040 /* Prepare old network data: */ 1041 UIDataSettingsMachineNetwork oldNetworkData; 1042 1042 1043 1043 /* For each network adapter: */ 1044 1044 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 1045 1045 { 1046 /* Prepare initial adapter data: */ 1047 UIDataSettingsMachineNetworkAdapter initialAdapterData; 1048 1049 /* Check if adapter is valid: */ 1050 const CNetworkAdapter &adapter = m_machine.GetNetworkAdapter(iSlot); 1051 if (!adapter.isNull()) 1052 { 1053 /* Gather main options: */ 1054 initialAdapterData.m_iSlot = iSlot; 1055 initialAdapterData.m_fAdapterEnabled = adapter.GetEnabled(); 1056 initialAdapterData.m_attachmentType = adapter.GetAttachmentType(); 1057 initialAdapterData.m_strBridgedAdapterName = wipedOutString(adapter.GetBridgedInterface()); 1058 initialAdapterData.m_strInternalNetworkName = wipedOutString(adapter.GetInternalNetwork()); 1059 initialAdapterData.m_strHostInterfaceName = wipedOutString(adapter.GetHostOnlyInterface()); 1060 initialAdapterData.m_strGenericDriverName = wipedOutString(adapter.GetGenericDriver()); 1061 initialAdapterData.m_strNATNetworkName = wipedOutString(adapter.GetNATNetwork()); 1062 1063 /* Gather advanced options: */ 1064 initialAdapterData.m_adapterType = adapter.GetAdapterType(); 1065 initialAdapterData.m_promiscuousMode = adapter.GetPromiscModePolicy(); 1066 initialAdapterData.m_strMACAddress = adapter.GetMACAddress(); 1067 initialAdapterData.m_strGenericProperties = loadGenericProperties(adapter); 1068 initialAdapterData.m_fCableConnected = adapter.GetCableConnected(); 1069 1070 /* Gather redirect options: */ 1071 foreach (const QString &redirect, adapter.GetNATEngine().GetRedirects()) 1046 /* Prepare old adapter data: */ 1047 UIDataSettingsMachineNetworkAdapter oldAdapterData; 1048 1049 /* Check whether adapter is valid: */ 1050 const CNetworkAdapter &comAdapter = m_machine.GetNetworkAdapter(iSlot); 1051 if (!comAdapter.isNull()) 1052 { 1053 /* Gather old adapter data: */ 1054 oldAdapterData.m_iSlot = iSlot; 1055 oldAdapterData.m_fAdapterEnabled = comAdapter.GetEnabled(); 1056 oldAdapterData.m_attachmentType = comAdapter.GetAttachmentType(); 1057 oldAdapterData.m_strBridgedAdapterName = wipedOutString(comAdapter.GetBridgedInterface()); 1058 oldAdapterData.m_strInternalNetworkName = wipedOutString(comAdapter.GetInternalNetwork()); 1059 oldAdapterData.m_strHostInterfaceName = wipedOutString(comAdapter.GetHostOnlyInterface()); 1060 oldAdapterData.m_strGenericDriverName = wipedOutString(comAdapter.GetGenericDriver()); 1061 oldAdapterData.m_strNATNetworkName = wipedOutString(comAdapter.GetNATNetwork()); 1062 oldAdapterData.m_adapterType = comAdapter.GetAdapterType(); 1063 oldAdapterData.m_promiscuousMode = comAdapter.GetPromiscModePolicy(); 1064 oldAdapterData.m_strMACAddress = comAdapter.GetMACAddress(); 1065 oldAdapterData.m_strGenericProperties = loadGenericProperties(comAdapter); 1066 oldAdapterData.m_fCableConnected = comAdapter.GetCableConnected(); 1067 foreach (const QString &redirect, comAdapter.GetNATEngine().GetRedirects()) 1072 1068 { 1073 1069 const QStringList redirectData = redirect.split(','); 1074 1070 AssertMsg(redirectData.size() == 6, ("Redirect rule should be composed of 6 parts!\n")); 1075 initialAdapterData.m_redirects << UIPortForwardingData(redirectData[0],1076 (KNATProtocol)redirectData[1].toUInt(),1077 redirectData[2],1078 redirectData[3].toUInt(),1079 redirectData[4],1080 redirectData[5].toUInt());1071 oldAdapterData.m_redirects << UIPortForwardingData(redirectData.at(0), 1072 (KNATProtocol)redirectData.at(1).toUInt(), 1073 redirectData.at(2), 1074 redirectData.at(3).toUInt(), 1075 redirectData.at(4), 1076 redirectData.at(5).toUInt()); 1081 1077 } 1082 1078 } 1083 1079 1084 /* Append initialadapter data: */1085 initialData.m_adapters << initialAdapterData;1086 } 1087 1088 /* Cache initialdata: */1089 m_pCache->cacheInitialData( initialData);1080 /* Cache old adapter data: */ 1081 oldNetworkData.m_adapters << oldAdapterData; 1082 } 1083 1084 /* Cache old network data: */ 1085 m_pCache->cacheInitialData(oldNetworkData); 1090 1086 1091 1087 /* Upload machine to data: */ … … 1100 1096 QWidget *pLastFocusWidget = m_pTabWidget->focusProxy(); 1101 1097 1102 /* For each networkadapter: */1098 /* For each adapter: */ 1103 1099 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 1104 1100 { … … 1106 1102 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTabWidget->widget(iSlot)); 1107 1103 1108 /* Load initial adapter data topage: */1104 /* Load old adapter data to the page: */ 1109 1105 pTab->loadAdapterData(m_pCache->base().m_adapters.at(iSlot)); 1110 1106 … … 1125 1121 void UIMachineSettingsNetworkPage::putToCache() 1126 1122 { 1127 /* Prepare currentdata: */1128 UIDataSettingsMachineNetwork currentData;1129 1130 /* For each networkadapter: */1123 /* Prepare new network data: */ 1124 UIDataSettingsMachineNetwork newNetworkData; 1125 1126 /* For each adapter: */ 1131 1127 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 1132 1128 { … … 1134 1130 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTabWidget->widget(iSlot)); 1135 1131 1136 /* Prepare currentadapter data: */1137 UIDataSettingsMachineNetworkAdapter currentAdapterData;1138 1139 /* Gather currentadapter data: */1140 pTab->saveAdapterData( currentAdapterData);1141 1142 /* Cache currentadapter data: */1143 currentData.m_adapters << currentAdapterData;1144 } 1145 1146 /* Cache currentdata: */1147 m_pCache->cacheCurrentData( currentData);1132 /* Prepare new adapter data: */ 1133 UIDataSettingsMachineNetworkAdapter newAdapterData; 1134 1135 /* Gather new adapter data: */ 1136 pTab->saveAdapterData(newAdapterData); 1137 1138 /* Cache new adapter data: */ 1139 newNetworkData.m_adapters << newAdapterData; 1140 } 1141 1142 /* Cache new network data: */ 1143 m_pCache->cacheCurrentData(newNetworkData); 1148 1144 } 1149 1145 … … 1153 1149 UISettingsPageMachine::fetchData(data); 1154 1150 1155 /* Check ifnetwork data was changed: */1156 if ( m_pCache->wasChanged())1157 { 1158 /* For each networkadapter: */1151 /* Make sure machine is in valid mode & network data was changed: */ 1152 if (isMachineInValidMode() && m_pCache->wasChanged()) 1153 { 1154 /* For each adapter: */ 1159 1155 for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot) 1160 1156 { 1161 /* Check if adapter data was changed: */ 1162 const UIDataSettingsMachineNetworkAdapter &initialAdapterData = m_pCache->base().m_adapters.at(iSlot); 1163 const UIDataSettingsMachineNetworkAdapter ¤tAdapterData = m_pCache->data().m_adapters.at(iSlot); 1164 if (currentAdapterData != initialAdapterData) 1157 /* Get old network data from the cache: */ 1158 const UIDataSettingsMachineNetworkAdapter &oldAdapterData = m_pCache->base().m_adapters.at(iSlot); 1159 /* Get new network data from the cache: */ 1160 const UIDataSettingsMachineNetworkAdapter &newAdapterData = m_pCache->data().m_adapters.at(iSlot); 1161 1162 /* Make sure adapter data was changed: */ 1163 if (newAdapterData != oldAdapterData) 1165 1164 { 1166 1165 /* Check if adapter still valid: */ 1167 CNetworkAdapter adapter = m_machine.GetNetworkAdapter(iSlot);1168 if (! adapter.isNull())1166 CNetworkAdapter comAdapter = m_machine.GetNetworkAdapter(iSlot); 1167 if (!comAdapter.isNull()) 1169 1168 { 1170 /* Store adapter data: */1169 /* Store new adapter data: */ 1171 1170 if (isMachineOffline()) 1172 1171 { 1173 1172 /* Whether the adapter is enabled: */ 1174 if ( adapter.isOk()1175 && currentAdapterData.m_fAdapterEnabled != initialAdapterData.m_fAdapterEnabled)1176 adapter.SetEnabled(currentAdapterData.m_fAdapterEnabled);1173 if ( comAdapter.isOk() 1174 && newAdapterData.m_fAdapterEnabled != oldAdapterData.m_fAdapterEnabled) 1175 comAdapter.SetEnabled(newAdapterData.m_fAdapterEnabled); 1177 1176 /* Adapter type: */ 1178 if ( adapter.isOk()1179 && currentAdapterData.m_adapterType != initialAdapterData.m_adapterType)1180 adapter.SetAdapterType(currentAdapterData.m_adapterType);1177 if ( comAdapter.isOk() 1178 && newAdapterData.m_adapterType != oldAdapterData.m_adapterType) 1179 comAdapter.SetAdapterType(newAdapterData.m_adapterType); 1181 1180 /* Adapter MAC address: */ 1182 if ( adapter.isOk()1183 && currentAdapterData.m_strMACAddress != initialAdapterData.m_strMACAddress)1184 adapter.SetMACAddress(currentAdapterData.m_strMACAddress);1181 if ( comAdapter.isOk() 1182 && newAdapterData.m_strMACAddress != oldAdapterData.m_strMACAddress) 1183 comAdapter.SetMACAddress(newAdapterData.m_strMACAddress); 1185 1184 } 1186 1185 if (isMachineInValidMode()) 1187 1186 { 1188 1187 /* Adapter attachment type: */ 1189 switch ( currentAdapterData.m_attachmentType)1188 switch (newAdapterData.m_attachmentType) 1190 1189 { 1191 1190 case KNetworkAttachmentType_Bridged: 1192 1191 { 1193 if ( adapter.isOk()1194 && currentAdapterData.m_strBridgedAdapterName != initialAdapterData.m_strBridgedAdapterName)1195 adapter.SetBridgedInterface(currentAdapterData.m_strBridgedAdapterName);1192 if ( comAdapter.isOk() 1193 && newAdapterData.m_strBridgedAdapterName != oldAdapterData.m_strBridgedAdapterName) 1194 comAdapter.SetBridgedInterface(newAdapterData.m_strBridgedAdapterName); 1196 1195 break; 1197 1196 } 1198 1197 case KNetworkAttachmentType_Internal: 1199 1198 { 1200 if ( adapter.isOk()1201 && currentAdapterData.m_strInternalNetworkName != initialAdapterData.m_strInternalNetworkName)1202 adapter.SetInternalNetwork(currentAdapterData.m_strInternalNetworkName);1199 if ( comAdapter.isOk() 1200 && newAdapterData.m_strInternalNetworkName != oldAdapterData.m_strInternalNetworkName) 1201 comAdapter.SetInternalNetwork(newAdapterData.m_strInternalNetworkName); 1203 1202 break; 1204 1203 } 1205 1204 case KNetworkAttachmentType_HostOnly: 1206 1205 { 1207 if ( adapter.isOk()1208 && currentAdapterData.m_strHostInterfaceName != initialAdapterData.m_strHostInterfaceName)1209 adapter.SetHostOnlyInterface(currentAdapterData.m_strHostInterfaceName);1206 if ( comAdapter.isOk() 1207 && newAdapterData.m_strHostInterfaceName != oldAdapterData.m_strHostInterfaceName) 1208 comAdapter.SetHostOnlyInterface(newAdapterData.m_strHostInterfaceName); 1210 1209 break; 1211 1210 } 1212 1211 case KNetworkAttachmentType_Generic: 1213 1212 { 1214 if ( adapter.isOk()1215 && currentAdapterData.m_strGenericDriverName != initialAdapterData.m_strGenericDriverName)1216 adapter.SetGenericDriver(currentAdapterData.m_strGenericDriverName);1217 if ( adapter.isOk()1218 && currentAdapterData.m_strGenericProperties != initialAdapterData.m_strGenericProperties)1219 saveGenericProperties( adapter, currentAdapterData.m_strGenericProperties);1213 if ( comAdapter.isOk() 1214 && newAdapterData.m_strGenericDriverName != oldAdapterData.m_strGenericDriverName) 1215 comAdapter.SetGenericDriver(newAdapterData.m_strGenericDriverName); 1216 if ( comAdapter.isOk() 1217 && newAdapterData.m_strGenericProperties != oldAdapterData.m_strGenericProperties) 1218 saveGenericProperties(comAdapter, newAdapterData.m_strGenericProperties); 1220 1219 break; 1221 1220 } 1222 1221 case KNetworkAttachmentType_NATNetwork: 1223 1222 { 1224 if ( adapter.isOk()1225 && currentAdapterData.m_strNATNetworkName != initialAdapterData.m_strNATNetworkName)1226 adapter.SetNATNetwork(currentAdapterData.m_strNATNetworkName);1223 if ( comAdapter.isOk() 1224 && newAdapterData.m_strNATNetworkName != oldAdapterData.m_strNATNetworkName) 1225 comAdapter.SetNATNetwork(newAdapterData.m_strNATNetworkName); 1227 1226 break; 1228 1227 } … … 1230 1229 break; 1231 1230 } 1232 if ( adapter.isOk()1233 && currentAdapterData.m_attachmentType != initialAdapterData.m_attachmentType)1234 adapter.SetAttachmentType(currentAdapterData.m_attachmentType);1231 if ( comAdapter.isOk() 1232 && newAdapterData.m_attachmentType != oldAdapterData.m_attachmentType) 1233 comAdapter.SetAttachmentType(newAdapterData.m_attachmentType); 1235 1234 /* Adapter promiscuous mode: */ 1236 if ( adapter.isOk()1237 && currentAdapterData.m_promiscuousMode != initialAdapterData.m_promiscuousMode)1238 adapter.SetPromiscModePolicy(currentAdapterData.m_promiscuousMode);1235 if ( comAdapter.isOk() 1236 && newAdapterData.m_promiscuousMode != oldAdapterData.m_promiscuousMode) 1237 comAdapter.SetPromiscModePolicy(newAdapterData.m_promiscuousMode); 1239 1238 /* Whether the adapter cable connected: */ 1240 if ( adapter.isOk()1241 && currentAdapterData.m_fCableConnected != initialAdapterData.m_fCableConnected)1242 adapter.SetCableConnected(currentAdapterData.m_fCableConnected);1239 if ( comAdapter.isOk() 1240 && newAdapterData.m_fCableConnected != oldAdapterData.m_fCableConnected) 1241 comAdapter.SetCableConnected(newAdapterData.m_fCableConnected); 1243 1242 /* Adapter redirect options: */ 1244 if ( adapter.isOk()1245 && currentAdapterData.m_redirects != initialAdapterData.m_redirects1246 && ( initialAdapterData.m_attachmentType == KNetworkAttachmentType_NAT1247 || currentAdapterData.m_attachmentType == KNetworkAttachmentType_NAT))1243 if ( comAdapter.isOk() 1244 && newAdapterData.m_redirects != oldAdapterData.m_redirects 1245 && ( oldAdapterData.m_attachmentType == KNetworkAttachmentType_NAT 1246 || newAdapterData.m_attachmentType == KNetworkAttachmentType_NAT)) 1248 1247 { 1249 foreach (const QString &strOldRedirect, adapter.GetNATEngine().GetRedirects())1250 adapter.GetNATEngine().RemoveRedirect(strOldRedirect.section(',', 0, 0));1251 foreach (const UIPortForwardingData &newRedirect, currentAdapterData.m_redirects)1252 adapter.GetNATEngine().AddRedirect(newRedirect.name, newRedirect.protocol,1248 foreach (const QString &strOldRedirect, comAdapter.GetNATEngine().GetRedirects()) 1249 comAdapter.GetNATEngine().RemoveRedirect(strOldRedirect.section(',', 0, 0)); 1250 foreach (const UIPortForwardingData &newRedirect, newAdapterData.m_redirects) 1251 comAdapter.GetNATEngine().AddRedirect(newRedirect.name, newRedirect.protocol, 1253 1252 newRedirect.hostIp, newRedirect.hostPort.value(), 1254 1253 newRedirect.guestIp, newRedirect.guestPort.value());
Note:
See TracChangeset
for help on using the changeset viewer.