2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2018-2021, 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 ORGANISEFORMAT_H
|
|
|
|
#define ORGANISEFORMAT_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QRgb>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
#include <QValidator>
|
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
class QTextDocument;
|
|
|
|
class QTextEdit;
|
2018-05-01 00:41:33 +02:00
|
|
|
class Song;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-08-04 21:18:14 +02:00
|
|
|
class OrganizeFormat {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-04 21:18:14 +02:00
|
|
|
explicit OrganizeFormat(const QString &format = QString());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QString format() const { return format_; }
|
2020-04-09 19:59:31 +02:00
|
|
|
bool remove_problematic() const { return remove_problematic_; }
|
2018-12-29 15:37:16 +01:00
|
|
|
bool remove_non_fat() const { return remove_non_fat_; }
|
|
|
|
bool remove_non_ascii() const { return remove_non_ascii_; }
|
2019-03-22 23:18:14 +01:00
|
|
|
bool allow_ascii_ext() const { return allow_ascii_ext_; }
|
2018-02-27 18:06:05 +01:00
|
|
|
bool replace_spaces() const { return replace_spaces_; }
|
|
|
|
|
|
|
|
void set_format(const QString &v);
|
2020-04-09 19:59:31 +02:00
|
|
|
void set_remove_problematic(const bool v) { remove_problematic_ = v; }
|
|
|
|
void set_remove_non_fat(const bool v) { remove_non_fat_ = v; }
|
|
|
|
void set_remove_non_ascii(const bool v) { remove_non_ascii_ = v; }
|
|
|
|
void set_allow_ascii_ext(const bool v) { allow_ascii_ext_ = v; }
|
|
|
|
void set_replace_spaces(const bool v) { replace_spaces_ = v; }
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
bool IsValid() const;
|
2022-11-26 23:37:41 +01:00
|
|
|
|
|
|
|
struct GetFilenameForSongResult {
|
|
|
|
GetFilenameForSongResult(const QString &_filename = QString(), const bool _unique_filename = false) : filename(_filename), unique_filename(_unique_filename) {}
|
|
|
|
QString filename;
|
|
|
|
bool unique_filename;
|
|
|
|
};
|
|
|
|
GetFilenameForSongResult GetFilenameForSong(const Song& song, QString extension = QString()) const;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
class Validator : public QValidator { // clazy:exclude=missing-qobject-macro
|
2018-02-27 18:06:05 +01:00
|
|
|
public:
|
2018-05-01 00:41:33 +02:00
|
|
|
explicit Validator(QObject *parent = nullptr);
|
2020-06-15 21:55:05 +02:00
|
|
|
QValidator::State validate(QString &input, int&) const override;
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
class SyntaxHighlighter : public QSyntaxHighlighter { // clazy:exclude=missing-qobject-macro
|
2018-02-27 18:06:05 +01:00
|
|
|
public:
|
|
|
|
static const QRgb kValidTagColorLight;
|
|
|
|
static const QRgb kInvalidTagColorLight;
|
|
|
|
static const QRgb kBlockColorLight;
|
|
|
|
static const QRgb kValidTagColorDark;
|
|
|
|
static const QRgb kInvalidTagColorDark;
|
|
|
|
static const QRgb kBlockColorDark;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
explicit SyntaxHighlighter(QObject *parent = nullptr);
|
|
|
|
explicit SyntaxHighlighter(QTextEdit *parent);
|
|
|
|
explicit SyntaxHighlighter(QTextDocument *parent);
|
2020-06-15 21:55:05 +02:00
|
|
|
void highlightBlock(const QString &text) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2022-11-26 23:37:41 +01:00
|
|
|
static const QStringList kKnownTags;
|
|
|
|
static const QStringList kUniqueTags;
|
|
|
|
|
|
|
|
QString ParseBlock(QString block, const Song &song, bool *have_tagdata = nullptr, bool *any_empty = nullptr) const;
|
2018-02-27 18:06:05 +01:00
|
|
|
QString TagValue(const QString &tag, const Song &song) const;
|
|
|
|
|
|
|
|
QString format_;
|
2020-04-09 19:59:31 +02:00
|
|
|
bool remove_problematic_;
|
2018-12-29 15:37:16 +01:00
|
|
|
bool remove_non_fat_;
|
|
|
|
bool remove_non_ascii_;
|
2019-03-22 23:18:14 +01:00
|
|
|
bool allow_ascii_ext_;
|
2018-02-27 18:06:05 +01:00
|
|
|
bool replace_spaces_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ORGANISEFORMAT_H
|