1 /**
2  * \file eventtimingcode.h
3  * Event timing code to string conversion.
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 21 Mar 2014
8  *
9  * Copyright (C) 2014-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 <QString>
30 #include <QStringList>
31 #include "kid3api.h"
32 
33 /**
34  * Event timing code.
35  */
36 class KID3_CORE_EXPORT EventTimeCode {
37 public:
38   /**
39    * Constructor.
40    * @param code code ID3v2 ETCO code
41    */
EventTimeCode(int code)42   explicit EventTimeCode(int code) : m_code(code) {}
43 
44   /**
45    * Get code.
46    * @return code.
47    */
getCode()48   int getCode() const { return m_code; }
49 
50   /**
51    * Check if code is valid.
52    * @return true if valid.
53    */
isValid()54   bool isValid() const { return m_code != -1; }
55 
56   /**
57    * Get string representation.
58    * @return code description.
59    */
60   QString toString() const;
61 
62   /**
63    * Get translated string representation.
64    * @return code description.
65    */
66   QString toTranslatedString() const;
67 
68   /**
69    * Get index of code in list of strings.
70    * @return index.
71    */
72   int toIndex() const;
73 
74   /**
75    * Create from string.
76    * @param str untranslated string
77    * @return event time code.
78    */
79   static EventTimeCode fromString(const char* str);
80 
81   /**
82    * Create from index.
83    * @param index index
84    * @return event time code.
85    */
86   static EventTimeCode fromIndex(int index);
87 
88   /**
89    * Get list of translated strings.
90    * @return code descriptions.
91    */
92   static QStringList getTranslatedStrings();
93 
94 private:
95   int m_code;
96 };
97