Merge branch 'audio-mobile' into develop

This commit is contained in:
emeric
2015-03-05 13:51:57 +01:00
42 changed files with 1292 additions and 107 deletions
+12 -7
View File
@@ -40,13 +40,18 @@ lms_SOURCES = \
$(srcdir)/transcode/InputMediaFile.cpp \
$(srcdir)/ui/LmsApplication.cpp \
$(srcdir)/ui/auth/LmsAuth.cpp \
$(srcdir)/ui/audio/Audio.cpp \
$(srcdir)/ui/audio/AudioMediaPlayer.cpp \
$(srcdir)/ui/audio/FilterChain.cpp \
$(srcdir)/ui/audio/KeywordSearchFilter.cpp \
$(srcdir)/ui/audio/PlayQueue.cpp \
$(srcdir)/ui/audio/TableFilter.cpp \
$(srcdir)/ui/audio/TrackView.cpp \
$(srcdir)/ui/audio/desktop/DesktopAudio.cpp \
$(srcdir)/ui/audio/desktop/AudioMediaPlayer.cpp \
$(srcdir)/ui/audio/desktop/FilterChain.cpp \
$(srcdir)/ui/audio/desktop/KeywordSearchFilter.cpp \
$(srcdir)/ui/audio/desktop/PlayQueue.cpp \
$(srcdir)/ui/audio/desktop/TableFilter.cpp \
$(srcdir)/ui/audio/desktop/TrackView.cpp \
$(srcdir)/ui/audio/mobile/ArtistSearch.cpp \
$(srcdir)/ui/audio/mobile/MobileAudio.cpp \
$(srcdir)/ui/audio/mobile/MobileAudioMediaPlayer.cpp \
$(srcdir)/ui/audio/mobile/ReleaseSearch.cpp \
$(srcdir)/ui/audio/mobile/TrackSearch.cpp \
$(srcdir)/ui/common/DirectoryValidator.cpp \
$(srcdir)/ui/common/LineEdit.cpp \
$(srcdir)/ui/common/SessionData.cpp \
+4
View File
@@ -49,6 +49,10 @@ CoverArt::scale(std::size_t size)
boost::gil::read_image(iss, source, boost::gil::jpeg_tag());
}
if (source.width() == static_cast<int>(size)
&& source.height() == static_cast<int>(size))
return true;
// Resize
boost::gil::resize_view(boost::gil::const_view(source),
boost::gil::view(dest),
+1 -1
View File
@@ -32,7 +32,7 @@ class CoverArt
public:
typedef std::vector<unsigned char> data_type;
CoverArt();
CoverArt() {}
CoverArt(const std::string& mime, const data_type& data) : _mimeType(mime), _data(data) {}
const std::string& getMimeType() const { return _mimeType; }
+20 -2
View File
@@ -72,8 +72,6 @@ Grabber::getFromTrack(const boost::filesystem::path& p)
return res;
}
std::vector<CoverArt>
Grabber::getFromTrack(Database::Track::pointer track)
{
@@ -96,5 +94,25 @@ Grabber::getFromTrack(Database::Track::pointer track)
return res;
}
std::vector<CoverArt>
Grabber::getFromRelease(Wt::Dbo::Session& session, std::string releaseName)
{
using namespace Database;
// For now, just return the embedded cover of the first track
SearchFilter filter;
filter.exactMatch[SearchFilter::Field::Release].push_back(releaseName);
Wt::Dbo::collection<Track::pointer> tracks
= Track::getAll(session, filter, -1, 1 /* limit result size */);
Wt::Dbo::collection<Database::Track::pointer>::iterator it = tracks.begin();
if (it != tracks.end())
return getFromTrack(*it);
else
return std::vector<CoverArt>();
}
} // namespace CoverArt
+1
View File
@@ -37,6 +37,7 @@ class Grabber
static std::vector<CoverArt> getFromInputFormatContext(const Av::InputFormatContext& input);
static std::vector<CoverArt> getFromTrack(Database::Track::pointer track);
static std::vector<CoverArt> getFromTrack(const boost::filesystem::path& path);
static std::vector<CoverArt> getFromRelease(Wt::Dbo::Session& session, std::string releaseName);
};
} // namespace CoverArt
+10 -2
View File
@@ -186,7 +186,7 @@ Track::getAllQuery(Wt::Dbo::Session& session, SearchFilter filter)
SqlQuery sqlQuery = generatePartialQuery(filter);
Wt::Dbo::Query<pointer> query
= session.query<Track::pointer>( "SELECT t FROM track t " + sqlQuery.innerJoin().get() + " " + sqlQuery.where().get()).groupBy("t.id");
= session.query<Track::pointer>( "SELECT t FROM track t " + sqlQuery.innerJoin().get() + " " + sqlQuery.where().get()).groupBy("t.id").orderBy("t.artist_name,t.date,t.release_name,t.disc_number,t.track_number");
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs())
query.bind(bindArg);
@@ -200,6 +200,14 @@ Track::getAll(Wt::Dbo::Session& session, SearchFilter filter, int offset, int si
return getAllQuery(session, filter).limit(size).offset(offset);
}
std::vector<Track::pointer>
Track::getTracks(Wt::Dbo::Session& session, SearchFilter filter, int offset, int size)
{
Wt::Dbo::collection< Track::pointer > tracks = getAll(session, filter, offset, size);
return std::vector<Track::pointer>(tracks.begin(), tracks.end());
}
Wt::Dbo::Query<Track::ReleaseResult>
Track::getReleasesQuery(Wt::Dbo::Session& session, SearchFilter filter)
{
@@ -264,7 +272,7 @@ Track::updateArtistQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel<Art
void
Track::updateTracksQueryModel(Wt::Dbo::Session& session, Wt::Dbo::QueryModel< pointer >& model, SearchFilter filter, const std::vector<Wt::WString>& columnNames)
{
Wt::Dbo::Query< pointer > query = getAllQuery(session, filter).orderBy("t.artist_name,t.date,t.release_name,t.disc_number,t.track_number");
Wt::Dbo::Query< pointer > query = getAllQuery(session, filter);
model.setQuery(query, columnNames.empty() ? true : false);
// TODO do something better
+1
View File
@@ -111,6 +111,7 @@ class Track
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
// Used for remote
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
static std::vector<pointer> getTracks(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
static std::vector<std::string> getReleases(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
static std::vector<std::string> getArtists(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
+3 -1
View File
@@ -70,7 +70,8 @@ AvConvTranscoder::AvConvTranscoder(const Parameters& parameters)
_source(_outputPipe.source, boost::iostreams::close_handle),
_is(_source),
_in(&_is),
_isComplete(false)
_isComplete(false),
_outputBytes(0)
{
if (!boost::filesystem::exists(_parameters.getInputMediaFile().getPath())) {
@@ -179,6 +180,7 @@ AvConvTranscoder::process(std::vector<unsigned char>& output, std::size_t maxSiz
while(readDataSize < maxSize && _in && _in.get(ch)) {
output.push_back(ch);
readDataSize++;
_outputBytes++; // stats
}
if (!_in || _in.fail() || _in.eof()) {
+2
View File
@@ -50,6 +50,7 @@ class AvConvTranscoder
void process(std::vector<unsigned char>& output, std::size_t maxSize);
bool isComplete(void) const { return _isComplete;};
std::size_t getOutputBytes(void) const { return _outputBytes; }
private:
@@ -72,6 +73,7 @@ class AvConvTranscoder
static boost::filesystem::path _avConvPath;
bool _isComplete;
std::size_t _outputBytes; // Bytes produced so far
};
} // naspace Transcode
+1 -1
View File
@@ -72,7 +72,7 @@ Parameters::getOutputBitrate(Stream::Type type) const
{
std::map<Stream::Type, std::size_t>::const_iterator it = _outputBitrate.find(type);
if (it != _inputStreams.end())
if (it != _outputBitrate.end())
{
return it->second;
}
+27 -7
View File
@@ -17,17 +17,15 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Wt/WEnvironment>
#include <Wt/WBootstrapTheme>
#include <Wt/WVBoxLayout>
#include <Wt/WHBoxLayout>
#include <Wt/WNavigationBar>
#include <Wt/WStackedWidget>
#include <Wt/WMenu>
#include <Wt/WNavigationBar>
#include <Wt/WPopupMenu>
#include <Wt/WPopupMenuItem>
#include <Wt/WVBoxLayout>
#include <Wt/WLineEdit>
#include <Wt/Auth/Identity>
#include "logger/Logger.hpp"
@@ -36,7 +34,8 @@
#include "settings/SettingsFirstConnectionFormView.hpp"
#include "auth/LmsAuth.hpp"
#include "audio/Audio.hpp"
#include "audio/desktop/DesktopAudio.hpp"
#include "audio/mobile/MobileAudio.hpp"
#include "video/VideoWidget.hpp"
#include "common/LineEdit.hpp"
@@ -46,6 +45,19 @@ 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 {
@@ -130,7 +142,7 @@ LmsApplication::handleAuthEvent(void)
{
Wt::Auth::User user(_sessionData.getDatabaseHandler().getLogin().user());
LMS_LOG(MOD_UI, SEV_NOTICE) << "User '" << user.identity(Wt::Auth::Identity::LoginName) << "' logged in";
LMS_LOG(MOD_UI, SEV_NOTICE) << "User '" << user.identity(Wt::Auth::Identity::LoginName) << "' logged in from '" << Wt::WApplication::instance()->environment().clientAddress() << "', user agent = " << Wt::WApplication::instance()->environment().agent() << ", session = " << Wt::WApplication::instance()->sessionId();
this->root()->setOverflow(Wt::WContainerWidget::OverflowHidden);
@@ -150,7 +162,15 @@ LmsApplication::handleAuthEvent(void)
Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack);
navigation->addMenu(leftMenu);
Audio *audio = new Audio(_sessionData);
const Wt::WEnvironment& env = Wt::WApplication::instance()->environment();
Audio *audio;
if (agentIsMobile())
audio = new Mobile::Audio(_sessionData.getDatabaseHandler());
else
audio = new Desktop::Audio(_sessionData);
VideoWidget *videoWidget = new VideoWidget(_sessionData);
leftMenu->addItem("Audio", audio);
@@ -193,7 +213,7 @@ LmsApplication::handleAuthEvent(void)
}
else
{
LMS_LOG(MOD_UI, SEV_NOTICE) << "User logged out";
LMS_LOG(MOD_UI, SEV_NOTICE) << "User logged out, session = " << Wt::WApplication::instance()->sessionId();
quit("");
redirect("/");
+64 -2
View File
@@ -318,6 +318,68 @@
</div>
</message>
<message id="mobile-search">
<div class="row">
<div class="col-xs-12">${search}</div>
</div>
</message>
<message id="mobile-search-title">
<div class="row">
<div class="col-xs-12">
<div class="mobile-search-title vertical-align">${text}</div>
</div>
</div>
</message>
<message id="mobile-search-more">
<div class="row">
<div class="col-xs-12">
<div class="mobile-search-more vertical-align">${text}</div>
</div>
</div>
</message>
<message id="mobile-artist-res">
<div class="row">
<div class="col-xs-12 mobile-search-entry">${name}</div>
</div>
</message>
<message id="mobile-release-res">
<div class="row">
<div class="col-xs-12">
<div class="mobile-search-entry">
<div class="row">
<div class ="vertical-align">
<div class="col-xs-2" style="margin-top:3px">${cover}</div>
<div class="col-xs-10">${name}</div>
</div>
</div>
</div>
</div>
</div>
</message>
<message id="mobile-track-res">
<div class="row">
<div class="col-xs-12">
<div class="mobile-search-entry">
<div class="row">
<div class="vertical-align">
<div class="col-xs-2" style="margin-top:3px">${cover}</div>
<div class="col-xs-7">${name}</div>
<div class="col-xs-3">${btn}</div>
</div>
</div>
</div>
</div>
</div>
</message>
<message id="mobile-audio-player">
<div class="row">
<div class="col-xs-12">${player}</div>
</div>
</message>
</messages>
+5 -49
View File
@@ -17,69 +17,25 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUDIO_HPP
#define AUDIO_HPP
#ifndef UI_AUDIO_HPP
#define UI_AUDIO_HPP
#include <string>
#include <Wt/WPopupMenu>
#include <Wt/WContainerWidget>
#include "common/SessionData.hpp"
#include "AudioMediaPlayer.hpp"
#include "TrackView.hpp"
#include "PlayQueue.hpp"
#include "FilterChain.hpp"
namespace UserInterface {
class Audio : public Wt::WContainerWidget
{
public:
Audio(SessionData& sessionData, Wt::WContainerWidget* parent = 0);
Audio(Wt::WContainerWidget *parent) : Wt::WContainerWidget(parent) {}
virtual ~Audio() {}
void search(const std::string& searchText);
virtual void search(std::string text) = 0;
private:
void playlistSaveFromPlayqueue(std::string name);
void playlistLoadToPlayqueue(std::string name);
void playlistShowSaveNewDialog();
void playlistShowSaveDialog(std::string name);
void playlistShowDeleteDialog(std::string name);
void playlistRefreshMenus();
void playTrack(boost::filesystem::path p);
enum PlayQueueAddType
{
PlayQueueAddAllTracks,
PlayQueueAddSelectedTracks,
};
void playSelectedTracks(PlayQueueAddType addType);
void addSelectedTracks();
void handlePlaylistSelected(Wt::WString name);
Database::Handler& _db;
AudioMediaPlayer* _mediaPlayer;
TrackView* _trackView;
PlayQueue* _playQueue;
FilterChain _filterChain;
Wt::WPopupMenu* _popupMenuSave;
Wt::WPopupMenu* _popupMenuLoad;
Wt::WPopupMenu* _popupMenuDelete;
};
} // namespace UserInterface
#endif
@@ -29,6 +29,7 @@
#include "AudioMediaPlayer.hpp"
namespace UserInterface {
namespace Desktop {
Wt::WMediaPlayer::Encoding
AudioMediaPlayer::getEncoding()
@@ -224,4 +225,5 @@ AudioMediaPlayer::handleVolumeSliderMoved(int value)
_mediaPlayer->setVolume( value / 100. );
}
} // namespace Desktop
} // namespace UserInterface
@@ -33,6 +33,7 @@
#include "resource/AvConvTranscodeStreamResource.hpp"
namespace UserInterface {
namespace Desktop {
class AudioMediaPlayer : public Wt::WContainerWidget
{
@@ -88,6 +89,7 @@ class AudioMediaPlayer : public Wt::WContainerWidget
};
} // namespace Desktop
} // namespace UserInterface
#endif
@@ -36,7 +36,7 @@
#include "TableFilter.hpp"
#include "KeywordSearchFilter.hpp"
#include "Audio.hpp"
#include "DesktopAudio.hpp"
namespace {
@@ -49,9 +49,10 @@ void WPopupMenuClear(Wt::WPopupMenu* menu)
}
namespace UserInterface {
namespace Desktop {
Audio::Audio(SessionData& sessionData, Wt::WContainerWidget* parent)
: Wt::WContainerWidget(parent),
: UserInterface::Audio(parent),
_db(sessionData.getDatabaseHandler()),
_mediaPlayer(nullptr),
_trackView(nullptr),
@@ -418,7 +419,7 @@ Audio::playlistRefreshMenus()
}
void
Audio::search(const std::string& searchText)
Audio::search(std::string searchText)
{
_filterChain.searchKeyword(searchText);
}
@@ -525,6 +526,6 @@ Audio::playTrack(boost::filesystem::path p)
}
}
} // namespace Desktop
} // namespace UserInterface
+88
View File
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UI_AUDIO_DESKTOP_HPP
#define UI_AUDIO_DESKTOP_HPP
#include <string>
#include <Wt/WPopupMenu>
#include "common/SessionData.hpp"
#include "AudioMediaPlayer.hpp"
#include "TrackView.hpp"
#include "PlayQueue.hpp"
#include "FilterChain.hpp"
#include "audio/Audio.hpp"
namespace UserInterface {
namespace Desktop {
class Audio : public UserInterface::Audio
{
public:
Audio(SessionData& sessionData, Wt::WContainerWidget* parent = 0);
void search(std::string searchText);
private:
void playlistSaveFromPlayqueue(std::string name);
void playlistLoadToPlayqueue(std::string name);
void playlistShowSaveNewDialog();
void playlistShowSaveDialog(std::string name);
void playlistShowDeleteDialog(std::string name);
void playlistRefreshMenus();
void playTrack(boost::filesystem::path p);
enum PlayQueueAddType
{
PlayQueueAddAllTracks,
PlayQueueAddSelectedTracks,
};
void playSelectedTracks(PlayQueueAddType addType);
void addSelectedTracks();
void handlePlaylistSelected(Wt::WString name);
Database::Handler& _db;
AudioMediaPlayer* _mediaPlayer;
TrackView* _trackView;
PlayQueue* _playQueue;
FilterChain _filterChain;
Wt::WPopupMenu* _popupMenuSave;
Wt::WPopupMenu* _popupMenuLoad;
Wt::WPopupMenu* _popupMenuDelete;
};
} // namespace Desktop
} // namespace UserInterface
#endif
@@ -25,6 +25,7 @@
#include "database/Types.hpp"
namespace UserInterface {
namespace Desktop {
class Filter
{
@@ -58,6 +59,7 @@ class Filter
Wt::Signal<void> _update;
};
} // namespace Dekstop
} // namespace UserInterface
#endif
@@ -20,6 +20,7 @@
#include "FilterChain.hpp"
namespace UserInterface {
namespace Desktop {
FilterChain::FilterChain()
@@ -69,5 +70,6 @@ FilterChain::updateFilters(std::size_t startIdx)
_refreshingFilters = false;
}
} // namespace Desktop
} // namespace UserInterface
@@ -26,6 +26,7 @@
#include "KeywordSearchFilter.hpp"
namespace UserInterface {
namespace Desktop {
// FilterChain
class FilterChain
@@ -52,6 +53,7 @@ class FilterChain
bool _refreshingFilters;
};
} // namespace Desktop
} // namespace UserInterface
#endif
@@ -24,6 +24,7 @@
#include "KeywordSearchFilter.hpp"
namespace UserInterface {
namespace Desktop {
KeywordSearchFilter::KeywordSearchFilter()
{
@@ -60,5 +61,6 @@ KeywordSearchFilter::getConstraint(Database::SearchFilter& filter)
}
}
} // namespace Desktop
} // namespace UserInterface
@@ -25,6 +25,7 @@
#include "Filter.hpp"
namespace UserInterface {
namespace Desktop {
class KeywordSearchFilter : public Filter
{
@@ -46,6 +47,7 @@ class KeywordSearchFilter : public Filter
std::string _lastEmittedText;
};
} // namespace Desktop
} // namespace UserInterface
#endif
@@ -58,6 +58,7 @@ namespace {
}
namespace UserInterface {
namespace Desktop {
enum ColumnId
{
@@ -377,7 +378,7 @@ PlayQueue::addTracks(const std::vector<Database::Track::id_type>& trackIds)
std::string coverUrl;
if (track->hasCover())
coverUrl = _coverResource->url() + "&coverid=" + Wt::asString(track.id()).toUTF8();
coverUrl = _coverResource->getTrackUrl(track.id());
else
coverUrl = "images/unknown-cover.jpg";
_model->setData(dataRow, COLUMN_ID_COVER, coverUrl, Wt::DecorationRole);
@@ -612,5 +613,6 @@ PlayQueue::getTracks(std::vector<Database::Track::id_type>& trackIds) const
}
}
} // namespace Desktop
} // namespace UserInterface
@@ -28,6 +28,7 @@
#include "resource/CoverResource.hpp"
namespace UserInterface {
namespace Desktop {
class PlayQueueItemDelegate;
class TrackSelector;
@@ -86,7 +87,7 @@ class PlayQueue : public Wt::WTableView
};
} // namespace Desktop
} // namespace UserInterface
#endif
@@ -28,6 +28,7 @@
#include "TableFilter.hpp"
namespace UserInterface {
namespace Desktop {
using namespace Database;
@@ -253,5 +254,6 @@ TableFilterRelease::getConstraint(SearchFilter& filter)
}
}
} // namespace Desktop
} // namespace UserInterface
@@ -28,6 +28,7 @@
#include "database/DatabaseHandler.hpp"
namespace UserInterface {
namespace Desktop {
class TableFilterGenre : public Wt::WTableView, public Filter
{
@@ -111,6 +112,7 @@ class TableFilterRelease : public Wt::WTableView, public Filter
};
} // namespace Desktop
} // namespace UserInterface
#endif
@@ -28,6 +28,7 @@
#include "TrackView.hpp"
namespace UserInterface {
namespace Desktop {
TrackView::TrackView( Database::Handler& db, Wt::WContainerWidget* parent)
: Wt::WTableView( parent ),
@@ -169,5 +170,6 @@ TrackView::getTracks(std::vector<Database::Track::id_type>& trackIds)
LMS_LOG(MOD_UI, SEV_DEBUG) << "Getting all tracks done!";
}
} // namespace Desktop
} // namespace UserInterface
@@ -28,6 +28,7 @@
#include "Filter.hpp"
namespace UserInterface {
namespace Desktop {
class TrackView : public Wt::WTableView, public Filter
{
@@ -69,6 +70,7 @@ class TrackView : public Wt::WTableView, public Filter
};
} // namespace Desktop
} // namespace UserInterface
#endif
+111
View File
@@ -0,0 +1,111 @@
/*
* 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/WText>
#include <Wt/WTemplate>
#include <Wt/WPushButton>
#include "ArtistSearch.hpp"
namespace UserInterface {
namespace Mobile {
ArtistSearch::ArtistSearch(Database::Handler& db, Wt::WContainerWidget *parent)
: Wt::WContainerWidget(parent),
_db(db),
_resCount(0)
{
Wt::WTemplate *title = new Wt::WTemplate(this);
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
title->bindWidget("text", new Wt::WText("Artists", Wt::PlainText));
}
void
ArtistSearch::clear()
{
while (count() > 1)
removeWidget(this->widget(1));
_resCount = 0;
}
void
ArtistSearch::search(Database::SearchFilter filter, size_t nb)
{
clear();
addResults(filter, nb);
}
void
ArtistSearch::addResults(Database::SearchFilter filter, std::size_t nb)
{
std::vector<std::string> artists;
{
Wt::Dbo::Transaction transaction(_db.getSession());
// Request one more to see if more results are to be expected
artists = Database::Track::getArtists(_db.getSession(), filter, _resCount, nb + 1);
}
bool expectMoreResults;
if (artists.size() == nb + 1)
{
expectMoreResults = true;
artists.pop_back();
}
else
expectMoreResults = false;
BOOST_FOREACH(std::string artist, artists)
{
Wt::WTemplate* res = new Wt::WTemplate(this);
res->setTemplateText(Wt::WString::tr("mobile-artist-res"));
Wt::WText *text = new Wt::WText(Wt::WString::fromUTF8(artist), Wt::PlainText);
res->bindWidget("name", text);
res->clicked().connect(std::bind([=] {
_sigArtistSelected(artist);
}));
}
_resCount += artists.size();;
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([=] {
_sigMoreArtistsSelected();
removeWidget(moreRes);
addResults(filter, 20);
}));
}
}
} // namespace Mobile
} // namespace UserInterface
+58
View File
@@ -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/>.
*/
#ifndef UI_MOBILE_ARTIST_SEARCH_HPP
#define UI_MOBILE_ARTIST_SEARCH_HPP
#include <boost/algorithm/string/split.hpp>
#include <Wt/WContainerWidget>
#include "database/DatabaseHandler.hpp"
namespace UserInterface {
namespace Mobile {
class ArtistSearch : public Wt::WContainerWidget
{
public:
ArtistSearch(Database::Handler& db, Wt::WContainerWidget *parent = 0);
void search(Database::SearchFilter filter, std::size_t nb);
// Slots
Wt::Signal<std::string>& artistSelected() { return _sigArtistSelected;}
Wt::Signal<void>& moreArtistsSelected() { return _sigMoreArtistsSelected;}
private:
Wt::Signal<std::string> _sigArtistSelected;
Wt::Signal<void> _sigMoreArtistsSelected;
void clear(void);
void addResults(Database::SearchFilter filter, size_t nb);
Database::Handler& _db;
std::size_t _resCount;
};
} // namespace Mobile
} // namespace UserInterface
#endif
+209
View File
@@ -0,0 +1,209 @@
/*
* 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 <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(Database::Handler& db, Wt::WContainerWidget *parent)
: UserInterface::Audio(parent),
_db(db)
{
// 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
} // namespace UserInterface
+47
View File
@@ -0,0 +1,47 @@
/*
* 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/>.
*/
#ifndef UI_AUDIO_MOBILE_HPP
#define UI_AUDIO_MOBILE_HPP
#include <Wt/WContainerWidget>
#include "database/DatabaseHandler.hpp"
#include "audio/Audio.hpp"
namespace UserInterface {
namespace Mobile {
class Audio : public UserInterface::Audio
{
public:
Audio(Database::Handler& db, Wt::WContainerWidget *parent = 0);
void search(std::string text) {}
private:
Database::Handler& _db;
};
} // namespace Mobile
} // namespace UserInterface
#endif
@@ -0,0 +1,60 @@
/*
* 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 <Wt/WEnvironment>
#include "MobileAudioMediaPlayer.hpp"
#include "resource/AvConvTranscodeStreamResource.hpp"
namespace UserInterface {
namespace Mobile {
Wt::WMediaPlayer::Encoding
AudioMediaPlayer::getEncoding()
{
const Wt::WEnvironment& env = Wt::WApplication::instance()->environment();
if (env.agentIsIE())
return Wt::WMediaPlayer::MP3;
else
return Wt::WMediaPlayer::OGA;
}
AudioMediaPlayer::AudioMediaPlayer(Wt::WContainerWidget *parent)
: Wt::WContainerWidget(parent)
{
_player = new Wt::WMediaPlayer(Wt::WMediaPlayer::Audio, this);
_player->addSource( getEncoding(), "" );
}
void
AudioMediaPlayer::play(const Transcode::Parameters& parameters)
{
AvConvTranscodeStreamResource *resource = new AvConvTranscodeStreamResource( parameters, this );
_player->clearSources();
_player->addSource( getEncoding(), Wt::WLink(resource));
_player->play();
}
} // namespace UserInterface
} // namespace Mobile
@@ -0,0 +1,50 @@
/*
* 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/>.
*/
#ifndef UI_AUDIO_MOBILE_MEDIA_PLAYER_HPP
#define UI_AUDIO_MOBILE_MEDIA_PLAYER_HPP
#include <Wt/WContainerWidget>
#include <Wt/WMediaPlayer>
#include "transcode/Parameters.hpp"
namespace UserInterface {
namespace Mobile {
class AudioMediaPlayer : public Wt::WContainerWidget
{
public:
static Wt::WMediaPlayer::Encoding getEncoding();
AudioMediaPlayer(Wt::WContainerWidget *parent = 0);
void play(const Transcode::Parameters& parameters);
private:
Wt::WMediaPlayer *_player;
};
} // namespace UserInterface
} // namespace Mobile
#endif
+120
View File
@@ -0,0 +1,120 @@
/*
* 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/WText>
#include <Wt/WImage>
#include <Wt/WPushButton>
#include <Wt/WTemplate>
#include "logger/Logger.hpp"
#include "ReleaseSearch.hpp"
namespace UserInterface {
namespace Mobile {
ReleaseSearch::ReleaseSearch(Database::Handler& db, Wt::WContainerWidget *parent)
: Wt::WContainerWidget(parent),
_db(db),
_resCount(0)
{
Wt::WTemplate* title = new Wt::WTemplate(this);
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
title->bindWidget("text", new Wt::WText("Releases", Wt::PlainText));
_coverResource = new CoverResource(db, 56);
}
void
ReleaseSearch::clear()
{
while (count() > 1)
removeWidget(this->widget(1));
_resCount = 0;
}
void
ReleaseSearch::search(Database::SearchFilter filter, size_t max)
{
clear();
addResults(filter, max);
}
void
ReleaseSearch::addResults(Database::SearchFilter filter, size_t nb)
{
std::vector<std::string> releases;
{
Wt::Dbo::Transaction transaction(_db.getSession());
// Request one more to see if more results are to be expected
releases = Database::Track::getReleases(_db.getSession(), filter, _resCount, nb + 1);
}
bool expectMoreResults;
if (releases.size() == nb + 1)
{
expectMoreResults = true;
releases.pop_back();
}
else
expectMoreResults = false;
BOOST_FOREACH(std::string release, releases)
{
Wt::WTemplate* releaseWidget = new Wt::WTemplate(this);
releaseWidget->setTemplateText(Wt::WString::tr("mobile-release-res"));
Wt::WImage *cover = new Wt::WImage();
cover->setStyleClass("center-block");
cover->setImageLink( Wt::WLink( _coverResource->getReleaseUrl(release)));
releaseWidget->bindWidget("cover", cover);
releaseWidget->bindWidget("name", new Wt::WText(Wt::WString::fromUTF8(release), Wt::PlainText));
releaseWidget->clicked().connect(std::bind([=] {
_sigReleaseSelected(release);
}));
}
_resCount += releases.size();;
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
} // namespace UserInterface
+65
View File
@@ -0,0 +1,65 @@
/*
* 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/>.
*/
#ifndef UI_MOBILE_RELEASE_SEARCH_HPP
#define UI_MOBILE_RELEASE_SEARCH_HPP
#include <boost/algorithm/string/split.hpp>
#include <Wt/WContainerWidget>
#include <Wt/WSignal>
#include "resource/CoverResource.hpp"
#include "database/DatabaseHandler.hpp"
namespace UserInterface {
namespace Mobile {
class ReleaseSearch : public Wt::WContainerWidget
{
public:
ReleaseSearch(Database::Handler& db, Wt::WContainerWidget *parent = 0);
void search(Database::SearchFilter filter, size_t nb);
// Slots
Wt::Signal<std::string>& releaseSelected() { return _sigReleaseSelected;}
Wt::Signal<void>& moreReleasesSelected() { return _sigMoreReleasesSelected;}
private:
Wt::Signal<std::string> _sigReleaseSelected;
Wt::Signal<void> _sigMoreReleasesSelected;
void clear(void);
void addResults(Database::SearchFilter filter, size_t nb);
Database::Handler& _db;
CoverResource* _coverResource;
std::size_t _resCount;
};
} // namespace Mobile
} // namespace UserInterface
#endif
+133
View File
@@ -0,0 +1,133 @@
/*
* 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/WText>
#include <Wt/WImage>
#include <Wt/WPushButton>
#include <Wt/WTemplate>
#include "logger/Logger.hpp"
#include "TrackSearch.hpp"
namespace UserInterface {
namespace Mobile {
TrackSearch::TrackSearch(Database::Handler& db, Wt::WContainerWidget *parent)
: Wt::WContainerWidget(parent),
_db(db),
_resCount(0)
{
Wt::WTemplate* title = new Wt::WTemplate(this);
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
title->bindWidget("text", new Wt::WText("Tracks", Wt::PlainText));
_coverResource = new CoverResource(db, 56);
}
void
TrackSearch::clear()
{
while (count() > 1)
removeWidget(this->widget(1));
_resCount = 0;
}
void
TrackSearch::search(Database::SearchFilter filter, size_t max)
{
clear();
addResults(filter, max);
}
void
TrackSearch::addResults(Database::SearchFilter filter, size_t nb)
{
Wt::Dbo::Transaction transaction(_db.getSession());
std::vector< Database::Track::pointer > tracks = Database::Track::getTracks(_db.getSession(), filter, _resCount, nb + 1);
bool expectMoreResults;
if (tracks.size() == nb + 1)
{
expectMoreResults = true;
tracks.pop_back();
}
else
expectMoreResults = false;
BOOST_FOREACH(Database::Track::pointer track, tracks)
{
Wt::WTemplate* trackWidget = new Wt::WTemplate(this);
trackWidget->setTemplateText(Wt::WString::tr("mobile-track-res"));
Wt::WImage *cover = new Wt::WImage();
cover->setStyleClass("center-block");
cover->setImageLink( Wt::WLink (_coverResource->getTrackUrl(track.id())) );
trackWidget->bindWidget("cover", cover);
// Track Name (bold)
// Artist - Album (italic)
Wt::WContainerWidget *container = new Wt::WContainerWidget();
Wt::WText *title = new Wt::WText(Wt::WString::fromUTF8(track->getName()), Wt::PlainText);
title->setStyleClass("mobile-track");
container->addWidget(title);
if (!track->getArtistName().empty()
|| !track->getReleaseName().empty())
{
title->setInline(false);
Wt::WText *artistRelease = new Wt::WText(Wt::WString::fromUTF8(track->getArtistName() + " - " + track->getReleaseName()), Wt::PlainText);
artistRelease->setStyleClass("mobile-artist");
container->addWidget(artistRelease);
}
trackWidget->bindWidget("name", container);
Wt::WPushButton *playBtn = new Wt::WPushButton("Play");
playBtn->setStyleClass("btn-primary center-block");
playBtn->clicked().connect(std::bind([=] {
_sigTrackPlay.emit(track.id());
}));
trackWidget->bindWidget("btn", playBtn);
}
_resCount += tracks.size();
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([=] {
_sigMoreTracksSelected();
removeWidget(moreRes);
addResults(filter, 20);
}));
}
}
} // namespace Mobile
} // namespace UserInterface
+65
View File
@@ -0,0 +1,65 @@
/*
* 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/>.
*/
#ifndef UI_MOBILE_TRACK_SEARCH_HPP
#define UI_MOBILE_TRACK_SEARCH_HPP
#include <boost/algorithm/string/split.hpp>
#include <Wt/WContainerWidget>
#include <Wt/WSignal>
#include "resource/CoverResource.hpp"
#include "database/DatabaseHandler.hpp"
namespace UserInterface {
namespace Mobile {
class TrackSearch : public Wt::WContainerWidget
{
public:
TrackSearch(Database::Handler& db, Wt::WContainerWidget *parent = 0);
void search(Database::SearchFilter filter, size_t nb);
// Slots
Wt::Signal<Database::Track::id_type>& trackPlay() { return _sigTrackPlay;}
Wt::Signal<void>& moreTracksSelected() { return _sigMoreTracksSelected;}
private:
Wt::Signal<Database::Track::id_type> _sigTrackPlay;
Wt::Signal<void> _sigMoreTracksSelected;
void clear(void);
void addResults(Database::SearchFilter filter, size_t nb);
Database::Handler& _db;
CoverResource* _coverResource;
std::size_t _resCount;
};
} // namespace Mobile
} // namespace UserInterface
#endif
+41
View File
@@ -55,3 +55,44 @@ div.contents {
font-weight: bold;
}
.mobile-search-title {
font-weight: bold;
height: 32px;
background-color: grey;
color: white;
text-align: center;
}
.mobile-search-entry {
min-height: 64px;
border-bottom: 1px solid lightgray;
overflow: hidden;
text-overflow: ellipsis;
}
.mobile-search-entry:active {
background-color: lightgrey;
}
.mobile-search-more {
height: 64px;
border-bottom: 1px solid lightgray;
}
.mobile-search-more:active {
background-color: lightgrey;
}
.mobile-track {
font-weight: bold;
}
.mobile-artist {
font-style: italic;
}
.vertical-align {
display: flex;
align-items: center;
}
@@ -44,11 +44,11 @@ void
AvConvTranscodeStreamResource::handleRequest(const Wt::Http::Request& request,
Wt::Http::Response& response)
{
static const std::size_t chunkSize = 8192; // TODO parametrize?
// see if this request is for a continuation:
Wt::Http::ResponseContinuation *continuation = request.continuation();
LMS_LOG(MOD_UI, SEV_DEBUG) << "Handling new request. Continuation = " << std::boolalpha << continuation;
std::shared_ptr<Transcode::AvConvTranscoder> transcoder;
if (continuation)
transcoder = boost::any_cast<std::shared_ptr<Transcode::AvConvTranscoder> >(continuation->data());
@@ -65,13 +65,15 @@ AvConvTranscodeStreamResource::handleRequest(const Wt::Http::Request& request,
if (!transcoder->isComplete())
{
std::vector<unsigned char> data;
data.reserve(chunkSize);
data.reserve(_bufferSize);
transcoder->process(data, chunkSize);
transcoder->process(data, _bufferSize);
// Give the client all the output data
response.out().write(reinterpret_cast<char*>(&data[0]), data.size());
LMS_LOG(MOD_UI, SEV_DEBUG) << "Written " << data.size() << " bytes! complete = " << std::boolalpha << transcoder->isComplete() << ", produced bytes = " << transcoder->getOutputBytes();
if (!response.out())
LMS_LOG(MOD_UI, SEV_ERROR) << "Write failed!";
}
+51 -25
View File
@@ -35,6 +35,21 @@ CoverResource::CoverResource(Database::Handler& db, std::size_t size, Wt::WObjec
_db(db),
_size(size)
{
// Load default cover art
std::vector<unsigned char> data;
{
std::ifstream ist(Wt::WApplication::instance()->docRoot() + "/images/unknown-cover.jpg");
char c;
while(ist.get(c))
data.push_back(c);
}
_defaultCover.setData(data);
_defaultCover.setMimeType("image/jpeg");
_defaultCover.scale(size);
}
CoverResource:: ~CoverResource()
@@ -42,55 +57,66 @@ CoverResource:: ~CoverResource()
beingDeleted();
}
std::string
CoverResource::getReleaseUrl(std::string releaseName)
{
return url() + "&release=" + releaseName;
}
std::string
CoverResource::getTrackUrl(Database::Track::id_type trackId)
{
return url()+ "&trackid=" + std::to_string(trackId);
}
void
CoverResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response)
{
// Get the id of the track
const std::string *trackIdStr = request.getParameter("coverid");
const std::string *trackIdStr = request.getParameter("trackid");
const std::string *releaseStr = request.getParameter("release");
std::vector<CoverArt::CoverArt> covers;
if (trackIdStr)
{
Database::Track::id_type trackId;
{
std::istringstream iss(*trackIdStr); iss >> trackId;
std::istringstream iss(*trackIdStr);
iss >> trackId;
}
Wt::Dbo::Transaction transaction(_db.getSession());
Database::Track::pointer track = Database::Track::getById(_db.getSession(), trackId);
std::vector<CoverArt::CoverArt> covers = CoverArt::Grabber::getFromTrack(track);
covers = CoverArt::Grabber::getFromTrack(track);
transaction.commit();
}
else if (releaseStr)
{
Wt::Dbo::Transaction transaction(_db.getSession());
covers = CoverArt::Grabber::getFromRelease(_db.getSession(), *releaseStr);
}
BOOST_FOREACH(CoverArt::CoverArt& cover, covers)
BOOST_FOREACH(CoverArt::CoverArt& cover, covers)
{
if (cover.scale(_size))
{
if (cover.scale(_size))
{
response.setMimeType( cover.getMimeType() );
response.setMimeType( cover.getMimeType() );
BOOST_FOREACH(unsigned char c, cover.getData())
response.out().put( c );
return;
}
else
LMS_LOG(MOD_UI, SEV_DEBUG) << "Resize error for track id = " << trackId;
}
LMS_LOG(MOD_UI, SEV_DEBUG) << "no valid cover found for track id = " << trackId;
{
std::ifstream ist(Wt::WApplication::instance()->docRoot() + "/images/unknown-cover.jpg");
char c;
while(ist.get(c))
BOOST_FOREACH(unsigned char c, cover.getData())
response.out().put( c );
response.setMimeType("image/jpeg");
return;
}
}
else
LMS_LOG(MOD_UI, SEV_DEBUG) << "no cover id parameter";
// If no cover found, just send default one
response.setMimeType( _defaultCover.getMimeType() );
BOOST_FOREACH(unsigned char c, _defaultCover.getData())
response.out().put( c );
}
} // namespace UserInterface
+5
View File
@@ -26,6 +26,7 @@
#include <Wt/WResource>
#include "database/DatabaseHandler.hpp"
#include "cover/CoverArt.hpp"
namespace UserInterface {
@@ -37,12 +38,16 @@ class CoverResource : public Wt::WResource
Wt::WObject *parent = 0);
~CoverResource();
std::string getReleaseUrl(std::string releaseName);
std::string getTrackUrl(Database::Track::id_type trackId);
void handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response);
private:
Database::Handler& _db;
std::size_t _size;
CoverArt::CoverArt _defaultCover;
};
} // namespace UserInterface