1 | /**
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * "VM network settings" dialog UI include (Qt Designer)
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /****************************************************************************
|
---|
24 | ** ui.h extension file, included from the uic-generated form implementation.
|
---|
25 | **
|
---|
26 | ** If you wish to add, delete or rename functions or slots use
|
---|
27 | ** Qt Designer which will update this file, preserving your code. Create an
|
---|
28 | ** init() function in place of a constructor, and a destroy() function in
|
---|
29 | ** place of a destructor.
|
---|
30 | *****************************************************************************/
|
---|
31 |
|
---|
32 | void VBoxVMNetworkSettings::init()
|
---|
33 | {
|
---|
34 | cbAdapterType->insertItem (vboxGlobal().toString (KNetworkAdapterType_Am79C970A));
|
---|
35 | cbAdapterType->insertItem (vboxGlobal().toString (KNetworkAdapterType_Am79C973));
|
---|
36 | #ifdef VBOX_WITH_E1000
|
---|
37 | cbAdapterType->insertItem (vboxGlobal().toString (KNetworkAdapterType_I82540EM));
|
---|
38 | cbAdapterType->insertItem (vboxGlobal().toString (KNetworkAdapterType_I82543GC));
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | leMACAddress->setValidator (new QRegExpValidator
|
---|
42 | (QRegExp ("[0-9A-Fa-f][02468ACEace][0-9A-Fa-f]{10}"), this));
|
---|
43 |
|
---|
44 | cbNetworkAttachment->insertItem (vboxGlobal().toString (KNetworkAttachmentType_Null));
|
---|
45 | cbNetworkAttachment->insertItem (vboxGlobal().toString (KNetworkAttachmentType_NAT));
|
---|
46 | cbNetworkAttachment->insertItem (vboxGlobal().toString (KNetworkAttachmentType_HostInterface));
|
---|
47 | cbNetworkAttachment->insertItem (vboxGlobal().toString (KNetworkAttachmentType_Internal));
|
---|
48 |
|
---|
49 | #if defined Q_WS_X11
|
---|
50 | leTAPDescriptor->setValidator (new QIntValidator (-1, std::numeric_limits <LONG>::max(), this));
|
---|
51 | #else
|
---|
52 | /* hide unavailable settings (TAP setup and terminate apps) */
|
---|
53 | frmTAPSetupTerminate->setHidden (true);
|
---|
54 | /* disable unused interface name UI */
|
---|
55 | frmHostInterface_X11->setHidden (true);
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #if defined Q_WS_WIN || defined VBOX_WITH_NETFLT
|
---|
59 | /* disable unused interface name UI */
|
---|
60 | grbTAP->setHidden (true);
|
---|
61 | /* Make the line editor of the editable combobox read-only to disable
|
---|
62 | * modifications by the user. The combobox itself remains "editable" to
|
---|
63 | * allow for setting text missing in the drop-down list. */
|
---|
64 | cbHostInterfaceName->lineEdit()->setReadOnly (true);
|
---|
65 |
|
---|
66 | connect (grbEnabled, SIGNAL (toggled (bool)),
|
---|
67 | this, SLOT (grbEnabledToggled (bool)));
|
---|
68 | #else
|
---|
69 | /* disable unused interface name UI */
|
---|
70 | txHostInterface_WIN->setHidden (true);
|
---|
71 | cbHostInterfaceName->setHidden (true);
|
---|
72 | /* setup iconsets */
|
---|
73 | pbTAPSetup->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
|
---|
74 | "select_file_dis_16px.png"));
|
---|
75 | pbTAPTerminate->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
|
---|
76 | "select_file_dis_16px.png"));
|
---|
77 | #endif
|
---|
78 |
|
---|
79 | /* the TAP file descriptor setting is always invisible -- currently not used
|
---|
80 | * (remove the relative code at all? -- just leave for some time...) */
|
---|
81 | frmTAPDescriptor->setHidden (true);
|
---|
82 | }
|
---|
83 |
|
---|
84 | VBoxVMNetworkSettings::CheckPageResult
|
---|
85 | VBoxVMNetworkSettings::checkPage (const QStringList &aList)
|
---|
86 | {
|
---|
87 | KNetworkAttachmentType type =
|
---|
88 | vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
|
---|
89 | if (!grbEnabled->isChecked())
|
---|
90 | return CheckPage_Ok;
|
---|
91 | else
|
---|
92 | #if defined Q_WS_WIN || defined VBOX_WITH_NETFLT
|
---|
93 | if (type == KNetworkAttachmentType_HostInterface &&
|
---|
94 | isInterfaceInvalid (aList, cbHostInterfaceName->currentText()))
|
---|
95 | return CheckPage_InvalidInterface;
|
---|
96 | else
|
---|
97 | #else
|
---|
98 | NOREF (aList);
|
---|
99 | #endif
|
---|
100 | if (type == KNetworkAttachmentType_Internal &&
|
---|
101 | cbInternalNetworkName->currentText().isEmpty())
|
---|
102 | return CheckPage_NoNetworkName;
|
---|
103 | else
|
---|
104 | return CheckPage_Ok;
|
---|
105 | }
|
---|
106 |
|
---|
107 | void VBoxVMNetworkSettings::loadInterfaceList (const QStringList &aList,
|
---|
108 | const QString &aNillItem)
|
---|
109 | {
|
---|
110 | #if defined Q_WS_WIN || defined VBOX_WITH_NETFLT
|
---|
111 | /* save current list item name */
|
---|
112 | QString currentListItemName = cbHostInterfaceName->currentText();
|
---|
113 | /* clear current list */
|
---|
114 | cbHostInterfaceName->clear();
|
---|
115 | /* load current list items */
|
---|
116 | if (aList.count())
|
---|
117 | cbHostInterfaceName->insertStringList (aList);
|
---|
118 | else
|
---|
119 | cbHostInterfaceName->setCurrentText (aNillItem);
|
---|
120 |
|
---|
121 | if (currentListItemName.isEmpty() || currentListItemName == aNillItem)
|
---|
122 | cbHostInterfaceName->setCurrentItem (0);
|
---|
123 | else
|
---|
124 | cbHostInterfaceName->setCurrentText (currentListItemName);
|
---|
125 | #else
|
---|
126 | NOREF (aList);
|
---|
127 | NOREF (aNillItem);
|
---|
128 | #endif
|
---|
129 | }
|
---|
130 |
|
---|
131 | void VBoxVMNetworkSettings::loadNetworksList (const QStringList &aList)
|
---|
132 | {
|
---|
133 | QString curText = cbInternalNetworkName->currentText();
|
---|
134 | cbInternalNetworkName->clear();
|
---|
135 | cbInternalNetworkName->clearEdit();
|
---|
136 | cbInternalNetworkName->insertStringList (aList);
|
---|
137 | cbInternalNetworkName->setCurrentText (curText);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void VBoxVMNetworkSettings::getFromAdapter (const CNetworkAdapter &adapter)
|
---|
141 | {
|
---|
142 | cadapter = adapter;
|
---|
143 |
|
---|
144 | grbEnabled->setChecked (adapter.GetEnabled());
|
---|
145 |
|
---|
146 | cbAdapterType->setCurrentText (vboxGlobal().
|
---|
147 | toString (adapter.GetAdapterType()));
|
---|
148 |
|
---|
149 | KNetworkAttachmentType type = adapter.GetAttachmentType();
|
---|
150 | cbNetworkAttachment->setCurrentItem (0);
|
---|
151 | for (int i = 0; i < cbNetworkAttachment->count(); i ++)
|
---|
152 | if (vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->text (i)) == type)
|
---|
153 | {
|
---|
154 | cbNetworkAttachment->setCurrentItem (i);
|
---|
155 | cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
|
---|
156 | break;
|
---|
157 | }
|
---|
158 |
|
---|
159 | leMACAddress->setText (adapter.GetMACAddress());
|
---|
160 |
|
---|
161 | chbCableConnected->setChecked (adapter.GetCableConnected());
|
---|
162 |
|
---|
163 | #if defined Q_WS_WIN || defined VBOX_WITH_NETFLT
|
---|
164 | if (!adapter.GetHostInterface().isEmpty())
|
---|
165 | cbHostInterfaceName->setCurrentText (adapter.GetHostInterface());
|
---|
166 | #else
|
---|
167 | leHostInterface->setText (adapter.GetHostInterface());
|
---|
168 | #endif
|
---|
169 | cbInternalNetworkName->setCurrentText (adapter.GetInternalNetwork());
|
---|
170 |
|
---|
171 | #if defined Q_WS_X11
|
---|
172 | leTAPDescriptor->setText (QString::number (adapter.GetTAPFileDescriptor()));
|
---|
173 | leTAPSetup->setText (adapter.GetTAPSetupApplication());
|
---|
174 | leTAPTerminate->setText (adapter.GetTAPTerminateApplication());
|
---|
175 | #endif
|
---|
176 | }
|
---|
177 |
|
---|
178 | void VBoxVMNetworkSettings::putBackToAdapter()
|
---|
179 | {
|
---|
180 | cadapter.SetEnabled (grbEnabled->isChecked());
|
---|
181 |
|
---|
182 | cadapter.SetAdapterType (vboxGlobal().
|
---|
183 | toNetworkAdapterType (cbAdapterType->currentText()));
|
---|
184 |
|
---|
185 | KNetworkAttachmentType type =
|
---|
186 | vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
|
---|
187 | switch (type)
|
---|
188 | {
|
---|
189 | case KNetworkAttachmentType_Null:
|
---|
190 | cadapter.Detach();
|
---|
191 | break;
|
---|
192 | case KNetworkAttachmentType_NAT:
|
---|
193 | cadapter.AttachToNAT();
|
---|
194 | break;
|
---|
195 | case KNetworkAttachmentType_HostInterface:
|
---|
196 | cadapter.AttachToHostInterface();
|
---|
197 | break;
|
---|
198 | case KNetworkAttachmentType_Internal:
|
---|
199 | cadapter.AttachToInternalNetwork();
|
---|
200 | break;
|
---|
201 | default:
|
---|
202 | AssertMsgFailed (("Invalid network attachment type: %d", type));
|
---|
203 | break;
|
---|
204 | }
|
---|
205 |
|
---|
206 | cadapter.SetMACAddress (leMACAddress->text());
|
---|
207 |
|
---|
208 | cadapter.SetCableConnected (chbCableConnected->isChecked());
|
---|
209 |
|
---|
210 | if (type == KNetworkAttachmentType_HostInterface)
|
---|
211 | {
|
---|
212 | #if defined Q_WS_WIN || defined VBOX_WITH_NETFLT
|
---|
213 | if (!cbHostInterfaceName->currentText().isEmpty())
|
---|
214 | cadapter.SetHostInterface (cbHostInterfaceName->currentText());
|
---|
215 | #else
|
---|
216 | QString iface = leHostInterface->text();
|
---|
217 | cadapter.SetHostInterface (iface.isEmpty() ? QString::null : iface);
|
---|
218 | #endif
|
---|
219 | #if defined Q_WS_X11
|
---|
220 | cadapter.SetTAPFileDescriptor (leTAPDescriptor->text().toLong());
|
---|
221 | QString setup = leTAPSetup->text();
|
---|
222 | cadapter.SetTAPSetupApplication (setup.isEmpty() ? QString::null : setup);
|
---|
223 | QString term = leTAPTerminate->text();
|
---|
224 | cadapter.SetTAPTerminateApplication (term.isEmpty() ? QString::null : term);
|
---|
225 | #endif
|
---|
226 | }
|
---|
227 | else if (type == KNetworkAttachmentType_Internal)
|
---|
228 | cadapter.SetInternalNetwork (cbInternalNetworkName->currentText());
|
---|
229 | }
|
---|
230 |
|
---|
231 | void VBoxVMNetworkSettings::setValidator (QIWidgetValidator *aWalidator)
|
---|
232 | {
|
---|
233 | mWalidator = aWalidator;
|
---|
234 | }
|
---|
235 |
|
---|
236 | void VBoxVMNetworkSettings::revalidate()
|
---|
237 | {
|
---|
238 | mWalidator->revalidate();
|
---|
239 | }
|
---|
240 |
|
---|
241 | void VBoxVMNetworkSettings::grbEnabledToggled (bool aOn)
|
---|
242 | {
|
---|
243 | #if defined Q_WS_WIN || defined VBOX_WITH_NETFLT
|
---|
244 | cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
|
---|
245 | #else
|
---|
246 | NOREF (aOn);
|
---|
247 | #endif
|
---|
248 | }
|
---|
249 |
|
---|
250 | void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &aString)
|
---|
251 | {
|
---|
252 | bool enableHostIf = grbEnabled->isChecked() &&
|
---|
253 | vboxGlobal().toNetworkAttachmentType (aString) ==
|
---|
254 | KNetworkAttachmentType_HostInterface;
|
---|
255 | bool enableIntNet = grbEnabled->isChecked() &&
|
---|
256 | vboxGlobal().toNetworkAttachmentType (aString) ==
|
---|
257 | KNetworkAttachmentType_Internal;
|
---|
258 | #if defined Q_WS_WIN || defined VBOX_WITH_NETFLT
|
---|
259 | txHostInterface_WIN->setEnabled (enableHostIf);
|
---|
260 | cbHostInterfaceName->setEnabled (enableHostIf);
|
---|
261 | #else
|
---|
262 | grbTAP->setEnabled (enableHostIf);
|
---|
263 | #endif
|
---|
264 | txInternalNetwork->setEnabled (enableIntNet);
|
---|
265 | cbInternalNetworkName->setEnabled (enableIntNet);
|
---|
266 | }
|
---|
267 |
|
---|
268 | bool VBoxVMNetworkSettings::isInterfaceInvalid (const QStringList &aList,
|
---|
269 | const QString &aIface)
|
---|
270 | {
|
---|
271 | #if defined Q_WS_WIN || defined VBOX_WITH_NETFLT
|
---|
272 | return aList.find (aIface) == aList.end();
|
---|
273 | #else
|
---|
274 | NOREF (aList);
|
---|
275 | NOREF (aIface);
|
---|
276 | return false;
|
---|
277 | #endif
|
---|
278 | }
|
---|
279 |
|
---|
280 | void VBoxVMNetworkSettings::pbGenerateMAC_clicked()
|
---|
281 | {
|
---|
282 | cadapter.SetMACAddress (QString::null);
|
---|
283 | leMACAddress->setText (cadapter.GetMACAddress());
|
---|
284 | }
|
---|
285 |
|
---|
286 | void VBoxVMNetworkSettings::pbTAPSetup_clicked()
|
---|
287 | {
|
---|
288 | QString selected = QFileDialog::getOpenFileName (
|
---|
289 | "/",
|
---|
290 | QString::null,
|
---|
291 | this,
|
---|
292 | NULL,
|
---|
293 | tr ("Select TAP setup application"));
|
---|
294 |
|
---|
295 | if (selected)
|
---|
296 | leTAPSetup->setText (selected);
|
---|
297 | }
|
---|
298 |
|
---|
299 | void VBoxVMNetworkSettings::pbTAPTerminate_clicked()
|
---|
300 | {
|
---|
301 | QString selected = QFileDialog::getOpenFileName (
|
---|
302 | "/",
|
---|
303 | QString::null,
|
---|
304 | this,
|
---|
305 | NULL,
|
---|
306 | tr ("Select TAP terminate application"));
|
---|
307 |
|
---|
308 | if (selected)
|
---|
309 | leTAPTerminate->setText (selected);
|
---|
310 | }
|
---|