Clementine-audio-player-Mac.../src/devices/wmdmlister.h

111 lines
2.8 KiB
C
Raw Normal View History

/* This file is part of Clementine.
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WMDMLISTER_H
#define WMDMLISTER_H
#include "devicelister.h"
2010-08-16 01:26:04 +02:00
struct IWMDMDevice;
struct IWMDMStorage;
2010-08-16 01:26:04 +02:00
struct IWMDeviceManager;
#include <QMap>
#include <QMutex>
#include <QPixmap>
2010-08-22 17:26:59 +02:00
#include <mswmdm.h>
2010-08-22 17:42:21 +02:00
#include <sac_shim.h>
2010-08-22 17:26:59 +02:00
#undef LoadIcon
class WmdmLister : public DeviceLister, public IWMDMNotification {
Q_OBJECT
public:
WmdmLister();
2010-08-22 17:26:59 +02:00
// DeviceLister
virtual void Init();
virtual QStringList DeviceUniqueIDs();
2010-08-16 01:26:04 +02:00
virtual QVariantList DeviceIcons(const QString& id);
virtual QString DeviceManufacturer(const QString& id);
virtual QString DeviceModel(const QString& id);
virtual quint64 DeviceCapacity(const QString& id);
virtual quint64 DeviceFreeSpace(const QString& id);
virtual QVariantMap DeviceHardwareInfo(const QString& id);
virtual QString MakeFriendlyName(const QString& id);
virtual QList<QUrl> MakeDeviceUrls(const QString& id);
virtual void UnmountDevice(const QString& id);
2010-08-22 17:26:59 +02:00
// IWMDMNotification
// The __stdcall is *really* important
virtual HRESULT __stdcall WMDMMessage(DWORD message_type, LPCWSTR name);
virtual LONG __stdcall QueryInterface(const IID& riid, void** object);
virtual ULONG __stdcall AddRef();
virtual ULONG __stdcall Release();
public slots:
2010-08-16 01:26:04 +02:00
virtual void UpdateDeviceFreeSpace(const QString& id);
2010-08-22 17:42:21 +02:00
virtual void ShutDown();
2010-08-16 01:26:04 +02:00
private:
struct DeviceInfo {
DeviceInfo() : device_(NULL), storage_(NULL), is_suitable_(false),
total_bytes_(0), free_bytes_(0) {}
2010-08-16 01:26:04 +02:00
QString unique_id() const;
IWMDMDevice* device_;
IWMDMStorage* storage_;
2010-08-16 01:26:04 +02:00
bool is_suitable_;
QString name_;
QString manufacturer_;
QPixmap icon_;
quint64 total_bytes_;
quint64 free_bytes_;
2010-08-16 01:26:04 +02:00
};
DeviceInfo ReadDeviceInfo(IWMDMDevice* device);
template <typename T>
T LockAndGetDeviceInfo(const QString& id, T DeviceInfo::*field);
private:
IWMDeviceManager* device_manager_;
2010-08-22 17:42:21 +02:00
SacHandle sac_;
2010-08-22 17:26:59 +02:00
DWORD notification_cookie_;
2010-08-16 01:26:04 +02:00
QMutex mutex_;
QMap<QString, DeviceInfo> devices_;
};
2010-08-16 01:26:04 +02:00
template <typename T>
T WmdmLister::LockAndGetDeviceInfo(const QString& id, T DeviceInfo::*field) {
QMutexLocker l(&mutex_);
if (!devices_.contains(id))
return T();
return devices_[id].*field;
}
#endif // WMDMLISTER_H