1 #include "clock.h"
2 #include <time.h>
3 
4 static const char *datecfg[] =
5 {
6    N_("None"),
7    N_("Full"),
8    N_("Numeric"),
9    N_("Date-only"),
10    N_("ISO 8601"),
11    N_("Custom"),
12 };
13 
14 
15 static void
_config_rect_click(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)16 _config_rect_click(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
17 {
18    Evas_Event_Mouse_Up *ev = event_info;
19    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
20    evas_object_del(data);
21 }
22 
23 static Evas_Object *
_config_autoclose_rect_add(Evas_Object * obj)24 _config_autoclose_rect_add(Evas_Object *obj)
25 {
26    Evas_Object *rect;
27 
28    rect = evas_object_rectangle_add(e_comp->evas);
29    e_comp_object_util_fullscreen(rect);
30    evas_object_color_set(rect, 0, 0, 0, 0);
31    evas_object_layer_set(rect, E_LAYER_MENU - 1);
32    evas_object_show(rect);
33    evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_UP, _config_rect_click, obj);
34    return rect;
35 }
36 
37 static void
_config_close(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)38 _config_close(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
39 {
40    time_config->config_dialog = NULL;
41 }
42 
43 static void
_config_changed(void * data,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)44 _config_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
45 {
46    time_config_update(data);
47 }
48 
49 static void
_clock_color_dismissed(void * data EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)50 _clock_color_dismissed(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
51 {
52    evas_object_del(obj);
53 }
54 
55 static void
_config_color_reset(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)56 _config_color_reset(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
57 {
58    Config_Item *ci = data;
59    Evas_Object *cs;
60    int num;
61 
62    num = !evas_object_data_get(obj, "bg_color");
63    if (ci->colorclass[num])
64      {
65         elm_config_color_overlay_unset(ci->colorclass[num]);
66         edje_color_class_del(ci->colorclass[num]);
67      }
68    eina_stringshare_replace(&ci->colorclass[num], NULL);
69    cs = evas_object_data_get(obj, "colorselector");
70    elm_colorselector_color_set(cs, 0, 0, 0, 0);
71    elm_colorselector_palette_item_color_set(evas_object_data_get(cs, "colorselector_it"),
72      0, 0, 0, 0);
73    time_config_update(data);
74 }
75 
76 static void
_config_color_change(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)77 _config_color_change(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
78 {
79    Config_Item *ci = data;
80    int r, g, b, a;
81    int num;
82    char buf[1024];
83 
84    num = !evas_object_data_get(obj, "bg_color");
85    elm_colorselector_color_get(obj, &r, &g, &b, &a);
86 
87    if (!ci->colorclass[num])
88      {
89         snprintf(buf, sizeof(buf), "e.clock_color_%s.%d", num ? "fg" : "bg", ci->id);
90         eina_stringshare_replace(&ci->colorclass[num], buf);
91      }
92    elm_config_color_overlay_set(ci->colorclass[num], r, g, b, a, 0, 0, 0, 0, 0, 0, 0, 0);
93    edje_color_class_set(ci->colorclass[num], r, g, b, a, 0, 0, 0, 0, 0, 0, 0, 0);
94    elm_colorselector_palette_item_color_set(evas_object_data_get(obj, "colorselector_it"), r, g, b, a);
95    time_config_update(data);
96 }
97 
98 static void
_config_color_setup(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)99 _config_color_setup(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
100 {
101    Config_Item *ci = data;
102    Evas_Object *cs, *ctx, *bx, *bt, *rect;
103    int r, g, b, a, x, y;
104    Eina_Bool bg;
105    const char *ccname, *ccnames[] =
106    {
107       "e.clock_color_bg",
108       "e.clock_color_fg",
109    };
110 
111    bg = !!evas_object_data_get(obj, "bg_color");
112    ccname = ci->colorclass[!bg];
113    if (!ccname) ccname = ccnames[!bg];
114    edje_color_class_get(ccname, &r, &g, &b, &a,
115      NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
116 
117    bx = elm_box_add(obj);
118    E_FILL(bx);
119    evas_object_show(bx);
120 
121    cs = elm_colorselector_add(obj);
122    evas_object_data_set(cs, "colorselector_bt", evas_object_data_get(obj, "colorselector_tt"));
123    evas_object_data_set(cs, "bg_color", (void*)(long)bg);
124    evas_object_smart_callback_add(cs, "changed,user", _config_color_change, ci);
125    elm_colorselector_mode_set(cs, ELM_COLORSELECTOR_COMPONENTS);
126    elm_colorselector_color_set(cs, r, g, b, a);
127    E_FILL(cs);
128    elm_box_pack_end(bx, cs);
129    evas_object_show(cs);
130 
131    bt = elm_button_add(bx);
132    evas_object_data_set(bt, "colorselector", cs);
133    evas_object_data_set(bt, "bg_color", (void*)(long)bg);
134    elm_object_text_set(bt, _("Reset"));
135    evas_object_smart_callback_add(bt, "clicked", _config_color_reset, ci);
136    evas_object_show(bt);
137    elm_box_pack_end(bx, bt);
138 
139    /* size hints: the final frontier */
140    rect = evas_object_rectangle_add(e_comp->elm);
141    evas_object_geometry_get(time_config->config_dialog, NULL, NULL, &x, &y);
142    evas_object_size_hint_min_set(rect, x - 10, 1);
143    e_comp_object_util_del_list_append(bx, rect);
144    elm_box_pack_end(bx, rect);
145 
146    ctx = elm_ctxpopup_add(obj);
147    elm_ctxpopup_hover_parent_set(ctx, e_comp->elm);
148    evas_object_layer_set(ctx, E_LAYER_MENU);
149    elm_object_style_set(ctx, "noblock");
150    rect = _config_autoclose_rect_add(ctx);
151    evas_object_smart_callback_call(ci->inst->o_clock, "gadget_popup", rect);
152    e_comp_object_util_del_list_append(ctx, rect);
153    evas_object_smart_callback_add(ctx, "dismissed", _clock_color_dismissed, NULL);
154    elm_object_content_set(ctx, bx);
155    evas_pointer_canvas_xy_get(e_comp->evas, &x, &y);
156    evas_object_move(ctx, x, y);
157    evas_object_show(ctx);
158 }
159 
160 static void
_config_digital_timestr_update(Config_Item * ci,Evas_Object * obj,int idx)161 _config_digital_timestr_update(Config_Item *ci, Evas_Object *obj, int idx)
162 {
163    const char *str, *p;
164    char seconds[] =
165    {
166     'S',
167     's',
168     'r',
169     'T',
170    };
171    unsigned int i;
172 
173    str = elm_entry_entry_get(obj);
174    eina_stringshare_replace(&ci->time_str[idx], str);
175    ci->show_seconds = 0;
176    for (p = strchr(str, '%'); p; p = strchr(p + 1, '%'))
177      {
178         for (i = 0; i < EINA_C_ARRAY_LENGTH(seconds); i++)
179           if (p[1] == seconds[i])
180             {
181                ci->show_seconds = 1;
182                time_config_update(ci);
183                return;
184             }
185      }
186 
187    time_config_update(ci);
188 }
189 
190 static void
_config_digital_datestr_changed(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)191 _config_digital_datestr_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
192 {
193    _config_digital_timestr_update(data, obj, 1);
194 }
195 
196 static Evas_Object *
_config_date_custom(Config_Item * ci,Evas_Object * bx)197 _config_date_custom(Config_Item *ci, Evas_Object *bx)
198 {
199    Evas_Object *o;
200 
201    o = elm_entry_add(bx);
202    elm_entry_single_line_set(o, 1);
203    elm_object_tooltip_text_set(o, _("strftime() format string"));
204    elm_entry_entry_set(o, ci->time_str[1]);
205    evas_object_smart_callback_add(o, "changed,user", _config_digital_datestr_changed, ci);
206    E_FILL(o);
207    E_EXPAND(o);
208    evas_object_show(o);
209    elm_box_pack_end(bx, o);
210    return o;
211 }
212 
213 static void
_config_date_changed(void * data,Evas_Object * obj,void * event_info)214 _config_date_changed(void *data, Evas_Object *obj, void *event_info)
215 {
216    Config_Item *ci = data;
217    Evas_Object *bx = elm_object_parent_widget_get(obj);
218    Eina_Bool custom;
219 
220    custom = ci->show_date == CLOCK_DATE_DISPLAY_CUSTOM;
221    ci->show_date = (intptr_t)elm_object_item_data_get(event_info);
222    if (custom)
223      {
224         elm_box_unpack(bx, obj);
225         elm_box_clear(bx);
226         E_FILL(obj);
227         E_EXPAND(obj);
228         elm_box_pack_end(bx, obj);
229      }
230    else if (ci->show_date == CLOCK_DATE_DISPLAY_CUSTOM)
231      {
232         E_WEIGHT(obj, 0, 0);
233         E_ALIGN(obj, 0, 0.5);
234         elm_object_focus_set(_config_date_custom(ci, bx), 1);
235      }
236    time_config_update(ci);
237 }
238 
239 static void
_config_weekend_changed(void * data,Evas_Object * obj EINA_UNUSED,void * event_info)240 _config_weekend_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
241 {
242    Config_Item *ci = data;
243 
244    ci->weekend.start = (intptr_t)elm_object_item_data_get(event_info);
245    time_config_update(ci);
246 }
247 
248 static void
_config_weekend_end_changed(void * data,Evas_Object * obj EINA_UNUSED,void * event_info)249 _config_weekend_end_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
250 {
251    Config_Item *ci = data;
252    int end;
253 
254    end = (intptr_t)elm_object_item_data_get(event_info);
255    if (end < ci->weekend.start) end += 7;
256    ci->weekend.len = end - ci->weekend.start + 1;
257    time_config_update(ci);
258 }
259 
260 static void
_config_date_populate(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)261 _config_date_populate(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
262 {
263    Config_Item *ci = data;
264    unsigned int i;
265 
266    elm_hoversel_clear(obj);
267    for (i = 0; i <= 5; i++)
268      if (ci->show_date != i)
269        elm_hoversel_item_add(obj, datecfg[i], NULL, ELM_ICON_NONE, NULL, (uintptr_t*)(unsigned long)i);
270 }
271 
272 static void
_config_weekend_populate(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)273 _config_weekend_populate(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
274 {
275    Config_Item *ci = data;
276    char daynames[7][64];
277    struct tm tm;
278    int i;
279 
280    memset(&tm, 0, sizeof(struct tm));
281    for (i = 0; i < 7; i++)
282      {
283         tm.tm_wday = i;
284         strftime(daynames[i], sizeof(daynames[i]), "%A", &tm);
285      }
286 
287    elm_hoversel_clear(obj);
288    for (i = ci->weekend.start + 1; i <= 6; i++)
289      if (ci->weekend.start != i)
290        elm_hoversel_item_add(obj, daynames[i], NULL, ELM_ICON_NONE, NULL, (intptr_t*)(long)i);
291    for (i = 0; i < ci->weekend.start; i++)
292      elm_hoversel_item_add(obj, daynames[i], NULL, ELM_ICON_NONE, NULL, (intptr_t*)(long)i);
293 }
294 
295 static void
_config_weekend_end_populate(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)296 _config_weekend_end_populate(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
297 {
298    Config_Item *ci = data;
299    char daynames[7][64];
300    struct tm tm;
301    int i, end;
302 
303    memset(&tm, 0, sizeof(struct tm));
304    for (i = 0; i < 7; i++)
305      {
306         tm.tm_wday = i;
307         strftime(daynames[i], sizeof(daynames[i]), "%A", &tm);
308      }
309 
310    elm_hoversel_clear(obj);
311    end = (ci->weekend.start + ci->weekend.len - 1) % 7;
312    for (i = end + 1; i <= 6; i++)
313      if (end != i)
314        elm_hoversel_item_add(obj, daynames[i], NULL, ELM_ICON_NONE, NULL, (intptr_t*)(long)i);
315    for (i = 0; i < end; i++)
316      elm_hoversel_item_add(obj, daynames[i], NULL, ELM_ICON_NONE, NULL, (intptr_t*)(long)i);
317 }
318 
319 static void
_config_timezone_setup(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)320 _config_timezone_setup(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
321 {
322    Evas_Object *hover, *gl, *r;
323    Config_Item *ci = data;
324 
325    hover = elm_hover_add(e_comp->elm);
326    evas_object_layer_set(hover, E_LAYER_MENU);
327    elm_hover_parent_set(hover, elm_object_parent_widget_get(obj));
328    elm_hover_target_set(hover, elm_object_parent_widget_get(obj));
329 
330    gl = elm_genlist_add(hover);
331    evas_object_layer_set(gl, E_LAYER_MENU);
332    evas_object_data_set(gl, "config_item", data);
333    evas_object_data_set(gl, "button", obj);
334    elm_genlist_mode_set(gl, ELM_LIST_COMPRESS);
335    elm_genlist_homogeneous_set(gl, 1);
336    elm_scroller_bounce_set(gl, 0, 0);
337    evas_object_show(gl);
338    elm_object_part_content_set(hover, "middle", gl);
339    time_zoneinfo_scan(gl);
340    e_comp_object_util_del_list_append(gl, hover);
341    r = _config_autoclose_rect_add(gl);
342    evas_object_smart_callback_call(ci->inst->o_clock, "gadget_popup", r);
343    e_comp_object_util_del_list_append(gl, r);
344    evas_object_show(hover);
345 }
346 
347 static void
_config_digital_timestr_changed(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)348 _config_digital_timestr_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
349 {
350    _config_digital_timestr_update(data, obj, 0);
351 }
352 
353 static void
_config_label_add(Evas_Object * tb,const char * txt,int row)354 _config_label_add(Evas_Object *tb, const char *txt, int row)
355 {
356    Evas_Object *o;
357 
358    o = elm_label_add(tb);
359    E_ALIGN(o, 0, 0.5);
360    elm_object_text_set(o, txt);
361    evas_object_show(o);
362    elm_table_pack(tb, o, 0, row, 1, 1);
363 }
364 
365 static void
_config_digital_rows_setup(Config_Item * ci,Evas_Object * tb)366 _config_digital_rows_setup(Config_Item *ci, Evas_Object *tb)
367 {
368    int row = 1;
369    Evas_Object *o;
370 
371    evas_object_del(elm_table_child_get(tb, 0, 1));
372    evas_object_del(elm_table_child_get(tb, 1, 1));
373    evas_object_del(elm_table_child_get(tb, 0, 2));
374    evas_object_del(elm_table_child_get(tb, 1, 2));
375    if (ci->advanced)
376      {
377         _config_label_add(tb, _("Time string:"), row);
378         o = elm_entry_add(tb);
379         E_FILL(o);
380         evas_object_show(o);
381         elm_entry_single_line_set(o, 1);
382         elm_entry_entry_set(o, ci->time_str[0]);
383         elm_object_focus_set(o, 1);
384         evas_object_smart_callback_add(o, "changed,user", _config_digital_timestr_changed, ci);
385         elm_table_pack(tb, o, 1, row++, 1, 1);
386 
387         o = elm_separator_add(tb);
388         E_EXPAND(o);
389         E_FILL(o);
390         elm_separator_horizontal_set(o, 1);
391         evas_object_show(o);
392         elm_table_pack(tb, o, 0, row++, 2, 1);
393         return;
394      }
395    if (ci->digital_clock)
396      {
397         _config_label_add(tb, _("24-hour Display:"), row);
398         o = elm_check_add(tb);
399         E_FILL(o);
400         evas_object_show(o);
401         elm_object_style_set(o, "toggle");
402         elm_object_part_text_set(o, "on", "On");
403         elm_object_part_text_set(o, "off", "Off");
404         elm_check_state_pointer_set(o, &ci->digital_24h);
405         evas_object_smart_callback_add(o, "changed", _config_changed, ci);
406         elm_table_pack(tb, o, 1, row++, 1, 1);
407      }
408 
409    _config_label_add(tb, _("Show Seconds:"), row);
410    o = elm_check_add(tb);
411    E_FILL(o);
412    evas_object_show(o);
413    elm_object_style_set(o, "toggle");
414    elm_object_part_text_set(o, "on", _("On"));
415    elm_object_part_text_set(o, "off", _("Off"));
416    elm_check_state_pointer_set(o, &ci->show_seconds);
417    evas_object_smart_callback_add(o, "changed", _config_changed, ci);
418    elm_table_pack(tb, o, 1, row++, 1, 1);
419 }
420 
421 static void
_config_advanced_changed(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)422 _config_advanced_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
423 {
424    Config_Item *ci = data;
425 
426    _config_digital_rows_setup(data, evas_object_data_get(obj, "table"));
427    time_config_update(ci);
428 }
429 
430 EINTERN Evas_Object *
config_clock(Config_Item * ci,E_Zone * zone)431 config_clock(Config_Item *ci, E_Zone *zone)
432 {
433    Evas_Object *popup, *tb, *o, *bx;
434    int i, row = 0;
435    char daynames[7][64];
436    struct tm tm;
437 
438    if (!zone) zone = e_zone_current_get();
439    memset(&tm, 0, sizeof(struct tm));
440    for (i = 0; i < 7; i++)
441      {
442         tm.tm_wday = i;
443         strftime(daynames[i], sizeof(daynames[i]), "%A", &tm);
444      }
445    popup = elm_popup_add(e_comp->elm);
446    E_EXPAND(popup);
447    evas_object_layer_set(popup, E_LAYER_POPUP);
448    elm_popup_allow_events_set(popup, 1);
449    elm_popup_scrollable_set(popup, 1);
450 
451    tb = elm_table_add(popup);
452    E_EXPAND(tb);
453    evas_object_show(tb);
454    elm_object_content_set(popup, tb);
455 
456    if (ci->digital_clock)
457      {
458         _config_label_add(tb, _("Mode"), row);
459         o = elm_check_add(tb);
460         E_FILL(o);
461         evas_object_show(o);
462         elm_object_style_set(o, "toggle");
463         elm_object_part_text_set(o, "on", _("Advanced"));
464         elm_object_part_text_set(o, "off", _("Simple"));
465         elm_check_state_pointer_set(o, &ci->advanced);
466         evas_object_smart_callback_add(o, "changed", _config_advanced_changed, ci);
467         evas_object_data_set(o, "table", tb);
468         elm_table_pack(tb, o, 1, row++, 1, 1);
469      }
470    _config_digital_rows_setup(ci, tb);
471    row = 3;
472 
473    _config_label_add(tb, _("Date Display:"), row);
474    bx = elm_box_add(tb);
475    elm_box_horizontal_set(bx, 1);
476    evas_object_show(bx);
477    elm_table_pack(tb, bx, 1, row++, 1, 1);
478    E_FILL(bx);
479    E_EXPAND(bx);
480    o = elm_hoversel_add(tb);
481    elm_box_pack_end(bx, o);
482    elm_hoversel_hover_parent_set(o, popup);
483    elm_hoversel_auto_update_set(o, 1);
484    evas_object_show(o);
485    evas_object_smart_callback_add(o, "clicked", _config_date_populate, ci);
486    evas_object_smart_callback_add(o, "selected", _config_date_changed, ci);
487    elm_object_text_set(o, datecfg[ci->show_date]);
488    if (ci->show_date == CLOCK_DATE_DISPLAY_CUSTOM)
489      {
490         E_ALIGN(o, 0, 0.5);
491         E_WEIGHT(o, 0, 0);
492         _config_date_custom(ci, bx);
493      }
494    else
495      {
496         E_FILL(o);
497         E_EXPAND(o);
498      }
499 
500    _config_label_add(tb, _("Weekend Start:"), row);
501    o = elm_hoversel_add(tb);
502    E_FILL(o);
503    elm_hoversel_hover_parent_set(o, popup);
504    elm_hoversel_auto_update_set(o, 1);
505    evas_object_show(o);
506    elm_table_pack(tb, o, 1, row++, 1, 1);
507    elm_object_text_set(o, daynames[ci->weekend.start]);
508    evas_object_smart_callback_add(o, "clicked", _config_weekend_populate, ci);
509    evas_object_smart_callback_add(o, "selected", _config_weekend_changed, ci);
510 
511    _config_label_add(tb, _("Weekend End:"), row);
512    o = elm_hoversel_add(tb);
513    E_FILL(o);
514    elm_hoversel_hover_parent_set(o, popup);
515    elm_hoversel_auto_update_set(o, 1);
516    evas_object_show(o);
517    elm_table_pack(tb, o, 1, row++, 1, 1);
518    elm_object_text_set(o, daynames[(ci->weekend.start + ci->weekend.len - 1) % 7]);
519    evas_object_smart_callback_add(o, "clicked", _config_weekend_end_populate, ci);
520    evas_object_smart_callback_add(o, "selected", _config_weekend_end_changed, ci);
521 
522    _config_label_add(tb, _("Timezone:"), row);
523    o = elm_button_add(tb);
524    E_FILL(o);
525    elm_object_text_set(o, ci->timezone ?: _("System"));
526    evas_object_show(o);
527    evas_object_smart_callback_add(o, "clicked", _config_timezone_setup, ci);
528    elm_table_pack(tb, o, 1, row++, 1, 1);
529 
530    for (i = 0; i <= 1; i++)
531      {
532         const char *ccname, *names[] =
533         {
534            N_("Background"),
535            N_("Foreground"),
536         };
537         const char *ccnames[] =
538         {
539            "e.clock_color_bg",
540            "e.clock_color_fg",
541         };
542         Evas_Object *cs;
543         Elm_Object_Item *it;
544         int r, g, b, a;
545 
546         cs = elm_colorselector_add(tb);
547         elm_colorselector_mode_set(cs, ELM_COLORSELECTOR_PALETTE);
548         ccname = ci->colorclass[i];
549         if (!ccname) ccname = ccnames[i];
550         edje_color_class_get(ccname, &r, &g, &b, &a,
551           NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
552 
553         it = elm_colorselector_palette_color_add(cs, r, g, b, a);
554         o = elm_button_add(tb);
555         elm_object_text_set(o, names[i]);
556         elm_object_content_set(o, cs);
557         E_FILL(o);
558         if (!i)
559           evas_object_data_set(o, "bg_color", (void*)1L);
560         evas_object_data_set(o, "colorselector_it", it);
561         evas_object_smart_callback_add(o, "clicked", _config_color_setup, ci);
562         evas_object_show(o);
563         elm_table_pack(tb, o, i, row, 1, 1);
564      }
565 
566    popup = e_comp_object_util_add(popup, E_COMP_OBJECT_TYPE_NONE);
567    evas_object_layer_set(popup, E_LAYER_POPUP);
568    evas_object_move(popup, zone->x, zone->y);
569    evas_object_resize(popup, zone->w / 4, zone->h / 3);
570    e_comp_object_util_center(popup);
571    evas_object_show(popup);
572    e_comp_object_util_autoclose(popup, NULL, e_comp_object_util_autoclose_on_escape, NULL);
573    evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _config_close, NULL);
574 
575    return time_config->config_dialog = popup;
576 }
577 
578 
579 static char *
_config_timezone_text_get(const char * str,Evas_Object * obj EINA_UNUSED,const char * part EINA_UNUSED)580 _config_timezone_text_get(const char *str, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
581 {
582    return strdup(str);
583 }
584 
585 static void
_config_timezone_text_del(void * d,Evas_Object * obj EINA_UNUSED)586 _config_timezone_text_del(void *d, Evas_Object *obj EINA_UNUSED)
587 {
588    free(d);
589 }
590 
591 static int
_config_timezone_sort(void * ita,void * itb)592 _config_timezone_sort(void *ita, void *itb)
593 {
594    const char *a, *b;
595    a = elm_object_item_data_get(ita);
596    b = elm_object_item_data_get(itb);
597    return strcmp(a, b);
598 }
599 
600 static void
_config_timezone_set(void * data EINA_UNUSED,Evas_Object * obj,void * event_info)601 _config_timezone_set(void *data EINA_UNUSED, Evas_Object *obj, void *event_info)
602 {
603    char *tz = elm_object_item_data_get(event_info);
604    Config_Item *ci;
605    Evas_Object *bt;
606 
607    ci = evas_object_data_get(obj, "config_item");
608    bt = evas_object_data_get(obj, "button");
609    eina_stringshare_replace(&ci->timezone, tz);
610    elm_object_text_set(bt, tz);
611    time_config_update(ci);
612    evas_object_del(obj);
613 }
614 
615 EINTERN void
config_timezone_populate(Evas_Object * obj,const char * name)616 config_timezone_populate(Evas_Object *obj, const char *name)
617 {
618    static const Elm_Genlist_Item_Class itc =
619    {
620       .item_style = "default",
621       .func = {
622            .text_get = (Elm_Genlist_Item_Text_Get_Cb)_config_timezone_text_get,
623            .del = _config_timezone_text_del,
624       },
625       .version = ELM_GENLIST_ITEM_CLASS_VERSION
626    };
627    Config_Item *ci;
628    Elm_Object_Item *it;
629 
630    it = elm_genlist_item_sorted_insert(obj, &itc, strdup(name), NULL, 0, (Eina_Compare_Cb)_config_timezone_sort, _config_timezone_set, NULL);
631    ci = evas_object_data_get(obj, "config_item");
632    if (eina_streq(name, ci->timezone))
633      elm_genlist_item_bring_in(it, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
634 }
635