Changeset 66681 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Apr 26, 2017 5:08:04 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 115072
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 1 added
- 11 edited
- 20 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r66628 r66681 175 175 ./src/extradata \ 176 176 ./src/globals \ 177 ./src/hostnetwork \ 177 178 ./src/medium \ 178 179 ./src/objects \ … … 340 341 src/globals/VBoxGlobal.h \ 341 342 src/globals/VBoxUtils.h \ 343 src/hostnetwork/UIHostNetworkDetailsDialog.h \ 344 src/hostnetwork/UIHostNetworkManager.h \ 342 345 src/medium/UIMediumEnumerator.h \ 343 346 src/medium/UIMediumManager.h \ … … 640 643 src/globals/UIThreadPool.cpp \ 641 644 src/globals/VBoxGlobal.cpp \ 645 src/hostnetwork/UIHostNetworkDetailsDialog.cpp \ 646 src/hostnetwork/UIHostNetworkManager.cpp \ 642 647 src/medium/UIMediumDefs.cpp \ 643 648 src/medium/UIMedium.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox1.qrc
r66369 r66681 3 3 <file alias="add_host_iface_16px.png">images/add_host_iface_16px.png</file> 4 4 <file alias="add_host_iface_disabled_16px.png">images/add_host_iface_disabled_16px.png</file> 5 <file alias="add_host_iface_22px.png">images/add_host_iface_22px.png</file> 6 <file alias="add_host_iface_disabled_22px.png">images/add_host_iface_disabled_22px.png</file> 5 7 <file alias="adjust_win_size_16px.png">images/adjust_win_size_16px.png</file> 6 8 <file alias="adjust_win_size_disabled_16px.png">images/adjust_win_size_disabled_16px.png</file> … … 84 86 <file alias="edit_host_iface_16px.png">images/edit_host_iface_16px.png</file> 85 87 <file alias="edit_host_iface_disabled_16px.png">images/edit_host_iface_disabled_16px.png</file> 88 <file alias="edit_host_iface_22px.png">images/edit_host_iface_22px.png</file> 89 <file alias="edit_host_iface_disabled_22px.png">images/edit_host_iface_disabled_22px.png</file> 86 90 <file alias="eraser_16px.png">images/eraser_16px.png</file> 87 91 <file alias="exit_16px.png">images/exit_16px.png</file> … … 165 169 <file alias="help_button_normal_mac_22px.png">images/help_button_normal_mac_22px.png</file> 166 170 <file alias="help_button_pressed_mac_22px.png">images/help_button_pressed_mac_22px.png</file> 171 <file alias="host_iface_manager_16px.png">images/host_iface_manager_16px.png</file> 172 <file alias="host_iface_manager_32px.png">images/host_iface_manager_32px.png</file> 167 173 <file alias="hostkey_16px.png">images/hostkey_16px.png</file> 168 174 <file alias="hostkey_24px.png">images/hostkey_24px.png</file> -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox1_hidpi.qrc
r66369 r66681 3 3 <file alias="add_host_iface_16px_hidpi.png">images/hidpi/add_host_iface_16px_hidpi.png</file> 4 4 <file alias="add_host_iface_disabled_16px_hidpi.png">images/hidpi/add_host_iface_disabled_16px_hidpi.png</file> 5 <file alias="add_host_iface_22px_hidpi.png">images/hidpi/add_host_iface_22px_hidpi.png</file> 6 <file alias="add_host_iface_disabled_22px_hidpi.png">images/hidpi/add_host_iface_disabled_22px_hidpi.png</file> 5 7 <file alias="adjust_win_size_16px_hidpi.png">images/hidpi/adjust_win_size_16px_hidpi.png</file> 6 8 <file alias="adjust_win_size_disabled_16px_hidpi.png">images/hidpi/adjust_win_size_disabled_16px_hidpi.png</file> … … 84 86 <file alias="edit_host_iface_16px_hidpi.png">images/hidpi/edit_host_iface_16px_hidpi.png</file> 85 87 <file alias="edit_host_iface_disabled_16px_hidpi.png">images/hidpi/edit_host_iface_disabled_16px_hidpi.png</file> 88 <file alias="edit_host_iface_22px_hidpi.png">images/hidpi/edit_host_iface_22px_hidpi.png</file> 89 <file alias="edit_host_iface_disabled_22px_hidpi.png">images/hidpi/edit_host_iface_disabled_22px_hidpi.png</file> 86 90 <file alias="eraser_16px_hidpi.png">images/hidpi/eraser_16px_hidpi.png</file> 87 91 <file alias="exit_16px_hidpi.png">images/hidpi/exit_16px_hidpi.png</file> … … 165 169 <file alias="help_button_normal_mac_22px_hidpi.png">images/hidpi/help_button_normal_mac_22px_hidpi.png</file> 166 170 <file alias="help_button_pressed_mac_22px_hidpi.png">images/hidpi/help_button_pressed_mac_22px_hidpi.png</file> 171 <file alias="host_iface_manager_16px_hidpi.png">images/hidpi/host_iface_manager_16px_hidpi.png</file> 172 <file alias="host_iface_manager_32px_hidpi.png">images/hidpi/host_iface_manager_32px_hidpi.png</file> 167 173 <file alias="hostkey_16px_hidpi.png">images/hidpi/hostkey_16px_hidpi.png</file> 168 174 <file alias="hostkey_24px_hidpi.png">images/hidpi/hostkey_24px_hidpi.png</file> -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox2.qrc
r66229 r66681 75 75 <file alias="remove_host_iface_16px.png">images/remove_host_iface_16px.png</file> 76 76 <file alias="remove_host_iface_disabled_16px.png">images/remove_host_iface_disabled_16px.png</file> 77 <file alias="remove_host_iface_22px.png">images/remove_host_iface_22px.png</file> 78 <file alias="remove_host_iface_disabled_22px.png">images/remove_host_iface_disabled_22px.png</file> 77 79 <file alias="reset_warnings_16px.png">images/reset_warnings_16px.png</file> 78 80 <file alias="restore_16px.png">images/restore_16px.png</file> -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox2_hidpi.qrc
r66229 r66681 84 84 <file alias="remove_host_iface_16px_hidpi.png">images/hidpi/remove_host_iface_16px_hidpi.png</file> 85 85 <file alias="remove_host_iface_disabled_16px_hidpi.png">images/hidpi/remove_host_iface_disabled_16px_hidpi.png</file> 86 <file alias="remove_host_iface_22px_hidpi.png">images/hidpi/remove_host_iface_22px_hidpi.png</file> 87 <file alias="remove_host_iface_disabled_22px_hidpi.png">images/hidpi/remove_host_iface_disabled_22px_hidpi.png</file> 86 88 <file alias="reset_warnings_16px_hidpi.png">images/hidpi/reset_warnings_16px_hidpi.png</file> 87 89 <file alias="restore_16px_hidpi.png">images/hidpi/restore_16px_hidpi.png</file> -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
r66677 r66681 986 986 } 987 987 988 bool UIMessageCenter::confirmHostOnlyInterfaceRemoval(const QString &strName, QWidget *pParent /* = 0 */) const989 {990 return questionBinary(pParent, MessageType_Question,991 tr("<p>Deleting this host-only network will remove "992 "the host-only interface this network is based on. Do you want to "993 "remove the (host-only network) interface <nobr><b>%1</b>?</nobr></p>"994 "<p><b>Note:</b> this interface may be in use by one or more "995 "virtual network adapters belonging to one of your VMs. "996 "After it is removed, these adapters will no longer be usable until "997 "you correct their settings by either choosing a different interface "998 "name or a different adapter attachment type.</p>")999 .arg(strName),1000 0 /* auto-confirm id */,1001 tr("Remove") /* ok button text */,1002 QString() /* cancel button text */,1003 false /* ok button by default? */);1004 }1005 1006 988 void UIMessageCenter::cannotCreateNATNetwork(const CVirtualBox &vbox, QWidget *pParent /* = 0*/) 1007 989 { … … 1017 999 .arg(strNetworkName), 1018 1000 formatErrorInfo(vbox)); 1019 }1020 1021 void UIMessageCenter::cannotCreateDHCPServer(const CVirtualBox &comVBox, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const1022 {1023 error(pParent, MessageType_Error,1024 tr("Failed to create a DHCP server for the network interface <b>%1</b>.")1025 .arg(strInterfaceName),1026 formatErrorInfo(comVBox));1027 }1028 1029 void UIMessageCenter::cannotRemoveDHCPServer(const CVirtualBox &comVBox, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const1030 {1031 error(pParent, MessageType_Error,1032 tr("Failed to remove the DHCP server for the network interface <b>%1</b>.")1033 .arg(strInterfaceName),1034 formatErrorInfo(comVBox));1035 }1036 1037 void UIMessageCenter::cannotCreateHostNetworkInterface(const CHost &comHost, QWidget *pParent /* = 0 */) const1038 {1039 error(pParent, MessageType_Error,1040 tr("Failed to create a host network interface."),1041 formatErrorInfo(comHost));1042 }1043 1044 void UIMessageCenter::cannotCreateHostNetworkInterface(const CProgress &comProgress, QWidget *pParent /* = 0 */) const1045 {1046 error(pParent, MessageType_Error,1047 tr("Failed to create a host network interface."),1048 formatErrorInfo(comProgress));1049 }1050 1051 void UIMessageCenter::cannotRemoveHostNetworkInterface(const CHost &comHost, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const1052 {1053 error(pParent, MessageType_Error,1054 tr("Failed to remove the host network interface <b>%1</b>.")1055 .arg(strInterfaceName),1056 formatErrorInfo(comHost));1057 }1058 1059 void UIMessageCenter::cannotRemoveHostNetworkInterface(const CProgress &comProgress, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const1060 {1061 error(pParent, MessageType_Error,1062 tr("Failed to remove the host network interface <b>%1</b>.")1063 .arg(strInterfaceName),1064 formatErrorInfo(comProgress));1065 1001 } 1066 1002 … … 1459 1395 error(pParent, MessageType_Error, 1460 1396 tr("Failed to close the disk image file <nobr><b>%1</b></nobr>.").arg(medium.location()), formatErrorInfo(rc)); 1397 } 1398 1399 bool UIMessageCenter::confirmHostOnlyInterfaceRemoval(const QString &strName, QWidget *pParent /* = 0 */) const 1400 { 1401 return questionBinary(pParent, MessageType_Question, 1402 tr("<p>Deleting this host-only network will remove " 1403 "the host-only interface this network is based on. Do you want to " 1404 "remove the (host-only network) interface <nobr><b>%1</b>?</nobr></p>" 1405 "<p><b>Note:</b> this interface may be in use by one or more " 1406 "virtual network adapters belonging to one of your VMs. " 1407 "After it is removed, these adapters will no longer be usable until " 1408 "you correct their settings by either choosing a different interface " 1409 "name or a different adapter attachment type.</p>") 1410 .arg(strName), 1411 0 /* auto-confirm id */, 1412 tr("Remove") /* ok button text */, 1413 QString() /* cancel button text */, 1414 false /* ok button by default? */); 1415 } 1416 1417 void UIMessageCenter::cannotAcquireHostNetworkInterfaces(const CHost &comHost, QWidget *pParent /* = 0 */) const 1418 { 1419 error(pParent, MessageType_Error, 1420 tr("Failed to acquire host network interfaces."), 1421 formatErrorInfo(comHost)); 1422 } 1423 1424 void UIMessageCenter::cannotFindHostNetworkInterface(const CHost &comHost, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const 1425 { 1426 error(pParent, MessageType_Error, 1427 tr("Unable to find the host network interface <b>%1</b>.") 1428 .arg(strInterfaceName), 1429 formatErrorInfo(comHost)); 1430 } 1431 1432 void UIMessageCenter::cannotCreateHostNetworkInterface(const CHost &comHost, QWidget *pParent /* = 0 */) const 1433 { 1434 error(pParent, MessageType_Error, 1435 tr("Failed to create a host network interface."), 1436 formatErrorInfo(comHost)); 1437 } 1438 1439 void UIMessageCenter::cannotCreateHostNetworkInterface(const CProgress &progress, QWidget *pParent /* = 0 */) const 1440 { 1441 error(pParent, MessageType_Error, 1442 tr("Failed to create a host network interface."), 1443 formatErrorInfo(progress)); 1444 } 1445 1446 void UIMessageCenter::cannotRemoveHostNetworkInterface(const CHost &comHost, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const 1447 { 1448 error(pParent, MessageType_Error, 1449 tr("Failed to remove the host network interface <b>%1</b>.") 1450 .arg(strInterfaceName), 1451 formatErrorInfo(comHost)); 1452 } 1453 1454 void UIMessageCenter::cannotRemoveHostNetworkInterface(const CProgress &progress, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const 1455 { 1456 error(pParent, MessageType_Error, 1457 tr("Failed to remove the host network interface <b>%1</b>.") 1458 .arg(strInterfaceName), 1459 formatErrorInfo(progress)); 1460 } 1461 1462 void UIMessageCenter::cannotAcquireHostNetworkInterfaceParameter(const CHostNetworkInterface &comInterface, QWidget *pParent /* = 0 */) const 1463 { 1464 error(pParent, MessageType_Error, 1465 tr("Failed to acquire host network interface parameter."), 1466 formatErrorInfo(comInterface)); 1467 } 1468 1469 void UIMessageCenter::cannotSaveHostNetworkInterfaceParameter(const CHostNetworkInterface &comInterface, QWidget *pParent /* = 0 */) const 1470 { 1471 error(pParent, MessageType_Error, 1472 tr("Failed to save host network interface parameter."), 1473 formatErrorInfo(comInterface)); 1474 } 1475 1476 void UIMessageCenter::cannotCreateDHCPServer(const CVirtualBox &comVBox, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const 1477 { 1478 error(pParent, MessageType_Error, 1479 tr("Failed to create a DHCP server for the network interface <b>%1</b>.") 1480 .arg(strInterfaceName), 1481 formatErrorInfo(comVBox)); 1482 } 1483 1484 void UIMessageCenter::cannotRemoveDHCPServer(const CVirtualBox &comVBox, const QString &strInterfaceName, QWidget *pParent /* = 0 */) const 1485 { 1486 error(pParent, MessageType_Error, 1487 tr("Failed to remove the DHCP server for the network interface <b>%1</b>.") 1488 .arg(strInterfaceName), 1489 formatErrorInfo(comVBox)); 1490 } 1491 1492 void UIMessageCenter::cannotAcquireDHCPServerParameter(const CDHCPServer &comServer, QWidget *pParent /* = 0 */) const 1493 { 1494 error(pParent, MessageType_Error, 1495 tr("Failed to acquire DHCP server parameter."), 1496 formatErrorInfo(comServer)); 1497 } 1498 1499 void UIMessageCenter::cannotSaveDHCPServerParameter(const CDHCPServer &comServer, QWidget *pParent /* = 0 */) const 1500 { 1501 error(pParent, MessageType_Error, 1502 tr("Failed to save DHCP server parameter."), 1503 formatErrorInfo(comServer)); 1461 1504 } 1462 1505 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
r66677 r66681 219 219 /* API: Global settings warnings: */ 220 220 bool confirmNATNetworkRemoval(const QString &strName, QWidget *pParent = 0) const; 221 bool confirmHostOnlyInterfaceRemoval(const QString &strName, QWidget *pParent = 0) const;222 221 void cannotCreateNATNetwork(const CVirtualBox &vbox, QWidget *pParent = 0); 223 222 void cannotRemoveNATNetwork(const CVirtualBox &vbox, const QString &strNetworkName, QWidget *pParent = 0); 224 void cannotCreateDHCPServer(const CVirtualBox &comVBox, const QString &strInterfaceName, QWidget *pParent = 0) const;225 void cannotRemoveDHCPServer(const CVirtualBox &comVBox, const QString &strInterfaceName, QWidget *pParent = 0) const;226 void cannotCreateHostNetworkInterface(const CHost &comHost, QWidget *pParent = 0) const;227 void cannotCreateHostNetworkInterface(const CProgress &comProgress, QWidget *pParent = 0) const;228 void cannotRemoveHostNetworkInterface(const CHost &comHost, const QString &strInterfaceName, QWidget *pParent = 0) const;229 void cannotRemoveHostNetworkInterface(const CProgress &comProgress, const QString &strInterfaceName, QWidget *pParent = 0) const;230 223 void cannotSetSystemProperties(const CSystemProperties &properties, QWidget *pParent = 0) const; 231 224 … … 258 251 void cannotOpenMedium(const CVirtualBox &vbox, UIMediumType type, const QString &strLocation, QWidget *pParent = 0) const; 259 252 void cannotCloseMedium(const UIMedium &medium, const COMResult &rc, QWidget *pParent = 0) const; 253 254 /* API: Host Network Manager warnings: */ 255 bool confirmHostOnlyInterfaceRemoval(const QString &strName, QWidget *pParent = 0) const; 256 void cannotAcquireHostNetworkInterfaces(const CHost &comHost, QWidget *pParent = 0) const; 257 void cannotFindHostNetworkInterface(const CHost &comHost, const QString &strInterfaceName, QWidget *pParent = 0) const; 258 void cannotCreateHostNetworkInterface(const CHost &comHost, QWidget *pParent = 0) const; 259 void cannotCreateHostNetworkInterface(const CProgress &progress, QWidget *pParent = 0) const; 260 void cannotRemoveHostNetworkInterface(const CHost &comHost, const QString &strInterfaceName, QWidget *pParent = 0) const; 261 void cannotRemoveHostNetworkInterface(const CProgress &progress, const QString &strInterfaceName, QWidget *pParent = 0) const; 262 void cannotAcquireHostNetworkInterfaceParameter(const CHostNetworkInterface &comInterface, QWidget *pParent = 0) const; 263 void cannotSaveHostNetworkInterfaceParameter(const CHostNetworkInterface &comInterface, QWidget *pParent = 0) const; 264 void cannotCreateDHCPServer(const CVirtualBox &comVBox, const QString &strInterfaceName, QWidget *pParent = 0) const; 265 void cannotRemoveDHCPServer(const CVirtualBox &comVBox, const QString &strInterfaceName, QWidget *pParent = 0) const; 266 void cannotAcquireDHCPServerParameter(const CDHCPServer &comServer, QWidget *pParent = 0) const; 267 void cannotSaveDHCPServerParameter(const CDHCPServer &comServer, QWidget *pParent = 0) const; 260 268 261 269 /* API: Wizards warnings: */ -
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkDetailsDialog.cpp
-
Property svn:keywords
changed from
Id Revision
toAuthor Date Id Revision
r66662 r66681 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI GlobalSettingsNetworkDetailsHostclass implementation.3 * VBox Qt GUI - UIHostNetworkDetailsDialog class implementation. 4 4 */ 5 5 … … 21 21 22 22 /* Qt includes: */ 23 # include <QCheckBox> 24 # include <QLabel> 23 25 # include <QRegExpValidator> 24 26 25 27 /* GUI includes: */ 28 # include "QIDialogButtonBox.h" 29 # include "QILineEdit.h" 26 30 # include "UIGlobalSettingsNetwork.h" 27 # include "UIGlobalSettingsNetworkDetailsHost.h" 31 # include "UIHostNetworkDetailsDialog.h" 32 # include "UIIconPool.h" 28 33 29 34 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 30 35 31 36 32 UI GlobalSettingsNetworkDetailsHost::UIGlobalSettingsNetworkDetailsHost(QWidget *pParent, UIDataSettingsGlobalNetworkHost&data)37 UIHostNetworkDetailsDialog::UIHostNetworkDetailsDialog(QWidget *pParent, UIDataHostNetwork &data) 33 38 : QIWithRetranslateUI2<QIDialog>(pParent) 34 39 , m_data(data) 35 40 { 36 /* Apply UI decorations: */ 37 Ui::UIGlobalSettingsNetworkDetailsHost::setupUi(this); 38 39 /* Setup dialog: */ 40 setWindowIcon(QIcon(":/guesttools_16px.png")); 41 42 /* Setup widgets */ 43 m_pIPv6Editor->setFixedWidthByText(QString().fill('X', 32) + QString().fill(':', 7)); 44 45 #if 0 /* defined (VBOX_WS_WIN) */ 46 QStyleOption options1; 47 options1.initFrom(m_pEnableManualCheckbox); 48 QGridLayout *playout1 = qobject_cast<QGridLayout*>(m_pDetailsTabWidget->widget(0)->layout()); 49 int iWid1 = m_pEnableManualCheckbox->style()->pixelMetric(QStyle::PM_IndicatorWidth, &options1, m_pEnableManualCheckbox) + 50 m_pEnableManualCheckbox->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &options1, m_pEnableManualCheckbox) - 51 playout1->spacing() - 1; 52 QSpacerItem *spacer1 = new QSpacerItem(iWid1, 0, QSizePolicy::Fixed, QSizePolicy::Fixed); 53 playout1->addItem(spacer1, 1, 0, 4); 54 #else 55 m_pEnableManualCheckbox->setVisible(false); 56 #endif 57 58 QStyleOption options2; 59 options2.initFrom(m_pEnabledDhcpServerCheckbox); 60 QGridLayout *pLayout2 = qobject_cast<QGridLayout*>(m_pDetailsTabWidget->widget(1)->layout()); 61 int wid2 = m_pEnabledDhcpServerCheckbox->style()->pixelMetric(QStyle::PM_IndicatorWidth, &options2, m_pEnabledDhcpServerCheckbox) + 62 m_pEnabledDhcpServerCheckbox->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &options2, m_pEnabledDhcpServerCheckbox) - 63 pLayout2->spacing() - 1; 64 QSpacerItem *pSpacer2 = new QSpacerItem(wid2, 0, QSizePolicy::Fixed, QSizePolicy::Fixed); 65 pLayout2->addItem(pSpacer2, 1, 0, 4); 66 67 /* Setup connections: */ 68 connect(m_pEnableManualCheckbox, SIGNAL(stateChanged(int)), this, SLOT (sltDhcpClientStatusChanged())); 69 connect(m_pEnabledDhcpServerCheckbox, SIGNAL(stateChanged (int)), this, SLOT(sltDhcpServerStatusChanged())); 41 /* Prepare: */ 42 prepare(); 43 } 44 45 void UIHostNetworkDetailsDialog::retranslateUi() 46 { 47 /* Translate this: */ 48 setWindowTitle(tr("Host Network Details")); 49 50 /* Translate tab-widget: */ 51 m_pTabWidget->setTabText(0, tr("&Adapter")); 52 m_pTabWidget->setTabText(1, tr("&DHCP Server")); 53 54 /* Translate 'Interface' tab content: */ 55 m_pLabelIPv4->setText(tr("&IPv4 Address:")); 56 m_pEditorIPv4->setToolTip(tr("Holds the host IPv4 address for this adapter.")); 57 m_pLabelNMv4->setText(tr("IPv4 Network &Mask:")); 58 m_pEditorNMv4->setToolTip(tr("Holds the host IPv4 network mask for this adapter.")); 59 m_pLabelIPv6->setText(tr("I&Pv6 Address:")); 60 m_pEditorIPv6->setToolTip(tr("Holds the host IPv6 address for this adapter if IPv6 is supported.")); 61 m_pLabelNMv6->setText(tr("IPv6 Network Mask &Length:")); 62 m_pEditorNMv6->setToolTip(tr("Holds the host IPv6 network mask prefix length for this adapter if IPv6 is supported.")); 63 64 /* Translate 'DHCP server' tab content: */ 65 m_pCheckBoxDHCP->setText(tr("&Enable Server")); 66 m_pCheckBoxDHCP->setToolTip(tr("When checked, the DHCP Server will be enabled for this network on machine start-up.")); 67 m_pLabelDHCPAddress->setText(tr("Server Add&ress:")); 68 m_pEditorDHCPAddress->setToolTip(tr("Holds the address of the DHCP server servicing the network associated with this host-only adapter.")); 69 m_pLabelDHCPMask->setText(tr("Server &Mask:")); 70 m_pEditorDHCPMask->setToolTip(tr("Holds the network mask of the DHCP server servicing the network associated with this host-only adapter.")); 71 m_pLabelDHCPLowerAddress->setText(tr("&Lower Address Bound:")); 72 m_pEditorDHCPLowerAddress->setToolTip(tr("Holds the lower address bound offered by the DHCP server servicing the network associated with this host-only adapter.")); 73 m_pLabelDHCPUpperAddress->setText(tr("&Upper Address Bound:")); 74 m_pEditorDHCPUpperAddress->setToolTip(tr("Holds the upper address bound offered by the DHCP server servicing the network associated with this host-only adapter.")); 75 } 76 77 void UIHostNetworkDetailsDialog::accept() 78 { 79 /* Save before accept: */ 80 save(); 81 82 /* Call to base-class: */ 83 QIDialog::accept(); 84 } 85 86 void UIHostNetworkDetailsDialog::prepare() 87 { 88 /* Prepare this: */ 89 prepareThis(); 70 90 71 91 /* Apply language settings: */ … … 74 94 /* Load: */ 75 95 load(); 76 77 /* Fix minimum possible size: */ 78 resize(minimumSizeHint()); 79 setFixedSize(minimumSizeHint()); 80 } 81 82 void UIGlobalSettingsNetworkDetailsHost::retranslateUi() 83 { 84 /* Translate uic generated strings: */ 85 Ui::UIGlobalSettingsNetworkDetailsHost::retranslateUi(this); 86 } 87 88 void UIGlobalSettingsNetworkDetailsHost::accept() 89 { 90 /* Save before accept: */ 91 save(); 92 /* Call to base-class: */ 93 QIDialog::accept(); 94 } 95 96 void UIGlobalSettingsNetworkDetailsHost::load() 97 { 98 /* Host Interface: */ 99 m_pEnableManualCheckbox->setChecked(!m_data.m_interface.m_fDhcpClientEnabled); 100 #if !0 /* !defined (VBOX_WS_WIN) */ 101 /* Disable automatic for all hosts for now: */ 102 m_pEnableManualCheckbox->setChecked(true); 103 m_pEnableManualCheckbox->setEnabled(false); 104 #endif 105 loadClientStuff(); 106 107 /* DHCP Server: */ 108 m_pEnabledDhcpServerCheckbox->setChecked(m_data.m_dhcpserver.m_fDhcpServerEnabled); 109 loadServerStuff(); 110 } 111 112 void UIGlobalSettingsNetworkDetailsHost::loadClientStuff() 113 { 114 /* Adjust network interface fields: */ 115 bool fIsManual = m_pEnableManualCheckbox->isChecked(); 116 bool fIsIpv6Supported = fIsManual && m_data.m_interface.m_fIpv6Supported; 117 118 m_pIPv4Editor->clear(); 119 m_pNMv4Editor->clear(); 120 m_pIPv6Editor->clear(); 121 m_pNMv6Editor->clear(); 122 123 m_pIPv4Label->setEnabled(fIsManual); 124 m_pNMv4Label->setEnabled(fIsManual); 125 m_pIPv4Editor->setEnabled(fIsManual); 126 m_pNMv4Editor->setEnabled(fIsManual); 127 m_pIPv6Label->setEnabled(fIsIpv6Supported); 128 m_pNMv6Label->setEnabled(fIsIpv6Supported); 129 m_pIPv6Editor->setEnabled(fIsIpv6Supported); 130 m_pNMv6Editor->setEnabled(fIsIpv6Supported); 131 96 } 97 98 void UIHostNetworkDetailsDialog::prepareThis() 99 { 100 /* Apply window icons: */ 101 setWindowIcon(UIIconPool::iconSetFull(":/edit_host_iface_22px.png", ":/edit_host_iface_16px.png")); 102 103 /* Create layout: */ 104 QVBoxLayout *pLayout = new QVBoxLayout(this); 105 AssertPtrReturnVoid(pLayout); 106 { 107 /* Prepare tab-widget: */ 108 prepareTabWidget(); 109 /* Prepare button-box: */ 110 prepareButtonBox(); 111 } 112 } 113 114 void UIHostNetworkDetailsDialog::prepareTabWidget() 115 { 116 /* Create tab-widget: */ 117 m_pTabWidget = new QITabWidget; 118 AssertPtrReturnVoid(m_pTabWidget); 119 { 120 /* Prepare 'Interface' tab: */ 121 prepareTabInterface(); 122 /* Prepare 'DHCP server' tab: */ 123 prepareTabDHCPServer(); 124 /* Add into layout: */ 125 layout()->addWidget(m_pTabWidget); 126 } 127 } 128 129 void UIHostNetworkDetailsDialog::prepareTabInterface() 130 { 131 /* Create 'Interface' tab: */ 132 QWidget *pTabInterface = new QWidget; 133 AssertPtrReturnVoid(pTabInterface); 134 { 135 /* Create 'Interface' layout: */ 136 QGridLayout *pLayoutInterface = new QGridLayout(pTabInterface); 137 AssertPtrReturnVoid(pLayoutInterface); 138 { 139 /* Create IPv4 address label: */ 140 m_pLabelIPv4 = new QLabel; 141 AssertPtrReturnVoid(m_pLabelIPv4); 142 { 143 /* Configure label: */ 144 m_pLabelIPv4->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 145 /* Add into layout: */ 146 pLayoutInterface->addWidget(m_pLabelIPv4, 0, 0); 147 } 148 /* Create IPv4 address editor: */ 149 m_pEditorIPv4 = new QILineEdit; 150 AssertPtrReturnVoid(m_pEditorIPv4); 151 { 152 /* Configure editor: */ 153 m_pLabelIPv4->setBuddy(m_pEditorIPv4); 154 /* Add into layout: */ 155 pLayoutInterface->addWidget(m_pEditorIPv4, 0, 1); 156 } 157 /* Create IPv4 network mask label: */ 158 m_pLabelNMv4 = new QLabel; 159 AssertPtrReturnVoid(m_pLabelNMv4); 160 { 161 /* Configure label: */ 162 m_pLabelNMv4->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 163 /* Add into layout: */ 164 pLayoutInterface->addWidget(m_pLabelNMv4, 1, 0); 165 } 166 /* Create IPv4 network mask editor: */ 167 m_pEditorNMv4 = new QILineEdit; 168 AssertPtrReturnVoid(m_pEditorNMv4); 169 { 170 /* Configure editor: */ 171 m_pLabelNMv4->setBuddy(m_pEditorNMv4); 172 /* Add into layout: */ 173 pLayoutInterface->addWidget(m_pEditorNMv4, 1, 1); 174 } 175 /* Create IPv6 address label: */ 176 m_pLabelIPv6 = new QLabel; 177 AssertPtrReturnVoid(m_pLabelIPv6); 178 { 179 /* Configure label: */ 180 m_pLabelIPv6->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 181 /* Add into layout: */ 182 pLayoutInterface->addWidget(m_pLabelIPv6, 2, 0); 183 } 184 /* Create IPv6 address editor: */ 185 m_pEditorIPv6 = new QILineEdit; 186 AssertPtrReturnVoid(m_pEditorIPv6); 187 { 188 /* Configure editor: */ 189 m_pLabelIPv6->setBuddy(m_pEditorIPv6); 190 m_pEditorIPv6->setFixedWidthByText(QString().fill('X', 32) + QString().fill(':', 7)); 191 /* Add into layout: */ 192 pLayoutInterface->addWidget(m_pEditorIPv6, 2, 1); 193 } 194 /* Create IPv6 network mask label: */ 195 m_pLabelNMv6 = new QLabel; 196 AssertPtrReturnVoid(m_pLabelNMv6); 197 { 198 /* Configure label: */ 199 m_pLabelNMv6->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 200 /* Add into layout: */ 201 pLayoutInterface->addWidget(m_pLabelNMv6, 3, 0); 202 } 203 /* Create IPv6 network mask editor: */ 204 m_pEditorNMv6 = new QILineEdit; 205 AssertPtrReturnVoid(m_pEditorNMv6); 206 { 207 /* Configure editor: */ 208 m_pLabelNMv6->setBuddy(m_pEditorNMv6); 209 /* Add into layout: */ 210 pLayoutInterface->addWidget(m_pEditorNMv6, 3, 1); 211 } 212 /* Create stretch: */ 213 QSpacerItem *pSpacer1 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); 214 AssertPtrReturnVoid(pSpacer1); 215 { 216 /* Add into layout: */ 217 pLayoutInterface->addItem(pSpacer1, 4, 0, 1, 2); 218 } 219 } 220 /* Add to tab-widget: */ 221 m_pTabWidget->addTab(pTabInterface, QString()); 222 } 223 } 224 225 void UIHostNetworkDetailsDialog::prepareTabDHCPServer() 226 { 227 /* Create 'DHCP server' tab: */ 228 QWidget *pTabDHCPServer = new QWidget; 229 AssertPtrReturnVoid(pTabDHCPServer); 230 { 231 /* Create 'DHCP server' layout: */ 232 QGridLayout *pLayoutDHCPServer = new QGridLayout(pTabDHCPServer); 233 AssertPtrReturnVoid(pLayoutDHCPServer); 234 { 235 /* Create DHCP server status check-box: */ 236 m_pCheckBoxDHCP = new QCheckBox; 237 AssertPtrReturnVoid(m_pCheckBoxDHCP); 238 { 239 /* Configure check-box: */ 240 connect(m_pCheckBoxDHCP, SIGNAL(stateChanged(int)), this, SLOT(sltDhcpServerStatusChanged())); 241 /* Add into layout: */ 242 pLayoutDHCPServer->addWidget(m_pCheckBoxDHCP, 0, 0, 1, 3); 243 } 244 /* Create DHCP address label: */ 245 m_pLabelDHCPAddress = new QLabel; 246 AssertPtrReturnVoid(m_pLabelDHCPAddress); 247 { 248 /* Configure label: */ 249 m_pLabelDHCPAddress->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 250 /* Add into layout: */ 251 pLayoutDHCPServer->addWidget(m_pLabelDHCPAddress, 1, 1); 252 } 253 /* Create DHCP address editor: */ 254 m_pEditorDHCPAddress = new QILineEdit; 255 AssertPtrReturnVoid(m_pEditorDHCPAddress); 256 { 257 /* Configure editor: */ 258 m_pLabelDHCPAddress->setBuddy(m_pEditorDHCPAddress); 259 /* Add into layout: */ 260 pLayoutDHCPServer->addWidget(m_pEditorDHCPAddress, 1, 2); 261 } 262 /* Create DHCP network mask label: */ 263 m_pLabelDHCPMask = new QLabel; 264 AssertPtrReturnVoid(m_pLabelDHCPMask); 265 { 266 /* Configure label: */ 267 m_pLabelDHCPMask->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 268 /* Add into layout: */ 269 pLayoutDHCPServer->addWidget(m_pLabelDHCPMask, 2, 1); 270 } 271 /* Create DHCP network mask editor: */ 272 m_pEditorDHCPMask = new QILineEdit; 273 AssertPtrReturnVoid(m_pEditorDHCPMask); 274 { 275 /* Configure editor: */ 276 m_pLabelDHCPMask->setBuddy(m_pEditorDHCPMask); 277 /* Add into layout: */ 278 pLayoutDHCPServer->addWidget(m_pEditorDHCPMask, 2, 2); 279 } 280 /* Create DHCP lower address label: */ 281 m_pLabelDHCPLowerAddress = new QLabel; 282 AssertPtrReturnVoid(m_pLabelDHCPLowerAddress); 283 { 284 /* Configure label: */ 285 m_pLabelDHCPLowerAddress->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 286 /* Add into layout: */ 287 pLayoutDHCPServer->addWidget(m_pLabelDHCPLowerAddress, 3, 1); 288 } 289 /* Create DHCP lower address editor: */ 290 m_pEditorDHCPLowerAddress = new QILineEdit; 291 AssertPtrReturnVoid(m_pEditorDHCPLowerAddress); 292 { 293 /* Configure editor: */ 294 m_pLabelDHCPLowerAddress->setBuddy(m_pEditorDHCPLowerAddress); 295 /* Add into layout: */ 296 pLayoutDHCPServer->addWidget(m_pEditorDHCPLowerAddress, 3, 2); 297 } 298 /* Create DHCP upper address label: */ 299 m_pLabelDHCPUpperAddress = new QLabel; 300 AssertPtrReturnVoid(m_pLabelDHCPUpperAddress); 301 { 302 /* Configure label: */ 303 m_pLabelDHCPUpperAddress->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 304 /* Add into layout: */ 305 pLayoutDHCPServer->addWidget(m_pLabelDHCPUpperAddress, 4, 1); 306 } 307 /* Create DHCP upper address editor: */ 308 m_pEditorDHCPUpperAddress = new QILineEdit; 309 AssertPtrReturnVoid(m_pEditorDHCPUpperAddress); 310 { 311 /* Configure editor: */ 312 m_pLabelDHCPUpperAddress->setBuddy(m_pEditorDHCPUpperAddress); 313 /* Add into layout: */ 314 pLayoutDHCPServer->addWidget(m_pEditorDHCPUpperAddress, 4, 2); 315 } 316 /* Create indent: */ 317 QStyleOption options; 318 options.initFrom(m_pCheckBoxDHCP); 319 const int iWidth2 = m_pCheckBoxDHCP->style()->pixelMetric(QStyle::PM_IndicatorWidth, &options, m_pCheckBoxDHCP) + 320 m_pCheckBoxDHCP->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &options, m_pCheckBoxDHCP) - 321 pLayoutDHCPServer->spacing() - 1; 322 QSpacerItem *pSpacer2 = new QSpacerItem(iWidth2, 0, QSizePolicy::Fixed, QSizePolicy::Expanding); 323 AssertPtrReturnVoid(pSpacer2); 324 { 325 /* Add into layout: */ 326 pLayoutDHCPServer->addItem(pSpacer2, 1, 0, 4); 327 } 328 /* Create stretch: */ 329 QSpacerItem *pSpacer3 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); 330 AssertPtrReturnVoid(pSpacer3); 331 { 332 /* Add into layout: */ 333 pLayoutDHCPServer->addItem(pSpacer3, 5, 0, 1, 3); 334 } 335 } 336 /* Add to tab-widget: */ 337 m_pTabWidget->addTab(pTabDHCPServer, QString()); 338 } 339 } 340 341 void UIHostNetworkDetailsDialog::prepareButtonBox() 342 { 343 /* Create dialog button-box: */ 344 QIDialogButtonBox *pButtonBox = new QIDialogButtonBox; 345 AssertPtrReturnVoid(pButtonBox); 346 { 347 /* Configure button-box: */ 348 pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 349 connect(pButtonBox, SIGNAL(accepted()), this, SLOT(accept())); 350 connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject())); 351 /* Add button-box into layout: */ 352 layout()->addWidget(pButtonBox); 353 } 354 } 355 356 void UIHostNetworkDetailsDialog::load() 357 { 358 /* Load 'Interface' data: */ 359 loadDataForInterface(); 360 361 /* Load 'DHCP server' data: */ 362 m_pCheckBoxDHCP->setChecked(m_data.m_dhcpserver.m_fDhcpServerEnabled); 363 loadDataForDHCPServer(); 364 } 365 366 void UIHostNetworkDetailsDialog::loadDataForInterface() 367 { 368 /* IPv4 fields: */ 369 m_pEditorIPv4->setText(m_data.m_interface.m_strInterfaceAddress); 370 m_pEditorNMv4->setText(m_data.m_interface.m_strInterfaceMask); 371 372 /* IPv6 fields: */ 373 const bool fIsIpv6Supported = m_data.m_interface.m_fIpv6Supported; 374 m_pLabelIPv6->setEnabled(fIsIpv6Supported); 375 m_pLabelNMv6->setEnabled(fIsIpv6Supported); 376 m_pEditorIPv6->setEnabled(fIsIpv6Supported); 377 m_pEditorNMv6->setEnabled(fIsIpv6Supported); 378 if (fIsIpv6Supported) 379 { 380 /* Load old values: */ 381 m_pEditorIPv6->setText(m_data.m_interface.m_strInterfaceAddress6); 382 m_pEditorNMv6->setText(m_data.m_interface.m_strInterfaceMaskLength6); 383 } 384 } 385 386 void UIHostNetworkDetailsDialog::loadDataForDHCPServer() 387 { 388 /* DHCP server fields: */ 389 const bool fIsManual = m_pCheckBoxDHCP->isChecked(); 390 m_pLabelDHCPAddress->setEnabled(fIsManual); 391 m_pLabelDHCPMask->setEnabled(fIsManual); 392 m_pLabelDHCPLowerAddress->setEnabled(fIsManual); 393 m_pLabelDHCPUpperAddress->setEnabled(fIsManual); 394 m_pEditorDHCPAddress->setEnabled(fIsManual); 395 m_pEditorDHCPMask->setEnabled(fIsManual); 396 m_pEditorDHCPLowerAddress->setEnabled(fIsManual); 397 m_pEditorDHCPUpperAddress->setEnabled(fIsManual); 132 398 if (fIsManual) 133 399 { 134 m_pIPv4Editor->setText(m_data.m_interface.m_strInterfaceAddress); 135 m_pNMv4Editor->setText(m_data.m_interface.m_strInterfaceMask); 136 if (fIsIpv6Supported) 137 { 138 m_pIPv6Editor->setText(m_data.m_interface.m_strInterfaceAddress6); 139 m_pNMv6Editor->setText(m_data.m_interface.m_strInterfaceMaskLength6); 140 } 141 } 142 } 143 144 void UIGlobalSettingsNetworkDetailsHost::loadServerStuff() 145 { 146 /* Adjust dhcp server fields: */ 147 bool fIsManual = m_pEnabledDhcpServerCheckbox->isChecked(); 148 149 m_pDhcpAddressEditor->clear(); 150 m_pDhcpMaskEditor->clear(); 151 m_pDhcpLowerAddressEditor->clear(); 152 m_pDhcpUpperAddressEditor->clear(); 153 154 m_pDhcpAddressLabel->setEnabled(fIsManual); 155 m_pDhcpMaskLabel->setEnabled(fIsManual); 156 m_pDhcpLowerAddressLabel->setEnabled(fIsManual); 157 m_pDhcpUpperAddressLabel->setEnabled(fIsManual); 158 m_pDhcpAddressEditor->setEnabled(fIsManual); 159 m_pDhcpMaskEditor->setEnabled(fIsManual); 160 m_pDhcpLowerAddressEditor->setEnabled(fIsManual); 161 m_pDhcpUpperAddressEditor->setEnabled(fIsManual); 162 163 if (fIsManual) 164 { 165 /* Load values from COM wrappers: */ 166 m_pDhcpAddressEditor->setText(m_data.m_dhcpserver.m_strDhcpServerAddress); 167 m_pDhcpMaskEditor->setText(m_data.m_dhcpserver.m_strDhcpServerMask); 168 m_pDhcpLowerAddressEditor->setText(m_data.m_dhcpserver.m_strDhcpLowerAddress); 169 m_pDhcpUpperAddressEditor->setText(m_data.m_dhcpserver.m_strDhcpUpperAddress); 400 /* Load old values: */ 401 m_pEditorDHCPAddress->setText(m_data.m_dhcpserver.m_strDhcpServerAddress); 402 m_pEditorDHCPMask->setText(m_data.m_dhcpserver.m_strDhcpServerMask); 403 m_pEditorDHCPLowerAddress->setText(m_data.m_dhcpserver.m_strDhcpLowerAddress); 404 m_pEditorDHCPUpperAddress->setText(m_data.m_dhcpserver.m_strDhcpUpperAddress); 170 405 171 406 /* Invent default values where necessary: */ … … 180 415 if ( m_data.m_dhcpserver.m_strDhcpServerAddress.isEmpty() 181 416 || m_data.m_dhcpserver.m_strDhcpServerAddress == "0.0.0.0") 182 m_p DhcpAddressEditor->setText(strProp);417 m_pEditorDHCPAddress->setText(strProp); 183 418 if ( m_data.m_dhcpserver.m_strDhcpServerMask.isEmpty() 184 419 || m_data.m_dhcpserver.m_strDhcpServerMask == "0.0.0.0") 185 m_p DhcpMaskEditor->setText(strMask);420 m_pEditorDHCPMask->setText(strMask); 186 421 if ( m_data.m_dhcpserver.m_strDhcpLowerAddress.isEmpty() 187 422 || m_data.m_dhcpserver.m_strDhcpLowerAddress == "0.0.0.0") 188 m_p DhcpLowerAddressEditor->setText(strProp);423 m_pEditorDHCPLowerAddress->setText(strProp); 189 424 if ( m_data.m_dhcpserver.m_strDhcpUpperAddress.isEmpty() 190 425 || m_data.m_dhcpserver.m_strDhcpUpperAddress == "0.0.0.0") 191 m_pDhcpUpperAddressEditor->setText(strProp); 192 } 193 } 194 195 void UIGlobalSettingsNetworkDetailsHost::save() 196 { 197 /* Host Interface: */ 198 m_data.m_interface.m_fDhcpClientEnabled = !m_pEnableManualCheckbox->isChecked(); 199 if (m_pEnableManualCheckbox->isChecked()) 200 { 201 m_data.m_interface.m_strInterfaceAddress = m_pIPv4Editor->text(); 202 m_data.m_interface.m_strInterfaceMask = m_pNMv4Editor->text(); 203 if (m_data.m_interface.m_fIpv6Supported) 204 { 205 m_data.m_interface.m_strInterfaceAddress6 = m_pIPv6Editor->text(); 206 m_data.m_interface.m_strInterfaceMaskLength6 = m_pNMv6Editor->text(); 207 } 208 } 209 210 /* DHCP Server: */ 211 m_data.m_dhcpserver.m_fDhcpServerEnabled = m_pEnabledDhcpServerCheckbox->isChecked(); 212 if (m_pEnabledDhcpServerCheckbox->isChecked()) 213 { 214 m_data.m_dhcpserver.m_strDhcpServerAddress = m_pDhcpAddressEditor->text(); 215 m_data.m_dhcpserver.m_strDhcpServerMask = m_pDhcpMaskEditor->text(); 216 m_data.m_dhcpserver.m_strDhcpLowerAddress = m_pDhcpLowerAddressEditor->text(); 217 m_data.m_dhcpserver.m_strDhcpUpperAddress = m_pDhcpUpperAddressEditor->text(); 426 m_pEditorDHCPUpperAddress->setText(strProp); 427 } 428 else 429 { 430 m_pEditorDHCPAddress->clear(); 431 m_pEditorDHCPMask->clear(); 432 m_pEditorDHCPLowerAddress->clear(); 433 m_pEditorDHCPUpperAddress->clear(); 434 } 435 } 436 437 void UIHostNetworkDetailsDialog::save() 438 { 439 /* Interface data: */ 440 m_data.m_interface.m_strInterfaceAddress = m_pEditorIPv4->text(); 441 m_data.m_interface.m_strInterfaceMask = m_pEditorNMv4->text(); 442 if (m_data.m_interface.m_fIpv6Supported) 443 { 444 m_data.m_interface.m_strInterfaceAddress6 = m_pEditorIPv6->text(); 445 m_data.m_interface.m_strInterfaceMaskLength6 = m_pEditorNMv6->text(); 446 } 447 448 /* Server data: */ 449 m_data.m_dhcpserver.m_fDhcpServerEnabled = m_pCheckBoxDHCP->isChecked(); 450 if (m_data.m_dhcpserver.m_fDhcpServerEnabled) 451 { 452 m_data.m_dhcpserver.m_strDhcpServerAddress = m_pEditorDHCPAddress->text(); 453 m_data.m_dhcpserver.m_strDhcpServerMask = m_pEditorDHCPMask->text(); 454 m_data.m_dhcpserver.m_strDhcpLowerAddress = m_pEditorDHCPLowerAddress->text(); 455 m_data.m_dhcpserver.m_strDhcpUpperAddress = m_pEditorDHCPUpperAddress->text(); 218 456 } 219 457 } 220 458 221 459 /* static */ 222 quint32 UI GlobalSettingsNetworkDetailsHost::ipv4FromQStringToQuint32(const QString &strAddress)460 quint32 UIHostNetworkDetailsDialog::ipv4FromQStringToQuint32(const QString &strAddress) 223 461 { 224 462 quint32 uAddress = 0; … … 235 473 236 474 /* static */ 237 QString UI GlobalSettingsNetworkDetailsHost::ipv4FromQuint32ToQString(quint32 uAddress)475 QString UIHostNetworkDetailsDialog::ipv4FromQuint32ToQString(quint32 uAddress) 238 476 { 239 477 QStringList address; -
Property svn:keywords
changed from
-
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkDetailsDialog.h
-
Property svn:keywords
set to
Author Date Id Revision
r66662 r66681 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI GlobalSettingsNetworkDetailsHostclass declaration.3 * VBox Qt GUI - UIHostNetworkDetailsDialog class declaration. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 6Oracle Corporation7 * Copyright (C) 2009-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __UI GlobalSettingsNetworkDetailsHost_h__19 #define __UI GlobalSettingsNetworkDetailsHost_h__18 #ifndef __UIHostNetworkDetailsDialog_h__ 19 #define __UIHostNetworkDetailsDialog_h__ 20 20 21 21 /* GUI includes: */ 22 22 #include "QIDialog.h" 23 23 #include "QIWithRetranslateUI.h" 24 #include "UIGlobalSettingsNetworkDetailsHost.gen.h" 25 26 27 /** Global settings: Network page: Host interface data structure. */ 28 struct UIDataSettingsGlobalNetworkHostInterface 24 25 /* Forward declarations: */ 26 class QCheckBox; 27 class QLabel; 28 class QILineEdit; 29 class QITabWidget; 30 31 32 /** Host Network Manager: Host Network Interface data structure. */ 33 struct UIDataHostNetworkInterface 29 34 { 30 35 /** Constructs data. */ 31 UIData SettingsGlobalNetworkHostInterface()36 UIDataHostNetworkInterface() 32 37 : m_strName(QString()) 33 , m_fDhcpClientEnabled(false)34 38 , m_strInterfaceAddress(QString()) 35 39 , m_strInterfaceMask(QString()) … … 40 44 41 45 /** Returns whether the @a other passed data is equal to this one. */ 42 bool equal(const UIData SettingsGlobalNetworkHostInterface &other) const46 bool equal(const UIDataHostNetworkInterface &other) const 43 47 { 44 48 return true 45 49 && (m_strName == other.m_strName) 46 && (m_fDhcpClientEnabled == other.m_fDhcpClientEnabled)47 50 && (m_strInterfaceAddress == other.m_strInterfaceAddress) 48 51 && (m_strInterfaceMask == other.m_strInterfaceMask) … … 54 57 55 58 /** Returns whether the @a other passed data is equal to this one. */ 56 bool operator==(const UIData SettingsGlobalNetworkHostInterface &other) const { return equal(other); }59 bool operator==(const UIDataHostNetworkInterface &other) const { return equal(other); } 57 60 /** Returns whether the @a other passed data is different from this one. */ 58 bool operator!=(const UIData SettingsGlobalNetworkHostInterface &other) const { return !equal(other); }61 bool operator!=(const UIDataHostNetworkInterface &other) const { return !equal(other); } 59 62 60 63 /** Holds host interface name. */ 61 64 QString m_strName; 62 /** Holds whether DHCP client enabled. */63 bool m_fDhcpClientEnabled;64 65 /** Holds IPv4 interface address. */ 65 66 QString m_strInterfaceAddress; … … 75 76 76 77 77 /** Global settings: Network page: DHCP server data structure. */78 struct UIData SettingsGlobalNetworkDHCPServer78 /** Host Network Manager: DHCP Server data structure. */ 79 struct UIDataDHCPServer 79 80 { 80 81 /** Constructs data. */ 81 UIData SettingsGlobalNetworkDHCPServer()82 UIDataDHCPServer() 82 83 : m_fDhcpServerEnabled(false) 83 84 , m_strDhcpServerAddress(QString()) … … 88 89 89 90 /** Returns whether the @a other passed data is equal to this one. */ 90 bool equal(const UIData SettingsGlobalNetworkDHCPServer &other) const91 bool equal(const UIDataDHCPServer &other) const 91 92 { 92 93 return true … … 100 101 101 102 /** Returns whether the @a other passed data is equal to this one. */ 102 bool operator==(const UIData SettingsGlobalNetworkDHCPServer &other) const { return equal(other); }103 bool operator==(const UIDataDHCPServer &other) const { return equal(other); } 103 104 /** Returns whether the @a other passed data is different from this one. */ 104 bool operator!=(const UIData SettingsGlobalNetworkDHCPServer &other) const { return !equal(other); }105 bool operator!=(const UIDataDHCPServer &other) const { return !equal(other); } 105 106 106 107 /** Holds whether DHCP server enabled. */ … … 117 118 118 119 119 /** Global settings: Network page: Host network data structure. */120 struct UIData SettingsGlobalNetworkHost120 /** Host Network Manager: Host network data structure. */ 121 struct UIDataHostNetwork 121 122 { 122 123 /** Constructs data. */ 123 UIData SettingsGlobalNetworkHost()124 : m_interface(UIData SettingsGlobalNetworkHostInterface())125 , m_dhcpserver(UIData SettingsGlobalNetworkDHCPServer())124 UIDataHostNetwork() 125 : m_interface(UIDataHostNetworkInterface()) 126 , m_dhcpserver(UIDataDHCPServer()) 126 127 {} 127 128 128 129 /** Returns whether the @a other passed data is equal to this one. */ 129 bool equal(const UIData SettingsGlobalNetworkHost&other) const130 bool equal(const UIDataHostNetwork &other) const 130 131 { 131 132 return true … … 136 137 137 138 /** Returns whether the @a other passed data is equal to this one. */ 138 bool operator==(const UIData SettingsGlobalNetworkHost&other) const { return equal(other); }139 bool operator==(const UIDataHostNetwork &other) const { return equal(other); } 139 140 /** Returns whether the @a other passed data is different from this one. */ 140 bool operator!=(const UIData SettingsGlobalNetworkHost&other) const { return !equal(other); }141 142 /** Holds the hostinterface data. */143 UIData SettingsGlobalNetworkHostInterface m_interface;141 bool operator!=(const UIDataHostNetwork &other) const { return !equal(other); } 142 143 /** Holds the interface data. */ 144 UIDataHostNetworkInterface m_interface; 144 145 /** Holds the DHCP server data. */ 145 UIData SettingsGlobalNetworkDHCPServer m_dhcpserver;146 }; 147 148 149 /* Global settings / Network page / Details sub-dialog:*/150 class UI GlobalSettingsNetworkDetailsHost : public QIWithRetranslateUI2<QIDialog>, public Ui::UIGlobalSettingsNetworkDetailsHost146 UIDataDHCPServer m_dhcpserver; 147 }; 148 149 150 /** Host Network Manager: Host network details dialog. */ 151 class UIHostNetworkDetailsDialog : public QIWithRetranslateUI2<QIDialog> 151 152 { 152 153 Q_OBJECT; … … 154 155 public: 155 156 156 /* Constructor:*/157 UI GlobalSettingsNetworkDetailsHost(QWidget *pParent, UIDataSettingsGlobalNetworkHost&data);157 /** Constructs host network details dialog for the passed @a pParent and @a data. */ 158 UIHostNetworkDetailsDialog(QWidget *pParent, UIDataHostNetwork &data); 158 159 159 160 protected: 160 161 161 /* Handler: Translation stuff:*/162 v oid retranslateUi();162 /** Handles translation event. */ 163 virtual void retranslateUi() /* override */; 163 164 164 165 private slots: 165 166 166 /* Handlers: [Re]load stuff: */ 167 void sltDhcpClientStatusChanged() { loadClientStuff(); } 168 void sltDhcpServerStatusChanged() { loadServerStuff(); } 169 170 /* Handler: Dialog stuff: */ 167 /** Handles DHCP server status change. */ 168 void sltDhcpServerStatusChanged() { loadDataForDHCPServer(); } 169 170 /** Accepts dialog changes. */ 171 171 void accept(); 172 172 173 173 private: 174 174 175 /* Helpers: Load/Save stuff: */ 176 void load(); 177 void loadClientStuff(); 178 void loadServerStuff(); 179 void save(); 180 181 /** Converts IPv4 address from QString to quint32. */ 182 static quint32 ipv4FromQStringToQuint32(const QString &strAddress); 183 /** Converts IPv4 address from quint32 to QString. */ 184 static QString ipv4FromQuint32ToQString(quint32 uAddress); 185 186 /* Variable: External data reference: */ 187 UIDataSettingsGlobalNetworkHost &m_data; 188 }; 189 190 #endif /* __UIGlobalSettingsNetworkDetailsHost_h__ */ 175 /** @name Prepare/cleanup cascade. 176 * @{ */ 177 /** Prepares all. */ 178 void prepare(); 179 /** Prepares this. */ 180 void prepareThis(); 181 /** Prepares tab-widget. */ 182 void prepareTabWidget(); 183 /** Prepares 'Interface' tab. */ 184 void prepareTabInterface(); 185 /** Prepares 'DHCP server' tab. */ 186 void prepareTabDHCPServer(); 187 /** Prepares button-box. */ 188 void prepareButtonBox(); 189 /** @} */ 190 191 /** @name Loading/saving stuff. 192 * @{ */ 193 /** Loads data. */ 194 void load(); 195 /** Loads interface data. */ 196 void loadDataForInterface(); 197 /** Loads server data. */ 198 void loadDataForDHCPServer(); 199 /** Saves data. */ 200 void save(); 201 /** @} */ 202 203 /** @name Helpers. 204 * @{ */ 205 /** Converts IPv4 address from QString to quint32. */ 206 static quint32 ipv4FromQStringToQuint32(const QString &strAddress); 207 /** Converts IPv4 address from quint32 to QString. */ 208 static QString ipv4FromQuint32ToQString(quint32 uAddress); 209 /** @} */ 210 211 /** @name General variables. 212 * @{ */ 213 /** Holds the external data reference. */ 214 UIDataHostNetwork &m_data; 215 /** Holds the tab-widget. */ 216 QITabWidget *m_pTabWidget; 217 /** @} */ 218 219 /** @name Interface variables. 220 * @{ */ 221 /** Holds the IPv4 address label. */ 222 QLabel *m_pLabelIPv4; 223 /** Holds the IPv4 address editor. */ 224 QILineEdit *m_pEditorIPv4; 225 /** Holds the IPv4 network mask label. */ 226 QLabel *m_pLabelNMv4; 227 /** Holds the IPv4 network mask editor. */ 228 QILineEdit *m_pEditorNMv4; 229 /** Holds the IPv6 address label. */ 230 QLabel *m_pLabelIPv6; 231 /** Holds the IPv6 address editor. */ 232 QILineEdit *m_pEditorIPv6; 233 /** Holds the IPv6 network mask label. */ 234 QLabel *m_pLabelNMv6; 235 /** Holds the IPv6 network mask editor. */ 236 QILineEdit *m_pEditorNMv6; 237 /** @} */ 238 239 /** @name DHCP server variables. 240 * @{ */ 241 /** Holds the DHCP server status chack-box. */ 242 QCheckBox *m_pCheckBoxDHCP; 243 /** Holds the DHCP address label. */ 244 QLabel *m_pLabelDHCPAddress; 245 /** Holds the DHCP address editor. */ 246 QILineEdit *m_pEditorDHCPAddress; 247 /** Holds the DHCP network mask label. */ 248 QLabel *m_pLabelDHCPMask; 249 /** Holds the DHCP network mask editor. */ 250 QILineEdit *m_pEditorDHCPMask; 251 /** Holds the DHCP lower address label. */ 252 QLabel *m_pLabelDHCPLowerAddress; 253 /** Holds the DHCP lower address editor. */ 254 QILineEdit *m_pEditorDHCPLowerAddress; 255 /** Holds the DHCP upper address label. */ 256 QLabel *m_pLabelDHCPUpperAddress; 257 /** Holds the DHCP upper address editor. */ 258 QILineEdit *m_pEditorDHCPUpperAddress; 259 /** @} */ 260 }; 261 262 #endif /* __UIHostNetworkDetailsDialog_h__ */ 263 -
Property svn:keywords
set to
-
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.cpp
-
Property svn:keywords
changed from
Id Revision
toAuthor Date Id Revision
r66662 r66681 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI GlobalSettingsNetworkclass implementation.3 * VBox Qt GUI - UIHostNetworkManager class implementation. 4 4 */ 5 5 … … 22 22 /* Qt includes: */ 23 23 # include <QHeaderView> 24 # include <QMenuBar> 25 # include <QPushButton> 24 26 25 27 /* GUI includes: */ 28 # include "QIDialogButtonBox.h" 29 # include "QITreeWidget.h" 30 # include "UIIconPool.h" 31 # include "UIMessageCenter.h" 32 # include "UIHostNetworkDetailsDialog.h" 33 # include "UIHostNetworkManager.h" 34 # include "UIToolBar.h" 35 # ifdef VBOX_WS_MAC 36 # include "UIWindowMenuManager.h" 37 # endif /* VBOX_WS_MAC */ 26 38 # include "VBoxGlobal.h" 27 # include "UIIconPool.h"28 # include "UIConverter.h"29 # include "UIMessageCenter.h"30 # include "UIGlobalSettingsNetwork.h"31 # include "UIGlobalSettingsNetworkDetailsNAT.h"32 # include "UIGlobalSettingsNetworkDetailsHost.h"33 39 34 40 /* COM includes: */ 35 # include "CNATNetwork.h" 41 # include "CDHCPServer.h" 42 # include "CHost.h" 36 43 # include "CHostNetworkInterface.h" 37 44 … … 41 48 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 42 49 43 /* COM includes: */ 44 #include "CDHCPServer.h" 45 46 47 /** Global settings: Network page data structure. */ 48 struct UIDataSettingsGlobalNetwork 49 { 50 /** Constructs data. */ 51 UIDataSettingsGlobalNetwork() {} 52 53 /** Returns whether the @a other passed data is equal to this one. */ 54 bool operator==(const UIDataSettingsGlobalNetwork & /* other */) const { return true; } 55 /** Returns whether the @a other passed data is different from this one. */ 56 bool operator!=(const UIDataSettingsGlobalNetwork & /* other */) const { return false; } 57 }; 58 59 60 /** Global settings: Network page: NAT network tree-widget item. */ 61 class UIItemNetworkNAT : public QITreeWidgetItem, public UIDataSettingsGlobalNetworkNAT 50 51 /** Host Network Manager: Tree-widget item. */ 52 class UIItemHostNetwork : public QITreeWidgetItem, public UIDataHostNetwork 62 53 { 63 54 public: 64 65 /** Constructs item. */66 UIItemNetworkNAT();67 55 68 56 /** Updates item fields from data. */ 69 57 void updateFields(); 70 /** Updates item data from fields. */71 void updateData();72 73 /** Performs validation, updates @a messages list if something is wrong. */74 bool validate(UIValidationMessage &messages);75 76 /** Returns item name. */77 QString name() const { return m_strName; }78 /** Returns new item name. */79 QString newName() const { return m_strNewName; }80 81 /** Returns IPv4 port forwarding rules. */82 const UIPortForwardingDataList &ipv4rules() const { return m_ipv4rules; }83 /** Defines IPv4 port forwarding rules. */84 void setIpv4rules(const UIPortForwardingDataList &ipv4rules) { m_ipv4rules = ipv4rules; }85 /** Returns IPv6 port forwarding rules. */86 const UIPortForwardingDataList &ipv6rules() const { return m_ipv6rules; }87 /** Defines IPv6 port forwarding rules. */88 void setIpv6rules(const UIPortForwardingDataList &ipv6rules) { m_ipv6rules = ipv6rules; }89 90 protected:91 92 /** Returns default text. */93 virtual QString defaultText() const /* override */;94 95 private:96 97 /** Holds IPv4 port forwarding rules. */98 UIPortForwardingDataList m_ipv4rules;99 /** Holds IPv6 port forwarding rules. */100 UIPortForwardingDataList m_ipv6rules;101 };102 103 104 /** Global settings: Network page: Host network tree-widget item. */105 class UIItemNetworkHost : public QITreeWidgetItem, public UIDataSettingsGlobalNetworkHost106 {107 public:108 109 /** Constructs item. */110 UIItemNetworkHost();111 112 /** Updates item fields from data. */113 void updateFields();114 115 /** Performs validation, updates @a messages list if something is wrong. */116 bool validate(UIValidationMessage &messages);117 58 118 59 /** Returns item name. */ … … 122 63 123 64 /********************************************************************************************************************************* 124 * Class UIItem NetworkNAT implementation.*65 * Class UIItemHostNetwork implementation. * 125 66 *********************************************************************************************************************************/ 126 67 127 UIItemNetworkNAT::UIItemNetworkNAT() 128 : QITreeWidgetItem() 129 { 130 } 131 132 void UIItemNetworkNAT::updateFields() 68 void UIItemHostNetwork::updateFields() 133 69 { 134 70 /* Compose item name/tool-tip: */ 71 setText(0, m_interface.m_strName); 72 const QString strTable("<table cellspacing=5>%1</table>"); 135 73 const QString strHeader("<tr><td><nobr>%1: </nobr></td><td><nobr>%2</nobr></td></tr>"); 136 74 const QString strSubHeader("<tr><td><nobr> %1: </nobr></td><td><nobr>%2</nobr></td></tr>"); 137 75 QString strToolTip; 138 76 139 /* Item name was not changed: */ 140 setCheckState(0, m_fEnabled ? Qt::Checked : Qt::Unchecked); 141 if (m_strNewName == m_strName) 142 { 143 /* Just use the old one: */ 144 setText(1, m_strName); 145 strToolTip += strHeader.arg(UIGlobalSettingsNetwork::tr("Network Name"), m_strName); 146 } 147 /* If name was changed: */ 148 else 149 { 150 /* We should explain that: */ 151 const QString oldName = m_strName; 152 const QString newName = m_strNewName.isEmpty() ? UIGlobalSettingsNetwork::tr("[empty]") : m_strNewName; 153 setText(1, UIGlobalSettingsNetwork::tr("%1 (renamed from %2)").arg(newName, oldName)); 154 strToolTip += strHeader.arg(UIGlobalSettingsNetwork::tr("Old Network Name"), m_strName); 155 strToolTip += strHeader.arg(UIGlobalSettingsNetwork::tr("New Network Name"), m_strNewName); 156 } 157 158 /* Other tool-tip information: */ 159 strToolTip += strHeader.arg(UIGlobalSettingsNetwork::tr("Network CIDR"), m_strCIDR); 160 strToolTip += strHeader.arg(UIGlobalSettingsNetwork::tr("Supports DHCP"), 161 m_fSupportsDHCP ? UIGlobalSettingsNetwork::tr("yes") : UIGlobalSettingsNetwork::tr("no")); 162 strToolTip += strHeader.arg(UIGlobalSettingsNetwork::tr("Supports IPv6"), 163 m_fSupportsIPv6 ? UIGlobalSettingsNetwork::tr("yes") : UIGlobalSettingsNetwork::tr("no")); 164 if (m_fSupportsIPv6 && m_fAdvertiseDefaultIPv6Route) 165 strToolTip += strSubHeader.arg(UIGlobalSettingsNetwork::tr("Default IPv6 route"), UIGlobalSettingsNetwork::tr("yes")); 77 /* Interface information: */ 78 strToolTip += strHeader.arg(UIHostNetworkManager::tr("Adapter")) 79 .arg(UIHostNetworkManager::tr("Manually configured", "interface")); 80 strToolTip += strSubHeader.arg(UIHostNetworkManager::tr("IPv4 Address")) 81 .arg(m_interface.m_strInterfaceAddress.isEmpty() ? 82 UIHostNetworkManager::tr ("Not set", "address") : 83 m_interface.m_strInterfaceAddress) + 84 strSubHeader.arg(UIHostNetworkManager::tr("IPv4 Network Mask")) 85 .arg(m_interface.m_strInterfaceMask.isEmpty() ? 86 UIHostNetworkManager::tr ("Not set", "mask") : 87 m_interface.m_strInterfaceMask); 88 if (m_interface.m_fIpv6Supported) 89 { 90 strToolTip += strSubHeader.arg(UIHostNetworkManager::tr("IPv6 Address")) 91 .arg(m_interface.m_strInterfaceAddress6.isEmpty() ? 92 UIHostNetworkManager::tr("Not set", "address") : 93 m_interface.m_strInterfaceAddress6) + 94 strSubHeader.arg(UIHostNetworkManager::tr("IPv6 Network Mask Length")) 95 .arg(m_interface.m_strInterfaceMaskLength6.isEmpty() ? 96 UIHostNetworkManager::tr("Not set", "length") : 97 m_interface.m_strInterfaceMaskLength6); 98 } 99 100 /* DHCP server information: */ 101 strToolTip += strHeader.arg(UIHostNetworkManager::tr("DHCP Server")) 102 .arg(m_dhcpserver.m_fDhcpServerEnabled ? 103 UIHostNetworkManager::tr("Enabled", "server") : 104 UIHostNetworkManager::tr("Disabled", "server")); 105 if (m_dhcpserver.m_fDhcpServerEnabled) 106 { 107 strToolTip += strSubHeader.arg(UIHostNetworkManager::tr("Address")) 108 .arg(m_dhcpserver.m_strDhcpServerAddress.isEmpty() ? 109 UIHostNetworkManager::tr("Not set", "address") : 110 m_dhcpserver.m_strDhcpServerAddress) + 111 strSubHeader.arg(UIHostNetworkManager::tr("Network Mask")) 112 .arg(m_dhcpserver.m_strDhcpServerMask.isEmpty() ? 113 UIHostNetworkManager::tr("Not set", "mask") : 114 m_dhcpserver.m_strDhcpServerMask) + 115 strSubHeader.arg(UIHostNetworkManager::tr("Lower Bound")) 116 .arg(m_dhcpserver.m_strDhcpLowerAddress.isEmpty() ? 117 UIHostNetworkManager::tr("Not set", "bound") : 118 m_dhcpserver.m_strDhcpLowerAddress) + 119 strSubHeader.arg(UIHostNetworkManager::tr("Upper Bound")) 120 .arg(m_dhcpserver.m_strDhcpUpperAddress.isEmpty() ? 121 UIHostNetworkManager::tr("Not set", "bound") : 122 m_dhcpserver.m_strDhcpUpperAddress); 123 } 166 124 167 125 /* Assign tool-tip finally: */ 168 setToolTip(1, strToolTip); 169 } 170 171 void UIItemNetworkNAT::updateData() 172 { 173 /* Update data: */ 174 m_fEnabled = checkState(0) == Qt::Checked; 175 } 176 177 bool UIItemNetworkNAT::validate(UIValidationMessage &message) 178 { 179 /* Pass by default: */ 180 bool fPass = true; 181 182 /* NAT network name validation: */ 183 bool fNameValid = true; 184 if (m_strNewName.isEmpty()) 185 { 186 /* Emptiness validation: */ 187 message.second << UIGlobalSettingsNetwork::tr("No new name specified for the NAT network previously called <b>%1</b>.").arg(m_strName); 188 fNameValid = false; 189 fPass = false; 190 } 191 192 /* NAT network CIDR validation: */ 193 if (m_strCIDR.isEmpty()) 194 { 195 /* Emptiness validation: */ 196 if (fNameValid) 197 message.second << UIGlobalSettingsNetwork::tr("No CIDR specified for the NAT network <b>%1</b>.").arg(m_strNewName); 198 else 199 message.second << UIGlobalSettingsNetwork::tr("No CIDR specified for the NAT network previously called <b>%1</b>.").arg(m_strName); 200 fPass = false; 201 } 202 else 203 { 204 /* Correctness validation: */ 205 RTNETADDRIPV4 network, mask; 206 int rc = RTCidrStrToIPv4(m_strCIDR.toUtf8().constData(), &network, &mask); 207 if (RT_FAILURE(rc)) 208 { 209 if (fNameValid) 210 message.second << UIGlobalSettingsNetwork::tr("Invalid CIDR specified (<i>%1</i>) for the NAT network <b>%2</b>.") 211 .arg(m_strCIDR, m_strNewName); 212 else 213 message.second << UIGlobalSettingsNetwork::tr("Invalid CIDR specified (<i>%1</i>) for the NAT network previously called <b>%2</b>.") 214 .arg(m_strCIDR, m_strName); 215 fPass = false; 216 } 217 } 218 219 /* Return result: */ 220 return fPass; 221 } 222 223 QString UIItemNetworkNAT::defaultText() const 224 { 225 return m_fEnabled ? 226 tr("%1, %2", "col.2 text, col.1 name") 227 .arg(text(1)) 228 .arg(parentTree()->headerItem()->text(0)) : 229 tr("%1", "col.2 text") 230 .arg(text(1)); 126 setToolTip(0, strTable.arg(strToolTip)); 231 127 } 232 128 233 129 234 130 /********************************************************************************************************************************* 235 * Class UI ItemNetworkHost implementation.*131 * Class UIHostNetworkManager implementation. * 236 132 *********************************************************************************************************************************/ 237 133 238 UIItemNetworkHost::UIItemNetworkHost() 239 : QITreeWidgetItem() 240 { 241 } 242 243 void UIItemNetworkHost::updateFields() 244 { 245 /* Compose item name/tool-tip: */ 246 setText(0, m_interface.m_strName); 247 const QString strHeader("<tr><td><nobr>%1: </nobr></td><td><nobr>%2</nobr></td></tr>"); 248 const QString strSubHeader("<tr><td><nobr> %1: </nobr></td><td><nobr>%2</nobr></td></tr>"); 249 QString strToolTip; 250 251 /* Host interface information: */ 252 strToolTip += strHeader.arg(UIGlobalSettingsNetwork::tr("Adapter")) 253 .arg(m_interface.m_fDhcpClientEnabled ? 254 UIGlobalSettingsNetwork::tr("Automatically configured", "interface") : 255 UIGlobalSettingsNetwork::tr("Manually configured", "interface")); 256 if (!m_interface.m_fDhcpClientEnabled) 257 { 258 strToolTip += strSubHeader.arg(UIGlobalSettingsNetwork::tr("IPv4 Address")) 259 .arg(m_interface.m_strInterfaceAddress.isEmpty() ? 260 UIGlobalSettingsNetwork::tr ("Not set", "address") : 261 m_interface.m_strInterfaceAddress) + 262 strSubHeader.arg(UIGlobalSettingsNetwork::tr("IPv4 Network Mask")) 263 .arg(m_interface.m_strInterfaceMask.isEmpty() ? 264 UIGlobalSettingsNetwork::tr ("Not set", "mask") : 265 m_interface.m_strInterfaceMask); 266 if (m_interface.m_fIpv6Supported) 267 { 268 strToolTip += strSubHeader.arg(UIGlobalSettingsNetwork::tr("IPv6 Address")) 269 .arg(m_interface.m_strInterfaceAddress6.isEmpty() ? 270 UIGlobalSettingsNetwork::tr("Not set", "address") : 271 m_interface.m_strInterfaceAddress6) + 272 strSubHeader.arg(UIGlobalSettingsNetwork::tr("IPv6 Network Mask Length")) 273 .arg(m_interface.m_strInterfaceMaskLength6.isEmpty() ? 274 UIGlobalSettingsNetwork::tr("Not set", "length") : 275 m_interface.m_strInterfaceMaskLength6); 276 } 277 } 278 279 /* DHCP server information: */ 280 strToolTip += strHeader.arg(UIGlobalSettingsNetwork::tr("DHCP Server")) 281 .arg(m_dhcpserver.m_fDhcpServerEnabled ? 282 UIGlobalSettingsNetwork::tr("Enabled", "server") : 283 UIGlobalSettingsNetwork::tr("Disabled", "server")); 284 if (m_dhcpserver.m_fDhcpServerEnabled) 285 { 286 strToolTip += strSubHeader.arg(UIGlobalSettingsNetwork::tr("Address")) 287 .arg(m_dhcpserver.m_strDhcpServerAddress.isEmpty() ? 288 UIGlobalSettingsNetwork::tr("Not set", "address") : 289 m_dhcpserver.m_strDhcpServerAddress) + 290 strSubHeader.arg(UIGlobalSettingsNetwork::tr("Network Mask")) 291 .arg(m_dhcpserver.m_strDhcpServerMask.isEmpty() ? 292 UIGlobalSettingsNetwork::tr("Not set", "mask") : 293 m_dhcpserver.m_strDhcpServerMask) + 294 strSubHeader.arg(UIGlobalSettingsNetwork::tr("Lower Bound")) 295 .arg(m_dhcpserver.m_strDhcpLowerAddress.isEmpty() ? 296 UIGlobalSettingsNetwork::tr("Not set", "bound") : 297 m_dhcpserver.m_strDhcpLowerAddress) + 298 strSubHeader.arg(UIGlobalSettingsNetwork::tr("Upper Bound")) 299 .arg(m_dhcpserver.m_strDhcpUpperAddress.isEmpty() ? 300 UIGlobalSettingsNetwork::tr("Not set", "bound") : 301 m_dhcpserver.m_strDhcpUpperAddress); 302 } 303 304 /* Assign tool-tip finally: */ 305 setToolTip(0, strToolTip); 306 } 307 308 bool UIItemNetworkHost::validate(UIValidationMessage &message) 309 { 310 /* Pass by default: */ 311 bool fPass = true; 312 313 /* Host interface validation: */ 314 if (!m_interface.m_fDhcpClientEnabled) 315 { 316 if (!m_interface.m_strInterfaceAddress.trimmed().isEmpty() && 317 ( !RTNetIsIPv4AddrStr(m_interface.m_strInterfaceAddress.toUtf8().constData()) 318 || RTNetStrIsIPv4AddrAny(m_interface.m_strInterfaceAddress.toUtf8().constData()))) 319 { 320 message.second << UIGlobalSettingsNetwork::tr("Host interface <b>%1</b> does not currently have a valid IPv4 address.").arg(text(0)); 321 fPass = false; 322 } 323 if (!m_interface.m_strInterfaceMask.trimmed().isEmpty() && 324 ( !RTNetIsIPv4AddrStr(m_interface.m_strInterfaceMask.toUtf8().constData()) 325 || RTNetStrIsIPv4AddrAny(m_interface.m_strInterfaceMask.toUtf8().constData()))) 326 { 327 message.second << UIGlobalSettingsNetwork::tr("Host interface <b>%1</b> does not currently have a valid IPv4 network mask.").arg(text(0)); 328 fPass = false; 329 } 330 if (m_interface.m_fIpv6Supported) 331 { 332 if (!m_interface.m_strInterfaceAddress6.trimmed().isEmpty() && 333 ( !RTNetIsIPv6AddrStr(m_interface.m_strInterfaceAddress6.toUtf8().constData()) 334 || RTNetStrIsIPv6AddrAny(m_interface.m_strInterfaceAddress6.toUtf8().constData()))) 335 { 336 message.second << UIGlobalSettingsNetwork::tr("Host interface <b>%1</b> does not currently have a valid IPv6 address.").arg(text(0)); 337 fPass = false; 338 } 339 bool fIsMaskPrefixLengthNumber = false; 340 const int iMaskPrefixLength = m_interface.m_strInterfaceMaskLength6.trimmed().toInt(&fIsMaskPrefixLengthNumber); 341 if ( !fIsMaskPrefixLengthNumber 342 || iMaskPrefixLength < 0 343 || iMaskPrefixLength > 128) 344 { 345 message.second << UIGlobalSettingsNetwork::tr("Host interface <b>%1</b> does not currently have a valid IPv6 network mask prefix length.").arg(text(0)); 346 fPass = false; 347 } 348 } 349 } 350 351 /* DHCP server validation: */ 352 if (m_dhcpserver.m_fDhcpServerEnabled) 353 { 354 if ( !RTNetIsIPv4AddrStr(m_dhcpserver.m_strDhcpServerAddress.toUtf8().constData()) 355 || RTNetStrIsIPv4AddrAny(m_dhcpserver.m_strDhcpServerAddress.toUtf8().constData())) 356 { 357 message.second << UIGlobalSettingsNetwork::tr("Host interface <b>%1</b> does not currently have a valid DHCP server address.").arg(text(0)); 358 fPass = false; 359 } 360 if ( !RTNetIsIPv4AddrStr(m_dhcpserver.m_strDhcpServerMask.toUtf8().constData()) 361 || RTNetStrIsIPv4AddrAny(m_dhcpserver.m_strDhcpServerMask.toUtf8().constData())) 362 { 363 message.second << UIGlobalSettingsNetwork::tr("Host interface <b>%1</b> does not currently have a valid DHCP server mask.").arg(text(0)); 364 fPass = false; 365 } 366 if ( !RTNetIsIPv4AddrStr(m_dhcpserver.m_strDhcpLowerAddress.toUtf8().constData()) 367 || RTNetStrIsIPv4AddrAny(m_dhcpserver.m_strDhcpLowerAddress.toUtf8().constData())) 368 { 369 message.second << UIGlobalSettingsNetwork::tr("Host interface <b>%1</b> does not currently have a valid DHCP server lower address bound.").arg(text(0)); 370 fPass = false; 371 } 372 if ( !RTNetIsIPv4AddrStr(m_dhcpserver.m_strDhcpUpperAddress.toUtf8().constData()) 373 || RTNetStrIsIPv4AddrAny(m_dhcpserver.m_strDhcpUpperAddress.toUtf8().constData())) 374 { 375 message.second << UIGlobalSettingsNetwork::tr("Host interface <b>%1</b> does not currently have a valid DHCP server upper address bound.").arg(text(0)); 376 fPass = false; 377 } 378 } 379 380 /* Return result: */ 381 return fPass; 382 } 383 384 385 /********************************************************************************************************************************* 386 * Class UIGlobalSettingsNetwork implementation. * 387 *********************************************************************************************************************************/ 388 389 UIGlobalSettingsNetwork::UIGlobalSettingsNetwork() 390 : m_pActionAddNetworkNAT(0), m_pActionEditNetworkNAT(0), m_pActionRemoveNetworkNAT(0) 391 , m_pActionAddNetworkHost(0), m_pActionEditNetworkHost(0), m_pActionRemoveNetworkHost(0) 392 , m_pCache(0) 393 { 134 /* static */ 135 UIHostNetworkManager *UIHostNetworkManager::s_pInstance = 0; 136 UIHostNetworkManager *UIHostNetworkManager::instance() { return s_pInstance; } 137 138 UIHostNetworkManager::UIHostNetworkManager(QWidget *pCenterWidget) 139 : m_pPseudoParentWidget(pCenterWidget) 140 , m_pToolBar(0) 141 , m_pMenu(0) 142 , m_pActionAdd(0) 143 , m_pActionEdit(0) 144 , m_pActionRemove(0) 145 , m_pTreeWidget(0) 146 , m_pButtonBox(0) 147 { 148 /* Prepare instance: */ 149 s_pInstance = this; 150 394 151 /* Prepare: */ 395 152 prepare(); 396 153 } 397 154 398 UI GlobalSettingsNetwork::~UIGlobalSettingsNetwork()155 UIHostNetworkManager::~UIHostNetworkManager() 399 156 { 400 157 /* Cleanup: */ 401 158 cleanup(); 402 } 403 404 void UIGlobalSettingsNetwork::loadToCacheFrom(QVariant &data) 405 { 406 /* Fetch data to properties: */ 407 UISettingsPageGlobal::fetchData(data); 408 409 /* Clear cache initially: */ 410 m_pCache->clear(); 411 412 /* Prepare old network data: */ 413 UIDataSettingsGlobalNetwork oldNetworkData; 414 415 /* Gather old network data: */ 416 foreach (const CNATNetwork &network, vboxGlobal().virtualBox().GetNATNetworks()) 417 loadToCacheFromNetworkNAT(network, m_pCache->child1(network.GetNetworkName())); 418 foreach (const CHostNetworkInterface &iface, vboxGlobal().host().GetNetworkInterfaces()) 419 if (iface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly) 420 loadToCacheFromNetworkHost(iface, m_pCache->child2(iface.GetName())); 421 422 /* Cache old network data: */ 423 m_pCache->cacheInitialData(oldNetworkData); 424 425 /* Upload properties to data: */ 426 UISettingsPageGlobal::uploadData(data); 427 } 428 429 void UIGlobalSettingsNetwork::getFromCache() 430 { 431 /* Load old network data from the cache: */ 432 for (int i = 0; i < m_pCache->childCount1(); ++i) 433 createTreeWidgetItemForNetworkNAT(m_pCache->child1(i)); 434 m_pTreeNetworkNAT->sortByColumn(1, Qt::AscendingOrder); 435 m_pTreeNetworkNAT->setCurrentItem(m_pTreeNetworkNAT->topLevelItem(0)); 436 sltHandleCurrentItemChangeNetworkNAT(); 437 for (int i = 0; i < m_pCache->childCount2(); ++i) 438 createTreeWidgetItemForNetworkHost(m_pCache->child2(i)); 439 m_pTreeNetworkHost->sortByColumn(0, Qt::AscendingOrder); 440 m_pTreeNetworkHost->setCurrentItem(m_pTreeNetworkHost->topLevelItem(0)); 441 sltHandleCurrentItemChangeNetworkHost(); 442 443 /* Revalidate: */ 444 revalidate(); 445 } 446 447 void UIGlobalSettingsNetwork::putToCache() 448 { 449 /* Prepare new network data: */ 450 UIDataSettingsGlobalNetwork newNetworkData; 451 452 /* Gather new network data: */ 453 for (int i = 0; i < m_pTreeNetworkNAT->topLevelItemCount(); ++i) 454 { 455 const UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(i)); 456 m_pCache->child1(pItem->m_strName).cacheCurrentData(*pItem); 457 foreach (const UIDataPortForwardingRule &rule, pItem->ipv4rules()) 458 m_pCache->child1(pItem->m_strName).child1(rule.name).cacheCurrentData(rule); 459 foreach (const UIDataPortForwardingRule &rule, pItem->ipv6rules()) 460 m_pCache->child1(pItem->m_strName).child2(rule.name).cacheCurrentData(rule); 461 } 462 for (int i = 0; i < m_pTreeNetworkHost->topLevelItemCount(); ++i) 463 { 464 const UIItemNetworkHost *pItem = static_cast<UIItemNetworkHost*>(m_pTreeNetworkHost->topLevelItem(i)); 465 m_pCache->child2(pItem->m_interface.m_strName).cacheCurrentData(*pItem); 466 } 467 468 /* Cache new network data: */ 469 m_pCache->cacheCurrentData(newNetworkData); 470 } 471 472 void UIGlobalSettingsNetwork::saveFromCacheTo(QVariant &data) 473 { 474 /* Fetch data to properties: */ 475 UISettingsPageGlobal::fetchData(data); 476 477 /* Update network data and failing state: */ 478 setFailed(!saveNetworkData()); 479 480 /* Upload properties to data: */ 481 UISettingsPageGlobal::uploadData(data); 482 } 483 484 bool UIGlobalSettingsNetwork::validate(QList<UIValidationMessage> &messages) 485 { 486 /* Pass by default: */ 487 bool fPass = true; 488 489 /* Validate NAT network items: */ 490 { 491 /* Prepare message: */ 492 UIValidationMessage message; 493 message.first = VBoxGlobal::removeAccelMark(m_pTabWidget->tabText(0)); 494 495 /* Validate items first: */ 496 for (int i = 0; i < m_pTreeNetworkNAT->topLevelItemCount(); ++i) 497 { 498 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(i)); 499 if (!pItem->validate(message)) 500 fPass = false; 501 } 502 503 /* And make sure item names are unique: */ 504 QList<QString> names; 505 for (int iItemIndex = 0; iItemIndex < m_pTreeNetworkNAT->topLevelItemCount(); ++iItemIndex) 506 { 507 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(iItemIndex)); 508 const QString strItemName(pItem->newName()); 509 if (strItemName.isEmpty()) 510 continue; 511 if (!names.contains(strItemName)) 512 names << strItemName; 513 else 514 { 515 message.second << UIGlobalSettingsNetwork::tr("The name <b>%1</b> is being used for several NAT networks.") 516 .arg(strItemName); 517 fPass = false; 518 } 519 } 520 521 /* Serialize message: */ 522 if (!message.second.isEmpty()) 523 messages << message; 524 } 525 526 /* Validate Host network items: */ 527 { 528 /* Prepare message: */ 529 UIValidationMessage message; 530 message.first = VBoxGlobal::removeAccelMark(m_pTabWidget->tabText(1)); 531 532 /* Validate items only: */ 533 for (int i = 0; i < m_pTreeNetworkHost->topLevelItemCount(); ++i) 534 { 535 UIItemNetworkHost *pItem = static_cast<UIItemNetworkHost*>(m_pTreeNetworkHost->topLevelItem(i)); 536 if (!pItem->validate(message)) 537 fPass = false; 538 } 539 540 /* Serialize message: */ 541 if (!message.second.isEmpty()) 542 messages << message; 543 } 544 545 /* Return result: */ 546 return fPass; 547 } 548 549 void UIGlobalSettingsNetwork::setOrderAfter(QWidget *pWidget) 550 { 551 setTabOrder(pWidget, m_pTabWidget->focusProxy()); 552 setTabOrder(m_pTabWidget->focusProxy(), m_pTreeNetworkNAT); 553 setTabOrder(m_pTreeNetworkNAT, m_pTreeNetworkHost); 554 } 555 556 void UIGlobalSettingsNetwork::retranslateUi() 557 { 558 /* Translate uic generated strings: */ 559 Ui::UIGlobalSettingsNetwork::retranslateUi(this); 560 561 /* NAT networks: */ 562 { 563 /* Translate tree-widget columns: */ 564 m_pTreeNetworkNAT->setHeaderLabels(QStringList() 565 << tr("Active", "NAT network") 566 << tr("Name")); 567 568 /* Translate action text: */ 569 m_pActionAddNetworkNAT->setText(tr("Add NAT Network")); 570 m_pActionRemoveNetworkNAT->setText(tr("Remove NAT Network")); 571 m_pActionEditNetworkNAT->setText(tr("Edit NAT Network")); 572 573 m_pActionAddNetworkNAT->setWhatsThis(tr("Adds new NAT network.")); 574 m_pActionRemoveNetworkNAT->setWhatsThis(tr("Removes selected NAT network.")); 575 m_pActionEditNetworkNAT->setWhatsThis(tr("Edits selected NAT network.")); 576 577 m_pActionAddNetworkNAT->setToolTip(m_pActionAddNetworkNAT->whatsThis()); 578 m_pActionRemoveNetworkNAT->setToolTip(m_pActionRemoveNetworkNAT->whatsThis()); 579 m_pActionEditNetworkNAT->setToolTip(m_pActionEditNetworkNAT->whatsThis()); 580 } 581 582 /* Host networks: */ 583 { 584 /* Translate action text: */ 585 m_pActionAddNetworkHost->setText(tr("Add Host-only Network")); 586 m_pActionRemoveNetworkHost->setText(tr("Remove Host-only Network")); 587 m_pActionEditNetworkHost->setText(tr("Edit Host-only Network")); 588 589 m_pActionAddNetworkHost->setWhatsThis(tr("Adds new host-only network.")); 590 m_pActionRemoveNetworkHost->setWhatsThis(tr("Removes selected host-only network.")); 591 m_pActionEditNetworkHost->setWhatsThis(tr("Edits selected host-only network.")); 592 593 m_pActionAddNetworkHost->setToolTip(m_pActionAddNetworkHost->whatsThis()); 594 m_pActionRemoveNetworkHost->setToolTip(m_pActionRemoveNetworkHost->whatsThis()); 595 m_pActionEditNetworkHost->setToolTip(m_pActionEditNetworkHost->whatsThis()); 596 } 597 } 598 599 void UIGlobalSettingsNetwork::sltAddNetworkNAT() 600 { 601 /* Compose a set of busy names: */ 602 QSet<QString> names; 603 for (int i = 0; i < m_pTreeNetworkNAT->topLevelItemCount(); ++i) 604 names << static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(i))->name(); 605 /* Compose a map of busy indexes: */ 606 QMap<int, bool> presence; 607 const QString strNameTemplate("NatNetwork%1"); 608 const QRegExp regExp(strNameTemplate.arg("([\\d]*)")); 609 foreach (const QString &strName, names) 610 if (regExp.indexIn(strName) != -1) 611 presence[regExp.cap(1).toInt()] = true; 612 /* Search for a minimum index: */ 613 int iMinimumIndex = 0; 614 for (int i = 0; !presence.isEmpty() && i <= presence.lastKey() + 1; ++i) 615 if (!presence.contains(i)) 616 { 617 iMinimumIndex = i; 618 break; 619 } 620 621 /* Compose resulting index and name: */ 622 const QString strNetworkIndex(iMinimumIndex == 0 ? QString() : QString::number(iMinimumIndex)); 623 const QString strNetworkName = strNameTemplate.arg(strNetworkIndex); 624 625 /* Compose new item data: */ 626 UIDataSettingsGlobalNetworkNAT data; 627 data.m_fEnabled = true; 628 data.m_strName = strNetworkName; 629 data.m_strNewName = strNetworkName; 630 data.m_strCIDR = "10.0.2.0/24"; 631 data.m_fSupportsDHCP = true; 632 633 /* Create tree-widget item: */ 634 createTreeWidgetItemForNetworkNAT(data, UIPortForwardingDataList(), UIPortForwardingDataList(), true); 635 m_pTreeNetworkNAT->sortByColumn(1, Qt::AscendingOrder); 636 } 637 638 void UIGlobalSettingsNetwork::sltEditNetworkNAT() 639 { 640 /* Get network item: */ 641 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->currentItem()); 642 AssertPtrReturnVoid(pItem); 643 644 /* Edit current item data: */ 645 UIDataSettingsGlobalNetworkNAT data = *pItem; 646 UIPortForwardingDataList ipv4rules = pItem->ipv4rules(); 647 UIPortForwardingDataList ipv6rules = pItem->ipv6rules(); 648 UIGlobalSettingsNetworkDetailsNAT details(this, data, ipv4rules, ipv6rules); 649 if (details.exec() == QDialog::Accepted) 650 { 651 /* Put data back: */ 652 pItem->UIDataSettingsGlobalNetworkNAT::operator=(data); 653 pItem->setIpv4rules(ipv4rules); 654 pItem->setIpv6rules(ipv6rules); 655 pItem->updateFields(); 656 sltHandleCurrentItemChangeNetworkNAT(); 657 /* Revalidate: */ 658 revalidate(); 659 } 660 } 661 662 void UIGlobalSettingsNetwork::sltRemoveNetworkNAT() 663 { 664 /* Get network item: */ 665 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->currentItem()); 666 AssertPtrReturnVoid(pItem); 667 668 /* Confirm network removal: */ 669 if (!msgCenter().confirmNATNetworkRemoval(pItem->name(), this)) 670 return; 671 672 /* Remove tree-widget item: */ 673 removeTreeWidgetItemOfNetworkNAT(pItem); 674 } 675 676 void UIGlobalSettingsNetwork::sltHandleItemChangeNetworkNAT(QTreeWidgetItem *pChangedItem) 677 { 678 /* Get network item: */ 679 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(pChangedItem); 680 AssertMsg(pItem, ("Changed item should present!\n")); 681 682 /* Update item data: */ 683 pItem->updateData(); 684 } 685 686 void UIGlobalSettingsNetwork::sltHandleCurrentItemChangeNetworkNAT() 687 { 688 /* Get current item: */ 689 UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->currentItem()); 690 /* Update availability: */ 691 m_pActionRemoveNetworkNAT->setEnabled(pItem); 692 m_pActionEditNetworkNAT->setEnabled(pItem); 693 } 694 695 void UIGlobalSettingsNetwork::sltHandleContextMenuRequestNetworkNAT(const QPoint &pos) 696 { 697 /* Compose temporary context-menu: */ 698 QMenu menu; 699 if (m_pTreeNetworkNAT->itemAt(pos)) 700 { 701 menu.addAction(m_pActionEditNetworkNAT); 702 menu.addAction(m_pActionRemoveNetworkNAT); 703 } 159 160 /* Cleanup instance: */ 161 s_pInstance = 0; 162 } 163 164 /* static */ 165 void UIHostNetworkManager::showModeless(QWidget *pCenterWidget /* = 0 */) 166 { 167 /* Create instance if not yet created: */ 168 if (!s_pInstance) 169 new UIHostNetworkManager(pCenterWidget); 170 171 /* Show instance: */ 172 s_pInstance->show(); 173 s_pInstance->setWindowState(s_pInstance->windowState() & ~Qt::WindowMinimized); 174 s_pInstance->activateWindow(); 175 } 176 177 void UIHostNetworkManager::retranslateUi() 178 { 179 /* Translate window title: */ 180 setWindowTitle(tr("Host Network Manager")); 181 182 /* Translate menu: */ 183 if (m_pMenu) 184 m_pMenu->setTitle(QApplication::translate("UIActionPool", "&File")); 185 186 /* Translate actions: */ 187 if (m_pActionAdd) 188 { 189 m_pActionAdd->setText(tr("&Create")); 190 m_pActionAdd->setToolTip(tr("Create Host-only Network (%1)").arg(m_pActionAdd->shortcut().toString())); 191 m_pActionAdd->setStatusTip(tr("Creates new host-only network.")); 192 } 193 if (m_pActionEdit) 194 { 195 m_pActionEdit->setText(tr("&Modify...")); 196 m_pActionEdit->setToolTip(tr("Modify Host-only Network (%1)").arg(m_pActionEdit->shortcut().toString())); 197 m_pActionEdit->setStatusTip(tr("Modifies selected host-only network.")); 198 } 199 if (m_pActionRemove) 200 { 201 m_pActionRemove->setText(tr("&Remove...")); 202 m_pActionRemove->setToolTip(tr("Remove Host-only Network (%1)").arg(m_pActionRemove->shortcut().toString())); 203 m_pActionRemove->setStatusTip(tr("Removes selected host-only network.")); 204 } 205 206 /* Adjust tool-bar: */ 207 #ifdef VBOX_WS_MAC 208 // WORKAROUND: 209 // There is a bug in Qt Cocoa which result in showing a "more arrow" when 210 // the necessary size of the toolbar is increased. Also for some languages 211 // the with doesn't match if the text increase. So manually adjust the size 212 // after changing the text. 213 if (m_pToolBar) 214 m_pToolBar->updateLayout(); 215 #endif 216 } 217 218 void UIHostNetworkManager::sltAddHostNetwork() 219 { 220 /* Get host for further activities: */ 221 CHost comHost = vboxGlobal().host(); 222 223 /* Create interface: */ 224 CHostNetworkInterface comInterface; 225 CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface); 226 227 /* Show error message if necessary: */ 228 if (!comHost.isOk() || progress.isNull()) 229 msgCenter().cannotCreateHostNetworkInterface(comHost, this); 704 230 else 705 231 { 706 menu.addAction(m_pActionAddNetworkNAT); 707 } 708 /* And show it: */ 709 menu.exec(m_pTreeNetworkNAT->mapToGlobal(pos)); 710 } 711 712 void UIGlobalSettingsNetwork::sltAddNetworkHost() 713 { 714 /* Prepare useful variables: */ 715 CVirtualBox vbox = vboxGlobal().virtualBox(); 716 CHost host = vboxGlobal().host(); 717 718 /* Create Host interface: */ 719 CHostNetworkInterface iface; 720 CProgress progress = host.CreateHostOnlyNetworkInterface(iface); 721 if (!host.isOk()) 722 return msgCenter().cannotCreateHostInterface(host, this); 723 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 724 if (!progress.isOk() || progress.GetResultCode() != 0) 725 return msgCenter().cannotCreateHostInterface(progress, this); 726 727 /* Make sure DHCP server is created too: */ 728 CDHCPServer dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName()); 729 if (dhcp.isNull()) 730 { 731 vbox.CreateDHCPServer(iface.GetNetworkName()); 732 if (!vbox.isOk()) 733 return msgCenter().cannotCreateDHCPServer(vbox, this); 734 dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName()); 735 } 736 AssertReturnVoid(!dhcp.isNull()); 737 738 /* Update tree: */ 739 const QString strCacheKey = iface.GetName(); 740 loadToCacheFromNetworkHost(iface, m_pCache->child2(strCacheKey)); 741 createTreeWidgetItemForNetworkHost(m_pCache->child2(strCacheKey), true); 742 m_pTreeNetworkHost->sortByColumn(0, Qt::AscendingOrder); 743 } 744 745 void UIGlobalSettingsNetwork::sltEditNetworkHost() 746 { 747 /* Get network item: */ 748 UIItemNetworkHost *pItem = static_cast<UIItemNetworkHost*>(m_pTreeNetworkHost->currentItem()); 749 AssertMsg(pItem, ("Current item should present!\n")); 750 751 /* Edit current item data: */ 752 UIDataSettingsGlobalNetworkHost data = *pItem; 753 UIGlobalSettingsNetworkDetailsHost details(this, data); 754 if (details.exec() == QDialog::Accepted) 755 { 756 /* Put data back: */ 757 pItem->UIDataSettingsGlobalNetworkHost::operator=(data); 758 pItem->updateFields(); 759 sltHandleCurrentItemChangeNetworkHost(); 760 /* Revalidate: */ 761 revalidate(); 762 } 763 } 764 765 void UIGlobalSettingsNetwork::sltRemoveNetworkHost() 766 { 767 /* Get network item: */ 768 UIItemNetworkHost *pItem = static_cast<UIItemNetworkHost*>(m_pTreeNetworkHost->currentItem()); 769 AssertMsg(pItem, ("Current item should present!\n")); 770 /* Get interface name: */ 771 const QString strInterfaceName(pItem->name()); 772 773 /* Confirm Host network removal: */ 774 if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this)) 775 return; 776 777 /* Prepare useful variables: */ 778 CVirtualBox vbox = vboxGlobal().virtualBox(); 779 CHost host = vboxGlobal().host(); 780 781 /* Find corresponding interface: */ 782 const CHostNetworkInterface &iface = host.FindHostNetworkInterfaceByName(strInterfaceName); 783 AssertReturnVoid(host.isOk() && !iface.isNull()); 784 785 /* Remove DHCP server if any: */ 786 const CDHCPServer &dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName()); 787 if (vbox.isOk() && !dhcp.isNull()) 788 { 789 vbox.RemoveDHCPServer(dhcp); 790 if (!vbox.isOk()) 791 return msgCenter().cannotRemoveDHCPServer(vbox, strInterfaceName, this); 792 } 793 794 /* Remove interface finally: */ 795 CProgress progress = host.RemoveHostOnlyNetworkInterface(iface.GetId()); 796 if (!host.isOk()) 797 return msgCenter().cannotRemoveHostInterface(host, strInterfaceName, this); 798 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 799 if (!progress.isOk() || progress.GetResultCode() != 0) 800 return msgCenter().cannotRemoveHostInterface(progress, strInterfaceName, this); 801 802 /* Update tree: */ 803 removeTreeWidgetItemOfNetworkHost(pItem); 804 } 805 806 void UIGlobalSettingsNetwork::sltHandleCurrentItemChangeNetworkHost() 807 { 808 /* Get current item: */ 809 UIItemNetworkHost *pItem = static_cast<UIItemNetworkHost*>(m_pTreeNetworkHost->currentItem()); 810 /* Update availability: */ 811 m_pActionRemoveNetworkHost->setEnabled(pItem); 812 m_pActionEditNetworkHost->setEnabled(pItem); 813 } 814 815 void UIGlobalSettingsNetwork::sltHandleContextMenuRequestNetworkHost(const QPoint &pos) 816 { 817 /* Compose temporary context-menu: */ 818 QMenu menu; 819 if (m_pTreeNetworkHost->itemAt(pos)) 820 { 821 menu.addAction(m_pActionEditNetworkHost); 822 menu.addAction(m_pActionRemoveNetworkHost); 823 } 824 else 825 { 826 menu.addAction(m_pActionAddNetworkHost); 827 } 828 /* And show it: */ 829 menu.exec(m_pTreeNetworkHost->mapToGlobal(pos)); 830 } 831 832 void UIGlobalSettingsNetwork::prepare() 833 { 834 /* Apply UI decorations: */ 835 Ui::UIGlobalSettingsNetwork::setupUi(this); 836 837 /* Prepare cache: */ 838 m_pCache = new UISettingsCacheGlobalNetwork; 839 AssertPtrReturnVoid(m_pCache); 840 841 /* Tree-widget created in the .ui file. */ 842 { 843 /* Prepare 'NAT Network' tab: */ 844 prepareTabNAT(); 845 /* Prepare 'Host Network' tab: */ 846 prepareTabHost(); 847 /* Prepare connections: */ 848 prepareConnections(); 849 } 850 851 /* Apply language settings: */ 852 retranslateUi(); 853 } 854 855 void UIGlobalSettingsNetwork::prepareTabNAT() 856 { 857 /* Tab and it's layout created in the .ui file. */ 858 { 859 #ifdef VBOX_WS_MAC 860 /* On macOS we can do a bit of smoothness: */ 861 m_pLayoutNAT->setContentsMargins(0, 0, 0, 0); 862 #endif 863 864 /* NAT Network tree-widget created in the .ui file. */ 865 AssertPtrReturnVoid(m_pTreeNetworkNAT); 866 { 867 /* Configure tree-widget: */ 868 m_pTreeNetworkNAT->setColumnCount(2); 869 m_pTreeNetworkNAT->header()->setStretchLastSection(false); 870 m_pTreeNetworkNAT->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); 871 m_pTreeNetworkNAT->header()->setSectionResizeMode(1, QHeaderView::Stretch); 872 m_pTreeNetworkNAT->setContextMenuPolicy(Qt::CustomContextMenu); 873 } 874 875 /* NAT Network toolbar created in the .ui file. */ 876 AssertPtrReturnVoid(m_pToolbarNetworkNAT); 877 { 878 /* Configure toolbar: */ 879 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize); 880 m_pToolbarNetworkNAT->setIconSize(QSize(iIconMetric, iIconMetric)); 881 m_pToolbarNetworkNAT->setOrientation(Qt::Vertical); 882 883 /* Create' Add NAT Network' action: */ 884 m_pActionAddNetworkNAT = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/add_host_iface_16px.png", 885 ":/add_host_iface_disabled_16px.png"), 886 QString(), this, SLOT(sltAddNetworkNAT())); 887 AssertPtrReturnVoid(m_pActionAddNetworkNAT); 888 { 889 /* Configure action: */ 890 m_pActionAddNetworkNAT->setShortcuts(QList<QKeySequence>() << QKeySequence("Ins") << QKeySequence("Ctrl+N")); 891 } 892 893 /* Create 'Edit NAT Network' action: */ 894 m_pActionEditNetworkNAT = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/edit_host_iface_16px.png", 895 ":/edit_host_iface_disabled_16px.png"), 896 QString(), this, SLOT(sltEditNetworkNAT())); 897 AssertPtrReturnVoid(m_pActionEditNetworkNAT); 898 { 899 /* Configure action: */ 900 m_pActionEditNetworkNAT->setShortcuts(QList<QKeySequence>() << QKeySequence("Space") << QKeySequence("F2")); 901 } 902 903 /* Create 'Remove NAT Network' action: */ 904 m_pActionRemoveNetworkNAT = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/remove_host_iface_16px.png", 905 ":/remove_host_iface_disabled_16px.png"), 906 QString(), this, SLOT(sltRemoveNetworkNAT())); 907 AssertPtrReturnVoid(m_pActionRemoveNetworkNAT); 908 { 909 /* Configure action: */ 910 m_pActionRemoveNetworkNAT->setShortcuts(QList<QKeySequence>() << QKeySequence("Del") << QKeySequence("Ctrl+R")); 911 } 912 } 913 } 914 } 915 916 void UIGlobalSettingsNetwork::prepareTabHost() 917 { 918 /* Tab and it's layout created in the .ui file. */ 919 { 920 #ifdef VBOX_WS_MAC 921 /* On macOS we can do a bit of smoothness: */ 922 m_pLayoutHostOnly->setContentsMargins(0, 0, 0, 0); 923 #endif 924 925 /* Host Network tree-widget created in the .ui file. */ 926 AssertPtrReturnVoid(m_pTreeNetworkHost); 927 { 928 /* Configure tree-widget: */ 929 m_pTreeNetworkHost->header()->hide(); 930 m_pTreeNetworkHost->setContextMenuPolicy(Qt::CustomContextMenu); 931 } 932 933 /* Host Network toolbar created in the .ui file. */ 934 AssertPtrReturnVoid(m_pToolbarNetworkHost); 935 { 936 /* Configure toolbar: */ 937 const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize); 938 m_pToolbarNetworkHost->setIconSize(QSize(iIconMetric, iIconMetric)); 939 m_pToolbarNetworkHost->setOrientation(Qt::Vertical); 940 941 /* Create 'Add Host Network' action: */ 942 m_pActionAddNetworkHost = m_pToolbarNetworkHost->addAction(UIIconPool::iconSet(":/add_host_iface_16px.png", 943 ":/add_host_iface_disabled_16px.png"), 944 QString(), this, SLOT(sltAddNetworkHost())); 945 AssertPtrReturnVoid(m_pActionAddNetworkHost); 946 { 947 /* Configure action: */ 948 m_pActionAddNetworkHost->setShortcuts(QList<QKeySequence>() << QKeySequence("Ins") << QKeySequence("Ctrl+N")); 949 } 950 951 /* Create 'Edit Host Network' action: */ 952 m_pActionEditNetworkHost = m_pToolbarNetworkHost->addAction(UIIconPool::iconSet(":/edit_host_iface_16px.png", 953 ":/edit_host_iface_disabled_16px.png"), 954 QString(), this, SLOT(sltEditNetworkHost())); 955 AssertPtrReturnVoid(m_pActionEditNetworkHost); 956 { 957 /* Configure action: */ 958 m_pActionEditNetworkHost->setShortcuts(QList<QKeySequence>() << QKeySequence("Space") << QKeySequence("F2")); 959 } 960 961 /* Create 'Remove Host Network' action: */ 962 m_pActionRemoveNetworkHost = m_pToolbarNetworkHost->addAction(UIIconPool::iconSet(":/remove_host_iface_16px.png", 963 ":/remove_host_iface_disabled_16px.png"), 964 QString(), this, SLOT(sltRemoveNetworkHost())); 965 AssertPtrReturnVoid(m_pActionRemoveNetworkHost); 966 { 967 /* Configure action: */ 968 m_pActionRemoveNetworkHost->setShortcuts(QList<QKeySequence>() << QKeySequence("Del") << QKeySequence("Ctrl+R")); 969 } 970 } 971 } 972 } 973 974 void UIGlobalSettingsNetwork::prepareConnections() 975 { 976 /* Configure 'NAT Network' connections: */ 977 connect(m_pTreeNetworkNAT, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), 978 this, SLOT(sltHandleCurrentItemChangeNetworkNAT())); 979 connect(m_pTreeNetworkNAT, SIGNAL(customContextMenuRequested(const QPoint &)), 980 this, SLOT(sltHandleContextMenuRequestNetworkNAT(const QPoint &))); 981 connect(m_pTreeNetworkNAT, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), 982 this, SLOT(sltEditNetworkNAT())); 983 connect(m_pTreeNetworkNAT, SIGNAL(itemChanged(QTreeWidgetItem *, int)), 984 this, SLOT(sltHandleItemChangeNetworkNAT(QTreeWidgetItem *))); 985 986 /* Configure 'Host Network' connections: */ 987 connect(m_pTreeNetworkHost, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), 988 this, SLOT(sltHandleCurrentItemChangeNetworkHost())); 989 connect(m_pTreeNetworkHost, SIGNAL(customContextMenuRequested(const QPoint &)), 990 this, SLOT(sltHandleContextMenuRequestNetworkHost(const QPoint &))); 991 connect(m_pTreeNetworkHost, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), 992 this, SLOT(sltEditNetworkHost())); 993 } 994 995 void UIGlobalSettingsNetwork::cleanup() 996 { 997 /* Cleanup cache: */ 998 delete m_pCache; 999 m_pCache = 0; 1000 } 1001 1002 bool UIGlobalSettingsNetwork::saveNetworkData() 1003 { 1004 /* Prepare result: */ 1005 bool fSuccess = true; 1006 /* Save network settings from the cache: */ 1007 if (fSuccess && m_pCache->wasChanged()) 1008 { 1009 /* For each NAT network ('removing' step): */ 1010 // We need to separately remove NAT networks first because 1011 // there could be name collisions with the existing NAT networks. 1012 for (int i = 0; fSuccess && i < m_pCache->childCount1(); ++i) 1013 { 1014 /* Get NAT network cache: */ 1015 const UISettingsCacheGlobalNetworkNAT &cache = m_pCache->child1(i); 1016 1017 /* Remove NAT network marked for 'remove' or 'update' (if it can't be updated): */ 1018 if (cache.wasRemoved() || (cache.wasUpdated() && !isNetworkCouldBeUpdated(cache))) 1019 fSuccess = removeNetworkNAT(cache); 1020 } 1021 /* For each NAT network ('creating' step): */ 1022 for (int i = 0; fSuccess && i < m_pCache->childCount1(); ++i) 1023 { 1024 /* Get NAT network cache: */ 1025 const UISettingsCacheGlobalNetworkNAT &cache = m_pCache->child1(i); 1026 1027 /* Create NAT network marked for 'create' or 'update' (if it can't be updated): */ 1028 if (cache.wasCreated() || (cache.wasUpdated() && !isNetworkCouldBeUpdated(cache))) 1029 fSuccess = createNetworkNAT(cache); 1030 1031 else 1032 1033 /* Update NAT network marked for 'update' (if it can be updated): */ 1034 if (cache.wasUpdated() && isNetworkCouldBeUpdated(cache)) 1035 fSuccess = updateNetworkNAT(cache); 1036 } 1037 1038 /* For each Host network ('updating' step): */ 1039 for (int i = 0; fSuccess && i < m_pCache->childCount2(); ++i) 1040 { 1041 const UISettingsCacheGlobalNetworkHost &cache = m_pCache->child2(i); 1042 if (cache.wasUpdated()) 1043 fSuccess = saveDataNetworkHost(m_pCache->child2(i)); 1044 } 1045 } 1046 /* Return result: */ 1047 return fSuccess; 1048 } 1049 1050 void UIGlobalSettingsNetwork::loadToCacheFromNetworkNAT(const CNATNetwork &network, UISettingsCacheGlobalNetworkNAT &cache) 1051 { 1052 /* Prepare old NAT data: */ 1053 UIDataSettingsGlobalNetworkNAT oldNATData; 1054 1055 /* Load NAT network settings: */ 1056 oldNATData.m_fEnabled = network.GetEnabled(); 1057 oldNATData.m_strName = network.GetNetworkName(); 1058 oldNATData.m_strNewName = oldNATData.m_strName; 1059 oldNATData.m_strCIDR = network.GetNetwork(); 1060 oldNATData.m_fSupportsDHCP = network.GetNeedDhcpServer(); 1061 oldNATData.m_fSupportsIPv6 = network.GetIPv6Enabled(); 1062 oldNATData.m_fAdvertiseDefaultIPv6Route = network.GetAdvertiseDefaultIPv6RouteEnabled(); 1063 1064 /* Load IPv4 rules: */ 1065 foreach (QString strIPv4Rule, network.GetPortForwardRules4()) 1066 { 1067 /* Replace all ':' with ',' first: */ 1068 strIPv4Rule.replace(':', ','); 1069 /* Parse rules: */ 1070 QStringList rules = strIPv4Rule.split(','); 1071 Assert(rules.size() == 6); 1072 if (rules.size() != 6) 1073 continue; 1074 cache.child1(rules.at(0)).cacheInitialData(UIDataPortForwardingRule(rules.at(0), 1075 gpConverter->fromInternalString<KNATProtocol>(rules.at(1)), 1076 QString(rules.at(2)).remove('[').remove(']'), 1077 rules.at(3).toUInt(), 1078 QString(rules.at(4)).remove('[').remove(']'), 1079 rules.at(5).toUInt())); 1080 } 1081 1082 /* Load IPv6 rules: */ 1083 foreach (QString strIPv6Rule, network.GetPortForwardRules6()) 1084 { 1085 /* Replace all ':' with ',' first: */ 1086 strIPv6Rule.replace(':', ','); 1087 /* But replace ',' back with ':' for addresses: */ 1088 QRegExp re("\\[[0-9a-fA-F,]*,[0-9a-fA-F,]*\\]"); 1089 re.setMinimal(true); 1090 while (re.indexIn(strIPv6Rule) != -1) 1091 { 1092 QString strCapOld = re.cap(0); 1093 QString strCapNew = strCapOld; 1094 strCapNew.replace(',', ':'); 1095 strIPv6Rule.replace(strCapOld, strCapNew); 1096 } 1097 /* Parse rules: */ 1098 QStringList rules = strIPv6Rule.split(','); 1099 Assert(rules.size() == 6); 1100 if (rules.size() != 6) 1101 continue; 1102 cache.child2(rules.at(0)).cacheInitialData(UIDataPortForwardingRule(rules.at(0), 1103 gpConverter->fromInternalString<KNATProtocol>(rules.at(1)), 1104 QString(rules.at(2)).remove('[').remove(']'), 1105 rules.at(3).toUInt(), 1106 QString(rules.at(4)).remove('[').remove(']'), 1107 rules.at(5).toUInt())); 1108 } 1109 1110 /* Cache old NAT data: */ 1111 cache.cacheInitialData(oldNATData); 1112 } 1113 1114 bool UIGlobalSettingsNetwork::removeNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache) 1115 { 1116 /* Prepare result: */ 1117 bool fSuccess = true; 1118 /* Save NAT settings from the cache: */ 1119 if (fSuccess) 1120 { 1121 /* Get old NAT data from the cache: */ 1122 const UIDataSettingsGlobalNetworkNAT &oldNatData = cache.base(); 1123 /* Get new NAT data from the cache: */ 1124 //const UIDataSettingsGlobalNetworkNAT &newNatData = cache.data(); 1125 1126 /* Get VBox for further activities: */ 1127 CVirtualBox comVBox = vboxGlobal().virtualBox(); 1128 /* Search for a NAT network with required name: */ 1129 CNATNetwork comNetwork = comVBox.FindNATNetworkByName(oldNatData.m_strName); 1130 fSuccess = comVBox.isOk() && comNetwork.isNotNull(); 1131 1132 /* Remove NAT network: */ 1133 if (fSuccess) 1134 { 1135 comVBox.RemoveNATNetwork(comNetwork); 1136 fSuccess = comVBox.isOk(); 1137 } 232 /* Show interface creation progress: */ 233 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 1138 234 1139 235 /* Show error message if necessary: */ 1140 if (!fSuccess) 1141 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comVBox)); 1142 } 1143 /* Return result: */ 1144 return fSuccess; 1145 } 1146 1147 bool UIGlobalSettingsNetwork::createNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache) 1148 { 1149 /* Prepare result: */ 1150 bool fSuccess = true; 1151 /* Save NAT settings from the cache: */ 1152 if (fSuccess) 1153 { 1154 /* Get old NAT data from the cache: */ 1155 //const UIDataSettingsGlobalNetworkNAT &oldNatData = cache.base(); 1156 /* Get new NAT data from the cache: */ 1157 const UIDataSettingsGlobalNetworkNAT &newNatData = cache.data(); 1158 1159 /* Get VBox for further activities: */ 1160 CVirtualBox comVBox = vboxGlobal().virtualBox(); 1161 /* Create NAT network with required name: */ 1162 CNATNetwork comNetwork = comVBox.CreateNATNetwork(newNatData.m_strNewName); 1163 fSuccess = comVBox.isOk() && comNetwork.isNotNull(); 1164 1165 /* Show error message if necessary: */ 1166 if (!fSuccess) 1167 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comVBox)); 236 if (!progress.isOk() || progress.GetResultCode() != 0) 237 msgCenter().cannotCreateHostNetworkInterface(progress, this); 1168 238 else 1169 239 { 1170 /* Save whether NAT network is enabled: */ 1171 if (fSuccess) 1172 { 1173 comNetwork.SetEnabled(newNatData.m_fEnabled); 1174 fSuccess = comNetwork.isOk(); 1175 } 1176 /* Save NAT network name: */ 1177 if (fSuccess) 1178 { 1179 comNetwork.SetNetworkName(newNatData.m_strNewName); 1180 fSuccess = comNetwork.isOk(); 1181 } 1182 /* Save NAT network CIDR: */ 1183 if (fSuccess) 1184 { 1185 comNetwork.SetNetwork(newNatData.m_strCIDR); 1186 fSuccess = comNetwork.isOk(); 1187 } 1188 /* Save whether NAT network needs DHCP server: */ 1189 if (fSuccess) 1190 { 1191 comNetwork.SetNeedDhcpServer(newNatData.m_fSupportsDHCP); 1192 fSuccess = comNetwork.isOk(); 1193 } 1194 /* Save whether NAT network supports IPv6: */ 1195 if (fSuccess) 1196 { 1197 comNetwork.SetIPv6Enabled(newNatData.m_fSupportsIPv6); 1198 fSuccess = comNetwork.isOk(); 1199 } 1200 /* Save whether NAT network should advertise default IPv6 route: */ 1201 if (fSuccess) 1202 { 1203 comNetwork.SetAdvertiseDefaultIPv6RouteEnabled(newNatData.m_fAdvertiseDefaultIPv6Route); 1204 fSuccess = comNetwork.isOk(); 1205 } 1206 1207 /* Save IPv4 forwarding rules: */ 1208 for (int i = 0; fSuccess && i < cache.childCount1(); ++i) 1209 { 1210 /* Get rule cache: */ 1211 const UISettingsCachePortForwardingRule &ruleCache = cache.child1(i); 1212 1213 /* Create rule not marked for 'remove': */ 1214 if (!ruleCache.wasRemoved()) 1215 { 1216 comNetwork.AddPortForwardRule(false, 1217 ruleCache.data().name, ruleCache.data().protocol, 1218 ruleCache.data().hostIp, ruleCache.data().hostPort.value(), 1219 ruleCache.data().guestIp, ruleCache.data().guestPort.value()); 1220 fSuccess = comNetwork.isOk(); 1221 } 1222 } 1223 1224 /* Save IPv6 forwarding rules: */ 1225 for (int i = 0; fSuccess && i < cache.childCount2(); ++i) 1226 { 1227 /* Get rule cache: */ 1228 const UISettingsCachePortForwardingRule &ruleCache = cache.child2(i); 1229 1230 /* Create rule not marked for 'remove': */ 1231 if (!ruleCache.wasRemoved()) 1232 { 1233 comNetwork.AddPortForwardRule(true, 1234 ruleCache.data().name, ruleCache.data().protocol, 1235 ruleCache.data().hostIp, ruleCache.data().hostPort.value(), 1236 ruleCache.data().guestIp, ruleCache.data().guestPort.value()); 1237 fSuccess = comNetwork.isOk(); 1238 } 1239 } 240 /* Get network name for further activities: */ 241 const QString strNetworkName = comInterface.GetNetworkName(); 1240 242 1241 243 /* Show error message if necessary: */ 1242 if (!fSuccess) 1243 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comNetwork)); 1244 } 1245 } 1246 /* Return result: */ 1247 return fSuccess; 1248 } 1249 1250 bool UIGlobalSettingsNetwork::updateNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache) 1251 { 1252 /* Prepare result: */ 1253 bool fSuccess = true; 1254 /* Save NAT settings from the cache: */ 1255 if (fSuccess) 1256 { 1257 /* Get old NAT data from the cache: */ 1258 const UIDataSettingsGlobalNetworkNAT &oldNatData = cache.base(); 1259 /* Get new NAT data from the cache: */ 1260 const UIDataSettingsGlobalNetworkNAT &newNatData = cache.data(); 1261 1262 /* Get VBox for further activities: */ 1263 CVirtualBox comVBox = vboxGlobal().virtualBox(); 1264 /* Search for a NAT network with required name: */ 1265 CNATNetwork comNetwork = comVBox.FindNATNetworkByName(oldNatData.m_strName); 1266 fSuccess = comVBox.isOk() && comNetwork.isNotNull(); 1267 1268 /* Show error message if necessary: */ 1269 if (!fSuccess) 1270 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comVBox)); 1271 else 1272 { 1273 /* Save whether NAT network is enabled: */ 1274 if (fSuccess && newNatData.m_fEnabled != oldNatData.m_fEnabled) 1275 { 1276 comNetwork.SetEnabled(newNatData.m_fEnabled); 1277 fSuccess = comNetwork.isOk(); 1278 } 1279 /* Save NAT network name: */ 1280 if (fSuccess && newNatData.m_strNewName != oldNatData.m_strNewName) 1281 { 1282 comNetwork.SetNetworkName(newNatData.m_strNewName); 1283 fSuccess = comNetwork.isOk(); 1284 } 1285 /* Save NAT network CIDR: */ 1286 if (fSuccess && newNatData.m_strCIDR != oldNatData.m_strCIDR) 1287 { 1288 comNetwork.SetNetwork(newNatData.m_strCIDR); 1289 fSuccess = comNetwork.isOk(); 1290 } 1291 /* Save whether NAT network needs DHCP server: */ 1292 if (fSuccess && newNatData.m_fSupportsDHCP != oldNatData.m_fSupportsDHCP) 1293 { 1294 comNetwork.SetNeedDhcpServer(newNatData.m_fSupportsDHCP); 1295 fSuccess = comNetwork.isOk(); 1296 } 1297 /* Save whether NAT network supports IPv6: */ 1298 if (fSuccess && newNatData.m_fSupportsIPv6 != oldNatData.m_fSupportsIPv6) 1299 { 1300 comNetwork.SetIPv6Enabled(newNatData.m_fSupportsIPv6); 1301 fSuccess = comNetwork.isOk(); 1302 } 1303 /* Save whether NAT network should advertise default IPv6 route: */ 1304 if (fSuccess && newNatData.m_fAdvertiseDefaultIPv6Route != oldNatData.m_fAdvertiseDefaultIPv6Route) 1305 { 1306 comNetwork.SetAdvertiseDefaultIPv6RouteEnabled(newNatData.m_fAdvertiseDefaultIPv6Route); 1307 fSuccess = comNetwork.isOk(); 1308 } 1309 1310 /* Save IPv4 forwarding rules: */ 1311 for (int i = 0; fSuccess && i < cache.childCount1(); ++i) 1312 { 1313 /* Get rule cache: */ 1314 const UISettingsCachePortForwardingRule &ruleCache = cache.child1(i); 1315 1316 /* Remove rule marked for 'remove' or 'update': */ 1317 if (ruleCache.wasRemoved() || ruleCache.wasUpdated()) 1318 { 1319 comNetwork.RemovePortForwardRule(false, 1320 ruleCache.base().name); 1321 fSuccess = comNetwork.isOk(); 1322 } 1323 } 1324 for (int i = 0; fSuccess && i < cache.childCount1(); ++i) 1325 { 1326 /* Get rule cache: */ 1327 const UISettingsCachePortForwardingRule &ruleCache = cache.child1(i); 1328 1329 /* Create rule marked for 'create' or 'update': */ 1330 if (ruleCache.wasCreated() || ruleCache.wasUpdated()) 1331 { 1332 comNetwork.AddPortForwardRule(false, 1333 ruleCache.data().name, ruleCache.data().protocol, 1334 ruleCache.data().hostIp, ruleCache.data().hostPort.value(), 1335 ruleCache.data().guestIp, ruleCache.data().guestPort.value()); 1336 fSuccess = comNetwork.isOk(); 1337 } 1338 } 1339 1340 /* Save IPv6 forwarding rules: */ 1341 for (int i = 0; fSuccess && i < cache.childCount2(); ++i) 1342 { 1343 /* Get rule cache: */ 1344 const UISettingsCachePortForwardingRule &ruleCache = cache.child2(i); 1345 1346 /* Remove rule marked for 'remove' or 'update': */ 1347 if (ruleCache.wasRemoved() || ruleCache.wasUpdated()) 1348 { 1349 comNetwork.RemovePortForwardRule(true, 1350 ruleCache.base().name); 1351 fSuccess = comNetwork.isOk(); 1352 } 1353 } 1354 for (int i = 0; fSuccess && i < cache.childCount2(); ++i) 1355 { 1356 /* Get rule cache: */ 1357 const UISettingsCachePortForwardingRule &ruleCache = cache.child2(i); 1358 1359 /* Create rule marked for 'create' or 'update': */ 1360 if (ruleCache.wasCreated() || ruleCache.wasUpdated()) 1361 { 1362 comNetwork.AddPortForwardRule(true, 1363 ruleCache.data().name, ruleCache.data().protocol, 1364 ruleCache.data().hostIp, ruleCache.data().hostPort.value(), 1365 ruleCache.data().guestIp, ruleCache.data().guestPort.value()); 1366 fSuccess = comNetwork.isOk(); 1367 } 1368 } 1369 1370 /* Show error message if necessary: */ 1371 if (!fSuccess) 1372 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comNetwork)); 1373 } 1374 } 1375 /* Return result: */ 1376 return fSuccess; 1377 } 1378 1379 void UIGlobalSettingsNetwork::createTreeWidgetItemForNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache) 1380 { 1381 /* Get old NAT data: */ 1382 const UIDataSettingsGlobalNetworkNAT oldNATData = cache.base(); 1383 1384 /* Load old port forwarding rules: */ 1385 UIPortForwardingDataList ipv4rules; 1386 UIPortForwardingDataList ipv6rules; 1387 for (int i = 0; i < cache.childCount1(); ++i) 1388 ipv4rules << cache.child1(i).base(); 1389 for (int i = 0; i < cache.childCount2(); ++i) 1390 ipv6rules << cache.child2(i).base(); 1391 1392 /* Pass to wrapper below: */ 1393 createTreeWidgetItemForNetworkNAT(oldNATData, ipv4rules, ipv6rules, false /* choose item? */); 1394 } 1395 1396 void UIGlobalSettingsNetwork::createTreeWidgetItemForNetworkNAT(const UIDataSettingsGlobalNetworkNAT &data, 1397 const UIPortForwardingDataList &ipv4rules, 1398 const UIPortForwardingDataList &ipv6rules, 1399 bool fChooseItem /* = false */) 1400 { 1401 /* Create tree-widget item: */ 1402 UIItemNetworkNAT *pItem = new UIItemNetworkNAT; 1403 AssertPtrReturnVoid(pItem); 1404 { 1405 /* Configure item: */ 1406 pItem->UIDataSettingsGlobalNetworkNAT::operator=(data); 1407 pItem->setIpv4rules(ipv4rules); 1408 pItem->setIpv6rules(ipv6rules); 1409 pItem->updateFields(); 1410 1411 /* Add item to the tree-widget: */ 1412 m_pTreeNetworkNAT->addTopLevelItem(pItem); 1413 } 1414 1415 /* And choose it as current if necessary: */ 1416 if (fChooseItem) 1417 m_pTreeNetworkNAT->setCurrentItem(pItem); 1418 } 1419 1420 void UIGlobalSettingsNetwork::removeTreeWidgetItemOfNetworkNAT(UIItemNetworkNAT *pItem) 1421 { 1422 /* Delete passed item: */ 1423 delete pItem; 1424 } 1425 1426 bool UIGlobalSettingsNetwork::isNetworkCouldBeUpdated(const UISettingsCacheGlobalNetworkNAT &cache) const 1427 { 1428 /* INATNetwork interface allows to set 'name' attribute 1429 * which can conflict with another one NAT network name. 1430 * This attribute could be changed in GUI directly or indirectly. 1431 * For such cases we have to recreate INATNetwork instance, 1432 * for other cases we will update NAT network attributes only. */ 1433 const UIDataSettingsGlobalNetworkNAT &oldNATData = cache.base(); 1434 const UIDataSettingsGlobalNetworkNAT &newNATData = cache.data(); 1435 return true 1436 && (newNATData.m_strNewName == oldNATData.m_strNewName) 1437 ; 1438 } 1439 1440 void UIGlobalSettingsNetwork::loadToCacheFromNetworkHost(const CHostNetworkInterface &iface, UISettingsCacheGlobalNetworkHost &cache) 1441 { 1442 /* Prepare old NAT data: */ 1443 UIDataSettingsGlobalNetworkHost oldHostData; 1444 1445 /* Get DHCP server (create if necessary): */ 1446 CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName()); 1447 if (dhcp.isNull()) 1448 { 1449 CVirtualBox vbox = vboxGlobal().virtualBox(); 1450 vbox.CreateDHCPServer(iface.GetNetworkName()); 1451 if (!vbox.isOk()) 1452 { 1453 msgCenter().cannotCreateDHCPServer(vbox, this); 1454 return; 1455 } 1456 dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName()); 1457 } 1458 Assert(!dhcp.isNull()); 1459 if (dhcp.isNull()) 1460 return; 1461 1462 /* Host interface settings: */ 1463 oldHostData.m_interface.m_strName = iface.GetName(); 1464 oldHostData.m_interface.m_fDhcpClientEnabled = iface.GetDHCPEnabled(); 1465 oldHostData.m_interface.m_strInterfaceAddress = iface.GetIPAddress(); 1466 oldHostData.m_interface.m_strInterfaceMask = iface.GetNetworkMask(); 1467 oldHostData.m_interface.m_fIpv6Supported = iface.GetIPV6Supported(); 1468 oldHostData.m_interface.m_strInterfaceAddress6 = iface.GetIPV6Address(); 1469 oldHostData.m_interface.m_strInterfaceMaskLength6 = QString::number(iface.GetIPV6NetworkMaskPrefixLength()); 1470 1471 /* DHCP server settings: */ 1472 oldHostData.m_dhcpserver.m_fDhcpServerEnabled = dhcp.GetEnabled(); 1473 oldHostData.m_dhcpserver.m_strDhcpServerAddress = dhcp.GetIPAddress(); 1474 oldHostData.m_dhcpserver.m_strDhcpServerMask = dhcp.GetNetworkMask(); 1475 oldHostData.m_dhcpserver.m_strDhcpLowerAddress = dhcp.GetLowerIP(); 1476 oldHostData.m_dhcpserver.m_strDhcpUpperAddress = dhcp.GetUpperIP(); 1477 1478 /* Cache old NAT data: */ 1479 cache.cacheInitialData(oldHostData); 1480 } 1481 1482 bool UIGlobalSettingsNetwork::saveDataNetworkHost(const UISettingsCacheGlobalNetworkHost &cache) 1483 { 1484 /* Prepare result: */ 1485 bool fSuccess = true; 1486 /* Save host-only settings from the cache: */ 1487 if (fSuccess) 1488 { 1489 /* Get old host-only data from the cache: */ 1490 const UIDataSettingsGlobalNetworkHost &oldHostOnlyData = cache.base(); 1491 /* Get new host-only data from the cache: */ 1492 const UIDataSettingsGlobalNetworkHost &newHostOnlyData = cache.data(); 1493 1494 /* Get VBox for further activities: */ 1495 CHost comHost = vboxGlobal().host(); 1496 /* Search for a host-only interface with the same name: */ 1497 CHostNetworkInterface comInterface = comHost.FindHostNetworkInterfaceByName(newHostOnlyData.m_interface.m_strName); 1498 fSuccess = comHost.isOk() && comInterface.isNotNull(); 1499 1500 /* Show error message if necessary: */ 1501 if (!fSuccess) 1502 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comHost)); 1503 else 1504 { 1505 /* Automatic host interface configuration: */ 1506 if ( fSuccess 1507 && newHostOnlyData.m_interface.m_fDhcpClientEnabled 1508 && newHostOnlyData.m_interface.m_fDhcpClientEnabled != oldHostOnlyData.m_interface.m_fDhcpClientEnabled) 1509 { 1510 comInterface.EnableDynamicIPConfig(); 1511 fSuccess = comInterface.isOk(); 1512 } 1513 1514 else 1515 1516 /* Manual host interface configuration: */ 1517 if ( fSuccess 1518 && !newHostOnlyData.m_interface.m_fDhcpClientEnabled) 1519 { 1520 if ( fSuccess 1521 && ( newHostOnlyData.m_interface.m_fDhcpClientEnabled != oldHostOnlyData.m_interface.m_fDhcpClientEnabled 1522 || newHostOnlyData.m_interface.m_strInterfaceAddress != oldHostOnlyData.m_interface.m_strInterfaceAddress 1523 || newHostOnlyData.m_interface.m_strInterfaceMask != oldHostOnlyData.m_interface.m_strInterfaceMask)) 1524 { 1525 comInterface.EnableStaticIPConfig(newHostOnlyData.m_interface.m_strInterfaceAddress, newHostOnlyData.m_interface.m_strInterfaceMask); 1526 fSuccess = comInterface.isOk(); 1527 } 1528 1529 if ( fSuccess 1530 && newHostOnlyData.m_interface.m_fIpv6Supported 1531 && ( newHostOnlyData.m_interface.m_fDhcpClientEnabled != oldHostOnlyData.m_interface.m_fDhcpClientEnabled 1532 || newHostOnlyData.m_interface.m_strInterfaceAddress6 != oldHostOnlyData.m_interface.m_strInterfaceAddress6 1533 || newHostOnlyData.m_interface.m_strInterfaceMaskLength6 != oldHostOnlyData.m_interface.m_strInterfaceMaskLength6)) 1534 { 1535 comInterface.EnableStaticIPConfigV6(newHostOnlyData.m_interface.m_strInterfaceAddress6, newHostOnlyData.m_interface.m_strInterfaceMaskLength6.toULong()); 1536 fSuccess = comInterface.isOk(); 1537 } 1538 } 1539 1540 /* Get network name for further activities: */ 1541 QString strNetworkName; 1542 if (fSuccess) 1543 { 1544 strNetworkName = comInterface.GetNetworkName(); 1545 fSuccess = comInterface.isOk(); 1546 } 1547 1548 /* Show error message if necessary: */ 1549 if (!fSuccess) 1550 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comInterface)); 244 if (!comInterface.isOk()) 245 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 1551 246 else 1552 247 { 1553 248 /* Get VBox for further activities: */ 1554 249 CVirtualBox comVBox = vboxGlobal().virtualBox(); 1555 /* Search for a DHCP server with the same name: */ 250 251 /* Find corresponding DHCP server (create if necessary): */ 1556 252 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 1557 fSuccess = comVBox.isOk() && comServer.isNotNull(); 253 if (!comVBox.isOk() || comServer.isNull()) 254 comServer = comVBox.CreateDHCPServer(strNetworkName); 1558 255 1559 256 /* Show error message if necessary: */ 1560 if (!fSuccess) 1561 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comVBox)); 257 if (!comVBox.isOk() || comServer.isNull()) 258 msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this); 259 } 260 261 /* Add interface to the tree: */ 262 UIDataHostNetwork data; 263 loadHostNetwork(comInterface, data); 264 createItemForNetworkHost(data, true); 265 266 /* Sort list by the 1st column: */ 267 m_pTreeWidget->sortByColumn(0, Qt::AscendingOrder); 268 } 269 } 270 } 271 272 void UIHostNetworkManager::sltEditHostNetwork() 273 { 274 /* Get network item: */ 275 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem()); 276 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n")); 277 278 /* Get item data: */ 279 UIDataHostNetwork oldData = *pItem; 280 UIDataHostNetwork newData = oldData; 281 282 /* Show details dialog: */ 283 UIHostNetworkDetailsDialog details(this, newData); 284 if (details.exec() != QDialog::Accepted) 285 return; 286 287 /* Get host for further activities: */ 288 CHost comHost = vboxGlobal().host(); 289 290 /* Find corresponding interface: */ 291 CHostNetworkInterface comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName); 292 293 /* Show error message if necessary: */ 294 if (!comHost.isOk() || comInterface.isNull()) 295 msgCenter().cannotFindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this); 296 else 297 { 298 /* Save IPv4 interface configuration: */ 299 if ( comInterface.isOk() 300 && ( newData.m_interface.m_strInterfaceAddress != oldData.m_interface.m_strInterfaceAddress 301 || newData.m_interface.m_strInterfaceMask != oldData.m_interface.m_strInterfaceMask)) 302 comInterface.EnableStaticIPConfig(newData.m_interface.m_strInterfaceAddress, newData.m_interface.m_strInterfaceMask); 303 /* Save IPv6 interface configuration: */ 304 if ( comInterface.isOk() 305 && newData.m_interface.m_fIpv6Supported 306 && ( newData.m_interface.m_strInterfaceAddress6 != oldData.m_interface.m_strInterfaceAddress6 307 || newData.m_interface.m_strInterfaceMaskLength6 != oldData.m_interface.m_strInterfaceMaskLength6)) 308 comInterface.EnableStaticIPConfigV6(newData.m_interface.m_strInterfaceAddress6, newData.m_interface.m_strInterfaceMaskLength6.toULong()); 309 310 /* Show error message if necessary: */ 311 if (!comInterface.isOk()) 312 msgCenter().cannotSaveHostNetworkInterfaceParameter(comInterface, this); 313 else 314 { 315 /* Get network name for further activities: */ 316 const QString strNetworkName = comInterface.GetNetworkName(); 317 318 /* Show error message if necessary: */ 319 if (!comInterface.isOk()) 320 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 321 else 322 { 323 /* Get VBox for further activities: */ 324 CVirtualBox comVBox = vboxGlobal().virtualBox(); 325 326 /* Find corresponding DHCP server (create if necessary): */ 327 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 328 if (!comVBox.isOk() || comServer.isNull()) 329 comServer = comVBox.CreateDHCPServer(strNetworkName); 330 331 /* Show error message if necessary: */ 332 if (!comVBox.isOk() || comServer.isNull()) 333 msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this); 1562 334 else 1563 335 { 1564 336 /* Save whether DHCP server is enabled: */ 1565 if (fSuccess && newHostOnlyData.m_dhcpserver.m_fDhcpServerEnabled != oldHostOnlyData.m_dhcpserver.m_fDhcpServerEnabled) 1566 { 1567 comServer.SetEnabled(newHostOnlyData.m_dhcpserver.m_fDhcpServerEnabled); 1568 fSuccess = comServer.isOk(); 1569 } 1570 if ( fSuccess 1571 && newHostOnlyData.m_dhcpserver.m_fDhcpServerEnabled 1572 && ( newHostOnlyData.m_dhcpserver.m_strDhcpServerAddress != oldHostOnlyData.m_dhcpserver.m_strDhcpServerAddress 1573 || newHostOnlyData.m_dhcpserver.m_strDhcpServerMask != oldHostOnlyData.m_dhcpserver.m_strDhcpServerMask 1574 || newHostOnlyData.m_dhcpserver.m_strDhcpLowerAddress != oldHostOnlyData.m_dhcpserver.m_strDhcpLowerAddress 1575 || newHostOnlyData.m_dhcpserver.m_strDhcpUpperAddress != oldHostOnlyData.m_dhcpserver.m_strDhcpUpperAddress)) 1576 { 1577 comServer.SetConfiguration(newHostOnlyData.m_dhcpserver.m_strDhcpServerAddress, newHostOnlyData.m_dhcpserver.m_strDhcpServerMask, 1578 newHostOnlyData.m_dhcpserver.m_strDhcpLowerAddress, newHostOnlyData.m_dhcpserver.m_strDhcpUpperAddress); 1579 fSuccess = comServer.isOk(); 1580 } 337 if ( comServer.isOk() 338 && newData.m_dhcpserver.m_fDhcpServerEnabled != oldData.m_dhcpserver.m_fDhcpServerEnabled) 339 comServer.SetEnabled(newData.m_dhcpserver.m_fDhcpServerEnabled); 340 /* Save DHCP server configuration: */ 341 if ( comServer.isOk() 342 && newData.m_dhcpserver.m_fDhcpServerEnabled 343 && ( newData.m_dhcpserver.m_strDhcpServerAddress != oldData.m_dhcpserver.m_strDhcpServerAddress 344 || newData.m_dhcpserver.m_strDhcpServerMask != oldData.m_dhcpserver.m_strDhcpServerMask 345 || newData.m_dhcpserver.m_strDhcpLowerAddress != oldData.m_dhcpserver.m_strDhcpLowerAddress 346 || newData.m_dhcpserver.m_strDhcpUpperAddress != oldData.m_dhcpserver.m_strDhcpUpperAddress)) 347 comServer.SetConfiguration(newData.m_dhcpserver.m_strDhcpServerAddress, newData.m_dhcpserver.m_strDhcpServerMask, 348 newData.m_dhcpserver.m_strDhcpLowerAddress, newData.m_dhcpserver.m_strDhcpUpperAddress); 1581 349 1582 350 /* Show error message if necessary: */ 1583 if (! fSuccess)1584 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comServer));351 if (!comServer.isOk()) 352 msgCenter().cannotSaveDHCPServerParameter(comServer, this); 1585 353 } 1586 354 } 1587 355 } 1588 } 1589 /* Return result: */ 1590 return fSuccess; 1591 } 1592 1593 void UIGlobalSettingsNetwork::createTreeWidgetItemForNetworkHost(const UISettingsCacheGlobalNetworkHost &cache, bool fChooseItem) 1594 { 1595 /* Add new item to the tree: */ 1596 UIItemNetworkHost *pItem = new UIItemNetworkHost; 1597 pItem->UIDataSettingsGlobalNetworkHost::operator=(cache.base()); 1598 pItem->updateFields(); 1599 m_pTreeNetworkHost->addTopLevelItem(pItem); 1600 /* And choose it as current if necessary: */ 1601 if (fChooseItem) 1602 m_pTreeNetworkHost->setCurrentItem(pItem); 1603 } 1604 1605 void UIGlobalSettingsNetwork::removeTreeWidgetItemOfNetworkHost(UIItemNetworkHost *pItem) 1606 { 1607 /* Delete passed item: */ 1608 delete pItem; 1609 } 1610 356 357 /* Update interface in the tree: */ 358 UIDataHostNetwork data; 359 loadHostNetwork(comInterface, data); 360 updateItemForNetworkHost(data, true, pItem); 361 } 362 } 363 364 void UIHostNetworkManager::sltRemoveHostNetwork() 365 { 366 /* Get network item: */ 367 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem()); 368 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n")); 369 370 /* Get interface name: */ 371 const QString strInterfaceName(pItem->name()); 372 373 /* Confirm host network removal: */ 374 if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this)) 375 return; 376 377 /* Get host for further activities: */ 378 CHost comHost = vboxGlobal().host(); 379 380 /* Find corresponding interface: */ 381 const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName); 382 383 /* Show error message if necessary: */ 384 if (!comHost.isOk() || comInterface.isNull()) 385 msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this); 386 else 387 { 388 /* Get network name for further activities: */ 389 QString strNetworkName; 390 if (comInterface.isOk()) 391 strNetworkName = comInterface.GetNetworkName(); 392 /* Get interface id for further activities: */ 393 QString strInterfaceId; 394 if (comInterface.isOk()) 395 strInterfaceId = comInterface.GetId(); 396 397 /* Show error message if necessary: */ 398 if (!comInterface.isOk()) 399 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 400 else 401 { 402 /* Get VBox for further activities: */ 403 CVirtualBox comVBox = vboxGlobal().virtualBox(); 404 405 /* Find corresponding DHCP server: */ 406 const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 407 if (comVBox.isOk() && comServer.isNotNull()) 408 { 409 /* Remove server if any: */ 410 comVBox.RemoveDHCPServer(comServer); 411 412 /* Show error message if necessary: */ 413 if (!comVBox.isOk()) 414 msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this); 415 } 416 417 /* Remove interface finally: */ 418 CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId); 419 420 /* Show error message if necessary: */ 421 if (!comHost.isOk() || progress.isNull()) 422 msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this); 423 else 424 { 425 /* Show interface removal progress: */ 426 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 427 428 /* Show error message if necessary: */ 429 if (!progress.isOk() || progress.GetResultCode() != 0) 430 return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this); 431 else 432 { 433 /* Remove interface from the tree: */ 434 delete pItem; 435 } 436 } 437 } 438 } 439 } 440 441 void UIHostNetworkManager::sltHandleCurrentItemChange() 442 { 443 /* Get network item: */ 444 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem()); 445 446 /* Update actions availability: */ 447 m_pActionRemove->setEnabled(pItem); 448 m_pActionEdit->setEnabled(pItem); 449 } 450 451 void UIHostNetworkManager::sltHandleContextMenuRequest(const QPoint &pos) 452 { 453 /* Compose temporary context-menu: */ 454 QMenu menu; 455 if (m_pTreeWidget->itemAt(pos)) 456 { 457 menu.addAction(m_pActionEdit); 458 menu.addAction(m_pActionRemove); 459 } 460 else 461 { 462 menu.addAction(m_pActionAdd); 463 } 464 /* And show it: */ 465 menu.exec(m_pTreeWidget->mapToGlobal(pos)); 466 } 467 468 void UIHostNetworkManager::prepare() 469 { 470 /* Prepare this: */ 471 prepareThis(); 472 473 /* Apply language settings: */ 474 retranslateUi(); 475 476 /* Center according pseudo-parent widget: */ 477 VBoxGlobal::centerWidget(this, m_pPseudoParentWidget, false); 478 479 /* Load host networks: */ 480 loadHostNetworks(); 481 } 482 483 void UIHostNetworkManager::prepareThis() 484 { 485 /* Initial size: */ 486 resize(620, 460); 487 488 /* Dialog should delete itself on 'close': */ 489 setAttribute(Qt::WA_DeleteOnClose); 490 /* And no need to count it as important for application. 491 * This way it will NOT be taken into account 492 * when other top-level windows will be closed: */ 493 setAttribute(Qt::WA_QuitOnClose, false); 494 495 /* Apply window icons: */ 496 setWindowIcon(UIIconPool::iconSetFull(":/host_iface_manager_32px.png", ":/host_iface_manager_16px.png")); 497 498 /* Prepare actions: */ 499 prepareActions(); 500 /* Prepare central-widget: */ 501 prepareCentralWidget(); 502 } 503 504 void UIHostNetworkManager::prepareActions() 505 { 506 /* Create 'Add' action: */ 507 m_pActionAdd = new QAction(this); 508 AssertPtrReturnVoid(m_pActionAdd); 509 { 510 /* Configure 'Add' action: */ 511 m_pActionAdd->setShortcut(QKeySequence("Ctrl+A")); 512 m_pActionAdd->setIcon(UIIconPool::iconSetFull(":/add_host_iface_22px.png", 513 ":/add_host_iface_16px.png", 514 ":/add_host_iface_disabled_22px.png", 515 ":/add_host_iface_disabled_16px.png")); 516 connect(m_pActionAdd, SIGNAL(triggered()), this, SLOT(sltAddHostNetwork())); 517 } 518 519 /* Create 'Edit' action: */ 520 m_pActionEdit = new QAction(this); 521 AssertPtrReturnVoid(m_pActionEdit); 522 { 523 /* Configure 'Edit' action: */ 524 m_pActionEdit->setShortcut(QKeySequence("Ctrl+Space")); 525 m_pActionEdit->setIcon(UIIconPool::iconSetFull(":/edit_host_iface_22px.png", 526 ":/edit_host_iface_16px.png", 527 ":/edit_host_iface_disabled_22px.png", 528 ":/edit_host_iface_disabled_16px.png")); 529 connect(m_pActionEdit, SIGNAL(triggered()), this, SLOT(sltEditHostNetwork())); 530 } 531 532 /* Create 'Remove' action: */ 533 m_pActionRemove = new QAction(this); 534 AssertPtrReturnVoid(m_pActionRemove); 535 { 536 /* Configure 'Remove' action: */ 537 m_pActionRemove->setShortcut(QKeySequence("Del")); 538 m_pActionRemove->setIcon(UIIconPool::iconSetFull(":/remove_host_iface_22px.png", 539 ":/remove_host_iface_16px.png", 540 ":/remove_host_iface_disabled_22px.png", 541 ":/remove_host_iface_disabled_16px.png")); 542 connect(m_pActionRemove, SIGNAL(triggered()), this, SLOT(sltRemoveHostNetwork())); 543 } 544 545 /* Prepare menu-bar: */ 546 prepareMenuBar(); 547 } 548 549 void UIHostNetworkManager::prepareMenuBar() 550 { 551 /* Create 'File' menu: */ 552 m_pMenu = menuBar()->addMenu(QString()); 553 AssertPtrReturnVoid(m_pMenu); 554 { 555 /* Configure 'File' menu: */ 556 m_pMenu->addAction(m_pActionAdd); 557 m_pMenu->addAction(m_pActionEdit); 558 m_pMenu->addAction(m_pActionRemove); 559 } 560 561 #ifdef VBOX_WS_MAC 562 /* Prepare 'Window' menu: */ 563 AssertPtrReturnVoid(gpWindowMenuManager); 564 menuBar()->addMenu(gpWindowMenuManager->createMenu(this)); 565 gpWindowMenuManager->addWindow(this); 566 #endif 567 } 568 569 void UIHostNetworkManager::prepareCentralWidget() 570 { 571 /* Create central-widget: */ 572 setCentralWidget(new QWidget); 573 AssertPtrReturnVoid(centralWidget()); 574 { 575 /* Create main-layout: */ 576 new QVBoxLayout(centralWidget()); 577 AssertPtrReturnVoid(centralWidget()->layout()); 578 { 579 /* Prepare tool-bar: */ 580 prepareToolBar(); 581 /* Prepare tree-widget: */ 582 prepareTreeWidget(); 583 /* Prepare button-box: */ 584 prepareButtonBox(); 585 } 586 } 587 } 588 589 void UIHostNetworkManager::prepareToolBar() 590 { 591 /* Create tool-bar: */ 592 m_pToolBar = new UIToolBar; 593 AssertPtrReturnVoid(m_pToolBar); 594 { 595 /* Configure tool-bar: */ 596 const QStyle *pStyle = QApplication::style(); 597 const int iIconMetric = (int)(pStyle->pixelMetric(QStyle::PM_SmallIconSize) * 1.375); 598 m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric)); 599 m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 600 m_pToolBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); 601 /* Add tool-bar actions: */ 602 if (m_pActionAdd) 603 m_pToolBar->addAction(m_pActionAdd); 604 if (m_pActionEdit) 605 m_pToolBar->addAction(m_pActionEdit); 606 if (m_pActionRemove) 607 m_pToolBar->addAction(m_pActionRemove); 608 /* Integrate tool-bar into dialog: */ 609 QVBoxLayout *pMainLayout = qobject_cast<QVBoxLayout*>(centralWidget()->layout()); 610 #ifdef VBOX_WS_MAC 611 /* Enable unified tool-bars on macOS: */ 612 addToolBar(m_pToolBar); 613 m_pToolBar->enableMacToolbar(); 614 /* Special spacing on macOS: */ 615 pMainLayout->setSpacing(10); 616 #else 617 /* Add tool-bar into layout: */ 618 pMainLayout->insertWidget(0, m_pToolBar); 619 /* Set spacing/margin like in the selector window: */ 620 pMainLayout->setSpacing(5); 621 pMainLayout->setContentsMargins(5, 5, 5, 5); 622 #endif 623 } 624 } 625 626 void UIHostNetworkManager::prepareTreeWidget() 627 { 628 /* Create tree-widget: */ 629 m_pTreeWidget = new QITreeWidget; 630 AssertPtrReturnVoid(m_pTreeWidget); 631 { 632 /* Configure tree-widget: */ 633 m_pTreeWidget->header()->hide(); 634 m_pTreeWidget->setRootIsDecorated(false); 635 m_pTreeWidget->setAlternatingRowColors(true); 636 m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); 637 m_pTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 638 m_pTreeWidget->sortItems(0, Qt::AscendingOrder); 639 connect(m_pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), 640 this, SLOT(sltHandleCurrentItemChange())); 641 connect(m_pTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), 642 this, SLOT(sltEditHostNetwork())); 643 connect(m_pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint &)), 644 this, SLOT(sltHandleContextMenuRequest(const QPoint &))); 645 /* Add tree-widget into layout: */ 646 QVBoxLayout *pMainLayout = qobject_cast<QVBoxLayout*>(centralWidget()->layout()); 647 pMainLayout->addWidget(m_pTreeWidget); 648 } 649 } 650 651 void UIHostNetworkManager::prepareButtonBox() 652 { 653 /* Create button-box: */ 654 m_pButtonBox = new QIDialogButtonBox; 655 AssertPtrReturnVoid(m_pButtonBox); 656 { 657 /* Configure button-box: */ 658 m_pButtonBox->setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Close); 659 m_pButtonBox->button(QDialogButtonBox::Close)->setShortcut(Qt::Key_Escape); 660 connect(m_pButtonBox, SIGNAL(helpRequested()), &msgCenter(), SLOT(sltShowHelpHelpDialog())); 661 connect(m_pButtonBox, SIGNAL(rejected()), this, SLOT(close())); 662 /* Add button-box into layout: */ 663 QVBoxLayout *pMainLayout = qobject_cast<QVBoxLayout*>(centralWidget()->layout()); 664 pMainLayout->addWidget(m_pButtonBox); 665 } 666 } 667 668 void UIHostNetworkManager::cleanupMenuBar() 669 { 670 #ifdef VBOX_WS_MAC 671 /* Cleanup 'Window' menu: */ 672 AssertPtrReturnVoid(gpWindowMenuManager); 673 gpWindowMenuManager->removeWindow(this); 674 gpWindowMenuManager->destroyMenu(this); 675 #endif 676 } 677 678 void UIHostNetworkManager::cleanup() 679 { 680 /* Cleanup menu-bar: */ 681 cleanupMenuBar(); 682 } 683 684 void UIHostNetworkManager::loadHostNetworks() 685 { 686 /* Clear tree first of all: */ 687 m_pTreeWidget->clear(); 688 689 /* Get host for further activities: */ 690 const CHost comHost = vboxGlobal().host(); 691 692 /* Get interfaces for further activities: */ 693 const QVector<CHostNetworkInterface> interfaces = comHost.GetNetworkInterfaces(); 694 695 /* Show error message if necessary: */ 696 if (!comHost.isOk()) 697 msgCenter().cannotAcquireHostNetworkInterfaces(comHost, this); 698 else 699 { 700 /* For each host-only interface => load it to the tree: */ 701 foreach (const CHostNetworkInterface &comInterface, interfaces) 702 if (comInterface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly) 703 { 704 UIDataHostNetwork data; 705 loadHostNetwork(comInterface, data); 706 createItemForNetworkHost(data, false); 707 } 708 709 /* Sort list by the 1st column: */ 710 m_pTreeWidget->sortByColumn(0, Qt::AscendingOrder); 711 /* Choose the 1st item as current initially: */ 712 m_pTreeWidget->setCurrentItem(m_pTreeWidget->topLevelItem(0)); 713 sltHandleCurrentItemChange(); 714 } 715 } 716 717 void UIHostNetworkManager::loadHostNetwork(const CHostNetworkInterface &comInterface, UIDataHostNetwork &data) 718 { 719 /* Gather interface settings: */ 720 if (comInterface.isOk()) 721 data.m_interface.m_strName = comInterface.GetName(); 722 if (comInterface.isOk()) 723 data.m_interface.m_strInterfaceAddress = comInterface.GetIPAddress(); 724 if (comInterface.isOk()) 725 data.m_interface.m_strInterfaceMask = comInterface.GetNetworkMask(); 726 if (comInterface.isOk()) 727 data.m_interface.m_fIpv6Supported = comInterface.GetIPV6Supported(); 728 if (comInterface.isOk()) 729 data.m_interface.m_strInterfaceAddress6 = comInterface.GetIPV6Address(); 730 if (comInterface.isOk()) 731 data.m_interface.m_strInterfaceMaskLength6 = QString::number(comInterface.GetIPV6NetworkMaskPrefixLength()); 732 733 /* Get host interface network name for further activities: */ 734 QString strNetworkName; 735 if (comInterface.isOk()) 736 strNetworkName = comInterface.GetNetworkName(); 737 738 /* Show error message if necessary: */ 739 if (!comInterface.isOk()) 740 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 741 742 /* Get VBox for further activities: */ 743 CVirtualBox comVBox = vboxGlobal().virtualBox(); 744 745 /* Find corresponding DHCP server (create if necessary): */ 746 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 747 if (!comVBox.isOk() || comServer.isNull()) 748 comServer = comVBox.CreateDHCPServer(strNetworkName); 749 750 /* Show error message if necessary: */ 751 if (!comVBox.isOk() || comServer.isNull()) 752 msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this); 753 else 754 { 755 /* Gather DHCP server settings: */ 756 if (comServer.isOk()) 757 data.m_dhcpserver.m_fDhcpServerEnabled = comServer.GetEnabled(); 758 if (comServer.isOk()) 759 data.m_dhcpserver.m_strDhcpServerAddress = comServer.GetIPAddress(); 760 if (comServer.isOk()) 761 data.m_dhcpserver.m_strDhcpServerMask = comServer.GetNetworkMask(); 762 if (comServer.isOk()) 763 data.m_dhcpserver.m_strDhcpLowerAddress = comServer.GetLowerIP(); 764 if (comServer.isOk()) 765 data.m_dhcpserver.m_strDhcpUpperAddress = comServer.GetUpperIP(); 766 767 /* Show error message if necessary: */ 768 if (!comServer.isOk()) 769 return msgCenter().cannotAcquireDHCPServerParameter(comServer, this); 770 } 771 } 772 773 void UIHostNetworkManager::createItemForNetworkHost(const UIDataHostNetwork &data, bool fChooseItem) 774 { 775 /* Create new item: */ 776 UIItemHostNetwork *pItem = new UIItemHostNetwork; 777 AssertPtrReturnVoid(pItem); 778 { 779 /* Configure item: */ 780 pItem->UIDataHostNetwork::operator=(data); 781 pItem->updateFields(); 782 /* Add item to the tree: */ 783 m_pTreeWidget->addTopLevelItem(pItem); 784 /* And choose it as current if necessary: */ 785 if (fChooseItem) 786 m_pTreeWidget->setCurrentItem(pItem); 787 } 788 } 789 790 void UIHostNetworkManager::updateItemForNetworkHost(const UIDataHostNetwork &data, bool fChooseItem, UIItemHostNetwork *pItem) 791 { 792 /* Update passed item: */ 793 AssertPtrReturnVoid(pItem); 794 { 795 /* Configure item: */ 796 pItem->UIDataHostNetwork::operator=(data); 797 pItem->updateFields(); 798 /* And choose it as current if necessary: */ 799 if (fChooseItem) 800 m_pTreeWidget->setCurrentItem(pItem); 801 } 802 } 803 -
Property svn:keywords
changed from
-
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.h
-
Property svn:keywords
changed from
Date Revision Author Id
toAuthor Date Id Revision
r66662 r66681 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI GlobalSettingsNetworkclass declaration.3 * VBox Qt GUI - UIHostNetworkManager class declaration. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef ___UIGlobalSettingsNetwork_h___ 19 #define ___UIGlobalSettingsNetwork_h___ 18 #ifndef ___UIHostNetworkManager_h___ 19 #define ___UIHostNetworkManager_h___ 20 21 /* Qt includes: */ 22 #include <QMainWindow> 20 23 21 24 /* GUI includes: */ 22 #include "UISettingsPage.h" 23 #include "UIGlobalSettingsNetwork.gen.h" 24 #include "UIPortForwardingTable.h" 25 #include "QIWithRetranslateUI.h" 25 26 26 27 /* Forward declarations: */ 27 class UIItemNetworkNAT; 28 class UIItemNetworkHost; 29 struct UIDataSettingsGlobalNetwork; 30 struct UIDataSettingsGlobalNetworkNAT; 31 struct UIDataSettingsGlobalNetworkHost; 32 typedef UISettingsCache<UIDataPortForwardingRule> UISettingsCachePortForwardingRule; 33 typedef UISettingsCachePoolOfTwo<UIDataSettingsGlobalNetworkNAT, UISettingsCachePortForwardingRule, UISettingsCachePortForwardingRule> UISettingsCacheGlobalNetworkNAT; 34 typedef UISettingsCache<UIDataSettingsGlobalNetworkHost> UISettingsCacheGlobalNetworkHost; 35 typedef UISettingsCachePoolOfTwo<UIDataSettingsGlobalNetwork, UISettingsCacheGlobalNetworkNAT, UISettingsCacheGlobalNetworkHost> UISettingsCacheGlobalNetwork; 28 class CHostNetworkInterface; 29 class QIDialogButtonBox; 30 class QITreeWidget; 31 class UIItemHostNetwork; 32 class UIToolBar; 33 struct UIDataHostNetwork; 36 34 37 35 38 /** Global settings: Network page. */ 39 class UIGlobalSettingsNetwork : public UISettingsPageGlobal, 40 public Ui::UIGlobalSettingsNetwork 36 /** Host Network Manager dialog. */ 37 class UIHostNetworkManager : public QIWithRetranslateUI<QMainWindow> 41 38 { 42 39 Q_OBJECT; 43 40 41 /** Constructs Host Network Manager dialog. 42 * @param pCenterWidget Brings the pseudo-parent widget to center according to. */ 43 UIHostNetworkManager(QWidget *pCenterWidget); 44 /** Destructs Host Network Manager dialog. */ 45 ~UIHostNetworkManager(); 46 44 47 public: 45 48 46 /** Constructs Network settings page. */47 UIGlobalSettingsNetwork();48 /** Destructs Network settings page. */49 ~UIGlobalSettingsNetwork();49 /** Returns Host Network Manager singleton instance. */ 50 static UIHostNetworkManager *instance(); 51 /** Shows Host Network Manager singleton instance, creates new if necessary. */ 52 static void showModeless(QWidget *pCenterWidget); 50 53 51 54 protected: 52 53 /** Loads data into the cache from corresponding external object(s),54 * this task COULD be performed in other than the GUI thread. */55 virtual void loadToCacheFrom(QVariant &data) /* override */;56 /** Loads data into corresponding widgets from the cache,57 * this task SHOULD be performed in the GUI thread only. */58 virtual void getFromCache() /* override */;59 60 /** Saves data from corresponding widgets to the cache,61 * this task SHOULD be performed in the GUI thread only. */62 virtual void putToCache() /* override */;63 /** Saves data from the cache to corresponding external object(s),64 * this task COULD be performed in other than the GUI thread. */65 virtual void saveFromCacheTo(QVariant &data) /* overrride */;66 67 /** Performs validation, updates @a messages list if something is wrong. */68 virtual bool validate(QList<UIValidationMessage> &messages) /* override */;69 70 /** Defines TAB order for passed @a pWidget. */71 virtual void setOrderAfter(QWidget *pWidget) /* override */;72 55 73 56 /** Handles translation event. */ … … 76 59 private slots: 77 60 78 /** Handles command to add NAT network. */ 79 void sltAddNetworkNAT(); 80 /** Handles command to edit NAT network. */ 81 void sltEditNetworkNAT(); 82 /** Handles command to remove NAT network. */ 83 void sltRemoveNetworkNAT(); 84 /** Handles @a pChangedItem change for NAT network tree. */ 85 void sltHandleItemChangeNetworkNAT(QTreeWidgetItem *pChangedItem); 86 /** Handles NAT network tree current item change. */ 87 void sltHandleCurrentItemChangeNetworkNAT(); 88 /** Handles context menu request for @a position of NAT network tree. */ 89 void sltHandleContextMenuRequestNetworkNAT(const QPoint &position); 61 /** @name Menu/action stuff. 62 * @{ */ 63 /** Handles command to add host network. */ 64 void sltAddHostNetwork(); 65 /** Handles command to edit host network. */ 66 void sltEditHostNetwork(); 67 /** Handles command to remove host network. */ 68 void sltRemoveHostNetwork(); 69 /** @} */ 90 70 91 /** Handles command to add host network. */ 92 void sltAddNetworkHost(); 93 /** Handles command to edit host network. */ 94 void sltEditNetworkHost(); 95 /** Handles command to remove host network. */ 96 void sltRemoveNetworkHost(); 97 /** Handles host network tree current item change. */ 98 void sltHandleCurrentItemChangeNetworkHost(); 99 /** Handles context menu request for @a position of host network tree. */ 100 void sltHandleContextMenuRequestNetworkHost(const QPoint &position); 71 /** @name Tree-widget stuff. 72 * @{ */ 73 /** Handles host network tree current item change. */ 74 void sltHandleCurrentItemChange(); 75 /** Handles context menu request for @a position of host network tree. */ 76 void sltHandleContextMenuRequest(const QPoint &position); 77 /** @} */ 101 78 102 79 private: 103 80 104 /** Prepares all. */ 105 void prepare(); 106 /** Prepares 'NAT Network' tab. */ 107 void prepareTabNAT(); 108 /** Prepares 'Host Network' tab. */ 109 void prepareTabHost(); 110 /** Prepares connections. */ 111 void prepareConnections(); 112 /** Cleanups all. */ 113 void cleanup(); 81 /** @name Prepare/cleanup cascade. 82 * @{ */ 83 /** Prepares all. */ 84 void prepare(); 85 /** Prepares this. */ 86 void prepareThis(); 87 /** Prepares actions. */ 88 void prepareActions(); 89 /** Prepares menu-bar. */ 90 void prepareMenuBar(); 91 /** Prepares central-widget. */ 92 void prepareCentralWidget(); 93 /** Prepares tool-bar. */ 94 void prepareToolBar(); 95 /** Prepares tree-widget. */ 96 void prepareTreeWidget(); 97 /** Prepares button-box. */ 98 void prepareButtonBox(); 114 99 115 /** Saves existing network data from the cache. */ 116 bool saveNetworkData(); 100 /** Cleanup menu-bar. */ 101 void cleanupMenuBar(); 102 /** Cleanups all. */ 103 void cleanup(); 104 /** @} */ 117 105 118 /** Uploads NAT @a network data into passed @a cache storage unit. */ 119 void loadToCacheFromNetworkNAT(const CNATNetwork &network, UISettingsCacheGlobalNetworkNAT &cache); 120 /** Removes corresponding NAT network on the basis of @a cache. */ 121 bool removeNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache); 122 /** Creates corresponding NAT network on the basis of @a cache. */ 123 bool createNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache); 124 /** Updates @a cache of corresponding NAT network. */ 125 bool updateNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache); 126 /** Creates a new item in the NAT network tree on the basis of passed @a cache. */ 127 void createTreeWidgetItemForNetworkNAT(const UISettingsCacheGlobalNetworkNAT &cache); 128 /** Creates a new item in the NAT network tree on the basis of passed @a data, @a ipv4rules, @a ipv6rules, @a fChooseItem if requested. */ 129 void createTreeWidgetItemForNetworkNAT(const UIDataSettingsGlobalNetworkNAT &data, 130 const UIPortForwardingDataList &ipv4rules, 131 const UIPortForwardingDataList &ipv6rules, 132 bool fChooseItem = false); 133 /** Removes existing @a pItem from the NAT network tree. */ 134 void removeTreeWidgetItemOfNetworkNAT(UIItemNetworkNAT *pItem); 135 /** Returns whether the NAT network described by the @a cache could be updated or recreated otherwise. */ 136 bool isNetworkCouldBeUpdated(const UISettingsCacheGlobalNetworkNAT &cache) const; 106 /** @name Loading stuff. 107 * @{ */ 108 /** Loads host networks. */ 109 void loadHostNetworks(); 110 /** Loads host @a comInterface data to passed @a data container. */ 111 void loadHostNetwork(const CHostNetworkInterface &comInterface, UIDataHostNetwork &data); 112 /** @} */ 137 113 138 /** Uploads host @a network data into passed @a data storage unit. */ 139 void loadToCacheFromNetworkHost(const CHostNetworkInterface &iface, UISettingsCacheGlobalNetworkHost &cache); 140 /** Saves @a data to corresponding host network. */ 141 bool saveDataNetworkHost(const UISettingsCacheGlobalNetworkHost &cache); 142 /** Creates a new item in the host network tree on the basis of passed @a data, @a fChooseItem if requested. */ 143 void createTreeWidgetItemForNetworkHost(const UISettingsCacheGlobalNetworkHost &cache, bool fChooseItem = false); 144 /** Removes existing @a pItem from the host network tree. */ 145 void removeTreeWidgetItemOfNetworkHost(UIItemNetworkHost *pItem); 114 /** @name Tree-widget stuff. 115 * @{ */ 116 /** Creates a new tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */ 117 void createItemForNetworkHost(const UIDataHostNetwork &data, bool fChooseItem); 118 /** Updates the passed tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */ 119 void updateItemForNetworkHost(const UIDataHostNetwork &data, bool fChooseItem, UIItemHostNetwork *pItem); 120 /** @} */ 146 121 147 /** Holds the Add NAT network action instance. */ 148 QAction *m_pActionAddNetworkNAT; 149 /** Holds the Edit NAT network action instance. */ 150 QAction *m_pActionEditNetworkNAT; 151 /** Holds the Remove NAT network action instance. */ 152 QAction *m_pActionRemoveNetworkNAT; 122 /** @name General variables. 123 * @{ */ 124 /** Holds the Host Network Manager singleton instance. */ 125 static UIHostNetworkManager *s_pInstance; 153 126 154 /** Holds the Add host network action instance. */ 155 QAction *m_pActionAddNetworkHost; 156 /** Holds the Edit host network action instance. */ 157 QAction *m_pActionEditNetworkHost; 158 /** Holds the Remove host network action instance. */ 159 QAction *m_pActionRemoveNetworkHost; 127 /** Widget to center UIMediumManager according. */ 128 QWidget *m_pPseudoParentWidget; 129 /** @} */ 160 130 161 /** Holds the page data cache instance. */ 162 UISettingsCacheGlobalNetwork *m_pCache; 131 /** @name Tool-bar and menu variables. 132 * @{ */ 133 /** Holds the tool-bar instance. */ 134 UIToolBar *m_pToolBar; 135 /** Holds menu-bar menu object instance. */ 136 QMenu *m_pMenu; 137 /** Holds the Add action instance. */ 138 QAction *m_pActionAdd; 139 /** Holds the Edit action instance. */ 140 QAction *m_pActionEdit; 141 /** Holds the Remove action instance. */ 142 QAction *m_pActionRemove; 143 /** @} */ 144 145 /** @name Tree-widget variables. 146 * @{ */ 147 /** Holds the tree-widget instance. */ 148 QITreeWidget *m_pTreeWidget; 149 /** @} */ 150 151 /** @name Button-box variables. 152 * @{ */ 153 /** Holds the dialog button-box instance. */ 154 QIDialogButtonBox *m_pButtonBox; 155 /** @} */ 163 156 }; 164 157 165 #endif /* !___UI GlobalSettingsNetwork_h___ */158 #endif /* !___UIHostNetworkManager_h___ */ 166 159 -
Property svn:keywords
changed from
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UIActionPoolSelector.cpp
r66680 r66681 83 83 setName(QApplication::translate("UIActionPool", "&Virtual Media Manager...")); 84 84 setStatusTip(QApplication::translate("UIActionPool", "Display the Virtual Media Manager window")); 85 } 86 }; 87 88 class UIActionSimpleHostNetworkManagerDialog : public UIActionSimple 89 { 90 Q_OBJECT; 91 92 public: 93 94 UIActionSimpleHostNetworkManagerDialog(UIActionPool *pParent) 95 : UIActionSimple(pParent, ":/host_iface_manager_16px.png") {} 96 97 protected: 98 99 QString shortcutExtraDataID() const 100 { 101 return QString("HostNetworkManager"); 102 } 103 104 QKeySequence defaultShortcut(UIActionPoolType) const 105 { 106 return QKeySequence("Ctrl+T"); 107 } 108 109 void retranslateUi() 110 { 111 setName(QApplication::translate("UIActionPool", "&Host Network Manager...")); 112 setStatusTip(QApplication::translate("UIActionPool", "Display the Host Network Manager window")); 85 113 } 86 114 }; … … 1035 1063 m_pool[UIActionIndexST_M_File] = new UIActionMenuFile(this); 1036 1064 m_pool[UIActionIndexST_M_File_S_ShowVirtualMediumManager] = new UIActionSimpleVirtualMediumManagerDialog(this); 1065 m_pool[UIActionIndexST_M_File_S_ShowHostNetworkManager] = new UIActionSimpleHostNetworkManagerDialog(this); 1037 1066 m_pool[UIActionIndexST_M_File_S_ImportAppliance] = new UIActionSimpleImportApplianceWizard(this); 1038 1067 m_pool[UIActionIndexST_M_File_S_ExportAppliance] = new UIActionSimpleExportApplianceWizard(this); -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UIActionPoolSelector.h
r66680 r66681 34 34 UIActionIndexST_M_File = UIActionIndex_Max + 1, 35 35 UIActionIndexST_M_File_S_ShowVirtualMediumManager, 36 UIActionIndexST_M_File_S_ShowHostNetworkManager, 36 37 UIActionIndexST_M_File_S_ImportAppliance, 37 38 UIActionIndexST_M_File_S_ExportAppliance, -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
r66680 r66681 50 50 # include "UIDesktopPane.h" 51 51 # include "UIVirtualBoxEventHandler.h" 52 # include "UIHostNetworkManager.h" 52 53 # include "UIMediumManager.h" 53 54 # include "UIMedium.h" … … 426 427 } 427 428 429 void UISelectorWindow::sltOpenHostNetworkManagerWindow() 430 { 431 /* Show modeless Host Network Manager: */ 432 UIHostNetworkManager::showModeless(this); 433 } 434 428 435 void UISelectorWindow::sltOpenImportApplianceWizard(const QString &strFileName /* = QString() */) 429 436 { … … 1371 1378 /* 'Show Virtual Medium Manager' action goes to 'File' menu: */ 1372 1379 pMenu->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager)); 1380 /* 'Show Host Network Manager' action goes to 'File' menu: */ 1381 pMenu->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager)); 1373 1382 1374 1383 #else /* !VBOX_WS_MAC */ … … 1388 1397 # endif /* VBOX_GUI_WITH_EXTRADATA_MANAGER_UI */ 1389 1398 addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager)); 1399 addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager)); 1390 1400 # ifdef VBOX_GUI_WITH_NETWORK_MANAGER 1391 1401 addAction(actionPool()->action(UIActionIndex_M_Application_S_NetworkAccessManager)); … … 1412 1422 /* 'Show Virtual Medium Manager' action goes to 'File' menu: */ 1413 1423 pMenu->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager)); 1424 /* 'Show Host Network Manager' action goes to 'File' menu: */ 1425 pMenu->addAction(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager)); 1414 1426 # ifdef VBOX_GUI_WITH_NETWORK_MANAGER 1415 1427 /* 'Network Access Manager' action goes to 'File' menu: */ … … 1813 1825 /* 'File' menu connections: */ 1814 1826 connect(actionPool()->action(UIActionIndexST_M_File_S_ShowVirtualMediumManager), SIGNAL(triggered()), this, SLOT(sltOpenVirtualMediumManagerWindow())); 1827 connect(actionPool()->action(UIActionIndexST_M_File_S_ShowHostNetworkManager), SIGNAL(triggered()), this, SLOT(sltOpenHostNetworkManagerWindow())); 1815 1828 connect(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance), SIGNAL(triggered()), this, SLOT(sltOpenImportApplianceWizard())); 1816 1829 connect(actionPool()->action(UIActionIndexST_M_File_S_ExportAppliance), SIGNAL(triggered()), this, SLOT(sltOpenExportApplianceWizard())); -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h
r66680 r66681 124 124 /** Handles call to open Virtual Medium Manager window. */ 125 125 void sltOpenVirtualMediumManagerWindow(); 126 /** Handles call to open Host Network Manager window. */ 127 void sltOpenHostNetworkManagerWindow(); 126 128 /** Handles call to open Import Appliance wizard. 127 129 * @param strFileName can bring the name of file to import appliance from. */
Note:
See TracChangeset
for help on using the changeset viewer.