Apply CCtxPopup to CContextView 95/35795/4 accepted/tizen/tv/20150225.041831 submit/tizen_tv/20150225.031242
authorKim Tae Soo <taesoo46.kim@samsung.com>
Tue, 24 Feb 2015 15:57:16 +0000 (00:57 +0900)
committerKim Tae Soo <taesoo46.kim@samsung.com>
Wed, 25 Feb 2015 00:39:13 +0000 (09:39 +0900)
Change-Id: I7e9e6099da3b963da617f43461b5747994331216
Signed-off-by: Kim Tae Soo <taesoo46.kim@samsung.com>
CMakeLists.txt
include/Info.h
include/common.h
include/context-view.h
include/define.h
src/views/Info.cpp
src/views/PlayListCtxPopup.cpp [new file with mode: 0644]
src/views/PlayListCtxPopup.h [new file with mode: 0644]
src/views/PlaySettingCtxPopup.cpp
src/views/context-view.cpp

index c286f96..31c660e 100644 (file)
@@ -73,6 +73,7 @@ SET(SRCS src/main.cpp
         src/views/SourceCtxPopup.cpp
         src/views/SortCtxPopup.cpp
         src/views/PlaySettingCtxPopup.cpp
+        src/views/PlayListCtxPopup.cpp
         src/playback/playlist-mgr.cpp
         src/playback/music-controller.cpp
         src/playback/playback-mgr.cpp
index f0da1b3..d4c35b0 100644 (file)
@@ -13,6 +13,9 @@ public:
 
        static void SetPlaybackSettingType(int type);
        static int  PlaybackSettingType(void);
+
+       static void SetPlayListDbId(int dbId);
+       static int  PlayListDbId(void);
 };
 
 
index d0a76f8..1f09007 100644 (file)
@@ -147,10 +147,12 @@ struct SParcel {
 
 // this values should be defined
 #define KEY_PLAY "Play"
-#define KEY_ENTER "Enter"
 #define KEY_NEXT "Next"
 #define KEY_PREVIOUS "Previous"
 #define KEY_EXIT "Exit"
+
+// Temp Definition
+#define KEY_ENTER "Return"
 #define KEY_BACK "Escape"
 #define KEY_MENU "Super_L"
 
index 8212262..7679dd1 100644 (file)
@@ -18,6 +18,8 @@
 #define __CONTEXT_VIEW_H__
 
 
+#include <CtxPopup.h>
+
 struct SContentInfo;
 struct SRltvCtnt;
 
@@ -43,12 +45,12 @@ private:
        static int sm_CbSortPlaylist(const void *d1, const void *d2);
        static void sm_CbPopupDeleted(void *data, Evas *e, Evas_Object *obj, void *ei);
 
-       static void sm_CbPopupBtnClicked(void *data, Evas_Object *obj, void *ei);
-       void m_OnPopupBtnClicked(Evas_Object *obj);
-
        static Eina_Bool sm_CbSelectIdler(void *dt);
        Eina_Bool m_OnSelectIdler(void);
 
+       static void sm_CbCtxPopupBtnSelected(void* cookie, CCtxPopup* instance, const char* text);
+       void m_CbCtxPopupBtnSelected(CCtxPopup* instance, const char* text);
+
 
 
 private:
@@ -81,7 +83,7 @@ private:
        bool m_CreateMoreinfoLayout(SRltvCtnt *rctnt, Evas_Object *img);
        bool m_CreateInfoPart(void);
        bool m_CreateFullView(void);
-       Evas_Object *m_CreatePlaylistPopup(void);
+       CCtxPopup *m_CreatePlaylistPopup(void);
        Evas_Object *m_CreateRemovePopup(Evas_Object *base, const char *msg,
                Evas_Object_Event_Cb _close_cb, Evas_Smart_Cb _remove_cb,
                Evas_Smart_Cb _cancel_cb, void *dt);
index 29ac199..27ae431 100644 (file)
 #define POSITION_SOURCE_POPUP_Y 155
 #define POSITION_PLAY_SETTING_POPUP_X 212
 #define POSITION_PLAY_SETTING_POPUP_Y 705
+#define POSITION_PLAY_LIST_POPUP_X 1644
+#define POSITION_PLAY_LIST_POPUP_Y 1020
 
 #endif /* __DEFINE_H__ */
index d878b0a..19db11a 100644 (file)
@@ -29,6 +29,7 @@ struct SInfo {
        int sourceType;
        int sortType;
        int playbackSettingType;
+       int playListDb;
 };
 
 static SInfo g_info;
@@ -61,4 +62,14 @@ void CInfo::SetPlaybackSettingType(int type)
 int  CInfo::PlaybackSettingType(void)
 {
        return g_info.playbackSettingType;
+}
+
+void CInfo::SetPlayListDbId(int dbId)
+{
+       g_info.playListDb = dbId;
+}
+
+int CInfo::PlayListDbId(void)
+{
+       return g_info.playListDb;
 }
\ No newline at end of file
diff --git a/src/views/PlayListCtxPopup.cpp b/src/views/PlayListCtxPopup.cpp
new file mode 100644 (file)
index 0000000..b6aad93
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* 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 <Elementary.h>
+#include <Eina.h>
+#include <Ecore.h>
+#include "i18n.h"
+#include "define.h"
+#include "dbg.h"
+#include "common.h"
+#include "Info.h"
+#include "CtxPopup.h"
+#include <MediaContentDbListener.h>
+#include <UsbConnectionListener.h>
+#include <app-res-defines.h>
+#include "PlayListCtxPopup.h"
+
+
+struct SPlayListCtxPopup {
+       char **settingTexts;
+       char **btnIds;
+       int  *dbIds;
+       int  listSize;
+};
+
+
+void CPlayListCtxPopup::t_OnConfiguration(void)
+{
+       t_SetList((const char **)m->settingTexts, m->listSize, 0,
+               CCtxPopup::TOPBTN_BASE, (const char **)m->btnIds,
+               POSITION_PLAY_LIST_POPUP_X, POSITION_PLAY_LIST_POPUP_Y,
+               MUSIC_STYLE_LIST_POPUP,
+               MUSIC_STYLE_TOPTEXT_BTN, MUSIC_STYLE_MIDDLETEXT_BTN, MUSIC_STYLE_BOTTOMTEXT_BTN);
+}
+
+void CPlayListCtxPopup::t_OnBtnClicked(Evas_Object* obj, void* ev)
+{
+       if (!obj)
+               return;
+
+       int index = -1;
+       const char *id = (const char*)evas_object_data_get(obj, BTN_ID);
+
+       if (!id)
+               return;
+
+       // Find Index
+       int i;
+       for (i = 0; i < m->listSize; i++) {
+               if (m->btnIds[i] && !strcmp(m->btnIds[i], id)) {
+                       index = i;
+                       break;
+               }
+       }
+
+       if (index == -1)
+               return;
+
+       CInfo::SetPlayListDbId(m->dbIds[index]);
+
+       CCtxPopup::t_OnBtnClicked(obj, ev);
+
+       Destroy();
+}
+
+
+bool CPlayListCtxPopup::Create(Evas_Object* base, const SCallback* callback, Eina_List *playList)
+{
+       Eina_List *l = NULL;
+       SCtxtPlaylistItem *item = NULL;
+       int i;
+       void *obj = NULL;
+
+       m = new SPlayListCtxPopup;
+       if (!m) {
+               _ERR("Memory Alloc Failed!!");
+               return false;
+       }
+
+       m->listSize = eina_list_count(playList);
+       if (m->listSize == 0) {
+               _DBG("Playlist is empty.");
+               delete m;
+               return false;
+       }
+
+       m->settingTexts = new char*[m->listSize];
+       m->btnIds = new char*[m->listSize];
+       m->dbIds = new int[m->listSize];
+
+       i = 0;
+       EINA_LIST_FOREACH(playList, l, obj) {
+               item = (SCtxtPlaylistItem *)obj;
+               m->settingTexts[i] = new char[strlen(N_(item->name)) + 1];
+               m->btnIds[i] = new char[strlen(item->name) + 1];
+               m->dbIds[i] = item->id;
+
+               strcpy(m->settingTexts[i], N_(item->name));
+               strcpy(m->btnIds[i], item->name);
+
+               i++;
+       }
+
+       bool r = CCtxPopup::Create(base, callback, true);
+       if (r == false) {
+               _ERR("CCtxPopup::Create failed");
+               delete m;
+               return false;
+       }
+
+       return true;
+}
+
+
+void CPlayListCtxPopup::Destroy(void)
+{
+       CCtxPopup::Destroy();
+
+       int i;
+
+       for (i = 0; i < m->listSize; i++) {
+               delete[] m->settingTexts[i];
+               delete[] m->btnIds[i];
+       }
+
+       delete[] m->settingTexts;
+       delete[] m->btnIds;
+       delete[] m->dbIds;
+       delete m;
+
+       m = NULL;
+}
\ No newline at end of file
diff --git a/src/views/PlayListCtxPopup.h b/src/views/PlayListCtxPopup.h
new file mode 100644 (file)
index 0000000..29888d2
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __PLAYLIST_CTX_POPUP_H__
+#define __PLAYLIST_CTX_POPUP_H__
+
+#include <CtxPopup.h>
+
+class CPlayListCtxPopup : public CCtxPopup {
+private:
+       struct SPlayListCtxPopup *m;
+
+protected:
+       virtual void t_OnConfiguration(void);
+       virtual void t_OnBtnClicked(Evas_Object* obj, void* ev);
+
+public:
+       CPlayListCtxPopup() : m(0) {}
+
+       bool Create(Evas_Object* base, const SCallback* callback, Eina_List *playList);
+       virtual void Destroy(void);
+};
+
+#endif /* __PLAYLIST_CTX_POPUP_H__ */
index f0c3d61..8645226 100644 (file)
@@ -42,7 +42,7 @@ const char *settingBtnId[TOTAL_SETTING_BTNS] = {
 
 void CPlaySettingCtxPopup::t_OnConfiguration(void)
 {
-       t_SetList(settingText, TOTAL_SETTING_BTNS, (int)CInfo::PlaybackSettingType(),
+       t_SetList(settingText, TOTAL_SETTING_BTNS, 0,
                CCtxPopup::TOPBTN_BASE, settingBtnId,
                POSITION_PLAY_SETTING_POPUP_X, POSITION_PLAY_SETTING_POPUP_Y,
                MUSIC_STYLE_SETTING_POPUP,
index 30c68f3..49b5f07 100644 (file)
@@ -33,6 +33,8 @@
 #include "BaseView.h"
 #include "ViewMgr.h"
 #include "context-view.h"
+#include "PlayListCtxPopup.h"
+#include "Info.h"
 
 #define _GET_PRIV(o) evas_object_data_get(o, "CTMDATA");
 #define _SET_PRIV(o, data) evas_object_data_set(o, "CTMDATA", data);
@@ -101,6 +103,7 @@ struct SContextView {
        Evas_Object *first_line[TABLE_MAX_COL];
        Evas_Object *last_line[TABLE_MAX_COL];
        Evas_Object *popup;
+       CPlayListCtxPopup *ctxpopup;
        Ecore_Idler *idler;
        CMusicController *mhandle;
        CViewMgr *vmgr;
@@ -269,32 +272,10 @@ void CContextView::sm_CbPopupDeleted(void *data, Evas *e, Evas_Object *obj, void
 }
 
 
-void CContextView::sm_CbPopupBtnClicked(void *data, Evas_Object *obj, void *ei)
-{
-       CContextView *root = (CContextView *)data;
-       if (root)
-               root->m_OnPopupBtnClicked(obj);
-}
-
-
-void CContextView::m_OnPopupBtnClicked(Evas_Object *obj)
-{
-       SCtxtPlaylistItem *item = (SCtxtPlaylistItem *)_GET_PRIV(obj);
-
-       if (!item) {
-               _ERR("Invalid argument.");
-               return;
-       }
-
-       m->lid = item->id;
-       m->idler = ecore_idler_add(sm_CbSelectIdler, this);
-}
-
-
 Eina_Bool CContextView::sm_CbSelectIdler(void *dt)
 {
        CContextView *root = (CContextView *)dt;
-       Eina_Bool r;
+       Eina_Bool r = ECORE_CALLBACK_CANCEL;
 
        if (root)
                r = root->m_OnSelectIdler();
@@ -321,6 +302,21 @@ Eina_Bool CContextView::m_OnSelectIdler(void)
 }
 
 
+void CContextView::sm_CbCtxPopupBtnSelected(void* cookie, CCtxPopup* instance, const char* text)
+{
+       CContextView *root = (CContextView*)cookie;
+       if (root)
+               root->m_CbCtxPopupBtnSelected(instance, text);
+}
+
+
+void CContextView::m_CbCtxPopupBtnSelected(CCtxPopup* instance, const char* text)
+{
+       m->lid = CInfo::PlayListDbId();
+       m->idler = ecore_idler_add(sm_CbSelectIdler, this);
+}
+
+
 Evas_Object *CContextView::m_AddScroller(Evas_Object *base)
 {
        Evas_Object *scroller = NULL;
@@ -1115,103 +1111,37 @@ bool CContextView::m_CreateFullView(void)
 }
 
 
-Evas_Object *CContextView::m_CreatePlaylistPopup(void)
+CCtxPopup *CContextView::m_CreatePlaylistPopup(void)
 {
-       Evas_Object *popup = NULL, *box = NULL, *btn = NULL, *scr = NULL, *firstbtn = NULL;
-       Eina_List *l = NULL, *list = NULL;
-       struct SCtxtPlaylistItem *item = NULL;
-       void *obj = NULL;
-       int i, tc;
-
-       popup = elm_ctxpopup_add(m->base);
-       if (!popup) {
-               _ERR("elm_ctxpopup_add failed.");
-               return NULL;
-       }
-
-       box = elm_box_add(popup);
-       if (!box) {
-               _ERR("elm_box_add failed.");
-               evas_object_del(popup);
-               return NULL;
-       }
-
-       evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0);
-       evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0);
+       CPlayListCtxPopup *ctxpopup = NULL;
+       Eina_List *list = NULL;
+       bool r;
 
        list = CMediadata::PlaylistsForCtxt();
        if (!list || eina_list_count(list) == 0) {
                _ERR("Fetching list of playlists failed");
-               evas_object_del(popup);
                return NULL;
        }
 
        list = eina_list_sort(list, 0, sm_CbSortPlaylist);
-       elm_object_style_set(popup, MUSIC_STYLE_LIST_POPUP);
-       evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL,
-               sm_CbPopupDeleted, list);
-
-       btn = NULL;
-       firstbtn = NULL;
-       i = 0;
-       tc = eina_list_count(list);
-
-       EINA_LIST_FOREACH(list, l, obj) {
-               item = (SCtxtPlaylistItem *)obj;
-               btn = elm_button_add(box);
-               if (!btn) {
-                       _ERR("elm_button_add failed.");
-                       evas_object_del(popup);
-                       return NULL;
-               }
 
-               if (i == 0) {
-                       elm_object_style_set(btn, MUSIC_STYLE_TOPTEXT_BTN);
-                       firstbtn = btn;
-               }
-               else if (i == tc - 1) {
-                       _INFO();
-                       elm_object_style_set(btn, MUSIC_STYLE_BOTTOMTEXT_BTN);
-                       elm_object_signal_emit(btn, MUSIC_SIGNAL_HIDELINE,
-                               MUSIC_CONTEXT_VIEW);
-               }
-               else {
-                       elm_object_style_set(btn, MUSIC_STYLE_MIDDLETEXT_BTN);
-               }
-
-               i++;
-               elm_object_text_set(btn, item->name);
-               evas_object_show(btn);
-               elm_box_pack_end(box, btn);
-               _SET_PRIV(btn, item);
-
-               evas_object_smart_callback_add(btn, MUSIC_SIGNAL_CLICKED,
-                       sm_CbPopupBtnClicked, this);
-               evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_MOVE,
-                       _object_mouse_moved, NULL);
-               evas_object_event_callback_add(btn, EVAS_CALLBACK_KEY_DOWN,
-                       sm_CbPopupKeyPressed, m);
-       }
-
-       scr = m_AddScroller(popup);
-       if (!scr) {
-               evas_object_del(popup);
+       ctxpopup = new CPlayListCtxPopup;
+       if (!ctxpopup) {
+               _ERR("Memory alloc failed");
                return NULL;
        }
 
-       elm_object_content_set(scr, box);
-       elm_object_content_set(popup, scr);
-       elm_object_part_content_set(m->base, MUSIC_PART_PLIST_POPUP, popup);
-
-       elm_ctxpopup_direction_priority_set(popup, (Elm_Ctxpopup_Direction)0, (Elm_Ctxpopup_Direction)0, (Elm_Ctxpopup_Direction)0, (Elm_Ctxpopup_Direction)0);
-
-       if (firstbtn && btn) {
-               elm_object_focus_set(firstbtn, EINA_TRUE);
-               elm_object_focus_next_object_set(firstbtn, btn, ELM_FOCUS_UP);
-               elm_object_focus_next_object_set(btn, firstbtn, ELM_FOCUS_DOWN);
+       CCtxPopup::SCallback cb;
+       cb.onSelected = sm_CbCtxPopupBtnSelected;
+       cb.cookie = this;
+       r = ctxpopup->Create(m->base, &cb, list);
+       if (!r) {
+               _ERR("PlayListCtxpopup Creation failed");
+               delete ctxpopup;
+               return NULL;
        }
 
-       return popup;
+       return ctxpopup;
 }
 
 
@@ -1282,11 +1212,15 @@ Evas_Object *CContextView::m_CreateRemovePopup(Evas_Object *base, const char *ms
 
 void CContextView::m_DestroyPopup(void)
 {
-       if (!m->popup)
-               return;
+       if (m->popup)
+               evas_object_del(m->popup);
+
+       if (m->ctxpopup && m->ctxpopup->FlagCreate())
+               m->ctxpopup->Destroy();
 
-       evas_object_del(m->popup);
        m->popup = NULL;
+       delete m->ctxpopup;
+       m->ctxpopup = NULL;
 }
 
 
@@ -1316,8 +1250,8 @@ void CContextView::m_HandleBtnSelected(int btnType)
                break;
 
        case CONTEXT_VIEW_BUTTON_ADDTO:
-               m->popup = m_CreatePlaylistPopup();
-               if (!m->popup)
+               m->ctxpopup = (CPlayListCtxPopup *)m_CreatePlaylistPopup();
+               if (!m->ctxpopup)
                        _create_message_box(m->base, MUSIC_TEXT_NOLIST_MSG);
                break;