2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
17 * @file view_logic_apps_support.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
19 * @brief Implementation file of AppsSupport class used by ViewLogic
22 #include "view_logic_apps_support.h"
23 #include <dpl/assert.h>
24 #include <dpl/log/log.h>
27 #include <widget_model.h>
28 #include <application_launcher.h>
30 namespace ViewModule {
32 const char* const SCHEME_TYPE_HTML5_VIDEO = "html5video";
33 const char* const HTTP_STREAMING_MPEG_MIMETYPE = "application/x-mpegurl";
34 const char* const HTTP_STREAMING_APPLE_MIMETYPE =
35 "application/vnd.apple.mpegurl";
38 //Implementation class
39 class AppsSupportImplementation
42 WidgetModel *m_widgetModel;
51 AppsSupportImplementation() :
56 ~AppsSupportImplementation()
58 Assert(!m_initialized &&
59 "AppsSupport has to be deinitialized prior destroying!");
62 void initialize(WidgetModel *widgetModel)
64 Assert(!m_initialized && "Already initialized!");
66 LogDebug("Initializing Apps Support");
67 Assert(widgetModel && "Passed widgetModel is NULL!");
68 m_widgetModel = widgetModel;
70 ApplicationLauncherSingleton::Instance().Touch();
72 ApplicationLauncherSingleton::Instance().setWidgetTizenId(
73 DPL::ToUTF8String(m_widgetModel->TizenId));
75 LogDebug("Initialized");
81 Assert(m_initialized && "Not initialized!");
82 LogDebug("Deinitialized");
84 m_initialized = false;
87 bool httpMultimediaRequest(std::string mimeType, std::string uri)
89 LogInfo("httpMultimediaRequest called");
91 if ("null" == mimeType || "null" == uri) {
92 LogError("uri/mimeType is null");
97 args = bundle_create();
98 void *userData = NULL;
99 appsvc_res_fn responseCallback = NULL;
101 // ignore case match of string of mime type
102 // if needed, define appsvc response callback
103 // and its user data per mimetype
104 if (!strcasecmp(mimeType.c_str(), HTTP_STREAMING_APPLE_MIMETYPE) ||
105 !strcasecmp(mimeType.c_str(), HTTP_STREAMING_MPEG_MIMETYPE))
107 appsvc_set_operation(args, APPSVC_OPERATION_VIEW);
108 appsvc_set_mime(args, mimeType.c_str());
109 appsvc_set_uri(args, uri.c_str());
110 } else if (!strcasecmp(mimeType.c_str(), "video/mp4") ||
111 !strcasecmp(mimeType.c_str(), "vidoe/3gp"))
113 CONTROLLER_POST_EVENT(
115 ApplicationLauncherEvents::LaunchApplicationByPkgname(
116 ApplicationLauncherPkgname::PKG_NAME_VIDEO_PLAYER,
117 SCHEME_TYPE_HTML5_VIDEO,
121 LogInfo("Not Supported MIME type in WRT");
126 CONTROLLER_POST_EVENT(
128 ApplicationLauncherEvents::LaunchApplicationByAppService(
136 void downloadRequest(const char *url,
137 const char *mimeType,
138 const char *userParam)
140 LogInfo("Download info : " << url << "(" <<
141 mimeType << ", " << userParam << ")");
143 // ignore case match of string of mime type
144 int isAppServiceable = httpMultimediaRequest(
145 mimeType ? std::string(mimeType) : "null",
146 url ? std::string(url) : "null");
148 if (isAppServiceable) {
149 LogInfo("Application Service start");
153 CONTROLLER_POST_EVENT(
155 ApplicationLauncherEvents::LaunchApplicationByPkgname(
156 ApplicationLauncherPkgname::PKG_NAME_DOWNLOAD_PROVIDER,
157 url ? std::string(url) : "null",
158 mimeType ? mimeType : "null",
159 userParam ? userParam : "null"));
162 void html5VideoRequest(void* event_info)
164 LogInfo("html5VideoRequestCallback called");
166 HTML5Video* video = static_cast<HTML5Video*>(event_info);
168 LogDebug("video->path : " << video->path);
169 LogDebug("video->cookie : " << video->cookie);
170 if (NULL == video->path) {
171 LogError("path is null");
174 CONTROLLER_POST_EVENT(
176 ApplicationLauncherEvents::LaunchApplicationByPkgname(
177 ApplicationLauncherPkgname::PKG_NAME_VIDEO_PLAYER,
178 SCHEME_TYPE_HTML5_VIDEO,
179 video->path ? video->path : "null",
180 video->cookie ? video->cookie : "null"));
184 AppsSupport::AppsSupport() : m_impl(new AppsSupportImplementation)
187 AppsSupport::~AppsSupport()
190 void AppsSupport::initialize(WidgetModel *widgetModel)
192 m_impl->initialize(widgetModel);
195 void AppsSupport::deinitialize()
197 m_impl->deinitialize();
200 void AppsSupport::html5VideoRequest(void* event_info)
202 m_impl->html5VideoRequest(event_info);
205 void AppsSupport::downloadRequest(const char *url,
206 const char *mimeType,
207 const char *userParam)
209 m_impl->downloadRequest(url, mimeType, userParam);