Merge branch 'develop'
Conflicts: TODO
This commit is contained in:
+1
-2
@@ -12,7 +12,6 @@ lms_SOURCES = \
|
||||
$(srcdir)/cover/CoverArt.cpp \
|
||||
$(srcdir)/cover/CoverArtGrabber.cpp \
|
||||
$(srcdir)/database/DatabaseHandler.cpp \
|
||||
$(srcdir)/database/Genre.cpp \
|
||||
$(srcdir)/database/MediaDirectory.cpp \
|
||||
$(srcdir)/database/SqlQuery.cpp \
|
||||
$(srcdir)/database/Track.cpp \
|
||||
@@ -46,11 +45,11 @@ lms_SOURCES = \
|
||||
$(srcdir)/ui/audio/KeywordSearchFilter.cpp \
|
||||
$(srcdir)/ui/audio/PlayQueue.cpp \
|
||||
$(srcdir)/ui/audio/TableFilter.cpp \
|
||||
$(srcdir)/ui/audio/TableFilterGenre.cpp \
|
||||
$(srcdir)/ui/audio/TrackView.cpp \
|
||||
$(srcdir)/ui/common/DirectoryValidator.cpp \
|
||||
$(srcdir)/ui/common/SessionData.cpp \
|
||||
$(srcdir)/ui/resource/AvConvTranscodeStreamResource.cpp \
|
||||
$(srcdir)/ui/resource/CoverResource.cpp \
|
||||
$(srcdir)/ui/video/VideoWidget.cpp \
|
||||
$(srcdir)/ui/video/VideoDatabaseWidget.cpp \
|
||||
$(srcdir)/ui/video/VideoMediaPlayerWidget.cpp \
|
||||
|
||||
@@ -114,6 +114,19 @@ InputFormatContext::getMetadata(void)
|
||||
|
||||
}
|
||||
|
||||
std::size_t
|
||||
InputFormatContext::getNbPictures(void) const
|
||||
{
|
||||
std::size_t res = 0;
|
||||
|
||||
for (std::size_t i = 0; i < native()->nb_streams; ++i)
|
||||
{
|
||||
if (native()->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC)
|
||||
++res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
InputFormatContext::getPictures(std::vector< std::vector<unsigned char> >& pictures) const
|
||||
{
|
||||
|
||||
@@ -46,6 +46,7 @@ class InputFormatContext : public FormatContext
|
||||
|
||||
|
||||
// Get attached pictures
|
||||
std::size_t getNbPictures(void) const;
|
||||
void getPictures(std::vector< std::vector<unsigned char> >& pictures) const;
|
||||
|
||||
// Get the streams
|
||||
|
||||
@@ -52,6 +52,25 @@ Grabber::getFromInputFormatContext(const Av::InputFormatContext& input)
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<CoverArt>
|
||||
Grabber::getFromTrack(const boost::filesystem::path& p)
|
||||
{
|
||||
std::vector<CoverArt> res;
|
||||
|
||||
try
|
||||
{
|
||||
Av::InputFormatContext input(p);
|
||||
|
||||
return getFromInputFormatContext(input);
|
||||
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
LMS_LOG(MOD_COVER, SEV_ERROR) << "Cannot get pictures: " << e.what();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,7 +79,7 @@ Grabber::getFromTrack(Database::Track::pointer track)
|
||||
{
|
||||
std::vector<CoverArt> res;
|
||||
|
||||
if (!track)
|
||||
if (!track || !track->hasCover())
|
||||
return std::vector<CoverArt>();
|
||||
|
||||
try
|
||||
|
||||
@@ -36,6 +36,7 @@ class Grabber
|
||||
|
||||
static std::vector<CoverArt> getFromInputFormatContext(const Av::InputFormatContext& input);
|
||||
static std::vector<CoverArt> getFromTrack(Database::Track::pointer track);
|
||||
static std::vector<CoverArt> getFromTrack(const boost::filesystem::path& path);
|
||||
};
|
||||
|
||||
} // namespace CoverArt
|
||||
|
||||
@@ -402,6 +402,11 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
|
||||
track.modify()->setDate( boost::any_cast<boost::posix_time::ptime>(items[MetaData::Type::OriginalDate]) );
|
||||
}
|
||||
|
||||
if (items.find(MetaData::Type::HasCover) != items.end())
|
||||
{
|
||||
track.modify()->setHasCover( boost::any_cast<bool>(items[MetaData::Type::HasCover]));
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
|
||||
}
|
||||
|
||||
+42
-16
@@ -32,6 +32,25 @@
|
||||
|
||||
namespace Database {
|
||||
|
||||
// Find utilities
|
||||
struct SearchFilter
|
||||
{
|
||||
enum class Field {
|
||||
Artist, // artist name
|
||||
Release, // release name
|
||||
Genre, // genre name
|
||||
Track, // track name
|
||||
};
|
||||
|
||||
typedef std::map<Field, std::vector<std::string> > FieldValues;
|
||||
|
||||
// Formulas :
|
||||
// ((like1-1 LIKE ? OR like1-2 LIKE = ? ...) AND (like2-1 LIKE ? OR like2-2 LIKE ? ...)) AND exact1 = ? AND exact2 = ? ...
|
||||
|
||||
std::vector<FieldValues> likeMatches;
|
||||
FieldValues exactMatch;
|
||||
};
|
||||
|
||||
class Track;
|
||||
|
||||
class Genre
|
||||
@@ -47,7 +66,9 @@ class Genre
|
||||
// Find utility
|
||||
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
|
||||
static pointer getNone(Wt::Dbo::Session& session);
|
||||
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset = -1, std::size_t size = -1);
|
||||
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, int size = -1);
|
||||
static Wt::Dbo::Query<boost::tuple<std::string, int> > getAllQuery(Wt::Dbo::Session& session, SearchFilter& filter);
|
||||
static void updateGenreQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel<boost::tuple<std::string, int> >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames = std::vector<Wt::WString>());
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, const std::string& name);
|
||||
@@ -81,25 +102,21 @@ class Track
|
||||
Track() {}
|
||||
Track(const boost::filesystem::path& p);
|
||||
|
||||
// Find utilities
|
||||
|
||||
// Find utility functions
|
||||
static pointer getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
|
||||
static pointer getById(Wt::Dbo::Session& session, id_type id);
|
||||
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
|
||||
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session,
|
||||
const std::vector<std::string>& artists, // OR filter if many
|
||||
const std::vector<std::string>& releases, // OR filter if many
|
||||
const std::vector<std::string>& genres, // OR filter if many
|
||||
int offset = -1, int size = -1);
|
||||
|
||||
static std::vector<std::string> getReleases(Wt::Dbo::Session& session,
|
||||
const std::vector<std::string>& artists, // OR filter if many
|
||||
const std::vector<std::string>& genres, // OR filter if many
|
||||
int offset = -1, int size = -1);
|
||||
|
||||
static std::vector<std::string> getArtists(Wt::Dbo::Session& session,
|
||||
const std::vector<std::string>& genres, // OR filter
|
||||
int offset = -1, int size = -1);
|
||||
// Used for remote
|
||||
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
||||
static std::vector<std::string> getReleases(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
||||
static std::vector<std::string> getArtists(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
||||
|
||||
// Utility fonctions
|
||||
// MVC models for the user interface
|
||||
static void updateTracksQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel< pointer >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames = std::vector<Wt::WString>());
|
||||
static void updateReleaseQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel<boost::tuple<std::string, int> >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames = std::vector<Wt::WString>());
|
||||
static void updateArtistQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel<boost::tuple<std::string, int> >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames = std::vector<Wt::WString>());
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, const boost::filesystem::path& p);
|
||||
@@ -117,6 +134,7 @@ class Track
|
||||
void setOriginalDate(const boost::posix_time::ptime& date) { _originalDate = date; }
|
||||
void setGenres(const std::string& genreList) { _genreList = genreList; }
|
||||
void setGenres(std::vector<Genre::pointer> genres);
|
||||
void setHasCover(bool hasCover) { _hasCover = hasCover; }
|
||||
|
||||
int getTrackNumber(void) const { return _trackNumber; }
|
||||
int getDiscNumber(void) const { return _discNumber; }
|
||||
@@ -132,6 +150,7 @@ class Track
|
||||
|
||||
boost::posix_time::ptime getLastWriteTime(void) const { return _fileLastWrite; }
|
||||
const std::vector<unsigned char>& getChecksum(void) const { return _fileChecksum; }
|
||||
bool hasCover(void) const { return _hasCover; }
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
@@ -148,11 +167,16 @@ class Track
|
||||
Wt::Dbo::field(a, _filePath, "path");
|
||||
Wt::Dbo::field(a, _fileLastWrite, "last_write");
|
||||
Wt::Dbo::field(a, _fileChecksum, "checksum");
|
||||
Wt::Dbo::field(a, _hasCover, "has_cover");
|
||||
Wt::Dbo::hasMany(a, _genres, Wt::Dbo::ManyToMany, "track_genre", "", Wt::Dbo::OnDeleteCascade);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static Wt::Dbo::Query< pointer > getAllQuery(Wt::Dbo::Session& session, SearchFilter filter);
|
||||
static Wt::Dbo::Query<boost::tuple<std::string, int> > getReleasesQuery(Wt::Dbo::Session& session, SearchFilter filter);
|
||||
static Wt::Dbo::Query<boost::tuple<std::string, int> > getArtistsQuery(Wt::Dbo::Session& session, SearchFilter filter);
|
||||
|
||||
static const std::size_t _maxNameLength = 128;
|
||||
|
||||
int _trackNumber;
|
||||
@@ -167,10 +191,12 @@ class Track
|
||||
std::string _filePath;
|
||||
std::vector<unsigned char> _fileChecksum;
|
||||
boost::posix_time::ptime _fileLastWrite;
|
||||
bool _hasCover;
|
||||
|
||||
Wt::Dbo::collection< Genre::pointer > _genres; // Tracks that belong to this genre
|
||||
};
|
||||
|
||||
|
||||
} // namespace database
|
||||
|
||||
#endif
|
||||
|
||||
@@ -98,6 +98,7 @@ _dbBackend( db.string() )
|
||||
_session.createTables();
|
||||
_dbBackend.executeSql("CREATE INDEX artist_name_idx ON track(artist_name)");
|
||||
_dbBackend.executeSql("CREATE INDEX release_name_idx ON track(release_name)");
|
||||
_dbBackend.executeSql("CREATE INDEX genre_name_idx ON genre(name)");
|
||||
}
|
||||
catch(std::exception& e) {
|
||||
LMS_LOG(MOD_DB, SEV_ERROR) << "Cannot create tables: " << e.what();
|
||||
|
||||
@@ -1,68 +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 "AudioTypes.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
Genre::Genre()
|
||||
{
|
||||
}
|
||||
|
||||
Genre::Genre(const std::string& name)
|
||||
: _name( std::string(name, 0, _maxNameLength) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Genre::pointer
|
||||
Genre::getByName(Wt::Dbo::Session& session, const std::string& name)
|
||||
{
|
||||
// TODO use like search
|
||||
return session.find<Genre>().where("name = ?").bind( std::string(name, 0, _maxNameLength) );
|
||||
}
|
||||
|
||||
Genre::pointer
|
||||
Genre::getNone(Wt::Dbo::Session& session)
|
||||
{
|
||||
pointer res = getByName(session, "<None>");
|
||||
if (!res)
|
||||
res = create(session, "<None>");
|
||||
return res;
|
||||
}
|
||||
|
||||
bool
|
||||
Genre::isNone(void) const
|
||||
{
|
||||
return (_name == "<None>");
|
||||
}
|
||||
|
||||
Genre::pointer
|
||||
Genre::create(Wt::Dbo::Session& session, const std::string& name)
|
||||
{
|
||||
return session.add(new Genre(name));
|
||||
}
|
||||
|
||||
Wt::Dbo::collection<Genre::pointer>
|
||||
Genre::getAll(Wt::Dbo::Session& session, std::size_t offset, std::size_t size)
|
||||
{
|
||||
return session.find<Genre>().offset(offset).limit(size);
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
@@ -89,7 +89,7 @@ InnerJoinClause::And(const InnerJoinClause& clause)
|
||||
if (!_clause.empty())
|
||||
_clause += " ";
|
||||
|
||||
_clause += clause._clause;
|
||||
_clause += "INNER JOIN " + clause._clause;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
+280
-111
@@ -19,20 +19,128 @@
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <Wt/Dbo/QueryModel>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "SqlQuery.hpp"
|
||||
|
||||
#include "AudioTypes.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
static SqlQuery generatePartialQuery(SearchFilter& filter, bool forceGenreInnerJoin = false)
|
||||
{
|
||||
bool genreJoin = forceGenreInnerJoin;
|
||||
SqlQuery sqlQuery;
|
||||
|
||||
|
||||
// Process like searches
|
||||
BOOST_FOREACH(SearchFilter::FieldValues& likeMatch, filter.likeMatches)
|
||||
{
|
||||
WhereClause likeWhereClause;
|
||||
|
||||
// Artist
|
||||
{
|
||||
WhereClause whereClause;
|
||||
|
||||
BOOST_FOREACH(const std::string& name, likeMatch[SearchFilter::Field::Artist])
|
||||
whereClause.Or( WhereClause("t.artist_name LIKE ?") ).bind("%%" + name + "%%");
|
||||
|
||||
likeWhereClause.Or( whereClause );
|
||||
}
|
||||
// Release
|
||||
{
|
||||
WhereClause whereClause;
|
||||
|
||||
BOOST_FOREACH(const std::string& name, likeMatch[SearchFilter::Field::Release])
|
||||
whereClause.Or( WhereClause("t.release_name LIKE ?") ).bind("%%" + name + "%%");
|
||||
|
||||
likeWhereClause.Or( whereClause );
|
||||
}
|
||||
// Genre
|
||||
{
|
||||
WhereClause whereClause;
|
||||
|
||||
BOOST_FOREACH(const std::string& name, likeMatch[SearchFilter::Field::Genre])
|
||||
{
|
||||
whereClause.Or( WhereClause("g.name LIKE ?") ).bind("%%" + name + "%%");
|
||||
genreJoin = true;
|
||||
}
|
||||
|
||||
likeWhereClause.Or( whereClause );
|
||||
}
|
||||
// Track
|
||||
{
|
||||
WhereClause whereClause;
|
||||
|
||||
BOOST_FOREACH(const std::string& name, likeMatch[SearchFilter::Field::Track])
|
||||
whereClause.Or( WhereClause("t.name LIKE ?") ).bind("%%" + name + "%%");
|
||||
|
||||
likeWhereClause.Or( whereClause );
|
||||
}
|
||||
|
||||
sqlQuery.where().And( likeWhereClause );
|
||||
}
|
||||
|
||||
// Add exact search constraints
|
||||
// Artist
|
||||
{
|
||||
WhereClause whereClause;
|
||||
|
||||
BOOST_FOREACH(const std::string& name, filter.exactMatch[SearchFilter::Field::Artist])
|
||||
whereClause.Or( WhereClause("t.artist_name = ?") ).bind(name);
|
||||
|
||||
sqlQuery.where().And( whereClause );
|
||||
}
|
||||
|
||||
// Release
|
||||
{
|
||||
WhereClause whereClause;
|
||||
|
||||
BOOST_FOREACH(const std::string& name, filter.exactMatch[SearchFilter::Field::Release])
|
||||
whereClause.Or( WhereClause("t.release_name = ?") ).bind(name);
|
||||
|
||||
sqlQuery.where().And( whereClause );
|
||||
}
|
||||
|
||||
// Genre
|
||||
{
|
||||
WhereClause whereClause;
|
||||
|
||||
BOOST_FOREACH(const std::string& name, filter.exactMatch[SearchFilter::Field::Genre])
|
||||
{
|
||||
whereClause.Or( WhereClause("g.name = ?") ).bind(name);
|
||||
genreJoin = true;
|
||||
}
|
||||
|
||||
sqlQuery.where().And( whereClause );
|
||||
}
|
||||
|
||||
if (genreJoin)
|
||||
{
|
||||
sqlQuery.innerJoin().And( InnerJoinClause("genre g ON g.id = t_g.genre_id"));
|
||||
sqlQuery.innerJoin().And( InnerJoinClause("track_genre t_g ON t_g.track_id = t.id"));
|
||||
}
|
||||
|
||||
return sqlQuery;
|
||||
}
|
||||
|
||||
|
||||
Track::Track(const boost::filesystem::path& p)
|
||||
:
|
||||
_trackNumber(0),
|
||||
_discNumber(0),
|
||||
_filePath( p.string() )
|
||||
_filePath( p.string() ),
|
||||
_hasCover(false)
|
||||
{
|
||||
}
|
||||
|
||||
Wt::Dbo::collection< Track::pointer >
|
||||
Track::getAll(Wt::Dbo::Session& session)
|
||||
{
|
||||
return session.find<Track>();
|
||||
}
|
||||
|
||||
void
|
||||
Track::setGenres(std::vector<Genre::pointer> genres)
|
||||
@@ -64,12 +172,6 @@ Track::create(Wt::Dbo::Session& session, const boost::filesystem::path& p)
|
||||
return session.add(new Track(p) );
|
||||
}
|
||||
|
||||
Wt::Dbo::collection< Track::pointer >
|
||||
Track::getAll(Wt::Dbo::Session& session)
|
||||
{
|
||||
return session.find<Track>();
|
||||
}
|
||||
|
||||
std::vector< Genre::pointer >
|
||||
Track::getGenres(void) const
|
||||
{
|
||||
@@ -78,89 +180,116 @@ Track::getGenres(void) const
|
||||
return genres;
|
||||
}
|
||||
|
||||
Wt::Dbo::collection< Track::pointer >
|
||||
Track::getAll(Wt::Dbo::Session& session,
|
||||
const std::vector<std::string>& artists,
|
||||
const std::vector<std::string>& releases,
|
||||
const std::vector<std::string>& genres,
|
||||
int offset, int size)
|
||||
Wt::Dbo::Query< Track::pointer >
|
||||
Track::getAllQuery(Wt::Dbo::Session& session, SearchFilter filter)
|
||||
{
|
||||
std::string sqlQuery = "SELECT t FROM track t";
|
||||
SqlQuery sqlQuery = generatePartialQuery(filter);
|
||||
|
||||
if (!genres.empty())
|
||||
{
|
||||
sqlQuery += " INNER JOIN genre g ON g.id = t_g.genre_id";
|
||||
sqlQuery += " INNER JOIN track_genre t_g ON t_g.track_id = t.id AND t_g.genre_id = g.id";
|
||||
}
|
||||
Wt::Dbo::Query<pointer> query
|
||||
= session.query<Track::pointer>( "SELECT t FROM track t " + sqlQuery.innerJoin().get() + " " + sqlQuery.where().get()).groupBy("t.id");
|
||||
|
||||
WhereClause where;
|
||||
|
||||
{
|
||||
WhereClause artistWhere;
|
||||
|
||||
for (std::size_t i = 0; i < artists.size(); ++i)
|
||||
artistWhere.Or( WhereClause("t.artist_name = ?") );
|
||||
|
||||
where.And(artistWhere);
|
||||
}
|
||||
|
||||
{
|
||||
WhereClause releaseWhere;
|
||||
|
||||
for (std::size_t i = 0; i < releases.size(); ++i)
|
||||
releaseWhere.Or( WhereClause("t.release_name = ?") );
|
||||
|
||||
where.And(releaseWhere);
|
||||
}
|
||||
|
||||
{
|
||||
WhereClause genreWhere;
|
||||
|
||||
for (std::size_t i = 0; i < genres.size(); ++i)
|
||||
genreWhere.Or( WhereClause("g.name = ?") );
|
||||
|
||||
where.And(genreWhere);
|
||||
}
|
||||
|
||||
|
||||
Wt::Dbo::Query<Track::pointer> query = session.query<Track::pointer>( sqlQuery + " " + where.get() ).offset(offset).limit(size);
|
||||
|
||||
BOOST_FOREACH(const std::string& artist, artists)
|
||||
query.bind(artist);
|
||||
|
||||
BOOST_FOREACH(const std::string& release, releases)
|
||||
query.bind(release);
|
||||
|
||||
BOOST_FOREACH(const std::string& genre, genres)
|
||||
query.bind(genre);
|
||||
|
||||
query.groupBy("t");
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs())
|
||||
query.bind(bindArg);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
Track::getArtists(Wt::Dbo::Session& session,
|
||||
const std::vector<std::string>& genres,
|
||||
int offset, int size)
|
||||
Wt::Dbo::collection< Track::pointer >
|
||||
Track::getAll(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size)
|
||||
{
|
||||
std::string sqlQuery = "SELECT t.artist_name FROM track t";
|
||||
return getAllQuery(session, filter).limit(size).offset(offset);
|
||||
}
|
||||
|
||||
if (!genres.empty())
|
||||
Wt::Dbo::Query< boost::tuple<std::string, int> >
|
||||
Track::getReleasesQuery(Wt::Dbo::Session& session, SearchFilter filter)
|
||||
{
|
||||
SqlQuery sqlQuery = generatePartialQuery(filter);
|
||||
|
||||
Wt::Dbo::Query<boost::tuple<std::string, int> > query
|
||||
= session.query<boost::tuple<std::string, int> >("SELECT t.release_name, COUNT(DISTINCT t.id) FROM track t " + sqlQuery.innerJoin().get() + " " + sqlQuery.where().get()).groupBy("t.release_name").orderBy("t.release_name");
|
||||
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs())
|
||||
query.bind(bindArg);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
Wt::Dbo::Query< boost::tuple<std::string, int> >
|
||||
Track::getArtistsQuery(Wt::Dbo::Session& session, SearchFilter filter)
|
||||
{
|
||||
SqlQuery sqlQuery = generatePartialQuery(filter);
|
||||
|
||||
Wt::Dbo::Query<boost::tuple<std::string, int> > query
|
||||
= session.query<boost::tuple<std::string, int> >( "SELECT t.artist_name, COUNT(DISTINCT t.id) FROM track t " + sqlQuery.innerJoin().get() + " " + sqlQuery.where().get()).groupBy("t.artist_name").orderBy("t.artist_name");
|
||||
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs())
|
||||
query.bind(bindArg);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
void
|
||||
Track::updateTracksQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel< pointer >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames)
|
||||
{
|
||||
Wt::Dbo::Query< pointer > query = getAllQuery(session, filter).orderBy("t.artist_name,t.date,t.release_name,t.disc_number,t.track_number");
|
||||
model.setQuery(query, columnNames.empty() ? true : false);
|
||||
|
||||
// TODO do something better
|
||||
if (columnNames.size() == 9)
|
||||
{
|
||||
sqlQuery += " INNER JOIN genre g ON g.id = t_g.genre_id";
|
||||
sqlQuery += " INNER JOIN track_genre t_g ON t_g.track_id = t.id AND t_g.genre_id = g.id";
|
||||
model.addColumn( "t.artist_name", columnNames[0] );
|
||||
model.addColumn( "t.release_name", columnNames[1] );
|
||||
model.addColumn( "t.disc_number", columnNames[2] );
|
||||
model.addColumn( "t.track_number", columnNames[3] );
|
||||
model.addColumn( "t.name", columnNames[4] );
|
||||
model.addColumn( "t.duration", columnNames[5] );
|
||||
model.addColumn( "t.date", columnNames[6] );
|
||||
model.addColumn( "t.original_date", columnNames[7] );
|
||||
model.addColumn( "t.genre_list", columnNames[8] );
|
||||
}
|
||||
|
||||
WhereClause whereClause;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < genres.size(); ++i)
|
||||
whereClause.Or( WhereClause("g.name = ?") );
|
||||
void
|
||||
Track::updateReleaseQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel<boost::tuple<std::string, int> >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames)
|
||||
{
|
||||
Wt::Dbo::Query< boost::tuple<std::string, int> > query = getReleasesQuery(session, filter);
|
||||
|
||||
Wt::Dbo::Query<std::string> query = session.query<std::string>( sqlQuery + " " + whereClause.get() ).offset(offset).limit(size).groupBy("t.artist_name");
|
||||
model.setQuery(query, columnNames.empty() ? true : false);
|
||||
|
||||
BOOST_FOREACH(const std::string& genre, genres)
|
||||
query.bind(genre);
|
||||
// TODO do something better
|
||||
if (columnNames.size() == 2)
|
||||
{
|
||||
model.addColumn( "t.release_name", columnNames[0]);
|
||||
model.addColumn( "COUNT(DISTINCT t.id)" );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Track::updateArtistQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel<boost::tuple<std::string, int> >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames)
|
||||
{
|
||||
Wt::Dbo::Query< boost::tuple<std::string, int> > query = getArtistsQuery(session, filter);
|
||||
|
||||
model.setQuery(query, columnNames.empty() ? true : false);
|
||||
|
||||
// TODO do something better
|
||||
if (columnNames.size() == 2)
|
||||
{
|
||||
model.addColumn( "t.artist_name", columnNames[0]);
|
||||
model.addColumn( "COUNT(DISTINCT t.id)" );
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
Track::getArtists(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size)
|
||||
{
|
||||
SqlQuery sqlQuery = generatePartialQuery(filter);
|
||||
|
||||
Wt::Dbo::Query<std::string> query
|
||||
= session.query<std::string>( "SELECT DISTINCT t.artist_name FROM track t " + sqlQuery.innerJoin().get() + " " + sqlQuery.where().get()).offset(offset).limit(size).orderBy("t.artist_name");
|
||||
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs())
|
||||
query.bind(bindArg);
|
||||
|
||||
typedef Wt::Dbo::collection< std::string > ArtistNames;
|
||||
ArtistNames artistNames(query);
|
||||
@@ -170,46 +299,17 @@ Track::getArtists(Wt::Dbo::Session& session,
|
||||
res.push_back((*it));
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
Track::getReleases(Wt::Dbo::Session& session,
|
||||
const std::vector<std::string>& artists,
|
||||
const std::vector<std::string>& genres,
|
||||
int offset, int size)
|
||||
Track::getReleases(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size)
|
||||
{
|
||||
SqlQuery sqlQuery = generatePartialQuery(filter);
|
||||
|
||||
std::string sqlQuery = "SELECT t.release_name FROM track t";
|
||||
Wt::Dbo::Query<std::string> query
|
||||
= session.query<std::string>( "SELECT DISTINCT t.release_name FROM track t " + sqlQuery.innerJoin().get() + " " + sqlQuery.where().get()).offset(offset).limit(size).orderBy("t.release_name");
|
||||
|
||||
if (!genres.empty())
|
||||
{
|
||||
sqlQuery += " INNER JOIN genre g ON g.id = t_g.genre_id";
|
||||
sqlQuery += " INNER JOIN track_genre t_g ON t_g.track_id = t.id AND t_g.genre_id = g.id";
|
||||
}
|
||||
|
||||
WhereClause whereClause;
|
||||
|
||||
{
|
||||
WhereClause clause;
|
||||
|
||||
BOOST_FOREACH(const std::string& artist, artists)
|
||||
clause.Or( WhereClause("t.artist_name = ?") ).bind(artist);
|
||||
|
||||
whereClause.And(clause);
|
||||
}
|
||||
{
|
||||
WhereClause clause;
|
||||
|
||||
BOOST_FOREACH(const std::string& genre, genres)
|
||||
clause.Or( WhereClause("g.name = ?") ).bind(genre);
|
||||
|
||||
whereClause.And(clause);
|
||||
}
|
||||
|
||||
Wt::Dbo::Query<std::string> query = session.query<std::string>( sqlQuery + " " + whereClause.get() ).offset(offset).limit(size).groupBy("t.release_name");
|
||||
|
||||
BOOST_FOREACH(const std::string& bindArg, whereClause.getBindArgs())
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs())
|
||||
query.bind(bindArg);
|
||||
|
||||
typedef Wt::Dbo::collection< std::string > ReleaseNames;
|
||||
@@ -222,8 +322,77 @@ Track::getReleases(Wt::Dbo::Session& session,
|
||||
return res;
|
||||
}
|
||||
|
||||
Genre::Genre()
|
||||
{
|
||||
}
|
||||
|
||||
Genre::Genre(const std::string& name)
|
||||
: _name( std::string(name, 0, _maxNameLength) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Genre::pointer
|
||||
Genre::getByName(Wt::Dbo::Session& session, const std::string& name)
|
||||
{
|
||||
// TODO use like search
|
||||
return session.find<Genre>().where("name = ?").bind( std::string(name, 0, _maxNameLength) );
|
||||
}
|
||||
|
||||
Genre::pointer
|
||||
Genre::getNone(Wt::Dbo::Session& session)
|
||||
{
|
||||
pointer res = getByName(session, "<None>");
|
||||
if (!res)
|
||||
res = create(session, "<None>");
|
||||
return res;
|
||||
}
|
||||
|
||||
bool
|
||||
Genre::isNone(void) const
|
||||
{
|
||||
return (_name == "<None>");
|
||||
}
|
||||
|
||||
Genre::pointer
|
||||
Genre::create(Wt::Dbo::Session& session, const std::string& name)
|
||||
{
|
||||
return session.add(new Genre(name));
|
||||
}
|
||||
|
||||
Wt::Dbo::collection<Genre::pointer>
|
||||
Genre::getAll(Wt::Dbo::Session& session, int offset, int size)
|
||||
{
|
||||
return session.find<Genre>().offset(offset).limit(size).orderBy("name");
|
||||
}
|
||||
|
||||
Wt::Dbo::Query<boost::tuple<std::string, int> >
|
||||
Genre::getAllQuery(Wt::Dbo::Session& session, SearchFilter& filter)
|
||||
{
|
||||
SqlQuery sqlQuery = generatePartialQuery(filter, true);
|
||||
|
||||
Wt::Dbo::Query<boost::tuple<std::string, int> > query
|
||||
= session.query<boost::tuple<std::string, int> >( "SELECT g.name, COUNT(DISTINCT t.id) FROM track t " + sqlQuery.innerJoin().get() + " " + sqlQuery.where().get()).groupBy("g.name").orderBy("g.name");
|
||||
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs())
|
||||
query.bind(bindArg);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
void
|
||||
Genre::updateGenreQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel< boost::tuple<std::string, int> >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames)
|
||||
{
|
||||
Wt::Dbo::Query< boost::tuple<std::string, int> > query = getAllQuery(session, filter);
|
||||
model.setQuery(query, columnNames.empty() ? true : false);
|
||||
|
||||
// TODO do something better
|
||||
if (columnNames.size() == 2)
|
||||
{
|
||||
model.addColumn( "g.name", columnNames[0] );
|
||||
model.addColumn( "COUNT(DISTINCT t.id)", columnNames[1] );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -114,6 +114,9 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
|
||||
// Duration
|
||||
items.insert( std::make_pair(MetaData::Type::Duration, boost::posix_time::time_duration( boost::posix_time::seconds( input.getDurationSecs() )) ));
|
||||
|
||||
// Cover
|
||||
items.insert( std::make_pair(MetaData::Type::HasCover, input.getNbPictures() > 0));
|
||||
|
||||
// Embedded MetaData
|
||||
// Make sure to convert strings into UTF-8
|
||||
std::map<std::string, std::string>::const_iterator it;
|
||||
|
||||
@@ -39,18 +39,12 @@ namespace MetaData
|
||||
DiscNumber, // size_t
|
||||
Date, // boost::posix_time::ptime
|
||||
OriginalDate, // boost::posix_time::ptime
|
||||
Cover, // GenericData
|
||||
HasCover, // bool
|
||||
AudioStreams, // vector<AudioStream>
|
||||
VideoStreams, // vector<VideoStream>
|
||||
SubtitleStreams, // vector<SubtitleStream>
|
||||
};
|
||||
|
||||
// Used by Cover
|
||||
struct GenericData {
|
||||
std::string mimeType;
|
||||
std::vector<unsigned char> data;
|
||||
};
|
||||
|
||||
// Used by Streams
|
||||
struct AudioStream {
|
||||
std::size_t nbChannels;
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
namespace Remote {
|
||||
namespace Server {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
AudioCollectionRequestHandler::AudioCollectionRequestHandler(Database::Handler& db)
|
||||
: _db(db)
|
||||
{}
|
||||
@@ -163,24 +165,23 @@ AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::G
|
||||
size = _maxListArtists;
|
||||
size = std::min(size, _maxListArtists);
|
||||
|
||||
SearchFilter filter;
|
||||
|
||||
// Get filters
|
||||
std::vector<std::string> genres;
|
||||
for (int id = 0; id < request.genre_size(); ++id)
|
||||
genres.push_back( request.genre(id) );
|
||||
filter.exactMatch[SearchFilter::Field::Genre].push_back( request.genre(id) );
|
||||
|
||||
// Now fetch requested data...
|
||||
|
||||
Wt::Dbo::Transaction transaction( _db.getSession() );
|
||||
|
||||
std::vector<std::string> artists
|
||||
= Database::Track::getArtists(_db.getSession(),
|
||||
genres,
|
||||
= Database::Track::getArtists(_db.getSession(), filter,
|
||||
request.batch_parameter().offset(), static_cast<int>(size) );
|
||||
|
||||
BOOST_FOREACH(const std::string& artist, artists)
|
||||
{
|
||||
response.add_artists()->set_name( std::string( boost::locale::conv::to_utf<char>(artist, "UTF-8") ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -200,20 +201,20 @@ AudioCollectionRequestHandler::processGetReleases(const AudioCollectionRequest::
|
||||
size = _maxListReleases;
|
||||
size = std::min(size, _maxListReleases);
|
||||
|
||||
SearchFilter filter;
|
||||
|
||||
std::vector<std::string> artists;
|
||||
for (int id = 0; id < request.artist_size(); ++id)
|
||||
artists.push_back( request.artist(id) );
|
||||
filter.exactMatch[SearchFilter::Field::Artist].push_back( request.artist(id) );
|
||||
|
||||
std::vector<std::string> genres;
|
||||
for (int id = 0; id < request.genre_size(); ++id)
|
||||
genres.push_back( request.genre(id) );
|
||||
filter.exactMatch[SearchFilter::Field::Genre].push_back( request.genre(id) );
|
||||
|
||||
Wt::Dbo::Transaction transaction( _db.getSession() );
|
||||
|
||||
std::vector<std::string> releases
|
||||
= Database::Track::getReleases( _db.getSession(),
|
||||
artists,
|
||||
genres,
|
||||
= Database::Track::getReleases( _db.getSession(), filter,
|
||||
request.batch_parameter().offset(), static_cast<int>(size));
|
||||
|
||||
BOOST_FOREACH(const std::string& release, releases)
|
||||
@@ -240,25 +241,24 @@ AudioCollectionRequestHandler::processGetTracks(const AudioCollectionRequest::Ge
|
||||
size = std::min(size, _maxListTracks);
|
||||
|
||||
// Get filters
|
||||
SearchFilter filter;
|
||||
|
||||
std::vector<std::string> artists;
|
||||
for (int id = 0; id < request.artist_size(); ++id)
|
||||
artists.push_back( request.artist(id) );
|
||||
filter.exactMatch[SearchFilter::Field::Artist].push_back( request.artist(id) );
|
||||
|
||||
std::vector<std::string> releases;
|
||||
for (int id = 0; id < request.release_size(); ++id)
|
||||
releases.push_back( request.release(id) );
|
||||
filter.exactMatch[SearchFilter::Field::Release].push_back( request.release(id) );
|
||||
|
||||
std::vector<std::string> genres;
|
||||
for (int id = 0; id < request.genre_size(); ++id)
|
||||
genres.push_back( request.genre(id) );
|
||||
filter.exactMatch[SearchFilter::Field::Genre].push_back( request.genre(id) );
|
||||
|
||||
Wt::Dbo::Transaction transaction( _db.getSession() );
|
||||
|
||||
Wt::Dbo::collection<Database::Track::pointer> tracks
|
||||
= Database::Track::getAll( _db.getSession(),
|
||||
artists,
|
||||
releases,
|
||||
genres,
|
||||
= Database::Track::getAll( _db.getSession(), filter,
|
||||
request.batch_parameter().offset(), static_cast<int>(size));
|
||||
|
||||
typedef Wt::Dbo::collection< Database::Track::pointer > Tracks;
|
||||
@@ -305,11 +305,11 @@ AudioCollectionRequestHandler::processGetCoverArt(const AudioCollectionRequest::
|
||||
case AudioCollectionRequest::GetCoverArt::TypeGetCoverArtRelease:
|
||||
if (request.has_release())
|
||||
{
|
||||
Wt::Dbo::collection<Database::Track::pointer> tracks = Database::Track::getAll(_db.getSession(),
|
||||
std::vector<std::string>(), // artist
|
||||
std::vector<std::string>(1, request.release()), // release
|
||||
std::vector<std::string>(), // genre
|
||||
-1, 1);
|
||||
SearchFilter filter;
|
||||
filter.exactMatch[SearchFilter::Field::Release].push_back(request.release());
|
||||
|
||||
Wt::Dbo::collection<Database::Track::pointer> tracks
|
||||
= Database::Track::getAll(_db.getSession(), filter, -1, 1 /* limit reuslt size */);
|
||||
|
||||
Wt::Dbo::collection<Database::Track::pointer>::iterator it = tracks.begin();
|
||||
|
||||
|
||||
+24
-14
@@ -92,25 +92,35 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::p
|
||||
|
||||
// If here is no account in the database, launch the first connection wizard
|
||||
if (firstConnection)
|
||||
{
|
||||
// Hack, use the auth widget builtin strings
|
||||
builtinLocalizedStrings().useBuiltin(skeletons::AuthStrings_xml1);
|
||||
|
||||
root()->addWidget( new Settings::FirstConnectionFormView(_sessionData));
|
||||
}
|
||||
createFirstConnectionUI();
|
||||
else
|
||||
{
|
||||
_sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent);
|
||||
createLmsUI();
|
||||
|
||||
LmsAuth *authWidget = new LmsAuth(_sessionData.getDatabaseHandler());
|
||||
}
|
||||
|
||||
authWidget->model()->addPasswordAuth(&Database::Handler::getPasswordService());
|
||||
authWidget->setRegistrationEnabled(false);
|
||||
void
|
||||
LmsApplication::createFirstConnectionUI()
|
||||
{
|
||||
// Hack, use the auth widget builtin strings
|
||||
builtinLocalizedStrings().useBuiltin(skeletons::AuthStrings_xml1);
|
||||
|
||||
authWidget->processEnvironment();
|
||||
root()->addWidget( new Settings::FirstConnectionFormView(_sessionData));
|
||||
}
|
||||
|
||||
root()->addWidget(authWidget);
|
||||
}
|
||||
void
|
||||
LmsApplication::createLmsUI()
|
||||
{
|
||||
|
||||
_sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent);
|
||||
|
||||
LmsAuth *authWidget = new LmsAuth(_sessionData.getDatabaseHandler());
|
||||
|
||||
authWidget->model()->addPasswordAuth(&Database::Handler::getPasswordService());
|
||||
authWidget->setRegistrationEnabled(false);
|
||||
|
||||
authWidget->processEnvironment();
|
||||
|
||||
root()->addWidget(authWidget);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ class LmsApplication : public Wt::WApplication
|
||||
private:
|
||||
|
||||
void handleAuthEvent(void);
|
||||
void createFirstConnectionUI();
|
||||
void createLmsUI();
|
||||
|
||||
SessionData _sessionData;
|
||||
|
||||
|
||||
@@ -308,6 +308,16 @@
|
||||
${apply-info}
|
||||
</div>
|
||||
</message>
|
||||
|
||||
<message id="mediaplayer-controls">
|
||||
<div class="btn-group" role="group" aria-label="...">
|
||||
${prev}
|
||||
${play}
|
||||
${pause}
|
||||
${next}
|
||||
</div>
|
||||
</message>
|
||||
|
||||
</messages>
|
||||
|
||||
|
||||
|
||||
+13
-13
@@ -29,7 +29,6 @@
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "TableFilter.hpp"
|
||||
#include "TableFilterGenre.hpp"
|
||||
#include "KeywordSearchFilter.hpp"
|
||||
|
||||
#include "Audio.hpp"
|
||||
@@ -49,19 +48,19 @@ _playQueue(nullptr)
|
||||
// Filters
|
||||
Wt::WHBoxLayout *filterLayout = new Wt::WHBoxLayout();
|
||||
|
||||
TableFilterGenre *filterGenre = new TableFilterGenre(_db);
|
||||
TableFilter *filterGenre = new TableFilter(_db, Database::SearchFilter::Field::Genre, { "Genre", "Tracks"} );
|
||||
filterLayout->addWidget(filterGenre);
|
||||
_filterChain.addFilter(filterGenre);
|
||||
|
||||
TableFilter *filterArtist = new TableFilter(_db, "track", "artist_name", "Artist");
|
||||
TableFilter *filterArtist = new TableFilter(_db, Database::SearchFilter::Field::Artist, {"Artist", "Tracks"} );
|
||||
filterLayout->addWidget(filterArtist);
|
||||
_filterChain.addFilter(filterArtist);
|
||||
|
||||
TableFilter *filterRelease = new TableFilter(_db, "track", "release_name", "Release");
|
||||
TableFilter *filterRelease = new TableFilter(_db, Database::SearchFilter::Field::Release, {"Release", "Tracks"});
|
||||
filterLayout->addWidget(filterRelease);
|
||||
_filterChain.addFilter(filterRelease);
|
||||
|
||||
mainLayout->addLayout(filterLayout, 0, 0);
|
||||
mainLayout->addLayout(filterLayout, 0, 1);
|
||||
// ENDOF(Filters)
|
||||
|
||||
// TODO ADD some stats (nb files, total duration, etc.)
|
||||
@@ -83,7 +82,7 @@ _playQueue(nullptr)
|
||||
|
||||
trackLayout->addLayout(trackControls);
|
||||
|
||||
mainLayout->addLayout(trackLayout, 1, 0);
|
||||
mainLayout->addLayout(trackLayout, 1, 1);
|
||||
|
||||
_filterChain.addFilter(_trackView);
|
||||
|
||||
@@ -95,6 +94,12 @@ _playQueue(nullptr)
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
|
||||
Wt::WVBoxLayout* playQueueLayout = new Wt::WVBoxLayout();
|
||||
playQueueLayout->setContentsMargins(5,5,5,5);
|
||||
|
||||
_mediaPlayer = new AudioMediaPlayer();
|
||||
playQueueLayout->addWidget(_mediaPlayer);
|
||||
|
||||
playQueueLayout->addWidget( _playQueue, 1);
|
||||
|
||||
Wt::WHBoxLayout* playlistControls = new Wt::WHBoxLayout();
|
||||
|
||||
@@ -140,17 +145,12 @@ _playQueue(nullptr)
|
||||
|
||||
playQueueLayout->addLayout(playlistControls);
|
||||
|
||||
playQueueLayout->addWidget( _playQueue, 1);
|
||||
|
||||
mainLayout->addLayout(playQueueLayout, 0, 1, 2, 1);
|
||||
mainLayout->addLayout(playQueueLayout, 0, 0, 2, 1);
|
||||
}
|
||||
|
||||
_mediaPlayer = new AudioMediaPlayer();
|
||||
mainLayout->addWidget(_mediaPlayer, 2, 0, 1, 2);
|
||||
|
||||
mainLayout->setRowStretch(1, 1);
|
||||
mainLayout->setRowResizable(0, true, Wt::WLength(200, Wt::WLength::Pixel));
|
||||
mainLayout->setColumnResizable(0, true);
|
||||
mainLayout->setColumnResizable(0, true, Wt::WLength(400, Wt::WLength::Pixel));
|
||||
|
||||
// Double click on track
|
||||
// Set the selected tracks to the play queue
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <Wt/WMediaPlayer>
|
||||
#include <Wt/WProgressBar>
|
||||
#include <Wt/WCheckBox>
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WHBoxLayout>
|
||||
#include <Wt/WVBoxLayout>
|
||||
|
||||
#include "AudioMediaPlayer.hpp"
|
||||
|
||||
@@ -30,65 +32,94 @@ AudioMediaPlayer::AudioMediaPlayer( Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_mediaResource(nullptr)
|
||||
{
|
||||
_mediaPlayer = new Wt::WMediaPlayer( Wt::WMediaPlayer::Audio, this );
|
||||
// _mediaPlayer->setAlternativeContent (new Wt::WText("You don't have HTML5 audio support!"));
|
||||
// _mediaPlayer->setOptions( Wt::WMediaPlayer::Autoplay );
|
||||
_mediaPlayer->addSource( Wt::WMediaPlayer::OGA, "" );
|
||||
this->setStyleClass("mediaplayer");
|
||||
this->setHeight(100);
|
||||
|
||||
Wt::WContainerWidget *sliderContainer = new Wt::WContainerWidget(this);
|
||||
Wt::WHBoxLayout *sliderLayout = new Wt::WHBoxLayout();
|
||||
sliderContainer->setLayout(sliderLayout);
|
||||
|
||||
sliderLayout->addWidget(_curTime = new Wt::WText("00:00:00"));
|
||||
_curTime->setLineHeight(30);
|
||||
sliderLayout->addWidget(_timeSlider = new Wt::WSlider( ), 1);
|
||||
_timeSlider->setHeight(30);
|
||||
sliderLayout->addWidget(_duration = new Wt::WText("00:00:00"));
|
||||
_duration->setLineHeight(30);
|
||||
|
||||
Wt::WContainerWidget *controlsContainer = new Wt::WContainerWidget(this);
|
||||
Wt::WHBoxLayout *controlsLayout = new Wt::WHBoxLayout();
|
||||
controlsContainer->setLayout(controlsLayout);
|
||||
|
||||
Wt::WContainerWidget *btnContainer = new Wt::WContainerWidget();
|
||||
|
||||
Wt::WTemplate *t = new Wt::WTemplate(Wt::WString::tr("mediaplayer-controls"), btnContainer);
|
||||
|
||||
Wt::WPushButton *prevBtn = new Wt::WPushButton("<<");
|
||||
t->bindWidget("prev", prevBtn);
|
||||
|
||||
_playBtn = new Wt::WPushButton("Play");
|
||||
t->bindWidget("play", _playBtn);
|
||||
_playBtn->setWidth(70);
|
||||
|
||||
_pauseBtn = new Wt::WPushButton("Pause");
|
||||
t->bindWidget("pause", _pauseBtn);
|
||||
_pauseBtn->setWidth(70);
|
||||
|
||||
Wt::WPushButton *nextBtn = new Wt::WPushButton(">>");
|
||||
t->bindWidget("next", nextBtn);
|
||||
|
||||
controlsLayout->addWidget(btnContainer);
|
||||
|
||||
_volumeSlider = new Wt::WSlider();
|
||||
_volumeSlider->setRange(0,100);
|
||||
_volumeSlider->setWidth(60);
|
||||
_volumeSlider->setMinimumSize(60, Wt::WLength::Auto);
|
||||
_volumeSlider->setHeight(30);
|
||||
controlsLayout->addWidget(_volumeSlider);
|
||||
|
||||
/* Wt::WText* name = new Wt::WText("My track name");
|
||||
controlsLayout->addWidget(name, 1);*/
|
||||
|
||||
Wt::WCheckBox *loop = new Wt::WCheckBox("Loop", controlsContainer);
|
||||
loop->changed().connect(std::bind([=] ()
|
||||
{
|
||||
_loop.emit( loop->checkState() == Wt::Checked);
|
||||
}));
|
||||
|
||||
Wt::WCheckBox *shuffle = new Wt::WCheckBox("Shuffle", controlsContainer);
|
||||
shuffle->changed().connect(std::bind([=] ()
|
||||
{
|
||||
_shuffle.emit( shuffle->checkState() == Wt::Checked);
|
||||
}));
|
||||
|
||||
controlsLayout->addWidget(loop);
|
||||
controlsLayout->addWidget(shuffle);
|
||||
|
||||
_mediaPlayer = new Wt::WMediaPlayer( Wt::WMediaPlayer::Audio, this );
|
||||
_mediaPlayer->addSource( Wt::WMediaPlayer::OGA, "" );
|
||||
_mediaPlayer->ended().connect(this, &AudioMediaPlayer::handleTrackEnded);
|
||||
|
||||
{
|
||||
Wt::WContainerWidget *container = new Wt::WContainerWidget(this);
|
||||
_mediaPlayer->setControlsWidget( 0 );
|
||||
_mediaPlayer->setButton(Wt::WMediaPlayer::Play, _playBtn);
|
||||
_mediaPlayer->setButton(Wt::WMediaPlayer::Pause, _pauseBtn);
|
||||
|
||||
Wt::WCheckBox *loop = new Wt::WCheckBox("Loop", this);
|
||||
loop->changed().connect(std::bind([=] ()
|
||||
{
|
||||
_loop.emit( loop->checkState() == Wt::Checked);
|
||||
}));
|
||||
_mediaPlayer->timeUpdated().connect(this, &AudioMediaPlayer::handleTimeUpdated);
|
||||
|
||||
Wt::WCheckBox *shuffle = new Wt::WCheckBox("Shuffle", this);
|
||||
shuffle->changed().connect(std::bind([=] ()
|
||||
{
|
||||
_shuffle.emit( shuffle->checkState() == Wt::Checked);
|
||||
}));
|
||||
_volumeSlider->setValue(_mediaPlayer->volume() * 100);
|
||||
|
||||
Wt::WPushButton *prevBtn = new Wt::WPushButton("<<", container );
|
||||
_playBtn = new Wt::WPushButton("Play", container );
|
||||
_pauseBtn = new Wt::WPushButton("Pause", container );
|
||||
Wt::WPushButton *nextBtn = new Wt::WPushButton(">>", container );
|
||||
nextBtn->clicked().connect(std::bind([=] ()
|
||||
{
|
||||
_mediaPlayer->stop();
|
||||
_playNext.emit();
|
||||
}));
|
||||
|
||||
_curTime = new Wt::WText(container);
|
||||
_timeSlider = new Wt::WSlider( container );
|
||||
_duration = new Wt::WText(container);
|
||||
|
||||
_volumeSlider = new Wt::WSlider( container );
|
||||
_volumeSlider->setRange(0,100);
|
||||
_volumeSlider->setValue(_mediaPlayer->volume() * 100);
|
||||
|
||||
_mediaPlayer->setControlsWidget( container );
|
||||
_mediaPlayer->setButton(Wt::WMediaPlayer::Play, _playBtn);
|
||||
_mediaPlayer->setButton(Wt::WMediaPlayer::Pause, _pauseBtn);
|
||||
|
||||
_mediaPlayer->setText( Wt::WMediaPlayer::CurrentTime, _curTime);
|
||||
_mediaPlayer->setText( Wt::WMediaPlayer::Duration, _duration);
|
||||
|
||||
_mediaPlayer->timeUpdated().connect(this, &AudioMediaPlayer::handleTimeUpdated);
|
||||
|
||||
nextBtn->clicked().connect(std::bind([=] ()
|
||||
{
|
||||
_mediaPlayer->stop();
|
||||
_playNext.emit();
|
||||
}));
|
||||
|
||||
prevBtn->clicked().connect(std::bind([=] ()
|
||||
{
|
||||
_mediaPlayer->stop();
|
||||
_playPrevious.emit();
|
||||
}));
|
||||
}
|
||||
|
||||
_timeSlider->valueChanged().connect(this, &AudioMediaPlayer::handlePlayOffset);
|
||||
_timeSlider->sliderMoved().connect(this, &AudioMediaPlayer::handleSliderMoved);
|
||||
prevBtn->clicked().connect(std::bind([=] ()
|
||||
{
|
||||
_mediaPlayer->stop();
|
||||
_playPrevious.emit();
|
||||
}));
|
||||
_timeSlider->valueChanged().connect(this, &AudioMediaPlayer::handlePlayOffset);
|
||||
// _timeSlider->sliderMoved().connect(this, &AudioMediaPlayer::handleSliderMoved);
|
||||
_timeSlider->setDisabled(true);
|
||||
|
||||
_volumeSlider->sliderMoved().connect(this, &AudioMediaPlayer::handleVolumeSliderMoved);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "database/SqlQuery.hpp"
|
||||
#include "database/AudioTypes.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
@@ -31,17 +31,20 @@ class Filter
|
||||
public:
|
||||
|
||||
struct Constraint {
|
||||
WhereClause where; // WHERE SQL clause
|
||||
std::vector<std::string> search;
|
||||
|
||||
typedef std::map<std::string, std::vector<std::string> > ColumnValues;
|
||||
ColumnValues columnValues;
|
||||
};
|
||||
|
||||
Filter() {}
|
||||
virtual ~Filter() {}
|
||||
|
||||
// Refresh filter using constraints created by parent filters
|
||||
virtual void refresh(const Constraint& constraint) = 0;
|
||||
virtual void refresh(Database::SearchFilter& filter) = 0;
|
||||
|
||||
// Update constraints for next filters
|
||||
virtual void getConstraint(Constraint& constraint) = 0;
|
||||
virtual void getConstraint(Database::SearchFilter& filter) = 0;
|
||||
|
||||
// Emitted when a constraint has changed
|
||||
Wt::Signal<void>& update() { return _update; };
|
||||
|
||||
@@ -50,7 +50,7 @@ FilterChain::updateFilters(std::size_t startIdx)
|
||||
|
||||
_refreshingFilters = true;
|
||||
|
||||
Filter::Constraint currentConstraint;
|
||||
Database::SearchFilter searchFilter;
|
||||
|
||||
for (std::size_t idFilter = 0; idFilter < _filters.size(); ++idFilter)
|
||||
{
|
||||
@@ -58,12 +58,12 @@ FilterChain::updateFilters(std::size_t startIdx)
|
||||
|
||||
// Apply contraints created by previous filters
|
||||
if (idFilter > startIdx) {
|
||||
filter->refresh(currentConstraint);
|
||||
filter->refresh(searchFilter);
|
||||
}
|
||||
|
||||
// Get constraints generated by this filter
|
||||
// (Note: adding accross successive calls)
|
||||
filter->getConstraint(currentConstraint);
|
||||
filter->getConstraint(searchFilter);
|
||||
}
|
||||
|
||||
_refreshingFilters = false;
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
* 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 "KeywordSearchFilter.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
@@ -34,15 +38,26 @@ KeywordSearchFilter::setText(const std::string& text)
|
||||
|
||||
// Get constraints created by this filter
|
||||
void
|
||||
KeywordSearchFilter::getConstraint(Constraint& constraint)
|
||||
KeywordSearchFilter::getConstraint(Database::SearchFilter& filter)
|
||||
{
|
||||
// No active search means no constaint!
|
||||
if (!_lastEmittedText.empty()) {
|
||||
const std::string bindText ("%%" + _lastEmittedText + "%%");
|
||||
constraint.where.And( WhereClause("(track.name like ? or track.release_name like ? or track.artist_name like ? or track.genre_list like ?)").bind(bindText).bind(bindText).bind(bindText).bind(bindText));
|
||||
}
|
||||
std::vector<std::string> values;
|
||||
boost::algorithm::split(values, _lastEmittedText, boost::is_any_of(" "), boost::token_compress_on);
|
||||
|
||||
// else no constraint!
|
||||
// For each part, do a global search on all searchable fields
|
||||
BOOST_FOREACH(std::string value, values)
|
||||
{
|
||||
Database::SearchFilter::FieldValues likeMatch;
|
||||
|
||||
likeMatch[Database::SearchFilter::Field::Artist].push_back(value);
|
||||
likeMatch[Database::SearchFilter::Field::Release].push_back(value);
|
||||
likeMatch[Database::SearchFilter::Field::Genre].push_back(value);
|
||||
likeMatch[Database::SearchFilter::Field::Track].push_back(value);
|
||||
|
||||
filter.likeMatches.push_back(likeMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -34,10 +34,10 @@ class KeywordSearchFilter : public Filter
|
||||
void setText(const std::string& text);
|
||||
|
||||
// Set constraint on this filter
|
||||
void refresh(const Constraint& constraint) {}
|
||||
void refresh(Database::SearchFilter& filter) {}
|
||||
|
||||
// Get constraints created by this filter
|
||||
void getConstraint(Constraint& constraint);
|
||||
void getConstraint(Database::SearchFilter& filter);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
+99
-52
@@ -20,35 +20,60 @@
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/random/uniform_int_distribution.hpp>
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WImage>
|
||||
#include <Wt/WLink>
|
||||
#include <Wt/WItemDelegate>
|
||||
#include <Wt/WStandardItem>
|
||||
#include <Wt/WFileResource>
|
||||
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "PlayQueue.hpp"
|
||||
|
||||
namespace {
|
||||
static const int CoverRole = Wt::UserRole + 1;
|
||||
|
||||
void modelForceRefreshDataRow(Wt::WStandardItemModel *model, int row)
|
||||
{
|
||||
for (int i = 0; i < model->columnCount(); ++i)
|
||||
model->setData(row, i, model->data(row, i));
|
||||
}
|
||||
namespace {
|
||||
|
||||
void swapRows(Wt::WStandardItemModel *model, int row1, int row2)
|
||||
{
|
||||
// Copy column by column
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Swap called row1 = " << row1 << ", row2 = " << row2 << ", CoverRole = " << CoverRole;
|
||||
|
||||
// Swap data column by column
|
||||
for (int i = 0; i < model->columnCount(); ++i)
|
||||
{
|
||||
boost::any tmp = model->data(row1, i); // 1 -> tmp
|
||||
model->setData(row1, i, model->data(row2, i)); // 2 -> 1
|
||||
model->setData(row2, i, tmp); // tmp-> 2
|
||||
Wt::WModelIndex index1 = model->index(row1, i);
|
||||
Wt::WModelIndex index2 = model->index(row2, i);
|
||||
|
||||
{
|
||||
auto tmp = model->itemData(index1); // 1 -> tmp
|
||||
model->setItemData(index1, model->itemData(index2)); // 2 -> 1
|
||||
model->setItemData(index2, tmp); // tmp-> 2
|
||||
}
|
||||
|
||||
// Workaround, do the same thing for the CoverRole
|
||||
{
|
||||
auto tmp = model->data(index1, CoverRole);
|
||||
model->setData(index1, model->data(index2, CoverRole), CoverRole);
|
||||
model->setData(index2, tmp, CoverRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
enum ColumnId
|
||||
{
|
||||
COLUMN_ID_TRACK_ID = 0,
|
||||
COLUMN_ID_POS = 1,
|
||||
COLUMN_ID_COVER = 2,
|
||||
COLUMN_ID_NAME = 3,
|
||||
COLUMN_ID_DURATION = 4
|
||||
};
|
||||
|
||||
static const int trackPosInvalid = -1;
|
||||
|
||||
class TrackSelector
|
||||
@@ -59,8 +84,8 @@ class TrackSelector
|
||||
void setShuffle(bool enable);
|
||||
void setLoop(bool enable) { _loop = enable; }
|
||||
|
||||
int getPrevious(void);
|
||||
int getNext(void);
|
||||
int previous(void);
|
||||
int next(void);
|
||||
int getCurrent(void);
|
||||
|
||||
// Set the internal pos thanks to the track pos
|
||||
@@ -86,11 +111,12 @@ class TrackSelector
|
||||
TrackSelector::TrackSelector()
|
||||
: _loop(false),
|
||||
_shuffle(false),
|
||||
_size(0),
|
||||
_curPos(0)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
TrackSelector::refreshPositions()
|
||||
{
|
||||
_trackPos.clear();
|
||||
@@ -102,7 +128,7 @@ TrackSelector::refreshPositions()
|
||||
_trackPos.push_back(i);
|
||||
|
||||
// Now shuffle
|
||||
// Perform size/2 permutations
|
||||
// Source: http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
||||
boost::random::mt19937 rng; // produces randomness out of thin air
|
||||
rng.seed(static_cast<unsigned int>(std::time(0)));
|
||||
|
||||
@@ -127,14 +153,18 @@ TrackSelector::setShuffle(bool enable)
|
||||
{
|
||||
_shuffle = enable;
|
||||
|
||||
if (_shuffle)
|
||||
setPosByRowId(_curPos);
|
||||
else
|
||||
setPos(_trackPos[_curPos]);
|
||||
if (_size != 0)
|
||||
{
|
||||
// Update the current index we are playing if we switch shuffle
|
||||
if (_shuffle)
|
||||
setPosByRowId(_curPos);
|
||||
else
|
||||
setPos(_trackPos[_curPos]);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
TrackSelector::getNext()
|
||||
TrackSelector::next()
|
||||
{
|
||||
if (_size == 0)
|
||||
return trackPosInvalid;
|
||||
@@ -153,7 +183,7 @@ TrackSelector::getNext()
|
||||
}
|
||||
|
||||
int
|
||||
TrackSelector::getPrevious()
|
||||
TrackSelector::previous()
|
||||
{
|
||||
if (_size == 0)
|
||||
return trackPosInvalid;
|
||||
@@ -200,55 +230,64 @@ TrackSelector::setSize(std::size_t size)
|
||||
class PlayQueueItemDelegate : public Wt::WItemDelegate
|
||||
{
|
||||
public:
|
||||
PlayQueueItemDelegate(Wt::WObject *parent = 0) : Wt::WItemDelegate(parent), _selectedRowPos(trackPosInvalid) {}
|
||||
|
||||
void setSelectedRowPos(int rowPos) { _selectedRowPos = rowPos; }
|
||||
PlayQueueItemDelegate(Wt::WObject *parent = 0) : Wt::WItemDelegate(parent) {}
|
||||
|
||||
Wt::WWidget* update(Wt::WWidget *widget, const Wt::WModelIndex &index, Wt::WFlags< Wt::ViewItemRenderFlag > flags)
|
||||
{
|
||||
Wt::WWidget* res = Wt::WItemDelegate::update(widget, index, flags);
|
||||
Wt::WWidget* res;
|
||||
|
||||
if (res && index.isValid())
|
||||
Wt::WString path = Wt::asString(index.data(CoverRole));
|
||||
if (!path.empty())
|
||||
{
|
||||
if (_selectedRowPos != trackPosInvalid && index.row() == _selectedRowPos)
|
||||
res->toggleStyleClass("playqueue-playing", true);
|
||||
// Create an image for this track
|
||||
Wt::WImage* image = new Wt::WImage( );
|
||||
Wt::WResource* resource;
|
||||
if (path != "none")
|
||||
resource = new CoverResource(boost::filesystem::path(path.toUTF8()), 64, image);
|
||||
else
|
||||
res->toggleStyleClass("playqueue-playing", false);
|
||||
resource = new Wt::WFileResource("image/jpeg", Wt::WApplication::instance()->docRoot() + "/images/unknown-cover.jpg", image);
|
||||
|
||||
image->setImageLink(Wt::WLink(resource));
|
||||
|
||||
res = image;
|
||||
res->setObjectName("z");
|
||||
}
|
||||
else
|
||||
res = Wt::WItemDelegate::update(widget, index, flags);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
int _selectedRowPos;
|
||||
};
|
||||
|
||||
|
||||
|
||||
PlayQueue::PlayQueue(Database::Handler& db, Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView(parent),
|
||||
_db(db),
|
||||
_curPlayedTrackPos(trackPosInvalid),
|
||||
_trackSelector(new TrackSelector())
|
||||
{
|
||||
_model = new Wt::WStandardItemModel(0, 4, this);
|
||||
_model = new Wt::WStandardItemModel(0, 5, this);
|
||||
|
||||
// 0 Column is hidden (track id)
|
||||
_model->setHeaderData(0, Wt::WString("#"));
|
||||
_model->setHeaderData(1, Wt::WString("#"));
|
||||
_model->setHeaderData(2, Wt::WString("Track"));
|
||||
_model->setHeaderData(3, Wt::WString("Duration"));
|
||||
_model->setHeaderData(COLUMN_ID_TRACK_ID, Wt::WString("#"));
|
||||
_model->setHeaderData(COLUMN_ID_POS, Wt::WString("#"));
|
||||
_model->setHeaderData(COLUMN_ID_COVER, Wt::WString("Cover"));
|
||||
_model->setHeaderData(COLUMN_ID_NAME, Wt::WString("Track"));
|
||||
_model->setHeaderData(COLUMN_ID_DURATION, Wt::WString("Duration"));
|
||||
|
||||
this->setModel(_model);
|
||||
this->setSelectionMode(Wt::ExtendedSelection);
|
||||
this->setSortingEnabled(false);
|
||||
this->setAlternatingRowColors(true);
|
||||
this->setRowHeight(64);
|
||||
this->setColumnWidth(COLUMN_ID_COVER, 64);
|
||||
this->setColumnWidth(COLUMN_ID_POS, 50);
|
||||
this->setColumnWidth(COLUMN_ID_DURATION, 75);
|
||||
|
||||
this->setColumnWidth(0, 50);
|
||||
this->setColumnWidth(1, 50);
|
||||
|
||||
this->setColumnHidden(0, true);
|
||||
this->setColumnHidden(COLUMN_ID_TRACK_ID, true);
|
||||
|
||||
_itemDelegate = new PlayQueueItemDelegate();
|
||||
this->setItemDelegate(_itemDelegate);
|
||||
@@ -318,10 +357,11 @@ PlayQueue::addTracks(const std::vector<Database::Track::id_type>& trackIds)
|
||||
|
||||
_model->insertRows(dataRow, 1);
|
||||
|
||||
_model->setData(dataRow, 0, track.id());
|
||||
_model->setData(dataRow, 1, dataRow + 1);
|
||||
_model->setData(dataRow, 2, track->getArtistName() + " - " + track->getName());
|
||||
_model->setData(dataRow, 3, track->getDuration());
|
||||
_model->setData(dataRow, COLUMN_ID_TRACK_ID, track.id(), Wt::UserRole);
|
||||
_model->setData(dataRow, COLUMN_ID_POS, dataRow + 1);
|
||||
_model->setData(dataRow, COLUMN_ID_COVER, track->hasCover() ? track->getPath() : "none", CoverRole);
|
||||
_model->setData(dataRow, COLUMN_ID_NAME, track->getArtistName() + " - " + track->getName());
|
||||
_model->setData(dataRow, COLUMN_ID_DURATION, track->getDuration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +391,7 @@ PlayQueue::playNext(void)
|
||||
|
||||
while (nbTries > 0)
|
||||
{
|
||||
int pos = _trackSelector->getNext();
|
||||
int pos = _trackSelector->next();
|
||||
if (pos == trackPosInvalid)
|
||||
break;
|
||||
|
||||
@@ -369,7 +409,7 @@ PlayQueue::playPrevious(void)
|
||||
|
||||
while (nbTries > 0)
|
||||
{
|
||||
int pos = _trackSelector->getPrevious();
|
||||
int pos = _trackSelector->previous();
|
||||
if (pos == trackPosInvalid)
|
||||
break;
|
||||
|
||||
@@ -386,7 +426,7 @@ PlayQueue::readTrack(int rowPos)
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Reading track at pos " << rowPos;
|
||||
Database::Track::id_type trackId = boost::any_cast<Database::Track::id_type>(_model->data(rowPos, 0));
|
||||
Database::Track::id_type trackId = boost::any_cast<Database::Track::id_type>(_model->data(rowPos, COLUMN_ID_TRACK_ID, Wt::UserRole));
|
||||
|
||||
Database::Track::pointer track = Database::Track::getById(_db.getSession(), trackId);
|
||||
if (track)
|
||||
@@ -395,6 +435,8 @@ PlayQueue::readTrack(int rowPos)
|
||||
|
||||
_sigTrackPlay.emit(track->getPath());
|
||||
|
||||
this->scrollTo( _model->index(_trackSelector->getCurrent(), 0));
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -407,15 +449,21 @@ PlayQueue::setPlayingTrackPos(int newRowPos)
|
||||
int oldRowPos = _curPlayedTrackPos;
|
||||
_curPlayedTrackPos = newRowPos;
|
||||
|
||||
_itemDelegate->setSelectedRowPos(newRowPos);
|
||||
|
||||
// Hack re-set the data in order to trigger the rerending of the widget
|
||||
// calling the update method of our custom item delegate gives bad results
|
||||
if (oldRowPos >= 0)
|
||||
modelForceRefreshDataRow(_model, oldRowPos);
|
||||
{
|
||||
_model->setData(oldRowPos, COLUMN_ID_POS, boost::any(), Wt::StyleClassRole);
|
||||
_model->setData(oldRowPos, COLUMN_ID_NAME, boost::any(), Wt::StyleClassRole);
|
||||
_model->setData(oldRowPos, COLUMN_ID_DURATION, boost::any(), Wt::StyleClassRole);
|
||||
}
|
||||
|
||||
if (newRowPos >= 0)
|
||||
modelForceRefreshDataRow(_model, newRowPos);
|
||||
{
|
||||
_model->setData(newRowPos, COLUMN_ID_POS, "playqueue-playing", Wt::StyleClassRole);
|
||||
_model->setData(newRowPos, COLUMN_ID_NAME, "playqueue-playing", Wt::StyleClassRole);
|
||||
_model->setData(newRowPos, COLUMN_ID_DURATION, "playqueue-playing", Wt::StyleClassRole);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -432,7 +480,6 @@ PlayQueue::delSelected(void)
|
||||
}
|
||||
|
||||
// If the current played track is removed, make sure to unselect it
|
||||
_itemDelegate->setSelectedRowPos(trackPosInvalid);
|
||||
_trackSelector->setSize(_model->rowCount());
|
||||
|
||||
renumber(minId, _model->rowCount() - 1);
|
||||
|
||||
@@ -19,28 +19,46 @@
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include "database/AudioTypes.hpp"
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "TableFilter.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
TableFilter::TableFilter(Database::Handler& db, std::string table, std::string field, const Wt::WString& displayName, Wt::WContainerWidget* parent)
|
||||
using namespace Database;
|
||||
|
||||
TableFilter::TableFilter(Database::Handler& db, Database::SearchFilter::Field field, std::vector<Wt::WString> columnNames, Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ),
|
||||
Filter(),
|
||||
_db(db),
|
||||
_table(table),
|
||||
_field(field)
|
||||
{
|
||||
_queryModel.setQuery( _db.getSession().query< ResultType >("select track." + _field + ", COUNT(DISTINCT track.id) from track GROUP BY track." + _field).orderBy("track." + _field));
|
||||
_queryModel.addColumn( "track." + _field, displayName);
|
||||
_queryModel.addColumn( "COUNT(DISTINCT track.id)", "Tracks");
|
||||
SearchFilter filter;
|
||||
|
||||
switch (field)
|
||||
{
|
||||
case Database::SearchFilter::Field::Artist:
|
||||
Track::updateArtistQueryModel(_db.getSession(), _queryModel, filter, columnNames);
|
||||
break;
|
||||
case Database::SearchFilter::Field::Release:
|
||||
Track::updateReleaseQueryModel(_db.getSession(), _queryModel, filter, columnNames);
|
||||
break;
|
||||
case Database::SearchFilter::Field::Genre:
|
||||
Genre::updateGenreQueryModel(_db.getSession(), _queryModel, filter, columnNames);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
this->setSelectionMode(Wt::ExtendedSelection);
|
||||
this->setSortingEnabled(false);
|
||||
this->setSortingEnabled(true);
|
||||
this->setAlternatingRowColors(true);
|
||||
this->setModel(&_queryModel);
|
||||
|
||||
this->setColumnWidth(1, 50);
|
||||
|
||||
this->selectionChanged().connect(this, &TableFilter::emitUpdate);
|
||||
|
||||
setLayoutSizeAware(true);
|
||||
@@ -66,52 +84,37 @@ _field(field)
|
||||
void
|
||||
TableFilter::layoutSizeChanged (int width, int height)
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "LAYOUT CHANGED!";
|
||||
|
||||
/* TODO
|
||||
std::size_t trackColumnSize = this->columnWidth(1).toPixels() + 30 ;
|
||||
std::size_t trackColumnSize = this->columnWidth(1).toPixels();
|
||||
// Set the remaining size for the name column
|
||||
this->setColumnWidth(0, width - 7 - trackColumnSize);
|
||||
*/
|
||||
|
||||
this->setColumnWidth(0, width - trackColumnSize - (7 * 2) - 2);
|
||||
}
|
||||
|
||||
// Set constraints on this filter
|
||||
void
|
||||
TableFilter::refresh(const Constraint& constraint)
|
||||
TableFilter::refresh(SearchFilter& filter)
|
||||
{
|
||||
SqlQuery sqlQuery;
|
||||
|
||||
sqlQuery.select("track." + _field + ", COUNT(DISTINCT track.id)");
|
||||
sqlQuery.from().And( FromClause("track")) ;
|
||||
sqlQuery.where().And(constraint.where); // Add constraint made by other filters
|
||||
sqlQuery.groupBy().And( "track." + _field); // Add constraint made by other filters
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << _table << ", generated query = '" << sqlQuery.get() << "'";
|
||||
|
||||
Wt::Dbo::Query<ResultType> query = _db.getSession().query<ResultType>( sqlQuery.get() );
|
||||
|
||||
query.orderBy(_table + "." + _field);
|
||||
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs()) {
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Binding value '" << bindArg << "'";
|
||||
query.bind(bindArg);
|
||||
switch (_field)
|
||||
{
|
||||
case Database::SearchFilter::Field::Artist:
|
||||
Track::updateArtistQueryModel(_db.getSession(), _queryModel, filter);
|
||||
break;
|
||||
case Database::SearchFilter::Field::Release:
|
||||
Track::updateReleaseQueryModel(_db.getSession(), _queryModel, filter);
|
||||
break;
|
||||
case Database::SearchFilter::Field::Genre:
|
||||
Genre::updateGenreQueryModel(_db.getSession(), _queryModel, filter);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_queryModel.setQuery( query, true );
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Finish !";
|
||||
}
|
||||
|
||||
// Get constraint created by this filter
|
||||
void
|
||||
TableFilter::getConstraint(Constraint& constraint)
|
||||
TableFilter::getConstraint(SearchFilter& filter)
|
||||
{
|
||||
Wt::WModelIndexSet indexSet = this->selectedIndexes();
|
||||
|
||||
// WHERE statement
|
||||
WhereClause clause;
|
||||
|
||||
BOOST_FOREACH(Wt::WModelIndex index, indexSet) {
|
||||
|
||||
if (!index.isValid())
|
||||
@@ -119,14 +122,10 @@ TableFilter::getConstraint(Constraint& constraint)
|
||||
|
||||
const ResultType& result = _queryModel.resultRow( index.row() );
|
||||
|
||||
// Get the track part
|
||||
std::string name(result.get<0>());
|
||||
std::string name = result.get<0>();
|
||||
|
||||
clause.Or(_table + "." + _field + " = ?").bind(name);
|
||||
filter.exactMatch[_field].push_back(name);
|
||||
}
|
||||
|
||||
// Adding our WHERE clause
|
||||
constraint.where.And( clause );
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -33,13 +33,13 @@ class TableFilter : public Wt::WTableView, public Filter
|
||||
{
|
||||
|
||||
public:
|
||||
TableFilter(Database::Handler& db, std::string table, std::string field, const Wt::WString& displayName, Wt::WContainerWidget* parent = 0);
|
||||
TableFilter(Database::Handler& db, Database::SearchFilter::Field field, std::vector<Wt::WString> displayName, Wt::WContainerWidget* parent = 0);
|
||||
|
||||
// Set constraints on this filter
|
||||
void refresh(const Constraint& constraint);
|
||||
void refresh(Database::SearchFilter& filter);
|
||||
|
||||
// Get constraints created by this filter
|
||||
void getConstraint(Constraint& constraint);
|
||||
void getConstraint(Database::SearchFilter& filter);
|
||||
|
||||
void layoutSizeChanged (int width, int height);
|
||||
|
||||
@@ -52,10 +52,9 @@ class TableFilter : public Wt::WTableView, public Filter
|
||||
SigDoubleClicked _sigDoubleClicked;
|
||||
|
||||
Database::Handler& _db;
|
||||
const std::string _table;
|
||||
const std::string _field;
|
||||
Database::SearchFilter::Field _field;
|
||||
|
||||
// Name, track count, special value that means 'all' if set to 1
|
||||
// Name, track count
|
||||
typedef boost::tuple<std::string, int> ResultType;
|
||||
Wt::Dbo::QueryModel< ResultType > _queryModel;
|
||||
|
||||
|
||||
@@ -1,133 +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 <boost/foreach.hpp>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "TableFilterGenre.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
TableFilterGenre::TableFilterGenre(Database::Handler& db, Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ),
|
||||
Filter(),
|
||||
_db(db)
|
||||
{
|
||||
_queryModel.setQuery( _db.getSession().query< ResultType >("select genre.name, COUNT(DISTINCT track.id) from genre INNER JOIN track_genre ON track_genre.genre_id = genre.id INNER JOIN track ON track.id = track_genre.track_id").orderBy("genre.name").groupBy("genre.name").orderBy("genre.name"));
|
||||
_queryModel.addColumn("genre.name", "Genre");
|
||||
_queryModel.addColumn("COUNT(DISTINCT track.id)", "tracks");
|
||||
|
||||
this->setSelectionMode(Wt::ExtendedSelection);
|
||||
this->setSortingEnabled(false);
|
||||
this->setAlternatingRowColors(true);
|
||||
this->setModel(&_queryModel);
|
||||
|
||||
this->selectionChanged().connect(this, &TableFilterGenre::emitUpdate);
|
||||
|
||||
setLayoutSizeAware(true);
|
||||
|
||||
_queryModel.setBatchSize(100);
|
||||
|
||||
// If an item is double clicked, select and emit signal
|
||||
this->doubleClicked().connect( std::bind([=] (Wt::WModelIndex idx, Wt::WMouseEvent evt)
|
||||
{
|
||||
if (!idx.isValid())
|
||||
return;
|
||||
|
||||
Wt::WModelIndexSet indexSet;
|
||||
indexSet.insert(idx);
|
||||
|
||||
this->setSelectedIndexes( indexSet );
|
||||
_sigDoubleClicked.emit( );
|
||||
}, std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
TableFilterGenre::layoutSizeChanged (int width, int height)
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "LAYOUT CHANGED!";
|
||||
|
||||
/* TODO
|
||||
std::size_t trackColumnSize = this->columnWidth(1).toPixels() + 30 ;
|
||||
// Set the remaining size for the name column
|
||||
this->setColumnWidth(0, width - 7 - trackColumnSize);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
// Set constraints on this filter
|
||||
void
|
||||
TableFilterGenre::refresh(const Constraint& constraint)
|
||||
{
|
||||
SqlQuery sqlQuery;
|
||||
|
||||
sqlQuery.select("genre.name, COUNT(DISTINCT track.id)");
|
||||
sqlQuery.from().And( std::string("genre INNER JOIN track_genre ON track_genre.genre_id = genre.id INNER JOIN track ON track.id = track_genre.track_id") );
|
||||
sqlQuery.where().And(constraint.where); // Add constraint made by other filters
|
||||
sqlQuery.groupBy().And( std::string("genre.name") );
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "genre, generated query = '" << sqlQuery.get() << "'";
|
||||
|
||||
Wt::Dbo::Query<ResultType> query = _db.getSession().query<ResultType>( sqlQuery.get() );
|
||||
|
||||
query.orderBy("genre.name");
|
||||
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs()) {
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Binding value '" << bindArg << "'";
|
||||
query.bind(bindArg);
|
||||
}
|
||||
|
||||
_queryModel.setQuery( query, true );
|
||||
|
||||
}
|
||||
|
||||
// Get constraint created by this filter
|
||||
void
|
||||
TableFilterGenre::getConstraint(Constraint& constraint)
|
||||
{
|
||||
Wt::WModelIndexSet indexSet = this->selectedIndexes();
|
||||
|
||||
// WHERE statement
|
||||
WhereClause clause;
|
||||
|
||||
BOOST_FOREACH(Wt::WModelIndex index, indexSet) {
|
||||
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
|
||||
const ResultType& result = _queryModel.resultRow( index.row() );
|
||||
|
||||
// Get the track part
|
||||
std::string name(result.get<0>());
|
||||
|
||||
if (name == "<None>")
|
||||
clause.Or( std::string("track.genre_list = ?") ).bind("");
|
||||
else
|
||||
clause.Or( std::string("track.genre_list LIKE ?") ).bind("%%" + name + "%%");
|
||||
}
|
||||
|
||||
// Adding our WHERE clause
|
||||
constraint.where.And( clause );
|
||||
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -1,65 +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 TABLE_FILTER_GENRE_HPP
|
||||
#define TABLE_FILTER_GENRE_HPP
|
||||
|
||||
|
||||
#include <Wt/Dbo/QueryModel>
|
||||
#include <Wt/WTableView>
|
||||
|
||||
#include "Filter.hpp"
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class TableFilterGenre : public Wt::WTableView, public Filter
|
||||
{
|
||||
|
||||
public:
|
||||
TableFilterGenre(Database::Handler& db, Wt::WContainerWidget* parent = 0);
|
||||
|
||||
// Set constraints on this filter
|
||||
void refresh(const Constraint& constraint);
|
||||
|
||||
// Get constraints created by this filter
|
||||
void getConstraint(Constraint& constraint);
|
||||
|
||||
void layoutSizeChanged (int width, int height);
|
||||
|
||||
typedef Wt::Signal<void> SigDoubleClicked;
|
||||
|
||||
SigDoubleClicked& sigDoubleClicked() { return _sigDoubleClicked; }
|
||||
|
||||
protected:
|
||||
|
||||
SigDoubleClicked _sigDoubleClicked;
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
// genre_name, count
|
||||
typedef boost::tuple<std::string, int> ResultType;
|
||||
Wt::Dbo::QueryModel< ResultType > _queryModel;
|
||||
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
|
||||
+22
-41
@@ -33,18 +33,25 @@ TrackView::TrackView( Database::Handler& db, Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ),
|
||||
_db(db)
|
||||
{
|
||||
_queryModel.setQuery(_db.getSession().query<ResultType>("select track from track").orderBy("track.artist_name,track.date,track.release_name,track.disc_number,track.track_number"));
|
||||
_queryModel.addColumn( "track.artist_name", "Artist" );
|
||||
_queryModel.addColumn( "track.release_name", "Album" );
|
||||
_queryModel.addColumn( "track.disc_number", "Disc #" );
|
||||
_queryModel.addColumn( "track.track_number", "Track #" );
|
||||
_queryModel.addColumn( "track.name", "Track" );
|
||||
_queryModel.addColumn( "track.duration", "Duration" );
|
||||
_queryModel.addColumn( "track.date", "Date" );
|
||||
_queryModel.addColumn( "track.original_date", "Original Date" );
|
||||
_queryModel.addColumn( "track.genre_list", "Genres" );
|
||||
|
||||
_queryModel.setBatchSize(500);
|
||||
static const std::vector<Wt::WString> columnNames =
|
||||
{
|
||||
"Artist",
|
||||
"Album",
|
||||
"Disc #",
|
||||
"Track #",
|
||||
"Track",
|
||||
"Duration",
|
||||
"Date",
|
||||
"Original Date",
|
||||
"Genres",
|
||||
};
|
||||
|
||||
Database::SearchFilter filter;
|
||||
|
||||
Database::Track::updateTracksQueryModel(_db.getSession(), _queryModel, filter, columnNames);
|
||||
|
||||
_queryModel.setBatchSize(300);
|
||||
|
||||
this->setSortingEnabled(true);
|
||||
this->setSelectionMode(Wt::ExtendedSelection);
|
||||
@@ -60,7 +67,6 @@ _db(db)
|
||||
this->setColumnWidth(6, 70); // Date
|
||||
this->setColumnWidth(7, 70); // Original Date
|
||||
this->setColumnWidth(8, 180); // Genres
|
||||
|
||||
// this->setOverflow(Wt::WContainerWidget::OverflowScroll, Wt::Vertical);
|
||||
|
||||
// Duration display
|
||||
@@ -102,28 +108,9 @@ _db(db)
|
||||
|
||||
// Set constraints created by parent filters
|
||||
void
|
||||
TrackView::refresh(const Constraint& constraint)
|
||||
TrackView::refresh(Database::SearchFilter& filter)
|
||||
{
|
||||
|
||||
SqlQuery sqlQuery;
|
||||
|
||||
sqlQuery.select( "track" );
|
||||
sqlQuery.from().And( FromClause("track"));
|
||||
sqlQuery.where().And(constraint.where);
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "TRACK REQ = '" << sqlQuery.get() << "'";
|
||||
|
||||
Wt::Dbo::Query<ResultType> query = _db.getSession().query<ResultType>( sqlQuery.get() );
|
||||
|
||||
query.groupBy("track").orderBy("track.artist_name,track.date,track.release_name,track.disc_number,track.track_number");
|
||||
|
||||
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs()) {
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Binding value '" << bindArg << "'";
|
||||
query.bind(bindArg);
|
||||
}
|
||||
|
||||
_queryModel.setQuery( query, true );
|
||||
|
||||
Database::Track::updateTracksQueryModel(_db.getSession(), _queryModel, filter);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -138,10 +125,7 @@ TrackView::getSelectedTracks(std::vector<Database::Track::id_type>& track_ids)
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
|
||||
const ResultType& result = _queryModel.resultRow( index.row() );
|
||||
|
||||
// Get the track part
|
||||
Wt::Dbo::ptr<Database::Track> track ( result.get<0>() );
|
||||
Database::Track::pointer track = _queryModel.resultRow( index.row() );
|
||||
|
||||
track_ids.push_back(track.id());
|
||||
}
|
||||
@@ -177,10 +161,7 @@ TrackView::getTracks(std::vector<Database::Track::id_type>& trackIds)
|
||||
|
||||
for (int i = 0; i < _queryModel.rowCount(); ++i)
|
||||
{
|
||||
const ResultType& result = _queryModel.resultRow( i );
|
||||
|
||||
// Get the track part
|
||||
Wt::Dbo::ptr<Database::Track> track ( result.get<0>() );
|
||||
Database::Track::pointer track = _queryModel.resultRow(i);
|
||||
|
||||
trackIds.push_back(track.id());
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ class TrackView : public Wt::WTableView, public Filter
|
||||
|
||||
// Filter interface
|
||||
// Set constraints created by parent filters
|
||||
void refresh(const Constraint& constraint);
|
||||
void refresh(Database::SearchFilter& filter);
|
||||
|
||||
// Create constraints for child filters (N/A)
|
||||
void getConstraint(Constraint& constraint) {}
|
||||
void getConstraint(Database::SearchFilter& filter) {}
|
||||
|
||||
// Get all the tracks that are currently selected
|
||||
void getSelectedTracks(std::vector<Database::Track::id_type>& trackIds);
|
||||
@@ -64,7 +64,7 @@ class TrackView : public Wt::WTableView, public Filter
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
typedef boost::tuple<Database::Track::pointer> ResultType;
|
||||
typedef Database::Track::pointer ResultType;
|
||||
Wt::Dbo::QueryModel< ResultType > _queryModel;
|
||||
Wt::WTableView* _tableView;
|
||||
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
|
||||
.playqueue-playing {
|
||||
font-weight: bold;
|
||||
.main-nav {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.Wt-hrh2 {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.Wt-vrh2 {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
div.contents {
|
||||
padding: 0px 12px 6px;
|
||||
}
|
||||
|
||||
.playqueue-playing {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.mediaplayer {
|
||||
background-color: #ccc;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
|
||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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 <boost/foreach.hpp>
|
||||
|
||||
#include <Wt/Http/Response>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "cover/CoverArtGrabber.hpp"
|
||||
|
||||
#include "CoverResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
CoverResource::CoverResource(const boost::filesystem::path& path, std::size_t size, Wt::WObject *parent)
|
||||
: Wt::WResource(parent),
|
||||
_path(path),
|
||||
_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
CoverResource:: ~CoverResource()
|
||||
{
|
||||
beingDeleted();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CoverResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response)
|
||||
{
|
||||
if (_data.empty())
|
||||
{
|
||||
std::vector<CoverArt::CoverArt> covers = CoverArt::Grabber::getFromTrack( _path );
|
||||
|
||||
BOOST_FOREACH(CoverArt::CoverArt& cover, covers)
|
||||
{
|
||||
cover.scale(_size);
|
||||
_data = cover.getData();
|
||||
_mimeType = cover.getMimeType();
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO if not found fallback on an empty image
|
||||
}
|
||||
|
||||
response.setMimeType(_mimeType);
|
||||
|
||||
for (unsigned int i = 0; i < _data.size(); ++i)
|
||||
response.out().put(_data[i]);
|
||||
}
|
||||
|
||||
|
||||
} // namespace UserInterface
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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 <boost/foreach.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <Wt/WResource>
|
||||
|
||||
#include "database/AudioTypes.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class CoverResource : public Wt::WResource
|
||||
{
|
||||
public:
|
||||
CoverResource(const boost::filesystem::path& p, // track to get cover from
|
||||
std::size_t size, // size * size pixels
|
||||
Wt::WObject *parent = 0);
|
||||
~CoverResource();
|
||||
|
||||
void handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response);
|
||||
|
||||
private:
|
||||
|
||||
boost::filesystem::path _path;
|
||||
std::size_t _size;
|
||||
std::string _mimeType;
|
||||
|
||||
std::vector<unsigned char> _data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace UserInterface
|
||||
@@ -51,6 +51,7 @@ _sessionData(sessionData)
|
||||
contents->setStyleClass("contents");
|
||||
contents->setOverflow(WContainerWidget::OverflowHidden);
|
||||
|
||||
// TODO menu style on hover
|
||||
Wt::WMenu *menu = new Wt::WMenu(contents, Wt::Vertical);
|
||||
menu->setStyleClass("nav nav-pills nav-stacked submenu");
|
||||
menu->setWidth(150);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Wt/WStringListModel>
|
||||
#include <Wt/WFormModel>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WCheckBox>
|
||||
|
||||
@@ -99,7 +99,7 @@ class AudioFormModel : public Wt::WFormModel
|
||||
|
||||
Database::User::pointer user = Database::User::getById(_db.getSession(), _userId);
|
||||
|
||||
_bitrateModel = new Wt::WStringListModel();
|
||||
_bitrateModel = new Wt::WStringListModel(this);
|
||||
BOOST_FOREACH(std::size_t bitrate, Database::User::audioBitrates)
|
||||
{
|
||||
if (user && bitrate <= user->getMaxAudioBitrate())
|
||||
|
||||
@@ -269,12 +269,12 @@ class UserFormModel : public Wt::WFormModel
|
||||
void initializeModels()
|
||||
{
|
||||
// AUDIO
|
||||
_audioBitrateModel = new Wt::WStringListModel();
|
||||
_audioBitrateModel = new Wt::WStringListModel(this);
|
||||
BOOST_FOREACH(std::size_t bitrate, Database::User::audioBitrates)
|
||||
_audioBitrateModel->addString( Wt::WString("{1}").arg( bitrate / 1000 ) ); // in kbps
|
||||
|
||||
// VIDEO
|
||||
_videoBitrateModel = new Wt::WStringListModel();
|
||||
_videoBitrateModel = new Wt::WStringListModel(this);
|
||||
BOOST_FOREACH(std::size_t bitrate, Database::User::videoBitrates)
|
||||
_videoBitrateModel->addString( Wt::WString("{1}").arg( bitrate / 1000 ) ); // in kbps
|
||||
|
||||
|
||||
@@ -810,6 +810,7 @@ int main()
|
||||
std::vector<TrackInfo> tracks;
|
||||
client.getTracks(tracks);
|
||||
|
||||
std::cout << "Got " << tracks.size() << " tracks!" << std::endl;
|
||||
BOOST_FOREACH(const TrackInfo& track, tracks)
|
||||
std::cout << "Track: '" << track << "'" << std::endl;
|
||||
|
||||
@@ -820,10 +821,11 @@ int main()
|
||||
// Get the artists for each genre
|
||||
BOOST_FOREACH(const GenreInfo& genre, genres)
|
||||
{
|
||||
std::cout << "Getting artists from genre '" << genre.name << "'" << std::endl;
|
||||
std::cout << "Getting artists from genre '" << genre.name << "'... ";
|
||||
std::vector<ArtistInfo> artists;
|
||||
client.getArtists(artists, std::vector<std::string>(1, genre.name));
|
||||
|
||||
std::cout << "Found " << artists.size() << " artists!" << std::endl;
|
||||
BOOST_FOREACH(const ArtistInfo& artist, artists)
|
||||
std::cout << "Genre '" << genre.name << "' -> Artist: " << artist << std::endl;
|
||||
}
|
||||
@@ -834,10 +836,11 @@ int main()
|
||||
std::cout << "Getting release for each artist..." << std::endl;
|
||||
BOOST_FOREACH(const ArtistInfo& artist, artists)
|
||||
{
|
||||
std::cout << "Getting release from artist '" << artist.name << "'" << std::endl;
|
||||
std::cout << "Getting release from artist '" << artist.name << "'... ";
|
||||
std::vector<ReleaseInfo> releases;
|
||||
client.getReleases(releases, std::vector<std::string>(1, artist.name) );
|
||||
|
||||
std::cout << "Found " << releases.size() << " releases!" << std::endl;
|
||||
BOOST_FOREACH(const ReleaseInfo& release, releases)
|
||||
std::cout << "Artist '" << artist.name << "' -> Release: '" << release << "'" << std::endl;
|
||||
}
|
||||
@@ -848,10 +851,11 @@ int main()
|
||||
std::cout << "Getting release for each genre..." << std::endl;
|
||||
BOOST_FOREACH(const GenreInfo& genre, genres)
|
||||
{
|
||||
std::cout << "Getting release from genre '" << genre.name << "'" << std::endl;
|
||||
std::cout << "Getting release from genre '" << genre.name << "'... ";
|
||||
std::vector<ReleaseInfo> releases;
|
||||
client.getReleases(releases, std::vector<std::string>(), std::vector<std::string>(1, genre.name));
|
||||
|
||||
std::cout << "Found " << releases.size() << " releases!" << std::endl;
|
||||
BOOST_FOREACH(const ReleaseInfo& release, releases)
|
||||
std::cout << "Genre '" << genre.name << "' -> Release: '" << release << "'" << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user