/* * 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 #include #include /*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; }