1 /* This file is part of Clementine. 2 Copyright 2010, 2014, David Sansome <me@davidsansome.com> 3 Copyright 2013-2014, John Maguire <john.maguire@gmail.com> 4 Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com> 5 6 Clementine is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Clementine is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Clementine. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef CORE_ORGANISEFORMAT_H_ 21 #define CORE_ORGANISEFORMAT_H_ 22 23 #include <QSyntaxHighlighter> 24 #include <QValidator> 25 #include <QTextEdit> 26 27 #include "core/song.h" 28 29 class OrganiseFormat { 30 public: 31 explicit OrganiseFormat(const QString& format = QString()); 32 33 static const char* kTagPattern; 34 static const char* kBlockPattern; 35 static const QStringList kKnownTags; 36 static const char kInvalidFatCharacters[]; 37 static const int kInvalidFatCharactersCount; 38 static const char kInvalidPrefixCharacters[]; 39 static const int kInvalidPrefixCharactersCount; 40 format()41 QString format() const { return format_; } replace_non_ascii()42 bool replace_non_ascii() const { return replace_non_ascii_; } replace_spaces()43 bool replace_spaces() const { return replace_spaces_; } replace_the()44 bool replace_the() const { return replace_the_; } 45 46 void set_format(const QString& v); set_replace_non_ascii(bool v)47 void set_replace_non_ascii(bool v) { replace_non_ascii_ = v; } set_replace_spaces(bool v)48 void set_replace_spaces(bool v) { replace_spaces_ = v; } set_replace_the(bool v)49 void set_replace_the(bool v) { replace_the_ = v; } 50 51 bool IsValid() const; 52 QString GetFilenameForSong(const Song& song) const; 53 54 class Validator : public QValidator { 55 public: 56 explicit Validator(QObject* parent = nullptr); 57 QValidator::State validate(QString& format, int& pos) const; 58 }; 59 60 class SyntaxHighlighter : public QSyntaxHighlighter { 61 public: 62 static const QRgb kValidTagColorLight; 63 static const QRgb kInvalidTagColorLight; 64 static const QRgb kBlockColorLight; 65 static const QRgb kValidTagColorDark; 66 static const QRgb kInvalidTagColorDark; 67 static const QRgb kBlockColorDark; 68 69 explicit SyntaxHighlighter(QObject* parent = nullptr); 70 explicit SyntaxHighlighter(QTextEdit* parent); 71 explicit SyntaxHighlighter(QTextDocument* parent); 72 void highlightBlock(const QString& format); 73 }; 74 75 private: 76 QString ParseBlock(QString block, const Song& song, 77 bool* any_empty = nullptr) const; 78 QString TagValue(const QString& tag, const Song& song) const; 79 80 QString format_; 81 bool replace_non_ascii_; 82 bool replace_spaces_; 83 bool replace_the_; 84 }; 85 86 #endif // CORE_ORGANISEFORMAT_H_ 87