4 * Created on: 26-May-2014
8 #include <Elementary.h>
10 #include <efl_extension.h>
12 #include "mh_view_main.h"
13 #include "mh_string.h"
16 static Eina_Bool __is_portrait_mode = EINA_TRUE;
17 static int (*rotate_cb)(Eina_Bool , void*) = NULL;
18 static void *rotate_cb_data = NULL;
19 static void __set_rotate_cb(int (*cb)(Eina_Bool, void*) , void *data);
21 static void __rename_popup_keyback_cb(void *data, Evas_Object *obj,
24 __MOBILE_AP_FUNC_ENTER__;
26 mh_appdata_t *ad = (mh_appdata_t *)data;
28 elm_object_focus_set(ad->rename_entry, EINA_FALSE);
30 if (ad->rename_popup) {
31 evas_object_del(ad->rename_popup);
33 ad->rename_popup = NULL;
34 ad->rename_entry = NULL;
35 __set_rotate_cb(NULL, NULL);
37 __MOBILE_AP_FUNC_EXIT__;
40 static void __rename_popup_mouseup_cb(void *data,
41 Evas *e, Evas_Object *obj, void *event_info)
43 __MOBILE_AP_FUNC_ENTER__;
45 Evas_Event_Mouse_Up *ev = event_info;
46 mh_appdata_t *ad = (mh_appdata_t *)data;
48 if (ev->button == 3) {
49 elm_object_focus_set(ad->rename_entry, EINA_FALSE);
50 if (ad->rename_popup) {
51 evas_object_del(ad->rename_popup);
53 ad->rename_popup = NULL;
54 ad->rename_entry = NULL;
56 __MOBILE_AP_FUNC_EXIT__;
60 static bool __is_space_str(const char *str)
63 if (*str != '\0' && *str != ' ') {
65 } else if (*str == '\0') {
73 static void __rename_popop_entry_changed_cb(void *data, Evas_Object *obj,
76 __MOBILE_AP_FUNC_ENTER__;
77 mh_appdata_t *ad = (mh_appdata_t *)data;
79 const char *entry_text = NULL;
80 char *input_str = NULL;
81 bool is_space_string = FALSE;
83 entry_text = elm_entry_entry_get(obj);
84 input_str = elm_entry_markup_to_utf8(entry_text);
86 if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
87 if (elm_object_focus_get(obj)) {
88 if (elm_entry_is_empty(obj))
89 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
91 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
96 if (input_str == NULL || (strlen(input_str) == 0)) {
97 elm_object_disabled_set(ad->rename_button, TRUE);
98 elm_entry_input_panel_return_key_disabled_set(obj, TRUE);
105 is_space_string = __is_space_str(input_str);
106 if (is_space_string) {
107 elm_object_disabled_set(ad->rename_button, TRUE);
108 elm_entry_input_panel_return_key_disabled_set(ad->rename_entry, TRUE);
113 if (strlen(input_str) > 0) {
114 elm_object_disabled_set(ad->rename_button, FALSE);
115 elm_entry_input_panel_return_key_disabled_set(ad->rename_entry, FALSE);
120 __MOBILE_AP_FUNC_EXIT__;
123 static void __device_name_maxlength_reached_cb(void *data, Evas_Object *obj,
126 __MOBILE_AP_FUNC_ENTER__;
128 if (data == NULL || obj == NULL) {
129 ERR("The param is NULL\n");
133 char buf[MH_LABEL_LENGTH_MAX] = { 0, };
134 notification_error_e ret;
136 snprintf(buf, sizeof(buf), STR_PW_MAX_LEN_WARN_MSG, DEVICE_NAME_LENGTH_MAX);
137 ret = notification_status_message_post(buf);
138 if (ret != NOTIFICATION_ERROR_NONE) {
139 ERR("notification_status_message_post() is failed : %d\n", ret);
142 __MOBILE_AP_FUNC_EXIT__;
145 static void __entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
147 __MOBILE_AP_FUNC_ENTER__;
149 if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
150 if (!elm_entry_is_empty(obj))
151 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
153 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
155 elm_object_signal_emit(obj, "elm,state,focus,on", "");
157 __MOBILE_AP_FUNC_EXIT__;
160 static void __entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
162 __MOBILE_AP_FUNC_ENTER__;
164 if (elm_object_part_content_get(obj, "elm.swallow.clear"))
165 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
166 elm_object_signal_emit(obj, "elm,state,focus,off", "");
168 __MOBILE_AP_FUNC_EXIT__;
171 static void __eraser_btn_clicked_cb(void *data, Evas_Object *obj,
174 __MOBILE_AP_FUNC_ENTER__;
177 ERR("data is null\n");
180 mh_appdata_t *ad = (mh_appdata_t*) data;
182 elm_entry_entry_set(ad->rename_entry, "");
183 elm_object_disabled_set(ad->rename_button, TRUE);
184 elm_entry_input_panel_return_key_disabled_set(ad->rename_entry, TRUE);
186 __MOBILE_AP_FUNC_EXIT__;
189 static void __rename_popup_cancel_cb(void *data, Evas_Object *obj,
192 __MOBILE_AP_FUNC_ENTER__;
194 if (data == NULL || obj == NULL) {
195 ERR("data is null\n");
198 mh_appdata_t *ad = (mh_appdata_t*) data;
200 if (ad->rename_popup) {
201 evas_object_del(ad->rename_popup);
202 ad->rename_popup = NULL;
204 if (ad->rename_entry) {
205 evas_object_del(ad->rename_entry);
206 ad->rename_entry = NULL;
208 __set_rotate_cb(NULL, NULL);
210 __MOBILE_AP_FUNC_EXIT__;
214 static void __rename_popup_ok_cb(void *data, Evas_Object *obj,
217 __MOBILE_AP_FUNC_ENTER__;
219 if (data == NULL || obj == NULL) {
220 ERR("data is null\n");
223 mh_appdata_t *ad = (mh_appdata_t*) data;
224 char *device_name_str = NULL;
225 const char *entry_str = elm_entry_entry_get(ad->rename_entry);
227 device_name_str = elm_entry_markup_to_utf8(entry_str);
228 if (device_name_str == NULL) {
229 ERR("elm_entry_utf8_to_markup is failed\n");
233 DBG("New device name:[%s]\n", device_name_str);
234 __set_rotate_cb(NULL, NULL);
235 if (ad->rename_popup) {
236 evas_object_del(ad->rename_popup);
237 ad->rename_popup = NULL;
239 if (ad->rename_entry) {
240 evas_object_del(ad->rename_entry);
241 ad->rename_entry = NULL;
243 if (g_strcmp0(ad->setup.device_name, device_name_str)) {
244 if (vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, device_name_str) != 0) {
245 DBG("Set vconf[%s] failed\n",VCONFKEY_SETAPPL_DEVICE_NAME_STR);
248 g_strlcpy(ad->setup.device_name, entry_str,
249 sizeof(ad->setup.device_name));
251 if (ad->main.help_item != NULL) {
252 if (ad->main.help_item)
253 elm_genlist_item_update(ad->main.help_item);
256 if (ad->setup.name_item != NULL) {
257 if (ad->setup.name_item)
258 elm_genlist_item_update(ad->setup.name_item);
261 free(device_name_str);
263 __MOBILE_AP_FUNC_EXIT__;
267 static void __enter_key_down_cb(void *data, Evas *evas, Evas_Object *obj,
270 __MOBILE_AP_FUNC_ENTER__;
272 Evas_Event_Key_Down *ev = event_info;
274 if (g_strcmp0(ev->key, "KP_Enter") == 0 ||
275 g_strcmp0(ev->key, "Return") == 0) {
276 Ecore_IMF_Context *imf_context;
277 elm_entry_cursor_end_set(obj);
278 imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(obj);
280 ecore_imf_context_input_panel_hide(imf_context);
281 elm_object_focus_set(obj, EINA_FALSE);
283 __MOBILE_AP_FUNC_EXIT__;
286 static void __set_rotate_cb(int (*cb)(Eina_Bool, void*), void *data)
289 rotate_cb_data = data;
292 Eina_Bool __is_current_mode_portrait(void)
294 return __is_portrait_mode;
297 static void __set_portrait_mode(Eina_Bool is_portrait)
299 __is_portrait_mode = is_portrait;
303 void _hadnle_rename_popup_rotation(Eina_Bool is_portrait)
305 __MOBILE_AP_FUNC_ENTER__;
307 __set_portrait_mode(is_portrait);
309 rotate_cb(is_portrait, rotate_cb_data);
311 __MOBILE_AP_FUNC_EXIT__;
314 static Evas_Object *__rename_entry_icon_get(void *data, Evas_Object *obj, const char *part)
316 __MOBILE_AP_FUNC_ENTER__;
318 Evas_Object *entry = NULL;
319 Evas_Object *button = NULL;
321 char *device_name_utf = NULL;
322 static Elm_Entry_Filter_Limit_Size limit_filter_data;
325 ERR("data is null\n");
328 mh_appdata_t *ad = (mh_appdata_t*) data;
330 if (strcmp(part, "elm.icon.entry")) {
334 entry = elm_entry_add(obj);
335 elm_entry_single_line_set(entry, EINA_TRUE);
336 elm_entry_scrollable_set(entry, EINA_TRUE);
337 limit_filter_data.max_char_count = DEVICE_NAME_LENGTH_MAX;
338 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
340 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
341 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
342 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
343 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
344 elm_object_domain_translatable_part_text_set(entry, "elm.guide", PACKAGE,
347 elm_entry_input_panel_return_key_type_set(entry,
348 ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
349 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
350 ad->rename_entry = entry;
352 device_name_utf = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
353 if (device_name_utf == NULL) {
354 ERR("vconf_get_str failed \n");
357 ptr = elm_entry_utf8_to_markup(device_name_utf);
359 ERR("elm_entry_utf8_to_markup is failed\n");
360 free(device_name_utf);
363 elm_entry_entry_set(entry, ptr);
365 free(device_name_utf);
367 elm_entry_cursor_end_set(entry);
369 evas_object_smart_callback_add(entry, "changed,user", __rename_popop_entry_changed_cb, ad);
370 evas_object_smart_callback_add(entry, "changed", __rename_popop_entry_changed_cb, ad);
371 evas_object_smart_callback_add(entry, "preedit,changed",
372 __rename_popop_entry_changed_cb, ad);
374 evas_object_smart_callback_add(entry, "maxlength,reached",
375 __device_name_maxlength_reached_cb, ad);
376 evas_object_smart_callback_add(entry, "focused", __entry_focused_cb, NULL);
377 evas_object_smart_callback_add(entry, "unfocused", __entry_unfocused_cb, NULL);
378 evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
379 __enter_key_down_cb, ad);
381 button = elm_button_add(obj);
382 elm_object_style_set(button, "search_clear");
383 elm_object_focus_allow_set(button, EINA_FALSE);
384 elm_object_part_content_set(entry, "elm.swallow.clear", button);
385 evas_object_smart_callback_add(button, "clicked", __eraser_btn_clicked_cb, ad);
386 evas_object_show(entry);
387 elm_object_focus_set(entry, EINA_TRUE);
391 static char *__rename_desc_label_get(void *data, Evas_Object *obj,
394 if (!strcmp(part, "elm.text.multiline" )) {
395 return g_strdup(STR_RENAME_DEVICE_MSG);
400 void _create_rename_device_popup(void *data)
402 __MOBILE_AP_FUNC_ENTER__;
405 ERR("data is null\n");
406 __MOBILE_AP_FUNC_EXIT__;
410 Evas_Object *popup = NULL;
411 Evas_Object *button = NULL;
412 Evas_Object *rename_btn = NULL;
413 Evas_Object *genlist = NULL;
414 Elm_Object_Item *item = NULL;
415 Evas_Object *layout = NULL;
416 mh_appdata_t *ad = (mh_appdata_t*) data;
418 if (ad->rename_popup) {
419 evas_object_del(ad->rename_popup);
420 ad->rename_popup = NULL;
423 popup = elm_popup_add(ad->layout);
424 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
425 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
426 "IDS_ST_HEADER_RENAME_DEVICE");
427 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
428 __rename_popup_keyback_cb, (void *)ad);
429 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
430 __rename_popup_mouseup_cb, (void *)ad);
432 layout = elm_layout_add(popup);
433 elm_layout_file_set(layout, FILE_PATH_OF_EDC, "rename_device_ly");
434 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
436 genlist = elm_genlist_add(layout);
437 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
438 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
439 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
440 elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
442 /* Entry genlist item */
443 ad->setup.rename_entry_itc = elm_genlist_item_class_new();
444 if (ad->setup.rename_entry_itc == NULL) {
445 ERR("elm_genlist_item_class_new failed\n");
446 __MOBILE_AP_FUNC_EXIT__;
449 ad->setup.rename_entry_itc->item_style = "entry";
450 ad->setup.rename_entry_itc->func.text_get = NULL;
451 ad->setup.rename_entry_itc->func.content_get = __rename_entry_icon_get;
452 ad->setup.rename_entry_itc->func.state_get = NULL;
453 ad->setup.rename_entry_itc->func.del = NULL;
455 elm_genlist_item_append(genlist, ad->setup.rename_entry_itc, ad,
456 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
458 /* Description genlist item */
459 ad->setup.rename_descp_itc = elm_genlist_item_class_new();
460 if (ad->setup.rename_descp_itc == NULL) {
461 ERR("elm_genlist_item_class_new failed\n");
462 __MOBILE_AP_FUNC_EXIT__;
465 ad->setup.rename_descp_itc->item_style = "multiline_sub";
466 ad->setup.rename_descp_itc->func.text_get = __rename_desc_label_get;
467 ad->setup.rename_descp_itc->func.content_get = NULL;
468 ad->setup.rename_descp_itc->func.state_get = NULL;
469 ad->setup.rename_descp_itc->func.del = NULL;
470 item = elm_genlist_item_append(genlist, ad->setup.rename_descp_itc, NULL, NULL,
471 ELM_GENLIST_ITEM_NONE, NULL, NULL);
472 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
474 button = elm_button_add(popup);
475 elm_object_style_set(button, "popup");
476 elm_object_text_set(button, STR_CANCEL);
477 elm_object_domain_translatable_text_set(button, PACKAGE, STR_CANCEL);
478 elm_object_part_content_set(popup, "button1", button);
479 evas_object_smart_callback_add(button, "clicked",
480 __rename_popup_cancel_cb, ad);
481 evas_object_show(button);
483 rename_btn = elm_button_add(popup);
484 ad->rename_button = rename_btn;
485 elm_object_style_set(rename_btn, "popup");
486 elm_object_domain_translatable_text_set(rename_btn, PACKAGE, STR_RENAME_DEVICE);
487 elm_object_part_content_set(popup, "button2", rename_btn);
488 evas_object_smart_callback_add(rename_btn, "clicked", __rename_popup_ok_cb, ad);
489 evas_object_show(rename_btn);
491 elm_genlist_realization_mode_set(genlist, EINA_TRUE);
492 evas_object_show(genlist);
493 elm_object_part_content_set(layout, "elm.swallow.layout", genlist);
494 evas_object_show(layout);
495 elm_object_content_set(popup, layout);
497 evas_object_show(popup);
498 ad->rename_popup = popup;
499 elm_object_focus_set(ad->rename_entry, EINA_TRUE);
501 __MOBILE_AP_FUNC_EXIT__;