[TSAM-11694] Merge client list into main view
[apps/native/ug-mobile-ap.git] / src / mh_view_main.c
index ab2a861..c1403dc 100755 (executable)
 #include "mh_string.h"
 
 static void __ctx_move_more_ctxpopup(Evas_Object *ctx, mh_appdata_t *ad);
-static void __ctx_delete_more_ctxpopup_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
-static void __create_ctxpopup_more_button(void *data, Evas_Object *obj, void *event_info);
+static void __ctx_delete_more_ctxpopup_cb(void *data, Evas *e, Evas_Object *obj,
+                                         void *event_info);
+static void __create_ctxpopup_more_button(void *data, Evas_Object *obj,
+                                         void *event_info);
 
 static Eina_Bool rotate_flag = EINA_FALSE;
 
@@ -36,20 +38,16 @@ void _genlist_update_device_item(mh_appdata_t *ad);
 mh_appdata_t *g_ad = NULL;
 #define UPDATE_INTERVAL 1
 
-void _select_connected_dev(void *data, Evas_Object *obj, void *event_info)
+void _list_connected_dev(mh_appdata_t *ap)
 {
        __MOBILE_AP_FUNC_ENTER__;
 
-       if (data == NULL) {
+       if (ap == NULL) {
                ERR("data is NULL\n");
                return;
        }
 
-       mh_appdata_t *ad = (mh_appdata_t *)data;
-
-       elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
-       _ctxpopup_more_button_callback_del(ad);
-       _create_connected_client_view(ad);
+       _add_connected_clients(ap);
        __MOBILE_AP_FUNC_EXIT__;
 }
 
@@ -139,9 +137,9 @@ Eina_Bool ap_update_device_conn_time(void * data)
                return ECORE_CALLBACK_CANCEL;
        }
 
-       while (count < ad->connected_device.no_of_clients) {
-               if (ad->connected_device.station_items[count])
-                       elm_genlist_item_fields_update(ad->connected_device.station_items[count++],
+       while (count < ad->main.no_of_clients) {
+               if (ad->main.station_items[count])
+                       elm_genlist_item_fields_update(ad->main.station_items[count++],
                                        "elm.text.sub", ELM_GENLIST_ITEM_FIELD_TEXT);
        }
        return ECORE_CALLBACK_RENEW;
@@ -368,25 +366,25 @@ void _genlist_update_device_item(mh_appdata_t *ad)
        no_of_dev = _get_list_clients_count(ad);
        Elm_Object_Item *item = NULL;
 
-       if (ad->main.device_item) {
-               elm_object_item_del(ad->main.device_item);
-               ad->main.device_item = NULL;
-               if (no_of_dev == 0) {
-                       item = elm_genlist_item_append(ad->main.genlist,
-                                       ad->main.device0_itc, ad, NULL,
-                                       ELM_GENLIST_ITEM_NONE, NULL, NULL);
-                       elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
+       if (no_of_dev == 0) {
+               if (ad->main.device_item) {
+                       elm_object_item_del(ad->main.device_item);
+                       ad->main.device_item = NULL;
+                       _update_conn_clients(ad);
+               }
+       } else {
+               if (ad->main.device_item) {
+               _update_conn_clients(ad);
                } else {
                        item = elm_genlist_item_append(ad->main.genlist,
                                        ad->main.device_itc, ad, NULL,
-                                       ELM_GENLIST_ITEM_NONE, _select_connected_dev, (void *)ad);
-                       elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DEFAULT);
+                                       ELM_GENLIST_ITEM_NONE, NULL, NULL);
+                       elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
+                       ad->main.device_item = item;
+                       _list_connected_dev(ad);
+                       }
                }
-               ad->main.device_item = item;
-       }
 
-       if (ad->connected_device.navi_it)
-               _update_conn_clients(ad);
 
        __MOBILE_AP_FUNC_EXIT__;
        return;
@@ -456,16 +454,13 @@ void _update_main_view(mh_appdata_t *ad, tethering_type_e type)
 
                no_of_dev = _get_list_clients_count(ad);
                if (ad->main.device_item == NULL) {
-                       if (no_of_dev == 0) {
-                               item = elm_genlist_item_append(ad->main.genlist,
-                                               ad->main.device0_itc, ad, NULL,
-                                               ELM_GENLIST_ITEM_NONE, NULL, NULL);
-                               elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
-                       } else {
+                       if (no_of_dev != 0) {
                                item = elm_genlist_item_append(ad->main.genlist,
                                                ad->main.device_itc, ad, NULL,
-                                               ELM_GENLIST_ITEM_NONE, _select_connected_dev, (void *)ad);
+                                               ELM_GENLIST_ITEM_NONE, NULL, NULL);
                                elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DEFAULT);
+                       _list_connected_dev(ad);
+                       _update_conn_clients(ad);
                        }
                        ad->main.device_item = item;
                }
@@ -985,45 +980,18 @@ static char *__get_help_label(void *data, Evas_Object *obj, const char *part)
        return NULL;
 }
 
-static char *__get_no_connected_device_label(void *data, Evas_Object *obj,
-                                                       const char *part)
-{
-       mh_appdata_t *ad = (mh_appdata_t*)data;
-       char buf[MH_LABEL_LENGTH_MAX] = {0, };
-       int no_of_dev;
-
-       if (data == NULL) {
-               ERR("The param is NULL\n");
-               return NULL;
-       }
-
-       if (!strcmp("elm.text.multiline", part)) {
-               no_of_dev = _get_list_clients_count(ad);
-               snprintf(buf, MH_LABEL_LENGTH_MAX, "<font_size=30>%s<br>%d</font_size>", STR_CONNECTED_DEV, no_of_dev);
-               return strdup(buf);
-       }
-
-       return NULL;
-}
-
-static char *__get_connected_device_label(void *data, Evas_Object *obj,
+static char *__get_device_label(void *data, Evas_Object *obj,
                                                        const char *part)
 {
-       mh_appdata_t *ad = (mh_appdata_t*)data;
        char buf[MH_LABEL_LENGTH_MAX] = {0, };
-       int no_of_dev;
 
        if (data == NULL) {
                ERR("The param is NULL\n");
                return NULL;
        }
 
-       if (!strcmp("elm.text.sub", part)) {
-               g_strlcpy(buf, STR_CONNECTED_DEV, sizeof(buf));
-               return strdup(buf);
-       } else if (!strcmp("elm.text", part)) {
-               no_of_dev = _get_list_clients_count(ad);
-               snprintf(buf, MH_LABEL_LENGTH_MAX, "%d", no_of_dev);
+       if (!strcmp("elm.text", part)) {
+               snprintf(buf, MH_LABEL_LENGTH_MAX, "<font_size=30>%s</font_size>", STR_CONNECTED_DEV);
                return strdup(buf);
        }
 
@@ -1144,18 +1112,6 @@ static void __set_genlist_itc(mh_appdata_t *ad)
 
        /* End of Off view's item class for genlist */
 
-       /* On view's item class for genlist */
-       ad->main.device0_itc = elm_genlist_item_class_new();
-       if (ad->main.device0_itc == NULL) {
-               ERR("elm_genlist_item_class_new failed\n");
-               return;
-       }
-
-       ad->main.device0_itc->item_style = MH_GENLIST_MULTILINE_TEXT_STYLE;
-       ad->main.device0_itc->func.text_get = __get_no_connected_device_label;
-       ad->main.device0_itc->func.content_get = NULL;
-       ad->main.device0_itc->func.state_get = NULL;
-       ad->main.device0_itc->func.del = NULL;
 
        ad->main.device_itc = elm_genlist_item_class_new();
        if (ad->main.device_itc == NULL) {
@@ -1163,8 +1119,8 @@ static void __set_genlist_itc(mh_appdata_t *ad)
                return;
        }
 
-       ad->main.device_itc->item_style = MH_GENLIST_2LINE_BOTTOM_TEXT_STYLE;
-       ad->main.device_itc->func.text_get = __get_connected_device_label;
+       ad->main.device_itc->item_style = MH_GENLIST_GROUP_INDEX_STYLE;
+       ad->main.device_itc->func.text_get = __get_device_label;
        ad->main.device_itc->func.content_get = NULL;
        ad->main.device_itc->func.state_get = NULL;
        ad->main.device_itc->func.del = NULL;
@@ -1305,16 +1261,13 @@ static void __create_inner_contents(mh_appdata_t *ad)
                                _connected_clients_cb, (void *)ad);
 
                no_of_dev = _get_list_clients_count(ad);
-               if (no_of_dev == 0) {
+               if (no_of_dev != 0) {
                        item = elm_genlist_item_append(ad->main.genlist,
-                                               ad->main.device0_itc, ad, NULL,
+                                               ad->main.device_itc, ad, NULL,
                                                ELM_GENLIST_ITEM_NONE, NULL, NULL);
                        elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
-               } else {
-                       item = elm_genlist_item_append(ad->main.genlist,
-                                               ad->main.device_itc, ad, NULL,
-                                               ELM_GENLIST_ITEM_NONE, _select_connected_dev, (void *)ad);
-                       elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DEFAULT);
+                       _list_connected_dev(ad);
+                       _update_conn_clients(ad);
                }
                ad->main.device_item = item;
        }