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