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       unsigned int size() const;
00083 
00092       static unsigned int headerSize(); // BIC: remove and make non-static
00093 
00099       static unsigned int headerSize(unsigned int 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, unsigned int 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 
00280       static String keyToTXXX(const String &);
00281 
00285       static String txxxToKey(const String &);
00286 
00300       static void splitProperties(const PropertyMap &original, PropertyMap &singleFrameProperties,
00301           PropertyMap &tiplProperties, PropertyMap &tmclProperties);
00302 
00303     private:
00304       Frame(const Frame &);
00305       Frame &operator=(const Frame &);
00306 
00307       class FramePrivate;
00308       friend class FramePrivate;
00309       FramePrivate *d;
00310     };
00311 
00313 
00326     class TAGLIB_EXPORT Frame::Header
00327     {
00328     public:
00337       Header(const ByteVector &data, bool synchSafeInts);
00338 
00346       explicit Header(const ByteVector &data, unsigned int version = 4);
00347 
00351       virtual ~Header();
00352 
00359       void setData(const ByteVector &data, bool synchSafeInts);
00360 
00365       void setData(const ByteVector &data, unsigned int version = 4);
00366 
00371       ByteVector frameID() const;
00372 
00381       void setFrameID(const ByteVector &id);
00382 
00387       unsigned int frameSize() const;
00388 
00392       void setFrameSize(unsigned int size);
00393 
00398       unsigned int version() const;
00399 
00404       void setVersion(unsigned int version);
00405 
00414       static unsigned int size();
00415 
00422       static unsigned int size(unsigned int version);
00423 
00433       bool tagAlterPreservation() const;
00434 
00446       void setTagAlterPreservation(bool discard);
00447 
00453       bool fileAlterPreservation() const;
00454 
00460       bool readOnly() const;
00461 
00467       bool groupingIdentity() const;
00468 
00474       bool compression() const;
00475 
00481       bool encryption() const;
00482 
00483 #ifndef DO_NOT_DOCUMENT
00484       bool unsycronisation() const;
00485 #endif
00486 
00490       bool unsynchronisation() const;
00491 
00495       bool dataLengthIndicator() const;
00496 
00500       ByteVector render() const;
00501 
00505       bool frameAlterPreservation() const;
00506 
00507     private:
00508       Header(const Header &);
00509       Header &operator=(const Header &);
00510 
00511       class HeaderPrivate;
00512       HeaderPrivate *d;
00513     };
00514 
00515   }
00516 }
00517 
00518 #endif