From 5d2d3b1b138f41ee2e9ce3dbeb09e7c2ca36d35a Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Fri, 10 May 2013 19:03:02 +0000 Subject: [PATCH] After ripping a CD, prompt as to whether to calculate ReplyGain. --- ChangeLog | 1 + devices/actiondialog.cpp | 61 +++++++++++++++++++++++++--------------- devices/actiondialog.h | 4 +++ replaygain/rgdialog.cpp | 10 ++++++- replaygain/rgdialog.h | 4 ++- 5 files changed, 56 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 349e42a79..c503a0c90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ 3. If cover name contains %artist%, then replace with the album artist of the current song. Likewise for %album% 4. Add option (to sidebar context menu) to toggle usage of monochrome icons. +5. After ripping a CD, prompt as to whether to calculate ReplyGain. 1.0.3 ----- diff --git a/devices/actiondialog.cpp b/devices/actiondialog.cpp index 42f494203..053a6e6e2 100644 --- a/devices/actiondialog.cpp +++ b/devices/actiondialog.cpp @@ -40,9 +40,13 @@ #include "freespaceinfo.h" #include "icons.h" #include "config.h" +#include "tags.h" #ifdef ENABLE_ONLINE_SERVICES #include "onlineservicesmodel.h" #endif +#ifdef ENABLE_REPLAYGAIN_SUPPORT +#include "rgdialog.h" +#endif #include static int iCount=0; @@ -88,7 +92,7 @@ ActionDialog::~ActionDialog() void ActionDialog::controlInfoLabel(Device *dev) { DeviceOptions opts; - if (Device::AudioCd==dev->devType()) { + if (sourceIsAudioCd) { opts.load(MPDConnectionDetails::configGroupName(MPDConnection::self()->getDetails().name), true); } else if (sourceUdi.isEmpty()) { opts=dev->options(); @@ -116,10 +120,10 @@ void ActionDialog::controlInfoLabel(Device *dev) index++; } codec->setText(QString("%1 (%2)").arg(encoder.name).arg(encoder.values.at(settingIndex).descr)+ - (Device::AudioCd!=dev->devType() && opts.transcoderWhenDifferent ? QLatin1String("")+i18n("(When different)") : QString())); + (sourceIsAudioCd && opts.transcoderWhenDifferent ? QLatin1String("")+i18n("(When different)") : QString())); } else { codec->setText(encoder.name+ - (Device::AudioCd!=dev->devType() && opts.transcoderWhenDifferent ? QLatin1String("")+i18n("(When different)") : QString())); + (sourceIsAudioCd && opts.transcoderWhenDifferent ? QLatin1String("")+i18n("(When different)") : QString())); } } } @@ -139,6 +143,7 @@ void ActionDialog::copy(const QString &srcUdi, const QString &dstUdi, const QLis return; } + sourceIsAudioCd=Device::AudioCd==dev->devType(); controlInfoLabel(dev); // check space... @@ -182,7 +187,7 @@ void ActionDialog::copy(const QString &srcUdi, const QString &dstUdi, const QLis overwrite->setChecked(Settings::self()->overwriteSongs()); sourceLabel->setText(QLatin1String("")+(sourceUdi.isEmpty() ? i18n("Local Music Library") - : Device::AudioCd==dev->devType() + : sourceIsAudioCd ? i18n("Audio CD") : dev->data())+QLatin1String("")); destinationLabel->setText(QLatin1String("")+(destUdi.isEmpty() ? i18n("Local Music Library") : dev->data())+QLatin1String("")); @@ -249,6 +254,7 @@ void ActionDialog::init(const QString &srcUdi, const QString &dstUdi, const QLis resize(500, 160); sourceUdi=srcUdi; destUdi=dstUdi; + sourceIsAudioCd=false; songsToAction=songs; mode=m; setCaption(Copy==mode ? i18n("Copy Songs") : i18n("Delete Songs")); @@ -266,6 +272,9 @@ void ActionDialog::init(const QString &srcUdi, const QString &dstUdi, const QLis currentPercent=0; currentDev=0; count=0; + #ifdef ENABLE_REPLAYGAIN_SUPPORT + albumsWithoutRgTags.clear(); + #endif } void ActionDialog::slotButtonClicked(int button) @@ -462,6 +471,24 @@ void ActionDialog::doNext() if (!refreshLibrary()) { emit completed(); accept(); + #ifdef ENABLE_REPLAYGAIN_SUPPORT + if (Copy==mode && !albumsWithoutRgTags.isEmpty() && sourceIsAudioCd) { + QWidget *pw=parentWidget(); + if (MessageBox::Yes==MessageBox::questionYesNo(pw, i18n("Calculate ReplayGain for ripped tracks?"))) { + RgDialog *dlg=new RgDialog(pw); + QList songs; + + foreach (const Song &s, actionedSongs) { + if (albumsWithoutRgTags.contains(s.album)) { + Song song=s; + song.file=namingOptions.createFilename(s); + songs.append(song); + } + } + dlg->show(songs, QString(), true); + } + } + #endif } } } @@ -483,6 +510,11 @@ void ActionDialog::actionStatus(int status, bool copiedCover) if (!wasSkip) { actionedSongs.append(currentSong); actionedTime+=currentSong.time; + #ifdef ENABLE_REPLAYGAIN_SUPPORT + if (Copy==mode && sourceIsAudioCd && !albumsWithoutRgTags.contains(currentSong.album) && Tags::readReplaygain(destFile).isEmpty()) { + albumsWithoutRgTags.insert(currentSong.album); + } + #endif } if (copiedCover) { copiedCovers.insert(Utils::getDir(destFile)); @@ -567,18 +599,13 @@ void ActionDialog::configureSource() void ActionDialog::configure(const QString &udi) { if (udi.isEmpty()) { - Device *dev=DevicesModel::self()->device(sourceUdi); - bool isCd=false; - if (dev) { - isCd=Device::AudioCd==dev->devType(); - } DevicePropertiesDialog *dlg=new DevicePropertiesDialog(this); connect(dlg, SIGNAL(updatedSettings(const QString &, const DeviceOptions &)), SLOT(saveProperties(const QString &, const DeviceOptions &))); if (!mpdConfigured) { connect(dlg, SIGNAL(cancelled()), SLOT(saveProperties())); } dlg->setCaption(i18n("Local Music Library Properties")); - dlg->show(MPDConnection::self()->getDetails().dir, namingOptions, DevicePropertiesWidget::Prop_Basic|(isCd ? DevicePropertiesWidget::Prop_Encoder : 0)); + dlg->show(MPDConnection::self()->getDetails().dir, namingOptions, DevicePropertiesWidget::Prop_Basic|(sourceIsAudioCd ? DevicePropertiesWidget::Prop_Encoder : 0)); connect(dlg, SIGNAL(destroyed()), SLOT(controlInfoLabel())); } else { Device *dev=DevicesModel::self()->device(udi); @@ -592,24 +619,14 @@ void ActionDialog::configure(const QString &udi) void ActionDialog::saveProperties(const QString &path, const DeviceOptions &opts) { Q_UNUSED(path) - Device *dev=DevicesModel::self()->device(sourceUdi); - bool isCd=false; - if (dev) { - isCd=Device::AudioCd==dev->devType(); - } namingOptions=opts; - namingOptions.save(MPDConnectionDetails::configGroupName(MPDConnection::self()->getDetails().name), true, isCd); + namingOptions.save(MPDConnectionDetails::configGroupName(MPDConnection::self()->getDetails().name), true, sourceIsAudioCd); mpdConfigured=true; } void ActionDialog::saveProperties() { - Device *dev=DevicesModel::self()->device(sourceUdi); - bool isCd=false; - if (dev) { - isCd=Device::AudioCd==dev->devType(); - } - namingOptions.save(MPDConnectionDetails::configGroupName(MPDConnection::self()->getDetails().name), true, isCd); + namingOptions.save(MPDConnectionDetails::configGroupName(MPDConnection::self()->getDetails().name), true, sourceIsAudioCd); mpdConfigured=true; } diff --git a/devices/actiondialog.h b/devices/actiondialog.h index 62f5543ec..d3ff0bc6f 100644 --- a/devices/actiondialog.h +++ b/devices/actiondialog.h @@ -83,6 +83,7 @@ private: private: Mode mode; + bool sourceIsAudioCd; QString sourceUdi; QString destUdi; QList songsToAction; @@ -106,6 +107,9 @@ private: Device *currentDev; QString destFile; DeviceOptions namingOptions; + #ifdef ENABLE_REPLAYGAIN_SUPPORT + QSet albumsWithoutRgTags; + #endif }; #endif diff --git a/replaygain/rgdialog.cpp b/replaygain/rgdialog.cpp index 3dc37d6e9..e9f499af3 100644 --- a/replaygain/rgdialog.cpp +++ b/replaygain/rgdialog.cpp @@ -107,6 +107,7 @@ RgDialog::RgDialog(QWidget *parent) , state(State_Idle) , totalToScan(0) , tagReader(0) + , autoScanTags(false) { iCount++; setButtons(User1|Ok|Cancel); @@ -165,13 +166,14 @@ RgDialog::~RgDialog() iCount--; } -void RgDialog::show(const QList &songs, const QString &udi) +void RgDialog::show(const QList &songs, const QString &udi, bool autoScan) { if (songs.count()<1) { deleteLater(); return; } + autoScanTags=autoScan; origSongs=songs; qSort(origSongs); #ifdef ENABLE_DEVICES_SUPPORT @@ -369,6 +371,7 @@ void RgDialog::stopReadingTags() disconnect(tagReader, SIGNAL(done()), this, SLOT(tagReaderDone())); tagReader->requestAbort(); tagReader=0; + autoScanTags=false; } void RgDialog::saveTags() @@ -634,6 +637,11 @@ void RgDialog::tagReaderDone() enableButton(User1, true); progress->setVisible(false); statusLabel->setVisible(false); + + if (autoScanTags) { + autoScanTags=false; + startScanning(); + } } void RgDialog::closeEvent(QCloseEvent *event) diff --git a/replaygain/rgdialog.h b/replaygain/rgdialog.h index 6c6552562..4f6f29ecb 100644 --- a/replaygain/rgdialog.h +++ b/replaygain/rgdialog.h @@ -48,7 +48,7 @@ public: RgDialog(QWidget *parent); virtual ~RgDialog(); - void show(const QList &songs, const QString &udi); + void show(const QList &songs, const QString &udi, bool autoScan=false); Q_SIGNALS: // These are for communicating with MPD object (which is in its own thread, so need to talk via signal/slots) @@ -114,6 +114,8 @@ private: QMap origTags; QSet needToSave; TagReader *tagReader; + + bool autoScanTags; }; #endif