VirtualBox

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

Last change on this file since 4862 was 4324, checked in by vboxsync, 18 years ago

Main: Improved serial port API (mostly spelling);
FE/Qt: Improved serial port UI (spelling and duplicate handling).

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