strawberry-audio-player-win.../3rdparty/taglib/tag.cpp

182 lines
5.4 KiB
C++
Raw Normal View History

2018-05-10 15:29:28 +02:00
/***************************************************************************
copyright : (C) 2002 - 2008 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include "tag.h"
#include "tstringlist.h"
#include "tpropertymap.h"
using namespace Strawberry_TagLib::TagLib;
2018-05-10 15:29:28 +02:00
class Tag::TagPrivate
{
};
2019-04-08 18:46:11 +02:00
Tag::Tag() :
d(nullptr)
2018-05-10 15:29:28 +02:00
{
}
Tag::~Tag()
{
}
bool Tag::isEmpty() const
{
return (title().isEmpty() &&
artist().isEmpty() &&
album().isEmpty() &&
comment().isEmpty() &&
genre().isEmpty() &&
year() == 0 &&
track() == 0);
}
PropertyMap Tag::properties() const
{
PropertyMap map;
2019-04-08 18:46:11 +02:00
if (!(title().isEmpty()))
2018-05-10 15:29:28 +02:00
map["TITLE"].append(title());
2019-04-08 18:46:11 +02:00
if (!(artist().isEmpty()))
2018-05-10 15:29:28 +02:00
map["ARTIST"].append(artist());
2019-04-08 18:46:11 +02:00
if (!(album().isEmpty()))
2018-05-10 15:29:28 +02:00
map["ALBUM"].append(album());
2019-04-08 18:46:11 +02:00
if (!(comment().isEmpty()))
2018-05-10 15:29:28 +02:00
map["COMMENT"].append(comment());
2019-04-08 18:46:11 +02:00
if (!(genre().isEmpty()))
2018-05-10 15:29:28 +02:00
map["GENRE"].append(genre());
2019-04-08 18:46:11 +02:00
if (!(year() == 0))
2018-05-10 15:29:28 +02:00
map["DATE"].append(String::number(year()));
2019-04-08 18:46:11 +02:00
if (!(track() == 0))
2018-05-10 15:29:28 +02:00
map["TRACKNUMBER"].append(String::number(track()));
return map;
}
void Tag::removeUnsupportedProperties(const StringList&)
{
}
PropertyMap Tag::setProperties(const PropertyMap &origProps)
{
PropertyMap properties(origProps);
properties.removeEmpty();
StringList oneValueSet;
// can this be simplified by using some preprocessor defines / function pointers?
2019-04-08 18:46:11 +02:00
if (properties.contains("TITLE")) {
2018-05-10 15:29:28 +02:00
setTitle(properties["TITLE"].front());
oneValueSet.append("TITLE");
} else
setTitle(String());
2019-04-08 18:46:11 +02:00
if (properties.contains("ARTIST")) {
2018-05-10 15:29:28 +02:00
setArtist(properties["ARTIST"].front());
oneValueSet.append("ARTIST");
} else
setArtist(String());
2019-04-08 18:46:11 +02:00
if (properties.contains("ALBUM")) {
2018-05-10 15:29:28 +02:00
setAlbum(properties["ALBUM"].front());
oneValueSet.append("ALBUM");
} else
setAlbum(String());
2019-04-08 18:46:11 +02:00
if (properties.contains("COMMENT")) {
2018-05-10 15:29:28 +02:00
setComment(properties["COMMENT"].front());
oneValueSet.append("COMMENT");
} else
setComment(String());
2019-04-08 18:46:11 +02:00
if (properties.contains("GENRE")) {
2018-05-10 15:29:28 +02:00
setGenre(properties["GENRE"].front());
oneValueSet.append("GENRE");
} else
setGenre(String());
2019-04-08 18:46:11 +02:00
if (properties.contains("DATE")) {
2018-05-10 15:29:28 +02:00
bool ok;
int date = properties["DATE"].front().toInt(&ok);
2019-04-08 18:46:11 +02:00
if (ok) {
2018-05-10 15:29:28 +02:00
setYear(date);
oneValueSet.append("DATE");
} else
setYear(0);
}
else
setYear(0);
2019-04-08 18:46:11 +02:00
if (properties.contains("TRACKNUMBER")) {
2018-05-10 15:29:28 +02:00
bool ok;
int track = properties["TRACKNUMBER"].front().toInt(&ok);
2019-04-08 18:46:11 +02:00
if (ok) {
2018-05-10 15:29:28 +02:00
setTrack(track);
oneValueSet.append("TRACKNUMBER");
} else
setTrack(0);
}
else
setTrack(0);
// for each tag that has been set above, remove the first entry in the corresponding
// value list. The others will be returned as unsupported by this format.
for(StringList::ConstIterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) {
2019-04-08 18:46:11 +02:00
if (properties[*it].size() == 1)
2018-05-10 15:29:28 +02:00
properties.erase(*it);
else
properties[*it].erase( properties[*it].begin() );
}
return properties;
}
void Tag::duplicate(const Tag *source, Tag *target, bool overwrite) // static
{
2019-04-08 18:46:11 +02:00
if (overwrite) {
2018-05-10 15:29:28 +02:00
target->setTitle(source->title());
target->setArtist(source->artist());
target->setAlbum(source->album());
target->setComment(source->comment());
target->setGenre(source->genre());
target->setYear(source->year());
target->setTrack(source->track());
}
else {
2019-04-08 18:46:11 +02:00
if (target->title().isEmpty())
2018-05-10 15:29:28 +02:00
target->setTitle(source->title());
2019-04-08 18:46:11 +02:00
if (target->artist().isEmpty())
2018-05-10 15:29:28 +02:00
target->setArtist(source->artist());
2019-04-08 18:46:11 +02:00
if (target->album().isEmpty())
2018-05-10 15:29:28 +02:00
target->setAlbum(source->album());
2019-04-08 18:46:11 +02:00
if (target->comment().isEmpty())
2018-05-10 15:29:28 +02:00
target->setComment(source->comment());
2019-04-08 18:46:11 +02:00
if (target->genre().isEmpty())
2018-05-10 15:29:28 +02:00
target->setGenre(source->genre());
2019-04-08 18:46:11 +02:00
if (target->year() == 0)
2018-05-10 15:29:28 +02:00
target->setYear(source->year());
2019-04-08 18:46:11 +02:00
if (target->track() == 0)
2018-05-10 15:29:28 +02:00
target->setTrack(source->track());
}
}