2 Copyright (C) 2012 Samsung Electronics
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
22 #include "OpenPanel.h"
25 #include <ui-gadget.h>
31 OpenPanel::OpenPanel(Evas_Object* ewkView)
36 OpenPanel::~OpenPanel()
41 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void* priv)
43 Evas_Object* base, *win;
48 base = (Evas_Object*)ug_get_layout(ug);
52 win = (Evas_Object*)ug_get_window();
56 case UG_MODE_FULLVIEW:
57 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
58 elm_win_resize_object_add(win, base);
59 evas_object_show(base);
66 static void result_cb(ui_gadget_h ug, service_h service, void* priv)
68 if (ug == NULL || priv == NULL)
71 OpenPanel* openPanel = (OpenPanel*)priv;
72 Evas_Object* ewk_view = openPanel->ewkView();
76 Eina_List* selectedFiles = NULL;
78 char* filename = NULL;
80 service_get_extra_data(service, "result", &filename);
82 if (filename && strlen(filename)) {
83 char* filelist = strdup(filename);
85 file = strtok(filelist, "?");
89 if ((stringlength = strlen(file)) > 0) {
90 char* buffer = new char[stringlength+1];
91 memset(buffer, 0x00, sizeof(buffer));
92 strncpy(buffer, file, strlen(file));
93 buffer[stringlength] = 0x00;
94 selectedFiles = eina_list_append(selectedFiles, buffer);
97 }while((file = strtok(NULL, "?")));
102 ewk_view_open_panel_reply(ewk_view, selectedFiles, EINA_TRUE);
106 static void destroy_cb(ui_gadget_h ug, void* priv)
110 OpenPanel* openPanel = (OpenPanel*)priv;
111 Evas_Object* ewk_view = openPanel->ewkView();
115 ewk_view_open_panel_reply(ewk_view, NULL, EINA_FALSE);
119 static void _cameraResultCb(service_h request, service_h reply, service_result_e result, void* data)
121 OpenPanel* openPanel = static_cast<OpenPanel*>(data);
123 if (result == SERVICE_RESULT_SUCCEEDED) {
124 char* resultFilename = 0;
125 int ret = service_get_extra_data(reply, SERVICE_DATA_SELECTED, &resultFilename);
126 if (ret != SERVICE_ERROR_NONE)
129 if (resultFilename) {
131 int len = strlen(resultFilename) + 1;
132 char* fileName = static_cast<char*>(malloc(sizeof(char) * len));
133 memset(fileName, 0, sizeof(char) * len);
134 strcpy(fileName, resultFilename);
135 list = eina_list_append(list, fileName);
136 ewk_view_open_panel_reply(openPanel->ewkView(), list, true);
138 ewk_view_open_panel_reply(openPanel->ewkView(), 0, false);
141 ewk_view_open_panel_reply(openPanel->ewkView(), 0, false);
145 bool OpenPanel::_capturePicture()
147 service_h svcHandle = 0;
148 if (service_create(&svcHandle) < 0 || !svcHandle)
151 service_set_window(svcHandle, ecore_x_window_root_first_get());
152 service_set_operation(svcHandle, SERVICE_OPERATION_CREATE_CONTENT);
153 service_set_mime(svcHandle, "image/jpg");
154 service_add_extra_data(svcHandle, "CALLER", "webkit");
156 int ret = service_send_launch_request(svcHandle, _cameraResultCb, this);
157 if (ret != SERVICE_ERROR_NONE) {
158 service_destroy(svcHandle);
162 service_destroy(svcHandle);
167 bool OpenPanel::_recordVideo()
169 service_h svcHandle = 0;
170 if (service_create(&svcHandle) < 0 || !svcHandle)
173 service_set_window(svcHandle, ecore_x_window_root_first_get());
174 service_set_operation(svcHandle, SERVICE_OPERATION_CREATE_CONTENT);
175 service_set_mime(svcHandle, "video/3gp");
176 service_add_extra_data(svcHandle, "CALLER", "webkit");
178 int ret = service_send_launch_request(svcHandle, _cameraResultCb, this);
179 if (ret != SERVICE_ERROR_NONE) {
180 service_destroy(svcHandle);
184 service_destroy(svcHandle);
189 bool OpenPanel::_recordVoice()
191 service_h svcHandle = 0;
192 if (service_create(&svcHandle) < 0 || !svcHandle)
195 service_set_operation(svcHandle, SERVICE_OPERATION_CREATE_CONTENT);
196 service_set_mime(svcHandle, "audio/amr");
198 int ret = service_send_launch_request(svcHandle, _cameraResultCb, this);
199 if (ret != SERVICE_ERROR_NONE) {
200 service_destroy(svcHandle);
204 service_destroy(svcHandle);
209 bool OpenPanel::openPanel(Evas_Object* ewkView, Eina_Bool allow_multiple_files, Eina_List* accepted_mime_types, const char* capture, void* userData)
213 Eina_Bool is_audio_extension_type = EINA_FALSE;
214 Eina_Bool is_video_extension_type = EINA_FALSE;
215 Eina_Bool is_image_extension_type = EINA_FALSE;
216 Eina_Bool is_audio_all_type = EINA_FALSE;
217 Eina_Bool is_video_all_type = EINA_FALSE;
218 Eina_Bool is_image_all_type = EINA_FALSE;
220 n = eina_list_count(accepted_mime_types);
222 char extensions[1024] = {0, };
223 char* accept_type = NULL;
225 /* set accept type */
226 for (i = 0; i < n; i++) {
227 accept_type = (char*)eina_list_nth(accepted_mime_types, i);
228 if (strncmp(accept_type, "audio/*", strlen("audio/*")) == 0) {
229 is_audio_all_type = EINA_TRUE;
230 } else if (strncmp(accept_type, "video/*", strlen("video/*")) == 0) {
231 is_video_all_type = EINA_TRUE;
232 } else if (strncmp(accept_type, "image/*", strlen("image/*")) == 0) {
233 is_image_all_type = EINA_TRUE;
234 } else if (strncmp(accept_type, "audio/", strlen("audio/")) == 0) {
235 is_audio_extension_type = EINA_TRUE;
236 accept_type = strchr(accept_type, '/') + 1;
237 strncat(extensions, accept_type, strlen(accept_type));
238 strncat(extensions, ";", 1);
239 } else if (strncmp(accept_type, "video/", strlen("video/")) == 0) {
240 is_video_extension_type = EINA_TRUE;
241 accept_type = strchr(accept_type, '/') + 1;
242 strncat(extensions, accept_type, strlen(accept_type));
243 strncat(extensions, ";", 1);
244 } else if (strncmp(accept_type, "image/", strlen("image/")) == 0) {
245 is_image_extension_type = EINA_TRUE;
246 accept_type = strchr(accept_type, '/') + 1;
247 strncat(extensions, accept_type, strlen(accept_type));
248 strncat(extensions, ";", 1);
253 if (accept_type == NULL) {
254 if (!strcmp(capture, "camera"))
255 return _capturePicture();
256 else if (!strcmp(capture, "camcorder"))
257 return _recordVideo();
258 else if (!strcmp(capture, "microphone"))
259 return _recordVoice();
261 if (strstr(accept_type, "image"))
262 return _capturePicture();
263 else if (strstr(accept_type, "video"))
264 return _recordVideo();
265 else if (strstr(accept_type, "audio"))
266 return _recordVoice();
270 service_h service = NULL;
271 if (service_create(&service) != SERVICE_ERROR_NONE)
273 service_add_extra_data(service, "path", "/opt/media");
275 if (is_audio_all_type && !is_video_all_type && !is_image_all_type && !is_video_extension_type && !is_image_extension_type) {
276 service_add_extra_data(service, "file_type", "SOUND");
277 } else if (is_video_all_type && !is_image_all_type && !is_audio_all_type && !is_image_extension_type && !is_audio_extension_type) {
278 service_add_extra_data(service, "file_type", "VIDEO");
279 } else if (is_image_all_type && !is_audio_all_type && !is_video_all_type && !is_audio_extension_type && !is_video_extension_type) {
280 service_add_extra_data(service, "file_type", "IMAGE");
281 } else if (is_audio_all_type && is_video_all_type && !is_image_all_type && !is_image_extension_type) {
282 service_add_extra_data(service, "file_type", "VS");
283 } else if (is_video_all_type && is_image_all_type && !is_audio_all_type && !is_audio_extension_type) {
284 service_add_extra_data(service, "file_type", "IV");
285 } else if (is_image_all_type && is_audio_all_type && !is_video_all_type && !is_video_extension_type) {
286 service_add_extra_data(service, "file_type", "IS");
287 } else if (!is_audio_all_type && !is_video_all_type && !is_image_all_type &&
288 (is_video_extension_type || is_image_extension_type || is_audio_extension_type)) {
289 service_add_extra_data(service, "file_type", extensions);
291 service_add_extra_data(service, "file_type", "ALL");
294 /* Set file select mode : multiple/single */
295 if (allow_multiple_files == TRUE){
296 service_add_extra_data(service, "select_type", "MULTI_FILE");
298 service_add_extra_data(service, "select_type", "SINGLE_FILE");
301 struct ug_cbs cbs = {0, 0, 0, 0};
302 cbs.layout_cb = layout_cb;
303 cbs.result_cb = result_cb;
304 cbs.destroy_cb = destroy_cb;
305 cbs.priv = (void*)this;
307 if(!ug_create(NULL, "myfile-efl", UG_MODE_FULLVIEW, service, &cbs))
310 service_destroy(service);
316 Evas_Object* OpenPanel::ewkView()
321 void OpenPanel::close()
325 } // namespace WebKit