initial draft of the org.tizen.video-player
[apps/core/preloaded/video-player.git] / src / mp-video-animation-ctrl.c
1 /*
2  * To apply the Flora License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
3  * 
4  *    Copyright [2012] [JongDong Lee <jongdong.lee@samsung.com>, ChangSun Lee <cs78.lee@samsung.com>]
5  * 
6  *    Licensed under the Flora License, Version 1.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  * 
10  *        http://www.tizenopensource.org/license
11  * 
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19
20 #include "mp-util.h"
21 #include "mp-video-log.h"
22 #include "video-player.h"
23 #include "mp-video-value-define.h"
24 #include "mp-video-animation-ctrl.h"
25
26 #define BUFFERING_TXT_MAX_LEN   16
27
28 static Evas_Object *pAnimationEdj = NULL;
29 static Ecore_Timer *pAnimationTimer = NULL;
30
31 static int nIconIndex = 0;
32
33 static Eina_Bool MpVideoAnimationCtrlTimerCb(void *data)
34 {
35 /*      VideoLogInfo(""); */
36
37         char sig_format[SIGNAL_TEXT_MAX_LEN] = { 0, };
38
39         snprintf(sig_format, SIGNAL_TEXT_MAX_LEN, "%s.%d",
40                  SIGNAL_ANIMATION_IMAGE_LOADING, nIconIndex);
41
42         edje_object_signal_emit(pAnimationEdj, sig_format, "*");
43
44         nIconIndex += 1;
45         if (nIconIndex > ANIMATION_MAX_COUNT)
46                 nIconIndex = 1;
47
48         return EINA_TRUE;
49 }
50
51 void *MpVideoAnimationCtrlInit(void *pUserData)
52 {
53         VideoLogInfo("");
54
55         if (pUserData == NULL) {
56                 VideoLogInfo("data is NULL");
57                 return NULL;
58         }
59
60         Evas *pMainWindowEvas = (Evas *) pUserData;
61
62         pAnimationEdj = MpUtilLoadEdjFile(pMainWindowEvas,
63                                           VIDEO_PLAYER_ANIMATION_EDJ,
64                                           ANIMATION_EDJ_GROUP);
65
66         evas_object_hide(pAnimationEdj);
67
68         return (void *)pAnimationEdj;
69 }
70
71 void MpVideoAnimationCtrlDestroy(void)
72 {
73         VideoLogInfo("");
74
75         if (pAnimationTimer) {
76                 ecore_timer_del(pAnimationTimer);
77                 pAnimationTimer = NULL;
78         }
79
80         if (pAnimationEdj) {
81                 evas_object_hide(pAnimationEdj);
82                 evas_object_del(pAnimationEdj);
83                 pAnimationEdj = NULL;
84         }
85
86         nIconIndex = 0;
87 }
88
89 void MpVideoAnimationCtrlSetPercent(int nPercent)
90 {
91         VideoLogInfo("");
92         if (nPercent >= 0) {
93                 char szBuffering[BUFFERING_TXT_MAX_LEN] = { 0, };
94
95                 snprintf(szBuffering, BUFFERING_TXT_MAX_LEN, "Loading %d%%...",
96                          nPercent);
97                 edje_object_part_text_set(pAnimationEdj, "loading.txt",
98                                           szBuffering);
99         } else {
100                 edje_object_part_text_set(pAnimationEdj, "loading.txt",
101                                           "Loading...");
102         }
103 }
104
105 void MpVideoAnimationCtrlPlay(void)
106 {
107         VideoLogInfo("");
108         if (pAnimationTimer == NULL) {
109                 pAnimationTimer = ecore_timer_add(ANIMATION_TIMER_INTERVAL,
110                                                   MpVideoAnimationCtrlTimerCb,
111                                                   NULL);
112         }
113 }
114
115 void MpVideoAnimationCtrlStop(void)
116 {
117         VideoLogInfo("");
118
119         if (pAnimationTimer) {
120                 ecore_timer_del(pAnimationTimer);
121                 pAnimationTimer = NULL;
122         }
123 }
124
125 void MpVideoAnimationCtrlShow(void)
126 {
127         VideoLogInfo("");
128
129         if (pAnimationTimer == NULL) {
130                 MpVideoAnimationCtrlPlay();
131                 MpVideoAnimationCtrlSetPercent(-1);
132                 evas_object_show(pAnimationEdj);
133         }
134 }
135
136 void MpVideoAnimationCtrlHide(void)
137 {
138         VideoLogInfo("");
139
140         MpVideoAnimationCtrlStop();
141         evas_object_hide(pAnimationEdj);
142 }
143
144 bool MpVideoAnimationCtrlGetActiveState(void)
145 {
146         VideoLogInfo("");
147         if (pAnimationTimer)
148                 return true;
149         else
150                 return false;
151 }