Added TagLib (with AUTORS and COPYING files)
[someplayer] / src / taglib / asf / asftag.cpp
1 /**************************************************************************
2     copyright            : (C) 2005-2007 by Lukáš Lalinský
3     email                : lalinsky@gmail.com
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 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29
30 #ifdef WITH_ASF
31
32 #include "asftag.h"
33
34 using namespace TagLib;
35
36 class ASF::Tag::TagPrivate
37 {
38 public:
39   String title;
40   String artist;
41   String copyright;
42   String comment;
43   String rating;
44   AttributeListMap attributeListMap;
45 };
46
47 ASF::Tag::Tag()
48 : TagLib::Tag()
49 {
50   d = new TagPrivate;
51 }
52
53 ASF::Tag::~Tag()
54 {
55   if(d)
56     delete d;
57 }
58
59 String
60 ASF::Tag::title() const
61 {
62   return d->title;
63 }
64
65 String
66 ASF::Tag::artist() const
67 {
68   return d->artist;
69 }
70
71 String
72 ASF::Tag::album() const
73 {
74   if(d->attributeListMap.contains("WM/AlbumTitle"))
75     return d->attributeListMap["WM/AlbumTitle"][0].toString();
76   return String::null;
77 }
78
79 String
80 ASF::Tag::copyright() const
81 {
82   return d->copyright;
83 }
84
85 String
86 ASF::Tag::comment() const
87 {
88   return d->comment;
89 }
90
91 String
92 ASF::Tag::rating() const
93 {
94   return d->rating;
95 }
96
97 unsigned int
98 ASF::Tag::year() const
99 {
100   if(d->attributeListMap.contains("WM/Year"))
101     return d->attributeListMap["WM/Year"][0].toString().toInt();
102   return 0;
103 }
104
105 unsigned int
106 ASF::Tag::track() const
107 {
108   if(d->attributeListMap.contains("WM/TrackNumber")) {
109     const ASF::Attribute attr = d->attributeListMap["WM/TrackNumber"][0];
110     if(attr.type() == ASF::Attribute::DWordType)
111       return attr.toUInt();
112     else
113       return attr.toString().toInt();
114   }
115   if(d->attributeListMap.contains("WM/Track"))
116     return d->attributeListMap["WM/Track"][0].toUInt();
117   return 0;
118 }
119
120 String
121 ASF::Tag::genre() const
122 {
123   if(d->attributeListMap.contains("WM/Genre"))
124     return d->attributeListMap["WM/Genre"][0].toString();
125   return String::null;
126 }
127
128 void
129 ASF::Tag::setTitle(const String &value)
130 {
131   d->title = value;
132 }
133
134 void
135 ASF::Tag::setArtist(const String &value)
136 {
137   d->artist = value;
138 }
139
140 void
141 ASF::Tag::setCopyright(const String &value)
142 {
143   d->copyright = value;
144 }
145
146 void
147 ASF::Tag::setComment(const String &value)
148 {
149   d->comment = value;
150 }
151
152 void
153 ASF::Tag::setRating(const String &value)
154 {
155   d->rating = value;
156 }
157
158 void
159 ASF::Tag::setAlbum(const String &value)
160 {
161   setAttribute("WM/AlbumTitle", value);
162 }
163
164 void
165 ASF::Tag::setGenre(const String &value)
166 {
167   setAttribute("WM/Genre", value);
168 }
169
170 void
171 ASF::Tag::setYear(uint value)
172 {
173   setAttribute("WM/Year", String::number(value));
174 }
175
176 void
177 ASF::Tag::setTrack(uint value)
178 {
179   setAttribute("WM/TrackNumber", String::number(value));
180 }
181
182 ASF::AttributeListMap&
183 ASF::Tag::attributeListMap()
184 {
185   return d->attributeListMap;
186 }
187
188 void ASF::Tag::removeItem(const String &key)
189 {
190   AttributeListMap::Iterator it = d->attributeListMap.find(key);
191   if(it != d->attributeListMap.end())
192     d->attributeListMap.erase(it);
193 }
194
195 void ASF::Tag::setAttribute(const String &name, const Attribute &attribute)
196 {
197   AttributeList value;
198   value.append(attribute);
199   d->attributeListMap.insert(name, value);
200 }
201
202 void ASF::Tag::addAttribute(const String &name, const Attribute &attribute)
203 {
204   if(d->attributeListMap.contains(name)) {
205     d->attributeListMap[name].append(attribute);
206   }
207   else {
208     setAttribute(name, attribute);
209   }
210 }
211
212 bool ASF::Tag::isEmpty() const {
213   return TagLib::Tag::isEmpty() &&
214          copyright().isEmpty() &&
215          rating().isEmpty() &&
216          d->attributeListMap.isEmpty();
217 }
218
219 #endif