4 * Copyright 2012-2013 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <syspopup_caller.h>
26 #include "common_utils.h"
27 #include "i18nmanager.h"
29 #define POPUP_HEAD_AREA 134
30 #define POPUP_BUTTON_AREA 80
35 } two_line_disp_data_t;
37 static GSList *managed_idler_list = NULL;
39 static char *__common_utils_2line_text_get(void *data, Evas_Object *obj, const char *part)
41 two_line_disp_data_t *item_data = (two_line_disp_data_t *)data;
42 if (!strcmp(part, "elm.text.1")) {
43 return g_strdup(item_data->info_str);
44 } else if (!strcmp(part, "elm.text.2")) {
45 return g_strdup(item_data->title_str);
50 static void __common_utils_2line_text_del(void *data, Evas_Object *obj)
52 two_line_disp_data_t *item_data = (two_line_disp_data_t *)data;
54 g_free(item_data->info_str);
55 g_free(item_data->title_str);
60 static void __common_utils_separator_del(void *data, Evas_Object *obj)
62 elm_genlist_item_class_free(data);
66 Elm_Object_Item* common_utils_add_dialogue_separator(Evas_Object* genlist, const char *separator_style)
68 assertm_if(NULL == genlist, "NULL!!");
70 static Elm_Genlist_Item_Class *separator_itc;
71 separator_itc = elm_genlist_item_class_new();
72 separator_itc->item_style = separator_style;
73 separator_itc->func.text_get = NULL;
74 separator_itc->func.content_get = NULL;
75 separator_itc->func.state_get = NULL;
76 separator_itc->func.del = __common_utils_separator_del;
78 Elm_Object_Item* sep = elm_genlist_item_append(
83 ELM_GENLIST_ITEM_GROUP,
87 assertm_if(NULL == sep, "NULL!!");
89 elm_genlist_item_select_mode_set(sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
94 char *common_utils_get_ap_security_type_info_txt(const char *pkg_name, wifi_device_info_t *device_info)
96 char *status_txt = NULL;
97 switch (device_info->security_mode)
99 case WLAN_SEC_MODE_NONE: /** Security disabled */
100 status_txt = g_strdup(sc(pkg_name, I18N_TYPE_Open));
102 case WLAN_SEC_MODE_IEEE8021X: /** EAP */
103 status_txt = g_strdup_printf("%s (%s)", sc(pkg_name, I18N_TYPE_Secured), sc(pkg_name, I18N_TYPE_EAP));
105 case WLAN_SEC_MODE_WEP: /** WEP */
106 case WLAN_SEC_MODE_WPA_PSK: /** WPA-PSK */
107 case WLAN_SEC_MODE_WPA2_PSK: /** WPA2-PSK */
108 if (TRUE == device_info->wps_mode) {
109 status_txt = g_strdup_printf("%s (%s)", sc(pkg_name, I18N_TYPE_Secured), sc(pkg_name, I18N_TYPE_WPS_Available));
111 status_txt = g_strdup(sc(pkg_name, I18N_TYPE_Secured));
114 default: /** Unknown */
115 status_txt = g_strdup(WIFI_UNKNOWN_DEVICE_STATUS_STR);
121 void common_utils_get_device_icon(const char *image_path_dir, wifi_device_info_t *device_info, char **icon_path)
123 char buf[MAX_DEVICE_ICON_PATH_STR_LEN] = {'\0', };
125 g_strlcpy(buf, image_path_dir, sizeof(buf));
126 g_strlcat(buf, "/37_wifi_icon", sizeof(buf));
128 if (device_info->security_mode != WLAN_SEC_MODE_NONE) {
129 g_strlcat(buf, "_lock", sizeof(buf));
132 switch (wlan_manager_get_signal_strength(device_info->rssi)) {
133 case SIGNAL_STRENGTH_TYPE_EXCELLENT:
134 g_strlcat(buf, "_03", sizeof(buf));
136 case SIGNAL_STRENGTH_TYPE_GOOD:
137 g_strlcat(buf, "_02", sizeof(buf));
139 case SIGNAL_STRENGTH_TYPE_WEAK:
140 g_strlcat(buf, "_01", sizeof(buf));
142 case SIGNAL_STRENGTH_TYPE_VERY_WEAK:
143 case SIGNAL_STRENGTH_TYPE_NULL:
145 g_strlcat(buf, "_00", sizeof(buf));
150 *icon_path = g_strdup_printf("%s", buf);
154 char *common_utils_get_rssi_text(const char *str_pkg_name, int rssi)
156 switch (wlan_manager_get_signal_strength(rssi)) {
157 case SIGNAL_STRENGTH_TYPE_EXCELLENT:
158 return g_strdup(sc(str_pkg_name, I18N_TYPE_Excellent));
159 case SIGNAL_STRENGTH_TYPE_GOOD:
160 return g_strdup(sc(str_pkg_name, I18N_TYPE_Good));
162 return g_strdup(sc(str_pkg_name, I18N_TYPE_Week));
166 Evas_Object *common_utils_entry_layout_get_entry(Evas_Object *layout)
168 return elm_object_part_content_get(layout, "elm.swallow.content");
171 char *common_utils_entry_layout_get_text(Evas_Object *layout)
173 Evas_Object *entry = elm_object_part_content_get(layout, "elm.swallow.content");
174 return elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
177 void common_popup_size_get(Ecore_IMF_Context *target_imf, int *width, int *height)
179 __COMMON_FUNC_ENTER__;
181 int window_width, window_height;
182 int start_x, start_y, imf_width, imf_height;
184 float resize_scale = 0.7f;
186 rotate_angle = common_utils_get_rotate_angle(APPCORE_RM_UNKNOWN);
187 ecore_x_window_size_get(ecore_x_window_root_first_get(), &window_width, &window_height);
189 *width = window_width;
191 if (rotate_angle == 0 || rotate_angle == 180) {
192 *height = window_height * resize_scale;
194 *height = window_width;
196 if (target_imf != NULL) {
197 ecore_imf_context_input_panel_geometry_get(target_imf, &start_x, &start_y, &imf_width, &imf_height);
198 *height = start_y * resize_scale;
201 *height = *height-POPUP_HEAD_AREA-POPUP_BUTTON_AREA;
203 __COMMON_FUNC_EXIT__;
206 void common_utils_entry_password_set(Evas_Object *layout, Eina_Bool pswd_set)
208 Evas_Object *entry = elm_object_part_content_get(layout, "elm.swallow.content");
209 elm_entry_password_set(entry, pswd_set);
212 void common_utils_set_edit_box_imf_panel_evnt_cb(Elm_Object_Item *item,
213 imf_ctxt_panel_cb_t input_panel_cb, void *user_data)
215 __COMMON_FUNC_ENTER__;
216 common_utils_entry_info_t *entry_info;
217 entry_info = elm_object_item_data_get(item);
221 entry_info->input_panel_cb = input_panel_cb;
222 entry_info->input_panel_cb_data = user_data;
224 Evas_Object *entry = elm_object_item_part_content_get(item, "elm.icon.entry");
225 Ecore_IMF_Context *imf_ctxt = elm_entry_imf_context_get(entry);
226 if (imf_ctxt && entry_info->input_panel_cb) {
227 /* Deleting the previously attached callback */
228 ecore_imf_context_input_panel_event_callback_del(imf_ctxt,
229 ECORE_IMF_INPUT_PANEL_STATE_EVENT,
230 entry_info->input_panel_cb);
231 ecore_imf_context_input_panel_event_callback_add(imf_ctxt,
232 ECORE_IMF_INPUT_PANEL_STATE_EVENT,
233 entry_info->input_panel_cb,
234 entry_info->input_panel_cb_data);
235 DEBUG_LOG(UG_NAME_NORMAL, "set the imf ctxt cbs");
238 __COMMON_FUNC_EXIT__;
242 void common_utils_edit_box_focus_set(Elm_Object_Item *item, Eina_Bool focus_set)
244 __COMMON_FUNC_ENTER__;
248 Evas_Object *entry = elm_object_item_part_content_get(item, "elm.icon.entry");
249 elm_object_focus_set(entry, focus_set);
251 __COMMON_FUNC_EXIT__;
255 Elm_Object_Item *common_utils_add_2_line_txt_disabled_item(Evas_Object* view_list, const char *style_name, const char *line1_txt, const char *line2_txt)
257 static Elm_Genlist_Item_Class two_line_display_itc;
258 two_line_disp_data_t *two_line_data = NULL;
259 Elm_Object_Item *item = NULL;
261 two_line_display_itc.item_style = style_name;
262 two_line_display_itc.func.text_get = __common_utils_2line_text_get;
263 two_line_display_itc.func.content_get = NULL;
264 two_line_display_itc.func.state_get = NULL;
265 two_line_display_itc.func.del = __common_utils_2line_text_del;
267 two_line_data = g_new0(two_line_disp_data_t, 1);
268 two_line_data->title_str = g_strdup(line1_txt);
269 two_line_data->info_str = g_strdup(line2_txt);
270 INFO_LOG(UG_NAME_NORMAL, "title_str = %s info_str = %s", two_line_data->title_str, two_line_data->info_str);
272 item = elm_genlist_item_append(view_list, &two_line_display_itc, two_line_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
273 elm_object_item_disabled_set(item, TRUE);
278 char *common_utils_get_list_item_entry_txt(Elm_Object_Item *entry_item)
280 common_utils_entry_info_t *entry_info =
281 (common_utils_entry_info_t *)elm_object_item_data_get(entry_item);
282 if (entry_info == NULL)
285 DEBUG_LOG(UG_NAME_NORMAL, "entry_info: 0x%x", entry_info);
287 return g_strdup(entry_info->entry_txt);
290 Evas_Object *common_utils_create_radio_button(Evas_Object *parent, const int value)
292 Evas_Object *radio = elm_radio_add(parent);
293 elm_radio_state_value_set(radio, value);
294 // elm_radio_group_add(radio, radio_main);
295 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND,
297 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
302 Evas_Object *common_utils_create_layout(Evas_Object *navi_frame)
305 layout = elm_layout_add(navi_frame);
306 elm_layout_theme_set(layout, "layout", "application", "noindicator");
307 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
309 Evas_Object* bg = elm_bg_add(layout);
310 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
311 elm_object_style_set(bg, "group_list");
312 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
314 evas_object_show(layout);
319 static void __common_utils_del_popup(void *data, Evas_Object *obj, void *event_info)
321 Evas_Object *popup = (Evas_Object *)data;
322 evas_object_del(popup);
325 Evas_Object *common_utils_show_info_popup(Evas_Object *parent, popup_btn_info_t *popup_data)
327 __COMMON_FUNC_ENTER__;
328 Evas_Object *popup = elm_popup_add(parent);
329 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
330 if (popup_data->title_txt)
331 elm_object_part_text_set(popup, "title,text", popup_data->title_txt);
332 if (popup_data->info_txt)
333 elm_object_text_set(popup, popup_data->info_txt);
334 if (popup_data->btn1_txt) {
335 Evas_Object *btn_1 = elm_button_add(popup);
336 elm_object_text_set(btn_1, popup_data->btn1_txt);
337 elm_object_part_content_set(popup, "button1", btn_1);
338 if (popup_data->btn1_cb) {
339 evas_object_smart_callback_add(btn_1, "clicked", popup_data->btn1_cb, popup_data->btn1_data);
340 } else { // set the default callback
341 evas_object_smart_callback_add(btn_1, "clicked", __common_utils_del_popup, popup);
344 if (popup_data->btn2_txt) {
345 Evas_Object *btn_2 = elm_button_add(popup);
346 elm_object_text_set(btn_2, popup_data->btn2_txt);
347 elm_object_part_content_set(popup, "button2", btn_2);
348 evas_object_smart_callback_add(btn_2, "clicked", popup_data->btn2_cb, NULL);
349 evas_object_show(popup);
350 if (popup_data->btn2_cb) {
351 evas_object_smart_callback_add(btn_2, "clicked", popup_data->btn2_cb, popup_data->btn2_data);
352 } else { // set the default callback
353 evas_object_smart_callback_add(btn_2, "clicked", __common_utils_del_popup, popup);
356 evas_object_show(popup);
361 Evas_Object *common_utils_show_info_ok_popup(Evas_Object *win,
362 const char *str_pkg_name, const char *info_txt)
364 popup_btn_info_t popup_data;
366 memset(&popup_data, 0, sizeof(popup_data));
367 popup_data.info_txt = (char *)info_txt;
368 popup_data.btn1_txt = sc(str_pkg_name, I18N_TYPE_Ok);
370 return common_utils_show_info_popup(win, &popup_data);
373 Evas_Object *common_utils_show_info_timeout_popup(Evas_Object *win,
374 const char* info_text, const double timeout)
376 Evas_Object *popup = elm_popup_add(win);
378 elm_object_text_set(popup, info_text);
379 elm_popup_timeout_set(popup, timeout);
380 evas_object_smart_callback_add(popup, "timeout",
381 __common_utils_del_popup, popup);
382 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
383 elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
384 evas_object_show(popup);
389 int common_utils_get_rotate_angle(enum appcore_rm rotate_mode)
391 int rotate_angle = 0;
392 if (APPCORE_RM_UNKNOWN == rotate_mode) {
393 appcore_get_rotation_state(&rotate_mode);
396 DEBUG_LOG(SP_NAME_NORMAL, "rotate_mode = %d", rotate_mode);
398 switch (rotate_mode) {
399 case APPCORE_RM_PORTRAIT_NORMAL: /**< Portrait mode */
400 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_PORTRAIT_NORMAL");
404 case APPCORE_RM_PORTRAIT_REVERSE: /**< Portrait upside down mode */
405 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_PORTRAIT_REVERSE");
409 case APPCORE_RM_LANDSCAPE_NORMAL: /**< Left handed landscape mode */
410 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_LANDSCAPE_NORMAL");
414 case APPCORE_RM_LANDSCAPE_REVERSE: /**< Right handed landscape mode */
415 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_LANDSCAPE_REVERSE");
420 ERROR_LOG(SP_NAME_ERR, "Invalid rotate mode. The default value (0) is set to 'rotate_angle'.");
428 wlan_security_mode_type_t common_utils_get_sec_mode(wifi_security_type_e sec_type)
431 case WIFI_SECURITY_TYPE_NONE:
432 return WLAN_SEC_MODE_NONE;
433 case WIFI_SECURITY_TYPE_WEP:
434 return WLAN_SEC_MODE_WEP;
435 case WIFI_SECURITY_TYPE_WPA_PSK:
436 return WLAN_SEC_MODE_WPA_PSK;
437 case WIFI_SECURITY_TYPE_WPA2_PSK:
438 return WLAN_SEC_MODE_WPA_PSK;
439 case WIFI_SECURITY_TYPE_EAP:
440 return WLAN_SEC_MODE_IEEE8021X;
442 return WLAN_SEC_MODE_NONE;
444 return WLAN_SEC_MODE_NONE;
447 int common_utils_send_message_to_net_popup(const char *title, const char *content, const char *type, const char *ssid)
450 bundle *b = bundle_create();
452 bundle_add(b, "_SYSPOPUP_TITLE_", title);
453 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
454 bundle_add(b, "_SYSPOPUP_TYPE_", type);
455 bundle_add(b, "_AP_NAME_", ssid);
457 ret = aul_launch_app("net.netpopup", b);
464 int common_util_set_system_registry(const char *key, int value)
466 __COMMON_FUNC_ENTER__;
468 if (vconf_set_int(key, value) < 0) {
469 ERROR_LOG(UG_NAME_NORMAL, "Failed to set vconf");
471 __COMMON_FUNC_EXIT__;
475 __COMMON_FUNC_EXIT__;
479 int common_util_get_system_registry(const char *key)
481 __COMMON_FUNC_ENTER__;
485 if (vconf_get_int(key, &value) < 0) {
486 ERROR_LOG(UG_NAME_NORMAL, "Failed to get vconf");
488 __COMMON_FUNC_EXIT__;
492 __COMMON_FUNC_EXIT__;
496 struct managed_idle_data {
502 static void __managed_idle_destroy_cb(gpointer data)
507 managed_idler_list = g_slist_remove(managed_idler_list, data);
510 static gboolean __managed_idle_hook_cb(gpointer user_data)
512 struct managed_idle_data *data = user_data;
517 return data->func(data->user_data);
520 guint common_util_managed_idle_add(GSourceFunc func, gpointer user_data)
523 struct managed_idle_data *data;
528 data = g_new0(struct managed_idle_data, 1);
533 data->user_data = user_data;
535 id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __managed_idle_hook_cb, data,
536 __managed_idle_destroy_cb);
544 managed_idler_list = g_slist_append(managed_idler_list, data);
549 void common_util_managed_idle_cleanup(void)
551 GSList *cur = managed_idler_list;
553 struct managed_idle_data *data;
555 for (;cur; cur = cur->next) {
558 src = g_main_context_find_source_by_id(g_main_context_default(),
561 g_source_destroy(src);
567 g_slist_free (managed_idler_list);
568 managed_idler_list = NULL;