Initial import from SVN
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,81 @@
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WBreak>
|
||||
#include <Wt/WLabel>
|
||||
#include <Wt/WBootstrapTheme>
|
||||
#include <Wt/WStackedWidget>
|
||||
#include <Wt/WMenu>
|
||||
#include <Wt/WNavigationBar>
|
||||
#include <Wt/WPopupMenu>
|
||||
#include <Wt/WPopupMenuItem>
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
|
||||
/*
|
||||
* The env argument contains information about the new session, and
|
||||
* the initial request. It must be passed to the Wt::WApplication
|
||||
* constructor so it is typically also an argument for your custom
|
||||
* application constructor.
|
||||
*/
|
||||
LmsApplication::LmsApplication(const Wt::WEnvironment& env)
|
||||
: Wt::WApplication(env)
|
||||
{
|
||||
|
||||
setTheme(new Wt::WBootstrapTheme());
|
||||
|
||||
setTitle("LMS"); // application title
|
||||
|
||||
Wt::WContainerWidget* container (new Wt::WContainerWidget(root()));
|
||||
|
||||
// Create a navigation bar with a link to a web page.
|
||||
Wt::WNavigationBar *navigation = new Wt::WNavigationBar(container);
|
||||
navigation->setTitle("LMS");
|
||||
navigation->setResponsive(true);
|
||||
|
||||
Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(container);
|
||||
contentsStack->addStyleClass("contents");
|
||||
|
||||
// Setup a Left-aligned menu.
|
||||
Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack, container);
|
||||
navigation->addMenu(leftMenu);
|
||||
|
||||
_audioWidget = new AudioWidget();
|
||||
_videoWidget = new VideoWidget();
|
||||
|
||||
leftMenu->addItem("Audio", _audioWidget);
|
||||
leftMenu->addItem("Video", _videoWidget);
|
||||
|
||||
// Setup a Right-aligned menu.
|
||||
Wt::WMenu *rightMenu = new Wt::WMenu();
|
||||
navigation->addMenu(rightMenu, Wt::AlignRight);
|
||||
|
||||
Wt::WPopupMenu *popup = new Wt::WPopupMenu();
|
||||
popup->addItem("Parameters");
|
||||
popup->addSeparator();
|
||||
popup->addItem("Logout");
|
||||
|
||||
Wt::WMenuItem *item = new Wt::WMenuItem("User");
|
||||
item->setMenu(popup);
|
||||
rightMenu->addItem(item);
|
||||
|
||||
// Add a Search control.
|
||||
_searchEdit = new Wt::WLineEdit();
|
||||
_searchEdit->setEmptyText("Search...");
|
||||
|
||||
_searchEdit->keyWentUp().connect(this, &LmsApplication::handleSearch);
|
||||
|
||||
navigation->addSearch(_searchEdit, Wt::AlignLeft);
|
||||
|
||||
container->addWidget(contentsStack);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LmsApplication::handleSearch(void)
|
||||
{
|
||||
// Check currently selected menu item and search it
|
||||
_audioWidget->search( _searchEdit->text().toUTF8() );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WLineEdit>
|
||||
|
||||
#include "audio/AudioWidget.hpp"
|
||||
#include "video/VideoWidget.hpp"
|
||||
|
||||
class LmsApplication : public Wt::WApplication
|
||||
{
|
||||
public:
|
||||
|
||||
LmsApplication(const Wt::WEnvironment& env);
|
||||
|
||||
private:
|
||||
|
||||
void handleSearch();
|
||||
|
||||
Wt::WLineEdit* _searchEdit;
|
||||
AudioWidget* _audioWidget;
|
||||
VideoWidget* _videoWidget;
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "TranscodeResource.hpp"
|
||||
|
||||
TranscodeResource::TranscodeResource(const boost::filesystem::path& p, const Transcoder::Parameters& params, Wt::WObject *parent)
|
||||
: Wt::WResource(parent),
|
||||
// _transcoder(params),
|
||||
_path(p)
|
||||
{
|
||||
// suggestFileName(p.filename());
|
||||
}
|
||||
|
||||
TranscodeResource::~TranscodeResource()
|
||||
{
|
||||
beingDeleted();
|
||||
}
|
||||
|
||||
void
|
||||
TranscodeResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response)
|
||||
{
|
||||
std::ifstream r(_path.string().c_str(), std::ios::in | std::ios::binary);
|
||||
handleRequestPiecewise(request, response, r);
|
||||
}
|
||||
|
||||
void
|
||||
TranscodeResource::handleRequestPiecewise(const Wt::Http::Request& request,
|
||||
Wt::Http::Response& response,
|
||||
std::istream& input)
|
||||
{
|
||||
suggestFileName( _path.filename().string() );
|
||||
Wt::Http::ResponseContinuation *continuation = request.continuation();
|
||||
::uint64_t startByte = continuation ?
|
||||
boost::any_cast< ::uint64_t >(continuation->data()) : 0;
|
||||
|
||||
if (startByte == 0) {
|
||||
/*
|
||||
* Initial request (not a continuation)
|
||||
*/
|
||||
if (!input) {
|
||||
response.setStatus(404);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* See if we should return a range.
|
||||
*/
|
||||
input.seekg(0, std::ios::end);
|
||||
std::istream::pos_type isize = input.tellg();
|
||||
input.seekg(0, std::ios::beg);
|
||||
|
||||
Wt::Http::Request::ByteRangeSpecifier ranges = request.getRanges(isize);
|
||||
|
||||
if (!ranges.isSatisfiable()) {
|
||||
std::ostringstream contentRange;
|
||||
contentRange << "bytes */" << isize;
|
||||
response.setStatus(416); // Requested range not satisfiable
|
||||
response.addHeader("Content-Range", contentRange.str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (ranges.size() == 1) {
|
||||
response.setStatus(206);
|
||||
startByte = ranges[0].firstByte();
|
||||
_beyondLastByte = std::streamsize(ranges[0].lastByte() + 1);
|
||||
|
||||
std::ostringstream contentRange;
|
||||
contentRange << "bytes " << startByte << "-"
|
||||
<< _beyondLastByte - 1 << "/" << isize;
|
||||
response.addHeader("Content-Range", contentRange.str());
|
||||
response.setContentLength(::uint64_t(_beyondLastByte) - startByte);
|
||||
} else {
|
||||
_beyondLastByte = std::streamsize(isize);
|
||||
response.setContentLength(::uint64_t(_beyondLastByte));
|
||||
}
|
||||
|
||||
response.setMimeType("plain/text");
|
||||
}
|
||||
|
||||
input.seekg(static_cast<std::istream::pos_type>(startByte));
|
||||
|
||||
// According to 27.6.1.3, paragraph 1 of ISO/IEC 14882:2003(E),
|
||||
// each unformatted input function may throw an exception.
|
||||
boost::scoped_array<char> buf(new char[_bufferSize]);
|
||||
std::streamsize sbufferSize = std::streamsize(_bufferSize);
|
||||
|
||||
std::streamsize restSize = _beyondLastByte - std::streamsize(startByte);
|
||||
std::streamsize pieceSize = sbufferSize > restSize ? restSize : sbufferSize;
|
||||
|
||||
std::cout << "Seeking to " << startByte << ", pieceSize = " << pieceSize << std::endl;
|
||||
|
||||
input.read(buf.get(), pieceSize);
|
||||
std::streamsize actualPieceSize = input.gcount();
|
||||
response.out().write(buf.get(), actualPieceSize);
|
||||
|
||||
if (input.good() && actualPieceSize < restSize) {
|
||||
continuation = response.createContinuation();
|
||||
continuation->setData(startByte + ::uint64_t(_bufferSize));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "metadata/AvFormat.hpp"
|
||||
#include "metadata/Extractor.hpp"
|
||||
#include "database/Database.hpp"
|
||||
|
||||
#include "transcode/AvConvTranscoder.hpp"
|
||||
|
||||
#include "av/Common.hpp"
|
||||
|
||||
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
|
||||
*/
|
||||
return new LmsApplication(env);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
// std::locale::global(std::locale(""));
|
||||
MetaData::AvFormat metadataParser;
|
||||
// MetaData::Extractor metadataParser;
|
||||
|
||||
Transcode::AvConvTranscoder::init();
|
||||
|
||||
// Set up the long living database session
|
||||
Database database("test.db", metadataParser);
|
||||
|
||||
// database.watchDirectory( WatchedDirectory("/storage/common/Media/Son", WatchedDirectory::Audio ));
|
||||
// database.watchDirectory(WatchedDirectory("/storage/common/Media/Son/Metal", WatchedDirectory::Audio));
|
||||
// database.watchDirectory("/storage/common/Media/Son/Metal/Iced Earth/2004 - The Glorious Burden");
|
||||
// database.watchDirectory("/storage/common/Media/Son/Metal/System Of a Down");
|
||||
// database.watchDirectory("/storage/common/Media/Son/Metal/Leprous");
|
||||
// database.watchDirectory("/storage/common/Media/Son/Electro");
|
||||
// database.watchDirectory( WatchedDirectory("/storage/common/Media/Son/Electro", WatchedDirectory::Audio) );
|
||||
// database.watchDirectory("/storage/common/Media/Son/Metal/Lacuna Coil");
|
||||
// database.watchDirectory( WatchedDirectory("/storage/common/Media/Video", WatchedDirectory::Video) );
|
||||
// database.watchDirectory( WatchedDirectory("/storage/common/Media/Video/Films", WatchedDirectory::Video) );
|
||||
database.watchDirectory( WatchedDirectory("/storage/common/Media/Video/Series", WatchedDirectory::Video) );
|
||||
|
||||
std::cout << "Starting refresh..." << std::endl;
|
||||
// boost::thread refreshThread(boost::bind(&Database::refresh, &database));
|
||||
|
||||
AvInit();
|
||||
|
||||
return Wt::WRun(argc, argv, &createApplication);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user