File indexing completed on 2024-05-19 04:56:09
0001 /** 0002 * \file attributedata.h 0003 * String representation of attribute data. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 28 Mar 2009 0008 * 0009 * Copyright (C) 2009-2024 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 <QByteArray> 0031 #include "kid3api.h" 0032 0033 /** Attribute data used e.g. by Windows Media Player. */ 0034 class KID3_CORE_EXPORT AttributeData { 0035 public: 0036 /** Attribute data types. */ 0037 enum Type { 0038 Unknown, /**< Unknown type */ 0039 Utf16, /**< UTF-16 encoded, zero-terminated Unicode string */ 0040 Guid, /**< 128-bit GUID */ 0041 DWord, /**< 32-bit value little-endian */ 0042 Binary /**< Binary data */ 0043 }; 0044 0045 /** 0046 * Constructor. 0047 * 0048 * @param type type 0049 */ 0050 explicit AttributeData(Type type) 0051 { 0052 m_type = type; 0053 } 0054 0055 /** 0056 * Constructor. 0057 * 0058 * @param name owner of Windows media PRIV frame 0059 */ 0060 explicit AttributeData(const QString& name); 0061 0062 /** 0063 * Destructor. 0064 */ 0065 ~AttributeData() {} 0066 0067 /** 0068 * Get type. 0069 * @return type. 0070 */ 0071 Type getType() const { return m_type; } 0072 0073 /** 0074 * Convert attribute data to string. 0075 * 0076 * @param data byte array with data 0077 * @param str result string 0078 * 0079 * @return true if ok. 0080 */ 0081 bool toString(const QByteArray& data, QString& str) const; 0082 0083 /** 0084 * Convert attribute data string to byte array. 0085 * 0086 * @param str string representation of data 0087 * @param data result data 0088 * 0089 * @return true if ok. 0090 */ 0091 bool toByteArray(const QString& str, QByteArray& data) const; 0092 0093 /** 0094 * Check if a string represents a hexadecimal number, i.e. 0095 * contains only characters 0..9, A..F, a..f. 0096 * 0097 * @param str string to check 0098 * @param lastAllowedLetter last allowed character (normally 'F') 0099 * @param additionalChars additional allowed characters 0100 * 0101 * @return true if string has hex format. 0102 */ 0103 static bool isHexString(const QString& str, char lastAllowedLetter = 'F', 0104 const QString& additionalChars = QString()); 0105 0106 private: 0107 Type m_type; 0108 };