PageRenderTime 99ms CodeModel.GetById 18ms app.highlight 75ms RepoModel.GetById 2ms app.codeStats 0ms

/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsNetwork.cpp

https://gitlab.com/ufo/virtualbox-ose-3-1-8
C++ | 752 lines | 577 code | 86 blank | 89 comment | 80 complexity | 8fcf61ccc89b439d2015d7970bec83f3 MD5 | raw file
  1/** @file
  2 *
  3 * VBox frontends: Qt4 GUI ("VirtualBox"):
  4 * VBoxVMSettingsNetwork class implementation
  5 */
  6
  7/*
  8 * Copyright (C) 2008 Sun Microsystems, Inc.
  9 *
 10 * This file is part of VirtualBox Open Source Edition (OSE), as
 11 * available from http://www.virtualbox.org. This file is free software;
 12 * you can redistribute it and/or modify it under the terms of the GNU
 13 * General Public License (GPL) as published by the Free Software
 14 * Foundation, in version 2 as it comes in the "COPYING" file of the
 15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 17 *
 18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
 20 * additional information or have any questions.
 21 */
 22
 23/* VBox Includes */
 24#include "QIWidgetValidator.h"
 25#include "QIArrowButtonSwitch.h"
 26#include "VBoxGlobal.h"
 27#include "VBoxVMSettingsNetwork.h"
 28
 29/* Qt Includes */
 30#include <QTimer>
 31#include <QCompleter>
 32
 33/* Empty item extra-code */
 34const char *emptyItemCode = "#empty#";
 35
 36/* VBoxVMSettingsNetwork Stuff */
 37VBoxVMSettingsNetwork::VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent, bool aDisableStaticControls)
 38    : QIWithRetranslateUI <QWidget> (0)
 39    , mParent (aParent)
 40    , mValidator (0)
 41    , mPolished (false)
 42    , mDisableStaticControls (false)
 43{
 44    /* Apply UI decorations */
 45    Ui::VBoxVMSettingsNetwork::setupUi (this);
 46
 47    /* Setup widgets */
 48    mCbAdapterName->setInsertPolicy (QComboBox::NoInsert);
 49    mLeMAC->setValidator (new QRegExpValidator (QRegExp (
 50                          "[0-9A-Fa-f][02468ACEace][0-9A-Fa-f]{10}"), this));
 51    mLeMAC->setMinimumWidthByText (QString().fill ('0', 12));
 52
 53    /* Setup connections */
 54    connect (mAbsAdvanced, SIGNAL (clicked()), this, SLOT (toggleAdvanced()));
 55    connect (mTbMAC, SIGNAL (clicked()), this, SLOT (generateMac()));
 56
 57#ifdef Q_WS_MAC
 58    /* Prevent this widgets to go in the Small/Mini size state which is
 59     * available on Mac OS X. Not sure why this happens but this seems to help
 60     * against. */
 61    QList <QWidget*> list = findChildren <QWidget*>();
 62    foreach (QWidget *w, list)
 63        if (w->parent() == this)
 64            w->setFixedHeight (w->sizeHint().height());
 65#endif /* Q_WS_MAC */
 66
 67    /* Applying language settings */
 68    retranslateUi();
 69
 70    /* If some controls should be disabled or not when the
 71     * same tab widgets are shown during runtime
 72     */
 73    mDisableStaticControls = aDisableStaticControls;
 74}
 75
 76void VBoxVMSettingsNetwork::getFromAdapter (const CNetworkAdapter &aAdapter)
 77{
 78    mAdapter = aAdapter;
 79
 80    /* Load adapter activity state */
 81    mCbEnableAdapter->setChecked (aAdapter.GetEnabled());
 82
 83    /* Load adapter type */
 84    int adapterPos = mCbAdapterType->findData (aAdapter.GetAdapterType());
 85    mCbAdapterType->setCurrentIndex (adapterPos == -1 ? 0 : adapterPos);
 86
 87    /* Load attachment type */
 88    int attachmentPos = mCbAttachmentType->findData (aAdapter.GetAttachmentType());
 89    mCbAttachmentType->setCurrentIndex (attachmentPos == -1 ? 0 : attachmentPos);
 90
 91    /* Load alternative name */
 92    switch (attachmentType())
 93    {
 94        case KNetworkAttachmentType_Bridged:
 95            mBrgName = mAdapter.GetHostInterface();
 96            if (mBrgName.isEmpty()) mBrgName = QString::null;
 97            break;
 98        case KNetworkAttachmentType_Internal:
 99            mIntName = mAdapter.GetInternalNetwork();
100            if (mIntName.isEmpty()) mIntName = QString::null;
101            break;
102        case KNetworkAttachmentType_HostOnly:
103            mHoiName = mAdapter.GetHostInterface();
104            if (mHoiName.isEmpty()) mHoiName = QString::null;
105            break;
106        default:
107            break;
108    }
109    updateAttachmentAlternative();
110
111    mLeMAC->setText (mAdapter.GetMACAddress());
112    mCbCableConnected->setChecked (mAdapter.GetCableConnected());
113}
114
115void VBoxVMSettingsNetwork::putBackToAdapter()
116{
117    /* Save adapter activity state */
118    mAdapter.SetEnabled (mCbEnableAdapter->isChecked());
119
120    /* Save adapter type */
121    KNetworkAdapterType type = (KNetworkAdapterType)
122        mCbAdapterType->itemData (mCbAdapterType->currentIndex()).toInt();
123    mAdapter.SetAdapterType (type);
124
125    /* Save attachment type & alternative name */
126    switch (attachmentType())
127    {
128        case KNetworkAttachmentType_Null:
129            mAdapter.Detach();
130            break;
131        case KNetworkAttachmentType_NAT:
132            mAdapter.AttachToNAT();
133            break;
134        case KNetworkAttachmentType_Bridged:
135            mAdapter.SetHostInterface (alternativeName());
136            mAdapter.AttachToBridgedInterface();
137            break;
138        case KNetworkAttachmentType_Internal:
139            mAdapter.SetInternalNetwork (alternativeName());
140            mAdapter.AttachToInternalNetwork();
141            break;
142        case KNetworkAttachmentType_HostOnly:
143            mAdapter.SetHostInterface (alternativeName());
144            mAdapter.AttachToHostOnlyInterface();
145            break;
146        default:
147            break;
148    }
149
150    mAdapter.SetMACAddress (mLeMAC->text().isEmpty() ? QString::null : mLeMAC->text());
151    mAdapter.SetCableConnected (mCbCableConnected->isChecked());
152}
153
154void VBoxVMSettingsNetwork::setValidator (QIWidgetValidator *aValidator)
155{
156    mValidator = aValidator;
157
158    if (!mDisableStaticControls)
159        connect (mCbEnableAdapter, SIGNAL (toggled (bool)),
160                 mValidator, SLOT (revalidate()));
161    connect (mCbAttachmentType, SIGNAL (activated (const QString&)),
162             this, SLOT (updateAttachmentAlternative()));
163    connect (mCbAdapterName, SIGNAL (activated (const QString&)),
164             this, SLOT (updateAlternativeName()));
165    connect (mCbAdapterName, SIGNAL (editTextChanged (const QString&)),
166             this, SLOT (updateAlternativeName()));
167
168    if (!mDisableStaticControls)
169        mValidator->revalidate();
170}
171
172bool VBoxVMSettingsNetwork::revalidate (QString &aWarning, QString &aTitle)
173{
174    /* 'True' for disabled adapter */
175    if (!mCbEnableAdapter->isChecked())
176        return true;
177
178    /* Validate alternatives */
179    bool valid = true;
180    switch (attachmentType())
181    {
182        case KNetworkAttachmentType_Bridged:
183            if (alternativeName().isNull())
184            {
185                aWarning = tr ("no bridged network adapter is selected");
186                valid = false;
187            }
188            break;
189        case KNetworkAttachmentType_Internal:
190            if (alternativeName().isNull())
191            {
192                aWarning = tr ("no internal network name is specified");
193                valid = false;
194            }
195            break;
196        case KNetworkAttachmentType_HostOnly:
197            if (alternativeName().isNull())
198            {
199                aWarning = tr ("no host-only network adapter is selected");
200                valid = false;
201            }
202            break;
203        default:
204            break;
205    }
206
207    if (!valid)
208        aTitle += ": " + vboxGlobal().removeAccelMark (pageTitle());
209
210    return valid;
211}
212
213QWidget* VBoxVMSettingsNetwork::setOrderAfter (QWidget *aAfter)
214{
215    setTabOrder (aAfter, mCbEnableAdapter);
216    setTabOrder (mCbEnableAdapter, mCbAttachmentType);
217    setTabOrder (mCbAttachmentType, mCbAdapterName);
218    setTabOrder (mCbAdapterName, mAbsAdvanced);
219    setTabOrder (mAbsAdvanced, mCbAdapterType);
220    setTabOrder (mCbAdapterType, mLeMAC);
221    setTabOrder (mLeMAC, mTbMAC);
222    setTabOrder (mTbMAC, mCbCableConnected);
223    return mCbCableConnected;
224}
225
226QString VBoxVMSettingsNetwork::pageTitle() const
227{
228    QString title;
229    if (!mAdapter.isNull())
230    {
231        title = VBoxGlobal::tr ("Adapter %1", "network")
232            .arg (QString ("&%1").arg (mAdapter.GetSlot() + 1));
233    }
234    return title;
235}
236
237KNetworkAttachmentType VBoxVMSettingsNetwork::attachmentType() const
238{
239    return (KNetworkAttachmentType) mCbAttachmentType->itemData (
240           mCbAttachmentType->currentIndex()).toInt();
241}
242
243QString VBoxVMSettingsNetwork::alternativeName (int aType) const
244{
245    if (aType == -1) aType = attachmentType();
246    QString result;
247    switch (aType)
248    {
249        case KNetworkAttachmentType_Bridged:
250            result = mBrgName;
251            break;
252        case KNetworkAttachmentType_Internal:
253            result = mIntName;
254            break;
255        case KNetworkAttachmentType_HostOnly:
256            result = mHoiName;
257            break;
258        default:
259            break;
260    }
261    Assert (result.isNull() || !result.isEmpty());
262    return result;
263}
264
265void VBoxVMSettingsNetwork::showEvent (QShowEvent *aEvent)
266{
267    if (!mPolished)
268    {
269        mPolished = true;
270
271        /* Give the minimum size hint to the first layout column */
272        mNetworkChildGridLayout->setColumnMinimumWidth (0, mLbAttachmentType->width());
273
274        if (mDisableStaticControls)
275        {
276            /* Disable controls for dynamically displayed page */
277            mCbEnableAdapter->setEnabled (false);
278            mCbAdapterType->setEnabled (false);
279            mLeMAC->setEnabled (false);
280            mTbMAC->setEnabled (false);
281            mLbAdapterType->setEnabled (false);
282            mLbMAC->setEnabled (false);
283            mAbsAdvanced->animateClick();
284        }
285        else
286        {
287            /* Hide advanced items initially */
288            toggleAdvanced();
289        }
290    }
291    QWidget::showEvent (aEvent);
292}
293
294void VBoxVMSettingsNetwork::retranslateUi()
295{
296    /* Translate uic generated strings */
297    Ui::VBoxVMSettingsNetwork::retranslateUi (this);
298
299    /* Translate combo-boxes content */
300    populateComboboxes();
301
302    /* Translate attachment info */
303    updateAttachmentAlternative();
304}
305
306void VBoxVMSettingsNetwork::updateAttachmentAlternative()
307{
308    /* Blocking signals to change content manually */
309    mCbAdapterName->blockSignals (true);
310
311    /* Update alternative-name combo-box availability */
312    mLbAdapterName->setEnabled (attachmentType() != KNetworkAttachmentType_Null &&
313                                attachmentType() != KNetworkAttachmentType_NAT);
314    mCbAdapterName->setEnabled (attachmentType() != KNetworkAttachmentType_Null &&
315                                attachmentType() != KNetworkAttachmentType_NAT);
316
317    /* Refresh list */
318    mCbAdapterName->clear();
319    switch (attachmentType())
320    {
321        case KNetworkAttachmentType_Bridged:
322            mCbAdapterName->insertItems (0, mParent->brgList());
323            mCbAdapterName->setEditable (false);
324            break;
325        case KNetworkAttachmentType_Internal:
326            mCbAdapterName->insertItems (0, mParent->intList());
327            mCbAdapterName->setEditable (true);
328            mCbAdapterName->setCompleter (0);
329            break;
330        case KNetworkAttachmentType_HostOnly:
331            mCbAdapterName->insertItems (0, mParent->hoiList());
332            mCbAdapterName->setEditable (false);
333            break;
334        default:
335            break;
336    }
337
338    /* Prepend 'empty' or 'default' item */
339    if (mCbAdapterName->count() == 0)
340    {
341        switch (attachmentType())
342        {
343            case KNetworkAttachmentType_Bridged:
344            case KNetworkAttachmentType_HostOnly:
345            {
346                /* Adapters list 'empty' */
347                int pos = mCbAdapterName->findData (emptyItemCode);
348                if (pos == -1)
349                    mCbAdapterName->insertItem (0, tr ("Not selected", "network adapter name"), emptyItemCode);
350                else
351                    mCbAdapterName->setItemText (pos, tr ("Not selected", "network adapter name"));
352                break;
353            }
354            case KNetworkAttachmentType_Internal:
355            {
356                /* Internal network 'default' name */
357                if (mCbAdapterName->findText ("intnet") == -1)
358                    mCbAdapterName->insertItem (0, "intnet");
359                break;
360            }
361            default:
362                break;
363        }
364    }
365
366    /* Select previous or default item */
367    switch (attachmentType())
368    {
369        case KNetworkAttachmentType_Bridged:
370        case KNetworkAttachmentType_HostOnly:
371        {
372            int pos = mCbAdapterName->findText (alternativeName());
373            mCbAdapterName->setCurrentIndex (pos == -1 ? 0 : pos);
374            break;
375        }
376        case KNetworkAttachmentType_Internal:
377        {
378            int pos = mCbAdapterName->findText (alternativeName());
379            mCbAdapterName->setCurrentIndex (pos == -1 ? 0 : pos);
380            break;
381        }
382        default:
383            break;
384    }
385
386    /* Remember selected item */
387    updateAlternativeName();
388
389    /* Unblocking signals as content is changed already */
390    mCbAdapterName->blockSignals (false);
391}
392
393void VBoxVMSettingsNetwork::updateAlternativeName()
394{
395    switch (attachmentType())
396    {
397        case KNetworkAttachmentType_Bridged:
398        {
399            QString newName (mCbAdapterName->itemData (mCbAdapterName->currentIndex()).toString() ==
400                             QString (emptyItemCode) ||
401                             mCbAdapterName->currentText().isEmpty() ?
402                             QString::null : mCbAdapterName->currentText());
403            if (mBrgName != newName)
404                mBrgName = newName;
405            break;
406        }
407        case KNetworkAttachmentType_Internal:
408        {
409            QString newName ((mCbAdapterName->itemData (mCbAdapterName->currentIndex()).toString() ==
410                              QString (emptyItemCode) &&
411                              mCbAdapterName->currentText() ==
412                              mCbAdapterName->itemText (mCbAdapterName->currentIndex())) ||
413                              mCbAdapterName->currentText().isEmpty() ?
414                              QString::null : mCbAdapterName->currentText());
415            if (mIntName != newName)
416            {
417                mIntName = newName;
418                if (!mIntName.isNull())
419                    QTimer::singleShot (0, mParent, SLOT (updatePages()));
420            }
421            break;
422        }
423        case KNetworkAttachmentType_HostOnly:
424        {
425            QString newName (mCbAdapterName->itemData (mCbAdapterName->currentIndex()).toString() ==
426                             QString (emptyItemCode) ||
427                             mCbAdapterName->currentText().isEmpty() ?
428                             QString::null : mCbAdapterName->currentText());
429            if (mHoiName != newName)
430                mHoiName = newName;
431            break;
432        }
433        default:
434            break;
435    }
436
437    if (mValidator)
438        mValidator->revalidate();
439}
440
441void VBoxVMSettingsNetwork::toggleAdvanced()
442{
443    mLbAdapterType->setVisible (mAbsAdvanced->isExpanded());
444    mCbAdapterType->setVisible (mAbsAdvanced->isExpanded());
445    mLbMAC->setVisible (mAbsAdvanced->isExpanded());
446    mLeMAC->setVisible (mAbsAdvanced->isExpanded());
447    mTbMAC->setVisible (mAbsAdvanced->isExpanded());
448    mCbCableConnected->setVisible (mAbsAdvanced->isExpanded());
449}
450
451void VBoxVMSettingsNetwork::generateMac()
452{
453    mAdapter.SetMACAddress (QString::null);
454    mLeMAC->setText (mAdapter.GetMACAddress());
455}
456
457void VBoxVMSettingsNetwork::populateComboboxes()
458{
459    /* Save the current selected adapter */
460    int currentAdapter = mCbAdapterType->currentIndex();
461
462    /* Clear the adapters combo-box */
463    mCbAdapterType->clear();
464
465    /* Populate adapters */
466    mCbAdapterType->insertItem (0,
467        vboxGlobal().toString (KNetworkAdapterType_Am79C970A));
468    mCbAdapterType->setItemData (0,
469        KNetworkAdapterType_Am79C970A);
470    mCbAdapterType->setItemData (0,
471        mCbAdapterType->itemText (0), Qt::ToolTipRole);
472    mCbAdapterType->insertItem (1,
473        vboxGlobal().toString (KNetworkAdapterType_Am79C973));
474    mCbAdapterType->setItemData (1,
475        KNetworkAdapterType_Am79C973);
476    mCbAdapterType->setItemData (1,
477        mCbAdapterType->itemText (1), Qt::ToolTipRole);
478#ifdef VBOX_WITH_E1000
479    mCbAdapterType->insertItem (2,
480        vboxGlobal().toString (KNetworkAdapterType_I82540EM));
481    mCbAdapterType->setItemData (2,
482        KNetworkAdapterType_I82540EM);
483    mCbAdapterType->setItemData (2,
484        mCbAdapterType->itemText (2), Qt::ToolTipRole);
485    mCbAdapterType->insertItem (3,
486        vboxGlobal().toString (KNetworkAdapterType_I82543GC));
487    mCbAdapterType->setItemData (3,
488        KNetworkAdapterType_I82543GC);
489    mCbAdapterType->setItemData (3,
490        mCbAdapterType->itemText (3), Qt::ToolTipRole);
491    mCbAdapterType->insertItem (4,
492        vboxGlobal().toString (KNetworkAdapterType_I82545EM));
493    mCbAdapterType->setItemData (4,
494        KNetworkAdapterType_I82545EM);
495    mCbAdapterType->setItemData (4,
496        mCbAdapterType->itemText (4), Qt::ToolTipRole);
497#endif /* VBOX_WITH_E1000 */
498#ifdef VBOX_WITH_VIRTIO
499    mCbAdapterType->insertItem (5,
500        vboxGlobal().toString (KNetworkAdapterType_Virtio));
501    mCbAdapterType->setItemData (5,
502        KNetworkAdapterType_Virtio);
503    mCbAdapterType->setItemData (5,
504        mCbAdapterType->itemText (5), Qt::ToolTipRole);
505#endif /* VBOX_WITH_VIRTIO */
506
507    /* Set the old value */
508    mCbAdapterType->setCurrentIndex (currentAdapter == -1 ?
509                                     0 : currentAdapter);
510
511
512    /* Save the current selected attachment type */
513    int currentAttachment = mCbAttachmentType->currentIndex();
514
515    /* Clear the attachments combo-box */
516    mCbAttachmentType->clear();
517
518    /* Populate attachments */
519    mCbAttachmentType->insertItem (0,
520        vboxGlobal().toString (KNetworkAttachmentType_Null));
521    mCbAttachmentType->setItemData (0,
522        KNetworkAttachmentType_Null);
523    mCbAttachmentType->setItemData (0,
524        mCbAttachmentType->itemText (0), Qt::ToolTipRole);
525    mCbAttachmentType->insertItem (1,
526        vboxGlobal().toString (KNetworkAttachmentType_NAT));
527    mCbAttachmentType->setItemData (1,
528        KNetworkAttachmentType_NAT);
529    mCbAttachmentType->setItemData (1,
530        mCbAttachmentType->itemText (1), Qt::ToolTipRole);
531    mCbAttachmentType->insertItem (2,
532        vboxGlobal().toString (KNetworkAttachmentType_Bridged));
533    mCbAttachmentType->setItemData (2,
534        KNetworkAttachmentType_Bridged);
535    mCbAttachmentType->setItemData (2,
536        mCbAttachmentType->itemText (2), Qt::ToolTipRole);
537    mCbAttachmentType->insertItem (3,
538        vboxGlobal().toString (KNetworkAttachmentType_Internal));
539    mCbAttachmentType->setItemData (3,
540        KNetworkAttachmentType_Internal);
541    mCbAttachmentType->setItemData (3,
542        mCbAttachmentType->itemText (3), Qt::ToolTipRole);
543    mCbAttachmentType->insertItem (4,
544        vboxGlobal().toString (KNetworkAttachmentType_HostOnly));
545    mCbAttachmentType->setItemData (4,
546        KNetworkAttachmentType_HostOnly);
547    mCbAttachmentType->setItemData (4,
548        mCbAttachmentType->itemText (4), Qt::ToolTipRole);
549
550    /* Set the old value */
551    mCbAttachmentType->setCurrentIndex (currentAttachment);
552}
553
554/* VBoxVMSettingsNetworkPage Stuff */
555VBoxVMSettingsNetworkPage::VBoxVMSettingsNetworkPage(bool aDisableStaticControls)
556    : mValidator (0)
557    , mDisableStaticControls (false)
558{
559    /* Setup Main Layout */
560    QVBoxLayout *mainLayout = new QVBoxLayout (this);
561    mainLayout->setContentsMargins (0, 5, 0, 5);
562
563    /* Creating Tab Widget */
564    mTwAdapters = new QTabWidget (this);
565    mainLayout->addWidget (mTwAdapters);
566
567    /* If some controls should be disabled or not when the
568     * same tab widgets are shown during runtime
569     */
570    mDisableStaticControls = aDisableStaticControls;
571}
572
573QStringList VBoxVMSettingsNetworkPage::brgList (bool aRefresh)
574{
575    if (aRefresh)
576    {
577        /* Load & filter interface list */
578        mBrgList.clear();
579        CHostNetworkInterfaceVector interfaces =
580            vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
581        for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
582             it != interfaces.end(); ++ it)
583        {
584            if (it->GetInterfaceType() == KHostNetworkInterfaceType_Bridged)
585                mBrgList << it->GetName();
586        }
587    }
588
589    return mBrgList;
590}
591
592QStringList VBoxVMSettingsNetworkPage::intList (bool aRefresh)
593{
594    if (aRefresh)
595    {
596        /* Load total network list of all VMs */
597        mIntList.clear();
598        CVirtualBox vbox = vboxGlobal().virtualBox();
599        ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());
600        CMachineVector vec = vbox.GetMachines();
601        for (CMachineVector::ConstIterator m = vec.begin(); m != vec.end(); ++ m)
602        {
603            if (m->GetAccessible())
604            {
605                for (ulong slot = 0; slot < count; ++ slot)
606                {
607                    QString name = m->GetNetworkAdapter (slot).GetInternalNetwork();
608                    if (!name.isEmpty() && !mIntList.contains (name))
609                        mIntList << name;
610                }
611            }
612        }
613    }
614
615    /* Append network list with names from all the pages */
616    QStringList list (mIntList);
617    for (int index = 0; index < mTwAdapters->count(); ++ index)
618    {
619        VBoxVMSettingsNetwork *page =
620            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
621        if (page)
622        {
623            QString name = page->alternativeName (KNetworkAttachmentType_Internal);
624            if (!name.isEmpty() && !list.contains (name))
625                list << name;
626        }
627    }
628
629    return list;
630}
631
632QStringList VBoxVMSettingsNetworkPage::hoiList (bool aRefresh)
633{
634    if (aRefresh)
635    {
636        /* Load & filter interface list */
637        mHoiList.clear();
638        CHostNetworkInterfaceVector interfaces =
639            vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
640        for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
641             it != interfaces.end(); ++ it)
642        {
643            if (it->GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)
644                mHoiList << it->GetName();
645        }
646    }
647
648    return mHoiList;
649}
650
651void VBoxVMSettingsNetworkPage::getFrom (const CMachine &aMachine)
652{
653    /* Setup tab order */
654    Assert (mFirstWidget);
655    setTabOrder (mFirstWidget, mTwAdapters->focusProxy());
656    QWidget *lastFocusWidget = mTwAdapters->focusProxy();
657
658    /* Cache data */
659    brgList (true);
660    intList (true);
661    hoiList (true);
662
663    /* Creating Tab Pages */
664    CVirtualBox vbox = vboxGlobal().virtualBox();
665    ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());
666    for (ulong slot = 0; slot < count; ++ slot)
667    {
668        /* Get Adapter */
669        CNetworkAdapter adapter = aMachine.GetNetworkAdapter (slot);
670
671        /* Creating Adapter's page */
672        VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork (this, mDisableStaticControls);
673
674        /* Loading Adapter's data into page */
675        page->getFromAdapter (adapter);
676
677        /* Attach Adapter's page to Tab Widget */
678        mTwAdapters->addTab (page, page->pageTitle());
679
680        /* Disable tab page if adapter is being configured dynamically */
681        if (mDisableStaticControls && !adapter.GetEnabled())
682            mTwAdapters->setTabEnabled(slot, false);
683
684        /* Setup validation */
685        page->setValidator (mValidator);
686
687        /* Setup tab order */
688        lastFocusWidget = page->setOrderAfter (lastFocusWidget);
689    }
690
691    /* Applying language settings */
692    retranslateUi();
693}
694
695void VBoxVMSettingsNetworkPage::putBackTo()
696{
697    for (int i = 0; i < mTwAdapters->count(); ++ i)
698    {
699        VBoxVMSettingsNetwork *page =
700            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
701        Assert (page);
702        page->putBackToAdapter();
703    }
704}
705
706void VBoxVMSettingsNetworkPage::setValidator (QIWidgetValidator *aVal)
707{
708    mValidator = aVal;
709}
710
711bool VBoxVMSettingsNetworkPage::revalidate (QString &aWarning, QString &aTitle)
712{
713    bool valid = true;
714
715    for (int i = 0; i < mTwAdapters->count(); ++ i)
716    {
717        VBoxVMSettingsNetwork *page =
718            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
719        Assert (page);
720        valid = page->revalidate (aWarning, aTitle);
721        if (!valid) break;
722    }
723
724    return valid;
725}
726
727void VBoxVMSettingsNetworkPage::retranslateUi()
728{
729    for (int i = 0; i < mTwAdapters->count(); ++ i)
730    {
731        VBoxVMSettingsNetwork *page =
732            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
733        Assert (page);
734        mTwAdapters->setTabText (i, page->pageTitle());
735    }
736}
737
738void VBoxVMSettingsNetworkPage::updatePages()
739{
740    for (int i = 0; i < mTwAdapters->count(); ++ i)
741    {
742        /* Get the iterated page */
743        VBoxVMSettingsNetwork *page =
744            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
745        Assert (page);
746
747        /* Update the page if the attachment type is 'internal network' */
748        if (page->attachmentType() == KNetworkAttachmentType_Internal)
749            QTimer::singleShot (0, page, SLOT (updateAttachmentAlternative()));
750    }
751}
752