Centralized the play/stop events from playqueue
This commit is contained in:
+25
-40
@@ -145,7 +145,7 @@ LmsApplication::finalize()
|
||||
|
||||
getApplicationGroup().postOthers([info]
|
||||
{
|
||||
LmsApp->getGroupEvents().appClosed(info);
|
||||
LmsApp->getEvents().appClosed(info);
|
||||
});
|
||||
|
||||
getApplicationGroup().leave();
|
||||
@@ -304,7 +304,7 @@ LmsApplication::handleAuthEvent()
|
||||
|
||||
getApplicationGroup().postOthers([info]
|
||||
{
|
||||
LmsApp->getGroupEvents().appOpen(info);
|
||||
LmsApp->getEvents().appOpen(info);
|
||||
});
|
||||
|
||||
createHome();
|
||||
@@ -407,7 +407,7 @@ LmsApplication::createHome()
|
||||
|
||||
Explore* explore = mainStack->addNew<Explore>();
|
||||
PlayQueue* playqueue = mainStack->addNew<PlayQueue>();
|
||||
PlayHistory* playhistory = mainStack->addNew<PlayHistory>();
|
||||
mainStack->addNew<PlayHistory>();
|
||||
mainStack->addNew<SettingsView>();
|
||||
|
||||
// Admin stuff
|
||||
@@ -446,54 +446,44 @@ LmsApplication::createHome()
|
||||
playqueue->playNext();
|
||||
});
|
||||
|
||||
// Events from the PlayQueue
|
||||
playqueue->loadTrack.connect([=](Database::IdType trackId, bool play)
|
||||
playqueue->loadTrack.connect([=] (Database::IdType trackId, bool play)
|
||||
{
|
||||
playhistory->addTrack(trackId);
|
||||
_events.trackLoaded(trackId, play);
|
||||
});
|
||||
|
||||
playqueue->loadTrack.connect([=](Database::IdType trackId, bool play)
|
||||
playqueue->trackUnload.connect([=]
|
||||
{
|
||||
explore->handleTrackPlayed(trackId);
|
||||
_events.trackUnloaded();
|
||||
});
|
||||
|
||||
playqueue->loadTrack.connect(player, &MediaPlayer::loadTrack);
|
||||
|
||||
playqueue->playbackStop.connect(player, &MediaPlayer::stop);
|
||||
|
||||
// Events from MediaScanner
|
||||
std::string sessionId = LmsApp->sessionId();
|
||||
_scanner.scanComplete().connect([=] (Scanner::MediaScanner::Stats stats)
|
||||
{
|
||||
// Runs from media scanner context
|
||||
Wt::WServer::instance()->post(sessionId, [=]
|
||||
{
|
||||
bool changes = false;
|
||||
|
||||
if (_isAdmin)
|
||||
{
|
||||
notifyMsg(MsgType::Info, Wt::WString::tr("Lms.Admin.Database.scan-complete")
|
||||
.arg(static_cast<unsigned>(stats.nbFiles()))
|
||||
.arg(static_cast<unsigned>(stats.additions))
|
||||
.arg(static_cast<unsigned>(stats.updates))
|
||||
.arg(static_cast<unsigned>(stats.deletions))
|
||||
.arg(static_cast<unsigned>(stats.nbDuplicates()))
|
||||
.arg(static_cast<unsigned>(stats.nbErrors())));
|
||||
changes = true;
|
||||
}
|
||||
|
||||
if (stats.nbChanges() > 0)
|
||||
{
|
||||
explore->handleDbChanged();
|
||||
changes = true;
|
||||
}
|
||||
|
||||
if (changes)
|
||||
triggerUpdate();
|
||||
_events.dbScanned.emit(stats);
|
||||
triggerUpdate();
|
||||
});
|
||||
});
|
||||
|
||||
_events.dbScanned.connect([=] (Scanner::MediaScanner::Stats stats)
|
||||
{
|
||||
if (_isAdmin)
|
||||
{
|
||||
notifyMsg(MsgType::Info, Wt::WString::tr("Lms.Admin.Database.scan-complete")
|
||||
.arg(static_cast<unsigned>(stats.nbFiles()))
|
||||
.arg(static_cast<unsigned>(stats.additions))
|
||||
.arg(static_cast<unsigned>(stats.updates))
|
||||
.arg(static_cast<unsigned>(stats.deletions))
|
||||
.arg(static_cast<unsigned>(stats.nbDuplicates()))
|
||||
.arg(static_cast<unsigned>(stats.nbErrors())));
|
||||
}
|
||||
});
|
||||
|
||||
// Events from Application group
|
||||
_groupEvents.appOpen.connect([=] (LmsApplicationInfo info)
|
||||
_events.appOpen.connect([=] (LmsApplicationInfo info)
|
||||
{
|
||||
// Only one active session by user
|
||||
if (!LmsApp->getUser()->isDemo())
|
||||
@@ -503,11 +493,6 @@ LmsApplication::createHome()
|
||||
}
|
||||
});
|
||||
|
||||
_groupEvents.appClosed.connect([=] (LmsApplicationInfo info)
|
||||
{
|
||||
;
|
||||
});
|
||||
|
||||
internalPathChanged().connect(std::bind([=]
|
||||
{
|
||||
handlePathChange(mainStack, _isAdmin);
|
||||
|
||||
@@ -38,12 +38,23 @@ namespace UserInterface {
|
||||
class TranscodeResource;
|
||||
class ImageResource;
|
||||
|
||||
struct GroupEvents
|
||||
// Events that can be listen to anywhere in the application
|
||||
struct Events
|
||||
{
|
||||
// Events relative to group
|
||||
Wt::Signal<LmsApplicationInfo> appOpen;
|
||||
Wt::Signal<LmsApplicationInfo> appClosed;
|
||||
|
||||
// A track is being loaded
|
||||
Wt::Signal<Database::IdType /* trackId */, bool /* play */> trackLoaded;
|
||||
// Unload current track
|
||||
Wt::Signal<> trackUnloaded;
|
||||
|
||||
// A database scan is complete
|
||||
Wt::Signal<Scanner::MediaScanner::Stats> dbScanned;
|
||||
};
|
||||
|
||||
// Used to classify the message sent to the user
|
||||
enum class MsgType
|
||||
{
|
||||
Success,
|
||||
@@ -73,7 +84,7 @@ class LmsApplication : public Wt::WApplication
|
||||
|
||||
Scanner::MediaScanner& getMediaScanner() { return _scanner; }
|
||||
|
||||
GroupEvents& getGroupEvents() { return _groupEvents; }
|
||||
Events& getEvents() { return _events; }
|
||||
|
||||
// Utils
|
||||
void goHome();
|
||||
@@ -105,7 +116,7 @@ class LmsApplication : public Wt::WApplication
|
||||
Wt::Signal<> _preQuit;
|
||||
Database::Handler _db;
|
||||
LmsApplicationGroupContainer& _appGroups;
|
||||
GroupEvents _groupEvents;
|
||||
Events _events;
|
||||
Wt::WString _userIdentity;
|
||||
Auth* _auth;
|
||||
Scanner::MediaScanner& _scanner;
|
||||
|
||||
@@ -48,6 +48,9 @@ MediaPlayer::MediaPlayer()
|
||||
_release->setTextFormat(Wt::TextFormat::Plain);
|
||||
|
||||
wApp->doJavaScript("LMS.mediaplayer.init(" + jsRef() + ")");
|
||||
|
||||
LmsApp->getEvents().trackLoaded.connect(this, &MediaPlayer::loadTrack);
|
||||
LmsApp->getEvents().trackUnloaded.connect(this, &MediaPlayer::stop);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -33,15 +33,14 @@ class MediaPlayer : public Wt::WTemplate
|
||||
public:
|
||||
MediaPlayer();
|
||||
|
||||
void stop();
|
||||
void loadTrack(Database::IdType trackId, bool play);
|
||||
|
||||
// Signals
|
||||
Wt::JSignal<> playbackEnded;
|
||||
Wt::JSignal<> playPrevious;
|
||||
Wt::JSignal<> playNext;
|
||||
|
||||
private:
|
||||
void stop();
|
||||
void loadTrack(Database::IdType trackId, bool play);
|
||||
|
||||
Wt::WText* _title;
|
||||
Wt::WAnchor* _release;
|
||||
|
||||
@@ -74,19 +74,17 @@ PlayHistory::PlayHistory()
|
||||
addSome();
|
||||
});
|
||||
|
||||
LmsApp->getEvents().trackLoaded.connect([=](Database::IdType trackId, bool /* play */)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction (LmsApp->getDboSession());
|
||||
|
||||
auto trackEntry = LmsApp->getUser()->getPlayedTrackList().modify()->add(trackId);
|
||||
_entriesContainer->insertWidget(0, createEntry(trackEntry->getTrack()));
|
||||
});
|
||||
|
||||
addSome();
|
||||
}
|
||||
|
||||
void
|
||||
PlayHistory::addTrack(Database::IdType trackId)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction (LmsApp->getDboSession());
|
||||
|
||||
auto trackEntry = LmsApp->getUser()->getPlayedTrackList().modify()->add(trackId);
|
||||
_entriesContainer->insertWidget(0, createEntry(trackEntry->getTrack()));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayHistory::addSome()
|
||||
{
|
||||
|
||||
@@ -32,8 +32,6 @@ class PlayHistory : public Wt::WTemplate
|
||||
public:
|
||||
PlayHistory();
|
||||
|
||||
void addTrack(Database::IdType trackId);
|
||||
|
||||
private:
|
||||
|
||||
void addSome();
|
||||
|
||||
@@ -135,7 +135,7 @@ PlayQueue::stop()
|
||||
{
|
||||
updateCurrentTrack(false);
|
||||
_trackPos.reset();
|
||||
playbackStop.emit();
|
||||
trackUnload.emit();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -51,7 +51,7 @@ class PlayQueue : public Wt::WTemplate
|
||||
Wt::Signal<Database::IdType /*trackId*/, bool /*play*/> loadTrack;
|
||||
|
||||
// Signal emitted when play has to be stopped
|
||||
Wt::Signal<> playbackStop;
|
||||
Wt::Signal<> trackUnload;
|
||||
|
||||
private:
|
||||
Database::TrackList::pointer getTrackList();
|
||||
|
||||
@@ -57,6 +57,16 @@ ArtistsInfo::ArtistsInfo()
|
||||
_mostPlayedContainer = bindNew<Wt::WContainerWidget>("most-played");
|
||||
_recentlyAddedContainer = bindNew<Wt::WContainerWidget>("recently-added");
|
||||
|
||||
LmsApp->getEvents().dbScanned.connect([=]
|
||||
{
|
||||
refreshRecentlyAdded();
|
||||
});
|
||||
|
||||
LmsApp->getEvents().trackLoaded.connect([=]
|
||||
{
|
||||
refreshMostPlayed();
|
||||
});
|
||||
|
||||
refreshMostPlayed();
|
||||
refreshRecentlyAdded();
|
||||
}
|
||||
|
||||
@@ -152,32 +152,14 @@ Explore::Explore()
|
||||
Wt::WStackedWidget* infoStack = bindNew<Wt::WStackedWidget>("info");
|
||||
|
||||
auto artistsInfo = std::make_unique<ArtistsInfo>();
|
||||
auto artistsInfoRaw = artistsInfo.get();
|
||||
infoStack->addWidget(std::move(artistsInfo));
|
||||
|
||||
auto releasesInfo = std::make_unique<ReleasesInfo>();
|
||||
auto releasesInfoRaw = releasesInfo.get();
|
||||
infoStack->addWidget(std::move(releasesInfo));
|
||||
|
||||
auto tracksInfo = std::make_unique<TracksInfo>();
|
||||
auto tracksInfoRaw = tracksInfo.get();
|
||||
infoStack->addWidget(std::move(tracksInfo));
|
||||
|
||||
_dbChanged.connect([=]
|
||||
{
|
||||
artistsInfoRaw->refreshRecentlyAdded();
|
||||
releasesInfoRaw->refreshRecentlyAdded();
|
||||
tracksInfoRaw->refreshRecentlyAdded();
|
||||
});
|
||||
|
||||
_trackPlayed.connect([=]
|
||||
{
|
||||
artistsInfoRaw->refreshMostPlayed();
|
||||
releasesInfoRaw->refreshMostPlayed();
|
||||
tracksInfoRaw->refreshMostPlayed();
|
||||
});
|
||||
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=]
|
||||
{
|
||||
handleContentsPathChange(contentsStack);
|
||||
|
||||
@@ -36,9 +36,6 @@ class Explore : public Wt::WTemplate
|
||||
Wt::Signal<std::vector<Database::Track::pointer>> tracksAdd;
|
||||
Wt::Signal<std::vector<Database::Track::pointer>> tracksPlay;
|
||||
|
||||
void handleDbChanged() { _dbChanged.emit(); };
|
||||
void handleTrackPlayed(Database::IdType trackId) { _trackPlayed.emit(); }
|
||||
|
||||
private:
|
||||
|
||||
void handleArtistAdd(Database::IdType id);
|
||||
@@ -51,9 +48,6 @@ class Explore : public Wt::WTemplate
|
||||
void handleTracksPlay(std::vector<Database::Track::pointer> tracks);
|
||||
|
||||
Filters* _filters;
|
||||
|
||||
Wt::Signal<> _dbChanged;
|
||||
Wt::Signal<> _trackPlayed;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -77,6 +77,16 @@ ReleasesInfo::ReleasesInfo()
|
||||
_mostPlayedContainer = bindNew<Wt::WContainerWidget>("most-played");
|
||||
_recentlyAddedContainer = bindNew<Wt::WContainerWidget>("recently-added");
|
||||
|
||||
LmsApp->getEvents().dbScanned.connect([=]
|
||||
{
|
||||
refreshRecentlyAdded();
|
||||
});
|
||||
|
||||
LmsApp->getEvents().trackLoaded.connect([=]
|
||||
{
|
||||
refreshMostPlayed();
|
||||
});
|
||||
|
||||
refreshRecentlyAdded();
|
||||
refreshMostPlayed();
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ class ReleasesInfo : public Wt::WTemplate
|
||||
public:
|
||||
ReleasesInfo();
|
||||
|
||||
private:
|
||||
void refreshRecentlyAdded();
|
||||
void refreshMostPlayed();
|
||||
|
||||
private:
|
||||
Wt::WContainerWidget* _mostPlayedContainer;
|
||||
Wt::WContainerWidget* _recentlyAddedContainer;
|
||||
};
|
||||
|
||||
@@ -57,6 +57,16 @@ TracksInfo::TracksInfo()
|
||||
_mostPlayedContainer = bindNew<Wt::WContainerWidget>("most-played");
|
||||
_recentlyAddedContainer = bindNew<Wt::WContainerWidget>("recently-added");
|
||||
|
||||
LmsApp->getEvents().dbScanned.connect([=]
|
||||
{
|
||||
refreshRecentlyAdded();
|
||||
});
|
||||
|
||||
LmsApp->getEvents().trackLoaded.connect([=]
|
||||
{
|
||||
refreshMostPlayed();
|
||||
});
|
||||
|
||||
refreshMostPlayed();
|
||||
refreshRecentlyAdded();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user