VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMachineAttributeSetter.cpp

Last change on this file was 106061, checked in by vboxsync, 8 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/* $Id: UIMachineAttributeSetter.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMachineAttributeSetter namespace implementation.
4 */
5
6/*
7 * Copyright (C) 2019-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QVariant>
30
31/* GUI includes: */
32#include "UIBootOrderEditor.h"
33#include "UILocalMachineStuff.h"
34#include "UIMachineAttributeSetter.h"
35#include "UIMessageCenter.h"
36#include "UINotificationCenter.h"
37
38/* COM includes: */
39#include "CAudioAdapter.h"
40#include "CAudioSettings.h"
41#include "CGraphicsAdapter.h"
42#include "CNetworkAdapter.h"
43#include "CUSBController.h"
44
45
46void removeUSBControllers(CMachine &comMachine, const UIUSBControllerTypeSet &controllerSet = UIUSBControllerTypeSet())
47{
48 /* Get controllers for further activities: */
49 const CUSBControllerVector &controllers = comMachine.GetUSBControllers();
50 if (!comMachine.isOk())
51 return;
52
53 /* For each controller: */
54 foreach (const CUSBController &comController, controllers)
55 {
56 /* Get controller type&name for further activities: */
57 const KUSBControllerType enmType = comController.GetType();
58 const QString strName = comController.GetName();
59
60 /* Pass only if requested types were not defined or contains the one we found: */
61 if (!controllerSet.isEmpty() && !controllerSet.contains(enmType))
62 continue;
63
64 /* Remove controller: */
65 comMachine.RemoveUSBController(strName);
66 if (!comMachine.isOk())
67 break;
68 }
69}
70
71void createUSBControllers(CMachine &comMachine, const UIUSBControllerTypeSet &controllerSet)
72{
73 /* For each requested USB controller type: */
74 foreach (const KUSBControllerType &enmType, controllerSet)
75 {
76 switch (enmType)
77 {
78 case KUSBControllerType_OHCI: comMachine.AddUSBController("OHCI", KUSBControllerType_OHCI); break;
79 case KUSBControllerType_EHCI: comMachine.AddUSBController("EHCI", KUSBControllerType_EHCI); break;
80 case KUSBControllerType_XHCI: comMachine.AddUSBController("xHCI", KUSBControllerType_XHCI); break;
81 default: break;
82 }
83 }
84}
85
86void UIMachineAttributeSetter::setMachineAttribute(const CMachine &comConstMachine,
87 const MachineAttribute &enmType,
88 const QVariant &guiAttribute)
89{
90 /* Get editable machine & session: */
91 CMachine comMachine = comConstMachine;
92 CSession comSession = tryToOpenSessionFor(comMachine);
93
94 /* Main API block: */
95 do
96 {
97 /* Save machine settings? */
98 bool fSaveSettings = true;
99 /* Error happened? */
100 bool fErrorHappened = false;
101
102 /* Assign attribute depending on passed type: */
103 switch (enmType)
104 {
105 case MachineAttribute_Name:
106 {
107 /* Change machine name: */
108 comMachine.SetName(guiAttribute.toString());
109 if (!comMachine.isOk())
110 {
111 UINotificationMessage::cannotChangeMachineParameter(comMachine);
112 fErrorHappened = true;
113 }
114 break;
115 }
116 case MachineAttribute_OSType:
117 {
118 /* Change machine OS type: */
119 comMachine.SetOSTypeId(guiAttribute.toString());
120 if (!comMachine.isOk())
121 {
122 UINotificationMessage::cannotChangeMachineParameter(comMachine);
123 fErrorHappened = true;
124 }
125 break;
126 }
127 case MachineAttribute_BaseMemory:
128 {
129 /* Change machine base memory (RAM): */
130 comMachine.SetMemorySize(guiAttribute.toInt());
131 if (!comMachine.isOk())
132 {
133 UINotificationMessage::cannotChangeMachineParameter(comMachine);
134 fErrorHappened = true;
135 }
136 break;
137 }
138 case MachineAttribute_BootOrder:
139 {
140 /* Change machine boot order: */
141 saveBootItems(guiAttribute.value<UIBootItemDataList>(), comMachine);
142 if (!comMachine.isOk())
143 {
144 UINotificationMessage::cannotChangeMachineParameter(comMachine);
145 fErrorHappened = true;
146 }
147 break;
148 }
149 case MachineAttribute_VideoMemory:
150 {
151 /* Acquire graphics adapter: */
152 CGraphicsAdapter comGraphics = comMachine.GetGraphicsAdapter();
153 if (!comMachine.isOk())
154 {
155 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
156 fErrorHappened = true;
157 break;
158 }
159 /* Change machine video memory (VRAM): */
160 comGraphics.SetVRAMSize(guiAttribute.toInt());
161 if (!comGraphics.isOk())
162 {
163 UINotificationMessage::cannotChangeGraphicsAdapterParameter(comGraphics);
164 fErrorHappened = true;
165 }
166 break;
167 }
168 case MachineAttribute_GraphicsControllerType:
169 {
170 /* Acquire graphics adapter: */
171 CGraphicsAdapter comGraphics = comMachine.GetGraphicsAdapter();
172 if (!comMachine.isOk())
173 {
174 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
175 fErrorHappened = true;
176 break;
177 }
178 /* Change machine graphics controller type: */
179 comGraphics.SetGraphicsControllerType(guiAttribute.value<KGraphicsControllerType>());
180 if (!comGraphics.isOk())
181 {
182 UINotificationMessage::cannotChangeGraphicsAdapterParameter(comGraphics);
183 fErrorHappened = true;
184 }
185 break;
186 }
187 case MachineAttribute_AudioHostDriverType:
188 {
189 /* Acquire audio adapter: */
190 CAudioSettings const comAudioSettings = comMachine.GetAudioSettings();
191 CAudioAdapter comAdapter = comAudioSettings.GetAdapter();
192 if (!comAudioSettings.isOk())
193 {
194 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
195 fErrorHappened = true;
196 break;
197 }
198 /* Change audio host driver type: */
199 comAdapter.SetAudioDriver(guiAttribute.value<KAudioDriverType>());
200 if (!comAdapter.isOk())
201 {
202 UINotificationMessage::cannotChangeAudioAdapterParameter(comAdapter);
203 fErrorHappened = true;
204 }
205 break;
206 }
207 case MachineAttribute_AudioControllerType:
208 {
209 /* Acquire audio adapter: */
210 CAudioSettings const comAudioSettings = comMachine.GetAudioSettings();
211 CAudioAdapter comAdapter = comAudioSettings.GetAdapter();
212 if (!comAudioSettings.isOk())
213 {
214 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
215 fErrorHappened = true;
216 break;
217 }
218 /* Change audio controller type: */
219 comAdapter.SetAudioController(guiAttribute.value<KAudioControllerType>());
220 if (!comAdapter.isOk())
221 {
222 UINotificationMessage::cannotChangeAudioAdapterParameter(comAdapter);
223 fErrorHappened = true;
224 }
225 break;
226 }
227 case MachineAttribute_NetworkAttachmentType:
228 {
229 /* Acquire value itself: */
230 const UINetworkAdapterDescriptor nad = guiAttribute.value<UINetworkAdapterDescriptor>();
231 /* Acquire network adapter: */
232 CNetworkAdapter comAdapter = comMachine.GetNetworkAdapter(nad.m_iSlot);
233 if (!comMachine.isOk())
234 {
235 UINotificationMessage::cannotAcquireMachineParameter(comMachine);
236 fErrorHappened = true;
237 break;
238 }
239 /* Change network adapter attachment type: */
240 comAdapter.SetAttachmentType(nad.m_enmType);
241 if (!comAdapter.isOk())
242 {
243 UINotificationMessage::cannotChangeNetworkAdapterParameter(comAdapter);
244 fErrorHappened = true;
245 break;
246 }
247 /* Change network adapter name: */
248 switch (nad.m_enmType)
249 {
250 case KNetworkAttachmentType_Bridged: comAdapter.SetBridgedInterface(nad.m_strName); break;
251 case KNetworkAttachmentType_Internal: comAdapter.SetInternalNetwork(nad.m_strName); break;
252 case KNetworkAttachmentType_HostOnly: comAdapter.SetHostOnlyInterface(nad.m_strName); break;
253 case KNetworkAttachmentType_Generic: comAdapter.SetGenericDriver(nad.m_strName); break;
254 case KNetworkAttachmentType_NATNetwork: comAdapter.SetNATNetwork(nad.m_strName); break;
255#ifdef VBOX_WITH_CLOUD_NET
256 case KNetworkAttachmentType_Cloud: comAdapter.SetCloudNetwork(nad.m_strName); break;
257#endif
258#ifdef VBOX_WITH_VMNET
259 case KNetworkAttachmentType_HostOnlyNetwork: comAdapter.SetHostOnlyNetwork(nad.m_strName); break;
260#endif
261 default: break;
262 }
263 if (!comAdapter.isOk())
264 {
265 UINotificationMessage::cannotChangeNetworkAdapterParameter(comAdapter);
266 fErrorHappened = true;
267 }
268 break;
269 }
270 case MachineAttribute_USBControllerType:
271 {
272 /* Remove all existing controller first of all: */
273 removeUSBControllers(comMachine);
274 if (!comMachine.isOk())
275 {
276 UINotificationMessage::cannotChangeMachineParameter(comMachine);
277 fErrorHappened = true;
278 break;
279 }
280 /* Add new controllers afterwards: */
281 const UIUSBControllerTypeSet controllerSet = guiAttribute.value<UIUSBControllerTypeSet>();
282 if (!controllerSet.contains(KUSBControllerType_Null))
283 {
284 createUSBControllers(comMachine, controllerSet);
285 if (!comMachine.isOk())
286 {
287 UINotificationMessage::cannotChangeMachineParameter(comMachine);
288 fErrorHappened = true;
289 }
290 }
291 break;
292 }
293 default:
294 break;
295 }
296
297 /* Error happened? */
298 if (fErrorHappened)
299 break;
300 /* Save machine settings? */
301 if (!fSaveSettings)
302 break;
303
304 /* Save machine settings: */
305 comMachine.SaveSettings();
306 if (!comMachine.isOk())
307 {
308 msgCenter().cannotSaveMachineSettings(comMachine);
309 break;
310 }
311 }
312 while (0);
313
314 /* Close session to editable comMachine if necessary: */
315 if (!comSession.isNull())
316 comSession.UnlockMachine();
317}
318
319void UIMachineAttributeSetter::setMachineLocation(const QUuid &uMachineId,
320 const QString &strLocation)
321{
322 /* Move machine: */
323 UINotificationProgressMachineMove *pNotification = new UINotificationProgressMachineMove(uMachineId,
324 strLocation,
325 "basic");
326 gpNotificationCenter->append(pNotification);
327}
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