summaryrefslogtreecommitdiff
path: root/viewer/src/msg-ui-viewer-gadget.c
blob: 1f51b332b26312878a9de26d24fb17ebe0355711 (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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
/*
 * 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://floralicense.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.
 */

#ifndef UG_MODULE_API
#define UG_MODULE_API __attribute__ ((visibility("default")))
#endif

/*==================================================================================================
 *										INCLUDE HEADERS
*==================================================================================================*/
#include <msg.h>
#include "msg-smil-player-interface.h"
#include "msg-ui-common-utility.h"
#include "msg-ui-viewer-main.h"
#include "msg-ui-image-resource.h"
#include <glib.h>
#include <vconf.h>
#include "msg-ui-common-utility.h"

/*==================================================================================================
 *									FUNCTION DECLARATIONS
 *==================================================================================================*/
static void *__msg_ui_viewer_on_create(ui_gadget_h ug, enum ug_mode mode, service_h svc_handle, void *priv);
static void __msg_ui_viewer_on_start(ui_gadget_h ug, service_h svc_handle, void *priv);
static void __msg_ui_viewer_on_pause(ui_gadget_h ug, service_h svc_handle, void *priv);
static void __msg_ui_viewer_on_resume(ui_gadget_h ug, service_h svc_handle, void *priv);
static void __msg_ui_viewer_on_destroy(ui_gadget_h ug, service_h svc_handle, void *priv);
static void __msg_ui_viewer_on_message(ui_gadget_h ug, service_h svc_msg_h, service_h svc_data_h, void *priv);
static void __msg_ui_viewer_on_event(ui_gadget_h ug, enum ug_event event, service_h svc_handle, void *priv);
static void __msg_ui_viewer_on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h svc_handle, void *priv);

static void __msg_ui_viewer_reload_viewer_ug(void *data, service_h svc_handle);
static void __msg_ui_viewer_destroy_viewer_ug(void *data);
static unsigned int __msg_ui_viewer_convert_atoh(const char *string);
static void __msg_ui_viewer_rotate_play_window(void *data, int rotate);

/*==================================================================================================
 *									FUNCTION IMPLEMENTATIONS
 *================================================================================================*/
static unsigned int __msg_ui_viewer_convert_atoh(const char *string)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, string == NULL, 0);
	unsigned int value = 0;
	unsigned int digit = 0;
	char c;

	while ((c = *string++) != '\0') {
		if (c >= '0' && c <= '9')
			digit = (unsigned int) (c - '0');
		else if (c >= 'a' && c <= 'f')
			digit = (unsigned int) (c - 'a') + 10;
		else if (c >= 'A' && c <= 'F')
			digit = (unsigned int) (c - 'A') + 10;
		else
			break;

		value = (value << 4) + digit;
	}

	return value;
}

static void __msg_ui_viewer_rotate_play_window(void *data, int rotate)
{
	MSG_UI_RET_IF(MSG_UI_LEVEL_ASSERT, data == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)data;
	MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "viewer_main_data->view_mode : %d", viewer_main_data->view_mode);

	if (viewer_main_data->view_mode == MSG_VIEWER_PLAYER_VIEW) {
		if (viewer_main_data->player_view) {
			MSG_SMIL_ERROR_E Error = MSG_SMIL_SUCCESS;

			if ((Error = msg_smil_on_slide_event_handler(&(viewer_main_data->SmilHandle), PLAYER_EVENT_ROTATE_WINDOW)) != MSG_SMIL_SUCCESS)
				MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "PLAYER_EVENT_ROTATE_WINDOW failed : %d", Error);
		}
	}
}

static void *__msg_ui_viewer_on_create(ui_gadget_h ug, enum ug_mode mode, service_h svc_handle, void *priv)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, ug == NULL, NULL);
	MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, svc_handle == NULL, NULL);
	MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, priv == NULL, NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)priv;
	msg_error_t err = MSG_SUCCESS;
	msg_handle_t msgHandle = NULL;
	Evas_Object *layout = NULL;

	/*Set Message Handler*/
	err = msg_open_msg_handle(&msgHandle);

	if (err != MSG_SUCCESS) {
		MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_open_msg_handle failed, Error = %d", err);
		ug_destroy_me(ug);
		return NULL;
	}

	msg_ui_viewer_main_init(viewer_main_data);

	viewer_main_data->viewer_ug = ug;
	viewer_main_data->cbs.layout_cb = msg_ui_viewer_layout_cb;
	viewer_main_data->cbs.result_cb = msg_ui_viewer_result_cb;
	viewer_main_data->cbs.destroy_cb = msg_ui_viewer_destroy_cb;
	viewer_main_data->cbs.priv = (void *)viewer_main_data;
	viewer_main_data->msgHandle = msgHandle;
	viewer_main_data->main_window = ug_get_window();
	MSG_UI_RETV_IF(MSG_UI_LEVEL_ERR, viewer_main_data->main_window == NULL, NULL);

	if (svc_handle) {
		char *mode_value = NULL;
		/* get mode value */
		service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_MODE, &mode_value);

		/*preview mode*/
		if (!g_strcmp0(mode_value, MSG_BUNDLE_VALUE_PREVIEW_MODE)) {
			unsigned int msg_t_pointer = 0;
			char *preview_data = NULL;

			viewer_main_data->launchmode = MSG_VIEWER_PREVIEW_MODE;

			/* get data value */
			service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_PREVIEW_DATA, &preview_data);

			if (preview_data) {
				/* get msg_t */
				msg_t_pointer = __msg_ui_viewer_convert_atoh((const char*)preview_data);
				viewer_main_data->msg_t = (msg_struct_t)msg_t_pointer;

				/*create mms_t*/
				viewer_main_data->mms_t = msg_create_struct(MSG_STRUCT_MMS);
				err = msg_get_mms_struct(viewer_main_data->msg_t, viewer_main_data->mms_t);

				if (err != MSG_SUCCESS) {
					MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "failed in get mms data handler");
					return NULL;
				}
			} else {
				MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "preview_data is NULL");
				return NULL;
			}
		} else { /*normal view mode*/
			char *msgid = NULL;
			service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_MSG_ID, &msgid);
			if (msgid) {
				viewer_main_data->msgID = (int)atoi(msgid);
				MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "msgID = %d", viewer_main_data->msgID);
			} else {
				MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "There is no msgID");
				return NULL;
			}

			/*get msg info struct handle */
			viewer_main_data->msg_t = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
			msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);

			if (viewer_main_data->msgID != -1) {
				err = msg_get_message(viewer_main_data->msgHandle, viewer_main_data->msgID, viewer_main_data->msg_t, sendOpt);
				if (err != MSG_SUCCESS) {
					MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_get_message has failed");
					msg_release_struct(&viewer_main_data->msg_t);
					msg_release_struct(&sendOpt);
					return NULL;
				}
			}

			msg_release_struct(&sendOpt);

			/*create mms_t*/
			viewer_main_data->mms_t = msg_create_struct(MSG_STRUCT_MMS);
			err = msg_get_mms_struct(viewer_main_data->msg_t, viewer_main_data->mms_t);

			if (err != MSG_SUCCESS) {
				MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "failed in get mms data handler");
				return NULL;
			}

			char *msg_box_mode = NULL;
			/* get mode if viewer should be displayed from message box */
			service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_MESSAGE_BOX, &msg_box_mode);

			if (msg_box_mode) {
				if (!g_strcmp0(msg_box_mode, MSG_BUNDLE_VALUE_MSGBOX_PROTECTED) || !g_strcmp0(msg_box_mode, MSG_BUNDLE_VALUE_MSGBOX_SPAM))
					viewer_main_data->msg_box_viewer = true;
			}
		}
	} else {
		MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "data is NULL");
		return NULL;
	}

	if (mode == UG_MODE_FULLVIEW) {
		viewer_main_data->ug_launch_mode = MSG_UG_MODE_FULLVIEW;
		/*create layout*/
		Evas_Object *bg = msg_ui_viewer_create_bg(viewer_main_data, viewer_main_data->main_window);

		bool show_indicator = true;
		char *indicator_mode = NULL;

		service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_INDICATOR_MODE, &indicator_mode);
		if (indicator_mode) {
			if (!g_strcmp0(indicator_mode, MSG_BUNDLE_VALUE_NO_INDICATOR))
				show_indicator = false;
		}

		layout = msg_ui_viewer_create_layout_main(viewer_main_data->main_window, show_indicator);
		viewer_main_data->layout_main = layout;

		if (bg)
			elm_object_part_content_set(layout, "elm.swallow.bg", bg);
		else
			return NULL;
	} else {
		viewer_main_data->ug_launch_mode = MSG_UG_MODE_FRAMVIEW;
		MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "framview is not supported");
		return NULL;
	}

	return layout;
}

static void __msg_ui_viewer_on_start(ui_gadget_h ug, service_h svc_handle, void *priv)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, ug == NULL);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, priv == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)priv;

	if (msg_ui_viewer_launch(viewer_main_data) == FALSE)
		ug_destroy_me(viewer_main_data->viewer_ug);
}

static void __msg_ui_viewer_on_pause(ui_gadget_h ug, service_h svc_handle, void *priv)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, ug == NULL);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, priv == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)priv;
	MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "viewer_main_data->view_mode : %d", viewer_main_data->view_mode);

	if (viewer_main_data->view_mode == MSG_VIEWER_PLAYER_VIEW) {
		if (viewer_main_data->player_view) {
			MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "Player view launch_cmd : %d, cmd_type : %d", viewer_main_data->player_view->launch_cmd, viewer_main_data->player_view->cmd_type);
			/* viewer will be paused */
			MSG_SMIL_ERROR_E Error = MSG_SMIL_SUCCESS;
			msg_ui_viewer_disconnect_handler(viewer_main_data->player_view);

			if (viewer_main_data->player_view->status == MSG_VIEWER_PLAY) {
				Error = msg_smil_on_slide_event_handler(&(viewer_main_data->player_view->SmilHandle), PLAYER_EVENT_PAUSE);
				if (Error != MSG_SMIL_SUCCESS) {
					MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_smil_on_slide_event_handler failed! : %d", Error);
				}

				viewer_main_data->player_view->status = MSG_VIEWER_PAUSE;

				if (viewer_main_data->player_view->play_controller) {
					edje_object_signal_emit(_EDJ(viewer_main_data->player_view->play_controller), "play", "*");

					if (viewer_main_data->player_view->play_controller_progressbar_timer)
						ecore_timer_freeze(viewer_main_data->player_view->play_controller_progressbar_timer);
				}
			}
		}
	}
}

static void __msg_ui_viewer_on_resume(ui_gadget_h ug, service_h svc_handle, void *priv)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, ug == NULL);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, priv == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)priv;
	MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "viewer_main_data->view_mode : %d", viewer_main_data->view_mode);

	if (viewer_main_data->view_mode == MSG_VIEWER_PLAYER_VIEW) {
		if (viewer_main_data->player_view) {
			MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "Player view launch_cmd : %d, cmd_type : %d", viewer_main_data->player_view->launch_cmd, viewer_main_data->player_view->cmd_type);

			bool isHelpText = (!viewer_main_data->player_view->smil_eventStatus) ? false : ((viewer_main_data->player_view->smil_eventStatus->isHelpSlide) ? true : false);
			MSG_VIEWER_ENTRY_TYPE_E entry_type = (isHelpText) ? MSG_VIEWER_ENTRY_HELP_TEXT : MSG_VIEWER_ENTRY_NORMAL_TEXT;
			msg_ui_viewer_set_font_size(viewer_main_data->player_view, entry_type, MSG_VIEWER_FONT_CHANGE_LATEST_UPDATE);

			if (!viewer_main_data->player_view->popup) {
				/*connect handler again*/
				msg_ui_viewer_connect_handler(viewer_main_data->player_view);
			}

			if (viewer_main_data->player_view->launch_cmd == MSG_VIEWER_LOAD_OTHER_APP_MODE) {
				/*reset launch_cmd and cmd_type*/
				viewer_main_data->player_view->launch_cmd = MSG_VIEWER_DEFAULT_MODE;
				viewer_main_data->player_view->cmd_type = MSG_VIEWER_CMD_NONE;
			}
		}
	} else if (viewer_main_data->view_mode == MSG_VIEWER_DRM_LIST_VIEW) {
		if (viewer_main_data->drm_list_view) {
			MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "drm list view drm_list_cmd : %d", viewer_main_data->drm_list_view->drm_list_cmd);
			if (viewer_main_data->drm_list_view->drm_list_cmd == MSG_VIEWER_DRM_LIST_CMD_LAUNCH_BROWSER) {
				if (msg_ui_viewer_drm_list_check_current_ro_valid(viewer_main_data->drm_list_view))
					msg_ui_viewer_drm_list_delete_current_list(viewer_main_data->drm_list_view);

				viewer_main_data->drm_list_view->drm_list_cmd = MSG_VIEWER_DRM_LIST_CMD_NONE;
				viewer_main_data->drm_list_view->selected_file_info = NULL;
			}
		}
	}
}

static void __msg_ui_viewer_on_destroy(ui_gadget_h ug, service_h svc_handle, void *priv)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, ug == NULL);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, priv == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)priv;
	msg_error_t err;

	MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "viewer_main_data->SmilHandle : %x", viewer_main_data->SmilHandle);

	if (viewer_main_data->player_view) {
		msg_ui_viewer_destroy_play_view(viewer_main_data->player_view);
		free(viewer_main_data->player_view);
		viewer_main_data->player_view = NULL;
	}

	if (viewer_main_data->drm_list_view) {
		msg_ui_viewer_destroy_drm_list_view(viewer_main_data->drm_list_view);
		free(viewer_main_data->drm_list_view);
		viewer_main_data->drm_list_view = NULL;
	}

	if (viewer_main_data->bg) {
		evas_object_del(viewer_main_data->bg);
		viewer_main_data->bg = NULL;
	}

	if (viewer_main_data->layout_main) {
		evas_object_del(viewer_main_data->layout_main);
		viewer_main_data->layout_main = NULL;
	}

	/*destroy viewer_main data*/
	/*free the drm list*/
	if (viewer_main_data->drm_list) {
		MSG_VIEWER_MEDIA_INFO_S *pmedia_info = NULL;
		int ntotal = eina_list_count(viewer_main_data->drm_list);
		int index = 0;

		for (index = 0; index < ntotal; index++) {
			pmedia_info = eina_list_nth(viewer_main_data->drm_list, index);
			if (pmedia_info) {
				free(pmedia_info);
				pmedia_info = NULL;
			}
		}
		eina_list_free(viewer_main_data->drm_list);
		viewer_main_data->drm_list = NULL;
	}

	if (viewer_main_data->SmilHandle) {
		msg_smil_destroy_smil_player(viewer_main_data->SmilHandle);
		msg_ui_viewer_set_smilhandle(viewer_main_data, NULL);
	}

	/* release msg info struct handle */
	if (viewer_main_data->msg_t) {
		msg_release_struct(&viewer_main_data->msg_t);
		viewer_main_data->msg_t = NULL;
	}

	/* release mms struct handle */
	if (viewer_main_data->mms_t) {
		msg_release_struct(&viewer_main_data->mms_t);
		viewer_main_data->mms_t = NULL;
	}

	if ((err = msg_close_msg_handle(&viewer_main_data->msgHandle)) != MSG_SUCCESS)
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "msg_close_msg_handle, err=[%d]", err);

	MSG_UI_LEAVE(MSG_UI_LEVEL_DEBUG);
}

static void __msg_ui_viewer_on_message(ui_gadget_h ug, service_h svc_msg_h, service_h svc_data_h, void *priv)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, priv == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)priv;

	__msg_ui_viewer_reload_viewer_ug(viewer_main_data, svc_msg_h);

	MSG_UI_LEAVE(MSG_UI_LEVEL_DEBUG);
}

static void __msg_ui_viewer_on_event(ui_gadget_h ug, enum ug_event event, service_h svc_handle, void *priv)
{
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, ug == NULL);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, priv == NULL);
	MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "event : %d", event);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)priv;

	switch (event) {
	case UG_EVENT_LOW_MEMORY:
		break;
	case UG_EVENT_LOW_BATTERY:
	{
		int battey_level = 0;
		vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW , &battey_level);
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "battey_level = %d", battey_level);
		if (battey_level == VCONFKEY_SYSMAN_BAT_POWER_OFF) {
			int charger_status = -1;
			vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &charger_status);

			if (!charger_status)
				__msg_ui_viewer_destroy_viewer_ug(priv);
		}

		break;
	}
	case UG_EVENT_LANG_CHANGE:
		msg_ui_viewer_change_language(viewer_main_data);
		break;
	case UG_EVENT_ROTATE_PORTRAIT:
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "UG_EVENT_ROTATE_PORTRAIT");
		__msg_ui_viewer_rotate_play_window(viewer_main_data, 0);
		break;
	case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN");
		__msg_ui_viewer_rotate_play_window(viewer_main_data, 180);
		break;
	case UG_EVENT_ROTATE_LANDSCAPE:
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "UG_EVENT_ROTATE_LANDSCAPE");
		__msg_ui_viewer_rotate_play_window(viewer_main_data, 270);
		break;
	case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN");
		__msg_ui_viewer_rotate_play_window(viewer_main_data, 90);
		break;
	case UG_EVENT_REGION_CHANGE:
		break;
	default:
		break;
	}
}

static void __msg_ui_viewer_on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h svc_handle, void *priv)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, ug == NULL);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, priv == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)priv;
	MSG_SMIL_ERROR_E Error = MSG_SMIL_SUCCESS;
	int	ispopup = FALSE;

	MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "viewer_main_data->view_mode : %d", viewer_main_data->view_mode);

	switch (event) {
	case UG_KEY_EVENT_END:
		if (viewer_main_data->view_mode == MSG_VIEWER_PLAYER_VIEW) {
			if (viewer_main_data->player_view) {
				if (viewer_main_data->player_view->popup) {
					evas_object_del(viewer_main_data->player_view->popup);
					viewer_main_data->player_view->popup = NULL;
					viewer_main_data->player_view->popup_type = MSG_VIEWER_POPUP_NONE;
					ispopup = TRUE;
				}

				if (viewer_main_data->player_view->status == MSG_VIEWER_PLAY ||
					viewer_main_data->player_view->status == MSG_VIEWER_PAUSE) {
					Error = msg_smil_on_slide_event_handler(&(viewer_main_data->player_view->SmilHandle), PLAYER_EVENT_STOP);
					if (Error != MSG_SMIL_SUCCESS) {
						MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_smil_on_slide_event_handler failed! : %d", Error);
					}

					viewer_main_data->player_view->status = MSG_VIEWER_STOP;
					msg_ui_viewer_update_play_controller(viewer_main_data->player_view, MSG_VIEWER_STOP);
				}
			}
		} else {
			MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "Not required case");
		}

		if (ispopup == FALSE) {
			if (!viewer_main_data->del_idler)
				viewer_main_data->del_idler = ecore_idler_add(msg_ui_viewer_ug_quit, viewer_main_data);
		}

		break;
	default:
		break;
	}
}

static void __msg_ui_viewer_reload_viewer_ug(void *data, service_h svc_handle)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, data == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)data;

	if (viewer_main_data->msg_t) {
		msg_release_struct(&viewer_main_data->msg_t);
		viewer_main_data->msg_t = NULL;
	}

	if (viewer_main_data->mms_t) {
		msg_release_struct(&viewer_main_data->mms_t);
		viewer_main_data->mms_t = NULL;
	}

	if (svc_handle) {
		char *msgid = NULL;
		service_get_extra_data(svc_handle, MSG_BUNDLE_KEY_MSG_ID, &msgid);
		if (msgid) {
			viewer_main_data->msgID = (int)atoi(msgid);
			MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "msgID = %d", viewer_main_data->msgID);
		} else {
			MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "There is no msgid");
			return;
		}
	}

	if (viewer_main_data->view_mode == MSG_VIEWER_PLAYER_VIEW) {
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "Reset play view mode");

		if (viewer_main_data->player_view) {
			msg_ui_viewer_destroy_play_view(viewer_main_data->player_view);
			free(viewer_main_data->player_view);
			viewer_main_data->player_view = NULL;
		}

		if (viewer_main_data->SmilHandle) {
			msg_smil_destroy_smil_player(viewer_main_data->SmilHandle);
			msg_ui_viewer_set_smilhandle(viewer_main_data, NULL);
		}

		if (msg_ui_viewer_launch(viewer_main_data) == FALSE) {
			msg_common_reset_font_size("entry");
			ug_destroy_me(viewer_main_data->viewer_ug);
		}
	} else if (viewer_main_data->view_mode == MSG_VIEWER_DRM_LIST_VIEW) {
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "DRM list view mode, come here to implement");
		if (viewer_main_data->drm_list_view) {
			msg_ui_viewer_destroy_drm_list_view(viewer_main_data->drm_list_view);
			free(viewer_main_data->drm_list_view);
			viewer_main_data->drm_list_view = NULL;
		}

	} else {
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "%d mode is not required anything", viewer_main_data->view_mode);
	}
}


static void __msg_ui_viewer_destroy_viewer_ug(void *data)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, data == NULL);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)data;
	MSG_SMIL_ERROR_E Error = MSG_SMIL_SUCCESS;

	if (viewer_main_data->view_mode == MSG_VIEWER_PLAYER_VIEW) {
		if (viewer_main_data->player_view) {
			if (viewer_main_data->player_view->popup) {
				evas_object_del(viewer_main_data->player_view->popup);
				viewer_main_data->player_view->popup = NULL;
				viewer_main_data->player_view->popup_type = MSG_VIEWER_POPUP_NONE;
			}

			if (viewer_main_data->player_view->status == MSG_VIEWER_PLAY ||
				viewer_main_data->player_view->status == MSG_VIEWER_PAUSE) {
				Error = msg_smil_on_slide_event_handler(&(viewer_main_data->player_view->SmilHandle), PLAYER_EVENT_STOP);
				if (Error != MSG_SMIL_SUCCESS) {
					MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "msg_smil_on_slide_event_handler failed! : %d", Error);
				} else {
					viewer_main_data->player_view->status = MSG_VIEWER_STOP;
				}
			}
		}
	} else {
		MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "%d mode is not required anything", viewer_main_data->view_mode);
	}

	if (!viewer_main_data->del_idler)
		viewer_main_data->del_idler = ecore_idler_add(msg_ui_viewer_ug_quit, viewer_main_data);
}

UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = NULL;

	if (!ops)
		return MSG_UI_RET_ERR;

	viewer_main_data = calloc(1, sizeof(MSG_VIEWER_MAIN_DATA_S));
	if (!viewer_main_data)
		return MSG_UI_RET_ERR;

	ops->create = __msg_ui_viewer_on_create;
	ops->start = __msg_ui_viewer_on_start;
	ops->pause = __msg_ui_viewer_on_pause;
	ops->resume = __msg_ui_viewer_on_resume;
	ops->destroy = __msg_ui_viewer_on_destroy;
	ops->message = __msg_ui_viewer_on_message;
	ops->event = __msg_ui_viewer_on_event;
	ops->key_event = __msg_ui_viewer_on_key_event;
	ops->priv = (void *)viewer_main_data;
	ops->opt = UG_OPT_INDICATOR_ENABLE;

	return MSG_UI_RET_SUCCESS;
}

UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
{
	MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG);
	MSG_VIEWER_MAIN_DATA_S *viewer_main_data = NULL;

	if (!ops)
		return;

	viewer_main_data = (MSG_VIEWER_MAIN_DATA_S *)ops->priv;

	if (viewer_main_data)
		free(viewer_main_data);
}