Solid

winopticaldrive.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Patrick von Reth <vonreth@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "winopticaldrive.h"
8
9#include <ntddcdrm.h>
10#include <ntddmmc.h>
11
12using namespace Solid::Backends::Win;
13
14WinOpticalDrive::WinOpticalDrive(WinDevice *device)
15 : WinStorageDrive(device)
16{
17 const QMap<ulong, MediaProfiles> profiles = MediaProfiles::profiles(WinBlock::driveLetterFromUdi(m_device->udi()));
18 for (const MediaProfiles &p : profiles) {
19 m_supportedTypes |= p.type;
20 }
21}
22
23WinOpticalDrive::~WinOpticalDrive()
24{
25}
26
27Solid::OpticalDrive::MediumTypes WinOpticalDrive::supportedMedia() const
28{
29 return m_supportedTypes;
30}
31
32bool WinOpticalDrive::eject()
33{
34 WinDeviceManager::deviceAction(WinBlock::driveLetterFromUdi(m_device->udi()), IOCTL_STORAGE_EJECT_MEDIA);
35 return true;
36}
37
38QList<int> WinOpticalDrive::writeSpeeds() const
39{
40 return QList<int>();
41}
42
43int WinOpticalDrive::writeSpeed() const
44{
45 return 0;
46}
47
48int WinOpticalDrive::readSpeed() const
49{
50 return 0;
51}
52
53MediaProfiles::MediaProfiles()
54 : profile(0)
55 , type(0)
56 , active(false)
57{
58}
59
60MediaProfiles::MediaProfiles(ulong profile, Solid::OpticalDrive::MediumTypes type, QString name)
61 : profile(profile)
62 , type(type)
63 , name(name)
64 , active(false)
65{
66}
67
68MediaProfiles::MediaProfiles(FEATURE_DATA_PROFILE_LIST_EX *feature)
69 : profile(0)
70 , type(0)
71 , active(false)
72{
73 ulong val = (feature->ProfileNumber[0] << 8 | feature->ProfileNumber[1] << 0);
74 MediaProfiles p = MediaProfiles::getProfile(val);
75 if (!p.isNull()) {
76 profile = p.profile;
77 type = p.type;
78 name = p.name;
79 active = feature->Current;
80 }
81}
82
83bool MediaProfiles::isNull()
84{
85 return name.isNull();
86}
87
88QMap<ulong, MediaProfiles> MediaProfiles::profiles(const QString &drive)
89{
90 // thx to http://www.adras.com/Determine-optical-drive-type-and-capabilities.t6826-144-1.html
91
93 DWORD buffSize = 1024;
94 char buffer[1024];
95 GET_CONFIGURATION_IOCTL_INPUT input;
96 ZeroMemory(&input, sizeof(GET_CONFIGURATION_IOCTL_INPUT));
97 input.Feature = FeatureProfileList;
98 input.RequestType = SCSI_GET_CONFIGURATION_REQUEST_TYPE_ALL;
99
100 WinDeviceManager::getDeviceInfo<char, GET_CONFIGURATION_IOCTL_INPUT>(drive, IOCTL_CDROM_GET_CONFIGURATION, buffer, buffSize, &input);
101
102 GET_CONFIGURATION_HEADER *info = (GET_CONFIGURATION_HEADER *)buffer;
103 FEATURE_DATA_PROFILE_LIST *profile = (FEATURE_DATA_PROFILE_LIST *)info->Data;
104 FEATURE_DATA_PROFILE_LIST_EX *feature = profile->Profiles;
105 for (int i = 0; i < profile->Header.AdditionalLength / 4; ++feature, ++i) {
106 MediaProfiles p = MediaProfiles(feature);
107 if (!p.isNull()) {
108 out.insert(p.profile, p);
109 }
110 }
111
112 return out;
113}
114
115const MediaProfiles MediaProfiles::getProfile(ulong val)
116{
117#define AddProfile(profile, type) profiles.insert(profile, MediaProfiles(profile, type, QString::fromLatin1(#profile)))
118 static QMap<ulong, MediaProfiles> profiles;
119 if (profiles.isEmpty()) {
120 AddProfile(ProfileCdrom, Solid::OpticalDrive::UnknownMediumType);
121 AddProfile(ProfileCdRecordable, Solid::OpticalDrive::Cdr);
122 AddProfile(ProfileCdRewritable, Solid::OpticalDrive::Cdrw);
123 AddProfile(ProfileDvdRom, Solid::OpticalDrive::Dvd);
124 AddProfile(ProfileDvdRecordable, Solid::OpticalDrive::Dvdr);
125 AddProfile(ProfileDvdRewritable, Solid::OpticalDrive::Dvdrw);
126 AddProfile(ProfileDvdRam, Solid::OpticalDrive::Dvdram);
127 AddProfile(ProfileDvdPlusR, Solid::OpticalDrive::Dvdplusr);
128 AddProfile(ProfileDvdPlusRW, Solid::OpticalDrive::Dvdplusrw);
129 AddProfile(ProfileDvdPlusRDualLayer, Solid::OpticalDrive::Dvdplusdl);
130 AddProfile(ProfileDvdPlusRWDualLayer, Solid::OpticalDrive::Dvdplusdlrw);
131 AddProfile(ProfileBDRom, Solid::OpticalDrive::Bd);
132 AddProfile(ProfileBDRRandomWritable, Solid::OpticalDrive::Bdr);
133 AddProfile(ProfileBDRSequentialWritable, Solid::OpticalDrive::Bdr);
134 AddProfile(ProfileBDRewritable, Solid::OpticalDrive::Bdre);
135 AddProfile(ProfileHDDVDRom, Solid::OpticalDrive::HdDvd);
136 AddProfile(ProfileHDDVDRecordable, Solid::OpticalDrive::HdDvdr);
137 AddProfile(ProfileHDDVDRewritable, Solid::OpticalDrive::HdDvdrw);
138 }
139 return profiles[val];
140}
141
142#include "moc_winopticaldrive.cpp"
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
bool isNull() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.