[UI] Refactored some code and integrated CSS changes made by G.Debros
This commit is contained in:
@@ -444,4 +444,80 @@
|
|||||||
</div>
|
</div>
|
||||||
</message>
|
</message>
|
||||||
|
|
||||||
|
<message id="wa-release-wrapper">
|
||||||
|
<div class="section text-center">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
${contents}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</message>
|
||||||
|
|
||||||
|
<message id="wa-release-res">
|
||||||
|
<div class="col-xs-6 col-md-2">
|
||||||
|
<br/>${cover}
|
||||||
|
<h4 class="release_truncated-name" title="${release_name}">${name}<div style="font-size: 75%"><br/>${artist}<br/></div></h4>
|
||||||
|
</div>
|
||||||
|
</message>
|
||||||
|
|
||||||
|
<message id="wa-artist-wrapper">
|
||||||
|
<div class="section text-center">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
${contents}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</message>
|
||||||
|
|
||||||
|
<message id="wa-artist-res">
|
||||||
|
<div class="col-xs-6 col-md-2">
|
||||||
|
<br/>${gif}
|
||||||
|
<h4 class="release_truncated-name" title="${artistname}">${name}<div style="font-size: 75%"></div></h4>
|
||||||
|
</div>
|
||||||
|
</message>
|
||||||
|
|
||||||
|
<!-- Track container
|
||||||
|
|
||||||
|
Track bar title
|
||||||
|
|
||||||
|
Release1
|
||||||
|
Track1
|
||||||
|
Track2
|
||||||
|
...
|
||||||
|
|
||||||
|
Release2
|
||||||
|
...
|
||||||
|
|
||||||
|
...
|
||||||
|
-->
|
||||||
|
<message id="wa-trackview-wrapper">
|
||||||
|
${title}
|
||||||
|
${release-container}
|
||||||
|
${show-more}
|
||||||
|
</message>
|
||||||
|
|
||||||
|
<message id="wa-trackview-release-container">
|
||||||
|
<div class="container">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
${cover}
|
||||||
|
<br />
|
||||||
|
<h4>${release-name} <br/>${artist-name} - ${year}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="menu row col-md-9">
|
||||||
|
<br/>
|
||||||
|
<div class="menu-category list-group ">
|
||||||
|
${track-container}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</message>
|
||||||
|
|
||||||
|
<message id="wa-trackview-track">
|
||||||
|
<div class="menu-item list-group-item ">${track-pos}. ${track-name} <span class="badge">${btn}</span><span class="badge">${time}</span></div>
|
||||||
|
</message>
|
||||||
|
|
||||||
</messages>
|
</messages>
|
||||||
|
|||||||
@@ -117,3 +117,20 @@ div.contents {
|
|||||||
height: 48px;
|
height: 48px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.release_res_shadow {
|
||||||
|
box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
.release_truncated-name {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.release_img-responsive {
|
||||||
|
display: block;
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|||||||
+2
-2
@@ -20,7 +20,6 @@ lms_SOURCES = \
|
|||||||
$(srcdir)/image/Image.cpp \
|
$(srcdir)/image/Image.cpp \
|
||||||
$(srcdir)/logger/Logger.cpp \
|
$(srcdir)/logger/Logger.cpp \
|
||||||
$(srcdir)/metadata/AvFormat.cpp \
|
$(srcdir)/metadata/AvFormat.cpp \
|
||||||
$(srcdir)/metadata/Utils.cpp \
|
|
||||||
$(srcdir)/service/ServiceManager.cpp \
|
$(srcdir)/service/ServiceManager.cpp \
|
||||||
$(srcdir)/service/DatabaseUpdateService.cpp \
|
$(srcdir)/service/DatabaseUpdateService.cpp \
|
||||||
$(srcdir)/ui/LmsApplication.cpp \
|
$(srcdir)/ui/LmsApplication.cpp \
|
||||||
@@ -49,7 +48,8 @@ lms_SOURCES = \
|
|||||||
$(srcdir)/ui/settings/SettingsMediaDirectories.cpp \
|
$(srcdir)/ui/settings/SettingsMediaDirectories.cpp \
|
||||||
$(srcdir)/ui/settings/SettingsMediaDirectoryFormView.cpp \
|
$(srcdir)/ui/settings/SettingsMediaDirectoryFormView.cpp \
|
||||||
$(srcdir)/ui/settings/SettingsUserFormView.cpp \
|
$(srcdir)/ui/settings/SettingsUserFormView.cpp \
|
||||||
$(srcdir)/ui/settings/SettingsUsers.cpp
|
$(srcdir)/ui/settings/SettingsUsers.cpp \
|
||||||
|
$(srcdir)/utils/Utils.cpp
|
||||||
|
|
||||||
if VIDEO
|
if VIDEO
|
||||||
lms_SOURCES += \
|
lms_SOURCES += \
|
||||||
|
|||||||
@@ -170,23 +170,25 @@ Grabber::getFromRelease(Wt::Dbo::Session& session, Database::Release::id_type re
|
|||||||
{
|
{
|
||||||
using namespace Database;
|
using namespace Database;
|
||||||
|
|
||||||
boost::filesystem::path firstTrackPath;
|
|
||||||
bool embeddedCover = false;
|
|
||||||
|
|
||||||
// Get the first track of the release
|
|
||||||
{
|
|
||||||
Wt::Dbo::Transaction transaction(session);
|
Wt::Dbo::Transaction transaction(session);
|
||||||
|
|
||||||
|
// If the release does not exist or is the special release "None", do nothing
|
||||||
|
Release::pointer release = Release::getById(session, releaseId);
|
||||||
|
if (!release || release->isNone())
|
||||||
|
return std::vector<Image::Image>();
|
||||||
|
|
||||||
|
// Get the first track of the release
|
||||||
std::vector<Track::pointer> tracks = Track::getByFilter(session,
|
std::vector<Track::pointer> tracks = Track::getByFilter(session,
|
||||||
SearchFilter::IdMatch({{SearchFilter::Field::Release, {releaseId}}}),
|
SearchFilter::ById(SearchFilter::Field::Release, releaseId),
|
||||||
-1, 1 /* limit result size */);
|
-1, 1 /* limit result size */);
|
||||||
|
|
||||||
if (tracks.empty())
|
if (tracks.empty())
|
||||||
return std::vector<Image::Image>();
|
return std::vector<Image::Image>();
|
||||||
|
|
||||||
firstTrackPath = tracks.front()->getPath();
|
boost::filesystem::path firstTrackPath = tracks.front()->getPath();
|
||||||
embeddedCover = (tracks.front()->getCoverType() == Track::CoverType::Embedded);
|
bool embeddedCover = (tracks.front()->getCoverType() == Track::CoverType::Embedded);
|
||||||
}
|
|
||||||
|
transaction.commit();
|
||||||
|
|
||||||
// First, try to get covers from the directory of the release
|
// First, try to get covers from the directory of the release
|
||||||
std::vector<Image::Image> res = getFromDirectory( firstTrackPath.parent_path(), nbMaxCovers);
|
std::vector<Image::Image> res = getFromDirectory( firstTrackPath.parent_path(), nbMaxCovers);
|
||||||
|
|||||||
+11
-12
@@ -44,6 +44,11 @@ Release::getByMBID(Wt::Dbo::Session& session, const std::string& mbid)
|
|||||||
return session.find<Release>().where("mbid = ?").bind(mbid);
|
return session.find<Release>().where("mbid = ?").bind(mbid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Release::pointer
|
||||||
|
Release::getById(Wt::Dbo::Session& session, Release::id_type id)
|
||||||
|
{
|
||||||
|
return session.find<Release>().where("id = ?").bind(id);
|
||||||
|
}
|
||||||
|
|
||||||
Release::pointer
|
Release::pointer
|
||||||
Release::create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID)
|
Release::create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID)
|
||||||
@@ -51,6 +56,12 @@ Release::create(Wt::Dbo::Session& session, const std::string& name, const std::s
|
|||||||
return session.add(new Release(name, MBID));
|
return session.add(new Release(name, MBID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Release::isNone() const
|
||||||
|
{
|
||||||
|
return _name == "<None>";
|
||||||
|
}
|
||||||
|
|
||||||
Release::pointer
|
Release::pointer
|
||||||
Release::getNone(Wt::Dbo::Session& session)
|
Release::getNone(Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
@@ -129,16 +140,4 @@ Release::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset,
|
|||||||
return std::vector<pointer>(res.begin(), res.end());
|
return std::vector<pointer>(res.begin(), res.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector< Wt::Dbo::ptr<Artist> >
|
|
||||||
Release::getArtists() const
|
|
||||||
{
|
|
||||||
assert(self());
|
|
||||||
assert(self()->id() != Wt::Dbo::dbo_traits<Release>::invalidId() );
|
|
||||||
assert(session());
|
|
||||||
|
|
||||||
Wt::Dbo::collection< Wt::Dbo::ptr<Artist> > res = session()->query<Wt::Dbo::ptr<Artist> >("SELECT a FROM artist a INNER JOIN release r ON r.id = t.release_id INNER JOIN track t ON t.release_id = r.id").where("r.id = ?").bind(id());
|
|
||||||
|
|
||||||
return std::vector< Wt::Dbo::ptr<Artist> > (res.begin(), res.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Database
|
} // namespace Database
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ class Release : public Wt::Dbo::Dbo<Release>
|
|||||||
std::string getMBID() const { return _MBID; }
|
std::string getMBID() const { return _MBID; }
|
||||||
bool isNone(void) const;
|
bool isNone(void) const;
|
||||||
boost::posix_time::time_duration getDuration(void) const;
|
boost::posix_time::time_duration getDuration(void) const;
|
||||||
std::vector<Wt::Dbo::ptr<Artist> > getArtists() const; // Get the artists of this release
|
|
||||||
std::vector<Wt::Dbo::ptr<Track> > getTracks() const; // Get the tracks of this release
|
|
||||||
|
|
||||||
void setMBID(std::string mbid) { _MBID = mbid; }
|
void setMBID(std::string mbid) { _MBID = mbid; }
|
||||||
|
|
||||||
|
|||||||
@@ -58,12 +58,18 @@ class SearchFilter
|
|||||||
return SearchFilter(_nameLikeMatch);
|
return SearchFilter(_nameLikeMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single ID match
|
// Single Field ID match
|
||||||
static SearchFilter ById(Field field, Wt::Dbo::dbo_default_traits::IdType id)
|
static SearchFilter ById(Field field, Wt::Dbo::dbo_default_traits::IdType id)
|
||||||
{
|
{
|
||||||
return SearchFilter({{field, {id} }});
|
return SearchFilter({{field, {id} }});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Single Field Name match
|
||||||
|
static SearchFilter ByName(Field field, std::vector<std::string> keywords)
|
||||||
|
{
|
||||||
|
return NameLikeMatch({{{field, keywords}}});
|
||||||
|
}
|
||||||
|
|
||||||
// The filter is a AND of the following conditions:
|
// The filter is a AND of the following conditions:
|
||||||
|
|
||||||
// ((Field1.name LIKE STR1-1 OR Field1.name LIKE STR1-2 ...) OR (Field2.name LIKE STR2-1 OR Field2.name LIKE STR2-2 ...) ...
|
// ((Field1.name LIKE STR1-1 OR Field1.name LIKE STR1-2 ...) OR (Field2.name LIKE STR2-1 OR Field2.name LIKE STR2-2 ...) ...
|
||||||
|
|||||||
@@ -19,15 +19,12 @@
|
|||||||
|
|
||||||
#include "AvFormat.hpp"
|
#include "AvFormat.hpp"
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include "logger/Logger.hpp"
|
||||||
|
#include "utils/Utils.hpp"
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
||||||
|
|
||||||
#include "av/AvInfo.hpp"
|
#include "av/AvInfo.hpp"
|
||||||
|
|
||||||
#include "logger/Logger.hpp"
|
|
||||||
|
|
||||||
#include "Utils.hpp"
|
|
||||||
|
|
||||||
namespace MetaData
|
namespace MetaData
|
||||||
{
|
{
|
||||||
@@ -112,11 +109,11 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
|
|||||||
for (it = metadata.begin(); it != metadata.end(); ++it)
|
for (it = metadata.begin(); it != metadata.end(); ++it)
|
||||||
{
|
{
|
||||||
if (boost::iequals(it->first, "artist"))
|
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"))
|
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"))
|
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")) {
|
else if (boost::iequals(it->first, "track")) {
|
||||||
std::size_t number;
|
std::size_t number;
|
||||||
if (readAs<std::size_t>(it->second, 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"))
|
else if (boost::iequals(it->first, "genre"))
|
||||||
{
|
{
|
||||||
|
// TODO use splitStrings
|
||||||
std::list<std::string> genres;
|
std::list<std::string> genres;
|
||||||
if (readList(it->second, ";,", genres))
|
if (readList(it->second, ";,", genres))
|
||||||
items.insert( std::make_pair(MetaData::Type::Genres, 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")
|
else if (boost::iequals(it->first, "MusicBrainz Artist Id")
|
||||||
|| boost::iequals(it->first, "MUSICBRAINZ_ARTISTID"))
|
|| 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")
|
else if (boost::iequals(it->first, "MusicBrainz Album Id")
|
||||||
|| boost::iequals(it->first, "MUSICBRAINZ_ALBUMID"))
|
|| 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)) ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
namespace MetaData
|
namespace MetaData
|
||||||
{
|
{
|
||||||
|
|
||||||
// Implements AVFORMAT library
|
// Parse that makes use of AvFormat
|
||||||
class AvFormat : public Parser
|
class AvFormat : public Parser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <Wt/WBreak>
|
#include <Wt/WBreak>
|
||||||
|
|
||||||
#include "logger/Logger.hpp"
|
#include "logger/Logger.hpp"
|
||||||
|
#include "utils/Utils.hpp"
|
||||||
|
|
||||||
#include "LmsApplication.hpp"
|
#include "LmsApplication.hpp"
|
||||||
#include "TrackView.hpp"
|
#include "TrackView.hpp"
|
||||||
@@ -41,18 +42,10 @@ class DurationItemDelegate : public Wt::WItemDelegate
|
|||||||
{
|
{
|
||||||
boost::posix_time::time_duration duration = boost::any_cast<boost::posix_time::time_duration>(index.data(Wt::DisplayRole));
|
boost::posix_time::time_duration duration = boost::any_cast<boost::posix_time::time_duration>(index.data(Wt::DisplayRole));
|
||||||
|
|
||||||
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
|
// TODO bug when redrawn
|
||||||
|
std::string format = duration.total_seconds() < 3600 ? "%M:%S" : "%H:%M:%S";
|
||||||
|
|
||||||
if (duration.total_seconds() < 3600)
|
return new Wt::WText(durationToString(duration, format), Wt::PlainText);
|
||||||
facet->time_duration_format("%M:%S");
|
|
||||||
else
|
|
||||||
facet->time_duration_format("%H:%M:%S");
|
|
||||||
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss.imbue(std::locale(oss.getloc(), facet));
|
|
||||||
oss << duration;
|
|
||||||
|
|
||||||
return new Wt::WText(oss.str(), Wt::PlainText);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <Wt/WText>
|
#include <Wt/WText>
|
||||||
#include <Wt/WTemplate>
|
#include <Wt/WTemplate>
|
||||||
#include <Wt/WPushButton>
|
#include <Wt/WPushButton>
|
||||||
|
#include <Wt/WImage>
|
||||||
|
|
||||||
#include "LmsApplication.hpp"
|
#include "LmsApplication.hpp"
|
||||||
|
|
||||||
@@ -38,6 +39,11 @@ _resCount(0)
|
|||||||
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||||
|
|
||||||
title->bindWidget("text", new Wt::WText("Artists", Wt::PlainText));
|
title->bindWidget("text", new Wt::WText("Artists", Wt::PlainText));
|
||||||
|
|
||||||
|
Wt::WTemplate* artistWrapper = new Wt::WTemplate(this);
|
||||||
|
artistWrapper->setTemplateText(Wt::WString::tr("wa-artist-wrapper"));
|
||||||
|
_contents = new Wt::WContainerWidget();
|
||||||
|
artistWrapper->bindWidget("contents", _contents );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -75,7 +81,13 @@ ArtistSearch::addResults(Database::SearchFilter filter, std::size_t nb)
|
|||||||
for (Artist::pointer artist : artists)
|
for (Artist::pointer artist : artists)
|
||||||
{
|
{
|
||||||
Wt::WTemplate* res = new Wt::WTemplate(this);
|
Wt::WTemplate* res = new Wt::WTemplate(this);
|
||||||
res->setTemplateText(Wt::WString::tr("mobile-artist-res"));
|
res->setTemplateText(Wt::WString::tr("wa-artist-res"));
|
||||||
|
|
||||||
|
Wt::WImage *artistImg = new Wt::WImage();
|
||||||
|
artistImg->setStyleClass("center-block"); // TODO move in css?
|
||||||
|
artistImg->setStyleClass("release_res_shadow release_img-responsive"); // TODO move in css?
|
||||||
|
|
||||||
|
res->bindWidget("gif", artistImg);
|
||||||
|
|
||||||
Wt::WText *text = new Wt::WText(Wt::WString::fromUTF8(artist->getName()), Wt::PlainText);
|
Wt::WText *text = new Wt::WText(Wt::WString::fromUTF8(artist->getName()), Wt::PlainText);
|
||||||
res->bindWidget("name", text);
|
res->bindWidget("name", text);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
#ifndef UI_MOBILE_ARTIST_SEARCH_HPP
|
#ifndef UI_MOBILE_ARTIST_SEARCH_HPP
|
||||||
#define UI_MOBILE_ARTIST_SEARCH_HPP
|
#define UI_MOBILE_ARTIST_SEARCH_HPP
|
||||||
|
|
||||||
#include <boost/algorithm/string/split.hpp>
|
|
||||||
#include <Wt/WContainerWidget>
|
#include <Wt/WContainerWidget>
|
||||||
|
|
||||||
#include "database/Types.hpp"
|
#include "database/Types.hpp"
|
||||||
@@ -48,6 +47,7 @@ class ArtistSearch : public Wt::WContainerWidget
|
|||||||
void clear(void);
|
void clear(void);
|
||||||
void addResults(Database::SearchFilter filter, size_t nb);
|
void addResults(Database::SearchFilter filter, size_t nb);
|
||||||
|
|
||||||
|
Wt::WContainerWidget* _contents;
|
||||||
std::size_t _resCount;
|
std::size_t _resCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,6 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/algorithm/string/split.hpp>
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
#include <Wt/WContainerWidget>
|
#include <Wt/WContainerWidget>
|
||||||
#include <Wt/WTemplate>
|
#include <Wt/WTemplate>
|
||||||
@@ -27,16 +24,17 @@
|
|||||||
#include <Wt/WText>
|
#include <Wt/WText>
|
||||||
#include <Wt/WTable>
|
#include <Wt/WTable>
|
||||||
|
|
||||||
#include "LmsApplication.hpp"
|
#include "logger/Logger.hpp"
|
||||||
|
#include "utils/Utils.hpp"
|
||||||
|
|
||||||
#include "MobileAudio.hpp"
|
#include "LmsApplication.hpp"
|
||||||
|
|
||||||
#include "ArtistSearch.hpp"
|
#include "ArtistSearch.hpp"
|
||||||
#include "ReleaseSearch.hpp"
|
#include "ReleaseSearch.hpp"
|
||||||
#include "TrackSearch.hpp"
|
#include "TrackSearch.hpp"
|
||||||
#include "MobileAudioMediaPlayer.hpp"
|
#include "MobileAudioMediaPlayer.hpp"
|
||||||
|
|
||||||
#include "logger/Logger.hpp"
|
#include "MobileAudio.hpp"
|
||||||
|
|
||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
namespace Mobile {
|
namespace Mobile {
|
||||||
@@ -87,26 +85,17 @@ Audio::Audio(Wt::WContainerWidget *parent)
|
|||||||
AudioMediaPlayer* mediaPlayer = new AudioMediaPlayer(encoding);
|
AudioMediaPlayer* mediaPlayer = new AudioMediaPlayer(encoding);
|
||||||
footer->bindWidget("player", mediaPlayer);
|
footer->bindWidget("player", mediaPlayer);
|
||||||
|
|
||||||
edit->changed().connect(std::bind([=] () {
|
edit->changed().connect(std::bind([=] ()
|
||||||
std::string text = edit->text().toUTF8();
|
{
|
||||||
|
|
||||||
// When a new search is done, output some results from:
|
// When a new search is done, output some results from:
|
||||||
// Artist
|
// Artist
|
||||||
// Release
|
// Release
|
||||||
// Song
|
// Song
|
||||||
std::vector<std::string> keywords;
|
std::vector<std::string> keywords = splitStrings(edit->text().toUTF8(), " ");;
|
||||||
boost::algorithm::split(keywords, text, boost::is_any_of(" "), boost::token_compress_on);
|
|
||||||
|
|
||||||
releaseSearch->search(SearchFilter::NameLikeMatch( {{
|
releaseSearch->search(SearchFilter::ByName(SearchFilter::Field::Release, keywords), 4);
|
||||||
{ SearchFilter::Field::Artist, keywords },
|
artistSearch->search(SearchFilter::ByName(SearchFilter::Field::Artist, keywords), 4);
|
||||||
{ SearchFilter::Field::Release, keywords }}}),
|
trackSearch->search(SearchFilter::ByName(SearchFilter::Field::Track, keywords), 4);
|
||||||
3);
|
|
||||||
|
|
||||||
artistSearch->search(SearchFilter::NameLikeMatch({{{SearchFilter::Field::Artist, keywords}}}),
|
|
||||||
3);
|
|
||||||
|
|
||||||
trackSearch->search(SearchFilter::NameLikeMatch({{{SearchFilter::Field::Track, keywords}}}),
|
|
||||||
3);
|
|
||||||
|
|
||||||
artistSearch->show();
|
artistSearch->show();
|
||||||
releaseSearch->show();
|
releaseSearch->show();
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ _resCount(0)
|
|||||||
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||||
|
|
||||||
title->bindWidget("text", new Wt::WText("Releases", Wt::PlainText));
|
title->bindWidget("text", new Wt::WText("Releases", Wt::PlainText));
|
||||||
|
|
||||||
|
Wt::WTemplate* releaseWrapper = new Wt::WTemplate(this);
|
||||||
|
releaseWrapper->setTemplateText(Wt::WString::tr("wa-release-wrapper"));
|
||||||
|
_contents = new Wt::WContainerWidget();
|
||||||
|
releaseWrapper->bindWidget("contents", _contents );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -58,9 +63,23 @@ ReleaseSearch::search(Database::SearchFilter filter, size_t max)
|
|||||||
addResults(filter, max);
|
addResults(filter, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Wt::WString
|
||||||
|
getArtistFromRelease(Release::pointer release)
|
||||||
|
{
|
||||||
|
auto artists = Artist::getByFilter(DboSession(),
|
||||||
|
SearchFilter::ById(SearchFilter::Field::Release, release.id()), -1, 2);
|
||||||
|
|
||||||
|
if (artists.size() > 1)
|
||||||
|
return Wt::WString::fromUTF8("Various artists", Wt::PlainText);
|
||||||
|
else
|
||||||
|
return Wt::WString::fromUTF8(artists.front()->getName(), Wt::PlainText);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ReleaseSearch::addResults(Database::SearchFilter filter, size_t nb)
|
ReleaseSearch::addResults(Database::SearchFilter filter, size_t nb)
|
||||||
{
|
{
|
||||||
|
using namespace Database;
|
||||||
|
|
||||||
Wt::Dbo::Transaction transaction(DboSession());
|
Wt::Dbo::Transaction transaction(DboSession());
|
||||||
|
|
||||||
std::vector<Release::pointer> releases = Release::getByFilter(DboSession(), filter, _resCount, nb + 1);
|
std::vector<Release::pointer> releases = Release::getByFilter(DboSession(), filter, _resCount, nb + 1);
|
||||||
@@ -77,14 +96,17 @@ ReleaseSearch::addResults(Database::SearchFilter filter, size_t nb)
|
|||||||
for (Release::pointer release : releases)
|
for (Release::pointer release : releases)
|
||||||
{
|
{
|
||||||
Wt::WTemplate* releaseWidget = new Wt::WTemplate(this);
|
Wt::WTemplate* releaseWidget = new Wt::WTemplate(this);
|
||||||
releaseWidget->setTemplateText(Wt::WString::tr("mobile-release-res"));
|
releaseWidget->setTemplateText(Wt::WString::tr("wa-release-res"));
|
||||||
|
|
||||||
Wt::WImage *cover = new Wt::WImage();
|
Wt::WImage *cover = new Wt::WImage();
|
||||||
cover->setStyleClass("center-block");
|
cover->setStyleClass("center-block");
|
||||||
cover->setImageLink( Wt::WLink( LmsApplication::instance()->getCoverResource()->getReleaseUrl(release.id(), 56)));
|
cover->setImageLink( Wt::WLink( LmsApplication::instance()->getCoverResource()->getReleaseUrl(release.id(), 512)));
|
||||||
releaseWidget->bindWidget("cover", cover);
|
cover->setStyleClass("release_res_shadow release_img-responsive"); // TODO move?
|
||||||
|
|
||||||
|
releaseWidget->bindWidget("cover", cover);
|
||||||
releaseWidget->bindWidget("name", new Wt::WText(Wt::WString::fromUTF8(release->getName()), Wt::PlainText));
|
releaseWidget->bindWidget("name", new Wt::WText(Wt::WString::fromUTF8(release->getName()), Wt::PlainText));
|
||||||
|
releaseWidget->bindString("release_name", Wt::WString::fromUTF8(release->getName()), Wt::PlainText);
|
||||||
|
releaseWidget->bindString("artist", getArtistFromRelease(release));
|
||||||
|
|
||||||
releaseWidget->clicked().connect(std::bind([=] {
|
releaseWidget->clicked().connect(std::bind([=] {
|
||||||
_sigReleaseSelected(release.id());
|
_sigReleaseSelected(release.id());
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class ReleaseSearch : public Wt::WContainerWidget
|
|||||||
void clear(void);
|
void clear(void);
|
||||||
void addResults(Database::SearchFilter filter, size_t nb);
|
void addResults(Database::SearchFilter filter, size_t nb);
|
||||||
|
|
||||||
|
Wt::WContainerWidget* _contents;
|
||||||
std::size_t _resCount;
|
std::size_t _resCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <Wt/WTemplate>
|
#include <Wt/WTemplate>
|
||||||
|
|
||||||
#include "logger/Logger.hpp"
|
#include "logger/Logger.hpp"
|
||||||
|
#include "utils/Utils.hpp"
|
||||||
#include "LmsApplication.hpp"
|
#include "LmsApplication.hpp"
|
||||||
|
|
||||||
#include "TrackSearch.hpp"
|
#include "TrackSearch.hpp"
|
||||||
@@ -33,101 +34,146 @@ namespace Mobile {
|
|||||||
using namespace Database;
|
using namespace Database;
|
||||||
|
|
||||||
TrackSearch::TrackSearch(Wt::WContainerWidget *parent)
|
TrackSearch::TrackSearch(Wt::WContainerWidget *parent)
|
||||||
: Wt::WContainerWidget(parent),
|
: Wt::WContainerWidget(parent)
|
||||||
_resCount(0)
|
|
||||||
{
|
{
|
||||||
|
Wt::WTemplate* wrapper = new Wt::WTemplate(this);
|
||||||
|
wrapper->setTemplateText(Wt::WString::tr("wa-trackview-wrapper"));
|
||||||
|
|
||||||
Wt::WTemplate* title = new Wt::WTemplate(this);
|
Wt::WTemplate* title = new Wt::WTemplate(this);
|
||||||
|
wrapper->bindWidget("title", title);
|
||||||
|
|
||||||
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||||
|
title->bindString("text", "Releases", Wt::PlainText);
|
||||||
|
|
||||||
title->bindWidget("text", new Wt::WText("Tracks", Wt::PlainText));
|
_releaseContainer = new Wt::WContainerWidget();
|
||||||
|
wrapper->bindWidget("release-container", _releaseContainer);
|
||||||
|
|
||||||
|
_showMore = new Wt::WTemplate();
|
||||||
|
wrapper->bindWidget("show-more", _showMore);
|
||||||
|
|
||||||
|
_showMore->setTemplateText(Wt::WString::tr("mobile-search-more"));
|
||||||
|
_showMore->bindString("text", "Tap to show more results...");
|
||||||
|
_showMore->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackSearch::clear()
|
TrackSearch::clear()
|
||||||
{
|
{
|
||||||
while (count() > 1)
|
// Flush the release container
|
||||||
removeWidget(this->widget(1));
|
_releaseContainer->clear();
|
||||||
|
|
||||||
_resCount = 0;
|
// Flush the current context
|
||||||
|
_currentTrackContainer = nullptr;
|
||||||
|
_nbTracks = 0;
|
||||||
|
_showMore->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackSearch::search(Database::SearchFilter filter, size_t max)
|
TrackSearch::search(SearchFilter filter, size_t nb)
|
||||||
{
|
{
|
||||||
|
_filter = filter;
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
addResults(filter, max);
|
addResults(nb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static
|
||||||
TrackSearch::addResults(Database::SearchFilter filter, size_t nb)
|
std::vector<Track::pointer >
|
||||||
|
getTracks(SearchFilter filter, size_t offset, size_t nb, bool &moreResults)
|
||||||
{
|
{
|
||||||
Wt::Dbo::Transaction transaction(DboSession());
|
std::vector<Track::pointer > tracks = Track::getByFilter(DboSession(), filter, offset, nb + 1);
|
||||||
|
|
||||||
std::vector<Track::pointer > tracks = Track::getByFilter(DboSession(), filter, _resCount, nb + 1);
|
|
||||||
|
|
||||||
bool expectMoreResults;
|
|
||||||
if (tracks.size() == nb + 1)
|
if (tracks.size() == nb + 1)
|
||||||
{
|
{
|
||||||
expectMoreResults = true;
|
moreResults = true;
|
||||||
tracks.pop_back();
|
tracks.pop_back();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
expectMoreResults = false;
|
moreResults = false;
|
||||||
|
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Wt::WString
|
||||||
|
getArtistNameFromRelease(Release::pointer release)
|
||||||
|
{
|
||||||
|
auto artists = Artist::getByFilter(DboSession(),
|
||||||
|
SearchFilter::ById(SearchFilter::Field::Release, release.id()), -1, 2);
|
||||||
|
|
||||||
|
if (artists.size() > 1)
|
||||||
|
return Wt::WString::fromUTF8("Various artists", Wt::PlainText);
|
||||||
|
else
|
||||||
|
return Wt::WString::fromUTF8(artists.front()->getName(), Wt::PlainText);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackSearch::addResults(size_t nb)
|
||||||
|
{
|
||||||
|
Wt::Dbo::Transaction transaction(DboSession());
|
||||||
|
|
||||||
|
bool moreResults;
|
||||||
|
std::vector<Track::pointer > tracks = getTracks(_filter, _nbTracks, nb, moreResults);
|
||||||
|
|
||||||
for (Track::pointer track : tracks)
|
for (Track::pointer track : tracks)
|
||||||
{
|
{
|
||||||
Wt::WTemplate* trackWidget = new Wt::WTemplate(this);
|
// First check if we need to create a new track container
|
||||||
trackWidget->setTemplateText(Wt::WString::tr("mobile-track-res"));
|
|
||||||
|
// New container if it is the first one or if the released has changed
|
||||||
|
if (!_currentTrackContainer
|
||||||
|
|| _currentReleaseId != track->getRelease().id())
|
||||||
|
{
|
||||||
|
Release::pointer release = track->getRelease();
|
||||||
|
|
||||||
|
Wt::WTemplate *releaseContainer = new Wt::WTemplate(_releaseContainer);
|
||||||
|
releaseContainer->setTemplateText(Wt::WString::tr("wa-trackview-release-container"));
|
||||||
|
_currentReleaseId = release.id();
|
||||||
|
|
||||||
Wt::WImage *cover = new Wt::WImage();
|
Wt::WImage *cover = new Wt::WImage();
|
||||||
cover->setStyleClass("center-block");
|
cover->setStyleClass ("center-block img-responsive"); // TODO move to CSS?
|
||||||
cover->setImageLink( Wt::WLink (LmsApplication::instance()->getCoverResource()->getTrackUrl(track.id(), 56)) );
|
cover->setImageLink(Wt::WLink (LmsApplication::instance()->getCoverResource()->getReleaseUrl(release.id(), 512)));
|
||||||
trackWidget->bindWidget("cover", cover);
|
|
||||||
|
|
||||||
// Track Name (bold)
|
releaseContainer->bindWidget("cover", cover);
|
||||||
// Artist - Album (italic)
|
releaseContainer->bindString("artist-name", getArtistNameFromRelease(release));
|
||||||
Wt::WContainerWidget *container = new Wt::WContainerWidget();
|
releaseContainer->bindString("release-name", release->getName(), Wt::PlainText);
|
||||||
Wt::WText *title = new Wt::WText(Wt::WString::fromUTF8(track->getName()), Wt::PlainText);
|
releaseContainer->bindInt("year", 2001);
|
||||||
title->setStyleClass("mobile-track");
|
|
||||||
container->addWidget(title);
|
|
||||||
|
|
||||||
if (!track->getArtist()->getName().empty()
|
_currentTrackContainer = new Wt::WContainerWidget();
|
||||||
|| !track->getRelease()->getName().empty())
|
releaseContainer->bindWidget("track-container", _currentTrackContainer);
|
||||||
{
|
|
||||||
title->setInline(false);
|
|
||||||
Wt::WText *artistRelease = new Wt::WText(Wt::WString::fromUTF8(track->getArtist()->getName() + " - " + track->getRelease()->getName()), Wt::PlainText);
|
|
||||||
artistRelease->setStyleClass("mobile-artist");
|
|
||||||
container->addWidget(artistRelease);
|
|
||||||
}
|
}
|
||||||
trackWidget->bindWidget("name", container);
|
|
||||||
|
|
||||||
Wt::WPushButton *playBtn = new Wt::WPushButton("Play");
|
assert(_currentTrackContainer != nullptr);
|
||||||
playBtn->setStyleClass("btn-primary center-block");
|
|
||||||
|
Wt::WTemplate* trackRes = new Wt::WTemplate(_currentTrackContainer);
|
||||||
|
trackRes->setTemplateText(Wt::WString::tr("wa-trackview-track"));
|
||||||
|
|
||||||
|
// TODO, do not display track pos for tracks that are not part of a release
|
||||||
|
trackRes->bindInt("track-pos", track->getTrackNumber());
|
||||||
|
trackRes->bindString("track-name", Wt::WString::fromUTF8(track->getName()), Wt::PlainText);
|
||||||
|
// TODO, display artist name for compilation releases?
|
||||||
|
|
||||||
|
// TODO handle large duration (> 1 hour)
|
||||||
|
trackRes->bindString("time", durationToString(track->getDuration(), "%M:%S"), Wt::PlainText);
|
||||||
|
|
||||||
|
Wt::WText *playBtn = new Wt::WText("Play", Wt::PlainText);
|
||||||
|
playBtn->setStyleClass("center-block"); // TODO move to CSS?
|
||||||
playBtn->clicked().connect(std::bind([=] {
|
playBtn->clicked().connect(std::bind([=] {
|
||||||
_sigTrackPlay.emit(track.id());
|
_sigTrackPlay.emit(track.id());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
trackWidget->bindWidget("btn", playBtn);
|
trackRes->bindWidget("btn", playBtn);
|
||||||
|
_nbTracks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
_resCount += tracks.size();
|
if (moreResults)
|
||||||
|
|
||||||
if (expectMoreResults)
|
|
||||||
{
|
{
|
||||||
Wt::WTemplate* moreRes = new Wt::WTemplate(this);
|
_showMore->clicked().connect(std::bind([=] {
|
||||||
moreRes->setTemplateText(Wt::WString::tr("mobile-search-more"));
|
|
||||||
|
|
||||||
moreRes->bindWidget("text", new Wt::WText("Tap to show more results..."));
|
|
||||||
|
|
||||||
moreRes->clicked().connect(std::bind([=] {
|
|
||||||
_sigMoreTracksSelected();
|
_sigMoreTracksSelected();
|
||||||
removeWidget(moreRes);
|
addResults(20);
|
||||||
|
|
||||||
addResults(filter, 20);
|
|
||||||
}));
|
}));
|
||||||
|
_showMore->show();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
_showMore->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Mobile
|
} // namespace Mobile
|
||||||
|
|||||||
@@ -48,9 +48,19 @@ class TrackSearch : public Wt::WContainerWidget
|
|||||||
Wt::Signal<void> _sigMoreTracksSelected;
|
Wt::Signal<void> _sigMoreTracksSelected;
|
||||||
|
|
||||||
void clear(void);
|
void clear(void);
|
||||||
void addResults(Database::SearchFilter filter, size_t nb);
|
void addResults(size_t nb);
|
||||||
|
|
||||||
std::size_t _resCount;
|
Wt::WTemplate* _showMore;
|
||||||
|
|
||||||
|
Database::SearchFilter _filter;
|
||||||
|
std::size_t _nbTracks;
|
||||||
|
|
||||||
|
// Main container that holds the releases
|
||||||
|
Wt::WContainerWidget* _releaseContainer;
|
||||||
|
|
||||||
|
// Used to add more results on the fly
|
||||||
|
Database::Release::id_type _currentReleaseId;
|
||||||
|
Wt::WContainerWidget* _currentTrackContainer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Mobile
|
} // namespace Mobile
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class CoverResource : public Wt::WResource
|
|||||||
|
|
||||||
std::string getReleaseUrl(Database::Release::id_type releaseId, size_t size) const;
|
std::string getReleaseUrl(Database::Release::id_type releaseId, size_t size) const;
|
||||||
std::string getTrackUrl(Database::Track::id_type trackId, size_t size) const;
|
std::string getTrackUrl(Database::Track::id_type trackId, size_t size) const;
|
||||||
|
std::string getArtistUrl(Database::Artist::id_type artistId, size_t size) const;
|
||||||
std::string getUnknownTrackUrl(size_t size) const;
|
std::string getUnknownTrackUrl(size_t size) const;
|
||||||
|
|
||||||
void handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response);
|
void handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response);
|
||||||
|
|||||||
@@ -21,12 +21,11 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
namespace MetaData
|
|
||||||
{
|
|
||||||
|
|
||||||
bool readAsPosixTime(const std::string& str, boost::posix_time::ptime& time)
|
bool readAsPosixTime(const std::string& str, boost::posix_time::ptime& time)
|
||||||
{
|
{
|
||||||
@@ -56,11 +55,11 @@ bool readList(const std::string& str, const std::string& separators, std::list<s
|
|||||||
{
|
{
|
||||||
std::string curStr;
|
std::string curStr;
|
||||||
|
|
||||||
BOOST_FOREACH(char c, str) {
|
for (char c : str)
|
||||||
|
{
|
||||||
if (separators.find(c) != std::string::npos) {
|
if (separators.find(c) != std::string::npos) {
|
||||||
if (!curStr.empty()) {
|
if (!curStr.empty()) {
|
||||||
results.push_back(string_to_utf8(curStr));
|
results.push_back(stringToUTF8(curStr));
|
||||||
curStr.clear();
|
curStr.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,11 +72,50 @@ bool readList(const std::string& str, const std::string& separators, std::list<s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!curStr.empty())
|
if (!curStr.empty())
|
||||||
results.push_back(string_to_utf8(curStr));
|
results.push_back(stringToUTF8(curStr));
|
||||||
|
|
||||||
return !str.empty();
|
return !str.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
durationToString(boost::posix_time::time_duration duration, std::string format)
|
||||||
|
{
|
||||||
|
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
|
||||||
|
facet->time_duration_format(format.c_str());
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss.imbue(std::locale(oss.getloc(), facet));
|
||||||
|
oss << duration;
|
||||||
|
|
||||||
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string>
|
||||||
|
splitStrings(std::string string, std::string separators)
|
||||||
|
{
|
||||||
|
std::vector<std::string> res;
|
||||||
|
|
||||||
|
boost::algorithm::split(res, string, boost::is_any_of(separators), boost::token_compress_on);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
stringTrim(const std::string& str, const std::string& whitespace)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
stringToUTF8(const std::string& str)
|
||||||
|
{
|
||||||
|
return boost::locale::conv::to_utf<char>(str, "UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Emeric Poupon
|
* Copyright (C) 2015 Emeric Poupon
|
||||||
*
|
*
|
||||||
* This file is part of LMS.
|
* This file is part of LMS.
|
||||||
*
|
*
|
||||||
@@ -17,20 +17,32 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef METADATA_UTILS_HPP
|
#pragma once
|
||||||
#define METADATA_UTILS_HPP
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include <boost/locale.hpp>
|
#include <boost/locale.hpp>
|
||||||
|
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||||
|
|
||||||
namespace MetaData
|
bool
|
||||||
{
|
readAsPosixTime(const std::string& str, boost::posix_time::ptime& time);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
bool readList(const std::string& str, const std::string& separators, std::list<std::string>& results);
|
std::string
|
||||||
|
durationToString(boost::posix_time::time_duration duration, std::string format);
|
||||||
|
|
||||||
|
std::vector<std::string>
|
||||||
|
splitStrings(std::string string, std::string separators);
|
||||||
|
|
||||||
|
std::string
|
||||||
|
stringTrim(const std::string& str, const std::string& whitespace = " \t");
|
||||||
|
|
||||||
|
std::string
|
||||||
|
stringToUTF8(const std::string& str);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline bool readAs(const std::string& str, T& data)
|
static inline bool readAs(const std::string& str, T& data)
|
||||||
@@ -40,30 +52,3 @@ static inline bool readAs(const std::string& str, T& data)
|
|||||||
return !iss.fail();
|
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
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user