2010-06-25 21:04:10 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-06-25 21:04:10 +02:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2010-06-26 00:36:21 +02:00
|
|
|
#ifndef DEVICEKITLISTER_H
|
|
|
|
#define DEVICEKITLISTER_H
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2010-06-26 00:01:47 +02:00
|
|
|
#include <QMutex>
|
2010-06-25 21:04:10 +02:00
|
|
|
#include <QStringList>
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include "devicelister.h"
|
2010-06-25 21:04:10 +02:00
|
|
|
|
|
|
|
class OrgFreedesktopUDisksInterface;
|
|
|
|
|
|
|
|
class QDBusObjectPath;
|
|
|
|
|
2010-06-26 00:36:21 +02:00
|
|
|
class DeviceKitLister : public DeviceLister {
|
2010-06-25 21:04:10 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2010-06-26 00:36:21 +02:00
|
|
|
DeviceKitLister();
|
|
|
|
~DeviceKitLister();
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2010-06-26 00:01:47 +02:00
|
|
|
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);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QString MakeFriendlyName(const QString& id);
|
|
|
|
QList<QUrl> MakeDeviceUrls(const QString& id);
|
2010-06-26 01:38:21 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void UnmountDevice(const QString& id);
|
2010-07-25 03:07:51 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2010-08-11 20:47:53 +02:00
|
|
|
void UpdateDeviceFreeSpace(const QString& id);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2010-06-26 00:01:47 +02:00
|
|
|
void Init();
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2010-06-26 00:01:47 +02:00
|
|
|
void DBusDeviceAdded(const QDBusObjectPath& path);
|
|
|
|
void DBusDeviceRemoved(const QDBusObjectPath& path);
|
|
|
|
void DBusDeviceChanged(const QDBusObjectPath& path);
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-06-26 00:01:47 +02:00
|
|
|
struct DeviceData {
|
2010-07-29 20:14:26 +02:00
|
|
|
DeviceData() : suitable(false), device_size(0), free_space(0) {}
|
2010-06-26 00:01:47 +02:00
|
|
|
|
|
|
|
QString unique_id() const;
|
2010-06-25 21:04:10 +02:00
|
|
|
|
|
|
|
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;
|
2010-06-25 21:04:10 +02:00
|
|
|
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;
|
2010-06-25 21:04:10 +02:00
|
|
|
};
|
|
|
|
|
2010-06-26 00:01:47 +02:00
|
|
|
DeviceData ReadDeviceData(const QDBusObjectPath& path) const;
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2010-06-26 00:01:47 +02:00
|
|
|
// You MUST hold the mutex while calling this function
|
|
|
|
QString FindUniqueIdByPath(const QDBusObjectPath& path) const;
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2010-07-04 17:01:24 +02:00
|
|
|
template <typename T>
|
|
|
|
T LockAndGetDeviceInfo(const QString& id, T DeviceData::*field);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2014-02-06 14:48:00 +01:00
|
|
|
std::unique_ptr<OrgFreedesktopUDisksInterface> interface_;
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2010-06-26 00:01:47 +02:00
|
|
|
QMutex mutex_;
|
|
|
|
QMap<QString, DeviceData> device_data_;
|
2010-06-25 21:04:10 +02:00
|
|
|
};
|
|
|
|
|
2010-07-04 17:01:24 +02:00
|
|
|
template <typename T>
|
2014-02-07 16:34:20 +01:00
|
|
|
T DeviceKitLister::LockAndGetDeviceInfo(const QString& id,
|
|
|
|
T DeviceData::*field) {
|
2010-07-04 17:01:24 +02:00
|
|
|
QMutexLocker l(&mutex_);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!device_data_.contains(id)) return T();
|
2010-07-04 17:01:24 +02:00
|
|
|
|
|
|
|
return device_data_[id].*field;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // DEVICEKITLISTER_H
|