From 298f6fb885f6fcb367bf30e5e0d3c064d982f7d0 Mon Sep 17 00:00:00 2001 From: emeric Date: Sat, 12 Apr 2014 21:28:20 +0200 Subject: [PATCH] Created UserInterface namespace, WebServerService -> UserInterfaceService. --- Makefile.am | 18 +++--- configure.ac | 8 +-- include/.empty | 0 main/RemoteServerService.cpp | 4 +- main/RemoteServerService.hpp | 3 +- main/ServiceManager.cpp | 13 +++-- main/ServiceManager.hpp | 2 +- main/UserInterfaceService.cpp | 38 +++++++++++++ ...erService.hpp => UserInterfaceService.hpp} | 6 +- main/WebServerService.cpp | 57 ------------------- main/main.cpp | 42 ++++---------- remote/server/Connection.cpp | 1 - remote/server/Connection.hpp | 2 - remote/server/ConnectionManager.cpp | 2 - remote/server/ConnectionManager.hpp | 2 - remote/server/RequestHandler.cpp | 17 ++++++ remote/server/RequestHandler.hpp | 14 ++++- remote/server/Server.cpp | 7 +-- remote/server/Server.hpp | 5 +- ui/LmsApplication.cpp | 23 ++++++-- ui/LmsApplication.hpp | 11 +++- ui/audio/AudioDatabaseWidget.cpp | 14 +++-- ui/audio/AudioDatabaseWidget.hpp | 9 +-- ui/audio/AudioMediaPlayerWidget.cpp | 3 + ui/audio/AudioMediaPlayerWidget.hpp | 4 +- ui/audio/AudioWidget.cpp | 7 ++- ui/audio/AudioWidget.hpp | 8 ++- ui/audio/FilterWidget.hpp | 6 +- ui/audio/SearchFilterWidget.cpp | 2 + ui/audio/SearchFilterWidget.hpp | 6 +- ui/audio/TableFilterWidget.cpp | 4 ++ ui/audio/TableFilterWidget.hpp | 4 +- ui/audio/TrackWidget.cpp | 4 ++ ui/audio/TrackWidget.hpp | 3 + ui/common/SessionData.cpp | 11 ++++ ui/common/SessionData.hpp | 35 ++++++++++++ ui/resource/AvConvTranscodeStreamResource.cpp | 4 +- ui/resource/AvConvTranscodeStreamResource.hpp | 8 +-- ui/video/VideoDatabaseWidget.cpp | 7 ++- ui/video/VideoDatabaseWidget.hpp | 11 ++-- ui/video/VideoMediaPlayerWidget.cpp | 3 + ui/video/VideoMediaPlayerWidget.hpp | 3 + ui/video/VideoParametersDialog.cpp | 3 + ui/video/VideoParametersDialog.hpp | 4 ++ ui/video/VideoWidget.cpp | 10 +++- ui/video/VideoWidget.hpp | 10 +++- 46 files changed, 291 insertions(+), 167 deletions(-) create mode 100644 include/.empty create mode 100644 main/UserInterfaceService.cpp rename main/{WebServerService.hpp => UserInterfaceService.hpp} (59%) delete mode 100644 main/WebServerService.cpp create mode 100644 remote/server/RequestHandler.cpp create mode 100644 ui/common/SessionData.cpp create mode 100644 ui/common/SessionData.hpp diff --git a/Makefile.am b/Makefile.am index a37cae1d..0df16502 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,11 +5,13 @@ SUBDIRS = test . bin_PROGRAMS = lms +lms2_CXXFLAGS=-std=c++11 -Wall -I$(top_srcdir)/boost/ -I$(top_srcdir)/ui -I$(top_srcdir)/remote + lms_SOURCES = \ - $(top_srcdir)/main/main.cpp \ - $(top_srcdir)/main/ServiceManager.cpp \ + $(top_srcdir)/main/main.cpp \ + $(top_srcdir)/main/ServiceManager.cpp \ $(top_srcdir)/main/DatabaseRefreshService.cpp \ - $(top_srcdir)/main/WebServerService.cpp \ + $(top_srcdir)/main/UserInterfaceService.cpp \ $(top_srcdir)/av/CodecContext.cpp \ $(top_srcdir)/av/Common.cpp \ $(top_srcdir)/av/Dictionary.cpp \ @@ -23,6 +25,7 @@ lms_SOURCES = \ $(top_srcdir)/ui/audio/SearchFilterWidget.cpp \ $(top_srcdir)/ui/audio/TableFilterWidget.cpp \ $(top_srcdir)/ui/audio/TrackWidget.cpp \ + $(top_srcdir)/ui/common/SessionData.cpp \ $(top_srcdir)/ui/resource/AvConvTranscodeStreamResource.cpp \ $(top_srcdir)/ui/video/VideoWidget.cpp \ $(top_srcdir)/ui/video/VideoDatabaseWidget.cpp \ @@ -43,12 +46,13 @@ lms_SOURCES = \ $(top_srcdir)/transcode/Parameters.cpp \ $(top_srcdir)/transcode/InputMediaFile.cpp \ $(top_srcdir)/metadata/AvFormat.cpp \ + $(top_srcdir)/main/RemoteServerService.cpp \ + $(top_srcdir)/remote/server/Connection.cpp \ + $(top_srcdir)/remote/server/ConnectionManager.cpp \ + $(top_srcdir)/remote/server/RequestHandler.cpp \ + $(top_srcdir)/remote/server/Server.cpp \ $(top_srcdir)/metadata/Utils.cpp -#$(top_srcdir)/main/RemoteServerService.cpp -#$(top_srcdir)/remote/server/Connection.cpp -#$(top_srcdir)/remote/server/ConnectionManager.cpp -#$(top_srcdir)/remote/server/Server.cpp lms_CXXFLAGS=-std=c++11 -Wall -I$(top_srcdir)/boost/ -I$(top_srcdir)/ui -I$(top_srcdir)/remote diff --git a/configure.ac b/configure.ac index 63584bcf..7f12eab3 100644 --- a/configure.ac +++ b/configure.ac @@ -12,10 +12,10 @@ AC_CHECK_HEADERS([Wt/WApplication], [], [AC_MSG_ERROR([Header not found or unusable !])]) -#AC_CHECK_LIB([pthread], -# [pthread_create], -# , -# [AC_MSG_ERROR([libpthread not found!])]) +AC_CHECK_LIB([pthread], + [pthread_create], + , + [AC_MSG_ERROR([libpthread not found!])]) AC_CHECK_LIB([avutil], [av_free], diff --git a/include/.empty b/include/.empty new file mode 100644 index 00000000..e69de29b diff --git a/main/RemoteServerService.cpp b/main/RemoteServerService.cpp index 1c09f0d1..7298aa2b 100644 --- a/main/RemoteServerService.cpp +++ b/main/RemoteServerService.cpp @@ -1,8 +1,8 @@ #include "RemoteServerService.hpp" -RemoteServerService::RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint) -: _server(endpoint) +RemoteServerService::RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath) +: _server(endpoint, dbPath) { } diff --git a/main/RemoteServerService.hpp b/main/RemoteServerService.hpp index 6c4db5b2..60d78b57 100644 --- a/main/RemoteServerService.hpp +++ b/main/RemoteServerService.hpp @@ -1,6 +1,7 @@ #ifndef REMOTE_SERVER_SERVICE_HPP #define REMOTE_SERVER_SERVICE_HPP +#include #include "Service.hpp" @@ -10,7 +11,7 @@ class RemoteServerService : public Service { public: - RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint); + RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath); void start(void); void stop(void); diff --git a/main/ServiceManager.cpp b/main/ServiceManager.cpp index a1a40d75..b18bfd79 100644 --- a/main/ServiceManager.cpp +++ b/main/ServiceManager.cpp @@ -1,5 +1,5 @@ -#include +//#include #include #include @@ -7,15 +7,15 @@ #include "ServiceManager.hpp" ServiceManager::ServiceManager() -/*: _signalSet(_ioService) */ +: _signalSet(_ioService) { -/* _signalSet.add(SIGINT); + _signalSet.add(SIGINT); _signalSet.add(SIGTERM); #if defined(SIGQUIT) _signalSet.add(SIGQUIT); #endif // defined(SIGQUIT) - _signalSet.add(SIGHUP);*/ + _signalSet.add(SIGHUP); } void @@ -27,15 +27,16 @@ ServiceManager::run() // Wait for events _ioService.run(); + std::cout << "ServiceManager::run complete!" << std::endl; } void ServiceManager::asyncWaitSignals(void) { -/* _signalSet.async_wait(boost::bind(&ServiceManager::handleSignal, + _signalSet.async_wait(boost::bind(&ServiceManager::handleSignal, this, boost::asio::placeholders::error, - boost::asio::placeholders::signal_number));*/ + boost::asio::placeholders::signal_number)); } void diff --git a/main/ServiceManager.hpp b/main/ServiceManager.hpp index a007ccef..7e1ee48b 100644 --- a/main/ServiceManager.hpp +++ b/main/ServiceManager.hpp @@ -31,7 +31,7 @@ class ServiceManager boost::asio::io_service _ioService; // Listen for interesting signals -// boost::asio::signal_set _signalSet; + boost::asio::signal_set _signalSet; std::set _services; }; diff --git a/main/UserInterfaceService.cpp b/main/UserInterfaceService.cpp new file mode 100644 index 00000000..66986725 --- /dev/null +++ b/main/UserInterfaceService.cpp @@ -0,0 +1,38 @@ +#include +#include + +#include "UserInterfaceService.hpp" +#include "ui/LmsApplication.hpp" + +UserInterfaceService::UserInterfaceService( int argc, char* argv[], boost::filesystem::path dbPath) +: _server(argv[0], "") +{ + // TODO configure server using another way (config file?) + _server.setServerConfiguration (argc, argv, WTHTTP_CONFIGURATION); + + // bind entry point + _server.addEntryPoint(Wt::Application, boost::bind(UserInterface::LmsApplication::create, _1, dbPath)); +} + +void +UserInterfaceService::start(void) +{ + _server.start(); + std::cout << "UserInterfaceService::start -> Service started..." << std::endl; +} + +void +UserInterfaceService::stop(void) +{ + std::cout << "UserInterfaceService::stop -> stopping..." << std::endl; + _server.stop(); + std::cout << "UserInterfaceService::stop -> stopped!" << std::endl; +} + +void +UserInterfaceService::restart(void) +{ + +} + + diff --git a/main/WebServerService.hpp b/main/UserInterfaceService.hpp similarity index 59% rename from main/WebServerService.hpp rename to main/UserInterfaceService.hpp index 172efee3..c9b78d6b 100644 --- a/main/WebServerService.hpp +++ b/main/UserInterfaceService.hpp @@ -1,14 +1,16 @@ #ifndef WEB_SERVER_SERVICE_HPP #define WEB_SERVER_SERVICE_HPP +#include + #include #include "Service.hpp" -class WebServerService : public Service +class UserInterfaceService : public Service { public: - WebServerService( int argc, char* argv[]); + UserInterfaceService( int argc, char* argv[], boost::filesystem::path dbPath); void start(void); void stop(void); diff --git a/main/WebServerService.cpp b/main/WebServerService.cpp deleted file mode 100644 index 68d58b40..00000000 --- a/main/WebServerService.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -#include "WebServerService.hpp" -#include "ui/LmsApplication.hpp" - - -static Wt::WApplication *createApplication(const Wt::WEnvironment& env) -{ - /* - * You could read information from the environment to decide whether - * the user has permission to start a new application - */ - std::cout << "Creating new Application" << std::endl; - return new LmsApplication(env); -} - -WebServerService::WebServerService( int argc, char* argv[]) -: _server(argv[0], "") -{ - - std::cout << "Constructing server... argv[0] = '" << argv[0] << "' argc = " << argc << std::endl; - - // TODO configure server - _server.setServerConfiguration (argc, argv, WTHTTP_CONFIGURATION); - - // bind entry point - - _server.addEntryPoint(Wt::Application, createApplication); - - std::cout << "WebServerService done!" << std::endl; -} - -void -WebServerService::start(void) -{ - std::cout << "Starting service..." << std::endl; - - bool res = _server.start(); - std::cout << "_server.start returned " << std::boolalpha << res << std::endl; - - std::cout << "Service started..." << std::endl; -} - -void -WebServerService::stop(void) -{ - _server.stop(); -} - -void -WebServerService::restart(void) -{ - -} - - diff --git a/main/main.cpp b/main/main.cpp index 6df4d802..ac45aa34 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,26 +1,18 @@ #include #include +#include +#include #include "transcode/AvConvTranscoder.hpp" #include "av/Common.hpp" #include "ServiceManager.hpp" #include "DatabaseRefreshService.hpp" -#include "WebServerService.hpp" +#include "UserInterfaceService.hpp" #include "RemoteServerService.hpp" #include "ui/LmsApplication.hpp" -static Wt::WApplication *createApplication(const Wt::WEnvironment& env) -{ - /* - * You could read information from the environment to decide whether - * the user has permission to start a new application - */ - std::cout << "Creating new Application" << std::endl; - return new LmsApplication(env); -} - int main(int argc, char* argv[]) { @@ -28,32 +20,20 @@ int main(int argc, char* argv[]) try { -// ServiceManager serviceManager; + ServiceManager serviceManager; + + // TODO Retreive the database path in some config file + const boost::filesystem::path dbPath("test.db"); // lib init Av::AvInit(); Transcode::AvConvTranscoder::init(); - return Wt::WRun(argc, argv, createApplication); -/* Wt::WServer server(argv[0], ""); + serviceManager.startService( std::make_shared( dbPath) ); + serviceManager.startService( std::make_shared(argc, argv, dbPath) ); + serviceManager.startService( std::make_shared( Remote::Server::Server::endpoint_type(), dbPath) ); - server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION); - server.addEntryPoint(Wt::Application, createApplication); - if (server.start()) { - int sig = Wt::WServer::waitForShutdown(argv[0]); - std::cerr << "Shutdown (signal = " << sig << ")" << std::endl; - server.stop(); - if (sig == SIGHUP) - Wt::WServer::restart(argc, argv, environ); - }*/ -// return 0; - - -// serviceManager.startService( std::make_shared( "test.db" ) ); -// serviceManager.startService( std::make_shared(argc, argv) ); -// serviceManager.startService( std::make_shared( Remote::Server::Server::endpoint_type() ) ); - -// serviceManager.run(); + serviceManager.run(); res = EXIT_SUCCESS; diff --git a/remote/server/Connection.cpp b/remote/server/Connection.cpp index c817c3d8..0d0bac67 100644 --- a/remote/server/Connection.cpp +++ b/remote/server/Connection.cpp @@ -78,5 +78,4 @@ void Connection::handleWrite(const boost::system::error_code& error) } } // namespace Server - } // namespace Remote diff --git a/remote/server/Connection.hpp b/remote/server/Connection.hpp index 552633dd..0c99ab10 100644 --- a/remote/server/Connection.hpp +++ b/remote/server/Connection.hpp @@ -11,7 +11,6 @@ #include "messages/Header.hpp" namespace Remote { - namespace Server { class ConnectionManager; @@ -71,7 +70,6 @@ class Connection : public std::enable_shared_from_this } // namespace Server - } // namespace Remote #endif diff --git a/remote/server/ConnectionManager.cpp b/remote/server/ConnectionManager.cpp index fd1b599f..77b3773f 100644 --- a/remote/server/ConnectionManager.cpp +++ b/remote/server/ConnectionManager.cpp @@ -5,7 +5,6 @@ #include "ConnectionManager.hpp" namespace Remote { - namespace Server { ConnectionManager::ConnectionManager() @@ -39,7 +38,6 @@ ConnectionManager::stopAll() } // namespace Server - } // namespace Remote diff --git a/remote/server/ConnectionManager.hpp b/remote/server/ConnectionManager.hpp index 9579aa01..d85b7405 100644 --- a/remote/server/ConnectionManager.hpp +++ b/remote/server/ConnectionManager.hpp @@ -6,7 +6,6 @@ #include "Connection.hpp" namespace Remote { - namespace Server { /// Manages open connections so that they may be cleanly stopped when the server @@ -35,7 +34,6 @@ class ConnectionManager }; } // namespace Server - } // namespace Remote #endif diff --git a/remote/server/RequestHandler.cpp b/remote/server/RequestHandler.cpp new file mode 100644 index 00000000..16583e26 --- /dev/null +++ b/remote/server/RequestHandler.cpp @@ -0,0 +1,17 @@ + +#include "RequestHandler.hpp" + +namespace Remote { +namespace Server { + +RequestHandler::RequestHandler(boost::filesystem::path dbPath) +: _db( dbPath ) +{ +} + + +} // namespace Server +} // namespace Remote + + + diff --git a/remote/server/RequestHandler.hpp b/remote/server/RequestHandler.hpp index f111f325..0a38f848 100644 --- a/remote/server/RequestHandler.hpp +++ b/remote/server/RequestHandler.hpp @@ -1,18 +1,30 @@ #ifndef REMOTE_REQUEST_HANDLER #define REMOTE_REQUEST_HANDLER +#include + +#include "database/DatabaseHandler.hpp" + // #include "remote/messages/ +namespace Remote { +namespace Server { + class RequestHandler { public: - + RequestHandler(boost::filesystem::path dbPath); private: + DatabaseHandler _db; + }; +} // namespace Server +} // namespace Remote + #endif diff --git a/remote/server/Server.cpp b/remote/server/Server.cpp index 6920988c..6cb1fbe0 100644 --- a/remote/server/Server.cpp +++ b/remote/server/Server.cpp @@ -6,14 +6,14 @@ #include "Server.hpp" namespace Remote { - namespace Server { -Server::Server(const endpoint_type& endpoint) +Server::Server(const endpoint_type& endpoint, boost::filesystem::path dbPath) : _acceptor(_ioService), _connectionManager(), -_socket(_ioService) +_socket(_ioService), +_requestHandler(dbPath) { // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR). boost::asio::ip::tcp::resolver resolver(_ioService); @@ -72,5 +72,4 @@ Server::stop() } } // namespace Server - } // namespace Remote diff --git a/remote/server/Server.hpp b/remote/server/Server.hpp index 9cd76605..590b779b 100644 --- a/remote/server/Server.hpp +++ b/remote/server/Server.hpp @@ -2,6 +2,7 @@ #define REMOTE_SERVER_HPP #include +#include #include "Connection.hpp" #include "ConnectionManager.hpp" @@ -9,7 +10,6 @@ #include "RequestHandler.hpp" namespace Remote { - namespace Server { class Server @@ -22,7 +22,7 @@ class Server typedef boost::asio::ip::tcp::endpoint endpoint_type; // Serve up data from the given database - Server(const endpoint_type& endpoint); + Server(const endpoint_type& endpoint, boost::filesystem::path dbPath); // Run the server's io_service loop. void run(); @@ -50,7 +50,6 @@ class Server }; } // namespace Server - } // namespace Remote #endif diff --git a/ui/LmsApplication.cpp b/ui/LmsApplication.cpp index 2f4d82f9..1312e9de 100644 --- a/ui/LmsApplication.cpp +++ b/ui/LmsApplication.cpp @@ -11,6 +11,18 @@ #include "LmsApplication.hpp" +namespace UserInterface { + +Wt::WApplication* +LmsApplication::create(const Wt::WEnvironment& env, boost::filesystem::path dbPath) +{ + /* + * You could read information from the environment to decide whether + * the user has permission to start a new application + */ + std::cout << "Creating new Application" << std::endl; + return new LmsApplication(env, dbPath); +} /* * The env argument contains information about the new session, and @@ -18,8 +30,9 @@ * constructor so it is typically also an argument for your custom * application constructor. */ -LmsApplication::LmsApplication(const Wt::WEnvironment& env) -: Wt::WApplication(env) +LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::path dbPath) +: Wt::WApplication(env), + _sessionData(dbPath) { setTheme(new Wt::WBootstrapTheme()); @@ -40,8 +53,8 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env) Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack, container); navigation->addMenu(leftMenu); - _audioWidget = new AudioWidget(); - _videoWidget = new VideoWidget(); + _audioWidget = new AudioWidget(_sessionData); + _videoWidget = new VideoWidget(_sessionData); leftMenu->addItem("Audio", _audioWidget); leftMenu->addItem("Video", _videoWidget); @@ -79,3 +92,5 @@ LmsApplication::handleSearch(void) _audioWidget->search( _searchEdit->text().toUTF8() ); } +} // namespace DatabaseHandler + diff --git a/ui/LmsApplication.hpp b/ui/LmsApplication.hpp index f369d66d..33f0ca0e 100644 --- a/ui/LmsApplication.hpp +++ b/ui/LmsApplication.hpp @@ -5,19 +5,28 @@ #include "audio/AudioWidget.hpp" #include "video/VideoWidget.hpp" +namespace UserInterface { + + class LmsApplication : public Wt::WApplication { public: - LmsApplication(const Wt::WEnvironment& env); + static Wt::WApplication *create(const Wt::WEnvironment& env, boost::filesystem::path dbPath); + + LmsApplication(const Wt::WEnvironment& env, boost::filesystem::path dbPath); private: void handleSearch(); + SessionData _sessionData; + Wt::WLineEdit* _searchEdit; AudioWidget* _audioWidget; VideoWidget* _videoWidget; }; + +} // namespace UserInterface diff --git a/ui/audio/AudioDatabaseWidget.cpp b/ui/audio/AudioDatabaseWidget.cpp index 215afed1..2ab6bc7c 100644 --- a/ui/audio/AudioDatabaseWidget.cpp +++ b/ui/audio/AudioDatabaseWidget.cpp @@ -9,9 +9,10 @@ #include "SearchFilterWidget.hpp" #include "TrackWidget.hpp" -AudioDatabaseWidget::AudioDatabaseWidget( Wt::WContainerWidget *parent) +namespace UserInterface { + +AudioDatabaseWidget::AudioDatabaseWidget( DatabaseHandler& db, Wt::WContainerWidget *parent) : Wt::WContainerWidget(parent), - _db("test.db"), // TODO _refreshingFilters(false) { std::size_t idFilter (0); @@ -22,23 +23,23 @@ _refreshingFilters(false) } { - TableFilterWidget* filterTable = new TableFilterWidget(_db, "genre", "name", this); + TableFilterWidget* filterTable = new TableFilterWidget(db, "genre", "name", this); _filters.push_back( filterTable ); filterTable->update().connect( boost::bind(&AudioDatabaseWidget::handleFilterUpdated, this, idFilter++) ); } { - TableFilterWidget* filterTable = new TableFilterWidget(_db, "artist", "name", this); + TableFilterWidget* filterTable = new TableFilterWidget(db, "artist", "name", this); _filters.push_back( filterTable ); filterTable->update().connect( boost::bind(&AudioDatabaseWidget::handleFilterUpdated, this, idFilter++) ); } { - TableFilterWidget* filterTable = new TableFilterWidget(_db, "release", "name", this); + TableFilterWidget* filterTable = new TableFilterWidget(db, "release", "name", this); _filters.push_back( filterTable ); filterTable->update().connect( boost::bind(&AudioDatabaseWidget::handleFilterUpdated, this, idFilter++) ); } { - TrackWidget* track = new TrackWidget(_db, this); + TrackWidget* track = new TrackWidget(db, this); _filters.push_back( track ); track->trackSelected().connect(this, &AudioDatabaseWidget::handleTrackSelected); } @@ -104,5 +105,6 @@ AudioDatabaseWidget::selectNextTrack(void) trackWidget->selectNextTrack(); } +} // namespace UserInterface diff --git a/ui/audio/AudioDatabaseWidget.hpp b/ui/audio/AudioDatabaseWidget.hpp index 12a5ba83..06d950a7 100644 --- a/ui/audio/AudioDatabaseWidget.hpp +++ b/ui/audio/AudioDatabaseWidget.hpp @@ -6,14 +6,16 @@ #include #include -#include "database/DatabaseHandler.hpp" +#include "common/SessionData.hpp" #include "FilterWidget.hpp" +namespace UserInterface { + class AudioDatabaseWidget : public Wt::WContainerWidget { public: - AudioDatabaseWidget( Wt::WContainerWidget *parent = 0); + AudioDatabaseWidget( DatabaseHandler& db, Wt::WContainerWidget *parent = 0); void search(const std::string& text); @@ -24,8 +26,6 @@ class AudioDatabaseWidget : public Wt::WContainerWidget private: - DatabaseHandler _db; - Wt::Signal< boost::filesystem::path > _trackSelected; void handleTrackSelected(boost::filesystem::path p); @@ -37,6 +37,7 @@ class AudioDatabaseWidget : public Wt::WContainerWidget }; +} // namespace UserInterface #endif diff --git a/ui/audio/AudioMediaPlayerWidget.cpp b/ui/audio/AudioMediaPlayerWidget.cpp index d08cd3ed..cd31ddfa 100644 --- a/ui/audio/AudioMediaPlayerWidget.cpp +++ b/ui/audio/AudioMediaPlayerWidget.cpp @@ -4,6 +4,7 @@ #include "AudioMediaPlayerWidget.hpp" +namespace UserInterface { AudioMediaPlayerWidget::AudioMediaPlayerWidget( Wt::WContainerWidget *parent) : Wt::WContainerWidget(parent), @@ -155,3 +156,5 @@ AudioMediaPlayerWidget::handleVolumeSliderMoved(int value) { _mediaPlayer->setVolume( value / 100. ); } + +} // namespace UserInterface diff --git a/ui/audio/AudioMediaPlayerWidget.hpp b/ui/audio/AudioMediaPlayerWidget.hpp index 9565cfd9..2f1c5311 100644 --- a/ui/audio/AudioMediaPlayerWidget.hpp +++ b/ui/audio/AudioMediaPlayerWidget.hpp @@ -10,10 +10,11 @@ #include #include - #include "transcode/Parameters.hpp" #include "resource/AvConvTranscodeStreamResource.hpp" +namespace UserInterface { + class AudioMediaPlayerWidget : public Wt::WContainerWidget { public: @@ -63,6 +64,7 @@ class AudioMediaPlayerWidget : public Wt::WContainerWidget }; +} // namespace UserInterface #endif diff --git a/ui/audio/AudioWidget.cpp b/ui/audio/AudioWidget.cpp index de87a98c..e50e18e5 100644 --- a/ui/audio/AudioWidget.cpp +++ b/ui/audio/AudioWidget.cpp @@ -4,15 +4,17 @@ #include "metadata/Extractor.hpp" +namespace UserInterface { -AudioWidget::AudioWidget(Wt::WContainerWidget* parent) +AudioWidget::AudioWidget(SessionData& sessionData, Wt::WContainerWidget* parent) : Wt::WContainerWidget(parent), +_sessionData(sessionData), _audioDbWidget(nullptr), _mediaPlayer(nullptr), _imgResource(nullptr), _img(nullptr) { - _audioDbWidget = new AudioDatabaseWidget(this); + _audioDbWidget = new AudioDatabaseWidget(sessionData.getDatabaseHandler(), this); _audioDbWidget->trackSelected().connect(this, &AudioWidget::playTrack); @@ -78,4 +80,5 @@ AudioWidget::handleTrackEnded(void) _audioDbWidget->selectNextTrack(); } +} // namespace UserInterface diff --git a/ui/audio/AudioWidget.hpp b/ui/audio/AudioWidget.hpp index bf076175..6131f69c 100644 --- a/ui/audio/AudioWidget.hpp +++ b/ui/audio/AudioWidget.hpp @@ -11,12 +11,14 @@ #include "audio/AudioMediaPlayerWidget.hpp" #include "audio/AudioDatabaseWidget.hpp" +namespace UserInterface { + class AudioWidget : public Wt::WContainerWidget { public: - AudioWidget(Wt::WContainerWidget* parent = 0); + AudioWidget(SessionData& sessionData, Wt::WContainerWidget* parent = 0); void search(const std::string& searchText); @@ -26,6 +28,8 @@ class AudioWidget : public Wt::WContainerWidget void handleTrackEnded(void); + SessionData& _sessionData; + AudioDatabaseWidget* _audioDbWidget; AudioMediaPlayerWidget* _mediaPlayer; @@ -39,5 +43,7 @@ class AudioWidget : public Wt::WContainerWidget }; +} // namespace UserInterface + #endif diff --git a/ui/audio/FilterWidget.hpp b/ui/audio/FilterWidget.hpp index 7c6f281c..916a83d9 100644 --- a/ui/audio/FilterWidget.hpp +++ b/ui/audio/FilterWidget.hpp @@ -10,6 +10,8 @@ #include "database/SqlQuery.hpp" +namespace UserInterface { + class FilterWidget : public Wt::WContainerWidget { public: @@ -39,8 +41,6 @@ class FilterWidget : public Wt::WContainerWidget { Wt::Signal _update; }; - - - +} // namespace UserInterface #endif diff --git a/ui/audio/SearchFilterWidget.cpp b/ui/audio/SearchFilterWidget.cpp index b5c8df84..2cf39d62 100644 --- a/ui/audio/SearchFilterWidget.cpp +++ b/ui/audio/SearchFilterWidget.cpp @@ -2,6 +2,7 @@ #include "SearchFilterWidget.hpp" +namespace UserInterface { SearchFilterWidget::SearchFilterWidget(Wt::WContainerWidget* parent) : FilterWidget( parent ) @@ -30,4 +31,5 @@ SearchFilterWidget::getConstraint(Constraint& constraint) // else no constraint! } +} // namespace UserInterface diff --git a/ui/audio/SearchFilterWidget.hpp b/ui/audio/SearchFilterWidget.hpp index 8918a81b..9125a5bc 100644 --- a/ui/audio/SearchFilterWidget.hpp +++ b/ui/audio/SearchFilterWidget.hpp @@ -5,6 +5,8 @@ #include "FilterWidget.hpp" +namespace UserInterface { + class SearchFilterWidget : public FilterWidget { public: SearchFilterWidget(Wt::WContainerWidget* parent = 0); @@ -24,9 +26,7 @@ class SearchFilterWidget : public FilterWidget { std::string _lastEmittedText; }; - - - +} // namespace UserInterface #endif diff --git a/ui/audio/TableFilterWidget.cpp b/ui/audio/TableFilterWidget.cpp index 50a72229..6177e3a7 100644 --- a/ui/audio/TableFilterWidget.cpp +++ b/ui/audio/TableFilterWidget.cpp @@ -2,6 +2,8 @@ #include "TableFilterWidget.hpp" +namespace UserInterface { + TableFilterWidget::TableFilterWidget(DatabaseHandler& db, std::string table, std::string field, Wt::WContainerWidget* parent) : FilterWidget( parent ), _db(db), @@ -88,3 +90,5 @@ TableFilterWidget::getConstraint(Constraint& constraint) constraint.where.And( clause ); } +} // namespace UserInterface + diff --git a/ui/audio/TableFilterWidget.hpp b/ui/audio/TableFilterWidget.hpp index ae8562ea..912ba553 100644 --- a/ui/audio/TableFilterWidget.hpp +++ b/ui/audio/TableFilterWidget.hpp @@ -8,6 +8,8 @@ #include "FilterWidget.hpp" #include "database/DatabaseHandler.hpp" +namespace UserInterface { + class TableFilterWidget : public FilterWidget { @@ -32,7 +34,7 @@ class TableFilterWidget : public FilterWidget Wt::WTableView* _tableView; }; - +} // namespace UserInterface #endif diff --git a/ui/audio/TrackWidget.cpp b/ui/audio/TrackWidget.cpp index f993682d..05c5b23c 100644 --- a/ui/audio/TrackWidget.cpp +++ b/ui/audio/TrackWidget.cpp @@ -6,6 +6,8 @@ #include "TrackWidget.hpp" +namespace UserInterface { + TrackWidget::TrackWidget( DatabaseHandler& db, Wt::WContainerWidget* parent) : FilterWidget( parent ), _db(db), @@ -132,3 +134,5 @@ TrackWidget::selectNextTrack(void) } } +} // namespace UserInterface + diff --git a/ui/audio/TrackWidget.hpp b/ui/audio/TrackWidget.hpp index 8c881292..3efca431 100644 --- a/ui/audio/TrackWidget.hpp +++ b/ui/audio/TrackWidget.hpp @@ -9,6 +9,7 @@ #include "FilterWidget.hpp" +namespace UserInterface { class TrackWidget : public FilterWidget { @@ -45,5 +46,7 @@ class TrackWidget : public FilterWidget }; +} // namespace UserInterface + #endif diff --git a/ui/common/SessionData.cpp b/ui/common/SessionData.cpp new file mode 100644 index 00000000..d57e4a45 --- /dev/null +++ b/ui/common/SessionData.cpp @@ -0,0 +1,11 @@ +#include "SessionData.hpp" + +namespace UserInterface { + +SessionData::SessionData(boost::filesystem::path dbPath) +: _db(dbPath) +{ +} + +} // namespace UserInterface + diff --git a/ui/common/SessionData.hpp b/ui/common/SessionData.hpp new file mode 100644 index 00000000..3836a415 --- /dev/null +++ b/ui/common/SessionData.hpp @@ -0,0 +1,35 @@ +#ifndef UI_SESSION_DATA_HPP +#define UI_SESSION_DATA_HPP + +#include + +#include + +#include "database/DatabaseHandler.hpp" + +namespace UserInterface { + +class SessionData +{ + public: + + SessionData(boost::filesystem::path dbPath); + + void setAuthenticatedUser(std::string user); + + + DatabaseHandler& getDatabaseHandler() { return _db;} + const DatabaseHandler& getDatabaseHandler() const { return _db;} + + private: + + + DatabaseHandler _db; + std::string _authenticatedUser; + +}; + +} // namespace UserInterface + +#endif + diff --git a/ui/resource/AvConvTranscodeStreamResource.cpp b/ui/resource/AvConvTranscodeStreamResource.cpp index febf6f95..e5d23df0 100644 --- a/ui/resource/AvConvTranscodeStreamResource.cpp +++ b/ui/resource/AvConvTranscodeStreamResource.cpp @@ -3,6 +3,8 @@ #include #include "AvConvTranscodeStreamResource.hpp" +namespace UserInterface { + AvConvTranscodeStreamResource::AvConvTranscodeStreamResource(const Transcode::Parameters& parameters, Wt::WObject *parent) : Wt::WResource(parent), _parameters( parameters ) @@ -71,6 +73,6 @@ AvConvTranscodeStreamResource::handleRequest(const Wt::Http::Request& request, std::cout << "No more data!" << std::endl; } - +} // namespace UserInterface diff --git a/ui/resource/AvConvTranscodeStreamResource.hpp b/ui/resource/AvConvTranscodeStreamResource.hpp index 24cc0c89..5c342712 100644 --- a/ui/resource/AvConvTranscodeStreamResource.hpp +++ b/ui/resource/AvConvTranscodeStreamResource.hpp @@ -1,15 +1,15 @@ #ifndef AVCONV_TRANSCODE_STREAM_RESOURCE_HPP #define AVCONV_TRANSCODE_STREAM_RESOURCE_HPP -#include #include #include -#include - #include #include "transcode/AvConvTranscoder.hpp" +#include "transcode/Parameters.hpp" + +namespace UserInterface { class AvConvTranscodeStreamResource : public Wt::WResource { @@ -28,7 +28,7 @@ class AvConvTranscodeStreamResource : public Wt::WResource static const std::size_t _bufferSize = 8192*16; }; - +} // namespace UserInterface #endif diff --git a/ui/video/VideoDatabaseWidget.cpp b/ui/video/VideoDatabaseWidget.cpp index 86c4414d..aa06771a 100644 --- a/ui/video/VideoDatabaseWidget.cpp +++ b/ui/video/VideoDatabaseWidget.cpp @@ -11,10 +11,11 @@ #include "VideoDatabaseWidget.hpp" +namespace UserInterface { -VideoDatabaseWidget::VideoDatabaseWidget( Wt::WContainerWidget *parent) +VideoDatabaseWidget::VideoDatabaseWidget(DatabaseHandler& db, Wt::WContainerWidget *parent) : Wt::WContainerWidget(parent), - _db("test.db") // TODO + _db(db) { _table = new Wt::WTable( this ); _table->setHeaderCount(1); @@ -137,3 +138,5 @@ VideoDatabaseWidget::handlePlayVideo(const boost::filesystem::path& videoFilePat } +} // namespace UserInterface + diff --git a/ui/video/VideoDatabaseWidget.hpp b/ui/video/VideoDatabaseWidget.hpp index 80fb8ed6..f4d42441 100644 --- a/ui/video/VideoDatabaseWidget.hpp +++ b/ui/video/VideoDatabaseWidget.hpp @@ -4,13 +4,15 @@ #include #include -#include "database/DatabaseHandler.hpp" +#include "common/SessionData.hpp" #include "database/FileTypes.hpp" +namespace UserInterface { + class VideoDatabaseWidget : public Wt::WContainerWidget { public: - VideoDatabaseWidget( Wt::WContainerWidget *parent = 0); + VideoDatabaseWidget( DatabaseHandler& db, Wt::WContainerWidget *parent = 0); // Signals Wt::Signal< boost::filesystem::path >& playVideo() { return _playVideo; } @@ -26,13 +28,14 @@ class VideoDatabaseWidget : public Wt::WContainerWidget void addDirectory(const std::string& name, const boost::filesystem::path& path); void addVideo(const std::string& name, const boost::posix_time::time_duration& duration, const boost::filesystem::path& path); - Wt::Signal< boost::filesystem::path > _playVideo; + DatabaseHandler& _db; - DatabaseHandler _db; + Wt::Signal< boost::filesystem::path > _playVideo; Wt::WTable* _table; }; +} // namespace UserInterface #endif diff --git a/ui/video/VideoMediaPlayerWidget.cpp b/ui/video/VideoMediaPlayerWidget.cpp index 63c5f2f0..9ebfa0b1 100644 --- a/ui/video/VideoMediaPlayerWidget.cpp +++ b/ui/video/VideoMediaPlayerWidget.cpp @@ -7,6 +7,7 @@ #include "VideoMediaPlayerWidget.hpp" +namespace UserInterface { Wt::WMediaPlayer::Encoding convert(Transcode::Format format) @@ -178,3 +179,5 @@ VideoMediaPlayerWidget::handleParametersDone(Wt::WDialog::DialogCode code) } } + +} // namespace UserInterface diff --git a/ui/video/VideoMediaPlayerWidget.hpp b/ui/video/VideoMediaPlayerWidget.hpp index a067b967..cbd00c00 100644 --- a/ui/video/VideoMediaPlayerWidget.hpp +++ b/ui/video/VideoMediaPlayerWidget.hpp @@ -12,6 +12,8 @@ #include "transcode/Parameters.hpp" #include "resource/AvConvTranscodeStreamResource.hpp" +namespace UserInterface { + class VideoMediaPlayerWidget : public Wt::WContainerWidget { public: @@ -58,6 +60,7 @@ class VideoMediaPlayerWidget : public Wt::WContainerWidget VideoParametersDialog* _dialog; }; +} // namespace UserInterface #endif diff --git a/ui/video/VideoParametersDialog.cpp b/ui/video/VideoParametersDialog.cpp index 6591c8ae..0ec361da 100644 --- a/ui/video/VideoParametersDialog.cpp +++ b/ui/video/VideoParametersDialog.cpp @@ -8,6 +8,8 @@ using namespace Transcode; +namespace UserInterface { + static const std::list streamTypes = {Stream::Video, Stream::Audio, Stream::Subtitle}; VideoParametersDialog::VideoParametersDialog(const Wt::WString &windowTitle, Wt::WDialog* parent) @@ -165,4 +167,5 @@ VideoParametersDialog::save(Transcode::Parameters& parameters) } } +} // namespace UserInterface diff --git a/ui/video/VideoParametersDialog.hpp b/ui/video/VideoParametersDialog.hpp index 1344206a..93920ac2 100644 --- a/ui/video/VideoParametersDialog.hpp +++ b/ui/video/VideoParametersDialog.hpp @@ -11,6 +11,8 @@ #include "transcode/Parameters.hpp" +namespace UserInterface { + class VideoParametersDialog : public Wt::WDialog { public: @@ -43,5 +45,7 @@ class VideoParametersDialog : public Wt::WDialog std::map > _streamSelection; }; +} // namespace UserInterface + #endif diff --git a/ui/video/VideoWidget.cpp b/ui/video/VideoWidget.cpp index 9129a1a6..39758cb0 100644 --- a/ui/video/VideoWidget.cpp +++ b/ui/video/VideoWidget.cpp @@ -3,12 +3,14 @@ #include "VideoWidget.hpp" +namespace UserInterface { -VideoWidget::VideoWidget(Wt::WContainerWidget* parent ) -: Wt::WContainerWidget(parent) +VideoWidget::VideoWidget(SessionData& sessionData, Wt::WContainerWidget* parent ) +: Wt::WContainerWidget(parent), +_sessionData(sessionData) { - _videoDbWidget = new VideoDatabaseWidget(this); + _videoDbWidget = new VideoDatabaseWidget(_sessionData.getDatabaseHandler(), this); _videoDbWidget->playVideo().connect(this, &VideoWidget::playVideo); @@ -61,3 +63,5 @@ VideoWidget::playVideo(boost::filesystem::path p) } } +} // namespace UserInterface + diff --git a/ui/video/VideoWidget.hpp b/ui/video/VideoWidget.hpp index 4425079d..25924c57 100644 --- a/ui/video/VideoWidget.hpp +++ b/ui/video/VideoWidget.hpp @@ -5,14 +5,18 @@ #include +#include "common/SessionData.hpp" + #include "video/VideoMediaPlayerWidget.hpp" #include "video/VideoDatabaseWidget.hpp" +namespace UserInterface { + class VideoWidget : public Wt::WContainerWidget { public: - VideoWidget(Wt::WContainerWidget* parent = 0); + VideoWidget(SessionData& sessionData, Wt::WContainerWidget* parent = 0); void search(const std::string& searchText); @@ -21,10 +25,14 @@ class VideoWidget : public Wt::WContainerWidget void backToList(void); void playVideo(boost::filesystem::path p); + SessionData& _sessionData; + VideoDatabaseWidget* _videoDbWidget; VideoMediaPlayerWidget* _mediaPlayer; }; +} // namespace UserInterface + #endif