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

142 lines
3.7 KiB
C
Raw Normal View History

/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
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
#include <QMap>
#include <QMutex>
#include <QPixmap>
#include <QUuid>
2010-08-16 01:26:04 +02:00
2010-08-22 21:18:22 +02:00
#include <boost/scoped_ptr.hpp>
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
2010-08-22 21:18:22 +02:00
class WmdmThread;
2010-08-22 17:26:59 +02:00
class WmdmLister : public DeviceLister, public IWMDMNotification {
Q_OBJECT
public:
WmdmLister();
2010-08-22 21:18:22 +02:00
~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();
2010-08-22 21:18:22 +02:00
// Called by WmdmLister
QString DeviceCanonicalName(const QString& id);
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 slots:
2010-08-30 19:23:24 +02:00
virtual void DoUpdateDriveFreeSpace(const QString& id);
virtual void ReallyShutdown();
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;
IWMDMDevice2* device_;
IWMDMStorage2* storage_;
2010-08-16 01:26:04 +02:00
bool is_suitable_;
QString name_;
QString manufacturer_;
QString canonical_name_;
2010-08-16 01:26:04 +02:00
QPixmap icon_;
quint64 total_bytes_;
quint64 free_bytes_;
// Only valid for filesystem devices
QString mount_point_;
QString fs_name_;
QString fs_type_;
int fs_serial_;
// Information we get by querying win7-style FS devices
QString device_name_;
QString volume_name_;
2010-08-16 01:26:04 +02:00
};
static const QUuid kDeviceProtocolMsc;
DeviceInfo ReadDeviceInfo(IWMDMDevice2* device);
2010-08-16 01:26:04 +02:00
template <typename T>
T LockAndGetDeviceInfo(const QString& id, T DeviceInfo::*field);
2010-08-30 19:23:24 +02:00
void UpdateFreeSpace(DeviceInfo* info);
void GuessDriveLetter(DeviceInfo* info);
bool CheckDriveLetter(DeviceInfo* info, const QString& drive);
2010-08-30 19:23:24 +02:00
2010-08-22 18:25:22 +02:00
static QString CanonicalNameToId(const QString& canonical_name);
void WMDMDeviceAdded(const QString& canonical_name);
void WMDMDeviceRemoved(const QString& canonical_name);
2010-08-16 01:26:04 +02:00
private:
2010-08-22 21:18:22 +02:00
boost::scoped_ptr<WmdmThread> thread_;
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