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

108 lines
3.2 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>
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* 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 CONNECTEDDEVICE_H
#define CONNECTEDDEVICE_H
#include "config.h"
#include <memory>
#include <QObject>
#include <QString>
2018-02-27 18:06:05 +01:00
#include <QUrl>
#include "core/shared_ptr.h"
2018-02-27 18:06:05 +01:00
#include "core/musicstorage.h"
#include "core/song.h"
class Application;
class CollectionBackend;
class CollectionModel;
class DeviceLister;
class DeviceManager;
2018-02-27 18:06:05 +01:00
using std::enable_shared_from_this;
class ConnectedDevice : public QObject, public virtual MusicStorage, public enable_shared_from_this<ConnectedDevice> {
2018-02-27 18:06:05 +01:00
Q_OBJECT
public:
explicit ConnectedDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr);
2018-02-27 18:06:05 +01:00
2023-02-18 14:09:27 +01:00
Song::Source source() const override { return Song::Source::Device; }
2022-10-19 18:36:33 +02:00
virtual bool Init() = 0;
virtual bool IsLoading() { return false; }
2019-07-19 19:56:37 +02:00
virtual void NewConnection() {}
virtual void ConnectAsync();
// For some devices (e.g. CD devices) we don't have callbacks to be notified when something change:
// we can call this method to refresh device's state
2018-02-27 18:06:05 +01:00
virtual void Refresh() {}
2020-06-15 21:55:05 +02:00
TranscodeMode GetTranscodeMode() const override;
Song::FileType GetTranscodeFormat() const override;
2018-02-27 18:06:05 +01:00
DeviceLister *lister() const { return lister_; }
QString unique_id() const { return unique_id_; }
CollectionModel *model() const { return model_; }
QUrl url() const { return url_; }
2021-10-30 02:21:29 +02:00
qint64 song_count() const { return song_count_; }
2018-02-27 18:06:05 +01:00
bool FinishCopy(bool success, QString &error_text) override;
bool FinishDelete(bool success, QString &error_text) override;
2018-02-27 18:06:05 +01:00
2020-06-15 21:55:05 +02:00
void Eject() override;
virtual void Close();
public slots:
2021-01-26 16:48:04 +01:00
void BackendCloseFinished();
2018-02-27 18:06:05 +01:00
signals:
void TaskStarted(const int id);
void SongCountUpdated(const int count);
void DeviceConnectFinished(const QString &id, const bool success);
void DeviceCloseFinished(const QString &id);
2018-02-27 18:06:05 +01:00
protected:
void InitBackendDirectory(const QString &mount_point, const bool first_time, const bool rewrite_path = true);
2018-02-27 18:06:05 +01:00
protected:
Application *app_;
QUrl url_;
bool first_time_;
DeviceLister *lister_;
QString unique_id_;
int database_id_;
SharedPtr<DeviceManager> manager_;
2018-02-27 18:06:05 +01:00
SharedPtr<CollectionBackend> backend_;
2018-02-27 18:06:05 +01:00
CollectionModel *model_;
2021-10-30 02:21:29 +02:00
qint64 song_count_;
2018-02-27 18:06:05 +01:00
private slots:
void BackendTotalSongCountUpdated(int count);
};
#endif // CONNECTEDDEVICE_H