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 
277 
291  static void splitProperties(const PropertyMap &original, PropertyMap &singleFrameProperties,
292  PropertyMap &tiplProperties, PropertyMap &tmclProperties);
293 
294  private:
295  Frame(const Frame &);
296  Frame &operator=(const Frame &);
297 
298  class FramePrivate;
299  friend class FramePrivate;
300  FramePrivate *d;
301  };
302 
304 
317  class TAGLIB_EXPORT Frame::Header
318  {
319  public:
328  Header(const ByteVector &data, bool synchSafeInts);
329 
337  explicit Header(const ByteVector &data, uint version = 4);
338 
342  virtual ~Header();
343 
350  void setData(const ByteVector &data, bool synchSafeInts);
351 
356  void setData(const ByteVector &data, uint version = 4);
357 
362  ByteVector frameID() const;
363 
372  void setFrameID(const ByteVector &id);
373 
378  uint frameSize() const;
379 
383  void setFrameSize(uint size);
384 
389  uint version() const;
390 
395  void setVersion(uint version);
396 
405  static uint size();
406 
413  static uint size(uint version);
414 
424  bool tagAlterPreservation() const;
425 
437  void setTagAlterPreservation(bool discard);
438 
444  bool fileAlterPreservation() const;
445 
451  bool readOnly() const;
452 
458  bool groupingIdentity() const;
459 
465  bool compression() const;
466 
472  bool encryption() const;
473 
474 #ifndef DO_NOT_DOCUMENT
475  bool unsycronisation() const;
476 #endif
477 
481  bool unsynchronisation() const;
482 
486  bool dataLengthIndicator() const;
487 
491  ByteVector render() const;
492 
496  bool frameAlterPreservation() const;
497 
498  private:
499  Header(const Header &);
500  Header &operator=(const Header &);
501 
502  class HeaderPrivate;
503  HeaderPrivate *d;
504  };
505 
506  }
507 }
508 
509 #endif