- Timestamp:
- Apr 8, 2022 10:22:37 AM (3 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r94518 r94527 911 911 src/settings/editors/UIMachineDisplayScreenFeaturesEditor.h \ 912 912 src/settings/editors/UIMachineDescriptionEditor.h \ 913 src/settings/editors/UIMachineNetworkFeaturesEditor.h \ 913 914 src/settings/editors/UIMaximumGuestScreenSizeEditor.h \ 914 915 src/settings/editors/UIMiniToolbarSettingsEditor.h \ … … 1477 1478 src/settings/editors/UIMachineDisplayScreenFeaturesEditor.cpp \ 1478 1479 src/settings/editors/UIMachineDescriptionEditor.cpp \ 1480 src/settings/editors/UIMachineNetworkFeaturesEditor.cpp \ 1479 1481 src/settings/editors/UIMaximumGuestScreenSizeEditor.cpp \ 1480 1482 src/settings/editors/UIMiniToolbarSettingsEditor.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIMachineNetworkFeaturesEditor.cpp
r94526 r94527 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIMachine DescriptionEditor class implementation.3 * VBox Qt GUI - UIMachineNetworkFeaturesEditor class implementation. 4 4 */ 5 5 … … 17 17 18 18 /* Qt includes: */ 19 #include <QCheckBox> 20 #include <QComboBox> 21 #include <QGridLayout> 22 #include <QLabel> 23 #include <QPushButton> 19 24 #include <QTextEdit> 20 25 #include <QVBoxLayout> 21 26 22 27 /* GUI includes: */ 23 #include "UIMachineDescriptionEditor.h" 24 25 26 UIMachineDescriptionEditor::UIMachineDescriptionEditor(QWidget *pParent /* = 0 */) 28 #include "QIArrowButtonSwitch.h" 29 #include "QILineEdit.h" 30 #include "QIToolButton.h" 31 #include "UICommon.h" 32 #include "UIConverter.h" 33 #include "UIIconPool.h" 34 #include "UIMachineNetworkFeaturesEditor.h" 35 36 /* COM includes: */ 37 #include "CSystemProperties.h" 38 39 40 UIMachineNetworkFeaturesEditor::UIMachineNetworkFeaturesEditor(QWidget *pParent /* = 0 */) 27 41 : QIWithRetranslateUI<QWidget>(pParent) 28 , m_pTextEdit(0) 42 , m_fAdvancedButtonExpanded(false) 43 , m_enmAdapterType(KNetworkAdapterType_Null) 44 , m_enmPromiscuousMode(KNetworkAdapterPromiscModePolicy_Max) 45 , m_fCableConnected(false) 46 , m_pButtonAdvanced(0) 47 , m_pWidgetSettings(0) 48 , m_pLayoutSettings(0) 49 , m_pLabelAdapterType(0) 50 , m_pComboAdapterType(0) 51 , m_pLabelPromiscuousMode(0) 52 , m_pComboPromiscuousMode(0) 53 , m_pLabelMAC(0) 54 , m_pEditorMAC(0) 55 , m_pButtonMAC(0) 56 , m_pLabelGenericProperties(0) 57 , m_pEditorGenericProperties(0) 58 , m_pCheckBoxCableConnected(0) 59 , m_pButtonPortForwarding(0) 29 60 { 30 61 prepare(); 31 62 } 32 63 33 void UIMachineDescriptionEditor::setValue(const QString &strValue) 34 { 35 /* Update cached value and 36 * text-edit if value has changed: */ 37 if (m_strValue != strValue) 38 { 39 m_strValue = strValue; 40 if (m_pTextEdit) 41 m_pTextEdit->setPlainText(strValue); 42 } 43 } 44 45 QString UIMachineDescriptionEditor::value() const 46 { 47 return m_pTextEdit ? m_pTextEdit->toPlainText() : m_strValue; 48 } 49 50 void UIMachineDescriptionEditor::retranslateUi() 51 { 52 if (m_pTextEdit) 53 m_pTextEdit->setToolTip(tr("Holds the description of the virtual machine. The description field is useful " 54 "for commenting on configuration details of the installed guest OS.")); 55 } 56 57 void UIMachineDescriptionEditor::prepare() 64 void UIMachineNetworkFeaturesEditor::setAdvancedButtonExpanded(bool fExpanded) 65 { 66 if (m_fAdvancedButtonExpanded != fExpanded) 67 { 68 m_fAdvancedButtonExpanded = fExpanded; 69 if (m_pButtonAdvanced) 70 { 71 m_pButtonAdvanced->setExpanded(m_fAdvancedButtonExpanded); 72 sltHandleAdvancedButtonStateChange(); 73 } 74 } 75 } 76 77 bool UIMachineNetworkFeaturesEditor::advancedButtonExpanded() const 78 { 79 return m_pButtonAdvanced ? m_pButtonAdvanced->isExpanded() : m_fAdvancedButtonExpanded; 80 } 81 82 void UIMachineNetworkFeaturesEditor::setAdapterType(const KNetworkAdapterType &enmType) 83 { 84 if (m_enmAdapterType != enmType) 85 { 86 m_enmAdapterType = enmType; 87 repopulateAdapterTypeCombo(); 88 } 89 } 90 91 KNetworkAdapterType UIMachineNetworkFeaturesEditor::adapterType() const 92 { 93 return m_pComboAdapterType ? m_pComboAdapterType->currentData().value<KNetworkAdapterType>() : m_enmAdapterType; 94 } 95 96 void UIMachineNetworkFeaturesEditor::setPromiscuousMode(const KNetworkAdapterPromiscModePolicy &enmMode) 97 { 98 if (m_enmPromiscuousMode != enmMode) 99 { 100 m_enmPromiscuousMode = enmMode; 101 repopulatePromiscuousModeCombo(); 102 } 103 } 104 105 KNetworkAdapterPromiscModePolicy UIMachineNetworkFeaturesEditor::promiscuousMode() const 106 { 107 return m_pComboPromiscuousMode ? m_pComboPromiscuousMode->currentData().value<KNetworkAdapterPromiscModePolicy>() : m_enmPromiscuousMode; 108 } 109 110 void UIMachineNetworkFeaturesEditor::setMACAddress(const QString &strAddress) 111 { 112 if (m_strMACAddress != strAddress) 113 { 114 m_strMACAddress = strAddress; 115 if (m_pEditorMAC) 116 m_pEditorMAC->setText(m_strMACAddress); 117 } 118 } 119 120 QString UIMachineNetworkFeaturesEditor::macAddress() const 121 { 122 return m_pEditorMAC ? m_pEditorMAC->text() : m_strMACAddress; 123 } 124 125 void UIMachineNetworkFeaturesEditor::setGenericProperties(const QString &strProperties) 126 { 127 if (m_strGenericProperties != strProperties) 128 { 129 m_strGenericProperties = strProperties; 130 if (m_pEditorGenericProperties) 131 m_pEditorGenericProperties->setPlainText(m_strGenericProperties); 132 } 133 } 134 135 QString UIMachineNetworkFeaturesEditor::genericProperties() const 136 { 137 return m_pEditorGenericProperties ? m_pEditorGenericProperties->toPlainText() : m_strGenericProperties; 138 } 139 140 void UIMachineNetworkFeaturesEditor::setCableConnected(bool fConnected) 141 { 142 if (m_fCableConnected != fConnected) 143 { 144 m_fCableConnected = fConnected; 145 if (m_pCheckBoxCableConnected) 146 m_pCheckBoxCableConnected->setChecked(m_fCableConnected); 147 } 148 } 149 150 bool UIMachineNetworkFeaturesEditor::cableConnected() const 151 { 152 return m_pCheckBoxCableConnected ? m_pCheckBoxCableConnected->isChecked() : m_fCableConnected; 153 } 154 155 void UIMachineNetworkFeaturesEditor::setPortForwardingRules(const UIPortForwardingDataList &rules) 156 { 157 if (m_portForwardingRules != rules) 158 m_portForwardingRules = rules; 159 } 160 161 UIPortForwardingDataList UIMachineNetworkFeaturesEditor::portForwardingRules() const 162 { 163 return m_portForwardingRules; 164 } 165 166 void UIMachineNetworkFeaturesEditor::setAdvancedOptionsAvailable(bool fAvailable) 167 { 168 m_pButtonAdvanced->setEnabled(fAvailable); 169 } 170 171 void UIMachineNetworkFeaturesEditor::setAdapterOptionsAvailable(bool fAvailable) 172 { 173 m_pLabelAdapterType->setEnabled(fAvailable); 174 m_pComboAdapterType->setEnabled(fAvailable); 175 } 176 177 void UIMachineNetworkFeaturesEditor::setPromiscuousOptionsAvailable(bool fAvailable) 178 { 179 m_pLabelPromiscuousMode->setEnabled(fAvailable); 180 m_pComboPromiscuousMode->setEnabled(fAvailable); 181 } 182 183 void UIMachineNetworkFeaturesEditor::setMACOptionsAvailable(bool fAvailable) 184 { 185 m_pLabelMAC->setEnabled(fAvailable); 186 m_pEditorMAC->setEnabled(fAvailable); 187 m_pButtonMAC->setEnabled(fAvailable); 188 } 189 190 void UIMachineNetworkFeaturesEditor::setGenericPropertiesAvailable(bool fAvailable) 191 { 192 m_pLabelGenericProperties->setVisible(fAvailable); 193 m_pEditorGenericProperties->setVisible(fAvailable); 194 } 195 196 void UIMachineNetworkFeaturesEditor::setCableOptionsAvailable(bool fAvailable) 197 { 198 m_pCheckBoxCableConnected->setEnabled(fAvailable); 199 } 200 201 void UIMachineNetworkFeaturesEditor::setForwardingOptionsAvailable(bool fAvailable) 202 { 203 m_pButtonPortForwarding->setEnabled(fAvailable); 204 } 205 206 int UIMachineNetworkFeaturesEditor::minimumLabelHorizontalHint() const 207 { 208 int iMinimumLabelHorizontalHint = 0; 209 if (m_pLabelAdapterType) 210 iMinimumLabelHorizontalHint = qMax(iMinimumLabelHorizontalHint, m_pLabelAdapterType->minimumSizeHint().width()); 211 if (m_pLabelPromiscuousMode) 212 iMinimumLabelHorizontalHint = qMax(iMinimumLabelHorizontalHint, m_pLabelPromiscuousMode->minimumSizeHint().width()); 213 if (m_pLabelMAC) 214 iMinimumLabelHorizontalHint = qMax(iMinimumLabelHorizontalHint, m_pLabelMAC->minimumSizeHint().width()); 215 if (m_pLabelGenericProperties) 216 iMinimumLabelHorizontalHint = qMax(iMinimumLabelHorizontalHint, m_pLabelGenericProperties->minimumSizeHint().width()); 217 return iMinimumLabelHorizontalHint; 218 } 219 220 void UIMachineNetworkFeaturesEditor::setMinimumLayoutIndent(int iIndent) 221 { 222 if (m_pLayoutSettings) 223 m_pLayoutSettings->setColumnMinimumWidth(0, iIndent); 224 } 225 226 void UIMachineNetworkFeaturesEditor::generateMac() 227 { 228 setMACAddress(uiCommon().host().GenerateMACAddress()); 229 } 230 231 void UIMachineNetworkFeaturesEditor::retranslateUi() 232 { 233 if (m_pButtonAdvanced) 234 { 235 m_pButtonAdvanced->setText(tr("A&dvanced")); 236 m_pButtonAdvanced->setToolTip(tr("Shows additional network adapter options.")); 237 } 238 239 if (m_pLabelAdapterType) 240 m_pLabelAdapterType->setText(tr("Adapter &Type:")); 241 if (m_pComboAdapterType) 242 { 243 for (int i = 0; i < m_pComboAdapterType->count(); ++i) 244 { 245 const KNetworkAdapterType enmType = m_pComboAdapterType->itemData(i).value<KNetworkAdapterType>(); 246 m_pComboAdapterType->setItemText(i, gpConverter->toString(enmType)); 247 } 248 m_pComboAdapterType->setToolTip(tr("Selects the type of the virtual network adapter. Depending on this value, VirtualBox " 249 "will provide different network hardware to the virtual machine.")); 250 } 251 252 if (m_pLabelPromiscuousMode) 253 m_pLabelPromiscuousMode->setText(tr("&Promiscuous Mode:")); 254 if (m_pComboPromiscuousMode) 255 { 256 for (int i = 0; i < m_pComboPromiscuousMode->count(); ++i) 257 { 258 const KNetworkAdapterPromiscModePolicy enmType = m_pComboPromiscuousMode->itemData(i).value<KNetworkAdapterPromiscModePolicy>(); 259 m_pComboPromiscuousMode->setItemText(i, gpConverter->toString(enmType)); 260 } 261 m_pComboPromiscuousMode->setToolTip(tr("Selects the promiscuous mode policy of the network adapter when attached to an " 262 "internal network, host only network or a bridge.")); 263 } 264 265 if (m_pLabelMAC) 266 m_pLabelMAC->setText(tr("&MAC Address:")); 267 if (m_pEditorMAC) 268 m_pEditorMAC->setToolTip(tr("Holds the MAC address of this adapter. It contains exactly 12 characters chosen from " 269 "{0-9,A-F}. Note that the second character must be an even digit.")); 270 if (m_pButtonMAC) 271 m_pButtonMAC->setToolTip(tr("Generates a new random MAC address.")); 272 273 if (m_pLabelGenericProperties) 274 m_pLabelGenericProperties->setText(tr("Generic Properties:")); 275 if (m_pEditorGenericProperties) 276 m_pEditorGenericProperties->setToolTip(tr("Holds the configuration settings for the network attachment driver. The " 277 "settings should be of the form <b>name=value</b> and will depend on the " 278 "driver. Use <b>shift-enter</b> to add a new entry.")); 279 280 if (m_pCheckBoxCableConnected) 281 { 282 m_pCheckBoxCableConnected->setText(tr("&Cable Connected")); 283 m_pCheckBoxCableConnected->setToolTip(tr("When checked, the virtual network cable is plugged in.")); 284 } 285 286 if (m_pButtonPortForwarding) 287 { 288 m_pButtonPortForwarding->setText(tr("&Port Forwarding")); 289 m_pButtonPortForwarding->setToolTip(tr("Displays a window to configure port forwarding rules.")); 290 } 291 } 292 293 void UIMachineNetworkFeaturesEditor::sltHandleAdvancedButtonStateChange() 294 { 295 /* What's the state? */ 296 const bool fExpanded = m_pButtonAdvanced->isExpanded(); 297 /* Update widget visibility: */ 298 m_pWidgetSettings->setVisible(fExpanded); 299 /* Notify listeners about the button state change: */ 300 emit sigNotifyAdvancedButtonStateChange(fExpanded); 301 } 302 303 void UIMachineNetworkFeaturesEditor::sltOpenPortForwardingDlg() 304 { 305 UIMachineSettingsPortForwardingDlg dlg(this, m_portForwardingRules); 306 if (dlg.exec() == QDialog::Accepted) 307 m_portForwardingRules = dlg.rules(); 308 } 309 310 void UIMachineNetworkFeaturesEditor::prepare() 58 311 { 59 312 /* Prepare main layout: */ … … 63 316 pLayout->setContentsMargins(0, 0, 0, 0); 64 317 65 /* Prepare text-edit: */66 m_p TextEdit = new QTextEdit(this);67 if (m_p TextEdit)318 /* Prepare advanced arrow button: */ 319 m_pButtonAdvanced = new QIArrowButtonSwitch(this); 320 if (m_pButtonAdvanced) 68 321 { 69 setFocusProxy(m_pTextEdit);70 m_pTextEdit->setAcceptRichText(false);71 #ifdef VBOX_WS_MAC 72 m_p TextEdit->setMinimumHeight(150);73 #endif 74 75 pLayout->addWidget(m_p TextEdit);322 const QStyle *pStyle = QApplication::style(); 323 const int iIconMetric = (int)(pStyle->pixelMetric(QStyle::PM_SmallIconSize) * .625); 324 m_pButtonAdvanced->setIconSize(QSize(iIconMetric, iIconMetric)); 325 m_pButtonAdvanced->setIcons(UIIconPool::iconSet(":/arrow_right_10px.png"), 326 UIIconPool::iconSet(":/arrow_down_10px.png")); 327 328 pLayout->addWidget(m_pButtonAdvanced); 76 329 } 77 } 330 331 /* Prepare advanced settings widget: */ 332 m_pWidgetSettings = new QWidget(this); 333 if (m_pWidgetSettings) 334 { 335 /* Prepare advanced settings layout: */ 336 m_pLayoutSettings = new QGridLayout(m_pWidgetSettings); 337 if (m_pLayoutSettings) 338 { 339 m_pLayoutSettings->setContentsMargins(0, 0, 0, 0); 340 m_pLayoutSettings->setColumnStretch(2, 1); 341 342 /* Prepare adapter type label: */ 343 m_pLabelAdapterType = new QLabel(m_pWidgetSettings); 344 if (m_pLabelAdapterType) 345 { 346 m_pLabelAdapterType->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 347 m_pLayoutSettings->addWidget(m_pLabelAdapterType, 0, 0); 348 } 349 /* Prepare adapter type combo: */ 350 m_pComboAdapterType = new QComboBox(m_pWidgetSettings); 351 if (m_pComboAdapterType) 352 { 353 if (m_pLabelAdapterType) 354 m_pLabelAdapterType->setBuddy(m_pComboAdapterType); 355 m_pLayoutSettings->addWidget(m_pComboAdapterType, 0, 1, 1, 3); 356 } 357 358 /* Prepare promiscuous mode label: */ 359 m_pLabelPromiscuousMode = new QLabel(m_pWidgetSettings); 360 if (m_pLabelPromiscuousMode) 361 { 362 m_pLabelPromiscuousMode->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 363 m_pLayoutSettings->addWidget(m_pLabelPromiscuousMode, 1, 0); 364 } 365 /* Prepare promiscuous mode combo: */ 366 m_pComboPromiscuousMode = new QComboBox(m_pWidgetSettings); 367 if (m_pComboPromiscuousMode) 368 { 369 if (m_pLabelPromiscuousMode) 370 m_pLabelPromiscuousMode->setBuddy(m_pComboPromiscuousMode); 371 m_pLayoutSettings->addWidget(m_pComboPromiscuousMode, 1, 1, 1, 3); 372 } 373 374 /* Prepare MAC label: */ 375 m_pLabelMAC = new QLabel(m_pWidgetSettings); 376 if (m_pLabelMAC) 377 { 378 m_pLabelMAC->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 379 m_pLayoutSettings->addWidget(m_pLabelMAC, 2, 0); 380 } 381 /* Prepare MAC editor: */ 382 m_pEditorMAC = new QILineEdit(m_pWidgetSettings); 383 if (m_pEditorMAC) 384 { 385 if (m_pLabelMAC) 386 m_pLabelMAC->setBuddy(m_pEditorMAC); 387 m_pEditorMAC->setAllowToCopyContentsWhenDisabled(true); 388 m_pEditorMAC->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9A-Fa-f]{12}"), this)); 389 m_pEditorMAC->setMinimumWidthByText(QString().fill('0', 12)); 390 391 m_pLayoutSettings->addWidget(m_pEditorMAC, 2, 1, 1, 2); 392 } 393 /* Prepare MAC button: */ 394 m_pButtonMAC = new QIToolButton(m_pWidgetSettings); 395 if (m_pButtonMAC) 396 { 397 m_pButtonMAC->setIcon(UIIconPool::iconSet(":/refresh_16px.png")); 398 m_pLayoutSettings->addWidget(m_pButtonMAC, 2, 3); 399 } 400 401 /* Prepare MAC label: */ 402 m_pLabelGenericProperties = new QLabel(m_pWidgetSettings); 403 if (m_pLabelGenericProperties) 404 { 405 m_pLabelGenericProperties->setAlignment(Qt::AlignRight | Qt::AlignTop); 406 m_pLayoutSettings->addWidget(m_pLabelGenericProperties, 3, 0); 407 } 408 /* Prepare MAC editor: */ 409 m_pEditorGenericProperties = new QTextEdit(m_pWidgetSettings); 410 if (m_pEditorGenericProperties) 411 m_pLayoutSettings->addWidget(m_pEditorGenericProperties, 3, 1, 1, 3); 412 413 /* Prepare cable connected check-box: */ 414 m_pCheckBoxCableConnected = new QCheckBox(m_pWidgetSettings); 415 if (m_pCheckBoxCableConnected) 416 m_pLayoutSettings->addWidget(m_pCheckBoxCableConnected, 4, 1, 1, 2); 417 418 /* Prepare port forwarding button: */ 419 m_pButtonPortForwarding = new QPushButton(m_pWidgetSettings); 420 if (m_pButtonPortForwarding) 421 m_pLayoutSettings->addWidget(m_pButtonPortForwarding, 5, 1); 422 } 423 424 pLayout->addWidget(m_pWidgetSettings); 425 } 426 } 427 428 /* Configure connections: */ 429 if (m_pButtonAdvanced) 430 connect(m_pButtonAdvanced, &QIArrowButtonSwitch::sigClicked, 431 this, &UIMachineNetworkFeaturesEditor::sltHandleAdvancedButtonStateChange); 432 if (m_pEditorMAC) 433 connect(m_pEditorMAC, &QILineEdit::textChanged, 434 this, &UIMachineNetworkFeaturesEditor::sigMACAddressChanged); 435 if (m_pButtonMAC) 436 connect(m_pButtonMAC, &QIToolButton::clicked, 437 this, &UIMachineNetworkFeaturesEditor::generateMac); 438 if (m_pButtonPortForwarding) 439 connect(m_pButtonPortForwarding, &QPushButton::clicked, 440 this, &UIMachineNetworkFeaturesEditor::sltOpenPortForwardingDlg); 441 442 /* Update widget availability: */ 443 m_pWidgetSettings->setVisible(m_pButtonAdvanced->isExpanded()); 78 444 79 445 /* Apply language settings: */ 80 446 retranslateUi(); 81 447 } 448 449 void UIMachineNetworkFeaturesEditor::repopulateAdapterTypeCombo() 450 { 451 if (m_pComboAdapterType) 452 { 453 /* Clear combo first of all: */ 454 m_pComboAdapterType->clear(); 455 456 /* Load currently supported types: */ 457 CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties(); 458 QVector<KNetworkAdapterType> supportedTypes = comProperties.GetSupportedNetworkAdapterTypes(); 459 460 /* Make sure requested value if sane is present as well: */ 461 if ( m_enmAdapterType != KNetworkAdapterType_Null 462 && !supportedTypes.contains(m_enmAdapterType)) 463 supportedTypes.prepend(m_enmAdapterType); 464 465 /* Update combo with all the supported values: */ 466 foreach (const KNetworkAdapterType &enmType, supportedTypes) 467 m_pComboAdapterType->addItem(QString(), QVariant::fromValue(enmType)); 468 469 /* Look for proper index to choose: */ 470 const int iIndex = m_pComboAdapterType->findData(QVariant::fromValue(m_enmAdapterType)); 471 if (iIndex != -1) 472 m_pComboAdapterType->setCurrentIndex(iIndex); 473 474 /* Retranslate finally: */ 475 retranslateUi(); 476 } 477 } 478 479 void UIMachineNetworkFeaturesEditor::repopulatePromiscuousModeCombo() 480 { 481 if (m_pComboPromiscuousMode) 482 { 483 /* Clear combo first of all: */ 484 m_pComboPromiscuousMode->clear(); 485 486 /* Populate currently supported types: */ 487 QVector<KNetworkAdapterPromiscModePolicy> supportedTypes = 488 QVector<KNetworkAdapterPromiscModePolicy>() << KNetworkAdapterPromiscModePolicy_Deny 489 << KNetworkAdapterPromiscModePolicy_AllowNetwork 490 << KNetworkAdapterPromiscModePolicy_AllowAll; 491 492 /* Make sure requested value if sane is present as well: */ 493 if ( m_enmPromiscuousMode != KNetworkAdapterPromiscModePolicy_Max 494 && !supportedTypes.contains(m_enmPromiscuousMode)) 495 supportedTypes.prepend(m_enmPromiscuousMode); 496 497 /* Update combo with all the supported values: */ 498 foreach (const KNetworkAdapterPromiscModePolicy &enmType, supportedTypes) 499 m_pComboPromiscuousMode->addItem(QString(), QVariant::fromValue(enmType)); 500 501 /* Look for proper index to choose: */ 502 const int iIndex = m_pComboPromiscuousMode->findData(QVariant::fromValue(m_enmPromiscuousMode)); 503 if (iIndex != -1) 504 m_pComboPromiscuousMode->setCurrentIndex(iIndex); 505 506 /* Retranslate finally: */ 507 retranslateUi(); 508 } 509 } -
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIMachineNetworkFeaturesEditor.h
r94526 r94527 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIMachine DescriptionEditor class declaration.3 * VBox Qt GUI - UIMachineNetworkFeaturesEditor class declaration. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef FEQT_INCLUDED_SRC_settings_editors_UIMachine DescriptionEditor_h19 #define FEQT_INCLUDED_SRC_settings_editors_UIMachine DescriptionEditor_h18 #ifndef FEQT_INCLUDED_SRC_settings_editors_UIMachineNetworkFeaturesEditor_h 19 #define FEQT_INCLUDED_SRC_settings_editors_UIMachineNetworkFeaturesEditor_h 20 20 #ifndef RT_WITHOUT_PRAGMA_ONCE 21 21 # pragma once … … 24 24 /* GUI includes: */ 25 25 #include "QIWithRetranslateUI.h" 26 #include "UIMachineSettingsPortForwardingDlg.h" 27 28 /* COM includes: */ 29 #include "COMEnums.h" 26 30 27 31 /* Forward declarations: */ 32 class QCheckBox; 33 class QComboBox; 34 class QGridLayout; 35 class QLabel; 28 36 class QTextEdit; 37 class QIArrowButtonSwitch; 38 class QILineEdit; 39 class QIToolButton; 29 40 30 41 /** QWidget subclass used as machine description editor. */ 31 class SHARED_LIBRARY_STUFF UIMachine DescriptionEditor : public QIWithRetranslateUI<QWidget>42 class SHARED_LIBRARY_STUFF UIMachineNetworkFeaturesEditor : public QIWithRetranslateUI<QWidget> 32 43 { 33 44 Q_OBJECT; 45 46 signals: 47 48 /** Notifies about the advanced button state change to @a fExpanded. */ 49 void sigNotifyAdvancedButtonStateChange(bool fExpanded); 50 /** Notifies about MAC address changed. */ 51 void sigMACAddressChanged(); 34 52 35 53 public: 36 54 37 55 /** Constructs editor passing @a pParent to the base-class. */ 38 UIMachine DescriptionEditor(QWidget *pParent = 0);56 UIMachineNetworkFeaturesEditor(QWidget *pParent = 0); 39 57 40 /** Defines editor @a strValue. */ 41 void setValue(const QString &strValue); 42 /** Returns editor value. */ 43 QString value() const; 58 /** Defines whether advanced button @a fExpanded. */ 59 void setAdvancedButtonExpanded(bool fExpanded); 60 /** Returns whether advanced button expanded. */ 61 bool advancedButtonExpanded() const; 62 63 /** Defines adapter @a enmType. */ 64 void setAdapterType(const KNetworkAdapterType &enmType); 65 /** Returns adapter type. */ 66 KNetworkAdapterType adapterType() const; 67 68 /** Defines promiscuous @a enmMode. */ 69 void setPromiscuousMode(const KNetworkAdapterPromiscModePolicy &enmMode); 70 /** Returns promiscuous mode. */ 71 KNetworkAdapterPromiscModePolicy promiscuousMode() const; 72 73 /** Defines MAC @a strAddress. */ 74 void setMACAddress(const QString &strAddress); 75 /** Returns MAC address. */ 76 QString macAddress() const; 77 78 /** Defines generic @a strProperties. */ 79 void setGenericProperties(const QString &strProperties); 80 /** Returns generic properties. */ 81 QString genericProperties() const; 82 83 /** Defines whether cable is @a fConnected. */ 84 void setCableConnected(bool fConnected); 85 /** Returns whether cable is connected. */ 86 bool cableConnected() const; 87 88 /** Defines list of port forwarding @a rules. */ 89 void setPortForwardingRules(const UIPortForwardingDataList &rules); 90 /** Returns list of port forwarding rules. */ 91 UIPortForwardingDataList portForwardingRules() const; 92 93 /** Defines whether advanced options @a fAvailable. */ 94 void setAdvancedOptionsAvailable(bool fAvailable); 95 /** Defines whether adapter options @a fAvailable. */ 96 void setAdapterOptionsAvailable(bool fAvailable); 97 /** Defines whether promiscuous options @a fAvailable. */ 98 void setPromiscuousOptionsAvailable(bool fAvailable); 99 /** Defines whether MAC options @a fAvailable. */ 100 void setMACOptionsAvailable(bool fAvailable); 101 /** Defines whether generic properties @a fAvailable. */ 102 void setGenericPropertiesAvailable(bool fAvailable); 103 /** Defines whether cable options @a fAvailable. */ 104 void setCableOptionsAvailable(bool fAvailable); 105 /** Defines whether forwarding options @a fAvailable. */ 106 void setForwardingOptionsAvailable(bool fAvailable); 107 108 /** Returns minimum layout hint. */ 109 int minimumLabelHorizontalHint() const; 110 /** Defines minimum layout @a iIndent. */ 111 void setMinimumLayoutIndent(int iIndent); 112 113 public slots: 114 115 /** Generates MAC address. */ 116 void generateMac(); 44 117 45 118 protected: … … 48 121 virtual void retranslateUi() RT_OVERRIDE; 49 122 123 private slots: 124 125 /** Handles advanced button state change to expanded. */ 126 void sltHandleAdvancedButtonStateChange(); 127 /** Handles request to open port forwarding dialog. */ 128 void sltOpenPortForwardingDlg(); 129 50 130 private: 51 131 … … 53 133 void prepare(); 54 134 55 /** Holds the value to be set. */ 56 QString m_strValue; 135 /** Repopulates adapter type combo. */ 136 void repopulateAdapterTypeCombo(); 137 /** Repopulates promiscuous mode combo. */ 138 void repopulatePromiscuousModeCombo(); 57 139 58 /** Holds the check-box instance. */ 59 QTextEdit *m_pTextEdit; 140 /** @name Widgets 141 * @{ */ 142 /** Holds whether advanced button expanded. */ 143 bool m_fAdvancedButtonExpanded; 144 /** Holds the adapter type to be set. */ 145 KNetworkAdapterType m_enmAdapterType; 146 /** Holds the promisc mode to be set. */ 147 KNetworkAdapterPromiscModePolicy m_enmPromiscuousMode; 148 /** Holds the MAC address to be set. */ 149 QString m_strMACAddress; 150 /** Holds the generic properties to be set. */ 151 QString m_strGenericProperties; 152 /** Holds whether cable is connected. */ 153 bool m_fCableConnected; 154 /** Holds the list of port forwarding rules. */ 155 UIPortForwardingDataList m_portForwardingRules; 156 /** @} */ 157 158 /** @name Widgets 159 * @{ */ 160 /** Holds the advanced button instance. */ 161 QIArrowButtonSwitch *m_pButtonAdvanced; 162 /** Holds the settings widget instance. */ 163 QWidget *m_pWidgetSettings; 164 /** Holds the settings layout instance. */ 165 QGridLayout *m_pLayoutSettings; 166 /** Holds the adapter type label instance. */ 167 QLabel *m_pLabelAdapterType; 168 /** Holds the adapter type editor instance. */ 169 QComboBox *m_pComboAdapterType; 170 /** Holds the promiscuous mode label instance. */ 171 QLabel *m_pLabelPromiscuousMode; 172 /** Holds the promiscuous mode combo instance. */ 173 QComboBox *m_pComboPromiscuousMode; 174 /** Holds the MAC label instance. */ 175 QLabel *m_pLabelMAC; 176 /** Holds the MAC editor instance. */ 177 QILineEdit *m_pEditorMAC; 178 /** Holds the MAC button instance. */ 179 QIToolButton *m_pButtonMAC; 180 /** Holds the generic properties label instance. */ 181 QLabel *m_pLabelGenericProperties; 182 /** Holds the generic properties editor instance. */ 183 QTextEdit *m_pEditorGenericProperties; 184 /** Holds the cable connected check-box instance. */ 185 QCheckBox *m_pCheckBoxCableConnected; 186 /** Holds the port forwarding button instance. */ 187 QPushButton *m_pButtonPortForwarding; 188 /** @} */ 60 189 }; 61 190 62 #endif /* !FEQT_INCLUDED_SRC_settings_editors_UIMachine DescriptionEditor_h */191 #endif /* !FEQT_INCLUDED_SRC_settings_editors_UIMachineNetworkFeaturesEditor_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.cpp
r94333 r94527 18 18 /* Qt includes: */ 19 19 #include <QCheckBox> 20 #include <QComboBox>21 20 #include <QGridLayout> 22 21 #include <QLabel> 23 #include <QRegExp> 24 #include <QRegularExpressionValidator> 25 #include <QPushButton> 26 #include <QTextEdit> 22 #include <QVBoxLayout> 27 23 28 24 /* GUI includes: */ 29 #include "QIArrowButtonSwitch.h"30 #include "QILineEdit.h"31 25 #include "QITabWidget.h" 32 #include "QIToolButton.h"33 #include "QIWidgetValidator.h"34 26 #include "UICommon.h" 35 #include "UIConverter.h"36 27 #include "UIErrorString.h" 37 #include "UIExtraDataManager.h" 38 #include "UIIconPool.h" 28 #include "UIMachineNetworkFeaturesEditor.h" 39 29 #include "UIMachineSettingsNetwork.h" 40 30 #include "UINetworkAttachmentEditor.h" … … 44 34 #include "CNATEngine.h" 45 35 #include "CNetworkAdapter.h" 46 47 /* Other VBox includes: */48 #ifdef VBOX_WITH_VDE49 # include <iprt/ldr.h>50 # include <VBox/VDEPlug.h>51 #endif52 36 53 37 … … 200 184 void sigTabUpdated(); 201 185 202 /** Notifies about the advanced button has@a fExpanded. */186 /** Notifies about the advanced button state change to @a fExpanded. */ 203 187 void sigNotifyAdvancedButtonStateChange(bool fExpanded); 204 188 … … 214 198 void sltHandleAttachmentTypeChange(); 215 199 void sltHandleAlternativeNameChange(); 216 void sltHandleAdvancedButtonStateChange();217 void sltGenerateMac();218 void sltOpenPortForwardingDlg();219 200 220 201 private: … … 226 207 /** Prepares connections. */ 227 208 void prepareConnections(); 228 /** Prepares advanced settings widgets. */229 void prepareAdvancedSettingsWidgets(QGridLayout *pLayout);230 231 /* Helping stuff: */232 void populateComboboxes();233 234 /** Handles advanced button state change. */235 void handleAdvancedButtonStateChange();236 237 /* Various static stuff: */238 static int position(QComboBox *pComboBox, int iData);239 static int position(QComboBox *pComboBox, const QString &strText);240 209 241 210 /* Parent page: */ … … 244 213 /* Other variables: */ 245 214 int m_iSlot; 246 KNetworkAdapterType m_enmAdapterType;247 UIPortForwardingDataList m_portForwardingRules;248 215 249 216 /** @name Widgets 250 217 * @{ */ 251 218 /** Holds the adapter check-box instance. */ 252 QCheckBox *m_pCheckBoxAdapter;219 QCheckBox *m_pCheckBoxAdapter; 253 220 /** Holds the adapter settings widget instance. */ 254 QWidget *m_pWidgetAdapterSettings; 255 /** Holds the adapter settings layout instance. */ 256 QGridLayout *m_pLayoutAdapterSettings; 257 /** Holds the advanced settings container widget instance. */ 258 QWidget *m_pWidgetAdvancedSettings; 259 /** Holds the attachment type label instance. */ 260 QLabel *m_pLabelAttachmentType; 261 /** Holds the network name label instance. */ 262 QLabel *m_pLabelNetworkName; 221 QWidget *m_pWidgetAdapterSettings; 263 222 /** Holds the attachment type editor instance. */ 264 UINetworkAttachmentEditor *m_pEditorAttachmentType; 265 /** Holds the advanced button instance. */ 266 QIArrowButtonSwitch *m_pButtonAdvanced; 267 /** Holds the adapter type label instance. */ 268 QLabel *m_pLabelAdapterType; 269 /** Holds the adapter type editor instance. */ 270 QComboBox *m_pComboAdapterType; 271 /** Holds the promiscuous mode label instance. */ 272 QLabel *m_pLabelPromiscuousMode; 273 /** Holds the promiscuous mode combo instance. */ 274 QComboBox *m_pComboPromiscuousMode; 275 /** Holds the MAC label instance. */ 276 QLabel *m_pLabelMAC; 277 /** Holds the MAC editor instance. */ 278 QILineEdit *m_pEditorMAC; 279 /** Holds the MAC button instance. */ 280 QIToolButton *m_pButtonMAC; 281 /** Holds the generic properties label instance. */ 282 QLabel *m_pLabelGenericProperties; 283 /** Holds the generic properties editor instance. */ 284 QTextEdit *m_pEditorGenericProperties; 285 /** Holds the cable connected check-box instance. */ 286 QCheckBox *m_pCheckBoxCableConnected; 287 /** Holds the port forwarding button instance. */ 288 QPushButton *m_pButtonPortForwarding; 223 UINetworkAttachmentEditor *m_pEditorAttachmentType; 224 /** Holds the network features editor instance. */ 225 UIMachineNetworkFeaturesEditor *m_pEditorNetworkFeatures; 289 226 /** @} */ 290 227 }; … … 299 236 , m_pParent(pParent) 300 237 , m_iSlot(-1) 301 , m_enmAdapterType(KNetworkAdapterType_Null)302 238 , m_pCheckBoxAdapter(0) 303 239 , m_pWidgetAdapterSettings(0) 304 , m_pLayoutAdapterSettings(0)305 , m_pWidgetAdvancedSettings(0)306 , m_pLabelAttachmentType(0)307 , m_pLabelNetworkName(0)308 240 , m_pEditorAttachmentType(0) 309 , m_pButtonAdvanced(0) 310 , m_pLabelAdapterType(0) 311 , m_pComboAdapterType(0) 312 , m_pLabelPromiscuousMode(0) 313 , m_pComboPromiscuousMode(0) 314 , m_pLabelMAC(0) 315 , m_pEditorMAC(0) 316 , m_pButtonMAC(0) 317 , m_pLabelGenericProperties(0) 318 , m_pEditorGenericProperties(0) 319 , m_pCheckBoxCableConnected(0) 320 , m_pButtonPortForwarding(0) 241 , m_pEditorNetworkFeatures(0) 321 242 { 322 243 prepare(); … … 353 274 sltHandleAttachmentTypeChange(); 354 275 355 /* Load adapter type: */ 356 m_enmAdapterType = oldAdapterData.m_adapterType; 357 358 /* Load promiscuous mode type: */ 359 m_pComboPromiscuousMode->setCurrentIndex(position(m_pComboPromiscuousMode, oldAdapterData.m_promiscuousMode)); 360 361 /* Other options: */ 362 m_pEditorMAC->setText(oldAdapterData.m_strMACAddress); 363 m_pEditorGenericProperties->setText(oldAdapterData.m_strGenericProperties); 364 m_pCheckBoxCableConnected->setChecked(oldAdapterData.m_fCableConnected); 276 /* Load settings: */ 277 m_pEditorNetworkFeatures->setAdapterType(oldAdapterData.m_adapterType); 278 m_pEditorNetworkFeatures->setPromiscuousMode(oldAdapterData.m_promiscuousMode); 279 m_pEditorNetworkFeatures->setMACAddress(oldAdapterData.m_strMACAddress); 280 m_pEditorNetworkFeatures->setGenericProperties(oldAdapterData.m_strGenericProperties); 281 m_pEditorNetworkFeatures->setCableConnected(oldAdapterData.m_fCableConnected); 365 282 366 283 /* Load port forwarding rules: */ 367 m_portForwardingRules.clear();284 UIPortForwardingDataList portForwardingRules; 368 285 for (int i = 0; i < adapterCache.childCount(); ++i) 369 m_portForwardingRules << adapterCache.child(i).base(); 370 371 /* Repopulate combo-boxes content: */ 372 populateComboboxes(); 286 portForwardingRules << adapterCache.child(i).base(); 287 m_pEditorNetworkFeatures->setPortForwardingRules(portForwardingRules); 288 289 /* Reload alternatives: */ 290 reloadAlternatives(); 373 291 /* Reapply attachment info: */ 374 292 sltHandleAttachmentTypeChange(); … … 402 320 case KNetworkAttachmentType_Generic: 403 321 newAdapterData.m_strGenericDriverName = m_pEditorAttachmentType->valueName(KNetworkAttachmentType_Generic); 404 newAdapterData.m_strGenericProperties = m_pEditorGenericProperties->toPlainText();405 322 break; 406 323 case KNetworkAttachmentType_NATNetwork: … … 421 338 } 422 339 423 /* Save adapter type: */ 424 newAdapterData.m_adapterType = m_pComboAdapterType->currentData().value<KNetworkAdapterType>(); 425 426 /* Save promiscuous mode type: */ 427 newAdapterData.m_promiscuousMode = (KNetworkAdapterPromiscModePolicy)m_pComboPromiscuousMode->itemData(m_pComboPromiscuousMode->currentIndex()).toInt(); 428 429 /* Other options: */ 430 newAdapterData.m_strMACAddress = m_pEditorMAC->text().isEmpty() ? QString() : m_pEditorMAC->text(); 431 newAdapterData.m_fCableConnected = m_pCheckBoxCableConnected->isChecked(); 340 /* Save settings: */ 341 newAdapterData.m_adapterType = m_pEditorNetworkFeatures->adapterType(); 342 newAdapterData.m_promiscuousMode = m_pEditorNetworkFeatures->promiscuousMode(); 343 newAdapterData.m_strMACAddress = m_pEditorNetworkFeatures->macAddress(); 344 if (newAdapterData.m_attachmentType == KNetworkAttachmentType_Generic) 345 newAdapterData.m_strGenericProperties = m_pEditorNetworkFeatures->genericProperties(); 346 newAdapterData.m_fCableConnected = m_pEditorNetworkFeatures->cableConnected(); 432 347 433 348 /* Save port forwarding rules: */ 434 foreach (const UIDataPortForwardingRule &rule, m_p ortForwardingRules)349 foreach (const UIDataPortForwardingRule &rule, m_pEditorNetworkFeatures->portForwardingRules()) 435 350 adapterCache.child(rule.name).cacheCurrentData(rule); 436 351 … … 536 451 537 452 /* Validate MAC-address length: */ 538 if (m_pEditor MAC->text().size() < 12)453 if (m_pEditorNetworkFeatures->macAddress().size() < 12) 539 454 { 540 455 message.second << tr("The MAC address must be 12 hexadecimal digits long."); … … 543 458 544 459 /* Make sure MAC-address is unicast: */ 545 if (m_pEditor MAC->text().size() >= 2)460 if (m_pEditorNetworkFeatures->macAddress().size() >= 2) 546 461 { 547 462 QRegExp validator("^[0-9A-Fa-f][02468ACEace]"); 548 if (validator.indexIn(m_pEditor MAC->text()) != 0)463 if (validator.indexIn(m_pEditorNetworkFeatures->macAddress()) != 0) 549 464 { 550 465 message.second << tr("The second digit in the MAC address may not be odd as only unicast addresses are allowed."); … … 565 480 setTabOrder(pAfter, m_pCheckBoxAdapter); 566 481 setTabOrder(m_pCheckBoxAdapter, m_pEditorAttachmentType); 567 setTabOrder(m_pEditorAttachmentType, m_pButtonAdvanced); 568 setTabOrder(m_pButtonAdvanced, m_pComboAdapterType); 569 setTabOrder(m_pComboAdapterType, m_pComboPromiscuousMode); 570 setTabOrder(m_pComboPromiscuousMode, m_pEditorMAC); 571 setTabOrder(m_pEditorMAC, m_pButtonMAC); 572 setTabOrder(m_pButtonMAC, m_pEditorGenericProperties); 573 setTabOrder(m_pEditorGenericProperties, m_pCheckBoxCableConnected); 574 setTabOrder(m_pCheckBoxCableConnected, m_pButtonPortForwarding); 575 return m_pButtonPortForwarding; 482 setTabOrder(m_pEditorAttachmentType, m_pEditorNetworkFeatures); 483 return m_pEditorNetworkFeatures; 576 484 } 577 485 … … 597 505 /* Basic attributes: */ 598 506 m_pCheckBoxAdapter->setEnabled(m_pParent->isMachineOffline()); 599 m_pLabelAttachmentType->setEnabled(m_pParent->isMachineInValidMode());600 507 m_pEditorAttachmentType->setEnabled(m_pParent->isMachineInValidMode()); 601 m_pLabelNetworkName->setEnabled(m_pParent->isMachineInValidMode() &&602 attachmentType() != KNetworkAttachmentType_Null &&603 attachmentType() != KNetworkAttachmentType_NAT);604 m_pButtonAdvanced->setEnabled(m_pParent->isMachineInValidMode());605 508 606 509 /* Advanced attributes: */ 607 m_pLabelAdapterType->setEnabled(m_pParent->isMachineOffline()); 608 m_pComboAdapterType->setEnabled(m_pParent->isMachineOffline()); 609 m_pLabelPromiscuousMode->setEnabled(m_pParent->isMachineInValidMode() && 610 attachmentType() != KNetworkAttachmentType_Null && 611 attachmentType() != KNetworkAttachmentType_Generic && 612 attachmentType() != KNetworkAttachmentType_NAT); 613 m_pComboPromiscuousMode->setEnabled(m_pParent->isMachineInValidMode() && 614 attachmentType() != KNetworkAttachmentType_Null && 615 attachmentType() != KNetworkAttachmentType_Generic && 616 attachmentType() != KNetworkAttachmentType_NAT); 617 m_pLabelMAC->setEnabled(m_pParent->isMachineOffline()); 618 m_pEditorMAC->setEnabled(m_pParent->isMachineOffline()); 619 m_pButtonMAC->setEnabled(m_pParent->isMachineOffline()); 620 m_pLabelGenericProperties->setEnabled(m_pParent->isMachineInValidMode()); 621 m_pEditorGenericProperties->setEnabled(m_pParent->isMachineInValidMode()); 622 m_pCheckBoxCableConnected->setEnabled(m_pParent->isMachineInValidMode()); 623 m_pButtonPortForwarding->setEnabled(m_pParent->isMachineInValidMode() && 624 attachmentType() == KNetworkAttachmentType_NAT); 625 626 /* Postprocessing: */ 627 handleAdvancedButtonStateChange(); 510 m_pEditorNetworkFeatures->setAdvancedOptionsAvailable(m_pParent->isMachineInValidMode()); 511 m_pEditorNetworkFeatures->setAdapterOptionsAvailable(m_pParent->isMachineOffline()); 512 m_pEditorNetworkFeatures->setPromiscuousOptionsAvailable( attachmentType() != KNetworkAttachmentType_Null 513 && attachmentType() != KNetworkAttachmentType_Generic 514 && attachmentType() != KNetworkAttachmentType_NAT); 515 m_pEditorNetworkFeatures->setMACOptionsAvailable(m_pParent->isMachineOffline()); 516 m_pEditorNetworkFeatures->setGenericPropertiesAvailable(attachmentType() == KNetworkAttachmentType_Generic); 517 m_pEditorNetworkFeatures->setCableOptionsAvailable(m_pParent->isMachineInValidMode()); 518 m_pEditorNetworkFeatures->setForwardingOptionsAvailable(attachmentType() == KNetworkAttachmentType_NAT); 628 519 } 629 520 … … 645 536 void UIMachineSettingsNetwork::setAdvancedButtonState(bool fExpanded) 646 537 { 647 /* Check whether the button state really changed: */ 648 if (m_pButtonAdvanced->isExpanded() == fExpanded) 649 return; 650 651 /* Push the state to button and handle the state change: */ 652 m_pButtonAdvanced->setExpanded(fExpanded); 653 handleAdvancedButtonStateChange(); 538 m_pEditorNetworkFeatures->setAdvancedButtonExpanded(fExpanded); 654 539 } 655 540 656 541 void UIMachineSettingsNetwork::retranslateUi() 657 542 { 658 int iFirstColumnWidth = 0; 659 m_pCheckBoxAdapter->setToolTip(tr("When checked, plugs this virtual network adapter into the virtual machine.")); 660 m_pCheckBoxAdapter->setText(tr("&Enable Network Adapter")); 661 m_pLabelAttachmentType->setText(tr("&Attached to:")); 662 iFirstColumnWidth = qMax(iFirstColumnWidth, m_pLabelAttachmentType->minimumSizeHint().width()); 663 m_pLabelNetworkName->setText(tr("&Name:")); 664 iFirstColumnWidth = qMax(iFirstColumnWidth, m_pLabelNetworkName->minimumSizeHint().width()); 665 m_pButtonAdvanced->setText(tr("A&dvanced")); 666 m_pButtonAdvanced->setToolTip(tr("Shows additional network adapter options.")); 667 m_pLabelAdapterType->setText(tr("Adapter &Type:")); 668 iFirstColumnWidth = qMax(iFirstColumnWidth, m_pLabelAdapterType->minimumSizeHint().width()); 669 m_pComboAdapterType->setToolTip(tr("Selects the type of the virtual network adapter. Depending on this value, VirtualBox " 670 "will provide different network hardware to the virtual machine.")); 671 m_pLabelPromiscuousMode->setText(tr("&Promiscuous Mode:")); 672 iFirstColumnWidth = qMax(iFirstColumnWidth, m_pLabelPromiscuousMode->minimumSizeHint().width()); 673 m_pComboPromiscuousMode->setToolTip(tr("Selects the promiscuous mode policy of the network adapter when attached to an " 674 "internal network, host only network or a bridge.")); 675 m_pLabelMAC->setText(tr("&MAC Address:")); 676 iFirstColumnWidth = qMax(iFirstColumnWidth, m_pLabelMAC->minimumSizeHint().width()); 677 m_pEditorMAC->setToolTip(tr("Holds the MAC address of this adapter. It contains exactly 12 characters chosen from {0-9,A-F}. " 678 "Note that the second character must be an even digit.")); 679 m_pButtonMAC->setToolTip(tr("Generates a new random MAC address.")); 680 m_pLabelGenericProperties->setText(tr("Generic Properties:")); 681 m_pEditorGenericProperties->setToolTip(tr("Holds the configuration settings for the network attachment driver. The settings " 682 "should be of the form <b>name=value</b> and will depend on the driver. " 683 "Use <b>shift-enter</b> to add a new entry.")); 684 m_pCheckBoxCableConnected->setToolTip(tr("When checked, the virtual network cable is plugged in.")); 685 m_pCheckBoxCableConnected->setText(tr("&Cable Connected")); 686 m_pButtonPortForwarding->setToolTip(tr("Displays a window to configure port forwarding rules.")); 687 m_pButtonPortForwarding->setText(tr("&Port Forwarding")); 688 689 /* Translate combo-boxes content: */ 690 populateComboboxes(); 691 692 /* Translate attachment info: */ 543 if (m_pCheckBoxAdapter) 544 { 545 m_pCheckBoxAdapter->setText(tr("&Enable Network Adapter")); 546 m_pCheckBoxAdapter->setToolTip(tr("When checked, plugs this virtual network adapter into the virtual machine.")); 547 } 548 549 /* Reload alternatives: */ 550 reloadAlternatives(); 551 /* Reapply attachment info: */ 693 552 sltHandleAttachmentTypeChange(); 694 /* Set the minimum width of the 1st column to size longest label to align all labels: */695 m_pLayoutAdapterSettings->setColumnMinimumWidth(0, iFirstColumnWidth);696 553 } 697 554 … … 703 560 /* Generate a new MAC address in case this adapter was never enabled before: */ 704 561 if ( m_pCheckBoxAdapter->isChecked() 705 && m_pEditor MAC->text().isEmpty())706 sltGenerateMac();562 && m_pEditorNetworkFeatures->macAddress().isEmpty()) 563 m_pEditorNetworkFeatures->generateMac(); 707 564 708 565 /* Revalidate: */ … … 712 569 void UIMachineSettingsNetwork::sltHandleAttachmentTypeChange() 713 570 { 714 /* Update alternative-name combo-box availability: */ 715 m_pLabelNetworkName->setEnabled(attachmentType() != KNetworkAttachmentType_Null && 716 attachmentType() != KNetworkAttachmentType_NAT); 717 /* Update promiscuous-mode combo-box availability: */ 718 m_pLabelPromiscuousMode->setEnabled(attachmentType() != KNetworkAttachmentType_Null && 719 attachmentType() != KNetworkAttachmentType_Generic && 720 attachmentType() != KNetworkAttachmentType_NAT); 721 m_pComboPromiscuousMode->setEnabled(attachmentType() != KNetworkAttachmentType_Null && 722 attachmentType() != KNetworkAttachmentType_Generic && 723 attachmentType() != KNetworkAttachmentType_NAT); 724 /* Update generic-properties editor visibility: */ 725 m_pLabelGenericProperties->setVisible(attachmentType() == KNetworkAttachmentType_Generic && 726 m_pButtonAdvanced->isExpanded()); 727 m_pEditorGenericProperties->setVisible(attachmentType() == KNetworkAttachmentType_Generic && 728 m_pButtonAdvanced->isExpanded()); 729 /* Update forwarding rules button availability: */ 730 m_pButtonPortForwarding->setEnabled(attachmentType() == KNetworkAttachmentType_NAT); 571 /* Advanced attributes: */ 572 m_pEditorNetworkFeatures->setPromiscuousOptionsAvailable( attachmentType() != KNetworkAttachmentType_Null 573 && attachmentType() != KNetworkAttachmentType_Generic 574 && attachmentType() != KNetworkAttachmentType_NAT); 575 m_pEditorNetworkFeatures->setGenericPropertiesAvailable(attachmentType() == KNetworkAttachmentType_Generic); 576 m_pEditorNetworkFeatures->setForwardingOptionsAvailable(attachmentType() == KNetworkAttachmentType_NAT); 731 577 732 578 /* Revalidate: */ … … 760 606 } 761 607 762 void UIMachineSettingsNetwork::sltHandleAdvancedButtonStateChange()763 {764 /* Handle the button state change: */765 handleAdvancedButtonStateChange();766 767 /* Notify listeners about the button state change: */768 emit sigNotifyAdvancedButtonStateChange(m_pButtonAdvanced->isExpanded());769 }770 771 void UIMachineSettingsNetwork::sltGenerateMac()772 {773 m_pEditorMAC->setText(uiCommon().host().GenerateMACAddress());774 }775 776 void UIMachineSettingsNetwork::sltOpenPortForwardingDlg()777 {778 UIMachineSettingsPortForwardingDlg dlg(this, m_portForwardingRules);779 if (dlg.exec() == QDialog::Accepted)780 m_portForwardingRules = dlg.rules();781 }782 783 608 void UIMachineSettingsNetwork::prepare() 784 609 { … … 794 619 { 795 620 /* Prepare main layout: */ 796 QGridLayout *pLayoutMain = new QGridLayout(this); 797 if (pLayoutMain) 798 { 799 pLayoutMain->setRowStretch(2, 1); 800 621 QGridLayout *pLayout = new QGridLayout(this); 622 if (pLayout) 623 { 801 624 /* Prepare adapter check-box: */ 802 625 m_pCheckBoxAdapter = new QCheckBox(this); 803 626 if (m_pCheckBoxAdapter) 804 pLayout Main->addWidget(m_pCheckBoxAdapter, 0, 0, 1, 2);627 pLayout->addWidget(m_pCheckBoxAdapter, 0, 0, 1, 2); 805 628 806 629 /* Prepare 20-px shifting spacer: */ 807 630 QSpacerItem *pSpacerItem = new QSpacerItem(20, 0, QSizePolicy::Fixed, QSizePolicy::Minimum); 808 631 if (pSpacerItem) 809 pLayout Main->addItem(pSpacerItem, 1, 0);632 pLayout->addItem(pSpacerItem, 1, 0); 810 633 811 634 /* Prepare adapter settings widget: */ … … 814 637 { 815 638 /* Prepare adapter settings widget layout: */ 816 m_pLayoutAdapterSettings = new QGridLayout(m_pWidgetAdapterSettings); 817 if (m_pLayoutAdapterSettings) 818 { 819 m_pLayoutAdapterSettings->setContentsMargins(0, 0, 0, 0); 820 m_pLayoutAdapterSettings->setColumnStretch(2, 1); 821 822 /* Prepare attachment type label: */ 823 m_pLabelAttachmentType = new QLabel(m_pWidgetAdapterSettings); 824 if (m_pLabelAttachmentType) 825 { 826 m_pLabelAttachmentType->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 827 m_pLayoutAdapterSettings->addWidget(m_pLabelAttachmentType, 0, 0); 828 } 829 /* Prepare adapter name label: */ 830 m_pLabelNetworkName = new QLabel(m_pWidgetAdapterSettings); 831 if (m_pLabelNetworkName) 832 { 833 m_pLabelNetworkName->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 834 m_pLayoutAdapterSettings->addWidget(m_pLabelNetworkName, 1, 0); 835 } 639 QVBoxLayout *pLayoutAdapterSettings = new QVBoxLayout(m_pWidgetAdapterSettings); 640 if (pLayoutAdapterSettings) 641 { 642 pLayoutAdapterSettings->setContentsMargins(0, 0, 0, 0); 643 836 644 /* Prepare attachment type editor: */ 837 m_pEditorAttachmentType = new UINetworkAttachmentEditor(m_pWidgetAdapterSettings );645 m_pEditorAttachmentType = new UINetworkAttachmentEditor(m_pWidgetAdapterSettings, true); 838 646 if (m_pEditorAttachmentType) 839 { 840 if (m_pLabelAttachmentType) 841 m_pLabelAttachmentType->setBuddy(m_pEditorAttachmentType); 842 if (m_pLabelNetworkName) 843 m_pLabelNetworkName->setBuddy(m_pEditorAttachmentType); 844 845 m_pLayoutAdapterSettings->addWidget(m_pEditorAttachmentType, 0, 1, 2, 3); 846 } 847 848 /* Prepare advanced arrow button: */ 849 m_pButtonAdvanced = new QIArrowButtonSwitch(m_pWidgetAdapterSettings); 850 if (m_pButtonAdvanced) 851 { 852 const QStyle *pStyle = QApplication::style(); 853 const int iIconMetric = (int)(pStyle->pixelMetric(QStyle::PM_SmallIconSize) * .625); 854 m_pButtonAdvanced->setIconSize(QSize(iIconMetric, iIconMetric)); 855 m_pButtonAdvanced->setIcons(UIIconPool::iconSet(":/arrow_right_10px.png"), 856 UIIconPool::iconSet(":/arrow_down_10px.png")); 857 858 m_pLayoutAdapterSettings->addWidget(m_pButtonAdvanced, 2, 0); 859 } 860 861 /* Create the container widget for advanced settings related widgets: */ 862 m_pWidgetAdvancedSettings = new QWidget; 863 m_pLayoutAdapterSettings->addWidget(m_pWidgetAdvancedSettings, 3, 0, 4, 3, Qt::AlignLeft); 864 QGridLayout *pLayoutAdvancedSettings = new QGridLayout(m_pWidgetAdvancedSettings); 865 pLayoutAdvancedSettings->setContentsMargins(0, 0, 0, 0); 866 prepareAdvancedSettingsWidgets(pLayoutAdvancedSettings); 867 } 868 869 pLayoutMain->addWidget(m_pWidgetAdapterSettings, 1, 1); 647 pLayoutAdapterSettings->addWidget(m_pEditorAttachmentType); 648 649 /* Prepare advanced settingseditor: */ 650 m_pEditorNetworkFeatures = new UIMachineNetworkFeaturesEditor(m_pWidgetAdapterSettings); 651 if (m_pEditorNetworkFeatures) 652 pLayoutAdapterSettings->addWidget(m_pEditorNetworkFeatures); 653 654 pLayoutAdapterSettings->addStretch(); 655 } 656 657 pLayout->addWidget(m_pWidgetAdapterSettings, 1, 1); 870 658 } 871 659 } … … 874 662 void UIMachineSettingsNetwork::prepareConnections() 875 663 { 876 connect(m_pCheckBoxAdapter, &QCheckBox::toggled, this, &UIMachineSettingsNetwork::sltHandleAdapterActivityChange); 664 connect(m_pCheckBoxAdapter, &QCheckBox::toggled, 665 this, &UIMachineSettingsNetwork::sltHandleAdapterActivityChange); 877 666 connect(m_pEditorAttachmentType, &UINetworkAttachmentEditor::sigValueTypeChanged, 878 667 this, &UIMachineSettingsNetwork::sltHandleAttachmentTypeChange); 879 668 connect(m_pEditorAttachmentType, &UINetworkAttachmentEditor::sigValueNameChanged, 880 669 this, &UIMachineSettingsNetwork::sltHandleAlternativeNameChange); 881 connect(m_pButtonAdvanced, &QIArrowButtonSwitch::sigClicked, this, &UIMachineSettingsNetwork::sltHandleAdvancedButtonStateChange); 882 connect(m_pEditorMAC, &QILineEdit::textChanged, m_pParent, &UIMachineSettingsNetworkPage::revalidate); 883 connect(m_pButtonMAC, &QIToolButton::clicked, this, &UIMachineSettingsNetwork::sltGenerateMac); 884 connect(m_pButtonPortForwarding, &QPushButton::clicked, this, &UIMachineSettingsNetwork::sltOpenPortForwardingDlg); 885 connect(this, &UIMachineSettingsNetwork::sigTabUpdated, m_pParent, &UIMachineSettingsNetworkPage::sltHandleTabUpdate); 886 } 887 888 void UIMachineSettingsNetwork::prepareAdvancedSettingsWidgets(QGridLayout *pLayout) 889 { 890 AssertPtrReturnVoid(pLayout); 891 892 /* Prepare adapter type label: */ 893 m_pLabelAdapterType = new QLabel(m_pWidgetAdapterSettings); 894 if (m_pLabelAdapterType) 895 { 896 m_pLabelAdapterType->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 897 pLayout->addWidget(m_pLabelAdapterType, 0, 0); 898 } 899 /* Prepare adapter type combo: */ 900 m_pComboAdapterType = new QComboBox(m_pWidgetAdapterSettings); 901 if (m_pComboAdapterType) 902 { 903 if (m_pLabelAdapterType) 904 m_pLabelAdapterType->setBuddy(m_pComboAdapterType); 905 pLayout->addWidget(m_pComboAdapterType, 0, 1, 1, 3); 906 } 907 908 /* Prepare promiscuous mode label: */ 909 m_pLabelPromiscuousMode = new QLabel(m_pWidgetAdapterSettings); 910 if (m_pLabelPromiscuousMode) 911 { 912 m_pLabelPromiscuousMode->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 913 pLayout->addWidget(m_pLabelPromiscuousMode, 1, 0); 914 } 915 /* Prepare promiscuous mode combo: */ 916 m_pComboPromiscuousMode = new QComboBox(m_pWidgetAdapterSettings); 917 if (m_pComboPromiscuousMode) 918 { 919 if (m_pLabelPromiscuousMode) 920 m_pLabelPromiscuousMode->setBuddy(m_pComboPromiscuousMode); 921 pLayout->addWidget(m_pComboPromiscuousMode, 1, 1, 1, 3); 922 } 923 924 /* Prepare MAC label: */ 925 m_pLabelMAC = new QLabel(m_pWidgetAdapterSettings); 926 if (m_pLabelMAC) 927 { 928 m_pLabelMAC->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 929 pLayout->addWidget(m_pLabelMAC, 2, 0); 930 } 931 /* Prepare MAC editor: */ 932 m_pEditorMAC = new QILineEdit(m_pWidgetAdapterSettings); 933 if (m_pEditorMAC) 934 { 935 if (m_pLabelMAC) 936 m_pLabelMAC->setBuddy(m_pEditorMAC); 937 m_pEditorMAC->setAllowToCopyContentsWhenDisabled(true); 938 m_pEditorMAC->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9A-Fa-f]{12}"), this)); 939 m_pEditorMAC->setMinimumWidthByText(QString().fill('0', 12)); 940 941 pLayout->addWidget(m_pEditorMAC, 2, 1, 1, 2); 942 } 943 /* Prepare MAC button: */ 944 m_pButtonMAC = new QIToolButton(m_pWidgetAdapterSettings); 945 if (m_pButtonMAC) 946 { 947 m_pButtonMAC->setIcon(UIIconPool::iconSet(":/refresh_16px.png")); 948 pLayout->addWidget(m_pButtonMAC, 2, 3); 949 } 950 951 /* Prepare MAC label: */ 952 m_pLabelGenericProperties = new QLabel(m_pWidgetAdapterSettings); 953 if (m_pLabelGenericProperties) 954 { 955 m_pLabelGenericProperties->setAlignment(Qt::AlignRight | Qt::AlignTop); 956 pLayout->addWidget(m_pLabelGenericProperties, 3, 0); 957 } 958 /* Prepare MAC editor: */ 959 m_pEditorGenericProperties = new QTextEdit(m_pWidgetAdapterSettings); 960 if (m_pEditorGenericProperties) 961 pLayout->addWidget(m_pEditorGenericProperties, 3, 1, 1, 3); 962 963 /* Prepare cable connected check-box: */ 964 m_pCheckBoxCableConnected = new QCheckBox(m_pWidgetAdapterSettings); 965 if (m_pCheckBoxCableConnected) 966 pLayout->addWidget(m_pCheckBoxCableConnected, 4, 1, 1, 2); 967 968 /* Prepare port forwarding button: */ 969 m_pButtonPortForwarding = new QPushButton(m_pWidgetAdapterSettings); 970 if (m_pButtonPortForwarding) 971 pLayout->addWidget(m_pButtonPortForwarding, 5, 1); 972 } 973 974 void UIMachineSettingsNetwork::populateComboboxes() 975 { 976 /* Adapter names: */ 977 { 978 reloadAlternatives(); 979 } 980 981 /* Adapter type: */ 982 { 983 /* Clear the adapter type combo-box: */ 984 m_pComboAdapterType->clear(); 985 986 /* Load currently supported network adapter types: */ 987 CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties(); 988 QVector<KNetworkAdapterType> supportedTypes = comProperties.GetSupportedNetworkAdapterTypes(); 989 /* Take currently requested type into account if it's sane: */ 990 if (!supportedTypes.contains(m_enmAdapterType) && m_enmAdapterType != KNetworkAdapterType_Null) 991 supportedTypes.prepend(m_enmAdapterType); 992 993 /* Populate adapter types: */ 994 int iAdapterTypeIndex = 0; 995 foreach (const KNetworkAdapterType &enmType, supportedTypes) 996 { 997 m_pComboAdapterType->insertItem(iAdapterTypeIndex, gpConverter->toString(enmType)); 998 m_pComboAdapterType->setItemData(iAdapterTypeIndex, QVariant::fromValue(enmType)); 999 m_pComboAdapterType->setItemData(iAdapterTypeIndex, m_pComboAdapterType->itemText(iAdapterTypeIndex), Qt::ToolTipRole); 1000 ++iAdapterTypeIndex; 1001 } 1002 1003 /* Choose requested adapter type: */ 1004 const int iIndex = m_pComboAdapterType->findData(m_enmAdapterType); 1005 m_pComboAdapterType->setCurrentIndex(iIndex != -1 ? iIndex : 0); 1006 } 1007 1008 /* Promiscuous Mode type: */ 1009 { 1010 /* Remember the currently selected promiscuous mode type: */ 1011 int iCurrentPromiscuousMode = m_pComboPromiscuousMode->currentIndex(); 1012 1013 /* Clear the promiscuous mode combo-box: */ 1014 m_pComboPromiscuousMode->clear(); 1015 1016 /* Populate promiscuous modes: */ 1017 int iPromiscuousModeIndex = 0; 1018 m_pComboPromiscuousMode->insertItem(iPromiscuousModeIndex, gpConverter->toString(KNetworkAdapterPromiscModePolicy_Deny)); 1019 m_pComboPromiscuousMode->setItemData(iPromiscuousModeIndex, KNetworkAdapterPromiscModePolicy_Deny); 1020 m_pComboPromiscuousMode->setItemData(iPromiscuousModeIndex, m_pComboPromiscuousMode->itemText(iPromiscuousModeIndex), Qt::ToolTipRole); 1021 ++iPromiscuousModeIndex; 1022 m_pComboPromiscuousMode->insertItem(iPromiscuousModeIndex, gpConverter->toString(KNetworkAdapterPromiscModePolicy_AllowNetwork)); 1023 m_pComboPromiscuousMode->setItemData(iPromiscuousModeIndex, KNetworkAdapterPromiscModePolicy_AllowNetwork); 1024 m_pComboPromiscuousMode->setItemData(iPromiscuousModeIndex, m_pComboPromiscuousMode->itemText(iPromiscuousModeIndex), Qt::ToolTipRole); 1025 ++iPromiscuousModeIndex; 1026 m_pComboPromiscuousMode->insertItem(iPromiscuousModeIndex, gpConverter->toString(KNetworkAdapterPromiscModePolicy_AllowAll)); 1027 m_pComboPromiscuousMode->setItemData(iPromiscuousModeIndex, KNetworkAdapterPromiscModePolicy_AllowAll); 1028 m_pComboPromiscuousMode->setItemData(iPromiscuousModeIndex, m_pComboPromiscuousMode->itemText(iPromiscuousModeIndex), Qt::ToolTipRole); 1029 ++iPromiscuousModeIndex; 1030 1031 /* Restore the previously selected promiscuous mode type: */ 1032 m_pComboPromiscuousMode->setCurrentIndex(iCurrentPromiscuousMode == -1 ? 0 : iCurrentPromiscuousMode); 1033 } 1034 } 1035 1036 void UIMachineSettingsNetwork::handleAdvancedButtonStateChange() 1037 { 1038 /* Update visibility of advanced options: */ 1039 m_pWidgetAdvancedSettings->setVisible(m_pButtonAdvanced->isExpanded()); 1040 } 1041 1042 /* static */ 1043 int UIMachineSettingsNetwork::position(QComboBox *pComboBox, int iData) 1044 { 1045 const int iPosition = pComboBox->findData(iData); 1046 return iPosition == -1 ? 0 : iPosition; 1047 } 1048 1049 /* static */ 1050 int UIMachineSettingsNetwork::position(QComboBox *pComboBox, const QString &strText) 1051 { 1052 const int iPosition = pComboBox->findText(strText); 1053 return iPosition == -1 ? 0 : iPosition; 670 connect(m_pEditorNetworkFeatures, &UIMachineNetworkFeaturesEditor::sigNotifyAdvancedButtonStateChange, 671 this, &UIMachineSettingsNetwork::sigNotifyAdvancedButtonStateChange); 672 connect(m_pEditorNetworkFeatures, &UIMachineNetworkFeaturesEditor::sigMACAddressChanged, 673 m_pParent, &UIMachineSettingsNetworkPage::revalidate); 674 connect(this, &UIMachineSettingsNetwork::sigTabUpdated, m_pParent, 675 &UIMachineSettingsNetworkPage::sltHandleTabUpdate); 1054 676 } 1055 677 … … 1063 685 , m_pCache(0) 1064 686 { 1065 /* Prepare: */1066 687 prepare(); 1067 688 } … … 1069 690 UIMachineSettingsNetworkPage::~UIMachineSettingsNetworkPage() 1070 691 { 1071 /* Cleanup: */1072 692 cleanup(); 1073 693 }
Note:
See TracChangeset
for help on using the changeset viewer.