RipCDDialog now allows selecting the CD drive

This commit is contained in:
Lukas Prediger 2021-06-01 18:51:00 +03:00 committed by John Maguire
parent b68734c761
commit 63953e1045
5 changed files with 207 additions and 100 deletions

View File

@ -1,5 +1,6 @@
/* This file is part of Clementine. /* This file is part of Clementine.
Copyright 2014, Andre Siviero <altsiviero@gmail.com> Copyright 2014, Andre Siviero <altsiviero@gmail.com>
Copyright 2021, Lukas Prediger <lumip@lumip.de>
Clementine is free software: you can redistribute it and/or modify Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -32,6 +33,7 @@
#include "core/tagreaderclient.h" #include "core/tagreaderclient.h"
#include "devices/cddadevice.h" #include "devices/cddadevice.h"
#include "devices/cddasongloader.h" #include "devices/cddasongloader.h"
#include "devices/devicemanager.h"
#include "ripper/ripper.h" #include "ripper/ripper.h"
#include "transcoder/transcoder.h" #include "transcoder/transcoder.h"
#include "transcoder/transcoderoptionsdialog.h" #include "transcoder/transcoderoptionsdialog.h"
@ -52,15 +54,15 @@ const int kTrackDurationColumn = 3;
const char* RipCDDialog::kSettingsGroup = "Transcoder"; const char* RipCDDialog::kSettingsGroup = "Transcoder";
const int RipCDDialog::kMaxDestinationItems = 10; const int RipCDDialog::kMaxDestinationItems = 10;
RipCDDialog::RipCDDialog(std::shared_ptr<CddaDevice> cdda_device, RipCDDialog::RipCDDialog(DeviceManager& device_manager, QWidget* parent)
QWidget* parent)
: QDialog(parent), : QDialog(parent),
ui_(new Ui_RipCDDialog), ui_(new Ui_RipCDDialog),
device_manager_(device_manager),
cdda_devices_(
device_manager.FindDeviceByUrlSchemes(CddaDevice::url_schemes())),
working_(false), working_(false),
cdda_device_(std::move(cdda_device)), cdda_device_(),
loader_(cdda_device_->loader()), loader_(nullptr) {
ripper_(new Ripper(cdda_device_->raw_cdio(), this)) {
Q_ASSERT(cdda_device_);
// Init // Init
ui_->setupUi(this); ui_->setupUi(this);
@ -82,30 +84,21 @@ RipCDDialog::RipCDDialog(std::shared_ptr<CddaDevice> cdda_device,
cancel_button_->hide(); cancel_button_->hide();
ui_->progress_group->hide(); ui_->progress_group->hide();
rip_button_->setEnabled(false); // will be enabled by DeviceSelected if a
// valid device is selected
InitializeDevices();
connect(ui_->select_all_button, SIGNAL(clicked()), SLOT(SelectAll())); connect(ui_->select_all_button, SIGNAL(clicked()), SLOT(SelectAll()));
connect(ui_->select_none_button, SIGNAL(clicked()), SLOT(SelectNone())); connect(ui_->select_none_button, SIGNAL(clicked()), SLOT(SelectNone()));
connect(ui_->invert_selection_button, SIGNAL(clicked()), connect(ui_->invert_selection_button, SIGNAL(clicked()),
SLOT(InvertSelection())); SLOT(InvertSelection()));
connect(rip_button_, SIGNAL(clicked()), SLOT(ClickedRipButton())); connect(rip_button_, SIGNAL(clicked()), SLOT(ClickedRipButton()));
connect(cancel_button_, SIGNAL(clicked()), ripper_, SLOT(Cancel()));
connect(close_button_, SIGNAL(clicked()), SLOT(hide())); connect(close_button_, SIGNAL(clicked()), SLOT(hide()));
connect(ui_->options, SIGNAL(clicked()), SLOT(Options())); connect(ui_->options, SIGNAL(clicked()), SLOT(Options()));
connect(ui_->select, SIGNAL(clicked()), SLOT(AddDestination())); connect(ui_->select, SIGNAL(clicked()), SLOT(AddDestination()));
connect(loader_, SIGNAL(SongsDurationLoaded(SongList)),
SLOT(BuildTrackListTable(SongList)));
connect(loader_, SIGNAL(SongsMetadataLoaded(SongList)),
SLOT(UpdateTrackListTable(SongList)));
connect(loader_, SIGNAL(SongsMetadataLoaded(SongList)),
SLOT(AddAlbumMetadataFromMusicBrainz(SongList)));
connect(ripper_, SIGNAL(Finished()), SLOT(Finished()));
connect(ripper_, SIGNAL(Cancelled()), SLOT(Cancelled()));
connect(ripper_, SIGNAL(ProgressInterval(int, int)),
SLOT(SetupProgressBarLimits(int, int)));
connect(ripper_, SIGNAL(Progress(int)), SLOT(UpdateProgressBar(int)));
setWindowTitle(tr("Rip CD")); setWindowTitle(tr("Rip CD"));
AddDestinationDirectory(QDir::homePath()); AddDestinationDirectory(QDir::homePath());
@ -131,8 +124,6 @@ RipCDDialog::RipCDDialog(std::shared_ptr<CddaDevice> cdda_device,
break; break;
} }
} }
connect(cdda_device_.get(), SIGNAL(DiscChanged()), SLOT(DiscChanged()));
} }
RipCDDialog::~RipCDDialog() {} RipCDDialog::~RipCDDialog() {}
@ -145,15 +136,56 @@ void RipCDDialog::closeEvent(QCloseEvent* event) {
void RipCDDialog::showEvent(QShowEvent* event) { void RipCDDialog::showEvent(QShowEvent* event) {
ResetDialog(); ResetDialog();
loader_->LoadSongs(); if (loader_) loader_->LoadSongs();
if (!working_) { if (!working_) {
ui_->progress_group->hide(); ui_->progress_group->hide();
} }
} }
void RipCDDialog::InitializeDevices() {
Q_ASSERT(!cdda_device_);
// add all devices to drop down selection
for (const DeviceInfo* device_info : cdda_devices_) {
ui_->cd_drive_selection->addItem(device_info->friendly_name_);
}
// ensure that selecting the first device below will emit a
// currentIndexChanged signal
ui_->cd_drive_selection->setCurrentIndex(-1);
connect(ui_->cd_drive_selection, SIGNAL(currentIndexChanged(int)),
SLOT(DeviceSelected(int)));
// look for any already connected device, guess that might be the one the user
// is interested in and make it the active selection
for (int i = 0; i < cdda_devices_.size(); ++i) {
DeviceInfo* device_info = cdda_devices_[i];
if (device_info->device_) {
// found one!
ui_->cd_drive_selection->setCurrentIndex(i);
return;
}
}
// there is no device that is already connected; just select the first one
if (!cdda_devices_.isEmpty()) ui_->cd_drive_selection->setCurrentIndex(0);
}
void RipCDDialog::ClickedRipButton() { void RipCDDialog::ClickedRipButton() {
Q_ASSERT(cdda_device_);
// create and connect Ripper instance for this task
Ripper* ripper = new Ripper(cdda_device_->raw_cdio(), this);
connect(cancel_button_, SIGNAL(clicked()), ripper, SLOT(Cancel()));
connect(ripper, SIGNAL(Finished()), SLOT(Finished()));
connect(ripper, SIGNAL(Cancelled()), SLOT(Cancelled()));
connect(ripper, SIGNAL(ProgressInterval(int, int)),
SLOT(SetupProgressBarLimits(int, int)));
connect(ripper, SIGNAL(Progress(int)), SLOT(UpdateProgressBar(int)));
// Add tracks and album information to the ripper. // Add tracks and album information to the ripper.
ripper_->ClearTracks(); ripper->ClearTracks();
TranscoderPreset preset = ui_->format->itemData(ui_->format->currentIndex()) TranscoderPreset preset = ui_->format->itemData(ui_->format->currentIndex())
.value<TranscoderPreset>(); .value<TranscoderPreset>();
for (int i = 1; i <= ui_->tableWidget->rowCount(); ++i) { for (int i = 1; i <= ui_->tableWidget->rowCount(); ++i) {
@ -163,15 +195,15 @@ void RipCDDialog::ClickedRipButton() {
QString transcoded_filename = GetOutputFileName( QString transcoded_filename = GetOutputFileName(
ParseFileFormatString(ui_->format_filename->text(), i)); ParseFileFormatString(ui_->format_filename->text(), i));
QString title = track_names_.value(i - 1)->text(); QString title = track_names_.value(i - 1)->text();
ripper_->AddTrack(i, title, transcoded_filename, preset); ripper->AddTrack(i, title, transcoded_filename, preset);
} }
ripper_->SetAlbumInformation( ripper->SetAlbumInformation(
ui_->albumLineEdit->text(), ui_->artistLineEdit->text(), ui_->albumLineEdit->text(), ui_->artistLineEdit->text(),
ui_->genreLineEdit->text(), ui_->yearLineEdit->text().toInt(), ui_->genreLineEdit->text(), ui_->yearLineEdit->text().toInt(),
ui_->discLineEdit->text().toInt(), preset.type_); ui_->discLineEdit->text().toInt(), preset.type_);
SetWorking(true); SetWorking(true);
ripper_->Start(); ripper->Start();
} }
void RipCDDialog::Options() { void RipCDDialog::Options() {
@ -233,11 +265,57 @@ void RipCDDialog::InvertSelection() {
} }
} }
void RipCDDialog::Finished() { SetWorking(false); } void RipCDDialog::DeviceSelected(int device_index) {
// disconnecting from previous loader and device, if any
if (loader_) disconnect(loader_, nullptr, this, nullptr);
if (cdda_device_) disconnect(cdda_device_.get(), nullptr, this, nullptr);
ResetDialog();
if (device_index < 0)
return; // Invalid selection, probably no devices around
Q_ASSERT(device_index < cdda_devices_.size());
DeviceInfo* device_info = cdda_devices_[device_index];
std::shared_ptr<ConnectedDevice> device =
device_manager_.Connect(device_info);
cdda_device_ = std::dynamic_pointer_cast<CddaDevice>(device);
if (!cdda_device_) {
rip_button_->setEnabled(false);
QMessageBox cdio_fail(QMessageBox::Critical, tr("Error"),
tr("Failed reading CD drive"));
cdio_fail.exec();
return;
}
connect(cdda_device_.get(), SIGNAL(DiscChanged()), SLOT(DiscChanged()));
// get SongLoader from device and connect signals
loader_ = cdda_device_->loader();
Q_ASSERT(loader_);
connect(loader_, SIGNAL(SongsDurationLoaded(SongList)),
SLOT(BuildTrackListTable(SongList)));
connect(loader_, SIGNAL(SongsMetadataLoaded(SongList)),
SLOT(UpdateTrackListTable(SongList)));
connect(loader_, SIGNAL(SongsMetadataLoaded(SongList)),
SLOT(AddAlbumMetadataFromMusicBrainz(SongList)));
// load songs from new SongLoader
loader_->LoadSongs();
rip_button_->setEnabled(true);
}
void RipCDDialog::Finished() {
SetWorking(false);
Ripper* ripper = dynamic_cast<Ripper*>(sender());
Q_ASSERT(ripper);
ripper->deleteLater();
}
void RipCDDialog::Cancelled() { void RipCDDialog::Cancelled() {
ui_->progress_bar->setValue(0); ui_->progress_bar->setValue(0);
SetWorking(false); Finished();
} }
void RipCDDialog::SetupProgressBarLimits(int min, int max) { void RipCDDialog::SetupProgressBarLimits(int min, int max) {

View File

@ -1,5 +1,6 @@
/* This file is part of Clementine. /* This file is part of Clementine.
Copyright 2014, Andre Siviero <altsiviero@gmail.com> Copyright 2014, Andre Siviero <altsiviero@gmail.com>
Copyright 2021, Lukas Prediger <lumip@lumip.de>
Clementine is free software: you can redistribute it and/or modify Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -34,12 +35,14 @@ class CddaSongLoader;
class Ripper; class Ripper;
class Ui_RipCDDialog; class Ui_RipCDDialog;
class CddaDevice; class CddaDevice;
class DeviceManager;
class DeviceInfo;
class RipCDDialog : public QDialog { class RipCDDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit RipCDDialog(std::shared_ptr<CddaDevice> cdda_device, explicit RipCDDialog(DeviceManager& device_manager,
QWidget* parent = nullptr); QWidget* parent = nullptr);
~RipCDDialog(); ~RipCDDialog();
@ -54,6 +57,7 @@ class RipCDDialog : public QDialog {
void SelectAll(); void SelectAll();
void SelectNone(); void SelectNone();
void InvertSelection(); void InvertSelection();
void DeviceSelected(int device_index);
void Finished(); void Finished();
void Cancelled(); void Cancelled();
void SetupProgressBarLimits(int min, int max); void SetupProgressBarLimits(int min, int max);
@ -79,6 +83,7 @@ class RipCDDialog : public QDialog {
QString ParseFileFormatString(const QString& file_format, int track_no) const; QString ParseFileFormatString(const QString& file_format, int track_no) const;
void SetWorking(bool working); void SetWorking(bool working);
void ResetDialog(); void ResetDialog();
void InitializeDevices();
QList<QCheckBox*> checkboxes_; QList<QCheckBox*> checkboxes_;
QList<QLineEdit*> track_names_; QList<QLineEdit*> track_names_;
@ -87,9 +92,10 @@ class RipCDDialog : public QDialog {
QPushButton* close_button_; QPushButton* close_button_;
QPushButton* rip_button_; QPushButton* rip_button_;
std::unique_ptr<Ui_RipCDDialog> ui_; std::unique_ptr<Ui_RipCDDialog> ui_;
DeviceManager& device_manager_;
QList<DeviceInfo*> cdda_devices_;
bool working_; bool working_;
std::shared_ptr<CddaDevice> cdda_device_; std::shared_ptr<CddaDevice> cdda_device_;
CddaSongLoader* loader_; CddaSongLoader* loader_;
Ripper* ripper_;
}; };
#endif // SRC_RIPPER_RIPCDDIALOG_H_ #endif // SRC_RIPPER_RIPCDDIALOG_H_

View File

@ -10,14 +10,14 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>522</width> <width>522</width>
<height>563</height> <height>575</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset> <iconset resource="../../data/data.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset> <normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@ -27,9 +27,90 @@
<string>Input options</string> <string>Input options</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="cd_drive_group">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<spacer name="cd_drive_spacer_left">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="cd_drive_label">
<property name="text">
<string>CD Drive</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cd_drive_selection"/>
</item>
<item>
<spacer name="cd_drive_spacer_right">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0"> <item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="select_all_button">
<property name="text">
<string>Select All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="select_none_button">
<property name="text">
<string>Select None</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="invert_selection_button">
<property name="text">
<string>Invert Selection</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QTableWidget" name="tableWidget"> <widget class="QTableWidget" name="tableWidget">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -74,44 +155,6 @@
</column> </column>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="select_all_button">
<property name="text">
<string>Select All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="select_none_button">
<property name="text">
<string>Select None</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="invert_selection_button">
<property name="text">
<string>Invert Selection</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -296,6 +339,8 @@
<tabstop>select</tabstop> <tabstop>select</tabstop>
<tabstop>button_box</tabstop> <tabstop>button_box</tabstop>
</tabstops> </tabstops>
<resources/> <resources>
<include location="../../data/data.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -1129,6 +1129,10 @@ msgstr "Tasten"
msgid "CBC Podcasts" msgid "CBC Podcasts"
msgstr "CBC Podcasts" msgstr "CBC Podcasts"
#: ../build/src/ui_ripcddialog.h:329
msgid "CD Drive"
msgstr "CD-Laufwerk"
#: core/song.cpp:453 #: core/song.cpp:453
msgid "CDDA" msgid "CDDA"
msgstr "CDDA" msgstr "CDDA"

View File

@ -57,9 +57,6 @@
#include "core/taskmanager.h" #include "core/taskmanager.h"
#include "core/timeconstants.h" #include "core/timeconstants.h"
#include "core/utilities.h" #include "core/utilities.h"
#ifdef HAVE_AUDIOCD
#include "devices/cddadevice.h"
#endif
#include "devices/devicemanager.h" #include "devices/devicemanager.h"
#include "devices/devicestatefiltermodel.h" #include "devices/devicestatefiltermodel.h"
#include "devices/deviceview.h" #include "devices/deviceview.h"
@ -2223,31 +2220,8 @@ void MainWindow::AddStreamAccepted() {
void MainWindow::OpenRipCDDialog() { void MainWindow::OpenRipCDDialog() {
#ifdef HAVE_AUDIOCD #ifdef HAVE_AUDIOCD
if (!rip_cd_dialog_) { if (!rip_cd_dialog_) {
QList<DeviceInfo*> cd_device_infos = Q_ASSERT(app_->device_manager());
app_->device_manager()->FindDeviceByUrlSchemes( rip_cd_dialog_ = std::make_unique<RipCDDialog>(*(app_->device_manager()));
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(); rip_cd_dialog_->show();
#endif #endif