From 14d5c25d374709928f3017dc7c9336092ad7d80d Mon Sep 17 00:00:00 2001 From: Lukas Prediger Date: Sun, 30 May 2021 16:17:09 +0300 Subject: [PATCH] Integrated cddevice back into cddadevice --- src/CMakeLists.txt | 2 -- src/devices/cddadevice.cpp | 44 +++++++++++++++++++++---------- src/devices/cddadevice.h | 16 +++++++----- src/devices/cddevice.cpp | 45 -------------------------------- src/devices/cddevice.h | 53 -------------------------------------- 5 files changed, 40 insertions(+), 120 deletions(-) delete mode 100644 src/devices/cddevice.cpp delete mode 100644 src/devices/cddevice.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fd5208326..126264c09 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/devices/cddadevice.cpp b/src/devices/cddadevice.cpp index 032da9cb6..8e10a3c9d 100644 --- a/src/devices/cddadevice.cpp +++ b/src/devices/cddadevice.cpp @@ -17,18 +17,19 @@ #include "cddadevice.h" -#include - -#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(); + } } diff --git a/src/devices/cddadevice.h b/src/devices/cddadevice.h index 9987a08b4..c60bb3179 100644 --- a/src/devices/cddadevice.h +++ b/src/devices/cddadevice.h @@ -18,17 +18,15 @@ #ifndef CDDADEVICE_H #define CDDADEVICE_H -#include +#include +#include // These must come after Qt includes (issue 3247) #include -#include #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_; }; diff --git a/src/devices/cddevice.cpp b/src/devices/cddevice.cpp deleted file mode 100644 index 1f57b2dd0..000000000 --- a/src/devices/cddevice.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* This file is part of Clementine. - Copyright 2021, Lukas Prediger - - 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 . -*/ - -#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(); -} diff --git a/src/devices/cddevice.h b/src/devices/cddevice.h deleted file mode 100644 index 2bc0bd860..000000000 --- a/src/devices/cddevice.h +++ /dev/null @@ -1,53 +0,0 @@ -/* This file is part of Clementine. - Copyright 2021, Lukas Prediger - - 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 . -*/ - -#ifndef CDDEVICE_H -#define CDDEVICE_H - -#include -#include -#include - -// Qt import must come first -#include - -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