summaryrefslogtreecommitdiff
path: root/main/src/ug-image-viewer.c
blob: 44958fdafb74974c183f670f68f1b797dccdefde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	  http://www.tizenopensource.org/license
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <Elementary.h>
#include <ui-gadget-module.h>
#include <Ecore_X.h> 		/*EFL*/

#include "ivug-common.h"	//common
#include "ivug-util.h"
#include "ivug-main.h"
#include "ivug-main-view.h"
#include "ivug-setas-view.h"
#include "ivug-details-view.h"
#include "ivug-slider.h"

#include "ug-image-viewer.h"

#include "ivug-data.h"
#include "ivug-parameter.h"

static Evas_Object *create_fullview(Evas_Object *win, struct ug_data *ugd)
{
	Evas_Object *base;

	/* Create Full view */
	base = elm_layout_add(win);

	Eina_Bool ret;

	ret = elm_layout_file_set(base , EDJ_PATH"/ivug-base.edj", "ivug_base" );

	if ( ret == EINA_FALSE)
	{
		MSG_IMAGEVIEW_HIGH("Cannot set layout. EDJ=%s Group=%s", EDJ_PATH"/ivug-base.edj", "ivug_base");
		evas_object_del(base);

		return NULL;
	}

	evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(base, EVAS_HINT_FILL, EVAS_HINT_FILL);

	elm_win_resize_object_add(win, base);

	return base;
}

static Evas_Object *create_frameview(Evas_Object *parent, struct ug_data *ugd)
{
	Evas_Object *base;

	/* Create Frame view */
	base = elm_layout_add(parent);
	elm_layout_theme_set(base, "layout", "application", "default");

	return base;
}

static void *on_create(struct ui_gadget *ug, enum ug_mode mode, bundle *data, void *priv)
{
	struct ug_data *ugd;

	PERF_CHECK_BEGIN("On Create");

	MSG_IMAGEVIEW_HIGH("Image Viewer : %s ug=0x%08x", __func__, ug);

	if (!ug || !priv)
	{
		MSG_IMAGEVIEW_ERROR("Error. ug=0x%08x priv=0x%08x", ug, priv);
		return NULL;
	}

	ugd = priv;
/*
	If application call this US, ug_get_parent_layout() returns window ID not layout.
	Probably, UG bugs.
*/
	ugd->parent_layout = ug_get_parent_layout(ug);	//parent's layout
	if (!ugd->parent_layout)
	{
		MSG_IMAGEVIEW_ERROR("Cannot get parent's layout. parent=0x%08x", ugd->parent_layout);
		return NULL;
	}

	PERF_CHECK_BEGIN(LVL1 "main_init");
	//init
	if (!ivug_main_init(ug))
	{
		MSG_IMAGEVIEW_ERROR("ivug_main_init error");
		return NULL;
	}
	PERF_CHECK_END(LVL1 "main_init");

	PERF_CHECK_BEGIN(LVL1 "parse bundle");

	ugd->ivug_param = ivug_param_create_from_bundle(data);
	if (  ugd->ivug_param == NULL )
	{
		MSG_IMAGEVIEW_ERROR("Cannot parse parameter");
		ivug_main_deinit(ug);
		return NULL;
	}
	PERF_CHECK_END(LVL1 "parse bundle");

	//create base
	if (mode == UG_MODE_FULLVIEW)
	{
		MSG_IMAGEVIEW_MED("create base layout for FullView");
		ugd->base = create_fullview(ug_get_window(), ugd);
	}
	else
	{
		MSG_IMAGEVIEW_MED("create base layout for FrameView");
		ugd->base = create_frameview(ug_get_window(), ugd);
	}

	if ( ugd->base == NULL )
	{
		MSG_IMAGEVIEW_ERROR("Cannot create base view");
		return NULL;
	}

	if(ugd->ivug_param->mode == IVUG_MODE_SETAS)
	{
		MSG_IMAGEVIEW_HIGH("UG types=%d", ugd->ivug_param->setas_type);

		if(ugd->ivug_param->setas_type == IVUG_SET_AS_UG_TYPE_WALLPAPER)
		{
			// From Wall paper in Setting
			ugd->setas_view = ivug_setas_view_screen_ug_create(ugd->base, ugd->ivug_param->filepath);
		}
		else
		{
			MSG_IMAGEVIEW_ERROR("Invalid SetAS UG Type:%d", ugd->ivug_param->setas_type);
			return NULL;
		}

		if(ugd->setas_view == NULL)
		{
			MSG_IMAGEVIEW_ERROR("SetAS UG creation failed Type:%d", ugd->ivug_param->setas_type);
			ivug_main_deinit(ug);
			if (ugd->base)
			{
				evas_object_del(ugd->base);
				ugd->base = NULL;
			}
			return NULL;
		}

		Evas_Object *layout = ivug_setas_view_object_get(ugd->setas_view);

		elm_object_part_content_set(ugd->base, "elm.swallow.content", layout);	//swallow
		evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

		evas_object_show(layout);
	}
	else
	{
		PERF_CHECK_BEGIN(LVL1 "main_view_create");

		ugd->main_view = ivug_main_view_create(ugd->base, ugd->ivug_param->mode, ugd->ivug_param->view_by);

		if (ugd->main_view == NULL)	//set main view.
		{
			MSG_IMAGEVIEW_ERROR("Main View Layout Lading Fail");
			ivug_main_deinit(ug);
			if (ugd->base)
			{
				evas_object_del(ugd->base);
				ugd->base = NULL;
			}
			return NULL;
		}

		PERF_CHECK_END(LVL1 "main_view_create");

// Load list.
		if ( ivug_main_view_load_list(ugd->main_view, ugd->ivug_param) == false)
		{
			MSG_IMAGEVIEW_ERROR("Cannot load media list.");
			// Need popup?
			ivug_main_deinit(ug);
			if (ugd->base)
			{
				evas_object_del(ugd->base);
				ugd->base = NULL;
			}
			return NULL;

		}

		Evas_Object *layout = ivug_main_view_object_get(ugd->main_view);

		elm_object_part_content_set(ugd->base, "elm.swallow.content", layout);	//swallow
		evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

		evas_object_show(layout);

	}

	PERF_CHECK_END("On Create");

	return ugd->base;
}

static void on_start(struct ui_gadget *ug, bundle *data, void *priv)
{
	MSG_IMAGEVIEW_HIGH("Image Viewer : %s", __func__);
}

static void on_pause(struct ui_gadget *ug, bundle *data, void *priv)
{
	MSG_IMAGEVIEW_HIGH("Image Viewer : %s", __func__);

	if (!ug || !priv)
	{
		MSG_IMAGEVIEW_ERROR("Invalid UG. UG=0x%08x Priv=0x%08x", ug, priv);
		return ;
	}

	struct ug_data *ugd = (struct ug_data *)priv;

	if ( ugd->main_view )
	{
		ivug_slider_stop_slide_show(ugd->main_view->slider);
	}

}

static void on_resume(struct ui_gadget *ug, bundle *data, void *priv)
{
	MSG_IMAGEVIEW_HIGH("Image Viewer : %s", __func__);

	if (!ug || !priv)
	{
		IVUG_DEBUG_MSG("Invalid UG. UG=0x%08x Priv=0x%08x", ug, priv);
		return ;
	}

	struct ug_data *ugd = (struct ug_data *)priv;

	if ( ugd->main_view )
	{
		ivug_main_view_update(ugd->main_view);

//		ivug_slider_resume_slide_show(ugd->main_view->slider);
	}

}

static void on_destroy(struct ui_gadget *ug, bundle *data, void *priv)
{
	MSG_IMAGEVIEW_HIGH("Image Viewer : %s UG=0x%08x", __func__, ug);

	PERF_CHECK_BEGIN("On Destroy");

	if (!ug || !priv)
	{
		MSG_IMAGEVIEW_ERROR("Invalid UG. UG=0x%08x Priv=0x%08x", ug, priv);
		return ;
	}

	struct ug_data *ugd = (struct ug_data *)priv;

	MSG_IMAGEVIEW_HIGH("On Destroy : ug=0x%08x", ug);
	//destroy main view.
	if ( ugd->main_view )
	{
		ivug_main_view_destroy(ugd->main_view);
		ugd->main_view = NULL;
	}

	if(ugd->setas_view)
	{
		ivug_setas_view_destroy(ugd->setas_view);
		ugd->setas_view = NULL;
	}

	//delete param.
	if(ugd->ivug_param)
	{
		ivug_param_delete(ugd->ivug_param);
		ugd->ivug_param = NULL;
	}

	//finalize data
	if ( !ivug_main_deinit(ug))
	{
		MSG_IMAGEVIEW_ERROR("ivug_main_deinit failed");
	}

	if (ugd->base)
	{
		evas_object_del(ugd->base);
		ugd->base = NULL;
	}

	MSG_IMAGEVIEW_HIGH("Destroyed all ug");

	PERF_CHECK_END("On Destroy");

}


static void on_message(struct ui_gadget *ug, bundle *msg, bundle *data, void *priv)
{
	MSG_IMAGEVIEW_HIGH("Image Viewer : %s UG=0x%08x", __func__, ug);	//on message
}

static void on_event(struct ui_gadget *ug, enum ug_event event, bundle *data, void *priv)
{
	if (!ug || !priv)
	{
		MSG_IMAGEVIEW_ERROR("Invalid UG. UG=0x%08x Priv=0x%08x", ug, priv);
		return;
	}
	MSG_IMAGEVIEW_HIGH("Image Viewer : %s UG=0x%08x", __func__, ug);	//on message

	//struct ug_data *ugd = (struct ug_data *)priv;

	switch (event) {
	case UG_EVENT_LOW_MEMORY:
		MSG_IMAGEVIEW_HIGH("Get Event : Low Memory");
		break;
	case UG_EVENT_LOW_BATTERY:
		MSG_IMAGEVIEW_HIGH("Get Event : Low battery");
		break;
	case UG_EVENT_LANG_CHANGE:
		MSG_IMAGEVIEW_HIGH("Get Event : Language changed");
		break;
	default:
		MSG_IMAGEVIEW_ERROR("Unknown event type : %d", event);
		break;
	}
}

UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
{
	struct ug_data *ugd;

	MSG_IMAGEVIEW_HIGH("UG_MODULE_INIT");

	if (!ops)
	{
		MSG_IMAGEVIEW_ERROR("OPS Pointer is NULL");
		return -1;
	}

	ugd = calloc(1, sizeof(struct ug_data));	//alloc ug_data memory
	if (!ugd)
	{
		MSG_IMAGEVIEW_ERROR("Cannot allocate memory.");
		return -1;
	}

	PERF_INIT();

	ops->create = on_create;
	ops->start = on_start;
	ops->pause = on_pause;
	ops->resume = on_resume;
	ops->destroy = on_destroy;
	ops->message = on_message;
	ops->event = on_event;
	ops->priv = ugd;
	ops->opt = UG_OPT_INDICATOR_ENABLE;

	return 0;
}

UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
{
	struct ug_data *ugd;
	if (!ops)
	{
		MSG_IMAGEVIEW_ERROR("OPS Pointer is NULL");
		return;
	}

	ugd = ops->priv;

	if (ugd)
	{
		free(ugd);
	}

	MSG_IMAGEVIEW_HIGH("UG_MODULE_EXIT");

	PERF_SHOW_RESULT(stdout);

	PERF_DEINIT();

}


#define _CONSTRUCTOR __attribute__ ((constructor))
#define _DESTRUCTOR __attribute__ ((destructor))

void _CONSTRUCTOR _DLLInit(void)
{
	printf("Image Viewer - Called constructor\n");
}

void _DESTRUCTOR _DLLExit(void)
{
	printf("Image Viewer - Called destructor\n");

}


int main()
{
/*	For detecting undefined symbol */
	return -1;
}