[SM][Wifi] Custom date set rules 63/159563/1
authorRadek Kintop <r.kintop@samsung.com>
Thu, 9 Nov 2017 16:19:38 +0000 (17:19 +0100)
committerRadek Kintop <r.kintop@samsung.com>
Thu, 9 Nov 2017 16:19:38 +0000 (17:19 +0100)
- can't set date after today
- can't set date 30 days before today
- toast popup time prolonged to more friendly 3.0s

Change-Id: I3e3187d51822111dd9a04d63aba64f2c8be1a284
Signed-off-by: Radek Kintop <r.kintop@samsung.com>
setting-common/src/setting-common-draw-popup.c
setting-smartmanager/smartmanager-data/src/smartmanager-data-usage-wifi-settings.c

index 1b1c023581d4178b69a6f1c61091a62b2102e764..3400adab0a398be43bce0bc34c34cffc1f164442 100644 (file)
@@ -579,7 +579,7 @@ void setting_create_toast_popup(const char *text, Evas_Object *parent)
        evas_object_smart_callback_add(popup, "dismissed",
                        __popup_hide_finished_cb, NULL);
 
-       elm_popup_timeout_set(popup, 2.0);
+       elm_popup_timeout_set(popup, 3.0);
 
        elm_object_focus_allow_set(popup, EINA_FALSE);
 
index 14d7c9e9391e679b18175bcc52b6725b3e3b7b38..b12e52177a179f594197243b0bfdec4b9a09f273 100755 (executable)
@@ -11,9 +11,9 @@ static int _update(void *data);
 static int _cleanup(void *data);
 
 /* Widget interaction callbacks: */
-static void _custom_cycle_dayes_popup_cancel_click_cb(void *data,
+static void _custom_cycle_days_popup_cancel_click_cb(void *data,
                                                                        Evas_Object *button, void *event_info);
-static void _custom_cycle_dayes_popup_done_click_cb(void *data,
+static void _custom_cycle_days_popup_done_click_cb(void *data,
                                                                        Evas_Object *button, void *event_info);
 static void _cycle_item_click_cb(void *data, Evas_Object *obj,
                                                                void *event_info);
@@ -178,14 +178,14 @@ static Eina_Bool _pop_view_cb(void *data, Elm_Object_Item *it)
        return EINA_TRUE;
 }
 
-static void _custom_cycle_dayes_popup_cancel_click_cb(void *data,
+static void _custom_cycle_days_popup_cancel_click_cb(void *data,
                                                                        Evas_Object *button, void *event_info)
 {
        Evas_Object *popup = evas_object_data_get(button, "popup");
        evas_object_del(popup);
 }
 
-static void _custom_cycle_dayes_popup_done_click_cb(void *data,
+static void _custom_cycle_days_popup_done_click_cb(void *data,
                                                                        Evas_Object *button, void *event_info)
 {
        SmartMgrData *smd = data;
@@ -258,7 +258,7 @@ static Evas_Object *_create_custom_cycle_days_popup(SmartMgrData *smd)
        elm_object_part_content_set(popup, "button1", button);
        evas_object_data_set(button, "popup", popup);
        evas_object_smart_callback_add(button, "clicked",
-                                                               _custom_cycle_dayes_popup_cancel_click_cb, smd);
+                                                               _custom_cycle_days_popup_cancel_click_cb, smd);
 
        button = elm_button_add(popup);
        evas_object_data_set(button, "entry", entry);
@@ -266,7 +266,7 @@ static Evas_Object *_create_custom_cycle_days_popup(SmartMgrData *smd)
        elm_object_text_set(button, _("Done"));
        elm_object_part_content_set(popup, "button2", button);
        evas_object_smart_callback_add(button, "clicked",
-                                                               _custom_cycle_dayes_popup_done_click_cb, smd);
+                                                               _custom_cycle_days_popup_done_click_cb, smd);
 
        return popup;
 }
@@ -416,6 +416,21 @@ static void _start_date_popup_set_click_cb(void *data, Evas_Object *obj,
        struct tm start_date = {0};
        Eina_Bool time_res = EINA_FALSE;
        SmartMgrData *smd = data;
+       double time_delta = 0.0;
+       time_t now = time(NULL);
+       struct tm *now_tm = NULL;
+       time_t past_max = now - (3600.0 * 24.0 * 90.0);
+       struct tm *past_max_tm = NULL;
+       char txt_buff[256] = {'\0',};
+       char past_date_txt_buff[80] = {'\0',};
+
+       /* set'now' to second past midnight: */
+       now_tm = localtime(&now);
+       now_tm->tm_sec = 1;
+       now_tm->tm_min = 0;
+       now_tm->tm_hour = 0;
+       now = mktime(now_tm);
+       now_tm = NULL;
 
        smd->wifi_limits.cycle_start = 1;
 
@@ -427,8 +442,31 @@ static void _start_date_popup_set_click_cb(void *data, Evas_Object *obj,
        if (CYCLE_MODE_CUSTOM == smd->wifi_limits.cycle_mode) {
                time_res = elm_datetime_value_get(start_date_popup_datetime,
                                                                                        &start_date);
+               start_date.tm_sec = 1;
+               start_date.tm_min = 0;
+               start_date.tm_hour = 0;
                if (EINA_TRUE == time_res) {
                        smd->wifi_limits.cycle_start = mktime(&start_date);
+                       time_delta = difftime(smd->wifi_limits.cycle_start, now);
+
+                       if (time_delta > 1.0) {
+                               setting_create_toast_popup(_("Start date can't be after "\
+                                               "current date. Start date changed to current date."),
+                                               smd->md.window);
+                               smd->wifi_limits.cycle_start = now;
+                       }
+
+                       if (time_delta < -(3600.0 * 24.0 * 90.0)) {
+                               past_max_tm = localtime(&past_max);
+                               strftime(past_date_txt_buff, sizeof(past_date_txt_buff),
+                                               "%a, %d/%m/%Y", past_max_tm);
+                               snprintf(txt_buff, sizeof(txt_buff), "%s %s. %s",
+                                               _("Start date can't be before"), past_date_txt_buff,
+                                               _("Start date changed to current date."));
+                               setting_create_toast_popup(txt_buff, smd->md.window);
+                               smd->wifi_limits.cycle_start = now;
+                       }
+
                } else {
                        SETTING_TRACE_ERROR("Failed to obtain data from datetime %p",
                                                start_date_popup_datetime);
@@ -531,8 +569,17 @@ static void _start_date_item_click_cb(void *data, Evas_Object *genlist,
                        start_date_popup_datetime = elm_datetime_add(start_date_popup);
                        elm_object_style_set(start_date_popup_datetime, "date_layout");
                        elm_datetime_format_set(start_date_popup_datetime, "%d/%b/%Y");
-                       elm_datetime_value_set(start_date_popup_datetime,
+                       if (smd->wifi_limits.cycle_start <= 0) {
+                               elm_datetime_value_set(start_date_popup_datetime,
                                                                        (Elm_Datetime_Time *)localtime(&now));
+                       } else {
+                               elm_datetime_value_set(start_date_popup_datetime,
+                               (Elm_Datetime_Time *)localtime((time_t *)(
+                                                                                               &(smd->wifi_limits.cycle_start))
+                                                                                               )
+                                                                               );
+
+                       }
                        elm_object_content_set(start_date_popup, start_date_popup_datetime);
                }
 
@@ -581,13 +628,23 @@ static void _start_date_item_click_cb(void *data, Evas_Object *genlist,
 static char *_cycle_item_text_get(void *data, Evas_Object *genlist,
                                                                                        const char *part)
 {
-       if (!data)
+       SmartMgrData *ad = data;
+       char txt_buff[256] = {'\0',};
+
+       if (!ad)
                return NULL;
 
-       if (!safeStrCmp(part, "elm.text"))
+       if (!safeStrCmp(part, "elm.text")) {
+               if (CYCLE_MODE_CUSTOM == ad->wifi_limits.cycle_mode) {
+
+                       snprintf(txt_buff, sizeof(txt_buff), "%d %s",
+                                               ad->wifi_limits.custom_mode_interval, _("Days"));
+                       return strdup(txt_buff);
+               }
                return strdup(
-                                       cycle_names[((SmartMgrData *)data)->wifi_limits.cycle_mode]
+                                       cycle_names[ad->wifi_limits.cycle_mode]
                                        );
+       }
 
        if (!safeStrCmp(part, "elm.text.sub"))
                return strdup(_("Cycle"));