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/cddalister.cpp
devices/cddasongloader.cpp
devices/cddevice.cpp
ripper/ripcddialog.cpp
ripper/ripper.cpp
HEADERS
devices/cddadevice.h
devices/cddalister.h
devices/cddasongloader.h
devices/cddevice.h
ripper/ripcddialog.h
ripper/ripper.h
UI

View File

@ -17,18 +17,19 @@
#include "cddadevice.h"
#include <QMutexLocker>
#include "core/song.h"
#include "library/librarybackend.h"
#include "library/librarymodel.h"
const int CddaDevice::kDiscChangePollingIntervalMs = 500;
CddaDevice::CddaDevice(const QUrl& url, DeviceLister* lister,
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,
first_time),
cd_device_(url),
cdio_(nullptr),
disc_changed_timer_(),
cdda_song_loader_(url) {
connect(&cdda_song_loader_, SIGNAL(SongsLoaded(SongList)), this,
SLOT(SongsLoaded(SongList)));
@ -38,15 +39,29 @@ CddaDevice::CddaDevice(const QUrl& url, DeviceLister* lister,
SLOT(SongsLoaded(SongList)));
connect(this, SIGNAL(SongsDiscovered(SongList)), model_,
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::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::SongsLoaded(const SongList& songs) {
@ -55,10 +70,13 @@ void CddaDevice::SongsLoaded(const SongList& songs) {
song_count_ = songs.size();
}
void CddaDevice::DiscChangeDetected() {
emit DiscChanged();
song_count_ = 0;
SongList no_songs;
SongsLoaded(no_songs);
LoadSongs();
void CddaDevice::CheckDiscChanged() {
Q_ASSERT(cdio_);
if (cdio_get_media_changed(cdio_) == 1) {
emit DiscChanged();
song_count_ = 0;
SongList no_songs;
SongsLoaded(no_songs);
LoadSongs();
}
}

View File

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