VirtualBox

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


Ignore:
Timestamp:
Mar 13, 2009 1:06:28 AM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4: 2869: Rework network adapter UI - Initial Version!

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r17730 r17784  
    272272        include/VBoxVMSettingsAudio.h \
    273273        include/VBoxVMSettingsNetwork.h \
     274        include/VBoxVMSettingsNetworkDetails.h \
    274275        include/VBoxVMSettingsSerial.h \
    275276        include/VBoxVMSettingsParallel.h \
     
    352353        src/VBoxVMSettingsAudio.cpp \
    353354        src/VBoxVMSettingsNetwork.cpp \
     355        src/VBoxVMSettingsNetworkDetails.cpp \
    354356        src/VBoxVMSettingsSerial.cpp \
    355357        src/VBoxVMSettingsParallel.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/VBoxUI.pro

    r17450 r17784  
    4545    ui/VBoxVMSettingsHD.ui \
    4646    ui/VBoxVMSettingsNetwork.ui \
     47    ui/VBoxVMSettingsNetworkDetails.ui \
    4748    ui/VBoxVMSettingsParallel.ui \
    4849    ui/VBoxVMSettingsSF.ui \
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox.qrc

    r17726 r17784  
    334334    <file alias="export_16px.png">images/export_16px.png</file>
    335335    <file alias="vmw_ovf_import.png">images/vmw_ovf_import.png</file>
     336    <file alias="connect_16px.png">images/connect_16px.png</file>
     337    <file alias="disconnect_16px.png">images/disconnect_16px.png</file>
    336338 </qresource>
    337339 </RCC>
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxProblemReporter.h

    r17730 r17784  
    263263#if defined Q_WS_WIN
    264264    int confirmDeletingHostInterface (const QString &aName, QWidget *aParent = 0);
    265     void cannotCreateHostInterface (const CHost &aHost,
    266                                     QWidget *aParent = 0);
    267     void cannotCreateHostInterface (const CProgress &aProgress, const QString &aName,
    268                                     QWidget *aParent = 0);
     265    void cannotCreateHostInterface (const CHost &aHost, QWidget *aParent = 0);
     266    void cannotCreateHostInterface (const CProgress &aProgress, QWidget *aParent = 0);
    269267    void cannotRemoveHostInterface (const CHost &aHost,
    270268                                    const CHostNetworkInterface &aIface,
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMSettingsNetwork.h

    r17217 r17784  
    66
    77/*
    8  * Copyright (C) 2006-2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#define __VBoxVMSettingsNetwork_h__
    2525
     26/* VBox Includes */
     27#include "COMDefs.h"
    2628#include "VBoxSettingsPage.h"
    2729#include "VBoxVMSettingsNetwork.gen.h"
    28 #include "COMDefs.h"
    2930
    30 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    31 class QTreeWidget;
    32 class QTreeWidgetItem;
    33 #endif
     31/* VBox Forwardes */
     32class VBoxVMSettingsNetworkPage;
     33class VBoxVMSettingsNetworkDetails;
    3434
    35 /*
    36  * QWidget sub-class which represents one tab-page per each network adapter.
    37  * It has generated UI part.
    38  */
    39 class VBoxVMSettingsNetwork : public QIWithRetranslateUI<QWidget>,
     35class VBoxVMSettingsNetwork : public QIWithRetranslateUI <QWidget>,
    4036                              public Ui::VBoxVMSettingsNetwork
    4137{
     
    4440public:
    4541
    46     VBoxVMSettingsNetwork();
     42    VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent);
    4743
    4844    void getFromAdapter (const CNetworkAdapter &aAdapter);
    4945    void putBackToAdapter();
    5046
    51     QString pageTitle() const;
    52 
    5347    void setValidator (QIWidgetValidator *aValidator);
     48    bool revalidate (QString &aWarning, QString &aTitle);
    5449
    5550    QWidget* setOrderAfter (QWidget *aAfter);
    5651
    57     void setNetworksList (const QStringList &aList);
    58 
    59 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    60     void setInterfaceName (const QString &);
    61     QString interfaceName() const;
    62 #endif
     52    QString pageTitle() const;
     53    QString currentName (KNetworkAttachmentType aType = KNetworkAttachmentType_Null) const;
    6354
    6455protected:
     
    6859private slots:
    6960
    70     void adapterToggled (bool aOn);
    71     void naTypeChanged (const QString &aString);
    72     void genMACClicked();
     61    void updateCableConnectedState();
     62    void detailsClicked();
    7363
    7464private:
    7565
    76     void prepareComboboxes();
     66    void populateComboboxes();
     67    KNetworkAttachmentType attachmentType() const;
    7768
    78     void setTapEnabled (bool aEnabled);
    79     void setTapVisible (bool aVisible);
    80 
     69    VBoxVMSettingsNetworkPage *mParent;
     70    VBoxVMSettingsNetworkDetails *mDetails;
    8171    CNetworkAdapter mAdapter;
    8272    QIWidgetValidator *mValidator;
    83 
    84 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    85     QString mInterfaceName;
    86 #endif
    8773};
    8874
    89 
    90 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    91 /*
    92  * QGroupBox sub-class which represents network interface list.
    93  */
    94 class VBoxNIList : public QIWithRetranslateUI<QWidget>
    95 {
    96     Q_OBJECT;
    97 
    98 public:
    99 
    100     VBoxNIList (QWidget *aParent);
    101 
    102     bool isWrongInterface() const;
    103     void setCurrentInterface (const QString &aName);
    104 #if defined (Q_WS_WIN) && defined(VBOX_WITH_NETFLT)
    105     void updateInterfacesList(KNetworkAttachmentType enmAttachmentType);
    106 #endif
    107 signals:
    108 
    109     void listChanged();
    110     void currentInterfaceChanged (const QString &);
    111 
    112 private slots:
    113 
    114     void onCurrentItemChanged (QTreeWidgetItem *aCurrent, QTreeWidgetItem *aPrev = 0);
    115     void addHostInterface();
    116     void delHostInterface();
    117 
    118 protected:
    119 
    120     void retranslateUi();
    121 
    122 private:
    123 #if defined (Q_WS_WIN) && defined(VBOX_WITH_NETFLT)
    124     void populateInterfacesList(KNetworkAttachmentType enmAttachmentType);
    125 #else
    126     void populateInterfacesList();
    127 #endif
    128     QILabelSeparator *mLbTitle;
    129     QTreeWidget      *mList;
    130 
    131 # if defined (Q_WS_WIN)
    132     QAction *mAddAction;
    133     QAction *mDelAction;
    134 #  ifdef VBOX_WITH_NETFLT
    135     KNetworkAttachmentType mEnmAttachmentType;
    136 #  endif
    137 # endif
    138 };
    139 #endif /* Q_WS_WIN || VBOX_WITH_NETFLT */
    140 
    141 
    142 /*
    143  * QWidget sub-class which represents network settings page itself.
    144  */
    14575class VBoxVMSettingsNetworkPage : public VBoxSettingsPage
    14676{
     
    15181    VBoxVMSettingsNetworkPage();
    15282
     83    QStringList natList() const;
     84    QStringList netList() const;
     85    QStringList intList (KHostNetworkInterfaceType aType) const;
     86
    15387protected:
    15488
     
    15690    void putBackTo();
    15791
    158     void setValidator (QIWidgetValidator *aVal);
     92    void setValidator (QIWidgetValidator *aValidator);
    15993    bool revalidate (QString &aWarning, QString &aTitle);
    16094
    16195    void retranslateUi();
    16296
    163 private slots:
    164 
    165     void updateNetworksList();
    166 #if defined (VBOX_WITH_NETFLT)
    167     void updateInterfaceList();
    168 #endif
    169 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    170     void onCurrentPageChanged (int);
    171     void onCurrentInterfaceChanged (const QString &);
    172 #endif
    173 
    17497private:
    17598
    176     void populateNetworksList();
    177 
    178     /* Widgets */
     99    QIWidgetValidator *mValidator;
    179100    QTabWidget *mTwAdapters;
    180 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    181     VBoxNIList *mNIList;
    182 #endif
    183 
    184     /* Widget Validator*/
    185     QIWidgetValidator *mValidator;
    186 
    187     /* Lists */
    188     QStringList mListNetworks;
    189 
    190     /* Flags */
    191     bool mLockNetworkListUpdate;
    192101};
    193102
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r17737 r17784  
    18961896                     * an additional symbolic network/interface name field, use
    18971897                     * this name instead */
    1898                     if (type == KNetworkAttachmentType_Bridged)
    1899                         attType = attType.arg (tr ("host interface, %1",
     1898                    if (type == KNetworkAttachmentType_NAT)
     1899                        attType = attType.arg (tr ("NAT, '%1'",
     1900                            "details report (network)").arg (adapter.GetNATNetwork()));
     1901                    else if (type == KNetworkAttachmentType_Bridged)
     1902                        attType = attType.arg (tr ("Bridged network, %1",
    19001903                            "details report (network)").arg (adapter.GetHostInterface()));
    19011904                    else if (type == KNetworkAttachmentType_Internal)
    1902                         attType = attType.arg (tr ("internal network, '%1'",
     1905                        attType = attType.arg (tr ("Internal network, '%1'",
    19031906                            "details report (network)").arg (adapter.GetInternalNetwork()));
     1907                    else if (type == KNetworkAttachmentType_HostOnly)
     1908                        attType = attType.arg (tr ("Host-only network, '%1'",
     1909                            "details report (network)").arg (adapter.GetHostInterface()));
    19041910                    else
    19051911                        attType = attType.arg (vboxGlobal().toString (type));
     
    29162922        tr ("NAT", "NetworkAttachmentType");
    29172923    mNetworkAttachmentTypes [KNetworkAttachmentType_Bridged] =
    2918         tr ("Bridged Interface", "NetworkAttachmentType");
     2924        tr ("Bridged Network", "NetworkAttachmentType");
    29192925    mNetworkAttachmentTypes [KNetworkAttachmentType_Internal] =
    29202926        tr ("Internal Network", "NetworkAttachmentType");
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp

    r17731 r17784  
    13371337{
    13381338    message (parent ? parent : mainWindowShown(), Error,
    1339         tr ("Failed to create the host network interface ."),
     1339        tr ("Failed to create the host-only network interface."),
    13401340        formatErrorInfo (host));
    13411341}
    13421342
    13431343void VBoxProblemReporter::cannotCreateHostInterface (
    1344     const CProgress &progress, const QString &name, QWidget *parent)
     1344    const CProgress &progress, QWidget *parent)
    13451345{
    13461346    message (parent ? parent : mainWindowShown(), Error,
    1347         tr ("Failed to create the host network interface <b>%1</b>.")
    1348             .arg (name),
     1347        tr ("Failed to create the host-only network interface."),
    13491348        formatErrorInfo (progress.GetErrorInfo()));
    13501349}
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsNetwork.cpp

    r17737 r17784  
    66
    77/*
    8  * Copyright (C) 2006-2008 Sun Microsystems, Inc.
     8 * Copyright (C) 2008 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121 */
    2222
    23 /* Common Includes */
    24 #include "VBoxVMSettingsNetwork.h"
     23/* VBox Includes */
    2524#include "QIWidgetValidator.h"
    2625#include "VBoxGlobal.h"
    27 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    28 #include "VBoxToolBar.h"
    29 #include "VBoxSettingsUtils.h"
    30 #include "VBoxProblemReporter.h"
    31 #endif
    32 
    33 /* Qt Includes */
    34 #if defined (Q_WS_X11) && !defined (VBOX_WITH_NETFLT)
    35 #include <QFileDialog>
    36 #endif
    37 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    38 #include <QTreeWidget>
    39 #endif
    40 
    41 /* Common Stuff */
    42 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    43 static QTreeWidgetItem* findItem (QTreeWidget *aList,
    44                                   const QString &aMatch)
    45 {
    46     QList<QTreeWidgetItem*> list =
    47         aList->findItems (aMatch, Qt::MatchExactly, 0);
    48     return list.count() ? list [0] : 0;
    49 }
    50 #endif
    51 
     26#include "VBoxVMSettingsNetwork.h"
     27#include "VBoxVMSettingsNetworkDetails.h"
    5228
    5329/* VBoxVMSettingsNetwork Stuff */
    54 VBoxVMSettingsNetwork::VBoxVMSettingsNetwork()
    55     : QIWithRetranslateUI<QWidget> (0)
     30VBoxVMSettingsNetwork::VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent)
     31    : QIWithRetranslateUI <QWidget> (0)
     32    , mParent (aParent)
     33    , mDetails (new VBoxVMSettingsNetworkDetails (this))
    5634    , mValidator (0)
    5735{
     
    5937    Ui::VBoxVMSettingsNetwork::setupUi (this);
    6038
    61     /* Setup common validators */
    62     mLeMAC->setValidator (new QRegExpValidator
    63         (QRegExp ("[0-9A-Fa-f][02468ACEace][0-9A-Fa-f]{10}"), this));
    64 
    65     /* Setup dialog for current platform */
    66 #if !defined (Q_WS_X11) || defined (VBOX_WITH_NETFLT)
    67     setTapVisible (false);
    68 #endif
     39    /* Setup widgets */
     40    mTbDetails->setIcon (VBoxGlobal::iconSet (
     41        ":/global_settings_16px.png", ":/global_settings_disabled_16px.png"));
    6942
    7043    /* Applying language settings */
     
    7548     * available on Mac OS X. Not sure why this happens but this seems to help
    7649     * against. */
    77     QList<QWidget*> list = findChildren<QWidget*>();
     50    QList <QWidget*> list = findChildren <QWidget*>();
    7851    foreach (QWidget *w, list)
    7952        if (w->parent() == this)
     
    8659    mAdapter = aAdapter;
    8760
     61    /* Load adapter state */
    8862    mGbAdapter->setChecked (aAdapter.GetEnabled());
    8963
    90     int aPos = mCbAType->findText (
    91         vboxGlobal().toString (aAdapter.GetAdapterType()));
    92     mCbAType->setCurrentIndex (aPos == -1 ? 0 : aPos);
    93 
    94     int naPos = mCbNAType->findText (
    95         vboxGlobal().toString (aAdapter.GetAttachmentType()));
    96     mCbNAType->setCurrentIndex (naPos == -1 ? 0 : naPos);
    97     naTypeChanged (mCbNAType->currentText());
    98 
    99     mLeMAC->setText (aAdapter.GetMACAddress());
    100 
    101     mCbCable->setChecked (aAdapter.GetCableConnected());
    102 
    103     int inPos = mCbNetwork->findText (aAdapter.GetInternalNetwork());
    104     mCbNetwork->setCurrentIndex (inPos == -1 ? 0 : inPos);
    105 
    106 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    107     mInterfaceName = aAdapter.GetHostInterface().isEmpty() ?
    108                      QString::null : aAdapter.GetHostInterface();
    109 #endif
    110 #if defined (Q_WS_X11) && !defined (VBOX_WITH_NETFLT)
    111     mLeInterface_x11->setText (aAdapter.GetHostInterface());
    112 #endif
     64    /* Load adapter type */
     65    int adapterPos = mCbAdapterType->findData (aAdapter.GetAdapterType());
     66    mCbAdapterType->setCurrentIndex (adapterPos == -1 ? 0 : adapterPos);
     67
     68    /* Load cable-connected status */
     69    mTbCable->setProperty ("EXT_Checked", QVariant (aAdapter.GetCableConnected()));
     70    updateCableConnectedState();
     71
     72    /* Load network attachment type */
     73    int attachmentPos = mCbAttachmentType->findData (aAdapter.GetAttachmentType());
     74    mCbAttachmentType->setCurrentIndex (attachmentPos == -1 ? 0 : attachmentPos);
     75
     76    /* Load details page */
     77    mDetails->getFromAdapter (aAdapter);
    11378}
    11479
    11580void VBoxVMSettingsNetwork::putBackToAdapter()
    11681{
     82    /* Save adapter state */
    11783    mAdapter.SetEnabled (mGbAdapter->isChecked());
    11884
    119     mAdapter.SetAdapterType (vboxGlobal().
    120         toNetworkAdapterType (mCbAType->currentText()));
    121 
    122     KNetworkAttachmentType type =
    123         vboxGlobal().toNetworkAttachmentType (mCbNAType->currentText());
    124     switch (type)
     85    /* Save adapter type */
     86    KNetworkAdapterType type = (KNetworkAdapterType)
     87        mCbAdapterType->itemData (mCbAdapterType->currentIndex()).toInt();
     88    mAdapter.SetAdapterType (type);
     89
     90    /* Save cable-connected status */
     91    mAdapter.SetCableConnected (mTbCable->property ("EXT_Checked").toBool());
     92
     93    /* Save network attachment type */
     94    switch (attachmentType())
    12595    {
    12696        case KNetworkAttachmentType_Null:
     
    140110            break;
    141111        default:
    142             AssertMsgFailed (("Invalid network attachment type: %d", type));
    143             break;
    144     }
    145 
    146     mAdapter.SetMACAddress (mLeMAC->text());
    147 
    148     mAdapter.SetCableConnected (mCbCable->isChecked());
    149 
    150     if (type == KNetworkAttachmentType_Bridged
    151 #if defined (Q_WS_WIN) && defined (VBOX_WITH_NETFLT)
    152             || type == KNetworkAttachmentType_HostOnly
    153 #endif
    154             )
    155     {
    156 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    157         mAdapter.SetHostInterface (mInterfaceName);
    158 #endif
    159 #if defined (Q_WS_X11) && !defined (VBOX_WITH_NETFLT)
    160         QString iface = mLeInterface_x11->text();
    161         mAdapter.SetHostInterface (iface.isEmpty() ? QString::null : iface);
    162 #endif
    163     }
    164     else if (type == KNetworkAttachmentType_Internal)
    165         mAdapter.SetInternalNetwork (mCbNetwork->currentText());
     112            AssertMsgFailed (("Invalid network attachment type: (%d).", attachmentType()));
     113    }
     114
     115    /* Save details page */
     116    mDetails->putBackToAdapter();
     117}
     118
     119void VBoxVMSettingsNetwork::setValidator (QIWidgetValidator *aValidator)
     120{
     121    mValidator = aValidator;
     122
     123    connect (mGbAdapter, SIGNAL (toggled (bool)),
     124             mValidator, SLOT (revalidate()));
     125    connect (mCbAttachmentType, SIGNAL (activated (const QString&)),
     126             mValidator, SLOT (revalidate()));
     127    connect (mTbCable, SIGNAL (clicked (bool)),
     128             this, SLOT (updateCableConnectedState()));
     129    connect (mTbDetails, SIGNAL (clicked (bool)),
     130             this, SLOT (detailsClicked()));
     131
     132    mValidator->revalidate();
     133}
     134
     135bool VBoxVMSettingsNetwork::revalidate (QString &aWarning, QString &aTitle)
     136{
     137    bool valid = mGbAdapter->isChecked() ?
     138                 mDetails->revalidate (attachmentType(), aWarning) : true;
     139
     140    if (!valid)
     141        aTitle += ": " + vboxGlobal().removeAccelMark (pageTitle());
     142
     143    return valid;
     144}
     145
     146QWidget* VBoxVMSettingsNetwork::setOrderAfter (QWidget *aAfter)
     147{
     148    setTabOrder (aAfter, mGbAdapter);
     149    setTabOrder (mGbAdapter, mCbAdapterType);
     150    setTabOrder (mCbAdapterType, mTbCable);
     151    setTabOrder (mTbCable, mCbAttachmentType);
     152    return mCbAttachmentType;
    166153}
    167154
    168155QString VBoxVMSettingsNetwork::pageTitle() const
    169156{
    170     QString pageTitle;
     157    QString title;
    171158    if (!mAdapter.isNull())
    172159    {
    173         pageTitle = VBoxGlobal::tr ("Adapter %1", "network")
     160        title = VBoxGlobal::tr ("Adapter %1", "network")
    174161            .arg (QString ("&%1").arg (mAdapter.GetSlot() + 1));
    175162    }
    176     return pageTitle;
    177 }
    178 
    179 void VBoxVMSettingsNetwork::setValidator (QIWidgetValidator *aValidator)
    180 {
    181     mValidator = aValidator;
    182 
    183     connect (mGbAdapter, SIGNAL (toggled (bool)),
    184              this, SLOT (adapterToggled (bool)));
    185     connect (mCbNAType, SIGNAL (activated (const QString&)),
    186              this, SLOT (naTypeChanged (const QString&)));
    187     connect (mCbNetwork, SIGNAL (activated (const QString&)),
    188              mValidator, SLOT (revalidate()));
    189     connect (mPbMAC, SIGNAL (clicked()), this, SLOT (genMACClicked()));
    190 
    191     mValidator->revalidate();
    192 }
    193 
    194 QWidget* VBoxVMSettingsNetwork::setOrderAfter (QWidget *aAfter)
    195 {
    196     setTabOrder (aAfter, mGbAdapter);
    197     setTabOrder (mGbAdapter, mCbAType);
    198     setTabOrder (mCbAType, mCbNAType);
    199     setTabOrder (mCbNAType, mCbNetwork);
    200     setTabOrder (mCbNetwork, mLeMAC);
    201     setTabOrder (mLeMAC, mPbMAC);
    202     setTabOrder (mPbMAC, mCbCable);
    203     setTabOrder (mCbCable, mLeInterface_x11);
    204     return mLeInterface_x11;
    205 }
    206 
    207 void VBoxVMSettingsNetwork::setNetworksList (const QStringList &aList)
    208 {
    209     QString curText = mCbNetwork->currentText();
    210     mCbNetwork->clear();
    211     mCbNetwork->clearEditText();
    212     mCbNetwork->insertItems (0, aList);
    213     mCbNetwork->setCurrentIndex (mCbNetwork->findText (curText));
    214     if (mValidator)
    215         mValidator->revalidate();
    216 }
    217 
    218 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    219 void VBoxVMSettingsNetwork::setInterfaceName (const QString &aName)
    220 {
    221     mInterfaceName = aName;
    222     if (mValidator)
    223         mValidator->revalidate();
    224 }
    225 
    226 QString VBoxVMSettingsNetwork::interfaceName() const
    227 {
    228     return mInterfaceName;
    229 }
    230 #endif
     163    return title;
     164}
     165
     166QString VBoxVMSettingsNetwork::currentName (KNetworkAttachmentType aType) const
     167{
     168    return mDetails->currentName (aType);
     169}
    231170
    232171void VBoxVMSettingsNetwork::retranslateUi()
     
    235174    Ui::VBoxVMSettingsNetwork::retranslateUi (this);
    236175
    237     prepareComboboxes();
    238 }
    239 
    240 void VBoxVMSettingsNetwork::adapterToggled (bool aOn)
    241 {
    242     if (!aOn)
    243     {
    244         mCbNAType->setCurrentIndex (0);
    245         naTypeChanged (mCbNAType->currentText());
    246     }
    247     if (mValidator)
    248         mValidator->revalidate();
    249 }
    250 
    251 void VBoxVMSettingsNetwork::naTypeChanged (const QString &aString)
    252 {
    253     bool enableIntNet = vboxGlobal().toNetworkAttachmentType (aString) ==
    254                         KNetworkAttachmentType_Internal;
    255     mLbNetwork->setEnabled (enableIntNet);
    256     mCbNetwork->setEnabled (enableIntNet);
    257 #if defined (Q_WS_X11) && !defined (VBOX_WITH_NETFLT)
    258     bool enableHostIf = vboxGlobal().toNetworkAttachmentType (aString) ==
    259                         KNetworkAttachmentType_Bridged;
    260     setTapEnabled (enableHostIf);
    261 #endif
    262     if (mValidator)
    263         mValidator->revalidate();
    264 }
    265 
    266 void VBoxVMSettingsNetwork::genMACClicked()
    267 {
    268     mAdapter.SetMACAddress (QString::null);
    269     mLeMAC->setText (mAdapter.GetMACAddress());
    270 }
    271 
    272 void VBoxVMSettingsNetwork::prepareComboboxes()
    273 {
    274     /* Save the current selected value */
    275     int currentAdapter = mCbAType->currentIndex();
    276     /* Clear the driver box */
    277     mCbAType->clear();
    278     /* Refill them */
    279     mCbAType->insertItem (0,
     176    /* Translate combo-boxes content */
     177    populateComboboxes();
     178}
     179
     180void VBoxVMSettingsNetwork::updateCableConnectedState()
     181{
     182    if (sender())
     183    {
     184        /* If click called with slot - toggle button's state */
     185        bool value = mTbCable->property ("EXT_Checked").toBool();
     186        mTbCable->setProperty ("EXT_Checked", QVariant (!value));
     187    }
     188
     189    /* Feat the icon relatively button state */
     190    mTbCable->setIcon (VBoxGlobal::iconSet (mTbCable->
     191        property ("EXT_Checked").toBool() ? ":/connect_16px.png" :
     192                                            ":/disconnect_16px.png"));
     193}
     194
     195void VBoxVMSettingsNetwork::detailsClicked()
     196{
     197    /* Reload alternate list */
     198    KNetworkAttachmentType type = attachmentType();
     199    QStringList list;
     200    switch (type)
     201    {
     202        case KNetworkAttachmentType_NAT:
     203            list = mParent->natList();
     204            break;
     205        case KNetworkAttachmentType_Bridged:
     206            list = mParent->intList (KHostNetworkInterfaceType_Bridged);
     207            break;
     208        case KNetworkAttachmentType_Internal:
     209            list = mParent->netList();
     210            break;
     211        case KNetworkAttachmentType_HostOnly:
     212            list = mParent->intList (KHostNetworkInterfaceType_HostOnly);
     213            break;
     214        default:
     215            break;
     216    }
     217    mDetails->loadList (type, list);
     218    mDetails->activateWindow();
     219    mDetails->exec();
     220    Assert (mValidator);
     221    mValidator->revalidate();
     222}
     223
     224void VBoxVMSettingsNetwork::populateComboboxes()
     225{
     226    /* Save the current selected adapter */
     227    int currentAdapter = mCbAdapterType->currentIndex();
     228
     229    /* Clear the adapters combo-box */
     230    mCbAdapterType->clear();
     231
     232    /* Populate adapters */
     233    mCbAdapterType->insertItem (0,
    280234        vboxGlobal().toString (KNetworkAdapterType_Am79C970A));
    281     mCbAType->setItemData (0,
    282         mCbAType->itemText(0), Qt::ToolTipRole);
    283     mCbAType->insertItem (1,
     235    mCbAdapterType->setItemData (0,
     236        KNetworkAdapterType_Am79C970A);
     237    mCbAdapterType->setItemData (0,
     238        mCbAdapterType->itemText (0), Qt::ToolTipRole);
     239    mCbAdapterType->insertItem (1,
    284240        vboxGlobal().toString (KNetworkAdapterType_Am79C973));
    285     mCbAType->setItemData (1,
    286         mCbAType->itemText(1), Qt::ToolTipRole);
     241    mCbAdapterType->setItemData (1,
     242        KNetworkAdapterType_Am79C973);
     243    mCbAdapterType->setItemData (1,
     244        mCbAdapterType->itemText (1), Qt::ToolTipRole);
    287245#ifdef VBOX_WITH_E1000
    288     mCbAType->insertItem (2,
     246    mCbAdapterType->insertItem (2,
    289247        vboxGlobal().toString (KNetworkAdapterType_I82540EM));
    290     mCbAType->setItemData (2,
    291         mCbAType->itemText(2), Qt::ToolTipRole);
    292     mCbAType->insertItem (3,
     248    mCbAdapterType->setItemData (2,
     249        KNetworkAdapterType_I82540EM);
     250    mCbAdapterType->setItemData (2,
     251        mCbAdapterType->itemText (2), Qt::ToolTipRole);
     252    mCbAdapterType->insertItem (3,
    293253        vboxGlobal().toString (KNetworkAdapterType_I82543GC));
    294     mCbAType->setItemData (3,
    295         mCbAType->itemText(3), Qt::ToolTipRole);
    296 #endif
     254    mCbAdapterType->setItemData (3,
     255        KNetworkAdapterType_I82543GC);
     256    mCbAdapterType->setItemData (3,
     257        mCbAdapterType->itemText (3), Qt::ToolTipRole);
     258#endif /* VBOX_WITH_E1000 */
     259
    297260    /* Set the old value */
    298     mCbAType->setCurrentIndex (currentAdapter);
    299 
    300     /* Save the current selected value */
    301     int currentAttachment = mCbNAType->currentIndex();
    302     /* Clear the driver box */
    303     mCbNAType->clear();
    304     /* Refill them */
    305     mCbNAType->insertItem (0,
     261    mCbAdapterType->setCurrentIndex (currentAdapter == -1 ?
     262                                     0 : currentAdapter);
     263
     264
     265    /* Save the current selected attachment type */
     266    int currentAttachment = mCbAttachmentType->currentIndex();
     267
     268    /* Clear the attachments combo-box */
     269    mCbAttachmentType->clear();
     270
     271    /* Populate attachments */
     272    mCbAttachmentType->insertItem (0,
    306273        vboxGlobal().toString (KNetworkAttachmentType_Null));
    307     mCbNAType->setItemData (0,
    308         mCbNAType->itemText(0), Qt::ToolTipRole);
    309     mCbNAType->insertItem (1,
     274    mCbAttachmentType->setItemData (0,
     275        KNetworkAttachmentType_Null);
     276    mCbAttachmentType->setItemData (0,
     277        mCbAttachmentType->itemText (0), Qt::ToolTipRole);
     278    mCbAttachmentType->insertItem (1,
    310279        vboxGlobal().toString (KNetworkAttachmentType_NAT));
    311     mCbNAType->setItemData (1,
    312         mCbNAType->itemText(1), Qt::ToolTipRole);
    313     mCbNAType->insertItem (2,
     280    mCbAttachmentType->setItemData (1,
     281        KNetworkAttachmentType_NAT);
     282    mCbAttachmentType->setItemData (1,
     283        mCbAttachmentType->itemText (1), Qt::ToolTipRole);
     284    mCbAttachmentType->insertItem (2,
    314285        vboxGlobal().toString (KNetworkAttachmentType_Bridged));
    315     mCbNAType->setItemData (2,
    316         mCbNAType->itemText(2), Qt::ToolTipRole);
    317     mCbNAType->insertItem (3,
     286    mCbAttachmentType->setItemData (2,
     287        KNetworkAttachmentType_Bridged);
     288    mCbAttachmentType->setItemData (2,
     289        mCbAttachmentType->itemText (2), Qt::ToolTipRole);
     290    mCbAttachmentType->insertItem (3,
    318291        vboxGlobal().toString (KNetworkAttachmentType_Internal));
    319     mCbNAType->setItemData (3,
    320         mCbNAType->itemText(3), Qt::ToolTipRole);
    321 #if defined(RT_OS_LINUX) || defined (RT_OS_WINDOWS)
    322     mCbNAType->insertItem (4,
     292    mCbAttachmentType->setItemData (3,
     293        KNetworkAttachmentType_Internal);
     294    mCbAttachmentType->setItemData (3,
     295        mCbAttachmentType->itemText (3), Qt::ToolTipRole);
     296#if defined (RT_OS_LINUX) || defined (RT_OS_WINDOWS)
     297    mCbAttachmentType->insertItem (4,
    323298        vboxGlobal().toString (KNetworkAttachmentType_HostOnly));
    324     mCbNAType->setItemData (4,
    325         mCbNAType->itemText(4), Qt::ToolTipRole);
    326 #endif /* RT_OS_LINUX */
     299    mCbAttachmentType->setItemData (4,
     300        KNetworkAttachmentType_HostOnly);
     301    mCbAttachmentType->setItemData (4,
     302        mCbAttachmentType->itemText (4), Qt::ToolTipRole);
     303#endif /* RT_OS_LINUX || RT_OS_WINDOWS */
     304
    327305    /* Set the old value */
    328     mCbNAType->setCurrentIndex (currentAttachment);
    329 }
    330 
    331 void VBoxVMSettingsNetwork::setTapEnabled (bool aEnabled)
    332 {
    333     mGbTap->setEnabled (aEnabled);
    334     mLbInterface_x11->setEnabled (aEnabled);
    335     mLeInterface_x11->setEnabled (aEnabled);
    336 }
    337 
    338 void VBoxVMSettingsNetwork::setTapVisible (bool aVisible)
    339 {
    340     mGbTap->setVisible (aVisible);
    341     mLbInterface_x11->setVisible (aVisible);
    342     mLeInterface_x11->setVisible (aVisible);
    343 #ifdef Q_WS_MAC
    344     /* Make sure the layout is recalculated (Important on the mac). */
    345     layout()->activate();
    346 #endif
    347 }
    348 
    349 /* VBoxNIList Stuff */
    350 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    351 class VBoxNIListItem : public QTreeWidgetItem
    352 {
    353 public:
    354 
    355     enum { typeId = QTreeWidgetItem::UserType + 1 };
    356 
    357     VBoxNIListItem (QTreeWidget *aParent, const QString &aName, bool aWrong = false)
    358         : QTreeWidgetItem (aParent, QStringList (aName), typeId)
    359         , mWrong (aWrong)
    360     {
    361         init();
    362     }
    363 
    364     VBoxNIListItem (const QString &aName, bool aWrong = false)
    365         : QTreeWidgetItem (QStringList (aName), typeId)
    366         , mWrong (aWrong)
    367     {
    368         init();
    369     }
    370 
    371     void init()
    372     {
    373         /* Force the fake item's font to italic */
    374         if (mWrong)
    375         {
    376             QFont fnt = font (0);
    377             fnt.setItalic (true);
    378             setFont (0, fnt);
    379         }
    380     }
    381 
    382     bool isWrong() { return mWrong; }
    383 
    384 private:
    385 
    386     bool mWrong;
    387 };
    388 
    389 VBoxNIList::VBoxNIList (QWidget *aParent)
    390     : QIWithRetranslateUI<QWidget> (aParent)
    391 {
    392     QVBoxLayout *mainLayout = new QVBoxLayout (this);
    393     VBoxGlobal::setLayoutMargin (mainLayout, 0);
    394     mLbTitle = new QILabelSeparator();
    395     mainLayout->addWidget (mLbTitle);
    396 //    mainLayout->addItem (new QSpacerItem (8, 16, QSizePolicy::Fixed, QSizePolicy::Minimum), 1, 0);
    397     /* Creating List Widget */
    398     QHBoxLayout *layout = new QHBoxLayout ();
    399     mainLayout->addLayout (layout);
    400     mList = new QTreeWidget (this);
    401     setFocusProxy (mList);
    402     mLbTitle->setBuddy (mList);
    403     mList->setColumnCount (1);
    404     mList->header()->hide();
    405     mList->setContextMenuPolicy (Qt::ActionsContextMenu);
    406     mList->setRootIsDecorated (false);
    407     layout->addWidget (mList);
    408 
    409     /* Prepare actions */
    410 # if defined (Q_WS_WIN)
    411     mAddAction = new QAction (mList);
    412     mDelAction = new QAction (mList);
    413     mList->addAction (mAddAction);
    414     mList->addAction (mDelAction);
    415     mAddAction->setShortcut (QKeySequence ("Ins"));
    416     mDelAction->setShortcut (QKeySequence ("Del"));
    417     mAddAction->setIcon (VBoxGlobal::iconSet (":/add_host_iface_16px.png",
    418                                               ":/add_host_iface_disabled_16px.png"));
    419     mDelAction->setIcon (VBoxGlobal::iconSet (":/remove_host_iface_16px.png",
    420                                               ":/remove_host_iface_disabled_16px.png"));
    421 # endif /* Q_WS_WIN */
    422 
    423 # if defined (Q_WS_WIN)
    424     /* Prepare toolbar */
    425     VBoxToolBar *toolBar = new VBoxToolBar (this);
    426     toolBar->setUsesTextLabel (false);
    427     toolBar->setIconSize (QSize (16, 16));
    428     toolBar->setOrientation (Qt::Vertical);
    429     toolBar->addAction (mAddAction);
    430     toolBar->addAction (mDelAction);
    431     layout->addWidget (toolBar);
    432 # endif /* Q_WS_WIN */
    433 
    434     /* Setup connections */
    435     connect (mList, SIGNAL (currentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)),
    436              this, SLOT (onCurrentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)));
    437 # if defined (Q_WS_WIN)
    438     connect (mAddAction, SIGNAL (triggered (bool)),
    439              this, SLOT (addHostInterface()));
    440     connect (mDelAction, SIGNAL (triggered (bool)),
    441              this, SLOT (delHostInterface()));
    442 # endif /* Q_WS_WIN */
    443 
    444 #if !defined(Q_WS_WIN) || !defined(VBOX_WITH_NETFLT)
    445     /* Populating interface list */
    446     populateInterfacesList();
    447 #endif
    448 
    449     /* Applying language settings */
    450     retranslateUi();
    451 }
    452 
    453 bool VBoxNIList::isWrongInterface() const
    454 {
    455     return !mList->currentItem();
    456 }
    457 
    458 void VBoxNIList::setCurrentInterface (const QString &aName)
    459 {
    460     /* Remove wrong item if present */
    461     for (int i = 0; i < mList->topLevelItemCount(); ++ i)
    462     {
    463         VBoxNIListItem *item =
    464             mList->topLevelItem (i)->type() == VBoxNIListItem::typeId ?
    465             static_cast<VBoxNIListItem*> (mList->topLevelItem (i)) : 0;
    466         Assert (item);
    467         if (item && item->isWrong())
    468             delete item;
    469     }
    470 
    471     if (aName.isEmpty())
    472     {
    473 #ifdef VBOX_WITH_NETFLT
    474         /* Always select the first item to have an initial value. */
    475         QTreeWidgetItem *item = mList->topLevelItem (0);
    476         if (item)
    477         {
    478             item->setSelected (true);
    479             mList->setCurrentItem (item);
    480             onCurrentItemChanged (mList->currentItem());
    481         }
    482 #else
    483         /* Make sure no one of items selected in the list currently */
    484         mList->setCurrentItem (NULL);
    485         mList->clearSelection();
    486 #endif
    487     }
    488     else
    489     {
    490         /* Search for the required item */
    491         QTreeWidgetItem *querryItem = findItem (mList, aName);
    492 
    493         /* Create fake required item if real is not present */
    494         if (!querryItem)
    495             querryItem = new VBoxNIListItem (mList, aName, true);
    496 
    497         /* Set the required item to be the current */
    498         mList->setCurrentItem (querryItem);
    499     }
    500 }
    501 
    502 void VBoxNIList::onCurrentItemChanged (QTreeWidgetItem *aCurrent,
    503                                        QTreeWidgetItem *)
    504 {
    505 # if defined (Q_WS_WIN)
    506 #  if defined (VBOX_WITH_NETFLT)
    507     if(mEnmAttachmentType == KNetworkAttachmentType_HostOnly)
    508 #  endif
    509     {
    510         VBoxNIListItem *item = aCurrent &&
    511             aCurrent->type() == VBoxNIListItem::typeId ?
    512             static_cast<VBoxNIListItem*> (aCurrent) : 0;
    513         mDelAction->setEnabled (item && !item->isWrong());
    514     }
    515 #  if defined (VBOX_WITH_NETFLT)
    516     else
    517     {
    518         mDelAction->setEnabled (false);
    519     }
    520 #  endif
    521 # else
    522     NOREF (aCurrent);
    523 # endif
    524 
    525     emit currentInterfaceChanged (mList->currentItem() ?
    526         mList->currentItem()->text (0) : QString::null);
    527 }
    528 
    529 void VBoxNIList::addHostInterface()
    530 {
    531 # if defined (Q_WS_WIN)
    532     /* Allow the started helper process to make itself the foreground window */
    533     AllowSetForegroundWindow (ASFW_ANY);
    534 
    535     /* Search for the max available interface index */
    536     int ifaceNumber = 0;
    537     QString ifaceName = tr ("VirtualBox Host Interface %1");
    538     QRegExp regExp (QString ("^") + ifaceName.arg ("([0-9]+)") + QString ("$"));
    539     for (int index = 0; index < mList->topLevelItemCount(); ++ index)
    540     {
    541         QString iface = mList->topLevelItem (index)->text (0);
    542         int pos = regExp.indexIn (iface);
    543         if (pos != -1)
    544             ifaceNumber = regExp.cap (1).toInt() > ifaceNumber ?
    545                           regExp.cap (1).toInt() : ifaceNumber;
    546     }
    547 
    548     /* Create interface */
    549     CHost host = vboxGlobal().virtualBox().GetHost();
    550     CHostNetworkInterface iFace;
    551     CProgress progress = host.CreateHostOnlyNetworkInterface (iFace);
    552     if (host.isOk())
    553     {
    554         QString iName = iFace.GetName();
    555 
    556         vboxProblem().showModalProgressDialog (progress, iName, this);
    557         /* Add&Select newly created interface */
    558         if (progress.GetResultCode() == 0)
    559             new VBoxNIListItem (mList, iName);
    560         else
    561             vboxProblem().cannotCreateHostInterface (progress, iName, this);
    562     }
    563     else
    564         vboxProblem().cannotCreateHostInterface (host, this);
    565 
    566     emit listChanged();
    567 
    568     /* Allow the started helper process to make itself the foreground window */
    569     AllowSetForegroundWindow (ASFW_ANY);
    570 # endif /* Q_WS_WIN */
    571 }
    572 
    573 void VBoxNIList::delHostInterface()
    574 {
    575     Assert (mList->currentItem());
    576 
    577 # if defined (Q_WS_WIN)
    578     /* Allow the started helper process to make itself the foreground window */
    579     AllowSetForegroundWindow (ASFW_ANY);
    580 
    581     /* Check interface name */
    582     QString iName = mList->currentItem()->text (0);
    583     if (iName.isEmpty())
    584         return;
    585 
    586     /* Asking user about deleting selected network interface */
    587     int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question,
    588         tr ("<p>Do you want to remove the selected host network interface "
    589             "<nobr><b>%1</b>?</nobr></p>"
    590             "<p><b>Note:</b> This interface may be in use by one or more "
    591             "network adapters of this or another VM. After it is removed, these "
    592             "adapters will no longer work until you correct their settings by "
    593             "either choosing a different interface name or a different adapter "
    594             "attachment type.</p>").arg (iName),
    595         0, /* autoConfirmId */
    596         QIMessageBox::Ok | QIMessageBox::Default,
    597         QIMessageBox::Cancel | QIMessageBox::Escape);
    598     if (delNetIface == QIMessageBox::Cancel)
    599         return;
    600 
    601     CHost host = vboxGlobal().virtualBox().GetHost();
    602     CHostNetworkInterfaceVector interfaces =
    603         host.GetNetworkInterfaces();
    604     CHostNetworkInterface iFace;
    605     for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
    606          it != interfaces.end(); ++it)
    607         if (it->GetName() == iName)
    608             iFace = *it;
    609     if (!iFace.isNull())
    610     {
    611         /* Delete interface */
    612         CProgress progress = host.RemoveHostOnlyNetworkInterface (iFace.GetId(), iFace);
    613         if (host.isOk())
    614         {
    615             vboxProblem().showModalProgressDialog (progress, iName, this);
    616             if (progress.GetResultCode() == 0)
    617                 delete findItem (mList, iName);
    618             else
    619                 vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
    620         }
    621     }
    622 
    623     if (!host.isOk())
    624         vboxProblem().cannotRemoveHostInterface (host, iFace, this);
    625 
    626     emit listChanged();
    627 # endif /* Q_WS_WIN */
    628 }
    629 
    630 void VBoxNIList::retranslateUi()
    631 {
    632     mLbTitle->setText (tr ("Host &Interfaces"));
    633 
    634     mList->setWhatsThis (tr ("Lists all available host interfaces."));
    635 
    636 # if defined (Q_WS_WIN)
    637     mAddAction->setText (tr ("A&dd New Host Interface"));
    638     mDelAction->setText (tr ("&Remove Selected Host Interface"));
    639     mAddAction->setWhatsThis (tr ("Adds a new host interface."));
    640     mDelAction->setWhatsThis (tr ("Removes the selected host interface."));
    641     mAddAction->setToolTip (mAddAction->text().remove ('&') +
    642         QString (" (%1)").arg (mAddAction->shortcut().toString()));
    643     mDelAction->setToolTip (mDelAction->text().remove ('&') +
    644         QString (" (%1)").arg (mDelAction->shortcut().toString()));
    645 # endif /* Q_WS_WIN */
    646 }
    647 
    648 #if defined(Q_WS_WIN) && defined(VBOX_WITH_NETFLT)
    649 void VBoxNIList::updateInterfacesList(KNetworkAttachmentType enmAttachmentType)
    650 {
    651     bool bHostOnly = enmAttachmentType == KNetworkAttachmentType_HostOnly;
    652     mEnmAttachmentType = enmAttachmentType;
    653     mAddAction->setEnabled(bHostOnly);
    654     mDelAction->setEnabled(bHostOnly);
    655     populateInterfacesList(enmAttachmentType);
    656 }
    657 
    658 void VBoxNIList::populateInterfacesList(KNetworkAttachmentType enmAttachmentType)
    659 #else
    660 void VBoxNIList::populateInterfacesList()
    661 #endif
    662 {
    663     /* Load current inner list */
    664     QList<QTreeWidgetItem*> itemsList;
    665     CHostNetworkInterfaceVector interfaces = vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
    666     for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
    667          it != interfaces.end(); ++it)
    668     {
    669 #if defined(Q_WS_WIN) && defined(VBOX_WITH_NETFLT)
    670         /* display real for not host-only and viceversa */
    671         if((enmAttachmentType == KNetworkAttachmentType_HostOnly)
    672                 == (it->GetInterfaceType() == KHostNetworkInterfaceType_HostOnly))
    673 #endif
    674             itemsList << new VBoxNIListItem (it->GetName());
    675     }
    676 
    677     /* Save current list item name */
    678     QString currentListItemName = mList->currentItem() ?
    679         mList->currentItem()->text (0) : QString::null;
    680 
    681     /* Load current list items */
    682     mList->clear();
    683     if (!itemsList.isEmpty())
    684         mList->insertTopLevelItems (0, itemsList);
    685 
    686     /* Select current list item */
    687     QTreeWidgetItem *item = findItem (mList, currentListItemName);
    688     mList->setCurrentItem (item ? item : mList->topLevelItem (0));
    689 
    690     /* Update item's state */
    691     onCurrentItemChanged (mList->currentItem());
    692 }
    693 #endif /* Q_WS_WIN || VBOX_WITH_NETFLT */
    694 
     306    mCbAttachmentType->setCurrentIndex (currentAttachment);
     307}
     308
     309KNetworkAttachmentType VBoxVMSettingsNetwork::attachmentType() const
     310{
     311    return (KNetworkAttachmentType) mCbAttachmentType->itemData (
     312           mCbAttachmentType->currentIndex()).toInt();
     313}
    695314
    696315/* VBoxVMSettingsNetworkPage Stuff */
    697316VBoxVMSettingsNetworkPage::VBoxVMSettingsNetworkPage()
    698317    : mValidator (0)
    699     , mLockNetworkListUpdate (true)
    700 {
    701     QVBoxLayout *layout = new QVBoxLayout (this);
    702     layout->setContentsMargins (0, 5, 0, 5);
     318{
     319    /* Setup Main Layout */
     320    QVBoxLayout *mainLayout = new QVBoxLayout (this);
     321    mainLayout->setContentsMargins (0, 5, 0, 5);
    703322
    704323    /* Creating Tab Widget */
    705324    mTwAdapters = new QTabWidget (this);
    706     layout->addWidget (mTwAdapters);
    707     /* Prepare Networks Lists */
    708     populateNetworksList();
    709 
    710 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    711     /* Creating Interfaces List */
    712     mNIList = new VBoxNIList (this);
    713     layout->addWidget (mNIList);
    714 #else
    715 //    layout->addItem (new QSpacerItem (0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
    716 #endif
    717 //    layout->activate();
     325    mainLayout->addWidget (mTwAdapters);
     326}
     327
     328QStringList VBoxVMSettingsNetworkPage::natList() const
     329{
     330    QStringList list;
     331
     332    /* Load total NAT names list of all VMs */
     333    CVirtualBox vbox = vboxGlobal().virtualBox();
     334    ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());
     335    CMachineVector vec = vbox.GetMachines();
     336    for (CMachineVector::ConstIterator m = vec.begin(); m != vec.end(); ++ m)
     337    {
     338        if (m->GetAccessible())
     339        {
     340            for (ulong slot = 0; slot < count; ++ slot)
     341            {
     342                QString name = m->GetNetworkAdapter (slot).GetNATNetwork();
     343                if (!name.isEmpty() && !list.contains (name))
     344                    list << name;
     345            }
     346        }
     347    }
     348
     349    /* Append NAT names list with names from all the pages */
     350    for (int index = 0; index < mTwAdapters->count(); ++ index)
     351    {
     352        VBoxVMSettingsNetwork *page =
     353            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
     354        if (page)
     355        {
     356            QString name = page->currentName (KNetworkAttachmentType_NAT);
     357            if (!name.isEmpty() && !list.contains (name))
     358                list << name;
     359        }
     360    }
     361
     362    return list;
     363}
     364
     365QStringList VBoxVMSettingsNetworkPage::netList() const
     366{
     367    QStringList list;
     368
     369    /* Load total network list of all VMs */
     370    CVirtualBox vbox = vboxGlobal().virtualBox();
     371    ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());
     372    CMachineVector vec =  vbox.GetMachines();
     373    for (CMachineVector::ConstIterator m = vec.begin(); m != vec.end(); ++ m)
     374    {
     375        if (m->GetAccessible())
     376        {
     377            for (ulong slot = 0; slot < count; ++ slot)
     378            {
     379                QString name = m->GetNetworkAdapter (slot).GetInternalNetwork();
     380                if (!name.isEmpty() && !list.contains (name))
     381                    list << name;
     382            }
     383        }
     384    }
     385
     386    /* Append network list with names from all the pages */
     387    for (int index = 0; index < mTwAdapters->count(); ++ index)
     388    {
     389        VBoxVMSettingsNetwork *page =
     390            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
     391        if (page)
     392        {
     393            QString name = page->currentName (KNetworkAttachmentType_Internal);
     394            if (!name.isEmpty() && !list.contains (name))
     395                list << name;
     396        }
     397    }
     398
     399    return list;
     400}
     401
     402QStringList VBoxVMSettingsNetworkPage::intList (KHostNetworkInterfaceType aType) const
     403{
     404    QStringList list;
     405
     406    /* Load total interfaces list */
     407    CHostNetworkInterfaceVector interfaces =
     408        vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
     409    for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
     410         it != interfaces.end(); ++ it)
     411    {
     412        if (it->GetInterfaceType() == aType)
     413            list << it->GetName();
     414    }
     415
     416    return list;
    718417}
    719418
    720419void VBoxVMSettingsNetworkPage::getFrom (const CMachine &aMachine)
    721420{
     421    /* Setup tab order */
    722422    Assert (mFirstWidget);
    723423    setTabOrder (mFirstWidget, mTwAdapters->focusProxy());
     
    733433
    734434        /* Creating Adapter's page */
    735         VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork();
     435        VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork (this);
    736436
    737437        /* Loading Adapter's data into page */
    738         page->setNetworksList (mListNetworks);
    739438        page->getFromAdapter (adapter);
    740439
     
    747446        /* Setup tab order */
    748447        lastFocusWidget = page->setOrderAfter (lastFocusWidget);
    749 
    750         /* Setup connections */
    751 #if defined (VBOX_WITH_NETFLT)
    752         connect (page->mCbNAType, SIGNAL (currentIndexChanged (int)),
    753                  this, SLOT (updateInterfaceList()));
    754 #endif
    755         connect (page->mCbNetwork, SIGNAL (editTextChanged (const QString&)),
    756                  this, SLOT (updateNetworksList()));
    757     }
    758 
    759 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    760     setTabOrder (lastFocusWidget, mNIList->focusProxy());
    761     connect (mTwAdapters, SIGNAL (currentChanged (int)),
    762              this, SLOT (onCurrentPageChanged (int)));
    763     connect (mNIList, SIGNAL (currentInterfaceChanged (const QString &)),
    764              this, SLOT (onCurrentInterfaceChanged (const QString &)));
    765     onCurrentPageChanged (mTwAdapters->currentIndex());
    766 #endif
     448    }
    767449
    768450    /* Applying language settings */
     
    774456    for (int i = 0; i < mTwAdapters->count(); ++ i)
    775457    {
    776         VBoxVMSettingsNetwork *page = static_cast<VBoxVMSettingsNetwork*>
    777             (mTwAdapters->widget (i));
    778         if (page)
    779             page->putBackToAdapter();
     458        VBoxVMSettingsNetwork *page =
     459            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
     460        Assert (page);
     461        page->putBackToAdapter();
    780462    }
    781463}
     
    784466{
    785467    mValidator = aVal;
    786 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    787     connect (mNIList, SIGNAL (listChanged()), mValidator, SLOT (revalidate()));
    788 #endif
    789 }
    790 
    791 bool VBoxVMSettingsNetworkPage::revalidate (QString &aWarning,
    792                                             QString &aTitle)
     468}
     469
     470bool VBoxVMSettingsNetworkPage::revalidate (QString &aWarning, QString &aTitle)
    793471{
    794472    bool valid = true;
     
    796474    for (int i = 0; i < mTwAdapters->count(); ++ i)
    797475    {
    798         VBoxVMSettingsNetwork *page = static_cast<VBoxVMSettingsNetwork*>
    799             (mTwAdapters->widget (i));
     476        VBoxVMSettingsNetwork *page =
     477            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
    800478        Assert (page);
    801 
    802         KNetworkAttachmentType type =
    803             vboxGlobal().toNetworkAttachmentType (page->mCbNAType->currentText());
    804 
    805 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    806         if ((type == KNetworkAttachmentType_Bridged
    807 #if defined (Q_WS_WIN) && defined (VBOX_WITH_NETFLT)
    808                 || type == KNetworkAttachmentType_HostOnly
    809 #endif
    810                 ) && page->interfaceName().isNull())
    811         {
    812             valid = false;
    813             aWarning = tr ("No host network interface is selected");
    814         } else
    815 #endif
    816         if (type == KNetworkAttachmentType_Internal &&
    817             page->mCbNetwork->currentText().isEmpty())
    818         {
    819             valid = false;
    820             aWarning = tr ("Internal network name is not set");
    821         }
    822 
    823         if (!valid)
    824         {
    825             aTitle += ": " + vboxGlobal().removeAccelMark (page->pageTitle());
    826             break;
    827         }
     479        valid = page->revalidate (aWarning, aTitle);
     480        if (!valid) break;
    828481    }
    829482
     
    836489    {
    837490        VBoxVMSettingsNetwork *page =
    838             static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
     491            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
     492        Assert (page);
    839493        mTwAdapters->setTabText (i, page->pageTitle());
    840494    }
    841495}
    842496
    843 void VBoxVMSettingsNetworkPage::updateNetworksList()
    844 {
    845     /* Lock to prevent few simultaneously update */
    846     if (mLockNetworkListUpdate)
    847         return;
    848     mLockNetworkListUpdate = true;
    849 
    850     /* Compose latest list from current + new on all pages */
    851     QStringList curList (mListNetworks);
    852     for (int index = 0; index < mTwAdapters->count(); ++ index)
    853     {
    854         VBoxVMSettingsNetwork *page =
    855             static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
    856         if (page)
    857         {
    858             QString curText = page->mCbNetwork->currentText();
    859             if (!curText.isEmpty() && !curList.contains (curText))
    860                 curList << curText;
    861         }
    862     }
    863 
    864     /* Load latest list to all pages */
    865     for (int index = 0; index < mTwAdapters->count(); ++ index)
    866     {
    867         VBoxVMSettingsNetwork *page =
    868             static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
    869         if (page)
    870             page->setNetworksList (curList);
    871     }
    872 
    873     /* Allow further Network List update */
    874     mLockNetworkListUpdate = false;
    875 }
    876 
    877 #if defined (VBOX_WITH_NETFLT)
    878 void VBoxVMSettingsNetworkPage::updateInterfaceList()
    879 {
    880     VBoxVMSettingsNetwork *page =
    881         static_cast <VBoxVMSettingsNetwork*> (mTwAdapters->currentWidget());
    882     KNetworkAttachmentType enmType = vboxGlobal().toNetworkAttachmentType (page->mCbNAType->currentText());
    883 
    884     bool isHostInterfaceAttached = enmType == KNetworkAttachmentType_Bridged;
    885 
    886     mNIList->setEnabled (isHostInterfaceAttached);
    887 # ifdef Q_WS_WIN
    888     if(!isHostInterfaceAttached)
    889     {
    890         mNIList->setEnabled (enmType == KNetworkAttachmentType_HostOnly);
    891     }
    892     mNIList->updateInterfacesList(enmType);
    893 # endif
    894 }
    895 #endif
    896 
    897 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)
    898 void VBoxVMSettingsNetworkPage::onCurrentPageChanged (int aIndex)
    899 {
    900     VBoxVMSettingsNetwork *page =
    901         static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (aIndex));
    902     Assert (page);
    903     mNIList->setCurrentInterface (page->interfaceName());
    904 
    905 #if defined (VBOX_WITH_NETFLT)
    906     updateInterfaceList();
    907 #endif
    908 }
    909 
    910 void VBoxVMSettingsNetworkPage::onCurrentInterfaceChanged (const QString &aName)
    911 {
    912     VBoxVMSettingsNetwork *page =
    913         static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->currentWidget());
    914     Assert (page);
    915     page->setInterfaceName (aName);
    916 }
    917 #endif
    918 
    919 void VBoxVMSettingsNetworkPage::populateNetworksList()
    920 {
    921     /* Clear inner list */
    922     mListNetworks.clear();
    923 
    924     /* Load internal network list */
    925     CVirtualBox vbox = vboxGlobal().virtualBox();
    926     ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());
    927     CMachineVector vec =  vbox.GetMachines();
    928     for (CMachineVector::ConstIterator m = vec.begin();
    929          m != vec.end(); ++ m)
    930     {
    931         if (m->GetAccessible())
    932         {
    933             for (ulong slot = 0; slot < count; ++ slot)
    934             {
    935                 CNetworkAdapter adapter = m->GetNetworkAdapter (slot);
    936                 if (adapter.GetAttachmentType() == KNetworkAttachmentType_Internal &&
    937                     !mListNetworks.contains (adapter.GetInternalNetwork()))
    938                     mListNetworks << adapter.GetInternalNetwork();
    939             }
    940         }
    941     }
    942 
    943     /* Allow further Network List update */
    944     mLockNetworkListUpdate = false;
    945 }
    946 
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsNetwork.ui

    r17217 r17784  
    2828  </property>
    2929  <layout class="QGridLayout" >
    30    <item row="0" column="0" colspan="2" >
     30   <item row="0" column="0" colspan="3" >
    3131    <widget class="QCheckBox" name="mGbAdapter" >
    3232     <property name="whatsThis" >
     
    7575       <widget class="QLabel" name="mLbAType" >
    7676        <property name="text" >
    77          <string>A&amp;dapter Type:</string>
     77         <string>Adapter &amp;Type:</string>
    7878        </property>
    7979        <property name="alignment" >
     
    8181        </property>
    8282        <property name="buddy" >
    83          <cstring>mCbAType</cstring>
     83         <cstring>mCbAdapterType</cstring>
    8484        </property>
    8585       </widget>
    8686      </item>
    8787      <item row="0" column="1" >
    88        <widget class="QComboBox" name="mCbAType" >
     88       <widget class="QComboBox" name="mCbAdapterType" >
    8989        <property name="whatsThis" >
    9090         <string>Selects the type of the virtual network adapter. Depending on this value, VirtualBox will provide different network hardware to the virtual machine.</string>
     91        </property>
     92       </widget>
     93      </item>
     94      <item row="0" column="2" >
     95       <widget class="QToolButton" name="mTbCable" >
     96        <property name="whatsThis" >
     97         <string>Indicates whether the virtual network cable is plugged in on machine startup or not.</string>
     98        </property>
     99        <property name="autoRaise" >
     100         <bool>true</bool>
    91101        </property>
    92102       </widget>
     
    101111        </property>
    102112        <property name="buddy" >
    103          <cstring>mCbNAType</cstring>
     113         <cstring>mCbAttachmentType</cstring>
    104114        </property>
    105115       </widget>
    106116      </item>
    107117      <item row="1" column="1" >
    108        <widget class="QComboBox" name="mCbNAType" >
     118       <widget class="QComboBox" name="mCbAttachmentType" >
    109119        <property name="whatsThis" >
    110120         <string>Controls the way how this virtual adapter is attached to the real network of the Host OS.</string>
     
    112122       </widget>
    113123      </item>
    114       <item row="2" column="0" >
    115        <widget class="QLabel" name="mLbNetwork" >
    116         <property name="text" >
    117          <string>&amp;Network Name:</string>
     124      <item row="1" column="2" >
     125       <widget class="QToolButton" name="mTbDetails" >
     126        <property name="whatsThis" >
     127         <string>Open extended settings dialog for current attachment type.</string>
    118128        </property>
    119         <property name="alignment" >
    120          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    121         </property>
    122         <property name="buddy" >
    123          <cstring>mCbNetwork</cstring>
    124         </property>
    125        </widget>
    126       </item>
    127       <item row="2" column="1" >
    128        <widget class="QComboBox" name="mCbNetwork" >
    129         <property name="whatsThis" >
    130          <string>Displays the name of the internal network selected for this adapter.</string>
    131         </property>
    132         <property name="editable" >
     129        <property name="autoRaise" >
    133130         <bool>true</bool>
    134         </property>
    135        </widget>
    136       </item>
    137       <item row="3" column="0" >
    138        <widget class="QLabel" name="mLbMAC" >
    139         <property name="text" >
    140          <string>&amp;MAC Address:</string>
    141         </property>
    142         <property name="alignment" >
    143          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    144         </property>
    145         <property name="buddy" >
    146          <cstring>mLeMAC</cstring>
    147         </property>
    148        </widget>
    149       </item>
    150       <item row="3" column="1" >
    151        <widget class="QLineEdit" name="mLeMAC" >
    152         <property name="sizePolicy" >
    153          <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
    154           <horstretch>0</horstretch>
    155           <verstretch>0</verstretch>
    156          </sizepolicy>
    157         </property>
    158         <property name="whatsThis" >
    159          <string>Displays the MAC address of this adapter. It contains exactly 12 characters chosen from {0-9,A-F}. Note that the second character must be an even digit.</string>
    160         </property>
    161        </widget>
    162       </item>
    163       <item row="3" column="2" >
    164        <widget class="QPushButton" name="mPbMAC" >
    165         <property name="whatsThis" >
    166          <string>Generates a new random MAC address.</string>
    167         </property>
    168         <property name="text" >
    169          <string>&amp;Generate</string>
    170         </property>
    171        </widget>
    172       </item>
    173       <item row="4" column="1" >
    174        <widget class="QCheckBox" name="mCbCable" >
    175         <property name="whatsThis" >
    176          <string>Indicates whether the virtual network cable is plugged in on machine startup or not.</string>
    177         </property>
    178         <property name="text" >
    179          <string>Ca&amp;ble Connected</string>
    180         </property>
    181        </widget>
    182       </item>
    183       <item row="5" column="0" colspan="3" >
    184        <widget class="QILabelSeparator" name="mGbTap" >
    185         <property name="text" >
    186          <string>Host Interface Settings</string>
    187         </property>
    188         <property name="buddy" >
    189          <cstring>mLeInterface_x11</cstring>
    190         </property>
    191        </widget>
    192       </item>
    193       <item row="6" column="0" >
    194        <widget class="QLabel" name="mLbInterface_x11" >
    195         <property name="text" >
    196          <string>&amp;Interface Name:</string>
    197         </property>
    198         <property name="alignment" >
    199          <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    200         </property>
    201         <property name="buddy" >
    202          <cstring>mLeInterface_x11</cstring>
    203         </property>
    204        </widget>
    205       </item>
    206       <item row="6" column="1" >
    207        <widget class="QLineEdit" name="mLeInterface_x11" >
    208         <property name="sizePolicy" >
    209          <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
    210           <horstretch>0</horstretch>
    211           <verstretch>0</verstretch>
    212          </sizepolicy>
    213         </property>
    214         <property name="whatsThis" >
    215          <string>Displays the TAP interface name.</string>
    216131        </property>
    217132       </widget>
     
    248163  </layout>
    249164 </widget>
    250  <customwidgets>
    251   <customwidget>
    252    <class>QILabelSeparator</class>
    253    <extends>QLabel</extends>
    254    <header>QILabelSeparator.h</header>
    255   </customwidget>
    256  </customwidgets>
    257165 <resources/>
    258166 <connections>
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