*
*/
-#include "set-scedule-info.h"
+#include "set-schedule-info.h"
#include <system_settings.h>
#include <time.h>
#include <notification_setting_internal.h>
#define TIME_STRING_SIZE 200
#define BUTTON_TEXT_SIZE 512
#define WEEK_BUTTON_SIZE 80
-#define WEEK_MAX_STRING 560
#define DAY_MAX_LENGTH 80
+#define WEEK_MAX_STRING DAY_MAX_LENGTH * 7
#define GREEN_TEXT_COLOR "<font_size=80><color=#b3b3b3>%s</color></font_size>"
#define GREY_TEXT_COLOR "<font_size=80><color=#97e57b>%s</color></font_size>"
Evas_Object *datetime;
Evas_Object *popup;
struct tm saved_time;
+ struct tm default_time;
bool is_start_time;
} datetime_s;
datetime_s start_time_p, end_time_p;
-static int day = 0;
+
+static int default_dnd_schedule_weekday = 0;
+static int new_dnd_schedule_weekday = 0;
static void set_set_schedule(bool state);
static void enable_time_items(bool enable);
static Evas_Object *create_time_button(Evas_Object *parent, const char *text, const char *format, datetime_s *dt);
static Evas_Object *create_start_end_time_layout(Evas_Object* parent);
static void close_set_schedule_cb(void *data, Evas_Object *obj, void *event_info);
-static const char *make_color_text(dnd_schedule_week_flag_e week_day, const char *text);
+static void make_color_text(int dayCode, dnd_schedule_week_flag_e week_day, const char *text, char* outBuf);
+static void save_dnd_weekday(int dayCode);
+static bool same_time(struct tm* timeA, struct tm* timeB);
-const char *get_time_string()
+bool load_dnd_schedule_time(struct tm *start_time_out, struct tm *end_time_out)
{
- char buff_start[TIME_STRING_SIZE / 2] = {0};
- char buff_end[TIME_STRING_SIZE / 2] = {0};
- char buff[TIME_STRING_SIZE] = {0};
-
time_t local_time = time(0);
struct tm *time_info = localtime(&local_time);
start_time_p.saved_time = *time_info;
start_time_p.saved_time.tm_sec = 0;
+
end_time_p.saved_time = *time_info;
end_time_p.saved_time.tm_sec = 0;
if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL)
{
NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
- return NULL;
+ return false;
}
+
notification_system_setting_dnd_schedule_get_start_time(system_setting, &start_time_p.saved_time.tm_hour, &start_time_p.saved_time.tm_min);
if(start_time_p.saved_time.tm_hour == 0 && start_time_p.saved_time.tm_min == 0)
{
start_time_p.saved_time.tm_hour = 22;
notification_system_setting_dnd_schedule_set_start_time(system_setting, start_time_p.saved_time.tm_hour, start_time_p.saved_time.tm_min);
}
+
notification_system_setting_dnd_schedule_get_end_time(system_setting, &end_time_p.saved_time.tm_hour, &end_time_p.saved_time.tm_min);
if(end_time_p.saved_time.tm_hour == 0 && end_time_p.saved_time.tm_min == 0)
{
}
notification_system_setting_update_system_setting(system_setting);
- if (err != NOTIFICATION_ERROR_NONE)
- NOTISET_ERR("notification_setting_update_setting [%d]\n", err);
- if(system_setting)
- notification_system_setting_free_system_setting(system_setting);
+ notification_system_setting_free_system_setting(system_setting);
+
+ start_time_p.default_time = start_time_p.saved_time;
+ end_time_p.default_time = end_time_p.saved_time;
+ *start_time_out = start_time_p.default_time;
+ *end_time_out = end_time_p.default_time;
+
+ return true;
+}
+
+const char *get_time_string(struct tm *start_time, struct tm *end_time)
+{
+ char buff_start[TIME_STRING_SIZE / 2] = {0};
+ char buff_end[TIME_STRING_SIZE / 2] = {0};
+ static char buff[TIME_STRING_SIZE] = {0};
if(get_time_format() == time_format_12H)
{
- strftime(buff_start, TIME_STRING_SIZE / 2, TIME_12_FORMAT, &start_time_p.saved_time);
- strftime(buff_end, TIME_STRING_SIZE / 2, TIME_12_FORMAT, &end_time_p.saved_time);
+ strftime(buff_start, TIME_STRING_SIZE / 2, TIME_12_FORMAT, start_time);
+ strftime(buff_end, TIME_STRING_SIZE / 2, TIME_12_FORMAT, end_time);
}
else
{
- strftime(buff_start, TIME_STRING_SIZE / 2, TIME_24_FORMAT, &start_time_p.saved_time);
- strftime(buff_end, TIME_STRING_SIZE / 2, TIME_24_FORMAT, &end_time_p.saved_time);
+ strftime(buff_start, TIME_STRING_SIZE / 2, TIME_24_FORMAT, start_time);
+ strftime(buff_end, TIME_STRING_SIZE / 2, TIME_24_FORMAT, end_time);
}
snprintf(buff, TIME_STRING_SIZE, "%s ~ %s %s", buff_start, buff_end, is_next_day() ? APP_STRING("IDS_ST_SBODY_NEXT_DAY_M_LC_ABB") : "");
- return strdup(buff);
+ return buff;
}
-static const char *make_color_text(dnd_schedule_week_flag_e week_day, const char *text)
+static void make_color_text(int dayCode, dnd_schedule_week_flag_e week_day, const char *text, char* outBuf)
{
- char variable[DAY_MAX_LENGTH] = { 0 };
- if((day & week_day) == 0)
- snprintf(variable, DAY_MAX_LENGTH, GREY_TEXT_MAIN, text);
+ char formattedDay[DAY_MAX_LENGTH] = { 0 };
+ if((dayCode & week_day) == 0)
+ snprintf(formattedDay, DAY_MAX_LENGTH, GREY_TEXT_MAIN, text);
else
- snprintf(variable, DAY_MAX_LENGTH, GREEN_TEXT_MAIN, text);
+ snprintf(formattedDay, DAY_MAX_LENGTH, GREEN_TEXT_MAIN, text);
- return strdup(variable);
+ strncat(outBuf, formattedDay, DAY_MAX_LENGTH);
}
-const char *get_day_string()
+int load_dnd_schedule_day()
{
- char buff[WEEK_MAX_STRING] = { 0 };
-
+ int res = 0;
notification_system_setting_h system_setting = NULL;
+
int err = notification_system_setting_load_system_setting(&system_setting);
- if(err != NOTIFICATION_ERROR_NONE || system_setting == NULL)
+ if(err == NOTIFICATION_ERROR_NONE && system_setting != NULL)
+ {
+ notification_system_setting_dnd_schedule_get_day(system_setting, &res);
+ default_dnd_schedule_weekday = res;
+ new_dnd_schedule_weekday = res;
+ notification_system_setting_free_system_setting(system_setting);
+ }
+ else
{
NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
- return NULL;
}
+ return res;
+}
- notification_system_setting_dnd_schedule_get_day(system_setting, &day);
- if(system_setting)
- notification_system_setting_free_system_setting(system_setting);
-
- strcat(buff, make_color_text(DND_SCHEDULE_WEEK_FLAG_MONDAY, APP_STRING("WDS_ALM_BUTTON_M_M_MONDAY_ABB")));
- strcat(buff, " ");
- strcat(buff, make_color_text(DND_SCHEDULE_WEEK_FLAG_TUESDAY, APP_STRING("WDS_ALM_BUTTON_T_M_TUESDAY_ABB")));
- strcat(buff, " ");
- strcat(buff, make_color_text(DND_SCHEDULE_WEEK_FLAG_WEDNESDAY, APP_STRING("WDS_ALM_BUTTON_W_M_WEDNESDAY_ABB")));
- strcat(buff, " ");
- strcat(buff, make_color_text(DND_SCHEDULE_WEEK_FLAG_THURSDAY, APP_STRING("WDS_ALM_BUTTON_T_M_THURSDAY_ABB")));
- strcat(buff, " ");
- strcat(buff, make_color_text(DND_SCHEDULE_WEEK_FLAG_FRIDAY, APP_STRING("WDS_ALM_BUTTON_F_M_FRIDAY_ABB")));
- strcat(buff, " ");
- strcat(buff, make_color_text(DND_SCHEDULE_WEEK_FLAG_SATURDAY, APP_STRING("WDS_ALM_BUTTON_S_M_SATURDAY_ABB")));
- strcat(buff, " ");
- strcat(buff, make_color_text(DND_SCHEDULE_WEEK_FLAG_SUNDAY, APP_STRING("WDS_ALM_BUTTON_S_M_SUNDAY_ABB")));
-
- return strdup(buff);
+const char *get_day_string(int dnd_schedule)
+{
+ NOTISET_TRACE_BEGIN;
+ static char buff[WEEK_MAX_STRING] = { 0 };
+ buff[0] = 0;
+
+ make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_MONDAY, APP_STRING("WDS_ALM_BUTTON_M_M_MONDAY_ABB"), buff);
+ strncat(buff, " ", WEEK_MAX_STRING);
+ make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_TUESDAY, APP_STRING("WDS_ALM_BUTTON_T_M_TUESDAY_ABB"), buff);
+ strncat(buff, " ", WEEK_MAX_STRING);
+ make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_WEDNESDAY, APP_STRING("WDS_ALM_BUTTON_W_M_WEDNESDAY_ABB"), buff);
+ strncat(buff, " ", WEEK_MAX_STRING);
+ make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_THURSDAY, APP_STRING("WDS_ALM_BUTTON_T_M_THURSDAY_ABB"), buff);
+ strncat(buff, " ", WEEK_MAX_STRING);
+ make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_FRIDAY, APP_STRING("WDS_ALM_BUTTON_F_M_FRIDAY_ABB"), buff);
+ strncat(buff, " ", WEEK_MAX_STRING);
+ make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_SATURDAY, APP_STRING("WDS_ALM_BUTTON_S_M_SATURDAY_ABB"), buff);
+ strncat(buff, " ", WEEK_MAX_STRING);
+ make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_SUNDAY, APP_STRING("WDS_ALM_BUTTON_S_M_SUNDAY_ABB"), buff);
+ return buff;
}
bool is_next_day()
ret_if(ug_main == NULL);
bool check = elm_check_state_get(obj);
enable_time_items(check);
- set_set_schedule(check);
+ set_set_schedule(check);//TODO: move saving of settings out of event handler
elm_genlist_item_update(elm_genlist_item_prev_get(elm_genlist_last_item_get(ug_main->list_main)));
}
return genlist;
}
+// TODO: minimize number of reading settings
bool get_schedule()
{
NOTISET_TRACE_BEGIN;
-
bool set_schedule = false;
notification_system_setting_h system_setting = NULL;
int err = notification_system_setting_load_system_setting(&system_setting);
static Evas_Object *create_week_repeat_layout(Evas_Object* parent)
{
-
Evas_Object *layout = elm_layout_add(parent);
char *res_path = app_get_resource_path();
return layout;
}
+static void save_dnd_weekday(int dayCode)
+{
+ notification_system_setting_h system_setting = NULL;
+
+ int err = notification_system_setting_load_system_setting(&system_setting);
+ if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL)
+ {
+ NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
+ return;
+ }
+
+ notification_system_setting_dnd_schedule_set_day(system_setting, dayCode);
+ notification_system_setting_update_system_setting(system_setting);
+ if(system_setting)
+ notification_system_setting_free_system_setting(system_setting);
+}
+
+static bool same_time(struct tm* timeA, struct tm* timeB)
+{
+ time_t t1 = mktime(timeA);
+ time_t t2 = mktime(timeB);
+ return difftime(t1, t2) == 0.0;
+}
+
+static void save_date_time(datetime_s *dt)
+{
+ notification_system_setting_h system_setting = NULL;
+ int err = notification_system_setting_load_system_setting(&system_setting);
+ if(err != NOTIFICATION_ERROR_NONE || system_setting == NULL)
+ {
+ NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
+ return;
+ }
+
+ if(dt->saved_time.tm_hour == start_time_p.saved_time.tm_hour && dt->saved_time.tm_min == start_time_p.saved_time.tm_min)
+ notification_system_setting_dnd_schedule_set_start_time(system_setting, dt->saved_time.tm_hour, dt->saved_time.tm_min);
+ else
+ notification_system_setting_dnd_schedule_set_end_time(system_setting, dt->saved_time.tm_hour, dt->saved_time.tm_min);
+
+ err = notification_system_setting_update_system_setting(system_setting);
+ if(err != NOTIFICATION_ERROR_NONE)
+ NOTISET_ERR("notification_setting_update_setting [%d]\n", err);
+
+ if(system_setting)
+ notification_system_setting_free_system_setting(system_setting);
+}
+
static void week_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
NOTISET_TRACE_BEGIN;
if(cc->change_color)
{
- day ^= cc->week;
+ new_dnd_schedule_weekday ^= cc->week;
snprintf(buf, sizeof(buf), GREY_TEXT_COLOR, cc->text);
elm_object_text_set(cc->label, buf);
}
else
{
- day |= cc->week;
+ new_dnd_schedule_weekday |= cc->week;
snprintf(buf, sizeof(buf), GREEN_TEXT_COLOR, cc->text);
elm_object_text_set(cc->label, buf);
}
- cc->change_color = !cc->change_color;
- notification_system_setting_h system_setting = NULL;
- int err = notification_system_setting_load_system_setting(&system_setting);
- if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL)
- {
- NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
- return;
- }
- notification_system_setting_dnd_schedule_set_day(system_setting, day);
- notification_system_setting_update_system_setting(system_setting);
- if(system_setting)
- notification_system_setting_free_system_setting(system_setting);
-
- elm_genlist_item_update(elm_genlist_item_prev_get(elm_genlist_last_item_get(ug_main->list_main)));
+ cc->change_color = !cc->change_color;
}
static Evas_Object *create_week_button(Evas_Object *parent, const char *text, dnd_schedule_week_flag_e week)
evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- notification_system_setting_h system_setting = NULL;
- int err = notification_system_setting_load_system_setting(&system_setting);
- if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL)
- {
- NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
- return NULL;
- }
- notification_system_setting_dnd_schedule_get_day(system_setting, &day);
- if(system_setting)
- notification_system_setting_free_system_setting(system_setting);
-
changecolor_s *cc = calloc(1, sizeof(changecolor_s));
cc->week = week;
cc->label = label;
cc->text = text;
- if((day & week) == 0)
+ if((default_dnd_schedule_weekday & week) == 0)
{
snprintf(buf, sizeof(buf), GREY_TEXT_COLOR, text);
cc->change_color = false;
evas_object_show(text);
Evas_Object *box = elm_box_add(layout);
-
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_box_horizontal_set(box, EINA_TRUE);
evas_object_show(box);
elm_box_recalculate(box);
-
return layout;
}
elm_datetime_value_get(dt->datetime, &dt->saved_time);
format = elm_datetime_format_get(dt->datetime);
- notification_system_setting_h system_setting = NULL;
- int err = notification_system_setting_load_system_setting(&system_setting);
- if(err != NOTIFICATION_ERROR_NONE || system_setting == NULL)
- {
- NOTISET_ERR("notification_system_setting_load_system_setting failed [%d]\n", err);
- return;
- }
-
- if(dt->saved_time.tm_hour == start_time_p.saved_time.tm_hour && dt->saved_time.tm_min == start_time_p.saved_time.tm_min)
- notification_system_setting_dnd_schedule_set_start_time(system_setting, dt->saved_time.tm_hour, dt->saved_time.tm_min);
- else
- notification_system_setting_dnd_schedule_set_end_time(system_setting, dt->saved_time.tm_hour, dt->saved_time.tm_min);
-
- err = notification_system_setting_update_system_setting(system_setting);
- if(err != NOTIFICATION_ERROR_NONE)
- NOTISET_ERR("notification_setting_update_setting [%d]\n", err);
-
- if(system_setting)
- notification_system_setting_free_system_setting(system_setting);
-
if(!strcmp(format, POPUP_TIME_12_FORMAT))
strftime(buff, TIME_STRING_SIZE, TIME_12_FORMAT, &dt->saved_time);
else
strftime(buff, TIME_STRING_SIZE, TIME_24_FORMAT, &dt->saved_time);
elm_genlist_item_update(elm_genlist_last_item_get(ug_main->list_sub));
- elm_genlist_item_update(elm_genlist_item_prev_get(elm_genlist_last_item_get(ug_main->list_main)));
elm_object_text_set(dt->button, buff);
{
NOTISET_TRACE_BEGIN;
ret_if(!data);
- elm_naviframe_item_pop(data);
+ ug_data *ugd = (ug_data*)data;
+ bool update_ui = false;
+ if(new_dnd_schedule_weekday != default_dnd_schedule_weekday)
+ {
+ save_dnd_weekday(new_dnd_schedule_weekday);
+ update_ui = true;
+ }
+
+ if(!same_time(&start_time_p.saved_time, &start_time_p.default_time))
+ {
+ save_date_time(&start_time_p);
+ update_ui = true;
+ }
+
+ if(!same_time(&end_time_p.saved_time, &end_time_p.default_time))
+ {
+ save_date_time(&end_time_p);
+ update_ui = true;
+ }
+
+ if(update_ui)
+ elm_genlist_item_update(elm_genlist_item_prev_get(elm_genlist_last_item_get(ugd->list_main)));
+
+ elm_naviframe_item_pop(ugd->naviframe);
}
void gl_set_schedule_selected(ug_data *data)
/* back Button */
Evas_Object *back_btn = elm_button_add(ugd->naviframe);
elm_object_style_set(back_btn, "naviframe/back_btn/default");
- evas_object_smart_callback_add(back_btn, "clicked", close_set_schedule_cb, ugd->naviframe);
+ evas_object_smart_callback_add(back_btn, "clicked", close_set_schedule_cb, ugd);
+ eext_object_event_callback_add(ugd->naviframe, EEXT_CALLBACK_BACK, close_set_schedule_cb, ugd);
/* Push to naviframe */
ugd->list_sub = _create_set_schedule_disturb_gl(ugd);