strawberry-audio-player-win.../src/core/tagreaderclient.h

90 lines
2.6 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2011, David Sansome <me@davidsansome.com>
*
* 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"
#include <QObject>
#include <QList>
#include <QString>
#include <QImage>
2018-02-27 18:06:05 +01:00
#include "core/messagehandler.h"
#include "core/workerpool.h"
#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;
class Song;
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);
2021-02-20 17:06:55 +01:00
typedef AbstractMessageHandler<spb::tagreader::Message> HandlerType;
2018-02-27 18:06:05 +01:00
typedef HandlerType::ReplyType ReplyType;
static const char *kWorkerExecutableName;
void Start();
2019-07-24 23:29:09 +02:00
void ExitAsync();
2018-02-27 18:06:05 +01:00
ReplyType *ReadFile(const QString &filename);
ReplyType *SaveFile(const QString &filename, const Song &metadata);
ReplyType *IsMediaFile(const QString &filename);
ReplyType *LoadEmbeddedArt(const QString &filename);
ReplyType *SaveEmbeddedArt(const QString &filename, const QByteArray &data);
2018-02-27 18:06:05 +01: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);
bool SaveFileBlocking(const QString &filename, const Song &metadata);
bool IsMediaFileBlocking(const QString &filename);
QImage LoadEmbeddedArtBlocking(const QString &filename);
bool SaveEmbeddedArtBlocking(const QString &filename, const QByteArray &data);
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();
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
};
typedef TagReaderClient::ReplyType TagReaderReply;
#endif // TAGREADERCLIENT_H