1 /**
2  * \file attributedata.h
3  * String representation of attribute data.
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 28 Mar 2009
8  *
9  * Copyright (C) 2009-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 <QByteArray>
31 #include "kid3api.h"
32 
33 /** Attribute data used e.g. by Windows Media Player. */
34 class KID3_CORE_EXPORT AttributeData {
35 public:
36   /** Attribute data types. */
37   enum Type {
38     Unknown, /**< Unknown type */
39     Utf16,   /**< UTF-16 encoded, zero-terminated Unicode string */
40     Guid,    /**< 128-bit GUID */
41     DWord,   /**< 32-bit value little-endian */
42     Binary   /**< Binary data */
43   };
44 
45   /**
46    * Constructor.
47    *
48    * @param type type
49    */
AttributeData(Type type)50   explicit AttributeData(Type type)
51   {
52     m_type = type;
53   }
54 
55   /**
56    * Constructor.
57    *
58    * @param name owner of Windows media PRIV frame
59    */
60   explicit AttributeData(const QString& name);
61 
62   /**
63    * Destructor.
64    */
~AttributeData()65   ~AttributeData() {}
66 
67   /**
68    * Get type.
69    * @return type.
70    */
getType()71   Type getType() const { return m_type; }
72 
73   /**
74    * Convert attribute data to string.
75    *
76    * @param data byte array with data
77    * @param str  result string
78    *
79    * @return true if ok.
80    */
81   bool toString(const QByteArray& data, QString& str);
82 
83   /**
84    * Convert attribute data string to byte array.
85    *
86    * @param str  string representation of data
87    * @param data result data
88    *
89    * @return true if ok.
90    */
91   bool toByteArray(const QString& str, QByteArray& data);
92 
93   /**
94    * Check if a string represents a hexadecimal number, i.e.
95    * contains only characters 0..9, A..F, a..f.
96    *
97    * @param str string to check
98    * @param lastAllowedLetter last allowed character (normally 'F')
99    * @param additionalChars additional allowed characters
100    *
101    * @return true if string has hex format.
102    */
103   static bool isHexString(const QString& str, char lastAllowedLetter = 'F',
104                           const QString& additionalChars = QString());
105 
106 private:
107   Type m_type;
108 };
109