VirtualBox

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

Last change on this file since 10759 was 10759, checked in by vboxsync, 17 years ago

Quickly re-enabled the HIF and internal networking panels on the mac. (the HIF bit needs some fixing I guess, but later.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.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-2007 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
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 cbAdapterType->insertItem (vboxGlobal().toString (KNetworkAdapterType_Am79C970A));
35 cbAdapterType->insertItem (vboxGlobal().toString (KNetworkAdapterType_Am79C973));
36#ifdef VBOX_WITH_E1000
37 cbAdapterType->insertItem (vboxGlobal().toString (KNetworkAdapterType_I82540EM));
38 cbAdapterType->insertItem (vboxGlobal().toString (KNetworkAdapterType_I82543GC));
39#endif
40
41 leMACAddress->setValidator (new QRegExpValidator
42 (QRegExp ("[0-9A-Fa-f][02468ACEace][0-9A-Fa-f]{10}"), this));
43
44 cbNetworkAttachment->insertItem (vboxGlobal().toString (KNetworkAttachmentType_Null));
45 cbNetworkAttachment->insertItem (vboxGlobal().toString (KNetworkAttachmentType_NAT));
46 cbNetworkAttachment->insertItem (vboxGlobal().toString (KNetworkAttachmentType_HostInterface));
47 cbNetworkAttachment->insertItem (vboxGlobal().toString (KNetworkAttachmentType_Internal));
48
49#if defined Q_WS_X11
50 leTAPDescriptor->setValidator (new QIntValidator (-1, std::numeric_limits <LONG>::max(), this));
51#else
52 /* hide unavailable settings (TAP setup and terminate apps) */
53 frmTAPSetupTerminate->setHidden (true);
54 /* disable unused interface name UI */
55 frmHostInterface_X11->setHidden (true);
56#endif
57
58#if defined Q_WS_WIN
59 /* disable unused interface name UI */
60 grbTAP->setHidden (true);
61 /* Make the line editor of the editable combobox read-only to disable
62 * modifications by the user. The combobox itself remains "editable" to
63 * allow for setting text missing in the drop-down list. */
64 cbHostInterfaceName->lineEdit()->setReadOnly (true);
65
66 connect (grbEnabled, SIGNAL (toggled (bool)),
67 this, SLOT (grbEnabledToggled (bool)));
68#else
69 /* disable unused interface name UI */
70 txHostInterface_WIN->setHidden (true);
71 cbHostInterfaceName->setHidden (true);
72 /* setup iconsets */
73 pbTAPSetup->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
74 "select_file_dis_16px.png"));
75 pbTAPTerminate->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
76 "select_file_dis_16px.png"));
77#endif
78
79 /* the TAP file descriptor setting is always invisible -- currently not used
80 * (remove the relative code at all? -- just leave for some time...) */
81 frmTAPDescriptor->setHidden (true);
82
83#if defined Q_WS_MAC /** @todo hif on mac */
84 /* no Host Interface Networking on the Mac yet */
85 grbTAP->setHidden (true);
86#endif
87}
88
89VBoxVMNetworkSettings::CheckPageResult
90VBoxVMNetworkSettings::checkPage (const QStringList &aList)
91{
92 KNetworkAttachmentType type =
93 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
94 if (!grbEnabled->isChecked())
95 return CheckPage_Ok;
96 else
97#if defined Q_WS_WIN
98 if (type == KNetworkAttachmentType_HostInterface &&
99 isInterfaceInvalid (aList, cbHostInterfaceName->currentText()))
100 return CheckPage_InvalidInterface;
101 else
102#else
103 NOREF (aList);
104#endif
105 if (type == KNetworkAttachmentType_Internal &&
106 cbInternalNetworkName->currentText().isEmpty())
107 return CheckPage_NoNetworkName;
108 else
109 return CheckPage_Ok;
110}
111
112void VBoxVMNetworkSettings::loadInterfaceList (const QStringList &aList,
113 const QString &aNillItem)
114{
115#if defined Q_WS_WIN
116 /* save current list item name */
117 QString currentListItemName = cbHostInterfaceName->currentText();
118 /* clear current list */
119 cbHostInterfaceName->clear();
120 /* load current list items */
121 if (aList.count())
122 cbHostInterfaceName->insertStringList (aList);
123 else
124 cbHostInterfaceName->setCurrentText (aNillItem);
125
126 if (currentListItemName.isEmpty() || currentListItemName == aNillItem)
127 cbHostInterfaceName->setCurrentItem (0);
128 else
129 cbHostInterfaceName->setCurrentText (currentListItemName);
130#else
131 NOREF (aList);
132 NOREF (aNillItem);
133#endif
134}
135
136void VBoxVMNetworkSettings::loadNetworksList (const QStringList &aList)
137{
138 QString curText = cbInternalNetworkName->currentText();
139 cbInternalNetworkName->clear();
140 cbInternalNetworkName->clearEdit();
141 cbInternalNetworkName->insertStringList (aList);
142 cbInternalNetworkName->setCurrentText (curText);
143}
144
145void VBoxVMNetworkSettings::getFromAdapter (const CNetworkAdapter &adapter)
146{
147 cadapter = adapter;
148
149 grbEnabled->setChecked (adapter.GetEnabled());
150
151 cbAdapterType->setCurrentText (vboxGlobal().
152 toString (adapter.GetAdapterType()));
153
154 KNetworkAttachmentType type = adapter.GetAttachmentType();
155 cbNetworkAttachment->setCurrentItem (0);
156 for (int i = 0; i < cbNetworkAttachment->count(); i ++)
157 if (vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->text (i)) == type)
158 {
159 cbNetworkAttachment->setCurrentItem (i);
160 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
161 break;
162 }
163
164 leMACAddress->setText (adapter.GetMACAddress());
165
166 chbCableConnected->setChecked (adapter.GetCableConnected());
167
168#if defined Q_WS_WIN
169 if (!adapter.GetHostInterface().isEmpty())
170 cbHostInterfaceName->setCurrentText (adapter.GetHostInterface());
171#else
172 leHostInterface->setText (adapter.GetHostInterface());
173#endif
174 cbInternalNetworkName->setCurrentText (adapter.GetInternalNetwork());
175
176#if defined Q_WS_X11
177 leTAPDescriptor->setText (QString::number (adapter.GetTAPFileDescriptor()));
178 leTAPSetup->setText (adapter.GetTAPSetupApplication());
179 leTAPTerminate->setText (adapter.GetTAPTerminateApplication());
180#endif
181}
182
183void VBoxVMNetworkSettings::putBackToAdapter()
184{
185 cadapter.SetEnabled (grbEnabled->isChecked());
186
187 cadapter.SetAdapterType (vboxGlobal().
188 toNetworkAdapterType (cbAdapterType->currentText()));
189
190 KNetworkAttachmentType type =
191 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
192 switch (type)
193 {
194 case KNetworkAttachmentType_Null:
195 cadapter.Detach();
196 break;
197 case KNetworkAttachmentType_NAT:
198 cadapter.AttachToNAT();
199 break;
200 case KNetworkAttachmentType_HostInterface:
201 cadapter.AttachToHostInterface();
202 break;
203 case KNetworkAttachmentType_Internal:
204 cadapter.AttachToInternalNetwork();
205 break;
206 default:
207 AssertMsgFailed (("Invalid network attachment type: %d", type));
208 break;
209 }
210
211 cadapter.SetMACAddress (leMACAddress->text());
212
213 cadapter.SetCableConnected (chbCableConnected->isChecked());
214
215 if (type == KNetworkAttachmentType_HostInterface)
216 {
217#if defined Q_WS_WIN
218 if (!cbHostInterfaceName->currentText().isEmpty())
219 cadapter.SetHostInterface (cbHostInterfaceName->currentText());
220#else
221 QString iface = leHostInterface->text();
222 cadapter.SetHostInterface (iface.isEmpty() ? QString::null : iface);
223#endif
224#if defined Q_WS_X11
225 cadapter.SetTAPFileDescriptor (leTAPDescriptor->text().toLong());
226 QString setup = leTAPSetup->text();
227 cadapter.SetTAPSetupApplication (setup.isEmpty() ? QString::null : setup);
228 QString term = leTAPTerminate->text();
229 cadapter.SetTAPTerminateApplication (term.isEmpty() ? QString::null : term);
230#endif
231 }
232 else if (type == KNetworkAttachmentType_Internal)
233 cadapter.SetInternalNetwork (cbInternalNetworkName->currentText());
234}
235
236void VBoxVMNetworkSettings::setValidator (QIWidgetValidator *aWalidator)
237{
238 mWalidator = aWalidator;
239}
240
241void VBoxVMNetworkSettings::revalidate()
242{
243 mWalidator->revalidate();
244}
245
246void VBoxVMNetworkSettings::grbEnabledToggled (bool aOn)
247{
248#if defined Q_WS_WIN
249 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
250#else
251 NOREF (aOn);
252#endif
253}
254
255void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &aString)
256{
257 bool enableHostIf = grbEnabled->isChecked() &&
258 vboxGlobal().toNetworkAttachmentType (aString) ==
259 KNetworkAttachmentType_HostInterface;
260 bool enableIntNet = grbEnabled->isChecked() &&
261 vboxGlobal().toNetworkAttachmentType (aString) ==
262 KNetworkAttachmentType_Internal;
263#if defined Q_WS_WIN
264 txHostInterface_WIN->setEnabled (enableHostIf);
265 cbHostInterfaceName->setEnabled (enableHostIf);
266#else
267 grbTAP->setEnabled (enableHostIf);
268#endif
269 txInternalNetwork->setEnabled (enableIntNet);
270 cbInternalNetworkName->setEnabled (enableIntNet);
271}
272
273bool VBoxVMNetworkSettings::isInterfaceInvalid (const QStringList &aList,
274 const QString &aIface)
275{
276#if defined Q_WS_WIN
277 return aList.find (aIface) == aList.end();
278#else
279 NOREF (aList);
280 NOREF (aIface);
281 return false;
282#endif
283}
284
285void VBoxVMNetworkSettings::pbGenerateMAC_clicked()
286{
287 cadapter.SetMACAddress (QString::null);
288 leMACAddress->setText (cadapter.GetMACAddress());
289}
290
291void VBoxVMNetworkSettings::pbTAPSetup_clicked()
292{
293 QString selected = QFileDialog::getOpenFileName (
294 "/",
295 QString::null,
296 this,
297 NULL,
298 tr ("Select TAP setup application"));
299
300 if (selected)
301 leTAPSetup->setText (selected);
302}
303
304void VBoxVMNetworkSettings::pbTAPTerminate_clicked()
305{
306 QString selected = QFileDialog::getOpenFileName (
307 "/",
308 QString::null,
309 this,
310 NULL,
311 tr ("Select TAP terminate application"));
312
313 if (selected)
314 leTAPTerminate->setText (selected);
315}
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