VirtualBox

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

Last change on this file since 103131 was 102282, checked in by vboxsync, 14 months ago

FE/Qt: bugref:10543: A bit of rework for UIGuestOSType; Make sure only supported guest OS types enumerated on per architecture basis.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.5 KB
Line 
1/* $Id: UIGuestOSType.cpp 102282 2023-11-23 19:52:48Z 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 "UIGuestOSType.h"
31
32/* COM includes: */
33#include "CGuestOSType.h"
34#include "CPlatformProperties.h"
35#include "CSystemProperties.h"
36
37
38void UIGuestOSTypeManager::reCacheGuestOSTypes()
39{
40 /* Acquire a list of guest OS types supported by this host: */
41 CGuestOSTypeVector guestOSTypes;
42 CSystemProperties comSysProps = uiCommon().virtualBox().GetSystemProperties();
43 foreach (const KPlatformArchitecture &enmArch, comSysProps.GetSupportedPlatformArchitectures())
44 {
45 CPlatformProperties comPlatProps = uiCommon().virtualBox().GetPlatformProperties(enmArch);
46 guestOSTypes += comPlatProps.GetSupportedGuestOSTypes();
47 }
48
49 /* Wipe out cache: */
50 m_typeIdIndexMap.clear();
51 m_guestOSTypes.clear();
52 m_guestOSFamilies.clear();
53 m_guestOSFamilyArch.clear();
54 m_guestOSSubtypeArch.clear();
55
56 /* Enumerate guest OS types: */
57 QVector<CGuestOSType> otherOSTypes;
58 foreach (const CGuestOSType &comType, guestOSTypes)
59 {
60 /* Filter out "other" family types: */
61 if (comType.GetFamilyId().contains("other", Qt::CaseInsensitive))
62 {
63 otherOSTypes << comType;
64 continue;
65 }
66 addGuestOSType(comType);
67 }
68
69 /* Add OS types with family "other" to the end of the lists: */
70 foreach (const CGuestOSType &comType, otherOSTypes)
71 addGuestOSType(comType);
72}
73
74void UIGuestOSTypeManager::addGuestOSType(const CGuestOSType &comType)
75{
76 m_guestOSTypes.append(UIGuestOSType(comType));
77 m_typeIdIndexMap[m_guestOSTypes.last().getId()] = m_guestOSTypes.size() - 1;
78 const QString strFamilyId = m_guestOSTypes.last().getFamilyId();
79 const QString strFamilyDesc = m_guestOSTypes.last().getFamilyDescription();
80 const QString strSubtype = m_guestOSTypes.last().getSubtype();
81 QPair<QString, QString> family = QPair<QString, QString>(strFamilyId, strFamilyDesc);
82 if (!m_guestOSFamilies.contains(family))
83 m_guestOSFamilies << family;
84
85 /* Acquire arch type: */
86 const KPlatformArchitecture enmArch = m_guestOSTypes.last().getPlatformArchitecture();
87 /* Cache family arch type; That will be x86, ARM or None (for *any*): */
88 if (!m_guestOSFamilyArch.contains(strFamilyId))
89 m_guestOSFamilyArch[strFamilyId] = enmArch;
90 else if (m_guestOSFamilyArch.value(strFamilyId) != enmArch)
91 m_guestOSFamilyArch[strFamilyId] = KPlatformArchitecture_None;
92 /* Cache subtype arch type; That will be x86, ARM or None (for *any*): */
93 if (!m_guestOSSubtypeArch.contains(strSubtype))
94 m_guestOSSubtypeArch[strSubtype] = enmArch;
95 else if (m_guestOSSubtypeArch.value(strSubtype) != enmArch)
96 m_guestOSSubtypeArch[strSubtype] = KPlatformArchitecture_None;
97}
98
99UIGuestOSTypeManager::UIGuestOSFamilyInfo
100UIGuestOSTypeManager::getFamilies(KPlatformArchitecture enmArch /* = KPlatformArchitecture_None */) const
101{
102 /* Return all families by default: */
103 if (enmArch == KPlatformArchitecture_None)
104 return m_guestOSFamilies;
105
106 /* Otherwise we'll have to prepare list by arch type: */
107 UIGuestOSTypeManager::UIGuestOSFamilyInfo families;
108 foreach (const UIGuestInfoPair &family, m_guestOSFamilies)
109 {
110 const KPlatformArchitecture enmCurrentArch = m_guestOSFamilyArch.value(family.first, KPlatformArchitecture_Max);
111 if ( enmCurrentArch == enmArch
112 || enmCurrentArch == KPlatformArchitecture_None)
113 families << family;
114 }
115 return families;
116}
117
118QStringList
119UIGuestOSTypeManager::getSubtypeListForFamilyId(const QString &strFamilyId,
120 KPlatformArchitecture enmArch /* = KPlatformArchitecture_None */) const
121{
122 /* Prepare list by arch type: */
123 QStringList subtypes;
124 foreach (const UIGuestOSType &type, m_guestOSTypes)
125 {
126 if (type.getFamilyId() != strFamilyId)
127 continue;
128 const QString strSubtype = type.getSubtype();
129 if (strSubtype.isEmpty() || subtypes.contains(strSubtype))
130 continue;
131 const KPlatformArchitecture enmCurrentArch = m_guestOSSubtypeArch.value(strSubtype, KPlatformArchitecture_Max);
132 if ( enmCurrentArch == enmArch
133 || enmArch == KPlatformArchitecture_None
134 || enmCurrentArch == KPlatformArchitecture_None)
135 subtypes << strSubtype;
136 }
137 return subtypes;
138}
139
140UIGuestOSTypeManager::UIGuestOSTypeInfo
141UIGuestOSTypeManager::getTypeListForFamilyId(const QString &strFamilyId,
142 KPlatformArchitecture enmArch /* = KPlatformArchitecture_None */) const
143{
144 UIGuestOSTypeInfo typeInfoList;
145 foreach (const UIGuestOSType &type, m_guestOSTypes)
146 {
147 if (type.getFamilyId() != strFamilyId)
148 continue;
149 QPair<QString, QString> info(type.getId(), type.getDescription());
150 if (typeInfoList.contains(info))
151 continue;
152 if ( enmArch == KPlatformArchitecture_None
153 || type.getPlatformArchitecture() == enmArch)
154 typeInfoList << info;
155 }
156 return typeInfoList;
157}
158
159UIGuestOSTypeManager::UIGuestOSTypeInfo
160UIGuestOSTypeManager::getTypeListForSubtype(const QString &strSubtype,
161 KPlatformArchitecture enmArch /* = KPlatformArchitecture_None */) const
162{
163 UIGuestOSTypeInfo typeInfoList;
164 if (strSubtype.isEmpty())
165 return typeInfoList;
166 foreach (const UIGuestOSType &type, m_guestOSTypes)
167 {
168 if (type.getSubtype() != strSubtype)
169 continue;
170 QPair<QString, QString> info(type.getId(), type.getDescription());
171 if (typeInfoList.contains(info))
172 continue;
173 if ( enmArch == KPlatformArchitecture_None
174 || type.getPlatformArchitecture() == enmArch)
175 typeInfoList << info;
176 }
177 return typeInfoList;
178}
179
180QString UIGuestOSTypeManager::getFamilyId(const QString &strTypeId) const
181{
182 /* Let QVector<>::value check for the bounds. It returns a default constructed value when it is out of bounds. */
183 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getFamilyId();
184}
185
186QString UIGuestOSTypeManager::getSubtype(const QString &strTypeId) const
187{
188 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getSubtype();
189}
190
191KGraphicsControllerType UIGuestOSTypeManager::getRecommendedGraphicsController(const QString &strTypeId) const
192{
193 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedGraphicsController();
194}
195
196KStorageControllerType UIGuestOSTypeManager::getRecommendedDVDStorageController(const QString &strTypeId) const
197{
198 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedDVDStorageController();
199}
200
201ULONG UIGuestOSTypeManager::getRecommendedRAM(const QString &strTypeId) const
202{
203 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedRAM();
204}
205
206ULONG UIGuestOSTypeManager::getRecommendedCPUCount(const QString &strTypeId) const
207{
208 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedCPUCount();
209}
210
211KFirmwareType UIGuestOSTypeManager::getRecommendedFirmware(const QString &strTypeId) const
212{
213 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedFirmware();
214}
215
216QString UIGuestOSTypeManager::getDescription(const QString &strTypeId) const
217{
218 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getDescription();
219}
220
221LONG64 UIGuestOSTypeManager::getRecommendedHDD(const QString &strTypeId) const
222{
223 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedHDD();
224}
225
226KStorageBus UIGuestOSTypeManager::getRecommendedHDStorageBus(const QString &strTypeId) const
227{
228 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedHDStorageBus();
229}
230
231KStorageBus UIGuestOSTypeManager::getRecommendedDVDStorageBus(const QString &strTypeId) const
232{
233 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedDVDStorageBus();
234}
235
236bool UIGuestOSTypeManager::getRecommendedFloppy(const QString &strTypeId) const
237{
238 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getRecommendedFloppy();
239}
240
241bool UIGuestOSTypeManager::isLinux(const QString &strTypeId) const
242{
243 QString strFamilyId = getFamilyId(strTypeId);
244 if (strFamilyId.contains("linux", Qt::CaseInsensitive))
245 return true;
246 return false;
247}
248
249bool UIGuestOSTypeManager::isWindows(const QString &strTypeId) const
250{
251 QString strFamilyId = getFamilyId(strTypeId);
252 if (strFamilyId.contains("windows", Qt::CaseInsensitive))
253 return true;
254 return false;
255}
256
257bool UIGuestOSTypeManager::is64Bit(const QString &strTypeId) const
258{
259 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).is64Bit();
260}
261
262KPlatformArchitecture UIGuestOSTypeManager::getPlatformArchitecture(const QString &strTypeId) const
263{
264 return m_guestOSTypes.value(m_typeIdIndexMap.value(strTypeId, -1)).getPlatformArchitecture();
265}
266
267/* static */
268bool UIGuestOSTypeManager::isDOSType(const QString &strOSTypeId)
269{
270 if ( strOSTypeId.left(3) == "dos"
271 || strOSTypeId.left(3) == "win"
272 || strOSTypeId.left(3) == "os2")
273 return true;
274
275 return false;
276}
277
278/*********************************************************************************************************************************
279* UIGuestOSType implementaion. *
280*********************************************************************************************************************************/
281
282UIGuestOSType::UIGuestOSType()
283{
284}
285
286UIGuestOSType::UIGuestOSType(const CGuestOSType &comGuestOSType)
287 : m_comGuestOSType(comGuestOSType)
288{
289}
290
291bool UIGuestOSType::isOk() const
292{
293 return (!m_comGuestOSType.isNull() && m_comGuestOSType.isOk());
294}
295
296const QString &UIGuestOSType::getFamilyId() const
297{
298 if (m_strFamilyId.isEmpty() && m_comGuestOSType.isOk())
299 m_strFamilyId = m_comGuestOSType.GetFamilyId();
300 return m_strFamilyId;
301}
302
303const QString &UIGuestOSType::getFamilyDescription() const
304{
305 if (m_strFamilyDescription.isEmpty() && m_comGuestOSType.isOk())
306 m_strFamilyDescription = m_comGuestOSType.GetFamilyDescription();
307 return m_strFamilyDescription;
308}
309
310const QString &UIGuestOSType::getId() const
311{
312 if (m_strId.isEmpty() && m_comGuestOSType.isOk())
313 m_strId = m_comGuestOSType.GetId();
314 return m_strId;
315}
316
317const QString &UIGuestOSType::getSubtype() const
318{
319 if (m_strSubtype.isEmpty() && m_comGuestOSType.isOk())
320 m_strSubtype = m_comGuestOSType.GetSubtype();
321 return m_strSubtype;
322}
323
324const QString &UIGuestOSType::getDescription() const
325{
326 if (m_strDescription.isEmpty() && m_comGuestOSType.isOk())
327 m_strDescription = m_comGuestOSType.GetDescription();
328 return m_strDescription;
329}
330
331KStorageBus UIGuestOSType::getRecommendedHDStorageBus() const
332{
333 if (m_comGuestOSType.isOk())
334 return m_comGuestOSType.GetRecommendedHDStorageBus();
335 return KStorageBus_Null;
336}
337
338ULONG UIGuestOSType::getRecommendedRAM() const
339{
340 if (m_comGuestOSType.isOk())
341 return m_comGuestOSType.GetRecommendedRAM();
342 return 0;
343}
344
345KStorageBus UIGuestOSType::getRecommendedDVDStorageBus() const
346{
347 if (m_comGuestOSType.isOk())
348 return m_comGuestOSType.GetRecommendedDVDStorageBus();
349 return KStorageBus_Null;
350}
351
352ULONG UIGuestOSType::getRecommendedCPUCount() const
353{
354 if (m_comGuestOSType.isOk())
355 return m_comGuestOSType.GetRecommendedCPUCount();
356 return 0;
357}
358
359KFirmwareType UIGuestOSType::getRecommendedFirmware() const
360{
361 if (m_comGuestOSType.isOk())
362 return m_comGuestOSType.GetRecommendedFirmware();
363 return KFirmwareType_Max;
364}
365
366bool UIGuestOSType::getRecommendedFloppy() const
367{
368 if (m_comGuestOSType.isOk())
369 return m_comGuestOSType.GetRecommendedFloppy();
370 return false;
371}
372
373LONG64 UIGuestOSType::getRecommendedHDD() const
374{
375 if (m_comGuestOSType.isOk())
376 return m_comGuestOSType.GetRecommendedHDD();
377 return 0;
378}
379
380KGraphicsControllerType UIGuestOSType::getRecommendedGraphicsController() const
381{
382 if (m_comGuestOSType.isOk())
383 return m_comGuestOSType.GetRecommendedGraphicsController();
384 return KGraphicsControllerType_Null;
385}
386
387KStorageControllerType UIGuestOSType::getRecommendedDVDStorageController() const
388{
389 if (m_comGuestOSType.isOk())
390 return m_comGuestOSType.GetRecommendedDVDStorageController();
391 return KStorageControllerType_Null;
392}
393
394bool UIGuestOSType::is64Bit() const
395{
396 if (m_comGuestOSType.isOk())
397 return m_comGuestOSType.GetIs64Bit();
398 return false;
399}
400
401KPlatformArchitecture UIGuestOSType::getPlatformArchitecture() const
402{
403 if (m_comGuestOSType.isOk())
404 return m_comGuestOSType.GetPlatformArchitecture();
405 return KPlatformArchitecture_Max;
406}
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