7#include "windevicemanager.h"
11#include "windevicemanager_p.h"
12#include "winprocessor.h"
13#include <solid/deviceinterface.h>
17using namespace Solid::Backends::Win;
19Q_GLOBAL_STATIC(SolidWinEventFilter, solidWineventFilter)
21SolidWinEventFilter *SolidWinEventFilter::instance()
23 return solidWineventFilter;
26SolidWinEventFilter::SolidWinEventFilter()
29 wchar_t title[] = L
"KDEWinDeviceManager";
32 ZeroMemory(&wcex,
sizeof(wcex));
33 wcex.cbSize =
sizeof(WNDCLASSEX);
34 wcex.lpfnWndProc = SolidWinEventFilter::WndProc;
35 wcex.hInstance = (HINSTANCE)::GetModuleHandle(NULL);
36 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
37 wcex.lpszClassName = title;
38 if (RegisterClassEx(&wcex) == 0) {
39 qWarning() <<
"Failed to initialize KDEWinDeviceManager we will be unable to detect device changes";
43 m_windowID = CreateWindow(title,
54 if (m_windowID == NULL) {
55 qWarning() <<
"Failed to initialize KDEWinDeviceManager we will be unable to detect device changes";
58 ShowWindow(m_windowID, SW_HIDE);
61SolidWinEventFilter::~SolidWinEventFilter()
63 PostMessage(m_windowID, WM_CLOSE, 0, 0);
66void SolidWinEventFilter::promoteAddedDevice(
const QSet<QString> &udi)
68 Q_EMIT deviceAdded(udi);
71void SolidWinEventFilter::promoteRemovedDevice(
const QSet<QString> &udi)
73 Q_EMIT deviceRemoved(udi);
76void SolidWinEventFilter::promotePowerChange()
78 Q_EMIT powerChanged();
81LRESULT CALLBACK SolidWinEventFilter::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
85 case WM_DEVICECHANGE: {
86 if ((wParam == DBT_DEVICEARRIVAL) || (wParam == DBT_DEVICEREMOVECOMPLETE)) {
87 DEV_BROADCAST_HDR *header =
reinterpret_cast<DEV_BROADCAST_HDR *
>(lParam);
88 if (header->dbch_devicetype == DBT_DEVTYP_VOLUME) {
89 DEV_BROADCAST_VOLUME *devNot =
reinterpret_cast<DEV_BROADCAST_VOLUME *
>(lParam);
91 case DBT_DEVICEREMOVECOMPLETE: {
92 QSet<QString> udis = WinBlock::getFromBitMask(devNot->dbcv_unitmask);
93 solidWineventFilter->promoteRemovedDevice(udis);
96 case DBT_DEVICEARRIVAL: {
97 QSet<QString> udis = WinBlock::updateUdiFromBitMask(devNot->dbcv_unitmask);
98 solidWineventFilter->promoteAddedDevice(udis);
107 case WM_POWERBROADCAST: {
108 solidWineventFilter->promotePowerChange();
116 return DefWindowProc(hWnd, message, wParam, lParam);
121WinDeviceManager::WinDeviceManager(
QObject *parent)
122 : DeviceManager(parent)
128 m_supportedInterfaces << Solid::DeviceInterface::GenericInterface
130 << Solid::DeviceInterface::StorageAccess
131 << Solid::DeviceInterface::StorageDrive
132 << Solid::DeviceInterface::OpticalDrive
133 << Solid::DeviceInterface::StorageVolume
134 << Solid::DeviceInterface::OpticalDisc
135 << Solid::DeviceInterface::Processor
136 << Solid::DeviceInterface::Battery;
142WinDeviceManager::~WinDeviceManager()
146QString WinDeviceManager::udiPrefix()
const
153 return m_supportedInterfaces;
158 return m_devicesList;
166 for (
const QString &udi : deviceList) {
167 WinDevice device(udi);
168 if (device.type() == type && device.parentUdi() == parentUdi) {
172 }
else if (type != Solid::DeviceInterface::Unknown) {
173 for (
const QString &udi : deviceList) {
174 WinDevice device(udi);
175 if (device.queryDeviceInterface(type)) {
185QObject *Solid::Backends::Win::WinDeviceManager::createDevice(
const QString &udi)
187 if (allDevices().contains(udi)) {
188 return new WinDevice(udi);
194void WinDeviceManager::slotDeviceAdded(
const QSet<QString> &udi)
198 m_devicesList =
QStringList(m_devices.begin(), m_devices.end());
199 std::sort(m_devicesList.
begin(), m_devicesList.
end());
200 for (
const QString &str : tmp) {
205void WinDeviceManager::slotDeviceRemoved(
const QSet<QString> &udi)
208 m_devicesList =
QStringList(m_devices.begin(), m_devices.end());
209 std::sort(m_devicesList.
begin(), m_devicesList.
end());
210 for (
const QString &str : udi) {
215void WinDeviceManager::updateDeviceList()
218 devices += WinBlock::getUdis();
219 devices += WinBattery::getUdis();
222 m_devicesList =
QStringList(m_devices.begin(), m_devices.end());
223 std::sort(m_devicesList.
begin(), m_devicesList.
end());
226#include "moc_windevicemanager.cpp"
227#include "moc_windevicemanager_p.cpp"
Type
This enum type defines the type of device interface that a Device can have.
void deviceAdded(const QString &udi)
This signal is emitted when a new device appears in the system.
void deviceRemoved(const QString &udi)
This signal is emitted when a device disappears from the system.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)