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

0001 /**
0002  * \file eventtimingcode.h
0003  * Event timing code to string conversion.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 21 Mar 2014
0008  *
0009  * Copyright (C) 2014-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 <QString>
0030 #include <QStringList>
0031 #include "kid3api.h"
0032 
0033 /**
0034  * Event timing code.
0035  */
0036 class KID3_CORE_EXPORT EventTimeCode {
0037 public:
0038   /**
0039    * Constructor.
0040    * @param code code ID3v2 ETCO code
0041    */
0042   explicit EventTimeCode(int code) : m_code(code) {}
0043 
0044   /**
0045    * Get code.
0046    * @return code.
0047    */
0048   int getCode() const { return m_code; }
0049 
0050   /**
0051    * Check if code is valid.
0052    * @return true if valid.
0053    */
0054   bool isValid() const { return m_code != -1; }
0055 
0056   /**
0057    * Get string representation.
0058    * @return code description.
0059    */
0060   QString toString() const;
0061 
0062   /**
0063    * Get translated string representation.
0064    * @return code description.
0065    */
0066   QString toTranslatedString() const;
0067 
0068   /**
0069    * Get index of code in list of strings.
0070    * @return index.
0071    */
0072   int toIndex() const;
0073 
0074   /**
0075    * Create from string.
0076    * @param str untranslated string
0077    * @return event time code.
0078    */
0079   static EventTimeCode fromString(const char* str);
0080 
0081   /**
0082    * Create from index.
0083    * @param index index
0084    * @return event time code.
0085    */
0086   static EventTimeCode fromIndex(int index);
0087 
0088   /**
0089    * Get list of translated strings.
0090    * @return code descriptions.
0091    */
0092   static QStringList getTranslatedStrings();
0093 
0094 private:
0095   int m_code;
0096 };