1 /***************************************************************************
2     copyright           : (C) 2011 by Mathias Panzenböck
3     email               : grosser.meister.morti@gmx.net
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., 51 Franklin Street, Fifth Floor, Boston, MA         *
19  *   02110-1301  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 
27 #include "modtag.h"
28 #include "tstringlist.h"
29 #include "tpropertymap.h"
30 
31 using namespace TagLib;
32 using namespace Mod;
33 
34 class Mod::Tag::TagPrivate
35 {
36 public:
TagPrivate()37   TagPrivate()
38   {
39   }
40 
41   String title;
42   String comment;
43   String trackerName;
44 };
45 
Tag()46 Mod::Tag::Tag() :
47   TagLib::Tag(),
48   d(new TagPrivate())
49 {
50 }
51 
~Tag()52 Mod::Tag::~Tag()
53 {
54   delete d;
55 }
56 
title() const57 String Mod::Tag::title() const
58 {
59   return d->title;
60 }
61 
artist() const62 String Mod::Tag::artist() const
63 {
64   return String();
65 }
66 
album() const67 String Mod::Tag::album() const
68 {
69   return String();
70 }
71 
comment() const72 String Mod::Tag::comment() const
73 {
74   return d->comment;
75 }
76 
genre() const77 String Mod::Tag::genre() const
78 {
79   return String();
80 }
81 
year() const82 unsigned int Mod::Tag::year() const
83 {
84   return 0;
85 }
86 
track() const87 unsigned int Mod::Tag::track() const
88 {
89   return 0;
90 }
91 
trackerName() const92 String Mod::Tag::trackerName() const
93 {
94   return d->trackerName;
95 }
96 
setTitle(const String & title)97 void Mod::Tag::setTitle(const String &title)
98 {
99   d->title = title;
100 }
101 
setArtist(const String &)102 void Mod::Tag::setArtist(const String &)
103 {
104 }
105 
setAlbum(const String &)106 void Mod::Tag::setAlbum(const String &)
107 {
108 }
109 
setComment(const String & comment)110 void Mod::Tag::setComment(const String &comment)
111 {
112   d->comment = comment;
113 }
114 
setGenre(const String &)115 void Mod::Tag::setGenre(const String &)
116 {
117 }
118 
setYear(unsigned int)119 void Mod::Tag::setYear(unsigned int)
120 {
121 }
122 
setTrack(unsigned int)123 void Mod::Tag::setTrack(unsigned int)
124 {
125 }
126 
setTrackerName(const String & trackerName)127 void Mod::Tag::setTrackerName(const String &trackerName)
128 {
129   d->trackerName = trackerName;
130 }
131 
properties() const132 PropertyMap Mod::Tag::properties() const
133 {
134   PropertyMap properties;
135   properties["TITLE"] = d->title;
136   properties["COMMENT"] = d->comment;
137   if(!(d->trackerName.isEmpty()))
138     properties["TRACKERNAME"] = d->trackerName;
139   return properties;
140 }
141 
setProperties(const PropertyMap & origProps)142 PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps)
143 {
144   PropertyMap properties(origProps);
145   properties.removeEmpty();
146   StringList oneValueSet;
147   if(properties.contains("TITLE")) {
148     d->title = properties["TITLE"].front();
149     oneValueSet.append("TITLE");
150   } else
151     d->title.clear();
152 
153   if(properties.contains("COMMENT")) {
154     d->comment = properties["COMMENT"].front();
155     oneValueSet.append("COMMENT");
156   } else
157     d->comment.clear();
158 
159   if(properties.contains("TRACKERNAME")) {
160     d->trackerName = properties["TRACKERNAME"].front();
161     oneValueSet.append("TRACKERNAME");
162   } else
163     d->trackerName.clear();
164 
165   // for each tag that has been set above, remove the first entry in the corresponding
166   // value list. The others will be returned as unsupported by this format.
167   for(StringList::ConstIterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) {
168     if(properties[*it].size() == 1)
169       properties.erase(*it);
170     else
171       properties[*it].erase( properties[*it].begin() );
172   }
173   return properties;
174 }
175