From 17a856b49742633ae54be79c8550dfdc38dc51da Mon Sep 17 00:00:00 2001 From: Kim Tae Soo Date: Wed, 25 Feb 2015 00:57:16 +0900 Subject: [PATCH] Apply CCtxPopup to CContextView Change-Id: I7e9e6099da3b963da617f43461b5747994331216 Signed-off-by: Kim Tae Soo --- CMakeLists.txt | 1 + include/Info.h | 3 + include/common.h | 4 +- include/context-view.h | 10 ++- include/define.h | 2 + src/views/Info.cpp | 11 +++ src/views/PlayListCtxPopup.cpp | 145 +++++++++++++++++++++++++++++++++++ src/views/PlayListCtxPopup.h | 21 ++++++ src/views/PlaySettingCtxPopup.cpp | 2 +- src/views/context-view.cpp | 154 +++++++++++--------------------------- 10 files changed, 237 insertions(+), 116 deletions(-) create mode 100644 src/views/PlayListCtxPopup.cpp create mode 100644 src/views/PlayListCtxPopup.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c286f96..31c660e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/include/Info.h b/include/Info.h index f0da1b3..d4c35b0 100644 --- a/include/Info.h +++ b/include/Info.h @@ -13,6 +13,9 @@ public: static void SetPlaybackSettingType(int type); static int PlaybackSettingType(void); + + static void SetPlayListDbId(int dbId); + static int PlayListDbId(void); }; diff --git a/include/common.h b/include/common.h index d0a76f8..1f09007 100644 --- a/include/common.h +++ b/include/common.h @@ -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" diff --git a/include/context-view.h b/include/context-view.h index 8212262..7679dd1 100644 --- a/include/context-view.h +++ b/include/context-view.h @@ -18,6 +18,8 @@ #define __CONTEXT_VIEW_H__ +#include + 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); diff --git a/include/define.h b/include/define.h index 29ac199..27ae431 100644 --- a/include/define.h +++ b/include/define.h @@ -416,5 +416,7 @@ #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__ */ diff --git a/src/views/Info.cpp b/src/views/Info.cpp index d878b0a..19db11a 100644 --- a/src/views/Info.cpp +++ b/src/views/Info.cpp @@ -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 index 0000000..b6aad93 --- /dev/null +++ b/src/views/PlayListCtxPopup.cpp @@ -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 +#include +#include +#include "i18n.h" +#include "define.h" +#include "dbg.h" +#include "common.h" +#include "Info.h" +#include "CtxPopup.h" +#include +#include +#include +#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 index 0000000..29888d2 --- /dev/null +++ b/src/views/PlayListCtxPopup.h @@ -0,0 +1,21 @@ +#ifndef __PLAYLIST_CTX_POPUP_H__ +#define __PLAYLIST_CTX_POPUP_H__ + +#include + +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__ */ diff --git a/src/views/PlaySettingCtxPopup.cpp b/src/views/PlaySettingCtxPopup.cpp index f0c3d61..8645226 100644 --- a/src/views/PlaySettingCtxPopup.cpp +++ b/src/views/PlaySettingCtxPopup.cpp @@ -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, diff --git a/src/views/context-view.cpp b/src/views/context-view.cpp index 30c68f3..49b5f07 100644 --- a/src/views/context-view.cpp +++ b/src/views/context-view.cpp @@ -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; -- 2.7.4