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