VirtualBox

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

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

FE/Qt: Network UI spelling.

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