File indexing completed on 2024-05-19 04:56:11

0001 /**
0002  * \file framenotice.h
0003  * Warning about tag frame.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 19 May 2017
0008  *
0009  * Copyright (C) 2017-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 <QObject>
0030 #include "kid3api.h"
0031 
0032 class Frame;
0033 class FrameCollection;
0034 
0035 /**
0036  * Notice about a frame in a tag.
0037  */
0038 class KID3_CORE_EXPORT FrameNotice {
0039   Q_GADGET
0040   Q_ENUMS(Warning)
0041 public:
0042   /** Warning type. */
0043   enum Warning {
0044     None,         /**< No warning */
0045     Truncated,    /**< Truncated */
0046     TooLarge,     /**< Size is too large */
0047     Unique,       /**< Must be unique */
0048     NlForbidden,  /**< New line is forbidden */
0049     CrForbidden,  /**< Carriage return is forbidden */
0050     OwnerEmpty,   /**< Owner must be non-empty */
0051     Numeric,      /**< Must be numeric */
0052     NrTotal,      /**< Must be numeric or number/total */
0053     DayMonth,     /**< Format is DDMM */
0054     HourMinute,   /**< Format is HHMM */
0055     Year,         /**< Format is YYYY */
0056     YearSpace,    /**< Must begin with a year and a space character */
0057     IsoDate,      /**< Must be ISO 8601 date/time */
0058     MusicalKey,   /**< Must be musical key, 3 characters, A-G, b, #, m, o */
0059     LanguageCode, /**< Must be ISO 639-2 language code, 3 lowercase characters */
0060     IsrcCode,     /**< Must be ISRC code, 12 characters */
0061     StringList,   /**< Must be list of strings */
0062     ExcessSpace,  /**< Has excess white space */
0063     NumWarnings
0064   };
0065 
0066   /**
0067    * Constructor.
0068    * @param warning warning type
0069    */
0070   FrameNotice(Warning warning = None) { m_warning = warning; }
0071 
0072   /**
0073    * Equality operator.
0074    * @param rhs right hand side to compare
0075    * @return true if this == rhs.
0076    */
0077   bool operator==(const FrameNotice& rhs) const {
0078     return m_warning == rhs.m_warning;
0079   }
0080 
0081   /**
0082    * Bool operator, true if not none.
0083    */
0084   operator bool() const { return m_warning != None; }
0085 
0086   /**
0087    * Get warning of notice.
0088    * @return warning.
0089    */
0090   Warning getWarning() const { return m_warning; }
0091 
0092   /**
0093    * Get translated description of notice.
0094    * @return description, empty if none.
0095    */
0096   QString getDescription() const;
0097 
0098   /**
0099    * Get regular expression to validate an ISO 8601 date/time.
0100    * @return regular expression matching ISO date/time and periods.
0101    */
0102   static const QRegularExpression& isoDateTimeRexExp();
0103 
0104   /**
0105    * Check if a picture frame exceeds a given size.
0106    * TooLarge notice is set in @a frame, if its size is larger than @a maxSize.
0107    * @param frame picture frame to check
0108    * @param maxSize maximum size of picture data in bytes
0109    * @return true if size too large.
0110    */
0111   static bool addPictureTooLargeNotice(Frame& frame, int maxSize);
0112 
0113   /**
0114    * Check if frames violate the ID3v2 standard.
0115    * Violating frames are marked with the corresponding notice.
0116    * @param frames frames to check
0117    * @return true if a violation is detected.
0118    */
0119   static bool addId3StandardViolationNotice(FrameCollection& frames);
0120 
0121 private:
0122   Warning m_warning;
0123 };