VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UIDetailsWidgetHostNetwork.cpp

Last change on this file was 104223, checked in by vboxsync, 6 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in metwork manager classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.6 KB
Line 
1/* $Id: UIDetailsWidgetHostNetwork.cpp 104223 2024-04-08 10:30:04Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIDetailsWidgetHostNetwork 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 <QLabel>
31#include <QPushButton>
32#include <QRadioButton>
33#include <QStyleOption>
34#include <QVBoxLayout>
35
36/* GUI includes: */
37#include "QIDialogButtonBox.h"
38#include "QILineEdit.h"
39#include "QITabWidget.h"
40#include "UIIconPool.h"
41#include "UIDetailsWidgetHostNetwork.h"
42#include "UIMessageCenter.h"
43#include "UINetworkManager.h"
44#include "UINetworkManagerUtils.h"
45#include "UINotificationCenter.h"
46#include "UITranslationEventListener.h"
47
48/* Other VBox includes: */
49#ifndef VBOX_WS_MAC
50# include "iprt/cidr.h"
51#endif
52
53
54UIDetailsWidgetHostNetwork::UIDetailsWidgetHostNetwork(EmbedTo enmEmbedding, QWidget *pParent /* = 0 */)
55 : QWidget(pParent)
56 , m_enmEmbedding(enmEmbedding)
57#ifdef VBOX_WS_MAC
58 , m_pLabelName(0)
59 , m_pEditorName(0)
60 , m_pLabelMask(0)
61 , m_pEditorMask(0)
62 , m_pLabelLBnd(0)
63 , m_pEditorLBnd(0)
64 , m_pLabelUBnd(0)
65 , m_pEditorUBnd(0)
66 , m_pButtonBox(0)
67#else /* !VBOX_WS_MAC */
68 , m_pTabWidget(0)
69 , m_pButtonAutomatic(0)
70 , m_pButtonManual(0)
71 , m_pLabelIPv4(0), m_pEditorIPv4(0)
72 , m_pLabelNMv4(0), m_pEditorNMv4(0)
73 , m_pLabelIPv6(0), m_pEditorIPv6(0)
74 , m_pLabelNMv6(0), m_pEditorNMv6(0)
75 , m_pButtonBoxInterface(0)
76 , m_pCheckBoxDHCP(0)
77 , m_pLabelDHCPAddress(0), m_pEditorDHCPAddress(0)
78 , m_pLabelDHCPMask(0), m_pEditorDHCPMask(0)
79 , m_pLabelDHCPLowerAddress(0), m_pEditorDHCPLowerAddress(0)
80 , m_pLabelDHCPUpperAddress(0), m_pEditorDHCPUpperAddress(0)
81 , m_pButtonBoxServer(0)
82#endif /* !VBOX_WS_MAC */
83{
84 prepare();
85}
86
87#ifdef VBOX_WS_MAC
88void UIDetailsWidgetHostNetwork::setData(const UIDataHostNetwork &data,
89 const QStringList &busyNames /* = QStringList() */)
90#else /* !VBOX_WS_MAC */
91void UIDetailsWidgetHostNetwork::setData(const UIDataHostNetwork &data)
92#endif /* !VBOX_WS_MAC */
93{
94 /* Cache old/new data: */
95 m_oldData = data;
96 m_newData = m_oldData;
97#ifdef VBOX_WS_MAC
98 m_busyNames = busyNames;
99#endif /* VBOX_WS_MAC */
100
101#ifdef VBOX_WS_MAC
102 /* Load data: */
103 loadData();
104#else /* !VBOX_WS_MAC */
105 /* Load 'Interface' data: */
106 loadDataForInterface();
107 /* Load 'DHCP server' data: */
108 loadDataForDHCPServer();
109#endif /* !VBOX_WS_MAC */
110}
111
112bool UIDetailsWidgetHostNetwork::revalidate() const
113{
114#ifdef VBOX_WS_MAC
115 /* Make sure network name isn't empty: */
116 if (m_newData.m_strName.isEmpty())
117 {
118 UINotificationMessage::warnAboutNoNameSpecified(m_oldData.m_strName);
119 return false;
120 }
121 else
122 {
123 /* Make sure item names are unique: */
124 if (m_busyNames.contains(m_newData.m_strName))
125 {
126 UINotificationMessage::warnAboutNameAlreadyBusy(m_newData.m_strName);
127 return false;
128 }
129 }
130
131 /* Make sure mask isn't empty: */
132 if (m_newData.m_strMask.isEmpty())
133 {
134 UINotificationMessage::warnAboutInvalidIPv4Mask(m_newData.m_strMask);
135 return false;
136 }
137 /* Make sure lower bound isn't empty: */
138 if (m_newData.m_strLBnd.isEmpty())
139 {
140 UINotificationMessage::warnAboutInvalidDHCPServerLowerAddress(m_newData.m_strLBnd);
141 return false;
142 }
143 /* Make sure upper bound isn't empty: */
144 if (m_newData.m_strUBnd.isEmpty())
145 {
146 UINotificationMessage::warnAboutInvalidDHCPServerUpperAddress(m_newData.m_strUBnd);
147 return false;
148 }
149
150#else /* !VBOX_WS_MAC */
151
152 /* Validate 'Interface' tab content: */
153 if ( m_newData.m_interface.m_fDHCPEnabled
154 && !m_newData.m_dhcpserver.m_fEnabled)
155 {
156 UINotificationMessage::warnAboutDHCPServerIsNotEnabled(m_newData.m_interface.m_strName);
157 return false;
158 }
159 if ( !m_newData.m_interface.m_fDHCPEnabled
160 && !m_newData.m_interface.m_strAddress.trimmed().isEmpty()
161 && ( !RTNetIsIPv4AddrStr(m_newData.m_interface.m_strAddress.toUtf8().constData())
162 || RTNetStrIsIPv4AddrAny(m_newData.m_interface.m_strAddress.toUtf8().constData())))
163 {
164 UINotificationMessage::warnAboutInvalidIPv4Address(m_newData.m_interface.m_strName);
165 return false;
166 }
167 if ( !m_newData.m_interface.m_fDHCPEnabled
168 && !m_newData.m_interface.m_strMask.trimmed().isEmpty()
169 && ( !RTNetIsIPv4AddrStr(m_newData.m_interface.m_strMask.toUtf8().constData())
170 || RTNetStrIsIPv4AddrAny(m_newData.m_interface.m_strMask.toUtf8().constData())))
171 {
172 UINotificationMessage::warnAboutInvalidIPv4Mask(m_newData.m_interface.m_strName);
173 return false;
174 }
175 if ( !m_newData.m_interface.m_fDHCPEnabled
176 && m_newData.m_interface.m_fSupportedIPv6
177 && !m_newData.m_interface.m_strAddress6.trimmed().isEmpty()
178 && ( !RTNetIsIPv6AddrStr(m_newData.m_interface.m_strAddress6.toUtf8().constData())
179 || RTNetStrIsIPv6AddrAny(m_newData.m_interface.m_strAddress6.toUtf8().constData())))
180 {
181 UINotificationMessage::warnAboutInvalidIPv6Address(m_newData.m_interface.m_strName);
182 return false;
183 }
184 bool fIsMaskPrefixLengthNumber = false;
185 const int iMaskPrefixLength = m_newData.m_interface.m_strPrefixLength6.trimmed().toInt(&fIsMaskPrefixLengthNumber);
186 if ( !m_newData.m_interface.m_fDHCPEnabled
187 && m_newData.m_interface.m_fSupportedIPv6
188 && ( !fIsMaskPrefixLengthNumber
189 || iMaskPrefixLength < 0
190 || iMaskPrefixLength > 128))
191 {
192 UINotificationMessage::warnAboutInvalidIPv6PrefixLength(m_newData.m_interface.m_strName);
193 return false;
194 }
195
196 /* Validate 'DHCP server' tab content: */
197 if ( m_newData.m_dhcpserver.m_fEnabled
198 && ( !RTNetIsIPv4AddrStr(m_newData.m_dhcpserver.m_strAddress.toUtf8().constData())
199 || RTNetStrIsIPv4AddrAny(m_newData.m_dhcpserver.m_strAddress.toUtf8().constData())))
200 {
201 UINotificationMessage::warnAboutInvalidDHCPServerAddress(m_newData.m_interface.m_strName);
202 return false;
203 }
204 if ( m_newData.m_dhcpserver.m_fEnabled
205 && ( !RTNetIsIPv4AddrStr(m_newData.m_dhcpserver.m_strMask.toUtf8().constData())
206 || RTNetStrIsIPv4AddrAny(m_newData.m_dhcpserver.m_strMask.toUtf8().constData())))
207 {
208 UINotificationMessage::warnAboutInvalidDHCPServerMask(m_newData.m_interface.m_strName);
209 return false;
210 }
211 if ( m_newData.m_dhcpserver.m_fEnabled
212 && ( !RTNetIsIPv4AddrStr(m_newData.m_dhcpserver.m_strLowerAddress.toUtf8().constData())
213 || RTNetStrIsIPv4AddrAny(m_newData.m_dhcpserver.m_strLowerAddress.toUtf8().constData())))
214 {
215 UINotificationMessage::warnAboutInvalidDHCPServerLowerAddress(m_newData.m_interface.m_strName);
216 return false;
217 }
218 if ( m_newData.m_dhcpserver.m_fEnabled
219 && ( !RTNetIsIPv4AddrStr(m_newData.m_dhcpserver.m_strUpperAddress.toUtf8().constData())
220 || RTNetStrIsIPv4AddrAny(m_newData.m_dhcpserver.m_strUpperAddress.toUtf8().constData())))
221 {
222 UINotificationMessage::warnAboutInvalidDHCPServerUpperAddress(m_newData.m_interface.m_strName);
223 return false;
224 }
225#endif /* !VBOX_WS_MAC */
226
227 /* True by default: */
228 return true;
229}
230
231void UIDetailsWidgetHostNetwork::updateButtonStates()
232{
233// if (m_oldData != m_newData)
234// printf("Interface: %s, %s, %s, %s; DHCP server: %d, %s, %s, %s, %s\n",
235// m_newData.m_interface.m_strAddress.toUtf8().constData(),
236// m_newData.m_interface.m_strMask.toUtf8().constData(),
237// m_newData.m_interface.m_strAddress6.toUtf8().constData(),
238// m_newData.m_interface.m_strPrefixLength6.toUtf8().constData(),
239// (int)m_newData.m_dhcpserver.m_fEnabled,
240// m_newData.m_dhcpserver.m_strAddress.toUtf8().constData(),
241// m_newData.m_dhcpserver.m_strMask.toUtf8().constData(),
242// m_newData.m_dhcpserver.m_strLowerAddress.toUtf8().constData(),
243// m_newData.m_dhcpserver.m_strUpperAddress.toUtf8().constData());
244
245#ifdef VBOX_WS_MAC
246 /* Update 'Apply' / 'Reset' button states: */
247 if (m_pButtonBox)
248 {
249 m_pButtonBox->button(QDialogButtonBox::Cancel)->setEnabled(m_oldData != m_newData);
250 m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(m_oldData != m_newData);
251 }
252#else /* !VBOX_WS_MAC */
253 /* Update 'Apply' / 'Reset' button states: */
254 if (m_pButtonBoxInterface)
255 {
256 m_pButtonBoxInterface->button(QDialogButtonBox::Cancel)->setEnabled(m_oldData != m_newData);
257 m_pButtonBoxInterface->button(QDialogButtonBox::Ok)->setEnabled(m_oldData != m_newData);
258 }
259 if (m_pButtonBoxServer)
260 {
261 m_pButtonBoxServer->button(QDialogButtonBox::Cancel)->setEnabled(m_oldData != m_newData);
262 m_pButtonBoxServer->button(QDialogButtonBox::Ok)->setEnabled(m_oldData != m_newData);
263 }
264#endif /* !VBOX_WS_MAC */
265
266 /* Notify listeners as well: */
267 emit sigDataChanged(m_oldData != m_newData);
268}
269
270void UIDetailsWidgetHostNetwork::sltRetranslateUI()
271{
272#ifdef VBOX_WS_MAC
273 if (m_pLabelName)
274 m_pLabelName->setText(UINetworkManager::tr("&Name:"));
275 if (m_pEditorName)
276 m_pEditorName->setToolTip(UINetworkManager::tr("Holds the name for this network."));
277 if (m_pLabelMask)
278 m_pLabelMask->setText(UINetworkManager::tr("&Mask:"));
279 if (m_pEditorMask)
280 m_pEditorMask->setToolTip(UINetworkManager::tr("Holds the mask for this network."));
281 if (m_pLabelLBnd)
282 m_pLabelLBnd->setText(UINetworkManager::tr("&Lower Bound:"));
283 if (m_pEditorLBnd)
284 m_pEditorLBnd->setToolTip(UINetworkManager::tr("Holds the lower address bound for this network."));
285 if (m_pLabelUBnd)
286 m_pLabelUBnd->setText(UINetworkManager::tr("&Upper Bound:"));
287 if (m_pEditorUBnd)
288 m_pEditorUBnd->setToolTip(UINetworkManager::tr("Holds the upper address bound for this network."));
289 if (m_pButtonBox)
290 {
291 m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("Reset"));
292 m_pButtonBox->button(QDialogButtonBox::Ok)->setText(UINetworkManager::tr("Apply"));
293 m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
294 m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
295 m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Reset changes in current network details"));
296 m_pButtonBox->button(QDialogButtonBox::Ok)->setStatusTip(UINetworkManager::tr("Apply changes in current network details"));
297 m_pButtonBox->button(QDialogButtonBox::Cancel)->
298 setToolTip(UINetworkManager::tr("Reset Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Cancel)->shortcut().toString()));
299 m_pButtonBox->button(QDialogButtonBox::Ok)->
300 setToolTip(UINetworkManager::tr("Apply Changes (%1)").arg(m_pButtonBox->button(QDialogButtonBox::Ok)->shortcut().toString()));
301 }
302
303#else /* !VBOX_WS_MAC */
304
305 /* Translate tab-widget: */
306 if (m_pTabWidget)
307 {
308 m_pTabWidget->setTabText(0, UINetworkManager::tr("&Adapter"));
309 m_pTabWidget->setTabText(1, UINetworkManager::tr("&DHCP Server"));
310 }
311
312 /* Translate 'Interface' tab content: */
313 if (m_pButtonAutomatic)
314 m_pButtonAutomatic->setText(UINetworkManager::tr("Configure Adapter &Automatically"));
315 if (m_pButtonManual)
316 m_pButtonManual->setText(UINetworkManager::tr("Configure Adapter &Manually"));
317 if (m_pLabelIPv4)
318 m_pLabelIPv4->setText(UINetworkManager::tr("&IPv4 Address:"));
319 if (m_pEditorIPv4)
320 m_pEditorIPv4->setToolTip(UINetworkManager::tr("Holds the host IPv4 address for this adapter."));
321 if (m_pLabelNMv4)
322 m_pLabelNMv4->setText(UINetworkManager::tr("IPv4 Network &Mask:"));
323 if (m_pEditorNMv4)
324 m_pEditorNMv4->setToolTip(UINetworkManager::tr("Holds the host IPv4 network mask for this adapter."));
325 if (m_pLabelIPv6)
326 m_pLabelIPv6->setText(UINetworkManager::tr("I&Pv6 Address:"));
327 if (m_pEditorIPv6)
328 m_pEditorIPv6->setToolTip(UINetworkManager::tr("Holds the host IPv6 address for this adapter if IPv6 is supported."));
329 if (m_pLabelNMv6)
330 m_pLabelNMv6->setText(UINetworkManager::tr("IPv6 Prefix &Length:"));
331 if (m_pEditorNMv6)
332 m_pEditorNMv6->setToolTip(UINetworkManager::tr("Holds the host IPv6 prefix length for this adapter if IPv6 is supported."));
333 if (m_pButtonBoxInterface)
334 {
335 m_pButtonBoxInterface->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("Reset"));
336 m_pButtonBoxInterface->button(QDialogButtonBox::Ok)->setText(UINetworkManager::tr("Apply"));
337 m_pButtonBoxInterface->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
338 m_pButtonBoxInterface->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
339 m_pButtonBoxInterface->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Reset changes in current interface details"));
340 m_pButtonBoxInterface->button(QDialogButtonBox::Ok)->setStatusTip(UINetworkManager::tr("Apply changes in current interface details"));
341 m_pButtonBoxInterface->button(QDialogButtonBox::Cancel)->
342 setToolTip(UINetworkManager::tr("Reset Changes (%1)").arg(m_pButtonBoxInterface->button(QDialogButtonBox::Cancel)->shortcut().toString()));
343 m_pButtonBoxInterface->button(QDialogButtonBox::Ok)->
344 setToolTip(UINetworkManager::tr("Apply Changes (%1)").arg(m_pButtonBoxInterface->button(QDialogButtonBox::Ok)->shortcut().toString()));
345 }
346
347 /* Translate 'DHCP server' tab content: */
348 if (m_pCheckBoxDHCP)
349 {
350 m_pCheckBoxDHCP->setText(UINetworkManager::tr("&Enable Server"));
351 m_pCheckBoxDHCP->setToolTip(UINetworkManager::tr("When checked, the DHCP Server will be enabled for this network on machine start-up."));
352 }
353 if (m_pLabelDHCPAddress)
354 m_pLabelDHCPAddress->setText(UINetworkManager::tr("Server Add&ress:"));
355 if (m_pEditorDHCPAddress)
356 m_pEditorDHCPAddress->setToolTip(UINetworkManager::tr("Holds the address of the DHCP server servicing the network associated with this host-only adapter."));
357 if (m_pLabelDHCPMask)
358 m_pLabelDHCPMask->setText(UINetworkManager::tr("Server &Mask:"));
359 if (m_pEditorDHCPMask)
360 m_pEditorDHCPMask->setToolTip(UINetworkManager::tr("Holds the network mask of the DHCP server servicing the network associated with this host-only adapter."));
361 if (m_pLabelDHCPLowerAddress)
362 m_pLabelDHCPLowerAddress->setText(UINetworkManager::tr("&Lower Address Bound:"));
363 if (m_pEditorDHCPLowerAddress)
364 m_pEditorDHCPLowerAddress->setToolTip(UINetworkManager::tr("Holds the lower address bound offered by the DHCP server servicing the network associated with this host-only adapter."));
365 if (m_pLabelDHCPUpperAddress)
366 m_pLabelDHCPUpperAddress->setText(UINetworkManager::tr("&Upper Address Bound:"));
367 if (m_pEditorDHCPUpperAddress)
368 m_pEditorDHCPUpperAddress->setToolTip(UINetworkManager::tr("Holds the upper address bound offered by the DHCP server servicing the network associated with this host-only adapter."));
369 if (m_pButtonBoxServer)
370 {
371 m_pButtonBoxServer->button(QDialogButtonBox::Cancel)->setText(UINetworkManager::tr("Reset"));
372 m_pButtonBoxServer->button(QDialogButtonBox::Ok)->setText(UINetworkManager::tr("Apply"));
373 m_pButtonBoxServer->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
374 m_pButtonBoxServer->button(QDialogButtonBox::Ok)->setShortcut(QString("Ctrl+Return"));
375 m_pButtonBoxServer->button(QDialogButtonBox::Cancel)->setStatusTip(UINetworkManager::tr("Reset changes in current DHCP server details"));
376 m_pButtonBoxServer->button(QDialogButtonBox::Ok)->setStatusTip(UINetworkManager::tr("Apply changes in current DHCP server details"));
377 m_pButtonBoxServer->button(QDialogButtonBox::Cancel)->
378 setToolTip(UINetworkManager::tr("Reset Changes (%1)").arg(m_pButtonBoxServer->button(QDialogButtonBox::Cancel)->shortcut().toString()));
379 m_pButtonBoxServer->button(QDialogButtonBox::Ok)->
380 setToolTip(UINetworkManager::tr("Apply Changes (%1)").arg(m_pButtonBoxServer->button(QDialogButtonBox::Ok)->shortcut().toString()));
381 }
382#endif /* !VBOX_WS_MAC */
383}
384
385#ifdef VBOX_WS_MAC
386void UIDetailsWidgetHostNetwork::sltTextChangedName(const QString &strText)
387{
388 m_newData.m_strName = strText;
389 updateButtonStates();
390}
391
392void UIDetailsWidgetHostNetwork::sltTextChangedMask(const QString &strText)
393{
394 m_newData.m_strMask = strText;
395 updateButtonStates();
396}
397
398void UIDetailsWidgetHostNetwork::sltTextChangedLBnd(const QString &strText)
399{
400 m_newData.m_strLBnd = strText;
401 updateButtonStates();
402}
403
404void UIDetailsWidgetHostNetwork::sltTextChangedUBnd(const QString &strText)
405{
406 m_newData.m_strUBnd = strText;
407 updateButtonStates();
408}
409
410#else /* !VBOX_WS_MAC */
411
412void UIDetailsWidgetHostNetwork::sltToggledButtonAutomatic(bool fChecked)
413{
414 m_newData.m_interface.m_fDHCPEnabled = fChecked;
415 loadDataForInterface();
416 updateButtonStates();
417}
418
419void UIDetailsWidgetHostNetwork::sltToggledButtonManual(bool fChecked)
420{
421 m_newData.m_interface.m_fDHCPEnabled = !fChecked;
422 loadDataForInterface();
423 updateButtonStates();
424}
425
426void UIDetailsWidgetHostNetwork::sltTextChangedIPv4(const QString &strText)
427{
428 m_newData.m_interface.m_strAddress = strText;
429 updateButtonStates();
430}
431
432void UIDetailsWidgetHostNetwork::sltTextChangedNMv4(const QString &strText)
433{
434 m_newData.m_interface.m_strMask = strText;
435 updateButtonStates();
436}
437
438void UIDetailsWidgetHostNetwork::sltTextChangedIPv6(const QString &strText)
439{
440 m_newData.m_interface.m_strAddress6 = strText;
441 updateButtonStates();
442}
443
444void UIDetailsWidgetHostNetwork::sltTextChangedNMv6(const QString &strText)
445{
446 m_newData.m_interface.m_strPrefixLength6 = strText;
447 updateButtonStates();
448}
449
450void UIDetailsWidgetHostNetwork::sltStatusChangedServer(int iChecked)
451{
452 m_newData.m_dhcpserver.m_fEnabled = (bool)iChecked;
453 loadDataForDHCPServer();
454 updateButtonStates();
455}
456
457void UIDetailsWidgetHostNetwork::sltTextChangedAddress(const QString &strText)
458{
459 m_newData.m_dhcpserver.m_strAddress = strText;
460 updateButtonStates();
461}
462
463void UIDetailsWidgetHostNetwork::sltTextChangedMask(const QString &strText)
464{
465 m_newData.m_dhcpserver.m_strMask = strText;
466 updateButtonStates();
467}
468
469void UIDetailsWidgetHostNetwork::sltTextChangedLowerAddress(const QString &strText)
470{
471 m_newData.m_dhcpserver.m_strLowerAddress = strText;
472 updateButtonStates();
473}
474
475void UIDetailsWidgetHostNetwork::sltTextChangedUpperAddress(const QString &strText)
476{
477 m_newData.m_dhcpserver.m_strUpperAddress = strText;
478 updateButtonStates();
479}
480#endif /* !VBOX_WS_MAC */
481
482void UIDetailsWidgetHostNetwork::sltHandleButtonBoxClick(QAbstractButton *pButton)
483{
484#ifdef VBOX_WS_MAC
485 /* Make sure button-box exists: */
486 if (!m_pButtonBox)
487 return;
488
489 /* Disable buttons first of all: */
490 m_pButtonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
491 m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
492
493 /* Compare with known buttons: */
494 if ( pButton == m_pButtonBox->button(QDialogButtonBox::Cancel))
495 emit sigDataChangeRejected();
496 else
497 if ( pButton == m_pButtonBox->button(QDialogButtonBox::Ok))
498 emit sigDataChangeAccepted();
499
500#else /* !VBOX_WS_MAC */
501
502 /* Make sure button-boxes exist: */
503 if (!m_pButtonBoxInterface || !m_pButtonBoxServer)
504 return;
505
506 /* Disable buttons first of all: */
507 m_pButtonBoxInterface->button(QDialogButtonBox::Cancel)->setEnabled(false);
508 m_pButtonBoxInterface->button(QDialogButtonBox::Ok)->setEnabled(false);
509 m_pButtonBoxServer->button(QDialogButtonBox::Cancel)->setEnabled(false);
510 m_pButtonBoxServer->button(QDialogButtonBox::Ok)->setEnabled(false);
511
512 /* Compare with known buttons: */
513 if ( pButton == m_pButtonBoxInterface->button(QDialogButtonBox::Cancel)
514 || pButton == m_pButtonBoxServer->button(QDialogButtonBox::Cancel))
515 emit sigDataChangeRejected();
516 else
517 if ( pButton == m_pButtonBoxInterface->button(QDialogButtonBox::Ok)
518 || pButton == m_pButtonBoxServer->button(QDialogButtonBox::Ok))
519 emit sigDataChangeAccepted();
520#endif /* !VBOX_WS_MAC */
521}
522
523void UIDetailsWidgetHostNetwork::prepare()
524{
525 /* Prepare this: */
526 prepareThis();
527
528 /* Apply language settings: */
529 sltRetranslateUI();
530
531 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
532 this, &UIDetailsWidgetHostNetwork::sltRetranslateUI);
533
534 /* Update button states finally: */
535 updateButtonStates();
536}
537
538void UIDetailsWidgetHostNetwork::prepareThis()
539{
540#ifdef VBOX_WS_MAC
541 /* Create layout: */
542 QGridLayout *pLayout = new QGridLayout(this);
543 if (pLayout)
544 {
545 // really macOS only:
546 pLayout->setSpacing(10);
547 pLayout->setContentsMargins(10, 10, 10, 10);
548
549 /* Prepare options: */
550 prepareOptions();
551 }
552
553#else /* !VBOX_WS_MAC */
554
555 /* Create layout: */
556 new QVBoxLayout(this);
557 if (layout())
558 {
559 /* Configure layout: */
560 layout()->setContentsMargins(0, 0, 0, 0);
561
562 /* Prepare tab-widget: */
563 prepareTabWidget();
564 }
565#endif /* !VBOX_WS_MAC */
566}
567
568#ifdef VBOX_WS_MAC
569void UIDetailsWidgetHostNetwork::prepareOptions()
570{
571 /* Acquire layout: */
572 QGridLayout *pLayout = static_cast<QGridLayout*>(layout());
573 if (pLayout)
574 {
575 /* Prepare name label: */
576 m_pLabelName = new QLabel(this);
577 if (m_pLabelName)
578 {
579 m_pLabelName->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
580 pLayout->addWidget(m_pLabelName, 0, 0);
581 }
582 /* Prepare name editor: */
583 m_pEditorName = new QILineEdit(this);
584 if (m_pEditorName)
585 {
586 m_pLabelName->setBuddy(m_pEditorName);
587 connect(m_pEditorName, &QLineEdit::textChanged,
588 this, &UIDetailsWidgetHostNetwork::sltTextChangedName);
589
590 pLayout->addWidget(m_pEditorName, 0, 1);
591 }
592
593 /* Prepare mask label: */
594 m_pLabelMask = new QLabel(this);
595 if (m_pLabelMask)
596 {
597 m_pLabelMask->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
598 pLayout->addWidget(m_pLabelMask, 1, 0);
599 }
600 /* Prepare mask editor: */
601 m_pEditorMask = new QILineEdit(this);
602 if (m_pEditorMask)
603 {
604 m_pLabelMask->setBuddy(m_pEditorMask);
605 connect(m_pEditorMask, &QLineEdit::textChanged,
606 this, &UIDetailsWidgetHostNetwork::sltTextChangedMask);
607
608 pLayout->addWidget(m_pEditorMask, 1, 1);
609 }
610
611 /* Prepare lower bound label: */
612 m_pLabelLBnd = new QLabel(this);
613 if (m_pLabelLBnd)
614 {
615 m_pLabelLBnd->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
616 pLayout->addWidget(m_pLabelLBnd, 2, 0);
617 }
618 /* Prepare lower bound editor: */
619 m_pEditorLBnd = new QILineEdit(this);
620 if (m_pEditorLBnd)
621 {
622 m_pLabelLBnd->setBuddy(m_pEditorLBnd);
623 connect(m_pEditorLBnd, &QLineEdit::textChanged,
624 this, &UIDetailsWidgetHostNetwork::sltTextChangedLBnd);
625
626 pLayout->addWidget(m_pEditorLBnd, 2, 1);
627 }
628
629 /* Prepare upper bound label: */
630 m_pLabelUBnd = new QLabel(this);
631 if (m_pLabelUBnd)
632 {
633 m_pLabelUBnd->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
634 pLayout->addWidget(m_pLabelUBnd, 3, 0);
635 }
636 /* Prepare upper bound editor: */
637 m_pEditorUBnd = new QILineEdit(this);
638 if (m_pEditorUBnd)
639 {
640 m_pLabelUBnd->setBuddy(m_pEditorUBnd);
641 connect(m_pEditorUBnd, &QLineEdit::textChanged,
642 this, &UIDetailsWidgetHostNetwork::sltTextChangedUBnd);
643
644 pLayout->addWidget(m_pEditorUBnd, 3, 1);
645 }
646
647 /* If parent embedded into stack: */
648 if (m_enmEmbedding == EmbedTo_Stack)
649 {
650 /* Prepare button-box: */
651 m_pButtonBox = new QIDialogButtonBox(this);
652 if (m_pButtonBox)
653 {
654 m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
655 connect(m_pButtonBox, &QIDialogButtonBox::clicked, this, &UIDetailsWidgetHostNetwork::sltHandleButtonBoxClick);
656
657 pLayout->addWidget(m_pButtonBox, 4, 0, 1, 2);
658 }
659 }
660 }
661}
662
663#else /* !VBOX_WS_MAC */
664
665void UIDetailsWidgetHostNetwork::prepareTabWidget()
666{
667 /* Create tab-widget: */
668 m_pTabWidget = new QITabWidget(this);
669 if (m_pTabWidget)
670 {
671 /* Prepare 'Interface' tab: */
672 prepareTabInterface();
673 /* Prepare 'DHCP server' tab: */
674 prepareTabDHCPServer();
675
676 /* Add into layout: */
677 layout()->addWidget(m_pTabWidget);
678 }
679}
680
681void UIDetailsWidgetHostNetwork::prepareTabInterface()
682{
683 /* Prepare 'Interface' tab: */
684 QWidget *pTabInterface = new QWidget(m_pTabWidget);
685 if (pTabInterface)
686 {
687 /* Prepare 'Interface' layout: */
688 QGridLayout *pLayoutInterface = new QGridLayout(pTabInterface);
689 if (pLayoutInterface)
690 {
691#ifdef VBOX_WS_MAC
692 pLayoutInterface->setSpacing(10);
693 pLayoutInterface->setContentsMargins(10, 10, 10, 10);
694#endif
695
696 /* Prepare automatic interface configuration layout: */
697 QHBoxLayout *pLayoutAutomatic = new QHBoxLayout;
698 if (pLayoutAutomatic)
699 {
700 pLayoutAutomatic->setContentsMargins(0, 0, 0, 0);
701
702 /* Prepare automatic interface configuration radio-button: */
703 m_pButtonAutomatic = new QRadioButton(pTabInterface);
704 if (m_pButtonAutomatic)
705 {
706 connect(m_pButtonAutomatic, &QRadioButton::toggled,
707 this, &UIDetailsWidgetHostNetwork::sltToggledButtonAutomatic);
708 pLayoutAutomatic->addWidget(m_pButtonAutomatic);
709 }
710
711 pLayoutInterface->addLayout(pLayoutAutomatic, 0, 0, 1, 3);
712#ifdef VBOX_WS_MAC
713 pLayoutInterface->setRowMinimumHeight(0, 22);
714#endif
715 }
716
717 /* Prepare manual interface configuration layout: */
718 QHBoxLayout *pLayoutManual = new QHBoxLayout;
719 if (pLayoutManual)
720 {
721 pLayoutManual->setContentsMargins(0, 0, 0, 0);
722
723 /* Prepare manual interface configuration radio-button: */
724 m_pButtonManual = new QRadioButton(pTabInterface);
725 if (m_pButtonManual)
726 {
727 connect(m_pButtonManual, &QRadioButton::toggled,
728 this, &UIDetailsWidgetHostNetwork::sltToggledButtonManual);
729 pLayoutManual->addWidget(m_pButtonManual);
730 }
731
732 pLayoutInterface->addLayout(pLayoutManual, 1, 0, 1, 3);
733#ifdef VBOX_WS_MAC
734 pLayoutInterface->setRowMinimumHeight(1, 22);
735#endif
736 }
737
738 /* Prepare IPv4 address label: */
739 m_pLabelIPv4 = new QLabel(pTabInterface);
740 if (m_pLabelIPv4)
741 {
742 m_pLabelIPv4->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
743 pLayoutInterface->addWidget(m_pLabelIPv4, 2, 1);
744 }
745 /* Prepare IPv4 layout: */
746 QHBoxLayout *pLayoutIPv4 = new QHBoxLayout;
747 if (pLayoutIPv4)
748 {
749 pLayoutIPv4->setContentsMargins(0, 0, 0, 0);
750
751 /* Prepare IPv4 address editor: */
752 m_pEditorIPv4 = new QILineEdit(pTabInterface);
753 if (m_pEditorIPv4)
754 {
755 m_pLabelIPv4->setBuddy(m_pEditorIPv4);
756 connect(m_pEditorIPv4, &QLineEdit::textChanged,
757 this, &UIDetailsWidgetHostNetwork::sltTextChangedIPv4);
758
759 pLayoutIPv4->addWidget(m_pEditorIPv4);
760 }
761
762 pLayoutInterface->addLayout(pLayoutIPv4, 2, 2);
763 }
764
765 /* Prepare NMv4 network mask label: */
766 m_pLabelNMv4 = new QLabel(pTabInterface);
767 if (m_pLabelNMv4)
768 {
769 m_pLabelNMv4->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
770 pLayoutInterface->addWidget(m_pLabelNMv4, 3, 1);
771 }
772 /* Prepare NMv4 layout: */
773 QHBoxLayout *pLayoutNMv4 = new QHBoxLayout;
774 if (pLayoutNMv4)
775 {
776 pLayoutNMv4->setContentsMargins(0, 0, 0, 0);
777
778 /* Prepare NMv4 network mask editor: */
779 m_pEditorNMv4 = new QILineEdit(pTabInterface);
780 if (m_pEditorNMv4)
781 {
782 m_pLabelNMv4->setBuddy(m_pEditorNMv4);
783 connect(m_pEditorNMv4, &QLineEdit::textChanged,
784 this, &UIDetailsWidgetHostNetwork::sltTextChangedNMv4);
785
786 pLayoutNMv4->addWidget(m_pEditorNMv4);
787 }
788
789 pLayoutInterface->addLayout(pLayoutNMv4, 3, 2);
790 }
791
792 /* Prepare IPv6 address label: */
793 m_pLabelIPv6 = new QLabel(pTabInterface);
794 if (m_pLabelIPv6)
795 {
796 m_pLabelIPv6->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
797 pLayoutInterface->addWidget(m_pLabelIPv6, 4, 1);
798 }
799 /* Prepare IPv6 layout: */
800 QHBoxLayout *pLayoutIPv6 = new QHBoxLayout;
801 if (pLayoutIPv6)
802 {
803 pLayoutIPv6->setContentsMargins(0, 0, 0, 0);
804
805 /* Prepare IPv6 address editor: */
806 m_pEditorIPv6 = new QILineEdit(pTabInterface);
807 if (m_pEditorIPv6)
808 {
809 m_pLabelIPv6->setBuddy(m_pEditorIPv6);
810 connect(m_pEditorIPv6, &QLineEdit::textChanged,
811 this, &UIDetailsWidgetHostNetwork::sltTextChangedIPv6);
812
813 pLayoutIPv6->addWidget(m_pEditorIPv6);
814 }
815
816 pLayoutInterface->addLayout(pLayoutIPv6, 4, 2);
817 }
818
819 /* Prepare NMv6 network mask label: */
820 m_pLabelNMv6 = new QLabel(pTabInterface);
821 if (m_pLabelNMv6)
822 {
823 m_pLabelNMv6->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
824 pLayoutInterface->addWidget(m_pLabelNMv6, 5, 1);
825 }
826 /* Prepare NMv6 layout: */
827 QHBoxLayout *pLayoutNMv6 = new QHBoxLayout;
828 if (pLayoutNMv6)
829 {
830 pLayoutNMv6->setContentsMargins(0, 0, 0, 0);
831
832 /* Prepare NMv6 network mask editor: */
833 m_pEditorNMv6 = new QILineEdit(pTabInterface);
834 if (m_pEditorNMv6)
835 {
836 m_pLabelNMv6->setBuddy(m_pEditorNMv6);
837 connect(m_pEditorNMv6, &QLineEdit::textChanged,
838 this, &UIDetailsWidgetHostNetwork::sltTextChangedNMv6);
839
840 pLayoutNMv6->addWidget(m_pEditorNMv6);
841 }
842
843 pLayoutInterface->addLayout(pLayoutNMv6, 5, 2);
844 }
845
846 /* Prepare indent: */
847 QStyleOption options;
848 options.initFrom(m_pButtonManual);
849 const int iWidth = m_pButtonManual->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &options, m_pButtonManual) +
850 m_pButtonManual->style()->pixelMetric(QStyle::PM_RadioButtonLabelSpacing, &options, m_pButtonManual) -
851 pLayoutInterface->spacing() - 1;
852 QSpacerItem *pSpacer1 = new QSpacerItem(iWidth, 0, QSizePolicy::Fixed, QSizePolicy::Expanding);
853 if (pSpacer1)
854 pLayoutInterface->addItem(pSpacer1, 2, 0, 4);
855 /* Prepare stretch: */
856 QSpacerItem *pSpacer2 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
857 if (pSpacer2)
858 pLayoutInterface->addItem(pSpacer2, 6, 0, 1, 3);
859
860 /* If parent embedded into stack: */
861 if (m_enmEmbedding == EmbedTo_Stack)
862 {
863 /* Prepare button-box: */
864 m_pButtonBoxInterface = new QIDialogButtonBox(pTabInterface);
865 if (m_pButtonBoxInterface)
866 {
867 m_pButtonBoxInterface->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
868 connect(m_pButtonBoxInterface, &QIDialogButtonBox::clicked, this, &UIDetailsWidgetHostNetwork::sltHandleButtonBoxClick);
869
870 pLayoutInterface->addWidget(m_pButtonBoxInterface, 7, 0, 1, 3);
871 }
872 }
873 }
874
875 m_pTabWidget->addTab(pTabInterface, QString());
876 }
877}
878
879void UIDetailsWidgetHostNetwork::prepareTabDHCPServer()
880{
881 /* Prepare 'DHCP server' tab: */
882 QWidget *pTabDHCPServer = new QWidget(m_pTabWidget);
883 if (pTabDHCPServer)
884 {
885 /* Prepare 'DHCP server' layout: */
886 QGridLayout *pLayoutDHCPServer = new QGridLayout(pTabDHCPServer);
887 if (pLayoutDHCPServer)
888 {
889#ifdef VBOX_WS_MAC
890 pLayoutDHCPServer->setSpacing(10);
891 pLayoutDHCPServer->setContentsMargins(10, 10, 10, 10);
892#endif
893
894 /* Prepare DHCP server status check-box: */
895 m_pCheckBoxDHCP = new QCheckBox(pTabDHCPServer);
896 if (m_pCheckBoxDHCP)
897 {
898 connect(m_pCheckBoxDHCP, &QCheckBox::stateChanged,
899 this, &UIDetailsWidgetHostNetwork::sltStatusChangedServer);
900 pLayoutDHCPServer->addWidget(m_pCheckBoxDHCP, 0, 0, 1, 2);
901#ifdef VBOX_WS_MAC
902 pLayoutDHCPServer->setRowMinimumHeight(0, 22);
903#endif
904 }
905
906 /* Prepare DHCP address label: */
907 m_pLabelDHCPAddress = new QLabel(pTabDHCPServer);
908 if (m_pLabelDHCPAddress)
909 {
910 m_pLabelDHCPAddress->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
911 pLayoutDHCPServer->addWidget(m_pLabelDHCPAddress, 1, 1);
912 }
913 /* Prepare DHCP address layout: */
914 QHBoxLayout *pLayoutDHCPAddress = new QHBoxLayout;
915 if (pLayoutDHCPAddress)
916 {
917 pLayoutDHCPAddress->setContentsMargins(0, 0, 0, 0);
918
919 /* Prepare DHCP address editor: */
920 m_pEditorDHCPAddress = new QILineEdit(pTabDHCPServer);
921 if (m_pEditorDHCPAddress)
922 {
923 m_pLabelDHCPAddress->setBuddy(m_pEditorDHCPAddress);
924 connect(m_pEditorDHCPAddress, &QLineEdit::textChanged,
925 this, &UIDetailsWidgetHostNetwork::sltTextChangedAddress);
926
927 pLayoutDHCPAddress->addWidget(m_pEditorDHCPAddress);
928 }
929
930 pLayoutDHCPServer->addLayout(pLayoutDHCPAddress, 1, 2);
931 }
932
933 /* Prepare DHCP network mask label: */
934 m_pLabelDHCPMask = new QLabel(pTabDHCPServer);
935 if (m_pLabelDHCPMask)
936 {
937 m_pLabelDHCPMask->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
938 pLayoutDHCPServer->addWidget(m_pLabelDHCPMask, 2, 1);
939 }
940 /* Prepare DHCP mask layout: */
941 QHBoxLayout *pLayoutDHCPMask = new QHBoxLayout;
942 if (pLayoutDHCPMask)
943 {
944 pLayoutDHCPMask->setContentsMargins(0, 0, 0, 0);
945
946 /* Prepare DHCP network mask editor: */
947 m_pEditorDHCPMask = new QILineEdit(pTabDHCPServer);
948 if (m_pEditorDHCPMask)
949 {
950 m_pLabelDHCPMask->setBuddy(m_pEditorDHCPMask);
951 connect(m_pEditorDHCPMask, &QLineEdit::textChanged,
952 this, &UIDetailsWidgetHostNetwork::sltTextChangedMask);
953
954 pLayoutDHCPMask->addWidget(m_pEditorDHCPMask);
955 }
956
957 pLayoutDHCPServer->addLayout(pLayoutDHCPMask, 2, 2);
958 }
959
960 /* Prepare DHCP lower address label: */
961 m_pLabelDHCPLowerAddress = new QLabel(pTabDHCPServer);
962 if (m_pLabelDHCPLowerAddress)
963 {
964 m_pLabelDHCPLowerAddress->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
965 pLayoutDHCPServer->addWidget(m_pLabelDHCPLowerAddress, 3, 1);
966 }
967 /* Prepare DHCP lower address layout: */
968 QHBoxLayout *pLayoutDHCPLowerAddress = new QHBoxLayout;
969 if (pLayoutDHCPLowerAddress)
970 {
971 pLayoutDHCPLowerAddress->setContentsMargins(0, 0, 0, 0);
972
973 /* Prepare DHCP lower address editor: */
974 m_pEditorDHCPLowerAddress = new QILineEdit(pTabDHCPServer);
975 if (m_pEditorDHCPLowerAddress)
976 {
977 m_pLabelDHCPLowerAddress->setBuddy(m_pEditorDHCPLowerAddress);
978 connect(m_pEditorDHCPLowerAddress, &QLineEdit::textChanged,
979 this, &UIDetailsWidgetHostNetwork::sltTextChangedLowerAddress);
980
981 pLayoutDHCPLowerAddress->addWidget(m_pEditorDHCPLowerAddress);
982 }
983
984 pLayoutDHCPServer->addLayout(pLayoutDHCPLowerAddress, 3, 2);
985 }
986
987 /* Prepare DHCP upper address label: */
988 m_pLabelDHCPUpperAddress = new QLabel(pTabDHCPServer);
989 if (m_pLabelDHCPUpperAddress)
990 {
991 m_pLabelDHCPUpperAddress->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
992 pLayoutDHCPServer->addWidget(m_pLabelDHCPUpperAddress, 4, 1);
993 }
994 /* Prepare DHCP upper address layout: */
995 QHBoxLayout *pLayoutDHCPUpperAddress = new QHBoxLayout;
996 if (pLayoutDHCPUpperAddress)
997 {
998 pLayoutDHCPUpperAddress->setContentsMargins(0, 0, 0, 0);
999
1000 /* Prepare DHCP upper address editor: */
1001 m_pEditorDHCPUpperAddress = new QILineEdit(pTabDHCPServer);
1002 if (m_pEditorDHCPUpperAddress)
1003 {
1004 m_pLabelDHCPUpperAddress->setBuddy(m_pEditorDHCPUpperAddress);
1005 connect(m_pEditorDHCPUpperAddress, &QLineEdit::textChanged,
1006 this, &UIDetailsWidgetHostNetwork::sltTextChangedUpperAddress);
1007
1008 pLayoutDHCPUpperAddress->addWidget(m_pEditorDHCPUpperAddress);
1009 }
1010
1011 pLayoutDHCPServer->addLayout(pLayoutDHCPUpperAddress, 4, 2);
1012 }
1013
1014 /* Prepare indent: */
1015 QStyleOption options;
1016 options.initFrom(m_pCheckBoxDHCP);
1017 const int iWidth = m_pCheckBoxDHCP->style()->pixelMetric(QStyle::PM_IndicatorWidth, &options, m_pCheckBoxDHCP) +
1018 m_pCheckBoxDHCP->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &options, m_pCheckBoxDHCP) -
1019 pLayoutDHCPServer->spacing() - 1;
1020 QSpacerItem *pSpacer1 = new QSpacerItem(iWidth, 0, QSizePolicy::Fixed, QSizePolicy::Expanding);
1021 if (pSpacer1)
1022 pLayoutDHCPServer->addItem(pSpacer1, 1, 0, 4);
1023 /* Prepare stretch: */
1024 QSpacerItem *pSpacer2 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
1025 if (pSpacer2)
1026 pLayoutDHCPServer->addItem(pSpacer2, 5, 0, 1, 3);
1027
1028 /* If parent embedded into stack: */
1029 if (m_enmEmbedding == EmbedTo_Stack)
1030 {
1031 /* Prepare button-box: */
1032 m_pButtonBoxServer = new QIDialogButtonBox(pTabDHCPServer);
1033 if (m_pButtonBoxServer)
1034 {
1035 m_pButtonBoxServer->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
1036 connect(m_pButtonBoxServer, &QIDialogButtonBox::clicked, this, &UIDetailsWidgetHostNetwork::sltHandleButtonBoxClick);
1037
1038 pLayoutDHCPServer->addWidget(m_pButtonBoxServer, 6, 0, 1, 3);
1039 }
1040 }
1041 }
1042
1043 m_pTabWidget->addTab(pTabDHCPServer, QString());
1044 }
1045}
1046#endif /* !VBOX_WS_MAC */
1047
1048#ifdef VBOX_WS_MAC
1049void UIDetailsWidgetHostNetwork::loadData()
1050{
1051 /* Check whether network exists and configurable: */
1052 const bool fIsNetworkExists = m_newData.m_fExists;
1053
1054 /* Toggle network fields availability: */
1055 if (m_pLabelName)
1056 m_pLabelName->setEnabled(fIsNetworkExists);
1057 if (m_pEditorName)
1058 m_pEditorName->setEnabled(fIsNetworkExists);
1059 if (m_pLabelMask)
1060 m_pLabelMask->setEnabled(fIsNetworkExists);
1061 if (m_pEditorMask)
1062 m_pEditorMask->setEnabled(fIsNetworkExists);
1063 if (m_pLabelLBnd)
1064 m_pLabelLBnd->setEnabled(fIsNetworkExists);
1065 if (m_pEditorLBnd)
1066 m_pEditorLBnd->setEnabled(fIsNetworkExists);
1067 if (m_pLabelUBnd)
1068 m_pLabelUBnd->setEnabled(fIsNetworkExists);
1069 if (m_pEditorUBnd)
1070 m_pEditorUBnd->setEnabled(fIsNetworkExists);
1071
1072 /* Load network fields: */
1073 if (m_pEditorName)
1074 m_pEditorName->setText(m_newData.m_strName);
1075 if (m_pEditorMask)
1076 m_pEditorMask->setText(m_newData.m_strMask);
1077 if (m_pEditorLBnd)
1078 m_pEditorLBnd->setText(m_newData.m_strLBnd);
1079 if (m_pEditorUBnd)
1080 m_pEditorUBnd->setText(m_newData.m_strUBnd);
1081}
1082
1083#else /* !VBOX_WS_MAC */
1084
1085void UIDetailsWidgetHostNetwork::loadDataForInterface()
1086{
1087 /* Check whether interface exists and configurable: */
1088 const bool fIsInterfaceExists = m_newData.m_interface.m_fExists;
1089 const bool fIsInterfaceConfigurable = !m_newData.m_interface.m_fDHCPEnabled;
1090
1091 /* Toggle radio-buttons availability: */
1092 if (m_pButtonAutomatic)
1093 m_pButtonAutomatic->setEnabled(fIsInterfaceExists);
1094 if (m_pButtonManual)
1095 m_pButtonManual->setEnabled(fIsInterfaceExists);
1096
1097 /* Toggle IPv4 & IPv6 interface fields availability: */
1098 if (m_pLabelIPv4)
1099 m_pLabelIPv4->setEnabled(fIsInterfaceExists && fIsInterfaceConfigurable);
1100 if (m_pLabelNMv4)
1101 m_pLabelNMv4->setEnabled(fIsInterfaceExists && fIsInterfaceConfigurable);
1102 if (m_pEditorIPv4)
1103 m_pEditorIPv4->setEnabled(fIsInterfaceExists && fIsInterfaceConfigurable);
1104 if (m_pEditorNMv4)
1105 m_pEditorNMv4->setEnabled(fIsInterfaceExists && fIsInterfaceConfigurable);
1106
1107 /* Load IPv4 interface fields: */
1108 if (m_pButtonAutomatic)
1109 m_pButtonAutomatic->setChecked(!fIsInterfaceConfigurable);
1110 if (m_pButtonManual)
1111 m_pButtonManual->setChecked(fIsInterfaceConfigurable);
1112 if (m_pEditorIPv4)
1113 m_pEditorIPv4->setText(m_newData.m_interface.m_strAddress);
1114 if (m_pEditorNMv4)
1115 m_pEditorNMv4->setText(m_newData.m_interface.m_strMask);
1116
1117 /* Toggle IPv6 interface fields availability: */
1118 const bool fIsIpv6Configurable = fIsInterfaceConfigurable && m_newData.m_interface.m_fSupportedIPv6;
1119 if (m_pLabelIPv6)
1120 m_pLabelIPv6->setEnabled(fIsInterfaceExists && fIsIpv6Configurable);
1121 if (m_pLabelNMv6)
1122 m_pLabelNMv6->setEnabled(fIsInterfaceExists && fIsIpv6Configurable);
1123 if (m_pEditorIPv6)
1124 m_pEditorIPv6->setEnabled(fIsInterfaceExists && fIsIpv6Configurable);
1125 if (m_pEditorNMv6)
1126 m_pEditorNMv6->setEnabled(fIsInterfaceExists && fIsIpv6Configurable);
1127
1128 /* Load IPv6 interface fields: */
1129 if (m_pEditorIPv6)
1130 m_pEditorIPv6->setText(m_newData.m_interface.m_strAddress6);
1131 if (m_pEditorNMv6)
1132 m_pEditorNMv6->setText(m_newData.m_interface.m_strPrefixLength6);
1133}
1134
1135void UIDetailsWidgetHostNetwork::loadDataForDHCPServer()
1136{
1137 /* Check whether interface exists and DHCP server available: */
1138 const bool fIsInterfaceExists = m_newData.m_interface.m_fExists;
1139 const bool fIsDHCPServerEnabled = m_newData.m_dhcpserver.m_fEnabled;
1140
1141 /* Toggle check-box availability: */
1142 m_pCheckBoxDHCP->setEnabled(fIsInterfaceExists);
1143
1144 /* Toggle DHCP server fields availability: */
1145 if (m_pLabelDHCPAddress)
1146 m_pLabelDHCPAddress->setEnabled(fIsInterfaceExists && fIsDHCPServerEnabled);
1147 if (m_pLabelDHCPMask)
1148 m_pLabelDHCPMask->setEnabled(fIsInterfaceExists && fIsDHCPServerEnabled);
1149 if (m_pLabelDHCPLowerAddress)
1150 m_pLabelDHCPLowerAddress->setEnabled(fIsInterfaceExists && fIsDHCPServerEnabled);
1151 if (m_pLabelDHCPUpperAddress)
1152 m_pLabelDHCPUpperAddress->setEnabled(fIsInterfaceExists && fIsDHCPServerEnabled);
1153 if (m_pEditorDHCPAddress)
1154 m_pEditorDHCPAddress->setEnabled(fIsInterfaceExists && fIsDHCPServerEnabled);
1155 if (m_pEditorDHCPMask)
1156 m_pEditorDHCPMask->setEnabled(fIsInterfaceExists && fIsDHCPServerEnabled);
1157 if (m_pEditorDHCPLowerAddress)
1158 m_pEditorDHCPLowerAddress->setEnabled(fIsInterfaceExists && fIsDHCPServerEnabled);
1159 if (m_pEditorDHCPUpperAddress)
1160 m_pEditorDHCPUpperAddress->setEnabled(fIsInterfaceExists && fIsDHCPServerEnabled);
1161
1162 /* Load DHCP server fields: */
1163 if (m_pCheckBoxDHCP)
1164 m_pCheckBoxDHCP->setChecked(fIsDHCPServerEnabled);
1165 if (m_pEditorDHCPAddress)
1166 m_pEditorDHCPAddress->setText(m_newData.m_dhcpserver.m_strAddress);
1167 if (m_pEditorDHCPMask)
1168 m_pEditorDHCPMask->setText(m_newData.m_dhcpserver.m_strMask);
1169 if (m_pEditorDHCPLowerAddress)
1170 m_pEditorDHCPLowerAddress->setText(m_newData.m_dhcpserver.m_strLowerAddress);
1171 if (m_pEditorDHCPUpperAddress)
1172 m_pEditorDHCPUpperAddress->setText(m_newData.m_dhcpserver.m_strUpperAddress);
1173
1174 /* Invent default values if server was enabled
1175 * but at least one current value is invalid: */
1176 if ( fIsDHCPServerEnabled
1177 && m_pEditorDHCPAddress
1178 && m_pEditorDHCPMask
1179 && m_pEditorDHCPLowerAddress
1180 && m_pEditorDHCPUpperAddress
1181 && ( m_pEditorDHCPAddress->text().isEmpty()
1182 || m_pEditorDHCPAddress->text() == "0.0.0.0"
1183 || m_pEditorDHCPMask->text().isEmpty()
1184 || m_pEditorDHCPMask->text() == "0.0.0.0"
1185 || m_pEditorDHCPLowerAddress->text().isEmpty()
1186 || m_pEditorDHCPLowerAddress->text() == "0.0.0.0"
1187 || m_pEditorDHCPUpperAddress->text().isEmpty()
1188 || m_pEditorDHCPUpperAddress->text() == "0.0.0.0"))
1189 {
1190 const QStringList &proposal = makeDhcpServerProposal(m_oldData.m_interface.m_strAddress,
1191 m_oldData.m_interface.m_strMask);
1192 m_pEditorDHCPAddress->setText(proposal.at(0));
1193 m_pEditorDHCPMask->setText(proposal.at(1));
1194 m_pEditorDHCPLowerAddress->setText(proposal.at(2));
1195 m_pEditorDHCPUpperAddress->setText(proposal.at(3));
1196 }
1197}
1198#endif /* !VBOX_WS_MAC */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use