2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
20 #include <vconf-keys.h>
22 #include <Ecore_Evas.h>
23 #include <Elementary.h>
24 #include <appcore-efl.h>
25 #include <appcore-common.h>
28 #include "mp-video-log.h"
29 #include "video-player.h"
30 #include "mp-video-subtitle-ctrl.h"
32 #define MP_VIDEO_SUBTITLE_MENU_NUM 2
33 #define VCONFKEY_GALLERY_SUBTITLE_STATE "db/setting/gallery/subtitle_state" //boolean
35 static int bSubtitleSettingState = FALSE;
36 static bool bExistSubtitleFile = FALSE;
37 static char szSubtitleFileUri[STR_LEN_MAX] = { 0 };
39 static char szSubTitleExtWildkey[MP_SUBTITLE_TYPE_MAX][STR_LEN_MAX] = { ".srt", ".sub", ".smi" };
45 bool MpVideoSubtitleCtrlCheckSubtitleFile(char *szMediaUriPath)
47 if (!bSubtitleSettingState) {
48 VideoLogInfo("Subtitle .");
52 if (!szMediaUriPath) {
53 VideoLogInfo("No Exist szMediaUri.");
57 if (strlen(szMediaUriPath) < 1) {
58 VideoLogInfo("No Exist szMediaUri.");
68 bExistSubtitleFile = FALSE;
69 memset(szSubtitleFileUri, 0, STR_LEN_MAX);
71 for (nCount = 0; nCount < MP_SUBTITLE_TYPE_MAX; nCount++) {
72 nStrLength = strcspn(szMediaUriPath, ".");
73 strncpy(szSubtitleFileUri, szMediaUriPath, nStrLength);
74 strcat(szSubtitleFileUri, szSubTitleExtWildkey[nCount]);
76 if (!stat(szSubtitleFileUri, &buf)) {
77 VideoLogInfo("Success finding subtitle file. - %d", nCount);
78 bExistSubtitleFile = TRUE;
81 memset(szSubtitleFileUri, 0, STR_LEN_MAX);
85 if (!bExistSubtitleFile) {
86 VideoLogInfo("Fail finding subtitle file.");
89 return bExistSubtitleFile;
92 void MpVideoSubtitleCtrlClear(void)
96 bExistSubtitleFile = FALSE;
97 bSubtitleSettingState = FALSE;
99 memset(szSubtitleFileUri, 0, STR_LEN_MAX);
102 static void MpVideoSubtitleCtrlStateChangeCb(keynode_t *pKeyNode, void *pUserData)
105 VideoLogInfo("User data is NULL.");
111 if (!vconf_get_bool(VCONFKEY_GALLERY_SUBTITLE_STATE, &bSubtitleSettingState)) {
112 if (!bSubtitleSettingState) {
113 VideoLogInfo("Subtitle OFF.");
115 VideoLogInfo("Subtitle ON.");
118 VideoLogInfo("Fail to get vconf - subtitle.");
125 bool MpVideoSubtitleCtrlInit(void *pUserData)
127 if (pUserData == NULL) {
128 VideoLogInfo("[ERR]No have pUserData");
134 VideoAppData *pAppData = (VideoAppData *)pUserData;
136 MpVideoSubtitleCtrlClear();
138 if (pAppData->nCurPlayerType != MP_VIDEO_PLAYER) {
139 VideoLogInfo("Current player type is not video player.");
143 if (!vconf_get_bool(VCONFKEY_GALLERY_SUBTITLE_STATE, &bSubtitleSettingState)) {
144 if (!bSubtitleSettingState) {
145 VideoLogInfo("Subtitle OFF.");
147 VideoLogInfo("Subtitle ON.");
150 VideoLogInfo("Fail to get vconf - subtitle.");
153 if (vconf_notify_key_changed(VCONFKEY_GALLERY_SUBTITLE_STATE, MpVideoSubtitleCtrlStateChangeCb, pAppData)) {
154 VideoLogInfo("[ERR] Fail to resiste subtitle notification callback.");
157 return MpVideoSubtitleCtrlCheckSubtitleFile(pAppData->szMediaUri);
160 void MpVideoSubtitleCtrlDestroy(void)
164 MpVideoSubtitleCtrlClear();
167 bool MpVideoSubtitleCtrlIsExistSubtitle(void)
171 return bExistSubtitleFile;
174 bool MpVideoSubtitleCtrlGetSubtitleUri(char *szSubtitleUri)
178 if (!MpVideoSubtitleCtrlIsExistSubtitle()) {
182 if (strlen(szSubtitleFileUri) < 1) {
183 VideoLogInfo("[ERR]No have szSubtitleFileUri");
187 strncpy(szSubtitleUri, szSubtitleFileUri, STR_LEN_MAX -1);