diff --git a/src/Makefile.am b/src/Makefile.am
index e6b0f919..67cf739e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/ui/LmsApplication.cpp b/src/ui/LmsApplication.cpp
index be39ef1f..50f31cbb 100644
--- a/src/ui/LmsApplication.cpp
+++ b/src/ui/LmsApplication.cpp
@@ -28,8 +28,8 @@
#include
#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
diff --git a/src/ui/LmsApplication.hpp b/src/ui/LmsApplication.hpp
index 447c1db3..18953981 100644
--- a/src/ui/LmsApplication.hpp
+++ b/src/ui/LmsApplication.hpp
@@ -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();
diff --git a/src/ui/audio/mobile/ArtistSearch.cpp b/src/ui/audio/mobile/ArtistSearch.cpp
index 35033792..a6b6e1d8 100644
--- a/src/ui/audio/mobile/ArtistSearch.cpp
+++ b/src/ui/audio/mobile/ArtistSearch.cpp
@@ -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
+getArtists(SearchFilter filter, size_t offset, size_t nb, bool &moreResults)
{
- Wt::Dbo::Transaction transaction(DboSession());
+ std::vector artists = Artist::getByFilter(DboSession(), filter, offset, nb + 1);
- std::vector 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 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
diff --git a/src/ui/audio/mobile/ArtistSearch.hpp b/src/ui/audio/mobile/ArtistSearch.hpp
index f1218c9c..50dc22de 100644
--- a/src/ui/audio/mobile/ArtistSearch.hpp
+++ b/src/ui/audio/mobile/ArtistSearch.hpp
@@ -23,6 +23,7 @@
#include
#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& artistSelected() { return _sigArtistSelected;}
- Wt::Signal& moreArtistsSelected() { return _sigMoreArtistsSelected;}
+ Wt::Signal& showMore() { return _sigShowMore;}
private:
- Wt::Signal _sigArtistSelected;
- Wt::Signal _sigMoreArtistsSelected;
+ Wt::Signal _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
diff --git a/src/ui/audio/mobile/ArtistSearchView.cpp b/src/ui/audio/mobile/ArtistSearchView.cpp
new file mode 100644
index 00000000..1fda1e0d
--- /dev/null
+++ b/src/ui/audio/mobile/ArtistSearchView.cpp
@@ -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 .
+ */
+
+#include
+#include
+
+#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 keywords = searchPathToSearchKeywords(path.substr(pathPrefix.length()));
+
+ artistSearch->search(SearchFilter::ByNameAnd(SearchFilter::Field::Artist, keywords), SEARCH_NB_ITEMS);
+
+ }, std::placeholders::_1));
+}
+
+} // namespace Mobile
+} // namespace UserInterface
+
diff --git a/src/ui/audio/mobile/ArtistSearchView.hpp b/src/ui/audio/mobile/ArtistSearchView.hpp
new file mode 100644
index 00000000..29971950
--- /dev/null
+++ b/src/ui/audio/mobile/ArtistSearchView.hpp
@@ -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 .
+ */
+
+#pragma once
+
+#include
+
+namespace UserInterface {
+namespace Mobile {
+
+class ArtistSearchView : public Wt::WContainerWidget
+{
+ public:
+
+ ArtistSearchView(Wt::WContainerWidget* parent = 0);
+
+};
+
+} // namespace Mobile
+} // namespace UserInterface
+
diff --git a/src/ui/audio/mobile/ArtistView.cpp b/src/ui/audio/mobile/ArtistView.cpp
new file mode 100644
index 00000000..0a48fb5f
--- /dev/null
+++ b/src/ui/audio/mobile/ArtistView.cpp
@@ -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 .
+ */
+
+#include
+
+#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
+
diff --git a/src/ui/audio/mobile/ArtistView.hpp b/src/ui/audio/mobile/ArtistView.hpp
new file mode 100644
index 00000000..97973389
--- /dev/null
+++ b/src/ui/audio/mobile/ArtistView.hpp
@@ -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 .
+ */
+
+#pragma once
+
+#include
+
+namespace UserInterface {
+namespace Mobile {
+
+class ArtistView : public Wt::WContainerWidget
+{
+ public:
+ ArtistView(Wt::WContainerWidget *parent = 0);
+
+};
+
+
+} //namespace Mobile
+} //namespace UserInterface
+
diff --git a/src/ui/audio/mobile/MobileAudio.cpp b/src/ui/audio/mobile/MobileAudio.cpp
index b5d0c66a..e18087f9 100644
--- a/src/ui/audio/mobile/MobileAudio.cpp
+++ b/src/ui/audio/mobile/MobileAudio.cpp
@@ -17,8 +17,9 @@
* along with LMS. If not, see .
*/
+#include