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

« back to all changes in this revision

Viewing changes to kid3/taglibext/urllinkframe.cpp

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez, Patrick Matthäi, Ana Beatriz Guerrero Lopez
  • Date: 2011-11-13 16:34:13 UTC
  • mfrom: (1.1.13) (2.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111113163413-5y0anlc4dqf511uh
Tags: 2.0.1-1
* New upstream release.

[ Patrick Matthäi ]
* Adjust build system.
* Add build dependency xsltproc.

[ Ana Beatriz Guerrero Lopez ]
* Some more adjustments to the build system taken from upstream's deb/
* directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    copyright            : (C) 2002, 2003 by Scott Wheeler
3
 
    email                : wheeler@kde.org
4
 
    copyright            : (C) 2006 by Urs Fleisch
5
 
    email                : ufleisch@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 "urllinkframe.h"
25
 
#include <tdebug.h>
26
 
 
27
 
using namespace TagLib;
28
 
using namespace ID3v2;
29
 
 
30
 
class UrlLinkFrame::UrlLinkFramePrivate {
31
 
public:
32
 
  String url;
33
 
};
34
 
 
35
 
class UserUrlLinkFrame::UserUrlLinkFramePrivate {
36
 
public:
37
 
  UserUrlLinkFramePrivate() : textEncoding(String::Latin1) {}
38
 
  String::Type textEncoding;
39
 
  String description;
40
 
};
41
 
 
42
 
UrlLinkFrame::UrlLinkFrame(const ByteVector &data) :
43
 
  Frame(data)
44
 
{
45
 
  d = new UrlLinkFramePrivate;
46
 
  setData(data);
47
 
}
48
 
 
49
 
UrlLinkFrame::~UrlLinkFrame()
50
 
{
51
 
  delete d;
52
 
}
53
 
 
54
 
void UrlLinkFrame::setUrl(const String &s)
55
 
{
56
 
  d->url = s;
57
 
}
58
 
 
59
 
String UrlLinkFrame::url() const
60
 
{
61
 
  return d->url;
62
 
}
63
 
 
64
 
void UrlLinkFrame::setText(const String &s)
65
 
{
66
 
  setUrl(s);
67
 
}
68
 
 
69
 
String UrlLinkFrame::toString() const
70
 
{
71
 
  return url();
72
 
}
73
 
 
74
 
void UrlLinkFrame::parseFields(const ByteVector &data)
75
 
{
76
 
  d->url = String(data);
77
 
}
78
 
 
79
 
ByteVector UrlLinkFrame::renderFields() const
80
 
{
81
 
  return d->url.data(String::Latin1);
82
 
}
83
 
 
84
 
UrlLinkFrame::UrlLinkFrame(const ByteVector &data, Header *h) : Frame(h)
85
 
{
86
 
  d = new UrlLinkFramePrivate;
87
 
  parseFields(fieldData(data));
88
 
}
89
 
 
90
 
 
91
 
UserUrlLinkFrame::UserUrlLinkFrame(String::Type encoding) :
92
 
  UrlLinkFrame("WXXX")
93
 
{
94
 
  d = new UserUrlLinkFramePrivate;
95
 
  d->textEncoding = encoding;
96
 
}
97
 
 
98
 
UserUrlLinkFrame::UserUrlLinkFrame(const ByteVector &data) :
99
 
  UrlLinkFrame(data)
100
 
{
101
 
  d = new UserUrlLinkFramePrivate;
102
 
  setData(data);
103
 
}
104
 
 
105
 
UserUrlLinkFrame::~UserUrlLinkFrame()
106
 
{
107
 
  delete d;
108
 
}
109
 
 
110
 
String UserUrlLinkFrame::toString() const
111
 
{
112
 
  return "[" + description() + "] " + url();
113
 
}
114
 
 
115
 
String::Type UserUrlLinkFrame::textEncoding() const
116
 
{
117
 
  return d->textEncoding;
118
 
}
119
 
 
120
 
void UserUrlLinkFrame::setTextEncoding(String::Type encoding)
121
 
{
122
 
  d->textEncoding = encoding;
123
 
}
124
 
 
125
 
String UserUrlLinkFrame::description() const
126
 
{
127
 
  return d->description;
128
 
}
129
 
 
130
 
void UserUrlLinkFrame::setDescription(const String &s)
131
 
{
132
 
  d->description = s;
133
 
}
134
 
 
135
 
void UserUrlLinkFrame::parseFields(const ByteVector &data)
136
 
{
137
 
  if (data.size() < 2) {
138
 
    debug("A user URL link frame must contain at least 2 bytes.");
139
 
    return;
140
 
  }
141
 
 
142
 
  int pos = 0;
143
 
 
144
 
  d->textEncoding = String::Type(data[0]);
145
 
  pos += 1;
146
 
 
147
 
  if (d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8) {
148
 
    int offset = data.find(textDelimiter(d->textEncoding), pos);
149
 
    if (offset < pos)
150
 
      return;
151
 
 
152
 
    d->description = String(data.mid(pos, offset - pos), d->textEncoding);
153
 
    pos = offset + 1;
154
 
  } else {
155
 
    int len = data.mid(pos).find(textDelimiter(d->textEncoding), 0, 2);
156
 
    if (len < 0)
157
 
      return;
158
 
 
159
 
    d->description = String(data.mid(pos, len), d->textEncoding);
160
 
    pos += len + 2;
161
 
  }
162
 
 
163
 
  setUrl(String(data.mid(pos)));
164
 
}
165
 
 
166
 
ByteVector UserUrlLinkFrame::renderFields() const
167
 
{
168
 
  ByteVector v;
169
 
 
170
 
  v.append(char(d->textEncoding));
171
 
  v.append(d->description.data(d->textEncoding));
172
 
  v.append(textDelimiter(d->textEncoding));
173
 
  v.append(url().data(String::Latin1));
174
 
 
175
 
  return v;
176
 
}
177
 
 
178
 
UserUrlLinkFrame::UserUrlLinkFrame(const ByteVector &data, Header *h) : UrlLinkFrame(data, h)
179
 
{
180
 
  d = new UserUrlLinkFramePrivate;
181
 
  parseFields(fieldData(data));
182
 
}