Added helpers to simplify session data accesses. Made the CoverResource global to the session
This commit is contained in:
@@ -54,7 +54,6 @@ lms_SOURCES = \
|
||||
$(srcdir)/ui/audio/mobile/TrackSearch.cpp \
|
||||
$(srcdir)/ui/common/DirectoryValidator.cpp \
|
||||
$(srcdir)/ui/common/LineEdit.cpp \
|
||||
$(srcdir)/ui/common/SessionData.cpp \
|
||||
$(srcdir)/ui/resource/AvConvTranscodeStreamResource.cpp \
|
||||
$(srcdir)/ui/resource/CoverResource.cpp \
|
||||
$(srcdir)/ui/video/VideoWidget.cpp \
|
||||
|
||||
+41
-19
@@ -71,6 +71,12 @@ LmsApplication::create(const Wt::WEnvironment& env, boost::filesystem::path dbPa
|
||||
return new LmsApplication(env, dbPath);
|
||||
}
|
||||
|
||||
LmsApplication*
|
||||
LmsApplication::instance()
|
||||
{
|
||||
return reinterpret_cast<LmsApplication*>(Wt::WApplication::instance());
|
||||
}
|
||||
|
||||
/*
|
||||
* The env argument contains information about the new session, and
|
||||
* the initial request. It must be passed to the Wt::WApplication
|
||||
@@ -79,7 +85,8 @@ LmsApplication::create(const Wt::WEnvironment& env, boost::filesystem::path dbPa
|
||||
*/
|
||||
LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::path dbPath)
|
||||
: Wt::WApplication(env),
|
||||
_sessionData(dbPath)
|
||||
_db(dbPath),
|
||||
_coverResource(nullptr)
|
||||
{
|
||||
|
||||
Wt::WBootstrapTheme *bootstrapTheme = new Wt::WBootstrapTheme(this);
|
||||
@@ -96,9 +103,9 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::p
|
||||
|
||||
bool firstConnection;
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
firstConnection = (Database::User::getAll(_sessionData.getDatabaseHandler().getSession()).size() == 0);
|
||||
firstConnection = (Database::User::getAll(DboSession()).size() == 0);
|
||||
}
|
||||
|
||||
// If here is no account in the database, launch the first connection wizard
|
||||
@@ -109,22 +116,41 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::p
|
||||
|
||||
}
|
||||
|
||||
Database::Handler& DbHandler()
|
||||
{
|
||||
return LmsApplication::instance()->getDbHandler();
|
||||
}
|
||||
Wt::Dbo::Session& DboSession()
|
||||
{
|
||||
return DbHandler().getSession();
|
||||
}
|
||||
|
||||
const Wt::Auth::User& CurrentAuthUser()
|
||||
{
|
||||
return DbHandler().getLogin().user();
|
||||
}
|
||||
|
||||
Database::User::pointer CurrentUser()
|
||||
{
|
||||
return DbHandler().getCurrentUser();
|
||||
}
|
||||
|
||||
void
|
||||
LmsApplication::createFirstConnectionUI()
|
||||
{
|
||||
// Hack, use the auth widget builtin strings
|
||||
builtinLocalizedStrings().useBuiltin(skeletons::AuthStrings_xml1);
|
||||
|
||||
root()->addWidget( new Settings::FirstConnectionFormView(_sessionData));
|
||||
root()->addWidget( new Settings::FirstConnectionFormView());
|
||||
}
|
||||
|
||||
void
|
||||
LmsApplication::createLmsUI()
|
||||
{
|
||||
_coverResource = new CoverResource(_db, root());
|
||||
DbHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent);
|
||||
|
||||
_sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent);
|
||||
|
||||
LmsAuth *authWidget = new LmsAuth(_sessionData.getDatabaseHandler());
|
||||
LmsAuth *authWidget = new LmsAuth();
|
||||
|
||||
authWidget->model()->addPasswordAuth(&Database::Handler::getPasswordService());
|
||||
authWidget->setRegistrationEnabled(false);
|
||||
@@ -138,11 +164,9 @@ LmsApplication::createLmsUI()
|
||||
void
|
||||
LmsApplication::handleAuthEvent(void)
|
||||
{
|
||||
if (_sessionData.getDatabaseHandler().getLogin().loggedIn())
|
||||
if (DbHandler().getLogin().loggedIn())
|
||||
{
|
||||
Wt::Auth::User user(_sessionData.getDatabaseHandler().getLogin().user());
|
||||
|
||||
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();
|
||||
LMS_LOG(MOD_UI, SEV_NOTICE) << "User '" << CurrentAuthUser().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);
|
||||
|
||||
@@ -162,20 +186,18 @@ LmsApplication::handleAuthEvent(void)
|
||||
Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack);
|
||||
navigation->addMenu(leftMenu);
|
||||
|
||||
const Wt::WEnvironment& env = Wt::WApplication::instance()->environment();
|
||||
|
||||
Audio *audio;
|
||||
|
||||
if (agentIsMobile())
|
||||
audio = new Mobile::Audio(_sessionData.getDatabaseHandler());
|
||||
audio = new Mobile::Audio();
|
||||
else
|
||||
audio = new Desktop::Audio(_sessionData);
|
||||
audio = new Desktop::Audio();
|
||||
|
||||
VideoWidget *videoWidget = new VideoWidget(_sessionData);
|
||||
VideoWidget *videoWidget = new VideoWidget();
|
||||
|
||||
leftMenu->addItem("Audio", audio);
|
||||
leftMenu->addItem("Video", videoWidget);
|
||||
leftMenu->addItem("Settings", new Settings::Settings(_sessionData));
|
||||
leftMenu->addItem("Settings", new Settings::Settings());
|
||||
|
||||
// Setup a Right-aligned menu.
|
||||
Wt::WMenu *rightMenu = new Wt::WMenu();
|
||||
@@ -185,14 +207,14 @@ LmsApplication::handleAuthEvent(void)
|
||||
Wt::WPopupMenu *popup = new Wt::WPopupMenu();
|
||||
popup->addItem("Logout");
|
||||
|
||||
Wt::WMenuItem *item = new Wt::WMenuItem( user.identity(Wt::Auth::Identity::LoginName) );
|
||||
Wt::WMenuItem *item = new Wt::WMenuItem( CurrentAuthUser().identity(Wt::Auth::Identity::LoginName) );
|
||||
item->setMenu(popup);
|
||||
rightMenu->addItem(item);
|
||||
|
||||
popup->itemSelected().connect(std::bind([=] (Wt::WMenuItem* item)
|
||||
{
|
||||
if (item && item->text() == "Logout")
|
||||
_sessionData.getDatabaseHandler().getLogin().logout();
|
||||
DbHandler().getLogin().logout();
|
||||
}, std::placeholders::_1));
|
||||
|
||||
// Add a Search control.
|
||||
|
||||
@@ -20,31 +20,42 @@
|
||||
#ifndef LMS_APPLICATION_HPP
|
||||
#define LMS_APPLICATION_HPP
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <Wt/WApplication>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
|
||||
class LmsApplication : public Wt::WApplication
|
||||
{
|
||||
public:
|
||||
|
||||
static Wt::WApplication *create(const Wt::WEnvironment& env, boost::filesystem::path dbPath);
|
||||
static LmsApplication* instance();
|
||||
|
||||
LmsApplication(const Wt::WEnvironment& env, boost::filesystem::path dbPath);
|
||||
|
||||
// Session application data
|
||||
CoverResource* getCoverResource() { return _coverResource; }
|
||||
Database::Handler& getDbHandler() { return _db;}
|
||||
|
||||
private:
|
||||
|
||||
void handleAuthEvent(void);
|
||||
void createFirstConnectionUI();
|
||||
void createLmsUI();
|
||||
|
||||
SessionData _sessionData;
|
||||
|
||||
Database::Handler _db;
|
||||
CoverResource* _coverResource;
|
||||
};
|
||||
|
||||
// Helpers to get session data
|
||||
Database::Handler& DbHandler();
|
||||
Wt::Dbo::Session& DboSession();
|
||||
|
||||
const Wt::Auth::User& CurrentAuthUser();
|
||||
Database::User::pointer CurrentUser();
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
|
||||
@@ -47,6 +47,21 @@ AudioMediaPlayer::AudioMediaPlayer( Wt::WMediaPlayer::Encoding encoding, Wt::WCo
|
||||
Wt::WVBoxLayout* mainLayout = new Wt::WVBoxLayout();
|
||||
this->setLayout(mainLayout);
|
||||
|
||||
/* TODO add media info here
|
||||
// Current Media info
|
||||
Wt::WHBoxLayout *currentMediaLayout = new Wt::WHBoxLayout();
|
||||
mainLayout->addLayout(currentMediaLayout);
|
||||
|
||||
currentMediaLayout->addWidget( _mediaCover = new Wt::WImage());
|
||||
_mediaCover->setImageLink( Wt::WLink("images/unknown-cover.jpg") );
|
||||
|
||||
Wt::WVBoxLayout* mediaInfoLayout = new Wt::WVBoxLayout();
|
||||
currentMediaLayout->addLayout(mediaInfoLayout, 1);
|
||||
|
||||
mediaInfoLayout->addWidget( _mediaTitle = new Wt::WText());
|
||||
mediaInfoLayout->addWidget( _mediaArtistRelease = new Wt::WText());
|
||||
*/
|
||||
// Time control
|
||||
Wt::WHBoxLayout *sliderLayout = new Wt::WHBoxLayout();
|
||||
mainLayout->addLayout(sliderLayout);
|
||||
|
||||
@@ -56,6 +71,7 @@ AudioMediaPlayer::AudioMediaPlayer( Wt::WMediaPlayer::Encoding encoding, Wt::WCo
|
||||
sliderLayout->addWidget(_duration = new Wt::WText("00:00:00"));
|
||||
_duration->setLineHeight(30);
|
||||
|
||||
// Controls
|
||||
Wt::WHBoxLayout *controlsLayout = new Wt::WHBoxLayout();
|
||||
|
||||
mainLayout->addLayout(controlsLayout);
|
||||
@@ -63,7 +79,6 @@ AudioMediaPlayer::AudioMediaPlayer( Wt::WMediaPlayer::Encoding encoding, Wt::WCo
|
||||
Wt::WContainerWidget *btnContainer = new Wt::WContainerWidget();
|
||||
// Do not allow button to wrap
|
||||
btnContainer->setMinimumSize(155, Wt::WLength::Auto);
|
||||
|
||||
Wt::WTemplate *t = new Wt::WTemplate(Wt::WString::tr("mediaplayer-controls"), btnContainer);
|
||||
|
||||
Wt::WPushButton *prevBtn = new Wt::WPushButton("<<");
|
||||
|
||||
@@ -27,9 +27,11 @@
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WMediaPlayer>
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WImage>
|
||||
|
||||
#include "transcode/Parameters.hpp"
|
||||
#include "resource/AvConvTranscodeStreamResource.hpp"
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Desktop {
|
||||
@@ -79,6 +81,11 @@ class AudioMediaPlayer : public Wt::WContainerWidget
|
||||
AvConvTranscodeStreamResource* _mediaResource;
|
||||
Wt::WMediaPlayer::Encoding _encoding;
|
||||
|
||||
// Media info
|
||||
Wt::WImage* _mediaCover;
|
||||
Wt::WText* _mediaTitle;
|
||||
Wt::WText* _mediaArtistRelease;
|
||||
|
||||
// Controls
|
||||
std::shared_ptr<Transcode::Parameters> _currentParameters;
|
||||
Wt::WPushButton* _playBtn;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <Wt/WLabel>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "TableFilter.hpp"
|
||||
#include "KeywordSearchFilter.hpp"
|
||||
@@ -55,9 +56,8 @@ namespace Desktop {
|
||||
// Restored at the beginning of the session
|
||||
static const std::string CurrentQueuePlaylistName = "__current__";
|
||||
|
||||
Audio::Audio(SessionData& sessionData, Wt::WContainerWidget* parent)
|
||||
Audio::Audio(Wt::WContainerWidget* parent)
|
||||
: UserInterface::Audio(parent),
|
||||
_db(sessionData.getDatabaseHandler()),
|
||||
_mediaPlayer(nullptr),
|
||||
_trackView(nullptr),
|
||||
_playQueue(nullptr)
|
||||
@@ -69,15 +69,15 @@ _playQueue(nullptr)
|
||||
// Filters
|
||||
Wt::WHBoxLayout *filterLayout = new Wt::WHBoxLayout();
|
||||
|
||||
TableFilterGenre *filterGenre = new TableFilterGenre(_db);
|
||||
TableFilterGenre *filterGenre = new TableFilterGenre();
|
||||
filterLayout->addWidget(filterGenre);
|
||||
_filterChain.addFilter(filterGenre);
|
||||
|
||||
TableFilterArtist *filterArtist = new TableFilterArtist(_db);
|
||||
TableFilterArtist *filterArtist = new TableFilterArtist();
|
||||
filterLayout->addWidget(filterArtist);
|
||||
_filterChain.addFilter(filterArtist);
|
||||
|
||||
TableFilterRelease *filterRelease = new TableFilterRelease(_db);
|
||||
TableFilterRelease *filterRelease = new TableFilterRelease();
|
||||
filterLayout->addWidget(filterRelease);
|
||||
_filterChain.addFilter(filterRelease);
|
||||
|
||||
@@ -88,7 +88,7 @@ _playQueue(nullptr)
|
||||
|
||||
Wt::WVBoxLayout* trackLayout = new Wt::WVBoxLayout();
|
||||
|
||||
_trackView = new TrackView(_db);
|
||||
_trackView = new TrackView();
|
||||
trackLayout->addWidget(_trackView, 1);
|
||||
|
||||
Wt::WHBoxLayout* trackControls = new Wt::WHBoxLayout();
|
||||
@@ -109,12 +109,11 @@ _playQueue(nullptr)
|
||||
|
||||
_filterChain.addFilter(_trackView);
|
||||
|
||||
_playQueue = new PlayQueue(_db);
|
||||
_playQueue = new PlayQueue();
|
||||
|
||||
// Playlist/PlayQueue
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Wt::WContainerWidget* playQueueContainer = new Wt::WContainerWidget();
|
||||
playQueueContainer->setStyleClass("playqueue");
|
||||
@@ -123,7 +122,7 @@ _playQueue(nullptr)
|
||||
|
||||
// Determine the encoding to be used
|
||||
Wt::WMediaPlayer::Encoding encoding;
|
||||
switch (user->getAudioEncoding())
|
||||
switch (CurrentUser()->getAudioEncoding())
|
||||
{
|
||||
case Database::AudioEncoding::MP3: encoding = Wt::WMediaPlayer::MP3; break;
|
||||
case Database::AudioEncoding::WEBMA: encoding = Wt::WMediaPlayer::WEBMA; break;
|
||||
@@ -188,7 +187,7 @@ _playQueue(nullptr)
|
||||
// Load the last known queue
|
||||
playlistLoadToPlayqueue(CurrentQueuePlaylistName);
|
||||
// Select the last known playing track
|
||||
_playQueue->select(user->getCurPlayingTrackPos());
|
||||
_playQueue->select(CurrentUser()->getCurPlayingTrackPos());
|
||||
}
|
||||
|
||||
mainLayout->setRowStretch(1, 1);
|
||||
@@ -281,14 +280,10 @@ Audio::playlistShowSaveNewDialog()
|
||||
void
|
||||
Audio::playlistShowSaveDialog(std::string playlistName)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
if (!user)
|
||||
return;
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Actually create the dialog only if the given list already exists
|
||||
if (Database::Playlist::get(_db.getSession(), playlistName, user))
|
||||
if (Database::Playlist::get(DboSession(), playlistName, CurrentUser()))
|
||||
{
|
||||
Wt::WMessageBox *messageBox = new Wt::WMessageBox
|
||||
("Overwrite playlist",
|
||||
@@ -318,20 +313,16 @@ Audio::playlistSaveFromPlayqueue(std::string playlistName)
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_INFO) << "Saving playqueue to playlist '" << playlistName << "'";
|
||||
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
if (!user)
|
||||
return;
|
||||
|
||||
Database::Playlist::pointer playlist = Database::Playlist::get(_db.getSession(), playlistName, user);
|
||||
Database::Playlist::pointer playlist = Database::Playlist::get(DboSession(), playlistName, CurrentUser());
|
||||
if (playlist)
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_INFO) << "Erasing playlist '" << playlistName << "'";
|
||||
playlist.remove();
|
||||
}
|
||||
|
||||
playlist = Database::Playlist::create(_db.getSession(), playlistName, false, user);
|
||||
playlist = Database::Playlist::create(DboSession(), playlistName, false, CurrentUser());
|
||||
|
||||
std::vector<Database::Track::id_type> trackIds;
|
||||
_playQueue->getTracks(trackIds);
|
||||
@@ -339,10 +330,10 @@ Audio::playlistSaveFromPlayqueue(std::string playlistName)
|
||||
int pos = 0;
|
||||
BOOST_FOREACH(Database::Track::id_type trackId, trackIds)
|
||||
{
|
||||
Database::Track::pointer track = Database::Track::getById(_db.getSession(), trackId);
|
||||
Database::Track::pointer track = Database::Track::getById(DboSession(), trackId);
|
||||
|
||||
if (track)
|
||||
Database::PlaylistEntry::create(_db.getSession(), track, playlist, pos++);
|
||||
Database::PlaylistEntry::create(DboSession(), track, playlist, pos++);
|
||||
}
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_INFO) << "Saving playqueue to playlist '" << playlistName << "' done. Contains " << pos << " entries";
|
||||
@@ -356,17 +347,13 @@ Audio::playlistLoadToPlayqueue(std::string playlistName)
|
||||
std::vector<Database::Track::id_type> entries;
|
||||
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
if (!user)
|
||||
return;
|
||||
|
||||
Database::Playlist::pointer playlist = Database::Playlist::get(_db.getSession(), playlistName, user);
|
||||
Database::Playlist::pointer playlist = Database::Playlist::get(DboSession(), playlistName, CurrentUser());
|
||||
if (!playlist)
|
||||
return;
|
||||
|
||||
entries = Database::PlaylistEntry::getEntries(_db.getSession(), playlist);
|
||||
entries = Database::PlaylistEntry::getEntries(DboSession(), playlist);
|
||||
}
|
||||
|
||||
_playQueue->clear();
|
||||
@@ -390,12 +377,9 @@ Audio::playlistShowDeleteDialog(std::string name)
|
||||
messageBox->buttonClicked().connect(std::bind([=] () {
|
||||
if (messageBox->buttonResult() == Wt::Yes)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
if (!user)
|
||||
return;
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Database::Playlist::pointer playlist = Database::Playlist::get(_db.getSession(), name, user);
|
||||
Database::Playlist::pointer playlist = Database::Playlist::get(DboSession(), name, CurrentUser());
|
||||
if (playlist)
|
||||
playlist.remove();
|
||||
|
||||
@@ -411,11 +395,7 @@ Audio::playlistShowDeleteDialog(std::string name)
|
||||
void
|
||||
Audio::playlistRefreshMenus()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
if (!user)
|
||||
return;
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Clear playlists in each menu
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Save item count: " << _popupMenuSave->count();
|
||||
@@ -430,7 +410,7 @@ Audio::playlistRefreshMenus()
|
||||
}));
|
||||
_popupMenuSave->addSeparator();
|
||||
|
||||
std::vector<Database::Playlist::pointer> playlists = Database::Playlist::get(_db.getSession(), user);
|
||||
std::vector<Database::Playlist::pointer> playlists = Database::Playlist::get(DboSession(), CurrentUser());
|
||||
|
||||
BOOST_FOREACH(Database::Playlist::pointer playlist, playlists)
|
||||
{
|
||||
@@ -528,18 +508,10 @@ Audio::playTrack(boost::filesystem::path p, int pos)
|
||||
|
||||
// Get user preferences
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
if (user)
|
||||
{
|
||||
bitrate = user->getAudioBitrate();
|
||||
user.modify()->setCurPlayingTrackPos(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_ERROR) << "Can't play: user does not exists!";
|
||||
return; // TODO logout?
|
||||
}
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
bitrate = CurrentUser()->getAudioBitrate();
|
||||
CurrentUser().modify()->setCurPlayingTrackPos(pos);
|
||||
}
|
||||
|
||||
Transcode::InputMediaFile inputFile(p);
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
#include <Wt/WPopupMenu>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
#include "AudioMediaPlayer.hpp"
|
||||
#include "TrackView.hpp"
|
||||
#include "PlayQueue.hpp"
|
||||
@@ -42,7 +40,7 @@ class Audio : public UserInterface::Audio
|
||||
|
||||
public:
|
||||
|
||||
Audio(SessionData& sessionData, Wt::WContainerWidget* parent = 0);
|
||||
Audio(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
void search(std::string searchText);
|
||||
|
||||
@@ -68,8 +66,6 @@ class Audio : public UserInterface::Audio
|
||||
|
||||
void handlePlaylistSelected(Wt::WString name);
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
AudioMediaPlayer* _mediaPlayer;
|
||||
TrackView* _trackView;
|
||||
PlayQueue* _playQueue;
|
||||
|
||||
@@ -27,10 +27,9 @@
|
||||
#include <Wt/WFileResource>
|
||||
#include <Wt/WTheme>
|
||||
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
#include "PlayQueue.hpp"
|
||||
|
||||
static const int TrackInfoRole = Wt::UserRole;
|
||||
@@ -271,9 +270,8 @@ class PlayQueueItemDelegate : public Wt::WItemDelegate
|
||||
};
|
||||
|
||||
|
||||
PlayQueue::PlayQueue(Database::Handler& db, Wt::WContainerWidget* parent)
|
||||
PlayQueue::PlayQueue(Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView(parent),
|
||||
_db(db),
|
||||
_curPlayedTrackPos(trackPosInvalid),
|
||||
_trackSelector(new TrackSelector())
|
||||
{
|
||||
@@ -315,7 +313,6 @@ _trackSelector(new TrackSelector())
|
||||
|
||||
}, std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
_coverResource = new CoverResource(db, 64);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -375,8 +372,8 @@ PlayQueue::addTracks(const std::vector<Database::Track::id_type>& trackIds)
|
||||
//
|
||||
BOOST_FOREACH(Database::Track::id_type trackId, trackIds)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Database::Track::pointer track (Database::Track::getById(_db.getSession(), trackId));
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
Database::Track::pointer track (Database::Track::getById(DboSession(), trackId));
|
||||
|
||||
if (track)
|
||||
{
|
||||
@@ -388,9 +385,9 @@ PlayQueue::addTracks(const std::vector<Database::Track::id_type>& trackIds)
|
||||
|
||||
std::string coverUrl;
|
||||
if (track->hasCover())
|
||||
coverUrl = _coverResource->getTrackUrl(track.id());
|
||||
coverUrl = LmsApplication::instance()->getCoverResource()->getTrackUrl(track.id(), 64);
|
||||
else
|
||||
coverUrl = "images/unknown-cover.jpg";
|
||||
coverUrl = LmsApplication::instance()->getCoverResource()->getUnkownTrackUrl(64);
|
||||
_model->setData(dataRow, COLUMN_ID_COVER, coverUrl, Wt::DecorationRole);
|
||||
|
||||
TrackInfo trackInfo;
|
||||
@@ -463,12 +460,12 @@ PlayQueue::playPrevious(void)
|
||||
bool
|
||||
PlayQueue::readTrack(int rowPos)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Reading track at pos " << rowPos;
|
||||
Database::Track::id_type trackId = boost::any_cast<Database::Track::id_type>(_model->data(rowPos, COLUMN_ID_TRACK_ID, Wt::UserRole));
|
||||
|
||||
Database::Track::pointer track = Database::Track::getById(_db.getSession(), trackId);
|
||||
Database::Track::pointer track = Database::Track::getById(DboSession(), trackId);
|
||||
if (track)
|
||||
{
|
||||
setPlayingTrackPos(rowPos);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <Wt/WTableView>
|
||||
#include <Wt/WStandardItemModel>
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
@@ -36,7 +36,7 @@ class TrackSelector;
|
||||
class PlayQueue : public Wt::WTableView
|
||||
{
|
||||
public:
|
||||
PlayQueue(Database::Handler& db, Wt::WContainerWidget* parent = 0);
|
||||
PlayQueue(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
void addTracks(const std::vector<Database::Track::id_type>& trackIds);
|
||||
void getTracks(std::vector<Database::Track::id_type>& trackIds) const;
|
||||
@@ -79,14 +79,10 @@ class PlayQueue : public Wt::WTableView
|
||||
Wt::Signal< boost::filesystem::path, int > _sigTrackPlay;
|
||||
Wt::Signal< void > _sigTracksUpdated;
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
Wt::WStandardItemModel* _model;
|
||||
|
||||
PlayQueueItemDelegate* _itemDelegate;
|
||||
|
||||
CoverResource* _coverResource;
|
||||
|
||||
int _curPlayedTrackPos;
|
||||
std::unique_ptr<TrackSelector> _trackSelector;
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
#include <Wt/WItemDelegate>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
#include "TableFilter.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
@@ -32,15 +32,14 @@ namespace Desktop {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
TableFilterGenre::TableFilterGenre(Database::Handler& db, Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ), Filter(),
|
||||
_db(db)
|
||||
TableFilterGenre::TableFilterGenre(Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ), Filter()
|
||||
{
|
||||
const std::vector<Wt::WString> columnNames = {"Genre", "Tracks"};
|
||||
|
||||
SearchFilter filter;
|
||||
|
||||
Genre::updateGenreQueryModel(_db.getSession(), _queryModel, filter, columnNames);
|
||||
Genre::updateGenreQueryModel(DboSession(), _queryModel, filter, columnNames);
|
||||
|
||||
this->setSelectionMode(Wt::ExtendedSelection);
|
||||
this->setSortingEnabled(true);
|
||||
@@ -83,7 +82,7 @@ TableFilterGenre::layoutSizeChanged (int width, int height)
|
||||
void
|
||||
TableFilterGenre::refresh(SearchFilter& filter)
|
||||
{
|
||||
Genre::updateGenreQueryModel(_db.getSession(), _queryModel, filter);
|
||||
Genre::updateGenreQueryModel(DboSession(), _queryModel, filter);
|
||||
}
|
||||
|
||||
// Get constraint created by this filter
|
||||
@@ -103,15 +102,14 @@ TableFilterGenre::getConstraint(SearchFilter& filter)
|
||||
}
|
||||
}
|
||||
|
||||
TableFilterArtist::TableFilterArtist(Database::Handler& db, Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ), Filter(),
|
||||
_db(db)
|
||||
TableFilterArtist::TableFilterArtist(Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ), Filter()
|
||||
{
|
||||
const std::vector<Wt::WString> columnNames = {"Artist", "Releases", "Tracks"};
|
||||
|
||||
SearchFilter filter;
|
||||
|
||||
Track::updateArtistQueryModel(_db.getSession(), _queryModel, filter, columnNames);
|
||||
Track::updateArtistQueryModel(DboSession(), _queryModel, filter, columnNames);
|
||||
|
||||
this->setSelectionMode(Wt::ExtendedSelection);
|
||||
this->setSortingEnabled(true);
|
||||
@@ -155,7 +153,7 @@ TableFilterArtist::layoutSizeChanged (int width, int height)
|
||||
void
|
||||
TableFilterArtist::refresh(SearchFilter& filter)
|
||||
{
|
||||
Track::updateArtistQueryModel(_db.getSession(), _queryModel, filter);
|
||||
Track::updateArtistQueryModel(DboSession(), _queryModel, filter);
|
||||
}
|
||||
|
||||
// Get constraint created by this filter
|
||||
@@ -175,15 +173,14 @@ TableFilterArtist::getConstraint(SearchFilter& filter)
|
||||
}
|
||||
}
|
||||
|
||||
TableFilterRelease::TableFilterRelease(Database::Handler& db, Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ), Filter(),
|
||||
_db(db)
|
||||
TableFilterRelease::TableFilterRelease(Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ), Filter()
|
||||
{
|
||||
const std::vector<Wt::WString> columnNames = {"Release", "Date", "Tracks"};
|
||||
|
||||
SearchFilter filter;
|
||||
|
||||
Track::updateReleaseQueryModel(_db.getSession(), _queryModel, filter, columnNames);
|
||||
Track::updateReleaseQueryModel(DboSession(), _queryModel, filter, columnNames);
|
||||
|
||||
this->setSelectionMode(Wt::ExtendedSelection);
|
||||
this->setSortingEnabled(true);
|
||||
@@ -234,7 +231,7 @@ TableFilterRelease::layoutSizeChanged (int width, int height)
|
||||
void
|
||||
TableFilterRelease::refresh(SearchFilter& filter)
|
||||
{
|
||||
Track::updateReleaseQueryModel(_db.getSession(), _queryModel, filter);
|
||||
Track::updateReleaseQueryModel(DboSession(), _queryModel, filter);
|
||||
}
|
||||
|
||||
// Get constraint created by this filter
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <Wt/WTableView>
|
||||
|
||||
#include "Filter.hpp"
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
#include "database/Types.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Desktop {
|
||||
@@ -33,7 +33,7 @@ namespace Desktop {
|
||||
class TableFilterGenre : public Wt::WTableView, public Filter
|
||||
{
|
||||
public:
|
||||
TableFilterGenre(Database::Handler& db, Wt::WContainerWidget* parent = 0);
|
||||
TableFilterGenre(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
// Set constraints on this filter
|
||||
void refresh(Database::SearchFilter& filter);
|
||||
@@ -51,8 +51,6 @@ class TableFilterGenre : public Wt::WTableView, public Filter
|
||||
|
||||
SigDoubleClicked _sigDoubleClicked;
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
// Name, track count
|
||||
Wt::Dbo::QueryModel<Database::Genre::GenreResult> _queryModel;
|
||||
};
|
||||
@@ -60,7 +58,7 @@ class TableFilterGenre : public Wt::WTableView, public Filter
|
||||
class TableFilterArtist : public Wt::WTableView, public Filter
|
||||
{
|
||||
public:
|
||||
TableFilterArtist(Database::Handler& db, Wt::WContainerWidget* parent = 0);
|
||||
TableFilterArtist(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
// Set constraints on this filter
|
||||
void refresh(Database::SearchFilter& filter);
|
||||
@@ -78,8 +76,6 @@ class TableFilterArtist : public Wt::WTableView, public Filter
|
||||
|
||||
SigDoubleClicked _sigDoubleClicked;
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
// Name, track count
|
||||
Wt::Dbo::QueryModel<Database::Track::ArtistResult> _queryModel;
|
||||
};
|
||||
@@ -87,7 +83,7 @@ class TableFilterArtist : public Wt::WTableView, public Filter
|
||||
class TableFilterRelease : public Wt::WTableView, public Filter
|
||||
{
|
||||
public:
|
||||
TableFilterRelease(Database::Handler& db, Wt::WContainerWidget* parent = 0);
|
||||
TableFilterRelease(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
// Set constraints on this filter
|
||||
void refresh(Database::SearchFilter& filter);
|
||||
@@ -105,8 +101,6 @@ class TableFilterRelease : public Wt::WTableView, public Filter
|
||||
|
||||
SigDoubleClicked _sigDoubleClicked;
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
// Name, track count
|
||||
Wt::Dbo::QueryModel<Database::Track::ReleaseResult> _queryModel;
|
||||
};
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
#include "TrackView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Desktop {
|
||||
|
||||
TrackView::TrackView( Database::Handler& db, Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent ),
|
||||
_db(db)
|
||||
TrackView::TrackView(Wt::WContainerWidget* parent)
|
||||
: Wt::WTableView( parent )
|
||||
{
|
||||
|
||||
static const std::vector<Wt::WString> columnNames =
|
||||
@@ -50,7 +50,7 @@ _db(db)
|
||||
|
||||
Database::SearchFilter filter;
|
||||
|
||||
Database::Track::updateTracksQueryModel(_db.getSession(), _queryModel, filter, columnNames);
|
||||
Database::Track::updateTracksQueryModel(DboSession(), _queryModel, filter, columnNames);
|
||||
|
||||
_queryModel.setBatchSize(300);
|
||||
|
||||
@@ -111,7 +111,7 @@ _db(db)
|
||||
void
|
||||
TrackView::refresh(Database::SearchFilter& filter)
|
||||
{
|
||||
Database::Track::updateTracksQueryModel(_db.getSession(), _queryModel, filter);
|
||||
Database::Track::updateTracksQueryModel(DboSession(), _queryModel, filter);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -34,7 +34,7 @@ class TrackView : public Wt::WTableView, public Filter
|
||||
{
|
||||
public:
|
||||
|
||||
TrackView( Database::Handler& db, Wt::WContainerWidget* parent = 0);
|
||||
TrackView(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
// Filter interface
|
||||
// Set constraints created by parent filters
|
||||
@@ -62,8 +62,6 @@ class TrackView : public Wt::WTableView, public Filter
|
||||
|
||||
SigTrackDoubleClicked _sigTrackDoubleClicked;
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
typedef Database::Track::pointer ResultType;
|
||||
Wt::Dbo::QueryModel< ResultType > _queryModel;
|
||||
Wt::WTableView* _tableView;
|
||||
|
||||
@@ -21,14 +21,15 @@
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WPushButton>
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "ArtistSearch.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
ArtistSearch::ArtistSearch(Database::Handler& db, Wt::WContainerWidget *parent)
|
||||
ArtistSearch::ArtistSearch(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_db(db),
|
||||
_resCount(0)
|
||||
{
|
||||
Wt::WTemplate *title = new Wt::WTemplate(this);
|
||||
@@ -60,10 +61,10 @@ ArtistSearch::addResults(Database::SearchFilter filter, std::size_t nb)
|
||||
std::vector<std::string> artists;
|
||||
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Request one more to see if more results are to be expected
|
||||
artists = Database::Track::getArtists(_db.getSession(), filter, _resCount, nb + 1);
|
||||
artists = Database::Track::getArtists(DboSession(), filter, _resCount, nb + 1);
|
||||
}
|
||||
|
||||
bool expectMoreResults;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
#include "database/Types.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
@@ -32,7 +32,7 @@ class ArtistSearch : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
ArtistSearch(Database::Handler& db, Wt::WContainerWidget *parent = 0);
|
||||
ArtistSearch(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void search(Database::SearchFilter filter, std::size_t nb);
|
||||
|
||||
@@ -48,7 +48,6 @@ class ArtistSearch : public Wt::WContainerWidget
|
||||
void clear(void);
|
||||
void addResults(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
Database::Handler& _db;
|
||||
std::size_t _resCount;
|
||||
};
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WTable>
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "MobileAudio.hpp"
|
||||
|
||||
#include "ArtistSearch.hpp"
|
||||
@@ -40,9 +42,8 @@
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
Audio::Audio(Database::Handler& db, Wt::WContainerWidget *parent)
|
||||
: UserInterface::Audio(parent),
|
||||
_db(db)
|
||||
Audio::Audio(Wt::WContainerWidget *parent)
|
||||
: UserInterface::Audio(parent)
|
||||
{
|
||||
// Root div has to be a "container"
|
||||
this->setStyleClass("container");
|
||||
@@ -56,27 +57,29 @@ _db(db)
|
||||
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);
|
||||
ArtistSearch* artistSearch = new ArtistSearch(this);
|
||||
ReleaseSearch* releaseSearch = new ReleaseSearch(this);
|
||||
TrackSearch* trackSearch = new TrackSearch(this);
|
||||
|
||||
Wt::WTemplate* playerTemplate = new Wt::WTemplate(this);
|
||||
playerTemplate->setTemplateText(Wt::WString::tr("mobile-audio-player"));
|
||||
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
|
||||
// Determine the encoding to be used
|
||||
Wt::WMediaPlayer::Encoding encoding;
|
||||
switch (user->getAudioEncoding())
|
||||
|
||||
{
|
||||
case Database::AudioEncoding::MP3: encoding = Wt::WMediaPlayer::MP3; break;
|
||||
case Database::AudioEncoding::WEBMA: encoding = Wt::WMediaPlayer::WEBMA; break;
|
||||
case Database::AudioEncoding::OGA: encoding = Wt::WMediaPlayer::OGA; break;
|
||||
case Database::AudioEncoding::FLA: encoding = Wt::WMediaPlayer::FLA; break;
|
||||
case Database::AudioEncoding::AUTO:
|
||||
default:
|
||||
encoding = AudioMediaPlayer::getBestEncoding();
|
||||
Wt::Dbo::Transaction transaction (DboSession());
|
||||
|
||||
switch (CurrentUser()->getAudioEncoding())
|
||||
{
|
||||
case Database::AudioEncoding::MP3: encoding = Wt::WMediaPlayer::MP3; break;
|
||||
case Database::AudioEncoding::WEBMA: encoding = Wt::WMediaPlayer::WEBMA; break;
|
||||
case Database::AudioEncoding::OGA: encoding = Wt::WMediaPlayer::OGA; break;
|
||||
case Database::AudioEncoding::FLA: encoding = Wt::WMediaPlayer::FLA; break;
|
||||
case Database::AudioEncoding::AUTO:
|
||||
default:
|
||||
encoding = AudioMediaPlayer::getBestEncoding();
|
||||
}
|
||||
}
|
||||
|
||||
AudioMediaPlayer* mediaPlayer = new AudioMediaPlayer(encoding);
|
||||
@@ -185,9 +188,10 @@ _db(db)
|
||||
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());
|
||||
// TODO reduce transaction scope here
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Database::Track::pointer track = Database::Track::getById(_db.getSession(), id);
|
||||
Database::Track::pointer track = Database::Track::getById(DboSession(), id);
|
||||
|
||||
if (track)
|
||||
{
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
|
||||
#include "audio/Audio.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
@@ -32,13 +30,12 @@ namespace Mobile {
|
||||
class Audio : public UserInterface::Audio
|
||||
{
|
||||
public:
|
||||
Audio(Database::Handler& db, Wt::WContainerWidget *parent = 0);
|
||||
Audio(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void search(std::string text) {}
|
||||
|
||||
private:
|
||||
|
||||
Database::Handler& _db;
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
@@ -23,23 +23,21 @@
|
||||
#include <Wt/WTemplate>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "ReleaseSearch.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
ReleaseSearch::ReleaseSearch(Database::Handler& db, Wt::WContainerWidget *parent)
|
||||
ReleaseSearch::ReleaseSearch(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
|
||||
@@ -65,10 +63,10 @@ ReleaseSearch::addResults(Database::SearchFilter filter, size_t nb)
|
||||
std::vector<std::string> releases;
|
||||
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Request one more to see if more results are to be expected
|
||||
releases = Database::Track::getReleases(_db.getSession(), filter, _resCount, nb + 1);
|
||||
releases = Database::Track::getReleases(DboSession(), filter, _resCount, nb + 1);
|
||||
}
|
||||
|
||||
bool expectMoreResults;
|
||||
@@ -87,7 +85,7 @@ ReleaseSearch::addResults(Database::SearchFilter filter, size_t nb)
|
||||
|
||||
Wt::WImage *cover = new Wt::WImage();
|
||||
cover->setStyleClass("center-block");
|
||||
cover->setImageLink( Wt::WLink( _coverResource->getReleaseUrl(release)));
|
||||
cover->setImageLink( Wt::WLink( LmsApplication::instance()->getCoverResource()->getReleaseUrl(release, 56)));
|
||||
releaseWidget->bindWidget("cover", cover);
|
||||
|
||||
releaseWidget->bindWidget("name", new Wt::WText(Wt::WString::fromUTF8(release), Wt::PlainText));
|
||||
|
||||
@@ -25,10 +25,6 @@
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
@@ -36,7 +32,7 @@ class ReleaseSearch : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
ReleaseSearch(Database::Handler& db, Wt::WContainerWidget *parent = 0);
|
||||
ReleaseSearch(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void search(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
@@ -52,10 +48,6 @@ class ReleaseSearch : public Wt::WContainerWidget
|
||||
void clear(void);
|
||||
void addResults(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
CoverResource* _coverResource;
|
||||
|
||||
std::size_t _resCount;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@
|
||||
#include <Wt/WTemplate>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "TrackSearch.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
TrackSearch::TrackSearch(Database::Handler& db, Wt::WContainerWidget *parent)
|
||||
TrackSearch::TrackSearch(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_db(db),
|
||||
_resCount(0)
|
||||
{
|
||||
Wt::WTemplate* title = new Wt::WTemplate(this);
|
||||
@@ -39,7 +39,6 @@ _resCount(0)
|
||||
|
||||
title->bindWidget("text", new Wt::WText("Tracks", Wt::PlainText));
|
||||
|
||||
_coverResource = new CoverResource(db, 56);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -61,9 +60,9 @@ TrackSearch::search(Database::SearchFilter filter, size_t max)
|
||||
void
|
||||
TrackSearch::addResults(Database::SearchFilter filter, size_t nb)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
std::vector< Database::Track::pointer > tracks = Database::Track::getTracks(_db.getSession(), filter, _resCount, nb + 1);
|
||||
std::vector< Database::Track::pointer > tracks = Database::Track::getTracks(DboSession(), filter, _resCount, nb + 1);
|
||||
|
||||
bool expectMoreResults;
|
||||
if (tracks.size() == nb + 1)
|
||||
@@ -81,7 +80,7 @@ TrackSearch::addResults(Database::SearchFilter filter, size_t nb)
|
||||
|
||||
Wt::WImage *cover = new Wt::WImage();
|
||||
cover->setStyleClass("center-block");
|
||||
cover->setImageLink( Wt::WLink (_coverResource->getTrackUrl(track.id())) );
|
||||
cover->setImageLink( Wt::WLink (LmsApplication::instance()->getCoverResource()->getTrackUrl(track.id(), 56)) );
|
||||
trackWidget->bindWidget("cover", cover);
|
||||
|
||||
// Track Name (bold)
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
|
||||
#include "resource/CoverResource.hpp"
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
@@ -36,7 +34,7 @@ class TrackSearch : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
TrackSearch(Database::Handler& db, Wt::WContainerWidget *parent = 0);
|
||||
TrackSearch(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void search(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
@@ -52,10 +50,6 @@ class TrackSearch : public Wt::WContainerWidget
|
||||
void clear(void);
|
||||
void addResults(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
CoverResource* _coverResource;
|
||||
|
||||
std::size_t _resCount;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,15 +17,16 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "LmsAuth.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
LmsAuth::LmsAuth(Database::Handler& db)
|
||||
: Wt::Auth::AuthWidget(db.getAuthService(),
|
||||
db.getUserDatabase(),
|
||||
db.getLogin())
|
||||
LmsAuth::LmsAuth()
|
||||
: Wt::Auth::AuthWidget(DbHandler().getAuthService(),
|
||||
DbHandler().getUserDatabase(),
|
||||
DbHandler().getLogin())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -26,15 +26,13 @@
|
||||
#include <Wt/Auth/AuthWidget>
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class LmsAuth : public Wt::Auth::AuthWidget
|
||||
{
|
||||
public:
|
||||
|
||||
LmsAuth(Database::Handler& db);
|
||||
LmsAuth();
|
||||
|
||||
// LoggedInView is delegated to LmsHome
|
||||
void createLoggedInView () ;
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
SessionData::SessionData(boost::filesystem::path dbPath)
|
||||
: _db(dbPath)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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_SESSION_DATA_HPP
|
||||
#define UI_SESSION_DATA_HPP
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class SessionData
|
||||
{
|
||||
public:
|
||||
|
||||
SessionData(boost::filesystem::path dbPath);
|
||||
|
||||
Database::Handler& getDatabaseHandler() { return _db;}
|
||||
const Database::Handler& getDatabaseHandler() const { return _db;}
|
||||
|
||||
private:
|
||||
|
||||
Database::Handler _db;
|
||||
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,26 +30,12 @@
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
CoverResource::CoverResource(Database::Handler& db, std::size_t size, Wt::WObject *parent)
|
||||
const std::string CoverResource::unknownCoverPath = "/images/unknown-cover.jpg";
|
||||
|
||||
CoverResource::CoverResource(Database::Handler& db, Wt::WObject *parent)
|
||||
: Wt::WResource(parent),
|
||||
_db(db),
|
||||
_size(size)
|
||||
_db(db)
|
||||
{
|
||||
// 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()
|
||||
@@ -57,16 +43,59 @@ CoverResource:: ~CoverResource()
|
||||
beingDeleted();
|
||||
}
|
||||
|
||||
std::string
|
||||
CoverResource::getReleaseUrl(std::string releaseName)
|
||||
const CoverArt::CoverArt&
|
||||
CoverResource::getDefaultCover(std::size_t size)
|
||||
{
|
||||
return url() + "&release=" + releaseName;
|
||||
auto itCover = _defaultCovers.find(size);
|
||||
if (itCover == _defaultCovers.end())
|
||||
{
|
||||
// Load default cover art for this size
|
||||
|
||||
CoverArt::CoverArt defaultCover;
|
||||
|
||||
std::vector<unsigned char> data;
|
||||
{
|
||||
std::ifstream ist(Wt::WApplication::instance()->docRoot() + unknownCoverPath);
|
||||
char c;
|
||||
while(ist.get(c))
|
||||
data.push_back(c);
|
||||
}
|
||||
|
||||
defaultCover.setData(data);
|
||||
defaultCover.setMimeType("image/jpeg");
|
||||
defaultCover.scale(size);
|
||||
|
||||
auto res = _defaultCovers.insert(std::make_pair(size, defaultCover));
|
||||
itCover = res.first;
|
||||
}
|
||||
|
||||
return itCover->second;
|
||||
}
|
||||
|
||||
std::string
|
||||
CoverResource::getTrackUrl(Database::Track::id_type trackId)
|
||||
CoverResource::getReleaseUrl(std::string releaseName, std::size_t size) const
|
||||
{
|
||||
return url()+ "&trackid=" + std::to_string(trackId);
|
||||
return url() + "&release=" + releaseName + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
std::string
|
||||
CoverResource::getTrackUrl(Database::Track::id_type trackId, std::size_t size) const
|
||||
{
|
||||
return url()+ "&trackid=" + std::to_string(trackId) + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
std::string
|
||||
CoverResource::getUnkownTrackUrl(size_t size) const
|
||||
{
|
||||
return Wt::WApplication::instance()->docRoot() + unknownCoverPath + "&size=" + std::to_string(size);
|
||||
}
|
||||
|
||||
void
|
||||
CoverResource::putCover(Wt::Http::Response& response, const CoverArt::CoverArt& cover)
|
||||
{
|
||||
response.setMimeType( cover.getMimeType() );
|
||||
BOOST_FOREACH(unsigned char c, cover.getData())
|
||||
response.out().put( c );
|
||||
}
|
||||
|
||||
void
|
||||
@@ -75,15 +104,24 @@ CoverResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Respons
|
||||
|
||||
// Get the id of the track
|
||||
const std::string *trackIdStr = request.getParameter("trackid");
|
||||
const std::string *sizeStr = request.getParameter("size");
|
||||
const std::string *releaseStr = request.getParameter("release");
|
||||
|
||||
std::vector<CoverArt::CoverArt> covers;
|
||||
|
||||
// Mandatory parameter size
|
||||
if (!sizeStr)
|
||||
return;
|
||||
|
||||
std::size_t size = std::stol(*sizeStr);
|
||||
if (size > maxSize)
|
||||
return;
|
||||
|
||||
if (trackIdStr)
|
||||
{
|
||||
Database::Track::id_type trackId = std::stol(*trackIdStr);
|
||||
std::string path;
|
||||
bool hasCover = false;;
|
||||
bool hasCover = false;
|
||||
|
||||
{
|
||||
// transactions are not thread safe
|
||||
@@ -94,15 +132,13 @@ CoverResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Respons
|
||||
Database::Track::pointer track = Database::Track::getById(_db.getSession(), trackId);
|
||||
if (track)
|
||||
{
|
||||
hasCover = track->hasCover();;
|
||||
hasCover = track->hasCover();
|
||||
path = track->getPath();
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCover)
|
||||
{
|
||||
covers = CoverArt::Grabber::getFromTrack(path);
|
||||
}
|
||||
}
|
||||
else if (releaseStr)
|
||||
{
|
||||
@@ -115,22 +151,15 @@ CoverResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Respons
|
||||
|
||||
BOOST_FOREACH(CoverArt::CoverArt& cover, covers)
|
||||
{
|
||||
if (cover.scale(_size))
|
||||
if (cover.scale(size))
|
||||
{
|
||||
response.setMimeType( cover.getMimeType() );
|
||||
|
||||
BOOST_FOREACH(unsigned char c, cover.getData())
|
||||
response.out().put( c );
|
||||
|
||||
putCover(response, cover);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If no cover found, just send default one
|
||||
response.setMimeType( _defaultCover.getMimeType() );
|
||||
BOOST_FOREACH(unsigned char c, _defaultCover.getData())
|
||||
response.out().put( c );
|
||||
|
||||
putCover(response, getDefaultCover(size));
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <Wt/WResource>
|
||||
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
@@ -32,25 +29,34 @@
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
|
||||
class CoverResource : public Wt::WResource
|
||||
{
|
||||
public:
|
||||
CoverResource(Database::Handler& db,
|
||||
std::size_t size, // size * size pixels
|
||||
Wt::WObject *parent = 0);
|
||||
static const std::string unknownCoverPath;
|
||||
static const std::size_t maxSize = 512;
|
||||
|
||||
CoverResource(Database::Handler& db, Wt::WObject *parent = 0);
|
||||
~CoverResource();
|
||||
|
||||
std::string getReleaseUrl(std::string releaseName);
|
||||
std::string getTrackUrl(Database::Track::id_type trackId);
|
||||
std::string getReleaseUrl(std::string releaseName, size_t size) const;
|
||||
std::string getTrackUrl(Database::Track::id_type trackId, size_t size) const;
|
||||
std::string getUnkownTrackUrl(size_t size) const;
|
||||
|
||||
void handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response);
|
||||
|
||||
private:
|
||||
|
||||
const CoverArt::CoverArt& getDefaultCover(std::size_t size);
|
||||
void putCover(Wt::Http::Response& response, const CoverArt::CoverArt& cover);
|
||||
|
||||
std::mutex _mutex;
|
||||
Database::Handler& _db;
|
||||
std::size_t _size;
|
||||
CoverArt::CoverArt _defaultCover;
|
||||
|
||||
// Default cover for different sizes
|
||||
std::map<std::size_t, CoverArt::CoverArt> _defaultCovers;
|
||||
|
||||
// TODO construct a cache for covers?
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -30,18 +30,18 @@
|
||||
#include "SettingsUsers.hpp"
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "service/ServiceManager.hpp"
|
||||
#include "service/DatabaseUpdateService.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "Settings.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
Settings::Settings(SessionData& sessionData, Wt::WContainerWidget* parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_sessionData(sessionData)
|
||||
Settings::Settings(Wt::WContainerWidget* parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
Wt::WHBoxLayout* hLayout = new Wt::WHBoxLayout(this);
|
||||
|
||||
@@ -62,28 +62,28 @@ _sessionData(sessionData)
|
||||
std::string userId;
|
||||
bool userIsAdmin;
|
||||
{
|
||||
Wt::Dbo::Transaction transaction( sessionData.getDatabaseHandler().getSession());
|
||||
::Database::User::pointer user = sessionData.getDatabaseHandler().getCurrentUser();
|
||||
userId = Database::User::getId(user);
|
||||
userIsAdmin = user->isAdmin();
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
userId = Database::User::getId(CurrentUser());
|
||||
userIsAdmin = CurrentUser()->isAdmin();
|
||||
}
|
||||
|
||||
menu->addItem("Audio", new AudioFormView(sessionData));
|
||||
menu->addItem("Audio", new AudioFormView());
|
||||
if (userIsAdmin)
|
||||
{
|
||||
MediaDirectories* mediaDirectory = new MediaDirectories(sessionData);
|
||||
MediaDirectories* mediaDirectory = new MediaDirectories();
|
||||
mediaDirectory->changed().connect(this, &Settings::handleDatabaseDirectoriesChanged);
|
||||
menu->addItem("Media Folders", mediaDirectory);
|
||||
|
||||
DatabaseFormView* databaseFormView = new DatabaseFormView(sessionData);
|
||||
DatabaseFormView* databaseFormView = new DatabaseFormView();
|
||||
databaseFormView->changed().connect(this, &Settings::restartDatabaseUpdateService);
|
||||
menu->addItem("Database Update", databaseFormView);
|
||||
|
||||
menu->addItem("Users", new Users(sessionData));
|
||||
menu->addItem("Users", new Users());
|
||||
}
|
||||
else
|
||||
{
|
||||
menu->addItem("Account", new AccountFormView(sessionData, userId));
|
||||
menu->addItem("Account", new AccountFormView(userId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,8 +94,8 @@ Settings::handleDatabaseDirectoriesChanged()
|
||||
LMS_LOG(MOD_UI, SEV_NOTICE) << "Media directories have changed: requesting imediate scan";
|
||||
// On directory add or delete, request an immediate scan
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession());
|
||||
Database::MediaDirectorySettings::get(_sessionData.getDatabaseHandler().getSession()).modify()->setManualScanRequested(true);
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
Database::MediaDirectorySettings::get(DboSession()).modify()->setManualScanRequested(true);
|
||||
}
|
||||
|
||||
restartDatabaseUpdateService();
|
||||
|
||||
@@ -19,15 +19,13 @@
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
class Settings : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Settings(SessionData& sessionData, Wt::WContainerWidget* parent = 0);
|
||||
Settings(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
private:
|
||||
|
||||
@@ -35,8 +33,6 @@ class Settings : public Wt::WContainerWidget
|
||||
|
||||
void restartDatabaseUpdateService(void);
|
||||
|
||||
SessionData& _sessionData;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Settings
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "common/Validators.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "SettingsAccountFormView.hpp"
|
||||
|
||||
@@ -45,9 +46,8 @@ class AccountFormModel : public Wt::WFormModel
|
||||
static const Field PasswordField;
|
||||
static const Field PasswordConfirmField;
|
||||
|
||||
AccountFormModel(SessionData& sessionData, std::string userId, Wt::WObject *parent = 0)
|
||||
AccountFormModel(std::string userId, Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent),
|
||||
_db(sessionData.getDatabaseHandler()),
|
||||
_userId(userId)
|
||||
{
|
||||
addField(NameField);
|
||||
@@ -64,10 +64,10 @@ class AccountFormModel : public Wt::WFormModel
|
||||
|
||||
void loadData()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Wt::Auth::User authUser = _db.getUserDatabase().findWithId( _userId );
|
||||
Database::User::pointer user = _db.getUser(authUser);
|
||||
Wt::Auth::User authUser = DbHandler().getUserDatabase().findWithId( _userId );
|
||||
Database::User::pointer user = DbHandler().getUser(authUser);
|
||||
|
||||
if (user && authUser.isValid())
|
||||
{
|
||||
@@ -85,11 +85,11 @@ class AccountFormModel : public Wt::WFormModel
|
||||
{
|
||||
// DBO transaction active here
|
||||
try {
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Update user
|
||||
Wt::Auth::User authUser = _db.getUserDatabase().findWithId(_userId);
|
||||
Database::User::pointer user = _db.getUser( authUser );
|
||||
Wt::Auth::User authUser = DbHandler().getUserDatabase().findWithId(_userId);
|
||||
Database::User::pointer user = DbHandler().getUser( authUser );
|
||||
|
||||
// user may have been deleted by someone else
|
||||
if (!authUser.isValid()) {
|
||||
@@ -131,9 +131,9 @@ class AccountFormModel : public Wt::WFormModel
|
||||
|
||||
if (field == NameField)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
// Must be unique since used as LoginIdentity
|
||||
Wt::Auth::User user = _db.getUserDatabase().findWithIdentity(Wt::Auth::Identity::LoginName, valueText(field));
|
||||
Wt::Auth::User user = DbHandler().getUserDatabase().findWithIdentity(Wt::Auth::Identity::LoginName, valueText(field));
|
||||
if (user.isValid() && user.id() != _userId)
|
||||
error = "Already exists";
|
||||
else
|
||||
@@ -178,7 +178,6 @@ class AccountFormModel : public Wt::WFormModel
|
||||
|
||||
private:
|
||||
|
||||
Database::Handler& _db;
|
||||
std::string _userId;
|
||||
};
|
||||
|
||||
@@ -187,11 +186,11 @@ const Wt::WFormModel::Field AccountFormModel::EmailField = "email";
|
||||
const Wt::WFormModel::Field AccountFormModel::PasswordField = "password";
|
||||
const Wt::WFormModel::Field AccountFormModel::PasswordConfirmField = "password-confirm";
|
||||
|
||||
AccountFormView::AccountFormView(SessionData& sessionData, std::string userId, Wt::WContainerWidget *parent)
|
||||
AccountFormView::AccountFormView(std::string userId, Wt::WContainerWidget *parent)
|
||||
: Wt::WTemplateFormView(parent)
|
||||
{
|
||||
|
||||
_model = new AccountFormModel(sessionData, userId, this);
|
||||
_model = new AccountFormModel(userId, this);
|
||||
|
||||
setTemplateText(tr("userAccountForm-template"));
|
||||
addFunction("id", &WTemplate::Functions::id);
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include <Wt/WTemplateFormView>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
@@ -34,7 +32,7 @@ class AccountFormModel;
|
||||
class AccountFormView : public Wt::WTemplateFormView
|
||||
{
|
||||
public:
|
||||
AccountFormView(SessionData& sessionData, std::string userId, Wt::WContainerWidget *parent = 0);
|
||||
AccountFormView(std::string userId, Wt::WContainerWidget *parent = 0);
|
||||
|
||||
private:
|
||||
void processCancel(); // reload from DB
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "common/Validators.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "SettingsAudioFormView.hpp"
|
||||
|
||||
@@ -58,9 +59,8 @@ class AudioFormModel : public Wt::WFormModel
|
||||
static const Field BitrateField;
|
||||
static const Field EncodingField;
|
||||
|
||||
AudioFormModel(SessionData& sessionData, Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent),
|
||||
_db(sessionData.getDatabaseHandler())
|
||||
AudioFormModel(Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent)
|
||||
{
|
||||
initializeModels();
|
||||
|
||||
@@ -79,11 +79,10 @@ class AudioFormModel : public Wt::WFormModel
|
||||
|
||||
void loadData()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
setValue(BitrateField, std::min(user->getMaxAudioBitrate(), user->getAudioBitrate()) / 1000); // in kps
|
||||
int encodingRow = getAudioEncodingRow( user->getAudioEncoding());
|
||||
setValue(BitrateField, std::min(CurrentUser()->getMaxAudioBitrate(), CurrentUser()->getAudioBitrate()) / 1000); // in kps
|
||||
int encodingRow = getAudioEncodingRow( CurrentUser()->getAudioEncoding());
|
||||
setValue(EncodingField, getAudioEncodingString(encodingRow));
|
||||
}
|
||||
|
||||
@@ -91,14 +90,13 @@ class AudioFormModel : public Wt::WFormModel
|
||||
{
|
||||
// DBO transaction active here
|
||||
try {
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// user may have been deleted by someone else
|
||||
user.modify()->setAudioBitrate( Wt::asNumber(value(BitrateField)) * 1000); // in kbps
|
||||
CurrentUser().modify()->setAudioBitrate( Wt::asNumber(value(BitrateField)) * 1000); // in kbps
|
||||
|
||||
int encodingRow = getAudioEncodingRow( boost::any_cast<Wt::WString>(value((EncodingField))));
|
||||
user.modify()->setAudioEncoding( getAudioEncodingValue(encodingRow));
|
||||
CurrentUser().modify()->setAudioEncoding( getAudioEncodingValue(encodingRow));
|
||||
}
|
||||
catch(Wt::Dbo::Exception& exception)
|
||||
{
|
||||
@@ -145,14 +143,12 @@ class AudioFormModel : public Wt::WFormModel
|
||||
private:
|
||||
void initializeModels()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
Database::User::pointer user = _db.getCurrentUser();
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
_bitrateModel = new Wt::WStringListModel(this);
|
||||
BOOST_FOREACH(std::size_t bitrate, Database::User::audioBitrates)
|
||||
{
|
||||
if (bitrate <= user->getMaxAudioBitrate())
|
||||
if (bitrate <= CurrentUser()->getMaxAudioBitrate())
|
||||
_bitrateModel->addString( Wt::WString("{1}").arg( bitrate / 1000 ) ); // in kbps
|
||||
}
|
||||
|
||||
@@ -166,7 +162,6 @@ class AudioFormModel : public Wt::WFormModel
|
||||
}
|
||||
}
|
||||
|
||||
Database::Handler& _db;
|
||||
std::string _userId;
|
||||
Wt::WStringListModel* _bitrateModel;
|
||||
Wt::WStringListModel* _encodingModel;
|
||||
@@ -175,11 +170,11 @@ class AudioFormModel : public Wt::WFormModel
|
||||
const Wt::WFormModel::Field AudioFormModel::BitrateField = "bitrate";
|
||||
const Wt::WFormModel::Field AudioFormModel::EncodingField = "encoding";
|
||||
|
||||
AudioFormView::AudioFormView(SessionData& sessionData, Wt::WContainerWidget *parent)
|
||||
AudioFormView::AudioFormView(Wt::WContainerWidget *parent)
|
||||
: Wt::WTemplateFormView(parent)
|
||||
{
|
||||
|
||||
_model = new AudioFormModel(sessionData, this);
|
||||
_model = new AudioFormModel(this);
|
||||
|
||||
setTemplateText(tr("audioForm-template"));
|
||||
addFunction("id", &WTemplate::Functions::id);
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include <Wt/WTemplateFormView>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
@@ -34,7 +32,7 @@ class AudioFormModel;
|
||||
class AudioFormView : public Wt::WTemplateFormView
|
||||
{
|
||||
public:
|
||||
AudioFormView(SessionData& sessionData, Wt::WContainerWidget *parent = 0);
|
||||
AudioFormView(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
private:
|
||||
void processCancel(); // reload from DB
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "database/MediaDirectory.hpp"
|
||||
|
||||
#include "common/DirectoryValidator.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "SettingsDatabaseFormView.hpp"
|
||||
|
||||
@@ -43,9 +44,8 @@ class DatabaseFormModel : public Wt::WFormModel
|
||||
static const Field UpdatePeriodField;
|
||||
static const Field UpdateStartTimeField;
|
||||
|
||||
DatabaseFormModel(SessionData& sessionData, Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent),
|
||||
_sessionData(sessionData)
|
||||
DatabaseFormModel(Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent)
|
||||
{
|
||||
initializeModels();
|
||||
|
||||
@@ -64,10 +64,10 @@ class DatabaseFormModel : public Wt::WFormModel
|
||||
|
||||
void loadData()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Get refresh settings
|
||||
::Database::MediaDirectorySettings::pointer settings = ::Database::MediaDirectorySettings::get(_sessionData.getDatabaseHandler().getSession());
|
||||
::Database::MediaDirectorySettings::pointer settings = ::Database::MediaDirectorySettings::get(DboSession());
|
||||
|
||||
int periodRow = getUpdatePeriodModelRow( settings->getUpdatePeriod() );
|
||||
if (periodRow != -1)
|
||||
@@ -81,10 +81,9 @@ class DatabaseFormModel : public Wt::WFormModel
|
||||
|
||||
void saveData()
|
||||
{
|
||||
Wt::Dbo::Session& session( _sessionData.getDatabaseHandler().getSession());
|
||||
Wt::Dbo::Transaction transaction(session);
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
::Database::MediaDirectorySettings::pointer settings = ::Database::MediaDirectorySettings::get(_sessionData.getDatabaseHandler().getSession() );
|
||||
::Database::MediaDirectorySettings::pointer settings = ::Database::MediaDirectorySettings::get(DboSession());
|
||||
|
||||
int periodRow = getUpdatePeriodModelRow( boost::any_cast<Wt::WString>(value(UpdatePeriodField)));
|
||||
assert(periodRow != -1);
|
||||
@@ -99,10 +98,9 @@ class DatabaseFormModel : public Wt::WFormModel
|
||||
bool setImmediateScan(Wt::WString& error)
|
||||
{
|
||||
try {
|
||||
Wt::Dbo::Session& session( _sessionData.getDatabaseHandler().getSession());
|
||||
Wt::Dbo::Transaction transaction(session);
|
||||
Wt::Dbo::Transaction transaction( DboSession());
|
||||
|
||||
::Database::MediaDirectorySettings::pointer settings = ::Database::MediaDirectorySettings::get(_sessionData.getDatabaseHandler().getSession() );
|
||||
::Database::MediaDirectorySettings::pointer settings = ::Database::MediaDirectorySettings::get(DboSession() );
|
||||
|
||||
settings.modify()->setManualScanRequested( true );
|
||||
}
|
||||
@@ -231,7 +229,6 @@ class DatabaseFormModel : public Wt::WFormModel
|
||||
}
|
||||
|
||||
|
||||
SessionData& _sessionData;
|
||||
Wt::WStringListModel* _updatePeriodModel;
|
||||
Wt::WStringListModel* _updateStartTimeModel;
|
||||
|
||||
@@ -241,10 +238,10 @@ const Wt::WFormModel::Field DatabaseFormModel::UpdatePeriodField = "update-peri
|
||||
const Wt::WFormModel::Field DatabaseFormModel::UpdateStartTimeField = "update-start-time";
|
||||
|
||||
|
||||
DatabaseFormView::DatabaseFormView(SessionData& sessionData, Wt::WContainerWidget *parent)
|
||||
DatabaseFormView::DatabaseFormView(Wt::WContainerWidget *parent)
|
||||
: Wt::WTemplateFormView(parent)
|
||||
{
|
||||
_model = new DatabaseFormModel(sessionData, this);
|
||||
_model = new DatabaseFormModel(this);
|
||||
|
||||
setTemplateText(tr("databaseForm-template"));
|
||||
addFunction("id", &WTemplate::Functions::id);
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
@@ -35,7 +33,7 @@ class DatabaseFormModel;
|
||||
class DatabaseFormView : public Wt::WTemplateFormView
|
||||
{
|
||||
public:
|
||||
DatabaseFormView(SessionData& sessionData, Wt::WContainerWidget *parent = 0);
|
||||
DatabaseFormView(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
Wt::Signal<void>& changed() { return _sigChanged; }
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "common/Validators.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "SettingsFirstConnectionFormView.hpp"
|
||||
|
||||
@@ -43,9 +44,8 @@ class FirstConnectionFormModel : public Wt::WFormModel
|
||||
static const Field PasswordField;
|
||||
static const Field PasswordConfirmField;
|
||||
|
||||
FirstConnectionFormModel(SessionData& sessionData, Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent),
|
||||
_db(sessionData.getDatabaseHandler())
|
||||
FirstConnectionFormModel(Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent)
|
||||
{
|
||||
addField(NameField);
|
||||
addField(EmailField);
|
||||
@@ -61,11 +61,11 @@ class FirstConnectionFormModel : public Wt::WFormModel
|
||||
{
|
||||
// DBO transaction active here
|
||||
try {
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Check if a user already exist
|
||||
// If it's the case, just do nothing
|
||||
if (Database::User::getAll(_db.getSession()).size() > 0)
|
||||
if (!Database::User::getAll(DboSession()).empty())
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_ERROR) << "Admin user already created";
|
||||
error = Wt::WString("Admin user already created!");
|
||||
@@ -73,8 +73,8 @@ class FirstConnectionFormModel : public Wt::WFormModel
|
||||
}
|
||||
|
||||
// Create user
|
||||
Wt::Auth::User authUser = _db.getUserDatabase().registerNew();
|
||||
Database::User::pointer user = _db.getUser(authUser);
|
||||
Wt::Auth::User authUser = DbHandler().getUserDatabase().registerNew();
|
||||
Database::User::pointer user = DbHandler().getUser(authUser);
|
||||
|
||||
// Account
|
||||
authUser.setIdentity(Wt::Auth::Identity::LoginName, valueText(NameField));
|
||||
@@ -139,7 +139,6 @@ class FirstConnectionFormModel : public Wt::WFormModel
|
||||
|
||||
private:
|
||||
|
||||
Database::Handler& _db;
|
||||
};
|
||||
|
||||
const Wt::WFormModel::Field FirstConnectionFormModel::NameField = "name";
|
||||
@@ -147,11 +146,11 @@ const Wt::WFormModel::Field FirstConnectionFormModel::EmailField = "email";
|
||||
const Wt::WFormModel::Field FirstConnectionFormModel::PasswordField = "password";
|
||||
const Wt::WFormModel::Field FirstConnectionFormModel::PasswordConfirmField = "password-confirm";
|
||||
|
||||
FirstConnectionFormView::FirstConnectionFormView(SessionData& sessionData, Wt::WContainerWidget *parent)
|
||||
FirstConnectionFormView::FirstConnectionFormView(Wt::WContainerWidget *parent)
|
||||
: Wt::WTemplateFormView(parent)
|
||||
{
|
||||
|
||||
_model = new FirstConnectionFormModel(sessionData, this);
|
||||
_model = new FirstConnectionFormModel(this);
|
||||
|
||||
setTemplateText(tr("firstConnectionForm-template"));
|
||||
addFunction("id", &WTemplate::Functions::id);
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WPushButton>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
@@ -35,7 +33,7 @@ class FirstConnectionFormModel;
|
||||
class FirstConnectionFormView : public Wt::WTemplateFormView
|
||||
{
|
||||
public:
|
||||
FirstConnectionFormView(SessionData& sessionData, Wt::WContainerWidget *parent = 0);
|
||||
FirstConnectionFormView(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#include "database/MediaDirectory.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "SettingsMediaDirectoryFormView.hpp"
|
||||
|
||||
#include "SettingsMediaDirectories.hpp"
|
||||
@@ -31,9 +33,8 @@
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
MediaDirectories::MediaDirectories(SessionData& sessionData, Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_db(sessionData.getDatabaseHandler())
|
||||
MediaDirectories::MediaDirectories(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
// Stack two widgets:
|
||||
_stack = new Wt::WStackedWidget(this);
|
||||
@@ -72,9 +73,9 @@ MediaDirectories::refresh(void)
|
||||
for (int i = _table->rowCount() - 1; i > 0; --i)
|
||||
_table->deleteRow(i);
|
||||
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
std::vector<Database::MediaDirectory::pointer> mediaDirectories = Database::MediaDirectory::getAll(_db.getSession());
|
||||
std::vector<Database::MediaDirectory::pointer> mediaDirectories = Database::MediaDirectory::getAll(DboSession());
|
||||
|
||||
std::size_t id = 1;
|
||||
BOOST_FOREACH(Database::MediaDirectory::pointer mediaDirectory, mediaDirectories)
|
||||
@@ -114,10 +115,10 @@ MediaDirectories::handleDelMediaDirectory(boost::filesystem::path p, Database::M
|
||||
if (messageBox->buttonResult() == Wt::Yes)
|
||||
{
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Delete the media diretory
|
||||
Database::MediaDirectory::pointer mediaDirectory = Database::MediaDirectory::get(_db.getSession(), p, type);
|
||||
Database::MediaDirectory::pointer mediaDirectory = Database::MediaDirectory::get(DboSession(), p, type);
|
||||
if (mediaDirectory)
|
||||
mediaDirectory.remove();
|
||||
}
|
||||
@@ -140,7 +141,7 @@ MediaDirectories::handleCreateMediaDirectory(void)
|
||||
{
|
||||
assert(_stack->count() == 1);
|
||||
|
||||
MediaDirectoryFormView* formView = new MediaDirectoryFormView(_db, _stack);
|
||||
MediaDirectoryFormView* formView = new MediaDirectoryFormView(_stack);
|
||||
formView->completed().connect(this, &MediaDirectories::handleMediaDirectoryFormCompleted);
|
||||
|
||||
_stack->setCurrentIndex(1);
|
||||
|
||||
@@ -27,15 +27,13 @@
|
||||
|
||||
#include "database/MediaDirectory.hpp"
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
class MediaDirectories : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
MediaDirectories(SessionData& sessioNData, Wt::WContainerWidget *parent = 0);
|
||||
MediaDirectories(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void refresh();
|
||||
|
||||
@@ -50,8 +48,6 @@ class MediaDirectories : public Wt::WContainerWidget
|
||||
void handleDelMediaDirectory(boost::filesystem::path p, Database::MediaDirectory::Type type);
|
||||
void handleCreateMediaDirectory(void);
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
Wt::WStackedWidget* _stack;
|
||||
Wt::WTable* _table;
|
||||
};
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "database/MediaDirectory.hpp"
|
||||
|
||||
#include "common/DirectoryValidator.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "SettingsMediaDirectoryFormView.hpp"
|
||||
|
||||
@@ -45,9 +45,8 @@ class MediaDirectoryFormModel : public Wt::WFormModel
|
||||
static const Field PathField;
|
||||
static const Field TypeField;
|
||||
|
||||
MediaDirectoryFormModel(Database::Handler& db, Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent),
|
||||
_db(db)
|
||||
MediaDirectoryFormModel(Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent)
|
||||
{
|
||||
initializeModels();
|
||||
|
||||
@@ -66,18 +65,18 @@ class MediaDirectoryFormModel : public Wt::WFormModel
|
||||
bool saveData(Wt::WString& error)
|
||||
{
|
||||
try {
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Database::MediaDirectory::Type type
|
||||
= (valueText(TypeField) == "Audio") ? Database::MediaDirectory::Audio : Database::MediaDirectory::Video;
|
||||
|
||||
if (Database::MediaDirectory::get(_db.getSession(), valueText(PathField).toUTF8(), type))
|
||||
if (Database::MediaDirectory::get(DboSession(), valueText(PathField).toUTF8(), type))
|
||||
{
|
||||
error = "This Path/Type already exists!";
|
||||
return false;
|
||||
}
|
||||
|
||||
Database::MediaDirectory::create(_db.getSession(), valueText(PathField).toUTF8(), type);
|
||||
Database::MediaDirectory::create(DboSession(), valueText(PathField).toUTF8(), type);
|
||||
|
||||
}
|
||||
catch(Wt::Dbo::Exception& exception)
|
||||
@@ -97,7 +96,6 @@ class MediaDirectoryFormModel : public Wt::WFormModel
|
||||
_typeModel->addString("Video");
|
||||
}
|
||||
|
||||
Database::Handler& _db;
|
||||
std::string _userId;
|
||||
Wt::WStringListModel* _typeModel;
|
||||
};
|
||||
@@ -105,11 +103,11 @@ class MediaDirectoryFormModel : public Wt::WFormModel
|
||||
const Wt::WFormModel::Field MediaDirectoryFormModel::PathField = "path";
|
||||
const Wt::WFormModel::Field MediaDirectoryFormModel::TypeField = "type";
|
||||
|
||||
MediaDirectoryFormView::MediaDirectoryFormView(Database::Handler& db, Wt::WContainerWidget *parent)
|
||||
MediaDirectoryFormView::MediaDirectoryFormView(Wt::WContainerWidget *parent)
|
||||
: Wt::WTemplateFormView(parent)
|
||||
{
|
||||
|
||||
_model = new MediaDirectoryFormModel(db, this);
|
||||
_model = new MediaDirectoryFormModel(this);
|
||||
|
||||
setTemplateText(tr("mediaDirectoryForm-template"));
|
||||
addFunction("id", &WTemplate::Functions::id);
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
@@ -35,7 +33,7 @@ class MediaDirectoryFormModel;
|
||||
class MediaDirectoryFormView : public Wt::WTemplateFormView
|
||||
{
|
||||
public:
|
||||
MediaDirectoryFormView(Database::Handler& db, Wt::WContainerWidget *parent = 0);
|
||||
MediaDirectoryFormView(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
// Signal emitted once the form is completed
|
||||
Wt::Signal<bool>& completed() { return _sigCompleted; }
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "common/Validators.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "SettingsUserFormView.hpp"
|
||||
|
||||
@@ -50,9 +51,8 @@ class UserFormModel : public Wt::WFormModel
|
||||
static const Field AudioBitrateLimitField;
|
||||
static const Field VideoBitrateLimitField;
|
||||
|
||||
UserFormModel(SessionData& sessionData, std::string userId, Wt::WObject *parent = 0)
|
||||
UserFormModel(std::string userId, Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent),
|
||||
_db(sessionData.getDatabaseHandler()),
|
||||
_userId(userId)
|
||||
{
|
||||
initializeModels();
|
||||
@@ -88,12 +88,12 @@ class UserFormModel : public Wt::WFormModel
|
||||
|
||||
if (!userId.empty())
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Wt::Auth::User authUser = _db.getUserDatabase().findWithId( userId );
|
||||
Database::User::pointer user = _db.getUser(authUser);
|
||||
Wt::Auth::User authUser = DbHandler().getUserDatabase().findWithId( userId );
|
||||
Database::User::pointer user = DbHandler().getUser(authUser);
|
||||
|
||||
Wt::Auth::User currentUser = _db.getLogin().user();
|
||||
Wt::Auth::User currentUser = CurrentAuthUser();
|
||||
|
||||
if (user && authUser.isValid())
|
||||
{
|
||||
@@ -130,13 +130,13 @@ class UserFormModel : public Wt::WFormModel
|
||||
bool saveData()
|
||||
{
|
||||
try {
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
if (_userId.empty())
|
||||
{
|
||||
// Create user
|
||||
Wt::Auth::User authUser = _db.getUserDatabase().registerNew();
|
||||
Database::User::pointer user = _db.getUser(authUser);
|
||||
Wt::Auth::User authUser = DbHandler().getUserDatabase().registerNew();
|
||||
Database::User::pointer user = DbHandler().getUser(authUser);
|
||||
|
||||
// Account
|
||||
authUser.setIdentity(Wt::Auth::Identity::LoginName, valueText(NameField));
|
||||
@@ -163,8 +163,8 @@ class UserFormModel : public Wt::WFormModel
|
||||
else
|
||||
{
|
||||
// Update user
|
||||
Wt::Auth::User authUser = _db.getUserDatabase().findWithId(_userId);
|
||||
Database::User::pointer user = _db.getUser( authUser );
|
||||
Wt::Auth::User authUser = DbHandler().getUserDatabase().findWithId(_userId);
|
||||
Database::User::pointer user = DbHandler().getUser( authUser );
|
||||
|
||||
// user may have been deleted by someone else
|
||||
if (!authUser.isValid()) {
|
||||
@@ -219,9 +219,9 @@ class UserFormModel : public Wt::WFormModel
|
||||
|
||||
if (field == NameField)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
// Must be unique since used as LoginIdentity
|
||||
Wt::Auth::User user = _db.getUserDatabase().findWithIdentity(Wt::Auth::Identity::LoginName, valueText(field));
|
||||
Wt::Auth::User user = DbHandler().getUserDatabase().findWithIdentity(Wt::Auth::Identity::LoginName, valueText(field));
|
||||
if (user.isValid() && user.id() != _userId)
|
||||
error = "Already exists";
|
||||
else
|
||||
@@ -280,7 +280,6 @@ class UserFormModel : public Wt::WFormModel
|
||||
|
||||
}
|
||||
|
||||
Database::Handler& _db;
|
||||
std::string _userId;
|
||||
Wt::WStringListModel* _audioBitrateModel;
|
||||
Wt::WStringListModel* _videoBitrateModel;
|
||||
@@ -295,11 +294,11 @@ const Wt::WFormModel::Field UserFormModel::AudioBitrateLimitField = "audio-bitra
|
||||
const Wt::WFormModel::Field UserFormModel::VideoBitrateLimitField = "video-bitrate-limit";
|
||||
|
||||
|
||||
UserFormView::UserFormView(SessionData& sessionData, std::string userId, Wt::WContainerWidget *parent)
|
||||
UserFormView::UserFormView(std::string userId, Wt::WContainerWidget *parent)
|
||||
: Wt::WTemplateFormView(parent)
|
||||
{
|
||||
|
||||
_model = new UserFormModel(sessionData, userId, this);
|
||||
_model = new UserFormModel(userId, this);
|
||||
|
||||
setTemplateText(tr("userForm-template"));
|
||||
addFunction("id", &WTemplate::Functions::id);
|
||||
@@ -344,9 +343,8 @@ UserFormView::UserFormView(SessionData& sessionData, std::string userId, Wt::WCo
|
||||
title = Wt::WString("Create user");
|
||||
}
|
||||
else {
|
||||
Database::Handler &db = sessionData.getDatabaseHandler();
|
||||
Wt::Dbo::Transaction transaction (db.getSession());
|
||||
Wt::Auth::User authUser = db.getUserDatabase().findWithId( userId );
|
||||
Wt::Dbo::Transaction transaction (DboSession());
|
||||
Wt::Auth::User authUser = DbHandler().getUserDatabase().findWithId( userId );
|
||||
|
||||
Wt::WString userName;
|
||||
if (authUser.isValid())
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include <Wt/WTemplateFormView>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
@@ -35,7 +33,7 @@ class UserFormView : public Wt::WTemplateFormView
|
||||
{
|
||||
public:
|
||||
|
||||
UserFormView(SessionData& sessionData, std::string userId, Wt::WContainerWidget *parent = 0);
|
||||
UserFormView(std::string userId, Wt::WContainerWidget *parent = 0);
|
||||
|
||||
// Signal emitted once the form is completed
|
||||
Wt::Signal<bool>& completed() { return _sigCompleted; }
|
||||
|
||||
@@ -28,15 +28,15 @@
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "SettingsUserFormView.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "SettingsUsers.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
Users::Users(SessionData& sessionData, Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_sessionData(sessionData)
|
||||
Users::Users(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
// Stack two widgets:
|
||||
_stack = new Wt::WStackedWidget(this);
|
||||
@@ -76,13 +76,11 @@ Users::refresh(void)
|
||||
for (int i = _table->rowCount() - 1; i > 0; --i)
|
||||
_table->deleteRow(i);
|
||||
|
||||
Database::Handler& db = _sessionData.getDatabaseHandler();
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Wt::Dbo::Transaction transaction(db.getSession());
|
||||
const Wt::Auth::User& currentUser = CurrentAuthUser();
|
||||
|
||||
const Wt::Auth::User& currentUser = db.getLogin().user();
|
||||
|
||||
std::vector<Database::User::pointer> users = Database::User::getAll(db.getSession());
|
||||
std::vector<Database::User::pointer> users = Database::User::getAll(DboSession());
|
||||
|
||||
std::size_t userIndex = 1;
|
||||
for (std::size_t i = 0; i < users.size(); ++i)
|
||||
@@ -94,7 +92,7 @@ Users::refresh(void)
|
||||
|
||||
// Hack try/catch here since it may fail!
|
||||
try {
|
||||
authUser = db.getUserDatabase().findWithId( userId );
|
||||
authUser = DbHandler().getUserDatabase().findWithId( userId );
|
||||
}
|
||||
catch(Wt::Dbo::Exception& e)
|
||||
{
|
||||
@@ -152,16 +150,14 @@ Users::handleDelUser(Wt::WString loginNameIdentity, std::string id)
|
||||
messageBox->buttonClicked().connect(std::bind([=] () {
|
||||
if (messageBox->buttonResult() == Wt::Yes)
|
||||
{
|
||||
Database::Handler& db = _sessionData.getDatabaseHandler();
|
||||
|
||||
Wt::Dbo::Transaction transaction(db.getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
// Delete the user
|
||||
Wt::Auth::User authUser = db.getUserDatabase().findWithId( id );
|
||||
Wt::Auth::User authUser = DbHandler().getUserDatabase().findWithId( id );
|
||||
|
||||
db.getUserDatabase().deleteUser( authUser );
|
||||
DbHandler().getUserDatabase().deleteUser( authUser );
|
||||
|
||||
Database::User::pointer user = Database::User::getById(db.getSession(), id);
|
||||
Database::User::pointer user = Database::User::getById(DboSession(), id);
|
||||
if (user)
|
||||
user.remove();
|
||||
|
||||
@@ -180,7 +176,7 @@ Users::handleCreateUser(std::string id)
|
||||
{
|
||||
assert(_stack->count() == 1);
|
||||
|
||||
UserFormView* userFormView = new UserFormView(_sessionData, id, _stack);
|
||||
UserFormView* userFormView = new UserFormView(id, _stack);
|
||||
userFormView->completed().connect(this, &Users::handleUserFormCompleted);
|
||||
|
||||
_stack->setCurrentIndex(1);
|
||||
|
||||
@@ -24,15 +24,13 @@
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WTable>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
class Users : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Users(SessionData& sessioNData, Wt::WContainerWidget *parent = 0);
|
||||
Users(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void refresh();
|
||||
|
||||
@@ -43,8 +41,6 @@ class Users : public Wt::WContainerWidget
|
||||
void handleDelUser(Wt::WString loginNameIdentity, std::string id);
|
||||
void handleCreateUser(std::string id); // set the id in order to edit the user
|
||||
|
||||
SessionData& _sessionData;
|
||||
|
||||
Wt::WStackedWidget* _stack;
|
||||
Wt::WTable* _table;
|
||||
};
|
||||
|
||||
@@ -27,13 +27,14 @@
|
||||
|
||||
#include "transcode/Parameters.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "VideoDatabaseWidget.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
VideoDatabaseWidget::VideoDatabaseWidget(Database::Handler& db, Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_db(db)
|
||||
VideoDatabaseWidget::VideoDatabaseWidget(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
_table = new Wt::WTable( this );
|
||||
_table->setHeaderCount(1);
|
||||
@@ -98,10 +99,10 @@ VideoDatabaseWidget::updateView(boost::filesystem::path directory, size_t depth)
|
||||
// If directory is not valid, add the root Media Directories
|
||||
if (depth == 0)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction ( _db.getSession() );
|
||||
Wt::Dbo::Transaction transaction ( DboSession() );
|
||||
|
||||
std::vector<Database::MediaDirectory::pointer> dirs
|
||||
= Database::MediaDirectory::getByType(_db.getSession(), Database::MediaDirectory::Video);
|
||||
= Database::MediaDirectory::getByType(DboSession(), Database::MediaDirectory::Video);
|
||||
|
||||
BOOST_FOREACH(Database::MediaDirectory::pointer dir, dirs)
|
||||
{
|
||||
@@ -128,9 +129,9 @@ VideoDatabaseWidget::updateView(boost::filesystem::path directory, size_t depth)
|
||||
addDirectory( path.filename().string(), path, depth + 1);
|
||||
else if (boost::filesystem::is_regular(path) )
|
||||
{
|
||||
Wt::Dbo::Transaction transaction ( _db.getSession() );
|
||||
Wt::Dbo::Transaction transaction ( DboSession() );
|
||||
|
||||
Database::Video::pointer video = Database::Video::getByPath( _db.getSession(), path);
|
||||
Database::Video::pointer video = Database::Video::getByPath( DboSession(), path);
|
||||
if (video)
|
||||
addVideo( video->getName(), video->getDuration(), path);
|
||||
}
|
||||
|
||||
@@ -23,14 +23,12 @@
|
||||
#include <Wt/WTable>
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class VideoDatabaseWidget : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
VideoDatabaseWidget( Database::Handler& db, Wt::WContainerWidget *parent = 0);
|
||||
VideoDatabaseWidget(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
// Signals
|
||||
Wt::Signal< boost::filesystem::path >& playVideo() { return _playVideo; }
|
||||
@@ -43,8 +41,6 @@ class VideoDatabaseWidget : public Wt::WContainerWidget
|
||||
|
||||
void updateView(boost::filesystem::path directory, size_t depth);
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
Wt::Signal< boost::filesystem::path > _playVideo;
|
||||
|
||||
Wt::WTable* _table;
|
||||
|
||||
@@ -22,16 +22,17 @@
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "VideoWidget.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
VideoWidget::VideoWidget(SessionData& sessionData, Wt::WContainerWidget* parent )
|
||||
: Wt::WContainerWidget(parent),
|
||||
_sessionData(sessionData)
|
||||
VideoWidget::VideoWidget(Wt::WContainerWidget* parent )
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
|
||||
_videoDbWidget = new VideoDatabaseWidget(_sessionData.getDatabaseHandler(), this);
|
||||
_videoDbWidget = new VideoDatabaseWidget(this);
|
||||
|
||||
_videoDbWidget->playVideo().connect(this, &VideoWidget::playVideo);
|
||||
|
||||
@@ -56,19 +57,10 @@ VideoWidget::playVideo(boost::filesystem::path p)
|
||||
|
||||
// Get user preferences
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession());
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
Database::User::pointer user = _sessionData.getDatabaseHandler().getCurrentUser();
|
||||
if (user)
|
||||
{
|
||||
audioBitrate = user->getMaxAudioBitrate();
|
||||
videoBitrate = user->getMaxVideoBitrate();
|
||||
}
|
||||
else
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_ERROR) << "Can't play video: user does not exists!";
|
||||
return; // TODO logout?
|
||||
}
|
||||
audioBitrate = CurrentUser()->getMaxAudioBitrate();
|
||||
videoBitrate = CurrentUser()->getMaxVideoBitrate();
|
||||
}
|
||||
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Max bitrate set to " << videoBitrate << "/" << audioBitrate;
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
#include "video/VideoMediaPlayerWidget.hpp"
|
||||
#include "video/VideoDatabaseWidget.hpp"
|
||||
|
||||
@@ -35,7 +33,7 @@ class VideoWidget : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
VideoWidget(SessionData& sessionData, Wt::WContainerWidget* parent = 0);
|
||||
VideoWidget(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
void search(const std::string& searchText);
|
||||
|
||||
@@ -44,8 +42,6 @@ class VideoWidget : public Wt::WContainerWidget
|
||||
void backToList(void);
|
||||
void playVideo(boost::filesystem::path p);
|
||||
|
||||
SessionData& _sessionData;
|
||||
|
||||
VideoDatabaseWidget* _videoDbWidget;
|
||||
VideoMediaPlayerWidget* _mediaPlayer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user