1 /**
2  * \file framenotice.h
3  * Warning about tag frame.
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 19 May 2017
8  *
9  * Copyright (C) 2017-2018  Urs Fleisch
10  *
11  * This file is part of Kid3.
12  *
13  * Kid3 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * Kid3 is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #pragma once
28 
29 #include <QObject>
30 #include "kid3api.h"
31 
32 class Frame;
33 class FrameCollection;
34 
35 /**
36  * Notice about a frame in a tag.
37  */
38 class KID3_CORE_EXPORT FrameNotice {
39   Q_GADGET
40   Q_ENUMS(Warning)
41 public:
42   /** Warning type. */
43   enum Warning {
44     None,         /**< No warning */
45     Truncated,    /**< Truncated */
46     TooLarge,     /**< Size is too large */
47     Unique,       /**< Must be unique */
48     NlForbidden,  /**< New line is forbidden */
49     CrForbidden,  /**< Carriage return is forbidden */
50     OwnerEmpty,   /**< Owner must be non-empty */
51     Numeric,      /**< Must be numeric */
52     NrTotal,      /**< Must be numeric or number/total */
53     DayMonth,     /**< Format is DDMM */
54     HourMinute,   /**< Format is HHMM */
55     Year,         /**< Format is YYYY */
56     YearSpace,    /**< Must begin with a year and a space character */
57     IsoDate,      /**< Must be ISO 8601 date/time */
58     MusicalKey,   /**< Must be musical key, 3 characters, A-G, b, #, m, o */
59     LanguageCode, /**< Must be ISO 639-2 language code, 3 lowercase characters */
60     IsrcCode,     /**< Must be ISRC code, 12 characters */
61     StringList,   /**< Must be list of strings */
62     ExcessSpace,  /**< Has excess white space */
63     NumWarnings
64   };
65 
66   /**
67    * Constructor.
68    * @param warning warning type
69    */
70   FrameNotice(Warning warning = None) { m_warning = warning; }
71 
72   /**
73    * Equality operator.
74    * @param rhs right hand side to compare
75    * @return true if this == rhs.
76    */
77   bool operator==(const FrameNotice& rhs) const {
78     return m_warning == rhs.m_warning;
79   }
80 
81   /**
82    * Bool operator, true if not none.
83    */
84   operator bool() const { return m_warning != None; }
85 
86   /**
87    * Get translated description of notice.
88    * @return description, empty if none.
89    */
90   QString getDescription() const;
91 
92   /**
93    * Get regular expression to validate an ISO 8601 date/time.
94    * @return regular expression matching ISO date/time and periods.
95    */
96   static const QRegularExpression& isoDateTimeRexExp();
97 
98   /**
99    * Check if a picture frame exceeds a given size.
100    * TooLarge notice is set in @a frame, if its size is larger than @a maxSize.
101    * @param frame picture frame to check
102    * @param maxSize maximum size of picture data in bytes
103    * @return true if size too large.
104    */
105   static bool addPictureTooLargeNotice(Frame& frame, int maxSize);
106 
107   /**
108    * Check if frames violate the ID3v2 standard.
109    * Violating frames are marked with the corresponding notice.
110    * @param frames frames to check
111    * @return true if a violation is detected.
112    */
113   static bool addId3StandardViolationNotice(FrameCollection& frames);
114 
115 private:
116   Warning m_warning;
117 };
118