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