2023-07-05 01:47:26 +02:00
|
|
|
#ifndef CLI_MEDIA_FILE_INFO_OBJECT_H
|
|
|
|
#define CLI_MEDIA_FILE_INFO_OBJECT_H
|
|
|
|
|
2023-08-01 00:50:21 +02:00
|
|
|
#include <tagparser/positioninset.h>
|
|
|
|
|
2023-07-30 16:35:34 +02:00
|
|
|
#include <QtGlobal>
|
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
namespace TagParser {
|
|
|
|
enum class KnownField : unsigned int;
|
|
|
|
}
|
2023-07-30 16:57:19 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
2023-07-30 16:35:34 +02:00
|
|
|
uint qHash(const TagParser::KnownField key, uint seed = 0) noexcept;
|
2023-07-30 16:57:19 +02:00
|
|
|
QT_END_NAMESPACE
|
2023-07-30 16:35:34 +02:00
|
|
|
#endif
|
|
|
|
|
2023-07-05 01:47:26 +02:00
|
|
|
#include <QJSValue>
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QJSEngine)
|
|
|
|
|
|
|
|
namespace TagParser {
|
|
|
|
class Diagnostics;
|
|
|
|
class MediaFileInfo;
|
|
|
|
class Tag;
|
|
|
|
class TagValue;
|
|
|
|
enum class KnownField : unsigned int;
|
|
|
|
enum class TagTextEncoding : unsigned int;
|
|
|
|
} // namespace TagParser
|
|
|
|
|
2023-08-02 18:26:01 +02:00
|
|
|
namespace QtGui {
|
|
|
|
struct SongDescription;
|
|
|
|
}
|
|
|
|
|
2023-07-05 01:47:26 +02:00
|
|
|
namespace Cli {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The UtilityObject class wraps useful functions of Qt, TagParser and the Utility namespace for use within QML.
|
|
|
|
*/
|
|
|
|
class UtilityObject : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit UtilityObject(QJSEngine *engine);
|
|
|
|
|
|
|
|
void setDiag(const std::string *context, TagParser::Diagnostics *diag);
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void log(const QString &message);
|
|
|
|
void diag(const QString &level, const QString &message, const QString &context = QString());
|
2023-08-02 17:43:34 +02:00
|
|
|
|
2023-07-05 01:47:26 +02:00
|
|
|
int exec();
|
2023-08-05 02:06:26 +02:00
|
|
|
void exit(int retcode = 0);
|
2023-08-02 17:43:34 +02:00
|
|
|
|
|
|
|
QJSValue readEnvironmentVariable(const QString &variable, const QJSValue &defaultValue = QJSValue()) const;
|
|
|
|
QJSValue readDirectory(const QString &path);
|
|
|
|
QJSValue readFile(const QString &path);
|
|
|
|
|
2023-07-05 01:47:26 +02:00
|
|
|
QString formatName(const QString &str) const;
|
|
|
|
QString fixUmlauts(const QString &str) const;
|
|
|
|
|
2023-08-02 18:26:01 +02:00
|
|
|
QJSValue queryMusicBrainz(const QJSValue &songDescription);
|
|
|
|
QJSValue queryLyricsWikia(const QJSValue &songDescription);
|
|
|
|
QJSValue queryMakeItPersonal(const QJSValue &songDescription);
|
|
|
|
|
2023-07-05 01:47:26 +02:00
|
|
|
private:
|
2023-08-02 18:26:01 +02:00
|
|
|
static QtGui::SongDescription makeSongDescription(const QJSValue &obj);
|
|
|
|
|
2023-08-02 17:43:34 +02:00
|
|
|
QJSEngine *m_engine;
|
2023-07-05 01:47:26 +02:00
|
|
|
const std::string *m_context;
|
|
|
|
TagParser::Diagnostics *m_diag;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void UtilityObject::setDiag(const std::string *context, TagParser::Diagnostics *diag)
|
|
|
|
{
|
|
|
|
m_context = context;
|
|
|
|
m_diag = diag;
|
|
|
|
}
|
|
|
|
|
2023-08-04 00:19:10 +02:00
|
|
|
class TagValueObject;
|
|
|
|
|
2023-08-01 00:50:21 +02:00
|
|
|
/*!
|
|
|
|
* \brief The PositionInSetObject class wraps a TagParser::PositionInSet for use within QML.
|
|
|
|
*/
|
|
|
|
class PositionInSetObject : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(qint32 position READ position WRITE setPosition)
|
|
|
|
Q_PROPERTY(qint32 total READ total WRITE setTotal)
|
|
|
|
|
|
|
|
public:
|
2023-08-04 00:19:10 +02:00
|
|
|
explicit PositionInSetObject(TagParser::PositionInSet value, TagValueObject *relatedValue, QJSEngine *engine, QObject *parent);
|
|
|
|
explicit PositionInSetObject(const PositionInSetObject &other);
|
2023-08-01 00:50:21 +02:00
|
|
|
~PositionInSetObject() override;
|
|
|
|
|
|
|
|
qint32 position() const;
|
|
|
|
void setPosition(qint32 position);
|
|
|
|
qint32 total() const;
|
|
|
|
void setTotal(qint32 total);
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
QString toString() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
TagParser::PositionInSet m_v;
|
2023-08-04 00:19:10 +02:00
|
|
|
TagValueObject *m_relatedValue;
|
2023-08-01 00:50:21 +02:00
|
|
|
};
|
|
|
|
|
2023-07-05 01:47:26 +02:00
|
|
|
/*!
|
|
|
|
* \brief The TagValueObject class wraps a TagParser::TagValue for use within QML.
|
|
|
|
*/
|
|
|
|
class TagValueObject : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString type READ type)
|
|
|
|
Q_PROPERTY(QJSValue content READ content WRITE setContent)
|
|
|
|
Q_PROPERTY(QJSValue initialContent READ initialContent)
|
|
|
|
Q_PROPERTY(bool initial READ isInitial)
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TagValueObject(const TagParser::TagValue &value, QJSEngine *engine, QObject *parent);
|
|
|
|
~TagValueObject() override;
|
|
|
|
|
|
|
|
const QString &type() const;
|
|
|
|
const QJSValue &content() const;
|
|
|
|
void setContent(const QJSValue &content);
|
2023-08-04 00:19:10 +02:00
|
|
|
void setContentFromTagValue(const TagParser::TagValue &value);
|
2023-07-05 01:47:26 +02:00
|
|
|
const QJSValue &initialContent() const;
|
|
|
|
bool isInitial() const;
|
|
|
|
TagParser::TagValue toTagValue(TagParser::TagTextEncoding encoding) const;
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void restore();
|
|
|
|
void clear();
|
2023-08-01 00:50:21 +02:00
|
|
|
QString toString() const;
|
2023-08-04 00:19:10 +02:00
|
|
|
void flagChange();
|
2023-07-05 01:47:26 +02:00
|
|
|
|
|
|
|
private:
|
2023-08-04 00:19:10 +02:00
|
|
|
QJSEngine *m_engine;
|
2023-07-05 01:47:26 +02:00
|
|
|
QString m_type;
|
|
|
|
QJSValue m_content;
|
|
|
|
QJSValue m_initialContent;
|
|
|
|
bool m_initial;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The TagObject class wraps a TagParser::Tag for use within QML.
|
|
|
|
*/
|
|
|
|
class TagObject : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString type READ type)
|
2023-08-02 18:08:35 +02:00
|
|
|
Q_PROPERTY(QJSValue target READ target)
|
2023-07-05 01:47:26 +02:00
|
|
|
Q_PROPERTY(QJSValue fields READ fields)
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TagObject(TagParser::Tag &tag, TagParser::Diagnostics &diag, QJSEngine *engine, QObject *parent);
|
|
|
|
~TagObject() override;
|
|
|
|
|
|
|
|
TagParser::Tag &tag();
|
|
|
|
QString type() const;
|
2023-08-02 18:08:35 +02:00
|
|
|
QJSValue target() const;
|
2023-07-05 01:47:26 +02:00
|
|
|
QJSValue &fields();
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void applyChanges();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static QString propertyNameForField(TagParser::KnownField field);
|
|
|
|
|
|
|
|
TagParser::Tag &m_tag;
|
|
|
|
TagParser::Diagnostics &m_diag;
|
|
|
|
QJSEngine *m_engine;
|
|
|
|
QString m_type;
|
|
|
|
QJSValue m_fields;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline TagParser::Tag &TagObject::tag()
|
|
|
|
{
|
|
|
|
return m_tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The MediaFileInfoObject class wraps a TagParser::MediaFileInfo for use within QML.
|
|
|
|
*/
|
|
|
|
class MediaFileInfoObject : public QObject {
|
|
|
|
Q_OBJECT
|
2023-08-03 23:32:33 +02:00
|
|
|
Q_PROPERTY(QString path READ path)
|
|
|
|
Q_PROPERTY(QString name READ name)
|
|
|
|
Q_PROPERTY(QString extension READ extension)
|
|
|
|
Q_PROPERTY(QString containingDirectory READ containingDirectory)
|
2023-08-02 17:56:20 +02:00
|
|
|
Q_PROPERTY(QString savePath READ savePath WRITE setSavePath)
|
2023-07-05 01:47:26 +02:00
|
|
|
Q_PROPERTY(QList<TagObject *> tags READ tags)
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit MediaFileInfoObject(TagParser::MediaFileInfo &mediaFileInfo, TagParser::Diagnostics &diag, QJSEngine *engine, QObject *parent = nullptr);
|
|
|
|
~MediaFileInfoObject() override;
|
|
|
|
|
|
|
|
TagParser::MediaFileInfo &fileInfo();
|
2023-08-03 23:32:33 +02:00
|
|
|
QString path() const;
|
|
|
|
QString name() const;
|
|
|
|
QString extension() const;
|
|
|
|
QString containingDirectory() const;
|
2023-08-02 17:56:20 +02:00
|
|
|
QString savePath() const;
|
|
|
|
void setSavePath(const QString &path);
|
2023-07-05 01:47:26 +02:00
|
|
|
QList<TagObject *> &tags();
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void applyChanges();
|
|
|
|
|
|
|
|
private:
|
|
|
|
TagParser::MediaFileInfo &m_f;
|
|
|
|
TagParser::Diagnostics &m_diag;
|
|
|
|
QJSEngine *m_engine;
|
|
|
|
QList<TagObject *> m_tags;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline TagParser::MediaFileInfo &MediaFileInfoObject::fileInfo()
|
|
|
|
{
|
|
|
|
return m_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Cli
|
|
|
|
|
|
|
|
#endif // CLI_MEDIA_FILE_INFO_OBJECT_H
|