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>
24 #include <efl_assist.h>
27 #include "common_utils.h"
28 #include "i18nmanager.h"
30 #define POPUP_HEAD_AREA 134
31 #define POPUP_BUTTON_AREA 80
36 } two_line_disp_data_t;
38 static GSList *managed_idler_list = NULL;
40 static char *__common_utils_2line_text_get(void *data, Evas_Object *obj, const char *part)
42 two_line_disp_data_t *item_data = (two_line_disp_data_t *)data;
43 if (!strcmp(part, "elm.text.1")) {
44 return g_strdup(item_data->info_str);
45 } else if (!strcmp(part, "elm.text.2")) {
46 return g_strdup(item_data->title_str);
51 static void __common_utils_2line_text_del(void *data, Evas_Object *obj)
53 two_line_disp_data_t *item_data = (two_line_disp_data_t *)data;
55 g_free(item_data->info_str);
56 g_free(item_data->title_str);
61 static void __common_utils_separator_del(void *data, Evas_Object *obj)
63 elm_genlist_item_class_free(data);
67 Elm_Object_Item* common_utils_add_dialogue_separator(Evas_Object* genlist, const char *separator_style)
69 assertm_if(NULL == genlist, "NULL!!");
71 static Elm_Genlist_Item_Class *separator_itc;
72 separator_itc = elm_genlist_item_class_new();
73 separator_itc->item_style = separator_style;
74 separator_itc->func.text_get = NULL;
75 separator_itc->func.content_get = NULL;
76 separator_itc->func.state_get = NULL;
77 separator_itc->func.del = __common_utils_separator_del;
79 Elm_Object_Item* sep = elm_genlist_item_append(
84 ELM_GENLIST_ITEM_GROUP,
88 assertm_if(NULL == sep, "NULL!!");
90 elm_genlist_item_select_mode_set(sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
95 char *common_utils_get_ap_security_type_info_txt(const char *pkg_name, wifi_device_info_t *device_info)
97 char *status_txt = NULL;
98 switch (device_info->security_mode)
100 case WLAN_SEC_MODE_NONE: /** Security disabled */
101 status_txt = g_strdup(sc(pkg_name, I18N_TYPE_Open));
103 case WLAN_SEC_MODE_IEEE8021X: /** EAP */
104 status_txt = g_strdup_printf("%s (%s)", sc(pkg_name, I18N_TYPE_Secured), sc(pkg_name, I18N_TYPE_EAP));
106 case WLAN_SEC_MODE_WEP: /** WEP */
107 case WLAN_SEC_MODE_WPA_PSK: /** WPA-PSK */
108 case WLAN_SEC_MODE_WPA2_PSK: /** WPA2-PSK */
109 if (TRUE == device_info->wps_mode) {
110 status_txt = g_strdup_printf("%s (%s)", sc(pkg_name, I18N_TYPE_Secured), sc(pkg_name, I18N_TYPE_WPS_Available));
112 status_txt = g_strdup(sc(pkg_name, I18N_TYPE_Secured));
115 default: /** Unknown */
116 status_txt = g_strdup(WIFI_UNKNOWN_DEVICE_STATUS_STR);
122 void common_utils_get_device_icon(const char *image_path_dir, wifi_device_info_t *device_info, char **icon_path)
124 char buf[MAX_DEVICE_ICON_PATH_STR_LEN] = {'\0', };
126 g_strlcpy(buf, image_path_dir, sizeof(buf));
127 g_strlcat(buf, "/37_wifi_icon", sizeof(buf));
129 if (device_info->security_mode != WLAN_SEC_MODE_NONE) {
130 g_strlcat(buf, "_lock", sizeof(buf));
133 switch (wlan_manager_get_signal_strength(device_info->rssi)) {
134 case SIGNAL_STRENGTH_TYPE_EXCELLENT:
135 g_strlcat(buf, "_03", sizeof(buf));
137 case SIGNAL_STRENGTH_TYPE_GOOD:
138 g_strlcat(buf, "_02", sizeof(buf));
140 case SIGNAL_STRENGTH_TYPE_WEAK:
141 g_strlcat(buf, "_01", sizeof(buf));
143 case SIGNAL_STRENGTH_TYPE_VERY_WEAK:
144 case SIGNAL_STRENGTH_TYPE_NULL:
146 g_strlcat(buf, "_00", sizeof(buf));
151 *icon_path = g_strdup_printf("%s", buf);
155 char *common_utils_get_rssi_text(const char *str_pkg_name, int rssi)
157 switch (wlan_manager_get_signal_strength(rssi)) {
158 case SIGNAL_STRENGTH_TYPE_EXCELLENT:
159 return g_strdup(sc(str_pkg_name, I18N_TYPE_Excellent));
160 case SIGNAL_STRENGTH_TYPE_GOOD:
161 return g_strdup(sc(str_pkg_name, I18N_TYPE_Good));
163 return g_strdup(sc(str_pkg_name, I18N_TYPE_Week));
167 Evas_Object *common_utils_entry_layout_get_entry(Evas_Object *layout)
169 return elm_object_part_content_get(layout, "elm.swallow.content");
172 char *common_utils_entry_layout_get_text(Evas_Object *layout)
174 Evas_Object *entry = elm_object_part_content_get(layout, "elm.swallow.content");
175 return elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
178 void common_popup_size_get(Ecore_IMF_Context *target_imf, int *width, int *height)
180 __COMMON_FUNC_ENTER__;
182 int window_width, window_height;
183 int start_x, start_y, imf_width, imf_height;
185 float resize_scale = 0.7f;
187 rotate_angle = common_utils_get_rotate_angle(APPCORE_RM_UNKNOWN);
188 ecore_x_window_size_get(ecore_x_window_root_first_get(), &window_width, &window_height);
190 *width = window_width;
192 if (rotate_angle == 0 || rotate_angle == 180) {
193 *height = window_height * resize_scale;
195 *height = window_width;
197 if (target_imf != NULL) {
198 ecore_imf_context_input_panel_geometry_get(target_imf, &start_x, &start_y, &imf_width, &imf_height);
199 *height = start_y * resize_scale;
202 *height = *height-POPUP_HEAD_AREA-POPUP_BUTTON_AREA;
204 __COMMON_FUNC_EXIT__;
207 void common_utils_entry_password_set(Evas_Object *layout, Eina_Bool pswd_set)
209 Evas_Object *entry = elm_object_part_content_get(layout, "elm.swallow.content");
210 elm_entry_password_set(entry, pswd_set);
213 void common_utils_set_edit_box_imf_panel_evnt_cb(Elm_Object_Item *item,
214 imf_ctxt_panel_cb_t input_panel_cb, void *user_data)
216 __COMMON_FUNC_ENTER__;
217 common_utils_entry_info_t *entry_info;
218 entry_info = elm_object_item_data_get(item);
222 entry_info->input_panel_cb = input_panel_cb;
223 entry_info->input_panel_cb_data = user_data;
225 Evas_Object *entry = elm_object_item_part_content_get(item, "elm.icon.entry");
226 Ecore_IMF_Context *imf_ctxt = elm_entry_imf_context_get(entry);
227 if (imf_ctxt && entry_info->input_panel_cb) {
228 /* Deleting the previously attached callback */
229 ecore_imf_context_input_panel_event_callback_del(imf_ctxt,
230 ECORE_IMF_INPUT_PANEL_STATE_EVENT,
231 entry_info->input_panel_cb);
232 ecore_imf_context_input_panel_event_callback_add(imf_ctxt,
233 ECORE_IMF_INPUT_PANEL_STATE_EVENT,
234 entry_info->input_panel_cb,
235 entry_info->input_panel_cb_data);
236 DEBUG_LOG(UG_NAME_NORMAL, "set the imf ctxt cbs");
239 __COMMON_FUNC_EXIT__;
243 void common_utils_edit_box_focus_set(Elm_Object_Item *item, Eina_Bool focus_set)
245 __COMMON_FUNC_ENTER__;
249 Evas_Object *entry = elm_object_item_part_content_get(item, "elm.icon.entry");
250 elm_object_focus_set(entry, focus_set);
252 __COMMON_FUNC_EXIT__;
256 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)
258 static Elm_Genlist_Item_Class two_line_display_itc;
259 two_line_disp_data_t *two_line_data = NULL;
260 Elm_Object_Item *item = NULL;
262 two_line_display_itc.item_style = style_name;
263 two_line_display_itc.func.text_get = __common_utils_2line_text_get;
264 two_line_display_itc.func.content_get = NULL;
265 two_line_display_itc.func.state_get = NULL;
266 two_line_display_itc.func.del = __common_utils_2line_text_del;
268 two_line_data = g_new0(two_line_disp_data_t, 1);
269 two_line_data->title_str = g_strdup(line1_txt);
270 two_line_data->info_str = g_strdup(line2_txt);
271 INFO_LOG(UG_NAME_NORMAL, "title_str = %s info_str = %s", two_line_data->title_str, two_line_data->info_str);
273 item = elm_genlist_item_append(view_list, &two_line_display_itc, two_line_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
274 elm_object_item_disabled_set(item, TRUE);
279 char *common_utils_get_list_item_entry_txt(Elm_Object_Item *entry_item)
281 common_utils_entry_info_t *entry_info =
282 (common_utils_entry_info_t *)elm_object_item_data_get(entry_item);
283 if (entry_info == NULL)
286 DEBUG_LOG(UG_NAME_NORMAL, "entry_info: 0x%x", entry_info);
288 return g_strdup(entry_info->entry_txt);
291 Evas_Object *common_utils_create_radio_button(Evas_Object *parent, const int value)
293 Evas_Object *radio = elm_radio_add(parent);
294 elm_radio_state_value_set(radio, value);
295 // elm_radio_group_add(radio, radio_main);
296 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND,
298 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
303 Evas_Object *common_utils_create_layout(Evas_Object *navi_frame)
306 layout = elm_layout_add(navi_frame);
307 elm_layout_theme_set(layout, "layout", "application", "noindicator");
308 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
310 Evas_Object* bg = elm_bg_add(layout);
311 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
312 elm_object_style_set(bg, "group_list");
313 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
315 evas_object_show(layout);
320 static void __common_utils_del_popup(void *data, Evas_Object *obj, void *event_info)
322 Evas_Object *popup = (Evas_Object *)data;
323 evas_object_del(popup);
326 Evas_Object *common_utils_show_info_popup(Evas_Object *parent, popup_btn_info_t *popup_data)
328 __COMMON_FUNC_ENTER__;
329 Evas_Object *popup = elm_popup_add(parent);
331 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
332 if (popup_data->title_txt)
333 elm_object_part_text_set(popup, "title,text", popup_data->title_txt);
334 if (popup_data->info_txt)
335 elm_object_text_set(popup, popup_data->info_txt);
336 if (popup_data->btn1_txt) {
337 Evas_Object *btn_1 = elm_button_add(popup);
338 elm_object_text_set(btn_1, popup_data->btn1_txt);
339 elm_object_part_content_set(popup, "button1", btn_1);
340 if (popup_data->btn1_cb) {
341 evas_object_smart_callback_add(btn_1, "clicked", popup_data->btn1_cb, popup_data->btn1_data);
342 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, popup_data->btn1_cb, popup_data->btn1_data);
343 } else { // set the default callback
344 evas_object_smart_callback_add(btn_1, "clicked", __common_utils_del_popup, popup);
345 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, ea_popup_back_cb, NULL);
348 if (popup_data->btn2_txt) {
349 Evas_Object *btn_2 = elm_button_add(popup);
350 elm_object_text_set(btn_2, popup_data->btn2_txt);
351 elm_object_part_content_set(popup, "button2", btn_2);
352 evas_object_smart_callback_add(btn_2, "clicked", popup_data->btn2_cb, NULL);
353 evas_object_show(popup);
354 if (popup_data->btn2_cb) {
355 evas_object_smart_callback_add(btn_2, "clicked", popup_data->btn2_cb, popup_data->btn2_data);
356 } else { // set the default callback
357 evas_object_smart_callback_add(btn_2, "clicked", __common_utils_del_popup, popup);
361 elm_object_focus_set(popup, EINA_TRUE);
362 evas_object_show(popup);
367 Evas_Object *common_utils_show_info_ok_popup(Evas_Object *win,
368 const char *str_pkg_name, const char *info_txt)
370 popup_btn_info_t popup_data;
372 memset(&popup_data, 0, sizeof(popup_data));
373 popup_data.info_txt = (char *)info_txt;
374 popup_data.btn1_txt = sc(str_pkg_name, I18N_TYPE_Ok);
376 return common_utils_show_info_popup(win, &popup_data);
379 Evas_Object *common_utils_show_info_timeout_popup(Evas_Object *win,
380 const char* info_text, const double timeout)
382 Evas_Object *popup = elm_popup_add(win);
384 elm_object_text_set(popup, info_text);
385 elm_popup_timeout_set(popup, timeout);
386 evas_object_smart_callback_add(popup, "timeout",
387 __common_utils_del_popup, popup);
388 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
389 elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
390 evas_object_show(popup);
395 int common_utils_get_rotate_angle(enum appcore_rm rotate_mode)
397 int rotate_angle = 0;
398 if (APPCORE_RM_UNKNOWN == rotate_mode) {
399 appcore_get_rotation_state(&rotate_mode);
402 DEBUG_LOG(SP_NAME_NORMAL, "rotate_mode = %d", rotate_mode);
404 switch (rotate_mode) {
405 case APPCORE_RM_PORTRAIT_NORMAL: /**< Portrait mode */
406 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_PORTRAIT_NORMAL");
410 case APPCORE_RM_PORTRAIT_REVERSE: /**< Portrait upside down mode */
411 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_PORTRAIT_REVERSE");
415 case APPCORE_RM_LANDSCAPE_NORMAL: /**< Left handed landscape mode */
416 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_LANDSCAPE_NORMAL");
420 case APPCORE_RM_LANDSCAPE_REVERSE: /**< Right handed landscape mode */
421 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_LANDSCAPE_REVERSE");
426 ERROR_LOG(SP_NAME_ERR, "Invalid rotate mode. The default value (0) is set to 'rotate_angle'.");
434 wlan_security_mode_type_t common_utils_get_sec_mode(wifi_security_type_e sec_type)
437 case WIFI_SECURITY_TYPE_NONE:
438 return WLAN_SEC_MODE_NONE;
439 case WIFI_SECURITY_TYPE_WEP:
440 return WLAN_SEC_MODE_WEP;
441 case WIFI_SECURITY_TYPE_WPA_PSK:
442 return WLAN_SEC_MODE_WPA_PSK;
443 case WIFI_SECURITY_TYPE_WPA2_PSK:
444 return WLAN_SEC_MODE_WPA_PSK;
445 case WIFI_SECURITY_TYPE_EAP:
446 return WLAN_SEC_MODE_IEEE8021X;
448 return WLAN_SEC_MODE_NONE;
450 return WLAN_SEC_MODE_NONE;
453 int common_utils_send_message_to_net_popup(const char *title, const char *content, const char *type, const char *ssid)
456 bundle *b = bundle_create();
458 bundle_add(b, "_SYSPOPUP_TITLE_", title);
459 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
460 bundle_add(b, "_SYSPOPUP_TYPE_", type);
461 bundle_add(b, "_AP_NAME_", ssid);
463 ret = aul_launch_app("net.netpopup", b);
470 int common_util_set_system_registry(const char *key, int value)
472 __COMMON_FUNC_ENTER__;
474 if (vconf_set_int(key, value) < 0) {
475 ERROR_LOG(UG_NAME_NORMAL, "Failed to set vconf");
477 __COMMON_FUNC_EXIT__;
481 __COMMON_FUNC_EXIT__;
485 int common_util_get_system_registry(const char *key)
487 __COMMON_FUNC_ENTER__;
491 if (vconf_get_int(key, &value) < 0) {
492 ERROR_LOG(UG_NAME_NORMAL, "Failed to get vconf");
494 __COMMON_FUNC_EXIT__;
498 __COMMON_FUNC_EXIT__;
502 struct managed_idle_data {
508 static void __managed_idle_destroy_cb(gpointer data)
513 managed_idler_list = g_slist_remove(managed_idler_list, data);
516 static gboolean __managed_idle_hook_cb(gpointer user_data)
518 struct managed_idle_data *data = user_data;
523 return data->func(data->user_data);
526 guint common_util_managed_idle_add(GSourceFunc func, gpointer user_data)
529 struct managed_idle_data *data;
534 data = g_new0(struct managed_idle_data, 1);
539 data->user_data = user_data;
541 id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __managed_idle_hook_cb, data,
542 __managed_idle_destroy_cb);
550 managed_idler_list = g_slist_append(managed_idler_list, data);
555 void common_util_managed_idle_cleanup(void)
557 GSList *cur = managed_idler_list;
559 struct managed_idle_data *data;
561 for (;cur; cur = cur->next) {
564 src = g_main_context_find_source_by_id(g_main_context_default(),
567 g_source_destroy(src);
573 g_slist_free (managed_idler_list);
574 managed_idler_list = NULL;