File indexing completed on 2024-04-28 04:45:52
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Sergey Ivanov <123kash@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef TAGHELPER_H 0018 #define TAGHELPER_H 0019 0020 #define MIN_COVER_SIZE 1024 // Minimum size for an embedded cover to be loaded 0021 0022 #include "MetaValues.h" 0023 #include "FileType.h" 0024 #include "amarokshared_export.h" 0025 0026 #pragma GCC diagnostic push 0027 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 0028 #include <fileref.h> 0029 #include <tag.h> 0030 #include <id3v1tag.h> 0031 #pragma GCC diagnostic pop 0032 0033 namespace Meta 0034 { 0035 namespace Tag 0036 { 0037 class AMAROKSHARED_EXPORT TagHelper 0038 { 0039 public: 0040 enum UIDType 0041 { 0042 UIDInvalid = 0, 0043 UIDAFT = 3 0044 }; 0045 0046 enum FMPS 0047 { 0048 FMPSPlayCount = 0, 0049 FMPSRating = 1, 0050 FMPSScore = 2 0051 }; 0052 0053 TagHelper( TagLib::Tag *tag, Amarok::FileType fileType ); 0054 explicit TagHelper( TagLib::ID3v1::Tag *tag, Amarok::FileType fileType ); 0055 virtual ~TagHelper(); 0056 0057 /** 0058 * Read all supported tags from file. 0059 */ 0060 virtual Meta::FieldHash tags() const; 0061 /** 0062 * Write changed metadata to file. 0063 * Return true if something written. 0064 */ 0065 virtual bool setTags( const Meta::FieldHash &changes ); 0066 0067 /** 0068 * Render tags. Used in UID generator. 0069 */ 0070 virtual TagLib::ByteVector render() const; 0071 0072 /** 0073 * Check If file contains embedded cover. 0074 */ 0075 virtual bool hasEmbeddedCover() const; 0076 0077 /** 0078 * Read embedded cover from file. 0079 */ 0080 virtual QImage embeddedCover() const; 0081 0082 /** 0083 * Add or update cover in file. Will be set as FrontCover. 0084 * Return true If something written. 0085 */ 0086 virtual bool setEmbeddedCover( const QImage &cover ); 0087 0088 /** 0089 * Return file type. 0090 */ 0091 Amarok::FileType fileType() const; 0092 0093 /** 0094 * Returns combination of: 0095 * title, album, artist, genre and comment fields. 0096 * Used to encoding detection. 0097 */ 0098 QByteArray testString() const; 0099 0100 protected: 0101 /** 0102 * Split UID url. 0103 * @return Pair of uid type and uid. Uid type can be used to 0104 * get field name where to write It (owner in case of ID3v2). 0105 */ 0106 QPair< UIDType, QString > splitUID( const QString &uidUrl ) const; 0107 /** 0108 * Check If @arg uid correct UID for specified @arg type. 0109 */ 0110 bool isValidUID( const QString &uid, const UIDType type ) const; 0111 /** 0112 * Returns field name for Meta::val* value. 0113 */ 0114 TagLib::String fieldName( const qint64 field ) const; 0115 /** 0116 * Returns Meta::val* value corresponds to field name. 0117 */ 0118 qint64 fieldName( const TagLib::String &field ) const; 0119 /** 0120 * Split DiscNr field on Disc number and Disc count. 0121 */ 0122 QPair< int, int > splitDiscNr( const QString &value ) const; 0123 /** 0124 * Returns field name for specified UID type. 0125 */ 0126 TagLib::String uidFieldName( const UIDType type ) const; 0127 /** 0128 * Returns field name for specified FMPS value. 0129 */ 0130 TagLib::String fmpsFieldName( const FMPS field ) const; 0131 0132 QHash< quint64, TagLib::String > m_fieldMap; 0133 QHash< FMPS, TagLib::String > m_fmpsFieldMap; 0134 QHash< UIDType, TagLib::String > m_uidFieldMap; 0135 0136 private: 0137 TagLib::Tag *m_tag; 0138 Amarok::FileType m_fileType; 0139 }; 0140 0141 /** 0142 * Returns TagHelper for specified @arg fileref. 0143 * @arg forceCreation If true: selector will force tag creation. 0144 * @return TagHelper or NULL if file doesn't have tags. 0145 * Should be deleted by user after use. 0146 */ 0147 AMAROKSHARED_EXPORT TagHelper *selectHelper( const TagLib::FileRef &fileref, bool forceCreation = false ); 0148 } 0149 } 0150 0151 #endif // TAGHELPER_H