TizenRefApp-5595 Implement Controller for progress popup 16/58816/2
authorNataliia Sydorchuk <n.sydorchuk@samsung.com>
Wed, 3 Feb 2016 16:18:48 +0000 (18:18 +0200)
committerNataliia Sydorchuk <n.sydorchuk@samsung.com>
Wed, 3 Feb 2016 16:22:18 +0000 (18:22 +0200)
Implementation: Edited callback on back event in Popup. Fixed warnings.

Change-Id: Ia04d176761fac7fc4e750ebb33117db0faca1ad1
Signed-off-by: Nataliia Sydorchuk <n.sydorchuk@samsung.com>
lib-common/inc/Ui/Popup.h
lib-common/src/Ui/Popup.cpp
lib-common/src/Ui/ProgressPopup.cpp

index 9f1e682..319ac7a 100644 (file)
@@ -34,6 +34,12 @@ namespace Ui
                 */
                typedef std::function<bool()> ButtonCallback;
 
+               /**
+                * @brief Back button pressed callback
+                * @return true to destroy the Popup, otherwise false
+                */
+               typedef std::function<bool()> BackCallback;
+
                Popup();
 
                /**
@@ -78,14 +84,22 @@ namespace Ui
                 */
                Evas_Object *addButton(const char *text, ButtonCallback callback = nullptr);
 
+               /**
+                * @brief Set callback on back button
+                * @param[in]   callback    Back callback
+                */
+               void setBackCallback(BackCallback callback);
+
        protected:
                virtual Evas_Object *onCreate(Evas_Object *parent) override;
 
        private:
                void onButtonPressed(Evas_Object *obj, void *eventInfo);
+               void onBackPressed(Evas_Object *obj, void *eventInfo);
 
                ButtonCallback m_ButtonCbs[POPUP_BUTTON_MAX_COUNT];
                size_t m_ButtonCount;
+               BackCallback m_OnBack;
        };
 }
 
index 09b0b65..9509d13 100644 (file)
@@ -81,6 +81,11 @@ Evas_Object *Popup::addButton(const char *text, ButtonCallback callback)
        return button;
 }
 
+void Popup::setBackCallback(BackCallback callback)
+{
+       m_OnBack = std::move(callback);
+}
+
 Evas_Object *Popup::onCreate(Evas_Object *parent)
 {
        Window *window = getWindow(parent);
@@ -90,7 +95,8 @@ Evas_Object *Popup::onCreate(Evas_Object *parent)
 
        Evas_Object *popup = elm_popup_add(parent);
        elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
-       eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, nullptr);
+       eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
+                       makeCallback(&Popup::onBackPressed), this);
        evas_object_show(popup);
 
        return popup;
@@ -103,3 +109,10 @@ void Popup::onButtonPressed(Evas_Object *obj, void *eventInfo)
                delete this;
        }
 }
+
+void Popup::onBackPressed(Evas_Object *obj, void *eventInfo)
+{
+       if (!m_OnBack || m_OnBack()) {
+               delete this;
+       }
+}
index f41f4ee..59ce5d4 100644 (file)
@@ -46,7 +46,7 @@ void ProgressPopup::setProgress(size_t value)
        snprintf(progress, sizeof(progress), "%d%%", (int)(100.0 * progressValue));
 
        char total[BUFFER_SIZE] = { 0, };
-       snprintf(total, sizeof(total), "%d/%d", value, m_MaxValue);
+       snprintf(total, sizeof(total), "%zu/%zu", value, m_MaxValue);
 
        elm_progressbar_value_set(m_Progressbar, progressValue);
        elm_object_part_text_set(m_Progressbar, "elm.text.bottom.left", progress);
@@ -64,7 +64,7 @@ Evas_Object *ProgressPopup::onCreate(Evas_Object *parent)
        elm_progressbar_pulse(m_Progressbar, EINA_TRUE);
 
        char total[BUFFER_SIZE] = { 0, };
-       snprintf(total, sizeof(total), "%d/%d", 0, m_MaxValue);
+       snprintf(total, sizeof(total), "%d/%zu", 0, m_MaxValue);
        elm_object_part_text_set(m_Progressbar, "elm.text.bottom.left", ZERO_PROGRESS);
        elm_object_part_text_set(m_Progressbar, "elm.text.bottom.right", total);