[SM] Code cleanup 75/153775/4
authorPawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
Fri, 29 Sep 2017 11:50:57 +0000 (13:50 +0200)
committerRadek Kintop <r.kintop@samsung.com>
Mon, 9 Oct 2017 15:42:03 +0000 (17:42 +0200)
Change-Id: I7e5d6a1cb098bfec271c3fe653bafec020762d51
Signed-off-by: Pawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
setting-smartmanager/smartmanager-data/src/smartmanager-data-usage-mobile-settings.c

index 2d93df54e29a80a5632f01a2a3e4c37052927c58..aca8dc6e6a6b6097c91401cf913d20979175bb94 100755 (executable)
@@ -228,8 +228,7 @@ static Evas_Object *_create_popup_button(Evas_Object *parent, char *part, char *
        evas_object_size_hint_weight_set(btn, weight_x, weight_y);
        evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
-       if (part)
-               elm_object_part_content_set(parent, part, btn);
+       elm_object_part_content_set(parent, part, btn);
 
        evas_object_show(btn);
 
@@ -390,7 +389,6 @@ static stc_callback_ret_e _get_and_unset_limit_restrictions_cb(stc_error_e resul
        return STC_CALLBACK_CONTINUE;
 }
 
-
 static void _popup_done_cb(void *data, Evas_Object *obj, void *event_info)
 {
        Limit_Popup_Data_T *limit_popup_data = (Limit_Popup_Data_T *)data;
@@ -472,22 +470,14 @@ static void _popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
 static void _clean_entry_cb(void *data, Evas_Object *obj, void *event_info)
 {
        Evas_Object *entry = (Evas_Object *)data;
-
-       if (!entry) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] entry == NULL", __FILE__, __LINE__);
-               return;
-       }
-
+       ret_if(!entry);
        elm_object_text_set(entry, "");
 }
 
 static Evas_Object *_create_entry(Evas_Object *parent, Element_Type_E type)
 {
        Evas_Object *entry = elm_entry_add(parent);
-       if (!entry) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] entry == NULL", __FILE__, __LINE__);
-               return NULL;
-       }
+       retv_if(!entry, NULL);
 
        elm_entry_markup_filter_append(entry, elm_entry_filter_accept_set, &accept_set);
        elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_size);
@@ -504,10 +494,7 @@ static Evas_Object *_create_entry(Evas_Object *parent, Element_Type_E type)
 Evas_Object *_create_label(Evas_Object *parent, char *title)
 {
        Evas_Object *label = elm_label_add(parent);
-       if (!label) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] label == NULL", __FILE__, __LINE__);
-               return NULL;
-       }
+       retv_if(!label, NULL);
 
        elm_object_text_set(label, title);
        evas_object_show(label);
@@ -518,11 +505,7 @@ Evas_Object *_create_label(Evas_Object *parent, char *title)
 Evas_Object *_create_box(Evas_Object *parent)
 {
        Evas_Object *box = elm_box_add(parent);
-
-       if (!box) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] box == NULL", __FILE__, __LINE__);
-               return NULL;
-       }
+       retv_if(!box, NULL);
 
        elm_box_horizontal_set(box, EINA_TRUE);
        elm_object_content_set(parent, box);
@@ -538,7 +521,6 @@ Evas_Object *_create_datetime(Evas_Object *parent, time_t start_date)
        elm_datetime_format_set(datetime, "%d/%b/%Y");
        elm_datetime_value_set(datetime, (Elm_Datetime_Time *)localtime(&start_date));
        elm_object_content_set(parent, datetime);
-
        evas_object_show(datetime);
 
        return datetime;
@@ -547,11 +529,7 @@ Evas_Object *_create_datetime(Evas_Object *parent, time_t start_date)
 Evas_Object *_create_popup(SmartMgrData *smd, char *title)
 {
        Evas_Object *popup = elm_popup_add(smd->md.window);
-       if (!popup) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] popup == NULL", __FILE__, __LINE__);
-               return NULL;
-       }
-
+       retv_if(!popup, NULL);
        elm_object_part_text_set(popup, "title,text", title);
        elm_popup_align_set(popup, 0.5, 0.5);
        eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_cancel_cb, popup);
@@ -562,10 +540,7 @@ Evas_Object *_create_popup(SmartMgrData *smd, char *title)
 static Limit_Popup_Data_T *_create_limit_popup_data(Evas_Object *popup, Evas_Object *entry, SmartMgrData *smd, Element_Type_E type)
 {
        Limit_Popup_Data_T *limit_popup_data = calloc(1, sizeof(Limit_Popup_Data_T));
-       if (!limit_popup_data) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] limit_popup_data == NULL", __FILE__, __LINE__);
-               return NULL;
-       }
+       retv_if(!limit_popup_data, NULL);
 
        limit_popup_data->smd = smd;
        limit_popup_data->element_type = type;
@@ -586,11 +561,13 @@ static void _popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_inf
        free(limit_popup_data);
 }
 
-static void _custom_cycle_popup_cancel_cb(void *data, Evas_Object *obj,
-               void *event_info)
+void write_cycle_interval(SmartMgrData *smd)
 {
-       Evas_Object *popup = (Evas_Object *)data;
-       evas_object_del(popup);
+       if (smd->selected_sim_subscriber_id == smd->subscriber_id_1) {
+               write_sim_1_cycle_interval(smd->selected_sim_limits->custom_mode_interval);
+       } else if (smd->selected_sim_subscriber_id == smd->subscriber_id_2) {
+               write_sim_2_cycle_interval(smd->selected_sim_limits->custom_mode_interval);
+       }
 }
 
 static void _custom_cycle_popup_ok_cb(void *data, Evas_Object *obj,
@@ -622,23 +599,18 @@ static void _custom_cycle_popup_ok_cb(void *data, Evas_Object *obj,
                                                        cycle_start_popup_data->smd->mobile_data_setting_genlist,
                                                        cycle_start_popup_data->smd);
 
-                       if (cycle_start_popup_data->smd->selected_sim_subscriber_id == cycle_start_popup_data->smd->subscriber_id_1) {
-                               write_sim_1_cycle_interval(cycle_start_popup_data->smd->selected_sim_limits->custom_mode_interval);
-                       } else if (cycle_start_popup_data->smd->selected_sim_subscriber_id == cycle_start_popup_data->smd->subscriber_id_2) {
-                               write_sim_2_cycle_interval(cycle_start_popup_data->smd->selected_sim_limits->custom_mode_interval);
-                       }
+                       write_cycle_interval(cycle_start_popup_data->smd);
 
                        evas_object_del(cycle_start_popup_data->popup);
                }
        }
 }
 
-static void _custom_cycle_popup_del_cb(void *data, Evas *e, Evas_Object *obj,
+static void _cycle_popup_del_cb(void *data, Evas *e, Evas_Object *obj,
                void *event_info)
 {
        Cycle_Start_Popup_Data_T *cycle_start_popup_data =
                        (Cycle_Start_Popup_Data_T *)data;
-
        free(cycle_start_popup_data);
 }
 
@@ -666,23 +638,16 @@ static void _create_custom_cycle_popup(SmartMgrData *smd, char *title,
        elm_object_text_set(cycle_start_popup_data->content, buf);
 
        _create_popup_button(popup, "button1", "Cancel", EVAS_HINT_EXPAND,
-                       EVAS_HINT_EXPAND, _custom_cycle_popup_cancel_cb, popup);
+                       EVAS_HINT_EXPAND, _popup_cancel_cb, popup);
        _create_popup_button(popup, "button2", "Done",   EVAS_HINT_EXPAND,
                        EVAS_HINT_EXPAND, _custom_cycle_popup_ok_cb,
                        cycle_start_popup_data);
 
        evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL,
-                       _custom_cycle_popup_del_cb, cycle_start_popup_data);
+                       _cycle_popup_del_cb, cycle_start_popup_data);
        evas_object_show(popup);
 }
 
-static void _custom_start_date_popup_cancel_cb(void *data, Evas_Object *obj,
-               void *event_info)
-{
-       Evas_Object *popup = (Evas_Object *)data;
-       evas_object_del(popup);
-}
-
 static struct tm _get_margin_date(margin_date_type date_type)
 {
        time_t now = {0};
@@ -700,6 +665,15 @@ static struct tm _get_margin_date(margin_date_type date_type)
        return time_tm;
 }
 
+void write_cycle_start(SmartMgrData *smd)
+{
+       if (smd->selected_sim_subscriber_id == smd->subscriber_id_1)  {
+               write_sim_1_cycle_start(smd->selected_sim_limits->cycle_start);
+       } else if (smd->selected_sim_subscriber_id == smd->subscriber_id_2)  {
+               write_sim_2_cycle_start(smd->selected_sim_limits->cycle_start);
+       }
+}
+
 static void _custom_start_date_popup_ok_cb(void *data, Evas_Object *obj,
                void *event_info)
 {
@@ -732,25 +706,12 @@ static void _custom_start_date_popup_ok_cb(void *data, Evas_Object *obj,
                cycle_start_popup_data->smd->selected_sim_limits->cycle_start = set_date;
                complement_data_usage_mobile_genlist(cycle_start_popup_data->smd->mobile_data_setting_genlist, cycle_start_popup_data->smd);
 
-               if (cycle_start_popup_data->smd->selected_sim_subscriber_id == cycle_start_popup_data->smd->subscriber_id_1)  {
-                       write_sim_1_cycle_start(cycle_start_popup_data->smd->selected_sim_limits->cycle_start);
-               } else if (cycle_start_popup_data->smd->selected_sim_subscriber_id == cycle_start_popup_data->smd->subscriber_id_2)  {
-                       write_sim_2_cycle_start(cycle_start_popup_data->smd->selected_sim_limits->cycle_start);
-               }
+               write_cycle_start(cycle_start_popup_data->smd);
 
                evas_object_del(cycle_start_popup_data->popup);
        }
 }
 
-static void _custom_start_date_popup_del_cb(void *data, Evas *e, Evas_Object *obj,
-               void *event_info)
-{
-       Cycle_Start_Popup_Data_T *cycle_start_popup_data =
-                       (Cycle_Start_Popup_Data_T *)data;
-
-       free(cycle_start_popup_data);
-}
-
 static void create_custom_start_date_popup(SmartMgrData *smd, char *title,
                int time)
 {
@@ -767,12 +728,12 @@ static void create_custom_start_date_popup(SmartMgrData *smd, char *title,
        cycle_start_popup_data->content = datetime;
 
        _create_popup_button(cycle_start_popup_data->popup, "button1", "Cancel", EVAS_HINT_EXPAND,
-                               EVAS_HINT_EXPAND, _custom_start_date_popup_cancel_cb, popup);
+                               EVAS_HINT_EXPAND, _popup_cancel_cb, popup);
        _create_popup_button(cycle_start_popup_data->popup, "button2", "Done",   EVAS_HINT_EXPAND,
                        EVAS_HINT_EXPAND, _custom_start_date_popup_ok_cb,
                        cycle_start_popup_data);
        evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL,
-                               _custom_start_date_popup_del_cb, cycle_start_popup_data);
+                       _cycle_popup_del_cb, cycle_start_popup_data);
 
        evas_object_show(popup);
 }
@@ -794,7 +755,6 @@ static bool _create_limit_popup(SmartMgrData *smd, char *title, Element_Type_E t
        elm_box_pack_end(box, clean);
        elm_box_pack_end(box, btn);
 
-       elm_object_style_set(clean, "no_bg");
        _entry_set_displayed_value(limit_popup_data);
 
        _create_popup_button(popup, "button1", "Cancel", EVAS_HINT_EXPAND, EVAS_HINT_EXPAND, _popup_cancel_cb, (void *)popup);
@@ -811,15 +771,12 @@ static Elm_Widget_Item *_append_item_to_radio_list(SmartMgrData *smd, Evas_Objec
                Evas_Smart_Cb select_cb)
 {
        Radio_List_Item_T *item_data = calloc(1, sizeof(Radio_List_Item_T));
-       if (!item_data) {
-               SETTING_TRACE_ERROR("item_data == NULL");
-               return NULL;
-       }
+       retv_if(!item_data, NULL);
 
        item_data->radio_value = radio_value;
-       item_data->text        = strdup(text);
-       item_data->smd         = smd;
-       item_data->popup       = popup;
+       item_data->text = strdup(text);
+       item_data->smd = smd;
+       item_data->popup = popup;
 
        Elm_Widget_Item *item = elm_genlist_item_append(genlist, itc, item_data, NULL, ELM_GENLIST_ITEM_NONE, select_cb, item_data);
        if (!item) {
@@ -915,23 +872,12 @@ static void _timer_popup_done_cb(void *data, Evas_Object *obj, void *event_info)
        elm_genlist_realized_items_update(
                        cycle_start_data->smd->mobile_data_setting_genlist);
 
-       if (cycle_start_data->smd->selected_sim_subscriber_id == cycle_start_data->smd->subscriber_id_1)  {
-               write_sim_1_cycle_start(cycle_start_data->smd->selected_sim_limits->cycle_start);
-       } else if (cycle_start_data->smd->selected_sim_subscriber_id == cycle_start_data->smd->subscriber_id_2)  {
-               write_sim_2_cycle_start(cycle_start_data->smd->selected_sim_limits->cycle_start);
-       }
+       write_cycle_start(cycle_start_data->smd);
 
        evas_object_del(cycle_start_data->popup);
        free(cycle_start_data);
 }
 
-static void _timer_popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
-{
-       Cycle_Start_Popup_Data_T *cycle_start_data = (Cycle_Start_Popup_Data_T *)data;
-       evas_object_del(cycle_start_data->popup);
-       free(cycle_start_data);
-}
-
 static void _create_monthly_start_date_popup(SmartMgrData *smd, char *title, int start_day)
 {
        Evas_Object *date_time = NULL;
@@ -954,9 +900,12 @@ static void _create_monthly_start_date_popup(SmartMgrData *smd, char *title, int
        cycle_start_data->content = date_time;
        elm_box_pack_end(box, date_time);
 
-       _create_popup_button(cycle_start_data->popup, "button1", "Cancel", EVAS_HINT_EXPAND, EVAS_HINT_EXPAND, _timer_popup_cancel_cb, cycle_start_data);
+       _create_popup_button(cycle_start_data->popup, "button1", "Cancel", EVAS_HINT_EXPAND, EVAS_HINT_EXPAND, _popup_cancel_cb, cycle_start_data->popup);
        _create_popup_button(cycle_start_data->popup, "button2", "Done", EVAS_HINT_EXPAND, EVAS_HINT_EXPAND, _timer_popup_done_cb, cycle_start_data);
 
+       evas_object_event_callback_add(cycle_start_data->popup, EVAS_CALLBACK_DEL,
+                       _cycle_popup_del_cb, cycle_start_data);
+
        evas_object_show(cycle_start_data->popup);
 }
 
@@ -981,10 +930,7 @@ static void _genlist_radio_del(void *data, Evas_Object *obj)
 static Elm_Gen_Item_Class *_create_genlist_1_line_class(Elm_Gen_Item_Content_Get_Cb _genlist_radio_content_get)
 {
        Elm_Gen_Item_Class *itc = elm_genlist_item_class_new();
-       if (!itc) {
-               SETTING_TRACE_ERROR("itc == NULL");
-               return NULL;
-       }
+       retv_if(!itc, NULL);
 
        itc->item_style = "type1";
        itc->func.content_get = _genlist_radio_content_get;
@@ -993,9 +939,17 @@ static Elm_Gen_Item_Class *_create_genlist_1_line_class(Elm_Gen_Item_Content_Get
        return itc;
 }
 
+void write_cycle_mode(SmartMgrData *smd)
+{
+       if (smd->selected_sim_subscriber_id == smd->subscriber_id_1)  {
+               write_sim_1_cycle_mode(smd->selected_sim_limits->cycle_mode);
+       } else if (smd->selected_sim_subscriber_id == smd->subscriber_id_2) {
+               write_sim_2_cycle_mode(smd->selected_sim_limits->cycle_mode);
+       }
+}
+
 static void _radio_cycle_selected_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       bool res = false;
        Radio_List_Item_T *item_data = (Radio_List_Item_T *)data;
 
        if  (item_data->smd->selected_sim_limits->cycle_mode != item_data->radio_value) {
@@ -1010,13 +964,7 @@ static void _radio_cycle_selected_cb(void *data, Evas_Object *obj, void *event_i
 
        evas_object_del(item_data->popup);
 
-       if (item_data->smd->selected_sim_subscriber_id == item_data->smd->subscriber_id_1)  {
-               res = write_sim_1_cycle_mode(item_data->smd->selected_sim_limits->cycle_mode);
-       } else if (item_data->smd->selected_sim_subscriber_id == item_data->smd->subscriber_id_2) {
-               res = write_sim_2_cycle_mode(item_data->smd->selected_sim_limits->cycle_mode);
-       }
-
-       ret_if(!res);
+       write_cycle_mode(item_data->smd);
 }
 
 static Evas_Object *_genlist_cycle_radio_content_get(void *data, Evas_Object *obj, const char *part)
@@ -1029,10 +977,7 @@ static Evas_Object *_genlist_cycle_radio_content_get(void *data, Evas_Object *ob
                return NULL;
 
        radio = elm_radio_add(obj);
-       if (!radio) {
-               SETTING_TRACE_ERROR("radio == NULL");
-               return NULL;
-       }
+       retv_if(!radio, NULL);
 
        elm_radio_state_value_set(radio, item_data->radio_value);
        evas_object_smart_callback_add(radio, "changed", _radio_cycle_selected_cb, data);
@@ -1063,10 +1008,7 @@ static Evas_Object *_genlist_start_date_radio_content_get(void *data, Evas_Objec
                return NULL;
 
        radio = elm_radio_add(obj);
-       if (!radio) {
-               SETTING_TRACE_ERROR("radio == NULL");
-               return NULL;
-       }
+       retv_if(!radio, NULL);
 
        elm_radio_state_value_set(radio, item_data->radio_value);
        evas_object_smart_callback_add(radio, "changed", _radio_start_date_selected_cb, data);
@@ -1074,18 +1016,13 @@ static Evas_Object *_genlist_start_date_radio_content_get(void *data, Evas_Objec
        if (item_data->smd->selected_sim_limits->cycle_start == item_data->radio_value)
                elm_radio_value_set(radio, item_data->radio_value);
 
-       if (item_data->smd->selected_sim_subscriber_id == item_data->smd->subscriber_id_1)  {
-               write_sim_1_cycle_start(item_data->smd->selected_sim_limits->cycle_start);
-       } else if (item_data->smd->selected_sim_subscriber_id == item_data->smd->subscriber_id_2)  {
-               write_sim_2_cycle_start(item_data->smd->selected_sim_limits->cycle_start);
-       }
+       write_cycle_start(item_data->smd);
 
        return radio;
 }
 
 void _radio_cycle_list_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       bool res = false;
        Radio_List_Item_T *item_data = (Radio_List_Item_T *)data;
 
        if (item_data->smd->selected_sim_limits->cycle_mode != item_data->radio_value) {
@@ -1100,13 +1037,7 @@ void _radio_cycle_list_item_selected_cb(void *data, Evas_Object *obj, void *even
 
        evas_object_del(item_data->popup);
 
-       if (item_data->smd->selected_sim_subscriber_id == item_data->smd->subscriber_id_1)  {
-               res = write_sim_1_cycle_mode(item_data->smd->selected_sim_limits->cycle_mode);
-       } else if (item_data->smd->selected_sim_subscriber_id == item_data->smd->subscriber_id_2) {
-               res = write_sim_2_cycle_mode(item_data->smd->selected_sim_limits->cycle_mode);
-       }
-
-       ret_if(!res);
+       write_cycle_mode(item_data->smd);
 }
 
 void _radio_start_date_list_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
@@ -1117,11 +1048,7 @@ void _radio_start_date_list_item_selected_cb(void *data, Evas_Object *obj, void
 
        evas_object_del(item_data->popup);
 
-       if (item_data->smd->selected_sim_subscriber_id == item_data->smd->subscriber_id_1)  {
-               write_sim_1_cycle_start(item_data->smd->selected_sim_limits->cycle_start);
-       } else if (item_data->smd->selected_sim_subscriber_id == item_data->smd->subscriber_id_2)  {
-               write_sim_2_cycle_start(item_data->smd->selected_sim_limits->cycle_start);
-       }
+       write_cycle_start(item_data->smd);
 }
 
 static void _create_list_popup(SmartMgrData *smd, char *title, Element_Type_E type)
@@ -1130,17 +1057,6 @@ static void _create_list_popup(SmartMgrData *smd, char *title, Element_Type_E ty
        Evas_Object *genlist = NULL;
        Elm_Gen_Item_Class *itc = NULL;
        Evas_Object *popup = setting_create_popup_with_list(&genlist, NULL, smd->md.naviframe, title, NULL, 0, EINA_TRUE, EINA_FALSE, 0);
-
-       if (!popup) {
-               SETTING_TRACE_ERROR("popup == NULL");
-               return;
-       }
-
-       if (!genlist) {
-               SETTING_TRACE_ERROR("genlist == NULL");
-               return;
-       }
-
        if (type == ELEMENT_TYPE_CYCLE) {
                itc = _create_genlist_1_line_class(_genlist_cycle_radio_content_get);
                for (i = 0; i < EINA_C_ARRAY_LENGTH(elements_cycle_initial_values); ++i) {
@@ -1278,8 +1194,8 @@ static void _item_selected_cb(void *data, Evas_Object *obj, void *event_info)
 {
        Element *element = (Element*)data;
        Elm_Object_Item *item = (Elm_Object_Item *)event_info;
-
        elm_genlist_item_selected_set(item, EINA_FALSE);
+
        switch (element->type) {
        case ELEMENT_TYPE_WARNING:
                _create_limit_popup(element->smd, "Set data usage warning level", ELEMENT_TYPE_WARNING);