diff --git a/src/ui/LmsApplication.cpp b/src/ui/LmsApplication.cpp index f5985f6d..531f07c5 100644 --- a/src/ui/LmsApplication.cpp +++ b/src/ui/LmsApplication.cpp @@ -161,15 +161,31 @@ Scanner::MediaScanner& MediaScanner() } Wt::WAnchor* -LmsApplication::createArtistAnchor(Database::id_type id) +LmsApplication::createArtistAnchor(Database::Artist::pointer artist, bool addText) { - return new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(id))); + auto res = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(artist.id()))); + + if (addText) + { + res->setTextFormat(Wt::PlainText); + res->setText(Wt::WString::fromUTF8(artist->getName())); + } + + return res; } Wt::WAnchor* -LmsApplication::createReleaseAnchor(Database::id_type id) +LmsApplication::createReleaseAnchor(Database::Release::pointer release, bool addText) { - return new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(id))); + auto res = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(release.id()))); + + if (addText) + { + res->setTextFormat(Wt::PlainText); + res->setText(Wt::WString::fromUTF8(release->getName())); + } + + return res; } void diff --git a/src/ui/LmsApplication.hpp b/src/ui/LmsApplication.hpp index 5b7d336a..098f6856 100644 --- a/src/ui/LmsApplication.hpp +++ b/src/ui/LmsApplication.hpp @@ -51,8 +51,8 @@ class LmsApplication : public Wt::WApplication void quit(); void notify(const Wt::WString& message); - static Wt::WAnchor* createArtistAnchor(Database::id_type id); - static Wt::WAnchor* createReleaseAnchor(Database::id_type id); + static Wt::WAnchor* createArtistAnchor(Database::Artist::pointer artist, bool addText = true); + static Wt::WAnchor* createReleaseAnchor(Database::Release::pointer release, bool addText = true); private: diff --git a/src/ui/PlayQueueView.cpp b/src/ui/PlayQueueView.cpp index e5bce0b4..ae329179 100644 --- a/src/ui/PlayQueueView.cpp +++ b/src/ui/PlayQueueView.cpp @@ -228,18 +228,14 @@ PlayQueue::addSome() 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)); + Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(track->getArtist()); 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)); + Wt::WAnchor *releaseAnchor = LmsApplication::createReleaseAnchor(track->getRelease()); entry->bindWidget("release-name", releaseAnchor); } diff --git a/src/ui/explore/ArtistView.cpp b/src/ui/explore/ArtistView.cpp index ec21c004..96caffca 100644 --- a/src/ui/explore/ArtistView.cpp +++ b/src/ui/explore/ArtistView.cpp @@ -123,7 +123,7 @@ Artist::refresh() entry->addFunction("tr", Wt::WTemplate::Functions::tr); { - Wt::WAnchor* coverAnchor = LmsApplication::createReleaseAnchor(releaseId); + Wt::WAnchor* coverAnchor = LmsApplication::createReleaseAnchor(release, false); Wt::WImage* cover = new Wt::WImage(coverAnchor); cover->setImageLink(LmsApp->getImageResource()->getReleaseUrl(release.id(), 128)); // Some images may not be square @@ -132,9 +132,7 @@ Artist::refresh() } { - Wt::WAnchor* releaseAnchor = LmsApplication::createReleaseAnchor(releaseId); - Wt::WText* releaseName = new Wt::WText(releaseAnchor); - releaseName->setText(Wt::WString::fromUTF8(release->getName(), Wt::PlainText)); + Wt::WAnchor* releaseAnchor = LmsApplication::createReleaseAnchor(release); entry->bindWidget("name", releaseAnchor); } diff --git a/src/ui/explore/ArtistsView.cpp b/src/ui/explore/ArtistsView.cpp index b48ce1b6..cd1ff5ab 100644 --- a/src/ui/explore/ArtistsView.cpp +++ b/src/ui/explore/ArtistsView.cpp @@ -18,7 +18,6 @@ */ #include -#include #include #include @@ -93,9 +92,7 @@ Artists::addSome() 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)); + Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(artist); entry->bindWidget("name", artistAnchor); } } diff --git a/src/ui/explore/ReleaseView.cpp b/src/ui/explore/ReleaseView.cpp index be145adb..602f1d6f 100644 --- a/src/ui/explore/ReleaseView.cpp +++ b/src/ui/explore/ReleaseView.cpp @@ -103,9 +103,7 @@ Release::refresh() else if (artists.size() == 1) { t->setCondition("if-has-artist", true); - 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)); + Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(artists.front()); t->bindWidget("artist-name", artistAnchor); } } @@ -165,9 +163,7 @@ Release::refresh() 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)); + Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(track->getArtist()); entry->bindWidget("artist-name", artistAnchor); } diff --git a/src/ui/explore/ReleasesView.cpp b/src/ui/explore/ReleasesView.cpp index 9e925316..5fcf654f 100644 --- a/src/ui/explore/ReleasesView.cpp +++ b/src/ui/explore/ReleasesView.cpp @@ -93,7 +93,7 @@ Releases::addSome() 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::WAnchor* coverAnchor = LmsApplication::createReleaseAnchor(release, false); Wt::WImage* cover = new Wt::WImage(coverAnchor); cover->setImageLink(LmsApp->getImageResource()->getReleaseUrl(releaseId, 128)); // Some images may not be square @@ -101,9 +101,7 @@ Releases::addSome() 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)); + Wt::WAnchor* releaseAnchor = LmsApplication::createReleaseAnchor(release); entry->bindWidget("release-name", releaseAnchor); } @@ -116,9 +114,7 @@ Releases::addSome() else if (artists.size() == 1) { entry->setCondition("if-has-artist", true); - 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)); + Wt::WAnchor* artistAnchor = LmsApplication::createArtistAnchor(artists.front()); entry->bindWidget("artist-name", artistAnchor); } diff --git a/src/ui/explore/TracksView.cpp b/src/ui/explore/TracksView.cpp index 531623e7..a646c1bb 100644 --- a/src/ui/explore/TracksView.cpp +++ b/src/ui/explore/TracksView.cpp @@ -126,9 +126,7 @@ Tracks::addSome() 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)); + Wt::WAnchor *artistAnchor = LmsApplication::createArtistAnchor(track->getArtist()); entry->bindWidget("artist-name", artistAnchor); } @@ -136,9 +134,7 @@ Tracks::addSome() 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)); + Wt::WAnchor *releaseAnchor = LmsApplication::createReleaseAnchor(track->getRelease()); entry->bindWidget("release-name", releaseAnchor); }