From 53bc31ebb9c1ec1ae7f25344288b617b39a7872f Mon Sep 17 00:00:00 2001 From: Kevin Whitaker Date: Wed, 15 Feb 2017 00:47:58 -0500 Subject: [PATCH] Start implementing web UI. Add track detail container. Comment out some old test code and DB code while more gets hooked up. Play/pause button is mostly implemented. --- CMakeLists.txt | 2 +- src/GroovePlayer.cpp | 40 +++++++++++++++--------------- src/WebInterface.cpp | 15 +++++------ src/WebInterface.h | 1 + src/ui/PlayerInterface.cpp | 51 ++++++++++++++++++++++++++++++++++++-- src/ui/PlayerInterface.h | 31 ++++++++++++++++++++++- src/ui/TrackDetails.cpp | 20 +++++++++++++++ src/ui/TrackDetails.h | 29 ++++++++++++++++++++++ 8 files changed, 158 insertions(+), 31 deletions(-) create mode 100644 src/ui/TrackDetails.cpp create mode 100644 src/ui/TrackDetails.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d170192..b74af1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ find_package(Wt REQUIRED) find_package(Groove REQUIRED) find_package(TagLib REQUIRED) -add_executable(arbitrateor src/main.cpp src/WebInterface.cpp src/GroovePlayer.cpp src/ui/LoginInterface.cpp src/ui/PlayerInterface.cpp) +add_executable(arbitrateor src/main.cpp src/WebInterface.cpp src/GroovePlayer.cpp src/ui/LoginInterface.cpp src/ui/PlayerInterface.cpp src/ui/TrackDetails.cpp) target_link_libraries(arbitrateor ${Wt_LIBRARIES} ${GROOVE_LIBRARY} ${GROOVE_FINGERPRINT_LIBRARY} ${GROOVE_PLAYER_LIBRARY} ${TAGLIB_LIBRARY} pthread stdc++fs) #TODO get threading links based on platform. Remove gcc experimental fs when official c++17 exists. install(TARGETS arbitrateor RUNTIME DESTINATION bin) diff --git a/src/GroovePlayer.cpp b/src/GroovePlayer.cpp index c14fb5d..5ca4fd1 100644 --- a/src/GroovePlayer.cpp +++ b/src/GroovePlayer.cpp @@ -390,16 +390,16 @@ void GroovePlayerMgr::grooveEventLoop() } else if(event.eventType == PLAYING_PAUSED) { - //Add action to DB - Wt::Dbo::Transaction pauseTransaction(sqlSession); - UserAction* action = new UserAction(); - action->action = UserAction::UAction::PlayPause; - action->user = Wt::Dbo::ptr(&event.userInvolved); - action->trackInvolved = Wt::Dbo::ptr(&event.tracksInvolved.front()); - action->datetime = Wt::WDateTime::currentDateTime(); - sqlSession.add(action); - pauseTransaction.commit(); - + //Add action to DB TODO +// Wt::Dbo::Transaction pauseTransaction(sqlSession); +// UserAction* action = new UserAction(); +// action->action = UserAction::UAction::PlayPause; +// action->user = Wt::Dbo::ptr(&event.userInvolved); +// action->trackInvolved = Wt::Dbo::ptr(&event.tracksInvolved.front()); +// action->datetime = Wt::WDateTime::currentDateTime(); +// sqlSession.add(action); +// pauseTransaction.commit(); + groove_playlist_pause(currentPlaylist); //Update vote display on all clients. @@ -414,16 +414,16 @@ void GroovePlayerMgr::grooveEventLoop() } else if(event.eventType == PLAYING_RESUMED) { - //Add action to DB - Wt::Dbo::Transaction playTransaction(sqlSession); - UserAction* action = new UserAction(); - action->action = UserAction::UAction::PlayPause; - action->user = Wt::Dbo::ptr(&event.userInvolved); - action->trackInvolved = Wt::Dbo::ptr(&event.tracksInvolved.front()); - action->datetime = Wt::WDateTime::currentDateTime(); - sqlSession.add(action); - playTransaction.commit(); - + //Add action to DB TODO +// Wt::Dbo::Transaction playTransaction(sqlSession); +// UserAction* action = new UserAction(); +// action->action = UserAction::UAction::PlayPause; +// action->user = Wt::Dbo::ptr(&event.userInvolved); +// action->trackInvolved = Wt::Dbo::ptr(&event.tracksInvolved.front()); +// action->datetime = Wt::WDateTime::currentDateTime(); +// sqlSession.add(action); +// playTransaction.commit(); + groove_playlist_play(currentPlaylist); //Update vote display on all clients. diff --git a/src/WebInterface.cpp b/src/WebInterface.cpp index 67a83db..6a2ec9e 100644 --- a/src/WebInterface.cpp +++ b/src/WebInterface.cpp @@ -59,42 +59,43 @@ void WebInterface::loginCompleted() void WebInterface::playPauseActionFromServer(User userPausing, bool pause) { - priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"play"); + priv_int->playerUI->isPaused = pause; + priv_int->playerUI->playpauseUpdated(); triggerUpdate(); } void WebInterface::songChangedFromServer(AudioTrack nextTrack) { - priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"change"); + //priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"change"); triggerUpdate(); } void WebInterface::skipVotedFromServer(User userRequestingToSkipCurrentTrack) { - priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"skip"); + //priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"skip"); triggerUpdate(); } void WebInterface::skipVoteUpdateFromServer(User userVoting, bool forSkip) { - priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"vote"); + //priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"vote"); triggerUpdate(); } void WebInterface::voteNextSongFromServer(User userVoting, AudioTrack trackVoted) { - priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"nextvote"); + //priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"nextvote"); triggerUpdate(); } void WebInterface::voteNextPollClosedFromServer() { - priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"voteclosed"); + //priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"voteclosed"); triggerUpdate(); } void WebInterface::voteTracksUpdatedFromServer(std::list voteableTracks) { - priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"votechanged"); + //priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"votechanged"); triggerUpdate(); } diff --git a/src/WebInterface.h b/src/WebInterface.h index 2d90853..647335e 100644 --- a/src/WebInterface.h +++ b/src/WebInterface.h @@ -38,6 +38,7 @@ public: void skipVoteUpdateFromServer(User userVoting, bool forSkip); void voteNextSongFromServer(User userVoting, AudioTrack trackVoted); void voteNextPollClosedFromServer(); + User currentUser; private: struct internal; internal* priv_int = 0; diff --git a/src/ui/PlayerInterface.cpp b/src/ui/PlayerInterface.cpp index a12c73f..6d1015a 100644 --- a/src/ui/PlayerInterface.cpp +++ b/src/ui/PlayerInterface.cpp @@ -19,10 +19,57 @@ #include "PlayerInterface.h" #include +#include "../GroovePlayer.h" PlayerInterface::PlayerInterface(WebInterface* app) { this->app = app; - tempText = new Wt::WText("You did it."); - addChild(tempText); + interfaceLayout = new Wt::WVBoxLayout(); + this->setLayout(interfaceLayout); + playControlContainer = new Wt::WContainerWidget(); + voteControlContainer = new Wt::WContainerWidget(); + playControlLayout = new Wt::WHBoxLayout(); + voteControlLayout = new Wt::WVBoxLayout(); + playControlContainer->setLayout(playControlLayout); + voteControlContainer->setLayout(voteControlLayout); + + currentTrackProgress = new Wt::WProgressBar(); + currentTrackProgress->setFormat(""); + trackProgress = new Wt::WTimer(); + trackProgress->setInterval(1000); + //TODO:track details + playpause = new Wt::WPushButton(); + playpause->setText(groove_playlist_playing(GroovePlayerMgr::getInstance()->currentPlaylist)==1?"Pause":"Resume"); + isPaused = groove_playlist_playing(GroovePlayerMgr::getInstance()->currentPlaylist)==0; + playpause->clicked().connect(this, &PlayerInterface::playpauseClicked); + + interfaceLayout->addWidget(playControlContainer); + interfaceLayout->addWidget(currentTrackProgress); + interfaceLayout->addWidget(voteControlContainer); + //TODO:add track details + playControlLayout->addWidget(playpause); +} + +void PlayerInterface::playpauseClicked() +{ + if(!isPaused) + { + GroovePlayerMgr::getInstance()->lastInternalEvents.push_back(GroovePlayerMgr::PlayerEvent() = {GroovePlayerMgr::PlayerEventType::PLAYING_PAUSED, app->currentUser}); + } + else + { + GroovePlayerMgr::getInstance()->lastInternalEvents.push_back(GroovePlayerMgr::PlayerEvent() = {GroovePlayerMgr::PlayerEventType::PLAYING_RESUMED, app->currentUser}); + } +} + +void PlayerInterface::playpauseUpdated() +{ + if(isPaused) + { + playpause->setText("Resume"); + } + else + { + playpause->setText("Pause"); + } } diff --git a/src/ui/PlayerInterface.h b/src/ui/PlayerInterface.h index e8df3f4..1c57315 100644 --- a/src/ui/PlayerInterface.h +++ b/src/ui/PlayerInterface.h @@ -21,15 +21,44 @@ #define PLAYERINTERFACE_H #include +#include +#include #include "../WebInterface.h" +#include #include +#include +#include +#include "TrackDetails.h" class PlayerInterface : public Wt::WContainerWidget { public: PlayerInterface(WebInterface* app); WebInterface* app; - Wt::WText* tempText; + + Wt::WVBoxLayout* interfaceLayout; + Wt::WContainerWidget* playControlContainer; + Wt::WHBoxLayout* playControlLayout; + Wt::WVBoxLayout* voteControlLayout; + Wt::WContainerWidget* voteControlContainer; + + //Play controls + TrackDetails* currentTrackDetails; + Wt::WProgressBar* currentTrackProgress; + Wt::WTimer* trackProgress; + Wt::WHBoxLayout* currentTrackLayout; + Wt::WContainerWidget* currentTrackContainer; + Wt::WPushButton* playpause; + + bool isPaused = false; + //TODO:put in controls for requesting/admin skip and adding users as admin. + + //Vote controls + //TODO:put in vote controls for seeing tracks to vote on and vote buttons. + //TODO:put in controls for requesting songs. + + void playpauseClicked(); + void playpauseUpdated(); }; #endif // PLAYERINTERFACE_H diff --git a/src/ui/TrackDetails.cpp b/src/ui/TrackDetails.cpp new file mode 100644 index 0000000..9656257 --- /dev/null +++ b/src/ui/TrackDetails.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2017 Kevin Whitaker + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "TrackDetails.h" diff --git a/src/ui/TrackDetails.h b/src/ui/TrackDetails.h new file mode 100644 index 0000000..b01f73e --- /dev/null +++ b/src/ui/TrackDetails.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2017 Kevin Whitaker + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef TRACKDETAILS_H +#define TRACKDETAILS_H + +#include + +class TrackDetails : Wt::WContainerWidget +{ +}; + +#endif // TRACKDETAILS_H -- GitLab