1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #include "enrollee_wifi.h"
24 #include "OCPlatform.h"
27 typedef struct appdata
33 Evas_Object *findButton;
35 Evas_Object *listview;
38 static void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
43 static void list_selected_cb(void *data, Evas_Object *obj, void *event_info)
45 Elm_Object_Item *it = (Elm_Object_Item *) event_info;
46 elm_list_item_selected_set(it, EINA_FALSE);
49 static Eina_Bool naviframe_pop_cb(void *data, Elm_Object_Item *it)
55 static void create_list_view(appdata_s *ad)
59 Evas_Object *nf = ad->nf;
60 Elm_Object_Item *nf_it;
63 list = elm_list_add(nf);
64 elm_list_mode_set(list, ELM_LIST_COMPRESS);
65 evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
67 // Main Menu Items Here
68 elm_list_item_append(list, "Start Enrollee ", NULL, NULL, StartEnrollee, nf);
72 // This button is set for devices which doesn't have H/W back key.
73 btn = elm_button_add(nf);
74 elm_object_style_set(btn, "naviframe/end_btn/default");
75 nf_it = elm_naviframe_item_push(nf, "EasySetup-Enrollee", btn, NULL, list, NULL);
76 elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, ad->win);
79 static void create_base_gui(appdata_s *ad)
82 ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
83 elm_win_conformant_set(ad->win, EINA_TRUE);
84 elm_win_autodel_set(ad->win, EINA_TRUE);
86 if (elm_win_wm_rotation_supported_get(ad->win))
90 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *) (&rots), 4);
93 evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
96 ad->conform = elm_conformant_add(ad->win);
97 evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
98 elm_win_resize_object_add(ad->win, ad->conform);
99 evas_object_show(ad->conform);
102 ad->layout = elm_layout_add(ad->conform);
103 evas_object_size_hint_weight_set(ad->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
104 elm_layout_theme_set(ad->layout, "layout", "application", "default");
105 evas_object_show(ad->layout);
107 elm_object_content_set(ad->conform, ad->layout);
110 ad->nf = elm_naviframe_add(ad->layout);
111 create_list_view(ad);
112 elm_object_part_content_set(ad->layout, "elm.swallow.content", ad->nf);
113 eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
114 eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_MORE, eext_naviframe_more_cb, NULL);
116 // Show window after base gui is set up
117 evas_object_show(ad->win);
121 // Configures the OCPlatform
122 static void configure_platform()
126 PlatformConfig config
127 { OC::ServiceType::InProc, ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos };
129 OCPlatform::Configure(config);
131 dlog_print(DLOG_INFO, LOG_TAG, "#### Platform configuration done!!!!");
133 catch (OCException &e)
135 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
139 static bool app_create(void *data)
141 /* Hook to take necessary actions before main event loop starts
142 Initialize UI resources and application's data
143 If this function returns true, the main loop of application starts
144 If this function returns false, the application is terminated */
145 appdata_s *ad = (appdata_s *) data;
147 elm_app_base_scale_set(1.8);
151 configure_platform();
156 static void app_control(app_control_h app_control, void *data)
158 // Handle the launch request.
161 static void app_pause(void *data)
163 // Take necessary actions when application becomes invisible.
166 static void app_resume(void *data)
168 // Take necessary actions when application becomes visible.
171 static void app_terminate(void *data)
173 // Release all resources.
176 static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
178 // APP_EVENT_LANGUAGE_CHANGED
180 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
181 elm_language_set(locale);
186 static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
188 // APP_EVENT_DEVICE_ORIENTATION_CHANGED
192 static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
194 // APP_EVENT_REGION_FORMAT_CHANGED
197 static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
199 // APP_EVENT_LOW_BATTERY
202 static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
204 // APP_EVENT_LOW_MEMORY
207 int main(int argc, char *argv[])
213 ui_app_lifecycle_callback_s event_callback =
215 app_event_handler_h handlers[5] =
218 event_callback.create = app_create;
219 event_callback.terminate = app_terminate;
220 event_callback.pause = app_pause;
221 event_callback.resume = app_resume;
222 event_callback.app_control = app_control;
224 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY,
225 ui_app_low_battery, &ad);
226 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY,
227 ui_app_low_memory, &ad);
228 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED],
229 APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
230 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED,
231 ui_app_lang_changed, &ad);
232 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED],
233 APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
234 ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
236 ret = ui_app_main(argc, argv, &event_callback, &ad);
237 if (APP_ERROR_NONE != ret)
239 dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);