[UI/MOBILE] Began internal path support
This commit is contained in:
@@ -448,6 +448,18 @@
|
||||
</div>
|
||||
</message>
|
||||
|
||||
<!--
|
||||
wa-artist-wrapper
|
||||
-> wa-artist-res
|
||||
-> wa-artist-res
|
||||
-> ...
|
||||
-->
|
||||
<message id="wa-artist-search">
|
||||
${title}
|
||||
${release-container}
|
||||
${show-more}
|
||||
</message>
|
||||
|
||||
<message id="wa-artist-wrapper">
|
||||
<div class="section text-center">
|
||||
<div class="container">
|
||||
|
||||
+4
-1
@@ -32,9 +32,12 @@ lms_SOURCES = \
|
||||
$(srcdir)/ui/audio/desktop/TableFilter.cpp \
|
||||
$(srcdir)/ui/audio/desktop/TrackView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/ArtistSearch.cpp \
|
||||
$(srcdir)/ui/audio/mobile/ArtistSearchView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/ArtistView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/MobileAudio.cpp \
|
||||
$(srcdir)/ui/audio/mobile/PreviewSearchView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/ReleaseSearch.cpp \
|
||||
$(srcdir)/ui/audio/mobile/TrackReleaseView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/ReleaseView.cpp \
|
||||
$(srcdir)/ui/audio/mobile/TrackSearch.cpp \
|
||||
$(srcdir)/ui/common/DirectoryValidator.cpp \
|
||||
$(srcdir)/ui/common/InputRange.cpp \
|
||||
|
||||
+72
-84
@@ -28,8 +28,8 @@
|
||||
#include <Wt/Auth/Identity>
|
||||
|
||||
#include "config/config.h"
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
#include "settings/Settings.hpp"
|
||||
#include "settings/SettingsFirstConnectionFormView.hpp"
|
||||
@@ -48,20 +48,6 @@ namespace skeletons {
|
||||
extern const char *AuthStrings_xml1;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool agentIsMobile()
|
||||
{
|
||||
const Wt::WEnvironment& env = Wt::WApplication::instance()->environment();
|
||||
return (env.agentIsIEMobile()
|
||||
|| env.agentIsMobileWebKit()
|
||||
|| env.userAgent().find("Mobile") != std::string::npos // Workaround for firefox
|
||||
|| env.userAgent().find("Tablet") != std::string::npos // Workaround for firefox
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
@@ -177,86 +163,88 @@ LmsApplication::createLmsUI()
|
||||
authWidget->processEnvironment();
|
||||
|
||||
root()->addWidget(authWidget);
|
||||
}
|
||||
|
||||
setInternalPath("/");
|
||||
}
|
||||
|
||||
void
|
||||
LmsApplication::handleAuthEvent(void)
|
||||
{
|
||||
if (DbHandler().getLogin().loggedIn())
|
||||
{
|
||||
LMS_LOG(UI, INFO) << "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);
|
||||
setConfirmCloseMessage("Closing LMS. Are you sure?");
|
||||
|
||||
// Create a Vertical layout: top is the nav bar, bottom is the contents
|
||||
Wt::WVBoxLayout *layout = new Wt::WVBoxLayout(this->root());
|
||||
// Create a navigation bar with a link to a web page.
|
||||
Wt::WNavigationBar *navigation = new Wt::WNavigationBar();
|
||||
navigation->setTitle("LMS", "https://github.com/epoupon/lms");
|
||||
navigation->setResponsive(true);
|
||||
navigation->addStyleClass("main-nav");
|
||||
|
||||
Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget();
|
||||
|
||||
contentsStack->setOverflow(Wt::WContainerWidget::OverflowAuto);
|
||||
contentsStack->addStyleClass("contents");
|
||||
|
||||
Wt::WMenu *menu = new Wt::WMenu(contentsStack);
|
||||
navigation->addMenu(menu, Wt::AlignRight);
|
||||
|
||||
LineEdit *searchEdit = new LineEdit(500);
|
||||
navigation->bindWidget("search", searchEdit);
|
||||
searchEdit->setEmptyText("Search...");
|
||||
searchEdit->addStyleClass("navbar-form navbar-nav");
|
||||
searchEdit->setWidth(150);
|
||||
// TODO add a span with a search icon
|
||||
|
||||
Audio *audio;
|
||||
|
||||
if (agentIsMobile())
|
||||
audio = new Mobile::Audio();
|
||||
else
|
||||
audio = new Desktop::Audio();
|
||||
|
||||
menu->addItem("Audio", audio);
|
||||
#if defined HAVE_VIDEO
|
||||
menu->addItem("Video", new VideoWidget());
|
||||
#endif
|
||||
menu->addItem("Settings", new Settings::Settings());
|
||||
|
||||
Wt::WPopupMenu *popup = new Wt::WPopupMenu();
|
||||
popup->addItem("Logout");
|
||||
|
||||
Wt::WMenuItem *item = new Wt::WMenuItem( CurrentAuthUser().identity(Wt::Auth::Identity::LoginName) );
|
||||
item->setMenu(popup);
|
||||
menu->addItem(item);
|
||||
|
||||
popup->itemSelected().connect(std::bind([=] (Wt::WMenuItem* item)
|
||||
{
|
||||
if (item && item->text() == "Logout")
|
||||
DbHandler().getLogin().logout();
|
||||
}, std::placeholders::_1));
|
||||
|
||||
searchEdit->timedChanged().connect(std::bind([=] ()
|
||||
{
|
||||
// TODO: check which view is activated and search into it
|
||||
audio->search(searchEdit->text().toUTF8());
|
||||
}));
|
||||
|
||||
|
||||
layout->addWidget(navigation);
|
||||
layout->addWidget(contentsStack, 1);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
if (!DbHandler().getLogin().loggedIn())
|
||||
{
|
||||
LMS_LOG(UI, INFO) << "User logged out, session = " << Wt::WApplication::instance()->sessionId();
|
||||
|
||||
quit("");
|
||||
redirect("/");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LMS_LOG(UI, INFO) << "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);
|
||||
setConfirmCloseMessage("Closing LMS. Are you sure?");
|
||||
|
||||
// Handle internal paths
|
||||
// this->setInternalPath("audio");
|
||||
|
||||
// Create a Vertical layout: top is the nav bar, bottom is the contents
|
||||
Wt::WVBoxLayout *layout = new Wt::WVBoxLayout(this->root());
|
||||
// Create a navigation bar with a link to a web page.
|
||||
Wt::WNavigationBar *navigation = new Wt::WNavigationBar();
|
||||
navigation->setTitle("LMS", "https://github.com/epoupon/lms");
|
||||
navigation->setResponsive(true);
|
||||
navigation->addStyleClass("main-nav");
|
||||
|
||||
Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget();
|
||||
|
||||
contentsStack->setOverflow(Wt::WContainerWidget::OverflowAuto);
|
||||
contentsStack->addStyleClass("contents");
|
||||
|
||||
Wt::WMenu *menu = new Wt::WMenu(contentsStack);
|
||||
navigation->addMenu(menu, Wt::AlignRight);
|
||||
|
||||
LineEdit *searchEdit = new LineEdit(500);
|
||||
navigation->bindWidget("search", searchEdit);
|
||||
searchEdit->setEmptyText("Search...");
|
||||
searchEdit->addStyleClass("navbar-form navbar-nav");
|
||||
searchEdit->setWidth(150);
|
||||
// TODO add a span with a search icon
|
||||
|
||||
Mobile::Audio *audio = new Mobile::Audio();
|
||||
|
||||
menu->addItem("Audio", audio);
|
||||
#if defined HAVE_VIDEO
|
||||
menu->addItem("Video", new VideoWidget());
|
||||
#endif
|
||||
menu->addItem("Settings", new Settings::Settings());
|
||||
|
||||
|
||||
Wt::WPopupMenu *popup = new Wt::WPopupMenu();
|
||||
popup->addItem("Logout");
|
||||
|
||||
Wt::WMenuItem *item = new Wt::WMenuItem( CurrentAuthUser().identity(Wt::Auth::Identity::LoginName) );
|
||||
item->setMenu(popup);
|
||||
menu->addItem(item);
|
||||
|
||||
popup->itemSelected().connect(std::bind([=] (Wt::WMenuItem* item)
|
||||
{
|
||||
if (item && item->text() == "Logout")
|
||||
DbHandler().getLogin().logout();
|
||||
}, std::placeholders::_1));
|
||||
|
||||
searchEdit->timedChanged().connect(std::bind([=] ()
|
||||
{
|
||||
// TODO: check which view is activated and search into it
|
||||
audio->search(searchEdit->text().toUTF8());
|
||||
}));
|
||||
|
||||
layout->addWidget(navigation);
|
||||
layout->addWidget(contentsStack, 1);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// Set initial path
|
||||
wApp->setInternalPath("/audio/search/preview", true);
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -56,6 +56,8 @@ class LmsApplication : public Wt::WApplication
|
||||
};
|
||||
|
||||
// Helpers to get session data
|
||||
#define LmsApp LmsApplication::instance()
|
||||
|
||||
Database::Handler& DbHandler();
|
||||
Wt::Dbo::Session& DboSession();
|
||||
|
||||
|
||||
@@ -31,89 +31,95 @@ namespace Mobile {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
ArtistSearch::ArtistSearch(Wt::WContainerWidget *parent)
|
||||
ArtistSearch::ArtistSearch(Wt::WString title, Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_resCount(0)
|
||||
_count(0)
|
||||
{
|
||||
Wt::WTemplate *title = new Wt::WTemplate(this);
|
||||
title->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||
Wt::WTemplate* artistSearch = new Wt::WTemplate(this);
|
||||
artistSearch->setTemplateText(Wt::WString::tr("wa-artist-search"));
|
||||
|
||||
title->bindWidget("text", new Wt::WText("Artists", Wt::PlainText));
|
||||
Wt::WTemplate *titleTemplate = new Wt::WTemplate(this);
|
||||
titleTemplate->setTemplateText(Wt::WString::tr("mobile-search-title"));
|
||||
titleTemplate->bindString("text", title);
|
||||
|
||||
artistSearch->bindWidget("title", titleTemplate);
|
||||
|
||||
Wt::WTemplate* artistWrapper = new Wt::WTemplate(this);
|
||||
artistWrapper->setTemplateText(Wt::WString::tr("wa-artist-wrapper"));
|
||||
_contents = new Wt::WContainerWidget();
|
||||
artistWrapper->bindWidget("contents", _contents );
|
||||
artistSearch->bindWidget("release-container", _contents );
|
||||
|
||||
_showMore = new Wt::WTemplate();
|
||||
_showMore->setTemplateText(Wt::WString::tr("mobile-search-more"));
|
||||
_showMore->bindString("text", "Tap to show more results...");
|
||||
_showMore->hide();
|
||||
_showMore->clicked().connect(std::bind([=] {
|
||||
_sigShowMore.emit();
|
||||
}));
|
||||
|
||||
artistSearch->bindWidget("show-more", _showMore);
|
||||
}
|
||||
|
||||
void
|
||||
ArtistSearch::clear()
|
||||
{
|
||||
while (count() > 1)
|
||||
removeWidget(this->widget(1));
|
||||
|
||||
_resCount = 0;
|
||||
_contents->clear();
|
||||
_count = 0;
|
||||
_showMore->hide();
|
||||
}
|
||||
|
||||
void
|
||||
ArtistSearch::search(Database::SearchFilter filter, size_t nb)
|
||||
{
|
||||
_filter = filter;
|
||||
|
||||
clear();
|
||||
addResults(filter, nb);
|
||||
addResults(nb);
|
||||
}
|
||||
|
||||
void
|
||||
ArtistSearch::addResults(Database::SearchFilter filter, std::size_t nb)
|
||||
static
|
||||
std::vector<Artist::pointer>
|
||||
getArtists(SearchFilter filter, size_t offset, size_t nb, bool &moreResults)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
std::vector<Artist::pointer> artists = Artist::getByFilter(DboSession(), filter, offset, nb + 1);
|
||||
|
||||
std::vector<Artist::pointer> artists = Artist::getByFilter(DboSession(), filter, _resCount, nb + 1);
|
||||
|
||||
bool expectMoreResults;
|
||||
if (artists.size() == nb + 1)
|
||||
{
|
||||
expectMoreResults = true;
|
||||
moreResults = true;
|
||||
artists.pop_back();
|
||||
}
|
||||
else
|
||||
expectMoreResults = false;
|
||||
moreResults = false;
|
||||
|
||||
return artists;
|
||||
}
|
||||
|
||||
void
|
||||
ArtistSearch::addResults(std::size_t nb)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
bool moreResults;
|
||||
std::vector<Artist::pointer> artists = getArtists(_filter, _count, nb, moreResults);
|
||||
|
||||
for (Artist::pointer artist : artists)
|
||||
{
|
||||
Wt::WTemplate* res = new Wt::WTemplate(this);
|
||||
Wt::WTemplate* res = new Wt::WTemplate(_contents);
|
||||
res->setTemplateText(Wt::WString::tr("wa-artist-res"));
|
||||
|
||||
Wt::WImage *artistImg = new Wt::WImage();
|
||||
Wt::WAnchor *coverAnchor = new Wt::WAnchor(Wt::WLink(Wt:: WLink::InternalPath, "/audio/artist/" + std::to_string(artist.id())));
|
||||
Wt::WImage *artistImg = new Wt::WImage(coverAnchor);
|
||||
artistImg->setStyleClass("center-block"); // TODO move in css?
|
||||
artistImg->setStyleClass("release_res_shadow release_img-responsive"); // TODO move in css?
|
||||
|
||||
res->bindWidget("gif", artistImg);
|
||||
|
||||
Wt::WText *text = new Wt::WText(Wt::WString::fromUTF8(artist->getName()), Wt::PlainText);
|
||||
res->bindWidget("name", text);
|
||||
|
||||
res->clicked().connect(std::bind([=] {
|
||||
_sigArtistSelected(artist.id());
|
||||
}));
|
||||
res->bindWidget("gif", coverAnchor);
|
||||
res->bindString("name", Wt::WString::fromUTF8(artist->getName(), Wt::PlainText));
|
||||
}
|
||||
|
||||
_resCount += artists.size();;
|
||||
|
||||
if (expectMoreResults)
|
||||
{
|
||||
Wt::WTemplate* moreRes = new Wt::WTemplate(this);
|
||||
moreRes->setTemplateText(Wt::WString::tr("mobile-search-more"));
|
||||
|
||||
moreRes->bindWidget("text", new Wt::WText("Tap to show more results..."));
|
||||
|
||||
moreRes->clicked().connect(std::bind([=] {
|
||||
_sigMoreArtistsSelected();
|
||||
removeWidget(moreRes);
|
||||
|
||||
addResults(filter, 20);
|
||||
}));
|
||||
}
|
||||
_count += artists.size();
|
||||
|
||||
if (moreResults)
|
||||
_showMore->show();
|
||||
else
|
||||
_showMore->hide();
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
#include "database/SearchFilter.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
@@ -31,24 +32,25 @@ class ArtistSearch : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
ArtistSearch(Wt::WContainerWidget *parent = 0);
|
||||
ArtistSearch(Wt::WString title, Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void search(Database::SearchFilter filter, std::size_t nb);
|
||||
void addResults(std::size_t nb);
|
||||
|
||||
// Slots
|
||||
Wt::Signal<Database::Artist::id_type>& artistSelected() { return _sigArtistSelected;}
|
||||
Wt::Signal<void>& moreArtistsSelected() { return _sigMoreArtistsSelected;}
|
||||
Wt::Signal<void>& showMore() { return _sigShowMore;}
|
||||
|
||||
private:
|
||||
|
||||
Wt::Signal<Database::Artist::id_type> _sigArtistSelected;
|
||||
Wt::Signal<void> _sigMoreArtistsSelected;
|
||||
Wt::Signal<void> _sigShowMore;
|
||||
|
||||
void clear(void);
|
||||
void addResults(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
Wt::WContainerWidget* _contents;
|
||||
std::size_t _resCount;
|
||||
Wt::WTemplate* _showMore;
|
||||
|
||||
Database::SearchFilter _filter;
|
||||
Wt::WContainerWidget* _contents;
|
||||
std::size_t _count;
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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 <Wt/WApplication>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "SearchUtils.hpp"
|
||||
|
||||
#include "ArtistSearch.hpp"
|
||||
|
||||
#include "ArtistSearchView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
#define SEARCH_NB_ITEMS 20
|
||||
|
||||
using namespace Database;
|
||||
|
||||
ArtistSearchView::ArtistSearchView(Wt::WContainerWidget* parent)
|
||||
{
|
||||
ArtistSearch* artistSearch = new ArtistSearch("Artists", this);
|
||||
artistSearch->showMore().connect(std::bind([=] {
|
||||
artistSearch->addResults(SEARCH_NB_ITEMS);
|
||||
}));
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
const std::string pathPrefix = "/audio/search/artist";
|
||||
|
||||
if (!wApp->internalPathMatches(pathPrefix))
|
||||
return;
|
||||
|
||||
std::vector<std::string> keywords = searchPathToSearchKeywords(path.substr(pathPrefix.length()));
|
||||
|
||||
artistSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Artist, keywords), SEARCH_NB_ITEMS);
|
||||
|
||||
}, std::placeholders::_1));
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
class ArtistSearchView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
ArtistSearchView(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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 <Wt/WApplication>
|
||||
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
#include "ReleaseSearch.hpp"
|
||||
#include "ArtistView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
ArtistView::ArtistView(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
ReleaseSearch *releases = new ReleaseSearch(this);
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
const std::string pathPrefix = "/audio/artist/";
|
||||
|
||||
if (!wApp->internalPathMatches(pathPrefix))
|
||||
return;
|
||||
|
||||
std::string strId = path.substr(pathPrefix.length());
|
||||
|
||||
Artist::id_type id;
|
||||
if (readAs(strId, id))
|
||||
releases->search(SearchFilter::ById(SearchFilter::Field::Artist, id), 20);
|
||||
|
||||
}, std::placeholders::_1));
|
||||
}
|
||||
|
||||
} //namespace Mobile
|
||||
} //namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
class ArtistView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
ArtistView(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} //namespace Mobile
|
||||
} //namespace UserInterface
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WStackedWidget>
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WText>
|
||||
|
||||
@@ -28,13 +29,29 @@
|
||||
#include "audio/AudioPlayer.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "ArtistSearchView.hpp"
|
||||
#include "PreviewSearchView.hpp"
|
||||
#include "ReleaseSearch.hpp"
|
||||
#include "TrackSearch.hpp"
|
||||
#include "ArtistView.hpp"
|
||||
#include "ReleaseView.hpp"
|
||||
|
||||
#include "MobileAudio.hpp"
|
||||
|
||||
#define SEARCH_NB_ITEMS 4
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
enum WidgetIdx
|
||||
{
|
||||
WidgetIdxSearchPreview = 0,
|
||||
WidgetIdxSearchArtist = 1,
|
||||
WidgetIdxSearchRelease = 2,
|
||||
WidgetIdxSearchTrack = 3,
|
||||
WidgetIdxArtist = 4,
|
||||
WidgetIdxRelease = 5,
|
||||
};
|
||||
|
||||
using namespace Database;
|
||||
|
||||
static void playTrack(AudioPlayer *audioPlayer, Database::Track::id_type trackId)
|
||||
@@ -52,23 +69,9 @@ static void playTrack(AudioPlayer *audioPlayer, Database::Track::id_type trackId
|
||||
void
|
||||
Audio::search(std::string text)
|
||||
{
|
||||
// When a new search is done, output some results from:
|
||||
// Artist
|
||||
// Release
|
||||
// Song
|
||||
auto keywords = splitString(text, " ");;
|
||||
|
||||
_releaseSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Release, keywords), SEARCH_NB_ITEMS);
|
||||
_artistSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Artist, keywords), SEARCH_NB_ITEMS);
|
||||
_trackSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Track, keywords), SEARCH_NB_ITEMS);
|
||||
|
||||
_artistSearch->show();
|
||||
_releaseSearch->show();
|
||||
_trackSearch->show();
|
||||
_trackReleaseView->hide();
|
||||
wApp->setInternalPath("/audio/search/preview/" + stringToUTF8(text), true);
|
||||
}
|
||||
|
||||
|
||||
Audio::Audio(Wt::WContainerWidget *parent)
|
||||
: UserInterface::Audio(parent)
|
||||
{
|
||||
@@ -76,12 +79,36 @@ Audio::Audio(Wt::WContainerWidget *parent)
|
||||
this->setStyleClass("container-fluid");
|
||||
this->setPadding(60, Wt::Bottom);
|
||||
|
||||
_artistSearch = new ArtistSearch(this);
|
||||
_releaseSearch = new ReleaseSearch(this);
|
||||
_trackSearch = new TrackSearch(this);
|
||||
Wt::WStackedWidget *stack = new Wt::WStackedWidget(this);
|
||||
|
||||
_trackReleaseView = new TrackReleaseView(this);
|
||||
_trackReleaseView->hide();
|
||||
// Same order as WidgetIdxXXX
|
||||
stack->addWidget(new PreviewSearchView());
|
||||
stack->addWidget(new ArtistSearchView());
|
||||
stack->addWidget(new ReleaseSearch());
|
||||
stack->addWidget(new TrackSearch());
|
||||
stack->addWidget(new ArtistView());
|
||||
stack->addWidget(new ReleaseView());
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
// order is important
|
||||
static std::map<std::string, int> indexes =
|
||||
{
|
||||
{ "/audio/search/preview", WidgetIdxSearchPreview},
|
||||
{ "/audio/search/artist", WidgetIdxSearchArtist},
|
||||
{ "/audio/search/release", WidgetIdxSearchRelease},
|
||||
{ "/audio/search/track", WidgetIdxSearchTrack},
|
||||
{ "/audio/artist", WidgetIdxArtist},
|
||||
{ "/audio/release", WidgetIdxRelease},
|
||||
};
|
||||
|
||||
for (auto index : indexes)
|
||||
{
|
||||
if (wApp->internalPathMatches(index.first))
|
||||
stack->setCurrentIndex(index.second);
|
||||
}
|
||||
|
||||
}, std::placeholders::_1));
|
||||
|
||||
Wt::WTemplate* footer = new Wt::WTemplate(this);
|
||||
footer->setTemplateText(Wt::WString::tr("mobile-audio-footer"));
|
||||
@@ -89,67 +116,6 @@ Audio::Audio(Wt::WContainerWidget *parent)
|
||||
AudioPlayer* audioPlayer = new AudioPlayer();
|
||||
footer->bindWidget("player", audioPlayer);
|
||||
|
||||
_artistSearch->moreArtistsSelected().connect(std::bind([=]
|
||||
{
|
||||
_releaseSearch->hide();
|
||||
_trackSearch->hide();
|
||||
_artistSearch->show();
|
||||
_trackReleaseView->hide();
|
||||
}));
|
||||
|
||||
_artistSearch->artistSelected().connect(std::bind([=] (Artist::id_type artistId)
|
||||
{
|
||||
_artistSearch->hide();
|
||||
_trackSearch->hide();
|
||||
_releaseSearch->show();
|
||||
_trackReleaseView->hide();
|
||||
|
||||
_releaseSearch->search(SearchFilter::ById(SearchFilter::Field::Artist, artistId), 20);
|
||||
}, std::placeholders::_1));
|
||||
|
||||
_releaseSearch->moreReleasesSelected().connect(std::bind([=]
|
||||
{
|
||||
_artistSearch->hide();
|
||||
_trackSearch->hide();
|
||||
_releaseSearch->show();
|
||||
_trackReleaseView->hide();
|
||||
}));
|
||||
|
||||
_releaseSearch->releaseSelected().connect(std::bind([=] (Release::id_type releaseId)
|
||||
{
|
||||
_artistSearch->hide();
|
||||
_releaseSearch->hide();
|
||||
_trackSearch->hide();
|
||||
_trackReleaseView->show();
|
||||
|
||||
_trackReleaseView->search(SearchFilter::ById(SearchFilter::Field::Release, releaseId), 40);
|
||||
}, std::placeholders::_1));
|
||||
|
||||
_trackSearch->moreSelected().connect(std::bind([=]
|
||||
{
|
||||
_artistSearch->hide();
|
||||
_releaseSearch->hide();
|
||||
_trackSearch->show();
|
||||
_trackReleaseView->hide();
|
||||
}));
|
||||
|
||||
_trackSearch->trackPlay().connect(std::bind([=] (Track::id_type id)
|
||||
{
|
||||
playTrack(audioPlayer, id);
|
||||
}, std::placeholders::_1));
|
||||
|
||||
_trackReleaseView->trackPlay().connect(std::bind([=] (Track::id_type id)
|
||||
{
|
||||
playTrack(audioPlayer, id);
|
||||
}, std::placeholders::_1));
|
||||
|
||||
// Initially, populate the widgets using an empty search
|
||||
{
|
||||
_artistSearch->search(SearchFilter(), SEARCH_NB_ITEMS);
|
||||
_releaseSearch->search(SearchFilter(), SEARCH_NB_ITEMS);
|
||||
_trackSearch->search(SearchFilter(), SEARCH_NB_ITEMS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
@@ -24,11 +24,6 @@
|
||||
|
||||
#include "audio/Audio.hpp"
|
||||
|
||||
#include "ArtistSearch.hpp"
|
||||
#include "ReleaseSearch.hpp"
|
||||
#include "TrackSearch.hpp"
|
||||
#include "TrackReleaseView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
@@ -40,11 +35,6 @@ class Audio : public UserInterface::Audio
|
||||
void search(std::string text);
|
||||
|
||||
private:
|
||||
|
||||
ArtistSearch* _artistSearch;
|
||||
ReleaseSearch* _releaseSearch;
|
||||
TrackSearch* _trackSearch;
|
||||
TrackReleaseView* _trackReleaseView;
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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 <Wt/WApplication>
|
||||
#include <Wt/WText>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include "SearchUtils.hpp"
|
||||
|
||||
#include "ArtistSearch.hpp"
|
||||
#include "ReleaseSearch.hpp"
|
||||
#include "TrackSearch.hpp"
|
||||
|
||||
#include "PreviewSearchView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
#define SEARCH_NB_ITEMS 4
|
||||
|
||||
using namespace Database;
|
||||
|
||||
PreviewSearchView::PreviewSearchView(Wt::WContainerWidget* parent)
|
||||
{
|
||||
const std::string pathPrefix = "/audio/search/preview";
|
||||
|
||||
ArtistSearch* artistSearch = new ArtistSearch("Artists", this);
|
||||
ReleaseSearch* releaseSearch = new ReleaseSearch(this);
|
||||
TrackSearch* trackSearch = new TrackSearch(this);
|
||||
|
||||
artistSearch->showMore().connect(std::bind([=]
|
||||
{
|
||||
std::string path = wApp->internalPath();
|
||||
path.replace(0, pathPrefix.length(), "/audio/search/artist");
|
||||
|
||||
wApp->setInternalPath(path, true);
|
||||
}));
|
||||
|
||||
releaseSearch->showMore().connect(std::bind([=]
|
||||
{
|
||||
std::string path = wApp->internalPath();
|
||||
path.replace(0, pathPrefix.length(), "/audio/search/release");
|
||||
|
||||
wApp->setInternalPath(path, true);
|
||||
}));
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
if (!wApp->internalPathMatches(pathPrefix))
|
||||
return;
|
||||
|
||||
std::vector<std::string> keywords = searchPathToSearchKeywords(path.substr(pathPrefix.length()));
|
||||
|
||||
artistSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Artist, keywords), SEARCH_NB_ITEMS);
|
||||
releaseSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Release, keywords), SEARCH_NB_ITEMS);
|
||||
trackSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Track, keywords), SEARCH_NB_ITEMS);
|
||||
|
||||
}, std::placeholders::_1));
|
||||
}
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
class PreviewSearchView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
PreviewSearchView(Wt::WContainerWidget* parent = 0);
|
||||
|
||||
};
|
||||
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -98,19 +98,28 @@ ReleaseSearch::addResults(Database::SearchFilter filter, size_t nb)
|
||||
Wt::WTemplate* releaseWidget = new Wt::WTemplate(this);
|
||||
releaseWidget->setTemplateText(Wt::WString::tr("wa-release-res"));
|
||||
|
||||
Wt::WImage *cover = new Wt::WImage();
|
||||
Wt::WAnchor *coverAnchor = new Wt::WAnchor(Wt::WLink(Wt:: WLink::InternalPath, "/audio/release/" + std::to_string(release.id())));
|
||||
Wt::WImage *cover = new Wt::WImage(coverAnchor);
|
||||
cover->setStyleClass("center-block");
|
||||
cover->setImageLink( Wt::WLink( LmsApplication::instance()->getCoverResource()->getReleaseUrl(release.id(), 512)));
|
||||
cover->setStyleClass("release_res_shadow release_img-responsive"); // TODO move?
|
||||
|
||||
releaseWidget->bindWidget("cover", cover);
|
||||
releaseWidget->bindWidget("cover", coverAnchor);
|
||||
releaseWidget->bindWidget("name", new Wt::WText(Wt::WString::fromUTF8(release->getName()), Wt::PlainText));
|
||||
releaseWidget->bindString("release_name", Wt::WString::fromUTF8(release->getName()), Wt::PlainText);
|
||||
releaseWidget->bindString("artist", getArtistFromRelease(release));
|
||||
|
||||
releaseWidget->clicked().connect(std::bind([=] {
|
||||
_sigReleaseSelected(release.id());
|
||||
}));
|
||||
|
||||
auto artists = Artist::getByFilter(DboSession(),
|
||||
SearchFilter::ById(SearchFilter::Field::Release, release.id()), -1, 2);
|
||||
if (artists.size() == 1)
|
||||
{
|
||||
Wt::WAnchor *artistAnchor = new Wt::WAnchor(Wt::WLink(Wt:: WLink::InternalPath, "/audio/artist/" + std::to_string(artists.front().id())));
|
||||
Wt::WText *artist = new Wt::WText(artistAnchor);
|
||||
artist->setText(Wt::WString::fromUTF8(artists.front()->getName(), Wt::PlainText));
|
||||
releaseWidget->bindWidget("artist", artistAnchor);
|
||||
}
|
||||
else
|
||||
releaseWidget->bindWidget("artist", new Wt::WText(Wt::WString::fromUTF8("Various Artists", Wt::PlainText)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UI_MOBILE_RELEASE_SEARCH_HPP
|
||||
#define UI_MOBILE_RELEASE_SEARCH_HPP
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "database/SearchFilter.hpp"
|
||||
#include "database/Types.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
@@ -53,4 +55,3 @@ class ReleaseSearch : public Wt::WContainerWidget
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,14 +26,14 @@
|
||||
#include "utils/Utils.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "TrackReleaseView.hpp"
|
||||
#include "ReleaseView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
using namespace Database;
|
||||
|
||||
TrackReleaseView::TrackReleaseView(Wt::WContainerWidget *parent)
|
||||
ReleaseView::ReleaseView(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
Wt::WTemplate* wrapper = new Wt::WTemplate(this);
|
||||
@@ -55,13 +55,29 @@ TrackReleaseView::TrackReleaseView(Wt::WContainerWidget *parent)
|
||||
_showMore->bindString("text", "Tap to show more results...");
|
||||
_showMore->hide();
|
||||
_showMore->clicked().connect(std::bind([=] {
|
||||
_sigMoreTracksSelected();
|
||||
addResults(20);
|
||||
}));
|
||||
|
||||
wApp->internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
const std::string pathPrefix = "/audio/release/";
|
||||
|
||||
if (!wApp->internalPathMatches(pathPrefix))
|
||||
return;
|
||||
|
||||
std::string strId = path.substr(pathPrefix.length());
|
||||
|
||||
Release::id_type id;
|
||||
if (readAs(strId, id))
|
||||
{
|
||||
clear();
|
||||
search(SearchFilter::ById(SearchFilter::Field::Release, id), 20);
|
||||
}
|
||||
}, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void
|
||||
TrackReleaseView::clear()
|
||||
ReleaseView::clear()
|
||||
{
|
||||
// Flush the release container
|
||||
_releaseContainer->clear();
|
||||
@@ -73,7 +89,7 @@ TrackReleaseView::clear()
|
||||
}
|
||||
|
||||
void
|
||||
TrackReleaseView::search(SearchFilter filter, size_t nb)
|
||||
ReleaseView::search(SearchFilter filter, size_t nb)
|
||||
{
|
||||
_filter = filter;
|
||||
|
||||
@@ -111,7 +127,7 @@ getArtistNameFromRelease(Release::pointer release)
|
||||
}
|
||||
|
||||
void
|
||||
TrackReleaseView::addResults(size_t nb)
|
||||
ReleaseView::addResults(size_t nb)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
@@ -175,8 +191,8 @@ TrackReleaseView::addResults(size_t nb)
|
||||
trackRes->bindString("track-name", Wt::WString::fromUTF8(track->getName()), Wt::PlainText);
|
||||
// TODO, display artist name for compilation releases?
|
||||
|
||||
// TODO handle large duration (> 1 hour)
|
||||
trackRes->bindString("time", durationToString(track->getDuration(), "%M:%S"), Wt::PlainText);
|
||||
std::string format = track->getDuration().total_seconds() < 3600 ? "%M:%S" : "%H:%M:%S";
|
||||
trackRes->bindString("time", durationToString(track->getDuration(), format), Wt::PlainText);
|
||||
|
||||
Wt::WText *playBtn = new Wt::WText("Play", Wt::PlainText);
|
||||
playBtn->setStyleClass("center-block"); // TODO move to CSS?
|
||||
@@ -17,8 +17,7 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UI_MOBILE_TRACK_SEARCH_HPP
|
||||
#define UI_MOBILE_TRACK_SEARCH_HPP
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WSignal>
|
||||
@@ -28,11 +27,11 @@
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
class TrackReleaseView : public Wt::WContainerWidget
|
||||
class ReleaseView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
TrackReleaseView(Wt::WContainerWidget *parent = 0);
|
||||
ReleaseView(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
void search(Database::SearchFilter filter, size_t nb);
|
||||
|
||||
@@ -64,4 +63,3 @@ class TrackReleaseView : public Wt::WContainerWidget
|
||||
} // namespace Mobile
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
static inline std::vector<std::string> searchPathToSearchKeywords(std::string path)
|
||||
{
|
||||
if (!path.empty() && path[0] == '/')
|
||||
path.erase(path.begin());
|
||||
|
||||
return splitString(path, " \t");
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
#include "database/SearchFilter.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Mobile {
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
|
||||
TESTS = database-basics database-integrity sql-query database-user
|
||||
|
||||
check_PROGRAMS = database-basics database-integrity sql-query database-user test-wt test-avmetadata test-avtranscoder test-wt-audio
|
||||
check_PROGRAMS = database-basics database-integrity sql-query database-user test-wt test-avmetadata
|
||||
|
||||
database_basics_SOURCES = \
|
||||
$(srcdir)/CheckDbBasics.cpp \
|
||||
@@ -83,7 +83,7 @@ test_wt_audio_SOURCES = TestWtAudio.cpp\
|
||||
$(top_srcdir)/src/ui/resource/CoverResource.cpp \
|
||||
$(top_srcdir)/src/ui/resource/TranscodeResource.cpp
|
||||
|
||||
test_wt_audio_CXXFLAGS=-std=c++11 -Wall -Wextra -I$(top_srcdir)/src $(MAGICKXX_CFLAGS)
|
||||
test_wt_audio_CXXFLAGS=-std=c++11 -Wall -Wextra -I$(top_srcdir)/src -I$(top_srcdir)/src/ui $(MAGICKXX_CFLAGS)
|
||||
test_wt_audio_LDADD=$(MAGICKXX_LIBS)
|
||||
|
||||
|
||||
|
||||
+118
-1
@@ -2,8 +2,62 @@
|
||||
#include <Wt/WServer>
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WStackedWidget>
|
||||
#include <Wt/WComboBox>
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WAnchor>
|
||||
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
|
||||
class ArtistView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
ArtistView(Wt::WContainerWidget *parent = 0)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void setId(int id)
|
||||
{
|
||||
clear();
|
||||
|
||||
Wt::WText *header = new Wt::WText("Artist view ID = " + std::to_string(id), this);
|
||||
header->setInline(false);
|
||||
|
||||
for (int i = id; i > 0; --i)
|
||||
{
|
||||
Wt::WAnchor *anchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/release/" + std::to_string(i)), this);
|
||||
Wt::WText *text = new Wt::WText("Release " + std::to_string(i), anchor);
|
||||
text->setInline(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ReleaseView : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
ReleaseView(Wt::WContainerWidget *parent = 0)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void setId(int id)
|
||||
{
|
||||
clear();
|
||||
Wt::WText *header = new Wt::WText("Release view ID = " + std::to_string(id), this);
|
||||
header->setInline(false);
|
||||
|
||||
for (int i = id; i > 0; --i)
|
||||
{
|
||||
Wt::WAnchor *anchor = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, "/artist/" + std::to_string(i)), this);
|
||||
Wt::WText *text = new Wt::WText("Artist " + std::to_string(i), anchor);
|
||||
text->setInline(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class TestApplication : public Wt::WApplication
|
||||
{
|
||||
@@ -11,7 +65,70 @@ class TestApplication : public Wt::WApplication
|
||||
TestApplication(const Wt::WEnvironment& env)
|
||||
: Wt::WApplication(env)
|
||||
{
|
||||
root()->addWidget(new Wt::WText("Hello, world!"));
|
||||
|
||||
enableInternalPaths();
|
||||
|
||||
Wt::WComboBox *combo = new Wt::WComboBox(root());
|
||||
combo->addItem("Artist");
|
||||
combo->addItem("Release");
|
||||
|
||||
Wt::WLineEdit *edit = new Wt::WLineEdit("Enter id", root());
|
||||
|
||||
edit->changed().connect(std::bind([=]
|
||||
{
|
||||
if (combo->currentText() == "Artist")
|
||||
wApp->setInternalPath("/artist/" + edit->text().toUTF8(), true);
|
||||
else if (combo->currentText() == "Release")
|
||||
wApp->setInternalPath("/release/" + edit->text().toUTF8(), true);
|
||||
}));
|
||||
|
||||
Wt::WStackedWidget *stack = new Wt::WStackedWidget(root());
|
||||
|
||||
Wt::WContainerWidget *artistContainer = new Wt::WContainerWidget();
|
||||
Wt::WContainerWidget *releaseContainer = new Wt::WContainerWidget();
|
||||
|
||||
stack->addWidget(releaseContainer);
|
||||
stack->addWidget(artistContainer);
|
||||
|
||||
internalPathChanged().connect(std::bind([=] (std::string path)
|
||||
{
|
||||
wApp->log("info") << "Path set to '" << path << "'";
|
||||
|
||||
std::vector<std::string> strings;
|
||||
boost::algorithm::split(strings, path, boost::is_any_of("/"), boost::token_compress_on);
|
||||
|
||||
if (strings.size() != 3)
|
||||
return;
|
||||
|
||||
std::string view = strings[1];
|
||||
int id;
|
||||
try {
|
||||
id = std::stol(strings[2]);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (view == "release")
|
||||
{
|
||||
releaseContainer->clear();
|
||||
ReleaseView *releaseView = new ReleaseView(releaseContainer);
|
||||
releaseView->setId(id);
|
||||
|
||||
stack->setCurrentIndex(0);
|
||||
}
|
||||
else if (view == "artist")
|
||||
{
|
||||
artistContainer->clear();
|
||||
ArtistView *artistView = new ArtistView(artistContainer);
|
||||
artistView->setId(id);
|
||||
|
||||
stack->setCurrentIndex(1);
|
||||
}
|
||||
|
||||
}, std::placeholders::_1));
|
||||
|
||||
setInternalPath("/main");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user