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);
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);
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')
72 static void __rename_popop_entry_changed_cb(void *data, Evas_Object *obj,
75 __MOBILE_AP_FUNC_ENTER__;
76 mh_appdata_t *ad = (mh_appdata_t *)data;
78 const char *entry_text = NULL;
79 char *input_str = NULL;
80 bool is_space_string = FALSE;
82 entry_text = elm_entry_entry_get(obj);
83 input_str = elm_entry_markup_to_utf8(entry_text);
85 if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
86 if (elm_object_focus_get(obj)) {
87 if (elm_entry_is_empty(obj))
88 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
90 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
95 if (input_str == NULL || (strlen(input_str) == 0)) {
96 elm_object_disabled_set(ad->rename_button, TRUE);
97 elm_entry_input_panel_return_key_disabled_set(obj, TRUE);
104 is_space_string = __is_space_str(input_str);
105 if (is_space_string) {
106 elm_object_disabled_set(ad->rename_button, TRUE);
107 elm_entry_input_panel_return_key_disabled_set(ad->rename_entry, TRUE);
112 if (strlen(input_str) > 0) {
113 elm_object_disabled_set(ad->rename_button, FALSE);
114 elm_entry_input_panel_return_key_disabled_set(ad->rename_entry, FALSE);
119 __MOBILE_AP_FUNC_EXIT__;
122 static void __device_name_maxlength_reached_cb(void *data, Evas_Object *obj,
125 __MOBILE_AP_FUNC_ENTER__;
127 if (data == NULL || obj == NULL) {
128 ERR("The param is NULL\n");
132 char buf[MH_LABEL_LENGTH_MAX] = { 0, };
133 notification_error_e ret;
135 snprintf(buf, sizeof(buf), STR_PW_MAX_LEN_WARN_MSG, DEVICE_NAME_LENGTH_MAX);
136 ret = notification_status_message_post(buf);
137 if (ret != NOTIFICATION_ERROR_NONE)
138 ERR("notification_status_message_post() is failed : %d\n", ret);
140 __MOBILE_AP_FUNC_EXIT__;
143 static void __entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
145 __MOBILE_AP_FUNC_ENTER__;
147 if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
148 if (!elm_entry_is_empty(obj))
149 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
151 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
153 elm_object_signal_emit(obj, "elm,state,focus,on", "");
155 __MOBILE_AP_FUNC_EXIT__;
158 static void __entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
160 __MOBILE_AP_FUNC_ENTER__;
162 if (elm_object_part_content_get(obj, "elm.swallow.clear"))
163 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
164 elm_object_signal_emit(obj, "elm,state,focus,off", "");
166 __MOBILE_AP_FUNC_EXIT__;
169 static void __eraser_btn_clicked_cb(void *data, Evas_Object *obj,
172 __MOBILE_AP_FUNC_ENTER__;
175 ERR("data is null\n");
178 mh_appdata_t *ad = (mh_appdata_t*) data;
180 elm_entry_entry_set(ad->rename_entry, "");
181 elm_object_disabled_set(ad->rename_button, TRUE);
182 elm_entry_input_panel_return_key_disabled_set(ad->rename_entry, TRUE);
184 __MOBILE_AP_FUNC_EXIT__;
187 static void __rename_popup_cancel_cb(void *data, Evas_Object *obj,
190 __MOBILE_AP_FUNC_ENTER__;
192 if (data == NULL || obj == NULL) {
193 ERR("data is null\n");
196 mh_appdata_t *ad = (mh_appdata_t*) data;
198 if (ad->rename_popup) {
199 evas_object_del(ad->rename_popup);
200 ad->rename_popup = NULL;
202 if (ad->rename_entry) {
203 evas_object_del(ad->rename_entry);
204 ad->rename_entry = NULL;
206 __set_rotate_cb(NULL, NULL);
208 __MOBILE_AP_FUNC_EXIT__;
212 static void __rename_popup_ok_cb(void *data, Evas_Object *obj,
215 __MOBILE_AP_FUNC_ENTER__;
217 if (data == NULL || obj == NULL) {
218 ERR("data is null\n");
221 mh_appdata_t *ad = (mh_appdata_t*) data;
222 char *device_name_str = NULL;
223 const char *entry_str = elm_entry_entry_get(ad->rename_entry);
225 device_name_str = elm_entry_markup_to_utf8(entry_str);
226 if (device_name_str == NULL) {
227 ERR("elm_entry_utf8_to_markup is failed\n");
231 DBG("New device name:[%s]\n", device_name_str);
232 __set_rotate_cb(NULL, NULL);
233 if (ad->rename_popup) {
234 evas_object_del(ad->rename_popup);
235 ad->rename_popup = NULL;
237 if (ad->rename_entry) {
238 evas_object_del(ad->rename_entry);
239 ad->rename_entry = NULL;
241 if (g_strcmp0(ad->setup.device_name, device_name_str)) {
242 if (vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, device_name_str) != 0)
243 DBG("Set vconf[%s] failed\n", VCONFKEY_SETAPPL_DEVICE_NAME_STR);
245 g_strlcpy(ad->setup.device_name, entry_str,
246 sizeof(ad->setup.device_name));
248 if (ad->main.help_item != NULL) {
249 if (ad->main.help_item)
250 elm_genlist_item_update(ad->main.help_item);
253 if (ad->setup.name_item != NULL) {
254 if (ad->setup.name_item)
255 elm_genlist_item_update(ad->setup.name_item);
258 free(device_name_str);
260 __MOBILE_AP_FUNC_EXIT__;
264 static void __enter_key_down_cb(void *data, Evas *evas, Evas_Object *obj,
267 __MOBILE_AP_FUNC_ENTER__;
269 Evas_Event_Key_Down *ev = event_info;
271 if (g_strcmp0(ev->key, "KP_Enter") == 0 ||
272 g_strcmp0(ev->key, "Return") == 0) {
273 Ecore_IMF_Context *imf_context;
274 elm_entry_cursor_end_set(obj);
275 imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(obj);
277 ecore_imf_context_input_panel_hide(imf_context);
278 elm_object_focus_set(obj, EINA_FALSE);
280 __MOBILE_AP_FUNC_EXIT__;
283 static void __set_rotate_cb(int (*cb)(Eina_Bool, void*), void *data)
286 rotate_cb_data = data;
289 Eina_Bool __is_current_mode_portrait(void)
291 return __is_portrait_mode;
294 static void __set_portrait_mode(Eina_Bool is_portrait)
296 __is_portrait_mode = is_portrait;
300 void _hadnle_rename_popup_rotation(Eina_Bool is_portrait)
302 __MOBILE_AP_FUNC_ENTER__;
304 __set_portrait_mode(is_portrait);
306 rotate_cb(is_portrait, rotate_cb_data);
308 __MOBILE_AP_FUNC_EXIT__;
311 static Evas_Object *__rename_entry_icon_get(void *data, Evas_Object *obj, const char *part)
313 __MOBILE_AP_FUNC_ENTER__;
315 Evas_Object *entry = NULL;
316 Evas_Object *button = NULL;
318 char *device_name_utf = NULL;
319 static Elm_Entry_Filter_Limit_Size limit_filter_data;
322 ERR("data is null\n");
325 mh_appdata_t *ad = (mh_appdata_t*) data;
327 if (strcmp(part, "elm.icon.entry"))
330 entry = elm_entry_add(obj);
331 elm_entry_single_line_set(entry, EINA_TRUE);
332 elm_entry_scrollable_set(entry, EINA_TRUE);
333 limit_filter_data.max_char_count = DEVICE_NAME_LENGTH_MAX;
334 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
336 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
337 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
338 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
339 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
340 elm_object_domain_translatable_part_text_set(entry, "elm.guide", PACKAGE,
343 elm_entry_input_panel_return_key_type_set(entry,
344 ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
345 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
346 ad->rename_entry = entry;
348 device_name_utf = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
349 if (device_name_utf == NULL) {
350 ERR("vconf_get_str failed \n");
353 ptr = elm_entry_utf8_to_markup(device_name_utf);
355 ERR("elm_entry_utf8_to_markup is failed\n");
356 free(device_name_utf);
359 elm_entry_entry_set(entry, ptr);
361 free(device_name_utf);
363 elm_entry_cursor_end_set(entry);
365 evas_object_smart_callback_add(entry, "changed,user", __rename_popop_entry_changed_cb, ad);
366 evas_object_smart_callback_add(entry, "changed", __rename_popop_entry_changed_cb, ad);
367 evas_object_smart_callback_add(entry, "preedit,changed",
368 __rename_popop_entry_changed_cb, ad);
370 evas_object_smart_callback_add(entry, "maxlength,reached",
371 __device_name_maxlength_reached_cb, ad);
372 evas_object_smart_callback_add(entry, "focused", __entry_focused_cb, NULL);
373 evas_object_smart_callback_add(entry, "unfocused", __entry_unfocused_cb, NULL);
374 evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
375 __enter_key_down_cb, ad);
377 button = elm_button_add(obj);
378 elm_object_style_set(button, "search_clear");
379 elm_object_focus_allow_set(button, EINA_FALSE);
380 elm_object_part_content_set(entry, "elm.swallow.clear", button);
381 evas_object_smart_callback_add(button, "clicked", __eraser_btn_clicked_cb, ad);
382 evas_object_show(entry);
383 elm_object_focus_set(entry, EINA_TRUE);
387 static char *__rename_desc_label_get(void *data, Evas_Object *obj,
390 if (!strcmp(part, "elm.text.multiline"))
391 return g_strdup(STR_RENAME_DEVICE_MSG);
396 void _create_rename_device_popup(void *data)
398 __MOBILE_AP_FUNC_ENTER__;
401 ERR("data is null\n");
402 __MOBILE_AP_FUNC_EXIT__;
406 Evas_Object *popup = NULL;
407 Evas_Object *button = NULL;
408 Evas_Object *rename_btn = NULL;
409 Evas_Object *genlist = NULL;
410 Elm_Object_Item *item = NULL;
411 Evas_Object *layout = NULL;
412 mh_appdata_t *ad = (mh_appdata_t*) data;
414 if (ad->rename_popup) {
415 evas_object_del(ad->rename_popup);
416 ad->rename_popup = NULL;
419 popup = elm_popup_add(ad->layout);
420 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
421 elm_object_domain_translatable_part_text_set(popup, "title,text", PACKAGE,
422 "IDS_ST_HEADER_RENAME_DEVICE");
423 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
424 __rename_popup_keyback_cb, (void *)ad);
425 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP,
426 __rename_popup_mouseup_cb, (void *)ad);
428 layout = elm_layout_add(popup);
429 elm_layout_file_set(layout, FILE_PATH_OF_EDC, "rename_device_ly");
430 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
432 genlist = elm_genlist_add(layout);
433 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
434 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
435 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
436 elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
438 /* Entry genlist item */
439 ad->setup.rename_entry_itc = elm_genlist_item_class_new();
440 if (ad->setup.rename_entry_itc == NULL) {
441 ERR("elm_genlist_item_class_new failed\n");
442 __MOBILE_AP_FUNC_EXIT__;
445 ad->setup.rename_entry_itc->item_style = "entry";
446 ad->setup.rename_entry_itc->func.text_get = NULL;
447 ad->setup.rename_entry_itc->func.content_get = __rename_entry_icon_get;
448 ad->setup.rename_entry_itc->func.state_get = NULL;
449 ad->setup.rename_entry_itc->func.del = NULL;
451 elm_genlist_item_append(genlist, ad->setup.rename_entry_itc, ad,
452 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
454 /* Description genlist item */
455 ad->setup.rename_descp_itc = elm_genlist_item_class_new();
456 if (ad->setup.rename_descp_itc == NULL) {
457 ERR("elm_genlist_item_class_new failed\n");
458 __MOBILE_AP_FUNC_EXIT__;
461 ad->setup.rename_descp_itc->item_style = "multiline_sub";
462 ad->setup.rename_descp_itc->func.text_get = __rename_desc_label_get;
463 ad->setup.rename_descp_itc->func.content_get = NULL;
464 ad->setup.rename_descp_itc->func.state_get = NULL;
465 ad->setup.rename_descp_itc->func.del = NULL;
466 item = elm_genlist_item_append(genlist, ad->setup.rename_descp_itc, NULL, NULL,
467 ELM_GENLIST_ITEM_NONE, NULL, NULL);
468 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
470 button = elm_button_add(popup);
471 elm_object_style_set(button, "popup");
472 elm_object_text_set(button, STR_CANCEL);
473 elm_object_domain_translatable_text_set(button, PACKAGE, STR_CANCEL);
474 elm_object_part_content_set(popup, "button1", button);
475 evas_object_smart_callback_add(button, "clicked",
476 __rename_popup_cancel_cb, ad);
477 evas_object_show(button);
479 rename_btn = elm_button_add(popup);
480 ad->rename_button = rename_btn;
481 elm_object_style_set(rename_btn, "popup");
482 elm_object_domain_translatable_text_set(rename_btn, PACKAGE, STR_RENAME_DEVICE);
483 elm_object_part_content_set(popup, "button2", rename_btn);
484 evas_object_smart_callback_add(rename_btn, "clicked", __rename_popup_ok_cb, ad);
485 evas_object_show(rename_btn);
487 elm_genlist_realization_mode_set(genlist, EINA_TRUE);
488 evas_object_show(genlist);
489 elm_object_part_content_set(layout, "elm.swallow.layout", genlist);
490 evas_object_show(layout);
491 elm_object_content_set(popup, layout);
493 evas_object_show(popup);
494 ad->rename_popup = popup;
495 elm_object_focus_set(ad->rename_entry, EINA_TRUE);
497 __MOBILE_AP_FUNC_EXIT__;