2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <Elementary.h>
24 #include <notification.h>
26 #include <tzsh_quickpanel_service.h>
27 #include <sound_manager.h>
31 #include "common_uic.h"
32 #include "quickpanel-ui.h"
33 #include "list_util.h"
34 #include "quickpanel_def.h"
36 #include "util-time.h"
39 #ifdef QP_SCREENREADER_ENABLE
40 #include "accessibility.h"
43 #ifdef QP_EMERGENCY_MODE_ENABLE
44 #include "emergency_mode.h"
47 static int _init(void *data);
48 static int _fini(void *data);
50 #define PKG_SETTING_EDIT "quickpanel-setting-efl"
51 #define QP_TIMEDATE_SETTING_UG "setting-time-efl"
52 #define E_DATA_EDITING_VISIBILITT "editing_visible"
53 #define E_DATA_TIME_N_DATE_EVENT "time_n_date_event"
55 QP_Module qp_datetime_view = {
56 .name = "qp_datetime_view",
65 static Evas_Object *_datetime_view_get(void);
67 static void _flag_set(Evas_Object *container, const char *key, int value)
69 retif(container == NULL, , "invalid parameter");
70 retif(key == NULL, , "invalid parameter");
72 evas_object_data_set(container, key, (void *)(long)(value));
75 static int _flag_get(Evas_Object *container, const char *key)
77 retif(container == NULL, 0, "invalid parameter");
78 retif(key == NULL, 0, "invalid parameter");
80 return (int)(long)evas_object_data_get(container, key);
83 static void _set_text_to_part(Evas_Object *obj, const char *part, const char *text)
85 const char *old_text = NULL;
87 retif(obj == NULL, , "Invalid parameter!");
88 retif(part == NULL, , "Invalid parameter!");
89 retif(text == NULL, , "Invalid parameter!");
91 old_text = elm_object_part_text_get(obj, part);
92 if (old_text != NULL) {
93 if (strcmp(old_text, text) == 0) {
98 elm_object_part_text_set(obj, part, text);
101 static void _text_time_clicked_cb(void *data, Evas_Object *obj, void *event_info)
103 Evas_Object *view = _datetime_view_get();
107 if (_flag_get(view, E_DATA_TIME_N_DATE_EVENT) == 0) {
108 DBG("Time & date area click is event disabled");
113 quickpanel_media_play_feedback();
115 ret = quickpanel_uic_launch_ug_by_appcontrol(QP_TIMEDATE_SETTING_UG, NULL);
116 quickpanel_uic_launch_app_inform_result(QP_TIMEDATE_SETTING_UG, ret);
118 quickpanel_uic_close_quickpanel(true, 1);
121 static void _button_setting_clicked_cb(void *data, Evas_Object *obj, void *event_info)
123 quickpanel_media_play_feedback();
125 #ifdef QP_EMERGENCY_MODE_ENABLE
126 if (quickpanel_emergency_mode_is_on()) {
127 quickpanel_uic_launch_app(PACKAGE_EMERGENCY_MODE_SETTING, NULL);
129 quickpanel_uic_launch_app(QP_SETTING_PKG_SETTING, NULL);
132 quickpanel_uic_launch_app(QP_SETTING_PKG_SETTING, NULL);
134 quickpanel_uic_close_quickpanel(true, 1);
137 static Evas_Object *_datetime_view_create(Evas_Object *parent)
139 Evas_Object *focus = NULL;
140 Eina_Bool ret = EINA_TRUE;
141 Evas_Object *view = NULL;
143 retif(parent == NULL, NULL, "Invalid parameter!");
145 view = elm_layout_add(parent);
148 ret = elm_layout_file_set(view, DEFAULT_EDJ,
149 "quickpanel/datetime");
150 if (ret == EINA_FALSE) {
151 ERR("failed to load quickpanel/datetime layout");
153 evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
154 evas_object_size_hint_align_set(view, EVAS_HINT_FILL, EVAS_HINT_FILL);
155 quickpanel_uic_initial_resize(view, QP_DATE_H);
157 focus = quickpanel_accessibility_ui_get_focus_object(view);
158 elm_object_part_content_set(view, "focus.datetime", focus);
159 evas_object_smart_callback_add(focus, "clicked", _text_time_clicked_cb, view);
161 focus = quickpanel_accessibility_ui_get_focus_object(view);
162 elm_object_part_content_set(view, "focus.setting", focus);
163 evas_object_smart_callback_add(focus, "clicked", _button_setting_clicked_cb, view);
165 _flag_set(view, E_DATA_EDITING_VISIBILITT, 0);
167 if (quickpanel_emergency_mode_is_on()) {
168 _flag_set(view, E_DATA_TIME_N_DATE_EVENT, 0);
169 elm_object_signal_emit(view, "timendate.click.disable", "prog");
171 _flag_set(view, E_DATA_TIME_N_DATE_EVENT, 1);
172 elm_object_signal_emit(view, "timendate.click.enable", "prog");
175 evas_object_show(view);
181 static Evas_Object *_datetime_view_get(void) {
182 struct appdata *ad = quickpanel_get_app_data();
183 retif(ad == NULL, NULL, "invalid argument");
184 retif(ad->view_root == NULL, NULL, "invalid argument");
186 return elm_object_part_content_get(ad->view_root
187 , "qp.base.datetime.swallow");
190 static void _datetime_view_attach(void *data)
192 Evas_Object *view = NULL;
193 struct appdata *ad = data;
194 retif(ad == NULL, ,"invalid parameter");
195 retif(ad->view_root == NULL, ,"invalid parameter");
197 view = _datetime_view_create(ad->view_root);
199 elm_object_part_content_set(ad->view_root, "qp.base.datetime.swallow", view);
203 static void _datetime_view_deattach(void *data)
205 Evas_Object *view = NULL;
206 struct appdata *ad = data;
207 retif(ad == NULL, ,"invalid parameter");
208 retif(ad->view_root == NULL, ,"invalid parameter");
210 view = elm_object_part_content_unset(ad->view_root, "qp.base.datetime.swallow");
212 evas_object_del(view);
217 static int _init(void *data)
219 struct appdata *ad = data;
220 retif(ad == NULL, QP_FAIL,"invalid parameter");
222 _datetime_view_attach(ad);
227 static int _fini(void *data)
229 _datetime_view_deattach(data);
234 HAPI void quickpanel_datetime_datentime_event_set(int is_clickable)
236 Evas_Object *view = _datetime_view_get();
238 DBG("date n time clickable set[%d]", is_clickable);
241 if (is_clickable == 1) {
242 if (_flag_get(view, E_DATA_TIME_N_DATE_EVENT) == 0) {
243 _flag_set(view, E_DATA_TIME_N_DATE_EVENT, 1);
244 elm_object_signal_emit(view, "timendate.click.enable", "prog");
247 if (_flag_get(view, E_DATA_TIME_N_DATE_EVENT) == 1) {
248 _flag_set(view, E_DATA_TIME_N_DATE_EVENT, 0);
249 elm_object_signal_emit(view, "timendate.click.disable", "prog");
255 HAPI void quickpanel_datetime_editing_icon_visibility_set(int is_visible)
257 Evas_Object *view = _datetime_view_get();
259 DBG("visibility set:%d", is_visible);
262 if (is_visible == 1) {
263 if (_flag_get(view, E_DATA_EDITING_VISIBILITT) == 0) {
264 _flag_set(view, E_DATA_EDITING_VISIBILITT, 1);
265 elm_object_signal_emit(view, "button,editing,show", "prog");
268 if (_flag_get(view, E_DATA_EDITING_VISIBILITT) == 1) {
269 _flag_set(view, E_DATA_EDITING_VISIBILITT, 0);
270 elm_object_signal_emit(view, "button,editing,hide", "prog");
276 HAPI void quickpanel_datetime_view_update(char *date, char *time, char *meridiem, int meridiem_type)
278 Evas_Object *view = NULL;
280 Eina_Strbuf *strbuf_date = NULL;
281 Eina_Strbuf *strbuf_time = NULL;
282 Eina_Strbuf *strbuf_access = NULL;
284 view = _datetime_view_get();
291 strbuf_date = eina_strbuf_new();
293 ERR("strbuf_date == NULL");
297 strbuf_time = eina_strbuf_new();
299 ERR("strbuf_time == NULL");
300 eina_strbuf_free(strbuf_date);
304 strbuf_access = eina_strbuf_new();
306 ERR("strbuf_access == NULL");
307 eina_strbuf_free(strbuf_date);
308 eina_strbuf_free(strbuf_time);
313 DBG("update time: %s %s %s", date, time, meridiem);
316 eina_strbuf_append_printf(strbuf_date, "%s", date);
317 eina_strbuf_append_printf(strbuf_access, "%s ", date);
320 eina_strbuf_ltrim(strbuf_date);
322 // -------------------------------------------------------------------------------------
324 if (meridiem_type == UTIL_TIME_MERIDIEM_TYPE_PRE && meridiem != NULL && strlen(meridiem) != 0) {
325 eina_strbuf_append_printf(strbuf_time, "<ampm>%s</> ", meridiem);
326 eina_strbuf_append_printf(strbuf_access, "%s ", meridiem);
330 eina_strbuf_append_printf(strbuf_time, "<time>%s</>", time);
331 eina_strbuf_append_printf(strbuf_access, "%s ", time);
334 if (meridiem_type == UTIL_TIME_MERIDIEM_TYPE_POST && meridiem != NULL && strlen(meridiem) != 0) {
335 eina_strbuf_append_printf(strbuf_time, " <ampm>%s</>", meridiem);
336 eina_strbuf_append_printf(strbuf_access, "%s ", meridiem);
339 eina_strbuf_ltrim(strbuf_time);
341 // -------------------------------------------------------------------------------------
343 LOGI("DATE STR SET: %s", eina_strbuf_string_get(strbuf_time));
345 _set_text_to_part(view, "text.date", eina_strbuf_string_get(strbuf_date));
346 _set_text_to_part(view, "text.time", eina_strbuf_string_get(strbuf_time));
348 quickpanel_accessibility_screen_reader_data_set(view, "focus.datetime", "", (char *)eina_strbuf_string_get(strbuf_access));
350 eina_strbuf_free(strbuf_date);
351 eina_strbuf_free(strbuf_time);
352 eina_strbuf_free(strbuf_access);
354 quickpanel_accessibility_screen_reader_data_set(view
355 , "focus.setting", "", _NOT_LOCALIZED("Settings"));