VirtualBox

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

最後變更 在這個檔案從5999是 5999,由 vboxsync 提交於 17 年 前

The Giant CDDL Dual-License Header Change.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette