VirtualBox

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

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

InnoTek -> innotek: all the headers and comments.

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