VirtualBox

Changeset 66720 in vbox


Ignore:
Timestamp:
Apr 28, 2017 2:30:01 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
115122
Message:

FE/Qt: bugref:8847: Host Network Manager: A bit of code moving.

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

Legend:

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

    r66718 r66720  
    2929# include "QITreeWidget.h"
    3030# include "UIIconPool.h"
    31 # include "UIMessageCenter.h"
    3231# include "UIHostNetworkDetailsDialog.h"
    3332# include "UIHostNetworkManager.h"
     33# include "UIMessageCenter.h"
    3434# include "UIToolBar.h"
    3535# ifdef VBOX_WS_MAC
     
    195195    , m_pMenu(0)
    196196    , m_pActionAdd(0)
     197    , m_pActionRemove(0)
    197198    , m_pActionEdit(0)
    198     , m_pActionRemove(0)
    199199    , m_pTreeWidget(0)
    200200    , m_pButtonBox(0)
     
    245245        m_pActionAdd->setStatusTip(tr("Creates new host-only network."));
    246246    }
     247    if (m_pActionRemove)
     248    {
     249        m_pActionRemove->setText(tr("&Remove..."));
     250        m_pActionRemove->setToolTip(tr("Remove Host-only Network (%1)").arg(m_pActionRemove->shortcut().toString()));
     251        m_pActionRemove->setStatusTip(tr("Removes selected host-only network."));
     252    }
    247253    if (m_pActionEdit)
    248254    {
     
    250256        m_pActionEdit->setToolTip(tr("Modify Host-only Network (%1)").arg(m_pActionEdit->shortcut().toString()));
    251257        m_pActionEdit->setStatusTip(tr("Modifies selected host-only network."));
    252     }
    253     if (m_pActionRemove)
    254     {
    255         m_pActionRemove->setText(tr("&Remove..."));
    256         m_pActionRemove->setToolTip(tr("Remove Host-only Network (%1)").arg(m_pActionRemove->shortcut().toString()));
    257         m_pActionRemove->setStatusTip(tr("Removes selected host-only network."));
    258258    }
    259259
     
    346346            /* Adjust tree-widget: */
    347347            sltAdjustTreeWidget();
     348        }
     349    }
     350}
     351
     352void UIHostNetworkManager::sltRemoveHostNetwork()
     353{
     354    /* Get network item: */
     355    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
     356    AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
     357
     358    /* Get interface name: */
     359    const QString strInterfaceName(pItem->name());
     360
     361    /* Confirm host network removal: */
     362    if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this))
     363        return;
     364
     365    /* Get host for further activities: */
     366    CHost comHost = vboxGlobal().host();
     367
     368    /* Find corresponding interface: */
     369    const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName);
     370
     371    /* Show error message if necessary: */
     372    if (!comHost.isOk() || comInterface.isNull())
     373        msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this);
     374    else
     375    {
     376        /* Get network name for further activities: */
     377        QString strNetworkName;
     378        if (comInterface.isOk())
     379            strNetworkName = comInterface.GetNetworkName();
     380        /* Get interface id for further activities: */
     381        QString strInterfaceId;
     382        if (comInterface.isOk())
     383            strInterfaceId = comInterface.GetId();
     384
     385        /* Show error message if necessary: */
     386        if (!comInterface.isOk())
     387            msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);
     388        else
     389        {
     390            /* Get VBox for further activities: */
     391            CVirtualBox comVBox = vboxGlobal().virtualBox();
     392
     393            /* Find corresponding DHCP server: */
     394            const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);
     395            if (comVBox.isOk() && comServer.isNotNull())
     396            {
     397                /* Remove server if any: */
     398                comVBox.RemoveDHCPServer(comServer);
     399
     400                /* Show error message if necessary: */
     401                if (!comVBox.isOk())
     402                    msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this);
     403            }
     404
     405            /* Remove interface finally: */
     406            CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId);
     407
     408            /* Show error message if necessary: */
     409            if (!comHost.isOk() || progress.isNull())
     410                msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this);
     411            else
     412            {
     413                /* Show interface removal progress: */
     414                msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0);
     415
     416                /* Show error message if necessary: */
     417                if (!progress.isOk() || progress.GetResultCode() != 0)
     418                    return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this);
     419                else
     420                {
     421                    /* Remove interface from the tree: */
     422                    delete pItem;
     423
     424                    /* Adjust tree-widget: */
     425                    sltAdjustTreeWidget();
     426                }
     427            }
    348428        }
    349429    }
     
    445525}
    446526
    447 void UIHostNetworkManager::sltRemoveHostNetwork()
    448 {
    449     /* Get network item: */
    450     UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
    451     AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
    452 
    453     /* Get interface name: */
    454     const QString strInterfaceName(pItem->name());
    455 
    456     /* Confirm host network removal: */
    457     if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this))
    458         return;
    459 
    460     /* Get host for further activities: */
    461     CHost comHost = vboxGlobal().host();
    462 
    463     /* Find corresponding interface: */
    464     const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName);
    465 
    466     /* Show error message if necessary: */
    467     if (!comHost.isOk() || comInterface.isNull())
    468         msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this);
    469     else
    470     {
    471         /* Get network name for further activities: */
    472         QString strNetworkName;
    473         if (comInterface.isOk())
    474             strNetworkName = comInterface.GetNetworkName();
    475         /* Get interface id for further activities: */
    476         QString strInterfaceId;
    477         if (comInterface.isOk())
    478             strInterfaceId = comInterface.GetId();
    479 
    480         /* Show error message if necessary: */
    481         if (!comInterface.isOk())
    482             msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);
    483         else
    484         {
    485             /* Get VBox for further activities: */
    486             CVirtualBox comVBox = vboxGlobal().virtualBox();
    487 
    488             /* Find corresponding DHCP server: */
    489             const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);
    490             if (comVBox.isOk() && comServer.isNotNull())
    491             {
    492                 /* Remove server if any: */
    493                 comVBox.RemoveDHCPServer(comServer);
    494 
    495                 /* Show error message if necessary: */
    496                 if (!comVBox.isOk())
    497                     msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this);
    498             }
    499 
    500             /* Remove interface finally: */
    501             CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId);
    502 
    503             /* Show error message if necessary: */
    504             if (!comHost.isOk() || progress.isNull())
    505                 msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this);
    506             else
    507             {
    508                 /* Show interface removal progress: */
    509                 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0);
    510 
    511                 /* Show error message if necessary: */
    512                 if (!progress.isOk() || progress.GetResultCode() != 0)
    513                     return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this);
    514                 else
    515                 {
    516                     /* Remove interface from the tree: */
    517                     delete pItem;
    518 
    519                     /* Adjust tree-widget: */
    520                     sltAdjustTreeWidget();
    521                 }
    522             }
    523         }
    524     }
    525 }
    526 
    527527void UIHostNetworkManager::sltAdjustTreeWidget()
    528528{
     
    633633    if (m_pTreeWidget->itemAt(pos))
    634634    {
     635        menu.addAction(m_pActionRemove);
    635636        menu.addAction(m_pActionEdit);
    636         menu.addAction(m_pActionRemove);
    637637    }
    638638    else
     
    695695    }
    696696
     697    /* Create 'Remove' action: */
     698    m_pActionRemove = new QAction(this);
     699    AssertPtrReturnVoid(m_pActionRemove);
     700    {
     701        /* Configure 'Remove' action: */
     702        m_pActionRemove->setShortcut(QKeySequence("Del"));
     703        m_pActionRemove->setIcon(UIIconPool::iconSetFull(":/remove_host_iface_22px.png",
     704                                                         ":/remove_host_iface_16px.png",
     705                                                         ":/remove_host_iface_disabled_22px.png",
     706                                                         ":/remove_host_iface_disabled_16px.png"));
     707        connect(m_pActionRemove, SIGNAL(triggered()), this, SLOT(sltRemoveHostNetwork()));
     708    }
     709
    697710    /* Create 'Edit' action: */
    698711    m_pActionEdit = new QAction(this);
     
    708721    }
    709722
    710     /* Create 'Remove' action: */
    711     m_pActionRemove = new QAction(this);
    712     AssertPtrReturnVoid(m_pActionRemove);
    713     {
    714         /* Configure 'Remove' action: */
    715         m_pActionRemove->setShortcut(QKeySequence("Del"));
    716         m_pActionRemove->setIcon(UIIconPool::iconSetFull(":/remove_host_iface_22px.png",
    717                                                          ":/remove_host_iface_16px.png",
    718                                                          ":/remove_host_iface_disabled_22px.png",
    719                                                          ":/remove_host_iface_disabled_16px.png"));
    720         connect(m_pActionRemove, SIGNAL(triggered()), this, SLOT(sltRemoveHostNetwork()));
    721     }
    722 
    723723    /* Prepare menu-bar: */
    724724    prepareMenuBar();
     
    733733        /* Configure 'File' menu: */
    734734        m_pMenu->addAction(m_pActionAdd);
     735        m_pMenu->addAction(m_pActionRemove);
    735736        m_pMenu->addAction(m_pActionEdit);
    736         m_pMenu->addAction(m_pActionRemove);
    737737    }
    738738
     
    780780        if (m_pActionAdd)
    781781            m_pToolBar->addAction(m_pActionAdd);
     782        if (m_pActionRemove)
     783            m_pToolBar->addAction(m_pActionRemove);
    782784        if (m_pActionEdit)
    783785            m_pToolBar->addAction(m_pActionEdit);
    784         if (m_pActionRemove)
    785             m_pToolBar->addAction(m_pActionRemove);
    786786        /* Integrate tool-bar into dialog: */
    787787        QVBoxLayout *pMainLayout = qobject_cast<QVBoxLayout*>(centralWidget()->layout());
  • trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.h

    r66696 r66720  
    7373        /** Handles command to add host network. */
    7474        void sltAddHostNetwork();
     75        /** Handles command to remove host network. */
     76        void sltRemoveHostNetwork();
    7577        /** Handles command to edit host network. */
    7678        void sltEditHostNetwork();
    77         /** Handles command to remove host network. */
    78         void sltRemoveHostNetwork();
    7979    /** @} */
    8080
     
    152152        /** Holds the Add action instance. */
    153153        QAction   *m_pActionAdd;
     154        /** Holds the Remove action instance. */
     155        QAction   *m_pActionRemove;
    154156        /** Holds the Edit action instance. */
    155157        QAction   *m_pActionEdit;
    156         /** Holds the Remove action instance. */
    157         QAction   *m_pActionRemove;
    158158    /** @} */
    159159
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