controller: find actual location of button 15/47115/2
authorMinkyu Kang <mk7.kang@samsung.com>
Mon, 31 Aug 2015 03:13:19 +0000 (12:13 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Mon, 31 Aug 2015 03:20:39 +0000 (12:20 +0900)
Change-Id: Ifbde0ac06917f0012f860113cc04a191a4ac098d
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
src/util/controller.c
src/view/viewer.c

index 79ec34d..942c201 100644 (file)
@@ -30,6 +30,7 @@ struct _event_cb {
 struct _control {
        Evas_Object *obj;
        char *part;
+       int loc;
 };
 
 struct _priv {
@@ -116,6 +117,7 @@ static bool _add_control(void *handle, const char *name, int loc,
 
        ctl->obj = btn;
        ctl->part = strdup(buf);
+       ctl->loc = loc;
 
        p->list = eina_list_append(p->list, ctl);
 
@@ -140,6 +142,21 @@ static void _add_callback(void *handle,
        p->cb.data = data;
 }
 
+static struct _control *_get_control_loc(Eina_List *list, int loc)
+{
+       Eina_List *l;
+       struct _control *ctl;
+
+       EINA_LIST_FOREACH(list, l, ctl) {
+               if (ctl->loc == loc)
+                       break;
+
+               ctl = NULL;
+       }
+
+       return ctl;
+}
+
 static void _focus(void *handle, int loc, bool foc)
 {
        struct _priv *p;
@@ -151,7 +168,7 @@ static void _focus(void *handle, int loc, bool foc)
        }
 
        p = handle;
-       ctl = eina_list_nth(p->list, loc);
+       ctl = _get_control_loc(p->list, loc);
 
        if (ctl && ctl->obj)
                elm_object_focus_set(ctl->obj, foc);
@@ -168,7 +185,7 @@ static void _signal(void *handle, int loc, const char *signal)
        }
 
        p = handle;
-       ctl = eina_list_nth(p->list, loc);
+       ctl = _get_control_loc(p->list, loc);
 
        if (ctl && ctl->obj)
                elm_object_signal_emit(ctl->obj, signal, "");
@@ -278,7 +295,7 @@ static Evas_Object *_get_object(void *handle, int loc)
 
        p = handle;
 
-       ctl = eina_list_nth(p->list, loc);
+       ctl = _get_control_loc(p->list, loc);
        if (!ctl)
                return NULL;
 
index 6fce492..f3e768a 100644 (file)
 
 #define STYLE_VIEWER_BTN "viewer_btn"
 #define PART_VIEWER_BTN "control_btn"
-#define PLAY_BTN_LOC 1
 
 #define VIEWER_TIMEOUT 3.0
 #define VIEWER_SEPARATOR "/ "
 #define VIDEO_COPYRIGHT "Unknown"
 
+#define BTN_LOC_PREV 0
+#define BTN_LOC_PLAY 2
+#define BTN_LOC_NEXT 4
+
 enum {
        VIEWER_MOVIE,
        VIEWER_PHOTO,
@@ -89,41 +92,41 @@ struct _btn_info {
 static struct _btn_info btn_movie[] = {
        {
                .name = SRC_BTN_PREV,
-               .loc = 1,
+               .loc = BTN_LOC_PREV,
        },
        {
                .name = SRC_BTN_PLAY,
-               .loc = 2,
+               .loc = BTN_LOC_PLAY,
        },
        {
                .name = SRC_BTN_NEXT,
-               .loc = 3,
+               .loc = BTN_LOC_NEXT,
        },
 };
 
 static struct _btn_info btn_photo[] = {
        {
                .name = SRC_BTN_GALLERY_PREV,
-               .loc = 0,
+               .loc = BTN_LOC_PREV,
        },
        {
                .name = SRC_BTN_GALLERY_NEXT,
-               .loc = 4,
+               .loc = BTN_LOC_NEXT,
        },
 };
 
 static struct _btn_info btn_video[] = {
        {
                .name = SRC_BTN_GALLERY_PREV,
-               .loc = 0,
+               .loc = BTN_LOC_PREV,
        },
        {
                .name = SRC_BTN_PLAY,
-               .loc = 2,
+               .loc = BTN_LOC_PLAY,
        },
        {
                .name = SRC_BTN_GALLERY_NEXT,
-               .loc = 4,
+               .loc = BTN_LOC_NEXT,
        },
 };
 
@@ -145,19 +148,19 @@ static struct _viewer_info viewer_info[] = {
        {
                .btns = btn_movie,
                .btn_count = 3,
-               .focus_loc = 1,
+               .focus_loc = BTN_LOC_PLAY,
                .callback = _callback_movie,
        },
        {
                .btns = btn_photo,
                .btn_count = 2,
-               .focus_loc = 1,
+               .focus_loc = BTN_LOC_NEXT,
                .callback = _callback_photo,
        },
        {
                .btns = btn_video,
                .btn_count = 3,
-               .focus_loc = 2,
+               .focus_loc = BTN_LOC_NEXT,
                .callback = _callback_video,
        },
 };
@@ -465,17 +468,17 @@ static bool _viewer_show(struct _priv *priv)
 
        switch (priv->playlist.dir) {
        case DIR_PREV:
-               loc = 0;
+               loc = BTN_LOC_PREV;
                break;
        case DIR_NEXT:
-               loc = info->btn_count - 1;
+               loc = BTN_LOC_NEXT;
                break;
        case DIR_NONE:
        default:
                loc = info->focus_loc;
                if (id == VIEWER_MOVIE) {
                        ctl->ops->signal(ctl->handle,
-                                       PLAY_BTN_LOC, SIG_SET_PAUSE);
+                                       BTN_LOC_PLAY, SIG_SET_PAUSE);
                }
                break;
        }
@@ -546,7 +549,7 @@ static bool _viewer_prev(struct _priv *priv)
        struct controller *ctl;
 
        ctl = priv->viewer.ctl[priv->viewer.cur];
-       ctl->ops->signal(ctl->handle, 0, SIG_SET_UNFOCUS);
+       ctl->ops->signal(ctl->handle, BTN_LOC_PREV, SIG_SET_UNFOCUS);
 
        _viewer_hide(priv);
 
@@ -571,8 +574,7 @@ static bool _viewer_next(struct _priv *priv)
        struct controller *ctl;
 
        ctl = priv->viewer.ctl[priv->viewer.cur];
-       ctl->ops->signal(ctl->handle, ctl->ops->get_count(ctl->handle) - 1,
-                       SIG_SET_UNFOCUS);
+       ctl->ops->signal(ctl->handle, BTN_LOC_NEXT, SIG_SET_UNFOCUS);
 
        _viewer_hide(priv);
 
@@ -742,8 +744,8 @@ static void _player_play(struct _priv *priv)
        }
 
        ctl = priv->viewer.ctl[priv->viewer.cur];
-       ctl->ops->signal(ctl->handle, PLAY_BTN_LOC, SIG_SET_PAUSE);
-       ctl->ops->focus(ctl->handle, PLAY_BTN_LOC, true);
+       ctl->ops->signal(ctl->handle, BTN_LOC_PLAY, SIG_SET_PAUSE);
+       ctl->ops->focus(ctl->handle, BTN_LOC_PLAY, true);
 }
 
 static void _player_pause(struct _priv *priv)
@@ -768,8 +770,8 @@ static void _player_pause(struct _priv *priv)
        }
 
        ctl = priv->viewer.ctl[priv->viewer.cur];
-       ctl->ops->signal(ctl->handle, PLAY_BTN_LOC, SIG_SET_PLAY);
-       ctl->ops->focus(ctl->handle, PLAY_BTN_LOC, true);
+       ctl->ops->signal(ctl->handle, BTN_LOC_PLAY, SIG_SET_PLAY);
+       ctl->ops->focus(ctl->handle, BTN_LOC_PLAY, true);
 }
 
 static void _player_stop(struct _priv *priv)
@@ -786,7 +788,7 @@ static void _player_stop(struct _priv *priv)
        playermgr_stop(priv->player);
 
        ctl = priv->viewer.ctl[priv->viewer.cur];
-       ctl->ops->signal(ctl->handle, PLAY_BTN_LOC, SIG_SET_PLAY);
+       ctl->ops->signal(ctl->handle, BTN_LOC_PLAY, SIG_SET_PLAY);
 }
 
 static void _player_complete_cb(void *data)