Qmmp
|
00001 /*************************************************************************** 00002 * Copyright (C) 2015 by Ilya Kotov * 00003 * forkotov02@hotmail.ru * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 00019 ***************************************************************************/ 00020 00021 #ifndef METADATAFORMATTER_H 00022 #define METADATAFORMATTER_H 00023 00024 #include <QString> 00025 #include <QMap> 00026 #include <QList> 00027 #include <qmmpui/playlisttrack.h> 00028 #include <qmmp/qmmp.h> 00029 00033 class MetaDataFormatter 00034 { 00035 public: 00057 MetaDataFormatter(const QString &pattern = QString()); 00062 void setPattern(const QString &pattern); 00066 const QString pattern() const; 00067 00071 QString format(const PlayListTrack *item) const; 00078 QString format(const QMap<Qmmp::MetaData, QString> &metaData, qint64 length = 0, int track = 0) const; 00086 static QString formatLength(qint64 length, bool hideZero = true); 00087 00088 private: 00089 struct Node; 00090 struct Param; 00091 00092 struct Node 00093 { 00094 enum { 00095 PRINT_TEXT = 0, 00096 IF_KEYWORD, 00097 OR_OPERATOR, 00098 AND_OPERATOR 00099 } command; 00100 00101 QList<Param> params; 00102 }; 00103 00104 struct Param 00105 { 00106 enum { 00107 FIELD = 0, 00108 TEXT, 00109 NODES 00110 } type; 00111 00112 //extra fields 00113 enum 00114 { 00115 TWO_DIGIT_TRACK = Qmmp::URL + 1, 00116 DURATION, 00117 FILE_NAME, 00118 TRACK_INDEX 00119 }; 00120 00121 int field; 00122 QString text; 00123 QList<Node> children; 00124 }; 00125 00126 bool parseField(QList<Node> *nodes, QString::const_iterator *i, QString::const_iterator end); 00127 bool parseIf(QList<Node> *nodes, QString::const_iterator *i, QString::const_iterator end); 00128 void parseText(QList<Node> *nodes, QString::const_iterator *i, QString::const_iterator end); 00129 void parseEscape(QList<Node> *nodes, QString::const_iterator *i, QString::const_iterator end); 00130 00131 QString evalute(const QList<Node> *nodes, const QMap<Qmmp::MetaData, QString> *metaData, qint64 length, int track) const; 00132 QString printParam(Param *p, const QMap<Qmmp::MetaData, QString> *metaData, qint64 length, int track) const; 00133 QString printField(int field, const QMap<Qmmp::MetaData, QString> *metaData, qint64 length, int track) const; 00134 00135 QString dumpNode(Node node) const; 00136 00137 QList<MetaDataFormatter::Node> compile(const QString &expr); 00138 QString m_pattern; 00139 QList<MetaDataFormatter::Node> m_nodes; 00140 QMap<QString, int> m_fieldNames; 00141 }; 00142 00143 #endif // METADATAFORMATTER2_H