From 7e4e46aad09b33095da495e464ba8dcfce373e20 Mon Sep 17 00:00:00 2001 From: emeric Date: Sun, 19 Oct 2014 19:55:33 +0200 Subject: [PATCH] WIP. new layout on the audio view --- src/Makefile.am | 1 - src/ui/LmsApplication.cpp | 132 +++++++++++++++++++++++++++----------- src/ui/LmsApplication.hpp | 6 -- src/ui/LmsHome.cpp | 59 ----------------- src/ui/LmsHome.hpp | 54 ---------------- 5 files changed, 93 insertions(+), 159 deletions(-) delete mode 100644 src/ui/LmsHome.cpp delete mode 100644 src/ui/LmsHome.hpp diff --git a/src/Makefile.am b/src/Makefile.am index ec61c7d1..8c4f3599 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,7 +41,6 @@ lms_SOURCES = \ $(srcdir)/transcode/Parameters.cpp \ $(srcdir)/transcode/InputMediaFile.cpp \ $(srcdir)/ui/LmsApplication.cpp \ - $(srcdir)/ui/LmsHome.cpp \ $(srcdir)/ui/auth/LmsAuth.cpp \ $(srcdir)/ui/audio/AudioWidget.cpp \ $(srcdir)/ui/audio/AudioMediaPlayerWidget.cpp \ diff --git a/src/ui/LmsApplication.cpp b/src/ui/LmsApplication.cpp index 3e8367c8..487a7c87 100644 --- a/src/ui/LmsApplication.cpp +++ b/src/ui/LmsApplication.cpp @@ -27,18 +27,20 @@ #include #include #include +#include #include #include "settings/Settings.hpp" - #include "auth/LmsAuth.hpp" #include "logger/Logger.hpp" -#include "LmsHome.hpp" #include "settings/SettingsFirstConnectionFormView.hpp" +#include "audio/AudioWidget.hpp" +#include "video/VideoWidget.hpp" + #include "LmsApplication.hpp" namespace skeletons { @@ -66,8 +68,7 @@ LmsApplication::create(const Wt::WEnvironment& env, boost::filesystem::path dbPa */ LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::path dbPath) : Wt::WApplication(env), - _sessionData(dbPath), - _home(nullptr) + _sessionData(dbPath) { Wt::WBootstrapTheme *bootstrapTheme = new Wt::WBootstrapTheme(this); @@ -78,54 +79,107 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::p // Add a resource bundle messageResourceBundle().use(appRoot() + "templates"); - setTitle("LMS"); // application title + setTitle("LMS"); - // 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"); - navigation->setResponsive(true); - navigation->addStyleClass("main-nav"); + bool firstConnection; + { + Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession()); - Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(); + firstConnection = (Database::User::getAll(_sessionData.getDatabaseHandler().getSession()).size() == 0); + } - // Setup a Left-aligned menu. - Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack); - navigation->addMenu(leftMenu); + // If here is no account in the database, launch the first connection wizard + if (firstConnection) + { + // Hack, use the auth widget builtin strings + builtinLocalizedStrings().useBuiltin(skeletons::AuthStrings_xml1); - _audioWidget = new AudioWidget(_sessionData); - _videoWidget = new VideoWidget(_sessionData); + root()->addWidget( new Settings::FirstConnectionFormView(_sessionData)); + } + else + { + _sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent); - leftMenu->addItem("Audio", _audioWidget); - leftMenu->addItem("Video", _videoWidget); -// leftMenu->addItem("Settings", new Settings::Settings(_sessionData)); + LmsAuth *authWidget = new LmsAuth(_sessionData.getDatabaseHandler()); - // Setup a Right-aligned menu. - Wt::WMenu *rightMenu = new Wt::WMenu(); + authWidget->model()->addPasswordAuth(&Database::Handler::getPasswordService()); + authWidget->setRegistrationEnabled(false); - navigation->addMenu(rightMenu, Wt::AlignRight); + authWidget->processEnvironment(); - Wt::WPopupMenu *popup = new Wt::WPopupMenu(); - popup->addItem("Logout"); + root()->addWidget(authWidget); + } +} -// popup->itemSelected().connect(this, &LmsHome::handleUserMenuSelected); -/* Wt::WMenuItem *item = new Wt::WMenuItem( user.identity(Wt::Auth::Identity::LoginName) ); - item->setMenu(popup); - rightMenu->addItem(item);*/ +void +LmsApplication::handleAuthEvent(void) +{ + if (_sessionData.getDatabaseHandler().getLogin().loggedIn()) + { + Wt::Auth::User user(_sessionData.getDatabaseHandler().getLogin().user()); - // Add a Search control. -/* _searchEdit = new Wt::WLineEdit(); - _searchEdit->setEmptyText("Search..."); + // 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"); + navigation->setResponsive(true); + navigation->addStyleClass("main-nav"); - _searchEdit->enterPressed().connect(this, &LmsHome::handleSearch); -*/ -// navigation->addSearch(_searchEdit, Wt::AlignLeft); + Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(); - layout->addWidget(navigation); - layout->addWidget(contentsStack, 1); - layout->setContentsMargins(0, 0, 0, 0); + // Setup a Left-aligned menu. + Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack); + navigation->addMenu(leftMenu); + + AudioWidget *audioWidget = new AudioWidget(_sessionData); + VideoWidget *videoWidget = new VideoWidget(_sessionData); + + leftMenu->addItem("Audio", audioWidget); + leftMenu->addItem("Video", videoWidget); + leftMenu->addItem("Settings", new Settings::Settings(_sessionData)); + + // Setup a Right-aligned menu. + Wt::WMenu *rightMenu = new Wt::WMenu(); + + navigation->addMenu(rightMenu, Wt::AlignRight); + + Wt::WPopupMenu *popup = new Wt::WPopupMenu(); + popup->addItem("Logout"); + + Wt::WMenuItem *item = new Wt::WMenuItem( user.identity(Wt::Auth::Identity::LoginName) ); + item->setMenu(popup); + rightMenu->addItem(item); + + popup->itemSelected().connect(std::bind([=] (Wt::WMenuItem* item) + { + if (item && item->text() == "Logout") + _sessionData.getDatabaseHandler().getLogin().logout(); + }, std::placeholders::_1)); + + // Add a Search control. + Wt::WLineEdit *searchEdit = new Wt::WLineEdit(); + searchEdit->setEmptyText("Search..."); + + searchEdit->enterPressed().connect(std::bind([=] () + { + audioWidget->search(searchEdit->text().toUTF8()); + })); + + navigation->addSearch(searchEdit, Wt::AlignLeft); + + layout->addWidget(navigation); + layout->addWidget(contentsStack, 1); + layout->setContentsMargins(0, 0, 0, 0); + } + else + { + LMS_LOG(MOD_UI, SEV_NOTICE) << "User logged out"; + + quit(""); + redirect("/"); + } } } // namespace UserInterface diff --git a/src/ui/LmsApplication.hpp b/src/ui/LmsApplication.hpp index dfde66f8..6d4b1259 100644 --- a/src/ui/LmsApplication.hpp +++ b/src/ui/LmsApplication.hpp @@ -24,8 +24,6 @@ #include "common/SessionData.hpp" -#include "LmsHome.hpp" - namespace UserInterface { @@ -43,10 +41,6 @@ class LmsApplication : public Wt::WApplication SessionData _sessionData; - LmsHome* _home; - AudioWidget* _audioWidget; - VideoWidget* _videoWidget; - }; diff --git a/src/ui/LmsHome.cpp b/src/ui/LmsHome.cpp deleted file mode 100644 index d7433a78..00000000 --- a/src/ui/LmsHome.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2013 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 -#include -#include -#include -#include - -#include "settings/Settings.hpp" - -#include "LmsHome.hpp" - -namespace UserInterface { - -LmsHome::LmsHome(SessionData& sessionData, Wt::WContainerWidget* parent) -: Wt::WContainerWidget(parent), - _sessionData(sessionData) -{ - const Wt::Auth::User& user = sessionData.getDatabaseHandler().getLogin().user(); - - - -} - -void -LmsHome::handleUserMenuSelected( Wt::WMenuItem* item) -{ - if (item && item->text() == "Logout") { - _sessionData.getDatabaseHandler().getLogin().logout(); - } -} - -void -LmsHome::handleSearch(void) -{ - // TODO Check currently selected menu item and search it - _audioWidget->search( _searchEdit->text().toUTF8() ); -} - -} // namespace UserInterface diff --git a/src/ui/LmsHome.hpp b/src/ui/LmsHome.hpp deleted file mode 100644 index eb232421..00000000 --- a/src/ui/LmsHome.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2013 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 . - */ - -#ifndef LMS_HOME_HPP -#define LMS_HOME_HPP - -#include -#include - -#include "common/SessionData.hpp" - -#include "audio/AudioWidget.hpp" -#include "video/VideoWidget.hpp" - -namespace UserInterface { - -class LmsHome : public Wt::WContainerWidget -{ - public: - - LmsHome(SessionData& sessionData, Wt::WContainerWidget* parent = 0); - - private: - - void handleSearch(void); - void handleUserMenuSelected( Wt::WMenuItem* item ); - - SessionData& _sessionData; - - Wt::WLineEdit* _searchEdit; - AudioWidget* _audioWidget; - VideoWidget* _videoWidget; -}; - -} // namespace UserInterface - -#endif -