4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include "syspopup-app.h"
28 typedef struct appdata {
34 char title[TITLE_BUF_LEN];
35 char content[CONTENT_BUF_LEN];
38 int myterm(bundle *b, void *data)
40 dlog_print(DLOG_DEBUG, LOG_TAG, "myterm called");
44 int mytimeout(bundle *b, void* data)
46 dlog_print(DLOG_DEBUG, LOG_TAG, "mytimeout called");
50 syspopup_handler handler = {
51 .def_term_fn = myterm,
52 .def_timeout_fn = mytimeout
55 static bool _app_control_extra_data_cb(app_control_h app_control, const char *key, void *user_data)
59 appdata_s *ad = user_data;
61 ret = app_control_get_extra_data(app_control, key, &value);
62 if (ret != APP_CONTROL_ERROR_NONE)
64 dlog_print(DLOG_ERROR, LOG_TAG, "app_control_get_extra_data() is failed. err = %d", ret);
67 if (bundle_add(ad->b, key, value) != BUNDLE_ERROR_NONE) {
68 return APP_CONTROL_ERROR_INVALID_PARAMETER;
74 static void win_delete_request_cb(void *data , Evas_Object *obj , void *event_info)
79 static void win_back_cb(void *data, Evas_Object *obj, void *event_info)
82 /* Let window go to hide state. */
83 elm_win_lower(ad->win);
86 static void response_cb(void *data, Evas_Object * obj, void *event_info)
88 dlog_print(DLOG_DEBUG, LOG_TAG, "response_cb called");
90 if ((int)event_info != 5)
95 static void block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
97 dlog_print(DLOG_DEBUG, LOG_TAG, "block_clicked_cb called");
101 static void create_base_gui(appdata_s *ad) {
106 ad->win = elm_win_add(NULL, PACKAGE, ELM_WIN_DIALOG_BASIC);
108 elm_win_title_set(ad->win, PACKAGE);
109 elm_win_borderless_set(ad->win, EINA_TRUE);
110 elm_win_alpha_set(ad->win, EINA_TRUE);
111 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
112 evas_object_resize(ad->win, w, h);
115 elm_win_autodel_set(ad->win, EINA_TRUE);
116 evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
120 static bool app_create(void *data)
122 appdata_s *ad = data;
129 static void app_control(app_control_h app_control, void *data)
131 /* Handle the launch request. */
132 appdata_s *ad = data;
139 ad->b = bundle_create();
141 ret = app_control_foreach_extra_data(app_control, _app_control_extra_data_cb, data);
142 if (ret != APP_CONTROL_ERROR_NONE)
143 dlog_print(DLOG_ERROR, LOG_TAG, "app_control_foreach_extra_data() is failed. err = %d", ret);
145 if (syspopup_has_popup(ad->b)) {
146 syspopup_reset(ad->b);
148 popup = elm_popup_add(ad->win);
150 ret = syspopup_create(ad->b, &handler, ad->win, ad);
151 evas_object_show(ad->win);
154 val = bundle_get_val(ad->b, "_SYSPOPUP_TITLE_");
156 snprintf(ad->title, TITLE_BUF_LEN, "%s",
159 snprintf(ad->title, TITLE_BUF_LEN, "%s",
163 val = bundle_get_val(ad->b, "_SYSPOPUP_CONTENT_");
165 snprintf(ad->content, CONTENT_BUF_LEN,
168 snprintf(ad->content, CONTENT_BUF_LEN,
169 "%s", "Unknown Content");
172 elm_object_style_set(popup, "char_wrap_style");
173 evas_object_size_hint_weight_set(popup,
176 evas_object_smart_callback_add(popup, "block,clicked", block_clicked_cb, NULL);
177 elm_object_part_text_set(popup, "title,text", ad->title);
178 elm_object_text_set(popup, ad->content);
179 evas_object_smart_callback_add(popup,
184 evas_object_show(popup);
191 static void app_pause(void *data)
193 /* Take necessary actions when application becomes invisible. */
196 static void app_resume(void *data)
198 /* Take necessary actions when application becomes visible. */
201 static void app_terminate(void *data)
203 /* Release all resources. */
206 static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
208 /* APP_EVENT_LANGUAGE_CHANGED*/
212 static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
214 /* APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
218 static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
220 /* APP_EVENT_REGION_FORMAT_CHANGED*/
223 static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
225 /* APP_EVENT_LOW_BATTERY*/
228 static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
230 /* APP_EVENT_LOW_MEMORY*/
233 int main(int argc, char *argv[])
238 ui_app_lifecycle_callback_s event_callback = {0,};
239 app_event_handler_h handlers[5] = {NULL, };
241 event_callback.create = app_create;
242 event_callback.terminate = app_terminate;
243 event_callback.pause = app_pause;
244 event_callback.resume = app_resume;
245 event_callback.app_control = app_control;
247 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
248 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
249 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
250 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
251 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
253 ret = ui_app_main(argc, argv, &event_callback, &ad);
254 if (ret != APP_ERROR_NONE) {
255 dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);