~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsNetwork.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "VBoxGlobal.h"
26
 
#include "VBoxVMSettingsNetwork.h"
27
 
#include "VBoxVMSettingsNetworkDetails.h"
28
 
 
29
 
/* Qt Includes */
30
 
#include <QTimer>
31
 
#include <QCompleter>
32
 
 
33
 
/* Empty item extra-code */
34
 
const char *emptyItemCode = "#empty#";
35
 
 
36
 
/* VBoxVMSettingsNetwork Stuff */
37
 
VBoxVMSettingsNetwork::VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent)
38
 
    : QIWithRetranslateUI <QWidget> (0)
39
 
    , mParent (aParent)
40
 
    , mDetails (new VBoxVMSettingsNetworkDetails (this))
41
 
    , mValidator (0)
42
 
{
43
 
    /* Apply UI decorations */
44
 
    Ui::VBoxVMSettingsNetwork::setupUi (this);
45
 
 
46
 
    /* Setup widgets */
47
 
    mTbDetails->setIcon (VBoxGlobal::iconSet (
48
 
        ":/settings_16px.png", ":/settings_dis_16px.png"));
49
 
    mCbName->setInsertPolicy (QComboBox::NoInsert);
50
 
 
51
 
    /* Applying language settings */
52
 
    retranslateUi();
53
 
 
54
 
#ifdef Q_WS_MAC
55
 
    /* Prevent this widgets to go in the Small/Mini size state which is
56
 
     * available on Mac OS X. Not sure why this happens but this seems to help
57
 
     * against. */
58
 
    QList <QWidget*> list = findChildren <QWidget*>();
59
 
    foreach (QWidget *w, list)
60
 
        if (w->parent() == this)
61
 
            w->setFixedHeight (w->sizeHint().height());
62
 
 
63
 
    /* Remove tool-button border at MAC */
64
 
    mTbDetails->setStyleSheet ("QToolButton {border: 0px none black;}");
65
 
#endif /* Q_WS_MAC */
66
 
}
67
 
 
68
 
void VBoxVMSettingsNetwork::getFromAdapter (const CNetworkAdapter &aAdapter)
69
 
{
70
 
    mAdapter = aAdapter;
71
 
 
72
 
    /* Load adapter activity state */
73
 
    mGbAdapter->setChecked (aAdapter.GetEnabled());
74
 
 
75
 
    /* Load adapter type */
76
 
    int adapterPos = mCbAdapterType->findData (aAdapter.GetAdapterType());
77
 
    mCbAdapterType->setCurrentIndex (adapterPos == -1 ? 0 : adapterPos);
78
 
 
79
 
    /* Load attachment type */
80
 
    int attachmentPos = mCbAttachmentType->findData (aAdapter.GetAttachmentType());
81
 
    mCbAttachmentType->setCurrentIndex (attachmentPos == -1 ? 0 : attachmentPos);
82
 
 
83
 
    /* Load alternative name */
84
 
    switch (attachmentType())
85
 
    {
86
 
        case KNetworkAttachmentType_Bridged:
87
 
            mBrgName = mAdapter.GetHostInterface();
88
 
            if (mBrgName.isEmpty()) mBrgName = QString::null;
89
 
            break;
90
 
        case KNetworkAttachmentType_Internal:
91
 
            mIntName = mAdapter.GetInternalNetwork();
92
 
            if (mIntName.isEmpty()) mIntName = QString::null;
93
 
            break;
94
 
        case KNetworkAttachmentType_HostOnly:
95
 
            mHoiName = mAdapter.GetHostInterface();
96
 
            if (mHoiName.isEmpty()) mHoiName = QString::null;
97
 
            break;
98
 
        default:
99
 
            break;
100
 
    }
101
 
    updateAttachmentAlternative();
102
 
 
103
 
    /* Load details page */
104
 
    mDetails->getFromAdapter (aAdapter);
105
 
}
106
 
 
107
 
void VBoxVMSettingsNetwork::putBackToAdapter()
108
 
{
109
 
    /* Save adapter activity state */
110
 
    mAdapter.SetEnabled (mGbAdapter->isChecked());
111
 
 
112
 
    /* Save adapter type */
113
 
    KNetworkAdapterType type = (KNetworkAdapterType)
114
 
        mCbAdapterType->itemData (mCbAdapterType->currentIndex()).toInt();
115
 
    mAdapter.SetAdapterType (type);
116
 
 
117
 
    /* Save attachment type & alternative name */
118
 
    switch (attachmentType())
119
 
    {
120
 
        case KNetworkAttachmentType_Null:
121
 
            mAdapter.Detach();
122
 
            break;
123
 
        case KNetworkAttachmentType_NAT:
124
 
            mAdapter.AttachToNAT();
125
 
            break;
126
 
        case KNetworkAttachmentType_Bridged:
127
 
            mAdapter.AttachToBridgedInterface();
128
 
            mAdapter.SetHostInterface (alternativeName());
129
 
            break;
130
 
        case KNetworkAttachmentType_Internal:
131
 
            mAdapter.AttachToInternalNetwork();
132
 
            mAdapter.SetInternalNetwork (alternativeName());
133
 
            break;
134
 
        case KNetworkAttachmentType_HostOnly:
135
 
            mAdapter.AttachToHostOnlyInterface();
136
 
            mAdapter.SetHostInterface (alternativeName());
137
 
            break;
138
 
        default:
139
 
            break;
140
 
    }
141
 
 
142
 
    /* Save details page */
143
 
    mDetails->putBackToAdapter();
144
 
}
145
 
 
146
 
void VBoxVMSettingsNetwork::setValidator (QIWidgetValidator *aValidator)
147
 
{
148
 
    mValidator = aValidator;
149
 
 
150
 
    connect (mGbAdapter, SIGNAL (toggled (bool)),
151
 
             mValidator, SLOT (revalidate()));
152
 
    connect (mCbAttachmentType, SIGNAL (activated (const QString&)),
153
 
             this, SLOT (updateAttachmentAlternative()));
154
 
    connect (mTbDetails, SIGNAL (clicked (bool)),
155
 
             this, SLOT (detailsClicked()));
156
 
    connect (mCbName, SIGNAL (activated (const QString&)),
157
 
             this, SLOT (updateAlternativeName()));
158
 
    connect (mCbName, SIGNAL (editTextChanged (const QString&)),
159
 
             this, SLOT (updateAlternativeName()));
160
 
 
161
 
    mValidator->revalidate();
162
 
}
163
 
 
164
 
bool VBoxVMSettingsNetwork::revalidate (QString &aWarning, QString &aTitle)
165
 
{
166
 
    /* 'True' for disabled adapter */
167
 
    if (!mGbAdapter->isChecked())
168
 
        return true;
169
 
 
170
 
    /* Validate alternatives */
171
 
    bool valid = true;
172
 
    switch (attachmentType())
173
 
    {
174
 
        case KNetworkAttachmentType_Bridged:
175
 
            if (alternativeName().isNull())
176
 
            {
177
 
                aWarning = tr ("no bridged network adapter is selected");
178
 
                valid = false;
179
 
            }
180
 
            break;
181
 
        case KNetworkAttachmentType_Internal:
182
 
            if (alternativeName().isNull())
183
 
            {
184
 
                aWarning = tr ("no internal network name is specified");
185
 
                valid = false;
186
 
            }
187
 
            break;
188
 
        case KNetworkAttachmentType_HostOnly:
189
 
            if (alternativeName().isNull())
190
 
            {
191
 
                aWarning = tr ("no host-only network adapter is selected");
192
 
                valid = false;
193
 
            }
194
 
            break;
195
 
        default:
196
 
            break;
197
 
    }
198
 
 
199
 
    if (!valid)
200
 
        aTitle += ": " + vboxGlobal().removeAccelMark (pageTitle());
201
 
 
202
 
    return valid;
203
 
}
204
 
 
205
 
QWidget* VBoxVMSettingsNetwork::setOrderAfter (QWidget *aAfter)
206
 
{
207
 
    setTabOrder (aAfter, mGbAdapter);
208
 
    setTabOrder (mGbAdapter, mCbAdapterType);
209
 
    setTabOrder (mCbAdapterType, mCbAttachmentType);
210
 
    setTabOrder (mCbAttachmentType, mTbDetails);
211
 
    setTabOrder (mTbDetails, mCbName);
212
 
    return mCbName;
213
 
}
214
 
 
215
 
QString VBoxVMSettingsNetwork::pageTitle() const
216
 
{
217
 
    QString title;
218
 
    if (!mAdapter.isNull())
219
 
    {
220
 
        title = VBoxGlobal::tr ("Adapter %1", "network")
221
 
            .arg (QString ("&%1").arg (mAdapter.GetSlot() + 1));
222
 
    }
223
 
    return title;
224
 
}
225
 
 
226
 
KNetworkAttachmentType VBoxVMSettingsNetwork::attachmentType() const
227
 
{
228
 
    return (KNetworkAttachmentType) mCbAttachmentType->itemData (
229
 
           mCbAttachmentType->currentIndex()).toInt();
230
 
}
231
 
 
232
 
QString VBoxVMSettingsNetwork::alternativeName (int aType) const
233
 
{
234
 
    if (aType == -1) aType = attachmentType();
235
 
    QString result;
236
 
    switch (aType)
237
 
    {
238
 
        case KNetworkAttachmentType_Bridged:
239
 
            result = mBrgName;
240
 
            break;
241
 
        case KNetworkAttachmentType_Internal:
242
 
            result = mIntName;
243
 
            break;
244
 
        case KNetworkAttachmentType_HostOnly:
245
 
            result = mHoiName;
246
 
            break;
247
 
        default:
248
 
            break;
249
 
    }
250
 
    Assert (result.isNull() || !result.isEmpty());
251
 
    return result;
252
 
}
253
 
 
254
 
void VBoxVMSettingsNetwork::retranslateUi()
255
 
{
256
 
    /* Translate uic generated strings */
257
 
    Ui::VBoxVMSettingsNetwork::retranslateUi (this);
258
 
 
259
 
    /* Translate combo-boxes content */
260
 
    populateComboboxes();
261
 
 
262
 
    /* Translate attachment info */
263
 
    updateAttachmentAlternative();
264
 
}
265
 
 
266
 
void VBoxVMSettingsNetwork::updateAttachmentAlternative()
267
 
{
268
 
    /* Blocking signals to change content manually */
269
 
    mCbName->blockSignals (true);
270
 
 
271
 
    /* Update alternative-name combo-box availability */
272
 
    mLbName->setEnabled (attachmentType() != KNetworkAttachmentType_Null &&
273
 
                         attachmentType() != KNetworkAttachmentType_NAT);
274
 
    mCbName->setEnabled (attachmentType() != KNetworkAttachmentType_Null &&
275
 
                         attachmentType() != KNetworkAttachmentType_NAT);
276
 
 
277
 
    /* Refresh list */
278
 
    mCbName->clear();
279
 
    switch (attachmentType())
280
 
    {
281
 
        case KNetworkAttachmentType_Bridged:
282
 
            mCbName->insertItems (0, mParent->brgList());
283
 
            mCbName->setEditable (false);
284
 
            break;
285
 
        case KNetworkAttachmentType_Internal:
286
 
            mCbName->insertItems (0, mParent->intList());
287
 
            mCbName->setEditable (true);
288
 
            mCbName->setCompleter (0);
289
 
            break;
290
 
        case KNetworkAttachmentType_HostOnly:
291
 
            mCbName->insertItems (0, mParent->hoiList());
292
 
            mCbName->setEditable (false);
293
 
            break;
294
 
        default:
295
 
            break;
296
 
    }
297
 
 
298
 
    /* Prepend 'empty' or 'default' item */
299
 
    if (mCbName->count() == 0)
300
 
    {
301
 
        switch (attachmentType())
302
 
        {
303
 
            case KNetworkAttachmentType_Bridged:
304
 
            case KNetworkAttachmentType_HostOnly:
305
 
            {
306
 
                /* Adapters list 'empty' */
307
 
                int pos = mCbName->findData (emptyItemCode);
308
 
                if (pos == -1)
309
 
                    mCbName->insertItem (0, tr ("Not selected", "network adapter name"), emptyItemCode);
310
 
                else
311
 
                    mCbName->setItemText (pos, tr ("Not selected", "network adapter name"));
312
 
                break;
313
 
            }
314
 
            case KNetworkAttachmentType_Internal:
315
 
            {
316
 
                /* Internal network 'default' name */
317
 
                if (mCbName->findText ("intnet") == -1)
318
 
                    mCbName->insertItem (0, "intnet");
319
 
                break;
320
 
            }
321
 
            default:
322
 
                break;
323
 
        }
324
 
    }
325
 
 
326
 
    /* Select previous or default item */
327
 
    switch (attachmentType())
328
 
    {
329
 
        case KNetworkAttachmentType_Bridged:
330
 
        case KNetworkAttachmentType_HostOnly:
331
 
        {
332
 
            int pos = mCbName->findText (alternativeName());
333
 
            mCbName->setCurrentIndex (pos == -1 ? 0 : pos);
334
 
            break;
335
 
        }
336
 
        case KNetworkAttachmentType_Internal:
337
 
        {
338
 
            int pos = mCbName->findText (alternativeName());
339
 
            mCbName->setCurrentIndex (pos == -1 ? 0 : pos);
340
 
            break;
341
 
        }
342
 
        default:
343
 
            break;
344
 
    }
345
 
 
346
 
    /* Remember selected item */
347
 
    updateAlternativeName();
348
 
 
349
 
    /* Unblocking signals as content is changed already */
350
 
    mCbName->blockSignals (false);
351
 
}
352
 
 
353
 
void VBoxVMSettingsNetwork::updateAlternativeName()
354
 
{
355
 
    switch (attachmentType())
356
 
    {
357
 
        case KNetworkAttachmentType_Bridged:
358
 
        {
359
 
            QString newName (mCbName->itemData (mCbName->currentIndex()).toString() ==
360
 
                             QString (emptyItemCode) ||
361
 
                             mCbName->currentText().isEmpty() ?
362
 
                             QString::null : mCbName->currentText());
363
 
            if (mBrgName != newName)
364
 
                mBrgName = newName;
365
 
            break;
366
 
        }
367
 
        case KNetworkAttachmentType_Internal:
368
 
        {
369
 
            QString newName ((mCbName->itemData (mCbName->currentIndex()).toString() ==
370
 
                              QString (emptyItemCode) &&
371
 
                              mCbName->currentText() ==
372
 
                              mCbName->itemText (mCbName->currentIndex())) ||
373
 
                              mCbName->currentText().isEmpty() ?
374
 
                              QString::null : mCbName->currentText());
375
 
            if (mIntName != newName)
376
 
            {
377
 
                mIntName = newName;
378
 
                if (!mIntName.isNull())
379
 
                    QTimer::singleShot (0, mParent, SLOT (updatePages()));
380
 
            }
381
 
            break;
382
 
        }
383
 
        case KNetworkAttachmentType_HostOnly:
384
 
        {
385
 
            QString newName (mCbName->itemData (mCbName->currentIndex()).toString() ==
386
 
                             QString (emptyItemCode) ||
387
 
                             mCbName->currentText().isEmpty() ?
388
 
                             QString::null : mCbName->currentText());
389
 
            if (mHoiName != newName)
390
 
                mHoiName = newName;
391
 
            break;
392
 
        }
393
 
        default:
394
 
            break;
395
 
    }
396
 
 
397
 
    if (mValidator)
398
 
        mValidator->revalidate();
399
 
}
400
 
 
401
 
void VBoxVMSettingsNetwork::detailsClicked()
402
 
{
403
 
    /* Lock the button to avoid double-click bug */
404
 
    mTbDetails->setEnabled (false);
405
 
 
406
 
    /* Show details sub-dialog */
407
 
    mDetails->activateWindow();
408
 
    mDetails->reload();
409
 
    mDetails->exec();
410
 
 
411
 
    /* Unlock the previously locked button */
412
 
    mTbDetails->setEnabled (true);
413
 
}
414
 
 
415
 
void VBoxVMSettingsNetwork::populateComboboxes()
416
 
{
417
 
    /* Save the current selected adapter */
418
 
    int currentAdapter = mCbAdapterType->currentIndex();
419
 
 
420
 
    /* Clear the adapters combo-box */
421
 
    mCbAdapterType->clear();
422
 
 
423
 
    /* Populate adapters */
424
 
    mCbAdapterType->insertItem (0,
425
 
        vboxGlobal().toString (KNetworkAdapterType_Am79C970A));
426
 
    mCbAdapterType->setItemData (0,
427
 
        KNetworkAdapterType_Am79C970A);
428
 
    mCbAdapterType->setItemData (0,
429
 
        mCbAdapterType->itemText (0), Qt::ToolTipRole);
430
 
    mCbAdapterType->insertItem (1,
431
 
        vboxGlobal().toString (KNetworkAdapterType_Am79C973));
432
 
    mCbAdapterType->setItemData (1,
433
 
        KNetworkAdapterType_Am79C973);
434
 
    mCbAdapterType->setItemData (1,
435
 
        mCbAdapterType->itemText (1), Qt::ToolTipRole);
436
 
#ifdef VBOX_WITH_E1000
437
 
    mCbAdapterType->insertItem (2,
438
 
        vboxGlobal().toString (KNetworkAdapterType_I82540EM));
439
 
    mCbAdapterType->setItemData (2,
440
 
        KNetworkAdapterType_I82540EM);
441
 
    mCbAdapterType->setItemData (2,
442
 
        mCbAdapterType->itemText (2), Qt::ToolTipRole);
443
 
    mCbAdapterType->insertItem (3,
444
 
        vboxGlobal().toString (KNetworkAdapterType_I82543GC));
445
 
    mCbAdapterType->setItemData (3,
446
 
        KNetworkAdapterType_I82543GC);
447
 
    mCbAdapterType->setItemData (3,
448
 
        mCbAdapterType->itemText (3), Qt::ToolTipRole);
449
 
    mCbAdapterType->insertItem (4,
450
 
        vboxGlobal().toString (KNetworkAdapterType_I82545EM));
451
 
    mCbAdapterType->setItemData (4,
452
 
        KNetworkAdapterType_I82545EM);
453
 
    mCbAdapterType->setItemData (4,
454
 
        mCbAdapterType->itemText (4), Qt::ToolTipRole);
455
 
#endif /* VBOX_WITH_E1000 */
456
 
 
457
 
    /* Set the old value */
458
 
    mCbAdapterType->setCurrentIndex (currentAdapter == -1 ?
459
 
                                     0 : currentAdapter);
460
 
 
461
 
 
462
 
    /* Save the current selected attachment type */
463
 
    int currentAttachment = mCbAttachmentType->currentIndex();
464
 
 
465
 
    /* Clear the attachments combo-box */
466
 
    mCbAttachmentType->clear();
467
 
 
468
 
    /* Populate attachments */
469
 
    mCbAttachmentType->insertItem (0,
470
 
        vboxGlobal().toString (KNetworkAttachmentType_Null));
471
 
    mCbAttachmentType->setItemData (0,
472
 
        KNetworkAttachmentType_Null);
473
 
    mCbAttachmentType->setItemData (0,
474
 
        mCbAttachmentType->itemText (0), Qt::ToolTipRole);
475
 
    mCbAttachmentType->insertItem (1,
476
 
        vboxGlobal().toString (KNetworkAttachmentType_NAT));
477
 
    mCbAttachmentType->setItemData (1,
478
 
        KNetworkAttachmentType_NAT);
479
 
    mCbAttachmentType->setItemData (1,
480
 
        mCbAttachmentType->itemText (1), Qt::ToolTipRole);
481
 
    mCbAttachmentType->insertItem (2,
482
 
        vboxGlobal().toString (KNetworkAttachmentType_Bridged));
483
 
    mCbAttachmentType->setItemData (2,
484
 
        KNetworkAttachmentType_Bridged);
485
 
    mCbAttachmentType->setItemData (2,
486
 
        mCbAttachmentType->itemText (2), Qt::ToolTipRole);
487
 
    mCbAttachmentType->insertItem (3,
488
 
        vboxGlobal().toString (KNetworkAttachmentType_Internal));
489
 
    mCbAttachmentType->setItemData (3,
490
 
        KNetworkAttachmentType_Internal);
491
 
    mCbAttachmentType->setItemData (3,
492
 
        mCbAttachmentType->itemText (3), Qt::ToolTipRole);
493
 
    mCbAttachmentType->insertItem (4,
494
 
        vboxGlobal().toString (KNetworkAttachmentType_HostOnly));
495
 
    mCbAttachmentType->setItemData (4,
496
 
        KNetworkAttachmentType_HostOnly);
497
 
    mCbAttachmentType->setItemData (4,
498
 
        mCbAttachmentType->itemText (4), Qt::ToolTipRole);
499
 
 
500
 
    /* Set the old value */
501
 
    mCbAttachmentType->setCurrentIndex (currentAttachment);
502
 
}
503
 
 
504
 
/* VBoxVMSettingsNetworkPage Stuff */
505
 
VBoxVMSettingsNetworkPage::VBoxVMSettingsNetworkPage()
506
 
    : mValidator (0)
507
 
{
508
 
    /* Setup Main Layout */
509
 
    QVBoxLayout *mainLayout = new QVBoxLayout (this);
510
 
    mainLayout->setContentsMargins (0, 5, 0, 5);
511
 
 
512
 
    /* Creating Tab Widget */
513
 
    mTwAdapters = new QTabWidget (this);
514
 
    mainLayout->addWidget (mTwAdapters);
515
 
}
516
 
 
517
 
QStringList VBoxVMSettingsNetworkPage::brgList (bool aRefresh)
518
 
{
519
 
    if (aRefresh)
520
 
    {
521
 
        /* Load & filter interface list */
522
 
        mBrgList.clear();
523
 
        CHostNetworkInterfaceVector interfaces =
524
 
            vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
525
 
        for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
526
 
             it != interfaces.end(); ++ it)
527
 
        {
528
 
            if (it->GetInterfaceType() == KHostNetworkInterfaceType_Bridged)
529
 
                mBrgList << it->GetName();
530
 
        }
531
 
    }
532
 
 
533
 
    return mBrgList;
534
 
}
535
 
 
536
 
QStringList VBoxVMSettingsNetworkPage::intList (bool aRefresh)
537
 
{
538
 
    if (aRefresh)
539
 
    {
540
 
        /* Load total network list of all VMs */
541
 
        mIntList.clear();
542
 
        CVirtualBox vbox = vboxGlobal().virtualBox();
543
 
        ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());
544
 
        CMachineVector vec = vbox.GetMachines();
545
 
        for (CMachineVector::ConstIterator m = vec.begin(); m != vec.end(); ++ m)
546
 
        {
547
 
            if (m->GetAccessible())
548
 
            {
549
 
                for (ulong slot = 0; slot < count; ++ slot)
550
 
                {
551
 
                    QString name = m->GetNetworkAdapter (slot).GetInternalNetwork();
552
 
                    if (!name.isEmpty() && !mIntList.contains (name))
553
 
                        mIntList << name;
554
 
                }
555
 
            }
556
 
        }
557
 
    }
558
 
 
559
 
    /* Append network list with names from all the pages */
560
 
    QStringList list (mIntList);
561
 
    for (int index = 0; index < mTwAdapters->count(); ++ index)
562
 
    {
563
 
        VBoxVMSettingsNetwork *page =
564
 
            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));
565
 
        if (page)
566
 
        {
567
 
            QString name = page->alternativeName (KNetworkAttachmentType_Internal);
568
 
            if (!name.isEmpty() && !list.contains (name))
569
 
                list << name;
570
 
        }
571
 
    }
572
 
 
573
 
    return list;
574
 
}
575
 
 
576
 
QStringList VBoxVMSettingsNetworkPage::hoiList (bool aRefresh)
577
 
{
578
 
    if (aRefresh)
579
 
    {
580
 
        /* Load & filter interface list */
581
 
        mHoiList.clear();
582
 
        CHostNetworkInterfaceVector interfaces =
583
 
            vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
584
 
        for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
585
 
             it != interfaces.end(); ++ it)
586
 
        {
587
 
            if (it->GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)
588
 
                mHoiList << it->GetName();
589
 
        }
590
 
    }
591
 
 
592
 
    return mHoiList;
593
 
}
594
 
 
595
 
void VBoxVMSettingsNetworkPage::getFrom (const CMachine &aMachine)
596
 
{
597
 
    /* Setup tab order */
598
 
    Assert (mFirstWidget);
599
 
    setTabOrder (mFirstWidget, mTwAdapters->focusProxy());
600
 
    QWidget *lastFocusWidget = mTwAdapters->focusProxy();
601
 
 
602
 
    /* Cache data */
603
 
    brgList (true);
604
 
    intList (true);
605
 
    hoiList (true);
606
 
 
607
 
    /* Creating Tab Pages */
608
 
    CVirtualBox vbox = vboxGlobal().virtualBox();
609
 
    ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());
610
 
    for (ulong slot = 0; slot < count; ++ slot)
611
 
    {
612
 
        /* Get Adapter */
613
 
        CNetworkAdapter adapter = aMachine.GetNetworkAdapter (slot);
614
 
 
615
 
        /* Creating Adapter's page */
616
 
        VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork (this);
617
 
 
618
 
        /* Loading Adapter's data into page */
619
 
        page->getFromAdapter (adapter);
620
 
 
621
 
        /* Attach Adapter's page to Tab Widget */
622
 
        mTwAdapters->addTab (page, page->pageTitle());
623
 
 
624
 
        /* Setup validation */
625
 
        page->setValidator (mValidator);
626
 
 
627
 
        /* Setup tab order */
628
 
        lastFocusWidget = page->setOrderAfter (lastFocusWidget);
629
 
    }
630
 
 
631
 
    /* Applying language settings */
632
 
    retranslateUi();
633
 
}
634
 
 
635
 
void VBoxVMSettingsNetworkPage::putBackTo()
636
 
{
637
 
    for (int i = 0; i < mTwAdapters->count(); ++ i)
638
 
    {
639
 
        VBoxVMSettingsNetwork *page =
640
 
            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
641
 
        Assert (page);
642
 
        page->putBackToAdapter();
643
 
    }
644
 
}
645
 
 
646
 
void VBoxVMSettingsNetworkPage::setValidator (QIWidgetValidator *aVal)
647
 
{
648
 
    mValidator = aVal;
649
 
}
650
 
 
651
 
bool VBoxVMSettingsNetworkPage::revalidate (QString &aWarning, QString &aTitle)
652
 
{
653
 
    bool valid = true;
654
 
 
655
 
    for (int i = 0; i < mTwAdapters->count(); ++ i)
656
 
    {
657
 
        VBoxVMSettingsNetwork *page =
658
 
            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
659
 
        Assert (page);
660
 
        valid = page->revalidate (aWarning, aTitle);
661
 
        if (!valid) break;
662
 
    }
663
 
 
664
 
    return valid;
665
 
}
666
 
 
667
 
void VBoxVMSettingsNetworkPage::retranslateUi()
668
 
{
669
 
    for (int i = 0; i < mTwAdapters->count(); ++ i)
670
 
    {
671
 
        VBoxVMSettingsNetwork *page =
672
 
            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
673
 
        Assert (page);
674
 
        mTwAdapters->setTabText (i, page->pageTitle());
675
 
    }
676
 
}
677
 
 
678
 
void VBoxVMSettingsNetworkPage::updatePages()
679
 
{
680
 
    for (int i = 0; i < mTwAdapters->count(); ++ i)
681
 
    {
682
 
        /* Get the iterated page */
683
 
        VBoxVMSettingsNetwork *page =
684
 
            qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i));
685
 
        Assert (page);
686
 
 
687
 
        /* Update the page if the attachment type is 'internal network' */
688
 
        if (page->attachmentType() == KNetworkAttachmentType_Internal)
689
 
            QTimer::singleShot (0, page, SLOT (updateAttachmentAlternative()));
690
 
    }
691
 
}
692