Added TagLib (with AUTORS and COPYING files)
[someplayer] / src / taglib / mpeg / id3v2 / frames / uniquefileidentifierframe.cpp
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19  *   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 #include <tbytevectorlist.h>
27 #include <tdebug.h>
28
29 #include "uniquefileidentifierframe.h"
30
31 using namespace TagLib;
32 using namespace ID3v2;
33
34 class UniqueFileIdentifierFrame::UniqueFileIdentifierFramePrivate
35 {
36 public:
37   String owner;
38   ByteVector identifier;
39 };
40
41 ////////////////////////////////////////////////////////////////////////////////
42 // public methods
43 ////////////////////////////////////////////////////////////////////////////////
44
45 UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const ByteVector &data) :
46     ID3v2::Frame(data)
47 {
48   d = new UniqueFileIdentifierFramePrivate;
49   setData(data);
50 }
51
52 UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const String &owner, const ByteVector &id) :
53     ID3v2::Frame("UFID")
54 {
55   d = new UniqueFileIdentifierFramePrivate;
56   d->owner = owner;
57   d->identifier = id;
58 }
59
60 UniqueFileIdentifierFrame::~UniqueFileIdentifierFrame()
61 {
62   delete d;
63 }
64
65 String UniqueFileIdentifierFrame::owner() const
66 {
67     return d->owner;
68 }
69
70 ByteVector UniqueFileIdentifierFrame::identifier() const
71 {
72   return d->identifier;
73 }
74
75 void UniqueFileIdentifierFrame::setOwner(const String &s)
76 {
77   d->owner = s;
78 }
79
80 void UniqueFileIdentifierFrame::setIdentifier(const ByteVector &v)
81 {
82   d->identifier = v;
83 }
84
85 String UniqueFileIdentifierFrame::toString() const
86 {
87   return String::null;
88 }
89
90 void UniqueFileIdentifierFrame::parseFields(const ByteVector &data)
91 {
92   if(data.size() < 1) {
93     debug("An UFID frame must contain at least 1 byte.");
94     return;
95   }
96
97   int pos = 0;
98   d->owner = readStringField(data, String::Latin1, &pos);
99   d->identifier = data.mid(pos);
100 }
101
102 ByteVector UniqueFileIdentifierFrame::renderFields() const
103 {
104   ByteVector data;
105
106   data.append(d->owner.data(String::Latin1));
107   data.append(char(0));
108   data.append(d->identifier);
109
110   return data;
111 }
112
113 UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const ByteVector &data, Header *h) :
114   Frame(h)
115 {
116   d = new UniqueFileIdentifierFramePrivate;
117   parseFields(fieldData(data));
118 }