VirtualBox

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

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

export to OSE again

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 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.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 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 // setup validation
35 // ----------------------------------------------------------------------
36
37 leMACAddress->setValidator (new QRegExpValidator (QRegExp ("[0-9,A-F,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
56 grbTAP->setEnabled (false); // initially disabled
57
58#if defined Q_WS_WIN
59 // disable unused interface name UI
60 frmHostInterface_X11->setHidden (true);
61 // setup iconsets -- qdesigner is not capable...
62 pbHostAdd->setIconSet (VBoxGlobal::iconSet ("nw_16px.png",
63 "nw_disabled_16px.png"));
64 pbHostRemove->setIconSet (VBoxGlobal::iconSet ("delete_16px.png",
65 "delete_dis_16px.png"));
66#else
67 // disable unused interface name UI
68 frmHostInterface_WIN->setHidden (true);
69 // setup iconsets -- qdesigner is not capable...
70 pbTAPSetup->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
71 "select_file_dis_16px.png"));
72 pbTAPTerminate->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
73 "select_file_dis_16px.png"));
74#endif
75
76#if !defined Q_WS_X11
77 // hide unavailable settings (TAP setup and terminate apps)
78 frmTAPSetupTerminate->setHidden (true);
79#endif
80
81 // the TAP file descriptor setting is always invisible -- currently not used
82 // (remove the relative code at all? -- just leave for some time...)
83 frmTAPDescriptor->setHidden (true);
84}
85
86void VBoxVMNetworkSettings::updateInterfaceList()
87{
88#if defined Q_WS_WIN
89 /* clear lists */
90 networkInterfaceList.clear();
91 lbHostInterface->clear();
92 /* read a QStringList of interface names */
93 CHostNetworkInterfaceEnumerator en =
94 vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
95 while (en.HasMore())
96 networkInterfaceList += en.GetNext().GetName();
97 /* setup a list of interface names */
98 if (networkInterfaceList.count())
99 lbHostInterface->insertStringList (networkInterfaceList);
100 else
101 lbHostInterface->insertItem (NoSuitableIfaces);
102 /* disable interface delete button */
103 pbHostRemove->setEnabled (!networkInterfaceList.isEmpty());
104#endif
105}
106
107void VBoxVMNetworkSettings::getFromAdapter (const CNetworkAdapter &adapter)
108{
109 cadapter = adapter;
110
111 grbEnabled->setChecked (adapter.GetEnabled());
112
113 CEnums::NetworkAttachmentType type = adapter.GetAttachmentType();
114 cbNetworkAttachment->setCurrentItem (0);
115 for (int i = 0; i < cbNetworkAttachment->count(); i ++)
116 if (vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->text (i)) == type)
117 {
118 cbNetworkAttachment->setCurrentItem (i);
119 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
120 break;
121 }
122
123 leMACAddress->setText (adapter.GetMACAddress());
124
125 chbCableConnected->setChecked (adapter.GetCableConnected());
126
127#if defined Q_WS_WIN
128 if (adapter.GetHostInterface().isEmpty())
129 lbHostInterface->setCurrentItem (0);
130 else
131 {
132 QListBoxItem* adapterNode = lbHostInterface->findItem(adapter.GetHostInterface());
133 if (adapterNode)
134 lbHostInterface->setCurrentItem(adapterNode);
135 }
136#else
137 leHostInterface->setText (adapter.GetHostInterface());
138#endif
139
140#if defined Q_WS_X11
141 leTAPDescriptor->setText (QString::number(adapter.GetTAPFileDescriptor()));
142 leTAPSetup->setText (adapter.GetTAPSetupApplication());
143 leTAPTerminate->setText (adapter.GetTAPTerminateApplication());
144#endif
145}
146
147void VBoxVMNetworkSettings::putBackToAdapter()
148{
149 cadapter.SetEnabled (grbEnabled->isChecked());
150
151 CEnums::NetworkAttachmentType type =
152 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
153 switch (type)
154 {
155 case CEnums::NoNetworkAttachment:
156 cadapter.Detach();
157 break;
158 case CEnums::NATNetworkAttachment:
159 cadapter.AttachToNAT();
160 break;
161 case CEnums::HostInterfaceNetworkAttachment:
162 cadapter.AttachToHostInterface();
163 break;
164 default:
165 AssertMsgFailed (("Invalid network attachment type: %d", type));
166 break;
167 }
168
169 cadapter.SetMACAddress (leMACAddress->text());
170
171 cadapter.SetCableConnected (chbCableConnected->isChecked());
172
173 if (type == CEnums::HostInterfaceNetworkAttachment)
174 {
175#if defined Q_WS_WIN
176 if (!lbHostInterface->currentText().isEmpty())
177 cadapter.SetHostInterface (lbHostInterface->currentText());
178#else
179 QString iface = leHostInterface->text();
180 cadapter.SetHostInterface (iface.isEmpty() ? QString::null : iface);
181#endif
182#if defined Q_WS_X11
183 cadapter.SetTAPFileDescriptor (leTAPDescriptor->text().toLong());
184 QString setup = leTAPSetup->text();
185 cadapter.SetTAPSetupApplication (setup.isEmpty() ? QString::null : setup);
186 QString term = leTAPTerminate->text();
187 cadapter.SetTAPTerminateApplication (term.isEmpty() ? QString::null : term);
188#endif
189 }
190}
191
192void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &string)
193{
194 grbTAP->setEnabled (vboxGlobal().toNetworkAttachmentType (string) ==
195 CEnums::HostInterfaceNetworkAttachment);
196}
197
198void VBoxVMNetworkSettings::lbHostInterface_highlighted(QListBoxItem* /*item*/)
199{
200 leHostInterfaceName->clear();
201}
202
203bool VBoxVMNetworkSettings::checkNetworkInterface (QString ni)
204{
205#if defined Q_WS_WIN
206 return networkInterfaceList.find (ni) != networkInterfaceList.end() ? 1 : 0;
207#else
208 NOREF(ni);
209 return true;
210#endif
211}
212
213void VBoxVMNetworkSettings::pbGenerateMAC_clicked()
214{
215 cadapter.SetMACAddress (QString::null);
216 leMACAddress->setText (cadapter.GetMACAddress());
217}
218
219void VBoxVMNetworkSettings::pbTAPSetup_clicked()
220{
221// QFileDialog dlg ("/", QString::null, this);
222// dlg.setMode (QFileDialog::ExistingFile);
223// dlg.setViewMode (QFileDialog::List);
224// dlg.setCaption (tr ("Select TAP setup application"));
225// if (dlg.exec() == QDialog::Accepted)
226// leTAPSetup->setText (dlg.selectedFile());
227
228 QString selected = QFileDialog::getOpenFileName (
229 "/",
230 QString::null,
231 this,
232 NULL,
233 tr ("Select TAP setup application"));
234
235 if (selected)
236 leTAPSetup->setText (selected);
237}
238
239void VBoxVMNetworkSettings::pbTAPTerminate_clicked()
240{
241// QFileDialog dlg ("/", QString::null, this);
242// dlg.setMode (QFileDialog::ExistingFile);
243// dlg.setViewMode (QFileDialog::List);
244// dlg.setCaption (tr ("Select TAP terminate application"));
245// if (dlg.exec() == QDialog::Accepted)
246// leTAPTerminate->setText (dlg.selectedFile());
247
248 QString selected = QFileDialog::getOpenFileName (
249 "/",
250 QString::null,
251 this,
252 NULL,
253 tr ("Select TAP terminate application"));
254
255 if (selected)
256 leTAPTerminate->setText (selected);
257}
258
259void VBoxVMNetworkSettings::hostInterfaceAdd()
260{
261#if defined Q_WS_WIN
262
263 /* allow the started helper process to make itself the foreground window */
264 AllowSetForegroundWindow (ASFW_ANY);
265
266 /* check interface name */
267 QString iName = leHostInterfaceName->text();
268 if (iName.isEmpty() || iName == NoSuitableIfaces)
269 {
270 vboxProblem().message (this, VBoxProblemReporter::Error,
271 tr ("Host network interface name cannot be empty"));
272 return;
273 }
274
275 /* create interface */
276 CHost host = vboxGlobal().virtualBox().GetHost();
277 CHostNetworkInterface iFace;
278 CProgress progress = host.CreateHostNetworkInterface (iName, iFace);
279 if (host.isOk())
280 {
281 vboxProblem().showModalProgressDialog (progress, iName, this);
282 if (progress.GetResultCode() == 0)
283 {
284 updateInterfaceList();
285 /* move the selection to the new created item */
286 QListBoxItem *createdNode =
287 lbHostInterface->findItem (leHostInterfaceName->text());
288 if (createdNode)
289 lbHostInterface->setCurrentItem (createdNode);
290 else
291 lbHostInterface->setCurrentItem (0);
292 }
293 else
294 vboxProblem().cannotCreateHostInterface (progress, iName, this);
295
296 }
297 else
298 vboxProblem().cannotCreateHostInterface (host, iName, this);
299
300 /* allow the started helper process to make itself the foreground window */
301 AllowSetForegroundWindow (ASFW_ANY);
302
303#endif
304}
305
306void VBoxVMNetworkSettings::hostInterfaceRemove()
307{
308#if defined Q_WS_WIN
309
310 /* allow the started helper process to make itself the foreground window */
311 AllowSetForegroundWindow (ASFW_ANY);
312
313 /* check interface name */
314 QString iName = lbHostInterface->currentText();
315 if (iName.isEmpty())
316 return;
317
318 CHost host = vboxGlobal().virtualBox().GetHost();
319 CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
320 if (host.isOk())
321 {
322 /* delete interface */
323 CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
324 if (host.isOk())
325 {
326 vboxProblem().showModalProgressDialog (progress, iName, this);
327 if (progress.GetResultCode() == 0)
328 {
329 updateInterfaceList();
330 /* move the selection to the start of the list */
331 lbHostInterface->setCurrentItem(0);
332 lbHostInterface->setSelected(0, true);
333 }
334 else
335 vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
336 }
337 }
338
339 if (!host.isOk())
340 vboxProblem().cannotRemoveHostInterface (host, iFace, this);
341#endif
342}
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