apply FSL(Flora Software License)
[apps/home/gallery.git] / libug / libug-gallery-efl / src / ge-ext-ug-load.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 <app_service.h>
18 #include "ge-ext-ug-load.h"
19 #include "ge-debug.h"
20 #include "ge-ui-util.h"
21 #include "ge-util.h"
22 #include "ge-albums.h"
23 #include "ge-gridview.h"
24
25 #define GE_IV_UG_NAME "image-viewer-efl"
26
27 static bool ge_destroy_me = false;
28
29 static void _ge_ext_destroy_me(ge_ugdata *ugd)
30 {
31         ge_dbg("");
32         GE_CHECK(ugd);
33         GE_CHECK(ugd->ug_called_by_me);
34         GE_CHECK(ugd->ug);
35         GE_CHECK(ugd->bundle);
36         bool send_result = false;
37
38         if (_ge_ug_iv_get())
39         {
40                 _ge_ug_iv_set(false);
41         }
42
43         if(ge_destroy_me == false)
44         {
45                 ug_destroy(ugd->ug_called_by_me);
46                 ugd->ug_called_by_me = NULL;
47         }
48         if(ugd->file_select_mode == GE_File_Select_Setas)
49         {
50                 if(ugd->file_setas_image_path)
51                 {
52                         ge_dbg("GE_SETAS_IMAGE_PATH:%s", ugd->file_setas_image_path);
53                         bundle_add(ugd->bundle, GE_SETAS_IMAGE_PATH, ugd->file_setas_image_path);
54
55                         free(ugd->file_setas_image_path);
56                         ugd->file_setas_image_path = NULL;
57                         send_result = true;
58                 }
59
60                 if(ugd->file_setas_crop_image_path &&
61                         ugd->file_select_setas_mode == GE_File_Select_Setas_CallerID)
62                 {
63                         ge_dbg("GE_SETAS_CALLERID_CROP_IMAGE_PATH:%s", ugd->file_setas_crop_image_path);
64                         bundle_add(ugd->bundle, GE_SETAS_CALLERID_CROP_IMAGE_PATH, ugd->file_setas_crop_image_path);
65
66                         free(ugd->file_setas_crop_image_path);
67                         ugd->file_setas_crop_image_path = NULL;
68                         send_result = true;
69                 }
70
71                 if(send_result)
72                 {
73                         ge_dbg("Call ug_send_result() to send result.");
74                         ug_send_result(ugd->ug, ugd->bundle);
75                 }
76         }
77
78         if(ge_destroy_me)
79         {
80                 ge_dbg("Seting is appllied, destroy gallery UG.");
81                 ge_destroy_me = false;
82                 ug_destroy_me(ugd->ug);//close selection ug
83                 ugd->ug_called_by_me = NULL;
84         }
85         else
86         {
87                 ge_dbg("Cancel button tapped, back to thumbnails view.");
88         }
89 }
90
91 static void _ge_ext_iv_layout_cb(struct ui_gadget *ug, enum ug_mode mode, void* priv)
92 {
93         ge_dbg("");
94         GE_CHECK(priv);
95         GE_CHECK(ug);
96
97         Evas_Object *base = (Evas_Object *) ug_get_layout(ug);
98         if (!base)
99         {
100                 ug_destroy(ug);
101                 return;
102         }
103
104         ge_ugdata *ugd = (ge_ugdata *)priv;
105
106         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
107         elm_win_resize_object_add(ugd->win, base);
108         evas_object_show(base);
109 }
110
111 static void _ge_ext_iv_result_cb(struct ui_gadget *ug, bundle *result, void *priv)
112 {
113         ge_dbg("");
114         GE_CHECK(priv);
115         GE_CHECK(result);
116         ge_ugdata *ugd = (ge_ugdata *)priv;
117         const char* path = NULL;
118
119         if(ugd->file_select_mode == GE_File_Select_Setas)
120         {
121                 path = bundle_get_val(result, GE_IMAGEVIEWER_IMAGE_PATH);
122                 ge_dbg("SETAS_IMAGE_PATH");
123                 ge_destroy_me = true;
124                 if(path)
125                 {
126                         ge_dbg(":%s", path);
127                         ugd->file_setas_image_path = strdup(path);
128                 }
129
130                 if(ugd->file_select_setas_mode == GE_File_Select_Setas_CallerID)
131                 {
132                         path = bundle_get_val(result, GE_IMAGEVIEWER_CROP_IMAGE_PATH);
133                         ge_dbg("CALLERID_CROP_IMAGE_PATH");
134                         if(path)
135                         {
136                                 ge_dbg(":%s", path);
137                                 ugd->file_setas_crop_image_path = strdup(path);
138                         }
139                 }
140         }
141
142         const char *error_state = bundle_get_val(result, GE_IMAGEVIEWER_RETURN_ERROR);
143         if (error_state)
144         {
145                 ge_dbg("error string : %s", error_state);
146
147                 if (!g_strcmp0(error_state, "not_supported_file_type")) {
148                         ge_destroy_me = FALSE;
149                         ge_item* cur_item = _ge_get_current_item();
150                         if(cur_item == NULL || cur_item->item == NULL ||
151                            cur_item->item->file_url == NULL) {
152                                 ge_dbgE("current item is NULL");
153                                 return;
154                         }
155                         service_h service;
156                         service_create(&service);
157                         GE_CHECK(service);
158                         service_set_operation(service, SERVICE_OPERATION_VIEW);
159                         service_set_uri(service, cur_item->item->file_url);
160                         service_send_launch_request(service, NULL, NULL);
161                         service_destroy(service);
162                 }
163         }
164 }
165
166 static void _ge_ext_iv_destroy_cb(struct ui_gadget *ug, void *priv)
167 {
168         ge_dbg("");
169         GE_CHECK(priv);
170         ge_ugdata *ad = (ge_ugdata *) priv;
171
172         _ge_ext_destroy_me(ad);
173 }
174
175 int ge_ext_load_iv_ug(ge_ugdata* ugd)
176 {
177         ge_dbg("");
178         GE_CHECK_VAL(ugd, -1);
179
180         struct ug_cbs cbs;
181         struct ui_gadget* ug = NULL;
182         bundle* param = NULL;
183
184         if(ugd->ug_called_by_me)
185         {
186                 ge_dbg("Already exits some UG called by me");
187                 return -1;
188         }
189
190         ge_item* cur_item = _ge_get_current_item();
191         if(cur_item == NULL || cur_item->item == NULL)
192         {
193                 ge_dbg("current item is NULL");
194                 return -1;
195         }
196         memset(&cbs,0x00,sizeof(struct ug_cbs));
197         cbs.layout_cb = _ge_ext_iv_layout_cb;
198         cbs.result_cb = _ge_ext_iv_result_cb;
199         cbs.destroy_cb = _ge_ext_iv_destroy_cb;
200         cbs.priv = ugd;
201
202         param = bundle_create();
203         GE_CHECK_VAL(param, -1);
204
205         _ge_ug_iv_set(true);
206
207         bundle_add(param, "View Mode", "SETAS" );
208         bundle_add(param, "Path", cur_item->item->file_url);
209
210         if(ugd->file_select_setas_mode == GE_File_Select_Setas_Wallpaper)
211         {
212                 bundle_add(param, "Setas type", "Wallpaper");
213
214                 if(ugd->file_setas_homescreen_path)
215                 {
216                         ge_dbg("homescreen_path:%s", ugd->file_setas_homescreen_path);
217                         bundle_add(param, GE_IMAGEVIEWER_HOMESCREEN_PATH, ugd->file_setas_homescreen_path);
218                         free(ugd->file_setas_homescreen_path);
219                         ugd->file_setas_homescreen_path = NULL;
220                 }
221
222                 if(ugd->file_setas_lockscreen_path)
223                 {
224                         ge_dbg("lockscreen_path:%s", ugd->file_setas_lockscreen_path);
225                         bundle_add(param, GE_IMAGEVIEWER_LOCKSCREEN_PATH, ugd->file_setas_lockscreen_path);
226                         free(ugd->file_setas_lockscreen_path);
227                         ugd->file_setas_lockscreen_path = NULL;
228                 }
229         }
230         else if(ugd->file_select_setas_mode == GE_File_Select_Setas_CallerID)
231         {
232                 bundle_add(param, "Setas type", "CallerID");
233                 if(ugd->file_setas_callid_size)
234                 {
235                         ge_dbg("callerid_size:%s", ugd->file_setas_callid_size);
236                         bundle_add(param, GE_IMAGEVIEWER_CALLERID_SIZE, ugd->file_setas_callid_size);
237                         free(ugd->file_setas_callid_size);
238                         ugd->file_setas_callid_size = NULL;
239                 }
240
241                 if(ugd->file_setas_callid_path)
242                 {
243                         ge_dbg("callerid_path:%s", ugd->file_setas_callid_path);
244                         bundle_add(param, GE_IMAGEVIEWER_CALLERID_PATH, ugd->file_setas_callid_path);
245                         free(ugd->file_setas_callid_path);
246                         ugd->file_setas_callid_path = NULL;
247                 }
248         }
249         ug = ug_create(ugd->ug, GE_IV_UG_NAME, UG_MODE_FULLVIEW, param, &cbs);
250         ugd->ug_called_by_me = ug;
251         bundle_free(param);
252
253         return 0;
254 }
255