4 * Copyright 2012 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.
24 #include <ui-gadget.h>
25 #include <notification.h>
27 #include <vconf-keys.h>
29 #include <paper_size.h>
30 #include <previewgen.h>
33 #include "mobileprint.h"
34 #include "pts_common.h"
35 #include "pts_main_view.h"
36 #include "pts_setting_view.h"
37 #include "preview_content.h"
38 #include "preview_util.h"
40 static char *WiFi_Type_String[] = {
41 "Wi-Fi", "Wi-Fi Direct"
47 Evas_Object *radio_group;
48 } radio_print_list_data_t;
50 static Elm_Genlist_Item_Class list_itc;
51 //static Elm_Genlist_Item_Class refresh_itc;
52 static Elm_Genlist_Item_Class wifi_list_itc;
54 static Evas_Object *printer_list_radio_main = NULL;
56 void pt_post_print_search(pts_appdata_t *ad);
57 Evas_Object *pts_create_no_found_popup(Evas_Object *parent, void *refresh_cb, void *cancel_cb);
59 static char *_pts_wifi_text_get(void *data, Evas_Object *obj, const char *part)
61 int index = (int)data;
63 if (!strcmp(part, "elm.text")) {
64 return strdup(WiFi_Type_String[index]);
66 return strdup("Unknown index");
70 static void _wifi_direct_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
73 PTS_RET_IF(ug == NULL, "ug is NULL");
75 Evas_Object *base, *win;
77 base = ug_get_layout(ug);
83 win = ug_get_window();
85 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
86 elm_win_resize_object_add(win, base);
88 ug_disable_effect(ug);
89 evas_object_show(base);
93 static void _wifi_direct_ug_result_cb(ui_gadget_h ug, service_h result, void *priv)
96 pts_appdata_t *ad = (pts_appdata_t *)priv;
97 PTS_RET_IF(ad == NULL, "ad is NULL");
100 service_get_extra_data(result, "ip_address", &ip_addr);
102 /* Check IP address of connected peer */
103 // TODO - Add active printer set routine to CUPS using this address
104 PTS_DEBUG("IP address of WiFi Direct Printer : %s", ip_addr);
105 PTS_IF_FREE_MEM(ad->search_info.ip_address);
106 ad->search_info.ip_address = strdup(ip_addr);
107 PTS_RET_IF(ad->search_info.ip_address == NULL, "ad->search_info.ip_address is NULL");
109 PTS_DEBUG("Not found ip_address");
115 static void _wifi_direct_ug_destroy_cb(ui_gadget_h ug, void *priv)
118 pts_appdata_t *ad = (pts_appdata_t *)priv;
119 PTS_RET_IF(ug == NULL || ad == NULL, "Invalid argument");
121 pts_search_printer(ad);
126 static int pts_launch_wifi_qs(void)
132 tpid = sysman_get_pid("wifi-qs");
134 PTS_DEBUG("wifi-qs existed !\n");
142 ret = syspopup_launch("wifi-qs", b);
144 PTS_DEBUG("syspopup is failed. [%d]\n", ret);
155 void _wifi_qs_monitoring_cb(keynode_t *key, void *data)
158 int wifi_qs_exit = -1;
159 int error_code = vconf_get_int(VCONFKEY_WIFI_QS_EXIT, &wifi_qs_exit);
161 PTS_RET_IF(error_code == -1, "Error when check wifi qs exit status");
163 vconf_ignore_key_changed(VCONFKEY_WIFI_QS_EXIT, _wifi_qs_monitoring_cb);
165 pts_appdata_t *ad = (pts_appdata_t *)data;
167 pts_search_printer(ad);
171 static void pts_launch_wifi_direct_ug(pts_appdata_t *ad)
176 struct ug_cbs cbs = {0, };
177 service_h service = NULL;
179 memset(&cbs, 0x00, sizeof(struct ug_cbs));
180 cbs.layout_cb = _wifi_direct_ug_layout_cb;
181 cbs.result_cb = _wifi_direct_ug_result_cb;
182 cbs.destroy_cb = _wifi_direct_ug_destroy_cb;
185 service_create(&service);
186 ret = service_add_extra_data(service, "device_filter", "printer");
187 if (ret != SERVICE_ERROR_NONE) { goto ERROR; }
188 ret= service_add_extra_data(service, "auto_exit", "on");
189 if (ret != SERVICE_ERROR_NONE) { goto ERROR; }
190 ret = service_add_extra_data(service, "multi_connect", "off");
191 if (ret != SERVICE_ERROR_NONE) { goto ERROR; }
192 ret= service_add_extra_data(service, "title_string", _("IDS_COM_OPT1_WI_FI_DIRECT"));
193 if (ret != SERVICE_ERROR_NONE) { goto ERROR; }
195 ug_create(NULL, "setting-wifidirect-efl", UG_MODE_FULLVIEW, service, &cbs);
196 service_destroy(service);
202 PTS_DEBUG("Failed to create wifi direct ug(%d)", ret);
203 service_destroy(service);
209 static void _pts_wifi_list_sel(void *data, Evas_Object *obj, void *event_info)
212 pts_appdata_t *ad = pts_get_appdata();
215 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
218 PTS_IF_DEL_OBJ(ad->select_info.wifi_type_popup);
222 index = (int)elm_object_item_data_get(item);
223 if (index == 0) { // Wi-Fi
224 ret = pts_launch_wifi_qs();
226 // Currently ret value is procces id of wifi_qs.
227 PTS_DEBUG("Now register vocnf cb for VCONFKEY_WIFI_QS_EXIT");
228 vconf_notify_key_changed(VCONFKEY_WIFI_QS_EXIT, _wifi_qs_monitoring_cb, ad);
230 PTS_DEBUG("Failed to launch wifi-qs(%d)",ret);
232 } else if (index == 1) { // Wi-Fi Direct
233 pts_launch_wifi_direct_ug(ad);
235 PTS_DEBUG("Unknown index");
237 PTS_IF_DEL_OBJ(ad->select_info.wifi_type_popup);
242 static void _pts_refresh_cb(void *data, Evas_Object *obj, void *event_info)
245 pts_appdata_t *ad = pts_get_appdata();
246 PTS_RET_IF(ad == NULL, "ad is NULL");
248 PTS_IF_DEL_OBJ(ad->list_info.no_found_popup);
249 PTS_IF_DEL_OBJ(ad->list_info.printer_list_popup);
251 pts_search_printer(ad);
257 static void _pts_cancel_cb(void *data, Evas_Object *obj, void *event_info)
260 pts_appdata_t *ad = pts_get_appdata();
261 PTS_RET_IF(ad == NULL, "ad is NULL");
263 if (ad->search_info.print_search_mode == PTS_SEARCH_INITIAL) {
264 PTS_IF_DEL_OBJ(ad->list_info.printer_list_popup);
269 PTS_IF_DEL_OBJ(ad->list_info.no_found_popup);
270 PTS_IF_DEL_OBJ(ad->select_info.wifi_type_popup);
273 if (ad->list_info.active_printer == NULL) {
274 PTS_DEBUG("No active printer. So remove all option");
275 elm_genlist_item_update(ad->setting_info.printer_item);
276 elm_object_item_del(ad->setting_info.header_separator_item);
277 elm_object_item_del(ad->setting_info.item_paper_size);
278 elm_object_item_del(ad->setting_info.item_paper_copies);
279 elm_object_item_del(ad->setting_info.item_page_range);
280 elm_object_item_del(ad->setting_info.item_paper_quality);
281 elm_object_item_del(ad->setting_info.item_paper_type);
282 elm_object_item_del(ad->setting_info.item_grayscale);
283 elm_object_item_del(ad->setting_info.footer_separator_item);
289 static int pts_save_selected_printer(pts_appdata_t *ad, pt_printer_mgr_t *pt)
292 PTS_RETV_IF(pt == NULL, PT_ERR_INVALID_PARAM, "printer_info is NULL.");
295 PTS_DEBUG("pt name is %s", pt->name);
296 PTS_DEBUG("pt address %x", pt);
298 /* Check whether the printer is already activated or not. */
299 if (NULL != ad->list_info.active_printer) {
300 if ((strcmp(ad->list_info.active_printer->name, pt->name) == 0) &&
301 (strcmp(ad->list_info.active_printer->address, pt->address) == 0)) {
302 // if same printer, then nothing to do...
303 PTS_DEBUG("Same printer is selected. No update required. %x", pt);
308 ret = pt_set_active_printer(pt);
309 PTS_RETV_IF(ret != PT_ERR_NONE, PT_ERR_FAIL, "Can not set active printer.");
311 ret = pt_set_default_printer(pt);
312 PTS_RETV_IF(ret != PT_ERR_NONE, PT_ERR_FAIL, "Can not set default printer.");
314 if (NULL == ad->list_info.active_printer) {
315 ad->list_info.active_printer = (pt_printer_mgr_t *)malloc(sizeof(pt_printer_mgr_t));
316 PTS_RETV_IF(ad->list_info.active_printer == NULL, PT_ERR_NO_MEMORY, "Can allocate memory");
318 memset(ad->list_info.active_printer, 0, sizeof(pt_printer_mgr_t));
319 memcpy(ad->list_info.active_printer, pt, sizeof(pt_printer_mgr_t));
321 ad->setting_info.paper_size = (Elm_Object_Item *)realloc(ad->setting_info.paper_size, pt_get_print_option_papersize_num() * sizeof(Elm_Object_Item *));
322 memset(ad->setting_info.paper_size, 0, pt_get_print_option_papersize_num() * sizeof(Elm_Object_Item *));
327 static void _pts_printer_list_cancel_cb(void *data, Evas_Object *obj, void *event_info)
330 struct appdata *ad = pts_get_appdata();
332 PTS_IF_DEL_OBJ(data);
334 if (ad->search_info.print_search_mode == PTS_SEARCH_INITIAL) {
339 //Don't terminate mobileprint. Previous screen is setting view.
345 static void _pts_printer_list_ok_cb(void *data, Evas_Object *obj, void *event_info)
348 pts_appdata_t *ad = (pts_appdata_t *)data;
349 PTS_RET_IF(ad == NULL, "ad is NULL");
351 PTS_RET_IF(ad->list_info.select_printer == NULL, "No supported printer");
352 PTS_IF_DEL_OBJ(printer_list_radio_main);
353 PTS_IF_DEL_OBJ(ad->list_info.printer_list_popup);
355 pts_save_selected_printer(ad, ad->list_info.select_printer);
357 if (ad->search_info.selection_done_cb != NULL) {
358 ad->search_info.selection_done_cb(ad->search_info.printer_search_user_data);
366 * select the printer from the searched printers list
368 static void __pts_search_print_list_sel(void *data, Evas_Object *obj, void *event_info)
371 PTS_RET_IF(data == NULL, "data is NULL");
372 PTS_RET_IF(event_info == NULL, "event_info is NULL");
373 pts_appdata_t *ad = (pts_appdata_t *)data;
374 Elm_Object_Item *item = event_info;
376 pt_printer_mgr_t *pt = NULL;
377 radio_print_list_data_t *core = NULL;
379 elm_genlist_item_selected_set(item, EINA_FALSE);
381 core = (radio_print_list_data_t *)elm_object_item_data_get(item);
382 PTS_RET_IF(core == NULL, "core is NULL");
384 PTS_RET_IF(pt == NULL, "pt is NULL");
386 PTS_DEBUG("Selected printer information: index=[%d]", core->radio_index);
387 PTS_DEBUG("pt->name : %s", pt->name);
388 PTS_DEBUG("pt->address : %s", pt->address);
390 ad->list_info.select_printer = pt;
391 elm_radio_value_set(core->radio_group, core->radio_index);
393 // Now call real event trigger to update radio button when selected.
394 elm_genlist_item_update(item);
400 * get the value of the label
402 static char *__pts_list_view_label_get(void *data, Evas_Object *obj, const char *part)
405 radio_print_list_data_t *core = (radio_print_list_data_t *) data;
406 pt_printer_mgr_t *item = core->pt;
407 PTS_RETV_IF(item == NULL, NULL, "item is NULL");
409 if (strcmp(part, "elm.text.1") == 0) {
411 char *printer_label = strdup(item->name);
412 pts_unstandardization(printer_label);
413 return printer_label;
415 } else if (strcmp(part, "elm.text.2") == 0) {
417 if (item->is_ppd_exist == FALSE) {
418 return strdup(_("IDS_COM_POP_UNSUPPORTED"));
420 return pts_parse_protocol(item->address);
430 * set the icon of the obj
432 static Evas_Object *__pts_list_view_icon_get(void *data, Evas_Object *obj, const char *part)
436 radio_print_list_data_t *core = (radio_print_list_data_t *) data;
437 pts_appdata_t *ad = pts_get_appdata();
438 PTS_RETV_IF(core == NULL || ad == NULL, NULL, "Invalid argument");
440 pt_printer_mgr_t *pt = core->pt;
441 Evas_Object *radio = NULL;
443 if (!strcmp(part, "elm.icon") || !strcmp(part, "elm.swallow.icon")) {
445 radio = elm_radio_add(obj);
446 elm_radio_state_value_set(radio, core->radio_index);
447 elm_radio_group_add(radio, core->radio_group);
448 if (ad->list_info.active_printer != NULL) {
449 if (strcmp(ad->list_info.active_printer->name, pt->name) ==0 &&
450 strcmp(ad->list_info.active_printer->address, pt->address) ==0) {
451 elm_radio_value_set(radio, core->radio_index);
452 ad->list_info.select_printer = pt;
454 PTS_DEBUG("Printer[%d] name=[%s], address=[%s] -> Active", core->radio_index, pt->name, pt->address);
456 PTS_DEBUG("Printer[%d] name=[%s], address=[%s] -> x", core->radio_index, pt->name, pt->address);
460 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
461 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
471 static Evas_Object *__pts_refresh_icon_get(void *data, Evas_Object *obj, const char *part)
476 pts_appdata_t *ad = (pts_appdata_t *)data;
477 PTS_RETV_IF(ad == NULL, NULL, "Invalid argument");
479 if (!strcmp(part, "elm.icon")) {
480 btn1 = elm_button_add(obj);
481 elm_object_text_set(btn1, _("IDS_COM_SK_REFRESH"));
482 //elm_object_part_content_set(obj, "button1", btn1);
483 evas_object_smart_callback_add(btn1, "clicked", _pts_refresh_cb, ad);
487 PTS_DEBUG("Unknwon part : %s", part);
496 * popup when machine is unsupported
498 static Eina_Bool __pts_exit_cb(void *data)
501 pts_appdata_t *ad = (pts_appdata_t *) data;
502 PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is NULL");
508 return ECORE_CALLBACK_CANCEL;
512 * popup error when searching printers failed
514 static Eina_Bool __pts_list_view_popup_error(void *data)
517 pts_appdata_t *ad = (pts_appdata_t *) data;
518 PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is NULL");
520 ad->search_info.is_process = 0;/*process is complete*/
522 PTS_IF_DEL_OBJ(ad->search_info.popup);
524 PTS_DEBUG("search printer failed");
525 pts_create_popup(ad->search_info.print_search_popup_parent, _("IDS_ASEML_POP_SEARCH_FAILED"), 1.0);
526 ecore_timer_add(1, (Ecore_Task_Cb)__pts_exit_cb, (void *)ad);
531 return ECORE_CALLBACK_CANCEL;
534 // pts_create_wifi_popup
535 Evas_Object *pts_create_wifi_type_selector_popup(Evas_Object *parent)
539 Evas_Object *popup = elm_popup_add(parent);
540 elm_object_style_set(popup,"min_menustyle");
541 elm_object_part_text_set(popup, "title,text", _("IDS_PRT_BODY_CONNECT_TO_WI_FI_NETWORK_TO_PRINT"));
542 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
544 /* accessability - screen reader support */
545 Evas_Object *po, *eo, *ao;
546 eo = elm_layout_edje_get(popup);
547 po = edje_object_part_object_get(eo, "access.title");
548 ao = elm_access_object_get(po);
549 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, _("IDS_PRT_BODY_CONNECT_TO_WI_FI_NETWORK_TO_PRINT"));
551 Evas_Object *cancel_button = elm_button_add(popup);
552 elm_object_style_set(cancel_button,"popup_button/default");
553 elm_object_text_set(cancel_button, _("IDS_COM_SK_CANCEL"));
554 elm_access_info_set(cancel_button, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_CANCEL_CONNECT_WIFI);
555 elm_object_part_content_set(popup, "button1", cancel_button);
556 evas_object_smart_callback_add(cancel_button, "clicked", _pts_cancel_cb, NULL);
558 wifi_list_itc.item_style = "1text";
559 wifi_list_itc.func.text_get = _pts_wifi_text_get;
560 wifi_list_itc.func.content_get = NULL;
561 wifi_list_itc.func.state_get = NULL;
562 wifi_list_itc.func.del = NULL;
564 Evas_Object *genlist = elm_genlist_add(popup);
565 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
566 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
569 for (index = 0; index < 2; index++) {
570 elm_genlist_item_append(genlist, &wifi_list_itc, (void *) index, NULL,
571 ELM_GENLIST_ITEM_NONE, _pts_wifi_list_sel, NULL);
574 Evas_Object *box = elm_box_add(popup);
575 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
577 elm_box_pack_end(box, genlist);
578 evas_object_size_hint_min_set(box, 400 * elm_config_scale_get(), elm_genlist_items_count(genlist) * 114 * elm_config_scale_get());
579 elm_object_content_set(popup, box);
581 evas_object_show(genlist);
582 evas_object_show(popup);
583 evas_object_show(parent);
589 Evas_Object *pts_create_no_found_popup(Evas_Object *parent, void *refresh_cb, void *cancel_cb)
593 Evas_Object *popup = elm_popup_add(parent);
594 //elm_object_style_set(popup,"menustyle");
595 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
596 elm_object_text_set(popup, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"));
597 // evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb,
600 Evas_Object *refresh_button = elm_button_add(popup);
601 //elm_object_style_set(refresh_button,"popup_button/default");
602 elm_object_text_set(refresh_button, _("IDS_COM_SK_REFRESH"));
603 elm_object_part_content_set(popup, "button1", refresh_button);
604 evas_object_smart_callback_add(refresh_button, "clicked", refresh_cb, NULL);
606 Evas_Object *cancel_button = elm_button_add(popup);
607 //elm_object_style_set(cancel_button,"popup_button/default");
608 elm_object_text_set(cancel_button, _("IDS_COM_SK_CANCEL"));
609 elm_object_part_content_set(popup, "button2", cancel_button);
610 evas_object_smart_callback_add(cancel_button, "clicked", cancel_cb, NULL);
612 evas_object_show(popup);
613 evas_object_show(parent);
620 * create the content of the list view
622 Evas_Object *pts_create_content_printer_list(Evas_Object *parent, pts_appdata_t *ad, int *print_counter)
625 PTS_RETV_IF(ad == NULL, NULL, "ad is NULL");
627 Evas_Object *genlist = NULL;
628 Elm_Object_Item *git;
629 genlist = elm_genlist_add(parent);
631 // ToDo: Make sure that printer_list_radio_main always is NULL at here..
632 //if (!printer_list_radio_main) {
633 printer_list_radio_main = elm_radio_add(genlist);
634 elm_radio_state_value_set(printer_list_radio_main, 0);
635 elm_radio_value_set(printer_list_radio_main, 1);
638 list_itc.item_style = "2text.1icon.4"; // Left Icon, Right Main/Sub Text
639 list_itc.func.text_get = __pts_list_view_label_get;
640 list_itc.func.content_get = __pts_list_view_icon_get;
641 list_itc.func.state_get = NULL;
642 list_itc.func.del = NULL;
645 refresh_itc.item_style = "1icon"; // Text Button
646 refresh_itc.func.text_get = NULL;
647 refresh_itc.func.content_get = __pts_refresh_icon_get;
648 refresh_itc.func.state_get = NULL;
649 refresh_itc.func.del = NULL;
652 pt_printer_mgr_t *it = NULL;
653 Eina_List *cursor = NULL;
655 // printer_list_radio_main is index zero.
656 // Thus radio index starts from 1.
658 radio_print_list_data_t *core = NULL;
660 ad->list_info.select_printer = NULL;
662 EINA_LIST_FOREACH(ad->list_info.printer_list, cursor, it) {
664 if (ad->list_info.select_printer == NULL && it->is_ppd_exist == TRUE) {
665 // set the first printer as default one.
666 ad->list_info.select_printer = it;
668 PTS_DEBUG("printer %d\n", radio_index);
669 core = (radio_print_list_data_t *)malloc(sizeof(radio_print_list_data_t));
670 core->radio_index = radio_index;
672 core->radio_group = printer_list_radio_main;
673 //core->ugd = ld->ugd;
675 git = elm_genlist_item_append(
680 ELM_GENLIST_ITEM_NONE,
681 __pts_search_print_list_sel,
684 if (it->is_ppd_exist == FALSE) {
685 elm_object_item_disabled_set(git, EINA_TRUE);
690 *print_counter = radio_index-1;
691 PTS_DEBUG("printer num = %d\n", *print_counter);
693 evas_object_show(genlist);
698 Evas_Object *pts_create_printer_list_popup(Evas_Object *parent, pts_appdata_t *ad)
702 Evas_Object *genlist;
703 Evas_Object *ok_button;
704 Evas_Object *refresh_button;
705 Evas_Object *cancel_button;
709 // Currently min_menustyle does not support "2text.1icon.4" genlist.
710 // When min_menustyle supports it, change this.
711 // To avoid this limitation, applied box object.
712 popup = elm_popup_add(parent);
713 //elm_object_style_set(popup,"menustyle");
714 elm_object_style_set(popup,"min_menustyle");
715 elm_object_part_text_set(popup, "title,text", _("IDS_PRT_BODY_SELECT_PRINTER"));
716 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
717 elm_access_info_set(popup, ELM_ACCESS_CONTEXT_INFO, _("IDS_PRT_BODY_SELECT_PRINTER")); //FIXME: should be set to title, not popup itself
719 /* accessability - screen reader support */
720 Evas_Object *po, *eo, *ao;
721 eo = elm_layout_edje_get(popup);
722 po = edje_object_part_object_get(eo, "access.title");
723 ao = elm_access_object_get(po);
724 elm_access_info_set(ao, ELM_ACCESS_INFO, _("IDS_PRT_BODY_SELECT_PRINTER"));
725 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_PRINTERS_LIST_IS_BELOW);
727 ok_button = elm_button_add(popup);
728 elm_object_style_set(ok_button,"popup_button/default");
729 elm_object_text_set(ok_button, _("IDS_COM_SK_OK"));
730 elm_access_info_set(ok_button, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_CONFIRM_SELECTED_PRINTER);
731 elm_object_part_content_set(popup, "button1", ok_button);
732 evas_object_smart_callback_add(ok_button, "clicked", _pts_printer_list_ok_cb, ad);
734 refresh_button = elm_button_add(popup);
735 elm_object_style_set(refresh_button,"popup_button/default");
736 elm_object_text_set(refresh_button, _("IDS_COM_SK_REFRESH"));
737 elm_access_info_set(ok_button, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_REFRESH_SEARCHING_PRINTERS);
738 elm_object_part_content_set(popup, "button2", refresh_button);
739 evas_object_smart_callback_add(refresh_button, "clicked", _pts_refresh_cb, ad);
741 cancel_button = elm_button_add(popup);
742 elm_object_style_set(cancel_button,"popup_button/default");
743 elm_object_text_set(cancel_button, _("IDS_COM_SK_CANCEL"));
744 elm_access_info_set(cancel_button, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_CANCEL_PRINTING);
745 elm_object_part_content_set(popup, "button3", cancel_button);
746 evas_object_smart_callback_add(cancel_button, "clicked", _pts_printer_list_cancel_cb, popup);
748 genlist = pts_create_content_printer_list(parent, ad, &printer_num);
749 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
750 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
752 Evas_Object *box = elm_box_add(popup);
753 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
755 elm_box_pack_end(box, genlist);
758 * XXX - below 143 value is just for entry height of 2text.1icon.4 style in genlist
761 int rotate_angle = 0;
763 rotate_angle = elm_win_rotation_get(ad->win);
764 PTS_DEBUG("rotate_angle: %d", rotate_angle);
766 PTS_DEBUG("No ld->ugd->root_win");
769 ad->list_info.printer_list_popup_portrait_height = MIN(PRINTER_LIST_POPUP_H, elm_genlist_items_count(genlist) * 143) * elm_config_scale_get();
770 ad->list_info.printer_list_popup_landscape_height = MIN(PRINTER_LIST_POPUP_LN_H, elm_genlist_items_count(genlist) * 143) * elm_config_scale_get();
772 if (0 == rotate_angle || 180 == rotate_angle)
773 evas_object_size_hint_min_set(box,
774 PRINTER_LIST_POPUP_W * elm_config_scale_get(),
775 ad->list_info.printer_list_popup_portrait_height);
777 evas_object_size_hint_min_set(box,
778 PRINTER_LIST_POPUP_LN_W * elm_config_scale_get(),
779 ad->list_info.printer_list_popup_landscape_height);
781 ad->list_info.printer_list_popup_box = box;
782 ad->list_info.printer_list_popup = popup;
784 elm_object_content_set(popup, box);
785 evas_object_show(genlist);
786 evas_object_show(box);
787 evas_object_show(popup);
788 evas_object_show(parent);
794 void pts_search_printer_select(pts_appdata_t *ad)
796 // if (ugd->print_search_mode == PTS_SEARCH_INITIAL)
797 pts_create_printer_list_popup(ad->search_info.print_search_popup_parent, ad);
799 // pts_create_printer_list_view(ugd->print_search_popup_parent, ld);
805 * the response callback when search the printer
807 static void __pts_get_printer_cb(pt_response_data_t *cb)
810 PTS_RET_IF(cb == NULL, "response data is NULL");
812 pts_appdata_t *ad = cb->userdata;
813 PTS_RET_IF(ad == NULL, "ad is NULL");
815 ad->list_info.printer_list = cb->printerlist;
816 ad->search_info.is_process = 0; /*process is complete*/
818 /* destroy popup progress bar */
819 PTS_IF_DEL_OBJ(ad->search_info.popup);
822 * Not found any printer
824 if (NULL == ad->list_info.printer_list) {
826 * destroy popup progress bar
828 PTS_DEBUG("search printer failed");
829 PTS_IF_FREE_MEM(ad->list_info.active_printer);
830 ad->list_info.no_found_popup = pts_create_no_found_popup(ad->search_info.print_search_popup_parent,
837 /* get printer list count */
838 pt_count = eina_list_count(ad->list_info.printer_list);
839 PTS_DEBUG("Printer count is %d", pt_count);
842 pts_search_printer_select(ad);
845 // Control can't be reach here...
851 * This function let the app create the print searching popup
853 * @param[in] ld the pointer to the ug list structure
855 Evas_Object *pts_create_print_search_popup(Evas_Object *parent)
858 PTS_RETV_IF(parent == NULL, NULL, "parent is NULL");
861 Evas_Object *layout = NULL;
862 Evas_Object *progressbar = NULL;
863 Evas_Object *btn = NULL;
864 Evas_Object *popup = NULL;
866 popup = elm_popup_add(parent);
867 layout = pts_create_base_layout(popup, "popup_search");
868 progressbar = elm_progressbar_add(popup);
869 elm_object_style_set(progressbar, "list_process");
870 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
871 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
872 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
873 elm_progressbar_pulse(progressbar, EINA_TRUE);
874 elm_access_info_set(progressbar, ELM_ACCESS_INFO, _("IDS_PRT_BODY_SEARCHING_FOR_PRINTERS_ING")); //FIXME Screen reader doesn't pronounce it
875 evas_object_show(progressbar);
877 elm_object_part_content_set(layout, "elm.swallow.content", progressbar);
878 elm_object_part_text_set(layout, "elm.text", _("IDS_PRT_BODY_SEARCHING_FOR_PRINTERS_ING"));
880 /* accessability - screen reader support */
881 Evas_Object *po, *ao;
882 po = edje_object_part_object_get(layout, "elm.swallow.content");
883 ao = elm_access_object_get(po);
884 elm_access_info_set(ao, ELM_ACCESS_INFO, _("IDS_PRT_BODY_SEARCHING_FOR_PRINTERS_ING"));
886 elm_object_content_set(popup, layout);
887 btn = elm_button_add(popup);
888 elm_object_text_set(btn, _("IDS_COM_SK_CANCEL"));
889 elm_access_info_set(btn, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_CANCEL_SEARCHING_PRINTERS);
890 elm_object_part_content_set(popup, "button1", btn);
891 evas_object_smart_callback_add(btn, "clicked", _pts_cancel_cb, NULL);
893 evas_object_show(layout);
894 evas_object_show(popup);
895 evas_object_show(parent);
901 static gboolean __is_wifi_direct_connected(int net_info)
903 /** Connected with peer as GC */
904 if ((net_info&PT_CONNECTION_WIFI_DIRECT)>0) {
910 static gboolean __is_wifi_connected(int net_info)
912 if ((net_info&PT_CONNECTION_WIFI)>0) {
918 static gboolean __is_usb_host_connected(int net_info)
920 if ((net_info&PT_CONNECTION_USB)>0) {
926 static gboolean __is_connected(int net_info)
934 static gboolean __is_valid_ip_address(const char *ip_address)
936 PTS_RETV_IF(ip_address == NULL, FALSE, "ip_address is NULL");
941 * start to search printer
943 void pts_search_printer(pts_appdata_t *ad)
946 PTS_RET_IF(ad == NULL, "ad is NULL");
949 ret = pt_get_connection_status(&net_type);
950 PTS_RET_IF(ret != PT_ERR_NONE, "Failed to get connection status(%d)", ret);
952 if (__is_connected(net_type)) {
953 if (__is_wifi_direct_connected(net_type)) {
954 ad->search_info.popup = pts_create_print_search_popup(ad->search_info.print_search_popup_parent);
955 ad->search_info.is_process = 1; /* in process */
956 PTS_IF_DEL_TIMER(ad->search_info.search_err_timer);
958 ret = pt_get_printers(__pts_get_printer_cb, ad);
959 if (PT_ERR_NONE != ret) {
960 ad->search_info.search_err_timer = ecore_timer_add(1.0, (Ecore_Task_Cb)__pts_list_view_popup_error, (void *)ad);
962 } else if (__is_wifi_connected(net_type) || __is_usb_host_connected(net_type)) {
963 ad->search_info.popup = pts_create_print_search_popup(ad->search_info.print_search_popup_parent);
964 ad->search_info.is_process = 1; /* in process */
965 PTS_IF_DEL_TIMER(ad->search_info.search_err_timer);
966 ret = pt_get_printers(__pts_get_printer_cb, ad);
967 if (PT_ERR_NONE != ret) {
968 ad->search_info.search_err_timer = ecore_timer_add(1.0, (Ecore_Task_Cb)__pts_list_view_popup_error, (void *)ad);
971 PTS_DEBUG("Undefined connection status");
975 ad->select_info.wifi_type_popup = pts_create_wifi_type_selector_popup(ad->search_info.print_search_popup_parent);