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

0001 /**
0002  * \file textexporter.h
0003  * Export tags as text.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 22 Jul 2011
0008  *
0009  * Copyright (C) 2011-2024  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 <QObject>
0030 #include "trackdata.h"
0031 #include "kid3api.h"
0032 
0033 /**
0034  * Export text from tags.
0035  */
0036 class KID3_CORE_EXPORT TextExporter : public QObject {
0037 public:
0038   /**
0039    * Constructor.
0040    * @param parent parent object
0041    */
0042   explicit TextExporter(QObject* parent = nullptr);
0043 
0044   /**
0045    * Destructor.
0046    */
0047   ~TextExporter() override;
0048 
0049   /**
0050    * Set data to be exported.
0051    *
0052    * @param trackDataVector data to export
0053    */
0054   void setTrackData(const ImportTrackDataVector& trackDataVector) {
0055     m_trackDataVector = trackDataVector;
0056   }
0057 
0058   /**
0059    * Reread the tags in the track data.
0060    * @param tagVersion tag version
0061    */
0062   void readTagsInTrackData(Frame::TagVersion tagVersion) {
0063     m_trackDataVector.readTags(tagVersion);
0064   }
0065 
0066   /**
0067    * Get exported text.
0068    * @return exported text.
0069    */
0070   QString getText() const { return m_text; }
0071 
0072   /**
0073    * Update text from tags.
0074    *
0075    * @param headerFormat header format
0076    * @param trackFormat track format
0077    * @param trailerFormat trailer format
0078    */
0079   void updateText(const QString& headerFormat, const QString& trackFormat,
0080                   const QString& trailerFormat);
0081 
0082   /**
0083    * Update text from tags using formats from the configuration.
0084    *
0085    * int fmtIdx index of format
0086    */
0087   void updateTextUsingConfig(int fmtIdx);
0088 
0089   /**
0090    * Export to a file.
0091    *
0092    * @param fn file name
0093    *
0094    * @return true if ok.
0095    */
0096   bool exportToFile(const QString& fn) const;
0097 
0098 private:
0099   ImportTrackDataVector m_trackDataVector;
0100   QString m_text;
0101 };