[UI/MOBILE] Began internal path support

This commit is contained in:
emeric
2016-03-05 11:34:59 +01:00
parent 6da1b42f93
commit a07704c218
22 changed files with 708 additions and 258 deletions
+2 -2
View File
@@ -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
View File
@@ -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");
}
};