RipCDDialog now relies on CddaDevice to be notified about disc changes
This commit is contained in:
parent
d2c636ab46
commit
9ca75ae357
@ -19,6 +19,7 @@
|
||||
|
||||
#include <QMutexLocker>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "library/librarybackend.h"
|
||||
#include "library/librarymodel.h"
|
||||
|
||||
@ -37,7 +38,7 @@ 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(LoadSongs()));
|
||||
connect(&cd_device_, SIGNAL(DiscChanged()), SLOT(DiscChangeDetected()));
|
||||
}
|
||||
|
||||
CddaDevice::~CddaDevice() {}
|
||||
@ -46,13 +47,18 @@ void CddaDevice::Init() { LoadSongs(); }
|
||||
|
||||
void CddaDevice::Refresh() {}
|
||||
|
||||
void CddaDevice::LoadSongs() {
|
||||
song_count_ = 0; // Reset song count, in case it was already set
|
||||
cdda_song_loader_.LoadSongs();
|
||||
}
|
||||
void CddaDevice::LoadSongs() { cdda_song_loader_.LoadSongs(); }
|
||||
|
||||
void CddaDevice::SongsLoaded(const SongList& songs) {
|
||||
model_->Reset();
|
||||
emit SongsDiscovered(songs);
|
||||
song_count_ = songs.size();
|
||||
}
|
||||
|
||||
void CddaDevice::DiscChangeDetected() {
|
||||
emit DiscChanged();
|
||||
song_count_ = 0;
|
||||
SongList no_songs;
|
||||
SongsLoaded(no_songs);
|
||||
LoadSongs();
|
||||
}
|
||||
|
@ -59,12 +59,15 @@ class CddaDevice : public ConnectedDevice {
|
||||
|
||||
signals:
|
||||
void SongsDiscovered(const SongList& songs);
|
||||
void DiscChanged();
|
||||
|
||||
private slots:
|
||||
void SongsLoaded(const SongList& songs);
|
||||
void LoadSongs();
|
||||
void DiscChangeDetected();
|
||||
|
||||
private:
|
||||
void LoadSongs();
|
||||
|
||||
CdDevice cd_device_;
|
||||
CddaSongLoader cdda_song_loader_;
|
||||
};
|
||||
|
@ -348,6 +348,26 @@ DeviceInfo* DeviceManager::FindEquivalentDevice(DeviceInfo* info) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QList<DeviceInfo*> DeviceManager::FindDeviceByUrlSchemes(
|
||||
QStringList url_schemes) const {
|
||||
QList<DeviceInfo*> matches;
|
||||
for (DeviceInfo* device_info : devices_) {
|
||||
for (const DeviceInfo::Backend& backend : device_info->backends_) {
|
||||
if (!backend.lister_) continue;
|
||||
|
||||
QList<QUrl> device_urls =
|
||||
backend.lister_->MakeDeviceUrls(backend.unique_id_);
|
||||
for (const QUrl& url : device_urls) {
|
||||
if (url_schemes.contains(url.scheme())) {
|
||||
matches << device_info;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
void DeviceManager::PhysicalDeviceAdded(const QString& id) {
|
||||
DeviceLister* lister = qobject_cast<DeviceLister*>(sender());
|
||||
|
||||
|
@ -78,6 +78,7 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
|
||||
DeviceInfo* FindDeviceById(const QString& id) const;
|
||||
DeviceInfo* FindDeviceByUrl(const QList<QUrl>& url) const;
|
||||
DeviceInfo* FindEquivalentDevice(DeviceInfo* info) const;
|
||||
QList<DeviceInfo*> FindDeviceByUrlSchemes(QStringList url_schemes) const;
|
||||
|
||||
// Actions on devices
|
||||
std::shared_ptr<ConnectedDevice> Connect(DeviceInfo* info);
|
||||
|
@ -30,13 +30,13 @@
|
||||
#include "config.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/tagreaderclient.h"
|
||||
#include "devices/cddadevice.h"
|
||||
#include "devices/cddasongloader.h"
|
||||
#include "ripper/ripper.h"
|
||||
#include "transcoder/transcoder.h"
|
||||
#include "transcoder/transcoderoptionsdialog.h"
|
||||
#include "ui/iconloader.h"
|
||||
#include "ui_ripcddialog.h"
|
||||
|
||||
namespace {
|
||||
bool ComparePresetsByName(const TranscoderPreset& left,
|
||||
const TranscoderPreset& right) {
|
||||
@ -52,12 +52,16 @@ const int kTrackDurationColumn = 3;
|
||||
const char* RipCDDialog::kSettingsGroup = "Transcoder";
|
||||
const int RipCDDialog::kMaxDestinationItems = 10;
|
||||
|
||||
RipCDDialog::RipCDDialog(QWidget* parent)
|
||||
RipCDDialog::RipCDDialog(std::shared_ptr<CddaDevice> cdda_device,
|
||||
QWidget* parent)
|
||||
: QDialog(parent),
|
||||
ui_(new Ui_RipCDDialog),
|
||||
ripper_(new Ripper(this)),
|
||||
working_(false),
|
||||
loader_(new CddaSongLoader(QUrl(), this)) {
|
||||
loader_(nullptr),
|
||||
cdda_device_(std::move(cdda_device)) {
|
||||
Q_ASSERT(cdda_device_);
|
||||
loader_ = new CddaSongLoader(cdda_device_->url(), this);
|
||||
// Init
|
||||
ui_->setupUi(this);
|
||||
|
||||
@ -128,12 +132,12 @@ RipCDDialog::RipCDDialog(QWidget* parent)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
connect(cdda_device_.get(), SIGNAL(DiscChanged()), SLOT(DiscChanged()));
|
||||
}
|
||||
|
||||
RipCDDialog::~RipCDDialog() {}
|
||||
|
||||
bool RipCDDialog::CheckCDIOIsValid() { return ripper_->CheckCDIOIsValid(); }
|
||||
|
||||
void RipCDDialog::closeEvent(QCloseEvent* event) {
|
||||
if (working_) {
|
||||
event->ignore();
|
||||
@ -149,17 +153,6 @@ void RipCDDialog::showEvent(QShowEvent* event) {
|
||||
}
|
||||
|
||||
void RipCDDialog::ClickedRipButton() {
|
||||
if (ripper_->MediaChanged()) {
|
||||
QMessageBox cdio_fail(QMessageBox::Critical, tr("Error Ripping CD"),
|
||||
tr("Media has changed. Reloading"));
|
||||
cdio_fail.exec();
|
||||
ResetDialog();
|
||||
if (CheckCDIOIsValid()) {
|
||||
loader_->LoadSongs();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Add tracks and album information to the ripper.
|
||||
ripper_->ClearTracks();
|
||||
TranscoderPreset preset = ui_->format->itemData(ui_->format->currentIndex())
|
||||
@ -298,6 +291,8 @@ void RipCDDialog::AddAlbumMetadataFromMusicBrainz(const SongList& songs) {
|
||||
ui_->yearLineEdit->setText(QString::number(song.year()));
|
||||
}
|
||||
|
||||
void RipCDDialog::DiscChanged() { ResetDialog(); }
|
||||
|
||||
void RipCDDialog::SetWorking(bool working) {
|
||||
working_ = working;
|
||||
rip_button_->setVisible(!working);
|
||||
|
@ -33,12 +33,14 @@ class QShowEvent;
|
||||
class CddaSongLoader;
|
||||
class Ripper;
|
||||
class Ui_RipCDDialog;
|
||||
class CddaDevice;
|
||||
|
||||
class RipCDDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RipCDDialog(QWidget* parent = nullptr);
|
||||
explicit RipCDDialog(std::shared_ptr<CddaDevice> cdda_device,
|
||||
QWidget* parent = nullptr);
|
||||
~RipCDDialog();
|
||||
bool CheckCDIOIsValid();
|
||||
|
||||
@ -64,6 +66,7 @@ class RipCDDialog : public QDialog {
|
||||
void UpdateTrackListTable(const SongList& songs);
|
||||
// Update album information with metadata.
|
||||
void AddAlbumMetadataFromMusicBrainz(const SongList& songs);
|
||||
void DiscChanged();
|
||||
|
||||
private:
|
||||
static const char* kSettingsGroup;
|
||||
@ -88,5 +91,6 @@ class RipCDDialog : public QDialog {
|
||||
Ripper* ripper_;
|
||||
bool working_;
|
||||
CddaSongLoader* loader_;
|
||||
std::shared_ptr<CddaDevice> cdda_device_;
|
||||
};
|
||||
#endif // SRC_RIPPER_RIPCDDIALOG_H_
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QFileSystemModel>
|
||||
#include <QLinearGradient>
|
||||
#include <QList>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
@ -56,6 +57,7 @@
|
||||
#include "core/taskmanager.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "core/utilities.h"
|
||||
#include "devices/cddadevice.h"
|
||||
#include "devices/devicemanager.h"
|
||||
#include "devices/devicestatefiltermodel.h"
|
||||
#include "devices/deviceview.h"
|
||||
@ -2219,15 +2221,33 @@ void MainWindow::AddStreamAccepted() {
|
||||
void MainWindow::OpenRipCDDialog() {
|
||||
#ifdef HAVE_AUDIOCD
|
||||
if (!rip_cd_dialog_) {
|
||||
rip_cd_dialog_.reset(new RipCDDialog);
|
||||
}
|
||||
if (rip_cd_dialog_->CheckCDIOIsValid()) {
|
||||
rip_cd_dialog_->show();
|
||||
} else {
|
||||
QMessageBox cdio_fail(QMessageBox::Critical, tr("Error"),
|
||||
tr("Failed reading CD drive"));
|
||||
cdio_fail.exec();
|
||||
QList<DeviceInfo*> cd_device_infos =
|
||||
app_->device_manager()->FindDeviceByUrlSchemes(
|
||||
CddaDevice::url_schemes());
|
||||
std::shared_ptr<ConnectedDevice> device;
|
||||
if (!cd_device_infos.isEmpty()) {
|
||||
DeviceInfo* device_info =
|
||||
cd_device_infos[0]; // TODO: currently just picking the first cd
|
||||
// drive; what if there are several?
|
||||
device = app_->device_manager()->Connect(
|
||||
device_info); // connect the device; will do nothing if already
|
||||
// connected
|
||||
}
|
||||
|
||||
if (!device) {
|
||||
QMessageBox cdio_fail(QMessageBox::Critical, tr("Error"),
|
||||
tr("Failed reading CD drive"));
|
||||
cdio_fail.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<CddaDevice> cdda_device =
|
||||
std::dynamic_pointer_cast<CddaDevice>(device);
|
||||
Q_ASSERT(cdda_device); // since we are requesting for cdda devices, the
|
||||
// cast must work; assert it
|
||||
rip_cd_dialog_.reset(new RipCDDialog(std::move(cdda_device)));
|
||||
}
|
||||
rip_cd_dialog_->show();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user