File indexing completed on 2024-05-19 04:55:59

0001 /**
0002  * \file importparser.h
0003  * Import parser.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 17 Sep 2003
0008  *
0009  * Copyright (C) 2003-2018  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #pragma once
0028 
0029 #include <QString>
0030 #include <QRegularExpression>
0031 #include <QMap>
0032 #include <QList>
0033 #include <QStringList>
0034 #include "kid3api.h"
0035 
0036 class TrackData;
0037 
0038 /**
0039  * Import parser.
0040  */
0041 class KID3_CORE_EXPORT ImportParser {
0042 public:
0043   /**
0044    * Constructor.
0045    */
0046   ImportParser();
0047 
0048   /**
0049    * Set import format.
0050    *
0051    * @param fmt format regexp
0052    * @param enableTrackIncr enable automatic track increment if no %t is found
0053    */
0054   void setFormat(const QString& fmt, bool enableTrackIncr = false);
0055 
0056   /**
0057    * Get next tags in text buffer.
0058    *
0059    * @param text text buffer containing data from file or clipboard
0060    * @param frames frames for output
0061    * @param pos  current position in buffer, will be updated to point
0062    *             behind current match (to be used for next call)
0063    * @return true if tags found (pos is index behind match).
0064    */
0065   bool getNextTags(const QString& text, TrackData& frames, int& pos);
0066 
0067   /**
0068    * Get list with track durations.
0069    *
0070    * @return list with track durations.
0071    */
0072   QList<int> getTrackDurations() const { return m_trackDuration; }
0073 
0074   /**
0075    * Get list with values accumulated for %{__return}.
0076    * @return accumulated return values.
0077    */
0078   QStringList getReturnValues() const { return m_returnValues; }
0079 
0080   /**
0081    * Get help text for format codes supported by setFormat().
0082    *
0083    * @param onlyRows if true only the tr elements are returned,
0084    *                 not the surrounding table
0085    *
0086    * @return help text.
0087    */
0088   static QString getFormatToolTip(bool onlyRows = false);
0089 
0090 private:
0091   /** track regexp pattern */
0092   QString m_pattern;
0093   /** regexp object */
0094   QRegularExpression m_re;
0095   /** automatically incremented track number */
0096   int m_trackIncrNr;
0097   QMap<QString, int> m_codePos;
0098   QList<int> m_trackDuration;
0099   QStringList m_returnValues;
0100   /** true if automatic track number incrementing is used */
0101   bool m_trackIncrEnabled;
0102 };