apply FSL(Flora Software License)
[apps/core/preloaded/video-player.git] / src / mp-video-animation-ctrl.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://www.tizenopensource.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 #include <appcore-efl.h>
20
21 #include "mp-util.h"
22 #include "mp-video-log.h"
23 #include "video-player.h"
24 #include "mp-video-value-define.h"
25 #include "mp-video-animation-ctrl.h"
26
27 #define BUFFERING_TXT_MAX_LEN   16
28
29 static Evas_Object *pAnimationEdj = NULL;
30 static Ecore_Timer *pAnimationTimer = NULL;
31
32 static int nIconIndex = 0;
33
34 static Eina_Bool MpVideoAnimationCtrlTimerCb(void *data)
35 {
36         char sig_format[SIGNAL_TEXT_MAX_LEN] = { 0, };
37
38         snprintf(sig_format, SIGNAL_TEXT_MAX_LEN, "%s.%d",
39                  SIGNAL_ANIMATION_IMAGE_LOADING, nIconIndex);
40
41         edje_object_signal_emit(pAnimationEdj, sig_format, "*");
42
43         nIconIndex += 1;
44         if (nIconIndex > ANIMATION_MAX_COUNT)
45                 nIconIndex = 1;
46
47         return EINA_TRUE;
48 }
49
50 void *MpVideoAnimationCtrlInit(void *pUserData)
51 {
52         VideoLogInfo("");
53
54         if (pUserData == NULL) {
55                 VideoLogInfo("data is NULL");
56                 return NULL;
57         }
58
59         Evas *pMainWindowEvas = (Evas *) pUserData;
60
61         pAnimationEdj = MpUtilLoadEdjFile(pMainWindowEvas,
62                                           VIDEO_PLAYER_ANIMATION_EDJ,
63                                           ANIMATION_EDJ_GROUP);
64
65         evas_object_hide(pAnimationEdj);
66
67         return (void *)pAnimationEdj;
68 }
69
70 void MpVideoAnimationCtrlDestroy(void)
71 {
72         VideoLogInfo("");
73
74         if (pAnimationTimer) {
75                 ecore_timer_del(pAnimationTimer);
76                 pAnimationTimer = NULL;
77         }
78
79         if (pAnimationEdj) {
80                 evas_object_hide(pAnimationEdj);
81                 evas_object_del(pAnimationEdj);
82                 pAnimationEdj = NULL;
83         }
84
85         nIconIndex = 0;
86 }
87
88 void MpVideoAnimationCtrlSetPercent(int nPercent)
89 {
90         VideoLogInfo("");
91         if (nPercent >= 0) {
92                 char szBuffering[BUFFERING_TXT_MAX_LEN] = { 0, };
93
94                 snprintf(szBuffering, BUFFERING_TXT_MAX_LEN, "Loading %d%%...",
95                          nPercent);
96                 edje_object_part_text_set(pAnimationEdj, "loading.txt",
97                                           szBuffering);
98         } else {
99                 edje_object_part_text_set(pAnimationEdj, "loading.txt",
100                                           "Loading...");
101         }
102 }
103
104 void MpVideoAnimationCtrlPlay(void)
105 {
106         VideoLogInfo("");
107         if (pAnimationTimer == NULL) {
108                 pAnimationTimer = ecore_timer_add(ANIMATION_TIMER_INTERVAL,
109                                                   MpVideoAnimationCtrlTimerCb,
110                                                   NULL);
111         }
112 }
113
114 void MpVideoAnimationCtrlStop(void)
115 {
116         VideoLogInfo("");
117
118         if (pAnimationTimer) {
119                 ecore_timer_del(pAnimationTimer);
120                 pAnimationTimer = NULL;
121         }
122 }
123
124 void MpVideoAnimationCtrlShow(void)
125 {
126         VideoLogInfo("");
127
128         if (pAnimationTimer == NULL) {
129                 MpVideoAnimationCtrlPlay();
130                 MpVideoAnimationCtrlSetPercent(-1);
131                 evas_object_show(pAnimationEdj);
132         }
133 }
134
135 void MpVideoAnimationCtrlHide(void)
136 {
137         VideoLogInfo("");
138
139         MpVideoAnimationCtrlStop();
140         evas_object_hide(pAnimationEdj);
141 }
142
143 bool MpVideoAnimationCtrlGetActiveState(void)
144 {
145         VideoLogInfo("");
146         if (pAnimationTimer)
147                 return true;
148         else
149                 return false;
150 }