VirtualBox

Changeset 87089 in vbox for trunk/src


Ignore:
Timestamp:
Dec 14, 2020 6:09:21 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9871: Network Manager: Rework dialog to have tab-widget with just one host network tab for now; This way dialog will be extended to have NAT network tab later.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/networkmanager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UINetworkManager.cpp

    r87088 r87089  
    2424/* GUI includes: */
    2525#include "QIDialogButtonBox.h"
     26#include "QITabWidget.h"
    2627#include "QITreeWidget.h"
    2728#include "UIActionPoolManager.h"
     
    5859
    5960
    60 /** Host Network Manager: Tree-widget item. */
     61/** Network Manager: Host Network tree-widget item. */
    6162class UIItemHostNetwork : public QITreeWidgetItem, public UIDataHostNetwork
    6263{
     
    196197    , m_fShowToolbar(fShowToolbar)
    197198    , m_pToolBar(0)
    198     , m_pTreeWidget(0)
    199     , m_pDetailsWidget(0)
     199    , m_pTabWidget(0)
     200    , m_pTabHostNetwork(0)
     201    , m_pLayoutHostNetwork(0)
     202    , m_pTreeWidgetHostNetwork(0)
     203    , m_pDetailsWidgetHostNetwork(0)
    200204{
    201205    prepare();
     
    221225#endif
    222226
    223     /* Translate tree-widget: */
    224     if (m_pTreeWidget)
     227    /* Translate tab-widget: */
     228    if (m_pTabWidget)
     229        m_pTabWidget->setTabText(0, UINetworkManager::tr("Host-only Networks"));
     230
     231    /* Translate host network tree-widget: */
     232    if (m_pTreeWidgetHostNetwork)
    225233    {
    226234        const QStringList fields = QStringList()
     
    229237                                   << UINetworkManager::tr("IPv6 Address/Mask")
    230238                                   << UINetworkManager::tr("DHCP Server");
    231         m_pTreeWidget->setHeaderLabels(fields);
     239        m_pTreeWidgetHostNetwork->setHeaderLabels(fields);
    232240    }
    233241}
     
    238246    QIWithRetranslateUI<QWidget>::resizeEvent(pEvent);
    239247
    240     /* Adjust tree-widget: */
    241     sltAdjustTreeWidget();
     248    /* Adjust tree-widgets: */
     249    sltAdjustTreeWidgets();
    242250}
    243251
     
    247255    QIWithRetranslateUI<QWidget>::showEvent(pEvent);
    248256
    249     /* Adjust tree-widget: */
    250     sltAdjustTreeWidget();
    251 }
    252 
    253 void UINetworkManagerWidget::sltResetHostNetworkDetailsChanges()
    254 {
     257    /* Adjust tree-widgets: */
     258    sltAdjustTreeWidgets();
     259}
     260
     261void UINetworkManagerWidget::sltResetDetailsChanges()
     262{
     263    /* Check tab-widget: */
     264    AssertMsgReturnVoid(m_pTabWidget, ("This action should not be allowed!\n"));
     265
    255266    /* Just push current item data to details-widget again: */
    256     sltHandleCurrentItemChange();
    257 }
    258 
    259 void UINetworkManagerWidget::sltApplyHostNetworkDetailsChanges()
    260 {
    261     /* Check tree-widget: */
    262     AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n"));
    263 
    264     /* Get network item: */
    265     UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
    266     AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
    267 
    268     /* Check details-widget: */
    269     AssertMsgReturnVoid(m_pDetailsWidget, ("Details-widget isn't created!\n"));
    270 
    271     /* Get item data: */
    272     UIDataHostNetwork oldData = *pItem;
    273     UIDataHostNetwork newData = m_pDetailsWidget->data();
    274 
     267    switch (m_pTabWidget->currentIndex())
     268    {
     269        case 0:
     270        {
     271            sltHandleCurrentItemChangeHostNetwork();
     272            break;
     273        }
     274        default:
     275            break;
     276    }
     277}
     278
     279void UINetworkManagerWidget::sltApplyDetailsChanges()
     280{
     281    /* Check tab-widget: */
     282    AssertMsgReturnVoid(m_pTabWidget, ("This action should not be allowed!\n"));
     283
     284    /* Apply details-widget data changes: */
     285    switch (m_pTabWidget->currentIndex())
     286    {
     287        case 0:
     288        {
     289            sltApplyDetailsChangesHostNetwork();
     290            break;
     291        }
     292        default:
     293            break;
     294    }
     295}
     296
     297void UINetworkManagerWidget::sltCreateHostNetwork()
     298{
    275299    /* Get host for further activities: */
    276300    CHost comHost = uiCommon().host();
    277301
    278     /* Find corresponding interface: */
    279     CHostNetworkInterface comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName);
     302    /* Create interface: */
     303    CHostNetworkInterface comInterface;
     304    CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface);
    280305
    281306    /* Show error message if necessary: */
    282     if (!comHost.isOk() || comInterface.isNull())
    283         msgCenter().cannotFindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this);
     307    if (!comHost.isOk() || progress.isNull())
     308        msgCenter().cannotCreateHostNetworkInterface(comHost, this);
    284309    else
    285310    {
    286         /* Save automatic interface configuration: */
    287         if (newData.m_interface.m_fDHCPEnabled)
    288         {
    289             if (   comInterface.isOk()
    290                 && !oldData.m_interface.m_fDHCPEnabled)
    291                 comInterface.EnableDynamicIPConfig();
    292         }
    293         /* Save manual interface configuration: */
    294         else
    295         {
    296             /* Save IPv4 interface configuration: */
    297             if (   comInterface.isOk()
    298                 && (   oldData.m_interface.m_fDHCPEnabled
    299                     || newData.m_interface.m_strAddress != oldData.m_interface.m_strAddress
    300                     || newData.m_interface.m_strMask != oldData.m_interface.m_strMask))
    301                 comInterface.EnableStaticIPConfig(newData.m_interface.m_strAddress, newData.m_interface.m_strMask);
    302             /* Save IPv6 interface configuration: */
    303             if (   comInterface.isOk()
    304                 && newData.m_interface.m_fSupportedIPv6
    305                 && (   oldData.m_interface.m_fDHCPEnabled
    306                     || newData.m_interface.m_strAddress6 != oldData.m_interface.m_strAddress6
    307                     || newData.m_interface.m_strPrefixLength6 != oldData.m_interface.m_strPrefixLength6))
    308                 comInterface.EnableStaticIPConfigV6(newData.m_interface.m_strAddress6, newData.m_interface.m_strPrefixLength6.toULong());
    309         }
     311        /* Show interface creation progress: */
     312        msgCenter().showModalProgressDialog(progress, UINetworkManager::tr("Adding network ..."), ":/progress_network_interface_90px.png", this, 0);
    310313
    311314        /* Show error message if necessary: */
    312         if (!comInterface.isOk())
    313             msgCenter().cannotSaveHostNetworkInterfaceParameter(comInterface, this);
     315        if (!progress.isOk() || progress.GetResultCode() != 0)
     316            msgCenter().cannotCreateHostNetworkInterface(progress, this);
    314317        else
    315318        {
     
    333336                if (!comVBox.isOk() || comServer.isNull())
    334337                    msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this);
    335                 else
    336                 {
    337                     /* Save whether DHCP server is enabled: */
    338                     if (   comServer.isOk()
    339                         && newData.m_dhcpserver.m_fEnabled != oldData.m_dhcpserver.m_fEnabled)
    340                         comServer.SetEnabled(newData.m_dhcpserver.m_fEnabled);
    341                     /* Save DHCP server configuration: */
    342                     if (   comServer.isOk()
    343                         && newData.m_dhcpserver.m_fEnabled
    344                         && (   newData.m_dhcpserver.m_strAddress != oldData.m_dhcpserver.m_strAddress
    345                             || newData.m_dhcpserver.m_strMask != oldData.m_dhcpserver.m_strMask
    346                             || newData.m_dhcpserver.m_strLowerAddress != oldData.m_dhcpserver.m_strLowerAddress
    347                             || newData.m_dhcpserver.m_strUpperAddress != oldData.m_dhcpserver.m_strUpperAddress))
    348                         comServer.SetConfiguration(newData.m_dhcpserver.m_strAddress, newData.m_dhcpserver.m_strMask,
    349                                                    newData.m_dhcpserver.m_strLowerAddress, newData.m_dhcpserver.m_strUpperAddress);
    350 
    351                     /* Show error message if necessary: */
    352                     if (!comServer.isOk())
    353                         msgCenter().cannotSaveDHCPServerParameter(comServer, this);
    354                 }
    355             }
    356         }
    357 
    358         /* Find corresponding interface again (if necessary): */
    359         if (!comInterface.isOk())
    360         {
    361             comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName);
    362 
    363             /* Show error message if necessary: */
    364             if (!comHost.isOk() || comInterface.isNull())
    365                 msgCenter().cannotFindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this);
    366         }
    367 
    368         /* If interface is Ok now: */
    369         if (comInterface.isNotNull() && comInterface.isOk())
    370         {
    371             /* Update interface in the tree: */
    372             UIDataHostNetwork data;
    373             loadHostNetwork(comInterface, data);
    374             updateItemForNetworkHost(data, true, pItem);
    375 
    376             /* Make sure current item fetched: */
    377             sltHandleCurrentItemChange();
    378 
    379             /* Adjust tree-widget: */
    380             sltAdjustTreeWidget();
    381         }
    382     }
    383 }
    384 
    385 void UINetworkManagerWidget::sltCreateHostNetwork()
    386 {
    387     /* Get host for further activities: */
    388     CHost comHost = uiCommon().host();
    389 
    390     /* Create interface: */
    391     CHostNetworkInterface comInterface;
    392     CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface);
    393 
    394     /* Show error message if necessary: */
    395     if (!comHost.isOk() || progress.isNull())
    396         msgCenter().cannotCreateHostNetworkInterface(comHost, this);
    397     else
    398     {
    399         /* Show interface creation progress: */
    400         msgCenter().showModalProgressDialog(progress, UINetworkManager::tr("Adding network ..."), ":/progress_network_interface_90px.png", this, 0);
    401 
    402         /* Show error message if necessary: */
    403         if (!progress.isOk() || progress.GetResultCode() != 0)
    404             msgCenter().cannotCreateHostNetworkInterface(progress, this);
    405         else
    406         {
    407             /* Get network name for further activities: */
    408             const QString strNetworkName = comInterface.GetNetworkName();
    409 
    410             /* Show error message if necessary: */
    411             if (!comInterface.isOk())
    412                 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);
    413             else
    414             {
    415                 /* Get VBox for further activities: */
    416                 CVirtualBox comVBox = uiCommon().virtualBox();
    417 
    418                 /* Find corresponding DHCP server (create if necessary): */
    419                 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);
    420                 if (!comVBox.isOk() || comServer.isNull())
    421                     comServer = comVBox.CreateDHCPServer(strNetworkName);
    422 
    423                 /* Show error message if necessary: */
    424                 if (!comVBox.isOk() || comServer.isNull())
    425                     msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this);
    426338            }
    427339
     
    431343            createItemForNetworkHost(data, true);
    432344
    433             /* Adjust tree-widget: */
    434             sltAdjustTreeWidget();
     345            /* Adjust tree-widgets: */
     346            sltAdjustTreeWidgets();
    435347        }
    436348    }
     
    439351void UINetworkManagerWidget::sltRemoveHostNetwork()
    440352{
    441     /* Check tree-widget: */
    442     AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n"));
     353    /* Check host network tree-widget: */
     354    AssertMsgReturnVoid(m_pTreeWidgetHostNetwork, ("Host network tree-widget isn't created!\n"));
    443355
    444356    /* Get network item: */
    445     UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
     357    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidgetHostNetwork->currentItem());
    446358    AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
    447359
     
    512424                    delete pItem;
    513425
    514                     /* Adjust tree-widget: */
    515                     sltAdjustTreeWidget();
     426                    /* Adjust tree-widgets: */
     427                    sltAdjustTreeWidgets();
    516428                }
    517429            }
     
    520432}
    521433
    522 void UINetworkManagerWidget::sltToggleHostNetworkDetailsVisibility(bool fVisible)
     434void UINetworkManagerWidget::sltToggleDetailsVisibilityHostNetwork(bool fVisible)
    523435{
    524436    /* Save the setting: */
    525437    gEDataManager->setHostNetworkManagerDetailsExpanded(fVisible);
    526438    /* Show/hide details area and Apply button: */
    527     if (m_pDetailsWidget)
    528         m_pDetailsWidget->setVisible(fVisible);
     439    if (m_pDetailsWidgetHostNetwork)
     440        m_pDetailsWidgetHostNetwork->setVisible(fVisible);
    529441    /* Notify external listeners: */
    530     emit sigHostNetworkDetailsVisibilityChanged(fVisible);
     442    emit sigDetailsVisibilityChangedHostNetwork(fVisible);
    531443}
    532444
     
    537449}
    538450
    539 void UINetworkManagerWidget::sltAdjustTreeWidget()
    540 {
    541     /* Check tree-widget: */
    542     if (m_pTreeWidget)
     451void UINetworkManagerWidget::sltAdjustTreeWidgets()
     452{
     453    /* Check host network tree-widget: */
     454    if (m_pTreeWidgetHostNetwork)
    543455    {
    544456        /* Get the tree-widget abstract interface: */
    545         QAbstractItemView *pItemView = m_pTreeWidget;
     457        QAbstractItemView *pItemView = m_pTreeWidgetHostNetwork;
    546458        /* Get the tree-widget header-view: */
    547         QHeaderView *pItemHeader = m_pTreeWidget->header();
     459        QHeaderView *pItemHeader = m_pTreeWidgetHostNetwork->header();
    548460
    549461        /* Calculate the total tree-widget width: */
    550         const int iTotal = m_pTreeWidget->viewport()->width();
     462        const int iTotal = m_pTreeWidgetHostNetwork->viewport()->width();
    551463        /* Look for a minimum width hints for non-important columns: */
    552464        const int iMinWidth1 = qMax(pItemView->sizeHintForColumn(Column_IPv4), pItemHeader->sectionSizeHint(Column_IPv4));
     
    558470        const int iWidth3 = iMinWidth3 < iTotal / Column_Max ? iMinWidth3 : iTotal / Column_Max;
    559471        /* Apply the proposal: */
    560         m_pTreeWidget->setColumnWidth(Column_IPv4, iWidth1);
    561         m_pTreeWidget->setColumnWidth(Column_IPv6, iWidth2);
    562         m_pTreeWidget->setColumnWidth(Column_DHCP, iWidth3);
    563         m_pTreeWidget->setColumnWidth(Column_Name, iTotal - iWidth1 - iWidth2 - iWidth3);
    564     }
    565 }
    566 
    567 void UINetworkManagerWidget::sltHandleItemChange(QTreeWidgetItem *pItem)
     472        m_pTreeWidgetHostNetwork->setColumnWidth(Column_IPv4, iWidth1);
     473        m_pTreeWidgetHostNetwork->setColumnWidth(Column_IPv6, iWidth2);
     474        m_pTreeWidgetHostNetwork->setColumnWidth(Column_DHCP, iWidth3);
     475        m_pTreeWidgetHostNetwork->setColumnWidth(Column_Name, iTotal - iWidth1 - iWidth2 - iWidth3);
     476    }
     477}
     478
     479void UINetworkManagerWidget::sltHandleItemChangeHostNetwork(QTreeWidgetItem *pItem)
    568480{
    569481    /* Get network item: */
     
    639551
    640552                    /* Make sure current item fetched: */
    641                     sltHandleCurrentItemChange();
    642 
    643                     /* Adjust tree-widget: */
    644                     sltAdjustTreeWidget();
     553                    sltHandleCurrentItemChangeHostNetwork();
     554
     555                    /* Adjust tree-widgets: */
     556                    sltAdjustTreeWidgets();
    645557                }
    646558            }
     
    649561}
    650562
    651 void UINetworkManagerWidget::sltHandleCurrentItemChange()
    652 {
    653     /* Check tree-widget: */
    654     AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n"));
     563void UINetworkManagerWidget::sltHandleCurrentItemChangeHostNetwork()
     564{
     565    /* Check host network tree-widget: */
     566    AssertMsgReturnVoid(m_pTreeWidgetHostNetwork, ("Host network tree-widget isn't created!\n"));
    655567
    656568    /* Get network item: */
    657     UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
     569    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidgetHostNetwork->currentItem());
    658570
    659571    /* Update actions availability: */
     
    661573    m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->setEnabled(pItem);
    662574
    663     /* Check details-widget: */
    664     AssertMsgReturnVoid(m_pDetailsWidget, ("Details-widget isn't created!\n"));
     575    /* Check host network details-widget: */
     576    AssertMsgReturnVoid(m_pDetailsWidgetHostNetwork, ("Host network details-widget isn't created!\n"));
    665577
    666578    /* If there is an item => update details data: */
    667579    if (pItem)
    668         m_pDetailsWidget->setData(*pItem);
     580        m_pDetailsWidgetHostNetwork->setData(*pItem);
    669581    else
    670582    {
    671583        /* Otherwise => clear details and close the area: */
    672         m_pDetailsWidget->setData(UIDataHostNetwork());
    673         sltToggleHostNetworkDetailsVisibility(false);
    674     }
    675 }
    676 
    677 void UINetworkManagerWidget::sltHandleContextMenuRequest(const QPoint &position)
    678 {
    679     /* Check tree-widget: */
    680     AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n"));
     584        m_pDetailsWidgetHostNetwork->setData(UIDataHostNetwork());
     585        sltToggleDetailsVisibilityHostNetwork(false);
     586    }
     587}
     588
     589void UINetworkManagerWidget::sltHandleContextMenuRequestHostNetwork(const QPoint &position)
     590{
     591    /* Check host network tree-widget: */
     592    AssertMsgReturnVoid(m_pTreeWidgetHostNetwork, ("Host network tree-widget isn't created!\n"));
    681593
    682594    /* Compose temporary context-menu: */
    683595    QMenu menu;
    684     if (m_pTreeWidget->itemAt(position))
     596    if (m_pTreeWidgetHostNetwork->itemAt(position))
    685597    {
    686598        menu.addAction(m_pActionPool->action(UIActionIndexMN_M_Network_S_Remove));
     
    693605    }
    694606    /* And show it: */
    695     menu.exec(m_pTreeWidget->mapToGlobal(position));
     607    menu.exec(m_pTreeWidgetHostNetwork->mapToGlobal(position));
     608}
     609
     610void UINetworkManagerWidget::sltApplyDetailsChangesHostNetwork()
     611{
     612    /* Check host network tree-widget: */
     613    AssertMsgReturnVoid(m_pTreeWidgetHostNetwork, ("Host network tree-widget isn't created!\n"));
     614
     615    /* Get host network item: */
     616    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidgetHostNetwork->currentItem());
     617    AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
     618
     619    /* Check host network details-widget: */
     620    AssertMsgReturnVoid(m_pDetailsWidgetHostNetwork, ("Host network details-widget isn't created!\n"));
     621
     622    /* Get item data: */
     623    UIDataHostNetwork oldData = *pItem;
     624    UIDataHostNetwork newData = m_pDetailsWidgetHostNetwork->data();
     625
     626    /* Get host for further activities: */
     627    CHost comHost = uiCommon().host();
     628
     629    /* Find corresponding interface: */
     630    CHostNetworkInterface comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName);
     631
     632    /* Show error message if necessary: */
     633    if (!comHost.isOk() || comInterface.isNull())
     634        msgCenter().cannotFindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this);
     635    else
     636    {
     637        /* Save automatic interface configuration: */
     638        if (newData.m_interface.m_fDHCPEnabled)
     639        {
     640            if (   comInterface.isOk()
     641                && !oldData.m_interface.m_fDHCPEnabled)
     642                comInterface.EnableDynamicIPConfig();
     643        }
     644        /* Save manual interface configuration: */
     645        else
     646        {
     647            /* Save IPv4 interface configuration: */
     648            if (   comInterface.isOk()
     649                && (   oldData.m_interface.m_fDHCPEnabled
     650                    || newData.m_interface.m_strAddress != oldData.m_interface.m_strAddress
     651                    || newData.m_interface.m_strMask != oldData.m_interface.m_strMask))
     652                comInterface.EnableStaticIPConfig(newData.m_interface.m_strAddress, newData.m_interface.m_strMask);
     653            /* Save IPv6 interface configuration: */
     654            if (   comInterface.isOk()
     655                && newData.m_interface.m_fSupportedIPv6
     656                && (   oldData.m_interface.m_fDHCPEnabled
     657                    || newData.m_interface.m_strAddress6 != oldData.m_interface.m_strAddress6
     658                    || newData.m_interface.m_strPrefixLength6 != oldData.m_interface.m_strPrefixLength6))
     659                comInterface.EnableStaticIPConfigV6(newData.m_interface.m_strAddress6, newData.m_interface.m_strPrefixLength6.toULong());
     660        }
     661
     662        /* Show error message if necessary: */
     663        if (!comInterface.isOk())
     664            msgCenter().cannotSaveHostNetworkInterfaceParameter(comInterface, this);
     665        else
     666        {
     667            /* Get network name for further activities: */
     668            const QString strNetworkName = comInterface.GetNetworkName();
     669
     670            /* Show error message if necessary: */
     671            if (!comInterface.isOk())
     672                msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);
     673            else
     674            {
     675                /* Get VBox for further activities: */
     676                CVirtualBox comVBox = uiCommon().virtualBox();
     677
     678                /* Find corresponding DHCP server (create if necessary): */
     679                CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);
     680                if (!comVBox.isOk() || comServer.isNull())
     681                    comServer = comVBox.CreateDHCPServer(strNetworkName);
     682
     683                /* Show error message if necessary: */
     684                if (!comVBox.isOk() || comServer.isNull())
     685                    msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this);
     686                else
     687                {
     688                    /* Save whether DHCP server is enabled: */
     689                    if (   comServer.isOk()
     690                        && newData.m_dhcpserver.m_fEnabled != oldData.m_dhcpserver.m_fEnabled)
     691                        comServer.SetEnabled(newData.m_dhcpserver.m_fEnabled);
     692                    /* Save DHCP server configuration: */
     693                    if (   comServer.isOk()
     694                        && newData.m_dhcpserver.m_fEnabled
     695                        && (   newData.m_dhcpserver.m_strAddress != oldData.m_dhcpserver.m_strAddress
     696                            || newData.m_dhcpserver.m_strMask != oldData.m_dhcpserver.m_strMask
     697                            || newData.m_dhcpserver.m_strLowerAddress != oldData.m_dhcpserver.m_strLowerAddress
     698                            || newData.m_dhcpserver.m_strUpperAddress != oldData.m_dhcpserver.m_strUpperAddress))
     699                        comServer.SetConfiguration(newData.m_dhcpserver.m_strAddress, newData.m_dhcpserver.m_strMask,
     700                                                   newData.m_dhcpserver.m_strLowerAddress, newData.m_dhcpserver.m_strUpperAddress);
     701
     702                    /* Show error message if necessary: */
     703                    if (!comServer.isOk())
     704                        msgCenter().cannotSaveDHCPServerParameter(comServer, this);
     705                }
     706            }
     707        }
     708
     709        /* Find corresponding interface again (if necessary): */
     710        if (!comInterface.isOk())
     711        {
     712            comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName);
     713
     714            /* Show error message if necessary: */
     715            if (!comHost.isOk() || comInterface.isNull())
     716                msgCenter().cannotFindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this);
     717        }
     718
     719        /* If interface is Ok now: */
     720        if (comInterface.isNotNull() && comInterface.isOk())
     721        {
     722            /* Update interface in the tree: */
     723            UIDataHostNetwork data;
     724            loadHostNetwork(comInterface, data);
     725            updateItemForNetworkHost(data, true, pItem);
     726
     727            /* Make sure current item fetched: */
     728            sltHandleCurrentItemChangeHostNetwork();
     729
     730            /* Adjust tree-widgets: */
     731            sltAdjustTreeWidgets();
     732        }
     733    }
    696734}
    697735
     
    711749    retranslateUi();
    712750
    713     /* Load host networks: */
     751    /* Load networks: */
    714752    loadHostNetworks();
    715753}
     
    729767            this, &UINetworkManagerWidget::sltRemoveHostNetwork);
    730768    connect(m_pActionPool->action(UIActionIndexMN_M_Network_T_Details), &QAction::toggled,
    731             this, &UINetworkManagerWidget::sltToggleHostNetworkDetailsVisibility);
     769            this, &UINetworkManagerWidget::sltToggleDetailsVisibilityHostNetwork);
    732770    connect(m_pActionPool->action(UIActionIndexMN_M_Network_S_Refresh), &QAction::triggered,
    733771            this, &UINetworkManagerWidget::sltRefreshHostNetworks);
     
    751789        if (m_fShowToolbar)
    752790            prepareToolBar();
    753         /* Prepare tree-widget: */
    754         prepareTreeWidget();
    755         /* Prepare details-widget: */
    756         prepareDetailsWidget();
     791        /* Prepare tab-widget: */
     792        prepareTabWidget();
    757793    }
    758794}
     
    791827}
    792828
    793 void UINetworkManagerWidget::prepareTreeWidget()
    794 {
    795     /* Prepare tree-widget: */
    796     m_pTreeWidget = new QITreeWidget(this);
    797     if (m_pTreeWidget)
    798     {
    799         m_pTreeWidget->setRootIsDecorated(false);
    800         m_pTreeWidget->setAlternatingRowColors(true);
    801         m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
    802         m_pTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    803         m_pTreeWidget->setColumnCount(Column_Max);
    804         m_pTreeWidget->setSortingEnabled(true);
    805         m_pTreeWidget->sortByColumn(Column_Name, Qt::AscendingOrder);
    806         m_pTreeWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
    807         connect(m_pTreeWidget, &QITreeWidget::currentItemChanged,
    808                 this, &UINetworkManagerWidget::sltHandleCurrentItemChange);
    809         connect(m_pTreeWidget, &QITreeWidget::customContextMenuRequested,
    810                 this, &UINetworkManagerWidget::sltHandleContextMenuRequest);
    811         connect(m_pTreeWidget, &QITreeWidget::itemChanged,
    812                 this, &UINetworkManagerWidget::sltHandleItemChange);
    813         connect(m_pTreeWidget, &QITreeWidget::itemDoubleClicked,
     829void UINetworkManagerWidget::prepareTabWidget()
     830{
     831    /* Create tab-widget: */
     832    m_pTabWidget = new QITabWidget(this);
     833    if (m_pTabWidget)
     834    {
     835        prepareTabHostNetwork();
     836
     837        /* Add into layout: */
     838        layout()->addWidget(m_pTabWidget);
     839    }
     840}
     841
     842void UINetworkManagerWidget::prepareTabHostNetwork()
     843{
     844    /* Prepare host network tab: */
     845    m_pTabHostNetwork = new QWidget(m_pTabWidget);
     846    if (m_pTabHostNetwork)
     847    {
     848        /* Prepare host network layout: */
     849        m_pLayoutHostNetwork = new QVBoxLayout(m_pTabHostNetwork);
     850        if (m_pLayoutHostNetwork)
     851        {
     852            prepareTreeWidgetHostNetwork();
     853            prepareDetailsWidgetHostNetwork();
     854        }
     855
     856        /* Add into tab-widget: */
     857        m_pTabWidget->addTab(m_pTabHostNetwork, QString());
     858    }
     859}
     860
     861void UINetworkManagerWidget::prepareTreeWidgetHostNetwork()
     862{
     863    /* Prepare host network tree-widget: */
     864    m_pTreeWidgetHostNetwork = new QITreeWidget(m_pTabHostNetwork);
     865    if (m_pTreeWidgetHostNetwork)
     866    {
     867        m_pTreeWidgetHostNetwork->setRootIsDecorated(false);
     868        m_pTreeWidgetHostNetwork->setAlternatingRowColors(true);
     869        m_pTreeWidgetHostNetwork->setContextMenuPolicy(Qt::CustomContextMenu);
     870        m_pTreeWidgetHostNetwork->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     871        m_pTreeWidgetHostNetwork->setColumnCount(Column_Max);
     872        m_pTreeWidgetHostNetwork->setSortingEnabled(true);
     873        m_pTreeWidgetHostNetwork->sortByColumn(Column_Name, Qt::AscendingOrder);
     874        m_pTreeWidgetHostNetwork->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
     875        connect(m_pTreeWidgetHostNetwork, &QITreeWidget::currentItemChanged,
     876                this, &UINetworkManagerWidget::sltHandleCurrentItemChangeHostNetwork);
     877        connect(m_pTreeWidgetHostNetwork, &QITreeWidget::customContextMenuRequested,
     878                this, &UINetworkManagerWidget::sltHandleContextMenuRequestHostNetwork);
     879        connect(m_pTreeWidgetHostNetwork, &QITreeWidget::itemChanged,
     880                this, &UINetworkManagerWidget::sltHandleItemChangeHostNetwork);
     881        connect(m_pTreeWidgetHostNetwork, &QITreeWidget::itemDoubleClicked,
    814882                m_pActionPool->action(UIActionIndexMN_M_Network_T_Details), &QAction::setChecked);
    815883
    816884        /* Add into layout: */
    817         layout()->addWidget(m_pTreeWidget);
    818     }
    819 }
    820 
    821 void UINetworkManagerWidget::prepareDetailsWidget()
    822 {
    823     /* Prepare details-widget: */
    824     m_pDetailsWidget = new UINetworkDetailsWidget(m_enmEmbedding, this);
    825     if (m_pDetailsWidget)
    826     {
    827         m_pDetailsWidget->setVisible(false);
    828         m_pDetailsWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    829         connect(m_pDetailsWidget, &UINetworkDetailsWidget::sigDataChanged,
    830                 this, &UINetworkManagerWidget::sigHostNetworkDetailsDataChanged);
    831         connect(m_pDetailsWidget, &UINetworkDetailsWidget::sigDataChangeRejected,
    832                 this, &UINetworkManagerWidget::sltResetHostNetworkDetailsChanges);
    833         connect(m_pDetailsWidget, &UINetworkDetailsWidget::sigDataChangeAccepted,
    834                 this, &UINetworkManagerWidget::sltApplyHostNetworkDetailsChanges);
     885        m_pLayoutHostNetwork->addWidget(m_pTreeWidgetHostNetwork);
     886    }
     887}
     888
     889void UINetworkManagerWidget::prepareDetailsWidgetHostNetwork()
     890{
     891    /* Prepare host network details-widget: */
     892    m_pDetailsWidgetHostNetwork = new UINetworkDetailsWidget(m_enmEmbedding, m_pTabHostNetwork);
     893    if (m_pDetailsWidgetHostNetwork)
     894    {
     895        m_pDetailsWidgetHostNetwork->setVisible(false);
     896        m_pDetailsWidgetHostNetwork->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     897        connect(m_pDetailsWidgetHostNetwork, &UINetworkDetailsWidget::sigDataChanged,
     898                this, &UINetworkManagerWidget::sigDetailsDataChangedHostNetwork);
     899        connect(m_pDetailsWidgetHostNetwork, &UINetworkDetailsWidget::sigDataChangeRejected,
     900                this, &UINetworkManagerWidget::sltHandleCurrentItemChangeHostNetwork);
     901        connect(m_pDetailsWidgetHostNetwork, &UINetworkDetailsWidget::sigDataChangeAccepted,
     902                this, &UINetworkManagerWidget::sltApplyDetailsChangesHostNetwork);
    835903
    836904        /* Add into layout: */
    837         layout()->addWidget(m_pDetailsWidget);
     905        m_pLayoutHostNetwork->addWidget(m_pDetailsWidgetHostNetwork);
    838906    }
    839907}
     
    845913    {
    846914        m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->setChecked(gEDataManager->hostNetworkManagerDetailsExpanded());
    847         sltToggleHostNetworkDetailsVisibility(m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->isChecked());
     915        sltToggleDetailsVisibilityHostNetwork(m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->isChecked());
    848916    }
    849917}
     
    851919void UINetworkManagerWidget::loadHostNetworks()
    852920{
    853     /* Check tree-widget: */
    854     if (!m_pTreeWidget)
     921    /* Check host network tree-widget: */
     922    if (!m_pTreeWidgetHostNetwork)
    855923        return;
    856924
    857925    /* Clear tree first of all: */
    858     m_pTreeWidget->clear();
     926    m_pTreeWidgetHostNetwork->clear();
    859927
    860928    /* Get host for further activities: */
     
    879947
    880948        /* Choose the 1st item as current initially: */
    881         m_pTreeWidget->setCurrentItem(m_pTreeWidget->topLevelItem(0));
    882         sltHandleCurrentItemChange();
    883 
    884         /* Adjust tree-widget: */
    885         sltAdjustTreeWidget();
     949        m_pTreeWidgetHostNetwork->setCurrentItem(m_pTreeWidgetHostNetwork->topLevelItem(0));
     950        sltHandleCurrentItemChangeHostNetwork();
     951
     952        /* Adjust tree-widgets: */
     953        sltAdjustTreeWidgets();
    886954    }
    887955}
     
    9551023        pItem->updateFields();
    9561024        /* Add item to the tree: */
    957         m_pTreeWidget->addTopLevelItem(pItem);
     1025        m_pTreeWidgetHostNetwork->addTopLevelItem(pItem);
    9581026        /* And choose it as current if necessary: */
    9591027        if (fChooseItem)
    960             m_pTreeWidget->setCurrentItem(pItem);
     1028            m_pTreeWidgetHostNetwork->setCurrentItem(pItem);
    9611029    }
    9621030}
     
    9721040        /* And choose it as current if necessary: */
    9731041        if (fChooseItem)
    974             m_pTreeWidget->setCurrentItem(pItem);
     1042            m_pTreeWidgetHostNetwork->setCurrentItem(pItem);
    9751043    }
    9761044}
     
    10191087{
    10201088    /* Translate window title: */
    1021     setWindowTitle(tr("Host Network Manager"));
     1089    setWindowTitle(tr("Network Manager"));
    10221090
    10231091    /* Translate buttons: */
     
    10261094    button(ButtonType_Close)->setText(tr("Close"));
    10271095    button(ButtonType_Help)->setText(tr("Help"));
    1028     button(ButtonType_Reset)->setStatusTip(tr("Reset changes in current host network details"));
    1029     button(ButtonType_Apply)->setStatusTip(tr("Apply changes in current host network details"));
     1096    button(ButtonType_Reset)->setStatusTip(tr("Reset changes in current network details"));
     1097    button(ButtonType_Apply)->setStatusTip(tr("Apply changes in current network details"));
    10301098    button(ButtonType_Close)->setStatusTip(tr("Close dialog without saving"));
    10311099    button(ButtonType_Help)->setStatusTip(tr("Show dialog help"));
     
    10581126#endif
    10591127        connect(this, &UINetworkManager::sigDataChangeRejected,
    1060                 pWidget, &UINetworkManagerWidget::sltResetHostNetworkDetailsChanges);
     1128                pWidget, &UINetworkManagerWidget::sltResetDetailsChanges);
    10611129        connect(this, &UINetworkManager::sigDataChangeAccepted,
    1062                 pWidget, &UINetworkManagerWidget::sltApplyHostNetworkDetailsChanges);
     1130                pWidget, &UINetworkManagerWidget::sltApplyDetailsChanges);
    10631131
    10641132        /* Add into layout: */
     
    10701138{
    10711139    /* Configure button-box: */
    1072     connect(widget(), &UINetworkManagerWidget::sigHostNetworkDetailsVisibilityChanged,
     1140    connect(widget(), &UINetworkManagerWidget::sigDetailsVisibilityChangedHostNetwork,
    10731141            button(ButtonType_Apply), &QPushButton::setVisible);
    1074     connect(widget(), &UINetworkManagerWidget::sigHostNetworkDetailsVisibilityChanged,
     1142    connect(widget(), &UINetworkManagerWidget::sigDetailsVisibilityChangedHostNetwork,
    10751143            button(ButtonType_Reset), &QPushButton::setVisible);
    1076     connect(widget(), &UINetworkManagerWidget::sigHostNetworkDetailsDataChanged,
     1144    connect(widget(), &UINetworkManagerWidget::sigDetailsDataChangedHostNetwork,
    10771145            button(ButtonType_Apply), &QPushButton::setEnabled);
    1078     connect(widget(), &UINetworkManagerWidget::sigHostNetworkDetailsDataChanged,
     1146    connect(widget(), &UINetworkManagerWidget::sigDetailsDataChangedHostNetwork,
    10791147            button(ButtonType_Reset), &QPushButton::setEnabled);
    10801148    connect(buttonBox(), &QIDialogButtonBox::clicked,
  • trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UINetworkManager.h

    r87088 r87089  
    3333class QAbstractButton;
    3434class QTreeWidgetItem;
     35class QVBoxLayout;
    3536class QIDialogButtonBox;
     37class QITabWidget;
    3638class QITreeWidget;
    3739class UIActionPool;
     
    4244
    4345
    44 /** QWidget extension providing GUI with the pane to control host network related functionality. */
     46/** QWidget extension providing GUI with the pane to control network related functionality. */
    4547class UINetworkManagerWidget : public QIWithRetranslateUI<QWidget>
    4648{
     
    4951signals:
    5052
    51     /** Notifies listeners about host network details-widget @a fVisible. */
    52     void sigHostNetworkDetailsVisibilityChanged(bool fVisible);
    53     /** Notifies listeners about host network details data @a fDiffers. */
    54     void sigHostNetworkDetailsDataChanged(bool fDiffers);
     53    /** Notifies listeners about network details-widget @a fVisible. */
     54    void sigDetailsVisibilityChangedHostNetwork(bool fVisible);
     55    /** Notifies listeners about network details data @a fDiffers. */
     56    void sigDetailsDataChangedHostNetwork(bool fDiffers);
    5557
    5658public:
    5759
    58     /** Constructs Host Network Manager widget.
     60    /** Constructs Network Manager widget.
    5961      * @param  enmEmbedding  Brings the type of widget embedding.
    6062      * @param  pActionPool   Brings the action-pool reference.
     
    8991    /** @name Details-widget stuff.
    9092      * @{ */
    91         /** Handles command to reset host network details changes. */
    92         void sltResetHostNetworkDetailsChanges();
    93         /** Handles command to apply host network details changes. */
    94         void sltApplyHostNetworkDetailsChanges();
     93        /** Handles command to reset details changes. */
     94        void sltResetDetailsChanges();
     95        /** Handles command to apply details changes. */
     96        void sltApplyDetailsChanges();
    9597    /** @} */
    9698
     
    104106        void sltRemoveHostNetwork();
    105107        /** Handles command to make host network details @a fVisible. */
    106         void sltToggleHostNetworkDetailsVisibility(bool fVisible);
     108        void sltToggleDetailsVisibilityHostNetwork(bool fVisible);
    107109        /** Handles command to refresh host networks. */
    108110        void sltRefreshHostNetworks();
     
    112114      * @{ */
    113115        /** Handles command to adjust tree-widget. */
    114         void sltAdjustTreeWidget();
    115 
    116         /** Handles tree-widget @a pItem change. */
    117         void sltHandleItemChange(QTreeWidgetItem *pItem);
    118         /** Handles tree-widget current item change. */
    119         void sltHandleCurrentItemChange();
    120         /** Handles context menu request for tree-widget @a position. */
    121         void sltHandleContextMenuRequest(const QPoint &position);
     116        void sltAdjustTreeWidgets();
     117
     118        /** Handles host network tree-widget @a pItem change. */
     119        void sltHandleItemChangeHostNetwork(QTreeWidgetItem *pItem);
     120        /** Handles host network tree-widget current item change. */
     121        void sltHandleCurrentItemChangeHostNetwork();
     122        /** Handles host network context-menu request for tree-widget @a position. */
     123        void sltHandleContextMenuRequestHostNetwork(const QPoint &position);
     124
     125        /** Handles command to apply host network details changes. */
     126        void sltApplyDetailsChangesHostNetwork();
    122127    /** @} */
    123128
     
    134139        /** Prepares toolbar. */
    135140        void prepareToolBar();
    136         /** Prepares tree-widget. */
    137         void prepareTreeWidget();
    138         /** Prepares details-widget. */
    139         void prepareDetailsWidget();
     141        /** Prepares tab-widget. */
     142        void prepareTabWidget();
     143        /** Prepares host network tab. */
     144        void prepareTabHostNetwork();
     145        /** Prepares host network tree-widget. */
     146        void prepareTreeWidgetHostNetwork();
     147        /** Prepares host network details-widget. */
     148        void prepareDetailsWidgetHostNetwork();
    140149        /** Load settings: */
    141150        void loadSettings();
     
    176185    /** @name Splitter variables.
    177186      * @{ */
    178         /** Holds the tree-widget instance. */
    179         QITreeWidget           *m_pTreeWidget;
    180         /** Holds the details-widget instance. */
    181         UINetworkDetailsWidget *m_pDetailsWidget;
     187        /** Holds the tab-widget instance. */
     188        QITabWidget            *m_pTabWidget;
     189
     190        /** Holds the host network tab. */
     191        QWidget                *m_pTabHostNetwork;
     192        /** Holds the host network layout. */
     193        QVBoxLayout            *m_pLayoutHostNetwork;
     194        /** Holds the host network tree-widget instance. */
     195        QITreeWidget           *m_pTreeWidgetHostNetwork;
     196        /** Holds the host network details-widget instance. */
     197        UINetworkDetailsWidget *m_pDetailsWidgetHostNetwork;
    182198    /** @} */
    183199};
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