44958fdafb74974c183f670f68f1b797dccdefde
[apps/core/preloaded/ug-image-viewer-efl.git] / main / src / ug-image-viewer.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
18 #include <Elementary.h>
19 #include <ui-gadget-module.h>
20 #include <Ecore_X.h>            /*EFL*/
21
22 #include "ivug-common.h"        //common
23 #include "ivug-util.h"
24 #include "ivug-main.h"
25 #include "ivug-main-view.h"
26 #include "ivug-setas-view.h"
27 #include "ivug-details-view.h"
28 #include "ivug-slider.h"
29
30 #include "ug-image-viewer.h"
31
32 #include "ivug-data.h"
33 #include "ivug-parameter.h"
34
35 static Evas_Object *create_fullview(Evas_Object *win, struct ug_data *ugd)
36 {
37         Evas_Object *base;
38
39         /* Create Full view */
40         base = elm_layout_add(win);
41
42         Eina_Bool ret;
43
44         ret = elm_layout_file_set(base , EDJ_PATH"/ivug-base.edj", "ivug_base" );
45
46         if ( ret == EINA_FALSE)
47         {
48                 MSG_IMAGEVIEW_HIGH("Cannot set layout. EDJ=%s Group=%s", EDJ_PATH"/ivug-base.edj", "ivug_base");
49                 evas_object_del(base);
50
51                 return NULL;
52         }
53
54         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
55         evas_object_size_hint_align_set(base, EVAS_HINT_FILL, EVAS_HINT_FILL);
56
57         elm_win_resize_object_add(win, base);
58
59         return base;
60 }
61
62 static Evas_Object *create_frameview(Evas_Object *parent, struct ug_data *ugd)
63 {
64         Evas_Object *base;
65
66         /* Create Frame view */
67         base = elm_layout_add(parent);
68         elm_layout_theme_set(base, "layout", "application", "default");
69
70         return base;
71 }
72
73 static void *on_create(struct ui_gadget *ug, enum ug_mode mode, bundle *data, void *priv)
74 {
75         struct ug_data *ugd;
76
77         PERF_CHECK_BEGIN("On Create");
78
79         MSG_IMAGEVIEW_HIGH("Image Viewer : %s ug=0x%08x", __func__, ug);
80
81         if (!ug || !priv)
82         {
83                 MSG_IMAGEVIEW_ERROR("Error. ug=0x%08x priv=0x%08x", ug, priv);
84                 return NULL;
85         }
86
87         ugd = priv;
88 /*
89         If application call this US, ug_get_parent_layout() returns window ID not layout.
90         Probably, UG bugs.
91 */
92         ugd->parent_layout = ug_get_parent_layout(ug);  //parent's layout
93         if (!ugd->parent_layout)
94         {
95                 MSG_IMAGEVIEW_ERROR("Cannot get parent's layout. parent=0x%08x", ugd->parent_layout);
96                 return NULL;
97         }
98
99         PERF_CHECK_BEGIN(LVL1 "main_init");
100         //init
101         if (!ivug_main_init(ug))
102         {
103                 MSG_IMAGEVIEW_ERROR("ivug_main_init error");
104                 return NULL;
105         }
106         PERF_CHECK_END(LVL1 "main_init");
107
108         PERF_CHECK_BEGIN(LVL1 "parse bundle");
109
110         ugd->ivug_param = ivug_param_create_from_bundle(data);
111         if (  ugd->ivug_param == NULL )
112         {
113                 MSG_IMAGEVIEW_ERROR("Cannot parse parameter");
114                 ivug_main_deinit(ug);
115                 return NULL;
116         }
117         PERF_CHECK_END(LVL1 "parse bundle");
118
119         //create base
120         if (mode == UG_MODE_FULLVIEW)
121         {
122                 MSG_IMAGEVIEW_MED("create base layout for FullView");
123                 ugd->base = create_fullview(ug_get_window(), ugd);
124         }
125         else
126         {
127                 MSG_IMAGEVIEW_MED("create base layout for FrameView");
128                 ugd->base = create_frameview(ug_get_window(), ugd);
129         }
130
131         if ( ugd->base == NULL )
132         {
133                 MSG_IMAGEVIEW_ERROR("Cannot create base view");
134                 return NULL;
135         }
136
137         if(ugd->ivug_param->mode == IVUG_MODE_SETAS)
138         {
139                 MSG_IMAGEVIEW_HIGH("UG types=%d", ugd->ivug_param->setas_type);
140
141                 if(ugd->ivug_param->setas_type == IVUG_SET_AS_UG_TYPE_WALLPAPER)
142                 {
143                         // From Wall paper in Setting
144                         ugd->setas_view = ivug_setas_view_screen_ug_create(ugd->base, ugd->ivug_param->filepath);
145                 }
146                 else
147                 {
148                         MSG_IMAGEVIEW_ERROR("Invalid SetAS UG Type:%d", ugd->ivug_param->setas_type);
149                         return NULL;
150                 }
151
152                 if(ugd->setas_view == NULL)
153                 {
154                         MSG_IMAGEVIEW_ERROR("SetAS UG creation failed Type:%d", ugd->ivug_param->setas_type);
155                         ivug_main_deinit(ug);
156                         if (ugd->base)
157                         {
158                                 evas_object_del(ugd->base);
159                                 ugd->base = NULL;
160                         }
161                         return NULL;
162                 }
163
164                 Evas_Object *layout = ivug_setas_view_object_get(ugd->setas_view);
165
166                 elm_object_part_content_set(ugd->base, "elm.swallow.content", layout);  //swallow
167                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
168
169                 evas_object_show(layout);
170         }
171         else
172         {
173                 PERF_CHECK_BEGIN(LVL1 "main_view_create");
174
175                 ugd->main_view = ivug_main_view_create(ugd->base, ugd->ivug_param->mode, ugd->ivug_param->view_by);
176
177                 if (ugd->main_view == NULL)     //set main view.
178                 {
179                         MSG_IMAGEVIEW_ERROR("Main View Layout Lading Fail");
180                         ivug_main_deinit(ug);
181                         if (ugd->base)
182                         {
183                                 evas_object_del(ugd->base);
184                                 ugd->base = NULL;
185                         }
186                         return NULL;
187                 }
188
189                 PERF_CHECK_END(LVL1 "main_view_create");
190
191 // Load list.
192                 if ( ivug_main_view_load_list(ugd->main_view, ugd->ivug_param) == false)
193                 {
194                         MSG_IMAGEVIEW_ERROR("Cannot load media list.");
195                         // Need popup?
196                         ivug_main_deinit(ug);
197                         if (ugd->base)
198                         {
199                                 evas_object_del(ugd->base);
200                                 ugd->base = NULL;
201                         }
202                         return NULL;
203
204                 }
205
206                 Evas_Object *layout = ivug_main_view_object_get(ugd->main_view);
207
208                 elm_object_part_content_set(ugd->base, "elm.swallow.content", layout);  //swallow
209                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
210
211                 evas_object_show(layout);
212
213         }
214
215         PERF_CHECK_END("On Create");
216
217         return ugd->base;
218 }
219
220 static void on_start(struct ui_gadget *ug, bundle *data, void *priv)
221 {
222         MSG_IMAGEVIEW_HIGH("Image Viewer : %s", __func__);
223 }
224
225 static void on_pause(struct ui_gadget *ug, bundle *data, void *priv)
226 {
227         MSG_IMAGEVIEW_HIGH("Image Viewer : %s", __func__);
228
229         if (!ug || !priv)
230         {
231                 MSG_IMAGEVIEW_ERROR("Invalid UG. UG=0x%08x Priv=0x%08x", ug, priv);
232                 return ;
233         }
234
235         struct ug_data *ugd = (struct ug_data *)priv;
236
237         if ( ugd->main_view )
238         {
239                 ivug_slider_stop_slide_show(ugd->main_view->slider);
240         }
241
242 }
243
244 static void on_resume(struct ui_gadget *ug, bundle *data, void *priv)
245 {
246         MSG_IMAGEVIEW_HIGH("Image Viewer : %s", __func__);
247
248         if (!ug || !priv)
249         {
250                 IVUG_DEBUG_MSG("Invalid UG. UG=0x%08x Priv=0x%08x", ug, priv);
251                 return ;
252         }
253
254         struct ug_data *ugd = (struct ug_data *)priv;
255
256         if ( ugd->main_view )
257         {
258                 ivug_main_view_update(ugd->main_view);
259
260 //              ivug_slider_resume_slide_show(ugd->main_view->slider);
261         }
262
263 }
264
265 static void on_destroy(struct ui_gadget *ug, bundle *data, void *priv)
266 {
267         MSG_IMAGEVIEW_HIGH("Image Viewer : %s UG=0x%08x", __func__, ug);
268
269         PERF_CHECK_BEGIN("On Destroy");
270
271         if (!ug || !priv)
272         {
273                 MSG_IMAGEVIEW_ERROR("Invalid UG. UG=0x%08x Priv=0x%08x", ug, priv);
274                 return ;
275         }
276
277         struct ug_data *ugd = (struct ug_data *)priv;
278
279         MSG_IMAGEVIEW_HIGH("On Destroy : ug=0x%08x", ug);
280         //destroy main view.
281         if ( ugd->main_view )
282         {
283                 ivug_main_view_destroy(ugd->main_view);
284                 ugd->main_view = NULL;
285         }
286
287         if(ugd->setas_view)
288         {
289                 ivug_setas_view_destroy(ugd->setas_view);
290                 ugd->setas_view = NULL;
291         }
292
293         //delete param.
294         if(ugd->ivug_param)
295         {
296                 ivug_param_delete(ugd->ivug_param);
297                 ugd->ivug_param = NULL;
298         }
299
300         //finalize data
301         if ( !ivug_main_deinit(ug))
302         {
303                 MSG_IMAGEVIEW_ERROR("ivug_main_deinit failed");
304         }
305
306         if (ugd->base)
307         {
308                 evas_object_del(ugd->base);
309                 ugd->base = NULL;
310         }
311
312         MSG_IMAGEVIEW_HIGH("Destroyed all ug");
313
314         PERF_CHECK_END("On Destroy");
315
316 }
317
318
319 static void on_message(struct ui_gadget *ug, bundle *msg, bundle *data, void *priv)
320 {
321         MSG_IMAGEVIEW_HIGH("Image Viewer : %s UG=0x%08x", __func__, ug);        //on message
322 }
323
324 static void on_event(struct ui_gadget *ug, enum ug_event event, bundle *data, void *priv)
325 {
326         if (!ug || !priv)
327         {
328                 MSG_IMAGEVIEW_ERROR("Invalid UG. UG=0x%08x Priv=0x%08x", ug, priv);
329                 return;
330         }
331         MSG_IMAGEVIEW_HIGH("Image Viewer : %s UG=0x%08x", __func__, ug);        //on message
332
333         //struct ug_data *ugd = (struct ug_data *)priv;
334
335         switch (event) {
336         case UG_EVENT_LOW_MEMORY:
337                 MSG_IMAGEVIEW_HIGH("Get Event : Low Memory");
338                 break;
339         case UG_EVENT_LOW_BATTERY:
340                 MSG_IMAGEVIEW_HIGH("Get Event : Low battery");
341                 break;
342         case UG_EVENT_LANG_CHANGE:
343                 MSG_IMAGEVIEW_HIGH("Get Event : Language changed");
344                 break;
345         default:
346                 MSG_IMAGEVIEW_ERROR("Unknown event type : %d", event);
347                 break;
348         }
349 }
350
351 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
352 {
353         struct ug_data *ugd;
354
355         MSG_IMAGEVIEW_HIGH("UG_MODULE_INIT");
356
357         if (!ops)
358         {
359                 MSG_IMAGEVIEW_ERROR("OPS Pointer is NULL");
360                 return -1;
361         }
362
363         ugd = calloc(1, sizeof(struct ug_data));        //alloc ug_data memory
364         if (!ugd)
365         {
366                 MSG_IMAGEVIEW_ERROR("Cannot allocate memory.");
367                 return -1;
368         }
369
370         PERF_INIT();
371
372         ops->create = on_create;
373         ops->start = on_start;
374         ops->pause = on_pause;
375         ops->resume = on_resume;
376         ops->destroy = on_destroy;
377         ops->message = on_message;
378         ops->event = on_event;
379         ops->priv = ugd;
380         ops->opt = UG_OPT_INDICATOR_ENABLE;
381
382         return 0;
383 }
384
385 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
386 {
387         struct ug_data *ugd;
388         if (!ops)
389         {
390                 MSG_IMAGEVIEW_ERROR("OPS Pointer is NULL");
391                 return;
392         }
393
394         ugd = ops->priv;
395
396         if (ugd)
397         {
398                 free(ugd);
399         }
400
401         MSG_IMAGEVIEW_HIGH("UG_MODULE_EXIT");
402
403         PERF_SHOW_RESULT(stdout);
404
405         PERF_DEINIT();
406
407 }
408
409
410 #define _CONSTRUCTOR __attribute__ ((constructor))
411 #define _DESTRUCTOR __attribute__ ((destructor))
412
413 void _CONSTRUCTOR _DLLInit(void)
414 {
415         printf("Image Viewer - Called constructor\n");
416 }
417
418 void _DESTRUCTOR _DLLExit(void)
419 {
420         printf("Image Viewer - Called destructor\n");
421
422 }
423
424
425 int main()
426 {
427 /*      For detecting undefined symbol */
428         return -1;
429 }
430