Reorganized the UI/xml part to better handle next steps
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/WAnchor>
|
||||
#include <Wt/WImage>
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
#include "Filters.hpp"
|
||||
#include "ArtistView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
Artist::Artist(Filters* filters, Wt::WContainerWidget* parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_filters(filters)
|
||||
{
|
||||
wApp->internalPathChanged().connect(std::bind([=]
|
||||
{
|
||||
refresh();
|
||||
}));
|
||||
|
||||
refresh();
|
||||
|
||||
filters->updated().connect(std::bind([=] {
|
||||
refresh();
|
||||
}));
|
||||
}
|
||||
|
||||
void
|
||||
Artist::refresh()
|
||||
{
|
||||
if (!wApp->internalPathMatches("/artist/"))
|
||||
return;
|
||||
|
||||
clear();
|
||||
|
||||
Database::Artist::id_type artistId;
|
||||
if (!readAs(wApp->internalPathNextPart("/artist/"), artistId))
|
||||
return;
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
auto artist = Database::Artist::getById(DboSession(), artistId);
|
||||
|
||||
if (!artist)
|
||||
{
|
||||
LmsApp->goHome();
|
||||
return;
|
||||
}
|
||||
|
||||
auto t = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Artist.template"), this);
|
||||
t->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
|
||||
auto clusterContainers = new Wt::WContainerWidget();
|
||||
t->bindWidget("clusters", clusterContainers);
|
||||
|
||||
{
|
||||
auto clusters = artist->getClusters(3);
|
||||
|
||||
for (auto cluster : clusters)
|
||||
{
|
||||
auto entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Artist.template.cluster-entry"), clusterContainers);
|
||||
|
||||
entry->bindString("name", Wt::WString::fromUTF8(cluster->getName()), Wt::PlainText);
|
||||
}
|
||||
}
|
||||
|
||||
t->bindString("name", Wt::WString::fromUTF8(artist->getName()), Wt::PlainText);
|
||||
{
|
||||
auto playBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Artist.play"), Wt::XHTMLText);
|
||||
t->bindWidget("play-btn", playBtn);
|
||||
|
||||
playBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
artistPlay.emit(artistId);
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
auto addBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Artist.add"), Wt::XHTMLText);
|
||||
t->bindWidget("add-btn", addBtn);
|
||||
|
||||
addBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
artistAdd.emit(artistId);
|
||||
}));
|
||||
}
|
||||
|
||||
auto releasesContainer = new Wt::WContainerWidget();
|
||||
t->bindWidget("releases", releasesContainer);
|
||||
|
||||
auto releases = artist->getReleases(_filters->getClusterIds());
|
||||
for (auto release : releases)
|
||||
{
|
||||
auto releaseId = release.id();
|
||||
|
||||
Wt::WTemplate* entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Artist.template.entry"), releasesContainer);
|
||||
entry->addFunction("tr", Wt::WTemplate::Functions::tr);
|
||||
|
||||
{
|
||||
Wt::WAnchor* coverAnchor = LmsApplication::createReleaseAnchor(releaseId);
|
||||
Wt::WImage* cover = new Wt::WImage(coverAnchor);
|
||||
cover->setImageLink(LmsApp->getImageResource()->getReleaseUrl(release.id(), 128));
|
||||
// Some images may not be square
|
||||
cover->setWidth(128);
|
||||
entry->bindWidget("cover", coverAnchor);
|
||||
}
|
||||
|
||||
{
|
||||
Wt::WAnchor* releaseAnchor = LmsApplication::createReleaseAnchor(releaseId);
|
||||
Wt::WText* releaseName = new Wt::WText(releaseAnchor);
|
||||
releaseName->setText(Wt::WString::fromUTF8(release->getName(), Wt::PlainText));
|
||||
entry->bindWidget("name", releaseAnchor);
|
||||
}
|
||||
|
||||
if (release->hasVariousArtists())
|
||||
entry->setCondition("if-has-various-artists", true);
|
||||
|
||||
boost::optional<int> year = release->getReleaseYear();
|
||||
if (year)
|
||||
{
|
||||
entry->setCondition("if-has-year", true);
|
||||
entry->bindInt("year", *year);
|
||||
|
||||
boost::optional<int> originalYear = release->getReleaseYear(true);
|
||||
if (originalYear && *originalYear != *year)
|
||||
{
|
||||
entry->setCondition("if-has-orig-year", true);
|
||||
entry->bindInt("orig-year", *originalYear);
|
||||
}
|
||||
}
|
||||
|
||||
auto playBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Artist.play"), Wt::XHTMLText);
|
||||
entry->bindWidget("play-btn", playBtn);
|
||||
playBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
releasePlay.emit(releaseId);
|
||||
}));
|
||||
|
||||
auto addBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Artist.add"), Wt::XHTMLText);
|
||||
entry->bindWidget("add-btn", addBtn);
|
||||
addBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
releaseAdd.emit(releaseId);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class Filters;
|
||||
|
||||
class Artist : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Artist(Filters* filters, Wt::WContainerWidget* parent = 0);
|
||||
|
||||
Wt::Signal<Database::id_type> artistAdd;
|
||||
Wt::Signal<Database::id_type> artistPlay;
|
||||
|
||||
Wt::Signal<Database::id_type> releaseAdd;
|
||||
Wt::Signal<Database::id_type> releasePlay;
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
Filters* _filters;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/WAnchor>
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WLineEdit>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
#include "Filters.hpp"
|
||||
#include "ArtistsView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
Artists::Artists(Filters* filters, Wt::WContainerWidget* parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_filters(filters)
|
||||
{
|
||||
auto container = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Artists.template"), this);
|
||||
container->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
|
||||
_search = new Wt::WLineEdit();
|
||||
container->bindWidget("search", _search);
|
||||
_search->setPlaceholderText(Wt::WString::tr("Lms.Explore.search-placeholder"));
|
||||
_search->textInput().connect(this, &Artists::refresh);
|
||||
|
||||
_artistsContainer = new Wt::WContainerWidget();
|
||||
container->bindWidget("artists", _artistsContainer);
|
||||
|
||||
_showMore = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.template.show-more"));
|
||||
_showMore->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
container->bindWidget("show-more", _showMore);
|
||||
|
||||
_showMore->clicked().connect(std::bind([=]
|
||||
{
|
||||
addSome();
|
||||
}));
|
||||
|
||||
refresh();
|
||||
|
||||
filters->updated().connect(this, &Artists::refresh);
|
||||
}
|
||||
|
||||
void
|
||||
Artists::refresh()
|
||||
{
|
||||
_artistsContainer->clear();
|
||||
addSome();
|
||||
}
|
||||
|
||||
void
|
||||
Artists::addSome()
|
||||
{
|
||||
auto searchKeywords = splitString(_search->text().toUTF8(), " ");
|
||||
|
||||
auto clusterIds = _filters->getClusterIds();
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
bool moreResults;
|
||||
auto artists = Artist::getByFilter(DboSession(),
|
||||
clusterIds,
|
||||
searchKeywords,
|
||||
_artistsContainer->count(), 20, moreResults);
|
||||
|
||||
for (auto artist : artists)
|
||||
{
|
||||
Wt::WTemplate* entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Artists.template.entry"), _artistsContainer);
|
||||
|
||||
entry->bindInt("nb-release", artist->getReleases(clusterIds).size());
|
||||
|
||||
{
|
||||
Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(artist.id());
|
||||
Wt::WText *artistText = new Wt::WText(artistAnchor);
|
||||
artistText->setText(Wt::WString::fromUTF8(artist->getName(), Wt::PlainText));
|
||||
entry->bindWidget("name", artistAnchor);
|
||||
}
|
||||
}
|
||||
|
||||
_showMore->setHidden(!moreResults);
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class Filters;
|
||||
|
||||
class Artists : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Artists(Filters* filters, Wt::WContainerWidget* parent = 0);
|
||||
|
||||
Wt::Signal<Database::id_type> artistAdd;
|
||||
Wt::Signal<Database::id_type> artistPlay;
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
void addSome();
|
||||
|
||||
Filters* _filters;
|
||||
Wt::WTemplate* _showMore;
|
||||
Wt::WLineEdit* _search;
|
||||
Wt::WContainerWidget* _artistsContainer;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/WStackedWidget>
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "Filters.hpp"
|
||||
#include "ArtistsView.hpp"
|
||||
#include "ArtistView.hpp"
|
||||
#include "ReleasesView.hpp"
|
||||
#include "ReleaseView.hpp"
|
||||
#include "TracksView.hpp"
|
||||
|
||||
#include "Explore.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
|
||||
enum IdxRoot
|
||||
{
|
||||
IdxArtists = 0,
|
||||
IdxArtist,
|
||||
IdxReleases,
|
||||
IdxRelease,
|
||||
IdxTracks,
|
||||
};
|
||||
|
||||
static void
|
||||
handlePathChange(Wt::WStackedWidget* stack)
|
||||
{
|
||||
static const std::map<std::string, int> indexes =
|
||||
{
|
||||
{ "/artists", IdxArtists },
|
||||
{ "/artist", IdxArtist },
|
||||
{ "/releases", IdxReleases },
|
||||
{ "/release", IdxRelease },
|
||||
{ "/tracks", IdxTracks },
|
||||
};
|
||||
|
||||
LMS_LOG(UI, DEBUG) << "Internal path changed to '" << wApp->internalPath() << "'";
|
||||
|
||||
for (auto index : indexes)
|
||||
{
|
||||
if (wApp->internalPathMatches(index.first))
|
||||
{
|
||||
stack->setCurrentIndex(index.second);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Explore::Explore(Wt::WContainerWidget* parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
auto container = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.template"), this);
|
||||
|
||||
_filters = new Filters();
|
||||
container->bindWidget("filters", _filters);
|
||||
|
||||
// Contents
|
||||
Wt::WStackedWidget* stack = new Wt::WStackedWidget();
|
||||
container->bindWidget("contents", stack);
|
||||
|
||||
auto artists = new Artists(_filters);
|
||||
stack->addWidget(artists);
|
||||
|
||||
artists->artistAdd.connect(this, &Explore::handleArtistAdd);
|
||||
artists->artistPlay.connect(this, &Explore::handleArtistPlay);
|
||||
|
||||
auto artist = new Artist(_filters);
|
||||
stack->addWidget(artist);
|
||||
|
||||
artist->artistAdd.connect(this, &Explore::handleArtistAdd);
|
||||
artist->artistPlay.connect(this, &Explore::handleArtistPlay);
|
||||
artist->releaseAdd.connect(this, &Explore::handleReleaseAdd);
|
||||
artist->releasePlay.connect(this, &Explore::handleReleasePlay);
|
||||
|
||||
auto releases = new Releases(_filters);
|
||||
stack->addWidget(releases);
|
||||
|
||||
releases->releaseAdd.connect(this, &Explore::handleReleaseAdd);
|
||||
releases->releasePlay.connect(this, &Explore::handleReleasePlay);
|
||||
|
||||
auto release = new Release(_filters);
|
||||
stack->addWidget(release);
|
||||
|
||||
release->releaseAdd.connect(this, &Explore::handleReleaseAdd);
|
||||
release->releasePlay.connect(this, &Explore::handleReleasePlay);
|
||||
release->trackAdd.connect(this, &Explore::handleTrackAdd);
|
||||
release->trackPlay.connect(this, &Explore::handleTrackPlay);
|
||||
|
||||
auto tracks = new Tracks(_filters);
|
||||
stack->addWidget(tracks);
|
||||
|
||||
tracks->trackAdd.connect(this, &Explore::handleTrackAdd);
|
||||
tracks->trackPlay.connect(this, &Explore::handleTrackPlay);
|
||||
tracks->tracksAdd.connect(this, &Explore::handleTracksAdd);
|
||||
tracks->tracksPlay.connect(this, &Explore::handleTracksPlay);
|
||||
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=]
|
||||
{
|
||||
handlePathChange(stack);
|
||||
}));
|
||||
|
||||
handlePathChange(stack);
|
||||
}
|
||||
|
||||
// TODO SQL this?
|
||||
static std::vector<Database::Track::pointer> getArtistTracks(Wt::Dbo::Session& session, Database::id_type artistId, std::set<Database::id_type> clusters)
|
||||
{
|
||||
std::vector<Database::Track::pointer> res;
|
||||
|
||||
auto artist = Database::Artist::getById(session, artistId);
|
||||
if (!artist)
|
||||
return res;
|
||||
|
||||
auto releases = artist->getReleases(clusters);
|
||||
for (auto release : releases)
|
||||
{
|
||||
auto tracks = release->getTracks(clusters);
|
||||
for (auto track : tracks)
|
||||
{
|
||||
if (track->getArtist() && track->getArtist().id() == artistId)
|
||||
res.push_back(track);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static std::vector<Database::Track::pointer> getReleaseTracks(Wt::Dbo::Session& session, Database::id_type releaseId, std::set<Database::id_type> clusters)
|
||||
{
|
||||
std::vector<Database::Track::pointer> res;
|
||||
|
||||
auto release = Database::Release::getById(session, releaseId);
|
||||
if (!release)
|
||||
return res;
|
||||
|
||||
return release->getTracks(clusters);
|
||||
}
|
||||
|
||||
static std::vector<Database::Track::pointer> getTrack(Wt::Dbo::Session& session, Database::id_type trackId)
|
||||
{
|
||||
std::vector<Database::Track::pointer> res;
|
||||
|
||||
auto track = Database::Track::getById(session, trackId);
|
||||
if (track)
|
||||
res.push_back(track);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
Explore::handleArtistAdd(Database::id_type id)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
tracksAdd.emit(getArtistTracks(DboSession(), id, _filters->getClusterIds()));
|
||||
}
|
||||
|
||||
void
|
||||
Explore::handleArtistPlay(Database::id_type id)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
tracksPlay.emit(getArtistTracks(DboSession(), id, _filters->getClusterIds()));
|
||||
}
|
||||
|
||||
void
|
||||
Explore::handleReleaseAdd(Database::id_type id)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
tracksAdd.emit(getReleaseTracks(DboSession(), id, _filters->getClusterIds()));
|
||||
}
|
||||
|
||||
void
|
||||
Explore::handleReleasePlay(Database::id_type id)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
tracksPlay.emit(getReleaseTracks(DboSession(), id, _filters->getClusterIds()));
|
||||
}
|
||||
|
||||
void
|
||||
Explore::handleTrackAdd(Database::id_type id)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
tracksAdd.emit(getTrack(DboSession(), id));
|
||||
}
|
||||
|
||||
void
|
||||
Explore::handleTrackPlay(Database::id_type id)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
tracksPlay.emit(getTrack(DboSession(), id));
|
||||
}
|
||||
|
||||
void
|
||||
Explore::handleTracksAdd(std::vector<Database::Track::pointer> tracks)
|
||||
{
|
||||
tracksAdd.emit(tracks);
|
||||
}
|
||||
|
||||
void
|
||||
Explore::handleTracksPlay(std::vector<Database::Track::pointer> tracks)
|
||||
{
|
||||
tracksPlay.emit(tracks);
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class Filters;
|
||||
|
||||
class Explore : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Explore(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
Wt::Signal<std::vector<Database::Track::pointer>> tracksAdd;
|
||||
Wt::Signal<std::vector<Database::Track::pointer>> tracksPlay;
|
||||
|
||||
private:
|
||||
|
||||
void handleArtistAdd(Database::id_type id);
|
||||
void handleArtistPlay(Database::id_type id);
|
||||
void handleReleaseAdd(Database::id_type id);
|
||||
void handleReleasePlay(Database::id_type id);
|
||||
void handleTrackAdd(Database::id_type id);
|
||||
void handleTrackPlay(Database::id_type id);
|
||||
void handleTracksAdd(std::vector<Database::Track::pointer> tracks);
|
||||
void handleTracksPlay(std::vector<Database::Track::pointer> tracks);
|
||||
|
||||
Filters* _filters;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/WComboBox>
|
||||
#include <Wt/WDialog>
|
||||
#include <Wt/WPushButton>
|
||||
#include <Wt/WTemplate>
|
||||
|
||||
#include "Filters.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
void
|
||||
Filters::showDialog()
|
||||
{
|
||||
auto dialog = new Wt::WDialog(Wt::WString::tr("Lms.Explore.add-filter"));
|
||||
|
||||
auto container = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.template.add-filter"));
|
||||
container->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
|
||||
dialog->contents()->addWidget(container);
|
||||
|
||||
auto typeCombo = new Wt::WComboBox();
|
||||
container->bindWidget("type", typeCombo);
|
||||
|
||||
auto valueCombo = new Wt::WComboBox();
|
||||
container->bindWidget("value", valueCombo);
|
||||
|
||||
auto addBtn = new Wt::WPushButton(Wt::WString::tr("Lms.add"));
|
||||
container->bindWidget("add-btn", addBtn);
|
||||
addBtn->clicked().connect(dialog, &Wt::WDialog::accept);
|
||||
|
||||
auto cancelBtn = new Wt::WPushButton(Wt::WString::tr("Lms.cancel"));
|
||||
container->bindWidget("cancel-btn", cancelBtn);
|
||||
cancelBtn->clicked().connect(dialog, &Wt::WDialog::reject);
|
||||
|
||||
// Populate data
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
auto types = Database::ClusterType::getAll(DboSession());
|
||||
|
||||
for (auto type : types)
|
||||
typeCombo->addItem(Wt::WString::fromUTF8(type->getName()));
|
||||
|
||||
|
||||
if (!types.empty())
|
||||
{
|
||||
auto values = types.front()->getClusters();
|
||||
|
||||
for (auto value : values)
|
||||
{
|
||||
if (_filterIds.find(value.id()) == _filterIds.end())
|
||||
valueCombo->addItem(Wt::WString::fromUTF8(value->getName()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
typeCombo->changed().connect(std::bind([=]
|
||||
{
|
||||
auto name = typeCombo->valueText().toUTF8();
|
||||
|
||||
valueCombo->clear();
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
auto clusterType = Database::ClusterType::getByName(DboSession(), name);
|
||||
|
||||
auto values = clusterType->getClusters();
|
||||
for (auto value : values)
|
||||
{
|
||||
if (_filterIds.find(value.id()) == _filterIds.end())
|
||||
valueCombo->addItem(Wt::WString::fromUTF8(value->getName()));
|
||||
}
|
||||
}));
|
||||
|
||||
dialog->setModal(true);
|
||||
#if WT_VERSION >= 0x03030700
|
||||
dialog->setMovable(false);
|
||||
#endif
|
||||
|
||||
dialog->setResizable(false);
|
||||
dialog->setClosable(false);
|
||||
|
||||
dialog->finished().connect(std::bind([=]
|
||||
{
|
||||
if (dialog->result() != Wt::WDialog::Accepted)
|
||||
return;
|
||||
|
||||
auto type = typeCombo->valueText().toUTF8();
|
||||
auto value = valueCombo->valueText().toUTF8();
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
auto clusterType = Database::ClusterType::getByName(DboSession(), type);
|
||||
if (!clusterType)
|
||||
return;
|
||||
|
||||
auto cluster = clusterType->getCluster(value);
|
||||
if (!cluster)
|
||||
return;
|
||||
|
||||
auto clusterId = cluster.id();
|
||||
_filterIds.insert(clusterId);
|
||||
_sigUpdated.emit();
|
||||
|
||||
auto filterBtn = new Wt::WPushButton(Wt::WString::fromUTF8(value));
|
||||
_filters->addWidget(filterBtn);
|
||||
|
||||
filterBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
_filters->removeWidget(filterBtn);
|
||||
_filterIds.erase(clusterId);
|
||||
_sigUpdated.emit();
|
||||
}));
|
||||
}));
|
||||
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
Filters::Filters(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
auto container = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.template.filters"), this);
|
||||
|
||||
// Filters
|
||||
Wt::WPushButton *addFilterBtn = new Wt::WPushButton(Wt::WText::tr("Lms.Explore.add-filter"));
|
||||
container->bindWidget("add-filter", addFilterBtn);
|
||||
|
||||
_filters = new Wt::WContainerWidget();
|
||||
container->bindWidget("filters", _filters);
|
||||
|
||||
addFilterBtn->clicked().connect(std::bind([this]
|
||||
{
|
||||
showDialog();
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "Filters.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class Filters : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Filters(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
std::set<Database::Cluster::id_type> getClusterIds() const { return _filterIds; }
|
||||
|
||||
Wt::Signal<void>& updated() { return _sigUpdated; }
|
||||
|
||||
private:
|
||||
|
||||
void showDialog();
|
||||
|
||||
Wt::WContainerWidget *_filters;
|
||||
Wt::Signal<void> _sigUpdated;
|
||||
std::set<Database::Cluster::id_type> _filterIds;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/WAnchor>
|
||||
#include <Wt/WImage>
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
#include "Filters.hpp"
|
||||
#include "ReleaseView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
Release::Release(Filters* filters, Wt::WContainerWidget* parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_filters(filters)
|
||||
{
|
||||
wApp->internalPathChanged().connect(std::bind([=]
|
||||
{
|
||||
refresh();
|
||||
}));
|
||||
|
||||
refresh();
|
||||
|
||||
filters->updated().connect(std::bind([=] {
|
||||
refresh();
|
||||
}));
|
||||
}
|
||||
|
||||
void
|
||||
Release::refresh()
|
||||
{
|
||||
if (!wApp->internalPathMatches("/release/"))
|
||||
return;
|
||||
|
||||
clear();
|
||||
|
||||
Database::Release::id_type releaseId;
|
||||
|
||||
if (!readAs(wApp->internalPathNextPart("/release/"), releaseId))
|
||||
return;
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
auto release = Database::Release::getById(DboSession(), releaseId);
|
||||
if (!release)
|
||||
{
|
||||
LmsApp->goHome();
|
||||
return;
|
||||
}
|
||||
|
||||
auto t = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Release.template"), this);
|
||||
t->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
|
||||
t->bindString("name", Wt::WString::fromUTF8(release->getName()), Wt::PlainText);
|
||||
|
||||
boost::optional<int> year = release->getReleaseYear();
|
||||
if (year)
|
||||
{
|
||||
t->setCondition("if-has-year", true);
|
||||
t->bindInt("year", *year);
|
||||
|
||||
boost::optional<int> originalYear = release->getReleaseYear(true);
|
||||
if (originalYear && *originalYear != *year)
|
||||
{
|
||||
t->setCondition("if-has-orig-year", true);
|
||||
t->bindInt("orig-year", *originalYear);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto artists = release->getArtists();
|
||||
if (artists.size() > 1)
|
||||
{
|
||||
t->bindString("artist-name", Wt::WString::tr("Lms.Explore.various-artists"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(artists.front().id());
|
||||
Wt::WText *artist = new Wt::WText(artistAnchor);
|
||||
artist->setText(Wt::WString::fromUTF8(artists.front()->getName(), Wt::PlainText));
|
||||
t->bindWidget("artist-name", artistAnchor);
|
||||
}
|
||||
}
|
||||
|
||||
Wt::WImage *cover = new Wt::WImage();
|
||||
cover->setImageLink(Wt::WLink(LmsApp->getImageResource()->getReleaseUrl(release.id(), 512)));
|
||||
t->bindWidget("cover", cover);
|
||||
|
||||
auto clusterContainers = new Wt::WContainerWidget();
|
||||
t->bindWidget("clusters", clusterContainers);
|
||||
|
||||
{
|
||||
auto clusters = release->getClusters(3);
|
||||
|
||||
for (auto cluster : clusters)
|
||||
{
|
||||
auto entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Release.template.cluster-entry"), clusterContainers);
|
||||
|
||||
entry->bindString("name", Wt::WString::fromUTF8(cluster->getName()), Wt::PlainText);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto playBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Release.play"), Wt::XHTMLText);
|
||||
t->bindWidget("play-btn", playBtn);
|
||||
playBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
releasePlay.emit(releaseId);
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
auto addBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Release.add"), Wt::XHTMLText);
|
||||
t->bindWidget("add-btn", addBtn);
|
||||
addBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
releaseAdd.emit(releaseId);
|
||||
}));
|
||||
}
|
||||
|
||||
auto tracksContainer = new Wt::WContainerWidget();
|
||||
t->bindWidget("tracks", tracksContainer);
|
||||
|
||||
auto clusterIds = _filters->getClusterIds();
|
||||
auto tracks = release->getTracks(clusterIds);
|
||||
|
||||
bool variousArtists = release->hasVariousArtists();
|
||||
|
||||
for (auto track : tracks)
|
||||
{
|
||||
auto trackId = track.id();
|
||||
|
||||
Wt::WTemplate* entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Release.template.entry"), tracksContainer);
|
||||
|
||||
entry->bindString("name", Wt::WString::fromUTF8(track->getName()), Wt::PlainText);
|
||||
|
||||
if (variousArtists && track->getArtist())
|
||||
{
|
||||
entry->setCondition("if-has-artist", true);
|
||||
Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(track->getArtist().id());
|
||||
Wt::WText *artistText = new Wt::WText(artistAnchor);
|
||||
artistText->setText(Wt::WString::fromUTF8(track->getArtist()->getName(), Wt::PlainText));
|
||||
entry->bindWidget("artist-name", artistAnchor);
|
||||
}
|
||||
|
||||
auto trackNumber = track->getTrackNumber();
|
||||
if (trackNumber)
|
||||
{
|
||||
entry->setCondition("if-has-track-number", true);
|
||||
entry->bindInt("track-number", *trackNumber);
|
||||
}
|
||||
|
||||
auto discNumber = track->getDiscNumber();
|
||||
auto totalDiscNumber = track->getTotalDiscNumber();
|
||||
if (discNumber && totalDiscNumber && *totalDiscNumber > 1)
|
||||
{
|
||||
entry->setCondition("if-has-disc-number", true);
|
||||
entry->bindInt("disc-number", *discNumber);
|
||||
}
|
||||
|
||||
auto playBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Release.play"), Wt::XHTMLText);
|
||||
entry->bindWidget("play-btn", playBtn);
|
||||
playBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
trackPlay.emit(trackId);
|
||||
}));
|
||||
|
||||
auto addBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Release.add"), Wt::XHTMLText);
|
||||
entry->bindWidget("add-btn", addBtn);
|
||||
addBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
trackAdd.emit(trackId);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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 {
|
||||
|
||||
class Filters;
|
||||
class Release : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Release(Filters* filters, Wt::WContainerWidget* parent = 0);
|
||||
|
||||
Wt::Signal<Database::id_type> releaseAdd;
|
||||
Wt::Signal<Database::id_type> releasePlay;
|
||||
|
||||
Wt::Signal<Database::id_type> trackAdd;
|
||||
Wt::Signal<Database::id_type> trackPlay;
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
Filters* _filters;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/WAnchor>
|
||||
#include <Wt/WImage>
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WTemplate>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
#include "Filters.hpp"
|
||||
#include "ReleasesView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
Releases::Releases(Filters* filters, Wt::WContainerWidget* parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_filters(filters)
|
||||
{
|
||||
auto container = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Releases.template"), this);
|
||||
container->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
|
||||
_search = new Wt::WLineEdit();
|
||||
container->bindWidget("search", _search);
|
||||
_search->setPlaceholderText(Wt::WString::tr("Lms.Explore.search-placeholder"));
|
||||
_search->textInput().connect(this, &Releases::refresh);
|
||||
|
||||
_releasesContainer = new Wt::WContainerWidget();
|
||||
container->bindWidget("releases", _releasesContainer);
|
||||
|
||||
_showMore = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.show-more"));
|
||||
_showMore->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
container->bindWidget("show-more", _showMore);
|
||||
|
||||
_showMore->clicked().connect(std::bind([=]
|
||||
{
|
||||
addSome();
|
||||
}));
|
||||
|
||||
refresh();
|
||||
|
||||
filters->updated().connect(this, &Releases::refresh);
|
||||
}
|
||||
|
||||
void
|
||||
Releases::refresh()
|
||||
{
|
||||
_releasesContainer->clear();
|
||||
addSome();
|
||||
}
|
||||
|
||||
void
|
||||
Releases::addSome()
|
||||
{
|
||||
auto searchKeywords = splitString(_search->text().toUTF8(), " ");
|
||||
|
||||
auto clusterIds = _filters->getClusterIds();
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
bool moreResults;
|
||||
auto releases = Release::getByFilter(DboSession(), clusterIds, searchKeywords, _releasesContainer->count(), 20, moreResults);
|
||||
|
||||
for (auto release : releases)
|
||||
{
|
||||
auto releaseId = release.id();
|
||||
|
||||
Wt::WTemplate* entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Releases.template.entry"), _releasesContainer);
|
||||
entry->addFunction("tr", Wt::WTemplate::Functions::tr);
|
||||
|
||||
Wt::WAnchor* coverAnchor = LmsApplication::createReleaseAnchor(releaseId);
|
||||
Wt::WImage* cover = new Wt::WImage(coverAnchor);
|
||||
cover->setImageLink(LmsApp->getImageResource()->getReleaseUrl(releaseId, 128));
|
||||
// Some images may not be square
|
||||
cover->setWidth(128);
|
||||
entry->bindWidget("cover", coverAnchor);
|
||||
|
||||
{
|
||||
Wt::WAnchor* releaseAnchor = LmsApplication::createReleaseAnchor(releaseId);
|
||||
Wt::WText* releaseName = new Wt::WText(releaseAnchor);
|
||||
releaseName->setText(Wt::WString::fromUTF8(release->getName(), Wt::PlainText));
|
||||
entry->bindWidget("release-name", releaseAnchor);
|
||||
}
|
||||
|
||||
|
||||
auto artists = release->getArtists();
|
||||
if (artists.size() > 1)
|
||||
{
|
||||
entry->bindString("artist-name", Wt::WString::tr("Lms.Explore.various-artists"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Wt::WAnchor* artistAnchor = LmsApplication::createArtistAnchor(artists.front().id());
|
||||
Wt::WText* artist = new Wt::WText(artistAnchor);
|
||||
artist->setText(Wt::WString::fromUTF8(artists.front()->getName(), Wt::PlainText));
|
||||
entry->bindWidget("artist-name", artistAnchor);
|
||||
}
|
||||
|
||||
auto playBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Releases.play"), Wt::XHTMLText);
|
||||
entry->bindWidget("play-btn", playBtn);
|
||||
playBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
releasePlay.emit(releaseId);
|
||||
}));
|
||||
|
||||
auto addBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Releases.add"), Wt::XHTMLText);
|
||||
entry->bindWidget("add-btn", addBtn);
|
||||
addBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
releaseAdd.emit(releaseId);
|
||||
}));
|
||||
}
|
||||
|
||||
_showMore->setHidden(!moreResults);
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WText>
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class Filters;
|
||||
|
||||
class Releases : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Releases(Filters* filters, Wt::WContainerWidget* parent = 0);
|
||||
|
||||
Wt::Signal<Database::id_type> releaseAdd;
|
||||
Wt::Signal<Database::id_type> releasePlay;
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
void addSome();
|
||||
|
||||
Filters* _filters;
|
||||
Wt::WTemplate* _showMore;
|
||||
Wt::WLineEdit* _search;
|
||||
Wt::WContainerWidget* _releasesContainer;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/WAnchor>
|
||||
#include <Wt/WImage>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
#include "Filters.hpp"
|
||||
#include "TracksView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
Tracks::Tracks(Filters* filters, Wt::WContainerWidget* parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_filters(filters)
|
||||
{
|
||||
auto container = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Tracks.template"), this);
|
||||
container->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
|
||||
_search = new Wt::WLineEdit();
|
||||
container->bindWidget("search", _search);
|
||||
_search->setPlaceholderText(Wt::WString::tr("Lms.Explore.search-placeholder"));
|
||||
_search->textInput().connect(this, &Tracks::refresh);
|
||||
|
||||
auto playBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Tracks.play"), Wt::XHTMLText);
|
||||
container->bindWidget("play-btn", playBtn);
|
||||
playBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
tracksPlay.emit(getTracks());
|
||||
}));
|
||||
|
||||
auto addBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Tracks.add"), Wt::XHTMLText);
|
||||
container->bindWidget("add-btn", addBtn);
|
||||
addBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
tracksAdd.emit(getTracks());
|
||||
}));
|
||||
|
||||
_tracksContainer = new Wt::WContainerWidget();
|
||||
container->bindWidget("tracks", _tracksContainer);
|
||||
|
||||
_showMore = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.template.show-more"));
|
||||
_showMore->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
container->bindWidget("show-more", _showMore);
|
||||
|
||||
_showMore->clicked().connect(std::bind([=]
|
||||
{
|
||||
addSome();
|
||||
}));
|
||||
|
||||
refresh();
|
||||
|
||||
filters->updated().connect(this, &Tracks::refresh);
|
||||
}
|
||||
|
||||
std::vector<Database::Track::pointer>
|
||||
Tracks::getTracks(int offset, int size, bool& moreResults)
|
||||
{
|
||||
auto searchKeywords = splitString(_search->text().toUTF8(), " ");
|
||||
auto clusterIds = _filters->getClusterIds();
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
return Track::getByFilter(DboSession(), clusterIds, searchKeywords, offset, size, moreResults);
|
||||
}
|
||||
|
||||
std::vector<Database::Track::pointer>
|
||||
Tracks::getTracks()
|
||||
{
|
||||
bool moreResults;
|
||||
return getTracks(-1, -1, moreResults);
|
||||
}
|
||||
|
||||
void
|
||||
Tracks::refresh()
|
||||
{
|
||||
_tracksContainer->clear();
|
||||
addSome();
|
||||
}
|
||||
|
||||
void
|
||||
Tracks::addSome()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
bool moreResults;
|
||||
auto tracks = getTracks(_tracksContainer->count(), 20, moreResults);
|
||||
|
||||
for (auto track : tracks)
|
||||
{
|
||||
auto trackId = track.id();
|
||||
Wt::WTemplate* entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Tracks.template.entry"), _tracksContainer);
|
||||
|
||||
entry->bindString("name", Wt::WString::fromUTF8(track->getName()), Wt::PlainText);
|
||||
|
||||
auto artist = track->getArtist();
|
||||
if (artist)
|
||||
{
|
||||
entry->setCondition("if-has-artist", true);
|
||||
Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(track->getArtist().id());
|
||||
Wt::WText *artistText = new Wt::WText(artistAnchor);
|
||||
artistText->setText(Wt::WString::fromUTF8(artist->getName(), Wt::PlainText));
|
||||
entry->bindWidget("artist-name", artistAnchor);
|
||||
}
|
||||
|
||||
auto release = track->getRelease();
|
||||
if (release)
|
||||
{
|
||||
entry->setCondition("if-has-release", true);
|
||||
Wt::WAnchor *releaseAnchor = LmsApplication::createReleaseAnchor(track->getRelease().id());
|
||||
Wt::WText *releaseText = new Wt::WText(releaseAnchor);
|
||||
releaseText->setText(Wt::WString::fromUTF8(release->getName(), Wt::PlainText));
|
||||
entry->bindWidget("release-name", releaseAnchor);
|
||||
}
|
||||
|
||||
Wt::WImage *cover = new Wt::WImage();
|
||||
cover->setImageLink(LmsApp->getImageResource()->getTrackUrl(track.id(), 64));
|
||||
// Some images may not be square
|
||||
cover->setWidth(64);
|
||||
entry->bindWidget("cover", cover);
|
||||
|
||||
auto playBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Tracks.play"), Wt::XHTMLText);
|
||||
entry->bindWidget("play-btn", playBtn);
|
||||
playBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
trackPlay.emit(trackId);
|
||||
}));
|
||||
|
||||
auto addBtn = new Wt::WText(Wt::WString::tr("Lms.Explore.Tracks.add"), Wt::XHTMLText);
|
||||
entry->bindWidget("add-btn", addBtn);
|
||||
addBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
trackAdd.emit(trackId);
|
||||
}));
|
||||
}
|
||||
|
||||
_showMore->setHidden(!moreResults);
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WTemplate>
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class Filters;
|
||||
class Tracks : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Tracks(Filters* filters, Wt::WContainerWidget* parent = 0);
|
||||
|
||||
Wt::Signal<Database::id_type> trackAdd;
|
||||
Wt::Signal<Database::id_type> trackPlay;
|
||||
|
||||
Wt::Signal<std::vector<Database::Track::pointer>> tracksAdd;
|
||||
Wt::Signal<std::vector<Database::Track::pointer>> tracksPlay;
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
void addSome();
|
||||
|
||||
std::vector<Database::Track::pointer> getTracks(int offset, int size, bool& moreResults);
|
||||
std::vector<Database::Track::pointer> getTracks();
|
||||
|
||||
Wt::WContainerWidget* _tracksContainer;
|
||||
Wt::WTemplate* _showMore;
|
||||
Wt::WLineEdit* _search;
|
||||
Filters* _filters;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
Reference in New Issue
Block a user