1 | /* $Id: UIDetailsWidgetNATNetwork.cpp 103711 2024-03-06 17:44:24Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIDetailsWidgetNATNetwork class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QCheckBox>
|
---|
30 | #include <QFontMetrics>
|
---|
31 | #include <QLabel>
|
---|
32 | #include <QPushButton>
|
---|
33 | #include <QRadioButton>
|
---|
34 | #include <QStyleOption>
|
---|
35 | #include <QVBoxLayout>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "QIDialogButtonBox.h"
|
---|
39 | #include "QILineEdit.h"
|
---|
40 | #include "QITabWidget.h"
|
---|
41 | #include "UIIconPool.h"
|
---|
42 | #include "UIDetailsWidgetNATNetwork.h"
|
---|
43 | #include "UIMessageCenter.h"
|
---|
44 | #include "UINetworkManager.h"
|
---|
45 | #include "UINetworkManagerUtils.h"
|
---|
46 | #include "UINotificationCenter.h"
|
---|
47 |
|
---|
48 | /* Other VBox includes: */
|
---|
49 | #include "iprt/cidr.h"
|
---|
50 |
|
---|
51 |
|
---|
52 | UIDetailsWidgetNATNetwork::UIDetailsWidgetNATNetwork(EmbedTo enmEmbedding, QWidget *pParent /* = 0 */)
|
---|
53 | : QIWithRetranslateUI<QWidget>(pParent)
|
---|
54 | , m_enmEmbedding(enmEmbedding)
|
---|
55 | , m_pTabWidget(0)
|
---|
56 | , m_pLabelNetworkName(0)
|
---|
57 | , m_pEditorNetworkName(0)
|
---|
58 | , m_pLabelNetworkIPv4Prefix(0)
|
---|
59 | , m_pEditorNetworkIPv4Prefix(0)
|
---|
60 | , m_pCheckboxSupportsDHCP(0)
|
---|
61 | , m_pCheckboxIPv6(0)
|
---|
62 | , m_pLabelNetworkIPv6Prefix(0)
|
---|
63 | , m_pEditorNetworkIPv6Prefix(0)
|
---|
64 | , m_pCheckboxAdvertiseDefaultIPv6Route(0)
|
---|
65 | , m_pButtonBoxOptions(0)
|
---|
66 | , m_pTabWidgetForwarding(0)
|
---|
67 | , m_pForwardingTableIPv4(0)
|
---|
68 | , m_pForwardingTableIPv6(0)
|
---|
69 | , m_pButtonBoxForwarding(0)
|
---|
70 | , m_fHoldPosition(false)
|
---|
71 | {
|
---|
72 | prepare();
|
---|
73 | }
|
---|
74 |
|
---|
75 | void UIDetailsWidgetNATNetwork::setData(const UIDataNATNetwork &data,
|
---|
76 | const QStringList &busyNames /* = QStringList() */,
|
---|
77 | bool fHoldPosition /* = false */)
|
---|
78 | {
|
---|
79 | /* Cache old/new data: */
|
---|
80 | m_oldData = data;
|
---|
81 | m_newData = m_oldData;
|
---|
82 | m_busyNames = busyNames;
|
---|
83 | m_fHoldPosition = fHoldPosition;
|
---|
84 |
|
---|
85 | /* Load 'Options' data: */
|
---|
86 | loadDataForOptions();
|
---|
87 | /* Load 'Forwarding' data: */
|
---|
88 | loadDataForForwarding();
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool UIDetailsWidgetNATNetwork::revalidate() const
|
---|
92 | {
|
---|
93 | /* Make sure network name isn't empty: */
|
---|
94 | if (m_newData.m_strName.isEmpty())
|
---|
95 | {
|
---|
96 | UINotificationMessage::warnAboutNoNameSpecified(m_oldData.m_strName);
|
---|
97 | return false;
|
---|
98 | }
|
---|
99 | else
|
---|
100 | {
|
---|
101 | /* Make sure item names are unique: */
|
---|
102 | if (m_busyNames.contains(m_newData.m_strName))
|
---|
103 | {
|
---|
104 | UINotificationMessage::warnAboutNameAlreadyBusy(m_newData.m_strName);
|
---|
105 | return false;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | /* Make sure IPv4 prefix isn't empty: */
|
---|
110 | if (m_newData.m_strPrefixIPv4.isEmpty())
|
---|
111 | {
|
---|
112 | UINotificationMessage::warnAboutNoIPv4PrefixSpecified(m_newData.m_strName);
|
---|
113 | return false;
|
---|
114 | }
|
---|
115 | /* Make sure IPv6 prefix isn't empty if IPv6 is supported: */
|
---|
116 | if (m_newData.m_fSupportsIPv6 && m_newData.m_strPrefixIPv6.isEmpty())
|
---|
117 | {
|
---|
118 | UINotificationMessage::warnAboutNoIPv6PrefixSpecified(m_newData.m_strName);
|
---|
119 | return false;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /* Validate 'Forwarding' tab content: */
|
---|
123 | return m_pForwardingTableIPv4->validate() && m_pForwardingTableIPv6->validate();
|
---|
124 | }
|
---|
125 |
|
---|
126 | void UIDetailsWidgetNATNetwork::updateButtonStates()
|
---|
127 | {
|
---|
128 | // if (m_oldData != m_newData)
|
---|
129 | // printf("Network: %s, %s, %s, %d, %d, %d\n",
|
---|
130 | // m_newData.m_strName.toUtf8().constData(),
|
---|
131 | // m_newData.m_strPrefixIPv4.toUtf8().constData(),
|
---|
132 | // m_newData.m_strPrefixIPv6.toUtf8().constData(),
|
---|
133 | // m_newData.m_fSupportsDHCP,
|
---|
134 | // m_newData.m_fSupportsIPv6,
|
---|
135 | // m_newData.m_fAdvertiseDefaultIPv6Route);
|
---|
136 |
|
---|
137 | /* Update 'Apply' / 'Reset' button states: */
|
---|
138 | if (m_pButtonBoxOptions)
|
---|
139 | {
|
---|
140 | m_pButtonBoxOptions->button(QDialogButtonBox::Cancel)->setEnabled(m_oldData != m_newData);
|
---|
141 | m_pButtonBoxOptions->button(QDialogButtonBox::Ok)->setEnabled(m_oldData != m_newData);
|
---|
142 | }
|
---|
143 | if (m_pButtonBoxForwarding)
|
---|
144 | {
|
---|
145 | m_pButtonBoxForwarding->button(QDialogButtonBox::Cancel)->setEnabled(m_oldData != m_newData);
|
---|
146 | m_pButtonBoxForwarding->button(QDialogButtonBox::Ok)->setEnabled(m_oldData != m_newData);
|
---|
147 | }
|
---|
148 |
|
---|
149 | /* Notify listeners as well: */
|
---|
150 | emit sigDataChanged(m_oldData != m_newData);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void UIDetailsWidgetNATNetwork::retranslateUi()
|
---|
154 | {
|
---|
155 | /* Translate tab-widget: */
|
---|
156 | if (m_pTabWidget)
|
---|
157 | {
|
---|
158 | m_pTabWidget->setTabText(0, UINetworkManager::tr("&General Options"));
|
---|
159 | m_pTabWidget->setTabText(1, UINetworkManager::tr("&Port Forwarding"));
|
---|
160 | }
|
---|
161 |
|
---|
162 | if (m_pLabelNetworkName)
|
---|
163 | m_pLabelNetworkName->setText(UINetworkManager::tr("N&ame:"));
|
---|
164 | if (m_pEditorNetworkName)
|
---|
165 | m_pEditorNetworkName->setToolTip(UINetworkManager::tr("Holds the name for this network."));
|
---|
166 | if (m_pLabelNetworkIPv4Prefix)
|
---|
167 | m_pLabelNetworkIPv4Prefix->setText(UINetworkManager::tr("IPv&4 Prefix:"));
|
---|
168 | if (m_pEditorNetworkIPv4Prefix)
|
---|
169 | m_pEditorNetworkIPv4Prefix->setToolTip(UINetworkManager::tr("Holds the IPv4 prefix for this network."));
|
---|
170 | if (m_pLabelNetworkIPv6Prefix)
|
---|
171 | m_pLabelNetworkIPv6Prefix->setText(UINetworkManager::tr("IPv&6 Prefix:"));
|
---|
172 | if (m_pEditorNetworkIPv6Prefix)
|
---|
173 | m_pEditorNetworkIPv6Prefix->setToolTip(UINetworkManager::tr("Holds the IPv6 prefix for this network."));
|
---|
174 | if (m_pCheckboxSupportsDHCP)
|
---|
175 | {
|
---|
176 | m_pCheckboxSupportsDHCP->setText(UINetworkManager::tr("Enable &DHCP"));
|
---|
177 | m_pCheckboxSupportsDHCP->setToolTip(UINetworkManager::tr("When checked, this network will support DHCP."));
|
---|
178 | }
|
---|
179 | if (m_pCheckboxIPv6)
|
---|
180 | {
|
---|
181 | m_pCheckboxIPv6->setText(UINetworkManager::tr("&Enable IPv6"));
|
---|
182 | m_pCheckboxIPv6->setToolTip(UINetworkManager::tr("When checked, this network will support IPv6."));
|
---|
183 | }
|
---|
184 | if (m_pCheckboxAdvertiseDefaultIPv6Route)
|
---|
185 | {
|
---|
186 | m_pCheckboxAdvertiseDefaultIPv6Route->setText(UINetworkManager::tr("Advertise Default IPv6 &Route"));
|
---|
187 | m_pCheckboxAdvertiseDefaultIPv6Route->setToolTip(UINetworkManager::tr("When checked, this network will be advertised "
|
---|
188 | "as the default IPv6 route."));
|
---|
189 | }
|
---|
190 | if (m_pButtonBoxOptions)
|
---|
191 | {
|
---|
192 | m_pButtonBoxOptions->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("Reset"));
|
---|
193 | m_pButtonBoxOptions->button(QDialogButtonBox::Ok)->setText(UINetworkManager::tr("Apply"));
|
---|
194 | m_pButtonBoxOptions->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
|
---|
195 | m_pButtonBoxOptions->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
|
---|
196 | m_pButtonBoxOptions->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Reset changes in current "
|
---|
197 | "interface details"));
|
---|
198 | m_pButtonBoxOptions->button(QDialogButtonBox::Ok)->setStatusTip(UINetworkManager::tr("Apply changes in current "
|
---|
199 | "interface details"));
|
---|
200 | m_pButtonBoxOptions->button(QDialogButtonBox::Cancel)->
|
---|
201 | setToolTip(UINetworkManager::tr("Reset Changes (%1)").arg(m_pButtonBoxOptions->button(QDialogButtonBox::Cancel)->shortcut().toString()));
|
---|
202 | m_pButtonBoxOptions->button(QDialogButtonBox::Ok)->
|
---|
203 | setToolTip(UINetworkManager::tr("Apply Changes (%1)").arg(m_pButtonBoxOptions->button(QDialogButtonBox::Ok)->shortcut().toString()));
|
---|
204 | }
|
---|
205 |
|
---|
206 | /* Translate 'Forwarding' tab content: */
|
---|
207 | if (m_pTabWidgetForwarding)
|
---|
208 | {
|
---|
209 | m_pTabWidgetForwarding->setTabText(0, UINetworkManager::tr("IPv&4"));
|
---|
210 | m_pTabWidgetForwarding->setTabText(1, UINetworkManager::tr("IPv&6"));
|
---|
211 | }
|
---|
212 | if (m_pButtonBoxForwarding)
|
---|
213 | {
|
---|
214 | m_pButtonBoxForwarding->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("Reset"));
|
---|
215 | m_pButtonBoxForwarding->button(QDialogButtonBox::Ok)->setText(UINetworkManager::tr("Apply"));
|
---|
216 | m_pButtonBoxForwarding->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
|
---|
217 | m_pButtonBoxForwarding->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
|
---|
218 | m_pButtonBoxForwarding->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Reset changes in current "
|
---|
219 | "interface details"));
|
---|
220 | m_pButtonBoxForwarding->button(QDialogButtonBox::Ok)->setStatusTip(UINetworkManager::tr("Apply changes in current "
|
---|
221 | "interface details"));
|
---|
222 | m_pButtonBoxForwarding->button(QDialogButtonBox::Cancel)->
|
---|
223 | setToolTip(UINetworkManager::tr("Reset Changes (%1)").arg(m_pButtonBoxForwarding->button(QDialogButtonBox::Cancel)->shortcut().toString()));
|
---|
224 | m_pButtonBoxForwarding->button(QDialogButtonBox::Ok)->
|
---|
225 | setToolTip(UINetworkManager::tr("Apply Changes (%1)").arg(m_pButtonBoxForwarding->button(QDialogButtonBox::Ok)->shortcut().toString()));
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | void UIDetailsWidgetNATNetwork::sltNetworkNameChanged(const QString &strText)
|
---|
230 | {
|
---|
231 | m_newData.m_strName = strText;
|
---|
232 | updateButtonStates();
|
---|
233 | }
|
---|
234 |
|
---|
235 | void UIDetailsWidgetNATNetwork::sltNetworkIPv4PrefixChanged(const QString &strText)
|
---|
236 | {
|
---|
237 | m_newData.m_strPrefixIPv4 = strText;
|
---|
238 | updateButtonStates();
|
---|
239 | }
|
---|
240 |
|
---|
241 | void UIDetailsWidgetNATNetwork::sltNetworkIPv6PrefixChanged(const QString &strText)
|
---|
242 | {
|
---|
243 | m_newData.m_strPrefixIPv6 = strText;
|
---|
244 | updateButtonStates();
|
---|
245 | }
|
---|
246 |
|
---|
247 | void UIDetailsWidgetNATNetwork::sltSupportsDHCPChanged(bool fChecked)
|
---|
248 | {
|
---|
249 | m_newData.m_fSupportsDHCP = fChecked;
|
---|
250 | updateButtonStates();
|
---|
251 | }
|
---|
252 |
|
---|
253 | void UIDetailsWidgetNATNetwork::sltSupportsIPv6Changed(bool fChecked)
|
---|
254 | {
|
---|
255 | m_newData.m_fSupportsIPv6 = fChecked;
|
---|
256 | loadDataForOptions();
|
---|
257 | updateButtonStates();
|
---|
258 | }
|
---|
259 |
|
---|
260 | void UIDetailsWidgetNATNetwork::sltAdvertiseDefaultIPv6RouteChanged(bool fChecked)
|
---|
261 | {
|
---|
262 | m_newData.m_fAdvertiseDefaultIPv6Route = fChecked;
|
---|
263 | updateButtonStates();
|
---|
264 | }
|
---|
265 |
|
---|
266 | void UIDetailsWidgetNATNetwork::sltForwardingRulesIPv4Changed()
|
---|
267 | {
|
---|
268 | m_newData.m_rules4 = m_pForwardingTableIPv4->rules();
|
---|
269 | updateButtonStates();
|
---|
270 | }
|
---|
271 |
|
---|
272 | void UIDetailsWidgetNATNetwork::sltForwardingRulesIPv6Changed()
|
---|
273 | {
|
---|
274 | m_newData.m_rules6 = m_pForwardingTableIPv6->rules();
|
---|
275 | updateButtonStates();
|
---|
276 | }
|
---|
277 |
|
---|
278 | void UIDetailsWidgetNATNetwork::sltHandleButtonBoxClick(QAbstractButton *pButton)
|
---|
279 | {
|
---|
280 | /* Make sure button-boxes exist: */
|
---|
281 | if (!m_pButtonBoxOptions || !m_pButtonBoxForwarding)
|
---|
282 | return;
|
---|
283 |
|
---|
284 | /* Disable buttons first of all: */
|
---|
285 | m_pButtonBoxOptions->button(QDialogButtonBox::Cancel)->setEnabled(false);
|
---|
286 | m_pButtonBoxOptions->button(QDialogButtonBox::Ok)->setEnabled(false);
|
---|
287 | m_pButtonBoxForwarding->button(QDialogButtonBox::Cancel)->setEnabled(false);
|
---|
288 | m_pButtonBoxForwarding->button(QDialogButtonBox::Ok)->setEnabled(false);
|
---|
289 |
|
---|
290 | /* Compare with known buttons: */
|
---|
291 | if ( pButton == m_pButtonBoxOptions->button(QDialogButtonBox::Cancel)
|
---|
292 | || pButton == m_pButtonBoxForwarding->button(QDialogButtonBox::Cancel))
|
---|
293 | emit sigDataChangeRejected();
|
---|
294 | else
|
---|
295 | if ( pButton == m_pButtonBoxOptions->button(QDialogButtonBox::Ok)
|
---|
296 | || pButton == m_pButtonBoxForwarding->button(QDialogButtonBox::Ok))
|
---|
297 | emit sigDataChangeAccepted();
|
---|
298 | }
|
---|
299 |
|
---|
300 | void UIDetailsWidgetNATNetwork::prepare()
|
---|
301 | {
|
---|
302 | /* Prepare this: */
|
---|
303 | prepareThis();
|
---|
304 |
|
---|
305 | /* Apply language settings: */
|
---|
306 | retranslateUi();
|
---|
307 |
|
---|
308 | /* Update button states finally: */
|
---|
309 | updateButtonStates();
|
---|
310 | }
|
---|
311 |
|
---|
312 | void UIDetailsWidgetNATNetwork::prepareThis()
|
---|
313 | {
|
---|
314 | /* Create layout: */
|
---|
315 | new QVBoxLayout(this);
|
---|
316 | if (layout())
|
---|
317 | {
|
---|
318 | /* Configure layout: */
|
---|
319 | layout()->setContentsMargins(0, 0, 0, 0);
|
---|
320 |
|
---|
321 | /* Prepare tab-widget: */
|
---|
322 | prepareTabWidget();
|
---|
323 | }
|
---|
324 | }
|
---|
325 |
|
---|
326 | void UIDetailsWidgetNATNetwork::prepareTabWidget()
|
---|
327 | {
|
---|
328 | /* Create tab-widget: */
|
---|
329 | m_pTabWidget = new QITabWidget(this);
|
---|
330 | if (m_pTabWidget)
|
---|
331 | {
|
---|
332 | /* Prepare 'Options' tab: */
|
---|
333 | prepareTabOptions();
|
---|
334 | /* Prepare 'Forwarding' tab: */
|
---|
335 | prepareTabForwarding();
|
---|
336 |
|
---|
337 | /* Add into layout: */
|
---|
338 | layout()->addWidget(m_pTabWidget);
|
---|
339 | }
|
---|
340 | }
|
---|
341 |
|
---|
342 | void UIDetailsWidgetNATNetwork::prepareTabOptions()
|
---|
343 | {
|
---|
344 | /* Prepare 'Options' tab: */
|
---|
345 | QWidget *pTabOptions = new QWidget(m_pTabWidget);
|
---|
346 | if (pTabOptions)
|
---|
347 | {
|
---|
348 | /* Prepare 'Options' layout: */
|
---|
349 | QGridLayout *pLayoutOptions = new QGridLayout(pTabOptions);
|
---|
350 | if (pLayoutOptions)
|
---|
351 | {
|
---|
352 | pLayoutOptions->setColumnStretch(0, 0);
|
---|
353 | pLayoutOptions->setColumnStretch(1, 0);
|
---|
354 | pLayoutOptions->setColumnStretch(2, 1);
|
---|
355 | pLayoutOptions->setColumnStretch(3, 1);
|
---|
356 | #ifdef VBOX_WS_MAC
|
---|
357 | pLayoutOptions->setSpacing(10);
|
---|
358 | pLayoutOptions->setContentsMargins(10, 10, 10, 10);
|
---|
359 | #endif
|
---|
360 |
|
---|
361 | /* Prepare network name label: */
|
---|
362 | m_pLabelNetworkName = new QLabel(pTabOptions);
|
---|
363 | if (m_pLabelNetworkName)
|
---|
364 | {
|
---|
365 | m_pLabelNetworkName->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
---|
366 | pLayoutOptions->addWidget(m_pLabelNetworkName, 0, 0, 1, 2);
|
---|
367 | }
|
---|
368 | /* Prepare network name editor: */
|
---|
369 | m_pEditorNetworkName = new QLineEdit(pTabOptions);
|
---|
370 | if (m_pEditorNetworkName)
|
---|
371 | {
|
---|
372 | if (m_pLabelNetworkName)
|
---|
373 | m_pLabelNetworkName->setBuddy(m_pEditorNetworkName);
|
---|
374 | connect(m_pEditorNetworkName, &QLineEdit::textEdited,
|
---|
375 | this, &UIDetailsWidgetNATNetwork::sltNetworkNameChanged);
|
---|
376 |
|
---|
377 | pLayoutOptions->addWidget(m_pEditorNetworkName, 0, 2, 1, 2);
|
---|
378 | }
|
---|
379 |
|
---|
380 | /* Prepare network IPv4 prefix label: */
|
---|
381 | m_pLabelNetworkIPv4Prefix = new QLabel(pTabOptions);
|
---|
382 | if (m_pLabelNetworkIPv4Prefix)
|
---|
383 | {
|
---|
384 | m_pLabelNetworkIPv4Prefix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
---|
385 | pLayoutOptions->addWidget(m_pLabelNetworkIPv4Prefix, 1, 0, 1, 2);
|
---|
386 | }
|
---|
387 | /* Prepare network IPv4 prefix editor: */
|
---|
388 | m_pEditorNetworkIPv4Prefix = new QLineEdit(pTabOptions);
|
---|
389 | if (m_pEditorNetworkIPv4Prefix)
|
---|
390 | {
|
---|
391 | if (m_pLabelNetworkIPv4Prefix)
|
---|
392 | m_pLabelNetworkIPv4Prefix->setBuddy(m_pEditorNetworkIPv4Prefix);
|
---|
393 | connect(m_pEditorNetworkIPv4Prefix, &QLineEdit::textEdited,
|
---|
394 | this, &UIDetailsWidgetNATNetwork::sltNetworkIPv4PrefixChanged);
|
---|
395 |
|
---|
396 | pLayoutOptions->addWidget(m_pEditorNetworkIPv4Prefix, 1, 2, 1, 2);
|
---|
397 | }
|
---|
398 | /* Prepare 'supports DHCP' check-box: */
|
---|
399 | m_pCheckboxSupportsDHCP = new QCheckBox(pTabOptions);
|
---|
400 | if (m_pCheckboxSupportsDHCP)
|
---|
401 | {
|
---|
402 | connect(m_pCheckboxSupportsDHCP, &QCheckBox::toggled,
|
---|
403 | this, &UIDetailsWidgetNATNetwork::sltSupportsDHCPChanged);
|
---|
404 | pLayoutOptions->addWidget(m_pCheckboxSupportsDHCP, 2, 2);
|
---|
405 | }
|
---|
406 |
|
---|
407 | /* Prepare IPv6 check-box: */
|
---|
408 | m_pCheckboxIPv6 = new QCheckBox(pTabOptions);
|
---|
409 | if (m_pCheckboxIPv6)
|
---|
410 | {
|
---|
411 | connect(m_pCheckboxIPv6, &QCheckBox::toggled,
|
---|
412 | this, &UIDetailsWidgetNATNetwork::sltSupportsIPv6Changed);
|
---|
413 | pLayoutOptions->addWidget(m_pCheckboxIPv6, 3, 0, 1, 3);
|
---|
414 | }
|
---|
415 | /* Prepare shifting spacer: */
|
---|
416 | QSpacerItem *pSpacer = new QSpacerItem(20, 0, QSizePolicy::Fixed, QSizePolicy::Minimum);
|
---|
417 | if (pSpacer)
|
---|
418 | pLayoutOptions->addItem(pSpacer, 4, 0);
|
---|
419 | /* Prepare network IPv6 prefix label: */
|
---|
420 | m_pLabelNetworkIPv6Prefix = new QLabel(pTabOptions);
|
---|
421 | if (m_pLabelNetworkIPv6Prefix)
|
---|
422 | {
|
---|
423 | m_pLabelNetworkIPv6Prefix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
---|
424 | pLayoutOptions->addWidget(m_pLabelNetworkIPv6Prefix, 4, 1);
|
---|
425 | }
|
---|
426 | /* Prepare network IPv6 prefix editor: */
|
---|
427 | m_pEditorNetworkIPv6Prefix = new QLineEdit(pTabOptions);
|
---|
428 | if (m_pEditorNetworkIPv6Prefix)
|
---|
429 | {
|
---|
430 | if (m_pLabelNetworkIPv6Prefix)
|
---|
431 | m_pLabelNetworkIPv6Prefix->setBuddy(m_pEditorNetworkIPv6Prefix);
|
---|
432 | connect(m_pEditorNetworkIPv6Prefix, &QLineEdit::textEdited,
|
---|
433 | this, &UIDetailsWidgetNATNetwork::sltNetworkIPv6PrefixChanged);
|
---|
434 |
|
---|
435 | pLayoutOptions->addWidget(m_pEditorNetworkIPv6Prefix, 4, 2, 1, 2);
|
---|
436 | }
|
---|
437 | /* Prepare 'advertise default IPv6 route' check-box: */
|
---|
438 | m_pCheckboxAdvertiseDefaultIPv6Route = new QCheckBox(pTabOptions);
|
---|
439 | if (m_pCheckboxAdvertiseDefaultIPv6Route)
|
---|
440 | {
|
---|
441 | connect(m_pCheckboxAdvertiseDefaultIPv6Route, &QCheckBox::toggled,
|
---|
442 | this, &UIDetailsWidgetNATNetwork::sltAdvertiseDefaultIPv6RouteChanged);
|
---|
443 | pLayoutOptions->addWidget(m_pCheckboxAdvertiseDefaultIPv6Route, 5, 2);
|
---|
444 | }
|
---|
445 |
|
---|
446 | /* If parent embedded into stack: */
|
---|
447 | if (m_enmEmbedding == EmbedTo_Stack)
|
---|
448 | {
|
---|
449 | /* Prepare button-box: */
|
---|
450 | m_pButtonBoxOptions = new QIDialogButtonBox(pTabOptions);
|
---|
451 | if (m_pButtonBoxOptions)
|
---|
452 | {
|
---|
453 | m_pButtonBoxOptions->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
---|
454 | connect(m_pButtonBoxOptions, &QIDialogButtonBox::clicked, this, &UIDetailsWidgetNATNetwork::sltHandleButtonBoxClick);
|
---|
455 |
|
---|
456 | pLayoutOptions->addWidget(m_pButtonBoxOptions, 7, 0, 1, 4);
|
---|
457 | }
|
---|
458 | }
|
---|
459 | }
|
---|
460 |
|
---|
461 | m_pTabWidget->addTab(pTabOptions, QString());
|
---|
462 | }
|
---|
463 | }
|
---|
464 |
|
---|
465 | void UIDetailsWidgetNATNetwork::prepareTabForwarding()
|
---|
466 | {
|
---|
467 | /* Prepare 'Forwarding' tab: */
|
---|
468 | QWidget *pTabForwarding = new QWidget(m_pTabWidget);
|
---|
469 | if (pTabForwarding)
|
---|
470 | {
|
---|
471 | /* Prepare 'Forwarding' layout: */
|
---|
472 | QGridLayout *pLayoutForwarding = new QGridLayout(pTabForwarding);
|
---|
473 | if (pLayoutForwarding)
|
---|
474 | {
|
---|
475 | #ifdef VBOX_WS_MAC
|
---|
476 | /* Configure layout: */
|
---|
477 | pLayoutForwarding->setSpacing(10);
|
---|
478 | pLayoutForwarding->setContentsMargins(10, 10, 10, 10);
|
---|
479 | #endif
|
---|
480 |
|
---|
481 | /* Prepare forwarding tab-widget: */
|
---|
482 | m_pTabWidgetForwarding = new QITabWidget(pTabForwarding);
|
---|
483 | if (m_pTabWidgetForwarding)
|
---|
484 | {
|
---|
485 | /* Prepare IPv4 forwarding table: */
|
---|
486 | m_pForwardingTableIPv4 = new UIPortForwardingTable(UIPortForwardingDataList(),
|
---|
487 | false /* ip IPv6 protocol */,
|
---|
488 | false /* allow empty guest IPs */);
|
---|
489 | if (m_pForwardingTableIPv4)
|
---|
490 | {
|
---|
491 | connect(m_pForwardingTableIPv4, &UIPortForwardingTable::sigDataChanged,
|
---|
492 | this, &UIDetailsWidgetNATNetwork::sltForwardingRulesIPv4Changed);
|
---|
493 | m_pTabWidgetForwarding->addTab(m_pForwardingTableIPv4, QString());
|
---|
494 | }
|
---|
495 | /* Prepare IPv6 forwarding table: */
|
---|
496 | m_pForwardingTableIPv6 = new UIPortForwardingTable(UIPortForwardingDataList(),
|
---|
497 | true /* ip IPv6 protocol */,
|
---|
498 | false /* allow empty guest IPs */);
|
---|
499 | if (m_pForwardingTableIPv6)
|
---|
500 | {
|
---|
501 | connect(m_pForwardingTableIPv4, &UIPortForwardingTable::sigDataChanged,
|
---|
502 | this, &UIDetailsWidgetNATNetwork::sltForwardingRulesIPv6Changed);
|
---|
503 | m_pTabWidgetForwarding->addTab(m_pForwardingTableIPv6, QString());
|
---|
504 | }
|
---|
505 |
|
---|
506 | pLayoutForwarding->addWidget(m_pTabWidgetForwarding, 0, 0);
|
---|
507 | }
|
---|
508 |
|
---|
509 | /* If parent embedded into stack: */
|
---|
510 | if (m_enmEmbedding == EmbedTo_Stack)
|
---|
511 | {
|
---|
512 | /* Prepare button-box: */
|
---|
513 | m_pButtonBoxForwarding = new QIDialogButtonBox(pTabForwarding);
|
---|
514 | if (m_pButtonBoxForwarding)
|
---|
515 | {
|
---|
516 | m_pButtonBoxForwarding->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
---|
517 | connect(m_pButtonBoxForwarding, &QIDialogButtonBox::clicked, this, &UIDetailsWidgetNATNetwork::sltHandleButtonBoxClick);
|
---|
518 |
|
---|
519 | pLayoutForwarding->addWidget(m_pButtonBoxForwarding, 1, 0);
|
---|
520 | }
|
---|
521 | }
|
---|
522 | }
|
---|
523 |
|
---|
524 | m_pTabWidget->addTab(pTabForwarding, QString());
|
---|
525 | }
|
---|
526 | }
|
---|
527 |
|
---|
528 | void UIDetailsWidgetNATNetwork::loadDataForOptions()
|
---|
529 | {
|
---|
530 | /* Check whether network exists and enabled: */
|
---|
531 | const bool fIsNetworkExists = m_newData.m_fExists;
|
---|
532 | const bool fIsIPv6Supported = m_newData.m_fSupportsIPv6;
|
---|
533 |
|
---|
534 | /* Update 'Options' field availability: */
|
---|
535 | m_pLabelNetworkName->setEnabled(fIsNetworkExists);
|
---|
536 | m_pEditorNetworkName->setEnabled(fIsNetworkExists);
|
---|
537 | m_pLabelNetworkIPv4Prefix->setEnabled(fIsNetworkExists);
|
---|
538 | m_pEditorNetworkIPv4Prefix->setEnabled(fIsNetworkExists);
|
---|
539 | m_pCheckboxSupportsDHCP->setEnabled(fIsNetworkExists);
|
---|
540 | m_pCheckboxIPv6->setEnabled(fIsNetworkExists);
|
---|
541 | m_pLabelNetworkIPv6Prefix->setEnabled(fIsNetworkExists && fIsIPv6Supported);
|
---|
542 | m_pEditorNetworkIPv6Prefix->setEnabled(fIsNetworkExists && fIsIPv6Supported);
|
---|
543 | m_pCheckboxAdvertiseDefaultIPv6Route->setEnabled(fIsNetworkExists && fIsIPv6Supported);
|
---|
544 |
|
---|
545 | /* Load 'Options' fields: */
|
---|
546 | m_pEditorNetworkName->setText(m_newData.m_strName);
|
---|
547 | m_pEditorNetworkIPv4Prefix->setText(m_newData.m_strPrefixIPv4);
|
---|
548 | m_pCheckboxSupportsDHCP->setChecked(m_newData.m_fSupportsDHCP);
|
---|
549 | m_pCheckboxIPv6->setChecked(m_newData.m_fSupportsIPv6);
|
---|
550 | m_pEditorNetworkIPv6Prefix->setText(m_newData.m_strPrefixIPv6);
|
---|
551 | m_pCheckboxAdvertiseDefaultIPv6Route->setChecked(m_newData.m_fAdvertiseDefaultIPv6Route);
|
---|
552 | }
|
---|
553 |
|
---|
554 | void UIDetailsWidgetNATNetwork::loadDataForForwarding()
|
---|
555 | {
|
---|
556 | /* Check whether network exists and enabled: */
|
---|
557 | const bool fIsNetworkExists = m_newData.m_fExists;
|
---|
558 |
|
---|
559 | /* Update 'Forwarding' field availability: */
|
---|
560 | m_pForwardingTableIPv4->setEnabled(fIsNetworkExists);
|
---|
561 | m_pForwardingTableIPv6->setEnabled(fIsNetworkExists);
|
---|
562 |
|
---|
563 | /* Calculate/load guest address hints: */
|
---|
564 | char szTmpIp[16];
|
---|
565 | RTNETADDRIPV4 rtNetwork4;
|
---|
566 | int iPrefix4;
|
---|
567 | const int rc = RTNetStrToIPv4Cidr(m_newData.m_strPrefixIPv4.toUtf8().constData(), &rtNetwork4, &iPrefix4);
|
---|
568 | RTStrPrintf(szTmpIp, sizeof(szTmpIp), "%RTnaipv4", rtNetwork4);
|
---|
569 | if (RT_SUCCESS(rc))
|
---|
570 | m_pForwardingTableIPv4->setGuestAddressHint(QString(szTmpIp));
|
---|
571 |
|
---|
572 | /* Load 'Forwarding' fields: */
|
---|
573 | m_pForwardingTableIPv4->setRules(m_newData.m_rules4, m_fHoldPosition);
|
---|
574 | m_pForwardingTableIPv6->setRules(m_newData.m_rules6, m_fHoldPosition);
|
---|
575 | m_fHoldPosition = false;
|
---|
576 | }
|
---|