File indexing completed on 2024-05-12 04:55:41

0001 /**
0002  * \file flacfile.hpp
0003  * Handling of FLAC files.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 04 Oct 2005
0008  *
0009  * Copyright (C) 2005-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 <QScopedPointer>
0030 #include "oggflacconfig.h"
0031 #include "oggfile.hpp"
0032 
0033 namespace FLAC {
0034   namespace Metadata {
0035     class Chain;
0036     class VorbisComment;
0037     class StreamInfo;
0038     class Picture;
0039   }
0040 }
0041 
0042  /** List box item containing FLAC file */
0043 class FlacFile : public OggFile {
0044 public:
0045   /**
0046    * Constructor.
0047    *
0048    * @param idx index in file proxy model
0049    */
0050   explicit FlacFile(const QPersistentModelIndex& idx);
0051 
0052   /**
0053    * Destructor.
0054    */
0055   ~FlacFile() override;
0056 
0057   /**
0058    * Get key of tagged file format.
0059    * @return "FlacMetadata".
0060    */
0061   QString taggedFileKey() const override;
0062 
0063   /**
0064    * Read tags from file.
0065    *
0066    * @param force true to force reading even if tags were already read.
0067    */
0068   void readTags(bool force) override;
0069 
0070   /**
0071    * Write tags to file and rename it if necessary.
0072    *
0073    * @param force   true to force writing even if file was not changed.
0074    * @param renamed will be set to true if the file was renamed,
0075    *                i.e. the file name is no longer valid, else *renamed
0076    *                is left unchanged
0077    * @param preserve true to preserve file time stamps
0078    *
0079    * @return true if ok, false if the file could not be written or renamed.
0080    */
0081   bool writeTags(bool force, bool* renamed, bool preserve) override;
0082 
0083   /**
0084    * Free resources allocated when calling readTags().
0085    *
0086    * @param force true to force clearing even if the tags are modified
0087    */
0088   void clearTags(bool force) override;
0089 
0090   /**
0091    * Get technical detail information.
0092    *
0093    * @param info the detail information is returned here
0094    */
0095   void getDetailInfo(DetailInfo& info) const override;
0096 
0097   /**
0098    * Get duration of file.
0099    *
0100    * @return duration in seconds,
0101    *         0 if unknown.
0102    */
0103   unsigned getDuration() const override;
0104 
0105   /**
0106    * Get file extension including the dot.
0107    *
0108    * @return file extension ".flac".
0109    */
0110   QString getFileExtension() const override;
0111 
0112 #ifdef HAVE_FLAC_PICTURE
0113   /**
0114    * Check if file has a tag.
0115    *
0116    * @param tagNr tag number
0117    * @return true if a tag is available.
0118    * @see isTagInformationRead()
0119    */
0120   bool hasTag(Frame::TagNumber tagNr) const override;
0121 
0122   /**
0123    * Set a frame in the tags.
0124    *
0125    * @param tagNr tag number
0126    * @param frame frame to set
0127    *
0128    * @return true if ok.
0129    */
0130   bool setFrame(Frame::TagNumber tagNr, const Frame& frame) override;
0131 
0132   /**
0133    * Add a frame in the tags.
0134    *
0135    * @param tagNr tag number
0136    * @param frame frame to add
0137    *
0138    * @return true if ok.
0139    */
0140   bool addFrame(Frame::TagNumber tagNr, Frame& frame) override;
0141 
0142   /**
0143    * Delete a frame from the tags.
0144    *
0145    * @param tagNr tag number
0146    * @param frame frame to delete.
0147    *
0148    * @return true if ok.
0149    */
0150   bool deleteFrame(Frame::TagNumber tagNr, const Frame& frame) override;
0151 
0152   /**
0153    * Remove frames.
0154    *
0155    * @param tagNr tag number
0156    * @param flt filter specifying which frames to remove
0157    */
0158   void deleteFrames(Frame::TagNumber tagNr, const FrameFilter& flt) override;
0159 
0160   /**
0161    * Get all frames in tag.
0162    *
0163    * @param tagNr tag number
0164    * @param frames frame collection to set.
0165    */
0166   void getAllFrames(Frame::TagNumber tagNr, FrameCollection& frames) override;
0167 #endif // HAVE_FLAC_PICTURE
0168 
0169 private:
0170   FlacFile(const FlacFile&);
0171   FlacFile& operator=(const FlacFile&);
0172 
0173   /**
0174    * Read information about a FLAC file.
0175    * @param info file info to fill
0176    * @param si stream info
0177    * @return true if ok.
0178    */
0179   bool readFileInfo(FileInfo& info, const FLAC::Metadata::StreamInfo* si) const;
0180 
0181   /**
0182    * Set the vorbis comment block with the comments.
0183    *
0184    * @param vc vorbis comment block to set
0185    */
0186   void setVorbisComment(FLAC::Metadata::VorbisComment* vc);
0187 
0188 #ifdef HAVE_FLAC_PICTURE
0189   /** Pictures */
0190   typedef QList<Frame> PictureList;
0191   PictureList m_pictures;
0192 #endif // HAVE_FLAC_PICTURE
0193 
0194   /** FLAC metadata chain. */
0195   QScopedPointer<FLAC::Metadata::Chain> m_chain;
0196 };