8#include <solid/deviceinterface.h>
10#include "winbattery.h"
12#include "wingenericinterface.h"
13#include "winopticaldisc.h"
14#include "winopticaldrive.h"
15#include "winprocessor.h"
16#include "winstorageaccess.h"
17#include "winstoragedrive.h"
18#include "winstoragevolume.h"
22#if defined(__MINGW32__) && !defined(IOCTL_STORAGE_QUERY_PROPERTY)
23#include <winioctl_backport.h>
26using namespace Solid::Backends::Win;
28WinDevice::WinDevice(
const QString &udi)
42 m_type = Solid::DeviceInterface::StorageDrive;
44 m_type = Solid::DeviceInterface::StorageVolume;
46 m_type = Solid::DeviceInterface::OpticalDrive;
48 m_type = Solid::DeviceInterface::OpticalDisc;
50 m_type = Solid::DeviceInterface::Processor;
52 m_type = Solid::DeviceInterface::Battery;
54 m_type = Solid::DeviceInterface::StorageAccess;
58 case Solid::DeviceInterface::StorageVolume: {
59 m_parentUdi =
QLatin1String(
"/org/kde/solid/win/storage/") + parentName;
62 case Solid::DeviceInterface::OpticalDisc: {
63 m_parentUdi =
QLatin1String(
"/org/kde/solid/win/storage.cdrom/") + parentName;
66 case Solid::DeviceInterface::StorageAccess: {
67 m_parentUdi = WinBlock::udiFromDriveLetter(WinBlock::resolveVirtualDrive(udi).mid(0, 2));
68 if (m_parentUdi.isEmpty()) {
78 case Solid::DeviceInterface::Processor:
81 case Solid::DeviceInterface::Battery:
85 if (queryDeviceInterface(Solid::DeviceInterface::StorageAccess) || queryDeviceInterface(Solid::DeviceInterface::StorageDrive)) {
88 qWarning() <<
"Unknown device" << udi;
93void WinDevice::initStorageDevice()
97 case Solid::DeviceInterface::StorageAccess:
98 dev = WinBlock::driveLetterFromUdi(udi());
99 m_product = QStringLiteral(
"Virtual drive %1").
arg(dev);
100 m_description = QStringLiteral(
"%1 (%2)").
arg(dev, WinBlock::resolveVirtualDrive(udi()));
102 case Solid::DeviceInterface::OpticalDrive:
103 dev = WinBlock::driveLetterFromUdi(udi());
105 case Solid::DeviceInterface::StorageDrive:
106 dev = QStringLiteral(
"PhysicalDrive%1").
arg(WinBlock(
this).deviceMajor());
109 dev = WinBlock::driveLetterFromUdi(udi());
112 m_description = QStringLiteral(
"%1 (%2)").
arg(dev, label);
118 STORAGE_PROPERTY_QUERY
query;
119 ZeroMemory(&query,
sizeof(STORAGE_PROPERTY_QUERY));
120 query.PropertyId = StorageDeviceProperty;
121 query.QueryType = PropertyStandardQuery;
124 WinDeviceManager::getDeviceInfo<char, STORAGE_PROPERTY_QUERY>(dev, IOCTL_STORAGE_QUERY_PROPERTY, buff, 1024, &query);
125 STORAGE_DEVICE_DESCRIPTOR *info = ((STORAGE_DEVICE_DESCRIPTOR *)buff);
126 if (info->VendorIdOffset != 0) {
128 if (info->ProductIdOffset != 0) {
131 }
else if (info->ProductIdOffset != 0) {
138void WinDevice::initBatteryDevice()
140 WinBattery::Battery battery = WinBattery::batteryInfoFromUdi(m_udi);
141 BATTERY_QUERY_INFORMATION
query;
142 ZeroMemory(&query,
sizeof(query));
143 query.BatteryTag = battery.second;
148 query.InformationLevel = BatteryDeviceName;
149 WinDeviceManager::getDeviceInfo<wchar_t, BATTERY_QUERY_INFORMATION>(battery.first, IOCTL_BATTERY_QUERY_INFORMATION, buff, size, &query);
152 query.InformationLevel = BatteryManufactureName;
153 WinDeviceManager::getDeviceInfo<wchar_t, BATTERY_QUERY_INFORMATION>(battery.first, IOCTL_BATTERY_QUERY_INFORMATION, buff, size, &query);
156 switch (WinBattery(
this).technology()) {
157 case Solid::Battery::LithiumIon:
158 m_description =
tr(
"Lithium Ion",
"battery technology");
160 case Solid::Battery::LeadAcid:
161 m_description =
tr(
"Lead Acid",
"battery technology");
163 case Solid::Battery::NickelCadmium:
164 m_description =
tr(
"Nickel Cadmium",
"battery technology");
166 case Solid::Battery::NickelMetalHydride:
167 m_description =
tr(
"Nickel Metal Hydride",
"battery technology");
170 m_description =
tr(
"Unknown",
"battery technology");
174void WinDevice::initCpuDevice()
176 WinProcessor cpu(
this);
177 WinProcessor::ProcessorInfo info = WinProcessor::updateCache()[cpu.number()];
178 m_vendor = info.vendor;
179 m_product = info.produuct;
180 m_description = info.name;
188QString WinDevice::parentUdi()
const
193QString WinDevice::vendor()
const
198QString WinDevice::product()
const
203QString WinDevice::description()
const
205 return m_description.
isEmpty() ? m_product : m_description;
210 if (parentUdi().isEmpty()) {
216 case Solid::DeviceInterface::OpticalDrive:
219 case Solid::DeviceInterface::OpticalDisc: {
220 WinOpticalDisc disk(
const_cast<WinDevice *
>(
this));
221 if (disk.availableContent() & Solid::OpticalDisc::Audio) {
228 case Solid::DeviceInterface::StorageDrive:
229 case Solid::DeviceInterface::StorageVolume: {
230 WinStorageDrive storage(
const_cast<WinDevice *
>(
this));
231 if (storage.bus() == Solid::StorageDrive::Usb) {
238 case Solid::DeviceInterface::Processor:
241 case Solid::DeviceInterface::Battery:
244 case Solid::DeviceInterface::StorageAccess:
257 case Solid::DeviceInterface::StorageAccess:
268 if (queryType == Solid::DeviceInterface::GenericInterface) {
273 interfaceList <<
type();
276 case Solid::DeviceInterface::GenericInterface:
278 case Solid::DeviceInterface::Block:
280 case Solid::DeviceInterface::StorageAccess:
282 case Solid::DeviceInterface::StorageDrive:
284 case Solid::DeviceInterface::OpticalDrive:
285 interfaceList << Solid::DeviceInterface::Block << Solid::DeviceInterface::StorageDrive;
287 case Solid::DeviceInterface::StorageVolume:
288 interfaceList << Solid::DeviceInterface::Block << Solid::DeviceInterface::StorageAccess;
290 case Solid::DeviceInterface::OpticalDisc:
291 interfaceList << Solid::DeviceInterface::Block << Solid::DeviceInterface::StorageVolume << Solid::DeviceInterface::StorageAccess;
293 case Solid::DeviceInterface::PortableMediaPlayer:
295 case Solid::DeviceInterface::Unknown:
296 case Solid::DeviceInterface::Last:
301 if (interfaceList.
size() == 0) {
302 qWarning() <<
"no interface found for type" <<
type();
304 return interfaceList.
contains(queryType);
309 if (!queryDeviceInterface(type)) {
312 WinInterface *iface = 0;
315 case Solid::DeviceInterface::GenericInterface:
316 iface =
new WinGenericInterface(
this);
318 case Solid::DeviceInterface::Block:
319 iface =
new WinBlock(
this);
321 case Solid::DeviceInterface::Processor:
322 iface =
new WinProcessor(
this);
324 case Solid::DeviceInterface::StorageAccess:
325 iface =
new WinStorageAccess(
this);
327 case Solid::DeviceInterface::StorageDrive:
328 iface =
new WinStorageDrive(
this);
330 case Solid::DeviceInterface::OpticalDrive:
331 iface =
new WinOpticalDrive(
this);
333 case Solid::DeviceInterface::StorageVolume:
334 iface =
new WinStorageVolume(
this);
336 case Solid::DeviceInterface::OpticalDisc:
337 iface =
new WinOpticalDisc(
this);
342 case Solid::DeviceInterface::Battery:
343 iface =
new WinBattery(
this);
345 case Solid::DeviceInterface::Unknown:
346 case Solid::DeviceInterface::Last:
360#include "moc_windevice.cpp"
Base class of all the device interfaces.
Type
This enum type defines the type of device interface that a Device can have.
This class allows applications to deal with devices available in the underlying system.
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString label(StandardShortcut id)
bool contains(const AT &value) const const
qsizetype size() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
QString fromWCharArray(const wchar_t *string, qsizetype size)
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString trimmed() const const
QString join(QChar separator) const const