From: Radek Kintop Date: Mon, 8 Feb 2016 14:31:07 +0000 (+0100) Subject: System clock X-Git-Tag: accepted/tizen/tv/20160218.005609~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9facbca42ab5766f0b11556b07140c0f22a3a539;p=profile%2Ftv%2Fapps%2Fnative%2Fair_settings.git System clock Change-Id: Ic432ec26d9cf6efabc6b49a557526416e2d87b1c Signed-off-by: Radek Kintop --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 085de81..43b4cf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ SET(SRCS src/grid/grid_wireless.c src/data/data_wireless.c src/data/data_wired.c + src/data/system/settings_clock.c ) SET(TARGET_EDJ "${PROJECT_NAME}.edj") diff --git a/include/data/system/settings_clock.h b/include/data/system/settings_clock.h new file mode 100644 index 0000000..d89f4ca --- /dev/null +++ b/include/data/system/settings_clock.h @@ -0,0 +1,14 @@ +#ifndef SETTINGS_CLOCK_H_ +#define SETTINGS_CLOCK_H_ + +#include +#include + +extern bool settings_clock_is_24h_set(bool *h24); +extern bool settings_clock_set_24h(bool h24); +extern bool settings_clock_is_time_automatic(bool *automatic); +extern bool settings_clock_set_time_automatic(bool automatic); +extern bool settings_clock_get_current_time(struct tm *current_time); +extern bool settings_clock_set_current_time(struct tm *current_time); + +#endif /* SETTINGS_CLOCK_H_ */ diff --git a/include/define.h b/include/define.h index c014b05..c28f601 100644 --- a/include/define.h +++ b/include/define.h @@ -69,14 +69,8 @@ #define PART_BOTTOM_BTN_DONE "part.bottom.btn.done" #define PART_MAIN_ITEM_SETUP "part.main.item.setup" #define PART_MAIN_ITEM_DATE "part.main.item.date" -#define PART_MAIN_ITEM_DATE_DAY "part.main.item.date.day" -#define PART_MAIN_ITEM_DATE_MONTH "part.main.item.date.month" -#define PART_MAIN_ITEM_DATE_YEAR "part.main.item.date.year" #define PART_MAIN_ITEM_24HOUR "part.main.item.24hour" #define PART_MAIN_ITEM_TIME "part.main.item.time" -#define PART_MAIN_ITEM_TIME_HOUR "part.main.item.time.hour" -#define PART_MAIN_ITEM_TIME_MIN "part.main.item.time.min" -#define PART_MAIN_ITEM_TIME_AMPM "part.main.item.time.ampm" #define PART_POPUP_BUTTON1 "part.popup.btn1" #define PART_POPUP_BUTTON2 "part.popup.btn2" diff --git a/include/view_clock.h b/include/view_clock.h index 7c5be5f..0b9f68d 100644 --- a/include/view_clock.h +++ b/include/view_clock.h @@ -14,18 +14,9 @@ * limitations under the License. */ -#include - #ifndef __AIR_SETTINGS_VIEW_CLOCK_H__ #define __AIR_SETTINGS_VIEW_CLOCK_H__ -/* Count */ -#define COUNT_SETUP_TYPE 2 - -/* Size */ -#define SIZE_SETUP_CTXPOPUP_W 446 -#define SIZE_SETUP_CTXPOPUP_H 64 - view_class *view_clock_get_vclass(void); #endif /* __AIR_SETTINGS_VIEW_CLOCK_H__ */ diff --git a/org.tizen.settings.xml.in b/org.tizen.settings.xml.in index 008110d..c668bf2 100644 --- a/org.tizen.settings.xml.in +++ b/org.tizen.settings.xml.in @@ -9,6 +9,7 @@ http://tizen.org/privilege/appmanager.launch + http://tizen.org/privilege/alarm.set http://tizen.org/privilege/internet http://tizen.org/privilege/network.get http://tizen.org/privilege/network.set diff --git a/res/view/clock.edc b/res/view/clock.edc index 54b57e5..729385b 100644 --- a/res/view/clock.edc +++ b/res/view/clock.edc @@ -14,6 +14,43 @@ * limitations under the License. */ +#define TITLE_BG_Y2 (104.0 / BASE_RESOLUTION_Y) + +#define CONTROLS_X1 0.39 +#define LABELS_X2 0.62 + +#define GUIDE_LABEL_Y1 0.14 +#define GUIDE_LABEL_Y2 0.18 + +#define MAIN_LABEL_Y1 0.21 +#define MAIN_LABEL_Y2 0.25 + +#define MANUAL_SETUP_Y1 0.26 +#define MANUAL_SETUP_Y2 0.31 +#define MANUAL_SETUP_X2 0.62 + +#define DATE_LABEL_Y1 0.33 +#define DATE_LABEL_Y2 0.37 + +#define DATE_ITEM_Y1 0.39 +#define DATE_ITEM_Y2 0.53 +#define DATE_ITEM_X2 0.62 + +#define _24HOUR_LABEL_Y1 0.55 +#define _24HOUR_LABEL_Y2 0.59 + +#define _24HOUR_ITEM_Y1 0.60 +#define _24HOUR_ITEM_Y2 0.64 +#define _24HOUR_ITEM_X2 0.55 + +#define TIME_LABEL_Y1 0.65 +#define TIME_LABEL_Y2 0.69 + +#define TIME_ITEM_Y1 0.70 +#define TIME_ITEM_Y2 0.84 +#define TIME_ITEM_X2 0.62 + + group { name, GRP_VIEW_CLOCK; @@ -38,59 +75,22 @@ group { scale, 1; description { state, "default" 0.0; - min, 0 104; - rel2.relative, 1.0 0.0; - align, 0.5 0.0; - fixed, 0 1; - } - } - - part { - name, PART_TOP_TITLE; - type, TEXT; - scale, 1; - description { - state, "default" 0.0; - color, 51 51 51 255; - rel1.to, "title.bg"; - rel2.to, "title.bg"; - text { - font, FONT_REGULAR; - size, 46; - align, 0.5 0.5; - } - } - } - - part { - name, "padding.guide"; - type, SPACER; - scale, 1; - description { - state, "default" 0.0; - min, 0 68; - align, 0.5 0.0; - rel1 { - to, "title.bg"; - relative, 0.0 1.0; - } - rel2.to, "title.bg"; + rel1.relative, 0.0 0.0; + rel2.relative, 1.0 TITLE_BG_Y2; } - } - - part { - name, "part.guide.bg"; - type, SPACER; - scale, 1; - description { - state, "default" 0.0; - min, 0 32; - rel1 { - to, "padding.guide"; - relative, 0.0 1.0; + part { + name, PART_TOP_TITLE; + type, TEXT; + scale, 1; + description { + state, "default" 0.0; + color, 51 51 51 255; + text { + font, FONT_REGULAR; + size, 46; + align, 0.5 0.5; + } } - rel2.to, "padding.guide"; - align, 0.5 0.0; } } @@ -101,8 +101,8 @@ group { description { state, "default" 0.0; color, 116 116 116 255; - rel1.to, "part.guide.bg"; - rel2.to, "part.guide.bg"; + rel1.relative, 0.0 GUIDE_LABEL_Y1; + rel2.relative, 1.0 GUIDE_LABEL_Y2; text { font, FONT_LIGHT; size, 32; @@ -112,63 +112,15 @@ group { } part { - name, "padding.main"; - type, SPACER; - scale, 1; - description { - state, "default" 0.0; - min, 0 74; - align, 0.5 0.0; - rel1 { - to, "part.guide.bg"; - relative, 0.0 1.0; - } - rel2.to, "part.guide.bg"; - } - } - - part { - name, "part.main.bg"; - type, SPACER; - scale, 1; - description { - state, "default" 0.0; - min, 0 578; - rel1 { - to, "padding.main"; - relative, 0.0 1.0; - } - rel2.to, "padding.main"; - align, 0.5 0.0; - } - } - - part { - name, "part.main"; - type, SPACER; - scale, 1; - description { - state, "default" 0.0; - max, 446 578; - fixed, 1 1; - align, 0.5 0.0; - rel1.to, "part.main.bg"; - rel2.to, "part.main.bg"; - } - } - - part { name, PART_MAIN_LABEL_SETUP; type, TEXT; scale, 1; description { state, "default" 0.0; color, 116 116 116 255; - max, 446 32; - fixed, 1 1; - align, 0.5 0.0; - rel1.to, "part.main"; - rel2.to, "part.main"; + align, 0.0 0.5; + rel1.relative, CONTROLS_X1 MAIN_LABEL_Y1; + rel2.relative, LABELS_X2 MAIN_LABEL_Y2; text { font, FONT_LIGHT; size, 32; @@ -178,36 +130,14 @@ group { } part { - name, "part.main.item.setup.bg"; - type, SPACER; - scale, 1; - description { - state, "default" 0.0; - min, 0 122; - fixed, 1 1; - align, 0.5 0.0; - rel1 { - to, PART_MAIN_LABEL_SETUP; - relative, 0.0 1.0; - } - rel2.to, PART_MAIN_LABEL_SETUP; - } - } - - part { name, PART_MAIN_ITEM_SETUP; type, SWALLOW; scale, 1; description { state, "default" 0.0; - max, 446 64; - fixed, 1 1; align, 0.5 0.5; - rel1.to, "part.main.item.setup.bg"; - rel2 { - to, "part.main.item.setup.bg"; - relative, 1.0 1.0; - } + rel1.relative, CONTROLS_X1 MANUAL_SETUP_Y1; + rel2.relative, MANUAL_SETUP_X2 MANUAL_SETUP_Y2; } } @@ -218,14 +148,9 @@ group { description { state, "default" 0.0; color, 116 116 116 255; - min, 0 32; - fixed, 1 1; - align, 0.5 0.0; - rel1 { - to, "part.main.item.setup.bg"; - relative, 0.0 1.0; - } - rel2.to, "part.main.item.setup.bg"; + align, 0.0 0.5; + rel1.relative, CONTROLS_X1 DATE_LABEL_Y1; + rel2.relative, LABELS_X2 DATE_LABEL_Y2; text { font, FONT_LIGHT; size, 32; @@ -240,104 +165,9 @@ group { scale, 1; description { state, "default" 0.0; - min, 0 122; - fixed, 1 1; - align, 0.5 0.0; - rel1 { - to, PART_MAIN_LABEL_DATE; - relative, 0.0 1.0; - } - rel2.to, PART_MAIN_LABEL_DATE; - } - } - - part { - name, "part.main.item.date.day"; - type, SWALLOW; - scale, 1; - description { - state, "default" 0.0; - max, 138 64; - fixed, 1 1; - align, 0.5 0.5; - rel1 { - to, PART_MAIN_ITEM_DATE; - relative, 0.5 0.5; - } - rel2 { - to, PART_MAIN_ITEM_DATE; - relative, 0.5 0.5; - } - } - } - - part { - name, "part.main.item.date.padl"; - type, RECT; - scale, 1; - description { - state, "default" 0.0; - max, 22 64; - fixed, 1 1; - align, 1.0 0.5; - rel1.to, "part.main.item.date.day"; - rel2 { - to, "part.main.item.date.day"; - relative, 0.0 1.0; - } - color, 100 100 100 255; - } - } - - part { - name, "part.main.item.date.padr"; - type, RECT; - scale, 1; - description { - state, "default" 0.0; - max, 22 64; - fixed, 1 1; align, 0.0 0.5; - rel1 { - to, "part.main.item.date.day"; - relative, 1.0 0.0; - } - rel2.to, "part.main.item.date.day"; - color, 100 100 100 255; - } - } - - part { - name, "part.main.item.date.month"; - type, SWALLOW; - scale, 1; - description { - state, "default" 0.0; - max, 138 64; - fixed, 1 1; - align, 1.0 0.5; - rel1.to, "part.main.item.date.padl"; - rel2 { - to, "part.main.item.date.padl"; - relative, 0.0 1.0; - } - } - } - - part { - name, "part.main.item.date.year"; - type, SWALLOW; - scale, 1; - description { - state, "default" 0.0; - max, 138 64; - fixed, 1 1; - align, 0.0 0.5; - rel1 { - to, "part.main.item.date.padr"; - relative, 1.0 0.0; - } - rel2.to, "part.main.item.date.padr"; + rel1.relative, CONTROLS_X1 DATE_ITEM_Y1; + rel2.relative, DATE_ITEM_X2 DATE_ITEM_Y2; } } @@ -348,14 +178,9 @@ group { description { state, "default" 0.0; color, 116 116 116 255; - min, 0 32; - fixed, 1 1; - align, 0.5 0.0; - rel1 { - to, PART_MAIN_ITEM_DATE; - relative, 0.0 1.0; - } - rel2.to, PART_MAIN_ITEM_DATE; + align, 0.0 0.5; + rel1.relative, CONTROLS_X1 _24HOUR_LABEL_Y1; + rel2.relative, LABELS_X2 _24HOUR_LABEL_Y2; text { font, FONT_LIGHT; size, 32; @@ -370,14 +195,9 @@ group { scale, 1; description { state, "default" 0.0; - min, 0 122; - fixed, 1 1; - align, 0.5 0.0; - rel1 { - to, PART_MAIN_LABEL_24HOUR; - relative, 0.0 1.0; - } - rel2.to, PART_MAIN_LABEL_24HOUR; + align, 0.0 0.5; + rel1.relative, CONTROLS_X1 _24HOUR_ITEM_Y1; + rel2.relative, _24HOUR_ITEM_X2 _24HOUR_ITEM_Y2; } } @@ -388,14 +208,9 @@ group { description { state, "default" 0.0; color, 116 116 116 255; - min, 0 32; - fixed, 1 1; - align, 0.5 0.0; - rel1 { - to, PART_MAIN_ITEM_24HOUR; - relative, 0.0 1.0; - } - rel2.to, PART_MAIN_ITEM_24HOUR; + align, 0.0 0.5; + rel1.relative, CONTROLS_X1 TIME_LABEL_Y1; + rel2.relative, LABELS_X2 TIME_LABEL_Y2; text { font, FONT_LIGHT; size, 32; @@ -410,103 +225,9 @@ group { scale, 1; description { state, "default" 0.0; - min, 0 84; - fixed, 1 1; - align, 0.5 0.0; - rel1 { - to, PART_MAIN_LABEL_TIME; - relative, 0.0 1.0; - } - rel2.to, PART_MAIN_LABEL_TIME; - } - } - - part { - name, "part.main.item.time.min"; - type, SWALLOW; - scale, 1; - description { - state, "default" 0.0; - max, 138 64; - fixed, 1 1; - align, 0.5 0.5; - rel1 { - to, PART_MAIN_ITEM_TIME; - relative, 0.5 0.5; - } - rel2 { - to, PART_MAIN_ITEM_TIME; - relative, 0.5 0.5; - } - } - } - - part { - name, "part.main.item.time.padl"; - scale, 1; - description { - state, "default" 0.0; - max, 22 64; - fixed, 1 1; - image.normal, IC_ADD_SCHEDULE_COLON_PNG; - align, 1.0 0.5; - rel1.to, "part.main.item.time.min"; - rel2 { - to, "part.main.item.time.min"; - relative, 0.0 1.0; - } - } - } - - part { - name, "part.main.item.time.padr"; - type, RECT; - scale, 1; - description { - state, "default" 0.0; - max, 22 64; - fixed, 1 1; align, 0.0 0.5; - rel1 { - to, "part.main.item.time.min"; - relative, 1.0 0.0; - } - rel2.to, "part.main.item.time.min"; - color, 100 100 100 255; - } - } - - part { - name, "part.main.item.time.hour"; - type, SWALLOW; - scale, 1; - description { - state, "default" 0.0; - max, 138 64; - fixed, 1 1; - align, 1.0 0.5; - rel1.to, "part.main.item.time.padl"; - rel2 { - to, "part.main.item.time.padl"; - relative, 0.0 1.0; - } - } - } - - part { - name, "part.main.item.time.ampm"; - type, SWALLOW; - scale, 1; - description { - state, "default" 0.0; - max, 138 64; - fixed, 1 1; - align, 0.0 0.5; - rel1 { - to, "part.main.item.time.padr"; - relative, 1.0 0.0; - } - rel2.to, "part.main.item.time.padr"; + rel1.relative, CONTROLS_X1 TIME_ITEM_Y1; + rel2.relative, TIME_ITEM_X2 TIME_ITEM_Y2; } } diff --git a/src/data/system/settings_clock.c b/src/data/system/settings_clock.c new file mode 100644 index 0000000..2bb10f4 --- /dev/null +++ b/src/data/system/settings_clock.c @@ -0,0 +1,87 @@ +#include "data/system/settings_clock.h" +#include +#include + +bool settings_clock_is_24h_set(bool *h24) +{ + int res = 0; + int val = 0; + if (!h24) + return false; + + res = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &val); + + if (res < 0) + return false; + + *h24 = (VCONFKEY_TIME_FORMAT_24 == val); + + return true; +} + +bool settings_clock_set_24h(bool h24) +{ + if (h24) { + return (0 == vconf_set_int(VCONFKEY_REGIONFORMAT_TIME1224, VCONFKEY_TIME_FORMAT_24)); + } else { + return (0 == vconf_set_int(VCONFKEY_REGIONFORMAT_TIME1224, VCONFKEY_TIME_FORMAT_12)); + } + + return true; +} + +bool settings_clock_is_time_automatic(bool *automatic) +{ + int res = 0; + int automatic_int = 0; + + if (!automatic) + return false; + + res = vconf_get_bool(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, &automatic_int); + + if (res < 0) + return false; + + *automatic = (automatic_int > 0); + + return true; +} + +bool settings_clock_set_time_automatic(bool automatic) +{ + return (0 == vconf_set_bool(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, automatic)); +} + +bool settings_clock_get_current_time(struct tm *current_time) +{ + time_t t = {0,}; + struct tm *tm_struct = NULL; + + if (!current_time) + return false; + + t = time(NULL); + tm_struct = localtime(&t); + + if (!tm_struct) + return false; + + *current_time = *tm_struct; + + return true; +} + +bool settings_clock_set_current_time(struct tm *current_time) +{ + time_t the_time = 0; + + if (!current_time) + return false; + + the_time = mktime(current_time); + if (ALARMMGR_RESULT_SUCCESS != alarmmgr_set_systime(the_time)) + return false; + + return true; +} diff --git a/src/layout/layout_system.c b/src/layout/layout_system.c index 5e89cd9..be8abc0 100644 --- a/src/layout/layout_system.c +++ b/src/layout/layout_system.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "layoutmgr.h" #include "inputmgr.h" diff --git a/src/view/view_clock.c b/src/view/view_clock.c index 3394bec..df74da2 100644 --- a/src/view/view_clock.c +++ b/src/view/view_clock.c @@ -17,7 +17,6 @@ #include #include #include -#include #include "viewmgr.h" #include "inputmgr.h" @@ -25,72 +24,119 @@ #include "define.h" #include "utils.h" #include "view_clock.h" +#include "data/system/settings_clock.h" +#include "app_string.h" enum setup_type { TYPE_MANUAL = 0, TYPE_AUTO, + TYPE_MAX }; -static int id_setup_type_opt[] = { +static int id_setup_type_opt[TYPE_MAX] = { TYPE_MANUAL, - TYPE_AUTO, + TYPE_AUTO }; -const char *str_setup_type_opt[] = { +static const char *str_setup_type_opt[] = { STR_MANUAL, - STR_AUTO, + STR_AUTO }; -struct _priv { +typedef struct { Evas_Object *win; Evas_Object *base; - Evas_Object *ly; Evas_Object *done; Evas_Object *cancel; - Evas_Object *clock_setup_btn; - int *setup_type; + Evas_Object *auto_manual_setup_btn; Evas_Object *setup_type_popup; + + Evas_Object *date_part; + Evas_Object *check_24; + Evas_Object *time_part; enum setup_type cur_type; - Evas_Object *year; -}; +} clock_view_priv_data; enum input_handler_type { INPUT_HANDLER_TYPE_BTN_DONE, INPUT_HANDLER_TYPE_BTN_CANCEL, + INPUT_HANDLER_TYPE_CHECK_H12_24, }; -static void _mouse_move_cb(int id, void *data, Evas *e, Evas_Object *obj, - Evas_Event_Mouse_Move *ev) -{ - if (obj) { - _ERR("Invalid argument."); - return; - } +/* User has moved mouse over auto/manual setup dropdown: */ +static void _auto_manual_mouse_move_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Move *ev); +/*(KEYPAD/REMOTE) User has clicked/pressed auto/manual setup dropdown: */ +static void _auto_manual_setup_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev); +/*(MOUSE) User has clicked/pressed auto/manual setup dropdown: */ +static void _auto_manual_setup_mouse_down_cb(); +/* (KEYPAD/REMOTE) User has clicked/pressed one of the options from auto/manual setup dropdown menu: */ +static void _auto_manual_setup_option_key_down_cb(int id, void *data, Evas *e, + Evas_Object *obj, Evas_Event_Key_Down *ev); +/* (MOUSE) User has clicked/pressed one of the options from auto/manual setup dropdown menu: */ +static void _auto_manual_setup_option_mouse_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Down *ev); +/* User has changed 12/24h hours type selection: */ +static void _h_24_12_changed_cb(int id, void *data, Evas_Object *check_24); +/* (MOUSE/KEYPAD/REMOTE) User has changed finished edition and clicks Done button: */ +static void _done_mouse_cb(int id, void *data, Evas_Object *obj); +/* (MOUSE/KEYPAD/REMOTE) User has changed finished edition and clicks Cancel button: */ +static void _cancel_mouse_cb(int id, void *data, Evas_Object *obj); +/* In automatic time settings some controls should be disabled:*/ +static void _disable_manual_settings(bool disable, const clock_view_priv_data *priv); +/* Helper to make time out of widgets values: */ +static void _get_time_from_controls(struct tm *result, const clock_view_priv_data *priv); + +static input_handler _auto_manual_setup_input_handler = { + .mouse_move = _auto_manual_mouse_move_cb, + .key_down = _auto_manual_setup_key_down_cb, + .mouse_down = _auto_manual_setup_mouse_down_cb +}; - if (!elm_object_focus_get(obj)) - elm_object_focus_set(obj, EINA_TRUE); -} +static input_handler _auto_manual_setup_option_selection_input_handler = { + .mouse_move = _auto_manual_mouse_move_cb, + .key_down = _auto_manual_setup_option_key_down_cb, + .mouse_down = _auto_manual_setup_option_mouse_cb +}; + +static input_handler h_12_24_changed = { + .changed = _h_24_12_changed_cb +}; + +static input_handler done_btn_handler = { + .clicked = _done_mouse_cb +}; + +static input_handler cancel_btn_handler = { + .clicked = _cancel_mouse_cb +}; -static void _destroy_setup_type_popup(struct _priv *priv) +static void _destroy_setup_type_popup(clock_view_priv_data *priv) { evas_object_hide(priv->setup_type_popup); evas_object_del(priv->setup_type_popup); priv->setup_type_popup = NULL; } -static void _setup_type_option_selected(struct _priv *priv, int id, +static void _setup_type_option_selected(clock_view_priv_data *priv, int id, Evas_Object *obj) { + if (!priv) { + _ERR("priv data is NULL"); + return; + } + _destroy_setup_type_popup(priv); - elm_object_text_set(priv->clock_setup_btn, elm_object_text_get(obj)); + elm_object_text_set(priv->auto_manual_setup_btn, elm_object_text_get(obj)); switch (id) { case TYPE_AUTO: - vconf_set_bool(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, TYPE_AUTO); + _disable_manual_settings(true, priv); break; case TYPE_MANUAL: - vconf_set_bool(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, TYPE_MANUAL); + _disable_manual_settings(false, priv); break; default: _ERR("Unhandled setup type."); @@ -100,157 +146,40 @@ static void _setup_type_option_selected(struct _priv *priv, int id, priv->cur_type = id; } -static void _setup_type_option_key_down_cb(int id, void *data, Evas *e, - Evas_Object *obj, Evas_Event_Key_Down *ev) -{ - struct _priv *priv; - - if (!data || !obj || !ev) { - _ERR("Invalid argument."); - return; - } - - priv = data; - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_ESC)) - _destroy_setup_type_popup(priv); - else if(!strcmp(ev->keyname, KEY_ENTER)) - _setup_type_option_selected(priv, id, obj); -} - -static void _setup_type_option_mouse_down_cb(int id, void *data, Evas *e, - Evas_Object *obj, Evas_Event_Mouse_Down *ev) +static void _draw_setup_type_popup(clock_view_priv_data *priv) { - struct _priv *priv; + Evas_Object *ctxpopup = NULL; + Evas_Coord x = 0, y = 0, w = 0, h = 0; - if (!data || !obj || !ev) { - _ERR("Invalid argument."); + if (!priv) { + _ERR("priv data NULL"); return; } - priv = data; - - _setup_type_option_selected(priv, id, obj); -} - -static input_handler _setup_type_option_input_handler = { - .mouse_move = _mouse_move_cb, - .key_down = _setup_type_option_key_down_cb, - .mouse_down = _setup_type_option_mouse_down_cb -}; + elm_object_signal_emit(priv->auto_manual_setup_btn, SIG_SELECTED, SRC_ELM); -static void _draw_setup_type_popup(struct _priv *priv) -{ - Evas_Object *ctxpopup; - Evas_Coord x, y, w, h; - - elm_object_signal_emit(priv->clock_setup_btn, SIG_SELECTED, SRC_ELM); - - ctxpopup = utils_add_ctxpopup(priv->base, COUNT_SETUP_TYPE, + ctxpopup = utils_add_ctxpopup(priv->base, TYPE_MAX, id_setup_type_opt, str_setup_type_opt, - &_setup_type_option_input_handler, priv); + &_auto_manual_setup_option_selection_input_handler, priv); if (!ctxpopup) { _ERR("Add ctxpopup failed."); return; } - evas_object_geometry_get(priv->clock_setup_btn, &x, &y, &w, &h); - evas_object_move(ctxpopup, - ELM_SCALE_SIZE(x + w / 2), - ELM_SCALE_SIZE(y + h)); - evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(SIZE_SETUP_CTXPOPUP_W), - ELM_SCALE_SIZE(SIZE_SETUP_CTXPOPUP_H)); + evas_object_geometry_get(priv->auto_manual_setup_btn, &x, &y, &w, &h); + evas_object_move(ctxpopup, (x + w / 2), (y + h)); + evas_object_resize(ctxpopup, w, 0); priv->setup_type_popup = ctxpopup; elm_object_focus_set(priv->setup_type_popup, EINA_TRUE); } -static void _setup_type_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, - Evas_Event_Key_Down *ev) -{ - struct _priv *priv; - - if (!obj || !ev) { - _ERR("Invalid argument."); - return; - } - - priv = data; - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_ESC) - || !strcmp(ev->keyname, KEY_UP)) -// viewmgr_update_view(VIEW_BASE, UPDATE_FOCUS, NULL); - _destroy_setup_type_popup(priv); - else if (!strcmp(ev->keyname, KEY_ENTER)) - _draw_setup_type_popup(priv); -} - -static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, - Evas_Event_Key_Down *ev) -{ - struct _priv *priv; - priv = data; - - if (!obj || !ev) { - _ERR("Invalid argument."); - return; - } - - struct tm _tm_year; - elm_datetime_value_get(priv->year, &_tm_year); - time_t the_time = mktime(&_tm_year); - - if (!strcmp(ev->keyname, KEY_ENTER)) { - switch (id) { - case INPUT_HANDLER_TYPE_BTN_CANCEL: - viewmgr_pop_view(); - break; - - case INPUT_HANDLER_TYPE_BTN_DONE: - alarmmgr_set_systime(the_time); - viewmgr_pop_view(); - break; - - default: - return; - } - } -} - -static void _mouse_down_cb(int id, void *data, Evas *e, Evas_Object *obj, - Evas_Event_Mouse_Down *ev) +static bool _add_clock_setting(clock_view_priv_data *priv) { - if (!obj || !ev) { - _ERR("Invalid argument."); - return; - } + Evas_Object *done = NULL; + Evas_Object *cancel = NULL; - switch (id) { - case INPUT_HANDLER_TYPE_BTN_CANCEL: - viewmgr_pop_view(); - break; - - case INPUT_HANDLER_TYPE_BTN_DONE: - break; - - default: - return; - } -} - -static input_handler _setup_type_input_handler = { - .mouse_move = _mouse_move_cb, - .key_down = _setup_type_key_down_cb, -}; - -static input_handler handler = { - .key_down = _key_down_cb, - .mouse_down = _mouse_down_cb, -}; - -static bool _add_clock_setting(struct _priv *priv) -{ if (!priv || !priv->base) { _ERR("Invalid argument."); return false; @@ -263,15 +192,12 @@ static bool _add_clock_setting(struct _priv *priv) elm_object_part_text_set(priv->base, PART_MAIN_LABEL_24HOUR, STR_24HOUR); elm_object_part_text_set(priv->base, PART_MAIN_LABEL_TIME, STR_TIME); - // Add btns - Evas_Object *done, *cancel; - + /* Add screen bottom buttons */ done = utils_add_button(priv->base, PART_BOTTOM_BTN_DONE, "elm/button/base/style.normal.button", STR_DONE); if (!done) { _ERR("failed to add done btn"); return false; } - inputmgr_add_callback(done, INPUT_HANDLER_TYPE_BTN_DONE, &handler, priv); cancel = utils_add_button(priv->base, PART_BOTTOM_BTN_CANCEL, NULL, STR_CANCEL); if (!cancel) { @@ -279,85 +205,45 @@ static bool _add_clock_setting(struct _priv *priv) evas_object_del(done); return false; } - inputmgr_add_callback(cancel, INPUT_HANDLER_TYPE_BTN_CANCEL, &handler, priv); priv->cancel = cancel; priv->done = done; - // item - SETUP - Evas_Object *setup_btn; - setup_btn = utils_add_button(priv->base, PART_MAIN_ITEM_SETUP, STYLE_OPTION_BTN, str_setup_type_opt[0]); - inputmgr_add_callback(setup_btn, 0, &_setup_type_input_handler, priv); - priv->clock_setup_btn = setup_btn; - - // item - year - Evas_Object *year = priv->year; - year = elm_datetime_add(priv->base); - elm_datetime_field_visible_set(year, ELM_DATETIME_HOUR, EINA_FALSE); - elm_datetime_field_visible_set(year, ELM_DATETIME_MINUTE, EINA_FALSE); - elm_datetime_field_visible_set(year, ELM_DATETIME_AMPM, EINA_FALSE); - elm_datetime_field_visible_set(year, ELM_DATETIME_MONTH, EINA_FALSE); - elm_datetime_field_visible_set(year, ELM_DATETIME_DATE, EINA_FALSE); - elm_object_part_content_set(priv->base, PART_MAIN_ITEM_DATE_YEAR, year); - priv->year = year; - - // item - month - Evas_Object *month; - month = elm_datetime_add(priv->base); - elm_datetime_field_visible_set(month, ELM_DATETIME_HOUR, EINA_FALSE); - elm_datetime_field_visible_set(month, ELM_DATETIME_MINUTE, EINA_FALSE); - elm_datetime_field_visible_set(month, ELM_DATETIME_AMPM, EINA_FALSE); - elm_datetime_field_visible_set(month, ELM_DATETIME_YEAR, EINA_FALSE); - elm_datetime_field_visible_set(month, ELM_DATETIME_DATE, EINA_FALSE); - elm_object_part_content_set(priv->base, PART_MAIN_ITEM_DATE_MONTH, month); - - // item - day - Evas_Object *day; - day = elm_datetime_add(priv->base); - elm_datetime_field_visible_set(day, ELM_DATETIME_HOUR, EINA_FALSE); - elm_datetime_field_visible_set(day, ELM_DATETIME_MINUTE, EINA_FALSE); - elm_datetime_field_visible_set(day, ELM_DATETIME_AMPM, EINA_FALSE); - elm_datetime_field_visible_set(day, ELM_DATETIME_YEAR, EINA_FALSE); - elm_datetime_field_visible_set(day, ELM_DATETIME_MONTH, EINA_FALSE); - elm_object_part_content_set(priv->base, PART_MAIN_ITEM_DATE_DAY, day); - - // item - hour - Evas_Object *hour; - hour = elm_datetime_add(priv->base); - elm_datetime_field_visible_set(hour, ELM_DATETIME_MINUTE, EINA_FALSE); - elm_datetime_field_visible_set(hour, ELM_DATETIME_AMPM, EINA_FALSE); - elm_datetime_field_visible_set(hour, ELM_DATETIME_YEAR, EINA_FALSE); - elm_datetime_field_visible_set(hour, ELM_DATETIME_MONTH, EINA_FALSE); - elm_datetime_field_visible_set(hour, ELM_DATETIME_DATE, EINA_FALSE); - elm_object_part_content_set(priv->base, PART_MAIN_ITEM_TIME_HOUR, hour); - - // item - min - Evas_Object *min; - min = elm_datetime_add(priv->base); - elm_datetime_field_visible_set(min, ELM_DATETIME_HOUR, EINA_FALSE); - elm_datetime_field_visible_set(min, ELM_DATETIME_AMPM, EINA_FALSE); - elm_datetime_field_visible_set(min, ELM_DATETIME_YEAR, EINA_FALSE); - elm_datetime_field_visible_set(min, ELM_DATETIME_MONTH, EINA_FALSE); - elm_datetime_field_visible_set(min, ELM_DATETIME_DATE, EINA_FALSE); - elm_object_part_content_set(priv->base, PART_MAIN_ITEM_TIME_MIN, min); - - // item - ampm - Evas_Object *ampm; - ampm = elm_datetime_add(priv->base); - elm_datetime_field_visible_set(ampm, ELM_DATETIME_HOUR, EINA_FALSE); - elm_datetime_field_visible_set(ampm, ELM_DATETIME_MINUTE, EINA_FALSE); - elm_datetime_field_visible_set(ampm, ELM_DATETIME_YEAR, EINA_FALSE); - elm_datetime_field_visible_set(ampm, ELM_DATETIME_MONTH, EINA_FALSE); - elm_datetime_field_visible_set(ampm, ELM_DATETIME_DATE, EINA_FALSE); - elm_object_part_content_set(priv->base, PART_MAIN_ITEM_TIME_AMPM, ampm); + /* item - SETUP (clock auto/manual) */ + priv->auto_manual_setup_btn = utils_add_button(priv->base, PART_MAIN_ITEM_SETUP, STYLE_OPTION_BTN, _(STR_MANUAL)); + + priv->date_part = elm_datetime_add(priv->base); + elm_datetime_field_visible_set(priv->date_part, ELM_DATETIME_HOUR, EINA_FALSE); + elm_datetime_field_visible_set(priv->date_part, ELM_DATETIME_MINUTE, EINA_FALSE); + elm_datetime_field_visible_set(priv->date_part, ELM_DATETIME_AMPM, EINA_FALSE); + elm_object_part_content_set(priv->base, PART_MAIN_ITEM_DATE, priv->date_part); + elm_object_scale_set(priv->date_part, 1.0 / APP_BASE_SCALE); + + /* 24/12h check: */ + priv->check_24 = elm_check_add(priv->base); + elm_object_part_content_set(priv->base, PART_MAIN_ITEM_24HOUR, priv->check_24); + elm_object_scale_set(priv->check_24, 1.0 / APP_BASE_SCALE); + + priv->time_part = elm_datetime_add(priv->base); + elm_datetime_field_visible_set(priv->time_part, ELM_DATETIME_YEAR, EINA_FALSE); + elm_datetime_field_visible_set(priv->time_part, ELM_DATETIME_MONTH, EINA_FALSE); + elm_datetime_field_visible_set(priv->time_part, ELM_DATETIME_DATE, EINA_FALSE); + elm_datetime_field_visible_set(priv->time_part, ELM_DATETIME_AMPM, EINA_TRUE); + elm_object_part_content_set(priv->base, PART_MAIN_ITEM_TIME, priv->time_part); + elm_object_scale_set(priv->time_part, 1.0 / APP_BASE_SCALE); + + inputmgr_add_callback(done, INPUT_HANDLER_TYPE_BTN_DONE, &done_btn_handler, priv); + inputmgr_add_callback(cancel, INPUT_HANDLER_TYPE_BTN_CANCEL, &cancel_btn_handler, priv); + inputmgr_add_callback(priv->auto_manual_setup_btn, 0, &_auto_manual_setup_input_handler, priv); + inputmgr_add_callback(priv->check_24, INPUT_HANDLER_TYPE_CHECK_H12_24, &h_12_24_changed, priv); return true; } static Evas_Object *_create(Evas_Object *win, void *data) { - struct _priv *priv; - Evas_Object *base; + clock_view_priv_data *priv = NULL; + Evas_Object *base = NULL; _DBG("Called"); if (!win) { @@ -365,7 +251,7 @@ static Evas_Object *_create(Evas_Object *win, void *data) return NULL; } - priv = calloc(1, sizeof(*priv)); + priv = (clock_view_priv_data *)calloc(1, sizeof(clock_view_priv_data)); if (!priv) { _ERR("Calloc failed."); return NULL; @@ -400,28 +286,61 @@ static Evas_Object *_create(Evas_Object *win, void *data) static void _show(void *data) { - struct _priv *priv; + bool automatic_time = false; + bool h24 = true; + clock_view_priv_data *priv = NULL; + struct tm current_time = {0,}; - if (!data) { + priv = (clock_view_priv_data *)data; + + if (!priv) { _ERR("Get data failed."); return; } - priv = data; - _DBG("Called"); + if (!settings_clock_get_current_time(¤t_time)) + _ERR("Failed to obtain current time"); + + if (!settings_clock_is_24h_set(&h24)) + _ERR("Failed to check if 24h time is set"); + + if (!settings_clock_is_time_automatic(&automatic_time)) + _ERR("Failed to check if time is auto"); + + if (automatic_time) { + priv->cur_type = TYPE_AUTO; + elm_object_domain_translatable_text_set(priv->auto_manual_setup_btn, SETTINGS_PACKAGE, _(STR_AUTO)); + } else { + elm_object_domain_translatable_text_set(priv->auto_manual_setup_btn, SETTINGS_PACKAGE, _(STR_MANUAL)); + priv->cur_type = TYPE_MANUAL; + } + + _disable_manual_settings(automatic_time, priv); + + elm_check_state_set(priv->check_24, h24); + + if (h24) { + elm_datetime_format_set(priv->time_part, "%H:%M %P"); + } else { + elm_datetime_format_set(priv->time_part, "%I:%M %P"); + } + + elm_datetime_value_set(priv->date_part, (Elm_Datetime_Time *)¤t_time); + elm_datetime_value_set(priv->time_part, (Elm_Datetime_Time *)¤t_time); + if (priv->base) evas_object_show(priv->base); } static void _hide(void *data) { - struct _priv *priv; + clock_view_priv_data *priv = NULL; if (!data) { _ERR("Get data failed."); return; } - priv = data; + priv = (clock_view_priv_data *)data; if (priv->base) evas_object_hide(priv->base); @@ -429,14 +348,14 @@ static void _hide(void *data) static void _destroy(void *data) { - struct _priv *priv; + clock_view_priv_data *priv = NULL; if (!data) { _ERR("Get data failed."); return; } - priv = data; + priv = (clock_view_priv_data *)data; if (priv->base) evas_object_del(priv->base); @@ -456,3 +375,162 @@ view_class *view_clock_get_vclass(void) { return &_vclass; } + +static void _auto_manual_mouse_move_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Move *ev) +{ + if (obj) { + _ERR("Invalid argument."); + return; + } + + if (!elm_object_focus_get(obj)) + elm_object_focus_set(obj, EINA_TRUE); +} + +static void _auto_manual_setup_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev) +{ + clock_view_priv_data *priv = NULL; + + if (!obj || !ev) { + _ERR("Invalid argument."); + return; + } + + priv = (clock_view_priv_data *)data; + + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_ESC) + || !strcmp(ev->keyname, KEY_UP)) { + _destroy_setup_type_popup(priv); + } else { + if (!strcmp(ev->keyname, KEY_ENTER)) + _draw_setup_type_popup(priv); + } +} + +static void _auto_manual_setup_mouse_down_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Down *ev) +{ + clock_view_priv_data *priv = NULL; + + if (!obj || !ev) { + _ERR("Invalid argument."); + return; + } + + priv = (clock_view_priv_data *)data; + _draw_setup_type_popup(priv); +} + +static void _auto_manual_setup_option_key_down_cb(int id, void *data, Evas *e, + Evas_Object *obj, Evas_Event_Key_Down *ev) +{ + clock_view_priv_data *priv = NULL; + + if (!data || !obj || !ev) { + _ERR("Invalid argument."); + return; + } + + priv = (clock_view_priv_data *)data; + + if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_ESC)) { + _destroy_setup_type_popup(priv); + } else { + if(!strcmp(ev->keyname, KEY_ENTER)) + _setup_type_option_selected(priv, id, obj); + } +} + +static void _auto_manual_setup_option_mouse_cb(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Down *ev) +{ + clock_view_priv_data *priv = NULL; + + if (!data || !obj) { + _ERR("Invalid argument"); + return; + } + priv = (clock_view_priv_data *)data; + + _setup_type_option_selected(priv, id, obj); +} + +static void _h_24_12_changed_cb(int id, void *data, Evas_Object *check_24) +{ + Eina_Bool state = EINA_FALSE; + clock_view_priv_data *priv = NULL; + + priv = (clock_view_priv_data *)data; + + if (!check_24 || !priv) + return; + + state = elm_check_state_get(check_24); + + if (state) {/*24h*/ + elm_datetime_format_set(priv->time_part, "%H:%M %P"); + } else {/*12h*/ + elm_datetime_format_set(priv->time_part, "%I:%M %P"); + } +} + +static void _done_mouse_cb(int id, void *data, Evas_Object *obj) +{ + struct tm current_time = {0,}; + clock_view_priv_data *priv = NULL; + priv = (clock_view_priv_data *)data; + + if (!priv) { + _ERR("priv is NULL"); + return; + } + + if (priv->cur_type == TYPE_AUTO) { + settings_clock_set_time_automatic(true); + } else { + settings_clock_set_time_automatic(false); + if (elm_check_state_get(priv->check_24)) {/*24h*/ + settings_clock_set_24h(true); + } else {/*12h*/ + settings_clock_set_24h(false); + } + _get_time_from_controls(¤t_time, priv); + if (!settings_clock_set_current_time(¤t_time)) + _ERR("Date and time set error"); + } + + viewmgr_pop_view(); +} + +static void _cancel_mouse_cb(int id, void *data, Evas_Object *obj) +{ + viewmgr_pop_view(); +} + +static void _disable_manual_settings(bool disable, const clock_view_priv_data *priv) +{ + elm_object_disabled_set(priv->date_part, disable); + elm_object_disabled_set(priv->time_part, disable); + elm_object_disabled_set(priv->check_24, disable); +} + +static void _get_time_from_controls(struct tm *result, const clock_view_priv_data *priv) +{ + struct tm tmp = {0,}; + + if (!result || !priv) + return; + + elm_datetime_value_get(priv->date_part, &tmp); + result->tm_year = tmp.tm_year; + result->tm_mon = tmp.tm_mon; + result->tm_mday = tmp.tm_year; + result->tm_wday = tmp.tm_wday; + result->tm_yday = tmp.tm_yday; + elm_datetime_value_get(priv->time_part, &tmp); + result->tm_hour = tmp.tm_hour; + result->tm_min = tmp.tm_min; + result->tm_sec = tmp.tm_sec; +}