Minor cleanup to acces Application elements

This commit is contained in:
emeric
2018-03-13 16:52:08 +01:00
parent ba1968b02c
commit acf769c129
9 changed files with 38 additions and 40 deletions
+3 -3
View File
@@ -121,16 +121,16 @@ Artist::refresh()
entry->addFunction("tr", Wt::WTemplate::Functions::tr);
{
Wt::WAnchor* coverAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(releaseId)));
Wt::WAnchor* coverAnchor = LmsApplication::createReleaseAnchor(releaseId);
Wt::WImage* cover = new Wt::WImage(coverAnchor);
cover->setImageLink(SessionImageResource()->getReleaseUrl(release.id(), 128));
cover->setImageLink(LmsApp->getImageResource()->getReleaseUrl(release.id(), 128));
// Some images may not be square
cover->setWidth(128);
entry->bindWidget("cover", coverAnchor);
}
{
Wt::WAnchor* releaseAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(releaseId)));
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);
+1 -1
View File
@@ -93,7 +93,7 @@ Artists::addSome()
entry->bindInt("nb-release", artist->getReleases(clusterIds).size());
{
Wt::WAnchor *artistAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(artist.id())));
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);
+16 -11
View File
@@ -17,12 +17,13 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Wt/WEnvironment>
#include <Wt/WAnchor>
#include <Wt/WBootstrapTheme>
#include <Wt/WNavigationBar>
#include <Wt/WStackedWidget>
#include <Wt/WEnvironment>
#include <Wt/WMenu>
#include <Wt/WNavigationBar>
#include <Wt/WPopupMenu>
#include <Wt/WStackedWidget>
#include <Wt/WText>
#include <Wt/Auth/Identity>
@@ -30,7 +31,6 @@
#include "utils/Logger.hpp"
#include "utils/Utils.hpp"
#include "Auth.hpp"
#include "Explore.hpp"
#include "HomeView.hpp"
#include "MediaPlayer.hpp"
@@ -41,10 +41,6 @@
#include "LmsApplication.hpp"
namespace skeletons {
extern const char *AuthStrings_xml1;
}
namespace UserInterface {
Wt::WApplication*
@@ -112,9 +108,6 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti
if (firstConnection)
{
// Hack, use the auth widget builtin strings
builtinLocalizedStrings().useBuiltin(skeletons::AuthStrings_xml1);
root()->addWidget(new Settings::FirstConnectionView());
}
else
@@ -160,6 +153,18 @@ Scanner::MediaScanner& MediaScanner()
return LmsApplication::instance()->getMediaScanner();
}
Wt::WAnchor*
LmsApplication::createArtistAnchor(Database::id_type id)
{
return new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(id)));
}
Wt::WAnchor*
LmsApplication::createReleaseAnchor(Database::id_type id)
{
return new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(id)));
}
void
LmsApplication::goHome()
{
+3 -8
View File
@@ -50,6 +50,9 @@ 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);
private:
LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool, Scanner::MediaScanner& scanner);
@@ -72,14 +75,6 @@ Wt::Dbo::Session& DboSession();
const Wt::Auth::User& CurrentAuthUser();
Database::User::pointer CurrentUser();
ImageResource *SessionImageResource();
TranscodeResource *SessionTranscodeResource();
Scanner::MediaScanner& MediaScanner();
void notify(const Wt::WString& message);
} // namespace UserInterface
#endif
+3 -3
View File
@@ -99,7 +99,7 @@ Release::refresh()
}
else
{
Wt::WAnchor *artistAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(artists.front().id())));
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);
@@ -107,7 +107,7 @@ Release::refresh()
}
Wt::WImage *cover = new Wt::WImage();
cover->setImageLink(Wt::WLink (SessionImageResource()->getReleaseUrl(release.id(), 512)));
cover->setImageLink(Wt::WLink(LmsApp->getImageResource()->getReleaseUrl(release.id(), 512)));
t->bindWidget("cover", cover);
auto clusterContainers = new Wt::WContainerWidget();
@@ -161,7 +161,7 @@ Release::refresh()
if (variousArtists && track->getArtist())
{
entry->setCondition("if-has-artist", true);
Wt::WAnchor *artistAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(track->getArtist().id())));
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);
+4 -4
View File
@@ -91,15 +91,15 @@ Releases::addSome()
Wt::WTemplate* entry = new Wt::WTemplate(Wt::WString::tr("template-releases-entry"), _releasesContainer);
entry->addFunction("tr", Wt::WTemplate::Functions::tr);
Wt::WAnchor* coverAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(releaseId)));
Wt::WAnchor* coverAnchor = LmsApplication::createReleaseAnchor(releaseId);
Wt::WImage* cover = new Wt::WImage(coverAnchor);
cover->setImageLink(SessionImageResource()->getReleaseUrl(releaseId, 128));
cover->setImageLink(LmsApp->getImageResource()->getReleaseUrl(releaseId, 128));
// Some images may not be square
cover->setWidth(128);
entry->bindWidget("cover", coverAnchor);
{
Wt::WAnchor* releaseAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(releaseId)));
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);
@@ -113,7 +113,7 @@ Releases::addSome()
}
else
{
Wt::WAnchor* artistAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(artists.front().id())));
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);
+3 -3
View File
@@ -124,7 +124,7 @@ Tracks::addSome()
if (artist)
{
entry->setCondition("if-has-artist", true);
Wt::WAnchor *artistAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(track->getArtist().id())));
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);
@@ -134,14 +134,14 @@ Tracks::addSome()
if (release)
{
entry->setCondition("if-has-release", true);
Wt::WAnchor *releaseAnchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(track->getRelease().id())));
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(SessionImageResource()->getTrackUrl(track.id(), 64));
cover->setImageLink(LmsApp->getImageResource()->getTrackUrl(track.id(), 64));
// Some images may not be square
cover->setWidth(64);
entry->bindWidget("cover", cover);
+4 -6
View File
@@ -267,9 +267,8 @@ DatabaseView::DatabaseView(Wt::WContainerWidget *parent)
{
model->saveData();
MediaScanner().reschedule();
notify(Wt::WString::tr("msg-notify-settings-saved"));
LmsApp->getMediaScanner().reschedule();
LmsApp->notify(Wt::WString::tr("msg-notify-settings-saved"));
}
// Udate the view: Delete any validation message in the view, etc.
@@ -285,9 +284,8 @@ DatabaseView::DatabaseView(Wt::WContainerWidget *parent)
immScanBtn->clicked().connect(std::bind([=] ()
{
MediaScanner().scheduleImmediateScan();
notify(Wt::WString::tr("msg-notify-scan-launched"));
LmsApp->getMediaScanner().scheduleImmediateScan();
LmsApp->notify(Wt::WString::tr("msg-notify-scan-launched"));
}));
updateView(model);
+1 -1
View File
@@ -149,7 +149,7 @@ FirstConnectionView::FirstConnectionView(Wt::WContainerWidget *parent)
if (model->validate())
{
model->saveData();
notify(Wt::WString::tr("msg-settings-first-connection-done"));
LmsApp->notify(Wt::WString::tr("msg-settings-first-connection-done"));
saveButton->setEnabled(false);
}