2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <AppCommon.h>
22 #include "song_info.h"
23 #include "album_info.h"
24 #include "music-controller.h"
25 #include "volume-control.h"
26 #include "common-ui.h"
27 #include "playback-view.h"
28 #include "context-view.h"
29 #include "HandleVolume.h"
30 #include "PlaySettingCtxPopup.h"
32 #include "SliderWidget.h"
33 #include "PlaybackController.h"
34 #include "AlbumCover.h"
35 #include "SongTitleLabel.h"
38 #define TOTAL_CONTROL_BTNS 6
39 #define TOTAL_EDIT_BTNS 3
48 Elm_Object_Item *item;
55 struct SPlaybackView {
57 Evas_Object *eoPlaylist;
59 Elm_Object_Item *focused_item;
61 CPlaybackController *pPlaybackController;
62 // These are reference values.
63 Evas_Object *eoBtnControl[TOTAL_CONTROL_BTNS];
64 Evas_Object *eoBtnEdit[TOTAL_EDIT_BTNS];
66 CAlbumCover *pAlbumCover;
67 CSliderWidget *pSliderWidget;
68 CSongTitleLabel *pSongTitleLabel;
71 CMusicController *pController; //! NOT NULL
75 SContentInfo *ctxtinfo;
77 CHandleVolume *pHandleVolume;
82 memset(this, 0, sizeof(SPlaybackView));
87 void CPlaybackView::sm_CbCtxtUpdate(void *dt, enum EActionType type, int lid)
89 CPlaybackView *root = (CPlaybackView *)dt;
91 root->m_OnCtxtUpdate(type, lid);
95 void CPlaybackView::m_OnCtxtUpdate(EActionType type, int lid)
97 SItemInfo *itinfo = NULL;
98 Elm_Object_Item *focusedItem = NULL;
100 if (!m->ctxtinfo || !m->ctxtinfo->context)
103 itinfo = m_FindItemInfoFromSong(m->elInfo,
104 (CSongInfo *)m->ctxtinfo->context);
106 _ERR(" Unable to find song in the list ");
110 if (type == ACTION_TYPE_DELETE) {
111 itinfo->check_status = true;
112 m_DeleteSelectedItems();
114 if (!m->mgr->PopView()) {
115 _ERR("CViewMgr::PopView failed");
120 memset(&parcel, 0, sizeof(SParcel));
121 parcel.updateType = E_PLAYLIST_UPDATE;
124 focusedItem = m->cs_itinfo->item;
126 else { // ACTION_TYPE_PLAY
127 if (m->ctxtinfo->status == PLAY_STATUS_PLAY)
130 if (itinfo == m->cs_itinfo)
133 m_HandleGenlistItemActivated(m->eoPlaylist, itinfo->item);
136 if (!m->mgr->PopView()) {
137 _ERR("CViewMgr::PopView failed");
141 focusedItem = m->focused_item;
144 if (!CViewMgr::GetInstance()->HideView(MUSIC_BASE_VIEW))
145 _ERR("CViewMgr::HideView failed");
150 elm_genlist_item_show(focusedItem, ELM_GENLIST_ITEM_SCROLLTO_IN);
151 elm_object_item_focus_set(focusedItem, EINA_TRUE);
156 void CPlaybackView::sm_CbCtxtClose(void *dt)
158 CPlaybackView *root = (CPlaybackView *)dt;
160 root->m_OnCtxtClose();
164 void CPlaybackView::m_OnCtxtClose(void)
166 if (!m->mgr->PopView()) {
167 _ERR("CViewMgr::PopView failed");
171 elm_object_item_focus_set(m->focused_item, EINA_TRUE);
175 int CPlaybackView::sm_CbCurrentSongCount(void *cookie)
177 CPlaybackView *root = (CPlaybackView *)cookie;
180 ret = root->m_CbCurrentSongCount();
186 int CPlaybackView::m_CbCurrentSongCount(void)
188 return eina_list_count(m->elInfo);
192 void CPlaybackView::m_ChangeEditmodeAll(Eina_List *list, bool flag)
194 SItemInfo *itinfo = NULL;
198 EINA_LIST_FOREACH(list, l, obj) {
199 itinfo = (SItemInfo *)obj;
200 itinfo->edit_mode = flag;
205 void CPlaybackView::m_DisableCheckAll(Eina_List *list)
207 SItemInfo *itinfo = NULL;
211 EINA_LIST_FOREACH(list, l, obj) {
212 itinfo = (SItemInfo *)obj;
213 itinfo->check_status = false;
216 m->numCheckedItem = 0;
220 void CPlaybackView::m_SelectItem(SItemInfo *pItemInfo)
222 if (!pItemInfo || !pItemInfo->item)
225 elm_genlist_item_bring_in(pItemInfo->item, ELM_GENLIST_ITEM_SCROLLTO_IN);
226 elm_object_item_signal_emit(pItemInfo->item, MUSIC_SIGNAL_SELECT_ITEM, MUSIC_PLAYBACK_VIEW);
228 pItemInfo->select_status = true;
232 void CPlaybackView::m_UnselectItem(SItemInfo *pItemInfo)
234 if (!pItemInfo || !pItemInfo->item)
237 elm_object_item_signal_emit(pItemInfo->item, MUSIC_SIGNAL_UNSELECT_ITEM,
238 MUSIC_PLAYBACK_VIEW);
240 pItemInfo->select_status = false;
244 void CPlaybackView::m_UpdateEmptySongInfo(void)
246 m->pController->SetPlayState(PLAY_STATUS_INITIAL);
250 void CPlaybackView::m_UpdateCtxtView(int playStatus)
252 if (!m->cs_itinfo || !m->ctxtinfo)
255 if (!m->mgr->CheckTop(MUSIC_CONTEXT_VIEW))
258 if (m->cs_itinfo->sinfo == m->ctxtinfo->context) {
259 m->ctxtinfo->status = (EPlayStatus)playStatus;
262 memset(&parcel, 0, sizeof(SParcel));
263 parcel.updateType = E_SONG_UPDATE;
264 m->mgr->UpdateView((const char *)MUSIC_CONTEXT_VIEW, &parcel);
269 void CPlaybackView::m_UpdateCurrentSongItem(int index)
271 SItemInfo *pItemInfo = NULL;
274 m_UnselectItem(m->cs_itinfo);
275 m_UpdateCtxtView(PLAY_STATUS_PAUSE);
278 pItemInfo = (SItemInfo *)eina_list_nth(m->elInfo, index);
281 m->cs_itinfo = pItemInfo;
282 if (m->pController->PlayState() == PLAY_STATUS_STOP) {
283 elm_genlist_item_bring_in(pItemInfo->item,
284 ELM_GENLIST_ITEM_SCROLLTO_IN);
287 m_SelectItem(pItemInfo);
288 m_UpdateCtxtView(PLAY_STATUS_PLAY);
294 void CPlaybackView::m_UpdateEditmodeFocusSequence(void)
296 elm_object_focus_next_object_set(m->eoPlaylist, m->eoBtnEdit[EDIT_BTN_CANCEL], ELM_FOCUS_LEFT);
297 elm_object_focus_next_object_set(m->eoBtnEdit[EDIT_BTN_CANCEL], m->eoPlaylist, ELM_FOCUS_RIGHT);
298 elm_object_focus_next_object_set(m->pSliderWidget->Base(), m->eoBtnEdit[EDIT_BTN_CANCEL], ELM_FOCUS_DOWN);
302 void CPlaybackView::m_UpdatePlaymodeFocusSequence(void)
304 switch (m->pController->PlayState()) {
305 case PLAY_STATUS_INITIAL:
309 case PLAY_STATUS_STOP:
310 elm_object_focus_next_object_set(m->eoPlaylist, m->eoBtnControl[CTRL_BTN_PLAY], ELM_FOCUS_LEFT);
311 elm_object_focus_next_object_set(m->eoBtnControl[CTRL_BTN_PLAY], m->eoPlaylist, ELM_FOCUS_RIGHT);
312 elm_object_focus_next_object_set(m->eoBtnControl[CTRL_BTN_PLAY], m->eoBtnControl[CTRL_BTN_REPEAT], ELM_FOCUS_LEFT);
313 elm_object_focus_next_object_set(m->eoBtnControl[CTRL_BTN_REPEAT], m->eoBtnControl[CTRL_BTN_PLAY], ELM_FOCUS_RIGHT);
314 elm_object_signal_emit(m->eoBtnControl[CTRL_BTN_PLAY], MUSIC_SIGNAL_PAUSE, MUSIC_PLAYBACK_VIEW);
317 case PLAY_STATUS_PLAY:
318 case PLAY_STATUS_PAUSE:
319 elm_object_focus_next_object_set(m->eoPlaylist,
320 m->eoBtnControl[CTRL_BTN_FORWARD], ELM_FOCUS_LEFT);
321 elm_object_focus_next_object_set(m->eoBtnControl[CTRL_BTN_FORWARD],
322 m->eoPlaylist, ELM_FOCUS_RIGHT);
323 elm_object_focus_next_object_set(m->eoBtnControl[CTRL_BTN_PLAY],
324 m->eoBtnControl[CTRL_BTN_FORWARD], ELM_FOCUS_RIGHT);
325 elm_object_focus_next_object_set(m->eoBtnControl[CTRL_BTN_PLAY],
326 m->eoBtnControl[CTRL_BTN_REWIND], ELM_FOCUS_LEFT);
327 elm_object_focus_next_object_set(m->eoBtnControl[CTRL_BTN_REPEAT],
328 m->eoBtnControl[CTRL_BTN_REWIND], ELM_FOCUS_RIGHT);
332 ASSERT(!"Invalid State");
338 void CPlaybackView::m_UpdateCurrentSongInfo(void)
340 CSongInfo *sinfo = NULL;
343 if (eina_list_count(m->elInfo) == 0) {
344 m->pController->EmptyPlaylist();
348 if (!m->pController->GetCurrentSongIndex(&index)) {
349 _ERR(" music get current song index failed ");
353 if (!m->pController->GetSonginfoFromIndex(index, &sinfo)) {
354 _ERR(" music get songinfo failed ");
359 m_UpdateCurrentSongItem(index);
360 m->pController->UpdatePlayerUI();
361 m_UpdatePlaymodeFocusSequence();
365 void CPlaybackView::m_DisableEditButtons(bool flag)
367 /* flag - 1 means disable edit buttons and 0 means enable */
369 elm_object_focus_set(m->eoBtnEdit[EDIT_BTN_CANCEL], EINA_TRUE);
371 elm_object_disabled_set(m->eoBtnEdit[EDIT_BTN_DELETE], (Eina_Bool)flag);
372 elm_object_disabled_set(m->eoBtnEdit[EDIT_BTN_DESELECT], (Eina_Bool)flag);
374 m_UpdateEditmodeFocusSequence();
375 elm_object_focus_set(m->eoBtnEdit[EDIT_BTN_CANCEL], EINA_TRUE);
378 elm_object_focus_next_object_set(m->eoBtnEdit[EDIT_BTN_CANCEL], m->eoBtnEdit[EDIT_BTN_DESELECT], ELM_FOCUS_RIGHT);
379 elm_object_focus_next_object_set(m->eoBtnEdit[EDIT_BTN_DELETE], m->eoPlaylist, ELM_FOCUS_RIGHT);
380 elm_object_focus_next_object_set(m->eoPlaylist, m->eoBtnEdit[EDIT_BTN_DELETE], ELM_FOCUS_LEFT);
385 void CPlaybackView::m_FromEditToPlaybackMode(void)
387 if (m->pController->PlayState() == PLAY_STATUS_STOP) {
388 elm_genlist_item_bring_in(m->cs_itinfo->item,
389 ELM_GENLIST_ITEM_SCROLLTO_IN);
392 m_SelectItem(m->cs_itinfo);
394 elm_object_signal_emit(Base(), MUSIC_SIGNAL_PLAYBACK_MODE,
395 MUSIC_PLAYBACK_VIEW);
396 elm_object_focus_set(m->eoBtnControl[CTRL_BTN_SETTINGS], EINA_TRUE);
398 m_ChangeEditmodeAll(m->elInfo, false);
400 elm_genlist_realized_items_update(m->eoPlaylist);
402 m_UpdatePlaymodeFocusSequence();
406 void CPlaybackView::m_FromPlaybackToEditMode(void)
408 elm_object_signal_emit(Base(), MUSIC_SIGNAL_EDIT_MODE,
409 MUSIC_PLAYBACK_VIEW);
411 m_DisableEditButtons(true);
413 elm_object_focus_set(m->eoBtnEdit[EDIT_BTN_CANCEL], EINA_TRUE);
415 m_ChangeEditmodeAll(m->elInfo, true);
417 elm_genlist_realized_items_update(m->eoPlaylist);
419 m_UpdateEditmodeFocusSequence();
423 void CPlaybackView::m_DeleteSelectedItems(void)
425 Eina_List *l = NULL, *l_next = NULL;
426 SItemInfo *pItemInfo = NULL;
428 bool updateFlag = false;
431 m_DisableEditButtons(true);
432 m->numCheckedItem = 0;
433 EINA_LIST_FOREACH_SAFE(m->elInfo, l, l_next, obj) {
434 pItemInfo = (SItemInfo *)obj;
435 if (pItemInfo->check_status) {
436 if (m->cs_itinfo == pItemInfo) {
438 m_UnselectItem(m->cs_itinfo);
440 m->pController->SetPlayState(PLAY_STATUS_STOP);
441 m->pController->Stop();
443 index = elm_genlist_item_index_get(pItemInfo->item);
444 m->pController->RemoveSong(pItemInfo->sinfo, index);
446 m->elInfo = eina_list_remove(m->elInfo, pItemInfo);
447 elm_object_item_del(pItemInfo->item);
451 if (eina_list_count(m->elInfo) == 0) {
452 m->pController->EmptyPlaylist();
453 elm_genlist_realized_items_update(m->eoPlaylist);
454 elm_object_focus_set(m->eoBtnEdit[EDIT_BTN_CANCEL], EINA_TRUE);
459 m_UpdateCurrentSongInfo();
461 elm_genlist_realized_items_update(m->eoPlaylist);
462 elm_object_focus_set(m->eoBtnEdit[EDIT_BTN_CANCEL], EINA_TRUE);
466 void CPlaybackView::m_KeyBackPress(void)
470 if (!CViewMgr::GetInstance()->ShowView(MUSIC_BASE_VIEW))
471 _ERR("CViewMgr::ShowView failed");
473 if (CViewMgr::GetInstance()->CheckTop(MUSIC_CONTEXT_VIEW)) {
474 if (!CViewMgr::GetInstance()->UpdateView(MUSIC_CONTEXT_VIEW, NULL))
475 _ERR("CViewMgr::UpdateView failed");
477 if (!CViewMgr::GetInstance()->ShowView(MUSIC_CONTEXT_VIEW))
478 _ERR("CViewMgr::ShowView failed");
483 void CPlaybackView::m_KeyExitPress(void)
485 m->pController->Stop();
490 void CPlaybackView::m_KeyPlayPress(void)
494 if (elm_object_disabled_get(m->eoBtnControl[CTRL_BTN_PLAY]))
497 state = m->pController->PlayState();
498 if (state == PLAY_STATUS_PAUSE) {
499 m->pController->Resume();
500 elm_object_signal_emit(m->eoBtnControl[CTRL_BTN_PLAY],
501 MUSIC_SIGNAL_PLAY, MUSIC_PLAYBACK_VIEW);
503 else if (state != PLAY_STATUS_PLAY) {
504 m->pController->Start();
509 void CPlaybackView::m_KeyPausePress(void)
513 if (elm_object_disabled_get(m->eoBtnControl[CTRL_BTN_PLAY]))
516 state = m->pController->PlayState();
517 if (state == PLAY_STATUS_PLAY) {
518 elm_object_signal_emit(m->eoBtnControl[CTRL_BTN_PLAY],
519 MUSIC_SIGNAL_PAUSE, MUSIC_PLAYBACK_VIEW);
520 m->pController->Pause();
525 void CPlaybackView::m_KeyNextPress(void)
527 if (elm_object_disabled_get(m->eoBtnControl[CTRL_BTN_FORWARD]))
530 m->pController->HandleRemoteButtons(m->eoBtnControl[CTRL_BTN_FORWARD], EVENT_PRESSED);
534 void CPlaybackView::m_KeyPreviousPress(void)
536 if (elm_object_disabled_get(m->eoBtnControl[CTRL_BTN_REWIND]))
539 m->pController->HandleRemoteButtons(m->eoBtnControl[CTRL_BTN_REWIND], EVENT_PRESSED);
543 void CPlaybackView::m_KeyNextUnpress(void)
545 if (elm_object_disabled_get(m->eoBtnControl[CTRL_BTN_FORWARD]))
548 m->pController->HandleRemoteButtons(m->eoBtnControl[CTRL_BTN_FORWARD], EVENT_UNPRESSED);
552 void CPlaybackView::m_KeyPreviousUnpress(void)
554 if (elm_object_disabled_get(m->eoBtnControl[CTRL_BTN_REWIND]))
557 m->pController->HandleRemoteButtons(m->eoBtnControl[CTRL_BTN_REWIND], EVENT_UNPRESSED);
561 void CPlaybackView::m_HandleKeyPress(ESKey skey)
585 m_KeyPreviousPress();
589 m->pHandleVolume->Up();
592 case SKEY_VOLUME_DOWN:
593 m->pHandleVolume->Down();
597 m->pHandleVolume->Mute();
606 void CPlaybackView::m_HandleKeyUnpress(ESKey skey)
610 m_KeyPreviousUnpress();
623 void CPlaybackView::m_AddCurrentSonginfo(void)
625 m->pSongTitleLabel = new CSongTitleLabel;
626 m->pSongTitleLabel->Create(Base());
628 m->pAlbumCover = new CAlbumCover;
629 m->pAlbumCover->Create(Base());
631 m->pSliderWidget = new CSliderWidget;
632 m->pSliderWidget->Create(Base());
636 SItemInfo *CPlaybackView::m_FindItemInfoFromSong(Eina_List *list, CSongInfo *sinfo)
639 SItemInfo *itinfo = NULL;
642 EINA_LIST_FOREACH(list, l, obj) {
643 itinfo = (SItemInfo *)obj;
644 if (itinfo->sinfo == sinfo)
652 SItemInfo *CPlaybackView::m_FindItemInfoFromItem(Eina_List *list, Elm_Object_Item *item)
655 SItemInfo *itinfo = NULL;
658 EINA_LIST_FOREACH(list, l, obj) {
659 itinfo = (SItemInfo *)obj;
660 if (itinfo->item == item)
668 void CPlaybackView::m_UpdateItemCheck(SItemInfo *itinfo)
671 _ERR(" No item info to Update check ");
675 if (itinfo->check_status) {
676 elm_object_item_signal_emit(itinfo->item,
677 MUSIC_SIGNAL_CHECK_OFF, MUSIC_PLAYBACK_VIEW);
678 itinfo->check_status = false;
682 elm_object_item_signal_emit(itinfo->item,
683 MUSIC_SIGNAL_CHECK_ON, MUSIC_PLAYBACK_VIEW);
684 itinfo->check_status = true;
690 class CElmGenlistItemClass {
692 static char *sm_CbTextGet(void *data, Evas_Object *obj, const char *part)
694 CSongInfo *sinfo = NULL;
695 SItemInfo *pItemInfo = (SItemInfo *)data;
696 char buf[MAX_LENGTH];
697 char *timestr = NULL;
701 if (!pItemInfo || !obj)
704 sinfo = pItemInfo->sinfo;
706 snprintf(buf, sizeof(buf), "%s", MUSIC_STR_EMPTY);
708 if (!strcmp(part, "elm.text0")) {
709 index = elm_genlist_item_index_get(pItemInfo->item);
710 snprintf(buf, sizeof(buf), "%d", index);
712 else if (!strcmp(part, "elm.text1"))
713 snprintf(buf, sizeof(buf), "%s", sinfo->Name());
714 else if (!strcmp(part, "elm.text2"))
715 snprintf(buf, sizeof(buf), "%s - %s",
718 else if (!strcmp(part, "elm.text3")) {
719 duration = sinfo->Duration();
720 timestr = CCommonUI::TimeStrFromMilSeconds(duration);
722 snprintf(buf, sizeof(buf), "%s", timestr);
727 if (strcmp(buf, MUSIC_STR_EMPTY))
732 static Evas_Object *sm_CbContentGet(void *data, Evas_Object *obj, const char *part)
734 CSongInfo *sinfo = NULL;
735 SItemInfo *pItemInfo = (SItemInfo *)data;
736 Evas_Object *img = NULL;
738 char buf[MAX_LENGTH];
740 if (!pItemInfo || !obj)
743 sinfo = pItemInfo->sinfo;
745 img = elm_image_add(obj);
749 elm_image_aspect_fixed_set(img, EINA_FALSE);
751 if (!strcmp(part, "elm.swallow.icon")) {
752 path = sinfo->ThumbnailPath();
754 elm_image_file_set(img, path, "NULL");
756 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
757 MUSIC_IMAGE_DEFAULT_THUMB_126);
758 elm_image_file_set(img, buf, "NULL");
765 static void sm_CbDel(void *data, Evas_Object *obj)
772 Elm_Genlist_Item_Class *CPlaybackView::m_GetItemClass(void)
774 Elm_Genlist_Item_Class *list_item = NULL;
776 list_item = elm_genlist_item_class_new();
778 _ERR(" elm_genlist_item_class_new failed ");
782 list_item->item_style = MUSIC_STYLE_PLAYLIST;
783 list_item->func.text_get = CElmGenlistItemClass::sm_CbTextGet;
784 list_item->func.content_get = CElmGenlistItemClass::sm_CbContentGet;
785 list_item->func.state_get = NULL;
786 list_item->func.del = CElmGenlistItemClass::sm_CbDel;
792 void CPlaybackView::m_AddGenlist(void)
794 Evas_Object *genlist = NULL;
796 genlist = elm_genlist_add(Base());
800 elm_genlist_homogeneous_set(genlist, EINA_TRUE);
801 evas_object_size_hint_weight_set(genlist,
802 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
803 elm_object_part_content_set(Base(), MUSIC_PART_PLAYLIST, genlist);
804 elm_genlist_select_mode_set(genlist, ELM_OBJECT_SELECT_MODE_ALWAYS);
805 elm_genlist_multi_select_set(genlist, EINA_FALSE);
807 Connect(genlist, EO_PLAYLIST, TYPE_REALIZED | TYPE_MOUSE_MOVE |
808 TYPE_KEY_DOWN | TYPE_ACTIVATED);
810 evas_object_show(genlist);
811 m->eoPlaylist = genlist;
815 void CPlaybackView::m_AddPlaylist(void)
817 Elm_Genlist_Item_Class *list_item = NULL;
820 CSongInfo *sinfo = NULL;
821 Elm_Object_Item *item = NULL;
822 SItemInfo *pItemInfo = NULL;
828 list_item = m_GetItemClass();
830 evas_object_del(m->eoPlaylist);
834 if (!m->pController->GetTotalSongs(&ts)) {
835 _ERR(" music get total songs failed ");
839 if (!m->pController->GetCurrentSongIndex(&index))
840 _ERR(" music get current song index failed ");
842 for (i = 0; i < ts; i++) {
843 if (!m->pController->GetSonginfoFromIndex(i, &sinfo)) {
844 _ERR(" music get songinfo failed ");
847 pItemInfo = (SItemInfo *)calloc(1, sizeof(*pItemInfo));
850 pItemInfo->sinfo = sinfo;
851 pItemInfo->edit_mode = false;
852 pItemInfo->check_status = false;
853 pItemInfo->select_status = false;
855 // event handling will be done in OnActivated function
856 item = elm_genlist_item_append(m->eoPlaylist, list_item,
857 pItemInfo, NULL, ELM_GENLIST_ITEM_NONE,
859 pItemInfo->item = item;
862 pItemInfo->select_status = true;
863 m->cs_itinfo = pItemInfo;
865 m->elInfo = eina_list_append(m->elInfo, pItemInfo);
867 m->numCheckedItem = 0;
871 void CPlaybackView::m_RemovePlaylist(void)
874 elm_genlist_clear(m->eoPlaylist);
875 m->eoPlaylist = NULL;
879 eina_list_free(m->elInfo);
885 void CPlaybackView::m_HandleGenlistItemActivated(Evas_Object *obj, Elm_Object_Item *genListItem)
888 SItemInfo *itinfo = NULL;
890 if (!obj || !genListItem)
893 itinfo = m_FindItemInfoFromItem(m->elInfo, genListItem);
895 _ERR(" no item info found ");
899 if (itinfo->edit_mode) {
900 m_UpdateItemCheck(itinfo);
901 if (m->numCheckedItem > 0)
902 m_DisableEditButtons(false);
904 m_DisableEditButtons(true);
908 index = elm_genlist_item_index_get(genListItem);
910 m->pController->PlayIndexSong(--index);
914 bool CPlaybackView::Create(void *data, Evas_Object *eoBase)
919 CPlaybackController::SCallback cb;
922 _CHECK(m = new SPlaybackView)
923 _CHECK(m->mgr = CViewMgr::GetInstance())
924 _CHECK(m->eoWin = m->mgr->Window())
925 _CHECK(m->pController = new CMusicController)
926 _CHECK(m->pController->Create())
927 _CHECK(eoBase = CCommonUI::AddBase(m->eoWin, MUSIC_PLAYBACK_VIEW))
928 _CHECK(CBaseView::Create(NULL, eoBase))
929 _CHECK(CTimer::Create());
930 _CHECK(m->pController->AddListener(this))
931 _CHECK(m->pPlaybackController = new CPlaybackController)
932 _COMMAND{ cb.cookie = this; cb.OnCurrentSongCount = sm_CbCurrentSongCount; }
933 _CHECK(m->pPlaybackController->Create(eoBase, &cb))
936 evas_object_data_set(eoBase, PLAYBACK_VIEW_DATA, m);
938 m_AddCurrentSonginfo();
942 for (i = 0; i < TOTAL_CONTROL_BTNS; i++)
943 m->eoBtnControl[i] = m->pPlaybackController->ControlBtnsObject((EPlayerControlBtns)i);
945 for (i = 0; i < TOTAL_EDIT_BTNS; i++)
946 m->eoBtnEdit[i] = m->pPlaybackController->EditBtnsObject((EPlayerEditBtns)i);
948 m->pHandleVolume = new CHandleVolume;
949 m->pHandleVolume->Create(eoBase);
951 m_UpdatePlaymodeFocusSequence();
953 Connect(eoBase, EO_BASE, TYPE_KEY_DOWN | TYPE_KEY_UP);
956 _CHECK_FAIL{ m->pPlaybackController->Destroy(); }
957 _CHECK_FAIL{ delete m->pPlaybackController; }
958 _CHECK_FAIL{ m->pController->RemoveListener(this); }
959 _CHECK_FAIL{ CTimer::Destroy(); }
960 _CHECK_FAIL{ CBaseView::Destroy(); }
961 _CHECK_FAIL{ evas_object_del(eoBase); }
962 _CHECK_FAIL{ m->pController->Destroy(); }
963 _CHECK_FAIL{ delete m->pController; }
964 _CHECK_FAIL{ /* mgr->Window() */ }
965 _CHECK_FAIL{ /* CViewerMgr::GetInstance() */}
966 _CHECK_FAIL{ delete m; m = NULL; }
967 }_CREATE_END_AND_CATCH{ return false; }
973 void CPlaybackView::Destroy(void)
977 Evas_Object *eoBase = Base();
981 m->pPlaybackController->Destroy();
982 delete m->pPlaybackController;
984 m->pController->RemoveListener(this);
986 m->pSliderWidget->Destroy();
987 delete m->pSliderWidget;
989 m->pAlbumCover->Destroy();
990 delete m->pAlbumCover;
992 m->pSongTitleLabel->Destroy();
993 delete m->pSongTitleLabel;
995 m->pHandleVolume->Destroy();
996 delete m->pHandleVolume;
997 CBaseView::Destroy();
998 evas_object_del(eoBase);
1006 void CPlaybackView::t_OnShow(void)
1012 m_UpdateCurrentSongInfo();
1014 state = m->pController->PlayState();
1015 if (state == PLAY_STATUS_INITIAL || state == PLAY_STATUS_STOP) {
1018 m->pController->Start();
1022 elm_genlist_item_show(m->cs_itinfo->item, ELM_GENLIST_ITEM_SCROLLTO_IN);
1023 elm_object_item_focus_set(m->cs_itinfo->item, EINA_TRUE);
1026 evas_object_show(Base());
1030 void CPlaybackView::t_OnUpdate(void *data)
1034 SParcel *parcel = (SParcel *)data;
1036 ESKey keyEvent = SKEY_MAX;
1039 updateType = E_PLAYLIST_UPDATE;
1041 updateType = parcel->updateType;
1042 keyEvent = parcel->keyEvent;
1045 switch (updateType) {
1046 case E_PLAYLIST_UPDATE:
1049 elm_object_disabled_set(m->eoBtnControl[CTRL_BTN_FORWARD], EINA_FALSE);
1050 elm_object_disabled_set(m->eoBtnControl[CTRL_BTN_REWIND], EINA_FALSE);
1051 elm_object_disabled_set(m->eoBtnControl[CTRL_BTN_PLAY], EINA_FALSE);
1052 elm_object_focus_next_object_set(m->eoBtnControl[CTRL_BTN_REPEAT],
1053 m->eoBtnControl[CTRL_BTN_REWIND], ELM_FOCUS_RIGHT);
1054 m_FromEditToPlaybackMode();
1058 m_HandleKeyPress(keyEvent);
1062 m_HandleKeyUnpress(keyEvent);
1071 void CPlaybackView::t_OnTimer(int id)
1076 void CPlaybackView::t_OnHide(void)
1080 evas_object_hide(Base());
1084 void CPlaybackView::OnSKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_SKey_Down *ev)
1088 m_HandleKeyPress(ev->skey);
1093 Elm_Object_Item *it = NULL;
1094 it = elm_object_focused_item_get(obj);
1096 _ERR(" unable to get focused item ");
1099 m->focused_item = it;
1104 SContentInfo *ctxtinfo = NULL;
1105 SItemInfo *itinfo = NULL;
1113 ctxtinfo = (SContentInfo *)calloc(1, sizeof(*ctxtinfo));
1117 itinfo = m_FindItemInfoFromItem(m->elInfo, it);
1123 if (m->pController->PlayState() == PLAY_STATUS_PLAY &&
1124 itinfo == m->cs_itinfo)
1125 ctxtinfo->status = PLAY_STATUS_PLAY;
1127 ctxtinfo->status = PLAY_STATUS_PAUSE;
1129 ctxtinfo->cbdata = this;
1130 ctxtinfo->update = sm_CbCtxtUpdate;
1131 ctxtinfo->close = sm_CbCtxtClose;
1132 ctxtinfo->type = CONTEXT_TYPE_PLAYSONG;
1133 ctxtinfo->context = itinfo->sinfo;
1135 m->ctxtinfo = ctxtinfo;
1137 memset(&parcel, 0, sizeof(SParcel));
1138 parcel.ctxtInfo = ctxtinfo;
1139 if (!m->mgr->PushView(MUSIC_CONTEXT_VIEW, &parcel))
1140 _ERR("viewmgr push view MUSIC_CONTEXT_VIEW failed");
1156 void CPlaybackView::OnSKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_SKey_Up *ev)
1160 m_HandleKeyUnpress(ev->skey);
1169 void CPlaybackView::OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev)
1174 Elm_Object_Item *item;
1176 item = elm_genlist_at_xy_item_get(obj, ev->cur.canvas.x,
1177 ev->cur.canvas.y, NULL);
1181 if (!elm_object_item_focus_get(item))
1182 elm_object_item_focus_set(item, EINA_TRUE);
1192 void CPlaybackView::OnRealized(int id, Evas_Object *obj, Elm_Object_Item *item)
1197 int index = elm_genlist_item_index_get(item);
1198 if ((index & 1) == 1)
1199 elm_object_item_signal_emit(item,
1200 MUSIC_SIGNAL_EVEN_ROW, MUSIC_PLAYBACK_VIEW);
1202 elm_object_item_signal_emit(item,
1203 MUSIC_SIGNAL_ODD_ROW, MUSIC_PLAYBACK_VIEW);
1205 SItemInfo *itInfo = m_FindItemInfoFromItem(m->elInfo, item);
1206 if (itInfo->select_status)
1207 elm_object_item_signal_emit(item,
1208 MUSIC_SIGNAL_SELECT_ITEM, MUSIC_PLAYBACK_VIEW);
1210 elm_object_item_signal_emit(item,
1211 MUSIC_SIGNAL_UNSELECT_ITEM, MUSIC_PLAYBACK_VIEW);
1213 if (itInfo->edit_mode) {
1214 elm_object_item_signal_emit(item,
1215 MUSIC_SIGNAL_EDITMODE_ON, MUSIC_PLAYBACK_VIEW);
1216 if (itInfo->check_status) {
1217 elm_object_item_signal_emit(item,
1218 MUSIC_SIGNAL_CHECK_ON, MUSIC_PLAYBACK_VIEW);
1221 elm_object_item_signal_emit(item,
1222 MUSIC_SIGNAL_CHECK_OFF, MUSIC_PLAYBACK_VIEW);
1225 elm_object_item_signal_emit(item,
1226 MUSIC_SIGNAL_EDITMODE_OFF, MUSIC_PLAYBACK_VIEW);
1236 void CPlaybackView::OnActivated(int id, Evas_Object *obj, Elm_Object_Item *item)
1240 m_HandleGenlistItemActivated(obj, item);
1249 void CPlaybackView::OnComplete(void)
1251 m_UpdateCurrentSongInfo();
1255 void CPlaybackView::OnError(void)
1260 void CPlaybackView::OnUsbStatusChanged(SUsbStorageStatus status)
1265 void CPlaybackView::OnUpdateContent(void)
1270 void CPlaybackView::OnStartPlayback(void)
1272 m_UpdateCurrentSongInfo();
1276 void CPlaybackView::OnStopPlayback(void)
1281 void CPlaybackView::OnEmptyPlaylist(void)
1283 eina_list_free(m->elInfo);
1285 elm_genlist_clear(m->eoPlaylist);
1286 m_UpdateEmptySongInfo();
1290 void CPlaybackView::OnPlayerModeChanged(EPlayerMode mode)
1293 case MODE_PLAYLIST_EDIT:
1294 m_FromPlaybackToEditMode();
1298 m_FromEditToPlaybackMode();
1302 ASSERT(!"Invalid Player Mode");
1308 void CPlaybackView::OnEditButtonsPressed(EPlayerEditBtns editBtns)
1311 case EDIT_BTN_CANCEL:
1312 m_DisableCheckAll(m->elInfo);
1313 m_DisableEditButtons(true);
1316 case EDIT_BTN_DESELECT:
1317 m_DisableCheckAll(m->elInfo);
1318 m_DisableEditButtons(true);
1319 elm_genlist_realized_items_update(m->eoPlaylist);
1322 case EDIT_BTN_DELETE:
1323 m_DeleteSelectedItems();
1327 ASSERT(!"Invalid Edit Button");