id3v2frame.h
Go to the documentation of this file.
1 /***************************************************************************
2  copyright : (C) 2002 - 2008 by Scott Wheeler
3  email : wheeler@kde.org
4  ***************************************************************************/
5 
6 /***************************************************************************
7  * This library is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU Lesser General Public License version *
9  * 2.1 as published by the Free Software Foundation. *
10  * *
11  * This library is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the Free Software *
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19  * 02110-1301 USA *
20  * *
21  * Alternatively, this file is available under the Mozilla Public *
22  * License Version 1.1. You may obtain a copy of the License at *
23  * http://www.mozilla.org/MPL/ *
24  ***************************************************************************/
25 
26 #ifndef TAGLIB_ID3V2FRAME_H
27 #define TAGLIB_ID3V2FRAME_H
28 
29 #include "tstring.h"
30 #include "tbytevector.h"
31 #include "taglib_export.h"
32 
33 namespace TagLib {
34 
35  class StringList;
36  class PropertyMap;
37 
38  namespace ID3v2 {
39 
40  class Tag;
41  class FrameFactory;
42 
44 
55  {
56  friend class Tag;
57  friend class FrameFactory;
58 
59  public:
60 
66  static Frame *createTextualFrame(const String &key, const StringList &values);
67 
71  virtual ~Frame();
72 
77  ByteVector frameID() const;
78 
82  uint size() const;
83 
92  static uint headerSize(); // BIC: remove and make non-static
93 
99  static uint headerSize(uint version); // BIC: remove and make non-static
100 
107  void setData(const ByteVector &data);
108 
118  virtual void setText(const String &text);
119 
125  virtual String toString() const = 0;
126 
130  ByteVector render() const;
131 
136  static ByteVector textDelimiter(String::Type t);
137 
143  static const String instrumentPrefix;
148  static const String commentPrefix;
153  static const String lyricsPrefix;
158  static const String urlPrefix;
159 
160  protected:
161  class Header;
162 
170  explicit Frame(const ByteVector &data);
171 
178  Frame(Header *h);
179 
183  Header *header() const;
184 
192  void setHeader(Header *h, bool deleteCurrent = true);
193 
198  void parse(const ByteVector &data);
199 
205  virtual void parseFields(const ByteVector &data) = 0;
206 
211  virtual ByteVector renderFields() const = 0;
212 
218  ByteVector fieldData(const ByteVector &frameData) const;
219 
226  String readStringField(const ByteVector &data, String::Type encoding,
227  int *positon = 0);
228 
233  // BIC: remove and make non-static
234  static String::Type checkEncoding(const StringList &fields,
235  String::Type encoding);
236 
243  // BIC: remove and make non-static
244  static String::Type checkEncoding(const StringList &fields,
245  String::Type encoding, uint version);
246 
253  String::Type checkTextEncoding(const StringList &fields,
254  String::Type encoding) const;
255 
256 
263  PropertyMap asProperties() const;
264 
269  static ByteVector keyToFrameID(const String &);
270 
275  static String frameIDToKey(const ByteVector &);
276 
280  static String keyToTXXX(const String &);
281 
285  static String txxxToKey(const String &);
286 
300  static void splitProperties(const PropertyMap &original, PropertyMap &singleFrameProperties,
301  PropertyMap &tiplProperties, PropertyMap &tmclProperties);
302 
303  private:
304  Frame(const Frame &);
305  Frame &operator=(const Frame &);
306 
307  class FramePrivate;
308  friend class FramePrivate;
309  FramePrivate *d;
310  };
311 
313 
326  class TAGLIB_EXPORT Frame::Header
327  {
328  public:
337  Header(const ByteVector &data, bool synchSafeInts);
338 
346  explicit Header(const ByteVector &data, uint version = 4);
347 
351  virtual ~Header();
352 
359  void setData(const ByteVector &data, bool synchSafeInts);
360 
365  void setData(const ByteVector &data, uint version = 4);
366 
371  ByteVector frameID() const;
372 
381  void setFrameID(const ByteVector &id);
382 
387  uint frameSize() const;
388 
392  void setFrameSize(uint size);
393 
398  uint version() const;
399 
404  void setVersion(uint version);
405 
414  static uint size();
415 
422  static uint size(uint version);
423 
433  bool tagAlterPreservation() const;
434 
446  void setTagAlterPreservation(bool discard);
447 
453  bool fileAlterPreservation() const;
454 
460  bool readOnly() const;
461 
467  bool groupingIdentity() const;
468 
474  bool compression() const;
475 
481  bool encryption() const;
482 
483 #ifndef DO_NOT_DOCUMENT
484  bool unsycronisation() const;
485 #endif
486 
490  bool unsynchronisation() const;
491 
495  bool dataLengthIndicator() const;
496 
500  ByteVector render() const;
501 
505  bool frameAlterPreservation() const;
506 
507  private:
508  Header(const Header &);
509  Header &operator=(const Header &);
510 
511  class HeaderPrivate;
512  HeaderPrivate *d;
513  };
514 
515  }
516 }
517 
518 #endif