VirtualBox

Changeset 80215 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Aug 9, 2019 5:08:08 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
132660
Message:

FE/Qt: bugref:7720: VirtualBox Manager: Details pane: Possibility to edit VM network attachment type / interface name on-the-fly.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDetailsGenerator.cpp

    r80139 r80215  
    563563    for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
    564564    {
     565        const QString strAnchorType = QString("network_attachment_type");
    565566        const CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(uSlot);
    566567
     
    570571
    571572        /* Gather adapter information: */
    572         const KNetworkAttachmentType enmType = comAdapter.GetAttachmentType();
    573         const QString strAttachmentTemplate = gpConverter->toString(comAdapter.GetAdapterType()).replace(QRegExp("\\s\\(.+\\)"), " (%1)");
     573        const KNetworkAttachmentType enmAttachmentType = comAdapter.GetAttachmentType();
     574        const QString strAttachmentTemplate = gpConverter->toString(comAdapter.GetAdapterType()).replace(QRegExp("\\s\\(.+\\)"), " (<a href=#%1,%2;%3;%4>%5</a>)");
    574575        QString strAttachmentType;
    575         switch (enmType)
     576        switch (enmAttachmentType)
    576577        {
    577578            case KNetworkAttachmentType_NAT:
    578579            {
    579580                if (fOptions & UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork_NAT)
    580                     strAttachmentType = strAttachmentTemplate.arg(gpConverter->toString(enmType));
     581                    strAttachmentType = strAttachmentTemplate
     582                                            .arg(strAnchorType)
     583                                            .arg(uSlot)
     584                                            .arg((int)KNetworkAttachmentType_NAT)
     585                                            .arg(QString())
     586                                            .arg(gpConverter->toString(KNetworkAttachmentType_NAT));
    581587                break;
    582588            }
     
    584590            {
    585591                if (fOptions & UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork_BridgetAdapter)
    586                     strAttachmentType = strAttachmentTemplate.arg(QApplication::translate("UIDetails", "Bridged Adapter, %1", "details (network)")
    587                                                                   .arg(comAdapter.GetBridgedInterface()));
     592                {
     593                    const QString strName = comAdapter.GetBridgedInterface();
     594                    strAttachmentType = strAttachmentTemplate
     595                                            .arg(strAnchorType)
     596                                            .arg(uSlot)
     597                                            .arg((int)KNetworkAttachmentType_Bridged)
     598                                            .arg(strName)
     599                                            .arg(QApplication::translate("UIDetails", "Bridged Adapter, %1", "details (network)")
     600                                                 .arg(strName));
     601                }
    588602                break;
    589603            }
     
    591605            {
    592606                if (fOptions & UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork_InternalNetwork)
    593                     strAttachmentType = strAttachmentTemplate.arg(QApplication::translate("UIDetails", "Internal Network, '%1'", "details (network)")
    594                                                                   .arg(comAdapter.GetInternalNetwork()));
     607                {
     608                    const QString strName = comAdapter.GetInternalNetwork();
     609                    strAttachmentType = strAttachmentTemplate
     610                                            .arg(strAnchorType)
     611                                            .arg(uSlot)
     612                                            .arg((int)KNetworkAttachmentType_Internal)
     613                                            .arg(strName)
     614                                            .arg(QApplication::translate("UIDetails", "Internal Network, '%1'", "details (network)")
     615                                                 .arg(strName));
     616                }
    595617                break;
    596618            }
     
    598620            {
    599621                if (fOptions & UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork_HostOnlyAdapter)
    600                     strAttachmentType = strAttachmentTemplate.arg(QApplication::translate("UIDetails", "Host-only Adapter, '%1'", "details (network)")
    601                                                                   .arg(comAdapter.GetHostOnlyInterface()));
     622                {
     623                    const QString strName = comAdapter.GetHostOnlyInterface();
     624                    strAttachmentType = strAttachmentTemplate
     625                                            .arg(strAnchorType)
     626                                            .arg(uSlot)
     627                                            .arg((int)KNetworkAttachmentType_HostOnly)
     628                                            .arg(strName)
     629                                            .arg(QApplication::translate("UIDetails", "Host-only Adapter, '%1'", "details (network)")
     630                                                 .arg(strName));
     631                }
    602632                break;
    603633            }
     
    606636                if (fOptions & UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork_GenericDriver)
    607637                {
     638                    const QString strName = comAdapter.GetGenericDriver();
    608639                    const QString strGenericDriverProperties(summarizeGenericProperties(comAdapter));
    609                     strAttachmentType = strGenericDriverProperties.isNull() ?
    610                         strAttachmentTemplate.arg(QApplication::translate("UIDetails", "Generic Driver, '%1'", "details (network)")
    611                                                   .arg(comAdapter.GetGenericDriver())) :
    612                         strAttachmentTemplate.arg(QApplication::translate("UIDetails", "Generic Driver, '%1' { %2 }", "details (network)")
    613                                                   .arg(comAdapter.GetGenericDriver(), strGenericDriverProperties));
     640                    strAttachmentType = strGenericDriverProperties.isNull()
     641                                      ? strAttachmentTemplate
     642                                            .arg(strAnchorType)
     643                                            .arg(uSlot)
     644                                            .arg((int)KNetworkAttachmentType_Generic)
     645                                            .arg(strName)
     646                                            .arg(QApplication::translate("UIDetails", "Generic Driver, '%1'", "details (network)")
     647                                                 .arg(strName))
     648                                      : strAttachmentTemplate
     649                                            .arg(strAnchorType)
     650                                            .arg(uSlot)
     651                                            .arg((int)KNetworkAttachmentType_Generic)
     652                                            .arg(strName)
     653                                            .arg(QApplication::translate("UIDetails", "Generic Driver, '%1' { %2 }", "details (network)")
     654                                                 .arg(strName, strGenericDriverProperties));
    614655                }
    615656                break;
     
    618659            {
    619660                if (fOptions & UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork_NATNetwork)
    620                     strAttachmentType = strAttachmentTemplate.arg(QApplication::translate("UIDetails", "NAT Network, '%1'", "details (network)")
    621                                                                   .arg(comAdapter.GetNATNetwork()));
     661                {
     662                    const QString strName = comAdapter.GetNATNetwork();
     663                    strAttachmentType = strAttachmentTemplate
     664                                            .arg(strAnchorType)
     665                                            .arg(uSlot)
     666                                            .arg((int)KNetworkAttachmentType_NATNetwork)
     667                                            .arg(strName)
     668                                            .arg(QApplication::translate("UIDetails", "NAT Network, '%1'", "details (network)")
     669                                                 .arg(strName));
     670                }
    622671                break;
    623672            }
     
    625674            {
    626675                if (fOptions & UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork_NotAttached)
    627                     strAttachmentType = strAttachmentTemplate.arg(gpConverter->toString(enmType));
     676                    strAttachmentType = strAttachmentTemplate
     677                                            .arg(strAnchorType)
     678                                            .arg(uSlot)
     679                                            .arg((int)enmAttachmentType)
     680                                            .arg(QString())
     681                                            .arg(gpConverter->toString(enmAttachmentType));
    628682                break;
    629683            }
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMachineAttributeSetter.cpp

    r80139 r80215  
    2727/* COM includes: */
    2828#include "CAudioAdapter.h"
     29#include "CNetworkAdapter.h"
    2930#include "CUSBController.h"
    3031
     
    215216                break;
    216217            }
     218            case MachineAttribute_NetworkAttachmentType:
     219            {
     220                /* Acquire value itself: */
     221                const UINetworkAdapterDescriptor nad = guiAttribute.value<UINetworkAdapterDescriptor>();
     222                /* Acquire network adapter: */
     223                CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(nad.m_iSlot);
     224                if (!comMachine.isOk())
     225                {
     226                    msgCenter().cannotAcquireMachineParameter(comMachine);
     227                    fErrorHappened = true;
     228                    break;
     229                }
     230                /* Change network adapter attachment type: */
     231                comAdapter.SetAttachmentType(nad.m_enmType);
     232                if (!comAdapter.isOk())
     233                {
     234                    msgCenter().cannotChangeNetworkAdapterAttribute(comAdapter);
     235                    fErrorHappened = true;
     236                    break;
     237                }
     238                /* Change network adapter name: */
     239                switch (nad.m_enmType)
     240                {
     241                    case KNetworkAttachmentType_Bridged: comAdapter.SetBridgedInterface(nad.m_strName); break;
     242                    case KNetworkAttachmentType_Internal: comAdapter.SetInternalNetwork(nad.m_strName); break;
     243                    case KNetworkAttachmentType_HostOnly: comAdapter.SetHostOnlyInterface(nad.m_strName); break;
     244                    case KNetworkAttachmentType_Generic: comAdapter.SetGenericDriver(nad.m_strName); break;
     245                    case KNetworkAttachmentType_NATNetwork: comAdapter.SetNATNetwork(nad.m_strName); break;
     246                    default: break;
     247                }
     248                if (!comAdapter.isOk())
     249                {
     250                    msgCenter().cannotChangeNetworkAdapterAttribute(comAdapter);
     251                    fErrorHappened = true;
     252                }
     253                break;
     254            }
    217255            case MachineAttribute_USBControllerType:
    218256            {
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMachineAttributeSetter.h

    r80139 r80215  
    3939    MachineAttribute_AudioHostDriverType,
    4040    MachineAttribute_AudioControllerType,
     41    MachineAttribute_NetworkAttachmentType,
    4142    MachineAttribute_USBControllerType,
    4243};
     44
     45/** Contains short network adapter description. */
     46struct UINetworkAdapterDescriptor
     47{
     48    /** Composes network adapter descriptor for certain @a iSlot, @a enmType and @a strName. */
     49    UINetworkAdapterDescriptor(int iSlot = -1,
     50                               KNetworkAttachmentType enmType = KNetworkAttachmentType_Null,
     51                               const QString &strName = QString())
     52        : m_iSlot(iSlot), m_enmType(enmType), m_strName(strName)
     53    {}
     54
     55    /** Holds the slot of described network adapter. */
     56    int                     m_iSlot;
     57    /** Holds the attachment type of described network adapter. */
     58    KNetworkAttachmentType  m_enmType;
     59    /** Holds the adapter name of described network adapter. */
     60    QString                 m_strName;
     61};
     62Q_DECLARE_METATYPE(UINetworkAdapterDescriptor);
    4363
    4464/** A set of USB controller types. */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r80083 r80215  
    6363#include "CNATEngine.h"
    6464#include "CNATNetwork.h"
     65#include "CNetworkAdapter.h"
    6566#include "CRangedIntegerFormValue.h"
    6667#include "CSerialPort.h"
     
    12471248    error(pParent, MessageType_Error,
    12481249          tr("Failed to change audio adapter attribute."),
     1250          UIErrorString::formatErrorInfo(comAdapter));
     1251}
     1252
     1253void UIMessageCenter::cannotChangeNetworkAdapterAttribute(const CNetworkAdapter &comAdapter, QWidget *pParent /* = 0 */) const
     1254{
     1255    error(pParent, MessageType_Error,
     1256          tr("Failed to change network adapter attribute."),
    12491257          UIErrorString::formatErrorInfo(comAdapter));
    12501258}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r80083 r80215  
    332332    void cannotSaveMachineSettings(const CMachine &machine, QWidget *pParent = 0) const;
    333333    void cannotChangeAudioAdapterAttribute(const CAudioAdapter &comAdapter, QWidget *pParent = 0) const;
     334    void cannotChangeNetworkAdapterAttribute(const CNetworkAdapter &comAdapter, QWidget *pParent = 0) const;
    334335
    335336    /* API: Virtual Medium Manager warnings: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsElement.cpp

    r80139 r80215  
    4444#include "UIMachineAttributeSetter.h"
    4545#include "UINameAndSystemEditor.h"
     46#include "UINetworkAttachmentEditor.h"
    4647#include "UIVideoMemoryEditor.h"
    4748#include "UIVirtualBoxManager.h"
     
    6263    AnchorRole_AudioHostDriverType,
    6364    AnchorRole_AudioControllerType,
     65    AnchorRole_NetworkAttachmentType,
    6466    AnchorRole_USBControllerType,
    6567#ifndef VBOX_WS_MAC
     
    179181    m_pTextPane->setAnchorRoleRestricted("#audio_host_driver_type", cal != ConfigurationAccessLevel_Full);
    180182    m_pTextPane->setAnchorRoleRestricted("#audio_controller_type", cal != ConfigurationAccessLevel_Full);
     183    m_pTextPane->setAnchorRoleRestricted("#network_attachment_type", cal != ConfigurationAccessLevel_Full);
    181184    m_pTextPane->setAnchorRoleRestricted("#usb_controller_type", cal != ConfigurationAccessLevel_Full);
    182185#ifndef VBOX_WS_MAC
     
    475478    roles["#audio_host_driver_type"] = AnchorRole_AudioHostDriverType;
    476479    roles["#audio_controller_type"] = AnchorRole_AudioControllerType;
     480    roles["#network_attachment_type"] = AnchorRole_NetworkAttachmentType;
    477481    roles["#usb_controller_type"] = AnchorRole_USBControllerType;
    478482#ifndef VBOX_WS_MAC
     
    755759                if (pPopup->exec() == QDialog::Accepted)
    756760                    setMachineAttribute(machine(), MachineAttribute_AudioControllerType, QVariant::fromValue(pEditor->value()));
     761
     762                /* Delete popup: */
     763                delete pPopup;
     764            }
     765            break;
     766        }
     767        case AnchorRole_NetworkAttachmentType:
     768        {
     769            /* Prepare popup: */
     770            QPointer<QIDialogContainer> pPopup = new QIDialogContainer(0, Qt::Tool);
     771            if (pPopup)
     772            {
     773                /* Prepare editor: */
     774                UINetworkAttachmentEditor *pEditor = new UINetworkAttachmentEditor(pPopup, true /* with label */);
     775                if (pEditor)
     776                {
     777                    pEditor->setValueNames(KNetworkAttachmentType_Bridged, UINetworkAttachmentEditor::bridgedAdapters());
     778                    pEditor->setValueNames(KNetworkAttachmentType_Internal, UINetworkAttachmentEditor::internalNetworks());
     779                    pEditor->setValueNames(KNetworkAttachmentType_HostOnly, UINetworkAttachmentEditor::hostInterfaces());
     780                    pEditor->setValueNames(KNetworkAttachmentType_Generic, UINetworkAttachmentEditor::genericDrivers());
     781                    pEditor->setValueNames(KNetworkAttachmentType_NATNetwork, UINetworkAttachmentEditor::natNetworks());
     782                    pEditor->setValueType(static_cast<KNetworkAttachmentType>(strData.section(',', 0, 0).section(';', 1, 1).toInt()));
     783                    pEditor->setValueName(pEditor->valueType(), strData.section(',', 0, 0).section(';', 2, 2));
     784                    connect(pEditor, &UINetworkAttachmentEditor::sigValidChanged,
     785                            pPopup.data(), &QIDialogContainer::setOkButtonEnabled);
     786                    pPopup->setWidget(pEditor);
     787                }
     788
     789                /* Adjust popup geometry: */
     790                pPopup->move(QCursor::pos());
     791                pPopup->adjustSize();
     792
     793                // WORKAROUND:
     794                // On Windows, Tool dialogs aren't activated by default by some reason.
     795                // So we have created sltActivateWindow wrapping actual activateWindow
     796                // to fix that annoying issue.
     797                QMetaObject::invokeMethod(pPopup, "sltActivateWindow", Qt::QueuedConnection);
     798                /* Execute popup, change machine name if confirmed: */
     799                if (pPopup->exec() == QDialog::Accepted)
     800                {
     801                    UINetworkAdapterDescriptor nad(strData.section(',', 0, 0).section(';', 0, 0).toInt(),
     802                                                   pEditor->valueType(), pEditor->valueName(pEditor->valueType()));
     803                    setMachineAttribute(machine(), MachineAttribute_NetworkAttachmentType, QVariant::fromValue(nad));
     804                }
    757805
    758806                /* Delete popup: */
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