[UI] First working mobile version
This commit is contained in:
@@ -17,18 +17,191 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WPushButton>
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WTable>
|
||||
|
||||
#include "MobileAudio.hpp"
|
||||
|
||||
#include "ArtistSearch.hpp"
|
||||
#include "ReleaseSearch.hpp"
|
||||
#include "TrackSearch.hpp"
|
||||
#include "MobileAudioMediaPlayer.hpp"
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
Audio::Audio(Wt::WContainerWidget *parent)
|
||||
: UserInterface::Audio(parent)
|
||||
Audio::Audio(Database::Handler& db, Wt::WContainerWidget *parent)
|
||||
: UserInterface::Audio(parent),
|
||||
_db(db)
|
||||
{
|
||||
new Wt::WText("Mobile version not implemented", this);
|
||||
// Root div has to be a "container"
|
||||
this->setStyleClass("container");
|
||||
|
||||
Wt::WTemplate* search = new Wt::WTemplate(this);
|
||||
search->setTemplateText(Wt::WString::tr("mobile-search"));
|
||||
|
||||
Wt::WLineEdit *edit = new Wt::WLineEdit();
|
||||
edit->setEmptyText("Search...");
|
||||
|
||||
search->bindWidget("search", edit);
|
||||
search->setMargin(10);
|
||||
|
||||
ArtistSearch* artistSearch = new ArtistSearch(_db, this);
|
||||
ReleaseSearch* releaseSearch = new ReleaseSearch(_db, this);
|
||||
TrackSearch* trackSearch = new TrackSearch(_db, this);
|
||||
|
||||
Wt::WTemplate* playerTemplate = new Wt::WTemplate(this);
|
||||
playerTemplate->setTemplateText(Wt::WString::tr("mobile-audio-player"));
|
||||
|
||||
AudioMediaPlayer* mediaPlayer = new AudioMediaPlayer();
|
||||
playerTemplate->bindWidget("player", mediaPlayer);
|
||||
|
||||
edit->changed().connect(std::bind([=] () {
|
||||
std::string text = edit->text().toUTF8();
|
||||
|
||||
// When a new search is done, output some results from:
|
||||
// Artist
|
||||
// Release
|
||||
// Song
|
||||
std::vector<std::string> keywords;
|
||||
boost::algorithm::split(keywords, text, boost::is_any_of(" "), boost::token_compress_on);
|
||||
|
||||
{
|
||||
Database::SearchFilter filter;
|
||||
BOOST_FOREACH(std::string keyword, keywords)
|
||||
{
|
||||
Database::SearchFilter::FieldValues likeMatch;
|
||||
|
||||
likeMatch[Database::SearchFilter::Field::Artist].push_back(keyword);
|
||||
likeMatch[Database::SearchFilter::Field::Release].push_back(keyword);
|
||||
filter.likeMatches.push_back(likeMatch);
|
||||
}
|
||||
|
||||
releaseSearch->search(filter, 3);
|
||||
}
|
||||
|
||||
{
|
||||
Database::SearchFilter filter;
|
||||
BOOST_FOREACH(std::string keyword, keywords)
|
||||
{
|
||||
Database::SearchFilter::FieldValues likeMatch;
|
||||
|
||||
likeMatch[Database::SearchFilter::Field::Artist].push_back(keyword);
|
||||
|
||||
filter.likeMatches.push_back(likeMatch);
|
||||
}
|
||||
|
||||
artistSearch->search(filter, 3);
|
||||
}
|
||||
|
||||
{
|
||||
Database::SearchFilter filter;
|
||||
BOOST_FOREACH(std::string keyword, keywords)
|
||||
{
|
||||
Database::SearchFilter::FieldValues likeMatch;
|
||||
|
||||
likeMatch[Database::SearchFilter::Field::Track].push_back(keyword);
|
||||
|
||||
filter.likeMatches.push_back(likeMatch);
|
||||
}
|
||||
|
||||
trackSearch->search(filter, 3);
|
||||
}
|
||||
|
||||
artistSearch->show();
|
||||
releaseSearch->show();
|
||||
trackSearch->show();
|
||||
|
||||
}));
|
||||
|
||||
artistSearch->moreArtistsSelected().connect(std::bind([=] {
|
||||
releaseSearch->hide();
|
||||
trackSearch->hide();
|
||||
artistSearch->show();
|
||||
}));
|
||||
|
||||
artistSearch->artistSelected().connect(std::bind([=] (std::string artist) {
|
||||
artistSearch->hide();
|
||||
trackSearch->hide();
|
||||
releaseSearch->show();
|
||||
|
||||
Database::SearchFilter filter;
|
||||
filter.exactMatch[Database::SearchFilter::Field::Artist].push_back(artist);
|
||||
|
||||
releaseSearch->search(filter, 20);
|
||||
}, std::placeholders::_1));
|
||||
|
||||
releaseSearch->moreReleasesSelected().connect(std::bind([=] {
|
||||
artistSearch->hide();
|
||||
trackSearch->hide();
|
||||
releaseSearch->show();
|
||||
}));
|
||||
|
||||
releaseSearch->releaseSelected().connect(std::bind([=] (std::string release)
|
||||
{
|
||||
artistSearch->hide();
|
||||
releaseSearch->hide();
|
||||
trackSearch->show();
|
||||
|
||||
// TODO load track search with selected release
|
||||
Database::SearchFilter filter;
|
||||
filter.exactMatch[Database::SearchFilter::Field::Release].push_back(release);
|
||||
|
||||
trackSearch->search(filter, 20);
|
||||
}, std::placeholders::_1));
|
||||
|
||||
trackSearch->moreTracksSelected().connect(std::bind([=]
|
||||
{
|
||||
artistSearch->hide();
|
||||
releaseSearch->hide();
|
||||
}));
|
||||
|
||||
trackSearch->trackPlay().connect(std::bind([=] (Database::Track::id_type id)
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Playing track id " << id;
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
Database::Track::pointer track = Database::Track::getById(_db.getSession(), id);
|
||||
|
||||
if (track)
|
||||
{
|
||||
// Determine the output format using the encoding of the player
|
||||
Transcode::Format::Encoding encoding;
|
||||
switch(AudioMediaPlayer::getEncoding())
|
||||
{
|
||||
case Wt::WMediaPlayer::MP3: encoding = Transcode::Format::MP3; break;
|
||||
case Wt::WMediaPlayer::M4A: encoding = Transcode::Format::M4A; break;
|
||||
case Wt::WMediaPlayer::OGA: encoding = Transcode::Format::OGA; break;
|
||||
default:
|
||||
encoding = Transcode::Format::MP3;
|
||||
}
|
||||
// TODO compute parameters using user s profile
|
||||
Transcode::InputMediaFile inputFile(track->getPath());
|
||||
Transcode::Parameters parameters(inputFile, Transcode::Format::get(encoding));
|
||||
parameters.setBitrate(Transcode::Stream::Audio, 96000);
|
||||
|
||||
mediaPlayer->play(parameters);
|
||||
}
|
||||
} , std::placeholders::_1));
|
||||
|
||||
// Initially, populate the widgets using an empty search
|
||||
{
|
||||
Database::SearchFilter filter; // empty filter
|
||||
artistSearch->search(filter, 3);
|
||||
releaseSearch->search(filter, 3);
|
||||
trackSearch->search(filter, 3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
Reference in New Issue
Block a user