~njh-aelius/maxosx/musicbrainz-tags

« back to all changes in this revision

Viewing changes to Frameworks/taglib/taglib/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.cpp

  • Committer: stephen_booth
  • Date: 2008-04-30 01:48:01 UTC
  • Revision ID: svn-v4:6b6cea13-1402-0410-9567-a7afb52bf336:trunk:1371
Fixing the taglib source tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    copyright            : (C) 2002 - 2008 by Scott Wheeler
3
 
    email                : wheeler@kde.org
4
 
    copyright            : (C) 2006 by Aaron VonderHaar
5
 
    email                : avh4@users.sourceforge.net
6
 
 ***************************************************************************/
7
 
 
8
 
/***************************************************************************
9
 
 *   This library is free software; you can redistribute it and/or modify  *
10
 
 *   it under the terms of the GNU Lesser General Public License version   *
11
 
 *   2.1 as published by the Free Software Foundation.                     *
12
 
 *                                                                         *
13
 
 *   This library is distributed in the hope that it will be useful, but   *
14
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
15
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
16
 
 *   Lesser General Public License for more details.                       *
17
 
 *                                                                         *
18
 
 *   You should have received a copy of the GNU Lesser General Public      *
19
 
 *   License along with this library; if not, write to the Free Software   *
20
 
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
21
 
 *   USA                                                                   *
22
 
 *                                                                         *
23
 
 *   Alternatively, this file is available under the Mozilla Public        *
24
 
 *   License Version 1.1.  You may obtain a copy of the License at         *
25
 
 *   http://www.mozilla.org/MPL/                                           *
26
 
 ***************************************************************************/
27
 
 
28
 
#include <tdebug.h>
29
 
 
30
 
#include "generalencapsulatedobjectframe.h"
31
 
 
32
 
using namespace TagLib;
33
 
using namespace ID3v2;
34
 
 
35
 
class GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFramePrivate
36
 
{
37
 
public:
38
 
  GeneralEncapsulatedObjectFramePrivate() : textEncoding(String::Latin1) {}
39
 
 
40
 
  String::Type textEncoding;
41
 
  String mimeType;
42
 
  String fileName;
43
 
  String description;
44
 
  ByteVector data;
45
 
};
46
 
 
47
 
////////////////////////////////////////////////////////////////////////////////
48
 
// public members
49
 
////////////////////////////////////////////////////////////////////////////////
50
 
 
51
 
GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFrame() : Frame("GEOB")
52
 
{
53
 
    d = new GeneralEncapsulatedObjectFramePrivate;
54
 
}
55
 
 
56
 
GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFrame(const ByteVector &data) : Frame(data)
57
 
{
58
 
  d = new GeneralEncapsulatedObjectFramePrivate;
59
 
  setData(data);
60
 
}
61
 
 
62
 
GeneralEncapsulatedObjectFrame::~GeneralEncapsulatedObjectFrame()
63
 
{
64
 
  delete d;
65
 
}
66
 
 
67
 
String GeneralEncapsulatedObjectFrame::toString() const
68
 
{
69
 
  String text = "[" + d->mimeType + "]";
70
 
 
71
 
  if(!d->fileName.isEmpty())
72
 
    text += " " + d->fileName;
73
 
 
74
 
  if(!d->description.isEmpty())
75
 
    text += " \"" + d->description + "\"";
76
 
 
77
 
  return text;
78
 
}
79
 
 
80
 
String::Type GeneralEncapsulatedObjectFrame::textEncoding() const
81
 
{
82
 
  return d->textEncoding;
83
 
}
84
 
 
85
 
void GeneralEncapsulatedObjectFrame::setTextEncoding(String::Type encoding)
86
 
{
87
 
  d->textEncoding = encoding;
88
 
}
89
 
 
90
 
String GeneralEncapsulatedObjectFrame::mimeType() const
91
 
{
92
 
  return d->mimeType;
93
 
}
94
 
 
95
 
void GeneralEncapsulatedObjectFrame::setMimeType(const String &type)
96
 
{
97
 
  d->mimeType = type;
98
 
}
99
 
 
100
 
String GeneralEncapsulatedObjectFrame::fileName() const
101
 
{
102
 
  return d->fileName;
103
 
}
104
 
 
105
 
void GeneralEncapsulatedObjectFrame::setFileName(const String &name)
106
 
{
107
 
  d->fileName = name;
108
 
}
109
 
 
110
 
String GeneralEncapsulatedObjectFrame::description() const
111
 
{
112
 
  return d->description;
113
 
}
114
 
 
115
 
void GeneralEncapsulatedObjectFrame::setDescription(const String &desc)
116
 
{
117
 
  d->description = desc;
118
 
}
119
 
 
120
 
ByteVector GeneralEncapsulatedObjectFrame::object() const
121
 
{
122
 
  return d->data;
123
 
}
124
 
 
125
 
void GeneralEncapsulatedObjectFrame::setObject(const ByteVector &data)
126
 
{
127
 
  d->data = data;
128
 
}
129
 
 
130
 
////////////////////////////////////////////////////////////////////////////////
131
 
// protected members
132
 
////////////////////////////////////////////////////////////////////////////////
133
 
 
134
 
void GeneralEncapsulatedObjectFrame::parseFields(const ByteVector &data)
135
 
{
136
 
  if(data.size() < 4) {
137
 
    debug("An object frame must contain at least 4 bytes.");
138
 
    return;
139
 
  }
140
 
 
141
 
  d->textEncoding = String::Type(data[0]);
142
 
 
143
 
  int pos = 1;
144
 
 
145
 
  d->mimeType = readStringField(data, String::Latin1, &pos);
146
 
  d->fileName = readStringField(data, d->textEncoding, &pos);
147
 
  d->description = readStringField(data, d->textEncoding, &pos);
148
 
 
149
 
  d->data = data.mid(pos);
150
 
}
151
 
 
152
 
ByteVector GeneralEncapsulatedObjectFrame::renderFields() const
153
 
{
154
 
  ByteVector data;
155
 
 
156
 
  data.append(char(d->textEncoding));
157
 
  data.append(d->mimeType.data(String::Latin1));
158
 
  data.append(textDelimiter(String::Latin1));
159
 
  data.append(d->fileName.data(d->textEncoding));
160
 
  data.append(textDelimiter(d->textEncoding));
161
 
  data.append(d->description.data(d->textEncoding));
162
 
  data.append(textDelimiter(d->textEncoding));
163
 
  data.append(d->data);
164
 
 
165
 
  return data;
166
 
}
167
 
 
168
 
////////////////////////////////////////////////////////////////////////////////
169
 
// private members
170
 
////////////////////////////////////////////////////////////////////////////////
171
 
 
172
 
GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFrame(const ByteVector &data, Header *h) : Frame(h)
173
 
{
174
 
  d = new GeneralEncapsulatedObjectFramePrivate;
175
 
  parseFields(fieldData(data));
176
 
}