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., 51 Franklin Street, Fifth Floor, Boston, MA *
20 * 02110-1301 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
PrivateFrame()48 PrivateFrame::PrivateFrame() :
49 Frame("PRIV"),
50 d(new PrivateFramePrivate())
51 {
52 }
53
PrivateFrame(const ByteVector & data)54 PrivateFrame::PrivateFrame(const ByteVector &data) :
55 Frame(data),
56 d(new PrivateFramePrivate())
57 {
58 setData(data);
59 }
60
~PrivateFrame()61 PrivateFrame::~PrivateFrame()
62 {
63 delete d;
64 }
65
toString() const66 String PrivateFrame::toString() const
67 {
68 return d->owner;
69 }
70
owner() const71 String PrivateFrame::owner() const
72 {
73 return d->owner;
74 }
75
data() const76 ByteVector PrivateFrame::data() const
77 {
78 return d->data;
79 }
80
setOwner(const String & s)81 void PrivateFrame::setOwner(const String &s)
82 {
83 d->owner = s;
84 }
85
setData(const ByteVector & data)86 void PrivateFrame::setData(const ByteVector & data)
87 {
88 d->data = data;
89 }
90
91 ////////////////////////////////////////////////////////////////////////////////
92 // protected members
93 ////////////////////////////////////////////////////////////////////////////////
94
parseFields(const ByteVector & data)95 void PrivateFrame::parseFields(const ByteVector &data)
96 {
97 if(data.size() < 2) {
98 debug("A private frame must contain at least 2 bytes.");
99 return;
100 }
101
102 // Owner identifier is assumed to be Latin1
103
104 const int byteAlign = 1;
105 const int endOfOwner = data.find(textDelimiter(String::Latin1), 0, byteAlign);
106
107 d->owner = String(data.mid(0, endOfOwner));
108 d->data = data.mid(endOfOwner + 1);
109 }
110
renderFields() const111 ByteVector PrivateFrame::renderFields() const
112 {
113 ByteVector v;
114
115 v.append(d->owner.data(String::Latin1));
116 v.append(textDelimiter(String::Latin1));
117 v.append(d->data);
118
119 return v;
120 }
121
122 ////////////////////////////////////////////////////////////////////////////////
123 // private members
124 ////////////////////////////////////////////////////////////////////////////////
125
PrivateFrame(const ByteVector & data,Header * h)126 PrivateFrame::PrivateFrame(const ByteVector &data, Header *h) :
127 Frame(h),
128 d(new PrivateFramePrivate())
129 {
130 parseFields(fieldData(data));
131 }
132