From d761949f86d275ebbdf9854f38e2cc28c6ba7789 Mon Sep 17 00:00:00 2001 From: Igor Nazarov Date: Tue, 20 Jun 2017 19:45:04 +0300 Subject: TizenRefApp-8716 [Gallery] Rename Presenter to GuiPresenter and move it into UCL Change-Id: I643d52b396092993912931b38397def1e196b7eb --- inc/gallery/presenters/AtspiHighlightHelper.h | 8 +- inc/gallery/presenters/Dialog.h | 4 +- inc/gallery/presenters/Dialog.hpp | 4 +- inc/gallery/presenters/MoreOptionsPresenter.h | 8 +- inc/gallery/presenters/Page.h | 4 +- inc/gallery/presenters/Page.hpp | 4 +- inc/gallery/presenters/Presenter.h | 108 ----------- inc/gallery/presenters/PreviewPage.h | 2 +- inc/gallery/presenters/ProcessingPresenter.h | 4 +- inc/gallery/presenters/SelectModePresenter.h | 10 +- inc/gallery/presenters/ThumbnailPage.h | 2 +- project_def.prop | 2 +- src/presenters/AtspiHighlightHelper.cpp | 10 +- src/presenters/Dialog.cpp | 2 +- src/presenters/MoreOptionsPresenter.cpp | 10 +- src/presenters/Page.cpp | 2 +- src/presenters/Presenter.cpp | 258 -------------------------- src/presenters/ProcessingPresenter.cpp | 6 +- src/presenters/SelectModePresenter.cpp | 10 +- ucl/inc/ucl/mvp/GuiPresenter.h | 108 +++++++++++ ucl/inc/ucl/mvp/types.h | 22 +++ ucl/src/mvp/GuiPresenter.cpp | 257 +++++++++++++++++++++++++ ucl/src/mvp/common.h | 22 +++ 23 files changed, 455 insertions(+), 412 deletions(-) delete mode 100644 inc/gallery/presenters/Presenter.h delete mode 100644 src/presenters/Presenter.cpp create mode 100644 ucl/inc/ucl/mvp/GuiPresenter.h create mode 100644 ucl/inc/ucl/mvp/types.h create mode 100644 ucl/src/mvp/GuiPresenter.cpp create mode 100644 ucl/src/mvp/common.h diff --git a/inc/gallery/presenters/AtspiHighlightHelper.h b/inc/gallery/presenters/AtspiHighlightHelper.h index 4175d57..650860e 100644 --- a/inc/gallery/presenters/AtspiHighlightHelper.h +++ b/inc/gallery/presenters/AtspiHighlightHelper.h @@ -17,19 +17,19 @@ #ifndef __GALLERY_PRESENTERS_ATSPI_HIGHLIGH_HELPER_H__ #define __GALLERY_PRESENTERS_ATSPI_HIGHLIGH_HELPER_H__ -#include "Presenter.h" +#include "ucl/mvp/GuiPresenter.h" namespace gallery { UCL_DECLARE_REF_ALIASES(AtspiHighlightHelper); - class AtspiHighlightHelper final : public Presenter { + class AtspiHighlightHelper final : public ucl::GuiPresenter { public: using EventHandler = ucl::WeakDelegate; public: - static AtspiHighlightHelperSRef newInstance(Presenter &parent, + static AtspiHighlightHelperSRef newInstance(GuiPresenter &parent, ucl::ElmWidget &rootWidget); void setEventHandler(EventHandler handler); @@ -40,7 +40,7 @@ namespace gallery { AtspiHighlightHelper(ucl::IRefCountObj &rc); virtual ~AtspiHighlightHelper(); - ucl::Result prepare(Presenter &parent, ucl::ElmWidget &rootWidget); + ucl::Result prepare(GuiPresenter &parent, ucl::ElmWidget &rootWidget); private: void onAtspiGesture(ucl::Widget &widget, void *eventInfo); diff --git a/inc/gallery/presenters/Dialog.h b/inc/gallery/presenters/Dialog.h index 9aa6246..f820c07 100644 --- a/inc/gallery/presenters/Dialog.h +++ b/inc/gallery/presenters/Dialog.h @@ -19,13 +19,13 @@ #include "ucl/gui/StyledWidget.h" -#include "Presenter.h" +#include "ucl/mvp/GuiPresenter.h" namespace gallery { UCL_DECLARE_REF_ALIASES(Dialog); - class Dialog : public Presenter, + class Dialog : public ucl::GuiPresenter, public ucl::IDisposable { public: void open(); diff --git a/inc/gallery/presenters/Dialog.hpp b/inc/gallery/presenters/Dialog.hpp index 35487b9..ed2c8f7 100644 --- a/inc/gallery/presenters/Dialog.hpp +++ b/inc/gallery/presenters/Dialog.hpp @@ -22,8 +22,8 @@ namespace gallery { inline ucl::Result Dialog::prepare(ucl::ElmWidget &parent, const PopupType popupType, ON_PREPARE &&onPrepare) { - UCL_FAIL_RETURN(Presenter::prepare(parent, PF_DEACTIVATOR), - "Presenter::prepare() failed!"); + UCL_FAIL_RETURN(GuiPresenter::prepare(parent, PF_DEACTIVATOR), + "GuiPresenter::prepare() failed!"); UCL_FAIL_RETURN(createPopup(parent, popupType), "createPopup() failed!"); diff --git a/inc/gallery/presenters/MoreOptionsPresenter.h b/inc/gallery/presenters/MoreOptionsPresenter.h index 88f45ca..72c605a 100644 --- a/inc/gallery/presenters/MoreOptionsPresenter.h +++ b/inc/gallery/presenters/MoreOptionsPresenter.h @@ -21,13 +21,13 @@ #include "ucl/misc/HashMap.h" -#include "Presenter.h" +#include "ucl/mvp/GuiPresenter.h" namespace gallery { UCL_DECLARE_REF_ALIASES(MoreOptionsPresenter); - class MoreOptionsPresenter final : public Presenter { + class MoreOptionsPresenter final : public ucl::GuiPresenter { public: UCL_DECLARE_REF_ALIASES(IListener); @@ -48,7 +48,7 @@ namespace gallery { Builder &clear(); Builder &addOption(Option option); Builder &setParentWidget(const ucl::ElmWidgetSRef &parentWidget); - MoreOptionsPresenterSRef build(Presenter &parent) const; + MoreOptionsPresenterSRef build(GuiPresenter &parent) const; private: ucl::SharedRef m_options; ucl::ElmWidgetSRef m_parentWidget; @@ -83,7 +83,7 @@ namespace gallery { const MoreOptionsCSRef &options); virtual ~MoreOptionsPresenter(); - ucl::Result prepare(Presenter &parent, ucl::ElmWidget &parentWidget); + ucl::Result prepare(GuiPresenter &parent, ucl::ElmWidget &parentWidget); ucl::Result addItem(const Option &option); bool resetTimer(double timeout); diff --git a/inc/gallery/presenters/Page.h b/inc/gallery/presenters/Page.h index 201ccc7..d8132dc 100644 --- a/inc/gallery/presenters/Page.h +++ b/inc/gallery/presenters/Page.h @@ -19,13 +19,13 @@ #include "ucl/gui/Naviframe.h" -#include "Presenter.h" +#include "ucl/mvp/GuiPresenter.h" namespace gallery { UCL_DECLARE_REF_ALIASES(Page); - class Page : public Presenter { + class Page : public ucl::GuiPresenter { public: using ExitRequestHandler = ucl::WeakDelegate; diff --git a/inc/gallery/presenters/Page.hpp b/inc/gallery/presenters/Page.hpp index 7a8fdbd..426445a 100644 --- a/inc/gallery/presenters/Page.hpp +++ b/inc/gallery/presenters/Page.hpp @@ -21,8 +21,8 @@ namespace gallery { template inline ucl::Result Page::prepare(ON_PREPARE &&onPrepare) { - UCL_FAIL_RETURN(Presenter::prepare(*m_navi), - "Presenter::prepare() failed!"); + UCL_FAIL_RETURN(GuiPresenter::prepare(*m_navi), + "GuiPresenter::prepare() failed!"); UCL_FAIL_RETURN(onPrepare(m_item), "onPrepare() failed!"); diff --git a/inc/gallery/presenters/Presenter.h b/inc/gallery/presenters/Presenter.h deleted file mode 100644 index ee39f0e..0000000 --- a/inc/gallery/presenters/Presenter.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __GALLERY_PRESENTERS_PRESENTER_H__ -#define __GALLERY_PRESENTERS_PRESENTER_H__ - -#include - -#include "ucl/gui/Window.h" - -#include "types.h" - -namespace gallery { - - UCL_DECLARE_REF_ALIASES(Presenter); - - class Presenter : public ucl::RefCountAware { - public: - struct DeactivatorInfo { - const void *deactivator; - bool isBroadcast; - }; - - public: - bool isActive() const; - bool isDeactivatedBy(const void *deactivator) const; - - void activateBy(const void *deactivator); - void deactivateBy(const void *deactivator); - - void addDeactivatorSource(ucl::Widget &source); - void delDeactivatorSource(ucl::Widget &source); - - protected: - enum { - PF_ADD_DEACTIVATOR_SOURCES = 1, - PF_ADD_SELF_EXCEPT = 2, - - PF_PASSIVE = 0, - PF_DEACTIVATOR = (PF_ADD_DEACTIVATOR_SOURCES | PF_ADD_SELF_EXCEPT), - PF_DEFAULT = PF_ADD_DEACTIVATOR_SOURCES - }; - - protected: - Presenter(ucl::IRefCountObj &rc); - virtual ~Presenter(); - - ucl::Result prepare(ucl::ElmWidget &widget, int flags = PF_DEFAULT); - ucl::Result prepare(Presenter &parent, int flags = PF_DEFAULT); - - ucl::Window &getWindow(); - bool isWindowReady() const; - - void addDeactivatorException(const void *deactivator); - void setDeactivatorSink(const ucl::WidgetSRef &sink); - - void sendActivate(ucl::Widget &sender); - void sendDeactivate(ucl::Widget &sender); - - void broadcastActivate(); - void broadcastDeactivate(); - - virtual void onActivate(); - virtual void onDeactivate(); - virtual void onActivateBy(const DeactivatorInfo &info); - virtual void onDeactivateBy(const DeactivatorInfo &info); - - private: - void sendDeactivator(ucl::Widget &sender, - ucl::SmartEvent event, const void *deactivator); - void broadcastDeactivator(ucl::SmartEvent event, - const void *deactivator); - - void sendDeactivatorInfo(ucl::Widget &sender, ucl::SmartEvent event, - const DeactivatorInfo &info); - - void activateByImpl(const DeactivatorInfo &info); - void deactivateByImpl(const DeactivatorInfo &info); - - void onActivateBySmart(ucl::Widget &widget, void *eventInfo); - void onDeactivateBySmart(ucl::Widget &widget, void *eventInfo); - - private: - std::unordered_set m_deactivatorExceptions; - std::unordered_set m_deactivators; - ucl::WindowSRef m_window; - ucl::WidgetSRef m_sink; - ucl::WidgetWRef m_parentSink; - bool m_hasBuildInSources; - bool m_isChild; - bool m_isPrepared; - }; -} - -#endif // __GALLERY_PRESENTERS_PRESENTER_H__ diff --git a/inc/gallery/presenters/PreviewPage.h b/inc/gallery/presenters/PreviewPage.h index 38d9798..5773ee4 100644 --- a/inc/gallery/presenters/PreviewPage.h +++ b/inc/gallery/presenters/PreviewPage.h @@ -94,7 +94,7 @@ namespace gallery { Elm_Interface_Atspi_Accessible *onAtspiHighlight( ucl::Widget &widget, Elm_Atspi_Relation_Type flowRelation); - // Presenter // + // GuiPresenter // virtual void onActivateBy(const DeactivatorInfo &info) final override; virtual void onDeactivateBy(const DeactivatorInfo &info) final override; diff --git a/inc/gallery/presenters/ProcessingPresenter.h b/inc/gallery/presenters/ProcessingPresenter.h index 94e1e80..9b54767 100644 --- a/inc/gallery/presenters/ProcessingPresenter.h +++ b/inc/gallery/presenters/ProcessingPresenter.h @@ -20,13 +20,13 @@ #include "ucl/gui/Layout.h" #include "ucl/gui/StyledWidget.h" -#include "Presenter.h" +#include "ucl/mvp/GuiPresenter.h" namespace gallery { UCL_DECLARE_REF_ALIASES(ProcessingPresenter); - class ProcessingPresenter final : public Presenter { + class ProcessingPresenter final : public ucl::GuiPresenter { public: enum class IconType { NONE, diff --git a/inc/gallery/presenters/SelectModePresenter.h b/inc/gallery/presenters/SelectModePresenter.h index 3cf1fa9..75c2e14 100644 --- a/inc/gallery/presenters/SelectModePresenter.h +++ b/inc/gallery/presenters/SelectModePresenter.h @@ -19,7 +19,7 @@ #include "ucl/gui/StyledWidget.h" -#include "Presenter.h" +#include "ucl/mvp/GuiPresenter.h" #include "gallery/view/PageContent.h" @@ -27,7 +27,7 @@ namespace gallery { UCL_DECLARE_REF_ALIASES(SelectModePresenter); - class SelectModePresenter final : public Presenter { + class SelectModePresenter final : public ucl::GuiPresenter { public: UCL_DECLARE_REF_ALIASES(IListener); @@ -43,7 +43,7 @@ namespace gallery { Builder(); Builder &setFlags(int flags); Builder &setPageContent(const PageContentSRef &content); - SelectModePresenterSRef build(Presenter &parent) const; + SelectModePresenterSRef build(GuiPresenter &parent) const; private: PageContentSRef m_content; int m_flags; @@ -79,7 +79,7 @@ namespace gallery { const PageContentSRef &content, int flags); virtual ~SelectModePresenter(); - ucl::Result prepare(Presenter &parent); + ucl::Result prepare(GuiPresenter &parent); void doUpdate(); @@ -100,7 +100,7 @@ namespace gallery { void onBottomBtnClick(ucl::Widget &widget, void *eventInfo); Eina_Bool onRotary(Eext_Rotary_Event_Info *info); - // Presenter // + // GuiPresenter // virtual void onDeactivate() final override; private: diff --git a/inc/gallery/presenters/ThumbnailPage.h b/inc/gallery/presenters/ThumbnailPage.h index 9ad821a..46beeed 100644 --- a/inc/gallery/presenters/ThumbnailPage.h +++ b/inc/gallery/presenters/ThumbnailPage.h @@ -69,7 +69,7 @@ namespace gallery { Elm_Interface_Atspi_Accessible *onAtspiHighlight( ucl::Widget &widget, Elm_Atspi_Relation_Type flowRelation); - // Presenter // + // GuiPresenter // virtual void onActivateBy(const DeactivatorInfo &info) final override; virtual void onDeactivateBy(const DeactivatorInfo &info) final override; diff --git a/project_def.prop b/project_def.prop index 0834ff8..b90d2da 100644 --- a/project_def.prop +++ b/project_def.prop @@ -9,7 +9,7 @@ type = app profile = wearable-4.0 # C/CPP Sources -USER_SRCS = ucl/src/gui/NaviItem.cpp src/resources.cpp ucl/src/gui/Layout.cpp src/model/Gallery.cpp src/presenters/ThumbnailPage.cpp src/view/PageContent.cpp src/presenters/ViewerPage.cpp src/presenters/Presenter.cpp ucl/src/appfw/UIApp.cpp src/model/MediaItem.cpp ucl/src/gui/ElmWidget.cpp ucl/src/appfw/helpers.cpp src/presenters/SelectModePresenter.cpp ucl/src/gui/EdjeWidget.cpp src/view/ImageViewer.cpp src/view/TouchParser.cpp ucl/src/gui/Window.cpp ucl/src/gui/Widget.cpp ucl/src/util/types/Result.cpp src/model/SoundManager.cpp src/model/GalleryAlbum.cpp src/presenters/Instance.cpp ucl/src/misc/Variant.cpp src/main.cpp src/presenters/internal.cpp src/presenters/InstanceManager.cpp src/presenters/AlertDialog.cpp src/model/BaseJob.cpp ucl/src/appfw/InstanceManagerBase.cpp src/presenters/VideoPlayerPage.cpp ucl/src/util/logging.cpp ucl/src/appfw/SysEventProvider.cpp src/view/helpers.cpp src/presenters/MoreOptionsPresenter.cpp src/presenters/PreviewPage.cpp src/presenters/NoContentPage.cpp src/model/internal.cpp src/presenters/ProcessingPresenter.cpp ucl/src/gui/Naviframe.cpp src/presenters/Page.cpp src/view/ImageGrid.cpp ucl/src/gui/WidgetItem.cpp +USER_SRCS = ucl/src/gui/NaviItem.cpp src/resources.cpp ucl/src/gui/Layout.cpp src/model/Gallery.cpp src/presenters/ThumbnailPage.cpp ucl/src/misc/Timeout.cpp src/view/PageContent.cpp src/presenters/ViewerPage.cpp ucl/src/appfw/UIApp.cpp src/model/MediaItem.cpp ucl/src/gui/ElmWidget.cpp ucl/src/appfw/helpers.cpp src/presenters/SelectModePresenter.cpp ucl/src/gui/EdjeWidget.cpp src/model/helpers.cpp src/view/ImageViewer.cpp src/presenters/AtspiHighlightHelper.cpp src/view/TouchParser.cpp ucl/src/gui/Window.cpp ucl/src/gui/Widget.cpp ucl/src/util/types/Result.cpp src/model/SoundManager.cpp src/model/GalleryAlbum.cpp src/presenters/Instance.cpp ucl/src/misc/Variant.cpp src/main.cpp src/presenters/InstanceManager.cpp src/presenters/AlertDialog.cpp src/model/BaseJob.cpp ucl/src/appfw/InstanceManagerBase.cpp src/presenters/VideoPlayerPage.cpp ucl/src/util/logging.cpp ucl/src/appfw/SysEventProvider.cpp src/view/helpers.cpp src/presenters/MoreOptionsPresenter.cpp src/presenters/PreviewPage.cpp ucl/src/mvp/GuiPresenter.cpp src/presenters/NoContentPage.cpp src/presenters/ProcessingPresenter.cpp ucl/src/gui/Naviframe.cpp src/presenters/Dialog.cpp src/presenters/Page.cpp src/view/ImageGrid.cpp src/presenters/helpers.cpp ucl/src/gui/WidgetItem.cpp # EDC Sources USER_EDCS = diff --git a/src/presenters/AtspiHighlightHelper.cpp b/src/presenters/AtspiHighlightHelper.cpp index d6f05c9..d960cb0 100644 --- a/src/presenters/AtspiHighlightHelper.cpp +++ b/src/presenters/AtspiHighlightHelper.cpp @@ -30,7 +30,7 @@ namespace gallery { using ucl::ATSPI_ON_GESTURE; AtspiHighlightHelperSRef AtspiHighlightHelper::newInstance( - Presenter &parent, ElmWidget &rootWidget) + GuiPresenter &parent, ElmWidget &rootWidget) { auto result = makeShared(); @@ -41,7 +41,7 @@ namespace gallery { } AtspiHighlightHelper::AtspiHighlightHelper(IRefCountObj &rc) : - Presenter(rc) + GuiPresenter(rc) { } @@ -49,11 +49,11 @@ namespace gallery { { } - Result AtspiHighlightHelper::prepare(Presenter &parent, + Result AtspiHighlightHelper::prepare(GuiPresenter &parent, ElmWidget &rootWidget) { - FAIL_RETURN(Presenter::prepare(parent), - "Presenter::prepare() failed!"); + FAIL_RETURN(GuiPresenter::prepare(parent), + "GuiPresenter::prepare() failed!"); registerWidget(rootWidget); diff --git a/src/presenters/Dialog.cpp b/src/presenters/Dialog.cpp index 3f16630..826b9fa 100644 --- a/src/presenters/Dialog.cpp +++ b/src/presenters/Dialog.cpp @@ -21,7 +21,7 @@ namespace gallery { Dialog::Dialog(IRefCountObj &rc) : - Presenter(rc), + GuiPresenter(rc), m_isDismissed(false) { } diff --git a/src/presenters/MoreOptionsPresenter.cpp b/src/presenters/MoreOptionsPresenter.cpp index 6a20b2d..f444293 100644 --- a/src/presenters/MoreOptionsPresenter.cpp +++ b/src/presenters/MoreOptionsPresenter.cpp @@ -90,7 +90,7 @@ namespace gallery { } MoreOptionsPresenterSRef MoreOptionsPresenter::Builder::build( - Presenter &parent) const + GuiPresenter &parent) const { if (isEmpty()) { LOG_RETURN_VALUE(RES_INVALID_ARGUMENTS, {}, "Builder is empty!"); @@ -112,7 +112,7 @@ namespace gallery { MoreOptionsPresenter::MoreOptionsPresenter(IRefCountObj &rc, const MoreOptionsCSRef &options) : - Presenter(rc), + GuiPresenter(rc), m_options(options), m_timer(nullptr), m_newOpenedState(false) @@ -127,11 +127,11 @@ namespace gallery { } } - Result MoreOptionsPresenter::prepare(Presenter &parent, + Result MoreOptionsPresenter::prepare(GuiPresenter &parent, ElmWidget &parentWidget) { - FAIL_RETURN(Presenter::prepare(parent, PF_DEACTIVATOR), - "Presenter::prepare() failed!"); + FAIL_RETURN(GuiPresenter::prepare(parent, PF_DEACTIVATOR), + "GuiPresenter::prepare() failed!"); Evas_Object *const more = eext_more_option_add(parentWidget); if (!more) { diff --git a/src/presenters/Page.cpp b/src/presenters/Page.cpp index 9ccf2ed..ae3f71e 100644 --- a/src/presenters/Page.cpp +++ b/src/presenters/Page.cpp @@ -33,7 +33,7 @@ namespace gallery { Page::Page(IRefCountObj &rc, const NaviframeSRef &navi, const ExitRequestHandler &onExitRequest) : - Presenter(rc), + GuiPresenter(rc), m_navi(navi), m_onExitRequest(onExitRequest) { diff --git a/src/presenters/Presenter.cpp b/src/presenters/Presenter.cpp deleted file mode 100644 index c2e34f0..0000000 --- a/src/presenters/Presenter.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gallery/presenters/Presenter.h" - -#include "common.h" - -namespace gallery { namespace { namespace impl { - - constexpr SmartEvent ACTIVATE_BY {"gallery,activate,by"}; - constexpr SmartEvent DEACTIVATE_BY {"gallery,deactivate,by"}; -}}} - -namespace gallery { - - using ucl::Window; - - Presenter::Presenter(IRefCountObj &rc) : - RefCountAware(&rc), - m_hasBuildInSources(false), - m_isChild(false), - m_isPrepared(false) - { - } - - Presenter::~Presenter() - { - if (m_hasBuildInSources) { - if (m_isChild) { - if (const auto parentSink = m_parentSink.lock()) { - delDeactivatorSource(*parentSink); - } - } else if (m_window) { - delDeactivatorSource(*m_window); - } - } - } - - Result Presenter::prepare(ElmWidget &widget, const int flags) - { - m_window = asShared(widget.getWindow()); - if (!m_window) { - LOG_RETURN(RES_FAIL, "m_window is NULL!"); - } - - if (flags & PF_ADD_DEACTIVATOR_SOURCES) { - addDeactivatorSource(*m_window); - m_hasBuildInSources = true; - } - - if (flags & PF_ADD_SELF_EXCEPT) { - addDeactivatorException(m_rc->getObjPtr()); - } - - m_isPrepared = true; - - return RES_OK; - } - - Result Presenter::prepare(Presenter &parent, const int flags) - { - if (!parent.m_sink) { - LOG_RETURN(RES_FAIL, "parent.m_sink is NULL!"); - } - - for (auto deactivator: parent.m_deactivators) { - if (m_deactivatorExceptions.find(deactivator) == - m_deactivatorExceptions.end()) { - m_deactivators.insert(deactivator); - } - } - - if (flags & PF_ADD_DEACTIVATOR_SOURCES) { - addDeactivatorSource(*parent.m_sink); - m_hasBuildInSources = true; - } - - if (flags & PF_ADD_SELF_EXCEPT) { - addDeactivatorException(m_rc->getObjPtr()); - } - - m_window = parent.m_window; - m_parentSink = parent.m_sink; - m_isChild = true; - m_isPrepared = true; - - return RES_OK; - } - - Window &Presenter::getWindow() - { - UCL_ASSERT(isWindowReady(), "m_window is NULL!"); - return *m_window; - } - - bool Presenter::isWindowReady() const - { - return !!m_window; - } - - void Presenter::addDeactivatorException(const void *const deactivator) - { - const auto pair = m_deactivatorExceptions.insert(deactivator); - if (pair.second) { - activateBy(deactivator); - } - } - - void Presenter::setDeactivatorSink(const WidgetSRef &sink) - { - m_sink = sink; - } - - void Presenter::sendActivate(Widget &sender) - { - sendDeactivator(sender, impl::ACTIVATE_BY, m_rc->getObjPtr()); - } - - void Presenter::sendDeactivate(Widget &sender) - { - sendDeactivator(sender, impl::DEACTIVATE_BY, m_rc->getObjPtr()); - } - - void Presenter::broadcastActivate() - { - broadcastDeactivator(impl::ACTIVATE_BY, m_rc->getObjPtr()); - } - - void Presenter::broadcastDeactivate() - { - broadcastDeactivator(impl::DEACTIVATE_BY, m_rc->getObjPtr()); - } - - void Presenter::sendDeactivator(Widget &sender, - SmartEvent event, const void *deactivator) - { - sendDeactivatorInfo(sender, event, {deactivator, false}); - } - - void Presenter::broadcastDeactivator(const SmartEvent event, - const void *const deactivator) - { - sendDeactivatorInfo(*m_window, event, {deactivator, true}); - } - - void Presenter::sendDeactivatorInfo(Widget &sender, - const SmartEvent event, const DeactivatorInfo &info) - { - sender.callEvent(event, const_cast(&info)); - } - - bool Presenter::isActive() const - { - return isEmpty(m_deactivators); - } - - bool Presenter::isDeactivatedBy(const void *const deactivator) const - { - return (m_deactivators.find(deactivator) != m_deactivators.end()); - } - - void Presenter::activateBy(const void *const deactivator) - { - activateByImpl({deactivator, false}); - } - - void Presenter::deactivateBy(const void *const deactivator) - { - deactivateByImpl({deactivator, false}); - } - - void Presenter::addDeactivatorSource(Widget &source) - { - source.addEventHandler(impl::ACTIVATE_BY, - WEAK_DELEGATE(Presenter::onActivateBySmart, asWeak(*this))); - source.addEventHandler(impl::DEACTIVATE_BY, - WEAK_DELEGATE(Presenter::onDeactivateBySmart, asWeak(*this))); - } - - void Presenter::delDeactivatorSource(Widget &source) - { - source.delEventHandler(impl::ACTIVATE_BY, - WEAK_DELEGATE(Presenter::onActivateBySmart, asWeak(*this))); - source.delEventHandler(impl::DEACTIVATE_BY, - WEAK_DELEGATE(Presenter::onDeactivateBySmart, asWeak(*this))); - } - - void Presenter::activateByImpl(const DeactivatorInfo &info) - { - const auto count = m_deactivators.erase(info.deactivator); - if (m_isPrepared && (count > 0)) { - if (m_sink) { - sendDeactivatorInfo(*m_sink, impl::ACTIVATE_BY, info); - } - onActivateBy(info); - if (m_deactivators.size() == 0) { - onActivate(); - } - } - } - - void Presenter::deactivateByImpl(const DeactivatorInfo &info) - { - if (m_deactivatorExceptions.find(info.deactivator) != - m_deactivatorExceptions.end()) { - return; - } - const auto pair = m_deactivators.insert(info.deactivator); - if (m_isPrepared && pair.second) { - if (m_sink) { - sendDeactivatorInfo(*m_sink, impl::DEACTIVATE_BY, info); - } - onDeactivateBy(info); - if (m_deactivators.size() == 1) { - onDeactivate(); - } - } - } - - void Presenter::onActivateBySmart(Widget &widget, void *eventInfo) - { - activateByImpl(*static_cast(eventInfo)); - } - - void Presenter::onDeactivateBySmart(Widget &widget, void *eventInfo) - { - deactivateByImpl(*static_cast(eventInfo)); - } - - void Presenter::onActivate() - { - } - - void Presenter::onDeactivate() - { - } - - void Presenter::onActivateBy(const DeactivatorInfo &info) - { - } - - void Presenter::onDeactivateBy(const DeactivatorInfo &info) - { - } -} diff --git a/src/presenters/ProcessingPresenter.cpp b/src/presenters/ProcessingPresenter.cpp index 3d1ad21..7238837 100644 --- a/src/presenters/ProcessingPresenter.cpp +++ b/src/presenters/ProcessingPresenter.cpp @@ -87,7 +87,7 @@ namespace gallery { // ProcessingPresenter // ProcessingPresenter::ProcessingPresenter(IRefCountObj &rc) : - Presenter(rc), + GuiPresenter(rc), m_iconType(IconType::NONE), m_timer(nullptr), m_state(State::WAITING), @@ -107,8 +107,8 @@ namespace gallery { const TString &processingText, const bool forceProgress) { - FAIL_RETURN(Presenter::prepare(parent, PF_PASSIVE), - "Presenter::prepare() failed!"); + FAIL_RETURN(GuiPresenter::prepare(parent, PF_PASSIVE), + "GuiPresenter::prepare() failed!"); FAIL_RETURN(createWidget(parent, processingText), "createWidget() failed!"); diff --git a/src/presenters/SelectModePresenter.cpp b/src/presenters/SelectModePresenter.cpp index b9b333c..a63c624 100644 --- a/src/presenters/SelectModePresenter.cpp +++ b/src/presenters/SelectModePresenter.cpp @@ -60,7 +60,7 @@ namespace gallery { } SelectModePresenterSRef SelectModePresenter::Builder::build( - Presenter &parent) const + GuiPresenter &parent) const { if (!m_content) { LOG_RETURN_VALUE(RES_INVALID_ARGUMENTS, {}, "m_content is NULL!"); @@ -78,7 +78,7 @@ namespace gallery { SelectModePresenter::SelectModePresenter(IRefCountObj &rc, const PageContentSRef &content, const int flags) : - Presenter(rc), + GuiPresenter(rc), m_content(content), m_flags(flags), m_totalCount(0), @@ -97,10 +97,10 @@ namespace gallery { deletePopup(); } - Result SelectModePresenter::prepare(Presenter &parent) + Result SelectModePresenter::prepare(GuiPresenter &parent) { - FAIL_RETURN(Presenter::prepare(parent, PF_DEACTIVATOR), - "Presenter::prepare() failed!"); + FAIL_RETURN(GuiPresenter::prepare(parent, PF_DEACTIVATOR), + "GuiPresenter::prepare() failed!"); m_selectButton = makeShared( elm_button_add(*m_content), true); diff --git a/ucl/inc/ucl/mvp/GuiPresenter.h b/ucl/inc/ucl/mvp/GuiPresenter.h new file mode 100644 index 0000000..f81bcac --- /dev/null +++ b/ucl/inc/ucl/mvp/GuiPresenter.h @@ -0,0 +1,108 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UCL_MVP_GUI_PRESENTER_H__ +#define __UCL_MVP_GUI_PRESENTER_H__ + +#include + +#include "ucl/gui/Window.h" + +#include "types.h" + +namespace ucl { + + UCL_DECLARE_REF_ALIASES(GuiPresenter); + + class GuiPresenter : public RefCountAware { + public: + struct DeactivatorInfo { + const void *deactivator; + bool isBroadcast; + }; + + public: + bool isActive() const; + bool isDeactivatedBy(const void *deactivator) const; + + void activateBy(const void *deactivator); + void deactivateBy(const void *deactivator); + + void addDeactivatorSource(Widget &source); + void delDeactivatorSource(Widget &source); + + protected: + enum { + PF_ADD_DEACTIVATOR_SOURCES = 1, + PF_ADD_SELF_EXCEPT = 2, + + PF_PASSIVE = 0, + PF_DEACTIVATOR = (PF_ADD_DEACTIVATOR_SOURCES | PF_ADD_SELF_EXCEPT), + PF_DEFAULT = PF_ADD_DEACTIVATOR_SOURCES + }; + + protected: + GuiPresenter(IRefCountObj &rc); + virtual ~GuiPresenter(); + + Result prepare(ElmWidget &widget, int flags = PF_DEFAULT); + Result prepare(GuiPresenter &parent, int flags = PF_DEFAULT); + + Window &getWindow(); + bool isWindowReady() const; + + void addDeactivatorException(const void *deactivator); + void setDeactivatorSink(const WidgetSRef &sink); + + void sendActivate(Widget &sender); + void sendDeactivate(Widget &sender); + + void broadcastActivate(); + void broadcastDeactivate(); + + virtual void onActivate(); + virtual void onDeactivate(); + virtual void onActivateBy(const DeactivatorInfo &info); + virtual void onDeactivateBy(const DeactivatorInfo &info); + + private: + void sendDeactivator(Widget &sender, + SmartEvent event, const void *deactivator); + void broadcastDeactivator(SmartEvent event, + const void *deactivator); + + void sendDeactivatorInfo(Widget &sender, SmartEvent event, + const DeactivatorInfo &info); + + void activateByImpl(const DeactivatorInfo &info); + void deactivateByImpl(const DeactivatorInfo &info); + + void onActivateBySmart(Widget &widget, void *eventInfo); + void onDeactivateBySmart(Widget &widget, void *eventInfo); + + private: + std::unordered_set m_deactivatorExceptions; + std::unordered_set m_deactivators; + WindowSRef m_window; + WidgetSRef m_sink; + WidgetWRef m_parentSink; + bool m_hasBuildInSources; + bool m_isChild; + bool m_isPrepared; + }; +} + +#endif // __UCL_MVP_GUI_PRESENTER_H__ diff --git a/ucl/inc/ucl/mvp/types.h b/ucl/inc/ucl/mvp/types.h new file mode 100644 index 0000000..6c263e2 --- /dev/null +++ b/ucl/inc/ucl/mvp/types.h @@ -0,0 +1,22 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UCL_MVP_TYPES_H__ +#define __UCL_MVP_TYPES_H__ + +#include "ucl/gui/types.h" + +#endif // __UCL_MVP_TYPES_H__ diff --git a/ucl/src/mvp/GuiPresenter.cpp b/ucl/src/mvp/GuiPresenter.cpp new file mode 100644 index 0000000..e7d7bd9 --- /dev/null +++ b/ucl/src/mvp/GuiPresenter.cpp @@ -0,0 +1,257 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ucl/mvp/GuiPresenter.h" + +#include "common.h" + +namespace ucl { namespace { namespace impl { + + constexpr SmartEvent ACTIVATE_BY {"ucl,activate,by"}; + constexpr SmartEvent DEACTIVATE_BY {"ucl,deactivate,by"}; +}}} + +namespace ucl { + + GuiPresenter::GuiPresenter(IRefCountObj &rc) : + RefCountAware(&rc), + m_hasBuildInSources(false), + m_isChild(false), + m_isPrepared(false) + { + } + + GuiPresenter::~GuiPresenter() + { + if (m_hasBuildInSources) { + if (m_isChild) { + if (const auto parentSink = m_parentSink.lock()) { + delDeactivatorSource(*parentSink); + } + } else if (m_window) { + delDeactivatorSource(*m_window); + } + } + } + + Result GuiPresenter::prepare(ElmWidget &widget, const int flags) + { + m_window = asShared(widget.getWindow()); + if (!m_window) { + LOG_RETURN(RES_FAIL, "m_window is NULL!"); + } + + if (flags & PF_ADD_DEACTIVATOR_SOURCES) { + addDeactivatorSource(*m_window); + m_hasBuildInSources = true; + } + + if (flags & PF_ADD_SELF_EXCEPT) { + addDeactivatorException(m_rc->getObjPtr()); + } + + m_isPrepared = true; + + return RES_OK; + } + + Result GuiPresenter::prepare(GuiPresenter &parent, const int flags) + { + if (flags & PF_ADD_DEACTIVATOR_SOURCES) { + + if (!parent.m_sink) { + LOG_RETURN(RES_FAIL, "parent.m_sink is NULL!"); + } + + for (auto deactivator: parent.m_deactivators) { + if (m_deactivatorExceptions.find(deactivator) == + m_deactivatorExceptions.end()) { + m_deactivators.insert(deactivator); + } + } + + addDeactivatorSource(*parent.m_sink); + m_parentSink = parent.m_sink; + m_hasBuildInSources = true; + } + + if (flags & PF_ADD_SELF_EXCEPT) { + addDeactivatorException(m_rc->getObjPtr()); + } + + m_window = parent.m_window; + m_isChild = true; + m_isPrepared = true; + + return RES_OK; + } + + Window &GuiPresenter::getWindow() + { + UCL_ASSERT(isWindowReady(), "m_window is NULL!"); + return *m_window; + } + + bool GuiPresenter::isWindowReady() const + { + return !!m_window; + } + + void GuiPresenter::addDeactivatorException(const void *const deactivator) + { + const auto pair = m_deactivatorExceptions.insert(deactivator); + if (pair.second) { + activateBy(deactivator); + } + } + + void GuiPresenter::setDeactivatorSink(const WidgetSRef &sink) + { + m_sink = sink; + } + + void GuiPresenter::sendActivate(Widget &sender) + { + sendDeactivator(sender, impl::ACTIVATE_BY, m_rc->getObjPtr()); + } + + void GuiPresenter::sendDeactivate(Widget &sender) + { + sendDeactivator(sender, impl::DEACTIVATE_BY, m_rc->getObjPtr()); + } + + void GuiPresenter::broadcastActivate() + { + broadcastDeactivator(impl::ACTIVATE_BY, m_rc->getObjPtr()); + } + + void GuiPresenter::broadcastDeactivate() + { + broadcastDeactivator(impl::DEACTIVATE_BY, m_rc->getObjPtr()); + } + + void GuiPresenter::sendDeactivator(Widget &sender, + SmartEvent event, const void *deactivator) + { + sendDeactivatorInfo(sender, event, {deactivator, false}); + } + + void GuiPresenter::broadcastDeactivator(const SmartEvent event, + const void *const deactivator) + { + sendDeactivatorInfo(*m_window, event, {deactivator, true}); + } + + void GuiPresenter::sendDeactivatorInfo(Widget &sender, + const SmartEvent event, const DeactivatorInfo &info) + { + sender.callEvent(event, const_cast(&info)); + } + + bool GuiPresenter::isActive() const + { + return isEmpty(m_deactivators); + } + + bool GuiPresenter::isDeactivatedBy(const void *const deactivator) const + { + return (m_deactivators.find(deactivator) != m_deactivators.end()); + } + + void GuiPresenter::activateBy(const void *const deactivator) + { + activateByImpl({deactivator, false}); + } + + void GuiPresenter::deactivateBy(const void *const deactivator) + { + deactivateByImpl({deactivator, false}); + } + + void GuiPresenter::addDeactivatorSource(Widget &source) + { + source.addEventHandler(impl::ACTIVATE_BY, WEAK_DELEGATE( + GuiPresenter::onActivateBySmart, asWeak(*this))); + source.addEventHandler(impl::DEACTIVATE_BY, WEAK_DELEGATE( + GuiPresenter::onDeactivateBySmart, asWeak(*this))); + } + + void GuiPresenter::delDeactivatorSource(Widget &source) + { + source.delEventHandler(impl::ACTIVATE_BY, WEAK_DELEGATE( + GuiPresenter::onActivateBySmart, asWeak(*this))); + source.delEventHandler(impl::DEACTIVATE_BY, WEAK_DELEGATE( + GuiPresenter::onDeactivateBySmart, asWeak(*this))); + } + + void GuiPresenter::activateByImpl(const DeactivatorInfo &info) + { + const auto count = m_deactivators.erase(info.deactivator); + if (m_isPrepared && (count > 0)) { + if (m_sink) { + sendDeactivatorInfo(*m_sink, impl::ACTIVATE_BY, info); + } + onActivateBy(info); + if (m_deactivators.size() == 0) { + onActivate(); + } + } + } + + void GuiPresenter::deactivateByImpl(const DeactivatorInfo &info) + { + if (m_deactivatorExceptions.find(info.deactivator) != + m_deactivatorExceptions.end()) { + return; + } + const auto pair = m_deactivators.insert(info.deactivator); + if (m_isPrepared && pair.second) { + if (m_sink) { + sendDeactivatorInfo(*m_sink, impl::DEACTIVATE_BY, info); + } + onDeactivateBy(info); + if (m_deactivators.size() == 1) { + onDeactivate(); + } + } + } + + void GuiPresenter::onActivateBySmart(Widget &widget, void *eventInfo) + { + activateByImpl(*static_cast(eventInfo)); + } + + void GuiPresenter::onDeactivateBySmart(Widget &widget, void *eventInfo) + { + deactivateByImpl(*static_cast(eventInfo)); + } + + void GuiPresenter::onActivate() + { + } + + void GuiPresenter::onDeactivate() + { + } + + void GuiPresenter::onActivateBy(const DeactivatorInfo &info) + { + } + + void GuiPresenter::onDeactivateBy(const DeactivatorInfo &info) + { + } +} diff --git a/ucl/src/mvp/common.h b/ucl/src/mvp/common.h new file mode 100644 index 0000000..2894a14 --- /dev/null +++ b/ucl/src/mvp/common.h @@ -0,0 +1,22 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UCL_MVP_COMMON_H__ +#define __UCL_MVP_COMMON_H__ + +#include "../common.h" + +#endif // __UCL_MVP_COMMON_H__ -- cgit v1.2.3