VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIGuestOSType.cpp@ 103977

Last change on this file since 103977 was 103906, checked in by vboxsync, 9 months ago

FE/Qt: bugref:10384: UIGuestOSType: Provide family, subtype and type getters with a list of exceptions which forced to be included into a filtered results even if they are not among supported values; This is especially useful for the UINameAndSystemEditor to make sure it reflects proper values even if they are restricted by the Main API.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.7 KB
Line 
1/* $Id: UIGuestOSType.cpp 103906 2024-03-18 18:37:37Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIGuestOSType class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2023 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/* GUI includes: */
29#include "UICommon.h"
30#include "UIGlobalSession.h"
31#include "UIGuestOSType.h"
32
33/* COM includes: */
34#include "CGuestOSType.h"
35#include "CPlatformProperties.h"
36#include "CSystemProperties.h"
37
38
39void UIGuestOSTypeManager::reCacheGuestOSTypes()
40{
41 /* Acquire CVirtualBox: */
42 CVirtualBox comVBox = gpGlobalSession->virtualBox();
43
44 /* Acquire a total list of guest OS types, supported or not: */
45 CGuestOSTypeVector guestOSTypes = comVBox.GetGuestOSTypes();
46
47 /* Acquire a list of guest OS types supported by this host: */
48 m_supportedGuestOSTypeIDs.clear();
49 CSystemProperties comSystemProps = comVBox.GetSystemProperties();
50 foreach (const KPlatformArchitecture &enmArch, comSystemProps.GetSupportedPlatformArchitectures())
51 {
52 CPlatformProperties comPlatformProps = comVBox.GetPlatformProperties(enmArch);
53 foreach (const CGuestOSType &comType, comPlatformProps.GetSupportedGuestOSTypes())
54 m_supportedGuestOSTypeIDs << comType.GetId();
55 }
56
57 /* Wipe out cache: */
58 m_typeIdIndexMap.clear();
59 m_guestOSTypes.clear();
60 m_guestOSFamilies.clear();
61 m_guestOSSubtypes.clear();
62
63 /* Enumerate guest OS types: */
64 QVector<CGuestOSType> otherOSTypes;
65 foreach (const CGuestOSType &comType, guestOSTypes)
66 {
67 /* Filter out "other" family types: */
68 if (comType.GetFamilyId().contains("other", Qt::CaseInsensitive))
69 {
70 otherOSTypes << comType;
71 continue;
72 }
73 addGuestOSType(comType);
74 }
75
76 /* Add OS types with family "other" to the end of the lists: */
77 foreach (const CGuestOSType &comType, otherOSTypes)
78 addGuestOSType(comType);
79}
80
81void UIGuestOSTypeManager::addGuestOSType(const CGuestOSType &comType)
82{
83 /* Acquire guest OS type ID and whether it's supported: */
84 const QString strId = comType.GetId();
85 const bool fSupported = m_supportedGuestOSTypeIDs.contains(strId);
86
87 /* Append guest OS type to a list of cached wrappers: */
88 m_guestOSTypes.append(UIGuestOSType(comType, fSupported));
89
90 /* Acquire a bit of attributes: */
91 const QString strFamilyId = m_guestOSTypes.last().getFamilyId();
92 const QString strFamilyDesc = m_guestOSTypes.last().getFamilyDescription();
93 const QString strSubtype = m_guestOSTypes.last().getSubtype();
94 const KPlatformArchitecture enmArch = m_guestOSTypes.last().getPlatformArchitecture();
95
96 /* Remember guest OS type index as well: */
97 m_typeIdIndexMap[strId] = m_guestOSTypes.size() - 1;
98
99 /* Cache or update family info: */
100 UIFamilyInfo fi(strFamilyId, strFamilyDesc, enmArch, fSupported);
101 if (!m_guestOSFamilies.contains(fi))
102 m_guestOSFamilies << fi;
103 else
104 {
105 const int iIndex = m_guestOSFamilies.indexOf(fi);
106 AssertReturnVoid(iIndex >= 0);
107 if (m_guestOSFamilies.at(iIndex).m_enmArch != enmArch)
108 m_guestOSFamilies[iIndex].m_enmArch = KPlatformArchitecture_None; // means any
109 if (m_guestOSFamilies.at(iIndex).m_fSupported != fSupported)
110 m_guestOSFamilies[iIndex].m_fSupported = true; // cause at least one is supported
111 }
112
113 /* Cache or update subtype info: */
114 UISubtypeInfo si(strSubtype, enmArch, fSupported);
115 if (!m_guestOSSubtypes.contains(strFamilyId))
116 m_guestOSSubtypes[strFamilyId] << si;
117 else
118 {
119 UIGuestOSSubtypeInfo &subtypes = m_guestOSSubtypes[strFamilyId];
120 if (!subtypes.contains(si))
121 subtypes << si;
122 else
123 {
124 const int iIndex = subtypes.indexOf(si);
125 AssertReturnVoid(iIndex >= 0);
126 if (subtypes.at(iIndex).m_enmArch != enmArch)
127 subtypes[iIndex].m_enmArch = KPlatformArchitecture_None; // means any
128 if (subtypes.at(iIndex).m_fSupported != fSupported)
129 subtypes[iIndex].m_fSupported = true; // cause at least one is supported
130 }
131 }
132}
133
134UIGuestOSTypeManager::UIGuestOSFamilyInfo
135UIGuestOSTypeManager::getFamilies(bool fListAll /* = true */,
136 const QStringList &including /* = QStringList() */,
137 KPlatformArchitecture enmArch /* = KPlatformArchitecture_None */) const
138{
139 /* Otherwise we'll have to prepare list by arch type: */
140 UIGuestOSTypeManager::UIGuestOSFamilyInfo families;
141 foreach (const UIFamilyInfo &fi, m_guestOSFamilies)
142 {
143 if ( !fListAll
144 && !fi.m_fSupported
145 && !including.contains(fi.m_strId))
146 continue;
147 const KPlatformArchitecture enmCurrentArch = fi.m_enmArch;
148 if ( enmCurrentArch == enmArch
149 || enmCurrentArch == KPlatformArchitecture_None
150 || enmArch == KPlatformArchitecture_None)
151 families << fi;
152 }
153 return families;
154}
155
156UIGuestOSTypeManager::UIGuestOSSubtypeInfo
157UIGuestOSTypeManager::getSubtypesForFamilyId(const QString &strFamilyId,
158 bool fListAll /* = true */,
159 const QStringList &including /* = QStringList() */,
160 KPlatformArchitecture enmArch /* = KPlatformArchitecture_None */) const
161{
162 /* Otherwise we'll have to prepare list by arch type: */
163 UIGuestOSSubtypeInfo subtypes;
164 foreach (const UISubtypeInfo &si, m_guestOSSubtypes.value(strFamilyId))
165 {
166 if ( !fListAll
167 && !si.m_fSupported
168 && !including.contains(si.m_strName))
169 continue;
170 const KPlatformArchitecture enmCurrentArch = si.m_enmArch;
171 if ( enmCurrentArch == enmArch
172 || enmCurrentArch == KPlatformArchitecture_None
173 || enmArch == KPlatformArchitecture_None)
174 subtypes << si;
175 }
176 return subtypes;
177}
178
179UIGuestOSTypeManager::UIGuestOSTypeInfo
180UIGuestOSTypeManager::getTypesForFamilyId(const QString &strFamilyId,
181 bool fListAll /* = true */,
182 const QStringList &including /* = QStringList() */,
183 KPlatformArchitecture enmArch /* = KPlatformArchitecture_None */) const
184{
185 UIGuestOSTypeInfo typeInfoList;
186 if (strFamilyId.isEmpty())
187 return typeInfoList;
188 foreach (const UIGuestOSType &type, m_guestOSTypes)
189 {
190 if ( !fListAll
191 && !type.isSupported()
192 && !including.contains(type.getId()))
193 continue;
194 if (type.getFamilyId() != strFamilyId)
195 continue;
196 QPair<QString, QString> info(type.getId(), type.getDescription());
197 if (typeInfoList.contains(info))
198 continue;
199 if ( enmArch == KPlatformArchitecture_None
200 || type.getPlatformArchitecture() == enmArch)
201 typeInfoList << info;
202 }
203 return typeInfoList;
204}
205
206UIGuestOSTypeManager::UIGuestOSTypeInfo
207UIGuestOSTypeManager::getTypesForSubtype(const QString &strSubtype,
208 bool fListAll /* = true */,
209 const QStringList &including /* = QStringList() */,
210 KPlatformArchitecture enmArch /* = KPlatformArchitecture_None */) const
211{
212 UIGuestOSTypeInfo typeInfoList;
213 if (strSubtype.isEmpty())
214 return typeInfoList;
215 foreach (const UIGuestOSType &type, m_guestOSTypes)
216 {
217 if ( !fListAll
218 && !type.isSupported()
219 && !including.contains(type.getId()))
220 continue;
221 if (type.getSubtype() != strSubtype)
222 continue;
223 QPair<QString, QString> info(type.getId(), type.getDescription());
224 if (typeInfoList.contains(info))
225 continue;
226 if ( enmArch == KPlatformArchitecture_None
227 || type.getPlatformArchitecture() == enmArch)
228 typeInfoList << info;
229 }
230 return typeInfoList;
231}
232
233QString UIGuestOSTypeManager::getFamilyId(const QString &strTypeId) const
234{
235 /* Let QVector<>::value check for the bounds. It returns a default constructed value when it is out of bounds. */
236 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getFamilyId();
237}
238
239QString UIGuestOSTypeManager::getSubtype(const QString &strTypeId) const
240{
241 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getSubtype();
242}
243
244KGraphicsControllerType UIGuestOSTypeManager::getRecommendedGraphicsController(const QString &strTypeId) const
245{
246 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedGraphicsController();
247}
248
249KStorageControllerType UIGuestOSTypeManager::getRecommendedDVDStorageController(const QString &strTypeId) const
250{
251 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedDVDStorageController();
252}
253
254ULONG UIGuestOSTypeManager::getRecommendedRAM(const QString &strTypeId) const
255{
256 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedRAM();
257}
258
259ULONG UIGuestOSTypeManager::getRecommendedCPUCount(const QString &strTypeId) const
260{
261 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedCPUCount();
262}
263
264KFirmwareType UIGuestOSTypeManager::getRecommendedFirmware(const QString &strTypeId) const
265{
266 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedFirmware();
267}
268
269QString UIGuestOSTypeManager::getDescription(const QString &strTypeId) const
270{
271 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getDescription();
272}
273
274LONG64 UIGuestOSTypeManager::getRecommendedHDD(const QString &strTypeId) const
275{
276 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedHDD();
277}
278
279KStorageBus UIGuestOSTypeManager::getRecommendedHDStorageBus(const QString &strTypeId) const
280{
281 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedHDStorageBus();
282}
283
284KStorageBus UIGuestOSTypeManager::getRecommendedDVDStorageBus(const QString &strTypeId) const
285{
286 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedDVDStorageBus();
287}
288
289bool UIGuestOSTypeManager::getRecommendedFloppy(const QString &strTypeId) const
290{
291 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedFloppy();
292}
293
294bool UIGuestOSTypeManager::isLinux(const QString &strTypeId) const
295{
296 QString strFamilyId = getFamilyId(strTypeId);
297 if (strFamilyId.contains("linux", Qt::CaseInsensitive))
298 return true;
299 return false;
300}
301
302bool UIGuestOSTypeManager::isWindows(const QString &strTypeId) const
303{
304 QString strFamilyId = getFamilyId(strTypeId);
305 if (strFamilyId.contains("windows", Qt::CaseInsensitive))
306 return true;
307 return false;
308}
309
310bool UIGuestOSTypeManager::is64Bit(const QString &strTypeId) const
311{
312 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).is64Bit();
313}
314
315KPlatformArchitecture UIGuestOSTypeManager::getPlatformArchitecture(const QString &strTypeId) const
316{
317 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getPlatformArchitecture();
318}
319
320/* static */
321bool UIGuestOSTypeManager::isDOSType(const QString &strOSTypeId)
322{
323 if ( strOSTypeId.left(3) == "dos"
324 || strOSTypeId.left(3) == "win"
325 || strOSTypeId.left(3) == "os2")
326 return true;
327
328 return false;
329}
330
331/*********************************************************************************************************************************
332* UIGuestOSType implementaion. *
333*********************************************************************************************************************************/
334
335UIGuestOSType::UIGuestOSType()
336 : m_fSupported(false)
337{
338}
339
340UIGuestOSType::UIGuestOSType(const CGuestOSType &comGuestOSType, bool fSupported)
341 : m_comGuestOSType(comGuestOSType)
342 , m_fSupported(fSupported)
343{
344}
345
346bool UIGuestOSType::isOk() const
347{
348 return (!m_comGuestOSType.isNull() && m_comGuestOSType.isOk());
349}
350
351bool UIGuestOSType::isSupported() const
352{
353 return m_fSupported;
354}
355
356const QString &UIGuestOSType::getFamilyId() const
357{
358 if (m_strFamilyId.isEmpty() && m_comGuestOSType.isOk())
359 m_strFamilyId = m_comGuestOSType.GetFamilyId();
360 return m_strFamilyId;
361}
362
363const QString &UIGuestOSType::getFamilyDescription() const
364{
365 if (m_strFamilyDescription.isEmpty() && m_comGuestOSType.isOk())
366 m_strFamilyDescription = m_comGuestOSType.GetFamilyDescription();
367 return m_strFamilyDescription;
368}
369
370const QString &UIGuestOSType::getId() const
371{
372 if (m_strId.isEmpty() && m_comGuestOSType.isOk())
373 m_strId = m_comGuestOSType.GetId();
374 return m_strId;
375}
376
377const QString &UIGuestOSType::getSubtype() const
378{
379 if (m_strSubtype.isEmpty() && m_comGuestOSType.isOk())
380 m_strSubtype = m_comGuestOSType.GetSubtype();
381 return m_strSubtype;
382}
383
384const QString &UIGuestOSType::getDescription() const
385{
386 if (m_strDescription.isEmpty() && m_comGuestOSType.isOk())
387 m_strDescription = m_comGuestOSType.GetDescription();
388 return m_strDescription;
389}
390
391KStorageBus UIGuestOSType::getRecommendedHDStorageBus() const
392{
393 if (m_comGuestOSType.isOk())
394 return m_comGuestOSType.GetRecommendedHDStorageBus();
395 return KStorageBus_Null;
396}
397
398ULONG UIGuestOSType::getRecommendedRAM() const
399{
400 if (m_comGuestOSType.isOk())
401 return m_comGuestOSType.GetRecommendedRAM();
402 return 0;
403}
404
405KStorageBus UIGuestOSType::getRecommendedDVDStorageBus() const
406{
407 if (m_comGuestOSType.isOk())
408 return m_comGuestOSType.GetRecommendedDVDStorageBus();
409 return KStorageBus_Null;
410}
411
412ULONG UIGuestOSType::getRecommendedCPUCount() const
413{
414 if (m_comGuestOSType.isOk())
415 return m_comGuestOSType.GetRecommendedCPUCount();
416 return 0;
417}
418
419KFirmwareType UIGuestOSType::getRecommendedFirmware() const
420{
421 if (m_comGuestOSType.isOk())
422 return m_comGuestOSType.GetRecommendedFirmware();
423 return KFirmwareType_Max;
424}
425
426bool UIGuestOSType::getRecommendedFloppy() const
427{
428 if (m_comGuestOSType.isOk())
429 return m_comGuestOSType.GetRecommendedFloppy();
430 return false;
431}
432
433LONG64 UIGuestOSType::getRecommendedHDD() const
434{
435 if (m_comGuestOSType.isOk())
436 return m_comGuestOSType.GetRecommendedHDD();
437 return 0;
438}
439
440KGraphicsControllerType UIGuestOSType::getRecommendedGraphicsController() const
441{
442 if (m_comGuestOSType.isOk())
443 return m_comGuestOSType.GetRecommendedGraphicsController();
444 return KGraphicsControllerType_Null;
445}
446
447KStorageControllerType UIGuestOSType::getRecommendedDVDStorageController() const
448{
449 if (m_comGuestOSType.isOk())
450 return m_comGuestOSType.GetRecommendedDVDStorageController();
451 return KStorageControllerType_Null;
452}
453
454bool UIGuestOSType::is64Bit() const
455{
456 if (m_comGuestOSType.isOk())
457 return m_comGuestOSType.GetIs64Bit();
458 return false;
459}
460
461KPlatformArchitecture UIGuestOSType::getPlatformArchitecture() const
462{
463 if (m_comGuestOSType.isOk())
464 return m_comGuestOSType.GetPlatformArchitecture();
465 return KPlatformArchitecture_Max;
466}
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