[UI] Refactored some code and integrated CSS changes made by G.Debros

This commit is contained in:
emeric
2015-11-21 22:11:16 +01:00
parent 3826377f01
commit fc88cce33e
20 changed files with 369 additions and 176 deletions
+8 -10
View File
@@ -19,15 +19,12 @@
#include "AvFormat.hpp"
#include <boost/foreach.hpp>
#include "logger/Logger.hpp"
#include "utils/Utils.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "av/AvInfo.hpp"
#include "logger/Logger.hpp"
#include "Utils.hpp"
namespace MetaData
{
@@ -112,11 +109,11 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
for (it = metadata.begin(); it != metadata.end(); ++it)
{
if (boost::iequals(it->first, "artist"))
items.insert( std::make_pair(MetaData::Type::Artist, string_trim( string_to_utf8(it->second)) ));
items.insert( std::make_pair(MetaData::Type::Artist, stringTrim( stringToUTF8(it->second)) ));
else if (boost::iequals(it->first, "album"))
items.insert( std::make_pair(MetaData::Type::Album, string_trim( string_to_utf8(it->second)) ));
items.insert( std::make_pair(MetaData::Type::Album, stringTrim( stringToUTF8(it->second)) ));
else if (boost::iequals(it->first, "title"))
items.insert( std::make_pair(MetaData::Type::Title, string_trim( string_to_utf8(it->second)) ));
items.insert( std::make_pair(MetaData::Type::Title, stringTrim( stringToUTF8(it->second)) ));
else if (boost::iequals(it->first, "track")) {
std::size_t number;
if (readAs<std::size_t>(it->second, number))
@@ -145,6 +142,7 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
}
else if (boost::iequals(it->first, "genre"))
{
// TODO use splitStrings
std::list<std::string> genres;
if (readList(it->second, ";,", genres))
items.insert( std::make_pair(MetaData::Type::Genres, genres));
@@ -153,12 +151,12 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
else if (boost::iequals(it->first, "MusicBrainz Artist Id")
|| boost::iequals(it->first, "MUSICBRAINZ_ARTISTID"))
{
items.insert( std::make_pair(MetaData::Type::MusicBrainzArtistID, string_trim( string_to_utf8(it->second)) ));
items.insert( std::make_pair(MetaData::Type::MusicBrainzArtistID, stringTrim( stringToUTF8(it->second)) ));
}
else if (boost::iequals(it->first, "MusicBrainz Album Id")
|| boost::iequals(it->first, "MUSICBRAINZ_ALBUMID"))
{
items.insert( std::make_pair(MetaData::Type::MusicBrainzAlbumID, string_trim( string_to_utf8(it->second)) ));
items.insert( std::make_pair(MetaData::Type::MusicBrainzAlbumID, stringTrim( stringToUTF8(it->second)) ));
}
}
+1 -1
View File
@@ -25,7 +25,7 @@
namespace MetaData
{
// Implements AVFORMAT library
// Parse that makes use of AvFormat
class AvFormat : public Parser
{
public:
-83
View File
@@ -1,83 +0,0 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <sstream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/foreach.hpp>
#include "Utils.hpp"
namespace MetaData
{
bool readAsPosixTime(const std::string& str, boost::posix_time::ptime& time)
{
const std::locale formats[] = {
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%m-%d")),
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%b-%d")),
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%B-%d")),
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y/%m/%d")),
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%d.%m.%Y")),
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%m")),
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y/%m")),
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y.%m")),
std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y")),
};
for(size_t i=0; i < sizeof(formats)/sizeof(formats[0]); ++i)
{
std::istringstream iss(str);
iss.imbue(formats[i]);
if (iss >> time)
return true;
}
return false;
}
bool readList(const std::string& str, const std::string& separators, std::list<std::string>& results)
{
std::string curStr;
BOOST_FOREACH(char c, str) {
if (separators.find(c) != std::string::npos) {
if (!curStr.empty()) {
results.push_back(string_to_utf8(curStr));
curStr.clear();
}
}
else {
if (curStr.empty() && std::isspace(c))
continue;
curStr.push_back(c);
}
}
if (!curStr.empty())
results.push_back(string_to_utf8(curStr));
return !str.empty();
}
}
-69
View File
@@ -1,69 +0,0 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef METADATA_UTILS_HPP
#define METADATA_UTILS_HPP
#include <string>
#include <list>
#include <boost/locale.hpp>
namespace MetaData
{
bool readAsPosixTime(const std::string& str, boost::posix_time::ptime& time);
bool readList(const std::string& str, const std::string& separators, std::list<std::string>& results);
template<typename T>
static inline bool readAs(const std::string& str, T& data)
{
std::istringstream iss ( str );
iss >> data;
return !iss.fail();
}
std::string
static inline string_trim(const std::string& str,
const std::string& whitespace = " \t")
{
const auto strBegin = str.find_first_not_of(whitespace);
if (strBegin == std::string::npos)
return ""; // no content
const auto strEnd = str.find_last_not_of(whitespace);
const auto strRange = strEnd - strBegin + 1;
return str.substr(strBegin, strRange);
}
std::string
static inline string_to_utf8(const std::string& str)
{
return boost::locale::conv::to_utf<char>(str, "UTF-8");
}
} // namespace MetaData
#endif