Refactoring
This commit is contained in:
@@ -61,7 +61,9 @@ TagReaderClient::TagReaderClient(QObject *parent)
|
||||
|
||||
setObjectName(QLatin1String(metaObject()->className()));
|
||||
|
||||
sInstance = this;
|
||||
if (!sInstance) {
|
||||
sInstance = this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -154,20 +156,20 @@ void TagReaderClient::ProcessRequest(TagReaderRequestPtr request) {
|
||||
|
||||
TagReaderResult result;
|
||||
|
||||
if (TagReaderIsMediaFileRequestPtr is_media_file_request = std::dynamic_pointer_cast<TagReaderIsMediaFileRequest>(request)) {
|
||||
if (TagReaderIsMediaFileRequestPtr is_media_file_request = dynamic_pointer_cast<TagReaderIsMediaFileRequest>(request)) {
|
||||
result = tagreader_.IsMediaFile(is_media_file_request->filename);
|
||||
if (result.error_code == TagReaderResult::ErrorCode::Unsupported) {
|
||||
result = gmereader_.IsMediaFile(is_media_file_request->filename);
|
||||
}
|
||||
}
|
||||
else if (TagReaderReadFileRequestPtr read_file_request = std::dynamic_pointer_cast<TagReaderReadFileRequest>(request)) {
|
||||
else if (TagReaderReadFileRequestPtr read_file_request = dynamic_pointer_cast<TagReaderReadFileRequest>(request)) {
|
||||
Song song;
|
||||
result = ReadFileBlocking(read_file_request->filename, &song);
|
||||
if (result.error_code == TagReaderResult::ErrorCode::Unsupported) {
|
||||
result = gmereader_.ReadFile(read_file_request->filename, &song);
|
||||
}
|
||||
if (result.success()) {
|
||||
if (TagReaderReadFileReplyPtr read_file_reply = std::dynamic_pointer_cast<TagReaderReadFileReply>(reply)) {
|
||||
if (TagReaderReadFileReplyPtr read_file_reply = qSharedPointerDynamicCast<TagReaderReadFileReply>(reply)) {
|
||||
read_file_reply->set_song(song);
|
||||
}
|
||||
}
|
||||
@@ -179,7 +181,7 @@ void TagReaderClient::ProcessRequest(TagReaderRequestPtr request) {
|
||||
QByteArray cover_data;
|
||||
result = LoadCoverDataBlocking(load_cover_data_request->filename, cover_data);
|
||||
if (result.success()) {
|
||||
if (TagReaderLoadCoverDataReplyPtr load_cover_data_reply = std::dynamic_pointer_cast<TagReaderLoadCoverDataReply>(reply)) {
|
||||
if (TagReaderLoadCoverDataReplyPtr load_cover_data_reply = qSharedPointerDynamicCast<TagReaderLoadCoverDataReply>(reply)) {
|
||||
load_cover_data_reply->set_data(cover_data);
|
||||
}
|
||||
}
|
||||
@@ -188,7 +190,7 @@ void TagReaderClient::ProcessRequest(TagReaderRequestPtr request) {
|
||||
QImage cover_image;
|
||||
result = LoadCoverImageBlocking(load_cover_image_request->filename, cover_image);
|
||||
if (result.success()) {
|
||||
if (TagReaderLoadCoverImageReplyPtr load_cover_image_reply = std::dynamic_pointer_cast<TagReaderLoadCoverImageReply>(reply)) {
|
||||
if (TagReaderLoadCoverImageReplyPtr load_cover_image_reply = qSharedPointerDynamicCast<TagReaderLoadCoverImageReply>(reply)) {
|
||||
load_cover_image_reply->set_image(cover_image);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
#include <QImage>
|
||||
#include <QMutex>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/mutex_protected.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "includes/mutex_protected.h"
|
||||
#include "core/song.h"
|
||||
|
||||
#include "tagreadertaglib.h"
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "constants/timeconstants.h"
|
||||
#include "core/logging.h"
|
||||
#include "tagreaderbase.h"
|
||||
#include "tagreadertaglib.h"
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreaderrequest.h"
|
||||
|
||||
using std::make_shared;
|
||||
|
||||
@@ -31,6 +31,12 @@ void TagReaderLoadCoverDataReply::Finish() {
|
||||
|
||||
finished_ = true;
|
||||
|
||||
QMetaObject::invokeMethod(this, &TagReaderLoadCoverDataReply::EmitFinished, Qt::QueuedConnection);
|
||||
|
||||
}
|
||||
|
||||
void TagReaderLoadCoverDataReply::EmitFinished() {
|
||||
|
||||
Q_EMIT TagReaderReply::Finished(filename_, result_);
|
||||
Q_EMIT TagReaderLoadCoverDataReply::Finished(filename_, data_, result_);
|
||||
|
||||
|
||||
@@ -22,9 +22,8 @@
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "tagreaderreply.h"
|
||||
#include "tagreaderresult.h"
|
||||
|
||||
@@ -42,10 +41,13 @@ class TagReaderLoadCoverDataReply : public TagReaderReply {
|
||||
Q_SIGNALS:
|
||||
void Finished(const QString &filename, const QByteArray &data, const TagReaderResult &result);
|
||||
|
||||
private Q_SLOTS:
|
||||
void EmitFinished() override;
|
||||
|
||||
private:
|
||||
QByteArray data_;
|
||||
};
|
||||
|
||||
using TagReaderLoadCoverDataReplyPtr = SharedPtr<TagReaderLoadCoverDataReply>;
|
||||
using TagReaderLoadCoverDataReplyPtr = QSharedPointer<TagReaderLoadCoverDataReply>;
|
||||
|
||||
#endif // TAGREADERLOADCOVERDATAREPLY_H
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreaderrequest.h"
|
||||
|
||||
using std::make_shared;
|
||||
|
||||
@@ -31,9 +31,16 @@ void TagReaderLoadCoverImageReply::Finish() {
|
||||
|
||||
finished_ = true;
|
||||
|
||||
QMetaObject::invokeMethod(this, &TagReaderLoadCoverImageReply::EmitFinished, Qt::QueuedConnection);
|
||||
|
||||
}
|
||||
|
||||
void TagReaderLoadCoverImageReply::EmitFinished() {
|
||||
|
||||
Q_EMIT TagReaderReply::Finished(filename_, result_);
|
||||
Q_EMIT TagReaderLoadCoverImageReply::Finished(filename_, image_, result_);
|
||||
|
||||
QObject::disconnect(this, &TagReaderReply::Finished, nullptr, nullptr);
|
||||
QObject::disconnect(this, &TagReaderLoadCoverImageReply::Finished, nullptr, nullptr);
|
||||
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QImage>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "tagreaderreply.h"
|
||||
#include "tagreaderresult.h"
|
||||
|
||||
@@ -42,10 +41,13 @@ class TagReaderLoadCoverImageReply : public TagReaderReply {
|
||||
Q_SIGNALS:
|
||||
void Finished(const QString &filename, const QImage &image, const TagReaderResult &result);
|
||||
|
||||
private Q_SLOTS:
|
||||
void EmitFinished() override;
|
||||
|
||||
private:
|
||||
QImage image_;
|
||||
};
|
||||
|
||||
using TagReaderLoadCoverImageReplyPtr = SharedPtr<TagReaderLoadCoverImageReply>;
|
||||
using TagReaderLoadCoverImageReplyPtr = QSharedPointer<TagReaderLoadCoverImageReply>;
|
||||
|
||||
#endif // TAGREADERLOADCOVERIMAGEREPLY_H
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreaderrequest.h"
|
||||
|
||||
using std::make_shared;
|
||||
|
||||
@@ -31,9 +31,16 @@ void TagReaderReadFileReply::Finish() {
|
||||
|
||||
finished_ = true;
|
||||
|
||||
QMetaObject::invokeMethod(this, &TagReaderReadFileReply::EmitFinished, Qt::QueuedConnection);
|
||||
|
||||
}
|
||||
|
||||
void TagReaderReadFileReply::EmitFinished() {
|
||||
|
||||
Q_EMIT TagReaderReply::Finished(filename_, result_);
|
||||
Q_EMIT TagReaderReadFileReply::Finished(filename_, song_, result_);
|
||||
|
||||
QObject::disconnect(this, &TagReaderReply::Finished, nullptr, nullptr);
|
||||
QObject::disconnect(this, &TagReaderReadFileReply::Finished, nullptr, nullptr);
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#define TAGREADERREADFILEREPLY_H
|
||||
|
||||
#include <QString>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "tagreaderreply.h"
|
||||
#include "tagreaderresult.h"
|
||||
@@ -41,10 +41,13 @@ class TagReaderReadFileReply : public TagReaderReply {
|
||||
Q_SIGNALS:
|
||||
void Finished(const QString &filename, const Song &song, const TagReaderResult &result);
|
||||
|
||||
private Q_SLOTS:
|
||||
void EmitFinished() override;
|
||||
|
||||
private:
|
||||
Song song_;
|
||||
};
|
||||
|
||||
using TagReaderReadFileReplyPtr = SharedPtr<TagReaderReadFileReply>;
|
||||
using TagReaderReadFileReplyPtr = QSharedPointer<TagReaderReadFileReply>;
|
||||
|
||||
#endif // TAGREADERREADFILEREPLY_H
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreaderrequest.h"
|
||||
|
||||
using std::make_shared;
|
||||
|
||||
@@ -34,7 +34,7 @@ TagReaderReply::TagReaderReply(const QString &filename, QObject *parent)
|
||||
|
||||
TagReaderReply::~TagReaderReply() {
|
||||
|
||||
qLog(Debug) << "Deleting tagreader reply for" << filename_;
|
||||
qLog(Debug) << "Tagreader reply for" << filename_ << "deleted";
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,13 @@ void TagReaderReply::Finish() {
|
||||
|
||||
finished_ = true;
|
||||
|
||||
Q_EMIT Finished(filename_, result_);
|
||||
QMetaObject::invokeMethod(this, &TagReaderReply::EmitFinished, Qt::QueuedConnection);
|
||||
|
||||
}
|
||||
|
||||
void TagReaderReply::EmitFinished() {
|
||||
|
||||
Q_EMIT TagReaderReply::Finished(filename_, result_);
|
||||
|
||||
QObject::disconnect(this, &TagReaderReply::Finished, nullptr, nullptr);
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "tagreaderresult.h"
|
||||
|
||||
class TagReaderReply : public QObject {
|
||||
@@ -34,12 +34,8 @@ class TagReaderReply : public QObject {
|
||||
virtual ~TagReaderReply() override;
|
||||
|
||||
template<typename T>
|
||||
static SharedPtr<T> Create(const QString &filename) {
|
||||
|
||||
SharedPtr<T> reply;
|
||||
reply.reset(new T(filename), [](QObject *obj) { obj->deleteLater(); });
|
||||
return reply;
|
||||
|
||||
static QSharedPointer<T> Create(const QString &filename) {
|
||||
return QSharedPointer<T>(new T(filename));
|
||||
}
|
||||
|
||||
QString filename() const { return filename_; }
|
||||
@@ -56,12 +52,15 @@ class TagReaderReply : public QObject {
|
||||
Q_SIGNALS:
|
||||
void Finished(const QString &filename, const TagReaderResult &result);
|
||||
|
||||
private Q_SLOTS:
|
||||
virtual void EmitFinished();
|
||||
|
||||
protected:
|
||||
const QString filename_;
|
||||
bool finished_;
|
||||
TagReaderResult result_;
|
||||
};
|
||||
|
||||
using TagReaderReplyPtr = SharedPtr<TagReaderReply>;
|
||||
using TagReaderReplyPtr = QSharedPointer<TagReaderReply>;
|
||||
|
||||
#endif // TAGREADERREPLY_H
|
||||
|
||||
@@ -29,6 +29,6 @@ TagReaderRequest::TagReaderRequest(const QString &_filename) : filename(_filenam
|
||||
|
||||
TagReaderRequest::~TagReaderRequest() {
|
||||
|
||||
qLog(Debug) << "Deleting tagreader request for" << filename;
|
||||
qLog(Debug) << "Tagreader request for" << filename << "deleted";
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreaderreply.h"
|
||||
|
||||
class TagReaderRequest {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreaderrequest.h"
|
||||
#include "savetagcoverdata.h"
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreaderrequest.h"
|
||||
|
||||
using std::make_shared;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreaderrequest.h"
|
||||
|
||||
using std::make_shared;
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/song.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "constants/timeconstants.h"
|
||||
|
||||
#include "albumcovertagdata.h"
|
||||
|
||||
@@ -278,7 +278,7 @@ TagReaderResult TagReaderTagLib::IsMediaFile(const QString &filename) const {
|
||||
|
||||
}
|
||||
|
||||
Song::FileType TagReaderTagLib::GuessFileType(TagLib::FileRef *fileref) const {
|
||||
Song::FileType TagReaderTagLib::GuessFileType(TagLib::FileRef *fileref) {
|
||||
|
||||
if (dynamic_cast<TagLib::RIFF::WAV::File*>(fileref->file())) return Song::FileType::WAV;
|
||||
if (dynamic_cast<TagLib::FLAC::File*>(fileref->file())) return Song::FileType::FLAC;
|
||||
|
||||
@@ -75,7 +75,7 @@ class TagReaderTagLib : public TagReaderBase {
|
||||
TagReaderResult SaveSongRating(const QString &filename, const float rating) const override;
|
||||
|
||||
private:
|
||||
Song::FileType GuessFileType(TagLib::FileRef *fileref) const;
|
||||
static Song::FileType GuessFileType(TagLib::FileRef *fileref);
|
||||
|
||||
void ParseID3v2Tags(TagLib::ID3v2::Tag *tag, QString *disc, QString *compilation, Song *song) const;
|
||||
void ParseVorbisComments(const TagLib::Ogg::FieldListMap &map, QString *disc, QString *compilation, Song *song) const;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "tagreaderrequest.h"
|
||||
#include "savetagsoptions.h"
|
||||
|
||||
Reference in New Issue
Block a user