VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/ui/VBoxVMNetworkSettings.ui.h@ 8155

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

The Big Sun Rebranding Header Change

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