id3v2frame.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     copyright            : (C) 2002 - 2008 by Scott Wheeler
00003     email                : wheeler@kde.org
00004  ***************************************************************************/
00005 
00006 /***************************************************************************
00007  *   This library is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU Lesser General Public License version   *
00009  *   2.1 as published by the Free Software Foundation.                     *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful, but   *
00012  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the Free Software   *
00018  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA         *
00019  *   02110-1301  USA                                                       *
00020  *                                                                         *
00021  *   Alternatively, this file is available under the Mozilla Public        *
00022  *   License Version 1.1.  You may obtain a copy of the License at         *
00023  *   http://www.mozilla.org/MPL/                                           *
00024  ***************************************************************************/
00025 
00026 #ifndef TAGLIB_ID3V2FRAME_H
00027 #define TAGLIB_ID3V2FRAME_H
00028 
00029 #include "tstring.h"
00030 #include "tbytevector.h"
00031 #include "taglib_export.h"
00032 
00033 namespace TagLib {
00034 
00035   class StringList;
00036   class PropertyMap;
00037 
00038   namespace ID3v2 {
00039 
00040     class Tag;
00041     class FrameFactory;
00042 
00044 
00054     class TAGLIB_EXPORT Frame
00055     {
00056       friend class Tag;
00057       friend class FrameFactory;
00058 
00059     public:
00060 
00066       static Frame *createTextualFrame(const String &key, const StringList &values);
00067 
00071       virtual ~Frame();
00072 
00077       ByteVector frameID() const;
00078 
00082       uint size() const;
00083 
00092       static uint headerSize(); // BIC: remove and make non-static
00093 
00099       static uint headerSize(uint version); // BIC: remove and make non-static
00100 
00107       void setData(const ByteVector &data);
00108 
00118       virtual void setText(const String &text);
00119 
00125       virtual String toString() const = 0;
00126 
00130       ByteVector render() const;
00131 
00136       static ByteVector textDelimiter(String::Type t);
00137 
00143       static const String instrumentPrefix;
00148       static const String commentPrefix;
00153       static const String lyricsPrefix;
00158       static const String urlPrefix;
00159 
00160     protected:
00161       class Header;
00162 
00170       explicit Frame(const ByteVector &data);
00171 
00178       Frame(Header *h);
00179 
00183       Header *header() const;
00184 
00192       void setHeader(Header *h, bool deleteCurrent = true);
00193 
00198       void parse(const ByteVector &data);
00199 
00205       virtual void parseFields(const ByteVector &data) = 0;
00206 
00211       virtual ByteVector renderFields() const = 0;
00212 
00218       ByteVector fieldData(const ByteVector &frameData) const;
00219 
00226       String readStringField(const ByteVector &data, String::Type encoding,
00227                              int *positon = 0);
00228 
00233       // BIC: remove and make non-static
00234       static String::Type checkEncoding(const StringList &fields,
00235                                         String::Type encoding);
00236 
00243       // BIC: remove and make non-static
00244       static String::Type checkEncoding(const StringList &fields,
00245                                         String::Type encoding, uint version);
00246 
00253       String::Type checkTextEncoding(const StringList &fields,
00254                                      String::Type encoding) const;
00255 
00256 
00263       PropertyMap asProperties() const;
00264 
00269       static ByteVector keyToFrameID(const String &);
00270 
00275       static String frameIDToKey(const ByteVector &);
00276 
00277 
00291       static void splitProperties(const PropertyMap &original, PropertyMap &singleFrameProperties,
00292           PropertyMap &tiplProperties, PropertyMap &tmclProperties);
00293 
00294     private:
00295       Frame(const Frame &);
00296       Frame &operator=(const Frame &);
00297 
00298       class FramePrivate;
00299       friend class FramePrivate;
00300       FramePrivate *d;
00301     };
00302 
00304 
00317     class TAGLIB_EXPORT Frame::Header
00318     {
00319     public:
00328       Header(const ByteVector &data, bool synchSafeInts);
00329 
00337       explicit Header(const ByteVector &data, uint version = 4);
00338 
00342       virtual ~Header();
00343 
00350       void setData(const ByteVector &data, bool synchSafeInts);
00351 
00356       void setData(const ByteVector &data, uint version = 4);
00357 
00362       ByteVector frameID() const;
00363 
00372       void setFrameID(const ByteVector &id);
00373 
00378       uint frameSize() const;
00379 
00383       void setFrameSize(uint size);
00384 
00389       uint version() const;
00390 
00395       void setVersion(uint version);
00396 
00405       static uint size();
00406 
00413       static uint size(uint version);
00414 
00424       bool tagAlterPreservation() const;
00425 
00437       void setTagAlterPreservation(bool discard);
00438 
00444       bool fileAlterPreservation() const;
00445 
00451       bool readOnly() const;
00452 
00458       bool groupingIdentity() const;
00459 
00465       bool compression() const;
00466 
00472       bool encryption() const;
00473 
00474 #ifndef DO_NOT_DOCUMENT
00475       bool unsycronisation() const;
00476 #endif
00477 
00481       bool unsynchronisation() const;
00482 
00486       bool dataLengthIndicator() const;
00487 
00491       ByteVector render() const;
00492 
00496       bool frameAlterPreservation() const;
00497 
00498     private:
00499       Header(const Header &);
00500       Header &operator=(const Header &);
00501 
00502       class HeaderPrivate;
00503       HeaderPrivate *d;
00504     };
00505 
00506   }
00507 }
00508 
00509 #endif