Added TagLib (with AUTORS and COPYING files)
[someplayer] / src / taglib / mpeg / id3v2 / frames / privateframe.cpp
1 /***************************************************************************
2     copyright            : (C) 2008 by Serkan Kalyoncu
3     copyright            : (C) 2008 by Scott Wheeler
4     email                : wheeler@kde.org
5 ***************************************************************************/
6
7 /***************************************************************************
8  *   This library is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU Lesser General Public License version   *
10  *   2.1 as published by the Free Software Foundation.                     *
11  *                                                                         *
12  *   This library is distributed in the hope that it will be useful, but   *
13  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
15  *   Lesser General Public License for more details.                       *
16  *                                                                         *
17  *   You should have received a copy of the GNU Lesser General Public      *
18  *   License along with this library; if not, write to the Free Software   *
19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20  *   USA                                                                   *
21  *                                                                         *
22  *   Alternatively, this file is available under the Mozilla Public        *
23  *   License Version 1.1.  You may obtain a copy of the License at         *
24  *   http://www.mozilla.org/MPL/                                           *
25  ***************************************************************************/
26
27 #include <tbytevectorlist.h>
28 #include <id3v2tag.h>
29 #include <tdebug.h>
30
31 #include "privateframe.h"
32
33 using namespace TagLib;
34 using namespace ID3v2;
35
36
37 class PrivateFrame::PrivateFramePrivate
38 {
39 public:
40   ByteVector data;
41   String owner;
42 };
43
44 ////////////////////////////////////////////////////////////////////////////////
45 // public members
46 ////////////////////////////////////////////////////////////////////////////////
47
48 PrivateFrame::PrivateFrame() : Frame("PRIV")
49 {
50   d = new PrivateFramePrivate;
51 }
52
53 PrivateFrame::PrivateFrame(const ByteVector &data) : Frame(data)
54 {
55   d = new PrivateFramePrivate;
56   setData(data);
57 }
58
59 PrivateFrame::~PrivateFrame()
60 {
61   delete d;
62 }
63
64 String PrivateFrame::toString() const
65 {
66   return d->owner;
67 }
68
69 String PrivateFrame::owner() const
70 {
71   return d->owner;
72 }
73
74 ByteVector PrivateFrame::data() const
75 {
76   return d->data;
77 }
78
79 void PrivateFrame::setOwner(const String &s)
80 {
81   d->owner = s;
82 }
83
84 void PrivateFrame::setData(const ByteVector & data)
85 {
86   d->data = data;
87 }
88
89 ////////////////////////////////////////////////////////////////////////////////
90 // protected members
91 ////////////////////////////////////////////////////////////////////////////////
92
93 void PrivateFrame::parseFields(const ByteVector &data)
94 {
95   if(data.size() < 2) {
96     debug("A private frame must contain at least 2 bytes.");
97     return;
98   }
99
100   // Owner identifier is assumed to be Latin1
101   
102   const int byteAlign =  1;
103   const int endOfOwner = data.find(textDelimiter(String::Latin1), 0, byteAlign);
104
105   d->owner =  String(data.mid(0, endOfOwner));
106   d->data = data.mid(endOfOwner + 1);
107 }
108
109 ByteVector PrivateFrame::renderFields() const
110 {
111   ByteVector v;
112
113   v.append(d->owner.data(String::Latin1));
114   v.append(textDelimiter(String::Latin1));
115   v.append(d->data);
116
117   return v;
118 }
119
120 ////////////////////////////////////////////////////////////////////////////////
121 // private members
122 ////////////////////////////////////////////////////////////////////////////////
123
124 PrivateFrame::PrivateFrame(const ByteVector &data, Header *h) : Frame(h)
125 {
126   d = new PrivateFramePrivate();
127   parseFields(fieldData(data));
128 }