VirtualBox

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

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

1905: Add GUI support for internal network name:

Done (checked under win&lin).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 10.6 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 grbIntNet->setHidden (true);
53 connect (grbEnabled, SIGNAL (toggled (bool)),
54 this, SLOT (grbEnabledToggled (bool)));
55#else
56 /* disable unused interface name UI */
57 txHostInterface_WIN->setHidden (true);
58 cbHostInterfaceName->setHidden (true);
59 txInternalNetwork_WIN->setHidden (true);
60 cbInternalNetworkName_WIN->setHidden (true);
61 /* setup iconsets */
62 pbTAPSetup->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
63 "select_file_dis_16px.png"));
64 pbTAPTerminate->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
65 "select_file_dis_16px.png"));
66#endif
67
68 /* the TAP file descriptor setting is always invisible -- currently not used
69 * (remove the relative code at all? -- just leave for some time...) */
70 frmTAPDescriptor->setHidden (true);
71
72#if defined Q_WS_MAC
73 /* no Host Interface Networking on the Mac yet */
74 grbTAP->setHidden (true);
75#endif
76}
77
78int VBoxVMNetworkSettings::checkPage (const QStringList &aList)
79{
80 CEnums::NetworkAttachmentType type =
81 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
82#if defined Q_WS_WIN
83 if (type == CEnums::HostInterfaceNetworkAttachment &&
84 isInterfaceInvalid (aList, cbHostInterfaceName->currentText()))
85 return 1;
86 else if (type == CEnums::InternalNetworkAttachment &&
87 cbInternalNetworkName_WIN->currentText().isEmpty())
88 return 2;
89 else
90 return 0;
91#else
92 NOREF (aList);
93 if (type == CEnums::InternalNetworkAttachment &&
94 cbInternalNetworkName_X11->currentText().isEmpty())
95 return 2;
96 else
97 return 0;
98#endif
99}
100
101void VBoxVMNetworkSettings::loadInterfaceList (const QStringList &aList,
102 const QString &aNillItem)
103{
104#if defined Q_WS_WIN
105 /* save current list item name */
106 QString currentListItemName = cbHostInterfaceName->currentText();
107 /* clear current list */
108 cbHostInterfaceName->clear();
109 /* load current list items */
110 if (aList.count())
111 {
112 cbHostInterfaceName->insertStringList (aList);
113 int index = aList.findIndex (currentListItemName);
114 if (index != -1)
115 cbHostInterfaceName->setCurrentItem (index);
116 }
117 else
118 {
119 cbHostInterfaceName->insertItem (aNillItem);
120 cbHostInterfaceName->setCurrentItem (0);
121 }
122#else
123 NOREF (aList);
124 NOREF (aNillItem);
125#endif
126}
127
128void VBoxVMNetworkSettings::loadNetworksList (const QStringList &aList)
129{
130 QComboBox *cbNetworkName = 0;
131#if defined Q_WS_WIN
132 cbNetworkName = cbInternalNetworkName_WIN;
133#else
134 cbNetworkName = cbInternalNetworkName_X11;
135#endif
136 Assert (cbNetworkName);
137 cbNetworkName->clear();
138 cbNetworkName->clearEdit();
139 cbNetworkName->insertStringList (aList);
140}
141
142void VBoxVMNetworkSettings::getFromAdapter (const CNetworkAdapter &adapter)
143{
144 cadapter = adapter;
145
146 grbEnabled->setChecked (adapter.GetEnabled());
147
148 CEnums::NetworkAttachmentType 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 cbInternalNetworkName_WIN->setCurrentText (adapter.GetInternalNetwork());
173#else
174 leHostInterface->setText (adapter.GetHostInterface());
175 cbInternalNetworkName_X11->setCurrentText (adapter.GetInternalNetwork());
176#endif
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 CEnums::NetworkAttachmentType type =
190 vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
191 switch (type)
192 {
193 case CEnums::NoNetworkAttachment:
194 cadapter.Detach();
195 break;
196 case CEnums::NATNetworkAttachment:
197 cadapter.AttachToNAT();
198 break;
199 case CEnums::HostInterfaceNetworkAttachment:
200 cadapter.AttachToHostInterface();
201 break;
202 case CEnums::InternalNetworkAttachment:
203 cadapter.AttachToInternalNetwork();
204 break;
205 default:
206 AssertMsgFailed (("Invalid network attachment type: %d", type));
207 break;
208 }
209
210 cadapter.SetMACAddress (leMACAddress->text());
211
212 cadapter.SetCableConnected (chbCableConnected->isChecked());
213
214 if (type == CEnums::HostInterfaceNetworkAttachment)
215 {
216#if defined Q_WS_WIN
217 if (!cbHostInterfaceName->currentText().isEmpty())
218 cadapter.SetHostInterface (cbHostInterfaceName->currentText());
219#else
220 QString iface = leHostInterface->text();
221 cadapter.SetHostInterface (iface.isEmpty() ? QString::null : iface);
222#endif
223#if defined Q_WS_X11
224 cadapter.SetTAPFileDescriptor (leTAPDescriptor->text().toLong());
225 QString setup = leTAPSetup->text();
226 cadapter.SetTAPSetupApplication (setup.isEmpty() ? QString::null : setup);
227 QString term = leTAPTerminate->text();
228 cadapter.SetTAPTerminateApplication (term.isEmpty() ? QString::null : term);
229#endif
230 }
231 else if (type == CEnums::InternalNetworkAttachment)
232 {
233#if defined Q_WS_WIN
234 if (!cbInternalNetworkName_WIN->currentText().isEmpty())
235 cadapter.SetInternalNetwork (cbInternalNetworkName_WIN->currentText());
236#else
237 if (!cbInternalNetworkName_X11->currentText().isEmpty())
238 cadapter.SetInternalNetwork (cbInternalNetworkName_X11->currentText());
239#endif
240 }
241}
242
243void VBoxVMNetworkSettings::setValidator (QIWidgetValidator *aWalidator)
244{
245 mWalidator = aWalidator;
246}
247
248void VBoxVMNetworkSettings::revalidate()
249{
250 mWalidator->revalidate();
251}
252
253void VBoxVMNetworkSettings::grbEnabledToggled (bool aOn)
254{
255#if defined Q_WS_WIN
256 if (!aOn)
257 {
258 cbNetworkAttachment->setCurrentItem (0);
259 cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
260 }
261#else
262 NOREF (aOn);
263#endif
264}
265
266void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &aString)
267{
268 bool enableHostIf = vboxGlobal().toNetworkAttachmentType (aString) ==
269 CEnums::HostInterfaceNetworkAttachment;
270 bool enableIntNet = vboxGlobal().toNetworkAttachmentType (aString) ==
271 CEnums::InternalNetworkAttachment;
272#if defined Q_WS_WIN
273 txHostInterface_WIN->setEnabled (enableHostIf);
274 cbHostInterfaceName->setEnabled (enableHostIf);
275 txInternalNetwork_WIN->setEnabled (enableIntNet);
276 cbInternalNetworkName_WIN->setEnabled (enableIntNet);
277#else
278 grbTAP->setEnabled (enableHostIf);
279 grbIntNet->setEnabled (enableIntNet);
280#endif
281}
282
283bool VBoxVMNetworkSettings::isInterfaceInvalid (const QStringList &aList,
284 const QString &aIface)
285{
286#if defined Q_WS_WIN
287 return aList.find (aIface) == aList.end();
288#else
289 NOREF (aList);
290 NOREF (aIface);
291 return false;
292#endif
293}
294
295void VBoxVMNetworkSettings::pbGenerateMAC_clicked()
296{
297 cadapter.SetMACAddress (QString::null);
298 leMACAddress->setText (cadapter.GetMACAddress());
299}
300
301void VBoxVMNetworkSettings::pbTAPSetup_clicked()
302{
303 QString selected = QFileDialog::getOpenFileName (
304 "/",
305 QString::null,
306 this,
307 NULL,
308 tr ("Select TAP setup application"));
309
310 if (selected)
311 leTAPSetup->setText (selected);
312}
313
314void VBoxVMNetworkSettings::pbTAPTerminate_clicked()
315{
316 QString selected = QFileDialog::getOpenFileName (
317 "/",
318 QString::null,
319 this,
320 NULL,
321 tr ("Select TAP terminate application"));
322
323 if (selected)
324 leTAPTerminate->setText (selected);
325}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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