Tizen 2.0 Release
[profile/ivi/org.tizen.video-player.git] / src / mp-video-subtitle-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 <vconf.h>
19 #include <vconf-keys.h>
20 #include <Ecore_Evas.h>
21 #include <Elementary.h>
22
23 #include "mp-util.h"
24 #include "mp-video-log.h"
25 #include "video-player.h"
26 #include "mp-video-service-ctrl.h"
27 #include "mp-video-subtitle-ctrl.h"
28
29 #define MP_VIDEO_SUBTITLE_MENU_NUM              2
30
31 #define MP_SUBTITLE_FONT_SMALL                  22
32 #define MP_SUBTITLE_FONT_MEDIUM                 35
33 #define MP_SUBTITLE_FONT_LARGE                  48
34 #define MP_SUBTITLE_MIN_VALUE                   3
35
36
37 /* subtitle edc layout */
38 static Evas_Object *pSubTitleEdj = NULL;
39
40 static bool bExistSubtitleFile = FALSE;
41 static char *szSubtitleFileUri = NULL;
42 static char szSubTitleExtWildkey[MP_SUBTITLE_TYPE_MAX][5] = { ".srt", ".sub", ".smi" };
43
44 static MpSubTitleSizeType nSubtitleSize = MP_SUBTITLE_SIZE_SMALL;
45
46 static bool bShowStatus = TRUE;
47
48
49 /*
50  * Internal function
51  */
52
53 static void MpVideoSubtitleCtrlClear(void)
54 {
55         VideoLogInfo("");
56
57         bExistSubtitleFile = FALSE;
58
59         if(szSubtitleFileUri)
60         {
61                 free(szSubtitleFileUri);
62                 szSubtitleFileUri = NULL;
63         }
64
65         if(pSubTitleEdj) {
66                 evas_object_del(pSubTitleEdj);
67                 pSubTitleEdj = NULL;
68         }
69
70 }
71
72 /*
73  * External function
74  */
75
76 bool MpVideoSubtitleCtrlCheckSubtitleFile(char *szMediaUriPath)
77 {
78         if (!szMediaUriPath) {
79                 VideoLogInfo("No Exist szMediaUri.");
80                 return FALSE;
81         }
82
83         if (strlen(szMediaUriPath) < 1) {
84                 VideoLogInfo("No Exist szMediaUri.");
85                 return FALSE;
86         }
87
88         VideoLogInfo("");
89
90         struct stat buf;
91         int nCount = 0;
92         int nStrLength = 0;
93
94         bExistSubtitleFile = FALSE;
95
96         if(szSubtitleFileUri == NULL)
97         {
98                 szSubtitleFileUri = calloc(1, sizeof(char) * STR_LEN_MAX);
99         }
100
101         char *szExt;
102
103         szExt = strrchr(szMediaUriPath, '.');
104
105         if (szExt) {
106                 nStrLength  = strlen(szMediaUriPath) - strlen(szExt);
107         }
108         else {
109                 nStrLength = strlen(szMediaUriPath);
110         }
111
112         for (nCount = 0; nCount < MP_SUBTITLE_TYPE_MAX; nCount++)
113         {
114                 memset(szSubtitleFileUri, 0, STR_LEN_MAX);
115                 strncpy(szSubtitleFileUri, szMediaUriPath, nStrLength);
116                 strcat(szSubtitleFileUri, szSubTitleExtWildkey[nCount]);
117                 VideoLogInfo("%s",szSubtitleFileUri);
118
119                 if (!stat(szSubtitleFileUri, &buf)) {
120                         VideoLogInfo("Success finding subtitle file. - %d", nCount);
121                         bExistSubtitleFile = TRUE;
122                         break;
123                 } else {
124                         memset(szSubtitleFileUri, 0, STR_LEN_MAX);
125                 }
126         }
127
128         if (!bExistSubtitleFile) {
129                 VideoLogInfo("Fail finding subtitle file.");
130         }
131
132         return bExistSubtitleFile;
133 }
134
135 void *MpVideoSubtitleCtrlInit(void *pUserData, void *pParent)
136 {
137         if (pUserData == NULL) {
138                 VideoLogInfo("[ERR]No have pUserData");
139                 return NULL;
140         }
141
142         if (pParent == NULL) {
143                 VideoLogInfo("[ERR]No have pParent");
144                 return NULL;
145         }
146
147         VideoLogInfo("");
148
149         VideoAppData *pAppData = (VideoAppData *)pUserData;
150
151         MpVideoSubtitleCtrlClear();
152
153         if(!MpVideoSubtitleCtrlCheckSubtitleFile(pAppData->szMediaUri))         {
154                 VideoLogInfo("Sub tiltle file is not exist.");
155         }
156
157         pSubTitleEdj = elm_layout_add(pParent);
158         elm_layout_file_set(pSubTitleEdj, VIDEO_PLAYER_SUBTITLE_EDJ, SUBTITLE_EDJ_GROUP);
159
160         return (void *)pSubTitleEdj;
161 }
162
163 void MpVideoSubtitleCtrlDestroy(void)
164 {
165         VideoLogInfo("");
166
167         MpVideoSubtitleCtrlClear();
168 }
169
170 void MpVideoSubtitleCtrlUpdate(char *szTxt)
171 {
172         VideoLogInfo("%d",strlen(szTxt));
173
174         if (!MpVideoSubtitleCtrlIsExistSubtitle()) {
175                 return;
176         }
177
178         if(pSubTitleEdj == NULL) {
179                 VideoLogInfo("Subtitle handle is NULL");
180                 return;
181         }
182
183         edje_object_part_text_set(_EDJ(pSubTitleEdj), "subtitle.label.txt",szTxt);
184 }
185
186
187 bool MpVideoSubtitleCtrlIsExistSubtitle(void)
188 {
189         VideoLogInfo("");
190
191         return bExistSubtitleFile;
192 }
193
194 bool MpVideoSubtitleCtrlGetSubtitleUri(char *szSubtitleUri)
195 {
196         VideoLogInfo("");
197
198         if (!MpVideoSubtitleCtrlIsExistSubtitle()) {
199                 return FALSE;
200         }
201
202         if (strlen(szSubtitleFileUri) < 1) {
203                 VideoLogInfo("[ERR]No have szSubtitleFileUri");
204                 return FALSE;
205         }
206
207         strncpy(szSubtitleUri, szSubtitleFileUri, STR_LEN_MAX -1);
208
209         return TRUE;
210 }
211
212 void MpVideoSubtitleCtrlSetLayoutShow(bool bShow)
213 {
214         VideoLogInfo("");
215
216         if (!MpVideoSubtitleCtrlIsExistSubtitle()) {
217                 return;
218         }
219
220         if(pSubTitleEdj == NULL) {
221                 VideoLogInfo("Subtitle handle is NULL");
222                 return;
223         }
224         if(bShow) {
225                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_LAYOUT_SHOW, "*");
226         }
227         else {
228                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_LAYOUT_HIDE, "*");
229         }
230
231 }
232
233 void MpVideoSubtitleCtrlSetSizeMode(int nSizeMode)
234 {
235         VideoLogInfo("");
236
237         if (!MpVideoSubtitleCtrlIsExistSubtitle()) {
238                 return;
239         }
240
241         if(pSubTitleEdj == NULL) {
242                 VideoLogInfo("Subtitle handle is NULL");
243                 return;
244         }
245
246         MpSubTitleSizeType type = nSizeMode;
247
248         if(type == MP_SUBTITLE_SIZE_LARGE) {
249                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_SIZE_LARGE, "*");
250         }
251         else if(type == MP_SUBTITLE_SIZE_MEDIUM) {
252                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_SIZE_MEDIUM, "*");
253         }
254         else if(type == MP_SUBTITLE_SIZE_SMALL) {
255                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_SIZE_SMALL, "*");
256         }
257
258         nSubtitleSize = type;
259
260 }
261
262 int MpVideoSubtitleCtrlGetSizeMode()
263 {
264         VideoLogInfo("");
265
266         if (!MpVideoSubtitleCtrlIsExistSubtitle()) {
267                 return -1;
268         }
269
270         if(pSubTitleEdj == NULL) {
271                 VideoLogInfo("Subtitle handle is NULL");
272                 return -1;
273         }
274
275         return nSubtitleSize;
276 }
277
278
279
280 void MpVideoSubtitleCtrlSetRotate(int nRotateStatus)
281 {
282         VideoLogInfo("");
283         if (!MpVideoSubtitleCtrlIsExistSubtitle()) {
284                 return;
285         }
286
287         if(pSubTitleEdj == NULL) {
288                 VideoLogInfo("Subtitle handle is NULL");
289                 return;
290         }
291
292         if(nRotateStatus == VIDEO_ROTATE_PORTRAIT_NORMAL ||
293                 nRotateStatus == VIDEO_ROTATE_PORTRAIT_REVERSE) {
294                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_PORTRATE_MODE, "*");
295
296         }
297         else if(nRotateStatus == VIDEO_ROTATE_LANDSCAPE_NORMAL ||
298                 nRotateStatus == VIDEO_ROTATE_LANDSCAPE_REVERSE) {
299                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_LANDSCAPE_MODE, "*");
300         }
301 }
302
303 void MpVideoSubtitleCtrlSetShowStatus(bool bShow)
304 {
305         VideoLogInfo("");
306
307         if(pSubTitleEdj == NULL) {
308                 VideoLogInfo("Subtitle handle is NULL");
309                 return;
310         }
311         if(bShowStatus != bShow) {
312                 bShowStatus = bShow;
313                 if(bShow) {
314                         edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_TXT_SHOW, "*");
315
316                 }
317                 else {
318                         edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_SUBTITLE_TXT_HIDE, "*");
319                 }
320         }
321 }
322
323 bool MpVideoSubtitleCtrlGetShowStatus()
324 {
325         VideoLogInfo("");
326
327         if(pSubTitleEdj == NULL) {
328                 VideoLogInfo("Subtitle handle is NULL");
329                 return FALSE;
330         }
331
332         return bShowStatus;
333 }
334
335 void MpVideoSubtitleCtrlSetLockScreen(bool bShow)
336 {
337         VideoLogInfo("");
338
339         if(pSubTitleEdj == NULL) {
340                 VideoLogInfo("Subtitle handle is NULL");
341                 return;
342         }
343
344         if(bShow) {
345                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_LOCKSCREEN_SHOW, "*");
346         }
347         else {
348                 edje_object_signal_emit(_EDJ(pSubTitleEdj), SIGNAL_LOCKSCREEN_HIDE, "*");
349         }
350
351 }
352