Tizen 2.1 base
[apps/home/ug-myfile-efl.git] / src / common / mf-ug-list-play.c
1 /*
2  * Copyright 2012          Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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
18
19
20
21 #include <stdio.h>
22 #include <Elementary.h>
23 #include <Ecore_X.h>
24 #include <vconf.h>
25 #include <stdbool.h>
26
27
28 #include "mf-ug-main.h"
29 #include "mf-ug-conf.h"
30 #include "mf-ug-cb.h"
31 #include "mf-ug-fm-svc-wrapper.h"
32 #include "mf-ug-util.h"
33 #include "mf-ug-winset.h"
34 #include "mf-ug-dlog.h"
35 #include "mf-ug-fs-util.h"
36 #include "mf-ug-resource.h"
37 #include "mf-ug-list-play.h"
38 static mf_player_cbs *g_player_cbs = NULL;
39 static Ecore_Pipe *g_player_pipe = NULL;
40
41 static void __mf_ug_list_play_control_cb(void *data);
42 static bool __mf_ug_list_play_play_current_file(void *data);
43
44
45 /******************************
46 ** Prototype    : __mf_ug_list_play_init_data
47 ** Description  : Samsung
48 ** Input        : void *data
49 ** Output       : None
50 ** Return Value :
51 ** Calls        :
52 ** Called By    :
53 **
54 **  History        :
55 **  1.Date         : 2010/12/10
56 **    Author       : Samsung
57 **    Modification : Created function
58 **
59 ******************************/
60 static void __mf_ug_list_play_init_data(void *data)
61 {
62         UG_TRACE_BEGIN;
63         ugData *ugd = (ugData *)data;
64
65         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
66
67         if (ugd->ug_ListPlay.ug_Player != 0) {
68                 mf_ug_list_play_destory_playing_file(ugd);
69                 ugd->ug_ListPlay.ug_Player = 0;
70         }
71         ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_INIT;
72         UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath);
73         UG_TRACE_END;
74 }
75
76 /******************************
77 ** Prototype    : __mf_ug_list_play_drm_has_valid_ro
78 ** Description  : Samsung
79 ** Input        : char *path
80 ** Output       : None
81 ** Return Value :
82 ** Calls        :
83 ** Called By    :
84 **
85 **  History        :
86 **  1.Date         : 2010/12/10
87 **    Author       : Samsung
88 **    Modification : Created function
89 **
90 ******************************/
91 static bool __mf_ug_list_play_drm_has_valid_ro(char *path)
92 {
93         UG_TRACE_BEGIN;
94         drm_result_e res = DRM_RETURN_INVALID_ARG;
95         drm_license_status_e licence_status;
96
97         if (path) {
98                 res = drm_get_license_status(path, DRM_PERMISSION_TYPE_PLAY, &licence_status);
99         }
100
101         if (res == DRM_RETURN_SUCCESS && licence_status == DRM_LICENSE_STATUS_VALID) {
102                 return true;
103         } else {
104                 return false;
105         }
106 }
107
108
109 /******************************
110 ** Prototype    : __mf_ug_list_play_check_drm_left_ro
111 ** Description  : Samsung
112 ** Input        : void *data
113 **                char *path
114 ** Output       : None
115 ** Return Value :
116 ** Calls        :
117 ** Called By    :
118 **
119 **  History        :
120 **  1.Date         : 2010/12/10
121 **    Author       : Samsung
122 **    Modification : Created function
123 **
124 ******************************/
125 static bool __mf_ug_list_play_check_drm_left_ro(void *data, char *path)
126 {
127         UG_TRACE_BEGIN;
128         ugData *ugd = (ugData *)data;
129         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
130
131
132         char left_ro_message[MAX_MESSAGE_LEN] = "\0";
133
134         bool ro_valid = false;
135         bool expired = false;
136
137
138         const char *title = ecore_file_file_get(path);
139         ugd->ug_ListPlay.ug_bDrmContentCanPlay = false;
140
141         if (__mf_ug_list_play_drm_has_valid_ro(path))
142         {
143                 drm_constraint_info_s constraint;
144                 memset(&constraint, 0x0, sizeof(drm_constraint_info_s));
145
146                 int res = drm_get_constraint_info(path, DRM_PERMISSION_TYPE_PLAY, &constraint);
147                 if (res == DRM_RETURN_SUCCESS) {
148                         if (constraint.const_type.is_unlimited) {
149                                 ug_debug("UNLIMITED");
150                                 ugd->ug_ListPlay.ug_bDrmContentCanPlay = TRUE;
151                                 return TRUE;
152                         }
153
154                         if (constraint.const_type.is_count) {
155                                 int remain_count = constraint.remaining_count;
156
157                                 if (remain_count == 1) {
158                                         snprintf(left_ro_message, sizeof(left_ro_message), "You can play \"%s\" just one more time", title);
159                                         ro_valid = true;
160                                         ugd->ug_ListPlay.ug_bDrmContentCanPlay = true;
161                                 } else if (remain_count == 0) {
162                                         snprintf(left_ro_message, sizeof(left_ro_message), "You can't play \"%s\" anymore", title);
163                                         ro_valid = false;
164                                 } else {
165                                         ro_valid = true;
166                                         ugd->ug_ListPlay.ug_bDrmContentCanPlay = true;
167                                 }
168                         }
169
170                         if (constraint.const_type.is_datetime) {
171                                 ug_debug("DRM_DATETIME\n");
172                                 snprintf(ugd->ug_ListPlay.ug_DrmInfo.validity, sizeof(ugd->ug_ListPlay.ug_DrmInfo.validity),
173                                         "%d.%d.%d %d:%d~%d.%d.%d %d:%d",
174                                         constraint.start_time.tm_mday,
175                                         constraint.start_time.tm_mon + 1,
176                                         constraint.start_time.tm_year + 109,
177                                         constraint.start_time.tm_hour,
178                                         constraint.start_time.tm_min,
179                                         constraint.end_time.tm_mday,
180                                         constraint.end_time.tm_mon + 1,
181                                         constraint.end_time.tm_year + 109,
182                                         constraint.end_time.tm_hour,
183                                         constraint.end_time.tm_min);
184                         }
185
186                         if (constraint.const_type.is_interval) {
187                                 ug_debug("DRM_INTERVAL\n");
188                                 snprintf(ugd->ug_ListPlay.ug_DrmInfo.validity, sizeof(ugd->ug_ListPlay.ug_DrmInfo.validity),
189                                         "until %d.%d.%d %d:%d",
190                                         constraint.interval_time.tm_mon,
191                                         constraint.interval_time.tm_mday,
192                                         constraint.interval_time.tm_year,
193                                         constraint.interval_time.tm_hour,
194                                         constraint.interval_time.tm_min);
195                         }
196
197                         if (constraint.const_type.is_timedcount) {
198                                 int count = constraint.timed_remaining_count;
199                                 int time = constraint.timed_count_timer;
200                                 snprintf(ugd->ug_ListPlay.ug_DrmInfo.validity, sizeof(ugd->ug_ListPlay.ug_DrmInfo.validity),
201                                          "%d left (%d sec)", count, time);
202                                 ug_debug("DRM_TIMED_COUNT [%d]\n", count);
203                                 if (count == 1)
204                                 {
205                                         snprintf(left_ro_message, sizeof(left_ro_message),
206                                                  "You can play \"%s\" just one more time", title);
207                                         ugd->ug_ListPlay.ug_bDrmContentCanPlay = TRUE;
208                                 }
209                                 else if (count == 0)
210                                 {
211                                         snprintf(left_ro_message, sizeof(left_ro_message),
212                                                  "You can't play \"%s\" anymore", title);
213                                 }
214                         }
215
216                         if (constraint.const_type.is_accumulated) {
217                                 int sec = constraint.accumulated_remaining_seconds;
218                                 int ndays = sec / ACCUMULATED_DATE;
219                                 ug_debug("DRM_ACCUMULATED [%d]\n", ndays);
220                                 snprintf(ugd->ug_ListPlay.ug_DrmInfo.validity, sizeof(ugd->ug_ListPlay.ug_DrmInfo.validity),
221                                          "%" UG_TIME_FORMAT " left", UG_TIME_ARGS(ndays));
222
223                                 if (ndays < ACCUMULATED_DATE)
224                                 {
225                                         snprintf(left_ro_message, sizeof(left_ro_message),
226                                                  "You can play %s just one day", title);
227
228                                         ugd->ug_ListPlay.ug_bDrmContentCanPlay = TRUE;
229                                 }
230                         }
231
232                         if (constraint.const_type.is_individual) {
233                                 ug_debug("DRM_INDIVISUAL_ID [%s]", constraint.individual_id);
234                         }
235
236                         if (constraint.const_type.is_system) {
237                                 ug_debug("DRM_SYSTEM [ID:%s, type:%d]", constraint.system_id, constraint.system_identity_type);
238                         }
239                 }
240         } else {
241                 ug_debug("have no valid ro\n");
242                 snprintf(left_ro_message, sizeof(left_ro_message), "No valid RO for <br>\"%s\"", title);
243                 ro_valid = false;
244                 expired = true;
245         }
246
247
248         UG_TRACE_END;
249
250         return true;
251 }
252
253 /******************************
254 ** Prototype    : __mf_ug_list_play_check_drm_forward
255 ** Description  : Samsung
256 ** Input        : void *data
257 **                char *path
258 ** Output       : None
259 ** Return Value :
260 ** Calls        :
261 ** Called By    :
262 **
263 **  History        :
264 **  1.Date         : 2010/12/10
265 **    Author       : Samsung
266 **    Modification : Created function
267 **
268 ******************************/
269 static drm_file_type_e __drm_get_file_type(void *path)
270 {
271         drm_file_type_e type = DRM_TYPE_UNDEFINED;
272         drm_result_e res = -1;
273
274         res = drm_get_file_type(path, &type);
275         if (res == DRM_RETURN_SUCCESS) {
276                 return type;
277         } else {
278                 return DRM_TYPE_UNDEFINED;
279         }
280 }
281 static bool __mf_ug_list_play_check_drm_forward(void *data, char *path)
282 {
283         UG_TRACE_BEGIN;
284         ugData *ugd = (ugData *)data;
285         drm_file_type_e type = __drm_get_file_type(path);
286
287         if (type == DRM_TYPE_OMA_V1 || type == DRM_TYPE_OMA_V2) {
288
289                 drm_file_info_s info;
290                 memset(&info, 0x0, sizeof(drm_file_info_s));
291                 int ret = drm_get_file_info(path, &info);
292                 if (ret == DRM_RETURN_SUCCESS) {
293                         if (info.oma_info.method == DRM_METHOD_TYPE_FORWARD_LOCK) {
294                                 ugd->ug_ListPlay.ug_DrmInfo.forward = true;
295                                 return TRUE;
296                         }
297                 }
298                 ugd->ug_ListPlay.ug_DrmInfo.forward = false;
299                 return false;
300         } else if (type == DRM_TYPE_PLAYREADY) {
301                 ug_debug("playready drm file");
302                 ugd->ug_ListPlay.ug_DrmInfo.forward = true;
303         } else {
304                 ug_debug("Not supported drm type");
305                 UG_TRACE_END;
306                 return false;
307         }
308         UG_TRACE_END;
309         return true;
310 }
311
312 /******************************
313 ** Prototype    : mf_ug_list_play_update_item_icon
314 ** Description  :
315 ** Input        : ugListItemData *data
316 **                int state
317 ** Output       : None
318 ** Return Value :
319 ** Calls        :
320 ** Called By    :
321 **
322 **  History        :
323 **  1.Date         : 2010/12/10
324 **    Author       : Samsung
325 **    Modification : Created function
326 **
327 ******************************/
328 static void __mf_ug_list_play_icon_hide(ugListItemData *itemData)
329 {
330         ug_mf_retm_if(itemData == NULL, "itemData is NULL");
331         ug_mf_retm_if(itemData->ug_pItem == NULL, "itemData->ug_pItem is NULL");
332
333         Evas_Object *btn = elm_object_item_part_content_unset(itemData->ug_pItem, "elm.icon.3");
334         evas_object_hide(btn);
335         UG_SAFE_FREE_OBJ(btn);
336         itemData->ug_pPlaybtn = NULL;
337
338 }
339 void mf_ug_list_disable_play_itc(void *data, bool disable)
340 {
341         UG_TRACE_BEGIN;
342
343         ugData *ugd = (ugData *)data;
344         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
345
346         Elm_Object_Item *gl_item = NULL;
347         ugListItemData *itemData = NULL;
348         Evas_Object *pGenlist = NULL;
349
350         if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL || strlen(ugd->ug_ListPlay.ug_pPlayFilePath) == 0) {
351
352                 UG_TRACE_END;
353                 return;
354         }
355         pGenlist = ugd->ug_MainWindow.ug_pContent;
356
357         gl_item = elm_genlist_first_item_get(pGenlist);
358         while (gl_item) {
359                 itemData = elm_object_item_data_get(gl_item);
360                 if (itemData && itemData->ug_pItemName) {
361                         if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) == 0) {
362                                 if (disable) {
363                                         UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath);
364                                         elm_genlist_item_fields_update(itemData->ug_pItem, "elm.icon.3", ELM_GENLIST_ITEM_FIELD_CONTENT);
365                                         //elm_genlist_item_item_class_update(itemData->ug_pItem, &ugd->ug_Status.ug_noplayitc);
366                                 } else {
367                                         elm_genlist_item_fields_update(itemData->ug_pItem, "elm.icon.3", ELM_GENLIST_ITEM_FIELD_CONTENT);
368                                 }
369                                 UG_TRACE_END;
370                                 return;
371                         }
372                 }
373                 gl_item = elm_genlist_item_next_get(gl_item);
374         }
375
376         ug_debug("mf_ug_list_play_update_item_icon failed");
377         UG_TRACE_END;
378 }
379
380
381 void mf_ug_list_paly_hide_play_icon(void *data)
382 {
383         UG_TRACE_BEGIN;
384
385         ugData *ugd = (ugData *)data;
386         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
387
388         Elm_Object_Item *gl_item = NULL;
389         ugListItemData *itemData = NULL;
390         Evas_Object *pGenlist = NULL;
391
392         if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL || strlen(ugd->ug_ListPlay.ug_pPlayFilePath) == 0) {
393
394                 UG_TRACE_END;
395                 return;
396         }
397         pGenlist = ugd->ug_MainWindow.ug_pContent;
398
399         gl_item = elm_genlist_first_item_get(pGenlist);
400         while (gl_item) {
401                 itemData = elm_object_item_data_get(gl_item);
402                 if (itemData && itemData->ug_pItemName) {
403                         if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) == 0) {
404                                 __mf_ug_list_play_icon_hide(itemData);
405                                 UG_TRACE_END;
406                                 return;
407                         }
408                 }
409                 gl_item = elm_genlist_item_next_get(gl_item);
410         }
411
412         ug_debug("mf_ug_list_play_update_item_icon failed");
413         UG_TRACE_END;
414 }
415 void mf_ug_list_play_update_play_icon(ugListItemData *itemData)
416 {
417         ug_mf_retm_if(itemData == NULL, "itemData is NULL");
418         ugData *ugd = (ugData *)itemData->ug_pData;
419         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
420         Evas_Object *btn = itemData->ug_pPlaybtn;
421         Evas_Object *music_icon = elm_object_part_content_get(btn, "icon");
422         const char *play_icon = NULL;
423         const char *pause_icon = NULL;
424         if (ugd->ug_ListPlay.ug_pPlayFilePath) {
425                 if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) == 0) {
426                         if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PLAYING) {
427                                 pause_icon = strdup(UG_ICON_MUSIC_PAUSE_WHITE);
428                                 elm_image_file_set(music_icon, pause_icon, NULL);
429                         } else if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PAUSED) {
430                                 play_icon = strdup(UG_ICON_MUSIC_PLAY_WHITE);
431                                 elm_image_file_set(music_icon, play_icon, NULL);
432                         } else {
433                                 play_icon = strdup(UG_ICON_MUSIC_PLAY_WHITE);
434                                 elm_image_file_set(music_icon, play_icon, NULL);
435                         }
436                 } else {
437                         play_icon = strdup(UG_ICON_MUSIC_PLAY_WHITE);
438                         elm_image_file_set(music_icon, play_icon, NULL);
439                 }
440         } else {
441                 play_icon = strdup(UG_ICON_MUSIC_PLAY_WHITE);
442                 elm_image_file_set(music_icon, play_icon, NULL);
443         }
444
445 }
446
447 void mf_ug_list_play_update_item_icon(void *data)
448 {
449         UG_TRACE_BEGIN;
450
451         ugData *ugd = (ugData *)data;
452         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
453
454         Elm_Object_Item *gl_item = NULL;
455         ugListItemData *itemData = NULL;
456         Evas_Object *pGenlist = NULL;
457
458         if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL || strlen(ugd->ug_ListPlay.ug_pPlayFilePath) == 0) {
459
460                 UG_TRACE_END;
461                 return;
462         }
463         pGenlist = ugd->ug_MainWindow.ug_pContent;
464
465         gl_item = elm_genlist_first_item_get(pGenlist);
466         while (gl_item) {
467                 itemData = elm_object_item_data_get(gl_item);
468                 if (itemData && itemData->ug_pItemName) {
469                         if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) == 0) {
470                                 elm_genlist_item_fields_update(itemData->ug_pItem, "elm.icon.3", ELM_GENLIST_ITEM_FIELD_CONTENT);
471                                 //mf_ug_list_play_update_play_icon(itemData);
472                                 UG_TRACE_END;
473                                 return;
474                         }
475                 }
476                 gl_item = elm_genlist_item_next_get(gl_item);
477         }
478
479         ug_debug("mf_ug_list_play_update_item_icon failed");
480         UG_TRACE_END;
481 }
482
483
484 /******************************
485 ** Prototype    : __mf_ug_list_play_set_play_start_status
486 ** Description  :
487 ** Input        : ugListItemData *data
488 ** Output       : None
489 ** Return Value :
490 ** Calls        :
491 ** Called By    :
492 **
493 **  History        :
494 **  1.Date         : 2010/12/10
495 **    Author       : Samsung
496 **    Modification : Created function
497 **
498 ******************************/
499 static void __mf_ug_list_play_set_play_start_status(void *data, char *path)
500 {
501         UG_TRACE_BEGIN;
502         ugData *ugd = (ugData *)data;
503         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
504
505         ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_PLAYING;
506         UG_TRACE_END;
507 }
508
509 /******************************
510 ** Prototype    : __mf_ug_list_play_set_play_resume_status
511 ** Description  :
512 ** Input        : ugListItemData *data
513 ** Output       : None
514 ** Return Value :
515 ** Calls        :
516 ** Called By    :
517 **
518 **  History        :
519 **  1.Date         : 2010/12/10
520 **    Author       : Samsung
521 **    Modification : Created function
522 **
523 ******************************/
524 static void __mf_ug_list_play_set_play_resume_status(void *data)
525 {
526         UG_TRACE_BEGIN;
527         ugData *ugd = (ugData *)data;
528         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
529
530         ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_PLAYING;
531         UG_TRACE_END;
532 }
533
534 /******************************
535 ** Prototype    : __mf_ug_list_play_set_play_pause_status
536 ** Description  :
537 ** Input        : ugListItemData *data
538 ** Output       : None
539 ** Return Value :
540 ** Calls        :
541 ** Called By    :
542 **
543 **  History        :
544 **  1.Date         : 2010/12/10
545 **    Author       : Samsung
546 **    Modification : Created function
547 **
548 ******************************/
549 static void __mf_ug_list_play_set_play_pause_status(ugData *data)
550 {
551         UG_TRACE_BEGIN;
552         ugData *ugd = (ugData *)data;
553         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
554
555         ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_PAUSED;
556         UG_TRACE_END;
557 }
558
559 /******************************
560 ** Prototype    : _mp_player_mgr_create
561 ** Description  :
562 ** Input        : void *data
563 **                const gchar *path
564 ** Output       : None
565 ** Return Value :
566 ** Calls        :
567 ** Called By    :
568 **
569 **  History        :
570 **  1.Date         : 2010/12/10
571 **    Author       : Samsung
572 **    Modification : Created function
573 **
574 ******************************/
575 static void __mf_player_mgr_callback_pipe_handler(void *data, void *buffer, unsigned int nbyte)
576 {
577         UG_TRACE_BEGIN;
578         mf_player_cb_extra_data *extra_data = buffer;
579         ug_mf_retm_if(extra_data == NULL, "NULL");
580         ug_mf_retm_if(g_player_cbs == NULL, "NULL");
581
582         switch (extra_data->cb_type) {
583         /*note: start callback and paused callback for player have been removed*/
584         /*case MF_PLAYER_CB_TYPE_STARTED:
585                 if (g_player_cbs->started_cb)
586                         g_player_cbs->started_cb(g_player_cbs->user_data[MF_PLAYER_CB_TYPE_STARTED]);
587                 break;
588
589         case MF_PLAYER_CB_TYPE_PAUSED:
590                 if (g_player_cbs->paused_cb)
591                         g_player_cbs->paused_cb(g_player_cbs->user_data[MF_PLAYER_CB_TYPE_PAUSED]);
592                 break;*/
593
594         case MF_PLAYER_CB_TYPE_COMPLETED:
595                 if (g_player_cbs->completed_cb)
596                         g_player_cbs->completed_cb(g_player_cbs->user_data[MF_PLAYER_CB_TYPE_COMPLETED]);
597                 break;
598
599         case MF_PLAYER_CB_TYPE_INTURRUPTED:
600                 if (g_player_cbs->interrupted_cb)
601                         g_player_cbs->interrupted_cb(extra_data->param.interrupted_code, g_player_cbs->user_data[MF_PLAYER_CB_TYPE_INTURRUPTED]);
602                 break;
603
604         case MF_PLAYER_CB_TYPE_ERROR:
605                 if (g_player_cbs->error_cb)
606                         g_player_cbs->error_cb(extra_data->param.error_code, g_player_cbs->user_data[MF_PLAYER_CB_TYPE_ERROR]);
607                 break;
608
609         case MF_PLAYER_CB_TYPE_BUFFERING:
610                 if (g_player_cbs->buffering_cb)
611                         g_player_cbs->buffering_cb(extra_data->param.percent ,g_player_cbs->user_data[MF_PLAYER_CB_TYPE_BUFFERING]);
612                 break;
613         case MF_PLAYER_CB_TYPE_PREPARE:
614                 if (g_player_cbs->prepare_cb)
615                         g_player_cbs->prepare_cb(g_player_cbs->user_data[MF_PLAYER_CB_TYPE_PREPARE]);
616                 break;
617
618         default:
619                 ug_debug("Not suppoted callback type [%d]", extra_data->cb_type);
620         }
621 }
622
623
624 static void
625 __mf_ug_list_play_mgr_completed_cb(void *userdata)
626 {
627         UG_TRACE_BEGIN;
628         MF_CHECK(g_player_pipe);
629
630         mf_player_cb_extra_data extra_data;
631         extra_data.cb_type = MF_PLAYER_CB_TYPE_COMPLETED;
632
633         ecore_pipe_write(g_player_pipe, &extra_data, sizeof(mf_player_cb_extra_data));
634 }
635
636 static void
637 __mf_ug_list_play_mgr_interrupted_cb(player_interrupted_code_e code, void *userdata)
638 {
639         UG_TRACE_BEGIN;
640         MF_CHECK(g_player_pipe);
641
642         mf_player_cb_extra_data extra_data;
643         extra_data.cb_type = MF_PLAYER_CB_TYPE_INTURRUPTED;
644         extra_data.param.interrupted_code = code;
645
646         ecore_pipe_write(g_player_pipe, &extra_data, sizeof(mf_player_cb_extra_data));
647 }
648
649
650 static void
651 __mf_ug_list_play_mgr_error_cb(int error_code, void *userdata)
652 {
653         UG_TRACE_BEGIN;
654         MF_CHECK(g_player_pipe);
655
656         mf_player_cb_extra_data extra_data;
657         extra_data.cb_type = MF_PLAYER_CB_TYPE_ERROR;
658         extra_data.param.error_code = error_code;
659
660         ecore_pipe_write(g_player_pipe, &extra_data, sizeof(mf_player_cb_extra_data));
661 }
662
663 static bool __mf_ug_list_play_create_player_mgr(void *data, const char *path)
664 {
665         UG_TRACE_BEGIN;
666         ugData *ugd = (ugData *)data;
667         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
668
669         int path_len = strlen(path);
670         char *g_err_name = NULL;
671         int ret = 0;
672
673         if (path_len > 0 && path_len < MYFILE_DIR_PATH_LEN_MAX) {
674                 if (ugd->ug_ListPlay.ug_Player == 0) {
675                         if (player_create(&ugd->ug_ListPlay.ug_Player) != PLAYER_ERROR_NONE) {
676                                 ug_debug("Error when __mf_ug_list_play_create_player_mgr\n");
677                                 UG_TRACE_END;
678                                 return false;
679                         }
680                         ug_debug("player is [%d]", ugd->ug_ListPlay.ug_Player);
681                         /*avsysaudiosink volume table setting */
682
683                         //ret = mm_player_set_attribute(ugd->ug_ListPlay.ug_Player, &g_err_name, "sound_volume_type", MM_SOUND_VOLUME_TYPE_MEDIA,
684                         //                            "profile_uri", path, strlen(path), NULL);
685
686                         ug_debug("path is [%s]", path);
687                         ret = player_set_uri(ugd->ug_ListPlay.ug_Player, path);
688                         //player_set_sound_type(ugd->ug_ListPlay.ug_Player, SOUND_TYPE_MEDIA);
689                         if (ret != PLAYER_ERROR_NONE) {
690                                 ug_debug(">>>>>>>>>>>>>g_err_name : %s\n", g_err_name);
691                                 UG_TRACE_END;
692                                 return false;
693                         }
694
695                         ret = player_set_sound_type(ugd->ug_ListPlay.ug_Player, SOUND_TYPE_MEDIA);
696                         if (ret != PLAYER_ERROR_NONE) {
697                                 ug_error("set sound type failed");
698                         } else {
699                                 ug_error("set sound type success");
700                         }
701
702                 } else {
703                         ug_debug("player handle is exist");
704                         UG_TRACE_END;
705                         return false;
706                 }
707         } else {
708                 ug_debug("the path_len is too long");
709                 UG_TRACE_END;
710                 return false;
711         }
712
713         UG_SAFE_FREE_CHAR(g_player_cbs);
714         if (g_player_pipe) {
715                 ecore_pipe_del(g_player_pipe);
716                 g_player_pipe = NULL;
717         }
718         g_player_cbs = calloc(1, sizeof(mf_player_cbs));
719         g_player_pipe = ecore_pipe_add(__mf_player_mgr_callback_pipe_handler, ugd);
720
721
722         player_set_completed_cb(ugd->ug_ListPlay.ug_Player, __mf_ug_list_play_mgr_completed_cb, NULL);
723         player_set_interrupted_cb(ugd->ug_ListPlay.ug_Player, __mf_ug_list_play_mgr_interrupted_cb, NULL);
724         player_set_error_cb(ugd->ug_ListPlay.ug_Player, __mf_ug_list_play_mgr_error_cb, NULL);
725         //player_set_buffering_cb(ugd->ug_ListPlay.ug_Player, _mp_player_mgr_buffering_cb, NULL);
726         return true;
727
728 }
729
730 /******************************
731 ** Prototype    : _mp_player_mgr_set_msg_callback
732 ** Description  :
733 ** Input        : MMMessageCallback cb
734 **                gpointer user_data
735 ** Output       : None
736 ** Return Value :
737 ** Calls        :
738 ** Called By    :
739 **
740 **  History        :
741 **  1.Date         : 2010/12/10
742 **    Author       : Samsung
743 **    Modification : Created function
744 **
745 ******************************/
746 static void __mf_ug_list_play_start(void *data)
747 {
748         UG_TRACE_BEGIN;
749         ugListItemData *itemData = (ugListItemData *)data;
750         ug_mf_retm_if(itemData == NULL, "itemData is NULL");
751         ugData *ugd = itemData->ug_pData;
752         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
753         int error_code = -1;
754         player_state_e state = PLAYER_STATE_NONE;
755
756         error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state);
757         ug_debug("state is [%d]", state);
758         if (error_code == 0 && state == PLAYER_STATE_PLAYING) {
759                 if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL) {
760                         ugd->ug_ListPlay.ug_pPlayFilePath = g_strdup(itemData->ug_pItemName->str);
761                 }
762                 __mf_ug_list_play_set_play_start_status(ugd, itemData->ug_pItemName->str);
763         } else if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PAUSED) {
764                 if (ugd->ug_ListPlay.ug_pPlayFilePath == NULL) {
765                         ugd->ug_ListPlay.ug_pPlayFilePath = g_strdup(itemData->ug_pItemName->str);
766                 }
767                 __mf_ug_list_play_set_play_resume_status(ugd);
768         }
769
770         UG_TRACE_END;
771 }
772
773 static void __mf_ug_list_play_pauset(void *data)
774 {
775         UG_TRACE_BEGIN;
776
777         ugData *ugd = (ugData *)data;
778         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
779
780         __mf_ug_list_play_set_play_pause_status(ugd);
781         UG_TRACE_END;
782 }
783
784 static void __mf_ug_list_play_complete_cb(void *data)
785 {
786         UG_TRACE_BEGIN;
787
788         ugData *ugd = (ugData *)data;
789         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
790
791         mf_ug_list_play_destory_playing_file(ugd);
792         mf_ug_list_disable_play_itc(ugd, true);
793         //mf_ug_list_play_update_item_icon(ugd);
794         UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath);
795         UG_TRACE_END;
796 }
797
798 static void __mf_ug_list_play_interrupt_cb(player_interrupted_code_e code, void *data)
799 {
800         UG_TRACE_BEGIN;
801         ugListItemData *itemData = data;
802         ug_mf_retm_if(itemData == NULL, "itemData is NULL");
803
804         ugData *ugd = (ugData *)itemData->ug_pData;
805         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
806         switch (code) {
807         case PLAYER_INTERRUPTED_BY_MEDIA:
808                 ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_MEDIA");
809                 break;
810         case PLAYER_INTERRUPTED_BY_CALL:
811                 ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_CALL_START");
812                 break;
813         case PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT:
814                 ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_RESOURCE_CONFLICT");
815                 break;
816         case PLAYER_INTERRUPTED_BY_ALARM:
817                 ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_ALARM_START");
818                 break;
819         case PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG:
820                 ug_debug("Interrupt :: PLAYER_INTERRUPTED_BY_EARJACK_UNPLUG");
821                 break;
822         case PLAYER_INTERRUPTED_COMPLETED:
823                 ug_debug("PLAYER_INTERRUPTED_COMPLETED");
824                 /* ready to resume */
825                 ug_debug("ugd->ug_ListPlay.ug_iPlayState is [%d]", ugd->ug_ListPlay.ug_iPlayState);
826                 if (ugd->ug_ListPlay.ug_iPlayState == PLAY_STATE_PAUSED) {
827                         ug_debug();
828                         __mf_ug_list_play_control_cb(itemData);
829                 }
830                 return;
831         default:
832                 break;
833         }
834         __mf_ug_list_play_set_play_pause_status(ugd);
835         mf_ug_list_play_update_item_icon(ugd);
836         UG_TRACE_END;
837
838 }
839
840 static void
841 __mf_list_play_control_prepare_cb(void *userdata)
842 {
843         UG_TRACE_BEGIN;
844
845         __mf_ug_list_play_play_current_file(userdata);
846 }
847
848
849 /******************************
850 ** Prototype    : _mp_player_mgr_realize
851 ** Description  :
852 ** Input        : ugListItemData *data
853 ** Output       : None
854 ** Return Value :
855 ** Calls        :
856 ** Called By    :
857 **
858 **  History        :
859 **  1.Date         : 2010/12/10
860 **    Author       : Samsung
861 **    Modification : Created function
862 **
863 ******************************/
864 static void
865 __mf_ug_list_play_prepare_cb(void *userdata)
866 {
867         UG_TRACE_BEGIN;
868         MF_CHECK(g_player_pipe);
869
870         mf_player_cb_extra_data extra_data;
871         memset(&extra_data, 0, sizeof(mf_player_cb_extra_data));
872         extra_data.cb_type = MF_PLAYER_CB_TYPE_PREPARE;
873
874         ecore_pipe_write(g_player_pipe, &extra_data, sizeof(mf_player_cb_extra_data));
875 }
876
877 static bool __mf_ug_list_play_realize_player_mgr(void *data)
878 {
879         UG_TRACE_BEGIN;
880         ugData *ugd = (ugData *)data;
881
882         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
883
884         int error_code = 0;
885         player_state_e state = PLAYER_STATE_NONE;
886
887         if (ugd->ug_ListPlay.ug_Player != 0) {
888                 error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state);
889                 ug_debug("state is [%d]", state);
890
891                 if (0 == error_code && PLAYER_STATE_IDLE == state) {
892                         ug_debug("player_prepare_async");
893                         if (player_prepare_async(ugd->ug_ListPlay.ug_Player, __mf_ug_list_play_prepare_cb, ugd) != PLAYER_ERROR_NONE)
894                         {
895                                 ug_debug("Error when mp_player_mgr_realize\n");
896                                 UG_TRACE_END;
897                                 return FALSE;
898                         } else {
899                                 return true;
900                         }
901                         //ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_READY;
902
903                 } else {
904                         UG_TRACE_END;
905                         return false;
906                 }
907         }
908         UG_TRACE_END;
909
910         return false;
911 }
912
913
914 /******************************
915 ** Prototype    : __mf_ug_list_play_ready_new_file_play
916 ** Description  : Samsung
917 ** Input        : void *data
918 **                bool drm_check_flag
919 ** Output       : None
920 ** Return Value :
921 ** Calls        :
922 ** Called By    :
923 **
924 **  History        :
925 **  1.Date         : 2010/12/10
926 **    Author       : Samsung
927 **    Modification : Created function
928 **
929 ******************************/
930 /*void mf_player_mgr_set_started_cb(player_started_cb  callback, void *user_data)
931 {
932         MF_CHECK(g_player_cbs);
933
934         g_player_cbs->started_cb = callback;
935         g_player_cbs->user_data[MF_PLAYER_CB_TYPE_STARTED] = user_data;
936 }
937
938 void mf_player_mgr_set_paused_cb(player_paused_cb  callback, void *user_data)
939 {
940         MF_CHECK(g_player_cbs);
941
942         g_player_cbs->paused_cb = callback;
943         g_player_cbs->user_data[MF_PLAYER_CB_TYPE_PAUSED] = user_data;
944 }*/
945
946 void mf_player_mgr_set_completed_cb(player_completed_cb  callback, void *user_data)
947 {
948
949         MF_CHECK(g_player_cbs);
950
951         g_player_cbs->completed_cb = callback;
952         g_player_cbs->user_data[MF_PLAYER_CB_TYPE_COMPLETED] = user_data;
953 }
954
955 void mf_player_mgr_set_interrupted_cb(player_interrupted_cb  callback, void *user_data)
956 {
957
958         MF_CHECK(g_player_cbs);
959
960         g_player_cbs->interrupted_cb = callback;
961         g_player_cbs->user_data[MF_PLAYER_CB_TYPE_INTURRUPTED] = user_data;
962 }
963
964 void mf_player_mgr_set_error_cb(player_error_cb  callback, void *user_data)
965 {
966
967         MF_CHECK(g_player_cbs);
968
969         g_player_cbs->error_cb = callback;
970         g_player_cbs->user_data[MF_PLAYER_CB_TYPE_ERROR] = user_data;
971 }
972
973 void mf_player_mgr_set_buffering_cb(player_buffering_cb  callback, void *user_data)
974 {
975         MF_CHECK(g_player_cbs);
976
977         g_player_cbs->buffering_cb = callback;
978         g_player_cbs->user_data[MF_PLAYER_CB_TYPE_BUFFERING] = user_data;
979 }
980
981 void mf_player_mgr_set_prepare_cb(player_prepared_cb callback, void *user_data)
982 {
983         MF_CHECK(g_player_cbs);
984
985         g_player_cbs->prepare_cb = callback;
986         g_player_cbs->user_data[MF_PLAYER_CB_TYPE_PREPARE] = user_data;
987 }
988
989 static Eina_Bool __mf_play_control_error(void *data)
990 {
991         UG_TRACE_BEGIN;
992         ugData *ugd = (ugData *)data;
993         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
994
995         mf_ug_list_play_destory_playing_file(ugd);
996         mf_ug_list_disable_play_itc(ugd, true);
997         UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath);
998         ugd->ug_ListPlay.playing_err_idler = NULL;
999         return EINA_FALSE;
1000 }
1001
1002 static void __mf_play_control_error_cb(int error_code, void *userdata)
1003 {
1004         UG_TRACE_BEGIN;
1005         ugData *ugd = (ugData *)userdata;
1006         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
1007
1008         switch (error_code)
1009         {
1010         case PLAYER_ERROR_OUT_OF_MEMORY:
1011                 ug_error("PLAYER_ERROR_OUT_OF_MEMORY");
1012                 break;
1013         case PLAYER_ERROR_INVALID_PARAMETER:
1014                 ug_error("PLAYER_ERROR_INVALID_PARAMETER");
1015                 //mp_widget_text_popup(ad, GET_STR("IDS_MUSIC_POP_UNABLE_TO_PLAY_ERROR_OCCURRED"));
1016                 break;
1017         case PLAYER_ERROR_NOT_SUPPORTED_FILE:   //can receive error msg while playing.
1018                 ug_error("receive MM_ERROR_PLAYER_CODEC_NOT_FOUND\n");
1019                 ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNSUPPORT_FILE_TYPE, NULL, NULL, NULL, NULL, NULL);
1020                 break;
1021         case PLAYER_ERROR_CONNECTION_FAILED:
1022                 ug_error("MM_ERROR_PLAYER_STREAMING_CONNECTION_FAIL");
1023
1024                 ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_CONNECT_FAILED, NULL, NULL, NULL, NULL, NULL);
1025                 break;
1026         default:
1027                 ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNSUPPORT_FILE_TYPE, NULL, NULL, NULL, NULL, NULL);
1028                 ug_error("error_code: %d", error_code);
1029         }
1030
1031         if(!ugd->ug_ListPlay.playing_err_idler) {
1032                 ugd->ug_ListPlay.playing_err_idler = ecore_idler_add(__mf_play_control_error, ugd);
1033         }
1034 }
1035
1036
1037 static bool __mf_ug_list_play_ready_new_file_play(void *data, bool drm_check_flag)
1038 {
1039
1040         UG_TRACE_BEGIN;
1041         ugListItemData *itemData = data;
1042         ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL");
1043
1044         ugData *ugd = (ugData *)itemData->ug_pData;
1045         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1046
1047         char *path = strdup(itemData->ug_pItemName->str);
1048
1049         /*check if file is exist */
1050         if (path != NULL) {
1051                 if (!ecore_file_exists(path)) {
1052                         ug_debug("Error file %s is not exist\n", path);
1053                         free(path);
1054                         path = NULL;
1055                         UG_TRACE_END;
1056                         return false;
1057                 }
1058                 /*/check if file is drm file */
1059                 if (mf_ug_file_attr_is_drm_file(path) == 0) {
1060                         if (!__mf_ug_list_play_check_drm_left_ro(ugd, path)) {
1061                                 free(path);
1062                                 path = NULL;
1063                                 UG_TRACE_END;
1064                                 return false;
1065                         }
1066
1067                         if (!__mf_ug_list_play_check_drm_forward(ugd, path)) {
1068                                 free(path);
1069                                 path = NULL;
1070                                 UG_TRACE_END;
1071                                 return false;
1072                         }
1073
1074                         ugd->ug_ListPlay.ug_bDrmconsumption = true;
1075                 } else {
1076                         ugd->ug_ListPlay.ug_bDrmconsumption = true;
1077                 }
1078
1079                 if (!__mf_ug_list_play_create_player_mgr(ugd, path)) {
1080                         free(path);
1081                         path = NULL;
1082                         ug_error("ERROR HERE !!!!!!!");
1083                         ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_ERROR_OCCUR, NULL, NULL, NULL, NULL, NULL);
1084                         UG_TRACE_END;
1085                         return false;
1086                 }
1087
1088                 //mf_player_mgr_set_started_cb(__mf_ug_list_play_start_cb, itemData);
1089                 //mf_player_mgr_set_paused_cb(__mf_ug_list_play_pauset_cb, ugd);
1090                 mf_player_mgr_set_completed_cb(__mf_ug_list_play_complete_cb, ugd);
1091                 mf_player_mgr_set_interrupted_cb(__mf_ug_list_play_interrupt_cb, ugd);
1092                 mf_player_mgr_set_prepare_cb(__mf_list_play_control_prepare_cb, itemData);
1093                 mf_player_mgr_set_error_cb(__mf_play_control_error_cb, ugd);
1094                 //mf_player_mgr_set_buffering_cb(_mp_play_control_buffering_cb, ad);
1095
1096                 if (!__mf_ug_list_play_realize_player_mgr(ugd)) {
1097                         free(path);
1098                         path = NULL;
1099                         ug_error("ERROR HERE !!!!!!!");
1100                         ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_ERROR_OCCUR, NULL, NULL, NULL, NULL, NULL);
1101                         UG_TRACE_END;
1102                         return false;
1103                 }
1104                 free(path);
1105                 path = NULL;
1106                 UG_TRACE_END;
1107                 return true;
1108         } else {
1109                 return false;
1110         }
1111
1112 }
1113
1114
1115 /******************************
1116 ** Prototype    : _mp_player_mgr_play
1117 ** Description  :
1118 ** Input        : ugListItemData *data
1119 ** Output       : None
1120 ** Return Value :
1121 ** Calls        :
1122 ** Called By    :
1123 **
1124 **  History        :
1125 **  1.Date         : 2010/12/10
1126 **    Author       : Samsung
1127 **    Modification : Created function
1128 **
1129 ******************************/
1130 static bool __mf_ug_list_play_play(void *data)
1131 {
1132
1133         UG_TRACE_BEGIN;
1134         ugListItemData *itemData = data;
1135         ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL");
1136         ugData *ugd = itemData->ug_pData;
1137         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1138
1139         int err = 0;
1140         int error_code = 0;
1141         player_state_e state = PLAYER_STATE_NONE;
1142
1143         if (ugd->ug_ListPlay.ug_Player != 0) {
1144                 error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state);
1145                 ug_debug("state is [%d]", state);
1146
1147                 if (0 == error_code && PLAYER_STATE_READY == state) {
1148                         err = player_start(ugd->ug_ListPlay.ug_Player);
1149                         if (err != PLAYER_ERROR_NONE) {
1150
1151                                 if (err == PLAYER_ERROR_SOUND_POLICY)
1152                                 {
1153                                         ug_error("PLAYER_ERROR_SOUND_POLICY error");
1154                                         ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_DURING_CALL, NULL,
1155                                                            NULL, NULL, NULL, NULL);
1156                                 }
1157                                 else
1158                                 {
1159                                         ug_error("error is [%d]", err);
1160                                         ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_ERROR_OCCURRED, NULL,
1161                                                            NULL, NULL, NULL, NULL);
1162                                 }
1163                                 ug_error("Error when _mp_player_mgr_play. err[%x]\n", err);
1164                                 UG_TRACE_END;
1165                                 return false;
1166                         } else {
1167                                 __mf_ug_list_play_start(itemData);
1168                                 mf_ug_list_disable_play_itc(ugd, false);
1169                                 UG_TRACE_END;
1170                                 return true;
1171                         }
1172                 } else {
1173                         UG_TRACE_END;
1174                         return false;
1175                 }
1176         } else {
1177                 UG_TRACE_END;
1178                 return false;
1179         }
1180 }
1181
1182 /******************************
1183 ** Prototype    : __mf_ug_list_play_stop
1184 ** Description  :
1185 ** Input        : void *data
1186 ** Output       : None
1187 ** Return Value :
1188 ** Calls        :
1189 ** Called By    :
1190 **
1191 **  History        :
1192 **  1.Date         : 2010/12/10
1193 **    Author       : Samsung
1194 **    Modification : Created function
1195 **
1196 ******************************/
1197 static bool __mf_ug_list_play_stop(ugData *data)
1198 {
1199         UG_TRACE_BEGIN;
1200         ugData *ugd = (ugData *)data;
1201         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1202
1203         player_state_e state = PLAYER_STATE_NONE;
1204         int error_code = 0;
1205
1206         if (ugd->ug_ListPlay.ug_Player != 0) {
1207                 error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state);
1208                 ug_debug("state is [%d]", state);
1209
1210                 if (0 == error_code && (PLAYER_STATE_PLAYING == state || PLAYER_STATE_PAUSED == state)) {
1211                         if (player_stop(ugd->ug_ListPlay.ug_Player) != 0) {
1212                                 ug_debug("Error when __mf_ug_list_play_stop\n");
1213                                 UG_TRACE_END;
1214                                 return false;
1215                         } else {
1216
1217                                 ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_STOP;
1218                                 ugd->ug_ListPlay.ug_bDrmContentCanPlay = false;
1219                                 UG_TRACE_END;
1220                                 return true;
1221                         }
1222
1223                 } else {
1224                         UG_TRACE_END;
1225                         return false;
1226                 }
1227         }
1228         UG_TRACE_END;
1229         return false;
1230 }
1231
1232 /******************************
1233 ** Prototype    : __mf_ug_list_play_unrealize
1234 ** Description  :
1235 ** Input        : void *data
1236 ** Output       : None
1237 ** Return Value :
1238 ** Calls        :
1239 ** Called By    :
1240 **
1241 **  History        :
1242 **  1.Date         : 2010/12/10
1243 **    Author       : Samsung
1244 **    Modification : Created function
1245 **
1246 ******************************/
1247 static bool __mf_ug_list_play_unrealize(ugData *data)
1248 {
1249
1250         UG_TRACE_BEGIN;
1251         ugData *ugd = (ugData *)data;
1252         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1253
1254         if (ugd->ug_ListPlay.ug_Player != 0) {
1255                 /*/unrealize can be invoked at any state */
1256                 if (player_unprepare(ugd->ug_ListPlay.ug_Player) != 0) {
1257                         ug_debug("Error when __mf_ug_list_play_unrealize\n");
1258                         UG_TRACE_END;
1259                         return false;
1260                 } else {
1261                         UG_TRACE_END;
1262                         return true;
1263                 }
1264         }
1265         UG_TRACE_END;
1266         return false;
1267 }
1268
1269 /******************************
1270 ** Prototype    : __mf_ug_list_play_destory
1271 ** Description  :
1272 ** Input        : void *data
1273 ** Output       : None
1274 ** Return Value :
1275 ** Calls        :
1276 ** Called By    :
1277 **
1278 **  History        :
1279 **  1.Date         : 2010/12/10
1280 **    Author       : Samsung
1281 **    Modification : Created function
1282 **
1283 ******************************/
1284 static bool __mf_ug_list_play_destory(ugData *data)
1285 {
1286         UG_TRACE_BEGIN;
1287         ugData *ugd = (ugData *)data;
1288         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1289
1290         if (ugd->ug_ListPlay.ug_Player != 0) {
1291                 /*/destroy can be invoked at any state */
1292                 if (player_destroy(ugd->ug_ListPlay.ug_Player) != 0) {
1293                         ug_debug("Error when __mf_ug_list_play_destory\n");
1294                         UG_TRACE_END;
1295                         return false;
1296                 } else {
1297                         ugd->ug_ListPlay.ug_Player = 0;
1298                         ugd->ug_ListPlay.ug_iPlayState = PLAY_STATE_INIT;
1299                         UG_TRACE_END;
1300                         return true;
1301                 }
1302         }
1303
1304         UG_SAFE_FREE_CHAR(g_player_cbs);
1305         if (g_player_pipe) {
1306                 ecore_pipe_del(g_player_pipe);
1307                 g_player_pipe = NULL;
1308         }
1309         UG_TRACE_END;
1310         return false;
1311 }
1312
1313 /******************************
1314 ** Prototype    : __mf_ug_list_play_play_current_file
1315 ** Description  : Samsung
1316 ** Input        : ugData *data
1317 ** Output       : None
1318 ** Return Value :
1319 ** Calls        :
1320 ** Called By    :
1321 **
1322 **  History        :
1323 **  1.Date         : 2010/12/10
1324 **    Author       : Samsung
1325 **    Modification : Created function
1326 **
1327 ******************************/
1328 static bool __mf_ug_list_play_play_current_file(void *data)
1329 {
1330
1331         UG_TRACE_BEGIN;
1332         ugListItemData *itemData = data;
1333         ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL");
1334         ugData *ugd = itemData->ug_pData;
1335         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1336
1337         int error_code = 0;
1338
1339         player_state_e state = PLAYER_STATE_NONE;
1340         error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state);
1341         ug_debug("state is [%d]", state);
1342         if (state != PLAYER_STATE_READY) {
1343                 UG_TRACE_END;
1344                 return false;
1345         }
1346         if (!__mf_ug_list_play_play(itemData)) {
1347                 mf_ug_list_play_destory_playing_file(ugd);
1348                 mf_ug_list_disable_play_itc(ugd, true);
1349                 UG_SAFE_FREE_CHAR(ugd->ug_ListPlay.ug_pPlayFilePath);
1350                 UG_TRACE_END;
1351                 return false;
1352         }
1353
1354         return true;
1355 }
1356
1357
1358 /******************************
1359 ** Prototype    : __mf_ug_list_play_resume
1360 ** Description  :
1361 ** Input        : ugListItemData *data
1362 ** Output       : None
1363 ** Return Value :
1364 ** Calls        :
1365 ** Called By    :
1366 **
1367 **  History        :
1368 **  1.Date         : 2010/12/10
1369 **    Author       : Samsung
1370 **    Modification : Created function
1371 **
1372 ******************************/
1373 static bool __mf_ug_list_play_resume(void *data)
1374 {
1375         UG_TRACE_BEGIN;
1376         ugData *ugd = (ugData *)data;
1377         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1378
1379         player_state_e state = PLAYER_STATE_NONE;
1380         int error_code = 0;
1381         int err = -1;
1382
1383         if (ugd->ug_ListPlay.ug_Player != 0) {
1384                 error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state);
1385                 ug_debug("state is [%d]", state);
1386
1387                 if (0 == error_code && PLAYER_STATE_PAUSED == state) {
1388                         err = player_start(ugd->ug_ListPlay.ug_Player);
1389
1390                         if (err != PLAYER_ERROR_NONE) {
1391
1392                                 if (err == PLAYER_ERROR_SOUND_POLICY)
1393                                 {
1394                                         ug_error("ERROR HERE !!!!!!!");
1395                                         ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_DURING_CALL, NULL,
1396                                                            NULL, NULL, NULL, NULL);
1397                                 }
1398                                 else
1399                                 {
1400                                         ug_error("ERROR HERE !!!!!!!");
1401                                         ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, MF_UG_LABEL_UNABLE_TO_PLAY_ERROR_OCCURRED, NULL,
1402                                                            NULL, NULL, NULL, NULL);
1403                                 }
1404                                 ug_error("Error when _mp_player_mgr_play. err[%x]\n", err);
1405                                 UG_TRACE_END;
1406                                 return false;
1407                         } else {
1408                                 __mf_ug_list_play_set_play_start_status(ugd, ugd->ug_ListPlay.ug_pPlayFilePath);
1409                                 mf_ug_list_disable_play_itc(ugd, false);
1410                                 UG_TRACE_END;
1411                                 return true;
1412                         }
1413                 } else {
1414                         UG_TRACE_END;
1415                         return false;
1416                 }
1417         }
1418         UG_TRACE_END;
1419         return false;
1420
1421 }
1422
1423
1424 /******************************
1425 ** Prototype    : __mf_ug_list_play_pause
1426 ** Description  :
1427 ** Input        : ugListItemData *data
1428 ** Output       : None
1429 ** Return Value :
1430 ** Calls        :
1431 ** Called By    :
1432 **
1433 **  History        :
1434 **  1.Date         : 2010/12/10
1435 **    Author       : Samsung
1436 **    Modification : Created function
1437 **
1438 ******************************/
1439 static bool __mf_ug_list_play_pause(void *data)
1440 {
1441         UG_TRACE_BEGIN;
1442         ugData *ugd = (ugData *)data;
1443         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1444
1445         int err = 0;
1446         player_state_e state = PLAYER_STATE_NONE;
1447         int error_code = 0;
1448
1449         if (ugd->ug_ListPlay.ug_Player) {
1450                 error_code = player_get_state(ugd->ug_ListPlay.ug_Player, &state);
1451                 ug_debug("state is [%d]", state);
1452
1453                 if (0 == error_code && PLAYER_STATE_PLAYING == state) {
1454                         err = player_pause(ugd->ug_ListPlay.ug_Player);
1455                         if (err != 0) {
1456                                 ug_debug("Error when _ug_player_mgr_pause. err[%x]\n", err);
1457                                 UG_TRACE_END;
1458                                 return false;
1459                         } else {
1460                                 UG_TRACE_END;
1461                                 return true;
1462                         }
1463                 } else {
1464                         UG_TRACE_END;
1465                         return false;
1466                 }
1467         }
1468         UG_TRACE_END;
1469         return false;
1470 }
1471
1472
1473 /******************************
1474 ** Prototype    : mp_play_control_cb
1475 ** Description  :
1476 ** Input        : ugListItemData *data
1477 **                int  state
1478 ** Output       : None
1479 ** Return Value :
1480 ** Calls        :
1481 ** Called By    :
1482 **
1483 **  History        :
1484 **  1.Date         : 2010/12/10
1485 **    Author       : Samsung
1486 **    Modification : Created function
1487 **
1488 ******************************/
1489 static void __mf_ug_list_play_control_cb(void *data)
1490 {
1491         UG_TRACE_BEGIN;
1492         ugListItemData *itemData = data;
1493         ug_mf_retm_if(itemData == NULL, "itemData is NULL");
1494
1495         ugData *ugd = (ugData *)itemData->ug_pData;
1496         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
1497
1498         int state = ugd->ug_ListPlay.ug_iPlayState;
1499
1500         if (state == PLAY_STATE_PLAYING) {
1501                 if(__mf_ug_list_play_pause(ugd)) {
1502                         __mf_ug_list_play_pauset(ugd);
1503                         mf_ug_list_disable_play_itc(ugd, false);
1504                 }
1505         } else {
1506                 if(__mf_ug_list_play_resume(ugd)) {
1507                         __mf_ug_list_play_start(itemData);
1508                 }
1509
1510         }
1511         UG_TRACE_END;
1512 }
1513
1514 static bool __mf_ug_list_play_play_new_file(ugListItemData *data, bool drm_check_flag)
1515 {
1516         UG_TRACE_BEGIN;
1517         ugListItemData *itemData = data;
1518         ug_mf_retvm_if(itemData == NULL, false, "itemData is NULL");
1519
1520         ugData *ugd = (ugData *)itemData->ug_pData;
1521         ug_mf_retvm_if(ugd == NULL, false, "ugd is NULL");
1522
1523         __mf_ug_list_play_init_data(ugd);
1524
1525         if (!__mf_ug_list_play_ready_new_file_play(itemData, true)) {
1526                 UG_TRACE_END;
1527                 return false;
1528         }
1529
1530         if (!__mf_ug_list_play_play_current_file(itemData)) {
1531                 UG_TRACE_END;
1532                 return false;
1533         }
1534         UG_TRACE_END;
1535
1536         return true;
1537 }
1538
1539
1540 /******************************
1541 ** Prototype    : _music_item_play
1542 ** Description  :
1543 ** Input        : ugListItemData *param
1544 ** Output       : None
1545 ** Return Value :
1546 ** Calls        :
1547 ** Called By    :
1548 **
1549 **  History        :
1550 **  1.Date         : 2010/12/10
1551 **    Author       : Samsung
1552 **    Modification : Created function
1553 **
1554 ******************************/
1555 void mf_ug_list_play_play_music_item(ugListItemData *data)
1556 {
1557         UG_TRACE_BEGIN;
1558         ugListItemData *itemData = data;
1559         ug_mf_retm_if(itemData == NULL, "itemData is NULL");
1560         ugData *ugd = itemData->ug_pData;
1561         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
1562
1563         int key = 0;
1564         int error_code = 0;
1565         error_code = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &key);
1566
1567         ug_debug("key is [%d]", key);
1568         ug_debug("ugd->ug_ListPlay.ug_iPlayState is [%d]", ugd->ug_ListPlay.ug_iPlayState);
1569
1570         if (error_code == 0 && key <= VCONFKEY_SYSMAN_BAT_POWER_OFF) {
1571                 ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, ("Battery low, play failed!"), NULL, NULL, NULL, NULL, NULL);
1572         } else if (error_code != 0) {
1573                 ugd->ug_MainWindow.ug_pNormalPopup = mf_ug_popup_create(ugd, UG_POPMODE_TEXT, NULL, ("Unkown error, play failed!"), NULL, NULL, NULL, NULL, NULL);
1574         } else {
1575                 if (ugd->ug_ListPlay.ug_pPlayFilePath != NULL) {
1576                         ug_debug();
1577                         if (g_strcmp0(ugd->ug_ListPlay.ug_pPlayFilePath, itemData->ug_pItemName->str) != 0) {
1578                                 mf_ug_list_play_destory_playing_file(ugd);
1579                                 mf_ug_list_disable_play_itc(ugd, true);
1580                                 //mf_ug_list_play_update_item_icon(ugd);
1581                                 __mf_ug_list_play_play_new_file(itemData, true);
1582                         } else {
1583                                 ug_debug();
1584                                 /*/ playing the same file */
1585                                 __mf_ug_list_play_control_cb(itemData);
1586                         }
1587                 } else {
1588                         ug_debug();
1589                         mf_ug_list_disable_play_itc(ugd, false);
1590                         __mf_ug_list_play_play_new_file(itemData, true);
1591                 }
1592         }
1593         UG_TRACE_END;
1594
1595 }
1596
1597 /******************************
1598 ** Prototype    : mf_ug_list_play_destory_playing_file
1599 ** Description  :
1600 ** Input        : ugListItemData *data
1601 ** Output       : None
1602 ** Return Value :
1603 ** Calls        :
1604 ** Called By    :
1605 **
1606 **  History        :
1607 **  1.Date         : 2010/12/10
1608 **    Author       : Samsung
1609 **    Modification : Created function
1610 **
1611 ******************************/
1612 void mf_ug_list_play_destory_playing_file(void *data)
1613 {
1614         UG_TRACE_BEGIN;
1615         ugData *ugd = (ugData *)data;
1616         ug_mf_retm_if(ugd == NULL, "ugd is NULL");
1617
1618         __mf_ug_list_play_stop(ugd);
1619         __mf_ug_list_play_unrealize(ugd);
1620         __mf_ug_list_play_destory(ugd);
1621         UG_TRACE_END;
1622 }
1623
1624
1625 static sound_type_e mf_ug_player_get_sound_type()
1626 {
1627         UG_TRACE_BEGIN;
1628         sound_type_e type = SOUND_TYPE_SYSTEM;
1629         int ret = 0;
1630         ret = sound_manager_get_current_sound_type(&type);
1631         ug_error("ret is [%d]", ret);
1632         UG_TRACE_END;
1633         return type;
1634 }
1635
1636 static int mf_ug_player_get_volume(sound_type_e type)
1637 {
1638         UG_TRACE_BEGIN;
1639         int volume = 0;
1640         int ret = 0;
1641         ret = sound_manager_get_volume(SOUND_TYPE_MEDIA, &volume);
1642         //ret = sound_manager_get_volume(type, &volume);
1643         ug_error("ret is [%d]", ret);
1644         UG_TRACE_END;
1645         return volume;
1646
1647 }
1648
1649 static void mf_ug_player_set_volume(sound_type_e type, int volume)
1650 {
1651         UG_TRACE_BEGIN;
1652         int ret = 0;
1653         ret = sound_manager_set_volume(type, volume);
1654         ug_error("ret is [%d]", ret);
1655         UG_TRACE_END;
1656 }
1657
1658
1659 static void mf_ug_player_vol_type_set(mf_player_volume_type type)
1660 {
1661         UG_TRACE_BEGIN;
1662         sound_type_e current_type;
1663         int volume = 0;
1664         current_type = mf_ug_player_get_sound_type();
1665         volume = mf_ug_player_get_volume(current_type);
1666         ug_error("current type is [%d] volume is [%d] type is [%d]", current_type, volume, type);
1667         sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_MEDIA);
1668         mf_ug_player_set_volume(SOUND_TYPE_MEDIA, volume);
1669         UG_TRACE_END;
1670         return;
1671         switch (type) {
1672         case    MF_VOLUME_ALERT:
1673                 sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_ALARM);
1674                 mf_ug_player_set_volume(SOUND_TYPE_ALARM, volume);
1675                 break;
1676         case    MF_VOLUME_NOTIFICATION:
1677                 sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_NOTIFICATION);
1678                 mf_ug_player_set_volume(SOUND_TYPE_NOTIFICATION, volume);
1679                 break;
1680         case    MF_VOLUME_RINGTONE:
1681                 sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_RINGTONE);
1682                 mf_ug_player_set_volume(SOUND_TYPE_RINGTONE, volume);
1683                 break;
1684         default:
1685                 sound_manager_set_volume_key_type(VOLUME_KEY_TYPE_MEDIA);
1686                 mf_ug_player_set_volume(SOUND_TYPE_MEDIA, volume);
1687                 break;
1688         }
1689         UG_TRACE_END;
1690 }
1691
1692 void mf_ug_player_vol_set(const char *path)
1693 {
1694         ug_mf_retm_if(path == NULL, "path is NULL");
1695         if (g_strcmp0(path, UG_SETTING_MSG_ALERTS_PATH) == 0) {
1696                 mf_ug_player_vol_type_set(MF_VOLUME_NOTIFICATION);
1697         } else if (g_strcmp0(path, UG_SETTING_RINGTONE_PATH) == 0) {
1698                 mf_ug_player_vol_type_set(MF_VOLUME_RINGTONE);
1699         } else if (g_strcmp0(path, UG_SETTING_ALERTS_PATH) == 0) {
1700                 mf_ug_player_vol_type_set(MF_VOLUME_ALERT);
1701         } else {
1702                 mf_ug_player_vol_type_set(MF_VOLUME_NONE);
1703         }
1704 }
1705