~ubuntu-branches/ubuntu/wily/kid3/wily

« back to all changes in this revision

Viewing changes to src/core/formats/taglibext/generalencapsulatedobjectframe.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell, Patrick Matthäi, Mark Purcell
  • Date: 2013-11-30 15:44:59 UTC
  • mfrom: (1.1.16) (2.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20131130154459-s6lpalx8yy2zq7gx
Tags: 3.0.2-1
* New upstream release 

[ Patrick Matthäi ]
* New upstream release.
  - Add new libreadline-dev build dependency.
* Don't explicitly request xz compression - dpkg 1.17 does this by default.
* Bump Standards-Version to 3.9.5 (no changes needed).
* Fix Vcs-Browser control field.

[ Mark Purcell ]
* Switch to dh - reduce debian/rules bloat
* kid3 Replaces kid3-qt - low popcon, reduce archive bloat
* Fix vcs-field-not-canonical
* debian/compat -> 9
* Update Description:

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    copyright            : (C) 2004 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
 
 
24
 
#include <tdebug.h>
25
 
 
26
 
#include "generalencapsulatedobjectframe.h"
27
 
 
28
 
using namespace TagLib;
29
 
using namespace ID3v2;
30
 
 
31
 
class GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFramePrivate
32
 
{
33
 
public:
34
 
  GeneralEncapsulatedObjectFramePrivate() : textEncoding(String::Latin1) {}
35
 
 
36
 
  String::Type textEncoding;
37
 
  String mimeType;
38
 
  String fileName;
39
 
  String description;
40
 
  ByteVector data;
41
 
};
42
 
 
43
 
////////////////////////////////////////////////////////////////////////////////
44
 
// public members
45
 
////////////////////////////////////////////////////////////////////////////////
46
 
 
47
 
GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFrame() : Frame("GEOB")
48
 
{
49
 
    d = new GeneralEncapsulatedObjectFramePrivate;
50
 
}
51
 
 
52
 
GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFrame(const ByteVector &data) : Frame(data)
53
 
{
54
 
  d = new GeneralEncapsulatedObjectFramePrivate;
55
 
  setData(data);
56
 
}
57
 
 
58
 
GeneralEncapsulatedObjectFrame::~GeneralEncapsulatedObjectFrame()
59
 
{
60
 
  delete d;
61
 
}
62
 
 
63
 
String GeneralEncapsulatedObjectFrame::toString() const
64
 
{
65
 
  String text = "[" + d->mimeType + "]";
66
 
 
67
 
  if(!d->fileName.isEmpty())
68
 
    text += " " + d->fileName;
69
 
 
70
 
  if(!d->description.isEmpty())
71
 
    text += " \"" + d->description + "\"";
72
 
 
73
 
  return text;
74
 
}
75
 
 
76
 
String::Type GeneralEncapsulatedObjectFrame::textEncoding() const
77
 
{
78
 
  return d->textEncoding;
79
 
}
80
 
 
81
 
void GeneralEncapsulatedObjectFrame::setTextEncoding(String::Type encoding)
82
 
{
83
 
  d->textEncoding = encoding;
84
 
}
85
 
 
86
 
String GeneralEncapsulatedObjectFrame::mimeType() const
87
 
{
88
 
  return d->mimeType;
89
 
}
90
 
 
91
 
void GeneralEncapsulatedObjectFrame::setMimeType(const String &type)
92
 
{
93
 
  d->mimeType = type;
94
 
}
95
 
 
96
 
String GeneralEncapsulatedObjectFrame::fileName() const
97
 
{
98
 
  return d->fileName;
99
 
}
100
 
 
101
 
void GeneralEncapsulatedObjectFrame::setFileName(const String &name)
102
 
{
103
 
  d->fileName = name;
104
 
}
105
 
 
106
 
String GeneralEncapsulatedObjectFrame::description() const
107
 
{
108
 
  return d->description;
109
 
}
110
 
 
111
 
void GeneralEncapsulatedObjectFrame::setDescription(const String &desc)
112
 
{
113
 
  d->description = desc;
114
 
}
115
 
 
116
 
ByteVector GeneralEncapsulatedObjectFrame::object() const
117
 
{
118
 
  return d->data;
119
 
}
120
 
 
121
 
void GeneralEncapsulatedObjectFrame::setObject(const ByteVector &data)
122
 
{
123
 
  d->data = data;
124
 
}
125
 
 
126
 
////////////////////////////////////////////////////////////////////////////////
127
 
// protected members
128
 
////////////////////////////////////////////////////////////////////////////////
129
 
 
130
 
void GeneralEncapsulatedObjectFrame::parseFields(const ByteVector &data)
131
 
{
132
 
  if(data.size() < 4) {
133
 
    debug("An object frame must contain at least 4 bytes.");
134
 
    return;
135
 
  }
136
 
 
137
 
  int fieldStart = 0;
138
 
 
139
 
  d->textEncoding = String::Type(data[fieldStart]);
140
 
  fieldStart += 1;
141
 
 
142
 
  int fieldEnd = data.find(textDelimiter(String::Latin1), fieldStart);
143
 
 
144
 
  if(fieldEnd < fieldStart)
145
 
    return;
146
 
 
147
 
  d->mimeType = String(data.mid(fieldStart, fieldEnd - fieldStart), String::Latin1);
148
 
  fieldStart = fieldEnd + 1;
149
 
 
150
 
  if (d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8) {
151
 
    fieldEnd = data.find(textDelimiter(d->textEncoding), fieldStart);
152
 
 
153
 
    if(fieldEnd < fieldStart)
154
 
      return;
155
 
 
156
 
    d->fileName = String(data.mid(fieldStart, fieldEnd - fieldStart), d->textEncoding);
157
 
    fieldStart = fieldEnd + 1;
158
 
 
159
 
    fieldEnd = data.find(textDelimiter(d->textEncoding), fieldStart);
160
 
 
161
 
    if(fieldEnd < fieldStart)
162
 
      return;
163
 
 
164
 
    d->description = String(data.mid(fieldStart, fieldEnd - fieldStart), d->textEncoding);
165
 
    fieldStart = fieldEnd + 1;
166
 
  } else {
167
 
    // use byteAlign = 2 to find $00 00 text delimiter
168
 
    // find in subvector so that it works too when pos is odd
169
 
    int len = data.mid(fieldStart).find(textDelimiter(d->textEncoding), 0, 2);
170
 
 
171
 
    if (len < 0)
172
 
      return;
173
 
 
174
 
    d->fileName = String(data.mid(fieldStart, len), d->textEncoding);
175
 
    fieldStart += len + 2;
176
 
 
177
 
    len = data.mid(fieldStart).find(textDelimiter(d->textEncoding), 0, 2);
178
 
 
179
 
    if (len < 0)
180
 
      return;
181
 
 
182
 
    d->description = String(data.mid(fieldStart, len), d->textEncoding);
183
 
    fieldStart += len + 2;
184
 
  }
185
 
 
186
 
  d->data = data.mid(fieldStart);
187
 
}
188
 
 
189
 
ByteVector GeneralEncapsulatedObjectFrame::renderFields() const
190
 
{
191
 
  ByteVector data;
192
 
 
193
 
  data.append(char(d->textEncoding));
194
 
  data.append(d->mimeType.data(String::Latin1));
195
 
  data.append(textDelimiter(String::Latin1));
196
 
  data.append(d->fileName.data(d->textEncoding));
197
 
  data.append(textDelimiter(d->textEncoding));
198
 
  data.append(d->description.data(d->textEncoding));
199
 
  data.append(textDelimiter(d->textEncoding));
200
 
  data.append(d->data);
201
 
 
202
 
  return data;
203
 
}
204
 
 
205
 
////////////////////////////////////////////////////////////////////////////////
206
 
// private members
207
 
////////////////////////////////////////////////////////////////////////////////
208
 
 
209
 
GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFrame(const ByteVector &data, Header *h) : Frame(h)
210
 
{
211
 
  d = new GeneralEncapsulatedObjectFramePrivate;
212
 
  parseFields(fieldData(data));
213
 
}