controller: convert to class 60/35360/1
authorMinkyu Kang <mk7.kang@samsung.com>
Thu, 12 Feb 2015 13:15:01 +0000 (22:15 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Thu, 12 Feb 2015 13:15:01 +0000 (22:15 +0900)
Change-Id: Ic33967cf937fa8bc42faa7b1a74a8ff0407ccb6c
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
include/control.h
src/control.cpp
src/view_player.cpp

index 14f4612..506294a 100644 (file)
 #ifndef __CONTROL_H__
 #define __CONTROL_H__
 
-struct control_data;
+struct SControlData;
 
-/**
- * Init control data
- *
- * @return the pointer of allocated control_data struct
- */
-struct control_data *control_init(void);
+class CVideoController :
+       public CListenerMgr,
+       public IMouseMoveListener,
+       public IMouseClickedListener {
+private:
+       SControlData *m;
 
-/**
- * Fini control data
- *
- * @param data the pointer of control_data struct
- */
-void control_fini(struct control_data *data);
+private:
+       int m_AddControls(const char **btns, int count);
+       Evas_Object *m_AddButton(const char *style);
+       void m_SetFocusDirection(Evas_Object **btn, int count);
+       int m_GetEventTypes(void);
 
-/**
- * Add a control buttons
- *
- * @param data the pointer of control_data struct
- * @param base the base object of layout
- * @param btns name of buttons
- * @param count the number of buttons
- * @return if success EINA_TRUE is returned otherwise will return EINA_FALSE
- */
-Eina_Bool control_add_bar(struct control_data *data,
-               Evas_Object *base, const char **btns, int count);
+private:
+       static void sm_CbEvent(void *dt, Evas_Object *obj,
+                       const char *emission, const char *source);
 
-/**
- * Show the control
- *
- * @return the pointer of allocated control_data struct
- */
-void control_show(struct control_data *data);
+public:
+       CVideoController(void) :
+               IMouseMoveListener(this),
+               IMouseClickedListener(this), m(0) {}
+       virtual ~CVideoController(void) {}
 
-/**
- * Hide the control
- *
- * @return the pointer of allocated control_data struct
- */
-void control_hide(struct control_data *data);
+       /**
+        * Create the controller
+        *
+        * @param base the base object of layout
+        * @param btns name of buttons
+        * @param count the number of buttons
+        * @return if success true is returned otherwise will return false
+        */
+       bool Create(Evas_Object *base, const char **btns, int count);
 
-/**
- * Init the event handler
- *
- * @param data the pointer of control_data struct
- * @param func callback function
- * @param param parameter of callback function
- */
-void control_handler_init(struct control_data *data,
-               void (*func)(void *, const char *), void *param);
+       /**
+        * Destroy the controller
+        */
+       void Destroy(void);
 
-/**
- * Set the focus to button
- *
- * @param data the pointer of control_data struct
- * @param id id of buttons
- * @param foc EINA_TRUE to set or EINA_FALSE to unset
- */
-void control_focus_set(struct control_data *data, int id, Eina_Bool foc);
+       /**
+        * Show the controller
+        */
+       void Show(void);
 
-/**
- * Emit the signal to button
- *
- * @param data the pointer of control_data struct
- * @param id id of buttons
- * @param emission name of signal
- * @param source source name of signal
- */
-void control_signal_emit(struct control_data *data, int id,
-               const char *emission, const char *source);
+       /**
+        * Hide the controller
+        */
+       void Hide(void);
+
+       /**
+        * Set the focus to button
+        *
+        * @param id id of buttons
+        * @param foc EINA_TRUE to set or EINA_FALSE to unset
+        */
+       void Focus(int id, Eina_Bool foc);
+
+       /**
+        * Emit the signal to button
+        *
+        * @param id id of buttons
+        * @param emission name of signal
+        * @param source source name of signal
+        */
+       void Signal(int id, const char *emission, const char *source);
+
+       /**
+        * Init the event handler
+        *
+        * @param data the pointer of control_data struct
+        * @param func callback function
+        * @param param parameter of callback function
+        */
+       void AddHandler(void (*func)(void *, const char *), void *param);
+
+       /* Listeners */
+       virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj,
+                       Evas_Event_Mouse_Move *ev);
+       virtual void OnMouseClicked(int id, Evas_Object *obj);
+};
 
 #endif
index adad5ad..c0fbc82 100644 (file)
@@ -17,6 +17,9 @@
 #include <Elementary.h>
 #include <Eina.h>
 #include <dbg.h>
+#include <AppCommon.h>
+#include <ViewMgr.h>
+#include <BaseView.h>
 #include <InputHandler.h>
 #include "define.h"
 #include "i18n.h"
 
 #define MAX_CONTROL_BTNS 7
 
-struct control_data;
-
-class CControlHandler :
-       public CListenerMgr,
-       public IMouseMoveListener,
-       public IMouseClickedListener {
-
-private:
-       control_data *m;
-
-public:
-       CControlHandler(control_data *dt) :
-               IMouseMoveListener(this),
-               IMouseClickedListener(this) {
-               m = dt;
-       }
-       virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj,
-                       Evas_Event_Mouse_Move *ev);
-       virtual void OnMouseClicked(int id, Evas_Object *obj);
-       int GetEventTypes(void);
-};
+struct SControlData;
 
 struct _event_cb {
        void (*func)(void *data, const char *ev);
        void *data;
 };
 
-struct control_data {
+struct SControlData {
        Evas_Object *base;
        Evas_Object *focused;
        Evas_Object *btn[MAX_CONTROL_BTNS];
        int btns;
        struct _event_cb cb;
-       CControlHandler *handler;
 };
 
-static void _event_callback(void *dt, Evas_Object *obj,
+void CVideoController::sm_CbEvent(void *dt, Evas_Object *obj,
                const char *emission, const char *source)
 {
-       struct control_data *data;
+       struct SControlData *data;
 
        if (!dt)
                return;
 
-       data = (control_data *)dt;
+       data = (SControlData *)dt;
 
        data->cb.func(data->cb.data, source);
 }
 
-static void _set_focus_directions(Evas_Object **btn, int count)
+void CVideoController::m_SetFocusDirection(Evas_Object **btn, int count)
 {
        Evas_Object *obj;
        int i;
@@ -95,11 +77,13 @@ static void _set_focus_directions(Evas_Object **btn, int count)
        }
 }
 
-static inline Evas_Object *_add_button(Evas_Object *base, const char *style)
+Evas_Object *CVideoController::m_AddButton(const char *style)
 {
+       ASSERT(m);
+
        Evas_Object *btn;
 
-       btn = elm_button_add(base);
+       btn = elm_button_add(m->base);
        if (!btn)
                return NULL;
 
@@ -109,141 +93,133 @@ static inline Evas_Object *_add_button(Evas_Object *base, const char *style)
        return btn;
 }
 
-static int _add_controls(struct control_data *data,
-               const char **btns, int count)
+int CVideoController::m_AddControls(const char **btns, int count)
 {
+       ASSERT(m);
+
        int i, j;
        char buf[32];
-       CControlHandler *handler;
-
-       handler = data->handler;
 
        for (i = 0; i < count; i++) {
                snprintf(buf, sizeof(buf), "video_btn_%s", btns[i]);
-               data->btn[i] = _add_button(data->base, buf);
-               if (!data->btn[i]) {
+               m->btn[i] = m_AddButton(buf);
+               if (!m->btn[i]) {
                        for (j = 0; j < i; j++)
-                               data->btn[j] = NULL;
+                               m->btn[j] = NULL;
                        return -1;
                }
 
                snprintf(buf, sizeof(buf), "part_btn%d", i);
-               elm_object_part_content_set(data->base,
-                               buf, data->btn[i]);
+               elm_object_part_content_set(m->base,
+                               buf, m->btn[i]);
 
                /* FIXME: disable setting button temporary */
                if (i == count - 1) {
-                       elm_object_focus_allow_set(data->btn[i], EINA_FALSE);
+                       elm_object_focus_allow_set(m->btn[i], EINA_FALSE);
                        break;
                }
 
-               handler->Connect(data->btn[i], -1, handler->GetEventTypes());
+               Connect(m->btn[i], -1, m_GetEventTypes());
 
-               elm_object_signal_callback_add(data->btn[i],
+               elm_object_signal_callback_add(m->btn[i],
                                SIG_BTN_ANI_FIN, btns[i],
-                               _event_callback, data);
+                               sm_CbEvent, m);
 
-               elm_object_focus_next_object_set(data->btn[i],
-                               data->btn[i], ELM_FOCUS_DOWN);
+               elm_object_focus_next_object_set(m->btn[i],
+                               m->btn[i], ELM_FOCUS_DOWN);
 
-               data->btns++;
+               m->btns++;
        }
 
        return 0;
 }
 
-Eina_Bool control_add_bar(struct control_data *data,
-               Evas_Object *base, const char **btns, int count)
+bool CVideoController::Create(Evas_Object *base, const char **btns, int count)
 {
+       ASSERT(!m);
+
        int r;
 
-       if (!data || !base || !btns)
-               return EINA_FALSE;
+       if (!base || !btns)
+               return false;
+
+       m = new SControlData;
+       if (!m) {
+               _ERR("failed to add slider");
+               return false;
+       }
 
-       data->base = base;
-       data->btns = 0;
+       m->base = base;
+       m->btns = 0;
 
-       r = _add_controls(data, btns, count);
+       r = m_AddControls(btns, count);
        if (r < 0)
-               return EINA_FALSE;
+               return false;
 
-       _set_focus_directions(data->btn, data->btns);
+       m_SetFocusDirection(m->btn, m->btns);
 
-       return EINA_TRUE;
+       return true;
 }
 
-void control_handler_init(struct control_data *data,
-               void (*func)(void *, const char *), void *param)
+void CVideoController::Destroy(void)
 {
-       if (!data || !func)
-               return;
+       ASSERT(m);
 
-       data->cb.func = func;
-       data->cb.data = param;
+       delete m;
+       m = NULL;
 }
 
-void control_focus_set(struct control_data *data, int id, Eina_Bool foc)
+void CVideoController::AddHandler(void (*func)(void *, const char *),
+               void *param)
 {
-       if (!data)
+       ASSERT(m);
+
+       if (!func)
                return;
 
-       elm_object_focus_set(data->btn[id], foc);
+       m->cb.func = func;
+       m->cb.data = param;
 }
 
-void control_signal_emit(struct control_data *data, int id,
-               const char *emission, const char *source)
+void CVideoController::Focus(int id, Eina_Bool foc)
 {
-       if (!data)
-               return;
+       ASSERT(m);
 
-       elm_object_signal_emit(data->btn[id], emission, source);
+       elm_object_focus_set(m->btn[id], foc);
 }
 
-void control_hide(struct control_data *data)
+void CVideoController::Signal(int id, const char *emission, const char *source)
 {
-       int i;
+       ASSERT(m);
 
-       for (i = 0; i < data->btns; i++) {
-               evas_object_freeze_events_set(data->btn[i], EINA_TRUE);
-               elm_object_focus_allow_set(data->btn[i], EINA_FALSE);
-       }
+       elm_object_signal_emit(m->btn[id], emission, source);
 }
 
-void control_show(struct control_data *data)
+void CVideoController::Hide(void)
 {
+       ASSERT(m);
+
        int i;
 
-       for (i = 0; i < data->btns; i++) {
-               evas_object_freeze_events_set(data->btn[i], EINA_FALSE);
-               elm_object_focus_allow_set(data->btn[i], EINA_TRUE);
+       for (i = 0; i < m->btns; i++) {
+               evas_object_freeze_events_set(m->btn[i], EINA_TRUE);
+               elm_object_focus_allow_set(m->btn[i], EINA_FALSE);
        }
 }
 
-void control_fini(struct control_data *data)
+void CVideoController::Show(void)
 {
-       if (!data)
-               return;
+       ASSERT(m);
 
-       delete data->handler;
-       free(data);
-}
-
-struct control_data *control_init(void)
-{
-       struct control_data *data;
+       int i;
 
-       data = (control_data *)calloc(1, sizeof(*data));
-       if (!data) {
-               _ERR("allocation fail");
-               return NULL;
+       for (i = 0; i < m->btns; i++) {
+               evas_object_freeze_events_set(m->btn[i], EINA_FALSE);
+               elm_object_focus_allow_set(m->btn[i], EINA_TRUE);
        }
-
-       data->handler = new CControlHandler(data);
-
-       return data;
 }
 
-void CControlHandler::OnMouseMove(int id, Evas *e, Evas_Object *obj,
+void CVideoController::OnMouseMove(int id, Evas *e, Evas_Object *obj,
                        Evas_Event_Mouse_Move *ev)
 {
        if (!obj)
@@ -253,12 +229,12 @@ void CControlHandler::OnMouseMove(int id, Evas *e, Evas_Object *obj,
                elm_object_focus_set(obj, EINA_TRUE);
 }
 
-void CControlHandler::OnMouseClicked(int id, Evas_Object *obj)
+void CVideoController::OnMouseClicked(int id, Evas_Object *obj)
 {
        elm_object_signal_emit(obj, SIG_BTN_ANI_START, "");
 }
 
-int CControlHandler::GetEventTypes(void)
+int CVideoController::m_GetEventTypes(void)
 {
        return TYPE_MOUSE_MOVE | TYPE_CLICKED;
 }
index 81967de..a76d115 100644 (file)
@@ -60,9 +60,9 @@ struct SPlayerView {
        char *id;
 
        struct playermgr *player;
-       struct control_data *control;
        struct volume_data *volume;
 
+       CVideoController *control;
        CVideoSlider *slider;
 
        struct timeout_handler *timeout_handle;
@@ -177,7 +177,7 @@ bool CPlayerView::m_PlayerInit(void)
        }
 
        m->slider->Reset(m->duration);
-       control_signal_emit(m->control, E_PLAYPAUSE_BTN, SIG_SET_PAUSE, "");
+       m->control->Signal(E_PLAYPAUSE_BTN, SIG_SET_PAUSE, "");
 
        if (m->bar_hidden) {
                m_ShowBar();
@@ -201,8 +201,7 @@ void CPlayerView::sm_EvtRewindBtn(void *dt)
 
        if (r > 0) {
                data->slider->Pause();
-               control_signal_emit(data->control, E_PLAYPAUSE_BTN,
-                               SIG_SET_PLAY, "");
+               data->control->Signal(E_PLAYPAUSE_BTN, SIG_SET_PLAY, "");
        }
 }
 
@@ -220,8 +219,7 @@ void CPlayerView::sm_EvtForwardBtn(void *dt)
 
        if (r > 0) {
                data->slider->Pause();
-               control_signal_emit(data->control, E_PLAYPAUSE_BTN,
-                               SIG_SET_PLAY, "");
+               data->control->Signal(E_PLAYPAUSE_BTN, SIG_SET_PLAY, "");
        }
 }
 
@@ -383,7 +381,7 @@ void CPlayerView::sm_CbShowViewFinish(void *dt, Evas_Object *obj,
 
        data = (SPlayerView *)dt;
 
-       control_show(data->control);
+       data->control->Show();
 }
 
 void CPlayerView::m_ShowBar(void)
@@ -403,7 +401,7 @@ void CPlayerView::m_HideBar(void)
        m->bar_hidden = true;
 
        m->slider->Pause();
-       control_hide(m->control);
+       m->control->Hide();
 }
 
 void CPlayerView::sm_CbTimeoutEvent(void *dt, int type, void *ev)
@@ -494,12 +492,12 @@ void CPlayerView::sm_CbEcoreEvent(void *dt, int type, void *ei)
 
 bool CPlayerView::m_AddControls(void)
 {
-       if (!control_add_bar(m->control, m->base, _control_name, CONTROL_BTNS))
+       if (!m->control->Create(m->base, _control_name, CONTROL_BTNS))
                return false;
 
        m->repeat = E_REPEAT_ALL;
 
-       control_handler_init(m->control, sm_EvtControlBtn, m);
+       m->control->AddHandler(sm_EvtControlBtn, m);
 
        if (!m->slider->Create(m->base, m->player))
                return false;
@@ -529,7 +527,7 @@ Eina_Bool CPlayerView::sm_CbDrawAnimation(void *dt)
        data = (SPlayerView *)dt;
 
        elm_object_signal_emit(data->base, SIG_SHOW_VIEW, "");
-       control_focus_set(data->control, E_PLAYPAUSE_BTN, EINA_TRUE);
+       data->control->Focus(E_PLAYPAUSE_BTN, EINA_TRUE);
 
        data->drawanim_timer = NULL;
 
@@ -551,7 +549,7 @@ void CPlayerView::m_ControlInit(SPlayerParam *param)
        if (!m->player)
                _ERR("player init failed");
 
-       m->control = control_init();
+       m->control = new CVideoController;
        if (!m->control)
                _ERR("control init failed");
 
@@ -632,7 +630,7 @@ bool CPlayerView::Create(void *data)
                m->error = true;
 
                m_UpdateInfoBar();
-               control_hide(m->control);
+               m->control->Hide();
                elm_object_signal_emit(m->base, SIG_SHOW_VIEW, "");
 
                CBaseView::Create(NULL);
@@ -669,12 +667,14 @@ void CPlayerView::Destroy(void)
        playermgr_fini(m->player);
 
        volume_fini(m->volume);
-       control_fini(m->control);
 
        timeout_handler_fini(m->timeout_handle);
 
        free(m->id);
 
+       m->control->Destroy();
+       delete m->control;
+
        m->slider->Destroy();
        delete m->slider;