VirtualBox

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

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

Network Interfaces Settings rework:

  1. Network Interfaces List with Add/Remove interface buttons is currently accessible in any “attached to” adapter state (not only in Attached to Host Interface case).
  2. Add/Remove keys changed to auto-raise tool-buttons. These keys are currently situated at the right vertical tool-bar near the interface’s list.
  3. Add Interface functionality is done through additional modal “Add Host Interface” Dialog.
  4. Remove Interface functionality has additional message-box with Ok/Cancel question about removing selected interface.
  5. Synchronization between all the adaptors interface’s lists done for add/remove functionality.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.3 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 ("Interface Name", this);
54 mLeName = new QLineEdit (aIfaceName, this);
55 QWhatsThis::add (mLeName, tr ("Enter name for the interface to be created"));
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 ("OK", this, "btOk");
64 QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
65 QPushButton *btCancel = new QPushButton ("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 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::HostInterfaceNetworkAttachment));
114 cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::InternalNetworkAttachment));
115
116#if defined Q_WS_X11
117 leTAPDescriptor->setValidator (new QIntValidator (-1, std::numeric_limits <LONG>::max(), this));
118#else
119 /* hide unavailable settings (TAP setup and terminate apps) */
120 frmTAPSetupTerminate->setHidden (true);
121#endif
122
123#if defined Q_WS_WIN
124 /* disable unused interface name UI */
125 frmHostInterface_X11->setHidden (true);
126 /* setup iconsets */
127 pbHostAdd->setIconSet (VBoxGlobal::iconSet ("add_host_iface_16px.png",
128 "add_host_iface_disabled_16px.png"));
129 pbHostRemove->setIconSet (VBoxGlobal::iconSet ("remove_host_iface_16px.png",
130 "remove_host_iface_disabled_16px.png"));
131 connect (grbEnabled, SIGNAL (toggled (bool)),
132 this, SLOT (grbEnabledToggled (bool)));
133#else
134 /* disable unused interface name UI */
135 frmHostInterface_WIN->setHidden (true);
136 /* setup iconsets */
137 pbTAPSetup->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
138 "select_file_dis_16px.png"));
139 pbTAPTerminate->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
140 "select_file_dis_16px.png"));
141#endif
142
143 /* the TAP file descriptor setting is always invisible -- currently not used
144 * (remove the relative code at all? -- just leave for some time...) */
145 frmTAPDescriptor->setHidden (true);
146}
147
148bool VBoxVMNetworkSettings::isPageValid (const QStringList &aList)
149{
150#if defined Q_WS_WIN
151 CEnums::NetworkAttachmentType type =
152 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
153
154 return !(type == CEnums::HostInterfaceNetworkAttachment &&
155 isInterfaceInvalid (aList, leHostInterfaceName->text()));
156#else
157 NOREF (aList);
158 return true;
159#endif
160}
161
162void VBoxVMNetworkSettings::loadList (const QStringList &aList)
163{
164#if defined Q_WS_WIN
165 /* save current list item name */
166 QString currentListItemName = leHostInterfaceName->text();
167 /* load current list items */
168 lbHostInterface->clearFocus();
169 lbHostInterface->clear();
170 if (aList.count())
171 lbHostInterface->insertStringList (aList);
172 else
173 lbHostInterface->insertItem (mNoInterfaces);
174 selectListItem (currentListItemName);
175 /* disable interface delete button */
176 pbHostRemove->setEnabled (!aList.isEmpty());
177#else
178 NOREF (aList);
179#endif
180}
181
182void VBoxVMNetworkSettings::getFromAdapter (const CNetworkAdapter &adapter)
183{
184 cadapter = adapter;
185
186 grbEnabled->setChecked (adapter.GetEnabled());
187
188 CEnums::NetworkAttachmentType type = adapter.GetAttachmentType();
189 cbNetworkAttachment->setCurrentItem (0);
190 for (int i = 0; i < cbNetworkAttachment->count(); i ++)
191 if (vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->text (i)) == type)
192 {
193 cbNetworkAttachment->setCurrentItem (i);
194 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
195 break;
196 }
197
198 leMACAddress->setText (adapter.GetMACAddress());
199
200 chbCableConnected->setChecked (adapter.GetCableConnected());
201
202#if defined Q_WS_WIN
203 selectListItem (adapter.GetHostInterface());
204#else
205 leHostInterface->setText (adapter.GetHostInterface());
206#endif
207
208#if defined Q_WS_X11
209 leTAPDescriptor->setText (QString::number (adapter.GetTAPFileDescriptor()));
210 leTAPSetup->setText (adapter.GetTAPSetupApplication());
211 leTAPTerminate->setText (adapter.GetTAPTerminateApplication());
212#endif
213}
214
215void VBoxVMNetworkSettings::putBackToAdapter()
216{
217 cadapter.SetEnabled (grbEnabled->isChecked());
218
219 CEnums::NetworkAttachmentType type =
220 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
221 switch (type)
222 {
223 case CEnums::NoNetworkAttachment:
224 cadapter.Detach();
225 break;
226 case CEnums::NATNetworkAttachment:
227 cadapter.AttachToNAT();
228 break;
229 case CEnums::HostInterfaceNetworkAttachment:
230 cadapter.AttachToHostInterface();
231 break;
232 case CEnums::InternalNetworkAttachment:
233 cadapter.AttachToInternalNetwork();
234 break;
235 default:
236 AssertMsgFailed (("Invalid network attachment type: %d", type));
237 break;
238 }
239
240 cadapter.SetMACAddress (leMACAddress->text());
241
242 cadapter.SetCableConnected (chbCableConnected->isChecked());
243
244 if (type == CEnums::HostInterfaceNetworkAttachment)
245 {
246#if defined Q_WS_WIN
247 if (!lbHostInterface->currentText().isEmpty())
248 cadapter.SetHostInterface (lbHostInterface->currentText());
249#else
250 QString iface = leHostInterface->text();
251 cadapter.SetHostInterface (iface.isEmpty() ? QString::null : iface);
252#endif
253#if defined Q_WS_X11
254 cadapter.SetTAPFileDescriptor (leTAPDescriptor->text().toLong());
255 QString setup = leTAPSetup->text();
256 cadapter.SetTAPSetupApplication (setup.isEmpty() ? QString::null : setup);
257 QString term = leTAPTerminate->text();
258 cadapter.SetTAPTerminateApplication (term.isEmpty() ? QString::null : term);
259#endif
260 }
261}
262
263void VBoxVMNetworkSettings::setValidator (QIWidgetValidator *aWalidator)
264{
265 mWalidator = aWalidator;
266}
267
268void VBoxVMNetworkSettings::revalidate()
269{
270 mWalidator->revalidate();
271}
272
273void VBoxVMNetworkSettings::grbEnabledToggled (bool aOn)
274{
275#if defined Q_WS_WIN
276 if (!aOn)
277 {
278 lbHostInterface->clearFocus();
279 cbNetworkAttachment->setCurrentItem (0);
280 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
281 if (lbHostInterface->selectedItem())
282 lbHostInterface->setSelected (lbHostInterface->selectedItem(), false);
283 }
284 if (lbHostInterface->currentItem() != -1)
285 lbHostInterface->setSelected (lbHostInterface->currentItem(), aOn);
286#else
287 NOREF (aOn);
288#endif
289}
290
291void VBoxVMNetworkSettings::selectListItem (const QString &aItemName)
292{
293 if (!aItemName.isEmpty())
294 {
295#if defined Q_WS_WIN
296 leHostInterfaceName->setText (aItemName);
297 QListBoxItem* adapterNode = lbHostInterface->findItem (aItemName);
298 if (adapterNode)
299 {
300 lbHostInterface->setCurrentItem (adapterNode);
301 lbHostInterface->setSelected (adapterNode, true);
302 }
303#endif
304 }
305}
306
307void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &aString)
308{
309#if defined Q_WS_WIN
310 bool enableHostIf = vboxGlobal().toNetworkAttachmentType (aString) ==
311 CEnums::HostInterfaceNetworkAttachment;
312 txHostInterface_WIN->setEnabled (enableHostIf);
313 leHostInterfaceName->setEnabled (enableHostIf);
314 lbHostInterface_highlighted (lbHostInterface->selectedItem());
315#else
316 NOREF (aString);
317#endif
318}
319
320void VBoxVMNetworkSettings::lbHostInterface_highlighted (QListBoxItem *aItem)
321{
322 if (!aItem) return;
323#if defined Q_WS_WIN
324 leHostInterfaceName->setText (leHostInterfaceName->isEnabled() ?
325 aItem->text() : QString::null);
326 if (!lbHostInterface->isSelected (aItem))
327 lbHostInterface->setSelected (aItem, true);
328#endif
329}
330
331bool VBoxVMNetworkSettings::isInterfaceInvalid (const QStringList &aList,
332 const QString &aIface)
333{
334#if defined Q_WS_WIN
335 return aList.find (aIface) == aList.end();
336#else
337 NOREF (aList);
338 NOREF (aIface);
339 return false;
340#endif
341}
342
343void VBoxVMNetworkSettings::pbGenerateMAC_clicked()
344{
345 cadapter.SetMACAddress (QString::null);
346 leMACAddress->setText (cadapter.GetMACAddress());
347}
348
349void VBoxVMNetworkSettings::pbTAPSetup_clicked()
350{
351 QString selected = QFileDialog::getOpenFileName (
352 "/",
353 QString::null,
354 this,
355 NULL,
356 tr ("Select TAP setup application"));
357
358 if (selected)
359 leTAPSetup->setText (selected);
360}
361
362void VBoxVMNetworkSettings::pbTAPTerminate_clicked()
363{
364 QString selected = QFileDialog::getOpenFileName (
365 "/",
366 QString::null,
367 this,
368 NULL,
369 tr ("Select TAP terminate application"));
370
371 if (selected)
372 leTAPTerminate->setText (selected);
373}
374
375void VBoxVMNetworkSettings::hostInterfaceAdd()
376{
377#if defined Q_WS_WIN
378
379 /* allow the started helper process to make itself the foreground window */
380 AllowSetForegroundWindow (ASFW_ANY);
381
382 /* creating add host interface dialog */
383 VBoxAddNIDialog dlg (this, lbHostInterface->currentItem() != -1 ?
384 tr ("Host Interface %1").arg (++mInterfaceNumber) :
385 leHostInterfaceName->text());
386 if (dlg.exec() != QDialog::Accepted)
387 return;
388 QString iName = dlg.getName();
389
390 /* create interface */
391 CHost host = vboxGlobal().virtualBox().GetHost();
392 CHostNetworkInterface iFace;
393 CProgress progress = host.CreateHostNetworkInterface (iName, iFace);
394 if (host.isOk())
395 {
396 vboxProblem().showModalProgressDialog (progress, iName, this);
397 if (progress.GetResultCode() == 0)
398 {
399 /* add&select newly created created interface */
400 delete lbHostInterface->findItem (mNoInterfaces);
401 lbHostInterface->insertItem (iName);
402 selectListItem (iName);
403 emit listChanged (this);
404 }
405 else
406 vboxProblem().cannotCreateHostInterface (progress, iName, this);
407 }
408 else
409 vboxProblem().cannotCreateHostInterface (host, iName, this);
410
411 /* allow the started helper process to make itself the foreground window */
412 AllowSetForegroundWindow (ASFW_ANY);
413
414#endif
415}
416
417void VBoxVMNetworkSettings::hostInterfaceRemove()
418{
419#if defined Q_WS_WIN
420
421 /* allow the started helper process to make itself the foreground window */
422 AllowSetForegroundWindow (ASFW_ANY);
423
424 /* check interface name */
425 QString iName = lbHostInterface->currentText();
426 if (iName.isEmpty())
427 return;
428
429 /* asking user about deleting selected network interface */
430 int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question,
431 tr ("<p>Do you want to remove selected network interface "
432 "<nobr><b>%1</b>?</nobr></p>"
433 "<p>If this interface is currently selected you should "
434 "apply VM settings changes to avoid VM using of non-existing "
435 "interface</p>").arg (iName),
436 0, /* autoConfirmId */
437 QIMessageBox::Ok | QIMessageBox::Default,
438 QIMessageBox::Cancel | QIMessageBox::Escape);
439 if (delNetIface == QIMessageBox::Cancel)
440 return;
441
442 CHost host = vboxGlobal().virtualBox().GetHost();
443 CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
444 if (host.isOk())
445 {
446 /* delete interface */
447 CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
448 if (host.isOk())
449 {
450 vboxProblem().showModalProgressDialog (progress, iName, this);
451 if (progress.GetResultCode() == 0)
452 {
453 if (lbHostInterface->count() == 1)
454 lbHostInterface->insertItem (mNoInterfaces);
455 delete lbHostInterface->findItem (iName);
456 emit listChanged (this);
457 }
458 else
459 vboxProblem().cannotRemoveHostInterface (progress, iFace, this);
460 }
461 }
462
463 if (!host.isOk())
464 vboxProblem().cannotRemoveHostInterface (host, iFace, this);
465#endif
466}
467
468#if defined Q_WS_WIN
469#include "VBoxVMNetworkSettings.ui.moc"
470#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