VirtualBox

Changeset 9951 in vbox


Ignore:
Timestamp:
Jun 26, 2008 12:17:43 PM (16 years ago)
Author:
vboxsync
Message:

Fe/Qt4: VBox VM Network Settings (for windows) ported to qt4.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsNetwork.h

    r9751 r9951  
    2828#include "COMDefs.h"
    2929
     30class QIWidgetValidator;
    3031class VBoxVMSettingsDlg;
    31 class QIWidgetValidator;
     32#ifdef Q_WS_WIN
     33class QTreeWidget;
     34class QTreeWidgetItem;
     35#endif
    3236
     37/*
     38 * QWidget sub-class which represents one tab-page per each network adapter.
     39 * It has generated UI part.
     40 */
    3341class VBoxVMSettingsNetwork : public QIWithRetranslateUI<QWidget>,
    3442                              public Ui::VBoxVMSettingsNetwork
     
    3846public:
    3947
    40     VBoxVMSettingsNetwork (QWidget *aParent = NULL);
    41 
    42     static void getFromMachine (const CMachine &aMachine,
    43                                 QWidget *aPage,
    44                                 VBoxVMSettingsDlg *aDlg,
    45                                 const QString &aPath);
    46     static void putBackToMachine();
    47     static bool revalidate (QString &aWarning, QString &aTitle);
    48 
    49     void loadListNetworks (const QStringList &aList);
     48    VBoxVMSettingsNetwork();
    5049
    5150    void getFromAdapter (const CNetworkAdapter &aAdapter);
    5251    void putBackToAdapter();
    5352
     53    QString pageTitle() const;
     54
    5455    void setValidator (QIWidgetValidator *aValidator);
     56    void setNetworksList (const QStringList &aList);
     57
     58#ifdef Q_WS_WIN
     59    void setInterfaceName (const QString &);
     60    QString interfaceName() const;
     61#endif
    5562
    5663protected:
     
    5966
    6067private slots:
    61 
    62     static void updateListNetworks();
    63 // #ifdef Q_WS_WIN
    64 //     static void addHostInterface();
    65 //     static void delHostInterface();
    66 // #endif
    6768
    6869    void adapterToggled (bool aOn);
     
    7677private:
    7778
    78     QString pageTitle() const;
    7979    void prepareComboboxes();
    8080
    81     static void prepareListNetworks();
    82 // #ifdef Q_WS_WIN
    83 //     static void prepareListInterfaces();
    84 // #endif
     81    CNetworkAdapter mAdapter;
     82    QIWidgetValidator *mValidator;
     83
     84#ifdef Q_WS_WIN
     85    QString mInterfaceName;
     86#endif
     87};
     88
     89
     90#ifdef Q_WS_WIN
     91/*
     92 * QGroupBox sub-class which represents network interface list.
     93 */
     94class VBoxNIList : public QIWithRetranslateUI<QGroupBox>
     95{
     96    Q_OBJECT;
     97
     98public:
     99
     100    VBoxNIList (QWidget *aParent);
     101
     102    bool isWrongInterface() const;
     103    void setCurrentInterface (const QString &aName);
     104
     105signals:
     106
     107    void listChanged();
     108    void currentInterfaceChanged (const QString &);
     109
     110private slots:
     111
     112    void onCurrentItemChanged (QTreeWidgetItem *aCurrent, QTreeWidgetItem *aPrev = 0);
     113    void addHostInterface();
     114    void delHostInterface();
     115
     116protected:
     117
     118    void retranslateUi();
     119
     120private:
     121
     122    void populateInterfacesList();
     123
     124    QTreeWidget *mList;
     125
     126    QAction *mAddAction;
     127    QAction *mDelAction;
     128};
     129#endif
     130
     131
     132/*
     133 * QWidget sub-class which represents network settings page itself.
     134 */
     135class VBoxVMSettingsNetworkPage : public QIWithRetranslateUI<QWidget>
     136{
     137    Q_OBJECT;
     138
     139public:
     140
     141    static void getFromMachine (const CMachine &aMachine,
     142                                QWidget *aPage,
     143                                VBoxVMSettingsDlg *aDlg,
     144                                const QString &aPath);
     145    static void putBackToMachine();
     146    static bool revalidate (QString &aWarning, QString &aTitle);
     147
     148protected slots:
     149
     150    void updateNetworksList();
     151#ifdef Q_WS_WIN
     152    void onCurrentPageChanged (int);
     153    void onCurrentInterfaceChanged (const QString &);
     154#endif
     155
     156protected:
     157
     158    VBoxVMSettingsNetworkPage (QWidget *aParent);
     159
     160    void getFrom (const CMachine &aMachine,
     161                  VBoxVMSettingsDlg *aDlg,
     162                  const QString &aPath);
     163    void putBackTo();
     164    bool validate (QString &aWarning, QString &aTitle);
     165
     166    void retranslateUi();
     167
     168    void populateNetworksList();
     169
     170    static VBoxVMSettingsNetworkPage *mSettings;
    85171
    86172    /* Widgets */
    87     static QTabWidget *mTwAdapters;
    88 // #ifdef Q_WS_WIN
    89 //     static QGroupBox *mGbInterfaces;
    90 //     static QListWidget *mLwInterfaces;
    91 // #endif
     173    QTabWidget *mTwAdapters;
     174#ifdef Q_WS_WIN
     175    VBoxNIList *mNIList;
     176#endif
    92177
    93     /* Actions */
    94 // #ifdef Q_WS_WIN
    95 //     static QAction *mAddAction;
    96 //     static QAction *mDelAction;
    97 // #endif
     178    /* Lists */
     179    QStringList mListNetworks;
    98180
    99181    /* Flags */
    100     static bool mLockNetworkListUpdate;
    101 
    102     /* Lists */
    103     static QStringList mListNetworks;
    104 // #ifdef Q_WS_WIN
    105 //     static QStringList mListInterface;
    106 //     static QString mNoInterfaces;
    107 // #endif
    108 
    109     QIWidgetValidator *mValidator;
    110     CNetworkAdapter mAdapter;
    111 // #ifdef Q_WS_WIN
    112 //     QString mInterface_win;
    113 // #endif
     182    bool mLockNetworkListUpdate;
    114183};
    115184
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsUtils.h

    r9782 r9951  
    2626#include <VBoxGlobal.h>
    2727
    28 //#include <QDialog>
    29 //#include <QLineEdit>
    30 //#include <QPushButton>
     28#ifdef Q_WS_WIN
     29#include <QDialog>
     30#include <QLineEdit>
     31#include <QPushButton>
     32#endif
    3133#include <QHBoxLayout>
    3234#include <QLabel>
     
    101103};
    102104
    103 // #ifdef Q_WS_WIN
    104 // /**
    105 // *  QDialog class reimplementation to use for adding network interface.
    106 // *  It has one line-edit field for entering network interface's name and
    107 // *  common dialog's ok/cancel buttons.
    108 // */
    109 // class VBoxAddNIDialog : public QDialog
    110 // {
    111 //     Q_OBJECT
    112 //
    113 // public:
    114 //
    115 //     VBoxAddNIDialog (QWidget *aParent, const QString &aIfaceName) :
    116 //         QDialog (aParent),
    117 //         mLeName (0)
    118 //     {
    119 //         setWindowTitle (tr ("Add Host Interface"));
    120 //         QVBoxLayout *mainLayout = new QVBoxLayout (this);
    121 //
    122 //         /* Setup Input layout */
    123 //         QHBoxLayout *inputLayout = new QHBoxLayout();
    124 //         QLabel *lbName = new QLabel (tr ("Interface Name"), this);
    125 //         mLeName = new QLineEdit (aIfaceName, this);
    126 //         mLeName->setWhatsThis (tr ("Descriptive name of the new "
    127 //                                    "network interface"));
    128 //         inputLayout->addWidget (lbName);
    129 //         inputLayout->addWidget (mLeName);
    130 //         connect (mLeName, SIGNAL (textChanged (const QString &)),
    131 //                  this, SLOT (validate()));
    132 //         mainLayout->addLayout (inputLayout);
    133 //
    134 //         /* Setup Button layout */
    135 //         QHBoxLayout *buttonLayout = new QHBoxLayout();
    136 //         mBtOk = new QPushButton (tr ("&OK"), this);
    137 //         QPushButton *btCancel = new QPushButton (tr ("Cancel"), this);
    138 //         connect (mBtOk, SIGNAL (clicked()), this, SLOT (accept()));
    139 //         connect (btCancel, SIGNAL (clicked()), this, SLOT (reject()));
    140 //         buttonLayout->addWidget (mBtOk);
    141 //         buttonLayout->addStretch();
    142 //         buttonLayout->addWidget (btCancel);
    143 //         mainLayout->addLayout (buttonLayout);
    144 //
    145 //         /* resize to fit the aIfaceName in one string */
    146 //         int requiredWidth = mLeName->fontMetrics().width (aIfaceName) +
    147 //                             inputLayout->spacing() +
    148 //                             lbName->fontMetrics().width (lbName->text()) +
    149 //                             lbName->frameWidth() * 2 +
    150 //                             lbName->lineWidth() * 2 +
    151 //                             mainLayout->margin() * 2;
    152 //         resize (requiredWidth, minimumHeight());
    153 //
    154 //         /* Validate interface name field */
    155 //         validate();
    156 //     }
    157 //
    158 //     ~VBoxAddNIDialog() {}
    159 //
    160 //     QString getName() { return mLeName->text(); }
    161 //
    162 // private slots:
    163 //
    164 //     void validate()
    165 //     {
    166 //         mBtOk->setEnabled (!mLeName->text().isEmpty());
    167 //     }
    168 //
    169 // private:
    170 //
    171 //     void showEvent (QShowEvent *aEvent)
    172 //     {
    173 //         setFixedHeight (height());
    174 //         QDialog::showEvent (aEvent);
    175 //     }
    176 //
    177 //     QPushButton *mBtOk;
    178 //     QLineEdit   *mLeName;
    179 // };
    180 // #endif
     105#ifdef Q_WS_WIN
     106/**
     107 *  QDialog class reimplementation to use for adding network interface.
     108 *  It has one line-edit field for entering network interface's name and
     109 *  common dialog's ok/cancel buttons.
     110 */
     111class VBoxAddNIDialog : public QDialog
     112{
     113    Q_OBJECT
     114
     115public:
     116
     117    VBoxAddNIDialog (QWidget *aParent, const QString &aIfaceName) :
     118        QDialog (aParent),
     119        mLeName (0)
     120    {
     121        setWindowTitle (tr ("Add Host Interface"));
     122        QVBoxLayout *mainLayout = new QVBoxLayout (this);
     123
     124        /* Setup Input layout */
     125        QHBoxLayout *inputLayout = new QHBoxLayout();
     126        QLabel *lbName = new QLabel (tr ("Interface Name"), this);
     127        mLeName = new QLineEdit (aIfaceName, this);
     128        mLeName->setWhatsThis (tr ("Descriptive name of the new "
     129                                   "network interface"));
     130        inputLayout->addWidget (lbName);
     131        inputLayout->addWidget (mLeName);
     132        connect (mLeName, SIGNAL (textChanged (const QString &)),
     133                 this, SLOT (validate()));
     134        mainLayout->addLayout (inputLayout);
     135
     136        /* Setup Button layout */
     137        QHBoxLayout *buttonLayout = new QHBoxLayout();
     138        mBtOk = new QPushButton (tr ("&OK"), this);
     139        QPushButton *btCancel = new QPushButton (tr ("Cancel"), this);
     140        connect (mBtOk, SIGNAL (clicked()), this, SLOT (accept()));
     141        connect (btCancel, SIGNAL (clicked()), this, SLOT (reject()));
     142        buttonLayout->addWidget (mBtOk);
     143        buttonLayout->addStretch();
     144        buttonLayout->addWidget (btCancel);
     145        mainLayout->addLayout (buttonLayout);
     146
     147        /* Resize to fit the aIfaceName in one string */
     148        int requiredWidth = mLeName->fontMetrics().width (aIfaceName) +
     149                            inputLayout->spacing() +
     150                            lbName->fontMetrics().width (lbName->text()) +
     151                            lbName->frameWidth() * 2 +
     152                            lbName->lineWidth() * 2 +
     153                            mainLayout->margin() * 2;
     154        resize (requiredWidth, minimumHeight());
     155
     156        /* Validate interface name field */
     157        validate();
     158    }
     159
     160    ~VBoxAddNIDialog() {}
     161
     162    QString getName() { return mLeName->text(); }
     163
     164private slots:
     165
     166    void validate()
     167    {
     168        mBtOk->setEnabled (!mLeName->text().isEmpty());
     169    }
     170
     171private:
     172
     173    void showEvent (QShowEvent *aEvent)
     174    {
     175        setFixedHeight (height());
     176        QDialog::showEvent (aEvent);
     177    }
     178
     179    QPushButton *mBtOk;
     180    QLineEdit   *mLeName;
     181};
     182#endif
    181183
    182184class USBListItem : public QTreeWidgetItem
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsDlg.cpp

    r9889 r9951  
    202202
    203203    /* Network */
    204     VBoxVMSettingsNetwork::getFromMachine (aMachine, mPageNetwork,
    205                                            this, pagePath (mPageNetwork));
     204    VBoxVMSettingsNetworkPage::getFromMachine (aMachine, mPageNetwork,
     205                                               this, pagePath (mPageNetwork));
    206206
    207207    /* Serial Ports */
     
    258258
    259259    /* Network */
    260     VBoxVMSettingsNetwork::putBackToMachine();
     260    VBoxVMSettingsNetworkPage::putBackToMachine();
    261261
    262262    /* Serial ports */
     
    371371        valid = VBoxVMSettingsFD::revalidate (warningText);
    372372    else if (pg == mPageNetwork)
    373         valid = VBoxVMSettingsNetwork::revalidate (warningText, pageTitle);
     373        valid = VBoxVMSettingsNetworkPage::revalidate (warningText, pageTitle);
    374374    else if (pg == mPageSerial)
    375375        valid = VBoxVMSettingsSerial::revalidate (warningText, pageTitle);
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsNetwork.cpp

    r9751 r9951  
    2121 */
    2222
     23/* Common Includes */
    2324#include "VBoxVMSettingsNetwork.h"
    2425#include "VBoxVMSettingsDlg.h"
    2526#include "QIWidgetValidator.h"
    2627#include "VBoxGlobal.h"
    27 
    28 /* Qt includes */
     28#ifdef Q_WS_WIN
     29#include "VBoxToolBar.h"
     30#include "VBoxVMSettingsUtils.h"
     31#include "VBoxProblemReporter.h"
     32#endif
     33
     34/* Qt Includes */
     35#ifdef Q_WS_X11
    2936#include <QFileDialog>
    30 
    31 // #ifdef Q_WS_WIN
    32 // static QListWidgetItem* findItem (QListWidget *aList,
    33 //                                   const QString &aMatch)
    34 // {
    35 //     QList<QListWidgetItem*> list =
    36 //         aList->findItems (aMatch, Qt::MatchExactly);
    37 //
    38 //     return list.count() ? list [0] : 0;
    39 // }
    40 //#endif
    41 
    42 /* Initialization of variables common for all pages */
    43 QTabWidget* VBoxVMSettingsNetwork::mTwAdapters = 0;
    44 // #ifdef Q_WS_WIN
    45 // QGroupBox* VBoxVMSettingsNetwork::mGbInterfaces = 0;
    46 // QListWidget* VBoxVMSettingsNetwork::mLwInterfaces = 0;
    47 // QAction* VBoxVMSettingsNetwork::mAddAction = 0;
    48 // QAction* VBoxVMSettingsNetwork::mDelAction = 0;
    49 // #endif
    50 bool VBoxVMSettingsNetwork::mLockNetworkListUpdate = true;
    51 QStringList VBoxVMSettingsNetwork::mListNetworks = QStringList();
    52 // #ifdef Q_WS_WIN
    53 // QStringList VBoxVMSettingsNetwork::mListInterface = QStringList();
    54 // QString VBoxVMSettingsNetwork::mNoInterfaces = tr ("<No suitable interfaces>");
    55 // #endif
    56 
    57 VBoxVMSettingsNetwork::VBoxVMSettingsNetwork(QWidget *aParent /* = NULL */)
    58     : QIWithRetranslateUI<QWidget> (aParent)
     37#endif
     38#ifdef Q_WS_WIN
     39#include <QTreeWidget>
     40#endif
     41
     42/* Common Stuff */
     43#ifdef Q_WS_WIN
     44static QTreeWidgetItem* findItem (QTreeWidget *aList,
     45                                  const QString &aMatch)
     46{
     47    QList<QTreeWidgetItem*> list =
     48        aList->findItems (aMatch, Qt::MatchExactly, 0);
     49    return list.count() ? list [0] : 0;
     50}
     51#endif
     52
     53
     54/* VBoxVMSettingsNetwork Stuff */
     55VBoxVMSettingsNetwork::VBoxVMSettingsNetwork()
     56    : QIWithRetranslateUI<QWidget> (0)
    5957    , mValidator (0)
    6058{
     
    6765
    6866    /* Setup dialog for current platform */
    69 
    7067#ifndef Q_WS_X11
    7168    mGbTAP->setHidden (true);
    7269#endif
    73 
    7470#ifdef Q_WS_MAC
    7571    /* No Host Interface Networking on the Mac yet */
    7672    mGbTAP->setHidden (true);
    7773#endif
    78 
    7974#ifdef Q_WS_X11
    8075    /* Setup iconsets */
     
    8984}
    9085
    91 void VBoxVMSettingsNetwork::getFromMachine (const CMachine &aMachine,
    92                                             QWidget *aPage,
    93                                             VBoxVMSettingsDlg *aDlg,
    94                                             const QString &aPath)
    95 {
    96     /* Creating Page Layout */
    97     QVBoxLayout *layout = new QVBoxLayout (aPage);
    98     layout->setContentsMargins (0, 5, 0, 0);
    99 
    100     /* Creating Tab Widget */
    101     mTwAdapters = new QTabWidget (aPage);
    102     layout->addWidget (mTwAdapters);
    103 
    104     /* Prepare networks & interfaces lists */
    105     prepareListNetworks();
    106 // #ifdef Q_WS_WIN
    107 //     prepareListInterfaces();
    108 // #endif
    109 
    110 // #ifdef Q_WS_WIN
    111 //     /* Creating Tree Widget */
    112 //     mGbInterfaces = new QGroupBox (aPage);
    113 //     layout->addWidget (mGbInterfaces);
    114 //     QHBoxLayout *iLayout = new QHBoxLayout (mGbInterfaces);
    115 //     mLwInterfaces = new QListWidget (mGbInterfaces);
    116 //     mLwInterfaces->setContextMenuPolicy (Qt::ActionsContextMenu);
    117 //     iLayout->addWidget (mLwInterfaces);
    118 //
    119 //     /* Prepare actions */
    120 //     mAddAction = new QAction (mLwInterfaces);
    121 //     mDelAction = new QAction (mLwInterfaces);
    122 //     mAddAction->setText (tr ("A&dd New Host Interface"));
    123 //     mDelAction->setText (tr ("&Remove Selected Host Interface"));
    124 //     mAddAction->setShortcut (QKeySequence ("Ins"));
    125 //     mDelAction->setShortcut (QKeySequence ("Del"));
    126 //     mAddAction->setToolTip (mAddAction->text().remove ('&') +
    127 //         QString (" (%1)").arg (mAddAction->shortcut().toString()));
    128 //     mDelAction->setToolTip (mDelAction->text().remove ('&') +
    129 //         QString (" (%1)").arg (mDelAction->shortcut().toString()));
    130 //     mAddAction->setWhatsThis (tr ("Adds a new host interface."));
    131 //     mDelAction->setWhatsThis (tr ("Removes the selected host interface."));
    132 //     mAddAction->setIcon (VBoxGlobal::iconSet (":/add_host_iface_16px.png",
    133 //                                               ":/add_host_iface_disabled_16px.png"));
    134 //     mDelAction->setIcon (VBoxGlobal::iconSet (":/remove_host_iface_16px.png",
    135 //                                               ":/remove_host_iface_disabled_16px.png"));
    136 //     connect (mAddAction, SIGNAL (clicked()), this, SLOT (addHostInterface()));
    137 //     connect (mDelAction, SIGNAL (clicked()), this, SLOT (delHostInterface()));
    138 //
    139 //     /* Prepare toolbar */
    140 //     VBoxToolBar *toolBar = new VBoxToolBar (mGbInterfaces);
    141 //     toolBar->setUsesTextLabel (false);
    142 //     toolBar->setUsesBigPixmaps (false);
    143 //     toolBar->setOrientation (Qt::Vertical);
    144 //     toolBar->addAction (mAddAction);
    145 //     toolBar->addAction (mDelAction);
    146 //     iLayout->addWidget (toolBar);
    147 // #endif
    148 
    149     /* Creating Tab Pages */
    150     CVirtualBox vbox = vboxGlobal().virtualBox();
    151     ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
    152     for (ulong slot = 0; slot < count; ++ slot)
    153     {
    154         /* Get Adapter */
    155         CNetworkAdapter adapter = aMachine.GetNetworkAdapter (slot);
    156 
    157         /* Creating Adapter's page */
    158         VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork();
    159 
    160         /* Set the mAdapter member which is necessary for next pageTitle call. */
    161         page->mAdapter = adapter;
    162         /* Setup validation */
    163         QIWidgetValidator *wval =
    164             new QIWidgetValidator (QString ("%1: %2").arg (aPath, page->pageTitle()),
    165                                    aPage, aDlg);
    166         connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
    167                  aDlg, SLOT (enableOk (const QIWidgetValidator*)));
    168         connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
    169                  aDlg, SLOT (revalidate (QIWidgetValidator*)));
    170 
    171         page->setValidator (wval);
    172 
    173         /* Loading Adapter's data into page */
    174         page->loadListNetworks (mListNetworks);
    175         page->getFromAdapter (adapter);
    176 
    177         /* Attach Adapter's page to Tab Widget */
    178         mTwAdapters->addTab (page, page->pageTitle());
    179     }
    180 
    181     layout->addStretch();
    182 }
    183 
    184 void VBoxVMSettingsNetwork::putBackToMachine()
    185 {
    186     for (int index = 0; index < mTwAdapters->count(); ++ index)
    187     {
    188         VBoxVMSettingsNetwork *page =
    189             static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
    190         if (page)
    191             page->putBackToAdapter();
    192     }
    193 }
    194 
    195 bool VBoxVMSettingsNetwork::revalidate (QString &aWarning, QString &aTitle)
    196 {
    197     bool valid = true;
    198 
    199     for (int index = 0; index < mTwAdapters->count(); ++ index)
    200     {
    201         VBoxVMSettingsNetwork *page =
    202             static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
    203         Assert (page);
    204 
    205         KNetworkAttachmentType type =
    206             vboxGlobal().toNetworkAttachmentType (page->mCbNAType->currentText());
    207 
    208 // #ifdef Q_WS_WIN
    209 //         if (type == KNetworkAttachmentType_HostInterface &&
    210 //             mListInterface.indexOf (mLwInterfaces->currentItem()->text()) == -1)
    211 //         {
    212 //             valid = false;
    213 //             aWarning = tr ("Incorrect host network interface is selected");
    214 //         }
    215 //         else
    216 // #endif
    217         if (type == KNetworkAttachmentType_Internal &&
    218             page->mCbNetwork->currentText().isEmpty())
    219         {
    220             valid = false;
    221             aWarning = tr ("Internal network name is not set");
    222         }
    223 
    224         if (!valid)
    225         {
    226             aTitle += ": " +
    227                 mTwAdapters->tabText (mTwAdapters->indexOf (page));
    228             break;
    229         }
    230     }
    231 
    232     return valid;
    233 }
    234 
    235 void VBoxVMSettingsNetwork::loadListNetworks (const QStringList &aList)
    236 {
    237     QString curText = mCbNetwork->currentText();
    238     mCbNetwork->clear();
    239     mCbNetwork->clearEditText();
    240     mCbNetwork->insertItems (0, aList);
    241     mCbNetwork->setCurrentIndex (mCbNetwork->findText (curText));
    242     mValidator->revalidate();
    243 }
    244 
    24586void VBoxVMSettingsNetwork::getFromAdapter (const CNetworkAdapter &aAdapter)
    24687{
     
    265106    mCbNetwork->setCurrentIndex (inPos == -1 ? 0 : inPos);
    266107
    267 // #ifdef Q_WS_WIN
    268 //     mInterface_win = aAdapter.GetHostInterface();
    269 // #endif
     108#ifdef Q_WS_WIN
     109    mInterfaceName = aAdapter.GetHostInterface().isEmpty() ?
     110                     QString::null : aAdapter.GetHostInterface();
     111#endif
    270112#ifdef Q_WS_X11
    271113    mLeInterface_x11->setText (aAdapter.GetHostInterface());
     
    309151    if (type == KNetworkAttachmentType_HostInterface)
    310152    {
    311 // #ifdef Q_WS_WIN
    312 //         mAdapter.SetHostInterface (mInterface_win);
    313 // #endif
     153#ifdef Q_WS_WIN
     154        mAdapter.SetHostInterface (mInterfaceName);
     155#endif
    314156#ifdef Q_WS_X11
    315157        QString iface = mLeInterface_x11->text();
     
    325167}
    326168
     169QString VBoxVMSettingsNetwork::pageTitle() const
     170{
     171    QString pageTitle;
     172    if (!mAdapter.isNull())
     173    {
     174        pageTitle = VBoxGlobal::tr ("Adapter %1", "network")
     175            .arg (mAdapter.GetSlot());
     176    }
     177    return pageTitle;
     178}
     179
    327180void VBoxVMSettingsNetwork::setValidator (QIWidgetValidator *aValidator)
    328181{
     
    335188    connect (mCbNetwork, SIGNAL (activated (const QString&)),
    336189             mValidator, SLOT (revalidate()));
    337     connect (mCbNetwork, SIGNAL (editTextChanged (const QString&)),
    338              this, SLOT (updateListNetworks()));
    339190    connect (mPbMAC, SIGNAL (clicked()), this, SLOT (genMACClicked()));
    340191#ifdef Q_WS_X11
     
    346197}
    347198
     199void VBoxVMSettingsNetwork::setNetworksList (const QStringList &aList)
     200{
     201    QString curText = mCbNetwork->currentText();
     202    mCbNetwork->clear();
     203    mCbNetwork->clearEditText();
     204    mCbNetwork->insertItems (0, aList);
     205    mCbNetwork->setCurrentIndex (mCbNetwork->findText (curText));
     206    if (mValidator)
     207        mValidator->revalidate();
     208}
     209
     210#ifdef Q_WS_WIN
     211void VBoxVMSettingsNetwork::setInterfaceName (const QString &aName)
     212{
     213    mInterfaceName = aName;
     214    if (mValidator)
     215        mValidator->revalidate();
     216}
     217
     218QString VBoxVMSettingsNetwork::interfaceName() const
     219{
     220    return mInterfaceName;
     221}
     222#endif
    348223
    349224void VBoxVMSettingsNetwork::retranslateUi()
     
    352227    Ui::VBoxVMSettingsNetwork::retranslateUi (this);
    353228
    354     mTwAdapters->setTabText (mTwAdapters->indexOf (this), pageTitle());
    355 
    356229    prepareComboboxes();
    357230}
    358231
     232void VBoxVMSettingsNetwork::adapterToggled (bool aOn)
     233{
     234    if (!aOn)
     235    {
     236        mCbNAType->setCurrentIndex (0);
     237        naTypeChanged (mCbNAType->currentText());
     238    }
     239    if (mValidator)
     240        mValidator->revalidate();
     241}
    359242
    360243void VBoxVMSettingsNetwork::naTypeChanged (const QString &aString)
     
    369252    mGbTAP->setEnabled (enableHostIf);
    370253#endif
    371     mValidator->revalidate();
     254    if (mValidator)
     255        mValidator->revalidate();
    372256}
    373257
     
    397281}
    398282#endif
    399 
    400 void VBoxVMSettingsNetwork::adapterToggled (bool aOn)
    401 {
    402     if (!aOn)
    403     {
    404         mCbNAType->setCurrentIndex (0);
    405         naTypeChanged (mCbNAType->currentText());
    406     }
    407     mValidator->revalidate();
    408 }
    409 
    410 void VBoxVMSettingsNetwork::updateListNetworks()
    411 {
    412     if (mLockNetworkListUpdate)
    413         return;
    414     mLockNetworkListUpdate = true;
    415 
    416     QStringList curList (mListNetworks);
    417     for (int index = 0; index < mTwAdapters->count(); ++ index)
    418     {
    419         VBoxVMSettingsNetwork *page =
    420             static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
    421         if (page)
    422         {
    423             QString curText = page->mCbNetwork->currentText();
    424             if (!curText.isEmpty() && !curList.contains (curText))
    425                 curList << curText;
    426         }
    427     }
    428 
    429     for (int index = 0; index < mTwAdapters->count(); ++ index)
    430     {
    431         VBoxVMSettingsNetwork *page =
    432             static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
    433         if (page)
    434             page->loadListNetworks (curList);
    435     }
    436 
    437     mLockNetworkListUpdate = false;
    438 }
    439 
    440 // #ifdef Q_WS_WIN
    441 // void VBoxVMSettingsNetwork::addHostInterface()
    442 // {
    443 //     /* Allow the started helper process to make itself the foreground window */
    444 //     AllowSetForegroundWindow (ASFW_ANY);
    445 //
    446 //     /* Search for the max available interface index */
    447 //     int ifaceNumber = 0;
    448 //     QString ifaceName = tr ("VirtualBox Host Interface %1");
    449 //     QRegExp regExp (QString ("^") + ifaceName.arg ("([0-9]+)") + QString ("$"));
    450 //     for (int index = 0; index < mLwInterfaces->count(); ++ index)
    451 //     {
    452 //         QString iface = mLwInterfaces->item (index)->text();
    453 //         int pos = regExp.indexIn (iface);
    454 //         if (pos != -1)
    455 //             ifaceNumber = regExp.cap (1).toInt() > ifaceNumber ?
    456 //                           regExp.cap (1).toInt() : ifaceNumber;
    457 //     }
    458 //
    459 //     /* Creating add host interface dialog */
    460 //     VBoxAddNIDialog dlg (this, ifaceName.arg (++ ifaceNumber));
    461 //     if (dlg.exec() != QDialog::Accepted)
    462 //         return;
    463 //     QString iName = dlg.getName();
    464 //
    465 //     /* Create interface */
    466 //     CHost host = vboxGlobal().virtualBox().GetHost();
    467 //     CHostNetworkInterface iFace;
    468 //     CProgress progress = host.CreateHostNetworkInterface (iName, iFace);
    469 //     if (host.isOk())
    470 //     {
    471 //         vboxProblem().showModalProgressDialog (progress, iName, this);
    472 //         if (progress.GetResultCode() == 0)
    473 //         {
    474 //             /* Add&Select newly created interface */
    475 //             delete findItem (mLwInterfaces, mNoInterfaces);
    476 //             mLwInterfaces->addItem (iName);
    477 //             mListInterface += iName;
    478 //             mLwInterfaces->setCurrentItem (mLwInterfaces->count() - 1);
    479 //             /* Enable interface delete button */
    480 //             mTbRemInterface->setEnabled (true);
    481 //         }
    482 //         else
    483 //             vboxProblem().cannotCreateHostInterface (progress, iName, this);
    484 //     }
    485 //     else
    486 //         vboxProblem().cannotCreateHostInterface (host, iName, this);
    487 //
    488 //     /* Allow the started helper process to make itself the foreground window */
    489 //     AllowSetForegroundWindow (ASFW_ANY);
    490 // }
    491 //
    492 // void VBoxVMSettingsNetwork::delHostInterface()
    493 // {
    494 //     /* Allow the started helper process to make itself the foreground window */
    495 //     AllowSetForegroundWindow (ASFW_ANY);
    496 //
    497 //     /* Check interface name */
    498 //     QString iName = mLwInterfaces->currentItem()->text();
    499 //     if (iName.isEmpty())
    500 //         return;
    501 //
    502 //     /* Asking user about deleting selected network interface */
    503 //     int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question,
    504 //         tr ("<p>Do you want to remove the selected host network interface "
    505 //             "<nobr><b>%1</b>?</nobr></p>"
    506 //             "<p><b>Note:</b> This interface may be in use by one or more "
    507 //             "network adapters of this or another VM. After it is removed, these "
    508 //             "adapters will no longer work until you correct their settings by "
    509 //             "either choosing a different interface name or a different adapter "
    510 //             "attachment type.</p>").arg (iName),
    511 //         0, /* autoConfirmId */
    512 //         QIMessageBox::Ok | QIMessageBox::Default,
    513 //         QIMessageBox::Cancel | QIMessageBox::Escape);
    514 //     if (delNetIface == QIMessageBox::Cancel)
    515 //         return;
    516 //
    517 //     CHost host = vboxGlobal().virtualBox().GetHost();
    518 //     CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
    519 //     if (host.isOk())
    520 //     {
    521 //         /* Delete interface */
    522 //         CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
    523 //         if (host.isOk())
    524 //         {
    525 //             vboxProblem().showModalProgressDialog (progress, iName, this);
    526 //             if (progress.GetResultCode() == 0)
    527 //             {
    528 //                 if (mLwInterfaces->count() == 1)
    529 //                 {
    530 //                     mLwInterfaces->addItem (mNoInterfaces);
    531 //                     /* Disable interface delete button */
    532 //                     mTbRemInterface->setEnabled (false);
    533 //                 }
    534 //                 delete findItem (mLwInterfaces, iName);
    535 //                 mLwInterfaces->currentItem()->setSelected (true);
    536 //                 mListInterface.erase (mListInterface.find (iName));
    537 //             }
    538 //             else
    539 //                 vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
    540 //         }
    541 //     }
    542 //
    543 //     if (!host.isOk())
    544 //         vboxProblem().cannotRemoveHostInterface (host, iFace, this);
    545 // }
    546 // #endif
    547 
    548 QString VBoxVMSettingsNetwork::pageTitle() const
    549 {
    550     QString pageTitle;
    551     if (!mAdapter.isNull())
    552     {
    553         pageTitle = QString (tr ("Adapter %1", "network"))
    554             .arg (mAdapter.GetSlot());
    555     }
    556     return pageTitle;
    557 }
    558283
    559284void VBoxVMSettingsNetwork::prepareComboboxes()
     
    596321}
    597322
    598 void VBoxVMSettingsNetwork::prepareListNetworks()
     323
     324/* VBoxNIList Stuff */
     325#ifdef Q_WS_WIN
     326class VBoxNIListItem : public QTreeWidgetItem
     327{
     328public:
     329
     330    enum { typeId = QTreeWidgetItem::UserType + 1 };
     331
     332    VBoxNIListItem (QTreeWidget *aParent, const QString &aName, bool aWrong = false)
     333        : QTreeWidgetItem (aParent, QStringList (aName), typeId)
     334        , mWrong (aWrong)
     335    {
     336        init();
     337    }
     338
     339    VBoxNIListItem (const QString &aName, bool aWrong = false)
     340        : QTreeWidgetItem (QStringList (aName), typeId)
     341        , mWrong (aWrong)
     342    {
     343        init();
     344    }
     345
     346    void init()
     347    {
     348        /* Force the fake item's font to italic */
     349        if (mWrong)
     350        {
     351            QFont fnt = font (0);
     352            fnt.setItalic (true);
     353            setFont (0, fnt);
     354        }
     355    }
     356
     357    bool isWrong() { return mWrong; }
     358
     359private:
     360
     361    bool mWrong;
     362};
     363
     364VBoxNIList::VBoxNIList (QWidget *aParent)
     365    : QIWithRetranslateUI<QGroupBox> (aParent)
     366{
     367    /* Creating List Widget */
     368    QHBoxLayout *layout = new QHBoxLayout (this);
     369    mList = new QTreeWidget (this);
     370    mList->setColumnCount (1);
     371    mList->header()->hide();
     372    mList->setContextMenuPolicy (Qt::ActionsContextMenu);
     373    mList->setRootIsDecorated (false);
     374    layout->addWidget (mList);
     375
     376    /* Prepare actions */
     377    mAddAction = new QAction (mList);
     378    mDelAction = new QAction (mList);
     379    mList->addAction (mAddAction);
     380    mList->addAction (mDelAction);
     381    mAddAction->setShortcut (QKeySequence ("Ins"));
     382    mDelAction->setShortcut (QKeySequence ("Del"));
     383    mAddAction->setIcon (VBoxGlobal::iconSet (":/add_host_iface_16px.png",
     384                                              ":/add_host_iface_disabled_16px.png"));
     385    mDelAction->setIcon (VBoxGlobal::iconSet (":/remove_host_iface_16px.png",
     386                                              ":/remove_host_iface_disabled_16px.png"));
     387
     388    /* Prepare toolbar */
     389    VBoxToolBar *toolBar = new VBoxToolBar (this);
     390    toolBar->setUsesTextLabel (false);
     391    toolBar->setUsesBigPixmaps (false);
     392    toolBar->setOrientation (Qt::Vertical);
     393    toolBar->addAction (mAddAction);
     394    toolBar->addAction (mDelAction);
     395    layout->addWidget (toolBar);
     396
     397    /* Setup connections */
     398    connect (mList, SIGNAL (currentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)),
     399             this, SLOT (onCurrentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)));
     400    connect (mAddAction, SIGNAL (triggered (bool)),
     401             this, SLOT (addHostInterface()));
     402    connect (mDelAction, SIGNAL (triggered (bool)),
     403             this, SLOT (delHostInterface()));
     404
     405    /* Populating interface list */
     406    populateInterfacesList();
     407
     408    /* Applying language settings */
     409    retranslateUi();
     410}
     411
     412bool VBoxNIList::isWrongInterface() const
     413{
     414    return !mList->currentItem();
     415}
     416
     417void VBoxNIList::setCurrentInterface (const QString &aName)
     418{
     419    /* Remove wrong item if present */
     420    for (int i = 0; i < mList->topLevelItemCount(); ++ i)
     421    {
     422        VBoxNIListItem *item =
     423            mList->topLevelItem (i)->type() == VBoxNIListItem::typeId ?
     424            static_cast<VBoxNIListItem*> (mList->topLevelItem (i)) : 0;
     425        Assert (item);
     426        if (item && item->isWrong())
     427            delete item;
     428    }
     429
     430    if (aName.isEmpty())
     431    {
     432        /* Make sure no one of items selected in the list currently */
     433        mList->setCurrentItem (0);
     434        mList->clearSelection();
     435    }
     436    else
     437    {
     438        /* Search for the required item */
     439        QTreeWidgetItem *querryItem = findItem (mList, aName);
     440
     441        /* Create fake required item if real is not present */
     442        if (!querryItem)
     443            querryItem = new VBoxNIListItem (mList, aName, true);
     444
     445        /* Set the required item to be the current */
     446        mList->setCurrentItem (querryItem);
     447    }
     448}
     449
     450void VBoxNIList::onCurrentItemChanged (QTreeWidgetItem *aCurrent,
     451                                       QTreeWidgetItem *)
     452{
     453    VBoxNIListItem *item = aCurrent &&
     454        aCurrent->type() == VBoxNIListItem::typeId ?
     455        static_cast<VBoxNIListItem*> (aCurrent) : 0;
     456    mDelAction->setEnabled (item && !item->isWrong());
     457
     458    emit currentInterfaceChanged (mList->currentItem() ?
     459        mList->currentItem()->text (0) : QString::null);
     460}
     461
     462void VBoxNIList::addHostInterface()
     463{
     464    /* Allow the started helper process to make itself the foreground window */
     465    AllowSetForegroundWindow (ASFW_ANY);
     466
     467    /* Search for the max available interface index */
     468    int ifaceNumber = 0;
     469    QString ifaceName = tr ("VirtualBox Host Interface %1");
     470    QRegExp regExp (QString ("^") + ifaceName.arg ("([0-9]+)") + QString ("$"));
     471    for (int index = 0; index < mList->topLevelItemCount(); ++ index)
     472    {
     473        QString iface = mList->topLevelItem (index)->text (0);
     474        int pos = regExp.indexIn (iface);
     475        if (pos != -1)
     476            ifaceNumber = regExp.cap (1).toInt() > ifaceNumber ?
     477                          regExp.cap (1).toInt() : ifaceNumber;
     478    }
     479
     480    /* Creating add host interface dialog */
     481    VBoxAddNIDialog dlg (this, ifaceName.arg (++ ifaceNumber));
     482    if (dlg.exec() != QDialog::Accepted)
     483        return;
     484    QString iName = dlg.getName();
     485
     486    /* Create interface */
     487    CHost host = vboxGlobal().virtualBox().GetHost();
     488    CHostNetworkInterface iFace;
     489    CProgress progress = host.CreateHostNetworkInterface (iName, iFace);
     490    if (host.isOk())
     491    {
     492        vboxProblem().showModalProgressDialog (progress, iName, this);
     493        /* Add&Select newly created interface */
     494        if (progress.GetResultCode() == 0)
     495            new VBoxNIListItem (mList, iName);
     496        else
     497            vboxProblem().cannotCreateHostInterface (progress, iName, this);
     498    }
     499    else
     500        vboxProblem().cannotCreateHostInterface (host, iName, this);
     501
     502    emit listChanged();
     503
     504    /* Allow the started helper process to make itself the foreground window */
     505    AllowSetForegroundWindow (ASFW_ANY);
     506}
     507
     508void VBoxNIList::delHostInterface()
     509{
     510    Assert (mList->currentItem());
     511
     512    /* Allow the started helper process to make itself the foreground window */
     513    AllowSetForegroundWindow (ASFW_ANY);
     514
     515    /* Check interface name */
     516    QString iName = mList->currentItem()->text (0);
     517    if (iName.isEmpty())
     518        return;
     519
     520    /* Asking user about deleting selected network interface */
     521    int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question,
     522        tr ("<p>Do you want to remove the selected host network interface "
     523            "<nobr><b>%1</b>?</nobr></p>"
     524            "<p><b>Note:</b> This interface may be in use by one or more "
     525            "network adapters of this or another VM. After it is removed, these "
     526            "adapters will no longer work until you correct their settings by "
     527            "either choosing a different interface name or a different adapter "
     528            "attachment type.</p>").arg (iName),
     529        0, /* autoConfirmId */
     530        QIMessageBox::Ok | QIMessageBox::Default,
     531        QIMessageBox::Cancel | QIMessageBox::Escape);
     532    if (delNetIface == QIMessageBox::Cancel)
     533        return;
     534
     535    CHost host = vboxGlobal().virtualBox().GetHost();
     536    CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
     537    if (host.isOk())
     538    {
     539        /* Delete interface */
     540        CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
     541        if (host.isOk())
     542        {
     543            vboxProblem().showModalProgressDialog (progress, iName, this);
     544            if (progress.GetResultCode() == 0)
     545                delete findItem (mList, iName);
     546            else
     547                vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
     548        }
     549    }
     550
     551    if (!host.isOk())
     552        vboxProblem().cannotRemoveHostInterface (host, iFace, this);
     553
     554    emit listChanged();
     555}
     556
     557void VBoxNIList::retranslateUi()
     558{
     559    setTitle (tr ("Host &Interfaces"));
     560
     561    mList->setWhatsThis (tr ("Lists all available host interfaces."));
     562
     563    mAddAction->setText (tr ("A&dd New Host Interface"));
     564    mDelAction->setText (tr ("&Remove Selected Host Interface"));
     565    mAddAction->setWhatsThis (tr ("Adds a new host interface."));
     566    mDelAction->setWhatsThis (tr ("Removes the selected host interface."));
     567    mAddAction->setToolTip (mAddAction->text().remove ('&') +
     568        QString (" (%1)").arg (mAddAction->shortcut().toString()));
     569    mDelAction->setToolTip (mDelAction->text().remove ('&') +
     570        QString (" (%1)").arg (mDelAction->shortcut().toString()));
     571}
     572
     573void VBoxNIList::populateInterfacesList()
     574{
     575    /* Load current inner list */
     576    QList<QTreeWidgetItem*> itemsList;
     577    CHostNetworkInterfaceEnumerator en =
     578        vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
     579    while (en.HasMore())
     580        itemsList << new VBoxNIListItem (en.GetNext().GetName());
     581
     582    /* Save current list item name */
     583    QString currentListItemName = mList->currentItem() ?
     584        mList->currentItem()->text (0) : QString::null;
     585
     586    /* Load current list items */
     587    mList->clear();
     588    if (!itemsList.isEmpty())
     589        mList->insertTopLevelItems (0, itemsList);
     590
     591    /* Select current list item */
     592    QTreeWidgetItem *item = findItem (mList, currentListItemName);
     593    mList->setCurrentItem (item ? item : mList->topLevelItem (0));
     594
     595    /* Update item's state */
     596    onCurrentItemChanged (mList->currentItem());
     597}
     598#endif
     599
     600
     601/* VBoxVMSettingsNetworkPage Stuff */
     602VBoxVMSettingsNetworkPage* VBoxVMSettingsNetworkPage::mSettings = 0;
     603
     604void VBoxVMSettingsNetworkPage::getFromMachine (const CMachine &aMachine,
     605                                                QWidget *aPage,
     606                                                VBoxVMSettingsDlg *aDlg,
     607                                                const QString &aPath)
     608{
     609    mSettings = new VBoxVMSettingsNetworkPage (aPage);
     610    QVBoxLayout *layout = new QVBoxLayout (aPage);
     611    layout->setContentsMargins (0, 5, 0, 0);
     612    layout->addWidget (mSettings);
     613    mSettings->getFrom (aMachine, aDlg, aPath);
     614}
     615
     616void VBoxVMSettingsNetworkPage::putBackToMachine()
     617{
     618    mSettings->putBackTo();
     619}
     620
     621bool VBoxVMSettingsNetworkPage::revalidate (QString &aWarning,
     622                                            QString &aTitle)
     623{
     624    return mSettings->validate (aWarning, aTitle);
     625}
     626
     627VBoxVMSettingsNetworkPage::VBoxVMSettingsNetworkPage (QWidget *aParent)
     628    : QIWithRetranslateUI<QWidget> (aParent)
     629    , mLockNetworkListUpdate (true)
     630{
     631    QVBoxLayout *layout = new QVBoxLayout (this);
     632    layout->setContentsMargins (0, 0, 0, 0);
     633
     634    /* Creating Tab Widget */
     635    mTwAdapters = new QTabWidget (aParent);
     636    layout->addWidget (mTwAdapters);
     637    /* Prepare Networks Lists */
     638    populateNetworksList();
     639
     640#ifdef Q_WS_WIN
     641    /* Creating Interfaces List */
     642    mNIList = new VBoxNIList (aParent);
     643    layout->addWidget (mNIList);
     644#else
     645    layout->addStretch();
     646#endif
     647}
     648
     649void VBoxVMSettingsNetworkPage::getFrom (const CMachine &aMachine,
     650                                         VBoxVMSettingsDlg *aDlg,
     651                                         const QString &aPath)
     652{
     653    /* Creating Tab Pages */
     654    CVirtualBox vbox = vboxGlobal().virtualBox();
     655    ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
     656    for (ulong slot = 0; slot < count; ++ slot)
     657    {
     658        /* Get Adapter */
     659        CNetworkAdapter adapter = aMachine.GetNetworkAdapter (slot);
     660
     661        /* Creating Adapter's page */
     662        VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork();
     663
     664        /* Loading Adapter's data into page */
     665        page->setNetworksList (mListNetworks);
     666        page->getFromAdapter (adapter);
     667
     668        /* Attach Adapter's page to Tab Widget */
     669        mTwAdapters->addTab (page, page->pageTitle());
     670
     671        /* Setup validation */
     672        QIWidgetValidator *wval =
     673            new QIWidgetValidator (QString ("%1: %2").arg (aPath, page->pageTitle()),
     674                                   (QWidget*)parent(), aDlg);
     675        connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
     676                 aDlg, SLOT (enableOk (const QIWidgetValidator*)));
     677        connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
     678                 aDlg, SLOT (revalidate (QIWidgetValidator*)));
     679        connect (page->mCbNetwork, SIGNAL (editTextChanged (const QString&)),
     680                 this, SLOT (updateNetworksList()));
     681#ifdef Q_WS_WIN
     682        connect (mNIList, SIGNAL (listChanged()), wval, SLOT (revalidate()));
     683#endif
     684        page->setValidator (wval);
     685    }
     686
     687#ifdef Q_WS_WIN
     688    connect (mTwAdapters, SIGNAL (currentChanged (int)),
     689             this, SLOT (onCurrentPageChanged (int)));
     690    connect (mNIList, SIGNAL (currentInterfaceChanged (const QString &)),
     691             this, SLOT (onCurrentInterfaceChanged (const QString &)));
     692    onCurrentPageChanged (mTwAdapters->currentIndex());
     693#endif
     694
     695    /* Applying language settings */
     696    retranslateUi();
     697}
     698
     699void VBoxVMSettingsNetworkPage::putBackTo()
     700{
     701    for (int i = 0; i < mTwAdapters->count(); ++ i)
     702    {
     703        VBoxVMSettingsNetwork *page = static_cast<VBoxVMSettingsNetwork*>
     704            (mTwAdapters->widget (i));
     705        if (page)
     706            page->putBackToAdapter();
     707    }
     708}
     709
     710bool VBoxVMSettingsNetworkPage::validate (QString &aWarning,
     711                                          QString &aTitle)
     712{
     713    bool valid = true;
     714
     715    for (int i = 0; i < mTwAdapters->count(); ++ i)
     716    {
     717        VBoxVMSettingsNetwork *page = static_cast<VBoxVMSettingsNetwork*>
     718            (mTwAdapters->widget (i));
     719        Assert (page);
     720
     721        KNetworkAttachmentType type =
     722            vboxGlobal().toNetworkAttachmentType (page->mCbNAType->currentText());
     723
     724#ifdef Q_WS_WIN
     725        if (type == KNetworkAttachmentType_HostInterface &&
     726            page->interfaceName().isNull())
     727        {
     728            valid = false;
     729            aWarning = tr ("No host network interface is selected");
     730        } else
     731#endif
     732        if (type == KNetworkAttachmentType_Internal &&
     733            page->mCbNetwork->currentText().isEmpty())
     734        {
     735            valid = false;
     736            aWarning = tr ("Internal network name is not set");
     737        }
     738
     739        if (!valid)
     740        {
     741            aTitle += ": " + page->pageTitle();
     742            break;
     743        }
     744    }
     745
     746    return valid;
     747}
     748
     749void VBoxVMSettingsNetworkPage::retranslateUi()
     750{
     751    for (int i = 0; i < mTwAdapters->count(); ++ i)
     752    {
     753        VBoxVMSettingsNetwork *page =
     754            static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
     755        mTwAdapters->setTabText (i, page->pageTitle());
     756    }
     757}
     758
     759void VBoxVMSettingsNetworkPage::updateNetworksList()
     760{
     761    /* Lock to prevent few simultaneously update */
     762    if (mLockNetworkListUpdate)
     763        return;
     764    mLockNetworkListUpdate = true;
     765
     766    /* Compose latest list from current + new on all pages */
     767    QStringList curList (mListNetworks);
     768    for (int index = 0; index < mTwAdapters->count(); ++ index)
     769    {
     770        VBoxVMSettingsNetwork *page =
     771            static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
     772        if (page)
     773        {
     774            QString curText = page->mCbNetwork->currentText();
     775            if (!curText.isEmpty() && !curList.contains (curText))
     776                curList << curText;
     777        }
     778    }
     779
     780    /* Load latest list to all pages */
     781    for (int index = 0; index < mTwAdapters->count(); ++ index)
     782    {
     783        VBoxVMSettingsNetwork *page =
     784            static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
     785        if (page)
     786            page->setNetworksList (curList);
     787    }
     788
     789    /* Allow further Network List update */
     790    mLockNetworkListUpdate = false;
     791}
     792
     793#ifdef Q_WS_WIN
     794void VBoxVMSettingsNetworkPage::onCurrentPageChanged (int aIndex)
     795{
     796    VBoxVMSettingsNetwork *page =
     797        static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (aIndex));
     798    Assert (page);
     799    mNIList->setCurrentInterface (page->interfaceName());
     800}
     801
     802void VBoxVMSettingsNetworkPage::onCurrentInterfaceChanged (const QString &aName)
     803{
     804    VBoxVMSettingsNetwork *page =
     805        static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->currentWidget());
     806    Assert (page);
     807    page->setInterfaceName (aName);
     808}
     809#endif
     810
     811void VBoxVMSettingsNetworkPage::populateNetworksList()
    599812{
    600813    /* Clear inner list */
     
    624837}
    625838
    626 // #ifdef Q_WS_WIN
    627 // void VBoxVMSettingsNetwork::prepareListInterfaces()
    628 // {
    629 //     /* Clear inner list */
    630 //     mListInterface.clear();
    631 //
    632 //     /* Load current inner list */
    633 //     CHostNetworkInterfaceEnumerator en =
    634 //         vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
    635 //     while (en.HasMore())
    636 //         mListInterface += en.GetNext().GetName();
    637 //
    638 //     /* Save current list item name */
    639 //     QString currentListItemName = mLwInterfaces->currentText();
    640 //
    641 //     /* Load current list items */
    642 //     mLwInterfaces->clear();
    643 //     if (mListInterface.count())
    644 //         mLwInterfaces->insertItems (0, mListInterface);
    645 //     else
    646 //         mLwInterfaces->insertItem (0, mNoInterfaces);
    647 //
    648 //     /* Select current list item */
    649 //     QListWidgetItem *item = findItem (mLwInterfaces, currentListItemName);
    650 //     mLwInterfaces->setCurrentItem (item ? item : mLwInterfaces->item (0));
    651 //
    652 //     /* Enable/Disable interface delete button */
    653 //     mDelAction->setEnabled (!mListInterface.isEmpty());
    654 // }
    655 // #endif
    656 
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