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

107 lines
2.9 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 DEVICEKITLISTER_H
#define DEVICEKITLISTER_H
#include <memory>
#include <QMutex>
#include <QStringList>
#include "devicelister.h"
class OrgFreedesktopUDisksInterface;
class QDBusObjectPath;
class DeviceKitLister : public DeviceLister {
Q_OBJECT
public:
DeviceKitLister();
~DeviceKitLister();
QStringList DeviceUniqueIDs();
2010-08-16 01:26:04 +02:00
QVariantList DeviceIcons(const QString& id);
2010-07-04 17:01:24 +02:00
QString DeviceManufacturer(const QString& id);
QString DeviceModel(const QString& id);
quint64 DeviceCapacity(const QString& id);
quint64 DeviceFreeSpace(const QString& id);
QVariantMap DeviceHardwareInfo(const QString& id);
QString MakeFriendlyName(const QString& id);
QList<QUrl> MakeDeviceUrls(const QString& id);
2010-06-26 01:38:21 +02:00
void UnmountDevice(const QString& id);
public slots:
void UpdateDeviceFreeSpace(const QString& id);
protected:
void Init();
private slots:
void DBusDeviceAdded(const QDBusObjectPath& path);
void DBusDeviceRemoved(const QDBusObjectPath& path);
void DBusDeviceChanged(const QDBusObjectPath& path);
private:
struct DeviceData {
2010-07-29 20:14:26 +02:00
DeviceData() : suitable(false), device_size(0), free_space(0) {}
QString unique_id() const;
bool suitable;
QString dbus_path;
QString drive_serial;
QString drive_model;
QString drive_vendor;
2010-07-04 17:01:24 +02:00
QString device_file;
QString device_presentation_name;
QString device_presentation_icon_name;
QStringList device_mount_paths;
quint64 device_size;
2010-07-29 20:14:26 +02:00
quint64 free_space;
};
DeviceData ReadDeviceData(const QDBusObjectPath& path) const;
// You MUST hold the mutex while calling this function
QString FindUniqueIdByPath(const QDBusObjectPath& path) const;
2010-07-04 17:01:24 +02:00
template <typename T>
T LockAndGetDeviceInfo(const QString& id, T DeviceData::*field);
private:
std::unique_ptr<OrgFreedesktopUDisksInterface> interface_;
QMutex mutex_;
QMap<QString, DeviceData> device_data_;
};
2010-07-04 17:01:24 +02:00
template <typename T>
T DeviceKitLister::LockAndGetDeviceInfo(const QString& id,
T DeviceData::*field) {
2010-07-04 17:01:24 +02:00
QMutexLocker l(&mutex_);
if (!device_data_.contains(id)) return T();
2010-07-04 17:01:24 +02:00
return device_data_[id].*field;
}
#endif // DEVICEKITLISTER_H