VirtualBox

Ignore:
Timestamp:
Jun 23, 2017 9:23:41 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
116329
Message:

FE/Qt: bugref:8847: Host Network Manager: Replace 'Apply' action with 'Apply' button in proper place; add 'Reset' button as well.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork
Files:
4 edited

Legend:

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

    r67452 r67575  
    2323# include <QCheckBox>
    2424# include <QLabel>
     25# include <QPushButton>
    2526# include <QRadioButton>
    2627# include <QRegExpValidator>
     
    2930
    3031/* GUI includes: */
     32# include "QIDialogButtonBox.h"
    3133# include "QILineEdit.h"
    3234# include "QITabWidget.h"
     
    4244
    4345
    44 UIHostNetworkDetailsDialog::UIHostNetworkDetailsDialog(QWidget *pParent /* = 0 */)
     46UIHostNetworkDetailsDialog::UIHostNetworkDetailsDialog(EmbedTo enmEmbedding, QWidget *pParent /* = 0 */)
    4547    : QIWithRetranslateUI2<QWidget>(pParent)
     48    , m_enmEmbedding(enmEmbedding)
    4649    , m_pTabWidget(0)
    4750    , m_pButtonAutomatic(0), m_pErrorPaneAutomatic(0)
     
    5154    , m_pLabelIPv6(0), m_pEditorIPv6(0), m_pErrorPaneIPv6(0)
    5255    , m_pLabelNMv6(0), m_pEditorNMv6(0), m_pErrorPaneNMv6(0)
     56    , m_pButtonBoxInterface(0)
    5357    , m_pCheckBoxDHCP(0)
    5458    , m_pLabelDHCPAddress(0), m_pEditorDHCPAddress(0), m_pErrorPaneDHCPAddress(0)
     
    5660    , m_pLabelDHCPLowerAddress(0), m_pEditorDHCPLowerAddress(0), m_pErrorPaneDHCPLowerAddress(0)
    5761    , m_pLabelDHCPUpperAddress(0), m_pEditorDHCPUpperAddress(0), m_pErrorPaneDHCPUpperAddress(0)
     62    , m_pButtonBoxServer(0)
    5863{
    5964    /* Prepare: */
     
    102107    m_pLabelNMv6->setText(tr("IPv6 Prefix &Length:"));
    103108    m_pEditorNMv6->setToolTip(tr("Holds the host IPv6 prefix length for this adapter if IPv6 is supported."));
     109    if (m_pButtonBoxInterface)
     110    {
     111        m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setText(tr("Reset"));
     112        m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setText(tr("Apply"));
     113        m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setShortcut(Qt::Key_Escape);
     114        m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setShortcut(QString("Ctrl+Return"));
     115        m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setStatusTip(tr("Reset changes in current interface details"));
     116        m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setStatusTip(tr("Apply changes in current interface details"));
     117        m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->
     118            setToolTip(tr("Reset Changes (%1)").arg(m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->shortcut().toString()));
     119        m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->
     120            setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->shortcut().toString()));
     121    }
    104122
    105123    /* Translate 'DHCP server' tab content: */
     
    114132    m_pLabelDHCPUpperAddress->setText(tr("&Upper Address Bound:"));
    115133    m_pEditorDHCPUpperAddress->setToolTip(tr("Holds the upper address bound offered by the DHCP server servicing the network associated with this host-only adapter."));
     134    if (m_pButtonBoxServer)
     135    {
     136        m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setText(tr("Reset"));
     137        m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setText(tr("Apply"));
     138        m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setShortcut(Qt::Key_Escape);
     139        m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setShortcut(QString("Ctrl+Return"));
     140        m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setStatusTip(tr("Reset changes in current DHCP server details"));
     141        m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setStatusTip(tr("Apply changes in current DHCP server details"));
     142        m_pButtonBoxServer->button(QDialogButtonBox::Discard)->
     143            setToolTip(tr("Reset Changes (%1)").arg(m_pButtonBoxServer->button(QDialogButtonBox::Discard)->shortcut().toString()));
     144        m_pButtonBoxServer->button(QDialogButtonBox::Apply)->
     145            setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBoxServer->button(QDialogButtonBox::Apply)->shortcut().toString()));
     146    }
    116147
    117148    /* Retranslate validation: */
     
    124155    loadDataForInterface();
    125156    revalidate();
    126     notify();
     157    updateButtonStates();
    127158}
    128159
     
    132163    loadDataForInterface();
    133164    revalidate();
    134     notify();
     165    updateButtonStates();
    135166}
    136167
     
    139170    m_newData.m_interface.m_strAddress = strText;
    140171    revalidate(m_pErrorPaneIPv4);
    141     notify();
     172    updateButtonStates();
    142173}
    143174
     
    146177    m_newData.m_interface.m_strMask = strText;
    147178    revalidate(m_pErrorPaneNMv4);
    148     notify();
     179    updateButtonStates();
    149180}
    150181
     
    153184    m_newData.m_interface.m_strAddress6 = strText;
    154185    revalidate(m_pErrorPaneIPv6);
    155     notify();
     186    updateButtonStates();
    156187}
    157188
     
    160191    m_newData.m_interface.m_strPrefixLength6 = strText;
    161192    revalidate(m_pErrorPaneNMv6);
    162     notify();
     193    updateButtonStates();
    163194}
    164195
     
    168199    loadDataForDHCPServer();
    169200    revalidate();
    170     notify();
     201    updateButtonStates();
    171202}
    172203
     
    175206    m_newData.m_dhcpserver.m_strAddress = strText;
    176207    revalidate(m_pErrorPaneDHCPAddress);
    177     notify();
     208    updateButtonStates();
    178209}
    179210
     
    182213    m_newData.m_dhcpserver.m_strMask = strText;
    183214    revalidate(m_pErrorPaneDHCPMask);
    184     notify();
     215    updateButtonStates();
    185216}
    186217
     
    189220    m_newData.m_dhcpserver.m_strLowerAddress = strText;
    190221    revalidate(m_pErrorPaneDHCPLowerAddress);
    191     notify();
     222    updateButtonStates();
    192223}
    193224
     
    196227    m_newData.m_dhcpserver.m_strUpperAddress = strText;
    197228    revalidate(m_pErrorPaneDHCPUpperAddress);
    198     notify();
     229    updateButtonStates();
     230}
     231
     232void UIHostNetworkDetailsDialog::sltHandleButtonBoxClick(QAbstractButton *pButton)
     233{
     234    /* Disable buttons first of all: */
     235    if (m_pButtonBoxInterface)
     236    {
     237        m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setEnabled(false);
     238        m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setEnabled(false);
     239    }
     240    if (m_pButtonBoxServer)
     241    {
     242        m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setEnabled(false);
     243        m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setEnabled(false);
     244    }
     245
     246    /* Compare with known buttons: */
     247    if (   (   m_pButtonBoxInterface
     248            && pButton == m_pButtonBoxInterface->button(QDialogButtonBox::Discard))
     249        || (   m_pButtonBoxServer
     250            && pButton == m_pButtonBoxServer->button(QDialogButtonBox::Discard)))
     251        emit sigDataChangeRejected();
     252
     253    else
     254
     255    if (   (   m_pButtonBoxInterface
     256            && pButton == m_pButtonBoxInterface->button(QDialogButtonBox::Apply))
     257        || (   m_pButtonBoxServer
     258            && pButton == m_pButtonBoxServer->button(QDialogButtonBox::Apply)))
     259        emit sigDataChangeAccepted();
    199260}
    200261
     
    206267    /* Apply language settings: */
    207268    retranslateUi();
     269
     270    /* Update button states finally: */
     271    updateButtonStates();
    208272}
    209273
     
    508572                pLayoutInterface->addItem(pSpacer2, 6, 0, 1, 3);
    509573            }
     574
     575            /* If parent embedded into stack: */
     576            if (m_enmEmbedding == EmbedTo_Stack)
     577            {
     578                /* Create button-box: */
     579                m_pButtonBoxInterface = new QIDialogButtonBox;
     580                AssertPtrReturnVoid(m_pButtonBoxInterface);
     581                /* Configure button-box: */
     582                m_pButtonBoxInterface->setStandardButtons(QDialogButtonBox::Discard | QDialogButtonBox::Apply);
     583                connect(m_pButtonBoxInterface, &QIDialogButtonBox::clicked, this, &UIHostNetworkDetailsDialog::sltHandleButtonBoxClick);
     584
     585                /* Add into layout: */
     586                pLayoutInterface->addWidget(m_pButtonBoxInterface, 7, 0, 1, 3);
     587            }
    510588        }
    511589        /* Add to tab-widget: */
     
    728806                /* Add into layout: */
    729807                pLayoutDHCPServer->addItem(pSpacer2, 5, 0, 1, 3);
     808            }
     809
     810            /* If parent embedded into stack: */
     811            if (m_enmEmbedding == EmbedTo_Stack)
     812            {
     813                /* Create button-box: */
     814                m_pButtonBoxServer = new QIDialogButtonBox;
     815                AssertPtrReturnVoid(m_pButtonBoxServer);
     816                /* Configure button-box: */
     817                m_pButtonBoxServer->setStandardButtons(QDialogButtonBox::Discard | QDialogButtonBox::Apply);
     818                connect(m_pButtonBoxServer, &QIDialogButtonBox::clicked, this, &UIHostNetworkDetailsDialog::sltHandleButtonBoxClick);
     819
     820                /* Add into layout: */
     821                pLayoutDHCPServer->addWidget(m_pButtonBoxServer, 6, 0, 1, 3);
    730822            }
    731823        }
     
    9221014}
    9231015
    924 void UIHostNetworkDetailsDialog::notify()
     1016void UIHostNetworkDetailsDialog::updateButtonStates()
    9251017{
    9261018//    if (m_oldData != m_newData)
     
    9361028//               m_newData.m_dhcpserver.m_strUpperAddress.toUtf8().constData());
    9371029
     1030    /* Update 'Apply' / 'Reset' button states: */
     1031    if (m_pButtonBoxInterface)
     1032    {
     1033        m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setEnabled(m_oldData != m_newData);
     1034        m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setEnabled(m_oldData != m_newData);
     1035    }
     1036    if (m_pButtonBoxServer)
     1037    {
     1038        m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setEnabled(m_oldData != m_newData);
     1039        m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setEnabled(m_oldData != m_newData);
     1040    }
     1041
     1042    /* Notify listeners as well: */
    9381043    emit sigDataChanged(m_oldData != m_newData);
    9391044}
  • trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkDetailsDialog.h

    r67452 r67575  
    2323
    2424/* GUI includes: */
     25#include "QIManagerDialog.h"
    2526#include "QIWithRetranslateUI.h"
    2627
    2728/* Forward declarations: */
     29class QAbstractButton;
    2830class QCheckBox;
    2931class QLabel;
    3032class QRadioButton;
     33class QIDialogButtonBox;
    3134class QILineEdit;
    3235class QITabWidget;
     
    165168    void sigDataChanged(bool fDiffers);
    166169
     170    /** Notifies listeners about data change rejected and should be reseted. */
     171    void sigDataChangeRejected();
     172    /** Notifies listeners about data change accepted and should be applied. */
     173    void sigDataChangeAccepted();
     174
    167175public:
    168176
    169177    /** Constructs host network details dialog for the passed @a pParent and @a data. */
    170     UIHostNetworkDetailsDialog(QWidget *pParent = 0);
     178    UIHostNetworkDetailsDialog(EmbedTo enmEmbedding, QWidget *pParent = 0);
    171179
    172180    /** Returns the host network data. */
     
    209217        /** Handles DHCP server upper address text change. */
    210218        void sltTextChangedUpperAddress(const QString &strText);
     219
     220        /** Handles button-box button click. */
     221        void sltHandleButtonBoxClick(QAbstractButton *pButton);
    211222    /** @} */
    212223
     
    241252        /** Retranslates validation for passed @a pWidget. */
    242253        void retranslateValidation(QWidget *pWidget = 0);
    243         /** Notifies listeners about data changed or not. */
    244         void notify();
     254        /** Updates button states. */
     255        void updateButtonStates();
    245256    /** @} */
    246257
    247258    /** @name General variables.
    248259      * @{ */
     260        /** Holds the parent widget embedding type. */
     261        const EmbedTo m_enmEmbedding;
     262
    249263        /** Holds the old data copy. */
    250264        UIDataHostNetwork  m_oldData;
     
    294308        /** Holds the IPv6 network mask error pane. */
    295309        QLabel       *m_pErrorPaneNMv6;
     310
     311        /** Holds the interface button-box instance. */
     312        QIDialogButtonBox *m_pButtonBoxInterface;
    296313    /** @} */
    297314
     
    328345        /** Holds the DHCP upper address error pane. */
    329346        QLabel     *m_pErrorPaneDHCPUpperAddress;
     347
     348        /** Holds the server button-box instance. */
     349        QIDialogButtonBox *m_pButtonBoxServer;
    330350    /** @} */
    331351};
  • trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.cpp

    r67573 r67575  
    198198    , m_pActionRemove(0)
    199199    , m_pActionDetails(0)
    200     , m_pActionCommit(0)
    201200    , m_pTreeWidget(0)
    202201    , m_pDetailsWidget(0)
     
    230229        m_pActionDetails->setToolTip(UIHostNetworkManager::tr("Open Host-only Network Details (%1)").arg(m_pActionDetails->shortcut().toString()));
    231230        m_pActionDetails->setStatusTip(UIHostNetworkManager::tr("Open pane with the selected host-only network details"));
    232     }
    233     if (m_pActionCommit)
    234     {
    235         m_pActionCommit->setText(UIHostNetworkManager::tr("&Apply..."));
    236         m_pActionCommit->setToolTip(UIHostNetworkManager::tr("Apply Changes in Host-only Network Details (%1)").arg(m_pActionCommit->shortcut().toString()));
    237         m_pActionCommit->setStatusTip(UIHostNetworkManager::tr("Apply changes in host-only network details pane"));
    238231    }
    239232
     
    276269}
    277270
    278 void UIHostNetworkManagerWidget::sltAddHostNetwork()
    279 {
    280     /* Get host for further activities: */
    281     CHost comHost = vboxGlobal().host();
    282 
    283     /* Create interface: */
    284     CHostNetworkInterface comInterface;
    285     CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface);
    286 
    287     /* Show error message if necessary: */
    288     if (!comHost.isOk() || progress.isNull())
    289         msgCenter().cannotCreateHostNetworkInterface(comHost, this);
    290     else
    291     {
    292         /* Show interface creation progress: */
    293         msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0);
    294 
    295         /* Show error message if necessary: */
    296         if (!progress.isOk() || progress.GetResultCode() != 0)
    297             msgCenter().cannotCreateHostNetworkInterface(progress, this);
    298         else
    299         {
    300             /* Get network name for further activities: */
    301             const QString strNetworkName = comInterface.GetNetworkName();
    302 
    303             /* Show error message if necessary: */
    304             if (!comInterface.isOk())
    305                 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);
    306             else
    307             {
    308                 /* Get VBox for further activities: */
    309                 CVirtualBox comVBox = vboxGlobal().virtualBox();
    310 
    311                 /* Find corresponding DHCP server (create if necessary): */
    312                 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);
    313                 if (!comVBox.isOk() || comServer.isNull())
    314                     comServer = comVBox.CreateDHCPServer(strNetworkName);
    315 
    316                 /* Show error message if necessary: */
    317                 if (!comVBox.isOk() || comServer.isNull())
    318                     msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this);
    319             }
    320 
    321             /* Add interface to the tree: */
    322             UIDataHostNetwork data;
    323             loadHostNetwork(comInterface, data);
    324             createItemForNetworkHost(data, true);
    325 
    326             /* Adjust tree-widget: */
    327             sltAdjustTreeWidget();
    328         }
    329     }
    330 }
    331 
    332 void UIHostNetworkManagerWidget::sltRemoveHostNetwork()
    333 {
    334     /* Get network item: */
    335     UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
    336     AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
    337 
    338     /* Get interface name: */
    339     const QString strInterfaceName(pItem->name());
    340 
    341     /* Confirm host network removal: */
    342     if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this))
    343         return;
    344 
    345     /* Get host for further activities: */
    346     CHost comHost = vboxGlobal().host();
    347 
    348     /* Find corresponding interface: */
    349     const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName);
    350 
    351     /* Show error message if necessary: */
    352     if (!comHost.isOk() || comInterface.isNull())
    353         msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this);
    354     else
    355     {
    356         /* Get network name for further activities: */
    357         QString strNetworkName;
    358         if (comInterface.isOk())
    359             strNetworkName = comInterface.GetNetworkName();
    360         /* Get interface id for further activities: */
    361         QString strInterfaceId;
    362         if (comInterface.isOk())
    363             strInterfaceId = comInterface.GetId();
    364 
    365         /* Show error message if necessary: */
    366         if (!comInterface.isOk())
    367             msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);
    368         else
    369         {
    370             /* Get VBox for further activities: */
    371             CVirtualBox comVBox = vboxGlobal().virtualBox();
    372 
    373             /* Find corresponding DHCP server: */
    374             const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);
    375             if (comVBox.isOk() && comServer.isNotNull())
    376             {
    377                 /* Remove server if any: */
    378                 comVBox.RemoveDHCPServer(comServer);
    379 
    380                 /* Show error message if necessary: */
    381                 if (!comVBox.isOk())
    382                     msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this);
    383             }
    384 
    385             /* Remove interface finally: */
    386             CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId);
    387 
    388             /* Show error message if necessary: */
    389             if (!comHost.isOk() || progress.isNull())
    390                 msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this);
    391             else
    392             {
    393                 /* Show interface removal progress: */
    394                 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0);
    395 
    396                 /* Show error message if necessary: */
    397                 if (!progress.isOk() || progress.GetResultCode() != 0)
    398                     return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this);
    399                 else
    400                 {
    401                     /* Remove interface from the tree: */
    402                     delete pItem;
    403 
    404                     /* Adjust tree-widget: */
    405                     sltAdjustTreeWidget();
    406                 }
    407             }
    408         }
    409     }
    410 }
    411 
    412 void UIHostNetworkManagerWidget::sltToggleHostNetworkDetailsVisibility(bool fVisible)
    413 {
    414     /* Show/hide details area and Apply button: */
    415     m_pDetailsWidget->setVisible(fVisible);
    416     m_pActionCommit->setVisible(fVisible);
    417 }
    418 
    419 void UIHostNetworkManagerWidget::sltCommitHostNetworkDetailsChanges()
    420 {
    421     /* Disable button first of all: */
    422     m_pActionCommit->setEnabled(false);
    423 
     271void UIHostNetworkManagerWidget::sltResetHostNetworkDetailsChanges()
     272{
     273    /* Just push the current item data there again: */
     274    sltHandleCurrentItemChange();
     275}
     276
     277void UIHostNetworkManagerWidget::sltApplyHostNetworkDetailsChanges()
     278{
    424279    /* Get network item: */
    425280    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
     
    540395}
    541396
     397void UIHostNetworkManagerWidget::sltAddHostNetwork()
     398{
     399    /* Get host for further activities: */
     400    CHost comHost = vboxGlobal().host();
     401
     402    /* Create interface: */
     403    CHostNetworkInterface comInterface;
     404    CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface);
     405
     406    /* Show error message if necessary: */
     407    if (!comHost.isOk() || progress.isNull())
     408        msgCenter().cannotCreateHostNetworkInterface(comHost, this);
     409    else
     410    {
     411        /* Show interface creation progress: */
     412        msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0);
     413
     414        /* Show error message if necessary: */
     415        if (!progress.isOk() || progress.GetResultCode() != 0)
     416            msgCenter().cannotCreateHostNetworkInterface(progress, this);
     417        else
     418        {
     419            /* Get network name for further activities: */
     420            const QString strNetworkName = comInterface.GetNetworkName();
     421
     422            /* Show error message if necessary: */
     423            if (!comInterface.isOk())
     424                msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);
     425            else
     426            {
     427                /* Get VBox for further activities: */
     428                CVirtualBox comVBox = vboxGlobal().virtualBox();
     429
     430                /* Find corresponding DHCP server (create if necessary): */
     431                CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);
     432                if (!comVBox.isOk() || comServer.isNull())
     433                    comServer = comVBox.CreateDHCPServer(strNetworkName);
     434
     435                /* Show error message if necessary: */
     436                if (!comVBox.isOk() || comServer.isNull())
     437                    msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this);
     438            }
     439
     440            /* Add interface to the tree: */
     441            UIDataHostNetwork data;
     442            loadHostNetwork(comInterface, data);
     443            createItemForNetworkHost(data, true);
     444
     445            /* Adjust tree-widget: */
     446            sltAdjustTreeWidget();
     447        }
     448    }
     449}
     450
     451void UIHostNetworkManagerWidget::sltRemoveHostNetwork()
     452{
     453    /* Get network item: */
     454    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
     455    AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
     456
     457    /* Get interface name: */
     458    const QString strInterfaceName(pItem->name());
     459
     460    /* Confirm host network removal: */
     461    if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this))
     462        return;
     463
     464    /* Get host for further activities: */
     465    CHost comHost = vboxGlobal().host();
     466
     467    /* Find corresponding interface: */
     468    const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName);
     469
     470    /* Show error message if necessary: */
     471    if (!comHost.isOk() || comInterface.isNull())
     472        msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this);
     473    else
     474    {
     475        /* Get network name for further activities: */
     476        QString strNetworkName;
     477        if (comInterface.isOk())
     478            strNetworkName = comInterface.GetNetworkName();
     479        /* Get interface id for further activities: */
     480        QString strInterfaceId;
     481        if (comInterface.isOk())
     482            strInterfaceId = comInterface.GetId();
     483
     484        /* Show error message if necessary: */
     485        if (!comInterface.isOk())
     486            msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);
     487        else
     488        {
     489            /* Get VBox for further activities: */
     490            CVirtualBox comVBox = vboxGlobal().virtualBox();
     491
     492            /* Find corresponding DHCP server: */
     493            const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);
     494            if (comVBox.isOk() && comServer.isNotNull())
     495            {
     496                /* Remove server if any: */
     497                comVBox.RemoveDHCPServer(comServer);
     498
     499                /* Show error message if necessary: */
     500                if (!comVBox.isOk())
     501                    msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this);
     502            }
     503
     504            /* Remove interface finally: */
     505            CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId);
     506
     507            /* Show error message if necessary: */
     508            if (!comHost.isOk() || progress.isNull())
     509                msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this);
     510            else
     511            {
     512                /* Show interface removal progress: */
     513                msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0);
     514
     515                /* Show error message if necessary: */
     516                if (!progress.isOk() || progress.GetResultCode() != 0)
     517                    return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this);
     518                else
     519                {
     520                    /* Remove interface from the tree: */
     521                    delete pItem;
     522
     523                    /* Adjust tree-widget: */
     524                    sltAdjustTreeWidget();
     525                }
     526            }
     527        }
     528    }
     529}
     530
     531void UIHostNetworkManagerWidget::sltToggleHostNetworkDetailsVisibility(bool fVisible)
     532{
     533    /* Show/hide details area and Apply button: */
     534    m_pDetailsWidget->setVisible(fVisible);
     535    /* Notify external lsiteners: */
     536    emit sigHostNetworkDetailsVisibilityChanged(fVisible);
     537}
     538
    542539void UIHostNetworkManagerWidget::sltAdjustTreeWidget()
    543540{
     
    658655    if (m_pActionDetails)
    659656        m_pActionDetails->setEnabled(pItem);
    660     if (m_pActionCommit)
    661         m_pActionCommit->setEnabled(false);
    662657
    663658    /* If there is an item => update details data: */
     
    682677        if (m_pActionDetails)
    683678            menu.addAction(m_pActionDetails);
    684         if (m_pActionCommit)
    685             menu.addAction(m_pActionCommit);
    686679    }
    687680    else
     
    756749    }
    757750
    758     /* Create 'Apply' action: */
    759     m_pActionCommit = new QAction(this);
    760     AssertPtrReturnVoid(m_pActionCommit);
    761     {
    762         /* Configure 'Apply' action: */
    763         m_pActionCommit->setVisible(false);
    764         m_pActionCommit->setShortcut(QKeySequence("Ctrl+Return"));
    765         m_pActionCommit->setIcon(UIIconPool::iconSetFull(":/commit_host_iface_22px.png",
    766                                                          ":/commit_host_iface_16px.png",
    767                                                          ":/commit_host_iface_disabled_22px.png",
    768                                                          ":/commit_host_iface_disabled_16px.png"));
    769         if (m_pActionDetails)
    770             connect(m_pActionDetails, &QAction::toggled, m_pActionCommit, &QAction::setVisible);
    771         connect(m_pActionCommit, &QAction::triggered, this, &UIHostNetworkManagerWidget::sltCommitHostNetworkDetailsChanges);
    772     }
    773 
    774751    /* Prepare menu: */
    775752    prepareMenu();
     
    789766        if (m_pActionDetails)
    790767            m_pMenu->addAction(m_pActionDetails);
    791         if (m_pActionCommit)
    792             m_pMenu->addAction(m_pActionCommit);
    793768    }
    794769}
     
    832807        if (m_pActionRemove)
    833808            m_pToolBar->addAction(m_pActionRemove);
    834         if ((m_pActionAdd || m_pActionRemove) && (m_pActionDetails || m_pActionCommit))
     809        if ((m_pActionAdd || m_pActionRemove) && m_pActionDetails)
    835810            m_pToolBar->addSeparator();
    836811        if (m_pActionDetails)
    837812            m_pToolBar->addAction(m_pActionDetails);
    838         if (m_pActionCommit)
    839             m_pToolBar->addAction(m_pActionCommit);
    840813#ifdef VBOX_WS_MAC
    841814        /* Check whether we are embedded into a stack: */
     
    885858{
    886859    /* Create details-widget: */
    887     m_pDetailsWidget = new UIHostNetworkDetailsDialog;
     860    m_pDetailsWidget = new UIHostNetworkDetailsDialog(m_enmEmbedding);
    888861    AssertPtrReturnVoid(m_pDetailsWidget);
    889862    {
     
    891864        m_pDetailsWidget->setVisible(false);
    892865        m_pDetailsWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    893         if (m_pActionCommit)
    894             connect(m_pDetailsWidget, &UIHostNetworkDetailsDialog::sigDataChanged,
    895                     m_pActionCommit, &QAction::setEnabled);
     866        connect(m_pDetailsWidget, &UIHostNetworkDetailsDialog::sigDataChanged,
     867                this, &UIHostNetworkManagerWidget::sigHostNetworkDetailsDataChanged);
     868        connect(m_pDetailsWidget, &UIHostNetworkDetailsDialog::sigDataChangeRejected,
     869                this, &UIHostNetworkManagerWidget::sltResetHostNetworkDetailsChanges);
     870        connect(m_pDetailsWidget, &UIHostNetworkDetailsDialog::sigDataChangeAccepted,
     871                this, &UIHostNetworkManagerWidget::sltApplyHostNetworkDetailsChanges);
    896872
    897873        /* Add into layout: */
     
    10431019}
    10441020
     1021void UIHostNetworkManager::sltHandleButtonBoxClick(QAbstractButton *pButton)
     1022{
     1023    /* Disable buttons first of all: */
     1024    buttonBox()->button(QDialogButtonBox::Reset)->setEnabled(false);
     1025    buttonBox()->button(QDialogButtonBox::Save)->setEnabled(false);
     1026
     1027    /* Compare with known buttons: */
     1028    if (pButton == buttonBox()->button(QDialogButtonBox::Reset))
     1029        emit sigDataChangeRejected();
     1030
     1031    else
     1032
     1033    if (pButton == buttonBox()->button(QDialogButtonBox::Save))
     1034        emit sigDataChangeAccepted();
     1035}
     1036
    10451037void UIHostNetworkManager::retranslateUi()
    10461038{
    10471039    /* Translate window title: */
    10481040    setWindowTitle(tr("Host Network Manager"));
     1041
     1042    /* Translate buttons: */
     1043    buttonBox()->button(QDialogButtonBox::Reset)->setText(tr("Reset"));
     1044    buttonBox()->button(QDialogButtonBox::Save)->setText(tr("Apply"));
     1045    buttonBox()->button(QDialogButtonBox::Close)->setText(tr("Close"));
     1046    buttonBox()->button(QDialogButtonBox::Reset)->setStatusTip(tr("Reset changes in current host network details"));
     1047    buttonBox()->button(QDialogButtonBox::Save)->setStatusTip(tr("Apply changes in current host network details"));
     1048    buttonBox()->button(QDialogButtonBox::Close)->setStatusTip(tr("Close dialog without saving"));
     1049    buttonBox()->button(QDialogButtonBox::Reset)->setShortcut(QString("Ctrl+Backspace"));
     1050    buttonBox()->button(QDialogButtonBox::Save)->setShortcut(QString("Ctrl+Return"));
     1051    //buttonBox()->button(QDialogButtonBox::Close)->setShortcut(Qt::Key_Escape); /* done in base-class */
     1052    buttonBox()->button(QDialogButtonBox::Reset)->
     1053        setToolTip(tr("Reset Changes (%1)").arg(buttonBox()->button(QDialogButtonBox::Reset)->shortcut().toString()));
     1054    buttonBox()->button(QDialogButtonBox::Save)->
     1055        setToolTip(tr("Apply Changes (%1)").arg(buttonBox()->button(QDialogButtonBox::Save)->shortcut().toString()));
     1056    buttonBox()->button(QDialogButtonBox::Close)->
     1057        setToolTip(tr("Close Window (%1)").arg(buttonBox()->button(QDialogButtonBox::Close)->shortcut().toString()));
    10491058}
    10501059
     
    10671076        setWidgetToolbar(pWidget->toolbar());
    10681077#endif
     1078        connect(this, &UIHostNetworkManager::sigDataChangeRejected,
     1079                pWidget, &UIHostNetworkManagerWidget::sltResetHostNetworkDetailsChanges);
     1080        connect(this, &UIHostNetworkManager::sigDataChangeAccepted,
     1081                pWidget, &UIHostNetworkManagerWidget::sltApplyHostNetworkDetailsChanges);
     1082
    10691083        /* Add into layout: */
    10701084        centralWidget()->layout()->addWidget(pWidget);
     
    10721086}
    10731087
     1088void UIHostNetworkManager::configureButtonBox()
     1089{
     1090    /* Configure button-box: */
     1091    connect(widget(), &UIHostNetworkManagerWidget::sigHostNetworkDetailsVisibilityChanged,
     1092            buttonBox()->button(QDialogButtonBox::Save), &QPushButton::setVisible);
     1093    connect(widget(), &UIHostNetworkManagerWidget::sigHostNetworkDetailsVisibilityChanged,
     1094            buttonBox()->button(QDialogButtonBox::Reset), &QPushButton::setVisible);
     1095    connect(widget(), &UIHostNetworkManagerWidget::sigHostNetworkDetailsDataChanged,
     1096            buttonBox()->button(QDialogButtonBox::Save), &QPushButton::setEnabled);
     1097    connect(widget(), &UIHostNetworkManagerWidget::sigHostNetworkDetailsDataChanged,
     1098            buttonBox()->button(QDialogButtonBox::Reset), &QPushButton::setEnabled);
     1099    connect(buttonBox(), &QIDialogButtonBox::clicked,
     1100            this, &UIHostNetworkManager::sltHandleButtonBoxClick);
     1101}
     1102
    10741103void UIHostNetworkManager::finalize()
    10751104{
  • trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.h

    r67573 r67575  
    4343    Q_OBJECT;
    4444
     45signals:
     46
     47    /** Notifies listeners about host network details widget @a fVisible. */
     48    void sigHostNetworkDetailsVisibilityChanged(bool fVisible);
     49    /** Notifies listeners about host network details data @a fDiffers. */
     50    void sigHostNetworkDetailsDataChanged(bool fDiffers);
     51
    4552public:
    4653
     
    6875        /** Handles show @a pEvent. */
    6976        virtual void showEvent(QShowEvent *pEvent) /* override */;
     77    /** @} */
     78
     79public slots:
     80
     81    /** @name Menu/action stuff.
     82      * @{ */
     83        /** Handles command to reset host network details changes. */
     84        void sltResetHostNetworkDetailsChanges();
     85        /** Handles command to apply host network details changes. */
     86        void sltApplyHostNetworkDetailsChanges();
    7087    /** @} */
    7188
     
    8097        /** Handles command to make host network details @a fVisible. */
    8198        void sltToggleHostNetworkDetailsVisibility(bool fVisible);
    82         /** Handles command to commit host network details changes. */
    83         void sltCommitHostNetworkDetailsChanges();
    8499    /** @} */
    85100
     
    153168        /** Holds the Details action instance. */
    154169        QAction   *m_pActionDetails;
    155         /** Holds the Commit action instance. */
    156         QAction   *m_pActionCommit;
    157170    /** @} */
    158171
     
    183196    Q_OBJECT;
    184197
    185 protected:
     198signals:
     199
     200    /** Notifies listeners about data change rejected and should be reseted. */
     201    void sigDataChangeRejected();
     202    /** Notifies listeners about data change accepted and should be applied. */
     203    void sigDataChangeAccepted();
     204
     205private slots:
     206
     207    /** @name Button-box stuff.
     208      * @{ */
     209        /** Handles button-box button click. */
     210        void sltHandleButtonBoxClick(QAbstractButton *pButton);
     211    /** @} */
     212
     213private:
    186214
    187215    /** Constructs Host Network Manager dialog.
     
    201229        /** Configures central-widget. */
    202230        virtual void configureCentralWidget() /* override */;
     231        /** Configures button-box. */
     232        virtual void configureButtonBox() /* override */;
    203233        /** Perform final preparations. */
    204234        virtual void finalize() /* override */;
Note: See TracChangeset for help on using the changeset viewer.

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