Added anchors in the player
This commit is contained in:
@@ -150,10 +150,16 @@ LmsApplication::finalize()
|
||||
preQuit().emit();
|
||||
}
|
||||
|
||||
Wt::WLink
|
||||
LmsApplication::createArtistLink(Database::Artist::pointer artist)
|
||||
{
|
||||
return Wt::WLink(Wt::LinkType::InternalPath, "/artist/" + std::to_string(artist.id()));
|
||||
}
|
||||
|
||||
std::unique_ptr<Wt::WAnchor>
|
||||
LmsApplication::createArtistAnchor(Database::Artist::pointer artist, bool addText)
|
||||
{
|
||||
auto res = std::make_unique<Wt::WAnchor>(Wt::WLink(Wt::LinkType::InternalPath, "/artist/" + std::to_string(artist.id())));
|
||||
auto res = std::make_unique<Wt::WAnchor>(createArtistLink(artist));
|
||||
|
||||
if (addText)
|
||||
{
|
||||
@@ -164,10 +170,16 @@ LmsApplication::createArtistAnchor(Database::Artist::pointer artist, bool addTex
|
||||
return res;
|
||||
}
|
||||
|
||||
Wt::WLink
|
||||
LmsApplication::createReleaseLink(Database::Release::pointer release)
|
||||
{
|
||||
return Wt::WLink(Wt::LinkType::InternalPath, "/release/" + std::to_string(release.id()));
|
||||
}
|
||||
|
||||
std::unique_ptr<Wt::WAnchor>
|
||||
LmsApplication::createReleaseAnchor(Database::Release::pointer release, bool addText)
|
||||
{
|
||||
auto res = std::make_unique<Wt::WAnchor>(Wt::WLink(Wt::LinkType::InternalPath, "/release/" + std::to_string(release.id())));
|
||||
auto res = std::make_unique<Wt::WAnchor>(createReleaseLink(release));
|
||||
|
||||
if (addText)
|
||||
{
|
||||
|
||||
@@ -72,7 +72,9 @@ class LmsApplication : public Wt::WApplication
|
||||
void goHomeAndQuit();
|
||||
void notifyMsg(const Wt::WString& message);
|
||||
|
||||
static Wt::WLink createArtistLink(Database::Artist::pointer artist);
|
||||
static std::unique_ptr<Wt::WAnchor> createArtistAnchor(Database::Artist::pointer artist, bool addText = true);
|
||||
static Wt::WLink createReleaseLink(Database::Release::pointer release);
|
||||
static std::unique_ptr<Wt::WAnchor> createReleaseAnchor(Database::Release::pointer release, bool addText = true);
|
||||
static std::unique_ptr<Wt::WTemplate> createCluster(Database::Cluster::pointer cluster, bool canDelete = false);
|
||||
|
||||
|
||||
+24
-11
@@ -19,8 +19,6 @@
|
||||
|
||||
#include "MediaPlayer.hpp"
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
#include "av/AvInfo.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
@@ -35,17 +33,21 @@
|
||||
namespace UserInterface {
|
||||
|
||||
MediaPlayer::MediaPlayer()
|
||||
: Wt::WTemplate(Wt::WString::tr("template-mediaplayer")),
|
||||
: Wt::WTemplate(Wt::WString::tr("Lms.MediaPlayer.template")),
|
||||
playbackEnded(this, "playbackEnded"),
|
||||
playPrevious(this, "playPrevious"),
|
||||
playNext(this, "playNext")
|
||||
{
|
||||
wApp->doJavaScript("LMS.mediaplayer.init(" + jsRef() + ")");
|
||||
}
|
||||
_title = bindNew<Wt::WText>("title");
|
||||
_title->setTextFormat(Wt::TextFormat::Plain);
|
||||
|
||||
static std::string escape(const std::string& str)
|
||||
{
|
||||
return boost::replace_all_copy(str, "\"", "\\\"");
|
||||
_artist = bindNew<Wt::WAnchor>("artist");
|
||||
_artist->setTextFormat(Wt::TextFormat::Plain);
|
||||
|
||||
_release = bindNew<Wt::WAnchor>("release");
|
||||
_release->setTextFormat(Wt::TextFormat::Plain);
|
||||
|
||||
wApp->doJavaScript("LMS.mediaplayer.init(" + jsRef() + ")");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -66,9 +68,6 @@ MediaPlayer::playTrack(Database::IdType trackId)
|
||||
std::ostringstream oss;
|
||||
oss
|
||||
<< "var params = {"
|
||||
<< " name: \"" << escape(track->getName()) + "\","
|
||||
<< " release: " << (track->getRelease() ? "\"" + escape(track->getRelease()->getName()) + "\"" : "undefined" ) << ","
|
||||
<< " artist: " << (track->getArtist() ? "\"" + escape(track->getArtist()->getName()) + "\"" : "undefined" ) << ","
|
||||
<< " resource: \"" << resource << "\","
|
||||
<< " duration: " << std::chrono::duration_cast<std::chrono::seconds>(track->getDuration()).count() << ","
|
||||
<< " imgResource: \"" << imgResource << "\","
|
||||
@@ -77,6 +76,20 @@ MediaPlayer::playTrack(Database::IdType trackId)
|
||||
|
||||
LMS_LOG(UI, DEBUG) << "Runing js = '" << oss.str() << "'";
|
||||
|
||||
_title->setText(Wt::WString::fromUTF8(track->getName()));
|
||||
|
||||
if (track->getArtist())
|
||||
{
|
||||
_artist->setText(Wt::WString::fromUTF8(track->getArtist()->getName()));
|
||||
_artist->setLink(LmsApp->createArtistLink(track->getArtist()));
|
||||
}
|
||||
|
||||
if (track->getRelease())
|
||||
{
|
||||
_release->setText(Wt::WString::fromUTF8(track->getRelease()->getName()));
|
||||
_release->setLink(LmsApp->createReleaseLink(track->getRelease()));
|
||||
}
|
||||
|
||||
wApp->doJavaScript(oss.str());
|
||||
}
|
||||
catch (Av::MediaFileException& e)
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WAnchor.h>
|
||||
#include <Wt/WJavaScript.h>
|
||||
#include <Wt/WTemplate.h>
|
||||
#include <Wt/WText.h>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
@@ -41,6 +43,9 @@ class MediaPlayer : public Wt::WTemplate
|
||||
|
||||
private:
|
||||
|
||||
Wt::WText* _title;
|
||||
Wt::WAnchor* _release;
|
||||
Wt::WAnchor* _artist;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
Reference in New Issue
Block a user