VirtualBox

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

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

hide Host Interface Networking UI on the Mac

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.8 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
32/**
33 * QDialog class reimplementation to use for adding network interface.
34 * It has one line-edit field for entering network interface's name and
35 * common dialog's ok/cancel buttons.
36 */
37#if defined Q_WS_WIN
38class VBoxAddNIDialog : public QDialog
39{
40 Q_OBJECT
41
42public:
43
44 VBoxAddNIDialog (QWidget *aParent, const QString &aIfaceName) :
45 QDialog (aParent, "VBoxAddNIDialog", true /* modal */),
46 mLeName (0)
47 {
48 setCaption (tr ("Add Host Interface"));
49 QVBoxLayout *mainLayout = new QVBoxLayout (this, 10, 10, "mainLayout");
50
51 /* Setup Input layout */
52 QHBoxLayout *inputLayout = new QHBoxLayout (mainLayout, 10, "inputLayout");
53 QLabel *lbName = new QLabel (tr ("Interface Name"), this);
54 mLeName = new QLineEdit (aIfaceName, this);
55 QWhatsThis::add (mLeName, tr ("Descriptive name of the new network interface"));
56 inputLayout->addWidget (lbName);
57 inputLayout->addWidget (mLeName);
58 connect (mLeName, SIGNAL (textChanged (const QString &)),
59 this, SLOT (validate()));
60
61 /* Setup Button layout */
62 QHBoxLayout *buttonLayout = new QHBoxLayout (mainLayout, 10, "buttonLayout");
63 mBtOk = new QPushButton (tr ("&OK"), this, "mBtOk");
64 QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
65 QPushButton *btCancel = new QPushButton (tr ("Cancel"), this, "btCancel");
66 connect (mBtOk, SIGNAL (clicked()), this, SLOT (accept()));
67 connect (btCancel, SIGNAL (clicked()), this, SLOT (reject()));
68 buttonLayout->addWidget (mBtOk);
69 buttonLayout->addItem (spacer);
70 buttonLayout->addWidget (btCancel);
71
72 /* Validate interface name field */
73 validate();
74 }
75
76 ~VBoxAddNIDialog() {}
77
78 QString getName() { return mLeName->text(); }
79
80private slots:
81
82 void validate()
83 {
84 mBtOk->setEnabled (!mLeName->text().isEmpty());
85 }
86
87private:
88
89 void showEvent (QShowEvent *aEvent)
90 {
91 setFixedHeight (height());
92 QDialog::showEvent (aEvent);
93 }
94
95 QPushButton *mBtOk;
96 QLineEdit *mLeName;
97};
98#endif
99
100
101/**
102 * VBoxVMNetworkSettings class to use as network interface setup page.
103 */
104void VBoxVMNetworkSettings::init()
105{
106 mInterfaceNumber = 0;
107 mNoInterfaces = tr ("<No suitable interfaces>");
108
109 leMACAddress->setValidator (new QRegExpValidator (QRegExp ("[0-9,A-F]{12,12}"), this));
110
111 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::NoNetworkAttachment));
112 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::NATNetworkAttachment));
113#ifndef Q_WS_MAC /* not yet on the Mac */
114 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::HostInterfaceNetworkAttachment));
115 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::InternalNetworkAttachment));
116#endif
117
118#if defined Q_WS_X11
119 leTAPDescriptor->setValidator (new QIntValidator (-1, std::numeric_limits <LONG>::max(), this));
120#else
121 /* hide unavailable settings (TAP setup and terminate apps) */
122 frmTAPSetupTerminate->setHidden (true);
123 /* disable unused interface name UI */
124 frmHostInterface_X11->setHidden (true);
125#endif
126
127#if defined Q_WS_WIN
128 /* setup iconsets */
129 pbHostAdd->setIconSet (VBoxGlobal::iconSet ("add_host_iface_16px.png",
130 "add_host_iface_disabled_16px.png"));
131 pbHostRemove->setIconSet (VBoxGlobal::iconSet ("remove_host_iface_16px.png",
132 "remove_host_iface_disabled_16px.png"));
133 /* setup languages */
134 QToolTip::add (pbHostAdd, tr ("Add"));
135 QToolTip::add (pbHostRemove, tr ("Remove"));
136 /* setup connections */
137 connect (grbEnabled, SIGNAL (toggled (bool)),
138 this, SLOT (grbEnabledToggled (bool)));
139#else
140 /* disable unused interface name UI */
141 frmHostInterface_WIN->setHidden (true);
142 /* setup iconsets */
143 pbTAPSetup->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
144 "select_file_dis_16px.png"));
145 pbTAPTerminate->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
146 "select_file_dis_16px.png"));
147#endif
148
149 /* the TAP file descriptor setting is always invisible -- currently not used
150 * (remove the relative code at all? -- just leave for some time...) */
151 frmTAPDescriptor->setHidden (true);
152
153#if defined Q_WS_MAC
154 /* no Host Interface Networking on the Mac yet */
155 grbTAP->setHidden (true);
156#endif
157}
158
159bool VBoxVMNetworkSettings::isPageValid (const QStringList &aList)
160{
161#if defined Q_WS_WIN
162 CEnums::NetworkAttachmentType type =
163 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
164
165 return !(type == CEnums::HostInterfaceNetworkAttachment &&
166 isInterfaceInvalid (aList, leHostInterfaceName->text()));
167#else
168 NOREF (aList);
169 return true;
170#endif
171}
172
173void VBoxVMNetworkSettings::loadList (const QStringList &aList)
174{
175#if defined Q_WS_WIN
176 /* save current list item name */
177 QString currentListItemName = leHostInterfaceName->text();
178 /* load current list items */
179 lbHostInterface->clearFocus();
180 lbHostInterface->clear();
181 if (aList.count())
182 lbHostInterface->insertStringList (aList);
183 else
184 lbHostInterface->insertItem (mNoInterfaces);
185 selectListItem (currentListItemName);
186 /* disable interface delete button */
187 pbHostRemove->setEnabled (!aList.isEmpty());
188#else
189 NOREF (aList);
190#endif
191}
192
193void VBoxVMNetworkSettings::getFromAdapter (const CNetworkAdapter &adapter)
194{
195 cadapter = adapter;
196
197 grbEnabled->setChecked (adapter.GetEnabled());
198
199 CEnums::NetworkAttachmentType type = adapter.GetAttachmentType();
200 cbNetworkAttachment->setCurrentItem (0);
201 for (int i = 0; i < cbNetworkAttachment->count(); i ++)
202 if (vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->text (i)) == type)
203 {
204 cbNetworkAttachment->setCurrentItem (i);
205 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
206 break;
207 }
208
209 leMACAddress->setText (adapter.GetMACAddress());
210
211 chbCableConnected->setChecked (adapter.GetCableConnected());
212
213#if defined Q_WS_WIN
214 selectListItem (adapter.GetHostInterface());
215#else
216 leHostInterface->setText (adapter.GetHostInterface());
217#endif
218
219#if defined Q_WS_X11
220 leTAPDescriptor->setText (QString::number (adapter.GetTAPFileDescriptor()));
221 leTAPSetup->setText (adapter.GetTAPSetupApplication());
222 leTAPTerminate->setText (adapter.GetTAPTerminateApplication());
223#endif
224}
225
226void VBoxVMNetworkSettings::putBackToAdapter()
227{
228 cadapter.SetEnabled (grbEnabled->isChecked());
229
230 CEnums::NetworkAttachmentType type =
231 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
232 switch (type)
233 {
234 case CEnums::NoNetworkAttachment:
235 cadapter.Detach();
236 break;
237 case CEnums::NATNetworkAttachment:
238 cadapter.AttachToNAT();
239 break;
240 case CEnums::HostInterfaceNetworkAttachment:
241 cadapter.AttachToHostInterface();
242 break;
243 case CEnums::InternalNetworkAttachment:
244 cadapter.AttachToInternalNetwork();
245 break;
246 default:
247 AssertMsgFailed (("Invalid network attachment type: %d", type));
248 break;
249 }
250
251 cadapter.SetMACAddress (leMACAddress->text());
252
253 cadapter.SetCableConnected (chbCableConnected->isChecked());
254
255 if (type == CEnums::HostInterfaceNetworkAttachment)
256 {
257#if defined Q_WS_WIN
258 if (!lbHostInterface->currentText().isEmpty())
259 cadapter.SetHostInterface (lbHostInterface->currentText());
260#else
261 QString iface = leHostInterface->text();
262 cadapter.SetHostInterface (iface.isEmpty() ? QString::null : iface);
263#endif
264#if defined Q_WS_X11
265 cadapter.SetTAPFileDescriptor (leTAPDescriptor->text().toLong());
266 QString setup = leTAPSetup->text();
267 cadapter.SetTAPSetupApplication (setup.isEmpty() ? QString::null : setup);
268 QString term = leTAPTerminate->text();
269 cadapter.SetTAPTerminateApplication (term.isEmpty() ? QString::null : term);
270#endif
271 }
272}
273
274void VBoxVMNetworkSettings::setValidator (QIWidgetValidator *aWalidator)
275{
276 mWalidator = aWalidator;
277}
278
279void VBoxVMNetworkSettings::revalidate()
280{
281 mWalidator->revalidate();
282}
283
284void VBoxVMNetworkSettings::grbEnabledToggled (bool aOn)
285{
286#if defined Q_WS_WIN
287 if (!aOn)
288 {
289 lbHostInterface->clearFocus();
290 cbNetworkAttachment->setCurrentItem (0);
291 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
292 if (lbHostInterface->selectedItem())
293 lbHostInterface->setSelected (lbHostInterface->selectedItem(), false);
294 }
295 if (lbHostInterface->currentItem() != -1)
296 lbHostInterface->setSelected (lbHostInterface->currentItem(), aOn);
297#else
298 NOREF (aOn);
299#endif
300}
301
302void VBoxVMNetworkSettings::selectListItem (const QString &aItemName)
303{
304 if (!aItemName.isEmpty())
305 {
306#if defined Q_WS_WIN
307 leHostInterfaceName->setText (aItemName);
308 QListBoxItem* adapterNode = lbHostInterface->findItem (aItemName);
309 if (adapterNode)
310 {
311 lbHostInterface->setCurrentItem (adapterNode);
312 lbHostInterface->setSelected (adapterNode, true);
313 }
314#endif
315 }
316}
317
318void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &aString)
319{
320#if defined Q_WS_WIN
321 bool enableHostIf = vboxGlobal().toNetworkAttachmentType (aString) ==
322 CEnums::HostInterfaceNetworkAttachment;
323 txHostInterface_WIN->setEnabled (enableHostIf);
324 leHostInterfaceName->setEnabled (enableHostIf);
325 lbHostInterface_highlighted (lbHostInterface->selectedItem());
326#else
327 NOREF (aString);
328#endif
329}
330
331void VBoxVMNetworkSettings::lbHostInterface_highlighted (QListBoxItem *aItem)
332{
333 if (!aItem) return;
334#if defined Q_WS_WIN
335 leHostInterfaceName->setText (leHostInterfaceName->isEnabled() ?
336 aItem->text() : QString::null);
337 if (!lbHostInterface->isSelected (aItem))
338 lbHostInterface->setSelected (aItem, true);
339#endif
340}
341
342bool VBoxVMNetworkSettings::isInterfaceInvalid (const QStringList &aList,
343 const QString &aIface)
344{
345#if defined Q_WS_WIN
346 return aList.find (aIface) == aList.end();
347#else
348 NOREF (aList);
349 NOREF (aIface);
350 return false;
351#endif
352}
353
354void VBoxVMNetworkSettings::pbGenerateMAC_clicked()
355{
356 cadapter.SetMACAddress (QString::null);
357 leMACAddress->setText (cadapter.GetMACAddress());
358}
359
360void VBoxVMNetworkSettings::pbTAPSetup_clicked()
361{
362 QString selected = QFileDialog::getOpenFileName (
363 "/",
364 QString::null,
365 this,
366 NULL,
367 tr ("Select TAP setup application"));
368
369 if (selected)
370 leTAPSetup->setText (selected);
371}
372
373void VBoxVMNetworkSettings::pbTAPTerminate_clicked()
374{
375 QString selected = QFileDialog::getOpenFileName (
376 "/",
377 QString::null,
378 this,
379 NULL,
380 tr ("Select TAP terminate application"));
381
382 if (selected)
383 leTAPTerminate->setText (selected);
384}
385
386void VBoxVMNetworkSettings::hostInterfaceAdd()
387{
388#if defined Q_WS_WIN
389
390 /* allow the started helper process to make itself the foreground window */
391 AllowSetForegroundWindow (ASFW_ANY);
392
393 /* creating add host interface dialog */
394 VBoxAddNIDialog dlg (this, lbHostInterface->currentItem() != -1 ?
395 tr ("VirtualBox Host Interface %1").arg (++mInterfaceNumber) :
396 leHostInterfaceName->text());
397 if (dlg.exec() != QDialog::Accepted)
398 return;
399 QString iName = dlg.getName();
400
401 /* create interface */
402 CHost host = vboxGlobal().virtualBox().GetHost();
403 CHostNetworkInterface iFace;
404 CProgress progress = host.CreateHostNetworkInterface (iName, iFace);
405 if (host.isOk())
406 {
407 vboxProblem().showModalProgressDialog (progress, iName, this);
408 if (progress.GetResultCode() == 0)
409 {
410 /* add&select newly created created interface */
411 delete lbHostInterface->findItem (mNoInterfaces);
412 lbHostInterface->insertItem (iName);
413 selectListItem (iName);
414 emit listChanged (this);
415 }
416 else
417 vboxProblem().cannotCreateHostInterface (progress, iName, this);
418 }
419 else
420 vboxProblem().cannotCreateHostInterface (host, iName, this);
421
422 /* allow the started helper process to make itself the foreground window */
423 AllowSetForegroundWindow (ASFW_ANY);
424
425#endif
426}
427
428void VBoxVMNetworkSettings::hostInterfaceRemove()
429{
430#if defined Q_WS_WIN
431
432 /* allow the started helper process to make itself the foreground window */
433 AllowSetForegroundWindow (ASFW_ANY);
434
435 /* check interface name */
436 QString iName = lbHostInterface->currentText();
437 if (iName.isEmpty())
438 return;
439
440 /* asking user about deleting selected network interface */
441 int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question,
442 tr ("<p>Do you want to remove the selected host network interface "
443 "<nobr><b>%1</b>?</nobr></p>"
444 "<p><b>Note:</b> This interface may be in use by one or more "
445 "network adapters of this or another VM. After it is removed, these "
446 "adapters will no longer work until you correct their settings by "
447 "either choosing a differnet interface name or a different adapter "
448 "attachment type.</p>").arg (iName),
449 0, /* autoConfirmId */
450 QIMessageBox::Ok | QIMessageBox::Default,
451 QIMessageBox::Cancel | QIMessageBox::Escape);
452 if (delNetIface == QIMessageBox::Cancel)
453 return;
454
455 CHost host = vboxGlobal().virtualBox().GetHost();
456 CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
457 if (host.isOk())
458 {
459 /* delete interface */
460 CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
461 if (host.isOk())
462 {
463 vboxProblem().showModalProgressDialog (progress, iName, this);
464 if (progress.GetResultCode() == 0)
465 {
466 if (lbHostInterface->count() == 1)
467 lbHostInterface->insertItem (mNoInterfaces);
468 delete lbHostInterface->findItem (iName);
469 emit listChanged (this);
470 }
471 else
472 vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
473 }
474 }
475
476 if (!host.isOk())
477 vboxProblem().cannotRemoveHostInterface (host, iFace, this);
478#endif
479}
480
481#if defined Q_WS_WIN
482#include "VBoxVMNetworkSettings.ui.moc"
483#endif
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