2010-06-26 00:01:47 +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-26 00:01:47 +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 14:41:18 +02:00
|
|
|
#ifndef DEVICEMANAGER_H
|
|
|
|
#define DEVICEMANAGER_H
|
2010-06-26 00:01:47 +02:00
|
|
|
|
2019-01-21 10:06:48 +01:00
|
|
|
#include <QAbstractItemModel>
|
2010-07-03 23:05:55 +02:00
|
|
|
#include <QIcon>
|
2012-06-29 16:56:17 +02:00
|
|
|
#include <QThreadPool>
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <memory>
|
2010-07-03 23:05:55 +02:00
|
|
|
|
2019-01-21 10:06:48 +01:00
|
|
|
#include "core/simpletreemodel.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "devicedatabasebackend.h"
|
2019-01-21 10:06:48 +01:00
|
|
|
#include "deviceinfo.h"
|
2014-02-06 14:48:00 +01:00
|
|
|
#include "library/librarymodel.h"
|
2010-06-26 00:01:47 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2010-06-26 14:41:18 +02:00
|
|
|
class ConnectedDevice;
|
2010-06-26 00:36:21 +02:00
|
|
|
class DeviceLister;
|
2010-07-24 20:31:05 +02:00
|
|
|
class DeviceStateFilterModel;
|
2010-06-26 00:01:47 +02:00
|
|
|
|
2019-01-21 10:06:48 +01:00
|
|
|
class DeviceManager : public SimpleTreeModel<DeviceInfo> {
|
2010-06-26 00:01:47 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
DeviceManager(Application* app, QObject* parent = nullptr);
|
2010-06-26 14:41:18 +02:00
|
|
|
~DeviceManager();
|
2010-06-26 00:01:47 +02:00
|
|
|
|
2010-07-04 13:34:25 +02:00
|
|
|
enum Role {
|
|
|
|
Role_State = LibraryModel::LastRole,
|
|
|
|
Role_UniqueId,
|
2010-07-04 17:01:24 +02:00
|
|
|
Role_FriendlyName,
|
|
|
|
Role_Capacity,
|
2010-07-18 00:06:19 +02:00
|
|
|
Role_FreeSpace,
|
2010-07-04 17:01:24 +02:00
|
|
|
Role_IconName,
|
2010-07-04 17:56:08 +02:00
|
|
|
Role_UpdatingPercentage,
|
2010-07-25 01:20:34 +02:00
|
|
|
Role_MountPath,
|
2010-08-29 17:32:36 +02:00
|
|
|
Role_TranscodeMode,
|
|
|
|
Role_TranscodeFormat,
|
2010-08-30 16:45:27 +02:00
|
|
|
Role_SongCount,
|
2010-07-19 21:56:29 +02:00
|
|
|
LastRole,
|
2010-07-04 13:34:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
State_Remembered,
|
2010-09-11 14:29:44 +02:00
|
|
|
State_NotMounted,
|
2010-07-04 13:34:25 +02:00
|
|
|
State_NotConnected,
|
|
|
|
State_Connected,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int kDeviceIconSize;
|
|
|
|
static const int kDeviceIconOverlaySize;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
DeviceStateFilterModel* connected_devices_model() const {
|
|
|
|
return connected_devices_model_;
|
|
|
|
}
|
2010-07-19 21:56:29 +02:00
|
|
|
|
2010-07-04 17:01:24 +02:00
|
|
|
// Get info about devices
|
2019-01-21 22:38:46 +01:00
|
|
|
int GetDatabaseId(const QModelIndex& idx) const;
|
|
|
|
DeviceLister* GetLister(QModelIndex idx) const;
|
|
|
|
std::shared_ptr<ConnectedDevice> GetConnectedDevice(QModelIndex idx) const;
|
|
|
|
std::shared_ptr<ConnectedDevice> GetConnectedDevice(DeviceInfo* info) const;
|
2010-07-04 01:00:07 +02:00
|
|
|
|
2019-01-21 22:38:46 +01:00
|
|
|
DeviceInfo* FindDeviceById(const QString& id) const;
|
|
|
|
DeviceInfo* FindDeviceByUrl(const QList<QUrl>& url) const;
|
2019-02-24 08:42:31 +01:00
|
|
|
DeviceInfo* FindEquivalentDevice(DeviceInfo* info) const;
|
2010-07-04 17:01:24 +02:00
|
|
|
|
|
|
|
// Actions on devices
|
2019-01-21 22:38:46 +01:00
|
|
|
std::shared_ptr<ConnectedDevice> Connect(DeviceInfo* info);
|
|
|
|
std::shared_ptr<ConnectedDevice> Connect(QModelIndex idx);
|
|
|
|
void Disconnect(QModelIndex idx);
|
|
|
|
void Forget(QModelIndex idx);
|
|
|
|
void UnmountAsync(QModelIndex idx);
|
2020-01-08 07:51:45 +01:00
|
|
|
bool IsConnected(QModelIndex idx) {
|
|
|
|
return GetConnectedDevice(idx) != nullptr;
|
|
|
|
}
|
2010-07-04 02:33:34 +02:00
|
|
|
|
2019-01-21 22:38:46 +01:00
|
|
|
void SetDeviceOptions(QModelIndex idx, const QString& friendly_name,
|
2014-02-07 16:34:20 +01:00
|
|
|
const QString& icon_name,
|
|
|
|
MusicStorage::TranscodeMode mode,
|
|
|
|
Song::FileType format);
|
2010-07-04 17:18:37 +02:00
|
|
|
|
2019-01-21 10:06:48 +01:00
|
|
|
// QAbstractItemModel
|
2019-01-21 22:38:46 +01:00
|
|
|
QVariant data(const QModelIndex& idx, int role = Qt::DisplayRole) const;
|
2010-07-03 23:05:55 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2019-01-21 22:38:46 +01:00
|
|
|
void Unmount(QModelIndex idx);
|
2010-08-01 13:01:07 +02:00
|
|
|
|
2019-01-21 22:38:46 +01:00
|
|
|
signals:
|
|
|
|
void DeviceConnected(QModelIndex idx);
|
|
|
|
void DeviceDisconnected(QModelIndex idx);
|
2019-02-24 07:12:07 +01:00
|
|
|
void DeviceCreatedFromDb(DeviceInfo* info);
|
2010-07-04 02:33:34 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2010-07-03 23:05:55 +02:00
|
|
|
void PhysicalDeviceAdded(const QString& id);
|
|
|
|
void PhysicalDeviceRemoved(const QString& id);
|
|
|
|
void PhysicalDeviceChanged(const QString& id);
|
2010-07-04 17:56:08 +02:00
|
|
|
void DeviceTaskStarted(int id);
|
|
|
|
void TasksChanged();
|
2010-08-30 16:45:27 +02:00
|
|
|
void DeviceSongCountUpdated(int count);
|
2012-06-29 16:56:17 +02:00
|
|
|
void LoadAllDevices();
|
2019-01-15 22:10:05 +01:00
|
|
|
void DeviceConnectFinished(const QString& id, bool success);
|
2019-02-24 07:12:07 +01:00
|
|
|
void AddDeviceFromDb(DeviceInfo* info);
|
2010-06-26 00:01:47 +02:00
|
|
|
|
2019-01-21 10:06:48 +01:00
|
|
|
protected:
|
|
|
|
void LazyPopulate(DeviceInfo* item) { LazyPopulate(item, true); }
|
|
|
|
void LazyPopulate(DeviceInfo* item, bool signal);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-07-04 01:00:07 +02:00
|
|
|
void AddLister(DeviceLister* lister);
|
2014-02-07 16:34:20 +01:00
|
|
|
template <typename T>
|
|
|
|
void AddDeviceClass();
|
2010-07-04 01:00:07 +02:00
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
DeviceDatabaseBackend::Device InfoToDatabaseDevice(
|
|
|
|
const DeviceInfo& info) const;
|
2010-07-04 01:00:07 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2010-07-04 01:00:07 +02:00
|
|
|
DeviceDatabaseBackend* backend_;
|
2010-06-26 14:41:18 +02:00
|
|
|
|
2010-07-24 20:31:05 +02:00
|
|
|
DeviceStateFilterModel* connected_devices_model_;
|
2010-07-19 21:56:29 +02:00
|
|
|
|
2010-07-04 13:34:25 +02:00
|
|
|
QIcon not_connected_overlay_;
|
|
|
|
|
2010-06-26 00:36:21 +02:00
|
|
|
QList<DeviceLister*> listers_;
|
2019-01-21 10:06:48 +01:00
|
|
|
QList<DeviceInfo*> devices_;
|
2010-07-04 17:56:08 +02:00
|
|
|
|
2010-07-17 16:22:07 +02:00
|
|
|
QMultiMap<QString, QMetaObject> device_classes_;
|
|
|
|
|
2010-07-04 17:56:08 +02:00
|
|
|
// Map of task ID to device index
|
|
|
|
QMap<int, QPersistentModelIndex> active_tasks_;
|
2012-06-29 16:56:17 +02:00
|
|
|
|
|
|
|
QThreadPool thread_pool_;
|
2010-06-26 00:01:47 +02:00
|
|
|
};
|
|
|
|
|
2010-07-17 16:22:07 +02:00
|
|
|
template <typename T>
|
|
|
|
void DeviceManager::AddDeviceClass() {
|
|
|
|
QStringList schemes = T::url_schemes();
|
|
|
|
QMetaObject obj = T::staticMetaObject;
|
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (const QString& scheme : schemes) {
|
2010-07-17 16:22:07 +02:00
|
|
|
device_classes_.insert(scheme, obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // DEVICEMANAGER_H
|