2 #include "e_mod_main.h"
7 /* gadcon requirements */
8 static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
9 static void _gc_shutdown(E_Gadcon_Client *gcc);
10 static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
11 static char *_gc_label(E_Gadcon_Client_Class *client_class);
12 static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas);
13 static const char *_gc_id_new(E_Gadcon_Client_Class *client_class);
15 /* and actually define the gadcon class that this module provides (just 1) */
16 static const E_Gadcon_Client_Class _gadcon_class =
18 GADCON_CLIENT_CLASS_VERSION,
21 _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
23 E_GADCON_CLIENT_STYLE_PLAIN
26 /* actual module specifics */
27 typedef struct _Instance Instance;
32 Evas_Object *o_clock, *o_table, *o_popclock, *o_cal;
33 E_Gadcon_Popup *popup;
40 const char *daynames[7];
41 unsigned char daynums[7][6];
42 Eina_Bool dayweekends[7][6];
43 Eina_Bool dayvalids[7][6];
44 Eina_Bool daytoday[7][6];
47 E_Module *clock_module = NULL;
48 E_Config_Dialog *clock_config = NULL;
49 Config *clock_cfg = NULL;
51 static E_Config_DD *clock_cfg_edd = NULL;
52 static Eina_List *clock_instances = NULL;
53 static E_Action *act = NULL;
56 _clear_timestrs(Instance *inst)
60 for (x = 0; x < 7; x++)
62 if (inst->daynames[x])
64 eina_stringshare_del(inst->daynames[x]);
65 inst->daynames[x] = NULL;
71 _time_eval(Instance *inst)
74 struct tm *tm, tms, tmm, tm2;
76 int started = 0, num, i;
79 gettimeofday(&timev, NULL);
80 tt = (time_t)(timev.tv_sec);
83 _clear_timestrs(inst);
88 // tms == current date time "saved"
89 // tm2 == date to look at adjusting for madj
90 // tm2 == month baseline @ 1st
91 memcpy(&tms, tm, sizeof(struct tm));
93 for (day = (0 - 6); day < (31 + 16); day++)
95 memcpy(&tmm, &tms, sizeof(struct tm));
99 tmm.tm_mon += inst->madj;
100 tmm.tm_mday = 1; // start at the 1st of the month
101 tmm.tm_wday = 0; // ignored by mktime
102 tmm.tm_yday = 0; // ignored by mktime
103 tmm.tm_isdst = 0; // ignored by mktime
106 memcpy(&tm2, tm, sizeof(struct tm));
109 tt += (day * 60 * 60 * 24);
111 memcpy(&tmm, tm, sizeof(struct tm));
114 if (tm->tm_wday == clock_cfg->week.start) started = 1;
123 inst->daynums[x][y] = tmm.tm_mday;
125 inst->dayvalids[x][y] = 0;
126 if (tmm.tm_mon == tm2.tm_mon) inst->dayvalids[x][y] = 1;
128 inst->daytoday[x][y] = 0;
129 if ((tmm.tm_mon == tms.tm_mon) &&
130 (tmm.tm_year == tms.tm_year) &&
131 (tmm.tm_mday == tms.tm_mday))
132 inst->daytoday[x][y] = 1;
134 inst->dayweekends[x][y] = 0;
135 for (i = clock_cfg->weekend.start;
136 i < (clock_cfg->weekend.start + clock_cfg->weekend.len);
139 if (tmm.tm_wday == (i % 7))
141 inst->dayweekends[x][y] = 1;
145 if (!inst->daynames[x])
149 buf[sizeof(buf) - 1] = 0;
150 strftime(buf, sizeof(buf) - 1, "%a", (const struct tm *)&tmm); // %A full weekeday
151 inst->daynames[x] = eina_stringshare_add(buf);
158 memcpy(&tmm, &tms, sizeof(struct tm));
162 tmm.tm_mon += inst->madj;
163 tmm.tm_mday = 1; // start at the 1st of the month
164 tmm.tm_wday = 0; // ignored by mktime
165 tmm.tm_yday = 0; // ignored by mktime
166 tmm.tm_isdst = 0; // ignored by mktime
169 memcpy(&tm2, tm, sizeof(struct tm));
170 inst->year[sizeof(inst->year) - 1] = 0;
171 strftime(inst->year, sizeof(inst->year) - 1, "%Y", (const struct tm *)&tm2);
172 inst->month[sizeof(inst->month) - 1] = 0;
173 strftime(inst->month, sizeof(inst->month) - 1, "%B", (const struct tm *)&tm2); // %b for short month
178 _clock_month_update(Instance *inst)
180 Evas_Object *od, *oi;
184 edje_object_part_text_set(oi, "e.text.month", inst->month);
185 edje_object_part_text_set(oi, "e.text.year", inst->year);
186 for (x = 0; x < 7; x++)
188 od = edje_object_part_table_child_get(oi, "e.table.daynames", x, 0);
189 edje_object_part_text_set(od, "e.text.label", inst->daynames[x]);
192 for (y = 0; y < 6; y++)
194 for (x = 0; x < 7; x++)
198 od = edje_object_part_table_child_get(oi, "e.table.days", x, y);
199 snprintf(buf, sizeof(buf), "%i", (int)inst->daynums[x][y]);
200 edje_object_part_text_set(od, "e.text.label", buf);
201 if (inst->dayweekends[x][y])
202 edje_object_signal_emit(od, "e,state,weekend", "e");
204 edje_object_signal_emit(od, "e,state,weekday", "e");
205 if (inst->dayvalids[x][y])
206 edje_object_signal_emit(od, "e,state,visible", "e");
208 edje_object_signal_emit(od, "e,state,hidden", "e");
209 if (inst->daytoday[x][y])
210 edje_object_signal_emit(od, "e,state,today", "e");
212 edje_object_signal_emit(od, "e,state,someday", "e");
218 _clock_month_prev_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
220 Instance *inst = data;
223 _clock_month_update(inst);
227 _clock_month_next_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
229 Instance *inst = data;
232 _clock_month_update(inst);
236 _clock_settings_cb(void *d1, void *d2 __UNUSED__)
239 e_int_config_clock_module(inst->popup->win->zone->container, NULL);
240 e_object_del(E_OBJECT(inst->popup));
245 _clock_popup_new(Instance *inst)
249 Evas_Coord mw = 128, mh = 128;
251 if (inst->popup) return;
257 inst->popup = e_gadcon_popup_new(inst->gcc);
258 evas = inst->popup->win->evas;
260 inst->o_table = e_widget_table_add(evas, 0);
262 oi = edje_object_add(evas);
263 inst->o_popclock = oi;
264 if (clock_cfg->digital_clock)
265 e_theme_edje_object_set(oi, "base/theme/modules/clock",
266 "e/modules/clock/digital");
268 e_theme_edje_object_set(oi, "base/theme/modules/clock",
269 "e/modules/clock/main");
270 if (clock_cfg->digital_24h)
271 edje_object_signal_emit(oi, "e,state,24h,on", "e");
273 edje_object_signal_emit(oi, "e,state,24h,off", "e");
274 if (clock_cfg->show_seconds)
275 edje_object_signal_emit(oi, "e,state,seconds,on", "e");
277 edje_object_signal_emit(oi, "e,state,seconds,off", "e");
278 o = e_widget_image_add_from_object(evas, oi, 128, 128);
279 evas_object_show(oi);
280 e_widget_table_object_align_append(inst->o_table, o,
281 0, 0, 1, 1, 0, 0, 0, 0, 0.5, 0.5);
283 o = e_widget_button_add(evas, _("Settings"), "preferences-system",
284 _clock_settings_cb, inst, NULL);
285 e_widget_table_object_align_append(inst->o_table, o,
286 0, 1, 1, 1, 0, 0, 0, 0, 0.5, 1.0);
288 oi = edje_object_add(evas);
290 e_theme_edje_object_set(oi, "base/theme/modules/clock",
291 "e/modules/clock/calendar");
292 _clock_month_update(inst);
294 edje_object_signal_callback_add(oi, "e,action,prev", "*",
295 _clock_month_prev_cb, inst);
296 edje_object_signal_callback_add(oi, "e,action,next", "*",
297 _clock_month_next_cb, inst);
298 evas_object_resize(oi, 500, 500);
299 edje_object_size_min_restricted_calc(oi, &mw, &mh, 128, 128);
301 o = e_widget_image_add_from_object(evas, oi, mw, mh);
302 evas_object_show(oi);
303 e_widget_table_object_align_append(inst->o_table, o,
304 1, 0, 1, 2, 0, 0, 0, 0, 0.5, 0.5);
306 e_gadcon_popup_content_set(inst->popup, inst->o_table);
307 e_gadcon_popup_show(inst->popup);
311 e_int_clock_instances_redo(void)
316 EINA_LIST_FOREACH(clock_instances, l, inst)
318 Evas_Object *o = inst->o_clock;
321 if (clock_cfg->digital_clock)
322 e_theme_edje_object_set(o, "base/theme/modules/clock",
323 "e/modules/clock/digital");
325 e_theme_edje_object_set(o, "base/theme/modules/clock",
326 "e/modules/clock/main");
327 if (clock_cfg->digital_24h)
328 edje_object_signal_emit(o, "e,state,24h,on", "e");
330 edje_object_signal_emit(o, "e,state,24h,off", "e");
331 if (clock_cfg->show_seconds)
332 edje_object_signal_emit(o, "e,state,seconds,on", "e");
334 edje_object_signal_emit(o, "e,state,seconds,off", "e");
335 edje_object_message_signal_process(o);
337 edje_object_size_min_get(o, &mw, &mh);
338 if ((mw < 1) || (mh < 1))
339 edje_object_size_min_calc(o, &mw, &mh);
342 e_gadcon_client_aspect_set(inst->gcc, mw, mh);
343 e_gadcon_client_min_size_set(inst->gcc, mw, mh);
348 _clock_popup_free(Instance *inst)
350 if (!inst->popup) return;
351 if (inst->popup) e_object_del(E_OBJECT(inst->popup));
356 _clock_menu_cb_post(void *data, E_Menu *menu __UNUSED__)
358 Instance *inst = data;
359 if ((!inst) || (!inst->menu))
363 e_object_del(E_OBJECT(inst->menu));
369 _clock_menu_cb_cfg(void *data, E_Menu *menu __UNUSED__, E_Menu_Item *mi __UNUSED__)
371 Instance *inst = data;
376 e_object_del(E_OBJECT(inst->popup));
379 con = e_container_current_get(e_manager_current_get());
380 e_int_config_clock_module(con, NULL);
384 _clock_cb_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
386 Instance *inst = data;
387 Evas_Event_Mouse_Down *ev = event;
391 if (inst->popup) _clock_popup_free(inst);
392 else _clock_popup_new(inst);
394 else if ((ev->button == 3) && (!inst->menu))
401 zone = e_util_zone_current_get(e_manager_current_get());
405 mi = e_menu_item_new(m);
406 e_menu_item_label_set(mi, _("Settings"));
407 e_util_menu_item_theme_icon_set(mi, "configure");
408 e_menu_item_callback_set(mi, _clock_menu_cb_cfg, inst);
410 m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
411 e_menu_post_deactivate_callback_set(m, _clock_menu_cb_post, inst);
414 e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL);
415 e_menu_activate_mouse(m, zone, x + ev->output.x, y + ev->output.y,
416 1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
417 evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
418 EVAS_BUTTON_NONE, ev->timestamp, NULL);
422 _clock_sizing_changed_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
424 Instance *inst = data;
428 edje_object_size_min_get(inst->o_clock, &mw, &mh);
429 if ((mw < 1) || (mh < 1))
430 edje_object_size_min_calc(inst->o_clock, &mw, &mh);
433 e_gadcon_client_aspect_set(inst->gcc, mw, mh);
434 e_gadcon_client_min_size_set(inst->gcc, mw, mh);
437 static E_Gadcon_Client *
438 _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
441 E_Gadcon_Client *gcc;
444 inst = E_NEW(Instance, 1);
446 o = edje_object_add(gc->evas);
447 edje_object_signal_callback_add(o, "e,state,sizing,changed", "*",
448 _clock_sizing_changed_cb, inst);
449 if (clock_cfg->digital_clock)
450 e_theme_edje_object_set(o, "base/theme/modules/clock",
451 "e/modules/clock/digital");
453 e_theme_edje_object_set(o, "base/theme/modules/clock",
454 "e/modules/clock/main");
455 if (clock_cfg->digital_24h)
456 edje_object_signal_emit(o, "e,state,24h,on", "e");
458 edje_object_signal_emit(o, "e,state,24h,off", "e");
459 if (clock_cfg->show_seconds)
460 edje_object_signal_emit(o, "e,state,seconds,on", "e");
462 edje_object_signal_emit(o, "e,state,seconds,off", "e");
465 gcc = e_gadcon_client_new(gc, name, id, style, o);
471 evas_object_event_callback_add(inst->o_clock,
472 EVAS_CALLBACK_MOUSE_DOWN,
473 _clock_cb_mouse_down,
476 e_gadcon_client_util_menu_attach(gcc);
478 clock_instances = eina_list_append(clock_instances, inst);
483 _gc_shutdown(E_Gadcon_Client *gcc)
490 e_object_del(E_OBJECT(inst->menu));
493 clock_instances = eina_list_remove(clock_instances, inst);
494 evas_object_del(inst->o_clock);
495 _clock_popup_free(inst);
496 _clear_timestrs(inst);
501 _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__)
508 edje_object_size_min_get(inst->o_clock, &mw, &mh);
509 if ((mw < 1) || (mh < 1))
510 edje_object_size_min_calc(inst->o_clock, &mw, &mh);
513 e_gadcon_client_aspect_set(gcc, mw, mh);
514 e_gadcon_client_min_size_set(gcc, mw, mh);
518 _gc_label(E_Gadcon_Client_Class *client_class __UNUSED__)
524 _gc_icon(E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas)
529 o = edje_object_add(evas);
530 snprintf(buf, sizeof(buf), "%s/e-module-clock.edj",
531 e_module_dir_get(clock_module));
532 edje_object_file_set(o, buf, "icon");
537 _gc_id_new(E_Gadcon_Client_Class *client_class __UNUSED__)
539 return _gadcon_class.name;
543 _e_mod_action(const char *params)
548 if (!params) return ;
549 if (strcmp(params, "show_calendar")) return ;
551 EINA_LIST_FOREACH(clock_instances, l, inst)
553 _clock_popup_free(inst);
555 _clock_popup_new(inst);
559 _e_mod_action_cb_edge(E_Object *obj,
561 E_Event_Zone_Edge *ev)
563 _e_mod_action(params);
567 _e_mod_action_cb(E_Object *obj, const char *params)
569 _e_mod_action(params);
573 _e_mod_action_cb_key(E_Object *obj,
577 _e_mod_action(params);
581 _e_mod_action_cb_mouse(E_Object *obj,
583 Ecore_Event_Mouse_Button *ev)
585 _e_mod_action(params);
589 EAPI E_Module_Api e_modapi =
591 E_MODULE_API_VERSION,
596 e_modapi_init(E_Module *m)
598 clock_cfg_edd = E_CONFIG_DD_NEW("Config", Config);
602 #define D clock_cfg_edd
603 E_CONFIG_VAL(D, T, weekend.start, INT);
604 E_CONFIG_VAL(D, T, weekend.len, INT);
605 E_CONFIG_VAL(D, T, week.start, INT);
606 E_CONFIG_VAL(D, T, digital_clock, INT);
607 E_CONFIG_VAL(D, T, digital_24h, INT);
608 E_CONFIG_VAL(D, T, show_seconds, INT);
610 clock_cfg = e_config_domain_load("module.clock", clock_cfg_edd);
613 clock_cfg = E_NEW(Config, 1);
614 clock_cfg->weekend.start = 6;
615 clock_cfg->weekend.len = 2;
616 clock_cfg->week.start = 1;
617 clock_cfg->digital_clock = 0;
618 clock_cfg->digital_24h = 0;
619 clock_cfg->show_seconds = 1;
620 e_config_save_queue();
623 act = e_action_add("clock");
626 act->func.go = _e_mod_action_cb;
627 act->func.go_key = _e_mod_action_cb_key;
628 act->func.go_mouse = _e_mod_action_cb_mouse;
629 act->func.go_edge = _e_mod_action_cb_edge;
631 e_action_predef_name_set(_("Clock"), _("Show calendar"), "clock", "show_calendar", NULL, 0);
635 e_gadcon_provider_register(&_gadcon_class);
640 e_modapi_shutdown(E_Module *m __UNUSED__)
644 e_object_del(E_OBJECT(clock_config));
652 E_CONFIG_DD_FREE(clock_cfg_edd);
653 clock_cfg_edd = NULL;
655 e_gadcon_provider_unregister(&_gadcon_class);
660 e_modapi_save(E_Module *m __UNUSED__)
662 e_config_domain_save("module.clock", clock_cfg_edd, clock_cfg);