VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UIDetailsWidgetNATNetwork.cpp@ 102493

Last change on this file since 102493 was 98103, checked in by vboxsync, 20 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.1 KB
Line 
1/* $Id: UIDetailsWidgetNATNetwork.cpp 98103 2023-01-17 14:15:46Z 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/assert.h"
50#include "iprt/cidr.h"
51
52
53UIDetailsWidgetNATNetwork::UIDetailsWidgetNATNetwork(EmbedTo enmEmbedding, QWidget *pParent /* = 0 */)
54 : QIWithRetranslateUI<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
76void 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
92bool 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
127void 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
154void UIDetailsWidgetNATNetwork::retranslateUi()
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
230void UIDetailsWidgetNATNetwork::sltNetworkNameChanged(const QString &strText)
231{
232 m_newData.m_strName = strText;
233 updateButtonStates();
234}
235
236void UIDetailsWidgetNATNetwork::sltNetworkIPv4PrefixChanged(const QString &strText)
237{
238 m_newData.m_strPrefixIPv4 = strText;
239 updateButtonStates();
240}
241
242void UIDetailsWidgetNATNetwork::sltNetworkIPv6PrefixChanged(const QString &strText)
243{
244 m_newData.m_strPrefixIPv6 = strText;
245 updateButtonStates();
246}
247
248void UIDetailsWidgetNATNetwork::sltSupportsDHCPChanged(bool fChecked)
249{
250 m_newData.m_fSupportsDHCP = fChecked;
251 updateButtonStates();
252}
253
254void UIDetailsWidgetNATNetwork::sltSupportsIPv6Changed(bool fChecked)
255{
256 m_newData.m_fSupportsIPv6 = fChecked;
257 loadDataForOptions();
258 updateButtonStates();
259}
260
261void UIDetailsWidgetNATNetwork::sltAdvertiseDefaultIPv6RouteChanged(bool fChecked)
262{
263 m_newData.m_fAdvertiseDefaultIPv6Route = fChecked;
264 updateButtonStates();
265}
266
267void UIDetailsWidgetNATNetwork::sltForwardingRulesIPv4Changed()
268{
269 m_newData.m_rules4 = m_pForwardingTableIPv4->rules();
270 updateButtonStates();
271}
272
273void UIDetailsWidgetNATNetwork::sltForwardingRulesIPv6Changed()
274{
275 m_newData.m_rules6 = m_pForwardingTableIPv6->rules();
276 updateButtonStates();
277}
278
279void 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
301void UIDetailsWidgetNATNetwork::prepare()
302{
303 /* Prepare this: */
304 prepareThis();
305
306 /* Apply language settings: */
307 retranslateUi();
308
309 /* Update button states finally: */
310 updateButtonStates();
311}
312
313void UIDetailsWidgetNATNetwork::prepareThis()
314{
315 /* Create layout: */
316 new QVBoxLayout(this);
317 if (layout())
318 {
319 /* Configure layout: */
320 layout()->setContentsMargins(0, 0, 0, 0);
321
322 /* Prepare tab-widget: */
323 prepareTabWidget();
324 }
325}
326
327void UIDetailsWidgetNATNetwork::prepareTabWidget()
328{
329 /* Create tab-widget: */
330 m_pTabWidget = new QITabWidget(this);
331 if (m_pTabWidget)
332 {
333 /* Prepare 'Options' tab: */
334 prepareTabOptions();
335 /* Prepare 'Forwarding' tab: */
336 prepareTabForwarding();
337
338 /* Add into layout: */
339 layout()->addWidget(m_pTabWidget);
340 }
341}
342
343void UIDetailsWidgetNATNetwork::prepareTabOptions()
344{
345 /* Prepare 'Options' tab: */
346 QWidget *pTabOptions = new QWidget(m_pTabWidget);
347 if (pTabOptions)
348 {
349 /* Prepare 'Options' layout: */
350 QGridLayout *pLayoutOptions = new QGridLayout(pTabOptions);
351 if (pLayoutOptions)
352 {
353 pLayoutOptions->setColumnStretch(0, 0);
354 pLayoutOptions->setColumnStretch(1, 0);
355 pLayoutOptions->setColumnStretch(2, 1);
356 pLayoutOptions->setColumnStretch(3, 1);
357#ifdef VBOX_WS_MAC
358 pLayoutOptions->setSpacing(10);
359 pLayoutOptions->setContentsMargins(10, 10, 10, 10);
360#endif
361
362 /* Prepare network name label: */
363 m_pLabelNetworkName = new QLabel(pTabOptions);
364 if (m_pLabelNetworkName)
365 {
366 m_pLabelNetworkName->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
367 pLayoutOptions->addWidget(m_pLabelNetworkName, 0, 0, 1, 2);
368 }
369 /* Prepare network name editor: */
370 m_pEditorNetworkName = new QLineEdit(pTabOptions);
371 if (m_pEditorNetworkName)
372 {
373 if (m_pLabelNetworkName)
374 m_pLabelNetworkName->setBuddy(m_pEditorNetworkName);
375 connect(m_pEditorNetworkName, &QLineEdit::textEdited,
376 this, &UIDetailsWidgetNATNetwork::sltNetworkNameChanged);
377
378 pLayoutOptions->addWidget(m_pEditorNetworkName, 0, 2, 1, 2);
379 }
380
381 /* Prepare network IPv4 prefix label: */
382 m_pLabelNetworkIPv4Prefix = new QLabel(pTabOptions);
383 if (m_pLabelNetworkIPv4Prefix)
384 {
385 m_pLabelNetworkIPv4Prefix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
386 pLayoutOptions->addWidget(m_pLabelNetworkIPv4Prefix, 1, 0, 1, 2);
387 }
388 /* Prepare network IPv4 prefix editor: */
389 m_pEditorNetworkIPv4Prefix = new QLineEdit(pTabOptions);
390 if (m_pEditorNetworkIPv4Prefix)
391 {
392 if (m_pLabelNetworkIPv4Prefix)
393 m_pLabelNetworkIPv4Prefix->setBuddy(m_pEditorNetworkIPv4Prefix);
394 connect(m_pEditorNetworkIPv4Prefix, &QLineEdit::textEdited,
395 this, &UIDetailsWidgetNATNetwork::sltNetworkIPv4PrefixChanged);
396
397 pLayoutOptions->addWidget(m_pEditorNetworkIPv4Prefix, 1, 2, 1, 2);
398 }
399 /* Prepare 'supports DHCP' check-box: */
400 m_pCheckboxSupportsDHCP = new QCheckBox(pTabOptions);
401 if (m_pCheckboxSupportsDHCP)
402 {
403 connect(m_pCheckboxSupportsDHCP, &QCheckBox::toggled,
404 this, &UIDetailsWidgetNATNetwork::sltSupportsDHCPChanged);
405 pLayoutOptions->addWidget(m_pCheckboxSupportsDHCP, 2, 2);
406 }
407
408 /* Prepare IPv6 check-box: */
409 m_pCheckboxIPv6 = new QCheckBox(pTabOptions);
410 if (m_pCheckboxIPv6)
411 {
412 connect(m_pCheckboxIPv6, &QCheckBox::toggled,
413 this, &UIDetailsWidgetNATNetwork::sltSupportsIPv6Changed);
414 pLayoutOptions->addWidget(m_pCheckboxIPv6, 3, 0, 1, 3);
415 }
416 /* Prepare shifting spacer: */
417 QSpacerItem *pSpacer = new QSpacerItem(20, 0, QSizePolicy::Fixed, QSizePolicy::Minimum);
418 if (pSpacer)
419 pLayoutOptions->addItem(pSpacer, 4, 0);
420 /* Prepare network IPv6 prefix label: */
421 m_pLabelNetworkIPv6Prefix = new QLabel(pTabOptions);
422 if (m_pLabelNetworkIPv6Prefix)
423 {
424 m_pLabelNetworkIPv6Prefix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
425 pLayoutOptions->addWidget(m_pLabelNetworkIPv6Prefix, 4, 1);
426 }
427 /* Prepare network IPv6 prefix editor: */
428 m_pEditorNetworkIPv6Prefix = new QLineEdit(pTabOptions);
429 if (m_pEditorNetworkIPv6Prefix)
430 {
431 if (m_pLabelNetworkIPv6Prefix)
432 m_pLabelNetworkIPv6Prefix->setBuddy(m_pEditorNetworkIPv6Prefix);
433 connect(m_pEditorNetworkIPv6Prefix, &QLineEdit::textEdited,
434 this, &UIDetailsWidgetNATNetwork::sltNetworkIPv6PrefixChanged);
435
436 pLayoutOptions->addWidget(m_pEditorNetworkIPv6Prefix, 4, 2, 1, 2);
437 }
438 /* Prepare 'advertise default IPv6 route' check-box: */
439 m_pCheckboxAdvertiseDefaultIPv6Route = new QCheckBox(pTabOptions);
440 if (m_pCheckboxAdvertiseDefaultIPv6Route)
441 {
442 connect(m_pCheckboxAdvertiseDefaultIPv6Route, &QCheckBox::toggled,
443 this, &UIDetailsWidgetNATNetwork::sltAdvertiseDefaultIPv6RouteChanged);
444 pLayoutOptions->addWidget(m_pCheckboxAdvertiseDefaultIPv6Route, 5, 2);
445 }
446
447 /* If parent embedded into stack: */
448 if (m_enmEmbedding == EmbedTo_Stack)
449 {
450 /* Prepare button-box: */
451 m_pButtonBoxOptions = new QIDialogButtonBox(pTabOptions);
452 if (m_pButtonBoxOptions)
453 {
454 m_pButtonBoxOptions->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
455 connect(m_pButtonBoxOptions, &QIDialogButtonBox::clicked, this, &UIDetailsWidgetNATNetwork::sltHandleButtonBoxClick);
456
457 pLayoutOptions->addWidget(m_pButtonBoxOptions, 7, 0, 1, 4);
458 }
459 }
460 }
461
462 m_pTabWidget->addTab(pTabOptions, QString());
463 }
464}
465
466void UIDetailsWidgetNATNetwork::prepareTabForwarding()
467{
468 /* Prepare 'Forwarding' tab: */
469 QWidget *pTabForwarding = new QWidget(m_pTabWidget);
470 if (pTabForwarding)
471 {
472 /* Prepare 'Forwarding' layout: */
473 QGridLayout *pLayoutForwarding = new QGridLayout(pTabForwarding);
474 if (pLayoutForwarding)
475 {
476#ifdef VBOX_WS_MAC
477 /* Configure layout: */
478 pLayoutForwarding->setSpacing(10);
479 pLayoutForwarding->setContentsMargins(10, 10, 10, 10);
480#endif
481
482 /* Prepare forwarding tab-widget: */
483 m_pTabWidgetForwarding = new QITabWidget(pTabForwarding);
484 if (m_pTabWidgetForwarding)
485 {
486 /* Prepare IPv4 forwarding table: */
487 m_pForwardingTableIPv4 = new UIPortForwardingTable(UIPortForwardingDataList(),
488 false /* ip IPv6 protocol */,
489 false /* allow empty guest IPs */);
490 if (m_pForwardingTableIPv4)
491 {
492 connect(m_pForwardingTableIPv4, &UIPortForwardingTable::sigDataChanged,
493 this, &UIDetailsWidgetNATNetwork::sltForwardingRulesIPv4Changed);
494 m_pTabWidgetForwarding->addTab(m_pForwardingTableIPv4, QString());
495 }
496 /* Prepare IPv6 forwarding table: */
497 m_pForwardingTableIPv6 = new UIPortForwardingTable(UIPortForwardingDataList(),
498 true /* ip IPv6 protocol */,
499 false /* allow empty guest IPs */);
500 if (m_pForwardingTableIPv6)
501 {
502 connect(m_pForwardingTableIPv4, &UIPortForwardingTable::sigDataChanged,
503 this, &UIDetailsWidgetNATNetwork::sltForwardingRulesIPv6Changed);
504 m_pTabWidgetForwarding->addTab(m_pForwardingTableIPv6, QString());
505 }
506
507 pLayoutForwarding->addWidget(m_pTabWidgetForwarding, 0, 0);
508 }
509
510 /* If parent embedded into stack: */
511 if (m_enmEmbedding == EmbedTo_Stack)
512 {
513 /* Prepare button-box: */
514 m_pButtonBoxForwarding = new QIDialogButtonBox(pTabForwarding);
515 if (m_pButtonBoxForwarding)
516 {
517 m_pButtonBoxForwarding->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
518 connect(m_pButtonBoxForwarding, &QIDialogButtonBox::clicked, this, &UIDetailsWidgetNATNetwork::sltHandleButtonBoxClick);
519
520 pLayoutForwarding->addWidget(m_pButtonBoxForwarding, 1, 0);
521 }
522 }
523 }
524
525 m_pTabWidget->addTab(pTabForwarding, QString());
526 }
527}
528
529void UIDetailsWidgetNATNetwork::loadDataForOptions()
530{
531 /* Check whether network exists and enabled: */
532 const bool fIsNetworkExists = m_newData.m_fExists;
533 const bool fIsIPv6Supported = m_newData.m_fSupportsIPv6;
534
535 /* Update 'Options' field availability: */
536 m_pLabelNetworkName->setEnabled(fIsNetworkExists);
537 m_pEditorNetworkName->setEnabled(fIsNetworkExists);
538 m_pLabelNetworkIPv4Prefix->setEnabled(fIsNetworkExists);
539 m_pEditorNetworkIPv4Prefix->setEnabled(fIsNetworkExists);
540 m_pCheckboxSupportsDHCP->setEnabled(fIsNetworkExists);
541 m_pCheckboxIPv6->setEnabled(fIsNetworkExists);
542 m_pLabelNetworkIPv6Prefix->setEnabled(fIsNetworkExists && fIsIPv6Supported);
543 m_pEditorNetworkIPv6Prefix->setEnabled(fIsNetworkExists && fIsIPv6Supported);
544 m_pCheckboxAdvertiseDefaultIPv6Route->setEnabled(fIsNetworkExists && fIsIPv6Supported);
545
546 /* Load 'Options' fields: */
547 m_pEditorNetworkName->setText(m_newData.m_strName);
548 m_pEditorNetworkIPv4Prefix->setText(m_newData.m_strPrefixIPv4);
549 m_pCheckboxSupportsDHCP->setChecked(m_newData.m_fSupportsDHCP);
550 m_pCheckboxIPv6->setChecked(m_newData.m_fSupportsIPv6);
551 m_pEditorNetworkIPv6Prefix->setText(m_newData.m_strPrefixIPv6);
552 m_pCheckboxAdvertiseDefaultIPv6Route->setChecked(m_newData.m_fAdvertiseDefaultIPv6Route);
553}
554
555void UIDetailsWidgetNATNetwork::loadDataForForwarding()
556{
557 /* Check whether network exists and enabled: */
558 const bool fIsNetworkExists = m_newData.m_fExists;
559
560 /* Update 'Forwarding' field availability: */
561 m_pForwardingTableIPv4->setEnabled(fIsNetworkExists);
562 m_pForwardingTableIPv6->setEnabled(fIsNetworkExists);
563
564 /* Calculate/load guest address hints: */
565 char szTmpIp[16];
566 RTNETADDRIPV4 rtNetwork4;
567 int iPrefix4;
568 const int rc = RTNetStrToIPv4Cidr(m_newData.m_strPrefixIPv4.toUtf8().constData(), &rtNetwork4, &iPrefix4);
569 RTStrPrintf(szTmpIp, sizeof(szTmpIp), "%RTnaipv4", rtNetwork4);
570 if (RT_SUCCESS(rc))
571 m_pForwardingTableIPv4->setGuestAddressHint(QString(szTmpIp));
572
573 /* Load 'Forwarding' fields: */
574 m_pForwardingTableIPv4->setRules(m_newData.m_rules4, m_fHoldPosition);
575 m_pForwardingTableIPv6->setRules(m_newData.m_rules6, m_fHoldPosition);
576 m_fHoldPosition = false;
577}
Note: See TracBrowser for help on using the repository browser.

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