Integrated cddevice back into cddadevice

This commit is contained in:
Lukas Prediger 2021-05-30 16:17:09 +03:00 committed by John Maguire
parent 9ca75ae357
commit 14d5c25d37
5 changed files with 40 additions and 120 deletions

View File

@ -1103,14 +1103,12 @@ optional_source(HAVE_AUDIOCD
devices/cddadevice.cpp devices/cddadevice.cpp
devices/cddalister.cpp devices/cddalister.cpp
devices/cddasongloader.cpp devices/cddasongloader.cpp
devices/cddevice.cpp
ripper/ripcddialog.cpp ripper/ripcddialog.cpp
ripper/ripper.cpp ripper/ripper.cpp
HEADERS HEADERS
devices/cddadevice.h devices/cddadevice.h
devices/cddalister.h devices/cddalister.h
devices/cddasongloader.h devices/cddasongloader.h
devices/cddevice.h
ripper/ripcddialog.h ripper/ripcddialog.h
ripper/ripper.h ripper/ripper.h
UI UI

View File

@ -17,18 +17,19 @@
#include "cddadevice.h" #include "cddadevice.h"
#include <QMutexLocker>
#include "core/song.h"
#include "library/librarybackend.h" #include "library/librarybackend.h"
#include "library/librarymodel.h" #include "library/librarymodel.h"
const int CddaDevice::kDiscChangePollingIntervalMs = 500;
CddaDevice::CddaDevice(const QUrl& url, DeviceLister* lister, CddaDevice::CddaDevice(const QUrl& url, DeviceLister* lister,
const QString& unique_id, DeviceManager* manager, const QString& unique_id, DeviceManager* manager,
Application* app, int database_id, bool first_time) Application* app, int database_id, bool first_time,
bool watch_for_disc_changes)
: ConnectedDevice(url, lister, unique_id, manager, app, database_id, : ConnectedDevice(url, lister, unique_id, manager, app, database_id,
first_time), first_time),
cd_device_(url), cdio_(nullptr),
disc_changed_timer_(),
cdda_song_loader_(url) { cdda_song_loader_(url) {
connect(&cdda_song_loader_, SIGNAL(SongsLoaded(SongList)), this, connect(&cdda_song_loader_, SIGNAL(SongsLoaded(SongList)), this,
SLOT(SongsLoaded(SongList))); SLOT(SongsLoaded(SongList)));
@ -38,15 +39,29 @@ CddaDevice::CddaDevice(const QUrl& url, DeviceLister* lister,
SLOT(SongsLoaded(SongList))); SLOT(SongsLoaded(SongList)));
connect(this, SIGNAL(SongsDiscovered(SongList)), model_, connect(this, SIGNAL(SongsDiscovered(SongList)), model_,
SLOT(SongsDiscovered(SongList))); SLOT(SongsDiscovered(SongList)));
connect(&cd_device_, SIGNAL(DiscChanged()), SLOT(DiscChangeDetected())); // connect(&cd_device_, SIGNAL(DiscChanged()), SLOT(DiscChangeDetected()));
cdio_ = cdio_open(url_.path().toLocal8Bit().constData(), DRIVER_DEVICE);
Q_ASSERT(cdio_); // todo: error handling?
connect(&disc_changed_timer_, SIGNAL(timeout()), SLOT(CheckDiscChanged()));
WatchForDiscChanges(watch_for_disc_changes);
} }
CddaDevice::~CddaDevice() {} CddaDevice::~CddaDevice() {
Q_ASSERT(cdio_);
cdio_destroy(cdio_);
}
void CddaDevice::Init() { LoadSongs(); } void CddaDevice::Init() { LoadSongs(); }
void CddaDevice::Refresh() {} void CddaDevice::Refresh() {}
void CddaDevice::WatchForDiscChanges(bool watch) {
if (watch && !disc_changed_timer_.isActive())
disc_changed_timer_.start(CddaDevice::kDiscChangePollingIntervalMs);
else if (!watch && disc_changed_timer_.isActive())
disc_changed_timer_.stop();
}
void CddaDevice::LoadSongs() { cdda_song_loader_.LoadSongs(); } void CddaDevice::LoadSongs() { cdda_song_loader_.LoadSongs(); }
void CddaDevice::SongsLoaded(const SongList& songs) { void CddaDevice::SongsLoaded(const SongList& songs) {
@ -55,10 +70,13 @@ void CddaDevice::SongsLoaded(const SongList& songs) {
song_count_ = songs.size(); song_count_ = songs.size();
} }
void CddaDevice::DiscChangeDetected() { void CddaDevice::CheckDiscChanged() {
emit DiscChanged(); Q_ASSERT(cdio_);
song_count_ = 0; if (cdio_get_media_changed(cdio_) == 1) {
SongList no_songs; emit DiscChanged();
SongsLoaded(no_songs); song_count_ = 0;
LoadSongs(); SongList no_songs;
SongsLoaded(no_songs);
LoadSongs();
}
} }

View File

@ -18,17 +18,15 @@
#ifndef CDDADEVICE_H #ifndef CDDADEVICE_H
#define CDDADEVICE_H #define CDDADEVICE_H
#include <QMutex> #include <QTimer>
#include <QUrl>
// These must come after Qt includes (issue 3247) // These must come after Qt includes (issue 3247)
#include <cdio/cdio.h> #include <cdio/cdio.h>
#include <gst/audio/gstaudiocdsrc.h>
#include "cddasongloader.h" #include "cddasongloader.h"
#include "cddevice.h"
#include "connecteddevice.h" #include "connecteddevice.h"
#include "core/song.h" #include "core/song.h"
#include "musicbrainz/musicbrainzclient.h"
class CddaDevice : public ConnectedDevice { class CddaDevice : public ConnectedDevice {
Q_OBJECT Q_OBJECT
@ -36,14 +34,17 @@ class CddaDevice : public ConnectedDevice {
public: public:
Q_INVOKABLE CddaDevice(const QUrl& url, DeviceLister* lister, Q_INVOKABLE CddaDevice(const QUrl& url, DeviceLister* lister,
const QString& unique_id, DeviceManager* manager, const QString& unique_id, DeviceManager* manager,
Application* app, int database_id, bool first_time); Application* app, int database_id, bool first_time,
bool watch_for_disc_changes = true);
~CddaDevice(); ~CddaDevice();
void Init(); void Init();
void Refresh(); void Refresh();
bool CopyToStorage(const MusicStorage::CopyJob&) { return false; } bool CopyToStorage(const MusicStorage::CopyJob&) { return false; }
bool DeleteFromStorage(const MusicStorage::DeleteJob&) { return false; } bool DeleteFromStorage(const MusicStorage::DeleteJob&) { return false; }
void WatchForDiscChanges(bool watch);
static const int kDiscChangePollingIntervalMs;
static QStringList url_schemes() { return QStringList() << "cdda"; } static QStringList url_schemes() { return QStringList() << "cdda"; }
// QUrl interprets a single number as an ip address, so the QString cdda://1 // QUrl interprets a single number as an ip address, so the QString cdda://1
@ -63,12 +64,13 @@ class CddaDevice : public ConnectedDevice {
private slots: private slots:
void SongsLoaded(const SongList& songs); void SongsLoaded(const SongList& songs);
void DiscChangeDetected(); void CheckDiscChanged();
private: private:
void LoadSongs(); void LoadSongs();
CdDevice cd_device_; CdIo_t* cdio_;
QTimer disc_changed_timer_;
CddaSongLoader cdda_song_loader_; CddaSongLoader cdda_song_loader_;
}; };

View File

@ -1,45 +0,0 @@
/* This file is part of Clementine.
Copyright 2021, Lukas Prediger <lumip@lumip.de>
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/>.
*/
#include "cddevice.h"
const int CdDevice::kDiscChangePollingIntervalMs = 500;
CdDevice::CdDevice(const QUrl& url, QObject* parent,
bool watch_for_disc_changes)
: QObject(parent), url_(url), cdio_(nullptr), disc_changed_timer_() {
cdio_ = cdio_open(url_.path().toLocal8Bit().constData(), DRIVER_DEVICE);
connect(&disc_changed_timer_, SIGNAL(timeout()), SLOT(CheckDiscChanged()));
WatchForDiscChanges(watch_for_disc_changes);
}
CdDevice::~CdDevice() {
Q_ASSERT(cdio_);
cdio_destroy(cdio_);
}
void CdDevice::WatchForDiscChanges(bool watch) {
if (watch && !disc_changed_timer_.isActive())
disc_changed_timer_.start(CdDevice::kDiscChangePollingIntervalMs);
else if (!watch && disc_changed_timer_.isActive())
disc_changed_timer_.stop();
}
void CdDevice::CheckDiscChanged() {
Q_ASSERT(cdio_);
if (cdio_get_media_changed(cdio_) == 1) emit DiscChanged();
}

View File

@ -1,53 +0,0 @@
/* This file is part of Clementine.
Copyright 2021, Lukas Prediger <lumip@lumip.de>
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 CDDEVICE_H
#define CDDEVICE_H
#include <QObject>
#include <QTimer>
#include <QUrl>
// Qt import must come first
#include <cdio/cdio.h>
class CdDevice : public QObject {
Q_OBJECT
public:
Q_INVOKABLE CdDevice(const QUrl& url, QObject* parent = nullptr,
bool watch_for_disc_changes = true);
~CdDevice();
const QUrl& url() const;
void WatchForDiscChanges(bool watch);
static const int kDiscChangePollingIntervalMs;
signals:
void DiscChanged();
private slots:
void CheckDiscChanged();
private:
QUrl url_;
CdIo_t* cdio_;
QTimer disc_changed_timer_;
};
#endif