[Gallery] Simplified MoreOptionsPresenter::Builder implementation 60/146760/2
authorIgor Nazarov <i.nazarov@samsung.com>
Wed, 30 Aug 2017 09:10:55 +0000 (12:10 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Wed, 30 Aug 2017 09:45:37 +0000 (12:45 +0300)
Change-Id: Ib78ed9f8b3a2cd5883542dd17c7e357c1265c61b

gallery/presenters/misc/MoreOptionsPresenter.cpp
gallery/presenters/misc/MoreOptionsPresenter.h
gallery/presenters/pages/PreviewPage.cpp
gallery/presenters/pages/PreviewPage.h
gallery/presenters/pages/ThumbnailPage.cpp
gallery/presenters/pages/ThumbnailPage.h

index f2fa2c927aea0ea54ffbfb4756c1c394e63d1f6d..d587e86e7a4c639f554819695fd5832b75c46e6a 100644 (file)
@@ -61,7 +61,8 @@ namespace gallery {
 
        bool MoreOptionsPresenter::Builder::isEmpty() const
        {
-               return ucl::isEmpty(m_options);
+               using ucl::isEmpty;
+               return isEmpty(m_options);
        }
 
        MoreOptionsPresenter::Builder &MoreOptionsPresenter::Builder::clear()
@@ -73,12 +74,7 @@ namespace gallery {
        MoreOptionsPresenter::Builder &MoreOptionsPresenter::Builder::addOption(
                        Option option)
        {
-               if (!m_options) {
-                       m_options = makeShared<MoreOptions>();
-               } else if (m_options.getUseCount() > 1) {
-                       m_options = makeShared<MoreOptions>(*m_options);
-               }
-               m_options->emplace_back(std::move(option));
+               m_options.emplace_back(std::move(option));
                return *this;
        }
 
@@ -100,9 +96,10 @@ namespace gallery {
                                        "m_parentWidget is NULL!");
                }
 
-               auto result = makeShared<MoreOptionsPresenter>(m_options);
+               auto result = makeShared<MoreOptionsPresenter>();
 
-               FAIL_RETURN_VALUE(result->prepare(parent, *m_parentWidget), {},
+               FAIL_RETURN_VALUE(result->prepare(parent,
+                               *m_parentWidget, m_options), {},
                                "result->prepare() failed!");
 
                return result;
@@ -110,10 +107,8 @@ namespace gallery {
 
        // MoreOptionsPresenter //
 
-       MoreOptionsPresenter::MoreOptionsPresenter(IRefCountObj &rc,
-                       const MoreOptionsCSRef &options) :
+       MoreOptionsPresenter::MoreOptionsPresenter(IRefCountObj &rc) :
                GuiPresenter(rc),
-               m_options(options),
                m_timer(nullptr),
                m_newOpenedState(false)
        {
@@ -128,7 +123,7 @@ namespace gallery {
        }
 
        Result MoreOptionsPresenter::prepare(GuiPresenter &parent,
-                       ElmWidget &parentWidget)
+                       ElmWidget &parentWidget, const std::list<Option> &options)
        {
                FAIL_RETURN(GuiPresenter::prepare(parent, PF_DEACTIVATOR),
                                "GuiPresenter::prepare() failed!");
@@ -141,7 +136,7 @@ namespace gallery {
                const auto layout = makeShared<Layout>(more, true);
                m_widget = layout;
 
-               for (auto &option: *m_options) {
+               for (auto &option: options) {
                        FAIL_RETURN(addItem(option), "addItem() failed!");
                }
 
@@ -184,7 +179,7 @@ namespace gallery {
                impl::setText(item, option.text, impl::PART_MAIN_TEXT);
                impl::setText(item, option.subText, impl::PART_SUB_TEXT);
 
-               m_map.set(item, &option);
+               m_map.set(item, option.id);
 
                return RES_OK;
        }
@@ -248,9 +243,9 @@ namespace gallery {
                        return;
                }
                if (const auto listener = m_listener.lock()) {
-                       const auto item = m_map.get(eventInfo);
-                       if (item) {
-                               listener->onMoreOptionClicked(*this, *item);
+                       int optionId = 0;
+                       if (m_map.get(eventInfo, optionId)) {
+                               listener->onMoreOptionClicked(*this, optionId);
                        } else {
                                ELOG("Invalid eventInfo!");
                        }
@@ -260,9 +255,9 @@ namespace gallery {
        void MoreOptionsPresenter::onItemSelected(Widget &widget, void *eventInfo)
        {
                if (const auto listener = m_listener.lock()) {
-                       const auto item = m_map.get(eventInfo);
-                       if (item) {
-                               listener->onMoreOptionSelected(*this, *item);
+                       int optionId = 0;
+                       if (m_map.get(eventInfo, optionId)) {
+                               listener->onMoreOptionSelected(*this, optionId);
                        } else {
                                ELOG("Invalid eventInfo!");
                        }
index 95b432b9e6a491b21d748119ee5aea000b9206d9..9a53249a06aa0c9490a33f9a35d8a5415d97d802 100644 (file)
@@ -38,8 +38,6 @@ namespace gallery {
                        ucl::LayoutTheme iconTheme;
                };
 
-               using MoreOptions = std::list<Option>;
-
                class Builder final {
                public:
                        Builder();
@@ -50,16 +48,16 @@ namespace gallery {
                        Builder &setParentWidget(const ucl::ElmWidgetSRef &parentWidget);
                        MoreOptionsPresenterSRef build(GuiPresenter &parent) const;
                private:
-                       ucl::SharedRef<MoreOptions> m_options;
+                       std::list<Option> m_options;
                        ucl::ElmWidgetSRef m_parentWidget;
                };
 
                class IListener : public ucl::Polymorphic {
                public:
                        virtual void onMoreOptionClicked(MoreOptionsPresenter &sender,
-                                       const Option &option) = 0;
+                                       int optionId) = 0;
                        virtual void onMoreOptionSelected(MoreOptionsPresenter &sender,
-                                       const Option &option) {};
+                                       int optionId) {};
                        virtual void onMoreOptionsOpened(MoreOptionsPresenter &sender) {};
                        virtual void onMoreOptionsClosed(MoreOptionsPresenter &sender) {};
                };
@@ -74,16 +72,13 @@ namespace gallery {
 
                void setOpenedDelayed(bool isOpened, double timeout);
 
-       private:
-               using MoreOptionsCSRef = ucl::SharedRef<const MoreOptions>;
-
        private:
                friend class ucl::ReffedObj<MoreOptionsPresenter>;
-               MoreOptionsPresenter(ucl::IRefCountObj &rc,
-                               const MoreOptionsCSRef &options);
+               MoreOptionsPresenter(ucl::IRefCountObj &rc);
                virtual ~MoreOptionsPresenter();
 
-               ucl::Result prepare(GuiPresenter &parent, ucl::ElmWidget &parentWidget);
+               ucl::Result prepare(GuiPresenter &parent, ucl::ElmWidget &parentWidget,
+                               const std::list<Option> &options);
                ucl::Result addItem(const Option &option);
 
                bool resetTimer(double timeout);
@@ -97,8 +92,7 @@ namespace gallery {
                void onItemSelected(ucl::Widget &widget, void *eventInfo);
 
        private:
-               const MoreOptionsCSRef m_options;
-               ucl::HashMap<void *, const Option *> m_map;
+               ucl::HashMap<void *, int> m_map;
                ucl::ElmWidgetSRef m_widget;
                IListenerWRef m_listener;
                Ecore_Timer *m_timer;
index 75b2d83969235bb3115efd47e64876a8deb16ae5..a406a4f8b83469dda7be2ab047b698eb9279d764 100644 (file)
@@ -550,9 +550,9 @@ namespace gallery {
        }
 
        void PreviewPage::onMoreOptionClicked(MoreOptionsPresenter &sender,
-                       const MoreOptionsPresenter::Option &option)
+                       const int optionId)
        {
-               switch (option.id) {
+               switch (optionId) {
                case impl::MORE_OPTION_ID_DELETE:
                        sender.setOpenedDelayed(false, impl::POPUP_SHOW_TIME_SEC);
                        confirmItemsDelete();
@@ -563,7 +563,7 @@ namespace gallery {
                        break;
                default:
                        sender.setOpened(false);
-                       WLOG("Unknown option id: %d;", option.id);
+                       WLOG("Unknown option id: %d;", optionId);
                        break;
                }
        }
index 21a639105c4a465dce6d73182adc382e8af0fc81..600d51d11cd82810de3c8867293bf760a7a93b63 100644 (file)
@@ -129,7 +129,7 @@ namespace gallery {
                // MoreOptionsPresenter::IListener //
 
                virtual void onMoreOptionClicked(MoreOptionsPresenter &sender,
-                               const MoreOptionsPresenter::Option &option) final override;
+                               int optionId) final override;
 
                // SelectModePresenter::IListener //
 
index 2ae01303c842c64115a2a0e1eb83128e5c0e900e..f33effbd68ded624659202ebe57481a95c8d2586 100644 (file)
@@ -319,9 +319,9 @@ namespace gallery {
        }
 
        void ThumbnailPage::onMoreOptionClicked(MoreOptionsPresenter &sender,
-                       const MoreOptionsPresenter::Option &option)
+                       const int optionId)
        {
-               switch (option.id) {
+               switch (optionId) {
                case impl::MORE_OPTION_ID_DELETE:
                        sender.setOpenedDelayed(false, impl::NAVIFRAME_TRANSITION_TIME_SEC);
                        m_page = PreviewPage::Builder().
@@ -334,7 +334,7 @@ namespace gallery {
                        break;
                default:
                        sender.setOpened(false);
-                       WLOG("Unknown option id: %d;", option.id);
+                       WLOG("Unknown option id: %d;", optionId);
                        break;
                }
        }
index 05f97f03b5517bfa495d0455edba6d9318bc8dc5..2eb52ecb269e01ec615e64745a3bb6b53bafa909 100644 (file)
@@ -84,7 +84,7 @@ namespace gallery {
                // MoreOptionsPresenter::IListener //
 
                virtual void onMoreOptionClicked(MoreOptionsPresenter &sender,
-                               const MoreOptionsPresenter::Option &option) final override;
+                               int optionId) final override;
 
        private:
                class RealizedItem;