VirtualBox

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

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

82543GC support is ready. RX crit section removed.

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