2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2011, David Sansome <me@davidsansome.com>
|
2023-05-14 11:34:55 +02:00
|
|
|
* Copyright 2019-2023, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TAGREADERCLIENT_H
|
|
|
|
#define TAGREADERCLIENT_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QList>
|
|
|
|
#include <QString>
|
|
|
|
#include <QImage>
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "core/messagehandler.h"
|
|
|
|
#include "core/workerpool.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "song.h"
|
|
|
|
#include "tagreadermessages.pb.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-24 23:29:09 +02:00
|
|
|
class QThread;
|
2018-05-01 00:41:33 +02:00
|
|
|
class Song;
|
2022-03-22 21:09:05 +01:00
|
|
|
template<typename HandlerType> class WorkerPool;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
class TagReaderClient : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TagReaderClient(QObject *parent = nullptr);
|
|
|
|
|
2022-10-13 22:39:31 +02:00
|
|
|
using HandlerType = AbstractMessageHandler<spb::tagreader::Message>;
|
|
|
|
using ReplyType = HandlerType::ReplyType;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void Start();
|
2019-07-24 23:29:09 +02:00
|
|
|
void ExitAsync();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2023-05-14 11:34:55 +02:00
|
|
|
enum class SaveType {
|
|
|
|
NoType = 0,
|
|
|
|
Tags = 1,
|
|
|
|
PlayCount = 2,
|
|
|
|
Rating = 4,
|
|
|
|
Cover = 8
|
2023-03-18 20:03:07 +01:00
|
|
|
};
|
2023-05-14 11:34:55 +02:00
|
|
|
Q_DECLARE_FLAGS(SaveTypes, SaveType)
|
2023-03-18 20:03:07 +01:00
|
|
|
|
|
|
|
class SaveCoverOptions {
|
|
|
|
public:
|
2023-05-14 11:34:55 +02:00
|
|
|
explicit SaveCoverOptions(const QString &_cover_filename = QString(), const QByteArray &_cover_data = QByteArray(), const QString &_mime_type = QString()) : cover_filename(_cover_filename), cover_data(_cover_data), mime_type(_mime_type) {}
|
|
|
|
explicit SaveCoverOptions(const QString &_cover_filename, const QString &_mime_type = QString()) : cover_filename(_cover_filename), mime_type(_mime_type) {}
|
|
|
|
explicit SaveCoverOptions(const QByteArray &_cover_data, const QString &_mime_type = QString()) : cover_data(_cover_data), mime_type(_mime_type) {}
|
2023-03-18 20:03:07 +01:00
|
|
|
QString cover_filename;
|
|
|
|
QByteArray cover_data;
|
2023-05-14 11:34:55 +02:00
|
|
|
QString mime_type;
|
2023-03-18 20:03:07 +01:00
|
|
|
};
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
ReplyType *IsMediaFile(const QString &filename);
|
2023-03-18 20:03:07 +01:00
|
|
|
ReplyType *ReadFile(const QString &filename);
|
2023-05-14 11:34:55 +02:00
|
|
|
ReplyType *SaveFile(const QString &filename, const Song &metadata, const SaveTypes types = SaveType::Tags, const SaveCoverOptions &save_cover_options = SaveCoverOptions());
|
2018-02-27 18:06:05 +01:00
|
|
|
ReplyType *LoadEmbeddedArt(const QString &filename);
|
2023-03-18 20:03:07 +01:00
|
|
|
ReplyType *SaveEmbeddedArt(const QString &filename, const SaveCoverOptions &save_cover_options);
|
2022-03-22 21:09:05 +01:00
|
|
|
ReplyType *UpdateSongPlaycount(const Song &metadata);
|
|
|
|
ReplyType *UpdateSongRating(const Song &metadata);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Convenience functions that call the above functions and wait for a response.
|
|
|
|
// These block the calling thread with a semaphore, and must NOT be called from the TagReaderClient's thread.
|
2018-02-27 18:06:05 +01:00
|
|
|
void ReadFileBlocking(const QString &filename, Song *song);
|
2023-05-14 11:34:55 +02:00
|
|
|
bool SaveFileBlocking(const QString &filename, const Song &metadata, const SaveTypes types = SaveType::Tags, const SaveCoverOptions &save_cover_options = SaveCoverOptions());
|
2018-02-27 18:06:05 +01:00
|
|
|
bool IsMediaFileBlocking(const QString &filename);
|
2021-02-26 21:03:51 +01:00
|
|
|
QByteArray LoadEmbeddedArtBlocking(const QString &filename);
|
|
|
|
QImage LoadEmbeddedArtAsImageBlocking(const QString &filename);
|
2023-03-18 20:03:07 +01:00
|
|
|
bool SaveEmbeddedArtBlocking(const QString &filename, const SaveCoverOptions &save_cover_options);
|
2021-10-24 16:08:17 +02:00
|
|
|
bool UpdateSongPlaycountBlocking(const Song &metadata);
|
|
|
|
bool UpdateSongRatingBlocking(const Song &metadata);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// TODO: Make this not a singleton
|
|
|
|
static TagReaderClient *Instance() { return sInstance; }
|
|
|
|
|
2019-07-24 23:29:09 +02:00
|
|
|
signals:
|
|
|
|
void ExitFinished();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
private slots:
|
2019-07-24 23:29:09 +02:00
|
|
|
void Exit();
|
2018-02-27 18:06:05 +01:00
|
|
|
void WorkerFailedToStart();
|
|
|
|
|
2021-10-24 16:08:17 +02:00
|
|
|
public slots:
|
|
|
|
void UpdateSongsPlaycount(const SongList &songs);
|
|
|
|
void UpdateSongsRating(const SongList &songs);
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
private:
|
|
|
|
static TagReaderClient *sInstance;
|
|
|
|
|
|
|
|
WorkerPool<HandlerType> *worker_pool_;
|
2021-02-20 17:06:55 +01:00
|
|
|
QList<spb::tagreader::Message> message_queue_;
|
2019-07-24 23:29:09 +02:00
|
|
|
QThread *original_thread_;
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
2022-10-13 22:39:31 +02:00
|
|
|
using TagReaderReply = TagReaderClient::ReplyType;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
#endif // TAGREADERCLIENT_H
|