Changeset 37645 in vbox
- Timestamp:
- Jun 27, 2011 12:08:42 PM (14 years ago)
- 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
r37592 r37645 18 18 */ 19 19 20 /* Qt includes */ 21 #include <QTimer> 22 #include <QCompleter> 23 24 /* Local includes */ 20 /* Local includes: */ 25 21 #include "QIWidgetValidator.h" 26 22 #include "QIArrowButtonSwitch.h" … … 35 31 36 32 /* Empty item extra-code: */ 37 const char *emptyItemCode = "#empty#"; 33 const char *pEmptyItemCode = "#empty#"; 34 35 QString wipedOutString(const QString &strInputString) 36 { 37 return strInputString.isEmpty() ? QString() : strInputString; 38 } 38 39 39 40 UIMachineSettingsNetwork::UIMachineSettingsNetwork(UIMachineSettingsNetworkPage *pParent) … … 42 43 , m_pValidator(0) 43 44 , m_iSlot(-1) 44 , m_fPolished(false)45 45 { 46 46 /* Apply UI decorations: */ … … 53 53 54 54 /* Setup connections: */ 55 connect(m_pAdvancedArrow, SIGNAL(clicked()), this, SLOT(sltToggleAdvanced())); 55 connect(m_pEnableAdapterCheckBox, SIGNAL(toggled(bool)), this, SLOT(sltHandleAdapterActivityChange())); 56 connect(m_pAttachmentTypeComboBox, SIGNAL(activated(int)), this, SLOT(sltHandleAttachmentTypeChange())); 57 connect(m_pAdapterNameCombo, SIGNAL(activated(int)), this, SLOT(sltHandleAlternativeNameChange())); 58 connect(m_pAdapterNameCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(sltHandleAlternativeNameChange())); 59 connect(m_pAdvancedArrow, SIGNAL(clicked()), this, SLOT(sltHandleAdvancedButtonStateChange())); 56 60 connect(m_pMACButton, SIGNAL(clicked()), this, SLOT(sltGenerateMac())); 57 61 connect(m_pPortForwardingButton, SIGNAL(clicked()), this, SLOT(sltOpenPortForwardingDlg())); 62 connect(this, SIGNAL(sigTabUpdated()), m_pParent, SLOT(sltHandleUpdatedTab())); 58 63 59 64 /* Applying language settings: */ … … 61 66 } 62 67 68 void UIMachineSettingsNetwork::fetchAdapterCache(const UICacheSettingsMachineNetworkAdapter &adapterCache) 69 { 70 /* Get adapter data: */ 71 const UIDataSettingsMachineNetworkAdapter &adapterData = adapterCache.base(); 72 73 /* Load slot number: */ 74 m_iSlot = adapterData.m_iSlot; 75 76 /* Load adapter activity state: */ 77 m_pEnableAdapterCheckBox->setChecked(adapterData.m_fAdapterEnabled); 78 /* Handle adapter activity change: */ 79 sltHandleAdapterActivityChange(); 80 81 /* Load attachment type: */ 82 m_pAttachmentTypeComboBox->setCurrentIndex(position(m_pAttachmentTypeComboBox, adapterData.m_attachmentType)); 83 /* Load alternative name: */ 84 m_strBridgedAdapterName = wipedOutString(adapterData.m_strBridgedAdapterName); 85 m_strInternalNetworkName = wipedOutString(adapterData.m_strInternalNetworkName); 86 m_strHostInterfaceName = wipedOutString(adapterData.m_strHostInterfaceName); 87 m_strGenericDriverName = wipedOutString(adapterData.m_strGenericDriverName); 88 /* Handle attachment type change: */ 89 sltHandleAttachmentTypeChange(); 90 91 /* Load adapter type: */ 92 m_pAdapterTypeCombo->setCurrentIndex(position(m_pAdapterTypeCombo, adapterData.m_adapterType)); 93 94 /* Load promiscuous mode type: */ 95 m_pPromiscuousModeCombo->setCurrentIndex(position(m_pPromiscuousModeCombo, adapterData.m_promiscuousMode)); 96 97 /* Other options: */ 98 m_pMACEditor->setText(adapterData.m_strMACAddress); 99 m_pGenericPropertiesTextEdit->setText(adapterData.m_strGenericProperties); 100 m_pCableConnectedCheckBox->setChecked(adapterData.m_fCableConnected); 101 102 /* Load port forwarding rules: */ 103 m_portForwardingRules = adapterData.m_redirects; 104 } 105 106 void UIMachineSettingsNetwork::uploadAdapterCache(UICacheSettingsMachineNetworkAdapter &adapterCache) 107 { 108 /* Prepare adapter data: */ 109 UIDataSettingsMachineNetworkAdapter adapterData = adapterCache.base(); 110 111 /* Save adapter activity state: */ 112 adapterData.m_fAdapterEnabled = m_pEnableAdapterCheckBox->isChecked(); 113 114 /* Save attachment type & alternative name: */ 115 adapterData.m_attachmentType = attachmentType(); 116 switch (adapterData.m_attachmentType) 117 { 118 case KNetworkAttachmentType_Null: 119 break; 120 case KNetworkAttachmentType_NAT: 121 break; 122 case KNetworkAttachmentType_Bridged: 123 adapterData.m_strBridgedAdapterName = alternativeName(); 124 break; 125 case KNetworkAttachmentType_Internal: 126 adapterData.m_strInternalNetworkName = alternativeName(); 127 break; 128 case KNetworkAttachmentType_HostOnly: 129 adapterData.m_strHostInterfaceName = alternativeName(); 130 break; 131 case KNetworkAttachmentType_Generic: 132 adapterData.m_strGenericDriverName = alternativeName(); 133 adapterData.m_strGenericProperties = m_pGenericPropertiesTextEdit->toPlainText(); 134 break; 135 default: 136 break; 137 } 138 139 /* Save adapter type: */ 140 adapterData.m_adapterType = (KNetworkAdapterType)m_pAdapterTypeCombo->itemData(m_pAdapterTypeCombo->currentIndex()).toInt(); 141 142 /* Save promiscuous mode type: */ 143 adapterData.m_promiscuousMode = (KNetworkAdapterPromiscModePolicy)m_pPromiscuousModeCombo->itemData(m_pPromiscuousModeCombo->currentIndex()).toInt(); 144 145 /* Other options: */ 146 adapterData.m_strMACAddress = m_pMACEditor->text().isEmpty() ? QString() : m_pMACEditor->text(); 147 adapterData.m_fCableConnected = m_pCableConnectedCheckBox->isChecked(); 148 149 /* Save port forwarding rules: */ 150 adapterData.m_redirects = m_portForwardingRules; 151 152 /* Cache adapter data: */ 153 adapterCache.cacheCurrentData(adapterData); 154 } 155 156 void UIMachineSettingsNetwork::setValidator(QIWidgetValidator *pValidator) 157 { 158 m_pValidator = pValidator; 159 } 160 161 bool UIMachineSettingsNetwork::revalidate(QString &strWarning, QString &strTitle) 162 { 163 /* 'True' for disabled adapter: */ 164 if (!m_pEnableAdapterCheckBox->isChecked()) 165 return true; 166 167 /* Validate alternatives: */ 168 bool fValid = true; 169 switch (attachmentType()) 170 { 171 case KNetworkAttachmentType_Bridged: 172 { 173 if (alternativeName().isNull()) 174 { 175 strWarning = tr("no bridged network adapter is selected"); 176 fValid = false; 177 } 178 break; 179 } 180 case KNetworkAttachmentType_Internal: 181 { 182 if (alternativeName().isNull()) 183 { 184 strWarning = tr("no internal network name is specified"); 185 fValid = false; 186 } 187 break; 188 } 189 case KNetworkAttachmentType_HostOnly: 190 { 191 if (alternativeName().isNull()) 192 { 193 strWarning = tr("no host-only network adapter is selected"); 194 fValid = false; 195 } 196 break; 197 } 198 case KNetworkAttachmentType_Generic: 199 { 200 if (alternativeName().isNull()) 201 { 202 strWarning = tr("no generic driver is selected"); 203 fValid = false; 204 } 205 break; 206 } 207 default: 208 break; 209 } 210 if (!fValid) 211 strTitle += ": " + vboxGlobal().removeAccelMark(tabTitle()); 212 213 return fValid; 214 } 215 216 QWidget* UIMachineSettingsNetwork::setOrderAfter(QWidget *pAfter) 217 { 218 setTabOrder(pAfter, m_pEnableAdapterCheckBox); 219 setTabOrder(m_pEnableAdapterCheckBox, m_pAttachmentTypeComboBox); 220 setTabOrder(m_pAttachmentTypeComboBox, m_pAdapterNameCombo); 221 setTabOrder(m_pAdapterNameCombo, m_pAdvancedArrow); 222 setTabOrder(m_pAdvancedArrow, m_pAdapterTypeCombo); 223 setTabOrder(m_pAdapterTypeCombo, m_pPromiscuousModeCombo); 224 setTabOrder(m_pPromiscuousModeCombo, m_pMACEditor); 225 setTabOrder(m_pMACEditor, m_pMACButton); 226 setTabOrder(m_pMACButton, m_pGenericPropertiesTextEdit); 227 setTabOrder(m_pGenericPropertiesTextEdit, m_pCableConnectedCheckBox); 228 setTabOrder(m_pCableConnectedCheckBox, m_pPortForwardingButton); 229 return m_pPortForwardingButton; 230 } 231 232 QString UIMachineSettingsNetwork::tabTitle() const 233 { 234 return VBoxGlobal::tr("Adapter %1").arg(QString("&%1").arg(m_iSlot + 1)); 235 } 236 237 KNetworkAttachmentType UIMachineSettingsNetwork::attachmentType() const 238 { 239 return (KNetworkAttachmentType)m_pAttachmentTypeComboBox->itemData(m_pAttachmentTypeComboBox->currentIndex()).toInt(); 240 } 241 242 QString UIMachineSettingsNetwork::alternativeName(int iType) const 243 { 244 if (iType == -1) 245 iType = attachmentType(); 246 QString strResult; 247 switch (iType) 248 { 249 case KNetworkAttachmentType_Bridged: 250 strResult = m_strBridgedAdapterName; 251 break; 252 case KNetworkAttachmentType_Internal: 253 strResult = m_strInternalNetworkName; 254 break; 255 case KNetworkAttachmentType_HostOnly: 256 strResult = m_strHostInterfaceName; 257 break; 258 case KNetworkAttachmentType_Generic: 259 strResult = m_strGenericDriverName; 260 break; 261 default: 262 break; 263 } 264 Assert(strResult.isNull() || !strResult.isEmpty()); 265 return strResult; 266 } 267 63 268 void UIMachineSettingsNetwork::polishTab() 64 269 { 65 270 /* Basic attributes: */ 66 m CbEnableAdapter->setEnabled(m_pParent->isMachineOffline());271 m_pEnableAdapterCheckBox->setEnabled(m_pParent->isMachineOffline()); 67 272 m_pAttachmentTypeLabel->setEnabled(m_pParent->isMachineInValidMode()); 68 m_pAttachmentTypeCombo ->setEnabled(m_pParent->isMachineInValidMode());273 m_pAttachmentTypeComboBox->setEnabled(m_pParent->isMachineInValidMode()); 69 274 m_pAdapterNameLabel->setEnabled(m_pParent->isMachineInValidMode() && 70 275 attachmentType() != KNetworkAttachmentType_Null && … … 89 294 m_pMACEditor->setEnabled(m_pParent->isMachineOffline()); 90 295 m_pMACButton->setEnabled(m_pParent->isMachineOffline()); 91 296 m_pGenericPropertiesTextEdit->setEnabled(m_pParent->isMachineOffline()); 92 297 m_pPortForwardingButton->setEnabled(m_pParent->isMachineInValidMode() && 93 298 attachmentType() == KNetworkAttachmentType_NAT); … … 96 301 if ((m_pParent->isMachineSaved() || m_pParent->isMachineOnline()) && !m_pAdvancedArrow->isExpanded()) 97 302 m_pAdvancedArrow->animateClick(); 98 sltToggleAdvanced(); 99 } 100 101 void UIMachineSettingsNetwork::fetchAdapterCache(const UICacheSettingsMachineNetworkAdapter &adapterCache) 102 { 103 /* Get adapter data: */ 104 const UIDataSettingsMachineNetworkAdapter &adapterData = adapterCache.base(); 105 106 /* Load slot number: */ 107 m_iSlot = adapterData.m_iSlot; 108 109 /* Load adapter activity state: */ 110 mCbEnableAdapter->setChecked(adapterData.m_fAdapterEnabled); 111 112 /* Load attachment type: */ 113 int iAttachmentPos = m_pAttachmentTypeCombo->findData(adapterData.m_attachmentType); 114 m_pAttachmentTypeCombo->setCurrentIndex(iAttachmentPos == -1 ? 0 : iAttachmentPos); 115 116 /* Load alternative name: */ 117 m_strBrgName = adapterData.m_strBridgedAdapterName; 118 if (m_strBrgName.isEmpty()) 119 m_strBrgName = QString(); 120 121 m_strIntName = adapterData.m_strInternalNetworkName; 122 if (m_strIntName.isEmpty()) 123 m_strIntName = QString(); 124 125 m_strHoiName = adapterData.m_strHostInterfaceName; 126 if (m_strHoiName.isEmpty()) 127 m_strHoiName = QString(); 128 129 m_strGenericDriver = adapterData.m_strGenericDriver; 130 if (m_strGenericDriver.isEmpty()) 131 m_strGenericDriver = QString(); 132 133 sltUpdateAttachmentAlternative(); 134 135 /* Load adapter type: */ 136 int iAdapterPos = m_pAdapterTypeCombo->findData(adapterData.m_adapterType); 137 m_pAdapterTypeCombo->setCurrentIndex(iAdapterPos == -1 ? 0 : iAdapterPos); 138 139 /* Load promiscuous mode type: */ 140 int iPromiscuousModePos = m_pPromiscuousModeCombo->findData(adapterData.m_promiscuousMode); 141 m_pPromiscuousModeCombo->setCurrentIndex(iPromiscuousModePos == -1 ? 0 : iPromiscuousModePos); 142 143 /* Other options: */ 144 m_pMACEditor->setText(adapterData.m_strMACAddress); 145 m_pGenericPropertiesTextEdit->setText(adapterData.m_strGenericProperties); 146 m_pCableConnectedCheckBox->setChecked(adapterData.m_fCableConnected); 147 148 /* Load port forwarding rules: */ 149 m_portForwardingRules = adapterData.m_redirects; 150 } 151 152 void UIMachineSettingsNetwork::uploadAdapterCache(UICacheSettingsMachineNetworkAdapter &adapterCache) 153 { 154 /* Prepare adapter data: */ 155 UIDataSettingsMachineNetworkAdapter adapterData = adapterCache.base(); 156 157 /* Save adapter activity state: */ 158 adapterData.m_fAdapterEnabled = mCbEnableAdapter->isChecked(); 159 160 /* Save attachment type & alternative name: */ 161 adapterData.m_attachmentType = attachmentType(); 162 switch (adapterData.m_attachmentType) 163 { 164 case KNetworkAttachmentType_Null: 165 break; 166 case KNetworkAttachmentType_NAT: 167 break; 168 case KNetworkAttachmentType_Bridged: 169 adapterData.m_strBridgedAdapterName = alternativeName(); 170 break; 171 case KNetworkAttachmentType_Internal: 172 adapterData.m_strInternalNetworkName = alternativeName(); 173 break; 174 case KNetworkAttachmentType_HostOnly: 175 adapterData.m_strHostInterfaceName = alternativeName(); 176 break; 177 case KNetworkAttachmentType_Generic: 178 adapterData.m_strGenericDriver = alternativeName(); 179 adapterData.m_strGenericProperties = m_pGenericPropertiesTextEdit->toPlainText(); 180 break; 181 default: 182 break; 183 } 184 185 /* Save adapter type: */ 186 adapterData.m_adapterType = (KNetworkAdapterType)m_pAdapterTypeCombo->itemData(m_pAdapterTypeCombo->currentIndex()).toInt(); 187 188 /* Save promiscuous mode type: */ 189 adapterData.m_promiscuousMode = (KNetworkAdapterPromiscModePolicy)m_pPromiscuousModeCombo->itemData(m_pPromiscuousModeCombo->currentIndex()).toInt(); 190 191 /* Other options: */ 192 adapterData.m_strMACAddress = m_pMACEditor->text().isEmpty() ? QString() : m_pMACEditor->text(); 193 adapterData.m_fCableConnected = m_pCableConnectedCheckBox->isChecked(); 194 195 /* Save port forwarding rules: */ 196 adapterData.m_redirects = m_portForwardingRules; 197 198 /* Cache adapter data: */ 199 adapterCache.cacheCurrentData(adapterData); 200 } 201 202 void UIMachineSettingsNetwork::setValidator(QIWidgetValidator *pValidator) 203 { 204 m_pValidator = pValidator; 205 206 connect(mCbEnableAdapter, SIGNAL(toggled(bool)), m_pValidator, SLOT(revalidate())); 207 connect(m_pAttachmentTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(sltUpdateAttachmentAlternative())); 208 connect(m_pAdapterNameCombo, SIGNAL(activated(const QString&)), this, SLOT(sltUpdateAlternativeName())); 209 connect(m_pAdapterNameCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(sltUpdateAlternativeName())); 210 211 m_pValidator->revalidate(); 212 } 213 214 bool UIMachineSettingsNetwork::revalidate(QString &strWarning, QString &strTitle) 215 { 216 /* 'True' for disabled adapter: */ 217 if (!mCbEnableAdapter->isChecked()) 218 return true; 219 220 /* Validate alternatives: */ 221 bool fValid = true; 222 switch (attachmentType()) 223 { 224 case KNetworkAttachmentType_Bridged: 225 if (alternativeName().isNull()) 226 { 227 strWarning = tr("no bridged network adapter is selected"); 228 fValid = false; 229 } 230 break; 231 case KNetworkAttachmentType_Internal: 232 if (alternativeName().isNull()) 233 { 234 strWarning = tr("no internal network name is specified"); 235 fValid = false; 236 } 237 break; 238 case KNetworkAttachmentType_HostOnly: 239 if (alternativeName().isNull()) 240 { 241 strWarning = tr("no host-only network adapter is selected"); 242 fValid = false; 243 } 244 break; 245 case KNetworkAttachmentType_Generic: 246 if (alternativeName().isNull()) 247 { 248 strWarning = tr("no generic driver is selected"); 249 fValid = false; 250 } 251 break; 252 default: 253 break; 254 } 255 if (!fValid) 256 strTitle += ": " + vboxGlobal().removeAccelMark(pageTitle()); 257 258 return fValid; 259 } 260 261 QWidget* UIMachineSettingsNetwork::setOrderAfter(QWidget *pAfter) 262 { 263 setTabOrder(pAfter, mCbEnableAdapter); 264 setTabOrder(mCbEnableAdapter, m_pAttachmentTypeCombo); 265 setTabOrder(m_pAttachmentTypeCombo, m_pAdapterNameCombo); 266 setTabOrder(m_pAdapterNameCombo, m_pAdvancedArrow); 267 setTabOrder(m_pAdvancedArrow, m_pAdapterTypeCombo); 268 setTabOrder(m_pAdapterTypeCombo, m_pPromiscuousModeCombo); 269 setTabOrder(m_pPromiscuousModeCombo, m_pMACEditor); 270 setTabOrder(m_pMACEditor, m_pMACButton); 271 setTabOrder(m_pMACButton, m_pCableConnectedCheckBox); 272 setTabOrder(m_pCableConnectedCheckBox, m_pPortForwardingButton); 273 return m_pPortForwardingButton; 274 } 275 276 QString UIMachineSettingsNetwork::pageTitle() const 277 { 278 return VBoxGlobal::tr("Adapter %1", "network").arg(QString("&%1").arg(m_iSlot + 1));; 279 } 280 281 KNetworkAttachmentType UIMachineSettingsNetwork::attachmentType() const 282 { 283 return (KNetworkAttachmentType)m_pAttachmentTypeCombo->itemData(m_pAttachmentTypeCombo->currentIndex()).toInt(); 284 } 285 286 QString UIMachineSettingsNetwork::alternativeName(int type) const 287 { 288 if (type == -1) 289 type = attachmentType(); 290 QString strResult; 291 switch (type) 292 { 293 case KNetworkAttachmentType_Bridged: 294 strResult = m_strBrgName; 295 break; 296 case KNetworkAttachmentType_Internal: 297 strResult = m_strIntName; 298 break; 299 case KNetworkAttachmentType_HostOnly: 300 strResult = m_strHoiName; 301 break; 302 case KNetworkAttachmentType_Generic: 303 strResult = m_strGenericDriver; 304 break; 305 default: 306 break; 307 } 308 Assert(strResult.isNull() || !strResult.isEmpty()); 309 return strResult; 310 } 311 312 void UIMachineSettingsNetwork::showEvent(QShowEvent *pEvent) 313 { 314 /* Polish page if necessary: */ 315 if (!m_fPolished) 316 { 317 m_fPolished = true; 318 /* Give the minimum size hint to the first layout column: */ 319 m_pNetworkChildGridLayout->setColumnMinimumWidth (0, m_pAttachmentTypeLabel->width()); 320 } 321 /* Call for base-class: */ 322 QWidget::showEvent(pEvent); 303 sltHandleAdvancedButtonStateChange(); 304 } 305 306 void UIMachineSettingsNetwork::reloadAlternative() 307 { 308 /* Repopulate alternative-name combo-box content: */ 309 updateAlternativeList(); 310 /* Select previous or default alternative-name combo-box item: */ 311 updateAlternativeName(); 323 312 } 324 313 … … 332 321 333 322 /* Translate attachment info: */ 334 sltUpdateAttachmentAlternative(); 335 } 336 337 void UIMachineSettingsNetwork::sltUpdateAttachmentAlternative() 338 { 339 /* Blocking signals to change content manually: */ 340 m_pAdapterNameCombo->blockSignals(true); 341 323 sltHandleAttachmentTypeChange(); 324 } 325 326 void UIMachineSettingsNetwork::sltHandleAdapterActivityChange() 327 { 328 /* Update availability: */ 329 m_pAdapterOptionsContainer->setEnabled(m_pEnableAdapterCheckBox->isChecked()); 330 /* Revalidate if possible: */ 331 if (m_pValidator) 332 m_pValidator->revalidate(); 333 } 334 335 void UIMachineSettingsNetwork::sltHandleAttachmentTypeChange() 336 { 342 337 /* Update alternative-name combo-box availability: */ 343 338 m_pAdapterNameLabel->setEnabled(attachmentType() != KNetworkAttachmentType_Null && … … 345 340 m_pAdapterNameCombo->setEnabled(attachmentType() != KNetworkAttachmentType_Null && 346 341 attachmentType() != KNetworkAttachmentType_NAT); 342 /* Update promiscuous-mode combo-box availability: */ 347 343 m_pPromiscuousModeLabel->setEnabled(attachmentType() != KNetworkAttachmentType_Null && 348 344 attachmentType() != KNetworkAttachmentType_Generic && … … 351 347 attachmentType() != KNetworkAttachmentType_Generic && 352 348 attachmentType() != KNetworkAttachmentType_NAT); 353 354 /* Refresh list: */ 355 m_pAdapterNameCombo->clear(); 349 /* Update generic-properties editor visibility: */ 350 m_pGenericPropertiesLabel->setVisible(attachmentType() == KNetworkAttachmentType_Generic && 351 m_pAdvancedArrow->isExpanded()); 352 m_pGenericPropertiesTextEdit->setVisible(attachmentType() == KNetworkAttachmentType_Generic && 353 m_pAdvancedArrow->isExpanded()); 354 /* Update forwarding-rules button availability: */ 355 m_pPortForwardingButton->setEnabled(attachmentType() == KNetworkAttachmentType_NAT); 356 /* Update alternative-name combo-box whats-this and editable state: */ 356 357 switch (attachmentType()) 357 358 { 358 359 case KNetworkAttachmentType_Bridged: 360 { 359 361 m_pAdapterNameCombo->setWhatsThis(tr("Selects the network adapter on the host system that traffic " 360 362 "to and from this network card will go through.")); 361 m_pAdapterNameCombo->insertItems(0, m_pParent->brgList());362 363 m_pAdapterNameCombo->setEditable(false); 363 364 break; 365 } 364 366 case KNetworkAttachmentType_Internal: 367 { 365 368 m_pAdapterNameCombo->setWhatsThis(tr("Enter the name of the internal network that this network card " 366 369 "will be connected to. You can create a new internal network by " 367 370 "choosing a name which is not used by any other network cards " 368 371 "in this virtual machine or others.")); 369 m_pAdapterNameCombo->insertItems(0, m_pParent->fullIntList());370 372 m_pAdapterNameCombo->setEditable(true); 371 m_pAdapterNameCombo->setCompleter(0);372 break;373 break; 374 } 373 375 case KNetworkAttachmentType_HostOnly: 376 { 374 377 m_pAdapterNameCombo->setWhatsThis(tr("Selects the virtual network adapter on the host system that traffic " 375 378 "to and from this network card will go through. " 376 379 "You can create and remove adapters using the global network " 377 380 "settings in the virtual machine manager window.")); 378 m_pAdapterNameCombo->insertItems(0, m_pParent->hoiList());379 381 m_pAdapterNameCombo->setEditable(false); 380 382 break; 383 } 381 384 case KNetworkAttachmentType_Generic: 385 { 382 386 m_pAdapterNameCombo->setWhatsThis(tr("Selects the driver to be used with this network card.")); 383 m_pAdapterNameCombo->insertItem(0, alternativeName());384 387 m_pAdapterNameCombo->setEditable(true); 385 m_pAdapterNameCombo->setCompleter(0);386 break;388 break; 389 } 387 390 default: 391 { 388 392 m_pAdapterNameCombo->setWhatsThis(QString()); 389 393 break; 390 } 391 392 /* Prepend 'empty' or 'default' item: */ 393 if (m_pAdapterNameCombo->count() == 0) 394 { 395 switch (attachmentType()) 396 { 397 case KNetworkAttachmentType_Bridged: 398 case KNetworkAttachmentType_HostOnly: 394 } 395 } 396 397 /* Update alternative combo: */ 398 reloadAlternative(); 399 400 /* Handle alternative-name cange: */ 401 sltHandleAlternativeNameChange(); 402 } 403 404 void UIMachineSettingsNetwork::sltHandleAlternativeNameChange() 405 { 406 /* Remember new name if its changed, 407 * Call for other pages update, if necessary: */ 408 switch (attachmentType()) 409 { 410 case KNetworkAttachmentType_Bridged: 411 { 412 QString newName(m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == QString(pEmptyItemCode) || 413 m_pAdapterNameCombo->currentText().isEmpty() ? QString() : m_pAdapterNameCombo->currentText()); 414 if (m_strBridgedAdapterName != newName) 415 m_strBridgedAdapterName = newName; 416 break; 417 } 418 case KNetworkAttachmentType_Internal: 419 { 420 QString newName((m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == QString(pEmptyItemCode) && 421 m_pAdapterNameCombo->currentText() == m_pAdapterNameCombo->itemText(m_pAdapterNameCombo->currentIndex())) || 422 m_pAdapterNameCombo->currentText().isEmpty() ? QString() : m_pAdapterNameCombo->currentText()); 423 if (m_strInternalNetworkName != newName) 399 424 { 400 /* Adapters list 'empty': */ 401 int pos = m_pAdapterNameCombo->findData(emptyItemCode); 402 if (pos == -1) 403 m_pAdapterNameCombo->insertItem(0, tr("Not selected", "network adapter name"), emptyItemCode); 404 else 405 m_pAdapterNameCombo->setItemText(pos, tr("Not selected", "network adapter name")); 406 break; 425 m_strInternalNetworkName = newName; 426 if (!m_strInternalNetworkName.isNull()) 427 emit sigTabUpdated(); 407 428 } 408 case KNetworkAttachmentType_Internal: 429 break; 430 } 431 case KNetworkAttachmentType_HostOnly: 432 { 433 QString newName(m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == QString(pEmptyItemCode) || 434 m_pAdapterNameCombo->currentText().isEmpty() ? QString() : m_pAdapterNameCombo->currentText()); 435 if (m_strHostInterfaceName != newName) 436 m_strHostInterfaceName = newName; 437 break; 438 } 439 case KNetworkAttachmentType_Generic: 440 { 441 QString newName((m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == QString(pEmptyItemCode) && 442 m_pAdapterNameCombo->currentText() == m_pAdapterNameCombo->itemText(m_pAdapterNameCombo->currentIndex())) || 443 m_pAdapterNameCombo->currentText().isEmpty() ? QString() : m_pAdapterNameCombo->currentText()); 444 if (m_strGenericDriverName != newName) 409 445 { 410 /* Internal network 'default' name: */ 411 if (m_pAdapterNameCombo->findText("intnet") == -1) 412 m_pAdapterNameCombo->insertItem(0, "intnet"); 413 break; 446 m_strGenericDriverName = newName; 447 if (!m_strGenericDriverName.isNull()) 448 emit sigTabUpdated(); 414 449 } 415 default:416 break;417 }418 }419 420 /* Select previous or default item: */421 switch (attachmentType())422 {423 case KNetworkAttachmentType_Bridged:424 case KNetworkAttachmentType_HostOnly:425 {426 int pos = m_pAdapterNameCombo->findText(alternativeName());427 m_pAdapterNameCombo->setCurrentIndex(pos == -1 ? 0 : pos);428 break;429 }430 case KNetworkAttachmentType_Internal:431 {432 int pos = m_pAdapterNameCombo->findText(alternativeName());433 m_pAdapterNameCombo->setCurrentIndex(pos == -1 ? 0 : pos);434 450 break; 435 451 } … … 438 454 } 439 455 440 /* Remember selected item: */ 441 sltUpdateAlternativeName(); 442 443 /* Update visibility of "generic" properties editor: */ 444 m_pGenericPropertiesLabel->setVisible(attachmentType() == KNetworkAttachmentType_Generic && 445 m_pAdvancedArrow->isExpanded()); 446 m_pGenericPropertiesTextEdit->setVisible(attachmentType() == KNetworkAttachmentType_Generic && 447 m_pAdvancedArrow->isExpanded()); 448 449 /* Update Forwarding rules button availability: */ 450 m_pPortForwardingButton->setEnabled(attachmentType() == KNetworkAttachmentType_NAT); 451 452 /* Unblocking signals as content is changed already: */ 453 m_pAdapterNameCombo->blockSignals(false); 454 } 455 456 void UIMachineSettingsNetwork::sltUpdateAlternativeName() 457 { 458 switch (attachmentType()) 459 { 460 case KNetworkAttachmentType_Bridged: 461 { 462 QString newName(m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == 463 QString(emptyItemCode) || 464 m_pAdapterNameCombo->currentText().isEmpty() ? 465 QString::null : m_pAdapterNameCombo->currentText()); 466 if (m_strBrgName != newName) 467 m_strBrgName = newName; 468 break; 469 } 470 case KNetworkAttachmentType_Internal: 471 { 472 QString newName((m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == 473 QString(emptyItemCode) && 474 m_pAdapterNameCombo->currentText() == 475 m_pAdapterNameCombo->itemText(m_pAdapterNameCombo->currentIndex())) || 476 m_pAdapterNameCombo->currentText().isEmpty() ? 477 QString::null : m_pAdapterNameCombo->currentText()); 478 if (m_strIntName != newName) 479 { 480 m_strIntName = newName; 481 if (!m_strIntName.isNull()) 482 QTimer::singleShot(0, m_pParent, SLOT (updatePages())); 483 } 484 break; 485 } 486 case KNetworkAttachmentType_HostOnly: 487 { 488 QString newName(m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == 489 QString(emptyItemCode) || 490 m_pAdapterNameCombo->currentText().isEmpty() ? 491 QString::null : m_pAdapterNameCombo->currentText()); 492 if (m_strHoiName != newName) 493 m_strHoiName = newName; 494 break; 495 } 496 case KNetworkAttachmentType_Generic: 497 { 498 QString newName((m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == 499 QString(emptyItemCode) && 500 m_pAdapterNameCombo->currentText() == 501 m_pAdapterNameCombo->itemText(m_pAdapterNameCombo->currentIndex())) || 502 m_pAdapterNameCombo->currentText().isEmpty() ? 503 QString::null : m_pAdapterNameCombo->currentText()); 504 if (m_strGenericDriver != newName) 505 m_strGenericDriver = newName; 506 break; 507 } 508 default: 509 break; 510 } 511 456 /* Revalidate if possible: */ 512 457 if (m_pValidator) 513 458 m_pValidator->revalidate(); 514 459 } 515 460 516 void UIMachineSettingsNetwork::sltToggleAdvanced() 517 { 461 void UIMachineSettingsNetwork::sltHandleAdvancedButtonStateChange() 462 { 463 /* Update visibility of advanced options: */ 518 464 m_pAdapterTypeLabel->setVisible(m_pAdvancedArrow->isExpanded()); 519 465 m_pAdapterTypeCombo->setVisible(m_pAdvancedArrow->isExpanded()); … … 548 494 { 549 495 /* Remember the currently selected attachment type: */ 550 int iCurrentAttachment = m_pAttachmentTypeCombo ->currentIndex();496 int iCurrentAttachment = m_pAttachmentTypeComboBox->currentIndex(); 551 497 552 498 /* Clear the attachments combo-box: */ 553 m_pAttachmentTypeCombo ->clear();499 m_pAttachmentTypeComboBox->clear(); 554 500 555 501 /* Populate attachments: */ 556 502 int iAttachmentTypeIndex = 0; 557 m_pAttachmentTypeCombo ->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_Null));558 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Null);559 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeCombo->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);503 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_Null)); 504 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Null); 505 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole); 560 506 ++iAttachmentTypeIndex; 561 m_pAttachmentTypeCombo ->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_NAT));562 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_NAT);563 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeCombo->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);507 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_NAT)); 508 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_NAT); 509 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole); 564 510 ++iAttachmentTypeIndex; 565 m_pAttachmentTypeCombo ->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_Bridged));566 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Bridged);567 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeCombo->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);511 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_Bridged)); 512 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Bridged); 513 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole); 568 514 ++iAttachmentTypeIndex; 569 m_pAttachmentTypeCombo ->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_Internal));570 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Internal);571 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeCombo->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);515 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_Internal)); 516 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Internal); 517 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole); 572 518 ++iAttachmentTypeIndex; 573 m_pAttachmentTypeCombo ->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_HostOnly));574 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_HostOnly);575 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeCombo->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);519 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_HostOnly)); 520 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_HostOnly); 521 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole); 576 522 ++iAttachmentTypeIndex; 577 m_pAttachmentTypeCombo ->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_Generic));578 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Generic);579 m_pAttachmentTypeCombo ->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeCombo->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);523 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, vboxGlobal().toString(KNetworkAttachmentType_Generic)); 524 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Generic); 525 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole); 580 526 ++iAttachmentTypeIndex; 581 527 582 528 /* Restore the previously selected attachment type: */ 583 m_pAttachmentTypeCombo ->setCurrentIndex(iCurrentAttachment);529 m_pAttachmentTypeComboBox->setCurrentIndex(iCurrentAttachment == -1 ? 0 : iCurrentAttachment); 584 530 } 585 531 … … 651 597 652 598 /* Restore the previously selected promiscuous mode type: */ 653 m_pPromiscuousModeCombo->setCurrentIndex(iCurrentPromiscuousMode); 654 } 655 } 656 657 /* UIMachineSettingsNetworkPage Stuff */ 599 m_pPromiscuousModeCombo->setCurrentIndex(iCurrentPromiscuousMode == -1 ? 0 : iCurrentPromiscuousMode); 600 } 601 } 602 603 void UIMachineSettingsNetwork::updateAlternativeList() 604 { 605 /* Block signals initially: */ 606 m_pAdapterNameCombo->blockSignals(true); 607 608 /* Repopulate alternative-name combo: */ 609 m_pAdapterNameCombo->clear(); 610 switch (attachmentType()) 611 { 612 case KNetworkAttachmentType_Bridged: 613 m_pAdapterNameCombo->insertItems(0, m_pParent->bridgedAdapterList()); 614 break; 615 case KNetworkAttachmentType_Internal: 616 m_pAdapterNameCombo->insertItems(0, m_pParent->internalNetworkList()); 617 break; 618 case KNetworkAttachmentType_HostOnly: 619 m_pAdapterNameCombo->insertItems(0, m_pParent->hostInterfaceList()); 620 break; 621 case KNetworkAttachmentType_Generic: 622 m_pAdapterNameCombo->insertItems(0, m_pParent->genericDriverList()); 623 break; 624 default: 625 break; 626 } 627 628 /* Prepend 'empty' or 'default' item to alternative-name combo: */ 629 if (m_pAdapterNameCombo->count() == 0) 630 { 631 switch (attachmentType()) 632 { 633 case KNetworkAttachmentType_Bridged: 634 case KNetworkAttachmentType_HostOnly: 635 { 636 /* If adapter list is empty => add 'Not selected' item: */ 637 int pos = m_pAdapterNameCombo->findData(pEmptyItemCode); 638 if (pos == -1) 639 m_pAdapterNameCombo->insertItem(0, tr("Not selected", "network adapter name"), pEmptyItemCode); 640 else 641 m_pAdapterNameCombo->setItemText(pos, tr("Not selected", "network adapter name")); 642 break; 643 } 644 case KNetworkAttachmentType_Internal: 645 { 646 /* Internal network list should have a default item: */ 647 if (m_pAdapterNameCombo->findText("intnet") == -1) 648 m_pAdapterNameCombo->insertItem(0, "intnet"); 649 break; 650 } 651 default: 652 break; 653 } 654 } 655 656 /* Unblock signals finally: */ 657 m_pAdapterNameCombo->blockSignals(false); 658 } 659 660 void UIMachineSettingsNetwork::updateAlternativeName() 661 { 662 /* Block signals initially: */ 663 m_pAdapterNameCombo->blockSignals(true); 664 665 switch (attachmentType()) 666 { 667 case KNetworkAttachmentType_Bridged: 668 case KNetworkAttachmentType_Internal: 669 case KNetworkAttachmentType_HostOnly: 670 case KNetworkAttachmentType_Generic: 671 { 672 m_pAdapterNameCombo->setCurrentIndex(position(m_pAdapterNameCombo, alternativeName())); 673 break; 674 } 675 default: 676 break; 677 } 678 679 /* Unblock signals finally: */ 680 m_pAdapterNameCombo->blockSignals(false); 681 } 682 683 /* static */ 684 int UIMachineSettingsNetwork::position(QComboBox *pComboBox, int iData) 685 { 686 int iPosition = pComboBox->findData(iData); 687 return iPosition == -1 ? 0 : iPosition; 688 } 689 690 /* static */ 691 int UIMachineSettingsNetwork::position(QComboBox *pComboBox, const QString &strText) 692 { 693 int iPosition = pComboBox->findText(strText); 694 return iPosition == -1 ? 0 : iPosition; 695 } 696 697 /* UIMachineSettingsNetworkPage Stuff: */ 658 698 UIMachineSettingsNetworkPage::UIMachineSettingsNetworkPage() 659 699 : m_pValidator(0) … … 673 713 for (ulong uSlot = 0; uSlot < uCount; ++uSlot) 674 714 { 675 /* Creating adapter page: */ 676 UIMachineSettingsNetwork *pPage = new UIMachineSettingsNetwork(this); 677 m_pTwAdapters->addTab(pPage, pPage->pageTitle()); 678 } 679 } 680 681 QStringList UIMachineSettingsNetworkPage::brgList(bool fRefresh) 682 { 683 if (fRefresh) 684 { 685 /* Load & filter interface list: */ 686 m_brgList.clear(); 687 CHostNetworkInterfaceVector interfaces = vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces(); 688 for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin(); 689 it != interfaces.end(); ++it) 690 { 691 if (it->GetInterfaceType() == KHostNetworkInterfaceType_Bridged) 692 m_brgList << it->GetName(); 693 } 694 } 695 696 return m_brgList; 697 } 698 699 QStringList UIMachineSettingsNetworkPage::intList(bool fRefresh) 700 { 701 if (fRefresh) 702 { 703 /* Load total network list of all VMs: */ 704 m_intList.clear(); 705 CVirtualBox vbox = vboxGlobal().virtualBox(); 706 ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetMaxNetworkAdapters(KChipsetType_PIIX3)); 707 CMachineVector vec = vbox.GetMachines(); 708 for (CMachineVector::ConstIterator m = vec.begin(); m != vec.end(); ++m) 709 { 710 if (m->GetAccessible()) 711 { 712 for (ulong slot = 0; slot < count; ++slot) 713 { 714 QString strName = m->GetNetworkAdapter(slot).GetInternalNetwork(); 715 if (!strName.isEmpty() && !m_intList.contains(strName)) 716 m_intList << strName; 717 } 718 } 719 } 720 } 721 722 return m_intList; 723 } 724 725 QStringList UIMachineSettingsNetworkPage::fullIntList(bool fRefresh) 726 { 727 QStringList list(intList(fRefresh)); 728 /* Append network list with names from all the pages: */ 729 for (int index = 0; index < m_pTwAdapters->count(); ++index) 730 { 731 UIMachineSettingsNetwork *pPage = 732 qobject_cast <UIMachineSettingsNetwork*>(m_pTwAdapters->widget(index)); 733 if (pPage) 734 { 735 QString strName = pPage->alternativeName(KNetworkAttachmentType_Internal); 736 if (!strName.isEmpty() && !list.contains(strName)) 737 list << strName; 738 } 739 } 740 return list; 741 } 742 743 QStringList UIMachineSettingsNetworkPage::hoiList(bool fRefresh) 744 { 745 if (fRefresh) 746 { 747 /* Load & filter interface list: */ 748 m_hoiList.clear(); 749 CHostNetworkInterfaceVector interfaces = vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces(); 750 for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin(); 751 it != interfaces.end(); ++it) 752 { 753 if (it->GetInterfaceType() == KHostNetworkInterfaceType_HostOnly) 754 m_hoiList << it->GetName(); 755 } 756 } 757 758 return m_hoiList; 715 /* Creating adapter tab: */ 716 UIMachineSettingsNetwork *pTab = new UIMachineSettingsNetwork(this); 717 m_pTwAdapters->addTab(pTab, pTab->tabTitle()); 718 } 759 719 } 760 720 … … 769 729 m_cache.clear(); 770 730 771 /* Cache names lists: */ 772 brgList(true); 773 intList(true); 774 hoiList(true); 731 /* Cache name lists: */ 732 refreshBridgedAdapterList(); 733 refreshInternalNetworkList(true); 734 refreshHostInterfaceList(); 735 refreshGenericDriverList(true); 775 736 776 737 /* For each network adapter: */ … … 788 749 adapterData.m_fAdapterEnabled = adapter.GetEnabled(); 789 750 adapterData.m_attachmentType = adapter.GetAttachmentType(); 790 791 adapterData.m_strBridgedAdapterName = adapter.GetBridgedInterface(); 792 if (adapterData.m_strBridgedAdapterName.isEmpty()) 793 adapterData.m_strBridgedAdapterName = QString(); 794 795 adapterData.m_strInternalNetworkName = adapter.GetInternalNetwork(); 796 if (adapterData.m_strInternalNetworkName.isEmpty()) 797 adapterData.m_strInternalNetworkName = QString(); 798 799 adapterData.m_strHostInterfaceName = adapter.GetHostOnlyInterface(); 800 if (adapterData.m_strHostInterfaceName.isEmpty()) 801 adapterData.m_strHostInterfaceName = QString(); 802 803 adapterData.m_strGenericDriver = adapter.GetGenericDriver(); 804 if (adapterData.m_strGenericDriver.isEmpty()) 805 adapterData.m_strGenericDriver = QString(); 751 adapterData.m_strBridgedAdapterName = wipedOutString(adapter.GetBridgedInterface()); 752 adapterData.m_strInternalNetworkName = wipedOutString(adapter.GetInternalNetwork()); 753 adapterData.m_strHostInterfaceName = wipedOutString(adapter.GetHostOnlyInterface()); 754 adapterData.m_strGenericDriverName = wipedOutString(adapter.GetGenericDriver()); 806 755 807 756 /* Gather advanced options: */ … … 848 797 { 849 798 /* Get adapter page: */ 850 UIMachineSettingsNetwork *p Page= qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));799 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot)); 851 800 852 801 /* Load adapter data to page: */ 853 p Page->fetchAdapterCache(m_cache.child(iSlot));802 pTab->fetchAdapterCache(m_cache.child(iSlot)); 854 803 855 804 /* Setup page validation: */ 856 p Page->setValidator(m_pValidator);805 pTab->setValidator(m_pValidator); 857 806 858 807 /* Setup tab order: */ 859 pLastFocusWidget = p Page->setOrderAfter(pLastFocusWidget);808 pLastFocusWidget = pTab->setOrderAfter(pLastFocusWidget); 860 809 } 861 810 … … 879 828 { 880 829 /* Get adapter page: */ 881 UIMachineSettingsNetwork *p Page= qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));830 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot)); 882 831 883 832 /* Gather & cache adapter data: */ 884 p Page->uploadAdapterCache(m_cache.child(iSlot));833 pTab->uploadAdapterCache(m_cache.child(iSlot)); 885 834 } 886 835 } … … 933 882 break; 934 883 case KNetworkAttachmentType_Generic: 935 adapter.SetGenericDriver(adapterData.m_strGenericDriver );884 adapter.SetGenericDriver(adapterData.m_strGenericDriverName); 936 885 updateGenericProperties(adapter, adapterData.m_strGenericProperties); 937 886 break; … … 977 926 for (int i = 0; i < m_pTwAdapters->count(); ++i) 978 927 { 979 UIMachineSettingsNetwork *p Page= qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(i));980 Assert(p Page);981 fValid = p Page->revalidate(strWarning, strTitle);928 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(i)); 929 Assert(pTab); 930 fValid = pTab->revalidate(strWarning, strTitle); 982 931 if (!fValid) 983 932 break; … … 991 940 for (int i = 0; i < m_pTwAdapters->count(); ++ i) 992 941 { 993 UIMachineSettingsNetwork *pPage = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(i)); 994 Assert(pPage); 995 m_pTwAdapters->setTabText(i, pPage->pageTitle()); 996 } 997 } 998 999 void UIMachineSettingsNetworkPage::updatePages() 1000 { 1001 for (int i = 0; i < m_pTwAdapters->count(); ++ i) 1002 { 1003 /* Get the iterated page: */ 1004 UIMachineSettingsNetwork *pPage = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(i)); 1005 Assert(pPage); 1006 1007 /* Update the page if the attachment type is 'internal network' */ 1008 if (pPage->attachmentType() == KNetworkAttachmentType_Internal) 1009 QTimer::singleShot(0, pPage, SLOT(sltUpdateAttachmentAlternative())); 942 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(i)); 943 Assert(pTab); 944 m_pTwAdapters->setTabText(i, pTab->tabTitle()); 945 } 946 } 947 948 void UIMachineSettingsNetworkPage::sltHandleUpdatedTab() 949 { 950 /* Determine the sender: */ 951 UIMachineSettingsNetwork *pSender = qobject_cast<UIMachineSettingsNetwork*>(sender()); 952 AssertMsg(pSender, ("This slot should be called only through signal<->slot mechanism from one of UIMachineSettingsNetwork tabs!\n")); 953 954 /* Determine sender's attachment type: */ 955 KNetworkAttachmentType senderAttachmentType = pSender->attachmentType(); 956 switch (senderAttachmentType) 957 { 958 case KNetworkAttachmentType_Internal: 959 { 960 refreshInternalNetworkList(); 961 break; 962 } 963 case KNetworkAttachmentType_Generic: 964 { 965 refreshGenericDriverList(); 966 break; 967 } 968 default: 969 break; 970 } 971 972 /* Update all the tabs except the sender: */ 973 for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot) 974 { 975 /* Get the iterated tab: */ 976 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot)); 977 AssertMsg(pTab, ("All the tabs of m_pTwAdapters should be of the UIMachineSettingsNetwork type!\n")); 978 979 /* Update all the tabs (except sender) with the same attachment type as sender have: */ 980 if (pTab != pSender && pTab->attachmentType() == senderAttachmentType) 981 pTab->reloadAlternative(); 1010 982 } 1011 983 } … … 1022 994 pTab->polishTab(); 1023 995 } 996 } 997 998 void UIMachineSettingsNetworkPage::refreshBridgedAdapterList() 999 { 1000 /* Reload bridged interface list: */ 1001 m_bridgedAdapterList.clear(); 1002 const CHostNetworkInterfaceVector &ifaces = vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces(); 1003 for (int i = 0; i < ifaces.size(); ++i) 1004 { 1005 const CHostNetworkInterface &iface = ifaces[i]; 1006 if (iface.GetInterfaceType() == KHostNetworkInterfaceType_Bridged && !m_bridgedAdapterList.contains(iface.GetName())) 1007 m_bridgedAdapterList << iface.GetName(); 1008 } 1009 } 1010 1011 void UIMachineSettingsNetworkPage::refreshInternalNetworkList(bool fFullRefresh /* = false */) 1012 { 1013 /* Reload internal network list: */ 1014 m_internalNetworkList.clear(); 1015 /* Get internal network names from other VMs: */ 1016 if (fFullRefresh) 1017 m_internalNetworkList << otherInternalNetworkList(); 1018 /* Append internal network list with names from all the tabs: */ 1019 for (int iTab = 0; iTab < m_pTwAdapters->count(); ++iTab) 1020 { 1021 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iTab)); 1022 if (pTab) 1023 { 1024 QString strName = pTab->alternativeName(KNetworkAttachmentType_Internal); 1025 if (!strName.isEmpty() && !m_internalNetworkList.contains(strName)) 1026 m_internalNetworkList << strName; 1027 } 1028 } 1029 } 1030 1031 void UIMachineSettingsNetworkPage::refreshHostInterfaceList() 1032 { 1033 /* Reload host-only interface list: */ 1034 m_hostInterfaceList.clear(); 1035 const CHostNetworkInterfaceVector &ifaces = vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces(); 1036 for (int i = 0; i < ifaces.size(); ++i) 1037 { 1038 const CHostNetworkInterface &iface = ifaces[i]; 1039 if (iface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly && !m_hostInterfaceList.contains(iface.GetName())) 1040 m_hostInterfaceList << iface.GetName(); 1041 } 1042 } 1043 1044 void UIMachineSettingsNetworkPage::refreshGenericDriverList(bool fFullRefresh /* = false */) 1045 { 1046 /* Load generic driver list: */ 1047 m_genericDriverList.clear(); 1048 /* Get generic driver names from other VMs: */ 1049 if (fFullRefresh) 1050 m_genericDriverList << otherGenericDriverList(); 1051 /* Append generic driver list with names from all the tabs: */ 1052 for (int iTab = 0; iTab < m_pTwAdapters->count(); ++iTab) 1053 { 1054 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iTab)); 1055 if (pTab) 1056 { 1057 QString strName = pTab->alternativeName(KNetworkAttachmentType_Generic); 1058 if (!strName.isEmpty() && !m_genericDriverList.contains(strName)) 1059 m_genericDriverList << strName; 1060 } 1061 } 1062 } 1063 1064 /* static */ 1065 QStringList UIMachineSettingsNetworkPage::otherInternalNetworkList() 1066 { 1067 /* Load total internal network list of all VMs: */ 1068 QStringList otherInternalNetworks; 1069 CVirtualBox vbox = vboxGlobal().virtualBox(); 1070 ulong uCount = qMin((ULONG) 4, vbox.GetSystemProperties().GetMaxNetworkAdapters(KChipsetType_PIIX3)); 1071 const CMachineVector &machines = vbox.GetMachines(); 1072 for (int i = 0; i < machines.size(); ++i) 1073 { 1074 const CMachine &machine = machines[i]; 1075 if (machine.GetAccessible()) 1076 { 1077 for (ulong uSlot = 0; uSlot < uCount; ++uSlot) 1078 { 1079 QString strName = machine.GetNetworkAdapter(uSlot).GetInternalNetwork(); 1080 if (!strName.isEmpty() && !otherInternalNetworks.contains(strName)) 1081 otherInternalNetworks << strName; 1082 } 1083 } 1084 } 1085 return otherInternalNetworks; 1086 } 1087 1088 /* static */ 1089 QStringList UIMachineSettingsNetworkPage::otherGenericDriverList() 1090 { 1091 /* Load total generic driver list of all VMs: */ 1092 QStringList otherGenericDrivers; 1093 CVirtualBox vbox = vboxGlobal().virtualBox(); 1094 ulong uCount = qMin((ULONG) 4, vbox.GetSystemProperties().GetMaxNetworkAdapters(KChipsetType_PIIX3)); 1095 const CMachineVector &machines = vbox.GetMachines(); 1096 for (int i = 0; i < machines.size(); ++i) 1097 { 1098 const CMachine &machine = machines[i]; 1099 if (machine.GetAccessible()) 1100 { 1101 for (ulong uSlot = 0; uSlot < uCount; ++uSlot) 1102 { 1103 QString strName = machine.GetNetworkAdapter(uSlot).GetGenericDriver(); 1104 if (!strName.isEmpty() && !otherGenericDrivers.contains(strName)) 1105 otherGenericDrivers << strName; 1106 } 1107 } 1108 } 1109 return otherGenericDrivers; 1024 1110 } 1025 1111 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.h
r37571 r37645 20 20 #define __UIMachineSettingsNetwork_h__ 21 21 22 /* Local includes */ 23 #include "COMDefs.h" 22 /* Local includes: */ 24 23 #include "UISettingsPage.h" 25 24 #include "UIMachineSettingsNetwork.gen.h" 26 25 #include "UIMachineSettingsPortForwardingDlg.h" 27 26 28 /* Forward declarations */27 /* Forward declarations: */ 29 28 class UIMachineSettingsNetworkPage; 30 29 class QITabWidget; … … 43 42 , m_strInternalNetworkName(QString()) 44 43 , m_strHostInterfaceName(QString()) 45 , m_strGenericDriver (QString())44 , m_strGenericDriverName(QString()) 46 45 , m_strGenericProperties(QString()) 47 46 , m_strMACAddress(QString()) … … 59 58 (m_strInternalNetworkName == other.m_strInternalNetworkName) && 60 59 (m_strHostInterfaceName == other.m_strHostInterfaceName) && 61 (m_strGenericDriver == other.m_strGenericDriver) &&60 (m_strGenericDriverName == other.m_strGenericDriverName) && 62 61 (m_strGenericProperties == other.m_strGenericProperties) && 63 62 (m_strMACAddress == other.m_strMACAddress) && … … 77 76 QString m_strInternalNetworkName; 78 77 QString m_strHostInterfaceName; 79 QString m_strGenericDriver ;78 QString m_strGenericDriverName; 80 79 QString m_strGenericProperties; 81 80 QString m_strMACAddress; … … 97 96 98 97 /* Machine settings / Network page / Adapter tab: */ 99 class UIMachineSettingsNetwork : public QIWithRetranslateUI<QWidget>, 100 public Ui::UIMachineSettingsNetwork 98 class UIMachineSettingsNetwork : public QIWithRetranslateUI<QWidget>, public Ui::UIMachineSettingsNetwork 101 99 { 102 100 Q_OBJECT; … … 104 102 public: 105 103 104 /* Constructor: */ 106 105 UIMachineSettingsNetwork(UIMachineSettingsNetworkPage *pParent); 107 106 108 void polishTab(); 109 107 /* Load / Save API: */ 110 108 void fetchAdapterCache(const UICacheSettingsMachineNetworkAdapter &adapterCache); 111 109 void uploadAdapterCache(UICacheSettingsMachineNetworkAdapter &adapterCache); 112 110 111 /* Validation stuff: */ 113 112 void setValidator(QIWidgetValidator *pValidator); 114 113 bool revalidate(QString &strWarning, QString &strTitle); 115 114 115 /* Navigation stuff: */ 116 116 QWidget* setOrderAfter(QWidget *pAfter); 117 117 118 QString pageTitle() const;119 118 /* Other public stuff: */ 119 QString tabTitle() const; 120 120 KNetworkAttachmentType attachmentType() const; 121 QString alternativeName(int type = -1) const; 121 QString alternativeName(int iType = -1) const; 122 void polishTab(); 123 void reloadAlternative(); 124 125 signals: 126 127 /* Signal to notify listeners about tab content changed: */ 128 void sigTabUpdated(); 122 129 123 130 protected: 124 131 125 void showEvent(QShowEvent *pEvent); 126 132 /* Translation stuff: */ 127 133 void retranslateUi(); 128 134 129 135 private slots: 130 136 131 void sltUpdateAttachmentAlternative(); 132 void sltUpdateAlternativeName(); 133 void sltToggleAdvanced(); 137 /* Different handlers: */ 138 void sltHandleAdapterActivityChange(); 139 void sltHandleAttachmentTypeChange(); 140 void sltHandleAlternativeNameChange(); 141 void sltHandleAdvancedButtonStateChange(); 134 142 void sltGenerateMac(); 135 143 void sltOpenPortForwardingDlg(); … … 137 145 private: 138 146 147 /* Helping stuff: */ 139 148 void populateComboboxes(); 140 149 void updateAlternativeList(); 150 void updateAlternativeName(); 151 152 /* Various static stuff: */ 153 static int position(QComboBox *pComboBox, int iData); 154 static int position(QComboBox *pComboBox, const QString &strText); 155 156 /* Parent page: */ 141 157 UIMachineSettingsNetworkPage *m_pParent; 158 159 /* Validator: */ 142 160 QIWidgetValidator *m_pValidator; 143 161 162 /* Other variables: */ 144 163 int m_iSlot; 145 QString m_strBrgName; 146 QString m_strIntName; 147 QString m_strHoiName; 148 QString m_strGenericDriver; 149 150 bool m_fPolished; 164 QString m_strBridgedAdapterName; 165 QString m_strInternalNetworkName; 166 QString m_strHostInterfaceName; 167 QString m_strGenericDriverName; 151 168 UIPortForwardingDataList m_portForwardingRules; 152 169 }; … … 159 176 public: 160 177 178 /* Constructor: */ 161 179 UIMachineSettingsNetworkPage(); 162 180 163 QStringList brgList(bool aRefresh = false); 164 QStringList intList(bool aRefresh = false); 165 QStringList fullIntList(bool aRefresh = false); 166 QStringList hoiList(bool aRefresh = false); 181 /* Bridged adapter list: */ 182 const QStringList& bridgedAdapterList() const { return m_bridgedAdapterList; } 183 /* Internal network list: */ 184 const QStringList& internalNetworkList() const { return m_internalNetworkList; } 185 /* Host-only interface list: */ 186 const QStringList& hostInterfaceList() const { return m_hostInterfaceList; } 187 /* Generic driver list: */ 188 const QStringList& genericDriverList() const { return m_genericDriverList; } 167 189 168 190 protected: … … 185 207 bool changed() const { return m_cache.wasChanged(); } 186 208 209 /* Validation stuff: */ 187 210 void setValidator(QIWidgetValidator *pValidator); 188 211 bool revalidate(QString &strWarning, QString &strTitle); 189 212 213 /* Translation stuff: */ 190 214 void retranslateUi(); 191 215 192 216 private slots: 193 217 194 void updatePages(); 218 /* Handles tab updates: */ 219 void sltHandleUpdatedTab(); 195 220 196 221 private: 197 222 223 /* Private helpers: */ 198 224 void polishPage(); 199 225 void refreshBridgedAdapterList(); 226 void refreshInternalNetworkList(bool fFullRefresh = false); 227 void refreshHostInterfaceList(); 228 void refreshGenericDriverList(bool fFullRefresh = false); 229 230 /* Various static stuff: */ 231 static QStringList otherInternalNetworkList(); 232 static QStringList otherGenericDriverList(); 200 233 static QString summarizeGenericProperties(const CNetworkAdapter &adapter); 201 234 static void updateGenericProperties(CNetworkAdapter &adapter, const QString &strPropText); 202 235 236 /* Validator: */ 203 237 QIWidgetValidator *m_pValidator; 238 239 /* Tab holder: */ 204 240 QITabWidget *m_pTwAdapters; 205 241 206 QStringList m_brgList; 207 QStringList m_intList; 208 QStringList m_hoiList; 242 /* Alternative-name lists: */ 243 QStringList m_bridgedAdapterList; 244 QStringList m_internalNetworkList; 245 QStringList m_hostInterfaceList; 246 QStringList m_genericDriverList; 209 247 210 248 /* Cache: */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.ui
r37592 r37645 19 19 <x>0</x> 20 20 <y>0</y> 21 <width>43 1</width>22 <height>2 48</height>21 <width>430</width> 22 <height>250</height> 23 23 </rect> 24 24 </property> 25 <layout class="QGridLayout" name=" VBoxVMSettingsNetworkGridLayout">25 <layout class="QGridLayout" name="m_pMainLayout"> 26 26 <item row="0" column="0" colspan="2"> 27 <widget class="QCheckBox" name="m CbEnableAdapter">27 <widget class="QCheckBox" name="m_pEnableAdapterCheckBox"> 28 28 <property name="whatsThis"> 29 29 <string>When checked, plugs this virtual network adapter into the virtual machine.</string> … … 31 31 <property name="text"> 32 32 <string>&Enable Network Adapter</string> 33 </property>34 <property name="checked">35 <bool>true</bool>36 33 </property> 37 34 </widget> … … 54 51 </item> 55 52 <item row="1" column="1"> 56 <widget class="QWidget" name="m_p NetworkChild" native="1">57 <layout class="QGridLayout" name="m_p NetworkChildGridLayout">53 <widget class="QWidget" name="m_pAdapterOptionsContainer" native="1"> 54 <layout class="QGridLayout" name="m_pAdapterOptionsLayout"> 58 55 <property name="margin"> 59 56 <number>0</number> … … 68 65 </property> 69 66 <property name="buddy"> 70 <cstring>m_pAttachmentTypeCombo </cstring>67 <cstring>m_pAttachmentTypeComboBox</cstring> 71 68 </property> 72 69 </widget> 73 70 </item> 74 71 <item row="0" column="1"> 75 <widget class="QComboBox" name="m_pAttachmentTypeCombo ">72 <widget class="QComboBox" name="m_pAttachmentTypeComboBox"> 76 73 <property name="sizePolicy"> 77 74 <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> … … 306 303 <include location="../VirtualBox1.qrc"/> 307 304 </resources> 308 <connections> 309 <connection> 310 <sender>mCbEnableAdapter</sender> 311 <signal>toggled(bool)</signal> 312 <receiver>m_pNetworkChild</receiver> 313 <slot>setEnabled(bool)</slot> 314 <hints> 315 <hint type="sourcelabel"> 316 <x>184</x> 317 <y>28</y> 318 </hint> 319 <hint type="destinationlabel"> 320 <x>196</x> 321 <y>111</y> 322 </hint> 323 </hints> 324 </connection> 325 </connections> 305 <connections/> 326 306 </ui>
Note:
See TracChangeset
for help on using the changeset viewer.