From f028931f118ee0a8d3c4da156d7645f8a10fd085 Mon Sep 17 00:00:00 2001 From: Kim Tae Soo Date: Fri, 6 Mar 2015 18:12:48 +0900 Subject: [PATCH] Apply CPopupWindow class Change-Id: I10549bcd391b8b8d1c8bdf3ffdfcca80dfd563fd Signed-off-by: Kim Tae Soo --- CMakeLists.txt | 1 + include/context-view.h | 16 ++---- src/views/RemovePopupWindow.cpp | 51 +++++++++++++++++ src/views/RemovePopupWindow.h | 35 ++++++++++++ src/views/context-view.cpp | 120 +++++++++++----------------------------- 5 files changed, 124 insertions(+), 99 deletions(-) create mode 100644 src/views/RemovePopupWindow.cpp create mode 100644 src/views/RemovePopupWindow.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ab5516..4ebda26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,7 @@ SET(SRCS src/main.cpp src/views/SortCtxPopup.cpp src/views/PlaySettingCtxPopup.cpp src/views/PlayListCtxPopup.cpp + src/views/RemovePopupWindow.cpp src/playback/playlist-mgr.cpp src/playback/music-controller.cpp src/playback/playback-mgr.cpp diff --git a/include/context-view.h b/include/context-view.h index 7679dd1..caf007c 100644 --- a/include/context-view.h +++ b/include/context-view.h @@ -19,6 +19,7 @@ #include +#include "PopupWindow.h" struct SContentInfo; struct SRltvCtnt; @@ -33,14 +34,11 @@ private: private: static void sm_CbRltdCtntSelected(void *data, Evas_Object *obj, const char *emission, const char *source); - static void sm_CbPopupKeyPressed(void *data, Evas *e, Evas_Object *obj, void *ei); - void m_OnPopUpKeyPressed(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); + static void sm_CbRemove(void* cookie, CPopupWindow *instance); + void m_OnRemove(CPopupWindow *instance); - static void sm_CbRemove(void *data, Evas_Object *obj, void *ei); - void m_OnRemove(Evas_Object *obj); - - static void sm_CbCancel(void *data, Evas_Object *obj, void *ei); - void m_OnCancel(Evas_Object *obj); + static void sm_CbCancel(void* cookie, CPopupWindow *instance); + void m_OnCancel(CPopupWindow *instance); static int sm_CbSortPlaylist(const void *d1, const void *d2); static void sm_CbPopupDeleted(void *data, Evas *e, Evas_Object *obj, void *ei); @@ -84,9 +82,7 @@ private: bool m_CreateInfoPart(void); bool m_CreateFullView(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); + CPopupWindow *m_CreateRemovePopup(Evas_Object *base, const char *msg); void m_DestroyPopup(void); void m_HandleBtnSelected(int btnType); void m_HandleMoreinfoSelected(Evas_Object *obj); diff --git a/src/views/RemovePopupWindow.cpp b/src/views/RemovePopupWindow.cpp new file mode 100644 index 0000000..2c0aa51 --- /dev/null +++ b/src/views/RemovePopupWindow.cpp @@ -0,0 +1,51 @@ +/* +* 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 +#include +#include "i18n.h" +#include "define.h" +#include "dbg.h" +#include "common.h" +#include "RemovePopupWindow.h" + + +#define NUM_BTNS 2 + +const char *btnText[NUM_BTNS] = { + _(MUSIC_TEXT_REMOVE), + _(MUSIC_TEXT_CANCEL) +}; + +void CRemovePopupWindow::t_OnConfiguration(void) +{ + t_SetParams(_(MUSIC_TEXT_REMOVE), NULL, _(m_msg), NUM_BTNS, (const char **)btnText); +} + +bool CRemovePopupWindow::Create(Evas_Object* base, const SCallback* callback, const char *msg) +{ + m_msg = msg; + + if (!CPopupWindow::Create(base, callback)) { + _ERR("Creation of remove popup failed"); + return false; + } + + return true; +} \ No newline at end of file diff --git a/src/views/RemovePopupWindow.h b/src/views/RemovePopupWindow.h new file mode 100644 index 0000000..5fdbec7 --- /dev/null +++ b/src/views/RemovePopupWindow.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + + +#ifndef __REMOVE_POPUP_WINDOW_H__ +#define __REMOVE_POPUP_WINDOW_H__ + +#include + +class CRemovePopupWindow : public CPopupWindow { +private: + const char *m_msg; + +protected: + virtual void t_OnConfiguration(void); + +public: + bool Create(Evas_Object* base, const SCallback* callback, const char *msg); +}; + + +#endif // __REMOVE_POPUP_WINDOW_H__ \ No newline at end of file diff --git a/src/views/context-view.cpp b/src/views/context-view.cpp index 3c9c0a9..f07350d 100644 --- a/src/views/context-view.cpp +++ b/src/views/context-view.cpp @@ -34,6 +34,8 @@ #include "ViewMgr.h" #include "context-view.h" #include "PlayListCtxPopup.h" +#include "PopupWindow.h" +#include "RemovePopupWindow.h" #include "Info.h" #define _GET_PRIV(o) evas_object_data_get(o, "CTMDATA"); @@ -102,7 +104,8 @@ struct SContextView { Evas_Object *playbtn; Evas_Object *first_line[TABLE_MAX_COL]; Evas_Object *last_line[TABLE_MAX_COL]; - Evas_Object *popup; + //Evas_Object *popup; + CRemovePopupWindow *popup; CPlayListCtxPopup *ctxpopup; Ecore_Idler *idler; CMusicController *mhandle; @@ -172,38 +175,19 @@ void CContextView::sm_CbRltdCtntSelected(void *data, Evas_Object *obj, const cha } -void CContextView::sm_CbPopupKeyPressed(void *data, Evas *e, Evas_Object *obj, void *ei) +void CContextView::sm_CbRemove(void* cookie, CPopupWindow *instance) { - CContextView *root = (CContextView *)data; + CContextView *root = (CContextView *)cookie; if (root) - root->m_OnPopUpKeyPressed(e, obj, (Evas_Event_Key_Down *)ei); + root->m_OnRemove(instance); } -void CContextView::m_OnPopUpKeyPressed(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) -{ - if (!ev->keyname) - return; - - if (!strcmp(ev->keyname, KEY_BACK) || - !strcmp(ev->keyname, KEY_BACK_REMOTE)) - m_DestroyPopup(); -} - - -void CContextView::sm_CbRemove(void *data, Evas_Object *obj, void *ei) -{ - CContextView *root = (CContextView *)data; - if (root) - root->m_OnRemove(obj); -} - - -void CContextView::m_OnRemove(Evas_Object *obj) +void CContextView::m_OnRemove(CPopupWindow *instance) { SContentInfo *cinfo = NULL; - if (!obj) { + if (!instance) { _ERR("Invalid argument."); return; } @@ -218,17 +202,17 @@ void CContextView::m_OnRemove(Evas_Object *obj) } -void CContextView::sm_CbCancel(void *data, Evas_Object *obj, void *ei) +void CContextView::sm_CbCancel(void* cookie, CPopupWindow *instance) { - CContextView *root = (CContextView *)data; + CContextView *root = (CContextView *)cookie; if (root) - root->m_OnCancel(obj); + root->m_OnCancel(instance); } -void CContextView::m_OnCancel(Evas_Object *obj) +void CContextView::m_OnCancel(CPopupWindow *instance) { - if (!obj) { + if (!instance) { _ERR("Invalid argument."); return; } @@ -1146,79 +1130,41 @@ CCtxPopup *CContextView::m_CreatePlaylistPopup(void) } -Evas_Object *CContextView::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) +CPopupWindow *CContextView::m_CreateRemovePopup(Evas_Object *base, const char *msg) { - Evas_Object *popup, *yesbtn, *nobtn, *lbl; + CRemovePopupWindow *popup; - if (!base || !_remove_cb || !_cancel_cb || !dt) { - _ERR("Invalid argument."); - return NULL; - } - - popup = elm_popup_add(base); + popup = new CRemovePopupWindow; if (!popup) { - _ERR("elm_popup_add failed."); - return NULL; - } - - elm_object_style_set(popup, MUSIC_STYLE_REMOVE_POPUP); - elm_object_part_text_set(popup, MUSIC_PART_RPOPUP_TITLE, - _(MUSIC_TEXT_REMOVE)); - elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER); - evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, - _close_cb, dt); - evas_object_show(popup); - - lbl = elm_label_add(popup); - if (!lbl) { - _ERR("Add Evas_Object failed."); - evas_object_del(popup); - return NULL; - } - - elm_object_style_set(lbl, MUSIC_STYLE_REMOVE_LABEL); - elm_object_text_set(lbl, _(msg)); - elm_object_content_set(popup, lbl); - - yesbtn = elm_button_add(popup); - if (!yesbtn) { - _ERR("Add Evas_Object failed."); - evas_object_del(popup); + _ERR("Memory alloc failed"); return NULL; } - elm_object_text_set(yesbtn, _(MUSIC_TEXT_REMOVE)); - elm_object_part_content_set(popup, MUSIC_PART_RPOPUP_BTN1, yesbtn); - evas_object_smart_callback_add(yesbtn, MUSIC_SIGNAL_CLICKED, - _remove_cb, dt); + CPopupWindow::SCallback cb; + cb.cookie = this; + cb.onBtn1Pressed = sm_CbRemove; + cb.onBtn2Pressed = sm_CbCancel; + cb.onBtn3Pressed = NULL; - nobtn = elm_button_add(popup); - if (!nobtn) { - _ERR("Add Evas_Object failed."); - evas_object_del(popup); + if (!popup->Create(base, &cb, msg)) { + _ERR("Pop creation failed"); + delete popup; return NULL; } - elm_object_text_set(nobtn, _(MUSIC_TEXT_CANCEL)); - elm_object_part_content_set(popup, MUSIC_PART_RPOPUP_BTN2, nobtn); - evas_object_smart_callback_add(nobtn, MUSIC_SIGNAL_CLICKED, - _cancel_cb, dt); - elm_object_focus_set(nobtn, EINA_TRUE); - return popup; } void CContextView::m_DestroyPopup(void) { - if (m->popup) - evas_object_del(m->popup); + if (m->popup && m->popup->FlagCreate()) + m->popup->Destroy(); if (m->ctxpopup && m->ctxpopup->FlagCreate()) m->ctxpopup->Destroy(); + delete m->popup; m->popup = NULL; delete m->ctxpopup; m->ctxpopup = NULL; @@ -1257,9 +1203,7 @@ void CContextView::m_HandleBtnSelected(int btnType) break; case CONTEXT_VIEW_BUTTON_DEL: - m->popup = m_CreateRemovePopup(m->base, - MUSIC_TEXT_REMOVE_SMSG, sm_CbPopupKeyPressed, - sm_CbRemove, sm_CbCancel, this); + m->popup = (CRemovePopupWindow *)m_CreateRemovePopup(m->base, MUSIC_TEXT_REMOVE_SMSG); break; case CONTEXT_VIEW_BUTTON_RENAME: @@ -1275,9 +1219,7 @@ void CContextView::m_HandleBtnSelected(int btnType) break; case CONTEXT_VIEW_BUTTON_DELETE: - m->popup = m_CreateRemovePopup(m->base, - MUSIC_TEXT_REMOVE_PLMSG, sm_CbPopupKeyPressed, - sm_CbRemove, sm_CbCancel, this); + m->popup = (CRemovePopupWindow *)m_CreateRemovePopup(m->base, MUSIC_TEXT_REMOVE_PLMSG); break; default: -- 2.7.4