1 /***************************************************************************
2 copyright : (C) 2008 by Lukas Lalinsky
3 email : lalinsky@gmail.com
4 ***************************************************************************/
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. *
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. *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
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 ***************************************************************************/
28 #include "popularimeterframe.h"
30 using namespace TagLib;
31 using namespace ID3v2;
33 class PopularimeterFrame::PopularimeterFramePrivate
36 PopularimeterFramePrivate() : rating(0), counter(0) {}
42 ////////////////////////////////////////////////////////////////////////////////
44 ////////////////////////////////////////////////////////////////////////////////
46 PopularimeterFrame::PopularimeterFrame() : Frame("POPM")
48 d = new PopularimeterFramePrivate;
51 PopularimeterFrame::PopularimeterFrame(const ByteVector &data) : Frame(data)
53 d = new PopularimeterFramePrivate;
57 PopularimeterFrame::~PopularimeterFrame()
62 String PopularimeterFrame::toString() const
64 return d->email + " rating=" + String::number(d->rating) + " counter=" + String::number(d->counter);
67 String PopularimeterFrame::email() const
72 void PopularimeterFrame::setEmail(const String &s)
77 int PopularimeterFrame::rating() const
82 void PopularimeterFrame::setRating(int s)
87 TagLib::uint PopularimeterFrame::counter() const
92 void PopularimeterFrame::setCounter(TagLib::uint s)
97 ////////////////////////////////////////////////////////////////////////////////
99 ////////////////////////////////////////////////////////////////////////////////
101 void PopularimeterFrame::parseFields(const ByteVector &data)
103 int pos = 0, size = int(data.size());
105 d->email = readStringField(data, String::Latin1, &pos);
110 d->rating = (unsigned char)(data[pos++]);
112 d->counter = data.mid(pos, 4).toUInt();
117 ByteVector PopularimeterFrame::renderFields() const
121 data.append(d->email.data(String::Latin1));
122 data.append(textDelimiter(String::Latin1));
123 data.append(char(d->rating));
124 data.append(ByteVector::fromUInt(d->counter));
129 ////////////////////////////////////////////////////////////////////////////////
131 ////////////////////////////////////////////////////////////////////////////////
133 PopularimeterFrame::PopularimeterFrame(const ByteVector &data, Header *h) : Frame(h)
135 d = new PopularimeterFramePrivate;
136 parseFields(fieldData(data));