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