VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp@ 104158

Last change on this file since 104158 was 103771, checked in by vboxsync, 9 months ago

FE/Qt: UICommon: Switching dependency from UICommon to UIGlobalSession whenever is possible.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp58652,​70973
    /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp66309,​66318
    /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp70873
    /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp74233
    /branches/VBox-4.2/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp91223
    /branches/VBox-4.3/trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp91223
    /branches/dsen/gui/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp79645-79692
File size: 4.5 KB
Line 
1/* $Id: UIMediumDefs.cpp 103771 2024-03-11 15:16:04Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMedium related implementations.
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 "UIGlobalSession.h"
30#include "UIMediumDefs.h"
31
32/* COM includes: */
33#include "CMediumFormat.h"
34#include "CSystemProperties.h"
35
36/* COM includes: */
37#include "CMediumFormat.h"
38#include "CSystemProperties.h"
39#include "CVirtualBox.h"
40
41
42/* Convert global medium type (KDeviceType) to local (UIMediumDeviceType): */
43UIMediumDeviceType UIMediumDefs::mediumTypeToLocal(KDeviceType globalType)
44{
45 switch (globalType)
46 {
47 case KDeviceType_HardDisk:
48 return UIMediumDeviceType_HardDisk;
49 case KDeviceType_DVD:
50 return UIMediumDeviceType_DVD;
51 case KDeviceType_Floppy:
52 return UIMediumDeviceType_Floppy;
53 default:
54 break;
55 }
56 return UIMediumDeviceType_Invalid;
57}
58
59/* Convert local medium type (UIMediumDeviceType) to global (KDeviceType): */
60KDeviceType UIMediumDefs::mediumTypeToGlobal(UIMediumDeviceType localType)
61{
62 switch (localType)
63 {
64 case UIMediumDeviceType_HardDisk:
65 return KDeviceType_HardDisk;
66 case UIMediumDeviceType_DVD:
67 return KDeviceType_DVD;
68 case UIMediumDeviceType_Floppy:
69 return KDeviceType_Floppy;
70 default:
71 break;
72 }
73 return KDeviceType_Null;
74}
75
76QList<QPair<QString, QString> > UIMediumDefs::MediumBackends(const CVirtualBox &comVBox, KDeviceType enmType)
77{
78 /* Prepare a list of pairs with the form <tt>{"Backend Name", "*.suffix1 .suffix2 ..."}</tt>. */
79 const CSystemProperties comSystemProperties = comVBox.GetSystemProperties();
80 QVector<CMediumFormat> mediumFormats = comSystemProperties.GetMediumFormats();
81 QList<QPair<QString, QString> > backendPropList;
82 for (int i = 0; i < mediumFormats.size(); ++i)
83 {
84 /* Acquire file extensions & device types: */
85 QVector<QString> fileExtensions;
86 QVector<KDeviceType> deviceTypes;
87 mediumFormats[i].DescribeFileExtensions(fileExtensions, deviceTypes);
88
89 /* Compose filters list: */
90 QStringList filters;
91 for (int iExtensionIndex = 0; iExtensionIndex < fileExtensions.size(); ++iExtensionIndex)
92 if (deviceTypes[iExtensionIndex] == enmType)
93 filters << QString("*.%1").arg(fileExtensions[iExtensionIndex]);
94 /* Create a pair out of the backend description and all suffix's. */
95 if (!filters.isEmpty())
96 backendPropList << QPair<QString, QString>(mediumFormats[i].GetName(), filters.join(" "));
97 }
98 return backendPropList;
99}
100
101QList<QPair<QString, QString> > UIMediumDefs::HDDBackends(const CVirtualBox &comVBox)
102{
103 return MediumBackends(comVBox, KDeviceType_HardDisk);
104}
105
106QList<QPair<QString, QString> > UIMediumDefs::DVDBackends(const CVirtualBox &comVBox)
107{
108 return MediumBackends(comVBox, KDeviceType_DVD);
109}
110
111QList<QPair<QString, QString> > UIMediumDefs::FloppyBackends(const CVirtualBox &comVBox)
112{
113 return MediumBackends(comVBox, KDeviceType_Floppy);
114}
115
116QString UIMediumDefs::getPreferredExtensionForMedium(KDeviceType enmDeviceType)
117{
118 CSystemProperties comSystemProperties = gpGlobalSession->virtualBox().GetSystemProperties();
119 QVector<CMediumFormat> mediumFormats = comSystemProperties.GetMediumFormats();
120 for (int i = 0; i < mediumFormats.size(); ++i)
121 {
122 /* File extensions */
123 QVector <QString> fileExtensions;
124 QVector <KDeviceType> deviceTypes;
125
126 mediumFormats[i].DescribeFileExtensions(fileExtensions, deviceTypes);
127 if (fileExtensions.size() != deviceTypes.size())
128 continue;
129 for (int a = 0; a < fileExtensions.size(); ++a)
130 {
131 if (deviceTypes[a] == enmDeviceType)
132 return fileExtensions[a];
133 }
134 }
135 return QString();
136}
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