1 | /* $Id: VBoxGLSettingsNetworkDetails.cpp 33686 2010-11-02 12:49:41Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt4 GUI ("VirtualBox"):
|
---|
5 | * VBoxGLSettingsNetworkDetails class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2009 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* VBox Includes */
|
---|
21 | #include "VBoxGLSettingsNetwork.h"
|
---|
22 | #include "VBoxGLSettingsNetworkDetails.h"
|
---|
23 |
|
---|
24 | /* Qt Includes */
|
---|
25 | #include <QHostAddress>
|
---|
26 | #include <QRegExpValidator>
|
---|
27 |
|
---|
28 | VBoxGLSettingsNetworkDetails::VBoxGLSettingsNetworkDetails (QWidget *aParent)
|
---|
29 | : QIWithRetranslateUI2 <QIDialog> (aParent
|
---|
30 | #ifdef Q_WS_MAC
|
---|
31 | ,Qt::Sheet
|
---|
32 | #endif /* Q_WS_MAC */
|
---|
33 | )
|
---|
34 | , mItem(0)
|
---|
35 | {
|
---|
36 | /* Apply UI decorations */
|
---|
37 | Ui::VBoxGLSettingsNetworkDetails::setupUi (this);
|
---|
38 |
|
---|
39 | /* Setup dialog */
|
---|
40 | setWindowIcon (QIcon (":/guesttools_16px.png"));
|
---|
41 |
|
---|
42 | /* Setup validators */
|
---|
43 | QString templateIPv4 ("([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\."
|
---|
44 | "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\."
|
---|
45 | "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\."
|
---|
46 | "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])");
|
---|
47 | QString templateIPv6 ("[0-9a-fA-Z]{1,4}:{1,2}[0-9a-fA-Z]{1,4}:{1,2}"
|
---|
48 | "[0-9a-fA-Z]{1,4}:{1,2}[0-9a-fA-Z]{1,4}:{1,2}"
|
---|
49 | "[0-9a-fA-Z]{1,4}:{1,2}[0-9a-fA-Z]{1,4}:{1,2}"
|
---|
50 | "[0-9a-fA-Z]{1,4}:{1,2}[0-9a-fA-Z]{1,4}");
|
---|
51 |
|
---|
52 | mLeIPv4->setValidator (new QRegExpValidator (QRegExp (templateIPv4), this));
|
---|
53 | mLeNMv4->setValidator (new QRegExpValidator (QRegExp (templateIPv4), this));
|
---|
54 | mLeIPv6->setValidator (new QRegExpValidator (QRegExp (templateIPv6), this));
|
---|
55 | mLeNMv6->setValidator (new QRegExpValidator (QRegExp ("[1-9][0-9]|1[0-1][0-9]|12[0-8]"), this));
|
---|
56 | mLeDhcpAddress->setValidator (new QRegExpValidator (QRegExp (templateIPv4), this));
|
---|
57 | mLeDhcpMask->setValidator (new QRegExpValidator (QRegExp (templateIPv4), this));
|
---|
58 | mLeDhcpLowerAddress->setValidator (new QRegExpValidator (QRegExp (templateIPv4), this));
|
---|
59 | mLeDhcpUpperAddress->setValidator (new QRegExpValidator (QRegExp (templateIPv4), this));
|
---|
60 |
|
---|
61 | /* Setup widgets */
|
---|
62 | mLeIPv6->setFixedWidthByText (QString().fill ('X', 32) + QString().fill (':', 7));
|
---|
63 |
|
---|
64 | #if 0 /* defined (Q_WS_WIN32) */
|
---|
65 | QStyleOption options1;
|
---|
66 | options1.initFrom (mCbManual);
|
---|
67 | QGridLayout *layout1 = qobject_cast <QGridLayout*> (mTwDetails->widget (0)->layout());
|
---|
68 | int wid1 = mCbManual->style()->pixelMetric (QStyle::PM_IndicatorWidth, &options1, mCbManual) +
|
---|
69 | mCbManual->style()->pixelMetric (QStyle::PM_CheckBoxLabelSpacing, &options1, mCbManual) -
|
---|
70 | layout1->spacing() - 1;
|
---|
71 | QSpacerItem *spacer1 = new QSpacerItem (wid1, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
72 | layout1->addItem (spacer1, 1, 0, 4);
|
---|
73 | #else
|
---|
74 | mCbManual->setVisible (false);
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | QStyleOption options2;
|
---|
78 | options2.initFrom (mCbDhcpServerEnabled);
|
---|
79 | QGridLayout *layout2 = qobject_cast <QGridLayout*> (mTwDetails->widget (1)->layout());
|
---|
80 | int wid2 = mCbDhcpServerEnabled->style()->pixelMetric (QStyle::PM_IndicatorWidth, &options2, mCbDhcpServerEnabled) +
|
---|
81 | mCbDhcpServerEnabled->style()->pixelMetric (QStyle::PM_CheckBoxLabelSpacing, &options2, mCbDhcpServerEnabled) -
|
---|
82 | layout2->spacing() - 1;
|
---|
83 | QSpacerItem *spacer2 = new QSpacerItem (wid2, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
84 | layout2->addItem (spacer2, 1, 0, 4);
|
---|
85 |
|
---|
86 | /* Setup connections */
|
---|
87 | connect (mCbManual, SIGNAL (stateChanged (int)),
|
---|
88 | this, SLOT (dhcpClientStatusChanged()));
|
---|
89 | connect (mCbDhcpServerEnabled, SIGNAL (stateChanged (int)),
|
---|
90 | this, SLOT (dhcpServerStatusChanged()));
|
---|
91 |
|
---|
92 | /* Applying language settings */
|
---|
93 | retranslateUi();
|
---|
94 |
|
---|
95 | /* Fix minimum possible size */
|
---|
96 | resize (minimumSizeHint());
|
---|
97 | qApp->processEvents();
|
---|
98 | setFixedSize (minimumSizeHint());
|
---|
99 | }
|
---|
100 |
|
---|
101 | void VBoxGLSettingsNetworkDetails::getFromItem (NetworkItem *aItem)
|
---|
102 | {
|
---|
103 | mItem = aItem;
|
---|
104 |
|
---|
105 | /* Host-only Interface */
|
---|
106 | mCbManual->setChecked (!mItem->isDhcpClientEnabled());
|
---|
107 | #if !0 /* !defined (Q_WS_WIN32) */
|
---|
108 | /* Disable automatic for all hosts for now */
|
---|
109 | mCbManual->setChecked (true);
|
---|
110 | mCbManual->setEnabled (false);
|
---|
111 | #endif
|
---|
112 | dhcpClientStatusChanged();
|
---|
113 |
|
---|
114 | /* DHCP Server */
|
---|
115 | mCbDhcpServerEnabled->setChecked (mItem->isDhcpServerEnabled());
|
---|
116 | dhcpServerStatusChanged();
|
---|
117 | }
|
---|
118 |
|
---|
119 | void VBoxGLSettingsNetworkDetails::putBackToItem()
|
---|
120 | {
|
---|
121 | /* Host-only Interface */
|
---|
122 | mItem->setDhcpClientEnabled (!mCbManual->isChecked());
|
---|
123 | if (mCbManual->isChecked())
|
---|
124 | {
|
---|
125 | mItem->setInterfaceAddress (mLeIPv4->text());
|
---|
126 | mItem->setInterfaceMask (mLeNMv4->text());
|
---|
127 | if (mItem->isIpv6Supported())
|
---|
128 | {
|
---|
129 | mItem->setInterfaceAddress6 (mLeIPv6->text());
|
---|
130 | mItem->setInterfaceMaskLength6 (mLeNMv6->text());
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | /* DHCP Server */
|
---|
135 | mItem->setDhcpServerEnabled (mCbDhcpServerEnabled->isChecked());
|
---|
136 | if (mCbDhcpServerEnabled->isChecked())
|
---|
137 | {
|
---|
138 | mItem->setDhcpServerAddress (mLeDhcpAddress->text());
|
---|
139 | mItem->setDhcpServerMask (mLeDhcpMask->text());
|
---|
140 | mItem->setDhcpLowerAddress (mLeDhcpLowerAddress->text());
|
---|
141 | mItem->setDhcpUpperAddress (mLeDhcpUpperAddress->text());
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | void VBoxGLSettingsNetworkDetails::retranslateUi()
|
---|
146 | {
|
---|
147 | /* Translate uic generated strings */
|
---|
148 | Ui::VBoxGLSettingsNetworkDetails::retranslateUi (this);
|
---|
149 | }
|
---|
150 |
|
---|
151 | void VBoxGLSettingsNetworkDetails::dhcpClientStatusChanged()
|
---|
152 | {
|
---|
153 | bool isManual = mCbManual->isChecked();
|
---|
154 | bool isIpv6Supported = isManual && mItem->isIpv6Supported();
|
---|
155 |
|
---|
156 | mLeIPv4->clear();
|
---|
157 | mLeNMv4->clear();
|
---|
158 | mLeIPv6->clear();
|
---|
159 | mLeNMv6->clear();
|
---|
160 |
|
---|
161 | mLbIPv4->setEnabled (isManual);
|
---|
162 | mLbNMv4->setEnabled (isManual);
|
---|
163 | mLeIPv4->setEnabled (isManual);
|
---|
164 | mLeNMv4->setEnabled (isManual);
|
---|
165 | mLbIPv6->setEnabled (isIpv6Supported);
|
---|
166 | mLbNMv6->setEnabled (isIpv6Supported);
|
---|
167 | mLeIPv6->setEnabled (isIpv6Supported);
|
---|
168 | mLeNMv6->setEnabled (isIpv6Supported);
|
---|
169 |
|
---|
170 | if (isManual)
|
---|
171 | {
|
---|
172 | mLeIPv4->setText (mItem->interfaceAddress());
|
---|
173 | mLeNMv4->setText (mItem->interfaceMask());
|
---|
174 | if (isIpv6Supported)
|
---|
175 | {
|
---|
176 | mLeIPv6->setText (mItem->interfaceAddress6());
|
---|
177 | mLeNMv6->setText (mItem->interfaceMaskLength6());
|
---|
178 | }
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | void VBoxGLSettingsNetworkDetails::dhcpServerStatusChanged()
|
---|
183 | {
|
---|
184 | bool isEnabled = mCbDhcpServerEnabled->isChecked();
|
---|
185 |
|
---|
186 | mLeDhcpAddress->clear();
|
---|
187 | mLeDhcpMask->clear();
|
---|
188 | mLeDhcpLowerAddress->clear();
|
---|
189 | mLeDhcpUpperAddress->clear();
|
---|
190 |
|
---|
191 | mLbDhcpAddress->setEnabled (isEnabled);
|
---|
192 | mLbDhcpMask->setEnabled (isEnabled);
|
---|
193 | mLbDhcpLowerAddress->setEnabled (isEnabled);
|
---|
194 | mLbDhcpUpperAddress->setEnabled (isEnabled);
|
---|
195 | mLeDhcpAddress->setEnabled (isEnabled);
|
---|
196 | mLeDhcpMask->setEnabled (isEnabled);
|
---|
197 | mLeDhcpLowerAddress->setEnabled (isEnabled);
|
---|
198 | mLeDhcpUpperAddress->setEnabled (isEnabled);
|
---|
199 |
|
---|
200 | if (isEnabled)
|
---|
201 | {
|
---|
202 | mLeDhcpAddress->setText (mItem->dhcpServerAddress());
|
---|
203 | mLeDhcpMask->setText (mItem->dhcpServerMask());
|
---|
204 | mLeDhcpLowerAddress->setText (mItem->dhcpLowerAddress());
|
---|
205 | mLeDhcpUpperAddress->setText (mItem->dhcpUpperAddress());
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|