2011-08-05 02:15:16 +02:00
|
|
|
/* 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 CDDADEVICE_H
|
|
|
|
#define CDDADEVICE_H
|
|
|
|
|
2021-05-30 15:17:09 +02:00
|
|
|
#include <QTimer>
|
2012-10-31 18:42:38 +01:00
|
|
|
|
|
|
|
// These must come after Qt includes (issue 3247)
|
2011-08-05 02:15:16 +02:00
|
|
|
#include <cdio/cdio.h>
|
|
|
|
|
2014-10-26 03:32:37 +01:00
|
|
|
#include "cddasongloader.h"
|
2011-08-05 02:15:16 +02:00
|
|
|
#include "connecteddevice.h"
|
|
|
|
#include "core/song.h"
|
|
|
|
|
2021-06-04 17:44:10 +02:00
|
|
|
class QUrl;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
class CddaDevice : public ConnectedDevice {
|
2011-08-05 02:15:16 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2021-06-05 19:25:22 +02:00
|
|
|
// Initializes the CddaDevice but does not open a handle to the device.
|
|
|
|
// Using code MUST call Init() after construction before calling and
|
|
|
|
// check that it returns true any other methods, to ensure that a valid
|
|
|
|
// device handle was correctly opened. Using class methods without
|
|
|
|
// a valid device handle is undefined behavior and might result in crashes.
|
2011-08-05 02:15:16 +02:00
|
|
|
Q_INVOKABLE CddaDevice(const QUrl& url, DeviceLister* lister,
|
2014-02-07 16:34:20 +01:00
|
|
|
const QString& unique_id, DeviceManager* manager,
|
2021-06-11 16:13:36 +02:00
|
|
|
Application* app, int database_id, bool first_time);
|
2011-08-05 02:15:16 +02:00
|
|
|
~CddaDevice();
|
|
|
|
|
2021-06-05 19:25:22 +02:00
|
|
|
bool Init() override;
|
2021-06-30 20:51:09 +02:00
|
|
|
bool CopyToStorage(const MusicStorage::CopyJob&) override { return false; }
|
2021-06-30 21:15:53 +02:00
|
|
|
bool DeleteFromStorage(const MusicStorage::DeleteJob&) override {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-30 15:18:31 +02:00
|
|
|
CddaSongLoader* loader();
|
2021-06-05 19:25:22 +02:00
|
|
|
// Check whether a valid device handle was opened.
|
|
|
|
bool IsValid() const;
|
2021-05-30 15:17:09 +02:00
|
|
|
void WatchForDiscChanges(bool watch);
|
2021-08-23 18:15:23 +02:00
|
|
|
SongList songs() const;
|
2011-08-05 02:15:16 +02:00
|
|
|
|
|
|
|
static QStringList url_schemes() { return QStringList() << "cdda"; }
|
|
|
|
|
2020-06-01 06:47:25 +02:00
|
|
|
// QUrl interprets a single number as an ip address, so the QString cdda://1
|
|
|
|
// would become the QUrl cdda://0.0.0.1. For this reason, we append a single
|
|
|
|
// character to strings when converting to URLs and strip that character
|
|
|
|
// when doing the reverse conversion.
|
|
|
|
static QUrl TrackStrToUrl(const QString& name) { return QUrl(name + "a"); }
|
|
|
|
static QString TrackUrlToStr(const QUrl& url) {
|
|
|
|
QString str = url.toString();
|
|
|
|
str.remove(str.lastIndexOf(QChar('a')), 1);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
signals:
|
2011-08-05 02:15:16 +02:00
|
|
|
void SongsDiscovered(const SongList& songs);
|
2021-05-30 14:23:37 +02:00
|
|
|
void DiscChanged();
|
2011-08-05 02:15:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2014-10-26 03:32:37 +01:00
|
|
|
void SongsLoaded(const SongList& songs);
|
2021-08-01 13:39:42 +02:00
|
|
|
void SongsLoadingFinished();
|
2021-05-30 15:17:09 +02:00
|
|
|
void CheckDiscChanged();
|
2011-08-05 02:15:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2021-08-23 18:15:23 +02:00
|
|
|
void LoadSongs();
|
2021-07-30 15:17:16 +02:00
|
|
|
|
2021-05-30 15:17:09 +02:00
|
|
|
CdIo_t* cdio_;
|
|
|
|
QTimer disc_changed_timer_;
|
2014-10-26 03:32:37 +01:00
|
|
|
CddaSongLoader cdda_song_loader_;
|
2011-08-05 02:15:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|