VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMNetworkSettings.ui.h@ 1521

Last change on this file since 1521 was 1521, checked in by vboxsync, 18 years ago

make internal network an available setting from GUI

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/**
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * "VM network settings" dialog UI include (Qt Designer)
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.215389.xyz. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
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
32void VBoxVMNetworkSettings::init()
33{
34 /* set initial values
35 * -------------------------------------------------------------------- */
36
37 leMACAddress->setValidator (new QRegExpValidator (QRegExp ("[0-9,A-F]{12,12}"), this));
38
39#if defined Q_WS_X11
40 leTAPDescriptor->setValidator (new QIntValidator (-1, std::numeric_limits <LONG>::max(), this));
41#endif
42
43 /* set initial values
44 * -------------------------------------------------------------------- */
45
46 NoSuitableIfaces = tr ("<No suitable interfaces>");
47
48#if defined Q_WS_WIN
49 updateInterfaceList();
50#endif
51
52 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::NoNetworkAttachment));
53 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::NATNetworkAttachment));
54 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::HostInterfaceNetworkAttachment));
55 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::InternalNetworkAttachment));
56
57 grbTAP->setEnabled (false); /* initially disabled */
58
59#if defined Q_WS_WIN
60 /* disable unused interface name UI */
61 frmHostInterface_X11->setHidden (true);
62 /* setup iconsets -- qdesigner is not capable... */
63 pbHostAdd->setIconSet (VBoxGlobal::iconSet ("add_host_iface_16px.png",
64 "add_host_iface_disabled_16px.png"));
65 pbHostRemove->setIconSet (VBoxGlobal::iconSet ("remove_host_iface_16px.png",
66 "remove_host_iface_disabled_16px.png"));
67#else
68 /* disable unused interface name UI */
69 frmHostInterface_WIN->setHidden (true);
70 /* setup iconsets -- qdesigner is not capable... */
71 pbTAPSetup->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
72 "select_file_dis_16px.png"));
73 pbTAPTerminate->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
74 "select_file_dis_16px.png"));
75#endif
76
77#if !defined Q_WS_X11
78 /* hide unavailable settings (TAP setup and terminate apps) */
79 frmTAPSetupTerminate->setHidden (true);
80#endif
81
82 /* the TAP file descriptor setting is always invisible -- currently not used
83 * (remove the relative code at all? -- just leave for some time...) */
84 frmTAPDescriptor->setHidden (true);
85}
86
87void VBoxVMNetworkSettings::updateInterfaceList()
88{
89#if defined Q_WS_WIN
90 /* clear lists */
91 networkInterfaceList.clear();
92 lbHostInterface->clear();
93 /* read a QStringList of interface names */
94 CHostNetworkInterfaceEnumerator en =
95 vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
96 while (en.HasMore())
97 networkInterfaceList += en.GetNext().GetName();
98 /* setup a list of interface names */
99 if (networkInterfaceList.count())
100 lbHostInterface->insertStringList (networkInterfaceList);
101 else
102 lbHostInterface->insertItem (NoSuitableIfaces);
103 /* disable interface delete button */
104 pbHostRemove->setEnabled (!networkInterfaceList.isEmpty());
105#endif
106}
107
108void VBoxVMNetworkSettings::getFromAdapter (const CNetworkAdapter &adapter)
109{
110 cadapter = adapter;
111
112 grbEnabled->setChecked (adapter.GetEnabled());
113
114 CEnums::NetworkAttachmentType type = adapter.GetAttachmentType();
115 cbNetworkAttachment->setCurrentItem (0);
116 for (int i = 0; i < cbNetworkAttachment->count(); i ++)
117 if (vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->text (i)) == type)
118 {
119 cbNetworkAttachment->setCurrentItem (i);
120 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
121 break;
122 }
123
124 leMACAddress->setText (adapter.GetMACAddress());
125
126 chbCableConnected->setChecked (adapter.GetCableConnected());
127
128#if defined Q_WS_WIN
129 if (adapter.GetHostInterface().isEmpty())
130 lbHostInterface->setCurrentItem (0);
131 else
132 {
133 QListBoxItem* adapterNode = lbHostInterface->findItem(adapter.GetHostInterface());
134 if (adapterNode)
135 lbHostInterface->setCurrentItem(adapterNode);
136 }
137#else
138 leHostInterface->setText (adapter.GetHostInterface());
139#endif
140
141#if defined Q_WS_X11
142 leTAPDescriptor->setText (QString::number(adapter.GetTAPFileDescriptor()));
143 leTAPSetup->setText (adapter.GetTAPSetupApplication());
144 leTAPTerminate->setText (adapter.GetTAPTerminateApplication());
145#endif
146}
147
148void VBoxVMNetworkSettings::putBackToAdapter()
149{
150 cadapter.SetEnabled (grbEnabled->isChecked());
151
152 CEnums::NetworkAttachmentType type =
153 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
154 switch (type)
155 {
156 case CEnums::NoNetworkAttachment:
157 cadapter.Detach();
158 break;
159 case CEnums::NATNetworkAttachment:
160 cadapter.AttachToNAT();
161 break;
162 case CEnums::HostInterfaceNetworkAttachment:
163 cadapter.AttachToHostInterface();
164 break;
165 case CEnums::InternalNetworkAttachment:
166 cadapter.AttachToInternalNetwork();
167 break;
168 default:
169 AssertMsgFailed (("Invalid network attachment type: %d", type));
170 break;
171 }
172
173 cadapter.SetMACAddress (leMACAddress->text());
174
175 cadapter.SetCableConnected (chbCableConnected->isChecked());
176
177 if (type == CEnums::HostInterfaceNetworkAttachment)
178 {
179#if defined Q_WS_WIN
180 if (!lbHostInterface->currentText().isEmpty())
181 cadapter.SetHostInterface (lbHostInterface->currentText());
182#else
183 QString iface = leHostInterface->text();
184 cadapter.SetHostInterface (iface.isEmpty() ? QString::null : iface);
185#endif
186#if defined Q_WS_X11
187 cadapter.SetTAPFileDescriptor (leTAPDescriptor->text().toLong());
188 QString setup = leTAPSetup->text();
189 cadapter.SetTAPSetupApplication (setup.isEmpty() ? QString::null : setup);
190 QString term = leTAPTerminate->text();
191 cadapter.SetTAPTerminateApplication (term.isEmpty() ? QString::null : term);
192#endif
193 }
194}
195
196void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &string)
197{
198 grbTAP->setEnabled (vboxGlobal().toNetworkAttachmentType (string) ==
199 CEnums::HostInterfaceNetworkAttachment);
200}
201
202void VBoxVMNetworkSettings::lbHostInterface_highlighted(QListBoxItem* /*item*/)
203{
204 leHostInterfaceName->clear();
205}
206
207bool VBoxVMNetworkSettings::checkNetworkInterface (QString ni)
208{
209#if defined Q_WS_WIN
210 return networkInterfaceList.find (ni) != networkInterfaceList.end() ? 1 : 0;
211#else
212 NOREF(ni);
213 return true;
214#endif
215}
216
217void VBoxVMNetworkSettings::pbGenerateMAC_clicked()
218{
219 cadapter.SetMACAddress (QString::null);
220 leMACAddress->setText (cadapter.GetMACAddress());
221}
222
223void VBoxVMNetworkSettings::pbTAPSetup_clicked()
224{
225// QFileDialog dlg ("/", QString::null, this);
226// dlg.setMode (QFileDialog::ExistingFile);
227// dlg.setViewMode (QFileDialog::List);
228// dlg.setCaption (tr ("Select TAP setup application"));
229// if (dlg.exec() == QDialog::Accepted)
230// leTAPSetup->setText (dlg.selectedFile());
231
232 QString selected = QFileDialog::getOpenFileName (
233 "/",
234 QString::null,
235 this,
236 NULL,
237 tr ("Select TAP setup application"));
238
239 if (selected)
240 leTAPSetup->setText (selected);
241}
242
243void VBoxVMNetworkSettings::pbTAPTerminate_clicked()
244{
245// QFileDialog dlg ("/", QString::null, this);
246// dlg.setMode (QFileDialog::ExistingFile);
247// dlg.setViewMode (QFileDialog::List);
248// dlg.setCaption (tr ("Select TAP terminate application"));
249// if (dlg.exec() == QDialog::Accepted)
250// leTAPTerminate->setText (dlg.selectedFile());
251
252 QString selected = QFileDialog::getOpenFileName (
253 "/",
254 QString::null,
255 this,
256 NULL,
257 tr ("Select TAP terminate application"));
258
259 if (selected)
260 leTAPTerminate->setText (selected);
261}
262
263void VBoxVMNetworkSettings::hostInterfaceAdd()
264{
265#if defined Q_WS_WIN
266
267 /* allow the started helper process to make itself the foreground window */
268 AllowSetForegroundWindow (ASFW_ANY);
269
270 /* check interface name */
271 QString iName = leHostInterfaceName->text();
272 if (iName.isEmpty() || iName == NoSuitableIfaces)
273 {
274 vboxProblem().message (this, VBoxProblemReporter::Error,
275 tr ("Host network interface name cannot be empty"));
276 return;
277 }
278
279 /* create interface */
280 CHost host = vboxGlobal().virtualBox().GetHost();
281 CHostNetworkInterface iFace;
282 CProgress progress = host.CreateHostNetworkInterface (iName, iFace);
283 if (host.isOk())
284 {
285 vboxProblem().showModalProgressDialog (progress, iName, this);
286 if (progress.GetResultCode() == 0)
287 {
288 updateInterfaceList();
289 /* move the selection to the new created item */
290 QListBoxItem *createdNode =
291 lbHostInterface->findItem (leHostInterfaceName->text());
292 if (createdNode)
293 lbHostInterface->setCurrentItem (createdNode);
294 else
295 lbHostInterface->setCurrentItem (0);
296 }
297 else
298 vboxProblem().cannotCreateHostInterface (progress, iName, this);
299
300 }
301 else
302 vboxProblem().cannotCreateHostInterface (host, iName, this);
303
304 /* allow the started helper process to make itself the foreground window */
305 AllowSetForegroundWindow (ASFW_ANY);
306
307#endif
308}
309
310void VBoxVMNetworkSettings::hostInterfaceRemove()
311{
312#if defined Q_WS_WIN
313
314 /* allow the started helper process to make itself the foreground window */
315 AllowSetForegroundWindow (ASFW_ANY);
316
317 /* check interface name */
318 QString iName = lbHostInterface->currentText();
319 if (iName.isEmpty())
320 return;
321
322 CHost host = vboxGlobal().virtualBox().GetHost();
323 CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
324 if (host.isOk())
325 {
326 /* delete interface */
327 CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
328 if (host.isOk())
329 {
330 vboxProblem().showModalProgressDialog (progress, iName, this);
331 if (progress.GetResultCode() == 0)
332 {
333 updateInterfaceList();
334 /* move the selection to the start of the list */
335 lbHostInterface->setCurrentItem(0);
336 lbHostInterface->setSelected(0, true);
337 }
338 else
339 vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
340 }
341 }
342
343 if (!host.isOk())
344 vboxProblem().cannotRemoveHostInterface (host, iFace, this);
345#endif
346}
Note: See TracBrowser for help on using the repository browser.

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