[UI/MOBILE] WIP on internal path support
This commit is contained in:
+3
-1
@@ -37,13 +37,15 @@ lms_SOURCES = \
|
||||
$(srcdir)/ui/audio/mobile/MobileAudio.cpp \
|
||||
$(srcdir)/ui/audio/mobile/PreviewSearchView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/ReleaseSearch.cpp \
|
||||
$(srcdir)/ui/audio/mobile/ReleaseSearchView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/ReleaseView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/TrackSearch.cpp \
|
||||
$(srcdir)/ui/audio/mobile/TrackSearchView.cpp \
|
||||
$(srcdir)/ui/common/DirectoryValidator.cpp \
|
||||
$(srcdir)/ui/common/InputRange.cpp \
|
||||
$(srcdir)/ui/common/LineEdit.cpp \
|
||||
$(srcdir)/ui/resource/AvConvTranscodeStreamResource.cpp \
|
||||
$(srcdir)/ui/resource/CoverResource.cpp \
|
||||
$(srcdir)/ui/resource/ImageResource.cpp \
|
||||
$(srcdir)/ui/resource/TranscodeResource.cpp \
|
||||
$(srcdir)/ui/settings/Settings.cpp \
|
||||
$(srcdir)/ui/settings/SettingsAccountFormView.cpp \
|
||||
|
||||
@@ -45,6 +45,12 @@ Artist::getByMBID(Wt::Dbo::Session& session, const std::string& mbid)
|
||||
return session.find<Artist>().where("mbid = ?").bind(mbid);
|
||||
}
|
||||
|
||||
Artist::pointer
|
||||
Artist::getById(Wt::Dbo::Session& session, Artist::id_type id)
|
||||
{
|
||||
return session.find<Artist>().where("id = ?").bind(id);
|
||||
}
|
||||
|
||||
Artist::pointer
|
||||
Artist::create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID)
|
||||
{
|
||||
@@ -84,6 +90,24 @@ Artist::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset,
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
std::vector<Artist::pointer>
|
||||
Artist::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size, bool& moreResults)
|
||||
{
|
||||
auto res = getByFilter(session, filter, offset, size + 1);
|
||||
|
||||
if (size != -1 && res.size() == static_cast<std::size_t>(size) + 1)
|
||||
{
|
||||
moreResults = true;
|
||||
res.pop_back();
|
||||
}
|
||||
else
|
||||
moreResults = false;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<Wt::Dbo::ptr<Release> >
|
||||
Artist::getReleases() const
|
||||
{
|
||||
|
||||
@@ -51,6 +51,7 @@ class Artist : public Wt::Dbo::Dbo<Artist>
|
||||
static pointer getNone(Wt::Dbo::Session& session); // Special entry
|
||||
static std::vector<pointer> getByName(Wt::Dbo::Session& session, const std::string& name);
|
||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size, bool& moreExpected);
|
||||
|
||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, int size = -1);
|
||||
static std::vector<pointer> getAllOrphans(Wt::Dbo::Session& session);
|
||||
|
||||
@@ -140,6 +140,22 @@ Release::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset,
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
std::vector<Release::pointer>
|
||||
Release::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size, bool& moreResults)
|
||||
{
|
||||
auto res = getByFilter(session, filter, offset, size + 1);
|
||||
|
||||
if (size != -1 && res.size() == static_cast<std::size_t>(size) + 1)
|
||||
{
|
||||
moreResults = true;
|
||||
res.pop_back();
|
||||
}
|
||||
else
|
||||
moreResults = false;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
Release::getReleaseYear(bool original) const
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ class Release : public Wt::Dbo::Dbo<Release>
|
||||
static std::vector<pointer> getAllOrphans(Wt::Dbo::Session& session);
|
||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session, int offset, int size);
|
||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size, bool& moreExpected);
|
||||
|
||||
// Create
|
||||
static pointer create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID = "");
|
||||
|
||||
@@ -159,6 +159,22 @@ Track::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset, i
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
std::vector<Track::pointer>
|
||||
Track::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size, bool& moreResults)
|
||||
{
|
||||
auto res = getByFilter(session, filter, offset, size + 1);
|
||||
|
||||
if (size != -1 && res.size() == static_cast<std::size_t>(size) + 1)
|
||||
{
|
||||
moreResults = true;
|
||||
res.pop_back();
|
||||
}
|
||||
else
|
||||
moreResults = false;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
Track::updateUIQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel< UIQueryResult >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames)
|
||||
{
|
||||
|
||||
@@ -105,6 +105,7 @@ class Track
|
||||
static pointer getById(Wt::Dbo::Session& session, id_type id);
|
||||
static pointer getByMBID(Wt::Dbo::Session& session, const std::string& MBID);
|
||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size, bool &moreResults);
|
||||
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
|
||||
static std::vector<boost::filesystem::path> getAllPaths(Wt::Dbo::Session& session);
|
||||
static std::vector<pointer> getMBIDDuplicates(Wt::Dbo::Session& session);
|
||||
|
||||
+25
-11
@@ -48,6 +48,18 @@ namespace skeletons {
|
||||
extern const char *AuthStrings_xml1;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool agentIsMobile()
|
||||
{
|
||||
const Wt::WEnvironment& env = Wt::WApplication::instance()->environment();
|
||||
return (env.agentIsIEMobile()
|
||||
|| env.agentIsMobileWebKit()
|
||||
|| env.userAgent().find("Mobile") != std::string::npos // Workaround for firefox
|
||||
|| env.userAgent().find("Tablet") != std::string::npos // Workaround for firefox
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
@@ -76,9 +88,9 @@ LmsApplication::instance()
|
||||
LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool)
|
||||
: Wt::WApplication(env),
|
||||
_db(connectionPool),
|
||||
_coverResource(nullptr)
|
||||
_imageResource(nullptr),
|
||||
_transcodeResource(nullptr)
|
||||
{
|
||||
|
||||
Wt::WBootstrapTheme *bootstrapTheme = new Wt::WBootstrapTheme(this);
|
||||
bootstrapTheme->setVersion(Wt::WBootstrapTheme::Version3);
|
||||
bootstrapTheme->setResponsive(true);
|
||||
@@ -106,7 +118,6 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti
|
||||
createFirstConnectionUI();
|
||||
else
|
||||
createLmsUI();
|
||||
|
||||
}
|
||||
|
||||
Database::Handler& DbHandler()
|
||||
@@ -128,9 +139,9 @@ Database::User::pointer CurrentUser()
|
||||
return DbHandler().getCurrentUser();
|
||||
}
|
||||
|
||||
CoverResource* SessionCoverResource()
|
||||
ImageResource* SessionImageResource()
|
||||
{
|
||||
return LmsApplication::instance()->getCoverResource();
|
||||
return LmsApplication::instance()->getImageResource();
|
||||
}
|
||||
|
||||
TranscodeResource* SessionTranscodeResource()
|
||||
@@ -150,7 +161,7 @@ LmsApplication::createFirstConnectionUI()
|
||||
void
|
||||
LmsApplication::createLmsUI()
|
||||
{
|
||||
_coverResource = new CoverResource(_db, root());
|
||||
_imageResource = new ImageResource(_db, root());
|
||||
_transcodeResource = new TranscodeResource(_db, root());
|
||||
|
||||
DbHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent);
|
||||
@@ -163,8 +174,6 @@ LmsApplication::createLmsUI()
|
||||
authWidget->processEnvironment();
|
||||
|
||||
root()->addWidget(authWidget);
|
||||
|
||||
setInternalPath("/");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -186,7 +195,7 @@ LmsApplication::handleAuthEvent(void)
|
||||
setConfirmCloseMessage("Closing LMS. Are you sure?");
|
||||
|
||||
// Handle internal paths
|
||||
// this->setInternalPath("audio");
|
||||
// setInternalPath("audio");
|
||||
|
||||
// Create a Vertical layout: top is the nav bar, bottom is the contents
|
||||
Wt::WVBoxLayout *layout = new Wt::WVBoxLayout(this->root());
|
||||
@@ -207,11 +216,16 @@ LmsApplication::handleAuthEvent(void)
|
||||
LineEdit *searchEdit = new LineEdit(500);
|
||||
navigation->bindWidget("search", searchEdit);
|
||||
searchEdit->setEmptyText("Search...");
|
||||
searchEdit->addStyleClass("navbar-form navbar-nav");
|
||||
AearchEdit->addStyleClass("navbar-form navbar-nav");
|
||||
searchEdit->setWidth(150);
|
||||
// TODO add a span with a search icon
|
||||
|
||||
Mobile::Audio *audio = new Mobile::Audio();
|
||||
Audio *audio;
|
||||
|
||||
if (agentIsMobile())
|
||||
audio = new Mobile::Audio();
|
||||
else
|
||||
audio = new Desktop::Audio();
|
||||
|
||||
menu->addItem("Audio", audio);
|
||||
#if defined HAVE_VIDEO
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <Wt/Dbo/SqlConnectionPool>
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
#include "resource/CoverResource.hpp"
|
||||
#include "resource/ImageResource.hpp"
|
||||
#include "resource/TranscodeResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
@@ -40,7 +40,7 @@ class LmsApplication : public Wt::WApplication
|
||||
LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool);
|
||||
|
||||
// Session application data
|
||||
CoverResource* getCoverResource() { return _coverResource; }
|
||||
ImageResource* getImageResource() { return _imageResource; }
|
||||
TranscodeResource* getTranscodeResource() { return _transcodeResource; }
|
||||
Database::Handler& getDbHandler() { return _db;}
|
||||
|
||||
@@ -51,7 +51,7 @@ class LmsApplication : public Wt::WApplication
|
||||
void createLmsUI();
|
||||
|
||||
Database::Handler _db;
|
||||
CoverResource* _coverResource;
|
||||
ImageResource* _imageResource;
|
||||
TranscodeResource* _transcodeResource;
|
||||
};
|
||||
|
||||
@@ -64,7 +64,7 @@ Wt::Dbo::Session& DboSession();
|
||||
const Wt::Auth::User& CurrentAuthUser();
|
||||
Database::User::pointer CurrentUser();
|
||||
|
||||
CoverResource *SessionCoverResource();
|
||||
ImageResource *SessionImageResource();
|
||||
TranscodeResource *SessionTranscodeResource();
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -77,7 +77,7 @@ AudioPlayer::loadTrack(Database::Track::id_type trackId)
|
||||
|
||||
bindString("track", Wt::WString::fromUTF8(track->getName()));
|
||||
bindString("artist", Wt::WString::fromUTF8(track->getArtist()->getName()));
|
||||
_cover->setImageLink(SessionCoverResource()->getTrackUrl(trackId, 64));
|
||||
_cover->setImageLink(SessionImageResource()->getTrackUrl(trackId, 64));
|
||||
|
||||
std::string durationFormat = track->getDuration().total_seconds() < 3600 ? "%M:%S" : "%H:%M:%S";
|
||||
|
||||
@@ -140,7 +140,7 @@ AudioPlayer::AudioPlayer(Wt::WContainerWidget *parent)
|
||||
|
||||
_cover = new Wt::WImage();
|
||||
bindWidget("cover", _cover);
|
||||
_cover->setImageLink(SessionCoverResource()->getUnknownTrackUrl(64));
|
||||
_cover->setImageLink(SessionImageResource()->getUnknownTrackUrl(64));
|
||||
|
||||
InputRange *seekbar = new InputRange();
|
||||
seekbar->addStyleClass("mediaplayer-seekbar");
|
||||
|
||||
@@ -387,7 +387,7 @@ PlayQueue::addTracks(const std::vector<Database::Track::id_type>& trackIds)
|
||||
_model->setData(dataRow, COLUMN_ID_TRACK_ID, track.id(), Wt::UserRole);
|
||||
|
||||
std::string coverUrl;
|
||||
coverUrl = LmsApplication::instance()->getCoverResource()->getTrackUrl(track.id(), 64);
|
||||
coverUrl = SessionImageResource()->getTrackUrl(track.id(), 64);
|
||||
|
||||
_model->setData(dataRow, COLUMN_ID_COVER, coverUrl, Wt::DecorationRole);
|
||||
_model->setData(dataRow, COLUMN_ID_COVER, std::string("playqueue-cover"), Wt::StyleClassRole);
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Desktop {
|
||||
|
||||
|
||||
@@ -29,23 +29,19 @@
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
ArtistSearch::ArtistSearch(Wt::WString title, Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_count(0)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
Wt::WTemplate* artistSearch = new Wt::WTemplate(this);
|
||||
artistSearch->setTemplateText(Wt::WString::tr("wa-artist-search"));
|
||||
Wt::WTemplate* t = new Wt::WTemplate(this);
|
||||
t->setTemplateText(Wt::WString::tr("wa-artist-search"));
|
||||
|
||||
Wt::WTemplate *titleTemplate = new Wt::WTemplate(this);
|
||||
titleTemplate->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||
titleTemplate->bindString("text", title);
|
||||
|
||||
artistSearch->bindWidget("title", titleTemplate);
|
||||
t->bindWidget("title", titleTemplate);
|
||||
|
||||
_contents = new Wt::WContainerWidget();
|
||||
artistSearch->bindWidget("release-container", _contents );
|
||||
t->bindWidget("contents", _contents );
|
||||
|
||||
_showMore = new Wt::WTemplate();
|
||||
_showMore->setTemplateText(Wt::WString::tr("mobile-search-more"));
|
||||
@@ -54,15 +50,13 @@ _count(0)
|
||||
_showMore->clicked().connect(std::bind([=] {
|
||||
_sigShowMore.emit();
|
||||
}));
|
||||
|
||||
artistSearch->bindWidget("show-more", _showMore);
|
||||
t->bindWidget("show-more", _showMore);
|
||||
}
|
||||
|
||||
void
|
||||
ArtistSearch::clear()
|
||||
{
|
||||
_contents->clear();
|
||||
_count = 0;
|
||||
_showMore->hide();
|
||||
}
|
||||
|
||||
@@ -75,38 +69,24 @@ ArtistSearch::search(Database::SearchFilter filter, size_t nb)
|
||||
addResults(nb);
|
||||
}
|
||||
|
||||
static
|
||||
std::vector<Artist::pointer>
|
||||
getArtists(SearchFilter filter, size_t offset, size_t nb, bool &moreResults)
|
||||
{
|
||||
std::vector<Artist::pointer> artists = Artist::getByFilter(DboSession(), filter, offset, nb + 1);
|
||||
|
||||
if (artists.size() == nb + 1)
|
||||
{
|
||||
moreResults = true;
|
||||
artists.pop_back();
|
||||
}
|
||||
else
|
||||
moreResults = false;
|
||||
|
||||
return artists;
|
||||
}
|
||||
|
||||
void
|
||||
ArtistSearch::addResults(std::size_t nb)
|
||||
{
|
||||
using namespace Database;
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
bool moreResults;
|
||||
std::vector<Artist::pointer> artists = getArtists(_filter, _count, nb, moreResults);
|
||||
std::vector<Artist::pointer> artists = Artist::getByFilter(DboSession(), _filter, _contents->count(), nb, moreResults);
|
||||
|
||||
for (Artist::pointer artist : artists)
|
||||
{
|
||||
Wt::WTemplate* res = new Wt::WTemplate(_contents);
|
||||
res->setTemplateText(Wt::WString::tr("wa-artist-res"));
|
||||
res->setTemplateText(Wt::WString::tr("wa-artist-search-res"));
|
||||
|
||||
Wt::WAnchor *coverAnchor = new Wt::WAnchor(Wt::WLink(Wt:: WLink::InternalPath, "/audio/artist/" + std::to_string(artist.id())));
|
||||
Wt::WImage *artistImg = new Wt::WImage(coverAnchor);
|
||||
artistImg->setImageLink( SessionImageResource()->getArtistUrl(artist.id(), 512));
|
||||
artistImg->setStyleClass("center-block"); // TODO move in css?
|
||||
artistImg->setStyleClass("release_res_shadow release_img-responsive"); // TODO move in css?
|
||||
|
||||
@@ -114,8 +94,6 @@ ArtistSearch::addResults(std::size_t nb)
|
||||
res->bindString("name", Wt::WString::fromUTF8(artist->getName(), Wt::PlainText));
|
||||
}
|
||||
|
||||
_count += artists.size();
|
||||
|
||||
if (moreResults)
|
||||
_showMore->show();
|
||||
else
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
@@ -45,11 +45,22 @@ ArtistView::ArtistView(Wt::WContainerWidget *parent)
|
||||
|
||||
Artist::id_type id;
|
||||
if (readAs(strId, id))
|
||||
releases->search(SearchFilter::ById(SearchFilter::Field::Artist, id), 20);
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
auto artist = Artist::getById(DboSession(), id);
|
||||
releases->search(SearchFilter::ById(SearchFilter::Field::Artist, id), 20, artist ? Wt::WString::fromUTF8(artist->getName()) : "Unknown artist");
|
||||
}
|
||||
|
||||
}, std::placeholders::_1));
|
||||
}
|
||||
|
||||
Wt::WLink
|
||||
ArtistView::getLink(Database::Artist::id_type id)
|
||||
{
|
||||
return Wt::WLink(Wt::WLink::InternalPath, "/audio/artist/" + std::to_string(id));
|
||||
}
|
||||
|
||||
} //namespace Mobile
|
||||
} //namespace UserInterface
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WLink>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
@@ -27,6 +30,9 @@ namespace Mobile {
|
||||
class ArtistView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
static Wt::WLink getLink(Database::Artist::id_type id);
|
||||
|
||||
ArtistView(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
};
|
||||
|
||||
@@ -29,10 +29,11 @@
|
||||
#include "audio/AudioPlayer.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "ArtistSearchView.hpp"
|
||||
#include "PreviewSearchView.hpp"
|
||||
#include "ReleaseSearch.hpp"
|
||||
#include "TrackSearch.hpp"
|
||||
#include "ArtistSearchView.hpp"
|
||||
#include "ReleaseSearchView.hpp"
|
||||
#include "TrackSearchView.hpp"
|
||||
|
||||
#include "ArtistView.hpp"
|
||||
#include "ReleaseView.hpp"
|
||||
|
||||
@@ -84,8 +85,8 @@ Audio::Audio(Wt::WContainerWidget *parent)
|
||||
// Same order as WidgetIdxXXX
|
||||
stack->addWidget(new PreviewSearchView());
|
||||
stack->addWidget(new ArtistSearchView());
|
||||
stack->addWidget(new ReleaseSearch());
|
||||
stack->addWidget(new TrackSearch());
|
||||
stack->addWidget(new ReleaseSearchView());
|
||||
stack->addWidget(new TrackSearchView());
|
||||
stack->addWidget(new ArtistView());
|
||||
stack->addWidget(new ReleaseView());
|
||||
|
||||
|
||||
@@ -60,6 +60,14 @@ PreviewSearchView::PreviewSearchView(Wt::WContainerWidget* parent)
|
||||
wApp->setInternalPath(path, true);
|
||||
}));
|
||||
|
||||
trackSearch->showMore().connect(std::bind([=]
|
||||
{
|
||||
std::string path = wApp->internalPath();
|
||||
path.replace(0, pathPrefix.length(), "/audio/search/track");
|
||||
|
||||
wApp->setInternalPath(path, true);
|
||||
}));
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
if (!wApp->internalPathMatches(pathPrefix))
|
||||
@@ -68,7 +76,7 @@ PreviewSearchView::PreviewSearchView(Wt::WContainerWidget* parent)
|
||||
std::vector<std::string> keywords = searchPathToSearchKeywords(path.substr(pathPrefix.length()));
|
||||
|
||||
artistSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Artist, keywords), SEARCH_NB_ITEMS);
|
||||
releaseSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Release, keywords), SEARCH_NB_ITEMS);
|
||||
releaseSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Release, keywords), SEARCH_NB_ITEMS, "Releases");
|
||||
trackSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Track, keywords), SEARCH_NB_ITEMS);
|
||||
|
||||
}, std::placeholders::_1));
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "ReleaseSearch.hpp"
|
||||
#include "ReleaseView.hpp"
|
||||
#include "ArtistView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
@@ -33,112 +35,94 @@ namespace Mobile {
|
||||
using namespace Database;
|
||||
|
||||
ReleaseSearch::ReleaseSearch(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_resCount(0)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
Wt::WTemplate* title = new Wt::WTemplate(this);
|
||||
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||
Wt::WTemplate* t = new Wt::WTemplate(this);
|
||||
t->setTemplateText(Wt::WString::tr("wa-release-search"));
|
||||
|
||||
title->bindWidget("text", new Wt::WText("Releases", Wt::PlainText));
|
||||
Wt::WTemplate *titleTemplate = new Wt::WTemplate(this);
|
||||
titleTemplate->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||
|
||||
_title = new Wt::WText();
|
||||
titleTemplate->bindWidget("text", _title);
|
||||
|
||||
t->bindWidget("title", titleTemplate);
|
||||
|
||||
Wt::WTemplate* releaseWrapper = new Wt::WTemplate(this);
|
||||
releaseWrapper->setTemplateText(Wt::WString::tr("wa-release-wrapper"));
|
||||
_contents = new Wt::WContainerWidget();
|
||||
releaseWrapper->bindWidget("contents", _contents );
|
||||
t->bindWidget("contents", _contents );
|
||||
|
||||
_showMore = new Wt::WTemplate();
|
||||
_showMore->setTemplateText(Wt::WString::tr("mobile-search-more"));
|
||||
_showMore->bindString("text", "Tap to show more results...");
|
||||
_showMore->hide();
|
||||
_showMore->clicked().connect(std::bind([=] {
|
||||
_sigShowMore.emit();
|
||||
}));
|
||||
|
||||
t->bindWidget("show-more", _showMore);
|
||||
}
|
||||
|
||||
void
|
||||
ReleaseSearch::clear()
|
||||
{
|
||||
while (count() > 1)
|
||||
removeWidget(this->widget(1));
|
||||
|
||||
_resCount = 0;
|
||||
_contents->clear();
|
||||
_showMore->hide();
|
||||
}
|
||||
|
||||
void
|
||||
ReleaseSearch::search(Database::SearchFilter filter, size_t max)
|
||||
ReleaseSearch::search(Database::SearchFilter filter, size_t max, Wt::WString title)
|
||||
{
|
||||
_filter = filter;
|
||||
_title->setText(title);
|
||||
|
||||
clear();
|
||||
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);
|
||||
addResults(max);
|
||||
}
|
||||
|
||||
void
|
||||
ReleaseSearch::addResults(Database::SearchFilter filter, size_t nb)
|
||||
ReleaseSearch::addResults(size_t nb)
|
||||
{
|
||||
using namespace Database;
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
std::vector<Release::pointer> releases = Release::getByFilter(DboSession(), filter, _resCount, nb + 1);
|
||||
|
||||
bool expectMoreResults;
|
||||
if (releases.size() == nb + 1)
|
||||
{
|
||||
expectMoreResults = true;
|
||||
releases.pop_back();
|
||||
}
|
||||
else
|
||||
expectMoreResults = false;
|
||||
bool moreResults;
|
||||
std::vector<Release::pointer> releases = Release::getByFilter(DboSession(), _filter, _contents->count(), nb, moreResults);
|
||||
|
||||
for (Release::pointer release : releases)
|
||||
{
|
||||
Wt::WTemplate* releaseWidget = new Wt::WTemplate(this);
|
||||
releaseWidget->setTemplateText(Wt::WString::tr("wa-release-res"));
|
||||
Wt::WTemplate* res = new Wt::WTemplate(_contents);
|
||||
res->setTemplateText(Wt::WString::tr("wa-release-search-res"));
|
||||
|
||||
Wt::WAnchor *coverAnchor = new Wt::WAnchor(Wt::WLink(Wt:: WLink::InternalPath, "/audio/release/" + std::to_string(release.id())));
|
||||
Wt::WAnchor *coverAnchor = new Wt::WAnchor(ReleaseView::getLink(release.id()));
|
||||
Wt::WImage *cover = new Wt::WImage(coverAnchor);
|
||||
cover->setStyleClass("center-block");
|
||||
cover->setImageLink( Wt::WLink( LmsApplication::instance()->getCoverResource()->getReleaseUrl(release.id(), 512)));
|
||||
cover->setImageLink( SessionImageResource()->getReleaseUrl(release.id(), 512));
|
||||
cover->setStyleClass("release_res_shadow release_img-responsive"); // TODO move?
|
||||
|
||||
releaseWidget->bindWidget("cover", coverAnchor);
|
||||
releaseWidget->bindWidget("name", new Wt::WText(Wt::WString::fromUTF8(release->getName()), Wt::PlainText));
|
||||
releaseWidget->bindString("release_name", Wt::WString::fromUTF8(release->getName()), Wt::PlainText);
|
||||
|
||||
res->bindWidget("cover", coverAnchor);
|
||||
res->bindWidget("name", new Wt::WText(Wt::WString::fromUTF8(release->getName()), Wt::PlainText));
|
||||
res->bindString("release_name", Wt::WString::fromUTF8(release->getName()), Wt::PlainText);
|
||||
|
||||
auto artists = Artist::getByFilter(DboSession(),
|
||||
SearchFilter::ById(SearchFilter::Field::Release, release.id()), -1, 2);
|
||||
if (artists.size() == 1)
|
||||
{
|
||||
Wt::WAnchor *artistAnchor = new Wt::WAnchor(Wt::WLink(Wt:: WLink::InternalPath, "/audio/artist/" + std::to_string(artists.front().id())));
|
||||
Wt::WAnchor *artistAnchor = new Wt::WAnchor(ArtistView::getLink(artists.front().id()));
|
||||
Wt::WText *artist = new Wt::WText(artistAnchor);
|
||||
artist->setText(Wt::WString::fromUTF8(artists.front()->getName(), Wt::PlainText));
|
||||
releaseWidget->bindWidget("artist", artistAnchor);
|
||||
res->bindWidget("artist", artistAnchor);
|
||||
}
|
||||
else
|
||||
releaseWidget->bindWidget("artist", new Wt::WText(Wt::WString::fromUTF8("Various Artists", Wt::PlainText)));
|
||||
res->bindWidget("artist", new Wt::WText(Wt::WString::fromUTF8("Various Artists", Wt::PlainText)));
|
||||
|
||||
}
|
||||
|
||||
_resCount += releases.size();;
|
||||
if (moreResults)
|
||||
_showMore->show();
|
||||
else
|
||||
_showMore->hide();
|
||||
|
||||
if (expectMoreResults)
|
||||
{
|
||||
Wt::WTemplate* moreRes = new Wt::WTemplate(this);
|
||||
moreRes->setTemplateText(Wt::WString::tr("mobile-search-more"));
|
||||
|
||||
moreRes->bindWidget("text", new Wt::WText("Tap to show more results..."));
|
||||
|
||||
moreRes->clicked().connect(std::bind([=] {
|
||||
_sigMoreReleasesSelected();
|
||||
removeWidget(moreRes);
|
||||
|
||||
addResults(filter, 20);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WSignal>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "database/SearchFilter.hpp"
|
||||
#include "database/Types.hpp"
|
||||
@@ -34,22 +35,23 @@ class ReleaseSearch : public Wt::WContainerWidget
|
||||
|
||||
ReleaseSearch(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void search(Database::SearchFilter filter, size_t nb);
|
||||
void search(Database::SearchFilter filter, std::size_t nb, Wt::WString title);
|
||||
void addResults(std::size_t nb);
|
||||
|
||||
// Slots
|
||||
Wt::Signal<Database::Release::id_type>& releaseSelected() { return _sigReleaseSelected;}
|
||||
Wt::Signal<void>& moreReleasesSelected() { return _sigMoreReleasesSelected;}
|
||||
Wt::Signal<void>& showMore() { return _sigShowMore;}
|
||||
|
||||
private:
|
||||
|
||||
Wt::Signal<Database::Release::id_type> _sigReleaseSelected;
|
||||
Wt::Signal<void> _sigMoreReleasesSelected;
|
||||
Wt::Signal<void> _sigShowMore;
|
||||
|
||||
void clear(void);
|
||||
void addResults(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
Wt::WContainerWidget* _contents;
|
||||
std::size_t _resCount;
|
||||
Wt::WTemplate* _showMore;
|
||||
Database::SearchFilter _filter;
|
||||
Wt::WContainerWidget* _contents;
|
||||
Wt::WText* _title;
|
||||
std::size_t _count;
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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 <Wt/WApplication>
|
||||
|
||||
#include "SearchUtils.hpp"
|
||||
|
||||
#include "ReleaseSearch.hpp"
|
||||
|
||||
#include "ReleaseSearchView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
#define SEARCH_NB_ITEMS 20
|
||||
|
||||
using namespace Database;
|
||||
|
||||
ReleaseSearchView::ReleaseSearchView(Wt::WContainerWidget* parent)
|
||||
{
|
||||
ReleaseSearch* artistSearch = new ReleaseSearch(this);
|
||||
artistSearch->showMore().connect(std::bind([=] {
|
||||
artistSearch->addResults(SEARCH_NB_ITEMS);
|
||||
}));
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
const std::string pathPrefix = "/audio/search/release";
|
||||
|
||||
if (!wApp->internalPathMatches(pathPrefix))
|
||||
return;
|
||||
|
||||
std::vector<std::string> keywords = searchPathToSearchKeywords(path.substr(pathPrefix.length()));
|
||||
|
||||
artistSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Release, keywords), SEARCH_NB_ITEMS, "Releases");
|
||||
|
||||
}, std::placeholders::_1));
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
class ReleaseSearchView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
ReleaseSearchView(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -150,7 +150,7 @@ ReleaseView::addResults(size_t nb)
|
||||
|
||||
Wt::WImage *cover = new Wt::WImage();
|
||||
cover->setStyleClass ("center-block img-responsive"); // TODO move to CSS?
|
||||
cover->setImageLink(Wt::WLink (LmsApplication::instance()->getCoverResource()->getReleaseUrl(release.id(), 512)));
|
||||
cover->setImageLink(Wt::WLink (LmsApp->getImageResource()->getReleaseUrl(release.id(), 512)));
|
||||
|
||||
releaseContainer->bindWidget("cover", cover);
|
||||
releaseContainer->bindString("artist-name", getArtistNameFromRelease(release), Wt::PlainText);
|
||||
@@ -210,5 +210,11 @@ ReleaseView::addResults(size_t nb)
|
||||
_showMore->hide();
|
||||
}
|
||||
|
||||
Wt::WLink
|
||||
ReleaseView::getLink(Database::Release::id_type id)
|
||||
{
|
||||
return Wt::WLink(Wt::WLink::InternalPath, "/audio/release/" + std::to_string(id));
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
@@ -31,6 +29,8 @@ class ReleaseView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
static Wt::WLink getLink(Database::Release::id_type id);
|
||||
|
||||
ReleaseView(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void search(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
@@ -36,37 +36,32 @@ using namespace Database;
|
||||
TrackSearch::TrackSearch(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
Wt::WTemplate* wrapper = new Wt::WTemplate(this);
|
||||
wrapper->setTemplateText(Wt::WString::tr("wa-track-wrapper"));
|
||||
Wt::WTemplate* t = new Wt::WTemplate(this);
|
||||
t->setTemplateText(Wt::WString::tr("wa-track-search"));
|
||||
|
||||
Wt::WTemplate* title = new Wt::WTemplate(this);
|
||||
wrapper->bindWidget("title", title);
|
||||
|
||||
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||
title->bindString("text", "Tracks", Wt::PlainText);
|
||||
t->bindWidget("title", title);
|
||||
|
||||
_container = new Wt::WContainerWidget();
|
||||
wrapper->bindWidget("track-container", _container);
|
||||
_contents = new Wt::WContainerWidget();
|
||||
t->bindWidget("contents", _contents);
|
||||
|
||||
_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();
|
||||
_showMore->clicked().connect(std::bind([=] {
|
||||
_sigMoreSelected();
|
||||
_sigShowMore.emit();
|
||||
addResults(20);
|
||||
}));
|
||||
t->bindWidget("show-more", _showMore);
|
||||
}
|
||||
|
||||
void
|
||||
TrackSearch::clear()
|
||||
{
|
||||
// Flush the release container
|
||||
_container->clear();
|
||||
|
||||
_nbTracks = 0;
|
||||
_contents->clear();
|
||||
_showMore->hide();
|
||||
}
|
||||
|
||||
@@ -79,43 +74,25 @@ TrackSearch::search(SearchFilter filter, size_t nb)
|
||||
addResults(nb);
|
||||
}
|
||||
|
||||
static
|
||||
std::vector<Track::pointer >
|
||||
getTracks(SearchFilter filter, size_t offset, size_t nb, bool &moreResults)
|
||||
{
|
||||
std::vector<Track::pointer > tracks = Track::getByFilter(DboSession(), filter, offset, nb + 1);
|
||||
|
||||
if (tracks.size() == nb + 1)
|
||||
{
|
||||
moreResults = true;
|
||||
tracks.pop_back();
|
||||
}
|
||||
else
|
||||
moreResults = false;
|
||||
|
||||
return tracks;
|
||||
}
|
||||
|
||||
void
|
||||
TrackSearch::addResults(size_t nb)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
bool moreResults;
|
||||
std::vector<Track::pointer > tracks = getTracks(_filter, _nbTracks, nb, moreResults);
|
||||
std::vector<Track::pointer > tracks = Track::getByFilter(DboSession(), _filter, _contents->count(), nb, moreResults);
|
||||
|
||||
for (Track::pointer track : tracks)
|
||||
{
|
||||
Wt::WTemplate* trackRes = new Wt::WTemplate(_container);
|
||||
trackRes->setTemplateText(Wt::WString::tr("wa-track"));
|
||||
Wt::WTemplate* res = new Wt::WTemplate(_contents);
|
||||
res->setTemplateText(Wt::WString::tr("wa-track-search-res"));
|
||||
|
||||
Wt::WImage *cover = new Wt::WImage();
|
||||
cover->setStyleClass ("center-block img-responsive");
|
||||
cover->setImageLink(Wt::WLink(LmsApplication::instance()->getCoverResource()->getTrackUrl(track.id(), 128)));
|
||||
trackRes->bindWidget("cover", cover);
|
||||
|
||||
trackRes->bindString("track-name", Wt::WString::fromUTF8(track->getName()), Wt::PlainText);
|
||||
trackRes->bindString("artist-name", Wt::WString::fromUTF8(track->getArtist()->getName()), Wt::PlainText);
|
||||
cover->setImageLink(SessionImageResource()->getTrackUrl(track.id(), 64));
|
||||
res->bindWidget("cover", cover);
|
||||
res->bindString("track-name", Wt::WString::fromUTF8(track->getName()), Wt::PlainText);
|
||||
res->bindString("artist-name", Wt::WString::fromUTF8(track->getArtist()->getName()), Wt::PlainText);
|
||||
|
||||
Wt::WText *playBtn = new Wt::WText("Play", Wt::PlainText);
|
||||
playBtn->setStyleClass("center-block"); // TODO move to CSS?
|
||||
@@ -123,8 +100,7 @@ TrackSearch::addResults(size_t nb)
|
||||
_sigTrackPlay.emit(track.id());
|
||||
}));
|
||||
|
||||
trackRes->bindWidget("btn", playBtn);
|
||||
_nbTracks++;
|
||||
res->bindWidget("btn", playBtn);
|
||||
}
|
||||
|
||||
if (moreResults)
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
#include "database/SearchFilter.hpp"
|
||||
#include "database/Types.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
@@ -34,25 +34,23 @@ class TrackSearch : public Wt::WContainerWidget
|
||||
|
||||
TrackSearch(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void addResults(size_t nb);
|
||||
void search(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
// Slots
|
||||
Wt::Signal<void>& showMore() { return _sigShowMore;}
|
||||
Wt::Signal<Database::Track::id_type>& trackPlay() { return _sigTrackPlay;}
|
||||
Wt::Signal<void>& moreSelected() { return _sigMoreSelected;}
|
||||
|
||||
private:
|
||||
|
||||
Wt::Signal<void> _sigShowMore;
|
||||
Wt::Signal<Database::Track::id_type> _sigTrackPlay;
|
||||
Wt::Signal<void> _sigMoreSelected;
|
||||
|
||||
void clear(void);
|
||||
void addResults(size_t nb);
|
||||
|
||||
Wt::WTemplate* _showMore;
|
||||
|
||||
Wt::WTemplate* _showMore;
|
||||
Database::SearchFilter _filter;
|
||||
std::size_t _nbTracks;
|
||||
Wt::WContainerWidget* _container;
|
||||
Wt::WContainerWidget* _contents;
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 <Wt/WApplication>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "SearchUtils.hpp"
|
||||
|
||||
#include "TrackSearch.hpp"
|
||||
|
||||
#include "TrackSearchView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
#define SEARCH_NB_ITEMS 20
|
||||
|
||||
using namespace Database;
|
||||
|
||||
TrackSearchView::TrackSearchView(Wt::WContainerWidget* parent)
|
||||
{
|
||||
TrackSearch* trackSearch = new TrackSearch(this);
|
||||
trackSearch->showMore().connect(std::bind([=] {
|
||||
trackSearch->addResults(SEARCH_NB_ITEMS);
|
||||
}));
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
const std::string pathPrefix = "/audio/search/track";
|
||||
|
||||
if (!wApp->internalPathMatches(pathPrefix))
|
||||
return;
|
||||
|
||||
std::vector<std::string> keywords = searchPathToSearchKeywords(path.substr(pathPrefix.length()));
|
||||
|
||||
trackSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Track, keywords), SEARCH_NB_ITEMS);
|
||||
|
||||
}, std::placeholders::_1));
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
class TrackSearchView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
TrackSearchView(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* 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 <Wt/WApplication>
|
||||
#include <Wt/Http/Response>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "cover/CoverArtGrabber.hpp"
|
||||
|
||||
#include "CoverResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
const std::string CoverResource::unknownCoverPath = "/images/unknown-cover.jpg";
|
||||
|
||||
CoverResource::CoverResource(Database::Handler& db, Wt::WObject *parent)
|
||||
: Wt::WResource(parent),
|
||||
_db(db)
|
||||
{
|
||||
}
|
||||
|
||||
CoverResource::~CoverResource()
|
||||
{
|
||||
beingDeleted();
|
||||
}
|
||||
|
||||
Image::Image
|
||||
CoverResource::getDefaultCover(std::size_t size)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
|
||||
auto itCover = _defaultCovers.find(size);
|
||||
if (itCover == _defaultCovers.end())
|
||||
{
|
||||
// Load default cover art for this size
|
||||
Image::Image image;
|
||||
|
||||
if (!image.load( Wt::WApplication::instance()->docRoot() + unknownCoverPath ))
|
||||
throw std::runtime_error("Cannot read default cover file");
|
||||
|
||||
image.scale(size);
|
||||
|
||||
auto res = _defaultCovers.insert(std::make_pair(size, image));
|
||||
itCover = res.first;
|
||||
}
|
||||
|
||||
return itCover->second;
|
||||
}
|
||||
|
||||
std::string
|
||||
CoverResource::getReleaseUrl(Database::Release::id_type releaseId, std::size_t size) const
|
||||
{
|
||||
return url() + "&releaseid=" + std::to_string(releaseId) + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
std::string
|
||||
CoverResource::getTrackUrl(Database::Track::id_type trackId, std::size_t size) const
|
||||
{
|
||||
return url() + "&trackid=" + std::to_string(trackId) + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
std::string
|
||||
CoverResource::getUnknownTrackUrl(size_t size) const
|
||||
{
|
||||
return url() + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
void
|
||||
CoverResource::putCover(Wt::Http::Response& response, Image::Image cover)
|
||||
{
|
||||
std::vector<unsigned char> data;
|
||||
|
||||
cover.save(data, Image::Format::JPEG);
|
||||
|
||||
response.setMimeType( Image::format_to_mimeType(Image::Format::JPEG) );
|
||||
response.out().write(reinterpret_cast<const char *>(&data[0]), data.size());
|
||||
}
|
||||
|
||||
void
|
||||
CoverResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response)
|
||||
{
|
||||
// Retrieve parameters
|
||||
const std::string *trackIdStr = request.getParameter("trackid");
|
||||
const std::string *releaseIdStr = request.getParameter("releaseid");
|
||||
const std::string *sizeStr = request.getParameter("size");
|
||||
|
||||
try
|
||||
{
|
||||
std::vector<Image::Image> covers;
|
||||
|
||||
// Mandatory parameter size
|
||||
if (!sizeStr)
|
||||
return;
|
||||
|
||||
std::size_t size = std::stol(*sizeStr);
|
||||
if (size > maxSize)
|
||||
return;
|
||||
|
||||
if (trackIdStr)
|
||||
{
|
||||
Database::Track::id_type trackId = std::stol(*trackIdStr);
|
||||
boost::filesystem::path path;
|
||||
Database::Track::CoverType coverType = Database::Track::CoverType::None;
|
||||
|
||||
{
|
||||
// transactions are not thread safe
|
||||
Wt::WApplication::UpdateLock lock(LmsApplication::instance());
|
||||
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
Database::Track::pointer track = Database::Track::getById(_db.getSession(), trackId);
|
||||
if (track)
|
||||
{
|
||||
coverType = track->getCoverType();
|
||||
path = track->getPath();
|
||||
}
|
||||
}
|
||||
|
||||
switch (coverType)
|
||||
{
|
||||
case Database::Track::CoverType::Embedded:
|
||||
covers = CoverArt::Grabber::instance().getFromTrack(path);
|
||||
break;
|
||||
|
||||
case Database::Track::CoverType::None:
|
||||
covers = CoverArt::Grabber::instance().getFromDirectory(path.parent_path());
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (releaseIdStr)
|
||||
{
|
||||
Database::Release::id_type releaseId = std::stol(*releaseIdStr);
|
||||
|
||||
// transactions are not thread safe
|
||||
Wt::WApplication::UpdateLock lock(LmsApplication::instance());
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
covers = CoverArt::Grabber::instance().getFromRelease(_db.getSession(), releaseId);
|
||||
}
|
||||
|
||||
for (Image::Image& cover : covers)
|
||||
{
|
||||
if (cover.scale(size))
|
||||
{
|
||||
putCover(response, cover);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If no cover found, just send default one
|
||||
putCover(response, getDefaultCover(size));
|
||||
}
|
||||
catch (std::invalid_argument& e)
|
||||
{
|
||||
LMS_LOG(UI, ERROR) << "Invalid argument: " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* 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 <Wt/WApplication>
|
||||
#include <Wt/Http/Response>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "cover/CoverArtGrabber.hpp"
|
||||
|
||||
#include "ImageResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
static const std::string unknownCoverPath = "/images/unknown-cover.jpg";
|
||||
static const std::string unknownArtistImagePath = "/images/unknown-artist.jpg";
|
||||
|
||||
ImageResource::ImageResource(Database::Handler& db, Wt::WObject *parent)
|
||||
: Wt::WResource(parent),
|
||||
_db(db)
|
||||
{
|
||||
}
|
||||
|
||||
ImageResource::~ImageResource()
|
||||
{
|
||||
beingDeleted();
|
||||
}
|
||||
|
||||
Image::Image
|
||||
ImageResource::getDefaultCover(std::size_t size)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
|
||||
auto itCover = _defaultCovers.find(size);
|
||||
if (itCover == _defaultCovers.end())
|
||||
{
|
||||
// Load default cover art for this size
|
||||
Image::Image image;
|
||||
|
||||
if (!image.load( Wt::WApplication::instance()->docRoot() + unknownCoverPath ))
|
||||
throw std::runtime_error("Cannot read default cover file");
|
||||
|
||||
image.scale(size);
|
||||
|
||||
auto res = _defaultCovers.insert(std::make_pair(size, image));
|
||||
itCover = res.first;
|
||||
}
|
||||
|
||||
return itCover->second;
|
||||
}
|
||||
|
||||
Image::Image
|
||||
ImageResource::getDefaultArtistImage(std::size_t size)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
|
||||
auto itCover = _defaultArtistImages.find(size);
|
||||
if (itCover == _defaultArtistImages.end())
|
||||
{
|
||||
Image::Image image;
|
||||
|
||||
if (!image.load( Wt::WApplication::instance()->docRoot() + unknownArtistImagePath))
|
||||
throw std::runtime_error("Cannot read default artist image file");
|
||||
|
||||
image.scale(size);
|
||||
|
||||
auto res = _defaultArtistImages.insert(std::make_pair(size, image));
|
||||
itCover = res.first;
|
||||
}
|
||||
|
||||
return itCover->second;
|
||||
}
|
||||
|
||||
std::string
|
||||
ImageResource::getReleaseUrl(Database::Release::id_type releaseId, std::size_t size) const
|
||||
{
|
||||
return url() + "&releaseid=" + std::to_string(releaseId) + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
std::string
|
||||
ImageResource::getTrackUrl(Database::Track::id_type trackId, std::size_t size) const
|
||||
{
|
||||
return url() + "&trackid=" + std::to_string(trackId) + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
std::string
|
||||
ImageResource::getArtistUrl(Database::Artist::id_type artistId, std::size_t size) const
|
||||
{
|
||||
return url() + "&artistid=" + std::to_string(artistId) + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
std::string
|
||||
ImageResource::getUnknownTrackUrl(size_t size) const
|
||||
{
|
||||
return url() + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
void
|
||||
ImageResource::putImage(Wt::Http::Response& response, Image::Image cover)
|
||||
{
|
||||
std::vector<unsigned char> data;
|
||||
|
||||
cover.save(data, Image::Format::JPEG);
|
||||
|
||||
response.setMimeType( Image::format_to_mimeType(Image::Format::JPEG) );
|
||||
response.out().write(reinterpret_cast<const char *>(&data[0]), data.size());
|
||||
}
|
||||
|
||||
void
|
||||
ImageResource::putCover(Wt::Http::Response& response, std::vector<Image::Image> covers, size_t size)
|
||||
{
|
||||
for (Image::Image cover : covers)
|
||||
{
|
||||
if (cover.scale(size))
|
||||
{
|
||||
putImage(response, cover);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If no cover found, just send default one
|
||||
putImage(response, getDefaultCover(size));
|
||||
}
|
||||
|
||||
void
|
||||
ImageResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response)
|
||||
{
|
||||
// Retrieve parameters
|
||||
const std::string *trackIdStr = request.getParameter("trackid");
|
||||
const std::string *releaseIdStr = request.getParameter("releaseid");
|
||||
const std::string *artistIdStr = request.getParameter("artistid");
|
||||
const std::string *sizeStr = request.getParameter("size");
|
||||
|
||||
// Mandatory parameter size
|
||||
if (!sizeStr)
|
||||
return;
|
||||
|
||||
std::size_t size;
|
||||
if (!readAs(*sizeStr, size) || size > maxSize)
|
||||
return;
|
||||
|
||||
if (trackIdStr)
|
||||
{
|
||||
Database::Track::id_type trackId;
|
||||
if (!readAs(*trackIdStr, trackId))
|
||||
return;
|
||||
|
||||
boost::filesystem::path path;
|
||||
Database::Track::CoverType coverType = Database::Track::CoverType::None;
|
||||
{
|
||||
// transactions are not thread safe
|
||||
Wt::WApplication::UpdateLock lock(LmsApplication::instance());
|
||||
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
Database::Track::pointer track = Database::Track::getById(_db.getSession(), trackId);
|
||||
if (track)
|
||||
{
|
||||
coverType = track->getCoverType();
|
||||
path = track->getPath();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Image::Image> covers;
|
||||
switch (coverType)
|
||||
{
|
||||
case Database::Track::CoverType::Embedded:
|
||||
covers = CoverArt::Grabber::instance().getFromTrack(path);
|
||||
break;
|
||||
|
||||
case Database::Track::CoverType::None:
|
||||
covers = CoverArt::Grabber::instance().getFromDirectory(path.parent_path());
|
||||
break;
|
||||
}
|
||||
|
||||
putCover(response, covers, size);
|
||||
return;
|
||||
}
|
||||
else if (releaseIdStr)
|
||||
{
|
||||
Database::Release::id_type releaseId;
|
||||
if (!readAs(*releaseIdStr, releaseId))
|
||||
return;
|
||||
|
||||
std::vector<Image::Image> covers;
|
||||
|
||||
// transactions are not thread safe
|
||||
{
|
||||
Wt::WApplication::UpdateLock lock(LmsApplication::instance());
|
||||
covers = CoverArt::Grabber::instance().getFromRelease(_db.getSession(), releaseId);
|
||||
}
|
||||
|
||||
putCover(response, covers, size);
|
||||
return;
|
||||
}
|
||||
else if (artistIdStr)
|
||||
{
|
||||
putImage(response, getDefaultArtistImage(size));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
putImage(response, getDefaultCover(size));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
@@ -30,14 +30,13 @@
|
||||
namespace UserInterface {
|
||||
|
||||
|
||||
class CoverResource : public Wt::WResource
|
||||
class ImageResource : public Wt::WResource
|
||||
{
|
||||
public:
|
||||
static const std::string unknownCoverPath;
|
||||
static const std::size_t maxSize = 512;
|
||||
|
||||
CoverResource(Database::Handler& db, Wt::WObject *parent = 0);
|
||||
~CoverResource();
|
||||
ImageResource(Database::Handler& db, Wt::WObject *parent = 0);
|
||||
~ImageResource();
|
||||
|
||||
std::string getReleaseUrl(Database::Release::id_type releaseId, size_t size) const;
|
||||
std::string getTrackUrl(Database::Track::id_type trackId, size_t size) const;
|
||||
@@ -49,7 +48,9 @@ class CoverResource : public Wt::WResource
|
||||
private:
|
||||
|
||||
Image::Image getDefaultCover(std::size_t size);
|
||||
void putCover(Wt::Http::Response& response, Image::Image image);
|
||||
Image::Image getDefaultArtistImage(std::size_t size);
|
||||
void putImage(Wt::Http::Response& response, Image::Image image);
|
||||
void putCover(Wt::Http::Response& response, std::vector<Image::Image> covers, std::size_t size);
|
||||
|
||||
// Used to protect transactions since they are not thread safe
|
||||
std::mutex _mutex;
|
||||
@@ -58,6 +59,9 @@ class CoverResource : public Wt::WResource
|
||||
// Default cover for different sizes
|
||||
std::map<std::size_t, Image::Image> _defaultCovers;
|
||||
|
||||
// Default artist images for different sizes
|
||||
std::map<std::size_t, Image::Image> _defaultArtistImages;
|
||||
|
||||
// TODO construct a cache for covers?
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user