Convert information modules into CXXXInfo classes.
[profile/tv/apps/native/musicplayer.git] / src / views / playback-view.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <Elementary.h>
18 #include <Eina.h>
19 #include <utilX.h>
20 #include "AppCommon.h"
21 #include "dbg.h"
22 #include "define.h"
23 #include <InputHandler.h>
24 #include "song_info.h"
25 #include "album_info.h"
26 #include "music-controller.h"
27 #include "volume-control.h"
28 #include "i18n.h"
29 #include "common.h"
30 #include "common-ui.h"
31 #include "BaseView.h"
32 #include "ViewMgr.h"
33 #include "playback-view.h"
34 #include "context-view.h"
35 #include "HandleVolume.h"
36
37
38 #define ARRAY_SIZE(array)       (sizeof(array) / sizeof(array[0]))
39 #define TITLE_FONT_SIZE         50
40 #define ARTIST_FONT_SIZE        30
41 #define TOTAL_CONTROL_BTNS      6
42 #define TOTAL_SETTING_BTNS      2
43 #define TOTAL_EDIT_BTNS         3
44 #define S_INTERVAL              1       /* seconds */
45 #define LP_INTERVAL             0.5     /* seconds */
46 #define WAIT_INTERVAL           0.5     /* seconds */
47 #define SLIDER_STEP             5000    /* milli seconds */
48 #define LP_CHANGE               10000   /* milli seconds */
49 #define S_INCREMENT             1000    /* milli seconds */
50
51
52 enum EEvasObject {
53         EO_BASE,
54
55         EO_ERROR_POPUP_BUTTON,
56
57         EO_EDIT_PLAYLIST,
58         EO_CLEAR_PLAYLIST,   // TOTAL_SETTING_BTNS
59
60         EO_CANCEL,
61         EO_DESELECT,
62         EO_DELETE,           // TOTAL_EDIT_BTNS
63
64         EO_BTN_SETTINGS,
65         EO_BTN_SHUFFLE,
66         EO_BTN_REPEAT,
67         EO_BTN_REWIND,
68         EO_BTN_PLAY,
69         EO_BTN_FORWARD,   // TOTAL_CONTROL_BTNS
70
71         EO_SLIDER,
72
73         EO_PLAYLIST,
74
75         EO_BOX,
76 };
77
78
79 struct SItemInfo {
80         Elm_Object_Item *item;
81         CSongInfo *sinfo;
82         bool edit_mode;
83         bool check_status;
84         bool select_status;
85 };
86
87 struct SPlaybackView {
88         Evas_Object *eoWin;
89
90         Evas_Object *eoBase;
91         Evas_Object *eoCtxPopup;   /*settings popup*/
92         Evas_Object *eoErrPopup;
93         Evas_Object *eoPlaylist;
94
95         Elm_Object_Item *focused_item;
96
97         Evas_Object *eoBtnControl[TOTAL_CONTROL_BTNS];
98         Evas_Object *eoBtnSetting[TOTAL_SETTING_BTNS];
99         Evas_Object *eoBtnEdit[TOTAL_EDIT_BTNS];
100
101         Evas_Object *eoAlbumCover;
102         Evas_Object *eoSlider;
103         Evas_Object *eoPressedObj;
104
105         Eina_List   *elInfo;
106         Ecore_Timer *etSlider;
107         Ecore_Timer *etLongPress;
108         Ecore_Timer *etWait;
109         CMusicController *hMusicController; //! NOT NULL
110         CSongInfo *csinfo;
111         CViewMgr *mgr;
112         SItemInfo *cs_itinfo;
113         SContentInfo *ctxtinfo;
114         int press_status;
115
116         CPlaybackView *parent;
117         CHandleVolume *pHandleVolume;
118
119         SPlaybackView() {
120                 memset(this, 0, sizeof(SPlaybackView));
121                 pHandleVolume = new CHandleVolume;
122         }
123         ~SPlaybackView() {
124                 delete pHandleVolume;
125         }
126 };
127
128 struct SBtnInfo {
129         const char *txt;
130         const char *part;
131         EEvasObject type;
132 };
133
134 enum EPressTypes {
135         PRESS_SHORT,
136         PRESS_SHORT_PAUSE,
137         PRESS_LONG,
138         PRESS_LONG_PAUSE,
139 };
140
141 enum EControlBtns {
142         BTN_SETTINGS,
143         BTN_SHUFFLE,
144         BTN_REPEAT,
145         BTN_REWIND,
146         BTN_PLAY,
147         BTN_FORWARD
148 };
149
150 enum ESettingBtns {
151         BTN_EDIT,
152         BTN_CLEAR
153 };
154
155 enum EEditBtns {
156         BTN_CANCEL,
157         BTN_DESELECT,
158         BTN_DELETE
159 };
160
161 enum ETimers {
162         TIMER_SLIDER,
163         TIMER_WAIT,
164         TIMER_LONGPRESS,
165         TIMER_VOLUME
166 };
167
168 Eina_Bool CPlaybackView::sm_CbUpdateSlider(void *dt)
169 {
170         SPlaybackView *m = (SPlaybackView *)dt;
171         char *timestr = NULL;
172         int value;
173         int duration;
174
175         if (!m)
176                 return ECORE_CALLBACK_CANCEL;
177
178         if (!m->hMusicController->GetPosition(&value)) {
179                 m->etSlider = NULL;
180                 return ECORE_CALLBACK_CANCEL;
181         }
182
183         duration = m->csinfo->Duration();
184
185         value = value + S_INCREMENT;
186         if (value > duration) {
187                 m->etSlider = NULL;
188                 return ECORE_CALLBACK_CANCEL;
189         }
190
191         elm_slider_value_set(m->eoSlider, value);
192         timestr = _get_timestr_from_milseconds(value);
193         if (timestr) {
194                 elm_object_part_text_set(m->eoBase, MUSIC_PART_PROGRESSTIME,
195                         timestr);
196                 free(timestr);
197         }
198
199         return ECORE_CALLBACK_RENEW;
200 }
201
202
203 Eina_Bool CPlaybackView::sm_CbLongpressTimer(void *dt)
204 {
205         SPlaybackView *m = (SPlaybackView *)dt;
206
207         m->parent->m_HandleOnRepeated();
208
209         return ECORE_CALLBACK_RENEW;
210 }
211
212
213 Eina_Bool CPlaybackView::sm_CbWaitTimer(void *dt)
214 {
215         SPlaybackView *m = (SPlaybackView *)dt;
216
217         m->press_status = PRESS_LONG;
218         if (m->hMusicController->PlayState() == PLAY_STATUS_PLAY) {
219                 /* Handle long press */
220                 m->parent->m_PlaybackPause();
221                 m->etLongPress = ecore_timer_add(LP_INTERVAL, sm_CbLongpressTimer, m);
222         }
223         else {
224                 m->press_status = PRESS_LONG_PAUSE;
225         }
226
227         m->etWait = NULL;
228         return ECORE_CALLBACK_CANCEL;
229 }
230
231
232 void CPlaybackView::sm_CbItemSelect(void *data, Evas_Object *obj, void *event_info)
233 {
234 }
235
236
237 void CPlaybackView::sm_CbGenlistItemCheckClicked(void *data, Elm_Object_Item *it, const char *emission, const char *source)
238 {
239         CPlaybackView *root = (CPlaybackView*)data;
240         if (root)
241                 root->m_OnGenlistItemCheckClicked(it, emission, source);
242 }
243
244
245 void CPlaybackView::m_OnGenlistItemCheckClicked(Elm_Object_Item *it, const char *emission, const char *source)
246 {
247         SItemInfo *itinfo = NULL;
248
249         if (!it || !emission)
250                 return;
251
252         itinfo = m_FindItemInfoFromItem(m->elInfo, it);
253         if (!itinfo) {
254                 _ERR(" no item info found ");
255                 return;
256         }
257
258         if (itinfo->edit_mode) {
259                 m_UpdateItemCheck(itinfo);
260                 m_DisableEditButtons(false);
261         }
262 }
263
264
265 void CPlaybackView::sm_CbCtxtUpdate(void *dt, enum EActionType type, int lid)
266 {
267         SPlaybackView *m = (SPlaybackView *)dt;
268         SItemInfo *itinfo = NULL;
269
270         if (!m)
271                 return;
272
273         if (!m->ctxtinfo || !m->ctxtinfo->context)
274                 return;
275
276         itinfo = m->parent->m_FindItemInfoFromSong(m->elInfo,
277                 (CSongInfo *)m->ctxtinfo->context);
278         if (!itinfo) {
279                 _ERR(" Unable to find song in the list ");
280                 return;
281         }
282
283         if (type == ACTION_TYPE_DELETE) {
284                 itinfo->check_status = true;
285                 m->parent->m_DeleteSelectedItems();
286         }
287         else if (type == ACTION_TYPE_PLAY) {
288                 if (m->ctxtinfo->status == PLAY_STATUS_PLAY)
289                         m->parent->m_KeyPausePress();
290                 else {
291                         if (itinfo == m->cs_itinfo)
292                                 m->parent->m_KeyPlayPress();
293                         else
294                                 m->parent->m_HandleGenlistItemActivated(m->eoPlaylist, itinfo->item);
295                 }
296         }
297         else
298                 _ERR(" Wrong ctxt add type in plaback view ");
299
300         if (!m->mgr->PushView(MUSIC_PLAYBACK_VIEW, NULL)) {
301                 _ERR(" viewmgr show failed ");
302                 return;
303         }
304         elm_object_item_focus_set(m->focused_item, EINA_TRUE);
305 }
306
307
308 void CPlaybackView::sm_CbCtxtClose(void *dt)
309 {
310         SPlaybackView *m = (SPlaybackView *)dt;
311
312         if (!m)
313                 return;
314
315         m->mgr->PopView();
316         m->mgr->PushView(MUSIC_PLAYBACK_VIEW, NULL);
317         elm_object_item_focus_set(m->focused_item, EINA_TRUE);
318 }
319
320
321 void CPlaybackView::m_RemoveTimer(int timer_code)
322 {
323         ETimers timerCode = (ETimers)timer_code;
324
325         switch (timerCode) {
326         case TIMER_SLIDER:
327                 if (m->etSlider) {
328                         ecore_timer_del(m->etSlider);
329                         m->etSlider = NULL;
330                 }
331                 break;
332
333         case TIMER_WAIT:
334                 if (m->etWait) {
335                         ecore_timer_del(m->etWait);
336                         m->etWait = NULL;
337                 }
338                 break;
339
340         case TIMER_LONGPRESS:
341                 if (m->etLongPress) {
342                         ecore_timer_del(m->etLongPress);
343                         m->etLongPress = NULL;
344                 }
345                 break;
346
347         case TIMER_VOLUME:
348                 m->pHandleVolume->RemoveTimer();
349                 break;
350
351         default:
352                 _ERR(" invalid value ");
353                 break;
354         }
355 }
356
357
358 void CPlaybackView::m_PlaybackPause(void)
359 {
360         m->hMusicController->Pause();
361
362         if (m->etSlider)
363                 ecore_timer_freeze(m->etSlider);
364 }
365
366
367 void CPlaybackView::m_PlaybackResume(void)
368 {
369         m->hMusicController->Resume();
370
371         if (m->etSlider)
372                 ecore_timer_thaw(m->etSlider);
373 }
374
375
376 void CPlaybackView::m_ChangeEditmodeAll(Eina_List *list, bool flag)
377 {
378         SItemInfo *itinfo = NULL;
379         void *obj = NULL;
380         Eina_List *l = NULL;
381
382         EINA_LIST_FOREACH(list, l, obj) {
383                 itinfo = (SItemInfo *)obj;
384                 itinfo->edit_mode = flag;
385         }
386 }
387
388
389 void CPlaybackView::m_DisableCheckAll(Eina_List *list)
390 {
391         SItemInfo *itinfo = NULL;
392         void *obj = NULL;
393         Eina_List *l = NULL;
394
395         EINA_LIST_FOREACH(list, l, obj) {
396                 itinfo = (SItemInfo *)obj;
397                 itinfo->check_status = false;
398         }
399 }
400
401
402 void CPlaybackView::m_SelectItem(SItemInfo *pItemInfo)
403 {
404         if (!pItemInfo || !pItemInfo->item)
405                 return;
406
407         elm_genlist_item_bring_in(pItemInfo->item, ELM_GENLIST_ITEM_SCROLLTO_IN);
408         elm_object_item_signal_emit(pItemInfo->item, MUSIC_SIGNAL_SELECT_ITEM, MUSIC_PLAYBACK_VIEW);
409
410         pItemInfo->select_status = true;
411 }
412
413
414 void CPlaybackView::m_UnselectItem(SItemInfo *pItemInfo)
415 {
416         if (!pItemInfo || !pItemInfo->item)
417                 return;
418
419         elm_object_item_signal_emit(pItemInfo->item, MUSIC_SIGNAL_UNSELECT_ITEM,
420                 MUSIC_PLAYBACK_VIEW);
421
422         pItemInfo->select_status = false;
423 }
424
425
426 void CPlaybackView::m_UpdateControlBtns(void)
427 {
428         int state;
429
430         state = m->hMusicController->PlayState();
431         if (state != PLAY_STATUS_STOP) {
432                 elm_object_disabled_set(m->eoBtnControl[BTN_FORWARD], EINA_FALSE);
433                 elm_object_disabled_set(m->eoBtnControl[BTN_REWIND],  EINA_FALSE);
434         }
435         else {
436                 if (!m->eoErrPopup)
437                         elm_object_focus_set(m->eoBtnControl[BTN_PLAY],   EINA_TRUE);
438                 elm_object_disabled_set(m->eoBtnControl[BTN_FORWARD], EINA_TRUE);
439                 elm_object_disabled_set(m->eoBtnControl[BTN_REWIND],  EINA_TRUE);
440         }
441
442         if (state == PLAY_STATUS_PLAY) {
443                 elm_object_signal_emit(m->eoBtnControl[BTN_PLAY], MUSIC_SIGNAL_PLAY, MUSIC_PLAYBACK_VIEW);
444         }
445         else {
446                 elm_object_signal_emit(m->eoBtnControl[BTN_PLAY], MUSIC_SIGNAL_PAUSE, MUSIC_PLAYBACK_VIEW);
447         }
448
449         state = m->hMusicController->ShuffleState();
450         if (state == SHUFFLE_STATUS_OFF) {
451                 elm_object_signal_emit(m->eoBtnControl[BTN_SHUFFLE], MUSIC_SIGNAL_SHUFFLE_OFF, MUSIC_PLAYBACK_VIEW);
452         }
453         else {
454                 elm_object_signal_emit(m->eoBtnControl[BTN_SHUFFLE], MUSIC_SIGNAL_SHUFFLE_ON, MUSIC_PLAYBACK_VIEW);
455         }
456
457         state = m->hMusicController->RepeatState();
458         if (state == REPEAT_STATUS_NONE) {
459                 elm_object_signal_emit(m->eoBtnControl[BTN_REPEAT], MUSIC_SIGNAL_REPEAT_OFF, MUSIC_PLAYBACK_VIEW);
460         }
461         else if (state == REPEAT_STATUS_ALL) {
462                 elm_object_signal_emit(m->eoBtnControl[BTN_REPEAT], MUSIC_SIGNAL_REPEAT_ALL, MUSIC_PLAYBACK_VIEW);
463         }
464         else {
465                 elm_object_signal_emit(m->eoBtnControl[BTN_REPEAT], MUSIC_SIGNAL_REPEAT_ONE, MUSIC_PLAYBACK_VIEW);
466         }
467 }
468
469
470 void CPlaybackView::m_UpdateCurrentSongProgressbar(void)
471 {
472         int duration;
473         char *timestr = NULL;
474         double step;
475         int state;
476
477         if (!m->csinfo)
478                 return;
479
480         elm_slider_value_set(m->eoSlider, 0);
481         elm_object_part_text_set(m->eoBase, MUSIC_PART_PROGRESSTIME, "00:00");
482
483         state = m->hMusicController->PlayState();
484
485         if (state == PLAY_STATUS_STOP) {
486                 elm_object_disabled_set(m->eoSlider, EINA_TRUE);
487                 m_RemoveTimer(TIMER_SLIDER);
488                 return;
489         }
490
491         elm_object_disabled_set(m->eoSlider, EINA_FALSE);
492
493         duration = m->csinfo->Duration();
494         {
495                 m_RemoveTimer(TIMER_SLIDER);
496                 m->etSlider = ecore_timer_add(S_INTERVAL,
497                         sm_CbUpdateSlider, m);
498
499                 elm_slider_min_max_set(m->eoSlider, 0, duration);
500                 timestr = _get_timestr_from_milseconds(duration);
501                 if (timestr) {
502                         elm_object_part_text_set(m->eoBase,
503                                 MUSIC_PART_FULLTIME, timestr);
504                         free(timestr);
505                 }
506
507                 step = (double)SLIDER_STEP / (double)duration;
508                 elm_slider_step_set(m->eoSlider, step);
509         }
510 }
511
512
513 void CPlaybackView::m_UpdateCurrentSongThumbnail(void)
514 {
515         char *path = NULL;
516         char buf[MAX_LENGTH];
517
518         if (!m->cs_itinfo || !m->cs_itinfo->sinfo)
519                 return;
520
521         path = m->cs_itinfo->sinfo->ThumbnailPath();
522         if (path)
523                 elm_image_file_set(m->eoAlbumCover, path, NULL);
524         else {
525                 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
526                         MUSIC_IMAGE_DEFAULT_THUMB_450);
527                 elm_image_file_set(m->eoAlbumCover, buf, NULL);
528         }
529 }
530
531
532 void CPlaybackView::m_UpdateCurrentSongLabels(void)
533 {
534         char buf[MAX_LENGTH];
535
536         if (!m->csinfo)
537                 return;
538
539         elm_object_part_text_set(m->eoBase, MUSIC_PART_SONG_TITLE,
540                 m->csinfo->Name());
541
542         snprintf(buf, sizeof(buf), "%s - %s", m->csinfo->Artist(),
543                 m->csinfo->Album());
544
545         elm_object_part_text_set(m->eoBase, MUSIC_PART_ARTIST_ALBUM, buf);
546 }
547
548
549 void CPlaybackView::m_UpdateEmptySongInfo(void)
550 {
551         char buf[MAX_LENGTH];
552
553         elm_object_signal_emit(m->eoBtnControl[BTN_PLAY],
554                 MUSIC_SIGNAL_PAUSE, MUSIC_PLAYBACK_VIEW);
555         elm_object_focus_set(m->eoBtnControl[BTN_SETTINGS], EINA_TRUE);
556         elm_object_focus_next_object_set(m->eoBtnControl[BTN_REPEAT],
557                 m->eoBtnControl[BTN_REPEAT], ELM_FOCUS_RIGHT);
558         elm_object_disabled_set(m->eoBtnControl[BTN_FORWARD], EINA_TRUE);
559         elm_object_disabled_set(m->eoBtnControl[BTN_REWIND], EINA_TRUE);
560         elm_object_disabled_set(m->eoBtnControl[BTN_PLAY], EINA_TRUE);
561         elm_object_disabled_set(m->eoSlider, EINA_TRUE);
562         elm_object_part_text_set(m->eoBase, MUSIC_PART_FULLTIME, "00:00");
563         elm_object_part_text_set(m->eoBase, MUSIC_PART_PROGRESSTIME, "00:00");
564         elm_slider_value_set(m->eoSlider, 0);
565         elm_object_part_text_set(m->eoBase, MUSIC_PART_SONG_TITLE,
566                 _(NO_PLAYLIST_MESSAGE));
567         elm_object_part_text_set(m->eoBase, MUSIC_PART_ARTIST_ALBUM,
568                 _(NO_PLAYLIST_MESSAGE_SUB));
569         snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
570                 MUSIC_IMAGE_DEFAULT_THUMB_450);
571         elm_image_file_set(m->eoAlbumCover, buf, NULL);
572         m->hMusicController->SetPlayState(PLAY_STATUS_INITIAL);
573 }
574
575
576 void CPlaybackView::m_UpdateCtxtView(int playStatus)
577 {
578         if (!m->cs_itinfo || !m->ctxtinfo)
579                 return;
580
581         if (!m->mgr->CheckTop(MUSIC_CONTEXT_VIEW))
582                 return;
583
584         if (m->cs_itinfo->sinfo == m->ctxtinfo->context) {
585                 m->ctxtinfo->status = (EPlayStatus)playStatus;
586
587                 SParcel parcel;
588                 parcel.ctxtInfo = NULL;
589                 parcel.updateType = E_SONG_UPDATE;
590                 parcel.layoutId = NULL;
591                 parcel.keyEvent = NULL;
592                 m->mgr->UpdateView((const char *)MUSIC_CONTEXT_VIEW, &parcel);
593         }
594 }
595
596
597 void CPlaybackView::m_UpdateCurrentSongItem(int index)
598 {
599         SItemInfo *pItemInfo = NULL;
600
601         if (m->cs_itinfo) {
602                 m_UnselectItem(m->cs_itinfo);
603                 m_UpdateCtxtView(PLAY_STATUS_PAUSE);
604         }
605
606         pItemInfo = (SItemInfo *)eina_list_nth(m->elInfo, index);
607
608         if (pItemInfo) {
609                 m->cs_itinfo = pItemInfo;
610                 if (m->hMusicController->PlayState() == PLAY_STATUS_STOP) {
611                         elm_genlist_item_bring_in(pItemInfo->item,
612                                 ELM_GENLIST_ITEM_SCROLLTO_IN);
613                 }
614                 else {
615                         m_SelectItem(pItemInfo);
616                         m_UpdateCtxtView(PLAY_STATUS_PLAY);
617                 }
618         }
619 }
620
621
622 void CPlaybackView::m_UpdateEditmodeFocusSequence(void)
623 {
624         elm_object_focus_next_object_set(m->eoPlaylist,
625                 m->eoBtnEdit[BTN_CANCEL], ELM_FOCUS_LEFT);
626         elm_object_focus_next_object_set(m->eoBtnEdit[BTN_CANCEL],
627                 m->eoPlaylist, ELM_FOCUS_RIGHT);
628         elm_object_focus_next_object_set(m->eoSlider, m->eoBtnEdit[BTN_CANCEL],
629                 ELM_FOCUS_DOWN);
630 }
631
632
633 void CPlaybackView::m_UpdatePlaymodeFocusSequence(void)
634 {
635         elm_object_focus_next_object_set(m->eoSlider, m->eoPlaylist,
636                 ELM_FOCUS_UP);
637         elm_object_focus_next_object_set(m->eoSlider, m->eoBtnControl[BTN_PLAY],
638                 ELM_FOCUS_DOWN);
639         if (m->hMusicController->PlayState() == PLAY_STATUS_STOP) {
640                 elm_object_focus_next_object_set(m->eoPlaylist,
641                         m->eoBtnControl[BTN_PLAY], ELM_FOCUS_LEFT);
642                 elm_object_focus_next_object_set(m->eoBtnControl[BTN_PLAY],
643                         m->eoPlaylist, ELM_FOCUS_RIGHT);
644         }
645         else {
646                 elm_object_focus_next_object_set(m->eoPlaylist,
647                         m->eoBtnControl[BTN_FORWARD], ELM_FOCUS_LEFT);
648                 elm_object_focus_next_object_set(m->eoBtnControl[BTN_FORWARD],
649                         m->eoPlaylist, ELM_FOCUS_RIGHT);
650                 elm_object_focus_next_object_set(m->eoBtnControl[BTN_PLAY],
651                         m->eoBtnControl[BTN_FORWARD], ELM_FOCUS_RIGHT);
652         }
653 }
654
655
656 void CPlaybackView::m_UpdateCurrentSongInfo(void)
657 {
658         CSongInfo *sinfo = NULL;
659         int index;
660
661         if (eina_list_count(m->elInfo) == 0) {
662                 m_UpdateEmptySongInfo();
663                 return;
664         }
665
666         if (!m->hMusicController->GetCurrentSongIndex(&index)) {
667                 _ERR(" music get current song index failed ");
668                 return;
669         }
670
671         if (!m->hMusicController->GetSonginfoFromIndex(index, &sinfo)) {
672                 _ERR(" music get songinfo failed ");
673                 return;
674         }
675         m->csinfo = sinfo;
676
677         m_UpdateCurrentSongItem(index);
678         m_UpdateCurrentSongLabels();
679         m_UpdateCurrentSongThumbnail();
680         m_UpdateCurrentSongProgressbar();
681         m_UpdateControlBtns();
682         m_UpdatePlaymodeFocusSequence();
683 }
684
685
686 void CPlaybackView::m_DisableEditButtons(bool flag)
687 {
688         /* flag - 1 means disable edit buttons and 0 means enable */
689         if (flag)
690                 elm_object_focus_set(m->eoBtnEdit[BTN_CANCEL], EINA_TRUE);
691
692         elm_object_disabled_set(m->eoBtnEdit[BTN_DELETE], (Eina_Bool)flag);
693         elm_object_disabled_set(m->eoBtnEdit[BTN_DESELECT], (Eina_Bool)flag);
694         if (flag) {
695                 m_UpdateEditmodeFocusSequence();
696                 elm_object_focus_set(m->eoBtnEdit[BTN_CANCEL], EINA_TRUE);
697         }
698         else {
699                 elm_object_focus_next_object_set(m->eoBtnEdit[BTN_CANCEL],
700                         m->eoBtnEdit[BTN_DESELECT], ELM_FOCUS_RIGHT);
701                 elm_object_focus_next_object_set(m->eoBtnEdit[BTN_DELETE],
702                         m->eoPlaylist, ELM_FOCUS_RIGHT);
703                 elm_object_focus_next_object_set(m->eoPlaylist,
704                         m->eoBtnEdit[BTN_DELETE], ELM_FOCUS_LEFT);
705         }
706 }
707
708
709 void CPlaybackView::m_CreateErrorPopup(void)
710 {
711         Evas_Object *popup = NULL, *btn = NULL, *label = NULL;
712
713         popup = elm_popup_add(m->eoBase);
714         if (!popup)
715                 return;
716
717         elm_object_style_set(popup, MUSIC_STYLE_ERROR_POPUP);
718         evas_object_show(popup);
719
720         label = elm_label_add(popup);
721         if (!label) {
722                 evas_object_del(popup);
723                 return;
724         }
725
726         elm_object_style_set(label, MUSIC_STYLE_ERROR_LABEL);
727         elm_object_text_set(label, MUSIC_TEXT_PLAYBACK_ERROR);
728         elm_object_content_set(popup, label);
729
730         btn = elm_button_add(popup);
731         if (!btn) {
732                 evas_object_del(popup);
733                 return;
734         }
735
736         elm_object_style_set(btn, MUSIC_STYLE_EDIT_BTN);
737         elm_object_text_set(btn, MUSIC_TEXT_OK);
738         elm_object_part_content_set(popup, MUSIC_PART_POPUP_BUTTON, btn);
739
740         m->eoErrPopup = popup;
741
742         Connect(btn, EO_ERROR_POPUP_BUTTON, TYPE_CLICKED | TYPE_KEY_DOWN);
743
744         elm_object_focus_set(btn, EINA_TRUE);
745
746         return;
747 }
748
749
750 void CPlaybackView::m_DestroyErrorPopup(void)
751 {
752         if (!m->eoErrPopup)
753                 return;
754
755         evas_object_del(m->eoErrPopup);
756         m->eoErrPopup = NULL;
757 }
758
759
760 void CPlaybackView::m_CreateSettingsPopup(void)
761 {
762         Evas_Object *box = NULL;
763         Evas_Object *eoCtxPopup = NULL;
764         int i;
765         double scale;
766         SBtnInfo btninfo[TOTAL_SETTING_BTNS];
767
768         btninfo[BTN_EDIT].txt = MUSIC_TEXT_EDIT_PLAYLIST;
769         btninfo[BTN_EDIT].type = EO_EDIT_PLAYLIST;
770
771         btninfo[BTN_CLEAR].txt = MUSIC_TEXT_CLEAR_PLAYLIST;
772         btninfo[BTN_CLEAR].type = EO_CLEAR_PLAYLIST;
773
774         eoCtxPopup = elm_ctxpopup_add(m->eoWin);
775         if (!eoCtxPopup)
776                 return;
777
778         box = _add_box(eoCtxPopup);
779         if (!box) {
780                 evas_object_del(eoCtxPopup);
781                 return;
782         }
783
784         for (i = 0; i < TOTAL_SETTING_BTNS; i++) {
785                 m->eoBtnSetting[i] = elm_button_add(box);
786                 if (!m->eoBtnSetting[i])
787                         continue;
788                 if (i == BTN_EDIT) {
789                         elm_object_style_set(m->eoBtnSetting[i],
790                                 MUSIC_STYLE_SETTING_BTN_T);
791                 }
792                 else {
793                         elm_object_style_set(m->eoBtnSetting[i],
794                                 MUSIC_STYLE_SETTING_BTN_B);
795                 }
796                 evas_object_size_hint_weight_set(m->eoBtnSetting[i],
797                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
798                 elm_box_pack_end(box, m->eoBtnSetting[i]);
799                 elm_object_text_set(m->eoBtnSetting[i], _(btninfo[i].txt));
800
801                 Connect(m->eoBtnSetting[i], btninfo[i].type, TYPE_CLICKED | TYPE_MOUSE_MOVE);
802
803                 evas_object_show(m->eoBtnSetting[i]);
804         }
805
806         elm_object_style_set(eoCtxPopup, MUSIC_STYLE_SETTING_POPUP);
807         elm_object_content_set(eoCtxPopup, box);
808
809         scale = elm_config_scale_get();
810         Connect(box, EO_BOX, TYPE_KEY_DOWN);
811         elm_object_part_content_set(m->eoBase, MUSIC_PART_SETTINGS_POPUP, eoCtxPopup);
812
813         /* If list empty disable these options */
814         if (eina_list_count(m->elInfo) == 0) {
815                 elm_object_disabled_set(m->eoBtnSetting[BTN_EDIT], EINA_TRUE);
816                 elm_object_disabled_set(m->eoBtnSetting[BTN_CLEAR], EINA_TRUE);
817         }
818
819         elm_object_focus_set(m->eoBtnSetting[BTN_EDIT], EINA_TRUE);
820
821         m->eoCtxPopup = eoCtxPopup;
822 }
823
824
825 void CPlaybackView::m_DestroySettingsPopup(void)
826 {
827         if (!m->eoCtxPopup)
828                 return;
829
830         evas_object_del(m->eoCtxPopup);
831         m->eoCtxPopup = NULL;
832 }
833
834
835 void CPlaybackView::m_FromEditToPlaybackMode(void)
836 {
837         if (m->hMusicController->PlayState() == PLAY_STATUS_STOP) {
838                 elm_genlist_item_bring_in(m->cs_itinfo->item,
839                         ELM_GENLIST_ITEM_SCROLLTO_IN);
840         }
841         else
842                 m_SelectItem(m->cs_itinfo);
843
844         elm_object_signal_emit(m->eoBase, MUSIC_SIGNAL_PLAYBACK_MODE,
845                 MUSIC_PLAYBACK_VIEW);
846         elm_object_focus_set(m->eoBtnControl[BTN_SETTINGS], EINA_TRUE);
847
848         m_ChangeEditmodeAll(m->elInfo, false);
849
850         elm_genlist_realized_items_update(m->eoPlaylist);
851
852         m_UpdatePlaymodeFocusSequence();
853 }
854
855
856 void CPlaybackView::m_FromPlaybackToEditMode(void)
857 {
858         elm_object_signal_emit(m->eoBase, MUSIC_SIGNAL_EDIT_MODE,
859                 MUSIC_PLAYBACK_VIEW);
860
861         m_DisableEditButtons(true);
862
863         elm_object_focus_set(m->eoBtnEdit[BTN_CANCEL], EINA_TRUE);
864
865         m_ChangeEditmodeAll(m->elInfo, true);
866
867         elm_genlist_realized_items_update(m->eoPlaylist);
868
869         m_UpdateEditmodeFocusSequence();
870 }
871
872
873 void CPlaybackView::m_HandleOnRepeated(void)
874 {
875         Evas_Object *obj = NULL;
876         int value;
877         int duration;
878         char *timestr = NULL;
879
880         if (!m->eoPressedObj)
881                 return;
882
883         obj = m->eoPressedObj;
884
885         value = elm_slider_value_get(m->eoSlider);
886         duration = m->cs_itinfo->sinfo->Duration();
887
888         if (obj == m->eoBtnControl[BTN_REWIND]) {
889                 if (value == 0) {
890                         m_RemoveTimer(TIMER_LONGPRESS);
891                         return;
892                 }
893                 value = value - LP_CHANGE;
894                 if (value <= 0)
895                         value = 0;
896         }
897         else {
898                 if (value == duration) {
899                         if (m->hMusicController->PlayNextSong())
900                                 m_UpdateCurrentSongInfo();
901                         else
902                                 _ERR(" music play next song failed ");
903
904                         m->press_status = PRESS_LONG_PAUSE;
905                         elm_object_signal_emit(m->eoBtnControl[BTN_PLAY], MUSIC_SIGNAL_PAUSE,
906                                 MUSIC_PLAYBACK_VIEW);
907                         m_PlaybackPause();
908                         m_RemoveTimer(TIMER_LONGPRESS);
909
910                         return;
911                 }
912                 value = value + LP_CHANGE;
913                 if (value >= duration)
914                         value = duration;
915         }
916
917         m->hMusicController->SetPosition(value);
918         elm_slider_value_set(m->eoSlider, value);
919         timestr = _get_timestr_from_milseconds(value);
920         if (timestr) {
921                 elm_object_part_text_set(m->eoBase, MUSIC_PART_PROGRESSTIME,
922                         timestr);
923                 free(timestr);
924         }
925
926         return;
927 }
928
929
930 void CPlaybackView::m_DeleteSelectedItems(void)
931 {
932         Eina_List *l = NULL, *l_next = NULL;
933         SItemInfo *pItemInfo = NULL;
934         void *obj = NULL;
935         int index;
936         bool flag = false;
937
938         m_DisableEditButtons(true);
939         EINA_LIST_FOREACH_SAFE(m->elInfo, l, l_next, obj) {
940                 pItemInfo = (SItemInfo *)obj;
941                 if (pItemInfo->check_status) {
942                         if (m->cs_itinfo == pItemInfo) {
943                                 flag = true;
944                                 m_UnselectItem(m->cs_itinfo);
945                                 m_RemoveTimer(TIMER_SLIDER);
946                                 m->cs_itinfo = NULL;
947                                 m->hMusicController->SetPlayState(PLAY_STATUS_STOP);
948                                 m->hMusicController->Stop();
949                         }
950                         index = elm_genlist_item_index_get(pItemInfo->item);
951                         m->hMusicController->RemoveSong(pItemInfo->sinfo, index);
952
953                         m->elInfo = eina_list_remove(m->elInfo,
954                                 pItemInfo);
955                         elm_object_item_del(pItemInfo->item);
956                 }
957         }
958
959         if (eina_list_count(m->elInfo) == 0) {
960                 m_UpdateEmptySongInfo();
961                 elm_genlist_realized_items_update(m->eoPlaylist);
962                 elm_object_focus_set(m->eoBtnEdit[BTN_CANCEL], EINA_TRUE);
963                 return;
964         }
965
966         if (flag)
967                 m_UpdateCurrentSongInfo();
968
969         elm_genlist_realized_items_update(m->eoPlaylist);
970         elm_object_focus_set(m->eoBtnEdit[BTN_CANCEL], EINA_TRUE);
971 }
972
973
974 void CPlaybackView::m_KeyBackPress(void)
975 {
976         if (m->eoCtxPopup) {
977                 m_DestroySettingsPopup();
978                 elm_object_focus_set(m->eoBtnControl[BTN_SETTINGS], EINA_FALSE);
979                 elm_object_focus_set(m->eoBtnControl[BTN_SETTINGS], EINA_TRUE);
980                 return;
981         }
982
983         t_OnHide();
984         m->mgr->PushView(MUSIC_BASE_VIEW, NULL);
985 }
986
987
988 void CPlaybackView::m_KeyExitPress(void)
989 {
990         m_RemoveTimer(TIMER_SLIDER);
991         m->hMusicController->Stop();
992         elm_exit();
993 }
994
995
996 void CPlaybackView::m_KeyPlayPress(void)
997 {
998         int state;
999
1000         if (elm_object_disabled_get(m->eoBtnControl[BTN_PLAY]))
1001                 return;
1002
1003         state = m->hMusicController->PlayState();
1004         if (state == PLAY_STATUS_PAUSE) {
1005                 m_PlaybackResume();
1006                 elm_object_signal_emit(m->eoBtnControl[BTN_PLAY],
1007                         MUSIC_SIGNAL_PLAY, MUSIC_PLAYBACK_VIEW);
1008         }
1009         else if (state != PLAY_STATUS_PLAY) {
1010                 if (m->hMusicController)
1011                         m->hMusicController->Start();
1012
1013                 m_UpdateCurrentSongInfo();
1014         }
1015 }
1016
1017
1018 void CPlaybackView::m_KeyPausePress(void)
1019 {
1020         int state;
1021
1022         if (elm_object_disabled_get(m->eoBtnControl[BTN_PLAY]))
1023                 return;
1024
1025         state = m->hMusicController->PlayState();
1026         if (state == PLAY_STATUS_PLAY) {
1027                 elm_object_signal_emit(m->eoBtnControl[BTN_PLAY],
1028                         MUSIC_SIGNAL_PAUSE, MUSIC_PLAYBACK_VIEW);
1029                 m_PlaybackPause();
1030         }
1031 }
1032
1033
1034 void CPlaybackView::m_KeyNextPress(void)
1035 {
1036         if (elm_object_disabled_get(m->eoBtnControl[BTN_FORWARD]))
1037                 return;
1038
1039         m_HandleOnPressed(m->eoBtnControl[BTN_FORWARD]);
1040 }
1041
1042
1043 void CPlaybackView::m_KeyPreviousPress(void)
1044 {
1045         if (elm_object_disabled_get(m->eoBtnControl[BTN_REWIND]))
1046                 return;
1047
1048         m_HandleOnPressed(m->eoBtnControl[BTN_REWIND]);
1049 }
1050
1051
1052 void CPlaybackView::m_KeyNextUnpress(void)
1053 {
1054         if (elm_object_disabled_get(m->eoBtnControl[BTN_FORWARD]))
1055                 return;
1056
1057         m_HandleOnUnpressed(m->eoBtnControl[BTN_FORWARD]);
1058 }
1059
1060
1061 void CPlaybackView::m_KeyPreviousUnpress(void)
1062 {
1063         if (elm_object_disabled_get(m->eoBtnControl[BTN_REWIND]))
1064                 return;
1065
1066         m_HandleOnUnpressed(m->eoBtnControl[BTN_REWIND]);
1067 }
1068
1069
1070 void CPlaybackView::m_HandleKeyPress(char *keyname)
1071 {
1072         if (strcmp(keyname, (char*)KEY_EXIT) == 0)
1073                 m_KeyExitPress();
1074         else if (strcmp(keyname, (char*)KEY_BACK) == 0)
1075                 m_KeyBackPress();
1076         else if (strcmp(keyname, (char*)KEY_PLAY) == 0)
1077                 m_KeyPlayPress();
1078         else if (strcmp(keyname, (char*)KEY_PAUSE) == 0)
1079                 m_KeyPausePress();
1080         else if (strcmp(keyname, (char*)KEY_NEXT) == 0)
1081                 m_KeyNextPress();
1082         else if (strcmp(keyname, (char*)KEY_PREVIOUS) == 0)
1083                 m_KeyPreviousPress();
1084         else if (strcmp(keyname, (char*)KEY_VOLUMEUP) == 0)
1085                 m->pHandleVolume->Up();
1086         else if (strcmp(keyname, (char*)KEY_VOLUMEDOWN) == 0)
1087                 m->pHandleVolume->Down();
1088         else if (strcmp(keyname, (char*)KEY_MUTE) == 0)
1089                 m->pHandleVolume->Mute();
1090 }
1091
1092
1093 void CPlaybackView::m_HandleKeyUnpress(char *keyname)
1094 {
1095         if (!strcmp(keyname, KEY_PREVIOUS))
1096                 m_KeyPreviousUnpress();
1097         else if (!strcmp(keyname, KEY_NEXT))
1098                 m_KeyNextUnpress();
1099 }
1100
1101
1102 void CPlaybackView::m_AddSlider(void)
1103 {
1104         Evas_Object *eoSlider = NULL;
1105
1106         eoSlider = elm_slider_add(m->eoBase);
1107         if (!eoSlider)
1108                 return;
1109
1110         elm_slider_indicator_show_set(eoSlider, EINA_FALSE);
1111         elm_slider_indicator_show_on_focus_set(eoSlider, EINA_FALSE);
1112         elm_object_style_set(eoSlider, MUSIC_STYLE_SLIDER);
1113         elm_slider_horizontal_set(eoSlider, EINA_TRUE);
1114         elm_object_part_content_set(m->eoBase, MUSIC_PART_PROGRESSBAR, eoSlider);
1115
1116         Connect(eoSlider, EO_SLIDER, TYPE_CHANGED | TYPE_MOUSE_MOVE);
1117
1118         evas_object_show(eoSlider);
1119         m->eoSlider = eoSlider;
1120 }
1121
1122
1123 void CPlaybackView::m_AddAlbumCover(void)
1124 {
1125         Evas_Object *eoAlbumCover = NULL;
1126
1127         eoAlbumCover = elm_image_add(m->eoBase);
1128         if (!eoAlbumCover)
1129                 return;
1130
1131         evas_object_size_hint_weight_set(eoAlbumCover, EVAS_HINT_EXPAND,
1132                         EVAS_HINT_EXPAND);
1133         elm_image_aspect_fixed_set(eoAlbumCover, EINA_FALSE);
1134
1135         elm_object_part_content_set(m->eoBase, MUSIC_PART_ALBUMCOVER,
1136                         eoAlbumCover);
1137         evas_object_show(eoAlbumCover);
1138         m->eoAlbumCover = eoAlbumCover;
1139
1140 }
1141
1142
1143 void CPlaybackView::m_AddCurrentSonginfo(void)
1144 {
1145         m_AddAlbumCover();
1146         m_AddSlider();
1147 }
1148
1149
1150 void CPlaybackView::m_AddEditPlaylistButtons(void)
1151 {
1152         Evas_Object *box = NULL;
1153         int i;
1154         SBtnInfo btninfo[TOTAL_EDIT_BTNS];
1155
1156         btninfo[BTN_CANCEL].txt = MUSIC_TEXT_CANCEL;
1157         btninfo[BTN_CANCEL].type = EO_CANCEL;
1158
1159         btninfo[BTN_DESELECT].txt = MUSIC_TEXT_DESELECT;
1160         btninfo[BTN_DESELECT].type = EO_DESELECT;
1161
1162         btninfo[BTN_DELETE].txt = MUSIC_TEXT_DELETE;
1163         btninfo[BTN_DELETE].type = EO_DELETE;
1164
1165         box = _add_box(m->eoBase);
1166         if (!box)
1167                 return;
1168
1169         elm_box_horizontal_set(box, EINA_TRUE);
1170         elm_box_padding_set(box,
1171                 MUSIC_EDIT_BTNS_PADDING * elm_config_scale_get(), 0);
1172
1173         for (i = 0; i < TOTAL_EDIT_BTNS; i++) {
1174                 m->eoBtnEdit[i] = elm_button_add(m->eoBase);
1175                 if (!m->eoBtnEdit[i])
1176                         continue;
1177
1178                 elm_object_style_set(m->eoBtnEdit[i],
1179                         MUSIC_STYLE_EDIT_BTN);
1180                 evas_object_size_hint_weight_set(m->eoBtnEdit[i],
1181                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1182                 elm_box_pack_end(box, m->eoBtnEdit[i]);
1183                 elm_object_text_set(m->eoBtnEdit[i], _(btninfo[i].txt));
1184
1185                 Connect(m->eoBtnEdit[i], btninfo[i].type, TYPE_CLICKED | TYPE_MOUSE_MOVE);
1186
1187                 evas_object_show(m->eoBtnEdit[i]);
1188         }
1189         elm_object_part_content_set(m->eoBase, MUSIC_PART_EDITBTNS, box);
1190         elm_object_signal_emit(m->eoBase, MUSIC_SIGNAL_PLAYBACK_MODE,
1191                 MUSIC_PLAYBACK_VIEW);
1192 }
1193
1194
1195 void CPlaybackView::m_AddControlButtons(void)
1196 {
1197         Evas_Object *box = NULL;
1198         int i;
1199         SBtnInfo btninfo[TOTAL_CONTROL_BTNS];
1200
1201         btninfo[BTN_SETTINGS].txt = MUSIC_STYLE_BTN_SETTINGS;
1202         btninfo[BTN_SETTINGS].type = EO_BTN_SETTINGS;
1203
1204         btninfo[BTN_SHUFFLE].txt = MUSIC_STYLE_BTN_SHUFFLE;
1205         btninfo[BTN_SHUFFLE].type = EO_BTN_SHUFFLE;
1206
1207         btninfo[BTN_REPEAT].txt = MUSIC_STYLE_BTN_REPEAT;
1208         btninfo[BTN_REPEAT].type = EO_BTN_REPEAT;
1209
1210         btninfo[BTN_REWIND].txt = MUSIC_STYLE_BTN_REWIND;
1211         btninfo[BTN_REWIND].type = EO_BTN_REWIND;
1212
1213         btninfo[BTN_PLAY].txt = MUSIC_STYLE_BTN_PLAY;
1214         btninfo[BTN_PLAY].type = EO_BTN_PLAY;
1215
1216         btninfo[BTN_FORWARD].txt = MUSIC_STYLE_BTN_FORWARD;
1217         btninfo[BTN_FORWARD].type = EO_BTN_FORWARD;
1218
1219         box = elm_box_add(m->eoBase);
1220         if (!box)
1221                 return;
1222
1223         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0);
1224         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0);
1225         elm_box_horizontal_set(box, EINA_TRUE);
1226         elm_box_padding_set(box,
1227                 MUSIC_CONTROL_BTNS_PADDING * elm_config_scale_get(), 0);
1228
1229         for (i = 0; i < TOTAL_CONTROL_BTNS; i++) {
1230                 m->eoBtnControl[i] = elm_button_add(m->eoBase);
1231                 if (!m->eoBtnControl[i])
1232                         continue;
1233
1234                 elm_object_style_set(m->eoBtnControl[i], btninfo[i].txt);
1235                 evas_object_size_hint_weight_set(m->eoBtnControl[i],
1236                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1237                 elm_box_pack_end(box, m->eoBtnControl[i]);
1238
1239                 if (i == BTN_REWIND || i == BTN_FORWARD) {
1240                         Connect(m->eoBtnControl[i], btninfo[i].type, TYPE_PRESSED | TYPE_UNPRESSED | TYPE_MOUSE_MOVE);
1241                 }
1242                 else {
1243                         Connect(m->eoBtnControl[i], btninfo[i].type, TYPE_CLICKED | TYPE_MOUSE_MOVE);
1244                 }
1245                 evas_object_show(m->eoBtnControl[i]);
1246         }
1247
1248         elm_object_part_content_set(m->eoBase, MUSIC_PART_CONTROLBTNS, box);
1249 }
1250
1251
1252 SItemInfo *CPlaybackView::m_FindItemInfoFromSong(Eina_List *list, CSongInfo *sinfo)
1253 {
1254         Eina_List *l = NULL;
1255         SItemInfo *itinfo = NULL;
1256         void *obj = NULL;
1257
1258         EINA_LIST_FOREACH(list, l, obj) {
1259                 itinfo = (SItemInfo *)obj;
1260                 if (itinfo->sinfo == sinfo)
1261                         return itinfo;
1262         }
1263
1264         return NULL;
1265 }
1266
1267
1268 SItemInfo *CPlaybackView::m_FindItemInfoFromItem(Eina_List *list, Elm_Object_Item *item)
1269 {
1270         Eina_List *l = NULL;
1271         SItemInfo *itinfo = NULL;
1272         void *obj = NULL;
1273
1274         EINA_LIST_FOREACH(list, l, obj) {
1275                 itinfo = (SItemInfo *)obj;
1276                 if (itinfo->item == item)
1277                         return itinfo;
1278         }
1279
1280         return NULL;
1281 }
1282
1283
1284 void CPlaybackView::m_UpdateItemCheck(SItemInfo *itinfo)
1285 {
1286         if (!itinfo) {
1287                 _ERR(" No item info to Update check ");
1288                 return;
1289         }
1290
1291         if (itinfo->check_status) {
1292                 elm_object_item_signal_emit(itinfo->item,
1293                         MUSIC_SIGNAL_CHECK_OFF, MUSIC_PLAYBACK_VIEW);
1294                 itinfo->check_status = false;
1295                 return;
1296         }
1297
1298         elm_object_item_signal_emit(itinfo->item,
1299                 MUSIC_SIGNAL_CHECK_ON, MUSIC_PLAYBACK_VIEW);
1300         itinfo->check_status = true;
1301 }
1302
1303
1304 class CElmGenlistItemClass {
1305 public:
1306         static char *sm_CbTextGet(void *data, Evas_Object *obj, const char *part)
1307         {
1308                 CSongInfo *sinfo = NULL;
1309                 SItemInfo *pItemInfo = (SItemInfo *)data;
1310                 char buf[MAX_LENGTH];
1311                 char *timestr = NULL;
1312                 int duration;
1313                 int index;
1314
1315                 if (!pItemInfo || !obj)
1316                         return NULL;
1317
1318                 sinfo = pItemInfo->sinfo;
1319
1320                 snprintf(buf, sizeof(buf), "%s", MUSIC_STR_EMPTY);
1321
1322                 if (!strcmp(part, "elm.text0")) {
1323                         index = elm_genlist_item_index_get(pItemInfo->item);
1324                         snprintf(buf, sizeof(buf), "%d", index + 1);
1325                         if ((index & 1) == 1) {
1326                                 elm_object_item_signal_emit(pItemInfo->item,
1327                                         MUSIC_SIGNAL_EVEN_ROW, MUSIC_PLAYBACK_VIEW);
1328                         }
1329                         else {
1330                                 elm_object_item_signal_emit(pItemInfo->item,
1331                                         MUSIC_SIGNAL_ODD_ROW, MUSIC_PLAYBACK_VIEW);
1332                         }
1333                 }
1334                 else if (!strcmp(part, "elm.text1"))
1335                         snprintf(buf, sizeof(buf), "%s", sinfo->Name());
1336                 else if (!strcmp(part, "elm.text2"))
1337                         snprintf(buf, sizeof(buf), "%s - %s",
1338                         sinfo->Artist(),
1339                         sinfo->Album());
1340                 else if (!strcmp(part, "elm.text3")) {
1341                         duration = sinfo->Duration();
1342                         timestr = _get_timestr_from_milseconds(duration);
1343                         if (timestr) {
1344                                 snprintf(buf, sizeof(buf), "%s", timestr);
1345                                 free(timestr);
1346                         }
1347                 }
1348
1349                 if (strcmp(buf, MUSIC_STR_EMPTY))
1350                         return strdup(buf);
1351
1352                 return NULL;
1353         }
1354         static Evas_Object *sm_CbContentGet(void *data, Evas_Object *obj, const char *part)
1355         {
1356                 CSongInfo *sinfo = NULL;
1357                 SItemInfo *pItemInfo = (SItemInfo *)data;
1358                 Evas_Object *img = NULL;
1359                 char *path = NULL;
1360                 char buf[MAX_LENGTH];
1361
1362                 if (!pItemInfo || !obj)
1363                         return NULL;
1364
1365                 sinfo = pItemInfo->sinfo;
1366
1367                 img = elm_image_add(obj);
1368                 if (!img)
1369                         return NULL;
1370
1371                 elm_image_aspect_fixed_set(img, EINA_FALSE);
1372
1373                 if (!strcmp(part, "elm.swallow.icon")) {
1374                         path = sinfo->ThumbnailPath();
1375                         if (path)
1376                                 elm_image_file_set(img, path, "NULL");
1377                         else {
1378                                 snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR,
1379                                         MUSIC_IMAGE_DEFAULT_THUMB_126);
1380                                 elm_image_file_set(img, buf, "NULL");
1381                         }
1382                 }
1383
1384                 if (pItemInfo->select_status) {
1385                         elm_object_item_signal_emit(pItemInfo->item,
1386                                 MUSIC_SIGNAL_SELECT_ITEM, MUSIC_PLAYBACK_VIEW);
1387                 }
1388                 else {
1389                         elm_object_item_signal_emit(pItemInfo->item,
1390                                 MUSIC_SIGNAL_UNSELECT_ITEM,
1391                                 MUSIC_PLAYBACK_VIEW);
1392                 }
1393
1394                 if (pItemInfo->edit_mode) {
1395                         elm_object_item_signal_emit(pItemInfo->item,
1396                                 MUSIC_SIGNAL_EDITMODE_ON, MUSIC_PLAYBACK_VIEW);
1397                         if (pItemInfo->check_status) {
1398                                 elm_object_item_signal_emit(pItemInfo->item,
1399                                         MUSIC_SIGNAL_CHECK_ON,
1400                                         MUSIC_PLAYBACK_VIEW);
1401                         }
1402                         else {
1403                                 elm_object_item_signal_emit(pItemInfo->item,
1404                                         MUSIC_SIGNAL_CHECK_OFF, MUSIC_PLAYBACK_VIEW);
1405                         }
1406                 }
1407                 else {
1408                         elm_object_item_signal_emit(pItemInfo->item,
1409                                 MUSIC_SIGNAL_EDITMODE_OFF, MUSIC_PLAYBACK_VIEW);
1410                 }
1411
1412                 return img;
1413
1414         }
1415         static void         sm_CbDel(void *data, Evas_Object *obj)
1416         {
1417                 free(data);
1418         }
1419 };
1420
1421
1422 Elm_Genlist_Item_Class *CPlaybackView::m_GetItemClass(void)
1423 {
1424         Elm_Genlist_Item_Class *list_item = NULL;
1425
1426         list_item = elm_genlist_item_class_new();
1427         if (!list_item) {
1428                 _ERR(" elm_genlist_item_class_new failed ");
1429                 return NULL;
1430         }
1431
1432         list_item->item_style       = MUSIC_STYLE_PLAYLIST;
1433         list_item->func.text_get    = CElmGenlistItemClass::sm_CbTextGet;
1434         list_item->func.content_get = CElmGenlistItemClass::sm_CbContentGet;
1435         list_item->func.state_get   = NULL;
1436         list_item->func.del         = CElmGenlistItemClass::sm_CbDel;
1437
1438         return list_item;
1439 }
1440
1441
1442 void CPlaybackView::m_AddGenlist(void)
1443 {
1444         Evas_Object *genlist = NULL;
1445         Evas_Object *eoBase = NULL;
1446
1447         eoBase = m->eoBase;
1448         genlist = elm_genlist_add(eoBase);
1449         if (!genlist)
1450                 return;
1451
1452         elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1453         evas_object_size_hint_weight_set(genlist,
1454                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1455         elm_object_part_content_set(eoBase, MUSIC_PART_PLAYLIST, genlist);
1456         elm_genlist_select_mode_set(genlist, ELM_OBJECT_SELECT_MODE_ALWAYS);
1457         elm_genlist_multi_select_set(genlist, EINA_FALSE);
1458
1459         Connect(genlist, EO_PLAYLIST, TYPE_REALIZED | TYPE_UNREALIZED | TYPE_MOUSE_MOVE | TYPE_KEY_DOWN | TYPE_ACTIVATED);
1460
1461         evas_object_show(genlist);
1462         m->eoPlaylist = genlist;
1463 }
1464
1465
1466 void CPlaybackView::m_AddPlaylist(void)
1467 {
1468         Elm_Genlist_Item_Class *list_item = NULL;
1469         int ts = 0;
1470         int i, index = -1;
1471         CSongInfo *sinfo = NULL;
1472         Elm_Object_Item *item = NULL;
1473         SItemInfo *pItemInfo = NULL;
1474
1475         m_AddGenlist();
1476         if (!m->eoPlaylist)
1477                 return;
1478
1479         list_item = m_GetItemClass();
1480         if (!list_item) {
1481                 evas_object_del(m->eoPlaylist);
1482                 return;
1483         }
1484
1485         if (!m->hMusicController->GetTotalSongs(&ts)) {
1486                 _ERR(" music get total songs failed ");
1487                 return;
1488         }
1489
1490         if (!m->hMusicController->GetCurrentSongIndex(&index))
1491                 _ERR(" music get current song index failed ");
1492
1493         for (i = 0; i < ts; i++) {
1494                 if (!m->hMusicController->GetSonginfoFromIndex(i, &sinfo)) {
1495                         _ERR(" music get songinfo failed ");
1496                         continue;
1497                 }
1498                 pItemInfo = (SItemInfo *)calloc(1, sizeof(*pItemInfo));
1499                 if (!pItemInfo)
1500                         return;
1501                 pItemInfo->sinfo = sinfo;
1502                 pItemInfo->edit_mode = false;
1503                 pItemInfo->check_status = false;
1504                 pItemInfo->select_status = false;
1505
1506                 item = elm_genlist_item_append(m->eoPlaylist, list_item,
1507                         pItemInfo, NULL, ELM_GENLIST_ITEM_NONE,
1508                         sm_CbItemSelect, m);
1509                 pItemInfo->item = item;
1510
1511                 if (i == index) {
1512                         pItemInfo->select_status = true;
1513                         m->cs_itinfo = pItemInfo;
1514                 }
1515                 m->elInfo = eina_list_append(m->elInfo, pItemInfo);
1516         }
1517 }
1518
1519
1520 void CPlaybackView::m_RemovePlaylist(void)
1521 {
1522         if (m->eoPlaylist) {
1523                 elm_genlist_clear(m->eoPlaylist);
1524                 m->eoPlaylist = NULL;
1525         }
1526
1527         if (m->elInfo) {
1528                 eina_list_free(m->elInfo);
1529                 m->elInfo = NULL;
1530         }
1531 }
1532
1533
1534 void CPlaybackView::m_HandleRewindBtnClicked(Evas_Object *obj)
1535 {
1536         elm_object_signal_emit(obj, MUSIC_SIGNAL_BTN_CLICKED,
1537                 MUSIC_PLAYBACK_VIEW);
1538
1539         if (m->hMusicController->PlayState() == PLAY_STATUS_STOP)
1540                 return;
1541
1542         if (!m->hMusicController->PlayPreviousSong()){
1543                 _ERR(" music play previous song failed ");
1544                 return;
1545         }
1546
1547         m_UpdateCurrentSongInfo();
1548 }
1549
1550
1551 void CPlaybackView::m_HandleForwardBtnClicked(Evas_Object *obj)
1552 {
1553         elm_object_signal_emit(obj, MUSIC_SIGNAL_BTN_CLICKED,
1554                 MUSIC_PLAYBACK_VIEW);
1555
1556         if (m->hMusicController->PlayState() == PLAY_STATUS_STOP)
1557                 return;
1558
1559         if (!m->hMusicController->PlayNextSong()) {
1560                 _ERR(" music play next song failed ");
1561                 return;
1562         }
1563
1564         m_UpdateCurrentSongInfo();
1565 }
1566
1567
1568 void CPlaybackView::m_HandleOnPressed(Evas_Object *obj)
1569 {
1570         m->press_status = PRESS_SHORT;
1571         m->eoPressedObj = obj;
1572
1573         m->etWait = ecore_timer_add(WAIT_INTERVAL, sm_CbWaitTimer, m);
1574 }
1575
1576
1577 void CPlaybackView::m_HandleOnUnpressed(Evas_Object *obj)
1578 {
1579         m_RemoveTimer(TIMER_WAIT);
1580         m_RemoveTimer(TIMER_LONGPRESS);
1581
1582         if (m->press_status == PRESS_SHORT) {
1583                 /* Handle song change */
1584                 if (m->hMusicController->PlayState() == PLAY_STATUS_PLAY)
1585                         m_PlaybackPause();
1586
1587                 if (obj == m->eoBtnControl[BTN_FORWARD])
1588                         m_HandleForwardBtnClicked(obj);
1589                 else
1590                         m_HandleRewindBtnClicked(obj);
1591
1592                 if (m->hMusicController->PlayState() != PLAY_STATUS_PLAY)
1593                         m_PlaybackResume();
1594         }
1595         else if (m->press_status == PRESS_LONG) {
1596                 if (m->hMusicController->PlayState() != PLAY_STATUS_PLAY)
1597                         m_PlaybackResume();
1598         }
1599
1600         m->press_status = PRESS_SHORT;
1601 }
1602
1603
1604 void CPlaybackView::m_HandleGenlistItemActivated(Evas_Object *obj, Elm_Object_Item *genListItem)
1605 {
1606         int index;
1607         SItemInfo *itinfo = NULL;
1608
1609         if (!obj || !genListItem)
1610                 return;
1611
1612         itinfo = m_FindItemInfoFromItem(m->elInfo, genListItem);
1613         if (!itinfo) {
1614                 _ERR(" no item info found ");
1615                 return;
1616         }
1617
1618         if (itinfo->edit_mode) {
1619                 m_UpdateItemCheck(itinfo);
1620                 m_DisableEditButtons(false);
1621                 return;
1622         }
1623
1624         index = elm_genlist_item_index_get(genListItem);
1625
1626         m->hMusicController->PlayIndexSong(index);
1627         m_UpdateCurrentSongInfo();
1628 }
1629
1630
1631 bool CPlaybackView::Create(void *data)
1632 {
1633         ASSERT(!m);
1634
1635         _CREATE_BEGIN{
1636                 _CHECK(m = new SPlaybackView)
1637                 _CHECK(m->mgr = CViewMgr::GetInstance())
1638                 _CHECK(m->eoWin = m->mgr->Window())
1639                 _CHECK(m->hMusicController = CMusicController::GetInstance())
1640                 _CHECK(m->eoBase = _add_base(m->eoWin, MUSIC_PLAYBACK_VIEW))
1641                 _CHECK(CBaseView::Create(data))
1642                 _WHEN_SUCCESS{}
1643                 _CHECK_FAIL{ CBaseView::Destroy(); }
1644                 _CHECK_FAIL{ evas_object_del(m->eoBase); }
1645                 _CHECK_FAIL{ /* CMusicController::GetInstance())*/ }
1646                 _CHECK_FAIL{ /* mgr->Window() */ }
1647                 _CHECK_FAIL{ /* CViewerMgr::GetInstance() */}
1648                 _CHECK_FAIL{ delete m; m = NULL; }
1649         }_CREATE_END_AND_CATCH{ return false; }
1650
1651         m->press_status = PRESS_SHORT;
1652         m->parent = this;
1653
1654         evas_object_data_set(m->eoBase, PLAYBACK_VIEW_DATA, m);
1655
1656         m_AddControlButtons();
1657         m_AddEditPlaylistButtons();
1658         m_AddCurrentSonginfo();
1659         m_AddPlaylist();
1660
1661         m->pHandleVolume->Create(m->eoBase);
1662         m_UpdatePlaymodeFocusSequence();
1663
1664         Connect(m->eoBase, EO_BASE, TYPE_KEY_DOWN | TYPE_KEY_UP);
1665
1666         m->hMusicController->AddListener(this);
1667
1668         return true;
1669 }
1670
1671
1672 void CPlaybackView::Destroy(void)
1673 {
1674         ASSERT(m);
1675
1676         m->hMusicController->RemoveListener(this);
1677
1678         m_DestroyErrorPopup();
1679
1680         m_RemoveTimer(TIMER_SLIDER);
1681         m_RemoveTimer(TIMER_WAIT);
1682         m_RemoveTimer(TIMER_LONGPRESS);
1683         m_DestroySettingsPopup();
1684
1685         m->pHandleVolume->Destroy();
1686         CBaseView::Destroy();
1687         evas_object_del(m->eoBase);
1688
1689         free(m->ctxtinfo);
1690         delete m;
1691         m = NULL;
1692 }
1693
1694
1695 Evas_Object* CPlaybackView::Base(void)
1696 {
1697         ASSERT(m);
1698
1699         return m->eoBase;
1700 }
1701
1702
1703 void CPlaybackView::t_OnClickedSettings(Evas_Object *obj)
1704 {
1705         elm_object_signal_emit(obj, MUSIC_SIGNAL_BTN_CLICKED, MUSIC_PLAYBACK_VIEW);
1706
1707         if (eina_list_count(m->elInfo) == 0)
1708                 return;
1709
1710         elm_object_signal_emit(obj, MUSIC_SIGNAL_CONTROL_SELECTED, MUSIC_PLAYBACK_VIEW);
1711         m_DestroySettingsPopup();
1712         m_CreateSettingsPopup();
1713 }
1714
1715
1716 void CPlaybackView::t_OnClickedShuffle(Evas_Object *obj)
1717 {
1718         elm_object_signal_emit(obj, MUSIC_SIGNAL_BTN_CLICKED, MUSIC_PLAYBACK_VIEW);
1719
1720         switch (m->hMusicController->ShuffleState()) {
1721         case SHUFFLE_STATUS_OFF:
1722                 m->hMusicController->SetShuffleState(SHUFFLE_STATUS_ON);
1723                 elm_object_signal_emit(obj, MUSIC_SIGNAL_SHUFFLE_ON, MUSIC_PLAYBACK_VIEW);
1724                 break;
1725
1726         default:
1727                 m->hMusicController->SetShuffleState(SHUFFLE_STATUS_OFF);
1728                 elm_object_signal_emit(obj, MUSIC_SIGNAL_SHUFFLE_OFF, MUSIC_PLAYBACK_VIEW);
1729                 break;
1730         }
1731 }
1732
1733
1734 void CPlaybackView::t_OnClickedRepeat(Evas_Object *obj)
1735 {
1736         elm_object_signal_emit(obj, MUSIC_SIGNAL_BTN_CLICKED, MUSIC_PLAYBACK_VIEW);
1737
1738         switch (m->hMusicController->RepeatState()) {
1739         case REPEAT_STATUS_NONE:
1740                 m->hMusicController->SetRepeatState(REPEAT_STATUS_ALL);
1741                 elm_object_signal_emit(obj, MUSIC_SIGNAL_REPEAT_ALL, MUSIC_PLAYBACK_VIEW);
1742                 break;
1743
1744         case REPEAT_STATUS_ALL:
1745                 m->hMusicController->SetRepeatState(REPEAT_STATUS_ONE);
1746                 elm_object_signal_emit(obj, MUSIC_SIGNAL_REPEAT_ONE, MUSIC_PLAYBACK_VIEW);
1747                 break;
1748
1749         default:
1750                 m->hMusicController->SetRepeatState(REPEAT_STATUS_NONE);
1751                 elm_object_signal_emit(obj, MUSIC_SIGNAL_REPEAT_OFF, MUSIC_PLAYBACK_VIEW);
1752                 break;
1753         }
1754 }
1755
1756
1757 void CPlaybackView::t_OnClickedPlay(Evas_Object *obj)
1758 {
1759         elm_object_signal_emit(obj, MUSIC_SIGNAL_BTN_CLICKED, MUSIC_PLAYBACK_VIEW);
1760
1761         switch (m->hMusicController->PlayState()) {
1762         case PLAY_STATUS_PAUSE:
1763                 m_PlaybackResume();
1764                 elm_object_signal_emit(obj, MUSIC_SIGNAL_PLAY, MUSIC_PLAYBACK_VIEW);
1765                 break;
1766
1767         case PLAY_STATUS_PLAY:
1768                 elm_object_signal_emit(obj, MUSIC_SIGNAL_PAUSE, MUSIC_PLAYBACK_VIEW);
1769                 m_PlaybackPause();
1770                 break;
1771
1772         default:
1773                 if (m->hMusicController)
1774                         m->hMusicController->Start();
1775                 m_UpdateCurrentSongInfo();
1776                 break;
1777         }
1778 }
1779
1780
1781 void CPlaybackView::t_OnShow(void)
1782 {
1783         ASSERT(m);
1784
1785         int state;
1786
1787         if (m->cs_itinfo) {
1788                 elm_genlist_item_show(m->cs_itinfo->item,
1789                         ELM_GENLIST_ITEM_SCROLLTO_IN);
1790                 elm_object_item_focus_set(m->cs_itinfo->item, EINA_TRUE);
1791         }
1792
1793         state = m->hMusicController->PlayState();
1794         if (state == PLAY_STATUS_INITIAL || state == PLAY_STATUS_STOP) {
1795                 m_RemovePlaylist();
1796                 m_AddPlaylist();
1797                 m->hMusicController->Start();
1798                 m_UpdateCurrentSongInfo();
1799         }
1800
1801         evas_object_show(m->eoBase);
1802 }
1803
1804
1805 void CPlaybackView::t_OnUpdate(void *data)
1806 {
1807         ASSERT(m);
1808
1809         if (!data)
1810                 return;
1811
1812         SParcel *parcel = (SParcel *)data;
1813         int updateType = parcel->updateType;
1814         char *key = (char *)parcel->keyEvent;
1815
1816         switch (updateType) {
1817         case E_PLAYLIST_UPDATE:
1818                 m_RemovePlaylist();
1819                 m_AddPlaylist();
1820                 elm_object_disabled_set(m->eoBtnControl[BTN_FORWARD], EINA_FALSE);
1821                 elm_object_disabled_set(m->eoBtnControl[BTN_REWIND], EINA_FALSE);
1822                 elm_object_disabled_set(m->eoBtnControl[BTN_PLAY], EINA_FALSE);
1823                 elm_object_focus_next_object_set(m->eoBtnControl[BTN_REPEAT],
1824                         m->eoBtnControl[BTN_REWIND], ELM_FOCUS_RIGHT);
1825                 m_FromEditToPlaybackMode();
1826                 break;
1827
1828         case E_KEY_PRESS:
1829                 m_HandleKeyPress(key);
1830                 break;
1831
1832         case E_KEY_RELEASE:
1833                 m_HandleKeyUnpress(key);
1834                 break;
1835
1836         default:
1837                 break;
1838         }
1839 }
1840
1841
1842 void CPlaybackView::t_OnHide(void)
1843 {
1844         ASSERT(m);
1845
1846         evas_object_hide(m->eoBase);
1847 }
1848
1849
1850 void CPlaybackView::OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev)
1851 {
1852         switch (id) {
1853         case EO_BASE:
1854                 m_HandleKeyPress(ev->keyname);
1855                 break;
1856
1857         case EO_ERROR_POPUP_BUTTON:
1858                 if (!strcmp(ev->keyname, KEY_BACK)) {
1859                         m_DestroyErrorPopup();
1860                         elm_object_focus_set(m->eoBtnControl[BTN_PLAY], EINA_TRUE);
1861                 }
1862                 break;
1863
1864         case EO_PLAYLIST:
1865                 {
1866                         Elm_Object_Item *it = NULL;
1867                         SContentInfo *ctxtinfo = NULL;
1868                         SItemInfo *itinfo = NULL;
1869
1870                         if (strcmp(ev->keyname, KEY_MENU))
1871                                 return;
1872
1873                         it = elm_object_focused_item_get(obj);
1874                         if (!it) {
1875                                 _ERR(" unable to get focused item ");
1876                                 return;
1877                         }
1878                         m->focused_item = it;
1879
1880                         if (m->ctxtinfo) {
1881                                 free(m->ctxtinfo);
1882                                 m->ctxtinfo = NULL;
1883                         }
1884
1885                         ctxtinfo = (SContentInfo *)calloc(1, sizeof(*ctxtinfo));
1886                         if (!ctxtinfo)
1887                                 return;
1888
1889                         itinfo = m_FindItemInfoFromItem(m->elInfo, it);
1890                         if (!itinfo) {
1891                                 free(ctxtinfo);
1892                                 return;
1893                         }
1894
1895                         if (m->hMusicController->PlayState() == PLAY_STATUS_PLAY &&
1896                                 itinfo == m->cs_itinfo)
1897                                 ctxtinfo->status = PLAY_STATUS_PLAY;
1898                         else
1899                                 ctxtinfo->status = PLAY_STATUS_PAUSE;
1900
1901                         ctxtinfo->cbdata = m;
1902                         ctxtinfo->update = sm_CbCtxtUpdate;
1903                         ctxtinfo->close = sm_CbCtxtClose;
1904                         ctxtinfo->type = CONTEXT_TYPE_PLAYSONG;
1905                         ctxtinfo->context = itinfo->sinfo;
1906
1907                         m->ctxtinfo = ctxtinfo;
1908
1909                         SParcel parcel;
1910                         parcel.ctxtInfo = ctxtinfo;
1911                         if (!m->mgr->PushView(MUSIC_CONTEXT_VIEW, &parcel))
1912                                 _ERR("viewmgr push view MUSIC_CONTEXT_VIEW failed");
1913                 }
1914
1915         case EO_BOX:
1916                 if (!strcmp(ev->keyname, KEY_BACK)) {
1917                         _ERR("eoCtxPopup BACK key pressed ");
1918                         m_DestroySettingsPopup();
1919                         elm_object_focus_set(m->eoBtnControl[BTN_SETTINGS], EINA_TRUE);
1920
1921                 }
1922                 else if (!strcmp(ev->keyname, KEY_EXIT)) {
1923                         _ERR("eoCtxPopup EXIT key pressed ");
1924                         m_DestroySettingsPopup();
1925                         m_RemoveTimer(TIMER_SLIDER);
1926                         m->hMusicController->Stop();
1927                         elm_exit();
1928                 }
1929                 break;
1930
1931         default:
1932                 break;
1933         }
1934 }
1935
1936
1937 void CPlaybackView::OnKeyUp(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev)
1938 {
1939         switch (id) {
1940         case EO_BASE:
1941                 m_HandleKeyUnpress(ev->keyname);
1942                 break;
1943
1944         default:
1945                 break;
1946         }
1947 }
1948
1949
1950 void CPlaybackView::OnMouseClicked(int id, Evas_Object *obj)
1951 {
1952         switch (id) {
1953         case EO_ERROR_POPUP_BUTTON:
1954                 m_DestroyErrorPopup();
1955                 elm_object_focus_set(m->eoBtnControl[BTN_PLAY], EINA_TRUE);
1956                 break;
1957
1958         case EO_EDIT_PLAYLIST:
1959                 m_DestroySettingsPopup();
1960                 m_FromPlaybackToEditMode();
1961                 break;
1962
1963         case EO_CLEAR_PLAYLIST:
1964                 m->hMusicController->Stop();
1965                 m->hMusicController->EmptyPlaylist();
1966
1967                 eina_list_free(m->elInfo);
1968                 m->elInfo = NULL;
1969
1970                 elm_genlist_clear(m->eoPlaylist);
1971
1972                 m_DestroySettingsPopup();
1973                 m_UpdateEmptySongInfo();
1974                 break;
1975
1976         case EO_CANCEL:
1977                 m_DisableCheckAll(m->elInfo);
1978                 m_DisableEditButtons(true);
1979                 m_FromEditToPlaybackMode();
1980                 break;
1981
1982         case EO_DESELECT:
1983                 m_DisableCheckAll(m->elInfo);
1984                 m_DisableEditButtons(true);
1985                 elm_genlist_realized_items_update(m->eoPlaylist);
1986                 elm_object_focus_set(m->eoBtnEdit[BTN_CANCEL], EINA_TRUE);
1987                 break;
1988
1989         case EO_DELETE:
1990                 m_DeleteSelectedItems();
1991                 break;
1992
1993         case EO_BTN_SETTINGS:
1994                 t_OnClickedSettings(obj);
1995                 break;
1996
1997         case EO_BTN_SHUFFLE:
1998                 t_OnClickedShuffle(obj);
1999                 break;
2000
2001         case EO_BTN_REPEAT:
2002                 t_OnClickedRepeat(obj);
2003                 break;
2004
2005         case EO_BTN_PLAY:
2006                 t_OnClickedPlay(obj);
2007                 break;
2008
2009         default:
2010                 break;
2011         }
2012 }
2013
2014
2015 void CPlaybackView::OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev)
2016 {
2017         switch (id) {
2018         case EO_CANCEL:
2019         case EO_DESELECT:
2020         case EO_DELETE:
2021         case EO_SLIDER:
2022         case EO_BTN_FORWARD:
2023         case EO_BTN_PLAY:
2024         case EO_BTN_REPEAT:
2025         case EO_BTN_REWIND:
2026         case EO_BTN_SETTINGS:
2027         case EO_BTN_SHUFFLE:
2028         case EO_EDIT_PLAYLIST:
2029         case EO_CLEAR_PLAYLIST:
2030                 if (!elm_object_focus_get(obj))
2031                         elm_object_focus_set(obj, EINA_TRUE);
2032                 break;
2033
2034         case EO_PLAYLIST:
2035                 {
2036                         Elm_Object_Item *item;
2037
2038                         item = elm_genlist_at_xy_item_get(obj, ev->cur.canvas.x,
2039                                 ev->cur.canvas.y, NULL);
2040                         if (!item)
2041                                 return;
2042
2043                         if (!elm_object_item_focus_get(item))
2044                                 elm_object_item_focus_set(item, EINA_TRUE);
2045                 }
2046                 break;
2047
2048         default:
2049                 break;
2050         }
2051 }
2052
2053
2054 void CPlaybackView::OnPressed(int id, Evas_Object *obj)
2055 {
2056         switch (id) {
2057         case EO_BTN_FORWARD:
2058         case EO_BTN_REWIND:
2059                 m_HandleOnPressed(obj);
2060                 break;
2061
2062         default:
2063                 break;
2064         }
2065 }
2066
2067
2068 void CPlaybackView::OnUnpressed(int id, Evas_Object *obj)
2069 {
2070         switch (id) {
2071         case EO_BTN_FORWARD:
2072         case EO_BTN_REWIND:
2073                 m_HandleOnUnpressed(obj);
2074                 break;
2075
2076         default:
2077                 break;
2078         }
2079 }
2080
2081
2082 void CPlaybackView::OnChanged(int id, Evas_Object *obj)
2083 {
2084         switch (id) {
2085         case EO_SLIDER:
2086                 {
2087                         char *timestr = NULL;
2088                         int value;
2089
2090                         if (m->hMusicController->PlayState() == PLAY_STATUS_PLAY) {
2091                                 if (m->etSlider)
2092                                         ecore_timer_freeze(m->etSlider);
2093                         }
2094
2095                         value = elm_slider_value_get(obj);
2096                         m->hMusicController->SetPosition(value);
2097                         timestr = _get_timestr_from_milseconds(value);
2098                         if (timestr) {
2099                                 elm_object_part_text_set(m->eoBase, MUSIC_PART_PROGRESSTIME,
2100                                         timestr);
2101                                 free(timestr);
2102                         }
2103
2104                         if (m->hMusicController->PlayState() == PLAY_STATUS_PLAY) {
2105                                 if (m->etSlider)
2106                                         ecore_timer_thaw(m->etSlider);
2107                         }
2108                 }
2109                 break;
2110
2111         default:
2112                 break;
2113         }
2114 }
2115
2116
2117 void CPlaybackView::OnRealized(int id, Evas_Object *obj, Elm_Object_Item *item)
2118 {
2119         switch (id) {
2120         case EO_PLAYLIST:
2121                 elm_object_item_signal_callback_add(item,
2122                         MUSIC_SIGNAL_CHECK_CLICKED, MUSIC_PLAYBACK_VIEW,
2123                         sm_CbGenlistItemCheckClicked, this);
2124                 break;
2125
2126         default:
2127                 break;
2128         }
2129 }
2130
2131
2132 void CPlaybackView::OnUnrealized(int id, Evas_Object *obj, Elm_Object_Item *item)
2133 {
2134         switch (id) {
2135         case EO_PLAYLIST:
2136                 elm_object_item_signal_callback_del(item,
2137                         MUSIC_SIGNAL_CHECK_CLICKED, MUSIC_PLAYBACK_VIEW,
2138                         sm_CbGenlistItemCheckClicked);
2139                 break;
2140
2141         default:
2142                 break;
2143         }
2144 }
2145
2146
2147 void CPlaybackView::OnActivated(int id, Evas_Object *obj, Elm_Object_Item *item)
2148 {
2149         switch (id) {
2150         case EO_PLAYLIST:
2151                 m_HandleGenlistItemActivated(obj, item);
2152                 break;
2153
2154         default:
2155                 break;
2156         }
2157 }
2158
2159
2160 void CPlaybackView::t_OnComplete(void)
2161 {
2162         m_UpdateCurrentSongInfo();
2163 }
2164
2165
2166 void CPlaybackView::t_OnError(void)
2167 {
2168         m_CreateErrorPopup();
2169 }
2170
2171
2172 void CPlaybackView::t_OnUsbConnected(void)
2173 {
2174 }
2175
2176
2177 void CPlaybackView::t_OnUpdateContent(void)
2178 {
2179 }