VirtualBox

Changeset 66855 in vbox


Ignore:
Timestamp:
May 10, 2017 10:39:43 AM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8847: Host Network Manager: Moving some common stuff into separate file.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork
Files:
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkDetailsDialog.cpp

    r66809 r66855  
    3232# include "QITabWidget.h"
    3333# include "UIHostNetworkDetailsDialog.h"
     34# include "UIHostNetworkUtils.h"
    3435# include "UIIconPool.h"
    3536
     
    891892}
    892893
    893 /* static */
    894 quint32 UIHostNetworkDetailsDialog::ipv4FromQStringToQuint32(const QString &strAddress)
    895 {
    896     quint32 uAddress = 0;
    897     foreach (const QString &strPart, strAddress.split('.'))
    898     {
    899         uAddress = uAddress << 8;
    900         bool fOk = false;
    901         uint uPart = strPart.toUInt(&fOk);
    902         if (fOk)
    903             uAddress += uPart;
    904     }
    905     return uAddress;
    906 }
    907 
    908 /* static */
    909 QString UIHostNetworkDetailsDialog::ipv4FromQuint32ToQString(quint32 uAddress)
    910 {
    911     QStringList address;
    912     while (uAddress)
    913     {
    914         uint uPart = uAddress & 0xFF;
    915         address.prepend(QString::number(uPart));
    916         uAddress = uAddress >> 8;
    917     }
    918     return address.join('.');
    919 }
    920 
  • trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkDetailsDialog.h

    r66809 r66855  
    1616 */
    1717
    18 #ifndef __UIHostNetworkDetailsDialog_h__
    19 #define __UIHostNetworkDetailsDialog_h__
     18#ifndef ___UIHostNetworkDetailsDialog_h___
     19#define ___UIHostNetworkDetailsDialog_h___
    2020
    2121/* Qt includes: */
     
    245245    /** @} */
    246246
    247     /** @name Helpers.
    248      * @{ */
    249         /** Converts IPv4 address from QString to quint32. */
    250         static quint32 ipv4FromQStringToQuint32(const QString &strAddress);
    251         /** Converts IPv4 address from quint32 to QString. */
    252         static QString ipv4FromQuint32ToQString(quint32 uAddress);
    253     /** @} */
    254 
    255247    /** @name General variables.
    256248     * @{ */
     
    337329};
    338330
    339 #endif /* __UIHostNetworkDetailsDialog_h__ */
    340 
     331#endif /* !___UIHostNetworkDetailsDialog_h___ */
     332
  • trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkUtils.cpp

    r66809 r66855  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIHostNetworkDetailsDialog class implementation.
     3 * VBox Qt GUI - UIHostNetworkUtils namespace implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121
    2222/* Qt includes: */
    23 # include <QCheckBox>
    24 # include <QLabel>
    25 # include <QRadioButton>
    26 # include <QRegExpValidator>
    27 # include <QStyleOption>
    28 # include <QVBoxLayout>
     23# include <QStringList>
    2924
    3025/* GUI includes: */
    31 # include "QILineEdit.h"
    32 # include "QITabWidget.h"
    33 # include "UIHostNetworkDetailsDialog.h"
    34 # include "UIIconPool.h"
    35 
    36 /* Other VBox includes: */
    37 # include "iprt/assert.h"
    38 # include "iprt/cidr.h"
     26# include "UIHostNetworkUtils.h"
    3927
    4028#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4129
    4230
    43 UIHostNetworkDetailsDialog::UIHostNetworkDetailsDialog(QWidget *pParent /* = 0 */)
    44     : QIWithRetranslateUI2<QWidget>(pParent)
    45     , m_pTabWidget(0)
    46     , m_pButtonAutomatic(0), m_pErrorPaneAutomatic(0)
    47     , m_pButtonManual(0)
    48     , m_pLabelIPv4(0), m_pEditorIPv4(0), m_pErrorPaneIPv4(0)
    49     , m_pLabelNMv4(0), m_pEditorNMv4(0), m_pErrorPaneNMv4(0)
    50     , m_pLabelIPv6(0), m_pEditorIPv6(0), m_pErrorPaneIPv6(0)
    51     , m_pLabelNMv6(0), m_pEditorNMv6(0), m_pErrorPaneNMv6(0)
    52     , m_pCheckBoxDHCP(0)
    53     , m_pLabelDHCPAddress(0), m_pEditorDHCPAddress(0), m_pErrorPaneDHCPAddress(0)
    54     , m_pLabelDHCPMask(0), m_pEditorDHCPMask(0), m_pErrorPaneDHCPMask(0)
    55     , m_pLabelDHCPLowerAddress(0), m_pEditorDHCPLowerAddress(0), m_pErrorPaneDHCPLowerAddress(0)
    56     , m_pLabelDHCPUpperAddress(0), m_pEditorDHCPUpperAddress(0), m_pErrorPaneDHCPUpperAddress(0)
    57 {
    58     /* Prepare: */
    59     prepare();
    60 }
    61 
    62 void UIHostNetworkDetailsDialog::setData(const UIDataHostNetwork &data)
    63 {
    64     /* Save old data: */
    65     m_oldData = data;
    66 
    67     /* Invent default old values if current old values are invalid: */
    68     const quint32 uAddr = ipv4FromQStringToQuint32(m_oldData.m_interface.m_strAddress);
    69     const quint32 uMask = ipv4FromQStringToQuint32(m_oldData.m_interface.m_strMask);
    70     const quint32 uProp = uAddr & uMask;
    71     const QString strMask = ipv4FromQuint32ToQString(uMask);
    72     const QString strProp = ipv4FromQuint32ToQString(uProp);
    73 //    printf("Proposal is = %s x %s\n",
    74 //           strProp.toUtf8().constData(),
    75 //           strMask.toUtf8().constData());
    76     if (   m_oldData.m_dhcpserver.m_strAddress.isEmpty()
    77         || m_oldData.m_dhcpserver.m_strAddress == "0.0.0.0")
    78         m_oldData.m_dhcpserver.m_strAddress = strProp;
    79     if (   m_oldData.m_dhcpserver.m_strMask.isEmpty()
    80         || m_oldData.m_dhcpserver.m_strMask == "0.0.0.0")
    81         m_oldData.m_dhcpserver.m_strMask = strMask;
    82     if (   m_oldData.m_dhcpserver.m_strLowerAddress.isEmpty()
    83         || m_oldData.m_dhcpserver.m_strLowerAddress == "0.0.0.0")
    84         m_oldData.m_dhcpserver.m_strLowerAddress = strProp;
    85     if (   m_oldData.m_dhcpserver.m_strUpperAddress.isEmpty()
    86         || m_oldData.m_dhcpserver.m_strUpperAddress == "0.0.0.0")
    87         m_oldData.m_dhcpserver.m_strUpperAddress = strProp;
    88 
    89     /* Copy old data to new one: */
    90     m_newData = m_oldData;
    91 
    92     /* Load 'Interface' data: */
    93     loadDataForInterface();
    94     /* Load 'DHCP server' data: */
    95     loadDataForDHCPServer();
    96 }
    97 
    98 void UIHostNetworkDetailsDialog::clearData()
    99 {
    100     /* Reset old/new data: */
    101     m_oldData = UIDataHostNetwork();
    102     m_newData = m_oldData;
    103 
    104     /* Load 'Interface' data: */
    105     loadDataForInterface();
    106     /* Load 'DHCP server' data: */
    107     loadDataForDHCPServer();
    108 }
    109 
    110 void UIHostNetworkDetailsDialog::retranslateUi()
    111 {
    112     /* Translate tab-widget: */
    113     m_pTabWidget->setTabText(0, tr("&Adapter"));
    114     m_pTabWidget->setTabText(1, tr("&DHCP Server"));
    115 
    116     /* Translate 'Interface' tab content: */
    117     m_pButtonAutomatic->setText(tr("Configure Adapter &Automatically"));
    118     m_pButtonManual->setText(tr("Configure Adapter &Manually"));
    119     m_pLabelIPv4->setText(tr("&IPv4 Address:"));
    120     m_pEditorIPv4->setToolTip(tr("Holds the host IPv4 address for this adapter."));
    121     m_pLabelNMv4->setText(tr("IPv4 Network &Mask:"));
    122     m_pEditorNMv4->setToolTip(tr("Holds the host IPv4 network mask for this adapter."));
    123     m_pLabelIPv6->setText(tr("I&Pv6 Address:"));
    124     m_pEditorIPv6->setToolTip(tr("Holds the host IPv6 address for this adapter if IPv6 is supported."));
    125     m_pLabelNMv6->setText(tr("IPv6 Network Mask &Length:"));
    126     m_pEditorNMv6->setToolTip(tr("Holds the host IPv6 network mask prefix length for this adapter if IPv6 is supported."));
    127 
    128     /* Translate 'DHCP server' tab content: */
    129     m_pCheckBoxDHCP->setText(tr("&Enable Server"));
    130     m_pCheckBoxDHCP->setToolTip(tr("When checked, the DHCP Server will be enabled for this network on machine start-up."));
    131     m_pLabelDHCPAddress->setText(tr("Server Add&ress:"));
    132     m_pEditorDHCPAddress->setToolTip(tr("Holds the address of the DHCP server servicing the network associated with this host-only adapter."));
    133     m_pLabelDHCPMask->setText(tr("Server &Mask:"));
    134     m_pEditorDHCPMask->setToolTip(tr("Holds the network mask of the DHCP server servicing the network associated with this host-only adapter."));
    135     m_pLabelDHCPLowerAddress->setText(tr("&Lower Address Bound:"));
    136     m_pEditorDHCPLowerAddress->setToolTip(tr("Holds the lower address bound offered by the DHCP server servicing the network associated with this host-only adapter."));
    137     m_pLabelDHCPUpperAddress->setText(tr("&Upper Address Bound:"));
    138     m_pEditorDHCPUpperAddress->setToolTip(tr("Holds the upper address bound offered by the DHCP server servicing the network associated with this host-only adapter."));
    139 
    140     /* Retranslate validation: */
    141     retranslateValidation();
    142 }
    143 
    144 void UIHostNetworkDetailsDialog::sltToggledButtonAutomatic(bool fChecked)
    145 {
    146     m_newData.m_interface.m_fDHCPEnabled = fChecked;
    147     loadDataForInterface();
    148     revalidate();
    149     notify();
    150 }
    151 
    152 void UIHostNetworkDetailsDialog::sltToggledButtonManual(bool fChecked)
    153 {
    154     m_newData.m_interface.m_fDHCPEnabled = !fChecked;
    155     loadDataForInterface();
    156     revalidate();
    157     notify();
    158 }
    159 
    160 void UIHostNetworkDetailsDialog::sltTextChangedIPv4(const QString &strText)
    161 {
    162     m_newData.m_interface.m_strAddress = strText;
    163     revalidate(m_pErrorPaneIPv4);
    164     notify();
    165 }
    166 
    167 void UIHostNetworkDetailsDialog::sltTextChangedNMv4(const QString &strText)
    168 {
    169     m_newData.m_interface.m_strMask = strText;
    170     revalidate(m_pErrorPaneNMv4);
    171     notify();
    172 }
    173 
    174 void UIHostNetworkDetailsDialog::sltTextChangedIPv6(const QString &strText)
    175 {
    176     m_newData.m_interface.m_strAddress6 = strText;
    177     revalidate(m_pErrorPaneIPv6);
    178     notify();
    179 }
    180 
    181 void UIHostNetworkDetailsDialog::sltTextChangedNMv6(const QString &strText)
    182 {
    183     m_newData.m_interface.m_strMaskLength6 = strText;
    184     revalidate(m_pErrorPaneNMv6);
    185     notify();
    186 }
    187 
    188 void UIHostNetworkDetailsDialog::sltStatusChangedServer(int iChecked)
    189 {
    190     m_newData.m_dhcpserver.m_fEnabled = (bool)iChecked;
    191     loadDataForDHCPServer();
    192     revalidate();
    193     notify();
    194 }
    195 
    196 void UIHostNetworkDetailsDialog::sltTextChangedAddress(const QString &strText)
    197 {
    198     m_newData.m_dhcpserver.m_strAddress = strText;
    199     revalidate(m_pErrorPaneDHCPAddress);
    200     notify();
    201 }
    202 
    203 void UIHostNetworkDetailsDialog::sltTextChangedMask(const QString &strText)
    204 {
    205     m_newData.m_dhcpserver.m_strMask = strText;
    206     revalidate(m_pErrorPaneDHCPMask);
    207     notify();
    208 }
    209 
    210 void UIHostNetworkDetailsDialog::sltTextChangedLowerAddress(const QString &strText)
    211 {
    212     m_newData.m_dhcpserver.m_strLowerAddress = strText;
    213     revalidate(m_pErrorPaneDHCPLowerAddress);
    214     notify();
    215 }
    216 
    217 void UIHostNetworkDetailsDialog::sltTextChangedUpperAddress(const QString &strText)
    218 {
    219     m_newData.m_dhcpserver.m_strUpperAddress = strText;
    220     revalidate(m_pErrorPaneDHCPUpperAddress);
    221     notify();
    222 }
    223 
    224 void UIHostNetworkDetailsDialog::prepare()
    225 {
    226     /* Prepare this: */
    227     prepareThis();
    228 
    229     /* Apply language settings: */
    230     retranslateUi();
    231 }
    232 
    233 void UIHostNetworkDetailsDialog::prepareThis()
    234 {
    235     /* Create layout: */
    236     QVBoxLayout *pLayout = new QVBoxLayout(this);
    237     AssertPtrReturnVoid(pLayout);
    238     {
    239         /* Configure layout: */
    240         pLayout->setContentsMargins(0, 0, 0, 0);
    241         /* Prepare tab-widget: */
    242         prepareTabWidget();
    243     }
    244 }
    245 
    246 void UIHostNetworkDetailsDialog::prepareTabWidget()
    247 {
    248     /* Create tab-widget: */
    249     m_pTabWidget = new QITabWidget;
    250     AssertPtrReturnVoid(m_pTabWidget);
    251     {
    252         /* Prepare 'Interface' tab: */
    253         prepareTabInterface();
    254         /* Prepare 'DHCP server' tab: */
    255         prepareTabDHCPServer();
    256         /* Add into layout: */
    257         layout()->addWidget(m_pTabWidget);
    258     }
    259 }
    260 
    261 void UIHostNetworkDetailsDialog::prepareTabInterface()
    262 {
    263     /* Create 'Interface' tab: */
    264     QWidget *pTabInterface = new QWidget;
    265     AssertPtrReturnVoid(pTabInterface);
    266     {
    267         /* Create 'Interface' layout: */
    268         QGridLayout *pLayoutInterface = new QGridLayout(pTabInterface);
    269         AssertPtrReturnVoid(pLayoutInterface);
    270         {
    271 #ifdef VBOX_WS_MAC
    272             /* Configure layout: */
    273             pLayoutInterface->setContentsMargins(10, 10, 10, 10);
    274 #endif
    275 
    276             /* Create automatic interface configuration layout: */
    277             QHBoxLayout *pLayoutAutomatic = new QHBoxLayout;
    278             AssertPtrReturnVoid(pLayoutAutomatic);
    279             {
    280                 /* Configure layout: */
    281                 pLayoutAutomatic->setContentsMargins(0, 0, 0, 0);
    282                 /* Create automatic interface configuration radio-button: */
    283                 m_pButtonAutomatic = new QRadioButton;
    284                 AssertPtrReturnVoid(m_pButtonAutomatic);
    285                 {
    286                     /* Configure radio-button: */
    287                     connect(m_pButtonAutomatic, &QRadioButton::toggled,
    288                             this, &UIHostNetworkDetailsDialog::sltToggledButtonAutomatic);
    289                     /* Add into layout: */
    290                     pLayoutAutomatic->addWidget(m_pButtonAutomatic);
    291                 }
    292                 /* Create automatic interface configuration error pane: */
    293                 m_pErrorPaneAutomatic = new QLabel;
    294                 AssertPtrReturnVoid(m_pErrorPaneAutomatic);
    295                 {
    296                     /* Configure label: */
    297                     m_pErrorPaneAutomatic->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    298                     m_pErrorPaneAutomatic->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
    299                     m_pErrorPaneAutomatic->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    300                     /* Add into layout: */
    301                     pLayoutAutomatic->addWidget(m_pErrorPaneAutomatic);
    302                 }
    303                 /* Add into layout: */
    304                 pLayoutInterface->addLayout(pLayoutAutomatic, 0, 0, 1, 3);
    305             }
    306 
    307             /* Create manual interface configuration radio-button: */
    308             m_pButtonManual = new QRadioButton;
    309             AssertPtrReturnVoid(m_pButtonManual);
    310             {
    311                 /* Configure radio-button: */
    312                 connect(m_pButtonManual, &QRadioButton::toggled,
    313                         this, &UIHostNetworkDetailsDialog::sltToggledButtonManual);
    314                 /* Add into layout: */
    315                 pLayoutInterface->addWidget(m_pButtonManual, 1, 0, 1, 3);
    316             }
    317 
    318             /* Create IPv4 address label: */
    319             m_pLabelIPv4 = new QLabel;
    320             AssertPtrReturnVoid(m_pLabelIPv4);
    321             {
    322                 /* Configure label: */
    323                 m_pLabelIPv4->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    324                 /* Add into layout: */
    325                 pLayoutInterface->addWidget(m_pLabelIPv4, 2, 1);
    326             }
    327             /* Create IPv4 layout: */
    328             QHBoxLayout *pLayoutIPv4 = new QHBoxLayout;
    329             AssertPtrReturnVoid(pLayoutIPv4);
    330             {
    331                 /* Configure layout: */
    332                 pLayoutIPv4->setContentsMargins(0, 0, 0, 0);
    333                 /* Create IPv4 address editor: */
    334                 m_pEditorIPv4 = new QILineEdit;
    335                 AssertPtrReturnVoid(m_pEditorIPv4);
    336                 {
    337                     /* Configure editor: */
    338                     m_pLabelIPv4->setBuddy(m_pEditorIPv4);
    339                     connect(m_pEditorIPv4, &QLineEdit::textChanged,
    340                             this, &UIHostNetworkDetailsDialog::sltTextChangedIPv4);
    341                     /* Add into layout: */
    342                     pLayoutIPv4->addWidget(m_pEditorIPv4);
    343                 }
    344                 /* Create IPv4 error pane: */
    345                 m_pErrorPaneIPv4 = new QLabel;
    346                 AssertPtrReturnVoid(m_pErrorPaneIPv4);
    347                 {
    348                     /* Configure label: */
    349                     m_pErrorPaneIPv4->setAlignment(Qt::AlignCenter);
    350                     m_pErrorPaneIPv4->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    351                     /* Add into layout: */
    352                     pLayoutIPv4->addWidget(m_pErrorPaneIPv4);
    353                 }
    354                 /* Add into layout: */
    355                 pLayoutInterface->addLayout(pLayoutIPv4, 2, 2);
    356             }
    357 
    358             /* Create NMv4 network mask label: */
    359             m_pLabelNMv4 = new QLabel;
    360             AssertPtrReturnVoid(m_pLabelNMv4);
    361             {
    362                 /* Configure label: */
    363                 m_pLabelNMv4->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    364                 /* Add into layout: */
    365                 pLayoutInterface->addWidget(m_pLabelNMv4, 3, 1);
    366             }
    367             /* Create NMv4 layout: */
    368             QHBoxLayout *pLayoutNMv4 = new QHBoxLayout;
    369             AssertPtrReturnVoid(pLayoutNMv4);
    370             {
    371                 /* Configure layout: */
    372                 pLayoutNMv4->setContentsMargins(0, 0, 0, 0);
    373                 /* Create NMv4 network mask editor: */
    374                 m_pEditorNMv4 = new QILineEdit;
    375                 AssertPtrReturnVoid(m_pEditorNMv4);
    376                 {
    377                     /* Configure editor: */
    378                     m_pLabelNMv4->setBuddy(m_pEditorNMv4);
    379                     connect(m_pEditorNMv4, &QLineEdit::textChanged,
    380                             this, &UIHostNetworkDetailsDialog::sltTextChangedNMv4);
    381                     /* Add into layout: */
    382                     pLayoutNMv4->addWidget(m_pEditorNMv4);
    383                 }
    384                 /* Create NMv4 error pane: */
    385                 m_pErrorPaneNMv4 = new QLabel;
    386                 AssertPtrReturnVoid(m_pErrorPaneNMv4);
    387                 {
    388                     /* Configure label: */
    389                     m_pErrorPaneNMv4->setAlignment(Qt::AlignCenter);
    390                     m_pErrorPaneNMv4->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    391                     /* Add into layout: */
    392                     pLayoutNMv4->addWidget(m_pErrorPaneNMv4);
    393                 }
    394                 /* Add into layout: */
    395                 pLayoutInterface->addLayout(pLayoutNMv4, 3, 2);
    396             }
    397 
    398             /* Create IPv6 address label: */
    399             m_pLabelIPv6 = new QLabel;
    400             AssertPtrReturnVoid(m_pLabelIPv6);
    401             {
    402                 /* Configure label: */
    403                 m_pLabelIPv6->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    404                 /* Add into layout: */
    405                 pLayoutInterface->addWidget(m_pLabelIPv6, 4, 1);
    406             }
    407             /* Create IPv6 layout: */
    408             QHBoxLayout *pLayoutIPv6 = new QHBoxLayout;
    409             AssertPtrReturnVoid(pLayoutIPv6);
    410             {
    411                 /* Configure layout: */
    412                 pLayoutIPv6->setContentsMargins(0, 0, 0, 0);
    413                 /* Create IPv6 address editor: */
    414                 m_pEditorIPv6 = new QILineEdit;
    415                 AssertPtrReturnVoid(m_pEditorIPv6);
    416                 {
    417                     /* Configure editor: */
    418                     m_pLabelIPv6->setBuddy(m_pEditorIPv6);
    419                     connect(m_pEditorIPv6, &QLineEdit::textChanged,
    420                             this, &UIHostNetworkDetailsDialog::sltTextChangedIPv6);
    421                     /* Add into layout: */
    422                     pLayoutIPv6->addWidget(m_pEditorIPv6);
    423                 }
    424                 /* Create IPv4 error pane: */
    425                 m_pErrorPaneIPv6 = new QLabel;
    426                 AssertPtrReturnVoid(m_pErrorPaneIPv6);
    427                 {
    428                     /* Configure label: */
    429                     m_pErrorPaneIPv6->setAlignment(Qt::AlignCenter);
    430                     m_pErrorPaneIPv6->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    431                     /* Add into layout: */
    432                     pLayoutIPv6->addWidget(m_pErrorPaneIPv6);
    433                 }
    434                 /* Add into layout: */
    435                 pLayoutInterface->addLayout(pLayoutIPv6, 4, 2);
    436             }
    437 
    438             /* Create NMv6 network mask label: */
    439             m_pLabelNMv6 = new QLabel;
    440             AssertPtrReturnVoid(m_pLabelNMv6);
    441             {
    442                 /* Configure label: */
    443                 m_pLabelNMv6->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    444                 /* Add into layout: */
    445                 pLayoutInterface->addWidget(m_pLabelNMv6, 5, 1);
    446             }
    447             /* Create NMv6 layout: */
    448             QHBoxLayout *pLayoutNMv6 = new QHBoxLayout;
    449             AssertPtrReturnVoid(pLayoutNMv6);
    450             {
    451                 /* Configure layout: */
    452                 pLayoutNMv6->setContentsMargins(0, 0, 0, 0);
    453                 /* Create NMv6 network mask editor: */
    454                 m_pEditorNMv6 = new QILineEdit;
    455                 AssertPtrReturnVoid(m_pEditorNMv6);
    456                 {
    457                     /* Configure editor: */
    458                     m_pLabelNMv6->setBuddy(m_pEditorNMv6);
    459                     connect(m_pEditorNMv6, &QLineEdit::textChanged,
    460                             this, &UIHostNetworkDetailsDialog::sltTextChangedNMv6);
    461                     /* Add into layout: */
    462                     pLayoutNMv6->addWidget(m_pEditorNMv6);
    463                 }
    464                 /* Create NMv6 error pane: */
    465                 m_pErrorPaneNMv6 = new QLabel;
    466                 AssertPtrReturnVoid(m_pErrorPaneNMv6);
    467                 {
    468                     /* Configure label: */
    469                     m_pErrorPaneNMv6->setAlignment(Qt::AlignCenter);
    470                     m_pErrorPaneNMv6->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    471                     /* Add into layout: */
    472                     pLayoutNMv6->addWidget(m_pErrorPaneNMv6);
    473                 }
    474                 /* Add into layout: */
    475                 pLayoutInterface->addLayout(pLayoutNMv6, 5, 2);
    476             }
    477 
    478             /* Create indent: */
    479             QStyleOption options;
    480             options.initFrom(m_pButtonManual);
    481             const int iWidth = m_pButtonManual->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &options, m_pButtonManual) +
    482                                m_pButtonManual->style()->pixelMetric(QStyle::PM_RadioButtonLabelSpacing, &options, m_pButtonManual) -
    483                                pLayoutInterface->spacing() - 1;
    484             QSpacerItem *pSpacer1 = new QSpacerItem(iWidth, 0, QSizePolicy::Fixed, QSizePolicy::Expanding);
    485             AssertPtrReturnVoid(pSpacer1);
    486             {
    487                 /* Add into layout: */
    488                 pLayoutInterface->addItem(pSpacer1, 2, 0, 4);
    489             }
    490             /* Create stretch: */
    491             QSpacerItem *pSpacer2 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
    492             AssertPtrReturnVoid(pSpacer2);
    493             {
    494                 /* Add into layout: */
    495                 pLayoutInterface->addItem(pSpacer2, 6, 0, 1, 3);
    496             }
    497         }
    498         /* Add to tab-widget: */
    499         m_pTabWidget->addTab(pTabInterface, QString());
    500     }
    501 }
    502 
    503 void UIHostNetworkDetailsDialog::prepareTabDHCPServer()
    504 {
    505     /* Create 'DHCP server' tab: */
    506     QWidget *pTabDHCPServer = new QWidget;
    507     AssertPtrReturnVoid(pTabDHCPServer);
    508     {
    509         /* Create 'DHCP server' layout: */
    510         QGridLayout *pLayoutDHCPServer = new QGridLayout(pTabDHCPServer);
    511         AssertPtrReturnVoid(pLayoutDHCPServer);
    512         {
    513 #ifdef VBOX_WS_MAC
    514             /* Configure layout: */
    515             pLayoutDHCPServer->setContentsMargins(10, 10, 10, 10);
    516 #endif
    517 
    518             /* Create DHCP server status check-box: */
    519             m_pCheckBoxDHCP = new QCheckBox;
    520             AssertPtrReturnVoid(m_pCheckBoxDHCP);
    521             {
    522                 /* Configure check-box: */
    523                 connect(m_pCheckBoxDHCP, &QCheckBox::stateChanged,
    524                         this, &UIHostNetworkDetailsDialog::sltStatusChangedServer);
    525                 /* Add into layout: */
    526                 pLayoutDHCPServer->addWidget(m_pCheckBoxDHCP, 0, 0, 1, 2);
    527             }
    528 
    529             /* Create DHCP address label: */
    530             m_pLabelDHCPAddress = new QLabel;
    531             AssertPtrReturnVoid(m_pLabelDHCPAddress);
    532             {
    533                 /* Configure label: */
    534                 m_pLabelDHCPAddress->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    535                 /* Add into layout: */
    536                 pLayoutDHCPServer->addWidget(m_pLabelDHCPAddress, 1, 1);
    537             }
    538             /* Create DHCP address layout: */
    539             QHBoxLayout *pLayoutDHCPAddress = new QHBoxLayout;
    540             AssertPtrReturnVoid(pLayoutDHCPAddress);
    541             {
    542                 /* Configure layout: */
    543                 pLayoutDHCPAddress->setContentsMargins(0, 0, 0, 0);
    544                 /* Create DHCP address editor: */
    545                 m_pEditorDHCPAddress = new QILineEdit;
    546                 AssertPtrReturnVoid(m_pEditorDHCPAddress);
    547                 {
    548                     /* Configure editor: */
    549                     m_pLabelDHCPAddress->setBuddy(m_pEditorDHCPAddress);
    550                     connect(m_pEditorDHCPAddress, &QLineEdit::textChanged,
    551                             this, &UIHostNetworkDetailsDialog::sltTextChangedAddress);
    552                     /* Add into layout: */
    553                     pLayoutDHCPAddress->addWidget(m_pEditorDHCPAddress);
    554                 }
    555                 /* Create DHCP address error pane: */
    556                 m_pErrorPaneDHCPAddress = new QLabel;
    557                 AssertPtrReturnVoid(m_pErrorPaneDHCPAddress);
    558                 {
    559                     /* Configure label: */
    560                     m_pErrorPaneDHCPAddress->setAlignment(Qt::AlignCenter);
    561                     m_pErrorPaneDHCPAddress->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    562                     /* Add into layout: */
    563                     pLayoutDHCPAddress->addWidget(m_pErrorPaneDHCPAddress);
    564                 }
    565                 /* Add into layout: */
    566                 pLayoutDHCPServer->addLayout(pLayoutDHCPAddress, 1, 2);
    567             }
    568 
    569             /* Create DHCP network mask label: */
    570             m_pLabelDHCPMask = new QLabel;
    571             AssertPtrReturnVoid(m_pLabelDHCPMask);
    572             {
    573                 /* Configure label: */
    574                 m_pLabelDHCPMask->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    575                 /* Add into layout: */
    576                 pLayoutDHCPServer->addWidget(m_pLabelDHCPMask, 2, 1);
    577             }
    578             /* Create DHCP mask layout: */
    579             QHBoxLayout *pLayoutDHCPMask = new QHBoxLayout;
    580             AssertPtrReturnVoid(pLayoutDHCPMask);
    581             {
    582                 /* Configure layout: */
    583                 pLayoutDHCPMask->setContentsMargins(0, 0, 0, 0);
    584                 /* Create DHCP network mask editor: */
    585                 m_pEditorDHCPMask = new QILineEdit;
    586                 AssertPtrReturnVoid(m_pEditorDHCPMask);
    587                 {
    588                     /* Configure editor: */
    589                     m_pLabelDHCPMask->setBuddy(m_pEditorDHCPMask);
    590                     connect(m_pEditorDHCPMask, &QLineEdit::textChanged,
    591                             this, &UIHostNetworkDetailsDialog::sltTextChangedMask);
    592                     /* Add into layout: */
    593                     pLayoutDHCPMask->addWidget(m_pEditorDHCPMask);
    594                 }
    595                 /* Create DHCP mask error pane: */
    596                 m_pErrorPaneDHCPMask = new QLabel;
    597                 AssertPtrReturnVoid(m_pErrorPaneDHCPMask);
    598                 {
    599                     /* Configure label: */
    600                     m_pErrorPaneDHCPMask->setAlignment(Qt::AlignCenter);
    601                     m_pErrorPaneDHCPMask->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    602                     /* Add into layout: */
    603                     pLayoutDHCPMask->addWidget(m_pErrorPaneDHCPMask);
    604                 }
    605                 /* Add into layout: */
    606                 pLayoutDHCPServer->addLayout(pLayoutDHCPMask, 2, 2);
    607             }
    608 
    609             /* Create DHCP lower address label: */
    610             m_pLabelDHCPLowerAddress = new QLabel;
    611             AssertPtrReturnVoid(m_pLabelDHCPLowerAddress);
    612             {
    613                 /* Configure label: */
    614                 m_pLabelDHCPLowerAddress->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    615                 /* Add into layout: */
    616                 pLayoutDHCPServer->addWidget(m_pLabelDHCPLowerAddress, 3, 1);
    617             }
    618             /* Create DHCP lower address layout: */
    619             QHBoxLayout *pLayoutDHCPLowerAddress = new QHBoxLayout;
    620             AssertPtrReturnVoid(pLayoutDHCPLowerAddress);
    621             {
    622                 /* Configure layout: */
    623                 pLayoutDHCPLowerAddress->setContentsMargins(0, 0, 0, 0);
    624                 /* Create DHCP lower address editor: */
    625                 m_pEditorDHCPLowerAddress = new QILineEdit;
    626                 AssertPtrReturnVoid(m_pEditorDHCPLowerAddress);
    627                 {
    628                     /* Configure editor: */
    629                     m_pLabelDHCPLowerAddress->setBuddy(m_pEditorDHCPLowerAddress);
    630                     connect(m_pEditorDHCPLowerAddress, &QLineEdit::textChanged,
    631                             this, &UIHostNetworkDetailsDialog::sltTextChangedLowerAddress);
    632                     /* Add into layout: */
    633                     pLayoutDHCPLowerAddress->addWidget(m_pEditorDHCPLowerAddress);
    634                 }
    635                 /* Create DHCP lower address error pane: */
    636                 m_pErrorPaneDHCPLowerAddress = new QLabel;
    637                 AssertPtrReturnVoid(m_pErrorPaneDHCPLowerAddress);
    638                 {
    639                     /* Configure label: */
    640                     m_pErrorPaneDHCPLowerAddress->setAlignment(Qt::AlignCenter);
    641                     m_pErrorPaneDHCPLowerAddress->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    642                     /* Add into layout: */
    643                     pLayoutDHCPLowerAddress->addWidget(m_pErrorPaneDHCPLowerAddress);
    644                 }
    645                 /* Add into layout: */
    646                 pLayoutDHCPServer->addLayout(pLayoutDHCPLowerAddress, 3, 2);
    647             }
    648 
    649             /* Create DHCP upper address label: */
    650             m_pLabelDHCPUpperAddress = new QLabel;
    651             AssertPtrReturnVoid(m_pLabelDHCPUpperAddress);
    652             {
    653                 /* Configure label: */
    654                 m_pLabelDHCPUpperAddress->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
    655                 /* Add into layout: */
    656                 pLayoutDHCPServer->addWidget(m_pLabelDHCPUpperAddress, 4, 1);
    657             }
    658             /* Create DHCP upper address layout: */
    659             QHBoxLayout *pLayoutDHCPUpperAddress = new QHBoxLayout;
    660             AssertPtrReturnVoid(pLayoutDHCPUpperAddress);
    661             {
    662                 /* Configure layout: */
    663                 pLayoutDHCPUpperAddress->setContentsMargins(0, 0, 0, 0);
    664                 /* Create DHCP upper address editor: */
    665                 m_pEditorDHCPUpperAddress = new QILineEdit;
    666                 AssertPtrReturnVoid(m_pEditorDHCPUpperAddress);
    667                 {
    668                     /* Configure editor: */
    669                     m_pLabelDHCPUpperAddress->setBuddy(m_pEditorDHCPUpperAddress);
    670                     connect(m_pEditorDHCPUpperAddress, &QLineEdit::textChanged,
    671                             this, &UIHostNetworkDetailsDialog::sltTextChangedUpperAddress);
    672                     /* Add into layout: */
    673                     pLayoutDHCPUpperAddress->addWidget(m_pEditorDHCPUpperAddress);
    674                 }
    675                 /* Create DHCP upper address error pane: */
    676                 m_pErrorPaneDHCPUpperAddress = new QLabel;
    677                 AssertPtrReturnVoid(m_pErrorPaneDHCPUpperAddress);
    678                 {
    679                     /* Configure label: */
    680                     m_pErrorPaneDHCPUpperAddress->setAlignment(Qt::AlignCenter);
    681                     m_pErrorPaneDHCPUpperAddress->setPixmap(UIIconPool::iconSet(":/status_error_16px.png").pixmap(QSize(16, 16)));
    682                     /* Add into layout: */
    683                     pLayoutDHCPUpperAddress->addWidget(m_pErrorPaneDHCPUpperAddress);
    684                 }
    685                 /* Add into layout: */
    686                 pLayoutDHCPServer->addLayout(pLayoutDHCPUpperAddress, 4, 2);
    687             }
    688 
    689             /* Create indent: */
    690             QStyleOption options;
    691             options.initFrom(m_pCheckBoxDHCP);
    692             const int iWidth = m_pCheckBoxDHCP->style()->pixelMetric(QStyle::PM_IndicatorWidth, &options, m_pCheckBoxDHCP) +
    693                                m_pCheckBoxDHCP->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &options, m_pCheckBoxDHCP) -
    694                                pLayoutDHCPServer->spacing() - 1;
    695             QSpacerItem *pSpacer1 = new QSpacerItem(iWidth, 0, QSizePolicy::Fixed, QSizePolicy::Expanding);
    696             AssertPtrReturnVoid(pSpacer1);
    697             {
    698                 /* Add into layout: */
    699                 pLayoutDHCPServer->addItem(pSpacer1, 1, 0, 4);
    700             }
    701             /* Create stretch: */
    702             QSpacerItem *pSpacer2 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
    703             AssertPtrReturnVoid(pSpacer2);
    704             {
    705                 /* Add into layout: */
    706                 pLayoutDHCPServer->addItem(pSpacer2, 5, 0, 1, 3);
    707             }
    708         }
    709         /* Add to tab-widget: */
    710         m_pTabWidget->addTab(pTabDHCPServer, QString());
    711     }
    712 }
    713 
    714 void UIHostNetworkDetailsDialog::loadDataForInterface()
    715 {
    716     /* Toggle IPv4 & IPv6 interface fields availability: */
    717     const bool fIsInterfaceConfigurable = !m_newData.m_interface.m_fDHCPEnabled;
    718     m_pLabelIPv4->setEnabled(fIsInterfaceConfigurable);
    719     m_pLabelNMv4->setEnabled(fIsInterfaceConfigurable);
    720     m_pEditorIPv4->setEnabled(fIsInterfaceConfigurable);
    721     m_pEditorNMv4->setEnabled(fIsInterfaceConfigurable);
    722 
    723     /* Load IPv4 interface fields: */
    724     m_pButtonAutomatic->setChecked(!fIsInterfaceConfigurable);
    725     m_pButtonManual->setChecked(fIsInterfaceConfigurable);
    726     m_pEditorIPv4->setText(m_newData.m_interface.m_strAddress);
    727     m_pEditorNMv4->setText(m_newData.m_interface.m_strMask);
    728 
    729     /* Toggle IPv6 interface fields availability: */
    730     const bool fIsIpv6Configurable = fIsInterfaceConfigurable && m_newData.m_interface.m_fSupportedIPv6;
    731     m_pLabelIPv6->setEnabled(fIsIpv6Configurable);
    732     m_pLabelNMv6->setEnabled(fIsIpv6Configurable);
    733     m_pEditorIPv6->setEnabled(fIsIpv6Configurable);
    734     m_pEditorNMv6->setEnabled(fIsIpv6Configurable);
    735 
    736     /* Load IPv6 interface fields: */
    737     m_pEditorIPv6->setText(m_newData.m_interface.m_strAddress6);
    738     m_pEditorNMv6->setText(m_newData.m_interface.m_strMaskLength6);
    739 }
    740 
    741 void UIHostNetworkDetailsDialog::loadDataForDHCPServer()
    742 {
    743     /* Toggle DHCP server fields availability: */
    744     const bool fIsDHCPServerEnabled = m_newData.m_dhcpserver.m_fEnabled;
    745     m_pLabelDHCPAddress->setEnabled(fIsDHCPServerEnabled);
    746     m_pLabelDHCPMask->setEnabled(fIsDHCPServerEnabled);
    747     m_pLabelDHCPLowerAddress->setEnabled(fIsDHCPServerEnabled);
    748     m_pLabelDHCPUpperAddress->setEnabled(fIsDHCPServerEnabled);
    749     m_pEditorDHCPAddress->setEnabled(fIsDHCPServerEnabled);
    750     m_pEditorDHCPMask->setEnabled(fIsDHCPServerEnabled);
    751     m_pEditorDHCPLowerAddress->setEnabled(fIsDHCPServerEnabled);
    752     m_pEditorDHCPUpperAddress->setEnabled(fIsDHCPServerEnabled);
    753 
    754     /* Load DHCP server fields: */
    755     m_pCheckBoxDHCP->setChecked(fIsDHCPServerEnabled);
    756     m_pEditorDHCPAddress->setText(m_newData.m_dhcpserver.m_strAddress);
    757     m_pEditorDHCPMask->setText(m_newData.m_dhcpserver.m_strMask);
    758     m_pEditorDHCPLowerAddress->setText(m_newData.m_dhcpserver.m_strLowerAddress);
    759     m_pEditorDHCPUpperAddress->setText(m_newData.m_dhcpserver.m_strUpperAddress);
    760 }
    761 
    762 void UIHostNetworkDetailsDialog::revalidate(QWidget *pWidget /* = 0 */)
    763 {
    764     /* Validate 'Interface' tab content: */
    765     if (!pWidget || pWidget == m_pErrorPaneAutomatic)
    766     {
    767         const bool fError =    m_newData.m_interface.m_fDHCPEnabled
    768                             && !m_newData.m_dhcpserver.m_fEnabled;
    769         m_pErrorPaneAutomatic->setVisible(fError);
    770     }
    771     if (!pWidget || pWidget == m_pErrorPaneIPv4)
    772     {
    773         const bool fError =    !m_newData.m_interface.m_fDHCPEnabled
    774                             && !m_newData.m_interface.m_strAddress.trimmed().isEmpty()
    775                             && (   !RTNetIsIPv4AddrStr(m_newData.m_interface.m_strAddress.toUtf8().constData())
    776                                 || RTNetStrIsIPv4AddrAny(m_newData.m_interface.m_strAddress.toUtf8().constData()));
    777         m_pErrorPaneIPv4->setVisible(fError);
    778     }
    779     if (!pWidget || pWidget == m_pErrorPaneNMv4)
    780     {
    781         const bool fError =    !m_newData.m_interface.m_fDHCPEnabled
    782                             && !m_newData.m_interface.m_strMask.trimmed().isEmpty()
    783                             && (   !RTNetIsIPv4AddrStr(m_newData.m_interface.m_strMask.toUtf8().constData())
    784                                 || RTNetStrIsIPv4AddrAny(m_newData.m_interface.m_strMask.toUtf8().constData()));
    785         m_pErrorPaneNMv4->setVisible(fError);
    786     }
    787     if (!pWidget || pWidget == m_pErrorPaneIPv6)
    788     {
    789         const bool fError =    !m_newData.m_interface.m_fDHCPEnabled
    790                             && m_newData.m_interface.m_fSupportedIPv6
    791                             && !m_newData.m_interface.m_strAddress6.trimmed().isEmpty()
    792                             && (   !RTNetIsIPv6AddrStr(m_newData.m_interface.m_strAddress6.toUtf8().constData())
    793                                 || RTNetStrIsIPv6AddrAny(m_newData.m_interface.m_strAddress6.toUtf8().constData()));
    794         m_pErrorPaneIPv6->setVisible(fError);
    795     }
    796     if (!pWidget || pWidget == m_pErrorPaneNMv6)
    797     {
    798         bool fIsMaskPrefixLengthNumber = false;
    799         const int iMaskPrefixLength = m_newData.m_interface.m_strMaskLength6.trimmed().toInt(&fIsMaskPrefixLengthNumber);
    800         const bool fError =    !m_newData.m_interface.m_fDHCPEnabled
    801                             && m_newData.m_interface.m_fSupportedIPv6
    802                             && (   !fIsMaskPrefixLengthNumber
    803                                 || iMaskPrefixLength < 0
    804                                 || iMaskPrefixLength > 128);
    805         m_pErrorPaneNMv6->setVisible(fError);
    806     }
    807 
    808     /* Validate 'DHCP server' tab content: */
    809     if (!pWidget || pWidget == m_pErrorPaneDHCPAddress)
    810     {
    811         const bool fError =    m_newData.m_dhcpserver.m_fEnabled
    812                             && (   !RTNetIsIPv4AddrStr(m_newData.m_dhcpserver.m_strAddress.toUtf8().constData())
    813                                 || RTNetStrIsIPv4AddrAny(m_newData.m_dhcpserver.m_strAddress.toUtf8().constData()));
    814         m_pErrorPaneDHCPAddress->setVisible(fError);
    815     }
    816     if (!pWidget || pWidget == m_pErrorPaneDHCPMask)
    817     {
    818         const bool fError =    m_newData.m_dhcpserver.m_fEnabled
    819                             && (   !RTNetIsIPv4AddrStr(m_newData.m_dhcpserver.m_strMask.toUtf8().constData())
    820                                 || RTNetStrIsIPv4AddrAny(m_newData.m_dhcpserver.m_strMask.toUtf8().constData()));
    821         m_pErrorPaneDHCPMask->setVisible(fError);
    822     }
    823     if (!pWidget || pWidget == m_pErrorPaneDHCPLowerAddress)
    824     {
    825         const bool fError =    m_newData.m_dhcpserver.m_fEnabled
    826                             && (   !RTNetIsIPv4AddrStr(m_newData.m_dhcpserver.m_strLowerAddress.toUtf8().constData())
    827                                 || RTNetStrIsIPv4AddrAny(m_newData.m_dhcpserver.m_strLowerAddress.toUtf8().constData()));
    828         m_pErrorPaneDHCPLowerAddress->setVisible(fError);
    829     }
    830     if (!pWidget || pWidget == m_pErrorPaneDHCPUpperAddress)
    831     {
    832         const bool fError =    m_newData.m_dhcpserver.m_fEnabled
    833                             && (   !RTNetIsIPv4AddrStr(m_newData.m_dhcpserver.m_strUpperAddress.toUtf8().constData())
    834                                 || RTNetStrIsIPv4AddrAny(m_newData.m_dhcpserver.m_strUpperAddress.toUtf8().constData()));
    835         m_pErrorPaneDHCPUpperAddress->setVisible(fError);
    836     }
    837 
    838     /* Retranslate validation: */
    839     retranslateValidation(pWidget);
    840 }
    841 
    842 void UIHostNetworkDetailsDialog::retranslateValidation(QWidget *pWidget /* = 0 */)
    843 {
    844     /* Translate 'Interface' tab content: */
    845     if (!pWidget || pWidget == m_pErrorPaneAutomatic)
    846         m_pErrorPaneAutomatic->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> is set to obtain address automatically "
    847                                              "but its DHCP server is not enabled.").arg(m_newData.m_interface.m_strName));
    848     if (!pWidget || pWidget == m_pErrorPaneIPv4)
    849         m_pErrorPaneIPv4->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> does not currently have a valid "
    850                                         "IPv4 address.").arg(m_newData.m_interface.m_strName));
    851     if (!pWidget || pWidget == m_pErrorPaneNMv4)
    852         m_pErrorPaneNMv4->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> does not currently have a valid "
    853                                         "IPv4 network mask.").arg(m_newData.m_interface.m_strName));
    854     if (!pWidget || pWidget == m_pErrorPaneIPv6)
    855         m_pErrorPaneIPv6->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> does not currently have a valid "
    856                                         "IPv6 address.").arg(m_newData.m_interface.m_strName));
    857     if (!pWidget || pWidget == m_pErrorPaneNMv6)
    858         m_pErrorPaneNMv6->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> does not currently have a valid "
    859                                         "IPv6 network mask prefix length.").arg(m_newData.m_interface.m_strName));
    860 
    861     /* Translate 'DHCP server' tab content: */
    862     if (!pWidget || pWidget == m_pErrorPaneDHCPAddress)
    863         m_pErrorPaneDHCPAddress->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> does not currently have a valid "
    864                                                "DHCP server address.").arg(m_newData.m_interface.m_strName));
    865     if (!pWidget || pWidget == m_pErrorPaneDHCPMask)
    866         m_pErrorPaneDHCPMask->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> does not currently have a valid "
    867                                             "DHCP server mask.").arg(m_newData.m_interface.m_strName));
    868     if (!pWidget || pWidget == m_pErrorPaneDHCPLowerAddress)
    869         m_pErrorPaneDHCPLowerAddress->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> does not currently have a valid "
    870                                                     "DHCP server lower address bound.").arg(m_newData.m_interface.m_strName));
    871     if (!pWidget || pWidget == m_pErrorPaneDHCPUpperAddress)
    872         m_pErrorPaneDHCPUpperAddress->setToolTip(tr("Host interface <nobr><b>%1</b></nobr> does not currently have a valid "
    873                                                     "DHCP server upper address bound.").arg(m_newData.m_interface.m_strName));
    874 }
    875 
    876 void UIHostNetworkDetailsDialog::notify()
    877 {
    878 //    if (m_oldData != m_newData)
    879 //        printf("Interface: %s, %s, %s, %s;  DHCP server: %d, %s, %s, %s, %s\n",
    880 //               m_newData.m_interface.m_strAddress.toUtf8().constData(),
    881 //               m_newData.m_interface.m_strMask.toUtf8().constData(),
    882 //               m_newData.m_interface.m_strAddress6.toUtf8().constData(),
    883 //               m_newData.m_interface.m_strMaskLength6.toUtf8().constData(),
    884 //               (int)m_newData.m_dhcpserver.m_fEnabled,
    885 //               m_newData.m_dhcpserver.m_strAddress.toUtf8().constData(),
    886 //               m_newData.m_dhcpserver.m_strMask.toUtf8().constData(),
    887 //               m_newData.m_dhcpserver.m_strLowerAddress.toUtf8().constData(),
    888 //               m_newData.m_dhcpserver.m_strUpperAddress.toUtf8().constData());
    889 
    890     emit sigDataChanged(m_oldData != m_newData);
    891 }
    892 
    893 /* static */
    894 quint32 UIHostNetworkDetailsDialog::ipv4FromQStringToQuint32(const QString &strAddress)
     31quint32 UIHostNetworkUtils::ipv4FromQStringToQuint32(const QString &strAddress)
    89532{
    89633    quint32 uAddress = 0;
     
    90643}
    90744
    908 /* static */
    909 QString UIHostNetworkDetailsDialog::ipv4FromQuint32ToQString(quint32 uAddress)
     45QString UIHostNetworkUtils::ipv4FromQuint32ToQString(quint32 uAddress)
    91046{
    91147    QStringList address;
  • trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkUtils.h

    r66809 r66855  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIHostNetworkDetailsDialog class declaration.
     3 * VBox Qt GUI - UIHostNetworkUtils namespace declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UIHostNetworkDetailsDialog_h__
    19 #define __UIHostNetworkDetailsDialog_h__
     18#ifndef ___UIHostNetworkUtils_h___
     19#define ___UIHostNetworkUtils_h___
    2020
    2121/* Qt includes: */
    22 #include <QWidget>
    23 
    24 /* GUI includes: */
    25 #include "QIWithRetranslateUI.h"
    26 
    27 /* Forward declarations: */
    28 class QCheckBox;
    29 class QLabel;
    30 class QRadioButton;
    31 class QILineEdit;
    32 class QITabWidget;
     22#include <QString>
    3323
    3424
    35 /** Host Network Manager: Host Network Interface data structure. */
    36 struct UIDataHostNetworkInterface
     25/** Host Network Manager: Host network utilities. */
     26namespace UIHostNetworkUtils
    3727{
    38     /** Constructs data. */
    39     UIDataHostNetworkInterface()
    40         : m_strName(QString())
    41         , m_fDHCPEnabled(false)
    42         , m_strAddress(QString())
    43         , m_strMask(QString())
    44         , m_fSupportedIPv6(false)
    45         , m_strAddress6(QString())
    46         , m_strMaskLength6(QString())
    47     {}
     28    /** Converts IPv4 address from QString to quint32. */
     29    quint32 ipv4FromQStringToQuint32(const QString &strAddress);
     30    /** Converts IPv4 address from quint32 to QString. */
     31    QString ipv4FromQuint32ToQString(quint32 uAddress);
     32}
    4833
    49     /** Returns whether the @a other passed data is equal to this one. */
    50     bool equal(const UIDataHostNetworkInterface &other) const
    51     {
    52         return true
    53                && (m_strName == other.m_strName)
    54                && (m_fDHCPEnabled == other.m_fDHCPEnabled)
    55                && (m_strAddress == other.m_strAddress)
    56                && (m_strMask == other.m_strMask)
    57                && (m_fSupportedIPv6 == other.m_fSupportedIPv6)
    58                && (m_strAddress6 == other.m_strAddress6)
    59                && (m_strMaskLength6 == other.m_strMaskLength6)
    60                ;
    61     }
     34/* Using this namespace where included: */
     35using namespace UIHostNetworkUtils;
    6236
    63     /** Returns whether the @a other passed data is equal to this one. */
    64     bool operator==(const UIDataHostNetworkInterface &other) const { return equal(other); }
    65     /** Returns whether the @a other passed data is different from this one. */
    66     bool operator!=(const UIDataHostNetworkInterface &other) const { return !equal(other); }
     37#endif /* !___UIHostNetworkUtils_h___ */
    6738
    68     /** Holds interface name. */
    69     QString m_strName;
    70     /** Holds whether DHCP is enabled for that interface. */
    71     bool m_fDHCPEnabled;
    72     /** Holds IPv4 interface address. */
    73     QString m_strAddress;
    74     /** Holds IPv4 interface mask. */
    75     QString m_strMask;
    76     /** Holds whether IPv6 protocol supported. */
    77     bool m_fSupportedIPv6;
    78     /** Holds IPv6 interface address. */
    79     QString m_strAddress6;
    80     /** Holds IPv6 interface mask length. */
    81     QString m_strMaskLength6;
    82 };
    83 
    84 
    85 /** Host Network Manager: DHCP Server data structure. */
    86 struct UIDataDHCPServer
    87 {
    88     /** Constructs data. */
    89     UIDataDHCPServer()
    90         : m_fEnabled(false)
    91         , m_strAddress(QString())
    92         , m_strMask(QString())
    93         , m_strLowerAddress(QString())
    94         , m_strUpperAddress(QString())
    95     {}
    96 
    97     /** Returns whether the @a other passed data is equal to this one. */
    98     bool equal(const UIDataDHCPServer &other) const
    99     {
    100         return true
    101                && (m_fEnabled == other.m_fEnabled)
    102                && (m_strAddress == other.m_strAddress)
    103                && (m_strMask == other.m_strMask)
    104                && (m_strLowerAddress == other.m_strLowerAddress)
    105                && (m_strUpperAddress == other.m_strUpperAddress)
    106                ;
    107     }
    108 
    109     /** Returns whether the @a other passed data is equal to this one. */
    110     bool operator==(const UIDataDHCPServer &other) const { return equal(other); }
    111     /** Returns whether the @a other passed data is different from this one. */
    112     bool operator!=(const UIDataDHCPServer &other) const { return !equal(other); }
    113 
    114     /** Holds whether DHCP server enabled. */
    115     bool m_fEnabled;
    116     /** Holds DHCP server address. */
    117     QString m_strAddress;
    118     /** Holds DHCP server mask. */
    119     QString m_strMask;
    120     /** Holds DHCP server lower address. */
    121     QString m_strLowerAddress;
    122     /** Holds DHCP server upper address. */
    123     QString m_strUpperAddress;
    124 };
    125 
    126 
    127 /** Host Network Manager: Host network data structure. */
    128 struct UIDataHostNetwork
    129 {
    130     /** Constructs data. */
    131     UIDataHostNetwork()
    132         : m_interface(UIDataHostNetworkInterface())
    133         , m_dhcpserver(UIDataDHCPServer())
    134     {}
    135 
    136     /** Returns whether the @a other passed data is equal to this one. */
    137     bool equal(const UIDataHostNetwork &other) const
    138     {
    139         return true
    140                && (m_interface == other.m_interface)
    141                && (m_dhcpserver == other.m_dhcpserver)
    142                ;
    143     }
    144 
    145     /** Returns whether the @a other passed data is equal to this one. */
    146     bool operator==(const UIDataHostNetwork &other) const { return equal(other); }
    147     /** Returns whether the @a other passed data is different from this one. */
    148     bool operator!=(const UIDataHostNetwork &other) const { return !equal(other); }
    149 
    150     /** Holds the interface data. */
    151     UIDataHostNetworkInterface m_interface;
    152     /** Holds the DHCP server data. */
    153     UIDataDHCPServer m_dhcpserver;
    154 };
    155 
    156 
    157 /** Host Network Manager: Host network details widget. */
    158 class UIHostNetworkDetailsDialog : public QIWithRetranslateUI2<QWidget>
    159 {
    160     Q_OBJECT;
    161 
    162 signals:
    163 
    164     /** Notifies listeners about data changed and whether it @a fDiffers. */
    165     void sigDataChanged(bool fDiffers);
    166 
    167 public:
    168 
    169     /** Constructs host network details dialog for the passed @a pParent and @a data. */
    170     UIHostNetworkDetailsDialog(QWidget *pParent = 0);
    171 
    172     /** Returns the host network data. */
    173     const UIDataHostNetwork &data() const { return m_newData; }
    174     /** Defines the host network @a data. */
    175     void setData(const UIDataHostNetwork &data);
    176     /** Clears the host network data. */
    177     void clearData();
    178 
    179 protected:
    180 
    181     /** Handles translation event. */
    182     virtual void retranslateUi() /* override */;
    183 
    184 private slots:
    185 
    186     /** @name Change handling stuff.
    187      * @{ */
    188         /** Handles interface automatic configuration choice change. */
    189         void sltToggledButtonAutomatic(bool fChecked);
    190         /** Handles interface manual configuration choice change. */
    191         void sltToggledButtonManual(bool fChecked);
    192         /** Handles interface IPv4 text change. */
    193         void sltTextChangedIPv4(const QString &strText);
    194         /** Handles interface NMv4 text change. */
    195         void sltTextChangedNMv4(const QString &strText);
    196         /** Handles interface IPv6 text change. */
    197         void sltTextChangedIPv6(const QString &strText);
    198         /** Handles interface NMv6 text change. */
    199         void sltTextChangedNMv6(const QString &strText);
    200 
    201         /** Handles DHCP server status change. */
    202         void sltStatusChangedServer(int iChecked);
    203         /** Handles DHCP server address text change. */
    204         void sltTextChangedAddress(const QString &strText);
    205         /** Handles DHCP server mask text change. */
    206         void sltTextChangedMask(const QString &strText);
    207         /** Handles DHCP server lower address text change. */
    208         void sltTextChangedLowerAddress(const QString &strText);
    209         /** Handles DHCP server upper address text change. */
    210         void sltTextChangedUpperAddress(const QString &strText);
    211     /** @} */
    212 
    213 private:
    214 
    215     /** @name Prepare/cleanup cascade.
    216      * @{ */
    217         /** Prepares all. */
    218         void prepare();
    219         /** Prepares this. */
    220         void prepareThis();
    221         /** Prepares tab-widget. */
    222         void prepareTabWidget();
    223         /** Prepares 'Interface' tab. */
    224         void prepareTabInterface();
    225         /** Prepares 'DHCP server' tab. */
    226         void prepareTabDHCPServer();
    227     /** @} */
    228 
    229     /** @name Loading stuff.
    230      * @{ */
    231         /** Loads interface data. */
    232         void loadDataForInterface();
    233         /** Loads server data. */
    234         void loadDataForDHCPServer();
    235     /** @} */
    236 
    237     /** @name Change handling stuff.
    238      * @{ */
    239         /** Revalidates changes for passed @a pWidget. */
    240         void revalidate(QWidget *pWidget = 0);
    241         /** Retranslates validation for passed @a pWidget. */
    242         void retranslateValidation(QWidget *pWidget = 0);
    243         /** Notifies listeners about data changed or not. */
    244         void notify();
    245     /** @} */
    246 
    247     /** @name Helpers.
    248      * @{ */
    249         /** Converts IPv4 address from QString to quint32. */
    250         static quint32 ipv4FromQStringToQuint32(const QString &strAddress);
    251         /** Converts IPv4 address from quint32 to QString. */
    252         static QString ipv4FromQuint32ToQString(quint32 uAddress);
    253     /** @} */
    254 
    255     /** @name General variables.
    256      * @{ */
    257         /** Holds the old data copy. */
    258         UIDataHostNetwork  m_oldData;
    259         /** Holds the new data copy. */
    260         UIDataHostNetwork  m_newData;
    261         /** Holds the tab-widget. */
    262         QITabWidget       *m_pTabWidget;
    263     /** @} */
    264 
    265     /** @name Interface variables.
    266      * @{ */
    267         /** Holds the automatic interface configuration button. */
    268         QRadioButton *m_pButtonAutomatic;
    269         /** Holds the automatic interface configuration error pane. */
    270         QLabel       *m_pErrorPaneAutomatic;
    271 
    272         /** Holds the manual interface configuration button. */
    273         QRadioButton *m_pButtonManual;
    274 
    275         /** Holds the IPv4 address label. */
    276         QLabel       *m_pLabelIPv4;
    277         /** Holds the IPv4 address editor. */
    278         QILineEdit   *m_pEditorIPv4;
    279         /** Holds the IPv4 address error pane. */
    280         QLabel       *m_pErrorPaneIPv4;
    281 
    282         /** Holds the IPv4 network mask label. */
    283         QLabel       *m_pLabelNMv4;
    284         /** Holds the IPv4 network mask editor. */
    285         QILineEdit   *m_pEditorNMv4;
    286         /** Holds the IPv4 network mask error pane. */
    287         QLabel       *m_pErrorPaneNMv4;
    288 
    289         /** Holds the IPv6 address label. */
    290         QLabel       *m_pLabelIPv6;
    291         /** Holds the IPv6 address editor. */
    292         QILineEdit   *m_pEditorIPv6;
    293         /** Holds the IPv6 address error pane. */
    294         QLabel       *m_pErrorPaneIPv6;
    295 
    296         /** Holds the IPv6 network mask label. */
    297         QLabel       *m_pLabelNMv6;
    298         /** Holds the IPv6 network mask editor. */
    299         QILineEdit   *m_pEditorNMv6;
    300         /** Holds the IPv6 network mask error pane. */
    301         QLabel       *m_pErrorPaneNMv6;
    302     /** @} */
    303 
    304     /** @name DHCP server variables.
    305      * @{ */
    306         /** Holds the DHCP server status chack-box. */
    307         QCheckBox  *m_pCheckBoxDHCP;
    308 
    309         /** Holds the DHCP address label. */
    310         QLabel     *m_pLabelDHCPAddress;
    311         /** Holds the DHCP address editor. */
    312         QILineEdit *m_pEditorDHCPAddress;
    313         /** Holds the DHCP address error pane. */
    314         QLabel     *m_pErrorPaneDHCPAddress;
    315 
    316         /** Holds the DHCP network mask label. */
    317         QLabel     *m_pLabelDHCPMask;
    318         /** Holds the DHCP network mask editor. */
    319         QILineEdit *m_pEditorDHCPMask;
    320         /** Holds the DHCP network mask error pane. */
    321         QLabel     *m_pErrorPaneDHCPMask;
    322 
    323         /** Holds the DHCP lower address label. */
    324         QLabel     *m_pLabelDHCPLowerAddress;
    325         /** Holds the DHCP lower address editor. */
    326         QILineEdit *m_pEditorDHCPLowerAddress;
    327         /** Holds the DHCP lower address error pane. */
    328         QLabel     *m_pErrorPaneDHCPLowerAddress;
    329 
    330         /** Holds the DHCP upper address label. */
    331         QLabel     *m_pLabelDHCPUpperAddress;
    332         /** Holds the DHCP upper address editor. */
    333         QILineEdit *m_pEditorDHCPUpperAddress;
    334         /** Holds the DHCP upper address error pane. */
    335         QLabel     *m_pErrorPaneDHCPUpperAddress;
    336     /** @} */
    337 };
    338 
    339 #endif /* __UIHostNetworkDetailsDialog_h__ */
    340 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette