00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <wmatag.h>
00023
00024 using namespace TagLib;
00025
00026 class WMA::Tag::TagPrivate
00027 {
00028 public:
00029 String title;
00030 String artist;
00031 String copyright;
00032 String comment;
00033 String rating;
00034 AttributeMap attributeMap;
00035 };
00036
00037 WMA::Tag::Tag()
00038 : TagLib::Tag()
00039 {
00040 d = new TagPrivate;
00041 }
00042
00043 WMA::Tag::~Tag()
00044 {
00045 if(d)
00046 delete d;
00047 }
00048
00049 String
00050 WMA::Tag::title() const
00051 {
00052 return d->title;
00053 }
00054
00055 String
00056 WMA::Tag::artist() const
00057 {
00058 return d->artist;
00059 }
00060
00061 String
00062 WMA::Tag::album() const
00063 {
00064 if(d->attributeMap.contains("WM/AlbumTitle"))
00065 return d->attributeMap["WM/AlbumTitle"].toString();
00066 return String::null;
00067 }
00068
00069 String
00070 WMA::Tag::copyright() const
00071 {
00072 return d->copyright;
00073 }
00074
00075 String
00076 WMA::Tag::comment() const
00077 {
00078 return d->comment;
00079 }
00080
00081 String
00082 WMA::Tag::rating() const
00083 {
00084 return d->rating;
00085 }
00086
00087 unsigned int
00088 WMA::Tag::year() const
00089 {
00090 if(d->attributeMap.contains("WM/Year"))
00091 return d->attributeMap["WM/Year"].toInt();
00092 return 0;
00093 }
00094
00095 unsigned int
00096 WMA::Tag::track() const
00097 {
00098 if(d->attributeMap.contains("WM/TrackNumber"))
00099 return d->attributeMap["WM/TrackNumber"].toInt();
00100 if(d->attributeMap.contains("WM/Track"))
00101 return d->attributeMap["WM/Track"].toInt();
00102 return 0;
00103 }
00104
00105 String
00106 WMA::Tag::genre() const
00107 {
00108 if(d->attributeMap.contains("WM/Genre"))
00109 return d->attributeMap["WM/Genre"].toString();
00110 return String::null;
00111 }
00112
00113 void
00114 WMA::Tag::setTitle(const String &value)
00115 {
00116 d->title = value;
00117 }
00118
00119 void
00120 WMA::Tag::setArtist(const String &value)
00121 {
00122 d->artist = value;
00123 }
00124
00125 void
00126 WMA::Tag::setCopyright(const String &value)
00127 {
00128 d->copyright = value;
00129 }
00130
00131 void
00132 WMA::Tag::setComment(const String &value)
00133 {
00134 d->comment = value;
00135 }
00136
00137 void
00138 WMA::Tag::setRating(const String &value)
00139 {
00140 d->rating = value;
00141 }
00142
00143 void
00144 WMA::Tag::setAlbum(const String &value)
00145 {
00146 setAttribute("WM/AlbumTitle", value);
00147 }
00148
00149 void
00150 WMA::Tag::setGenre(const String &value)
00151 {
00152 setAttribute("WM/Genre", value);
00153 }
00154
00155 void
00156 WMA::Tag::setYear(uint value)
00157 {
00158 setAttribute("WM/Year", String::number(value));
00159 }
00160
00161 void
00162 WMA::Tag::setTrack(uint value)
00163 {
00164 setAttribute("WM/TrackNumber", String::number(value));
00165 }
00166
00167 const WMA::AttributeMap& WMA::Tag::attributeMap() const
00168 {
00169 return d->attributeMap;
00170 }
00171
00172 void WMA::Tag::removeItem(const ByteVector &key)
00173 {
00174 AttributeMap::Iterator it = d->attributeMap.find(key);
00175 if(it != d->attributeMap.end())
00176 d->attributeMap.erase(it);
00177 }
00178
00179 void WMA::Tag::setAttribute(const ByteVector &key, const String &value)
00180 {
00181 setAttribute(key, WMA::Attribute(key, value));
00182 }
00183
00184 void WMA::Tag::setAttribute(const ByteVector &key, const Attribute &attribute)
00185 {
00186 removeItem(key);
00187 d->attributeMap.insert(key, attribute);
00188 }
00189
00190 bool WMA::Tag::isEmpty() const {
00191 return TagLib::Tag::isEmpty() &&
00192 copyright().isEmpty() &&
00193 rating().isEmpty() &&
00194 d->attributeMap.isEmpty();
00195 }
00196
00197 void WMA::Tag::duplicate(const Tag *source, Tag *target, bool overwrite) {
00198 TagLib::Tag::duplicate(source, target, overwrite);
00199 if(overwrite) {
00200 target->setCopyright(source->copyright());
00201 target->setRating(source->rating());
00202 }
00203 else {
00204 if (target->copyright().isEmpty())
00205 target->setCopyright(source->copyright());
00206 if (target->rating().isEmpty())
00207 target->setRating(source->rating());
00208 }
00209 }
00210