strawberry-audio-player-win.../src/device/devicelister.h

106 lines
3.4 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef DEVICELISTER_H
#define DEVICELISTER_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QList>
#include <QMetaType>
#include <QString>
#include <QStringList>
2018-02-27 18:06:05 +01:00
#include <QUrl>
2020-02-09 02:29:35 +01:00
class QThread;
2018-02-27 18:06:05 +01:00
class DeviceLister : public QObject {
Q_OBJECT
public:
DeviceLister();
2020-06-15 21:55:05 +02:00
~DeviceLister() override;
2018-02-27 18:06:05 +01:00
2020-10-17 17:29:09 +02:00
// Tries to start the thread and initialize the engine. This object will be moved to the new thread.
2018-02-27 18:06:05 +01:00
void Start();
2019-09-15 01:12:05 +02:00
virtual void ExitAsync();
2018-02-27 18:06:05 +01:00
// If two listers know about the same device, then the metadata will get taken from the one with the highest priority.
2018-02-27 18:06:05 +01:00
virtual int priority() const { return 100; }
// Query information about the devices that are available. Must be thread-safe.
virtual QStringList DeviceUniqueIDs() = 0;
virtual QVariantList DeviceIcons(const QString &id) = 0;
virtual QString DeviceManufacturer(const QString &id) = 0;
virtual QString DeviceModel(const QString &id) = 0;
virtual quint64 DeviceCapacity(const QString &id) = 0;
virtual quint64 DeviceFreeSpace(const QString &id) = 0;
virtual QVariantMap DeviceHardwareInfo(const QString &id) = 0;
2019-09-15 20:27:32 +02:00
virtual bool DeviceNeedsMount(const QString &id) { Q_UNUSED(id); return false; }
2018-02-27 18:06:05 +01:00
// When connecting to a device for the first time, do we want an user's confirmation for scanning it? (by default yes)
2019-09-15 20:27:32 +02:00
virtual bool AskForScan(const QString &id) const { Q_UNUSED(id); return true; }
2018-02-27 18:06:05 +01:00
virtual QString MakeFriendlyName(const QString &id) = 0;
virtual QList<QUrl> MakeDeviceUrls(const QString &id) = 0;
// Ensure the device is mounted. This should run asynchronously and emit DeviceMounted when it's done.
virtual int MountDeviceAsync(const QString &id);
2018-02-27 18:06:05 +01:00
// Do whatever needs to be done to safely remove the device.
virtual void UnmountDeviceAsync(const QString &id);
virtual bool CopyMusic() { return true; }
2018-02-27 18:06:05 +01:00
public slots:
virtual void UpdateDeviceFreeSpace(const QString &id) = 0;
virtual void ShutDown() {}
2020-06-14 18:58:24 +02:00
virtual void MountDevice(const QString &id, const int request_id);
2019-09-15 20:27:32 +02:00
virtual void UnmountDevice(const QString &id) { Q_UNUSED(id); }
2019-09-15 01:12:05 +02:00
virtual void Exit();
2018-02-27 18:06:05 +01:00
2019-01-05 23:11:16 +01:00
signals:
2021-01-26 16:48:04 +01:00
void DeviceAdded(QString id);
void DeviceRemoved(QString id);
void DeviceChanged(QString id);
void DeviceMounted(QString id, int request_id, bool success);
void ExitFinished();
2018-02-27 18:06:05 +01:00
protected:
virtual bool Init() = 0;
2018-02-27 18:06:05 +01:00
QUrl MakeUrlFromLocalPath(const QString &path) const;
bool IsIpod(const QString &path) const;
QStringList GuessIconForPath(const QString &path);
QStringList GuessIconForModel(const QString &vendor, const QString &model);
protected:
QThread *thread_;
QThread *original_thread_;
2018-02-27 18:06:05 +01:00
int next_mount_request_id_;
private slots:
void ThreadStarted();
};
#endif // DEVICELISTER_H