02a32ee298ce730e143ed1312bb0dd0b95075eaa
[apps/home/gallery.git] / src / util / gl-ext-exec.c
1 /*
2   * Copyright 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://www.tizenopensource.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 #include <Elementary.h>
18 #include <app_service.h>
19 #include "gl-ext-exec.h"
20 #include "gl-debug.h"
21 #include "gallery.h"
22 #include "gl-db-handler.h"
23 #include "gl-util.h"
24
25
26 #define GL_APP_PKG_VIDEOPLAYER  "org.tizen.video-player"
27
28 #define GL_ARGV_VIDEO_LIST_TYPE "video_list_type"
29 #define GL_ARGV_VIDEO_ALL_FOLDER_VIDEO "all_folder_video"
30 #define GL_ARGV_VIDEO_FOLDER "folder"
31
32 #define GL_ARGV_VIDEO_ORDER_TYPE "order_type"
33 #define GL_ARGV_VIDEO_ORDER_DATE_DESC "date_desc"
34 #define GL_ARGV_VIDEO_START_POS "start_pos_time"
35
36 #define GL_ARGV_VIDEO_LAUNCH_APP "launching_application"
37 #define GL_ARGV_VIDEO_LAUNCH_GALLERY "gallery"
38
39 #define GL_ARGV_LAUNCH_TYPE "launch-type"
40 #define GL_ARGV_LAUNCH_SEND "send"
41 #define GL_ARGV_LAUNCH_FT_WITH_CONTACT "ft-with-contact"
42
43 #define GL_ARGV_FT_FILE "file"
44 #define GL_ARGV_PATH "path"
45 #define GL_ARGV_FT_CONTACT "contact"
46
47 #define GL_SEPERATOR_EMOLINK GL_SEPERATOR_BT
48 #define GL_SEPERATOR_FT ';'
49
50
51 //refer to imageviewer
52 static int
53 _gl_ext_launch_video_player(void *data, service_h service)
54 {
55         GL_CHECK_VAL(service, -1);
56         GL_CHECK_VAL(data, -1);
57         gl_item *gitem = (gl_item *)data;
58         GL_CHECK_VAL(gitem->ad, -1);
59         gl_appdata *ad = (gl_appdata *)gitem->ad;
60         GL_CHECK_VAL(gitem->item, -1);
61         GL_CHECK_VAL(gitem->item->uuid, -1);
62         GL_CHECK_VAL(gitem->item->file_url, -1);
63
64         const char *video_path = gitem->item->file_url;
65         /* Albums view */
66         gl_cluster *cur_cluster = ad->albuminfo.current_album;
67         if (cur_cluster && cur_cluster->cluster)
68         {
69                 gl_dbg("Album: %s", cur_cluster->cluster->display_name);
70                 if (!g_strcmp0(cur_cluster->cluster->uuid, GL_ALBUM_ALL_ID))
71                 {
72                         gl_dbg("All album");
73                         service_add_extra_data(service,
74                                                GL_ARGV_VIDEO_LIST_TYPE,
75                                                GL_ARGV_VIDEO_ALL_FOLDER_VIDEO);
76                         service_add_extra_data(service,
77                                                GL_ARGV_VIDEO_ORDER_TYPE,
78                                                GL_ARGV_VIDEO_ORDER_DATE_DESC);
79                         service_add_extra_data(service,
80                                                GL_ARGV_VIDEO_LAUNCH_APP,
81                                                GL_ARGV_VIDEO_LAUNCH_GALLERY);
82                 }
83                 else if (cur_cluster->cluster->type == MINFO_PHONE ||
84                                 cur_cluster->cluster->type == MINFO_MMC)
85                 {
86                         gl_dbg("Real album");
87                         service_add_extra_data(service,
88                                                GL_ARGV_VIDEO_LIST_TYPE,
89                                                GL_ARGV_VIDEO_FOLDER);
90                         service_add_extra_data(service,
91                                                GL_ARGV_VIDEO_ORDER_TYPE,
92                                                GL_ARGV_VIDEO_ORDER_DATE_DESC);
93                         service_add_extra_data(service,
94                                                GL_ARGV_VIDEO_LAUNCH_APP,
95                                                GL_ARGV_VIDEO_LAUNCH_GALLERY);
96                 }
97                 else
98                 {
99                         gl_dbgE("Wrong type!");
100                 }
101         }
102         else
103         {
104                 /* Fixme: return or not? */
105                 gl_dbgE("Invalid current album, return?");
106         }
107
108         service_add_extra_data(service, GL_ARGV_PATH, video_path);
109         service_set_operation(service, SERVICE_OPERATION_VIEW);
110         service_set_package(service, GL_APP_PKG_VIDEOPLAYER);
111         if (service_send_launch_request(service, NULL, NULL) == SERVICE_ERROR_NONE)
112                 return 0;
113         else
114                 return -1;
115 }
116
117 static int
118 _gl_ext_compose_exec_cmd(void *data, gl_ext_app_type type,
119         char *path, char **pkg_name)
120 {
121         GL_CHECK_VAL(data, -1);
122         gl_dbg("type:%d, path:%s", type, path);
123
124         switch (type)
125         {
126         case GL_APP_VIDEOPLAYER:
127                 GL_CHECK_VAL(path, -1);
128                 *pkg_name = GL_APP_PKG_VIDEOPLAYER;
129                 break;
130         default:
131                 *pkg_name = NULL;
132         }
133
134         return 0;
135 }
136
137 int
138 gl_ext_exec(void *data, gl_ext_app_type type)
139 {
140         GL_CHECK_VAL(data, GL_LAUNCH_FAIL);
141         gl_item *gitem = (gl_item *)data;
142         GL_CHECK_VAL(gitem->ad, GL_LAUNCH_FAIL);
143         gl_appdata *ad = (gl_appdata *)gitem->ad;
144         GL_CHECK_VAL(gitem->item, GL_LAUNCH_FAIL);
145         GL_CHECK_VAL(gitem->item->file_url, GL_LAUNCH_FAIL);
146         char *path = gitem->item->file_url;
147         service_h service = NULL;
148         char *pkg_name = NULL;
149
150         if (ad->uginfo.app_called_by_me)
151         {
152                 gl_dbg("APP launched, return.");
153                 return GL_LAUNCH_FAIL;
154         }
155
156         _gl_ext_compose_exec_cmd(ad, type, path, &pkg_name);
157         GL_CHECK_VAL(gitem->item->file_url, GL_LAUNCH_FAIL);
158
159         service_create(&service);
160         GL_CHECK_VAL(service, GL_LAUNCH_FAIL);
161
162         int ret = 0;
163         if (type == GL_APP_VIDEOPLAYER) {
164                 if (path == NULL) {
165                         service_destroy(service);
166                         return GL_LAUNCH_FAIL;
167                 }
168                 if (_gl_ext_launch_video_player(data, service) != 0) {
169                         service_destroy(service);
170                         return GL_LAUNCH_FAIL;
171                 }
172         } else {
173                 service_set_operation(service, SERVICE_OPERATION_DEFAULT);
174                 service_set_package(service, pkg_name);
175                 ret = service_send_launch_request(service, NULL, NULL);
176                 if (ret != SERVICE_ERROR_NONE) {
177                         service_destroy(service);
178                         gl_dbgE("service_send_launch_request failed[%d]!", ret);
179                         return GL_LAUNCH_FAIL;
180                 }
181         }
182
183         ret = service_destroy(service);
184         if (ret != SERVICE_ERROR_NONE) {
185                 ad->uginfo.app_called_by_me = true;
186                 return GL_LAUNCH_SUCCESS;
187         } else {
188                 return GL_LAUNCH_FAIL;
189         }
190 }