X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Ftaglib%2Fmpeg%2Fid3v2%2Fframes%2Fpopularimeterframe.cpp;fp=src%2Ftaglib%2Fmpeg%2Fid3v2%2Fframes%2Fpopularimeterframe.cpp;h=e65cbe0c9cb7c82248ff6be2dd45c4ae2aac935e;hb=68d60ad21e61d1e3255673985ae19606ceb0c59d;hp=0000000000000000000000000000000000000000;hpb=dca4bf6a28a8b904d45ff26376e667b05063a400;p=someplayer diff --git a/src/taglib/mpeg/id3v2/frames/popularimeterframe.cpp b/src/taglib/mpeg/id3v2/frames/popularimeterframe.cpp new file mode 100644 index 0000000..e65cbe0 --- /dev/null +++ b/src/taglib/mpeg/id3v2/frames/popularimeterframe.cpp @@ -0,0 +1,137 @@ +/*************************************************************************** + copyright : (C) 2008 by Lukas Lalinsky + email : lalinsky@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * + * USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#include + +#include "popularimeterframe.h" + +using namespace TagLib; +using namespace ID3v2; + +class PopularimeterFrame::PopularimeterFramePrivate +{ +public: + PopularimeterFramePrivate() : rating(0), counter(0) {} + String email; + int rating; + TagLib::uint counter; +}; + +//////////////////////////////////////////////////////////////////////////////// +// public members +//////////////////////////////////////////////////////////////////////////////// + +PopularimeterFrame::PopularimeterFrame() : Frame("POPM") +{ + d = new PopularimeterFramePrivate; +} + +PopularimeterFrame::PopularimeterFrame(const ByteVector &data) : Frame(data) +{ + d = new PopularimeterFramePrivate; + setData(data); +} + +PopularimeterFrame::~PopularimeterFrame() +{ + delete d; +} + +String PopularimeterFrame::toString() const +{ + return d->email + " rating=" + String::number(d->rating) + " counter=" + String::number(d->counter); +} + +String PopularimeterFrame::email() const +{ + return d->email; +} + +void PopularimeterFrame::setEmail(const String &s) +{ + d->email = s; +} + +int PopularimeterFrame::rating() const +{ + return d->rating; +} + +void PopularimeterFrame::setRating(int s) +{ + d->rating = s; +} + +TagLib::uint PopularimeterFrame::counter() const +{ + return d->counter; +} + +void PopularimeterFrame::setCounter(TagLib::uint s) +{ + d->counter = s; +} + +//////////////////////////////////////////////////////////////////////////////// +// protected members +//////////////////////////////////////////////////////////////////////////////// + +void PopularimeterFrame::parseFields(const ByteVector &data) +{ + int pos = 0, size = int(data.size()); + + d->email = readStringField(data, String::Latin1, &pos); + + d->rating = 0; + d->counter = 0; + if(pos < size) { + d->rating = (unsigned char)(data[pos++]); + if(pos < size) { + d->counter = data.mid(pos, 4).toUInt(); + } + } +} + +ByteVector PopularimeterFrame::renderFields() const +{ + ByteVector data; + + data.append(d->email.data(String::Latin1)); + data.append(textDelimiter(String::Latin1)); + data.append(char(d->rating)); + data.append(ByteVector::fromUInt(d->counter)); + + return data; +} + +//////////////////////////////////////////////////////////////////////////////// +// private members +//////////////////////////////////////////////////////////////////////////////// + +PopularimeterFrame::PopularimeterFrame(const ByteVector &data, Header *h) : Frame(h) +{ + d = new PopularimeterFramePrivate; + parseFields(fieldData(data)); +}