VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsNetwork.cpp@ 41819

Last change on this file since 41819 was 41819, checked in by vboxsync, 12 years ago

FE/Qt: UIConverter template interface supporting various required conversions between different GUI and COM types.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 47.5 KB
Line 
1/* $Id: UIMachineSettingsNetwork.cpp 41819 2012-06-18 17:59:30Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt4 GUI ("VirtualBox"):
5 * UIMachineSettingsNetwork class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2011 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* GUI includes: */
21#include "QIWidgetValidator.h"
22#include "QIArrowButtonSwitch.h"
23#include "UIMachineSettingsNetwork.h"
24#include "QITabWidget.h"
25#include "VBoxGlobal.h"
26#include "UIConverter.h"
27
28/* COM includes: */
29#include "CNetworkAdapter.h"
30#include "CNATEngine.h"
31#include "CHostNetworkInterface.h"
32
33/* Other VBox includes: */
34#ifdef VBOX_WITH_VDE
35# include <iprt/ldr.h>
36# include <VBox/VDEPlug.h>
37#endif /* VBOX_WITH_VDE */
38
39/* Empty item extra-code: */
40const char *pEmptyItemCode = "#empty#";
41
42QString wipedOutString(const QString &strInputString)
43{
44 return strInputString.isEmpty() ? QString() : strInputString;
45}
46
47UIMachineSettingsNetwork::UIMachineSettingsNetwork(UIMachineSettingsNetworkPage *pParent)
48 : QIWithRetranslateUI<QWidget>(0)
49 , m_pParent(pParent)
50 , m_pValidator(0)
51 , m_iSlot(-1)
52{
53 /* Apply UI decorations: */
54 Ui::UIMachineSettingsNetwork::setupUi(this);
55
56 /* Setup widgets: */
57 m_pAdapterNameCombo->setInsertPolicy(QComboBox::NoInsert);
58 m_pMACEditor->setValidator(new QRegExpValidator(QRegExp("[0-9A-Fa-f][02468ACEace][0-9A-Fa-f]{10}"), this));
59 m_pMACEditor->setMinimumWidthByText(QString().fill('0', 12));
60
61 /* Setup connections: */
62 connect(m_pEnableAdapterCheckBox, SIGNAL(toggled(bool)), this, SLOT(sltHandleAdapterActivityChange()));
63 connect(m_pAttachmentTypeComboBox, SIGNAL(activated(int)), this, SLOT(sltHandleAttachmentTypeChange()));
64 connect(m_pAdapterNameCombo, SIGNAL(activated(int)), this, SLOT(sltHandleAlternativeNameChange()));
65 connect(m_pAdapterNameCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(sltHandleAlternativeNameChange()));
66 connect(m_pAdvancedArrow, SIGNAL(clicked()), this, SLOT(sltHandleAdvancedButtonStateChange()));
67 connect(m_pMACButton, SIGNAL(clicked()), this, SLOT(sltGenerateMac()));
68 connect(m_pPortForwardingButton, SIGNAL(clicked()), this, SLOT(sltOpenPortForwardingDlg()));
69 connect(this, SIGNAL(sigTabUpdated()), m_pParent, SLOT(sltHandleUpdatedTab()));
70
71 /* Applying language settings: */
72 retranslateUi();
73}
74
75void UIMachineSettingsNetwork::fetchAdapterCache(const UICacheSettingsMachineNetworkAdapter &adapterCache)
76{
77 /* Get adapter data: */
78 const UIDataSettingsMachineNetworkAdapter &adapterData = adapterCache.base();
79
80 /* Load slot number: */
81 m_iSlot = adapterData.m_iSlot;
82
83 /* Load adapter activity state: */
84 m_pEnableAdapterCheckBox->setChecked(adapterData.m_fAdapterEnabled);
85 /* Handle adapter activity change: */
86 sltHandleAdapterActivityChange();
87
88 /* Load attachment type: */
89 m_pAttachmentTypeComboBox->setCurrentIndex(position(m_pAttachmentTypeComboBox, adapterData.m_attachmentType));
90 /* Load alternative name: */
91 m_strBridgedAdapterName = wipedOutString(adapterData.m_strBridgedAdapterName);
92 m_strInternalNetworkName = wipedOutString(adapterData.m_strInternalNetworkName);
93 m_strHostInterfaceName = wipedOutString(adapterData.m_strHostInterfaceName);
94 m_strGenericDriverName = wipedOutString(adapterData.m_strGenericDriverName);
95 /* Handle attachment type change: */
96 sltHandleAttachmentTypeChange();
97
98 /* Load adapter type: */
99 m_pAdapterTypeCombo->setCurrentIndex(position(m_pAdapterTypeCombo, adapterData.m_adapterType));
100
101 /* Load promiscuous mode type: */
102 m_pPromiscuousModeCombo->setCurrentIndex(position(m_pPromiscuousModeCombo, adapterData.m_promiscuousMode));
103
104 /* Other options: */
105 m_pMACEditor->setText(adapterData.m_strMACAddress);
106 m_pGenericPropertiesTextEdit->setText(adapterData.m_strGenericProperties);
107 m_pCableConnectedCheckBox->setChecked(adapterData.m_fCableConnected);
108
109 /* Load port forwarding rules: */
110 m_portForwardingRules = adapterData.m_redirects;
111}
112
113void UIMachineSettingsNetwork::uploadAdapterCache(UICacheSettingsMachineNetworkAdapter &adapterCache)
114{
115 /* Prepare adapter data: */
116 UIDataSettingsMachineNetworkAdapter adapterData = adapterCache.base();
117
118 /* Save adapter activity state: */
119 adapterData.m_fAdapterEnabled = m_pEnableAdapterCheckBox->isChecked();
120
121 /* Save attachment type & alternative name: */
122 adapterData.m_attachmentType = attachmentType();
123 switch (adapterData.m_attachmentType)
124 {
125 case KNetworkAttachmentType_Null:
126 break;
127 case KNetworkAttachmentType_NAT:
128 break;
129 case KNetworkAttachmentType_Bridged:
130 adapterData.m_strBridgedAdapterName = alternativeName();
131 break;
132 case KNetworkAttachmentType_Internal:
133 adapterData.m_strInternalNetworkName = alternativeName();
134 break;
135 case KNetworkAttachmentType_HostOnly:
136 adapterData.m_strHostInterfaceName = alternativeName();
137 break;
138 case KNetworkAttachmentType_Generic:
139 adapterData.m_strGenericDriverName = alternativeName();
140 adapterData.m_strGenericProperties = m_pGenericPropertiesTextEdit->toPlainText();
141 break;
142 default:
143 break;
144 }
145
146 /* Save adapter type: */
147 adapterData.m_adapterType = (KNetworkAdapterType)m_pAdapterTypeCombo->itemData(m_pAdapterTypeCombo->currentIndex()).toInt();
148
149 /* Save promiscuous mode type: */
150 adapterData.m_promiscuousMode = (KNetworkAdapterPromiscModePolicy)m_pPromiscuousModeCombo->itemData(m_pPromiscuousModeCombo->currentIndex()).toInt();
151
152 /* Other options: */
153 adapterData.m_strMACAddress = m_pMACEditor->text().isEmpty() ? QString() : m_pMACEditor->text();
154 adapterData.m_fCableConnected = m_pCableConnectedCheckBox->isChecked();
155
156 /* Save port forwarding rules: */
157 adapterData.m_redirects = m_portForwardingRules;
158
159 /* Cache adapter data: */
160 adapterCache.cacheCurrentData(adapterData);
161}
162
163void UIMachineSettingsNetwork::setValidator(QIWidgetValidator *pValidator)
164{
165 m_pValidator = pValidator;
166}
167
168bool UIMachineSettingsNetwork::revalidate(QString &strWarning, QString &strTitle)
169{
170 /* 'True' for disabled adapter: */
171 if (!m_pEnableAdapterCheckBox->isChecked())
172 return true;
173
174 /* Validate alternatives: */
175 bool fValid = true;
176 switch (attachmentType())
177 {
178 case KNetworkAttachmentType_Bridged:
179 {
180 if (alternativeName().isNull())
181 {
182 strWarning = tr("no bridged network adapter is selected");
183 fValid = false;
184 }
185 break;
186 }
187 case KNetworkAttachmentType_Internal:
188 {
189 if (alternativeName().isNull())
190 {
191 strWarning = tr("no internal network name is specified");
192 fValid = false;
193 }
194 break;
195 }
196 case KNetworkAttachmentType_HostOnly:
197 {
198 if (alternativeName().isNull())
199 {
200 strWarning = tr("no host-only network adapter is selected");
201 fValid = false;
202 }
203 break;
204 }
205 case KNetworkAttachmentType_Generic:
206 {
207 if (alternativeName().isNull())
208 {
209 strWarning = tr("no generic driver is selected");
210 fValid = false;
211 }
212 break;
213 }
214 default:
215 break;
216 }
217 if (!fValid)
218 strTitle += ": " + vboxGlobal().removeAccelMark(tabTitle());
219
220 return fValid;
221}
222
223QWidget* UIMachineSettingsNetwork::setOrderAfter(QWidget *pAfter)
224{
225 setTabOrder(pAfter, m_pEnableAdapterCheckBox);
226 setTabOrder(m_pEnableAdapterCheckBox, m_pAttachmentTypeComboBox);
227 setTabOrder(m_pAttachmentTypeComboBox, m_pAdapterNameCombo);
228 setTabOrder(m_pAdapterNameCombo, m_pAdvancedArrow);
229 setTabOrder(m_pAdvancedArrow, m_pAdapterTypeCombo);
230 setTabOrder(m_pAdapterTypeCombo, m_pPromiscuousModeCombo);
231 setTabOrder(m_pPromiscuousModeCombo, m_pMACEditor);
232 setTabOrder(m_pMACEditor, m_pMACButton);
233 setTabOrder(m_pMACButton, m_pGenericPropertiesTextEdit);
234 setTabOrder(m_pGenericPropertiesTextEdit, m_pCableConnectedCheckBox);
235 setTabOrder(m_pCableConnectedCheckBox, m_pPortForwardingButton);
236 return m_pPortForwardingButton;
237}
238
239QString UIMachineSettingsNetwork::tabTitle() const
240{
241 return VBoxGlobal::tr("Adapter %1").arg(QString("&%1").arg(m_iSlot + 1));
242}
243
244KNetworkAttachmentType UIMachineSettingsNetwork::attachmentType() const
245{
246 return (KNetworkAttachmentType)m_pAttachmentTypeComboBox->itemData(m_pAttachmentTypeComboBox->currentIndex()).toInt();
247}
248
249QString UIMachineSettingsNetwork::alternativeName(int iType) const
250{
251 if (iType == -1)
252 iType = attachmentType();
253 QString strResult;
254 switch (iType)
255 {
256 case KNetworkAttachmentType_Bridged:
257 strResult = m_strBridgedAdapterName;
258 break;
259 case KNetworkAttachmentType_Internal:
260 strResult = m_strInternalNetworkName;
261 break;
262 case KNetworkAttachmentType_HostOnly:
263 strResult = m_strHostInterfaceName;
264 break;
265 case KNetworkAttachmentType_Generic:
266 strResult = m_strGenericDriverName;
267 break;
268 default:
269 break;
270 }
271 Assert(strResult.isNull() || !strResult.isEmpty());
272 return strResult;
273}
274
275void UIMachineSettingsNetwork::polishTab()
276{
277 /* Basic attributes: */
278 m_pEnableAdapterCheckBox->setEnabled(m_pParent->isMachineOffline());
279 m_pAttachmentTypeLabel->setEnabled(m_pParent->isMachineInValidMode());
280 m_pAttachmentTypeComboBox->setEnabled(m_pParent->isMachineInValidMode());
281 m_pAdapterNameLabel->setEnabled(m_pParent->isMachineInValidMode() &&
282 attachmentType() != KNetworkAttachmentType_Null &&
283 attachmentType() != KNetworkAttachmentType_NAT);
284 m_pAdapterNameCombo->setEnabled(m_pParent->isMachineInValidMode() &&
285 attachmentType() != KNetworkAttachmentType_Null &&
286 attachmentType() != KNetworkAttachmentType_NAT);
287 m_pAdvancedArrow->setEnabled(m_pParent->isMachineInValidMode());
288
289 /* Advanced attributes: */
290 m_pAdapterTypeLabel->setEnabled(m_pParent->isMachineOffline());
291 m_pAdapterTypeCombo->setEnabled(m_pParent->isMachineOffline());
292 m_pPromiscuousModeLabel->setEnabled(m_pParent->isMachineInValidMode() &&
293 attachmentType() != KNetworkAttachmentType_Null &&
294 attachmentType() != KNetworkAttachmentType_Generic &&
295 attachmentType() != KNetworkAttachmentType_NAT);
296 m_pPromiscuousModeCombo->setEnabled(m_pParent->isMachineInValidMode() &&
297 attachmentType() != KNetworkAttachmentType_Null &&
298 attachmentType() != KNetworkAttachmentType_Generic &&
299 attachmentType() != KNetworkAttachmentType_NAT);
300 m_pMACLabel->setEnabled(m_pParent->isMachineOffline());
301 m_pMACEditor->setEnabled(m_pParent->isMachineOffline());
302 m_pMACButton->setEnabled(m_pParent->isMachineOffline());
303 m_pGenericPropertiesLabel->setEnabled(m_pParent->isMachineInValidMode());
304 m_pGenericPropertiesTextEdit->setEnabled(m_pParent->isMachineInValidMode());
305 m_pPortForwardingButton->setEnabled(m_pParent->isMachineInValidMode() &&
306 attachmentType() == KNetworkAttachmentType_NAT);
307
308 /* Postprocessing: */
309 if ((m_pParent->isMachineSaved() || m_pParent->isMachineOnline()) && !m_pAdvancedArrow->isExpanded())
310 m_pAdvancedArrow->animateClick();
311 sltHandleAdvancedButtonStateChange();
312}
313
314void UIMachineSettingsNetwork::reloadAlternative()
315{
316 /* Repopulate alternative-name combo-box content: */
317 updateAlternativeList();
318 /* Select previous or default alternative-name combo-box item: */
319 updateAlternativeName();
320}
321
322void UIMachineSettingsNetwork::retranslateUi()
323{
324 /* Translate uic generated strings: */
325 Ui::UIMachineSettingsNetwork::retranslateUi(this);
326
327 /* Translate combo-boxes content: */
328 populateComboboxes();
329
330 /* Translate attachment info: */
331 sltHandleAttachmentTypeChange();
332}
333
334void UIMachineSettingsNetwork::sltHandleAdapterActivityChange()
335{
336 /* Update availability: */
337 m_pAdapterOptionsContainer->setEnabled(m_pEnableAdapterCheckBox->isChecked());
338 /* Revalidate if possible: */
339 if (m_pValidator)
340 m_pValidator->revalidate();
341}
342
343void UIMachineSettingsNetwork::sltHandleAttachmentTypeChange()
344{
345 /* Update alternative-name combo-box availability: */
346 m_pAdapterNameLabel->setEnabled(attachmentType() != KNetworkAttachmentType_Null &&
347 attachmentType() != KNetworkAttachmentType_NAT);
348 m_pAdapterNameCombo->setEnabled(attachmentType() != KNetworkAttachmentType_Null &&
349 attachmentType() != KNetworkAttachmentType_NAT);
350 /* Update promiscuous-mode combo-box availability: */
351 m_pPromiscuousModeLabel->setEnabled(attachmentType() != KNetworkAttachmentType_Null &&
352 attachmentType() != KNetworkAttachmentType_Generic &&
353 attachmentType() != KNetworkAttachmentType_NAT);
354 m_pPromiscuousModeCombo->setEnabled(attachmentType() != KNetworkAttachmentType_Null &&
355 attachmentType() != KNetworkAttachmentType_Generic &&
356 attachmentType() != KNetworkAttachmentType_NAT);
357 /* Update generic-properties editor visibility: */
358 m_pGenericPropertiesLabel->setVisible(attachmentType() == KNetworkAttachmentType_Generic &&
359 m_pAdvancedArrow->isExpanded());
360 m_pGenericPropertiesTextEdit->setVisible(attachmentType() == KNetworkAttachmentType_Generic &&
361 m_pAdvancedArrow->isExpanded());
362 /* Update forwarding-rules button availability: */
363 m_pPortForwardingButton->setEnabled(attachmentType() == KNetworkAttachmentType_NAT);
364 /* Update alternative-name combo-box whats-this and editable state: */
365 switch (attachmentType())
366 {
367 case KNetworkAttachmentType_Bridged:
368 {
369 m_pAdapterNameCombo->setWhatsThis(tr("Selects the network adapter on the host system that traffic "
370 "to and from this network card will go through."));
371 m_pAdapterNameCombo->setEditable(false);
372 break;
373 }
374 case KNetworkAttachmentType_Internal:
375 {
376 m_pAdapterNameCombo->setWhatsThis(tr("Enter the name of the internal network that this network card "
377 "will be connected to. You can create a new internal network by "
378 "choosing a name which is not used by any other network cards "
379 "in this virtual machine or others."));
380 m_pAdapterNameCombo->setEditable(true);
381 break;
382 }
383 case KNetworkAttachmentType_HostOnly:
384 {
385 m_pAdapterNameCombo->setWhatsThis(tr("Selects the virtual network adapter on the host system that traffic "
386 "to and from this network card will go through. "
387 "You can create and remove adapters using the global network "
388 "settings in the virtual machine manager window."));
389 m_pAdapterNameCombo->setEditable(false);
390 break;
391 }
392 case KNetworkAttachmentType_Generic:
393 {
394 m_pAdapterNameCombo->setWhatsThis(tr("Selects the driver to be used with this network card."));
395 m_pAdapterNameCombo->setEditable(true);
396 break;
397 }
398 default:
399 {
400 m_pAdapterNameCombo->setWhatsThis(QString());
401 break;
402 }
403 }
404
405 /* Update alternative combo: */
406 reloadAlternative();
407
408 /* Handle alternative-name cange: */
409 sltHandleAlternativeNameChange();
410}
411
412void UIMachineSettingsNetwork::sltHandleAlternativeNameChange()
413{
414 /* Remember new name if its changed,
415 * Call for other pages update, if necessary: */
416 switch (attachmentType())
417 {
418 case KNetworkAttachmentType_Bridged:
419 {
420 QString newName(m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == QString(pEmptyItemCode) ||
421 m_pAdapterNameCombo->currentText().isEmpty() ? QString() : m_pAdapterNameCombo->currentText());
422 if (m_strBridgedAdapterName != newName)
423 m_strBridgedAdapterName = newName;
424 break;
425 }
426 case KNetworkAttachmentType_Internal:
427 {
428 QString newName((m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == QString(pEmptyItemCode) &&
429 m_pAdapterNameCombo->currentText() == m_pAdapterNameCombo->itemText(m_pAdapterNameCombo->currentIndex())) ||
430 m_pAdapterNameCombo->currentText().isEmpty() ? QString() : m_pAdapterNameCombo->currentText());
431 if (m_strInternalNetworkName != newName)
432 {
433 m_strInternalNetworkName = newName;
434 if (!m_strInternalNetworkName.isNull())
435 emit sigTabUpdated();
436 }
437 break;
438 }
439 case KNetworkAttachmentType_HostOnly:
440 {
441 QString newName(m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == QString(pEmptyItemCode) ||
442 m_pAdapterNameCombo->currentText().isEmpty() ? QString() : m_pAdapterNameCombo->currentText());
443 if (m_strHostInterfaceName != newName)
444 m_strHostInterfaceName = newName;
445 break;
446 }
447 case KNetworkAttachmentType_Generic:
448 {
449 QString newName((m_pAdapterNameCombo->itemData(m_pAdapterNameCombo->currentIndex()).toString() == QString(pEmptyItemCode) &&
450 m_pAdapterNameCombo->currentText() == m_pAdapterNameCombo->itemText(m_pAdapterNameCombo->currentIndex())) ||
451 m_pAdapterNameCombo->currentText().isEmpty() ? QString() : m_pAdapterNameCombo->currentText());
452 if (m_strGenericDriverName != newName)
453 {
454 m_strGenericDriverName = newName;
455 if (!m_strGenericDriverName.isNull())
456 emit sigTabUpdated();
457 }
458 break;
459 }
460 default:
461 break;
462 }
463
464 /* Revalidate if possible: */
465 if (m_pValidator)
466 m_pValidator->revalidate();
467}
468
469void UIMachineSettingsNetwork::sltHandleAdvancedButtonStateChange()
470{
471 /* Update visibility of advanced options: */
472 m_pAdapterTypeLabel->setVisible(m_pAdvancedArrow->isExpanded());
473 m_pAdapterTypeCombo->setVisible(m_pAdvancedArrow->isExpanded());
474 m_pPromiscuousModeLabel->setVisible(m_pAdvancedArrow->isExpanded());
475 m_pPromiscuousModeCombo->setVisible(m_pAdvancedArrow->isExpanded());
476 m_pGenericPropertiesLabel->setVisible(attachmentType() == KNetworkAttachmentType_Generic &&
477 m_pAdvancedArrow->isExpanded());
478 m_pGenericPropertiesTextEdit->setVisible(attachmentType() == KNetworkAttachmentType_Generic &&
479 m_pAdvancedArrow->isExpanded());
480 m_pMACLabel->setVisible(m_pAdvancedArrow->isExpanded());
481 m_pMACEditor->setVisible(m_pAdvancedArrow->isExpanded());
482 m_pMACButton->setVisible(m_pAdvancedArrow->isExpanded());
483 m_pCableConnectedCheckBox->setVisible(m_pAdvancedArrow->isExpanded());
484 m_pPortForwardingButton->setVisible(m_pAdvancedArrow->isExpanded());
485}
486
487void UIMachineSettingsNetwork::sltGenerateMac()
488{
489 m_pMACEditor->setText(vboxGlobal().host().GenerateMACAddress());
490}
491
492void UIMachineSettingsNetwork::sltOpenPortForwardingDlg()
493{
494 UIMachineSettingsPortForwardingDlg dlg(this, m_portForwardingRules);
495 if (dlg.exec() == QDialog::Accepted)
496 m_portForwardingRules = dlg.rules();
497}
498
499void UIMachineSettingsNetwork::populateComboboxes()
500{
501 /* Attachment type: */
502 {
503 /* Remember the currently selected attachment type: */
504 int iCurrentAttachment = m_pAttachmentTypeComboBox->currentIndex();
505
506 /* Clear the attachments combo-box: */
507 m_pAttachmentTypeComboBox->clear();
508
509 /* Populate attachments: */
510 int iAttachmentTypeIndex = 0;
511 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, gpConverter->toString(KNetworkAttachmentType_Null));
512 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Null);
513 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);
514 ++iAttachmentTypeIndex;
515 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, gpConverter->toString(KNetworkAttachmentType_NAT));
516 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_NAT);
517 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);
518 ++iAttachmentTypeIndex;
519 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, gpConverter->toString(KNetworkAttachmentType_Bridged));
520 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Bridged);
521 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);
522 ++iAttachmentTypeIndex;
523 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, gpConverter->toString(KNetworkAttachmentType_Internal));
524 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Internal);
525 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);
526 ++iAttachmentTypeIndex;
527 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, gpConverter->toString(KNetworkAttachmentType_HostOnly));
528 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_HostOnly);
529 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);
530 ++iAttachmentTypeIndex;
531 m_pAttachmentTypeComboBox->insertItem(iAttachmentTypeIndex, gpConverter->toString(KNetworkAttachmentType_Generic));
532 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, KNetworkAttachmentType_Generic);
533 m_pAttachmentTypeComboBox->setItemData(iAttachmentTypeIndex, m_pAttachmentTypeComboBox->itemText(iAttachmentTypeIndex), Qt::ToolTipRole);
534 ++iAttachmentTypeIndex;
535
536 /* Restore the previously selected attachment type: */
537 m_pAttachmentTypeComboBox->setCurrentIndex(iCurrentAttachment == -1 ? 0 : iCurrentAttachment);
538 }
539
540 /* Adapter type: */
541 {
542 /* Remember the currently selected adapter type: */
543 int iCurrentAdapter = m_pAdapterTypeCombo->currentIndex();
544
545 /* Clear the adapter type combo-box: */
546 m_pAdapterTypeCombo->clear();
547
548 /* Populate adapter types: */
549 int iAdapterTypeIndex = 0;
550 m_pAdapterTypeCombo->insertItem(iAdapterTypeIndex, gpConverter->toString(KNetworkAdapterType_Am79C970A));
551 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, KNetworkAdapterType_Am79C970A);
552 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, m_pAdapterTypeCombo->itemText(iAdapterTypeIndex), Qt::ToolTipRole);
553 ++iAdapterTypeIndex;
554 m_pAdapterTypeCombo->insertItem(iAdapterTypeIndex, gpConverter->toString(KNetworkAdapterType_Am79C973));
555 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, KNetworkAdapterType_Am79C973);
556 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, m_pAdapterTypeCombo->itemText(iAdapterTypeIndex), Qt::ToolTipRole);
557 ++iAdapterTypeIndex;
558#ifdef VBOX_WITH_E1000
559 m_pAdapterTypeCombo->insertItem(iAdapterTypeIndex, gpConverter->toString(KNetworkAdapterType_I82540EM));
560 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, KNetworkAdapterType_I82540EM);
561 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, m_pAdapterTypeCombo->itemText(iAdapterTypeIndex), Qt::ToolTipRole);
562 ++iAdapterTypeIndex;
563 m_pAdapterTypeCombo->insertItem(iAdapterTypeIndex, gpConverter->toString(KNetworkAdapterType_I82543GC));
564 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, KNetworkAdapterType_I82543GC);
565 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, m_pAdapterTypeCombo->itemText(iAdapterTypeIndex), Qt::ToolTipRole);
566 ++iAdapterTypeIndex;
567 m_pAdapterTypeCombo->insertItem(iAdapterTypeIndex, gpConverter->toString(KNetworkAdapterType_I82545EM));
568 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, KNetworkAdapterType_I82545EM);
569 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, m_pAdapterTypeCombo->itemText(iAdapterTypeIndex), Qt::ToolTipRole);
570 ++iAdapterTypeIndex;
571#endif /* VBOX_WITH_E1000 */
572#ifdef VBOX_WITH_VIRTIO
573 m_pAdapterTypeCombo->insertItem(iAdapterTypeIndex, gpConverter->toString(KNetworkAdapterType_Virtio));
574 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, KNetworkAdapterType_Virtio);
575 m_pAdapterTypeCombo->setItemData(iAdapterTypeIndex, m_pAdapterTypeCombo->itemText(iAdapterTypeIndex), Qt::ToolTipRole);
576 ++iAdapterTypeIndex;
577#endif /* VBOX_WITH_VIRTIO */
578
579 /* Restore the previously selected adapter type: */
580 m_pAdapterTypeCombo->setCurrentIndex(iCurrentAdapter == -1 ? 0 : iCurrentAdapter);
581 }
582
583 /* Promiscuous Mode type: */
584 {
585 /* Remember the currently selected promiscuous mode type: */
586 int iCurrentPromiscuousMode = m_pPromiscuousModeCombo->currentIndex();
587
588 /* Clear the promiscuous mode combo-box: */
589 m_pPromiscuousModeCombo->clear();
590
591 /* Populate promiscuous modes: */
592 int iPromiscuousModeIndex = 0;
593 m_pPromiscuousModeCombo->insertItem(iPromiscuousModeIndex, gpConverter->toString(KNetworkAdapterPromiscModePolicy_Deny));
594 m_pPromiscuousModeCombo->setItemData(iPromiscuousModeIndex, KNetworkAdapterPromiscModePolicy_Deny);
595 m_pPromiscuousModeCombo->setItemData(iPromiscuousModeIndex, m_pPromiscuousModeCombo->itemText(iPromiscuousModeIndex), Qt::ToolTipRole);
596 ++iPromiscuousModeIndex;
597 m_pPromiscuousModeCombo->insertItem(iPromiscuousModeIndex, gpConverter->toString(KNetworkAdapterPromiscModePolicy_AllowNetwork));
598 m_pPromiscuousModeCombo->setItemData(iPromiscuousModeIndex, KNetworkAdapterPromiscModePolicy_AllowNetwork);
599 m_pPromiscuousModeCombo->setItemData(iPromiscuousModeIndex, m_pPromiscuousModeCombo->itemText(iPromiscuousModeIndex), Qt::ToolTipRole);
600 ++iPromiscuousModeIndex;
601 m_pPromiscuousModeCombo->insertItem(iPromiscuousModeIndex, gpConverter->toString(KNetworkAdapterPromiscModePolicy_AllowAll));
602 m_pPromiscuousModeCombo->setItemData(iPromiscuousModeIndex, KNetworkAdapterPromiscModePolicy_AllowAll);
603 m_pPromiscuousModeCombo->setItemData(iPromiscuousModeIndex, m_pPromiscuousModeCombo->itemText(iPromiscuousModeIndex), Qt::ToolTipRole);
604 ++iPromiscuousModeIndex;
605
606 /* Restore the previously selected promiscuous mode type: */
607 m_pPromiscuousModeCombo->setCurrentIndex(iCurrentPromiscuousMode == -1 ? 0 : iCurrentPromiscuousMode);
608 }
609}
610
611void UIMachineSettingsNetwork::updateAlternativeList()
612{
613 /* Block signals initially: */
614 m_pAdapterNameCombo->blockSignals(true);
615
616 /* Repopulate alternative-name combo: */
617 m_pAdapterNameCombo->clear();
618 switch (attachmentType())
619 {
620 case KNetworkAttachmentType_Bridged:
621 m_pAdapterNameCombo->insertItems(0, m_pParent->bridgedAdapterList());
622 break;
623 case KNetworkAttachmentType_Internal:
624 m_pAdapterNameCombo->insertItems(0, m_pParent->internalNetworkList());
625 break;
626 case KNetworkAttachmentType_HostOnly:
627 m_pAdapterNameCombo->insertItems(0, m_pParent->hostInterfaceList());
628 break;
629 case KNetworkAttachmentType_Generic:
630 m_pAdapterNameCombo->insertItems(0, m_pParent->genericDriverList());
631 break;
632 default:
633 break;
634 }
635
636 /* Prepend 'empty' or 'default' item to alternative-name combo: */
637 if (m_pAdapterNameCombo->count() == 0)
638 {
639 switch (attachmentType())
640 {
641 case KNetworkAttachmentType_Bridged:
642 case KNetworkAttachmentType_HostOnly:
643 {
644 /* If adapter list is empty => add 'Not selected' item: */
645 int pos = m_pAdapterNameCombo->findData(pEmptyItemCode);
646 if (pos == -1)
647 m_pAdapterNameCombo->insertItem(0, tr("Not selected", "network adapter name"), pEmptyItemCode);
648 else
649 m_pAdapterNameCombo->setItemText(pos, tr("Not selected", "network adapter name"));
650 break;
651 }
652 case KNetworkAttachmentType_Internal:
653 {
654 /* Internal network list should have a default item: */
655 if (m_pAdapterNameCombo->findText("intnet") == -1)
656 m_pAdapterNameCombo->insertItem(0, "intnet");
657 break;
658 }
659 default:
660 break;
661 }
662 }
663
664 /* Unblock signals finally: */
665 m_pAdapterNameCombo->blockSignals(false);
666}
667
668void UIMachineSettingsNetwork::updateAlternativeName()
669{
670 /* Block signals initially: */
671 m_pAdapterNameCombo->blockSignals(true);
672
673 switch (attachmentType())
674 {
675 case KNetworkAttachmentType_Bridged:
676 case KNetworkAttachmentType_Internal:
677 case KNetworkAttachmentType_HostOnly:
678 case KNetworkAttachmentType_Generic:
679 {
680 m_pAdapterNameCombo->setCurrentIndex(position(m_pAdapterNameCombo, alternativeName()));
681 break;
682 }
683 default:
684 break;
685 }
686
687 /* Unblock signals finally: */
688 m_pAdapterNameCombo->blockSignals(false);
689}
690
691/* static */
692int UIMachineSettingsNetwork::position(QComboBox *pComboBox, int iData)
693{
694 int iPosition = pComboBox->findData(iData);
695 return iPosition == -1 ? 0 : iPosition;
696}
697
698/* static */
699int UIMachineSettingsNetwork::position(QComboBox *pComboBox, const QString &strText)
700{
701 int iPosition = pComboBox->findText(strText);
702 return iPosition == -1 ? 0 : iPosition;
703}
704
705/* UIMachineSettingsNetworkPage Stuff: */
706UIMachineSettingsNetworkPage::UIMachineSettingsNetworkPage()
707 : m_pValidator(0)
708 , m_pTwAdapters(0)
709{
710 /* Setup main layout: */
711 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
712 pMainLayout->setContentsMargins(0, 5, 0, 5);
713
714 /* Creating tab-widget: */
715 m_pTwAdapters = new QITabWidget(this);
716 pMainLayout->addWidget(m_pTwAdapters);
717
718 /* How many adapters to display: */
719 ulong uCount = qMin((ULONG)4, vboxGlobal().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(KChipsetType_PIIX3));
720 /* Add corresponding tab pages to parent tab widget: */
721 for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
722 {
723 /* Creating adapter tab: */
724 UIMachineSettingsNetwork *pTab = new UIMachineSettingsNetwork(this);
725 m_pTwAdapters->addTab(pTab, pTab->tabTitle());
726 }
727}
728
729/* Load data to cashe from corresponding external object(s),
730 * this task COULD be performed in other than GUI thread: */
731void UIMachineSettingsNetworkPage::loadToCacheFrom(QVariant &data)
732{
733 /* Fetch data to machine: */
734 UISettingsPageMachine::fetchData(data);
735
736 /* Clear cache initially: */
737 m_cache.clear();
738
739 /* Cache name lists: */
740 refreshBridgedAdapterList();
741 refreshInternalNetworkList(true);
742 refreshHostInterfaceList();
743 refreshGenericDriverList(true);
744
745 /* For each network adapter: */
746 for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
747 {
748 /* Prepare adapter data: */
749 UIDataSettingsMachineNetworkAdapter adapterData;
750
751 /* Check if adapter is valid: */
752 const CNetworkAdapter &adapter = m_machine.GetNetworkAdapter(iSlot);
753 if (!adapter.isNull())
754 {
755 /* Gather main options: */
756 adapterData.m_iSlot = iSlot;
757 adapterData.m_fAdapterEnabled = adapter.GetEnabled();
758 adapterData.m_attachmentType = adapter.GetAttachmentType();
759 adapterData.m_strBridgedAdapterName = wipedOutString(adapter.GetBridgedInterface());
760 adapterData.m_strInternalNetworkName = wipedOutString(adapter.GetInternalNetwork());
761 adapterData.m_strHostInterfaceName = wipedOutString(adapter.GetHostOnlyInterface());
762 adapterData.m_strGenericDriverName = wipedOutString(adapter.GetGenericDriver());
763
764 /* Gather advanced options: */
765 adapterData.m_adapterType = adapter.GetAdapterType();
766 adapterData.m_promiscuousMode = adapter.GetPromiscModePolicy();
767 adapterData.m_strMACAddress = adapter.GetMACAddress();
768 adapterData.m_strGenericProperties = summarizeGenericProperties(adapter);
769 adapterData.m_fCableConnected = adapter.GetCableConnected();
770
771 /* Gather redirect options: */
772 QVector<QString> redirects = adapter.GetNatDriver().GetRedirects();
773 for (int i = 0; i < redirects.size(); ++i)
774 {
775 QStringList redirectData = redirects[i].split(',');
776 AssertMsg(redirectData.size() == 6, ("Redirect rule should be composed of 6 parts!\n"));
777 adapterData.m_redirects << UIPortForwardingData(redirectData[0],
778 (KNATProtocol)redirectData[1].toUInt(),
779 redirectData[2],
780 redirectData[3].toUInt(),
781 redirectData[4],
782 redirectData[5].toUInt());
783 }
784 }
785
786 /* Cache adapter data: */
787 m_cache.child(iSlot).cacheInitialData(adapterData);
788 }
789
790 /* Upload machine to data: */
791 UISettingsPageMachine::uploadData(data);
792}
793
794/* Load data to corresponding widgets from cache,
795 * this task SHOULD be performed in GUI thread only: */
796void UIMachineSettingsNetworkPage::getFromCache()
797{
798 /* Setup tab order: */
799 Assert(firstWidget());
800 setTabOrder(firstWidget(), m_pTwAdapters->focusProxy());
801 QWidget *pLastFocusWidget = m_pTwAdapters->focusProxy();
802
803 /* For each network adapter: */
804 for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
805 {
806 /* Get adapter page: */
807 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
808
809 /* Load adapter data to page: */
810 pTab->fetchAdapterCache(m_cache.child(iSlot));
811
812 /* Setup page validation: */
813 pTab->setValidator(m_pValidator);
814
815 /* Setup tab order: */
816 pLastFocusWidget = pTab->setOrderAfter(pLastFocusWidget);
817 }
818
819 /* Applying language settings: */
820 retranslateUi();
821
822 /* Polish page finally: */
823 polishPage();
824
825 /* Revalidate if possible: */
826 if (m_pValidator)
827 m_pValidator->revalidate();
828}
829
830/* Save data from corresponding widgets to cache,
831 * this task SHOULD be performed in GUI thread only: */
832void UIMachineSettingsNetworkPage::putToCache()
833{
834 /* For each network adapter: */
835 for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
836 {
837 /* Get adapter page: */
838 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
839
840 /* Gather & cache adapter data: */
841 pTab->uploadAdapterCache(m_cache.child(iSlot));
842 }
843}
844
845/* Save data from cache to corresponding external object(s),
846 * this task COULD be performed in other than GUI thread: */
847void UIMachineSettingsNetworkPage::saveFromCacheTo(QVariant &data)
848{
849 /* Fetch data to machine: */
850 UISettingsPageMachine::fetchData(data);
851
852 /* Check if network data was changed: */
853 if (m_cache.wasChanged())
854 {
855 /* For each network adapter: */
856 for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
857 {
858 /* Check if adapter data was changed: */
859 const UICacheSettingsMachineNetworkAdapter &adapterCache = m_cache.child(iSlot);
860 if (adapterCache.wasChanged())
861 {
862 /* Check if adapter still valid: */
863 CNetworkAdapter adapter = m_machine.GetNetworkAdapter(iSlot);
864 if (!adapter.isNull())
865 {
866 /* Get adapter data from cache: */
867 const UIDataSettingsMachineNetworkAdapter &adapterData = adapterCache.data();
868
869 /* Store adapter data: */
870 if (isMachineOffline())
871 {
872 /* Basic attributes: */
873 adapter.SetEnabled(adapterData.m_fAdapterEnabled);
874 adapter.SetAdapterType(adapterData.m_adapterType);
875 adapter.SetMACAddress(adapterData.m_strMACAddress);
876 }
877 if (isMachineInValidMode())
878 {
879 /* Attachment type: */
880 switch (adapterData.m_attachmentType)
881 {
882 case KNetworkAttachmentType_Bridged:
883 adapter.SetBridgedInterface(adapterData.m_strBridgedAdapterName);
884 break;
885 case KNetworkAttachmentType_Internal:
886 adapter.SetInternalNetwork(adapterData.m_strInternalNetworkName);
887 break;
888 case KNetworkAttachmentType_HostOnly:
889 adapter.SetHostOnlyInterface(adapterData.m_strHostInterfaceName);
890 break;
891 case KNetworkAttachmentType_Generic:
892 adapter.SetGenericDriver(adapterData.m_strGenericDriverName);
893 updateGenericProperties(adapter, adapterData.m_strGenericProperties);
894 break;
895 default:
896 break;
897 }
898 adapter.SetAttachmentType(adapterData.m_attachmentType);
899 /* Advanced attributes: */
900 adapter.SetPromiscModePolicy(adapterData.m_promiscuousMode);
901 /* Cable connected flag: */
902 adapter.SetCableConnected(adapterData.m_fCableConnected);
903 /* Redirect options: */
904 QVector<QString> oldRedirects = adapter.GetNatDriver().GetRedirects();
905 for (int i = 0; i < oldRedirects.size(); ++i)
906 adapter.GetNatDriver().RemoveRedirect(oldRedirects[i].section(',', 0, 0));
907 UIPortForwardingDataList newRedirects = adapterData.m_redirects;
908 for (int i = 0; i < newRedirects.size(); ++i)
909 {
910 UIPortForwardingData newRedirect = newRedirects[i];
911 adapter.GetNatDriver().AddRedirect(newRedirect.name, newRedirect.protocol,
912 newRedirect.hostIp, newRedirect.hostPort.value(),
913 newRedirect.guestIp, newRedirect.guestPort.value());
914 }
915 }
916 }
917 }
918 }
919 }
920
921 /* Upload machine to data: */
922 UISettingsPageMachine::uploadData(data);
923}
924
925void UIMachineSettingsNetworkPage::setValidator(QIWidgetValidator *pValidator)
926{
927 m_pValidator = pValidator;
928}
929
930bool UIMachineSettingsNetworkPage::revalidate(QString &strWarning, QString &strTitle)
931{
932 bool fValid = true;
933
934 for (int i = 0; i < m_pTwAdapters->count(); ++i)
935 {
936 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(i));
937 Assert(pTab);
938 fValid = pTab->revalidate(strWarning, strTitle);
939 if (!fValid)
940 break;
941 }
942
943 return fValid;
944}
945
946void UIMachineSettingsNetworkPage::retranslateUi()
947{
948 for (int i = 0; i < m_pTwAdapters->count(); ++ i)
949 {
950 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(i));
951 Assert(pTab);
952 m_pTwAdapters->setTabText(i, pTab->tabTitle());
953 }
954}
955
956void UIMachineSettingsNetworkPage::sltHandleUpdatedTab()
957{
958 /* Determine the sender: */
959 UIMachineSettingsNetwork *pSender = qobject_cast<UIMachineSettingsNetwork*>(sender());
960 AssertMsg(pSender, ("This slot should be called only through signal<->slot mechanism from one of UIMachineSettingsNetwork tabs!\n"));
961
962 /* Determine sender's attachment type: */
963 KNetworkAttachmentType senderAttachmentType = pSender->attachmentType();
964 switch (senderAttachmentType)
965 {
966 case KNetworkAttachmentType_Internal:
967 {
968 refreshInternalNetworkList();
969 break;
970 }
971 case KNetworkAttachmentType_Generic:
972 {
973 refreshGenericDriverList();
974 break;
975 }
976 default:
977 break;
978 }
979
980 /* Update all the tabs except the sender: */
981 for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
982 {
983 /* Get the iterated tab: */
984 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
985 AssertMsg(pTab, ("All the tabs of m_pTwAdapters should be of the UIMachineSettingsNetwork type!\n"));
986
987 /* Update all the tabs (except sender) with the same attachment type as sender have: */
988 if (pTab != pSender && pTab->attachmentType() == senderAttachmentType)
989 pTab->reloadAlternative();
990 }
991}
992
993void UIMachineSettingsNetworkPage::polishPage()
994{
995 /* Get the count of network adapter tabs: */
996 for (int iSlot = 0; iSlot < m_pTwAdapters->count(); ++iSlot)
997 {
998 m_pTwAdapters->setTabEnabled(iSlot,
999 isMachineOffline() ||
1000 (isMachineInValidMode() && m_cache.child(iSlot).base().m_fAdapterEnabled));
1001 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iSlot));
1002 pTab->polishTab();
1003 }
1004}
1005
1006void UIMachineSettingsNetworkPage::refreshBridgedAdapterList()
1007{
1008 /* Reload bridged interface list: */
1009 m_bridgedAdapterList.clear();
1010 const CHostNetworkInterfaceVector &ifaces = vboxGlobal().host().GetNetworkInterfaces();
1011 for (int i = 0; i < ifaces.size(); ++i)
1012 {
1013 const CHostNetworkInterface &iface = ifaces[i];
1014 if (iface.GetInterfaceType() == KHostNetworkInterfaceType_Bridged && !m_bridgedAdapterList.contains(iface.GetName()))
1015 m_bridgedAdapterList << iface.GetName();
1016 }
1017}
1018
1019void UIMachineSettingsNetworkPage::refreshInternalNetworkList(bool fFullRefresh /* = false */)
1020{
1021 /* Reload internal network list: */
1022 m_internalNetworkList.clear();
1023 /* Get internal network names from other VMs: */
1024 if (fFullRefresh)
1025 m_internalNetworkList << otherInternalNetworkList();
1026 /* Append internal network list with names from all the tabs: */
1027 for (int iTab = 0; iTab < m_pTwAdapters->count(); ++iTab)
1028 {
1029 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iTab));
1030 if (pTab)
1031 {
1032 QString strName = pTab->alternativeName(KNetworkAttachmentType_Internal);
1033 if (!strName.isEmpty() && !m_internalNetworkList.contains(strName))
1034 m_internalNetworkList << strName;
1035 }
1036 }
1037}
1038
1039void UIMachineSettingsNetworkPage::refreshHostInterfaceList()
1040{
1041 /* Reload host-only interface list: */
1042 m_hostInterfaceList.clear();
1043 const CHostNetworkInterfaceVector &ifaces = vboxGlobal().host().GetNetworkInterfaces();
1044 for (int i = 0; i < ifaces.size(); ++i)
1045 {
1046 const CHostNetworkInterface &iface = ifaces[i];
1047 if (iface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly && !m_hostInterfaceList.contains(iface.GetName()))
1048 m_hostInterfaceList << iface.GetName();
1049 }
1050}
1051
1052void UIMachineSettingsNetworkPage::refreshGenericDriverList(bool fFullRefresh /* = false */)
1053{
1054 /* Load generic driver list: */
1055 m_genericDriverList.clear();
1056 /* Get generic driver names from other VMs: */
1057 if (fFullRefresh)
1058 m_genericDriverList << otherGenericDriverList();
1059 /* Append generic driver list with names from all the tabs: */
1060 for (int iTab = 0; iTab < m_pTwAdapters->count(); ++iTab)
1061 {
1062 UIMachineSettingsNetwork *pTab = qobject_cast<UIMachineSettingsNetwork*>(m_pTwAdapters->widget(iTab));
1063 if (pTab)
1064 {
1065 QString strName = pTab->alternativeName(KNetworkAttachmentType_Generic);
1066 if (!strName.isEmpty() && !m_genericDriverList.contains(strName))
1067 m_genericDriverList << strName;
1068 }
1069 }
1070}
1071
1072/* static */
1073QStringList UIMachineSettingsNetworkPage::otherInternalNetworkList()
1074{
1075 /* Load total internal network list of all VMs: */
1076 CVirtualBox vbox = vboxGlobal().virtualBox();
1077 QStringList otherInternalNetworks(QList<QString>::fromVector(vbox.GetInternalNetworks()));
1078 return otherInternalNetworks;
1079}
1080
1081/* static */
1082QStringList UIMachineSettingsNetworkPage::otherGenericDriverList()
1083{
1084 /* Load total generic driver list of all VMs: */
1085 CVirtualBox vbox = vboxGlobal().virtualBox();
1086 QStringList otherGenericDrivers(QList<QString>::fromVector(vbox.GetGenericNetworkDrivers()));
1087 return otherGenericDrivers;
1088}
1089
1090/* static */
1091QString UIMachineSettingsNetworkPage::summarizeGenericProperties(const CNetworkAdapter &adapter)
1092{
1093 /* Prepare formatted string: */
1094 QVector<QString> names;
1095 QVector<QString> props;
1096 props = adapter.GetProperties(QString(), names);
1097 QString strResult;
1098 /* Load generic properties: */
1099 for (int i = 0; i < names.size(); ++i)
1100 {
1101 strResult += names[i] + "=" + props[i];
1102 if (i < names.size() - 1)
1103 strResult += "\n";
1104 }
1105 /* Return formatted string: */
1106 return strResult;
1107}
1108
1109/* static */
1110void UIMachineSettingsNetworkPage::updateGenericProperties(CNetworkAdapter &adapter, const QString &strPropText)
1111{
1112 /* Parse new properties: */
1113 QStringList newProps = strPropText.split("\n");
1114 QHash<QString, QString> hash;
1115
1116 /* Save new properties: */
1117 for (int i = 0; i < newProps.size(); ++i)
1118 {
1119 QString strLine = newProps[i];
1120 int iSplitPos = strLine.indexOf("=");
1121 if (iSplitPos)
1122 {
1123 QString strKey = strLine.left(iSplitPos);
1124 QString strVal = strLine.mid(iSplitPos+1);
1125 adapter.SetProperty(strKey, strVal);
1126 hash[strKey] = strVal;
1127 }
1128 }
1129
1130 /* Removing deleted properties: */
1131 QVector<QString> names;
1132 QVector<QString> props;
1133 props = adapter.GetProperties(QString(), names);
1134 for (int i = 0; i < names.size(); ++i)
1135 {
1136 QString strName = names[i];
1137 QString strValue = props[i];
1138 if (strValue != hash[strName])
1139 adapter.SetProperty(strName, hash[strName]);
1140 }
1141}
1142
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette