#define MUSIC_CTXT_TABLE_HPAD 14
+enum EObjectType {
+ CONTEXT_VIEW,
+
+ CONTEXT_VIEW_BUTTON_PLAY,
+ CONTEXT_VIEW_BUTTON_NEXT,
+ CONTEXT_VIEW_BUTTON_LAST,
+ CONTEXT_VIEW_BUTTON_ADDTO,
+ CONTEXT_VIEW_BUTTON_PLAYSONG,
+ CONTEXT_VIEW_BUTTON_DEL,
+ CONTEXT_VIEW_BUTTON_RENAME,
+ CONTEXT_VIEW_BUTTON_ADDSONG,
+ CONTEXT_VIEW_BUTTON_REMOVESONG,
+ CONTEXT_VIEW_BUTTON_DELETE,
+
+ CONTEXT_VIEW_MORE_INFO,
+
+ CONTEXT_VIEW_RELATIVE_CONTENT
+};
+
enum EBtnType {
CTXBTN_INVALID = -1,
CTXBTN_PLAY = 0,
struct SBtnInfo {
const char *txt;
const char *icon;
+ EObjectType type;
};
struct SRltvCtnt {
int lid;
CContextView *parent;
- class CHandlerButton : public CListenerMgr,
- public IMouseMoveListener, public IMouseUpListener, public IKeyUpListener,
- public IFocusedListener, public IUnfocusedListener {
- public:
- struct SCallback {
- void(*addScroller)(void* cookie, Evas_Object *base, Evas_Object **scroller);
- void* cookie;
- };
-
- private:
- SContextView *m;
- SCallback m_callback;
-
- private:
- static void sm_CbPopupKeyPressed(void *data, Evas *e, Evas_Object *obj, void *ei)
- {
- CHandlerButton *root = (CHandlerButton *)data;
- if (root)
- root->m_OnPopUpKeyPressed(e, obj, (Evas_Event_Key_Down *)ei);
- }
-
- void m_OnPopUpKeyPressed(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev)
- {
- if (!ev->keyname)
- return;
-
- if (!strcmp(ev->keyname, KEY_BACK))
- m_DestroyPopup();
- }
-
- static void sm_CbRemove(void *data, Evas_Object *obj, void *ei)
- {
- CHandlerButton *root = (CHandlerButton *)data;
- if (root)
- root->m_OnRemove(obj);
- }
-
- void m_OnRemove(Evas_Object *obj)
- {
- SContentInfo *cinfo = NULL;
-
- if (!obj) {
- _ERR("Invalid argument.");
- return;
- }
-
- m_DestroyPopup();
-
- if (!m->ctxtinfo || !m->ctxtinfo->update)
- return;
-
- cinfo = m->ctxtinfo;
- cinfo->update(cinfo->cbdata, ACTION_TYPE_DELETE, 0);
- }
-
- static void sm_CbCancel(void *data, Evas_Object *obj, void *ei)
- {
- CHandlerButton *root = (CHandlerButton *)data;
- if (root)
- root->m_OnCancel(obj);
- }
-
- void m_OnCancel(Evas_Object *obj)
- {
- if (!obj) {
- _ERR("Invalid argument.");
- return;
- }
-
- m_DestroyPopup();
- }
-
- static int sm_CbSortPlaylist(const void *d1, const void *d2)
- {
- SCtxtPlaylistItem *info1 = (SCtxtPlaylistItem *)d1;
- SCtxtPlaylistItem *info2 = (SCtxtPlaylistItem *)d2;
- char *txt1 = NULL;
- char *txt2 = NULL;
-
- txt1 = info1->name;
- txt2 = info2->name;
-
- if (!txt1)
- return 1;
- if (!txt2)
- return -1;
-
- return strcasecmp(txt1, txt2);
- }
-
- static void sm_CbPopupDeleted(void *data, Evas *e, Evas_Object *obj, void *ei)
- {
- Eina_List *list = (Eina_List *)data;
- SCtxtPlaylistItem *item = NULL;
- void *listObj = NULL;
-
- if (!list)
- return;
-
- EINA_LIST_FREE(list, listObj) {
- item = (SCtxtPlaylistItem *)listObj;
- free(item->name);
- free(item);
- }
- }
-
- static void sm_CbPopupBtnClicked(void *data, Evas_Object *obj, void *ei)
- {
- CHandlerButton *root = (CHandlerButton *)data;
- if (root)
- root->m_OnPopupBtnClicked(obj);
- }
-
- void 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);
- }
-
- static Eina_Bool sm_CbSelectIdler(void *dt)
- {
- CHandlerButton *root = (CHandlerButton *)dt;
- Eina_Bool r;
-
- if (root)
- r = root->m_OnSelectIdler();
-
- return r;
- }
-
- Eina_Bool m_OnSelectIdler(void)
- {
- SContentInfo *cinfo = NULL;
-
- m->idler = NULL;
- m_DestroyPopup();
-
- if (!m->ctxtinfo || !m->ctxtinfo->update)
- return ECORE_CALLBACK_CANCEL;
-
- cinfo = m->ctxtinfo;
- cinfo->update(cinfo->cbdata, ACTION_TYPE_ADDTO, m->lid);
- cinfo->close(cinfo->cbdata);
-
- return ECORE_CALLBACK_CANCEL;
- }
-
- private:
- void m_HandleBtnSelected(int btnType)
- {
- SContentInfo *cinfo = NULL;
-
- if (!m->ctxtinfo || !m->ctxtinfo->update)
- return;
-
- EBtnType type = (EBtnType)btnType;
-
- cinfo = m->ctxtinfo;
-
- switch (type) {
- case CTXBTN_PLAY:
- case CTXBTN_PLAYSONG:
- cinfo->update(cinfo->cbdata, ACTION_TYPE_PLAY, 0);
- break;
-
- case CTXBTN_NEXT:
- cinfo->update(cinfo->cbdata, ACTION_TYPE_ADDNEXT, 0);
- break;
-
- case CTXBTN_LAST:
- cinfo->update(cinfo->cbdata, ACTION_TYPE_ADDLAST, 0);
- break;
-
- case CTXBTN_ADDTO:
- m->popup = m_CreatePlaylistPopup();
- if (!m->popup)
- _create_message_box(m->base, MUSIC_TEXT_NOLIST_MSG);
- break;
-
- case CTXBTN_DEL:
- m->popup = m_CreateRemovePopup(m->base,
- MUSIC_TEXT_REMOVE_SMSG, sm_CbPopupKeyPressed,
- sm_CbRemove, sm_CbCancel, this);
- break;
-
- case CTXBTN_RENAME:
- cinfo->update(cinfo->cbdata, ACTION_TYPE_RENAME, 0);
- break;
-
- case CTXBTN_ADDSONG:
- cinfo->update(cinfo->cbdata, ACTION_TYPE_ADDSONG, 0);
- break;
-
- case CTXBTN_REMOVESONG:
- cinfo->update(cinfo->cbdata, ACTION_TYPE_REMOVESONG, 0);
- break;
-
- case CTXBTN_DELETE:
- m->popup = m_CreateRemovePopup(m->base,
- MUSIC_TEXT_REMOVE_PLMSG, sm_CbPopupKeyPressed,
- sm_CbRemove, sm_CbCancel, this);
- break;
-
- default:
- _ERR("Wrong btn type");
- }
- }
-
- Evas_Object *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);
-
- 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);
- }
-
- m_callback.addScroller(m_callback.cookie, popup, &scr);
- if (!scr) {
- evas_object_del(popup);
- 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);
- }
-
- return popup;
- }
-
- 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)
- {
- Evas_Object *popup, *yesbtn, *nobtn, *lbl;
-
- if (!base || !_remove_cb || !_cancel_cb || !dt) {
- _ERR("Invalid argument.");
- return NULL;
- }
-
- popup = elm_popup_add(base);
- 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);
- 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);
-
- nobtn = elm_button_add(popup);
- if (!nobtn) {
- _ERR("Add Evas_Object failed.");
- evas_object_del(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 m_DestroyPopup(void)
- {
- if (!m->popup)
- return;
-
- evas_object_del(m->popup);
- m->popup = NULL;
- }
-
- public:
- CHandlerButton(SContextView *ins) :
- IMouseMoveListener(this),
- IMouseUpListener(this),
- IKeyUpListener(this),
- IFocusedListener(this),
- IUnfocusedListener(this) {
- m = ins;
- }
-
- ~CHandlerButton() {
- m_DestroyPopup();
- }
-
- void SetCallback(const SCallback* cb) {
- m_callback = *cb;
- }
-
- virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev)
- {
- if (!obj)
- return;
-
- if (!elm_object_focus_get(obj))
- elm_object_focus_set(obj, EINA_TRUE);
- }
-
- virtual void OnMouseUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Up *ev)
- {
- m_HandleBtnSelected(id);
- }
-
- virtual void OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev)
- {
- if (strcmp(ev->keyname, KEY_ENTER))
- return;
-
- m_HandleBtnSelected(id);
- }
-
- virtual void OnFocused(int id, Evas_Object *obj, Elm_Object_Item *item)
- {
- if (!obj)
- return;
-
- elm_object_signal_emit(obj, MUSIC_SIGNAL_FOCUSED, MUSIC_CONTEXT_VIEW);
- }
-
- virtual void OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item)
- {
- if (!obj)
- return;
-
- elm_object_signal_emit(obj, MUSIC_SIGNAL_UNFOCUSED, MUSIC_CONTEXT_VIEW);
- }
- } *pHandlerButton;
-
- class CHandlerLayout : public CListenerMgr,
- public IMouseMoveListener, public IMouseUpListener, public IKeyUpListener,
- public IFocusedListener, public IUnfocusedListener {
- protected:
- SContextView *m;
-
- public:
- CHandlerLayout(SContextView *ins) :
- IMouseMoveListener(this),
- IMouseUpListener(this),
- IKeyUpListener(this),
- IFocusedListener(this),
- IUnfocusedListener(this) {
- m = ins;
- };
-
- virtual void OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev)
- {
- if (!obj)
- return;
-
- if (!elm_object_focus_get(obj))
- elm_object_focus_set(obj, EINA_TRUE);
- }
-
- virtual void OnMouseUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Up *ev) = 0;
- virtual void OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev) = 0;
-
- virtual void OnFocused(int id, Evas_Object *obj, Elm_Object_Item *item)
- {
- if (!obj)
- return;
-
- elm_object_signal_emit(obj, MUSIC_SIGNAL_FOCUSED, MUSIC_CONTEXT_VIEW);
- }
-
- virtual void OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item)
- {
- if (!obj)
- return;
-
- elm_object_signal_emit(obj, MUSIC_SIGNAL_UNFOCUSED, MUSIC_CONTEXT_VIEW);
- }
- };
-
- class CHandlerRelativeContentLayout : public CHandlerLayout {
- public:
- CHandlerRelativeContentLayout(SContextView *ins) : CHandlerLayout(ins) {}
-
- virtual void OnMouseUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Up *ev)
- {
- if (!obj)
- return;
-
- elm_object_signal_emit(obj, MUSIC_SIGNAL_CONTENT_CLICKED,
- MUSIC_CONTEXT_VIEW);
- }
-
- virtual void OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev)
- {
- if (!obj || !ev)
- return;
-
- if (strcmp(ev->keyname, KEY_ENTER))
- return;
-
- elm_object_signal_emit(obj, MUSIC_SIGNAL_CONTENT_CLICKED,
- MUSIC_CONTEXT_VIEW);
- }
- };
-
- Eina_List *listRltvCtntLayout;
-
- class CHandlerMoreInfoLayout : public CHandlerLayout {
- private:
- void m_HandleMoreinfoSelected(Evas_Object *obj)
- {
- SRltvCtnt *rctnt = NULL;
-
- if (!obj)
- return;
-
- rctnt = (SRltvCtnt *)_GET_PRIV(obj);
- if (!rctnt)
- return;
-
- /* Using prints till actual APIs come from wiki and youtube */
- switch (m->type) {
- case CONTEXT_TYPE_ALBUM:
- _INFO("Album more info clicked %s", rctnt->link);
- break;
-
- case CONTEXT_TYPE_ARTIST:
- _INFO("Artist more info clicked %s", rctnt->link);
- break;
-
- case CONTEXT_TYPE_GENRE:
- _INFO("Genre more info clicked %s", rctnt->link);
- break;
-
- default:
- _ERR("Wrong content type for more info");
- }
- }
-
- public:
- CHandlerMoreInfoLayout(SContextView *ins) : CHandlerLayout(ins) {}
-
- virtual void OnMouseUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Up *ev)
- {
- if (!obj)
- return;
-
- m_HandleMoreinfoSelected(obj);
- }
-
- virtual void OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev)
- {
- if (!obj || !ev)
- return;
-
- if (strcmp(ev->keyname, KEY_ENTER))
- return;
-
- m_HandleMoreinfoSelected(obj);
- }
- } *pHandlerMoreInfoLayout;
-
SContextView() {
memset(this, 0, sizeof(SContextView));
- pHandlerButton = new CHandlerButton(this);
- pHandlerMoreInfoLayout = new CHandlerMoreInfoLayout(this);
}
~SContextView() {
- delete pHandlerButton;
- delete pHandlerMoreInfoLayout;
}
};
}
-void CContextView::sm_CbAddScroller(void *cookie, Evas_Object *base, Evas_Object **scroller)
+void CContextView::sm_CbPopupKeyPressed(void *data, Evas *e, Evas_Object *obj, void *ei)
{
- CContextView *root = (CContextView *)cookie;
+ CContextView *root = (CContextView *)data;
if (root)
- root->m_OnAddScroller(base, scroller);
+ root->m_OnPopUpKeyPressed(e, obj, (Evas_Event_Key_Down *)ei);
+}
+
+
+void CContextView::m_OnPopUpKeyPressed(Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev)
+{
+ if (!ev->keyname)
+ return;
+
+ if (!strcmp(ev->keyname, KEY_BACK))
+ 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)
+{
+ SContentInfo *cinfo = NULL;
+
+ if (!obj) {
+ _ERR("Invalid argument.");
+ return;
+ }
+
+ m_DestroyPopup();
+
+ if (!m->ctxtinfo || !m->ctxtinfo->update)
+ return;
+
+ cinfo = m->ctxtinfo;
+ cinfo->update(cinfo->cbdata, ACTION_TYPE_DELETE, 0);
+}
+
+
+void CContextView::sm_CbCancel(void *data, Evas_Object *obj, void *ei)
+{
+ CContextView *root = (CContextView *)data;
+ if (root)
+ root->m_OnCancel(obj);
+}
+
+
+void CContextView::m_OnCancel(Evas_Object *obj)
+{
+ if (!obj) {
+ _ERR("Invalid argument.");
+ return;
+ }
+
+ m_DestroyPopup();
+}
+
+
+int CContextView::sm_CbSortPlaylist(const void *d1, const void *d2)
+{
+ SCtxtPlaylistItem *info1 = (SCtxtPlaylistItem *)d1;
+ SCtxtPlaylistItem *info2 = (SCtxtPlaylistItem *)d2;
+ char *txt1 = NULL;
+ char *txt2 = NULL;
+
+ txt1 = info1->name;
+ txt2 = info2->name;
+
+ if (!txt1)
+ return 1;
+ if (!txt2)
+ return -1;
+
+ return strcasecmp(txt1, txt2);
+}
+
+
+void CContextView::sm_CbPopupDeleted(void *data, Evas *e, Evas_Object *obj, void *ei)
+{
+ Eina_List *list = (Eina_List *)data;
+ SCtxtPlaylistItem *item = NULL;
+ void *listObj = NULL;
+
+ if (!list)
+ return;
+
+ EINA_LIST_FREE(list, listObj) {
+ item = (SCtxtPlaylistItem *)listObj;
+ free(item->name);
+ free(item);
+ }
+}
+
+
+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;
+
+ if (root)
+ r = root->m_OnSelectIdler();
+
+ return r;
}
-void CContextView::m_OnAddScroller(Evas_Object *base, Evas_Object **scroller)
+Eina_Bool CContextView::m_OnSelectIdler(void)
{
- Evas_Object *scr = m_AddScroller(base);
- *scroller = scr;
+ SContentInfo *cinfo = NULL;
+
+ m->idler = NULL;
+ m_DestroyPopup();
+
+ if (!m->ctxtinfo || !m->ctxtinfo->update)
+ return ECORE_CALLBACK_CANCEL;
+
+ cinfo = m->ctxtinfo;
+ cinfo->update(cinfo->cbdata, ACTION_TYPE_ADDTO, m->lid);
+ cinfo->close(cinfo->cbdata);
+
+ return ECORE_CALLBACK_CANCEL;
}
btninfo[CTXBTN_PLAY].txt = MUSIC_TEXT_PLAY_THIS;
btninfo[CTXBTN_PLAY].icon = MUSIC_IMAGE_CTXT_BTNPLAY;
+ btninfo[CTXBTN_PLAY].type = CONTEXT_VIEW_BUTTON_PLAY;
btninfo[CTXBTN_NEXT].txt = MUSIC_TEXT_ADD_NEXT;
btninfo[CTXBTN_NEXT].icon = MUSIC_IMAGE_CTXT_BTNNEXT;
+ btninfo[CTXBTN_NEXT].type = CONTEXT_VIEW_BUTTON_NEXT;
btninfo[CTXBTN_LAST].txt = MUSIC_TEXT_ADD_LAST;
btninfo[CTXBTN_LAST].icon = MUSIC_IMAGE_CTXT_BTNLAST;
+ btninfo[CTXBTN_LAST].type = CONTEXT_VIEW_BUTTON_LAST;
btninfo[CTXBTN_ADDTO].txt = MUSIC_TEXT_ADD_TO_PLAYLIST;
btninfo[CTXBTN_ADDTO].icon = MUSIC_IMAGE_CTXT_ADDTO;
+ btninfo[CTXBTN_ADDTO].type = CONTEXT_VIEW_BUTTON_ADDTO;
btninfo[CTXBTN_PLAYSONG].txt = MUSIC_TEXT_PLAY;
btninfo[CTXBTN_PLAYSONG].icon = MUSIC_IMAGE_CTXT_BTNPLAY;
+ btninfo[CTXBTN_PLAYSONG].type = CONTEXT_VIEW_BUTTON_PLAYSONG;
btninfo[CTXBTN_DEL].txt = MUSIC_TEXT_DEL;
btninfo[CTXBTN_DEL].icon = MUSIC_IMAGE_CTXT_BTNDEL;
+ btninfo[CTXBTN_DEL].type = CONTEXT_VIEW_BUTTON_DEL;
btninfo[CTXBTN_RENAME].txt = MUSIC_TEXT_RENAME;
btninfo[CTXBTN_RENAME].icon = MUSIC_IMAGE_CTXT_RENAME;
+ btninfo[CTXBTN_RENAME].type = CONTEXT_VIEW_BUTTON_RENAME;
btninfo[CTXBTN_ADDSONG].txt = MUSIC_TEXT_ADDSONG;
btninfo[CTXBTN_ADDSONG].icon = MUSIC_IMAGE_CTXT_ADDSONG;
+ btninfo[CTXBTN_ADDSONG].type = CONTEXT_VIEW_BUTTON_ADDSONG;
btninfo[CTXBTN_REMOVESONG].txt = MUSIC_TEXT_REMOVESONG;
btninfo[CTXBTN_REMOVESONG].icon = MUSIC_IMAGE_CTXT_REMOVESONG;
+ btninfo[CTXBTN_REMOVESONG].type = CONTEXT_VIEW_BUTTON_REMOVESONG;
btninfo[CTXBTN_DELETE].txt = MUSIC_TEXT_DEL;
btninfo[CTXBTN_DELETE].icon = MUSIC_IMAGE_CTXT_BTNDEL;
+ btninfo[CTXBTN_DELETE].type = CONTEXT_VIEW_BUTTON_DELETE;
box = m_AddBtnBox(m->base);
if (!box)
return false;
}
- m->pHandlerButton->Connect(btn, i);
+ Connect(btn, btninfo[i].type, TYPE_MOUSE_MOVE | TYPE_MOUSE_UP | TYPE_KEY_UP | TYPE_FOCUSED | TYPE_UNFOCUSED);
if (!m_AddBtnInfo(btn, btninfo[i].icon, btninfo[i].txt)) {
evas_object_del(box);
Evas_Object *ly = NULL;
Eina_List *l = NULL;
SRltvCtnt *rctnt = NULL;
- SContextView::CHandlerRelativeContentLayout *layoutHandler = NULL;
+ int objectId = (int)CONTEXT_VIEW_RELATIVE_CONTENT;
void *obj = NULL;
if (!list)
elm_object_signal_callback_add(ly, MUSIC_SIGNAL_BTN_CLICKED,
MUSIC_CONTEXT_VIEW, sm_CbRltdCtntSelected, m);
- layoutHandler = new SContextView::CHandlerRelativeContentLayout(m);
- layoutHandler->Connect(ly);
- m->listRltvCtntLayout = eina_list_append(m->listRltvCtntLayout, layoutHandler);
+ Connect(ly, objectId, TYPE_MOUSE_MOVE | TYPE_MOUSE_UP | TYPE_KEY_UP | TYPE_FOCUSED | TYPE_UNFOCUSED);
+ objectId++;
if (row == 0)
m->first_line[col] = ly;
elm_object_focus_allow_set(ly, EINA_TRUE);
_SET_PRIV(ly, rctnt);
- m->pHandlerMoreInfoLayout->Connect(ly);
+ Connect(ly, CONTEXT_VIEW_MORE_INFO, TYPE_MOUSE_MOVE | TYPE_MOUSE_UP | TYPE_KEY_UP | TYPE_FOCUSED | TYPE_UNFOCUSED);
elm_object_focus_next_object_set(ly, ly, ELM_FOCUS_LEFT);
elm_object_focus_next_object_set(ly, ly, ELM_FOCUS_RIGHT);
}
+Evas_Object *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);
+
+ 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);
+ 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);
+ }
+
+ return popup;
+}
+
+
+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)
+{
+ Evas_Object *popup, *yesbtn, *nobtn, *lbl;
+
+ if (!base || !_remove_cb || !_cancel_cb || !dt) {
+ _ERR("Invalid argument.");
+ return NULL;
+ }
+
+ popup = elm_popup_add(base);
+ 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);
+ 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);
+
+ nobtn = elm_button_add(popup);
+ if (!nobtn) {
+ _ERR("Add Evas_Object failed.");
+ evas_object_del(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)
+ return;
+
+ evas_object_del(m->popup);
+ m->popup = NULL;
+}
+
+
+void CContextView::m_HandleBtnSelected(int btnType)
+{
+ SContentInfo *cinfo = NULL;
+
+ if (!m->ctxtinfo || !m->ctxtinfo->update)
+ return;
+
+ EBtnType type = (EBtnType)btnType;
+
+ cinfo = m->ctxtinfo;
+
+ switch (type) {
+ case CONTEXT_VIEW_BUTTON_PLAY:
+ case CONTEXT_VIEW_BUTTON_PLAYSONG:
+ cinfo->update(cinfo->cbdata, ACTION_TYPE_PLAY, 0);
+ break;
+
+ case CONTEXT_VIEW_BUTTON_NEXT:
+ cinfo->update(cinfo->cbdata, ACTION_TYPE_ADDNEXT, 0);
+ break;
+
+ case CONTEXT_VIEW_BUTTON_LAST:
+ cinfo->update(cinfo->cbdata, ACTION_TYPE_ADDLAST, 0);
+ break;
+
+ case CONTEXT_VIEW_BUTTON_ADDTO:
+ m->popup = m_CreatePlaylistPopup();
+ if (!m->popup)
+ _create_message_box(m->base, MUSIC_TEXT_NOLIST_MSG);
+ break;
+
+ case CONTEXT_VIEW_BUTTON_DEL:
+ m->popup = m_CreateRemovePopup(m->base,
+ MUSIC_TEXT_REMOVE_SMSG, sm_CbPopupKeyPressed,
+ sm_CbRemove, sm_CbCancel, this);
+ break;
+
+ case CONTEXT_VIEW_BUTTON_RENAME:
+ cinfo->update(cinfo->cbdata, ACTION_TYPE_RENAME, 0);
+ break;
+
+ case CONTEXT_VIEW_BUTTON_ADDSONG:
+ cinfo->update(cinfo->cbdata, ACTION_TYPE_ADDSONG, 0);
+ break;
+
+ case CONTEXT_VIEW_BUTTON_REMOVESONG:
+ cinfo->update(cinfo->cbdata, ACTION_TYPE_REMOVESONG, 0);
+ break;
+
+ case CONTEXT_VIEW_BUTTON_DELETE:
+ m->popup = m_CreateRemovePopup(m->base,
+ MUSIC_TEXT_REMOVE_PLMSG, sm_CbPopupKeyPressed,
+ sm_CbRemove, sm_CbCancel, this);
+ break;
+
+ default:
+ _ERR("Wrong btn type");
+ }
+}
+
+
+void CContextView::m_HandleMoreinfoSelected(Evas_Object *obj)
+{
+ SRltvCtnt *rctnt = NULL;
+
+ if (!obj)
+ return;
+
+ rctnt = (SRltvCtnt *)_GET_PRIV(obj);
+ if (!rctnt)
+ return;
+
+ /* Using prints till actual APIs come from wiki and youtube */
+ switch (m->type) {
+ case CONTEXT_TYPE_ALBUM:
+ _INFO("Album more info clicked %s", rctnt->link);
+ break;
+
+ case CONTEXT_TYPE_ARTIST:
+ _INFO("Artist more info clicked %s", rctnt->link);
+ break;
+
+ case CONTEXT_TYPE_GENRE:
+ _INFO("Genre more info clicked %s", rctnt->link);
+ break;
+
+ default:
+ _ERR("Wrong content type for more info");
+ }
+}
+
+
bool CContextView::Create(void *data)
{
ASSERT(!m);
m->base = base;
m->ctxtinfo = ctxtinfo;
m->parent = this;
- m->listRltvCtntLayout = NULL;
if (!m_CreateFullView()) {
_ERR(" create full failed ");
Connect(base);
- SContextView::CHandlerButton::SCallback cb;
- cb.addScroller = &sm_CbAddScroller;
- cb.cookie = this;
- m->pHandlerButton->SetCallback(&cb);
-
return true;
}
if (m->idler)
ecore_idler_del(m->idler);
- if (m->listRltvCtntLayout) {
- SContextView::CHandlerRelativeContentLayout *layoutHandler;
- void *obj;
- EINA_LIST_FREE(m->listRltvCtntLayout, obj) {
- layoutHandler = (SContextView::CHandlerRelativeContentLayout *)obj;
- delete layoutHandler;
- }
- }
-
CBaseView::Destroy();
evas_object_del(m->base);
void CContextView::OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev)
{
- if (!strcmp(ev->keyname, KEY_BACK)) {
- if (m->ctxtinfo && m->ctxtinfo->close)
- m->ctxtinfo->close(m->ctxtinfo->cbdata);
+ switch (id) {
+ case CONTEXT_VIEW:
+ {
+ if (!strcmp(ev->keyname, KEY_BACK)) {
+ if (m->ctxtinfo && m->ctxtinfo->close)
+ m->ctxtinfo->close(m->ctxtinfo->cbdata);
+ }
+ else if (!strcmp(ev->keyname, KEY_EXIT))
+ elm_exit();
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+void CContextView::OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev)
+{
+ switch (id) {
+ case CONTEXT_VIEW:
+ break;
+
+ case CONTEXT_VIEW_BUTTON_PLAY:
+ case CONTEXT_VIEW_BUTTON_NEXT:
+ case CONTEXT_VIEW_BUTTON_LAST:
+ case CONTEXT_VIEW_BUTTON_ADDTO:
+ case CONTEXT_VIEW_BUTTON_PLAYSONG:
+ case CONTEXT_VIEW_BUTTON_DEL:
+ case CONTEXT_VIEW_BUTTON_RENAME:
+ case CONTEXT_VIEW_BUTTON_ADDSONG:
+ case CONTEXT_VIEW_BUTTON_REMOVESONG:
+ case CONTEXT_VIEW_BUTTON_DELETE:
+ {
+ if (strcmp(ev->keyname, KEY_ENTER))
+ return;
+
+ m_HandleBtnSelected(id);
+ }
+ break;
+
+ case CONTEXT_VIEW_MORE_INFO:
+ {
+ if (!obj || !ev)
+ return;
+
+ if (strcmp(ev->keyname, KEY_ENTER))
+ return;
+
+ m_HandleMoreinfoSelected(obj);
+ }
+ break;
+
+ default: // CONTEXT_VIEW_RELATIVE_CONTENT
+ {
+ if (!obj || !ev)
+ return;
+
+ if (strcmp(ev->keyname, KEY_ENTER))
+ return;
+
+ elm_object_signal_emit(obj, MUSIC_SIGNAL_CONTENT_CLICKED,
+ MUSIC_CONTEXT_VIEW);
+ }
+ break;
+ }
+}
+
+
+void CContextView::OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev)
+{
+ switch (id) {
+ case CONTEXT_VIEW:
+ break;
+
+ default:
+ {
+ if (!obj)
+ return;
+
+ if (!elm_object_focus_get(obj))
+ elm_object_focus_set(obj, EINA_TRUE);
+ }
+ break;
+ }
+}
+
+
+void CContextView::OnMouseUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Up *ev)
+{
+ switch (id) {
+ case CONTEXT_VIEW:
+ break;
+
+ case CONTEXT_VIEW_BUTTON_PLAY:
+ case CONTEXT_VIEW_BUTTON_NEXT:
+ case CONTEXT_VIEW_BUTTON_LAST:
+ case CONTEXT_VIEW_BUTTON_ADDTO:
+ case CONTEXT_VIEW_BUTTON_PLAYSONG:
+ case CONTEXT_VIEW_BUTTON_DEL:
+ case CONTEXT_VIEW_BUTTON_RENAME:
+ case CONTEXT_VIEW_BUTTON_ADDSONG:
+ case CONTEXT_VIEW_BUTTON_REMOVESONG:
+ case CONTEXT_VIEW_BUTTON_DELETE:
+ {
+ m_HandleBtnSelected(id);
+ }
+ break;
+
+ case CONTEXT_VIEW_MORE_INFO:
+ {
+ if (!obj)
+ return;
+
+ m_HandleMoreinfoSelected(obj);
+ }
+ break;
+
+ default: // CONTEXT_VIEW_RELATIVE_CONTENT
+ {
+ if (!obj)
+ return;
+
+ elm_object_signal_emit(obj, MUSIC_SIGNAL_CONTENT_CLICKED,
+ MUSIC_CONTEXT_VIEW);
+ }
+ break;
+ }
+}
+
+
+void CContextView::OnFocused(int id, Evas_Object *obj, Elm_Object_Item *item)
+{
+ switch (id) {
+ case CONTEXT_VIEW:
+ break;
+
+ default:
+ {
+ if (!obj)
+ return;
+
+ elm_object_signal_emit(obj, MUSIC_SIGNAL_FOCUSED, MUSIC_CONTEXT_VIEW);
+ }
+ break;
+ }
+}
+
+
+void CContextView::OnUnfocused(int id, Evas_Object *obj, Elm_Object_Item *item)
+{
+ switch (id) {
+ case CONTEXT_VIEW:
+ break;
+
+ default:
+ {
+ if (!obj)
+ return;
+
+ elm_object_signal_emit(obj, MUSIC_SIGNAL_UNFOCUSED, MUSIC_CONTEXT_VIEW);
+ }
+ break;
}
- else if (!strcmp(ev->keyname, KEY_EXIT))
- elm_exit();
}