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 const 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);
14 static Config_Item *_conf_item_get(const char *id);
17 /* and actually define the gadcon class that this module provides (just 1) */
18 static const E_Gadcon_Client_Class _gadcon_class =
20 GADCON_CLIENT_CLASS_VERSION,
23 _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
25 E_GADCON_CLIENT_STYLE_PLAIN
28 /* actual module specifics */
29 typedef struct _Instance Instance;
34 Evas_Object *o_clock, *o_table, *o_popclock, *o_cal;
35 E_Gadcon_Popup *popup;
42 const char *daynames[7];
43 unsigned char daynums[7][6];
44 Eina_Bool dayweekends[7][6];
45 Eina_Bool dayvalids[7][6];
46 Eina_Bool daytoday[7][6];
50 Config *clock_config = NULL;
52 static E_Config_DD *conf_edd = NULL;
53 static E_Config_DD *conf_item_edd = NULL;
54 static Eina_List *clock_instances = NULL;
55 static E_Action *act = NULL;
56 static Ecore_Timer *update_today = NULL;
59 _clear_timestrs(Instance *inst)
63 for (x = 0; x < 7; x++)
65 if (inst->daynames[x])
67 eina_stringshare_del(inst->daynames[x]);
68 inst->daynames[x] = NULL;
74 _time_eval(Instance *inst)
77 struct tm *tm, tms, tmm, tm2;
79 int started = 0, num, i;
82 gettimeofday(&timev, NULL);
83 tt = (time_t)(timev.tv_sec);
86 _clear_timestrs(inst);
91 // tms == current date time "saved"
92 // tm2 == date to look at adjusting for madj
93 // tm2 == month baseline @ 1st
94 memcpy(&tms, tm, sizeof(struct tm));
96 for (day = (0 - 6); day < (31 + 16); day++)
98 memcpy(&tmm, &tms, sizeof(struct tm));
102 tmm.tm_mon += inst->madj;
103 tmm.tm_mday = 1; // start at the 1st of the month
104 tmm.tm_wday = 0; // ignored by mktime
105 tmm.tm_yday = 0; // ignored by mktime
106 tmm.tm_isdst = 0; // ignored by mktime
109 memcpy(&tm2, tm, sizeof(struct tm));
112 tt += (day * 60 * 60 * 24);
114 memcpy(&tmm, tm, sizeof(struct tm));
117 if (tm->tm_wday == inst->cfg->week.start) started = 1;
126 inst->daynums[x][y] = tmm.tm_mday;
128 inst->dayvalids[x][y] = 0;
129 if (tmm.tm_mon == tm2.tm_mon) inst->dayvalids[x][y] = 1;
131 inst->daytoday[x][y] = 0;
132 if ((tmm.tm_mon == tms.tm_mon) &&
133 (tmm.tm_year == tms.tm_year) &&
134 (tmm.tm_mday == tms.tm_mday))
135 inst->daytoday[x][y] = 1;
137 inst->dayweekends[x][y] = 0;
138 for (i = inst->cfg->weekend.start;
139 i < (inst->cfg->weekend.start + inst->cfg->weekend.len);
142 if (tmm.tm_wday == (i % 7))
144 inst->dayweekends[x][y] = 1;
148 if (!inst->daynames[x])
152 buf[sizeof(buf) - 1] = 0;
153 strftime(buf, sizeof(buf) - 1, "%a", (const struct tm *)&tmm); // %A full weekeday
154 inst->daynames[x] = eina_stringshare_add(buf);
161 memcpy(&tmm, &tms, sizeof(struct tm));
165 tmm.tm_mon += inst->madj;
166 tmm.tm_mday = 1; // start at the 1st of the month
167 tmm.tm_wday = 0; // ignored by mktime
168 tmm.tm_yday = 0; // ignored by mktime
169 tmm.tm_isdst = 0; // ignored by mktime
172 memcpy(&tm2, tm, sizeof(struct tm));
173 inst->year[sizeof(inst->year) - 1] = 0;
174 strftime(inst->year, sizeof(inst->year) - 1, "%Y", (const struct tm *)&tm2);
175 inst->month[sizeof(inst->month) - 1] = 0;
176 strftime(inst->month, sizeof(inst->month) - 1, "%B", (const struct tm *)&tm2); // %b for short month
181 _clock_month_update(Instance *inst)
183 Evas_Object *od, *oi;
187 edje_object_part_text_set(oi, "e.text.month", inst->month);
188 edje_object_part_text_set(oi, "e.text.year", inst->year);
189 for (x = 0; x < 7; x++)
191 od = edje_object_part_table_child_get(oi, "e.table.daynames", x, 0);
192 edje_object_part_text_set(od, "e.text.label", inst->daynames[x]);
195 for (y = 0; y < 6; y++)
197 for (x = 0; x < 7; x++)
201 od = edje_object_part_table_child_get(oi, "e.table.days", x, y);
202 snprintf(buf, sizeof(buf), "%i", (int)inst->daynums[x][y]);
203 edje_object_part_text_set(od, "e.text.label", buf);
204 if (inst->dayweekends[x][y])
205 edje_object_signal_emit(od, "e,state,weekend", "e");
207 edje_object_signal_emit(od, "e,state,weekday", "e");
208 if (inst->dayvalids[x][y])
209 edje_object_signal_emit(od, "e,state,visible", "e");
211 edje_object_signal_emit(od, "e,state,hidden", "e");
212 if (inst->daytoday[x][y])
213 edje_object_signal_emit(od, "e,state,today", "e");
215 edje_object_signal_emit(od, "e,state,someday", "e");
221 _clock_month_prev_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
223 Instance *inst = data;
226 _clock_month_update(inst);
230 _clock_month_next_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
232 Instance *inst = data;
235 _clock_month_update(inst);
239 _clock_settings_cb(void *d1, void *d2 __UNUSED__)
242 e_int_config_clock_module(inst->popup->win->zone->container, inst->cfg);
243 e_object_del(E_OBJECT(inst->popup));
248 _clock_popup_new(Instance *inst)
252 Evas_Coord mw = 128, mh = 128;
259 strftime(todaystr, sizeof(todaystr) - 1, "%a, %x", tm);
261 if (inst->popup) return;
267 inst->popup = e_gadcon_popup_new(inst->gcc);
268 evas = inst->popup->win->evas;
270 inst->o_table = e_widget_table_add(evas, 0);
272 oi = edje_object_add(evas);
273 inst->o_popclock = oi;
274 if (inst->cfg->digital_clock)
275 e_theme_edje_object_set(oi, "base/theme/modules/clock",
276 "e/modules/clock/digital");
278 e_theme_edje_object_set(oi, "base/theme/modules/clock",
279 "e/modules/clock/main");
280 if (inst->cfg->digital_24h)
281 edje_object_signal_emit(oi, "e,state,24h,on", "e");
283 edje_object_signal_emit(oi, "e,state,24h,off", "e");
284 if (inst->cfg->show_seconds)
285 edje_object_signal_emit(oi, "e,state,seconds,on", "e");
287 edje_object_signal_emit(oi, "e,state,seconds,off", "e");
289 edje_object_part_text_set(oi, "e.text.today", todaystr);
291 o = e_widget_image_add_from_object(evas, oi, 128, 128);
292 evas_object_show(oi);
293 e_widget_table_object_align_append(inst->o_table, o,
294 0, 0, 1, 1, 0, 0, 0, 0, 0.5, 0.5);
296 o = e_widget_button_add(evas, _("Settings"), "preferences-system",
297 _clock_settings_cb, inst, NULL);
298 e_widget_table_object_align_append(inst->o_table, o,
299 0, 1, 1, 1, 0, 0, 0, 0, 0.5, 1.0);
301 oi = edje_object_add(evas);
303 e_theme_edje_object_set(oi, "base/theme/modules/clock",
304 "e/modules/clock/calendar");
305 _clock_month_update(inst);
307 edje_object_signal_callback_add(oi, "e,action,prev", "*",
308 _clock_month_prev_cb, inst);
309 edje_object_signal_callback_add(oi, "e,action,next", "*",
310 _clock_month_next_cb, inst);
311 evas_object_resize(oi, 500, 500);
312 edje_object_size_min_restricted_calc(oi, &mw, &mh, 128, 128);
314 o = e_widget_image_add_from_object(evas, oi, mw, mh);
315 evas_object_show(oi);
316 e_widget_table_object_align_append(inst->o_table, o,
317 1, 0, 1, 2, 0, 0, 0, 0, 0.5, 0.5);
319 e_gadcon_popup_content_set(inst->popup, inst->o_table);
320 e_gadcon_popup_show(inst->popup);
324 _eval_instance_size(Instance *inst)
326 Evas_Coord mw, mh, omw, omh;
328 edje_object_size_min_get(inst->o_clock, &mw, &mh);
332 if ((mw < 1) || (mh < 1))
334 Evas_Coord x, y, sw = 0, sh = 0, ow, oh;
338 switch (inst->gcc->gadcon->orient)
340 case E_GADCON_ORIENT_TOP:
341 case E_GADCON_ORIENT_CORNER_TL:
342 case E_GADCON_ORIENT_CORNER_TR:
343 case E_GADCON_ORIENT_BOTTOM:
344 case E_GADCON_ORIENT_CORNER_BL:
345 case E_GADCON_ORIENT_CORNER_BR:
346 case E_GADCON_ORIENT_HORIZ:
348 orient = "e,state,horizontal";
351 case E_GADCON_ORIENT_LEFT:
352 case E_GADCON_ORIENT_CORNER_LB:
353 case E_GADCON_ORIENT_CORNER_LT:
354 case E_GADCON_ORIENT_RIGHT:
355 case E_GADCON_ORIENT_CORNER_RB:
356 case E_GADCON_ORIENT_CORNER_RT:
357 case E_GADCON_ORIENT_VERT:
359 orient = "e,state,vertical";
364 orient = "e,state,float";
367 if (inst->gcc->gadcon->shelf)
370 sh = inst->gcc->gadcon->shelf->h;
372 sw = inst->gcc->gadcon->shelf->w;
375 evas_object_geometry_get(inst->o_clock, NULL, NULL, &ow, &oh);
377 edje_object_signal_emit(inst->o_clock, orient, "e");
378 evas_object_resize(inst->o_clock, sw, sh);
379 edje_object_message_signal_process(inst->o_clock);
381 edje_object_parts_extends_calc(inst->o_clock, &x, &y, &mw, &mh);
382 evas_object_resize(inst->o_clock, ow, oh);
388 if (mw < omw) mw = omw;
389 if (mh < omh) mh = omh;
391 e_gadcon_client_aspect_set(inst->gcc, mw, mh);
392 e_gadcon_client_min_size_set(inst->gcc, mw, mh);
396 e_int_clock_instances_redo(void)
406 strftime(todaystr, sizeof(todaystr) - 1, "%a, %x", tm);
408 EINA_LIST_FOREACH(clock_instances, l, inst)
410 Evas_Object *o = inst->o_clock;
412 if (inst->cfg->digital_clock)
413 e_theme_edje_object_set(o, "base/theme/modules/clock",
414 "e/modules/clock/digital");
416 e_theme_edje_object_set(o, "base/theme/modules/clock",
417 "e/modules/clock/main");
418 if (inst->cfg->digital_24h)
419 edje_object_signal_emit(o, "e,state,24h,on", "e");
421 edje_object_signal_emit(o, "e,state,24h,off", "e");
422 if (inst->cfg->show_seconds)
423 edje_object_signal_emit(o, "e,state,seconds,on", "e");
425 edje_object_signal_emit(o, "e,state,seconds,off", "e");
427 edje_object_part_text_set(o, "e.text.today", todaystr);
428 _eval_instance_size(inst);
430 if (inst->o_popclock)
432 o = inst->o_popclock;
434 if (inst->cfg->digital_clock)
435 e_theme_edje_object_set(o, "base/theme/modules/clock",
436 "e/modules/clock/digital");
438 e_theme_edje_object_set(o, "base/theme/modules/clock",
439 "e/modules/clock/main");
440 if (inst->cfg->digital_24h)
441 edje_object_signal_emit(o, "e,state,24h,on", "e");
443 edje_object_signal_emit(o, "e,state,24h,off", "e");
444 if (inst->cfg->show_seconds)
445 edje_object_signal_emit(o, "e,state,seconds,on", "e");
447 edje_object_signal_emit(o, "e,state,seconds,off", "e");
449 edje_object_part_text_set(o, "e.text.today", todaystr);
455 _update_today_timer(void *data __UNUSED__)
457 time_t t, t_tomorrow;
458 const struct tm *now;
461 e_int_clock_instances_redo();
462 if (!clock_instances)
470 memcpy(&today, now, sizeof(today));
475 t_tomorrow = mktime(&today) + 24 * 60 * 60;
476 update_today = ecore_timer_add(t_tomorrow - t, _update_today_timer, NULL);
481 _clock_popup_free(Instance *inst)
483 if (!inst->popup) return;
484 if (inst->popup) e_object_del(E_OBJECT(inst->popup));
486 inst->o_popclock = NULL;
490 _clock_menu_cb_post(void *data, E_Menu *menu __UNUSED__)
492 Instance *inst = data;
493 if ((!inst) || (!inst->menu))
497 e_object_del(E_OBJECT(inst->menu));
503 _clock_menu_cb_cfg(void *data, E_Menu *menu __UNUSED__, E_Menu_Item *mi __UNUSED__)
505 Instance *inst = data;
510 e_object_del(E_OBJECT(inst->popup));
513 con = e_container_current_get(e_manager_current_get());
514 e_int_config_clock_module(con, inst->cfg);
518 _clock_cb_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
520 Instance *inst = data;
521 Evas_Event_Mouse_Down *ev = event;
525 if (inst->popup) _clock_popup_free(inst);
526 else _clock_popup_new(inst);
528 else if ((ev->button == 3) && (!inst->menu))
535 zone = e_util_zone_current_get(e_manager_current_get());
539 mi = e_menu_item_new(m);
540 e_menu_item_label_set(mi, _("Settings"));
541 e_util_menu_item_theme_icon_set(mi, "configure");
542 e_menu_item_callback_set(mi, _clock_menu_cb_cfg, inst);
544 m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
545 e_menu_post_deactivate_callback_set(m, _clock_menu_cb_post, inst);
548 e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL);
549 e_menu_activate_mouse(m, zone, x + ev->output.x, y + ev->output.y,
550 1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
551 evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
552 EVAS_BUTTON_NONE, ev->timestamp, NULL);
557 _clock_sizing_changed_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
559 _eval_instance_size(data);
562 static E_Gadcon_Client *
563 _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
566 E_Gadcon_Client *gcc;
574 strftime(todaystr, sizeof(todaystr) - 1, "%a, %x", tm);
576 inst = E_NEW(Instance, 1);
577 inst->cfg = _conf_item_get(id);
579 o = edje_object_add(gc->evas);
580 edje_object_signal_callback_add(o, "e,state,sizing,changed", "*",
581 _clock_sizing_changed_cb, inst);
582 if (inst->cfg->digital_clock)
583 e_theme_edje_object_set(o, "base/theme/modules/clock",
584 "e/modules/clock/digital");
586 e_theme_edje_object_set(o, "base/theme/modules/clock",
587 "e/modules/clock/main");
588 if (inst->cfg->digital_24h)
589 edje_object_signal_emit(o, "e,state,24h,on", "e");
591 edje_object_signal_emit(o, "e,state,24h,off", "e");
592 if (inst->cfg->show_seconds)
593 edje_object_signal_emit(o, "e,state,seconds,on", "e");
595 edje_object_signal_emit(o, "e,state,seconds,off", "e");
597 edje_object_part_text_set(o, "e.text.today", todaystr);
600 gcc = e_gadcon_client_new(gc, name, id, style, o);
606 evas_object_event_callback_add(inst->o_clock,
607 EVAS_CALLBACK_MOUSE_DOWN,
608 _clock_cb_mouse_down,
611 clock_instances = eina_list_append(clock_instances, inst);
613 if (!update_today) _update_today_timer(NULL);
619 _gc_shutdown(E_Gadcon_Client *gcc)
626 e_menu_post_deactivate_callback_set(inst->menu, NULL, NULL);
627 e_object_del(E_OBJECT(inst->menu));
630 clock_instances = eina_list_remove(clock_instances, inst);
631 evas_object_del(inst->o_clock);
632 _clock_popup_free(inst);
633 _clear_timestrs(inst);
636 if ((!clock_instances) && (update_today))
638 ecore_timer_del(update_today);
644 _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__)
646 _eval_instance_size(gcc->data);
650 _gc_label(E_Gadcon_Client_Class *client_class __UNUSED__)
656 _gc_icon(E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas)
661 o = edje_object_add(evas);
662 snprintf(buf, sizeof(buf), "%s/e-module-clock.edj",
663 e_module_dir_get(clock_config->module));
664 edje_object_file_set(o, buf, "icon");
670 _gc_id_new(E_Gadcon_Client_Class *client_class __UNUSED__)
672 Config_Item *ci = NULL;
674 ci = _conf_item_get(NULL);
679 _conf_item_get(const char *id)
683 GADCON_CLIENT_CONFIG_GET(Config_Item, clock_config->items, _gadcon_class, id);
685 ci = E_NEW(Config_Item, 1);
686 ci->id = eina_stringshare_add(id);
687 ci->weekend.start = 6;
690 ci->digital_clock = 0;
692 ci->show_seconds = 1;
694 clock_config->items = eina_list_append(clock_config->items, ci);
695 e_config_save_queue();
701 _e_mod_action(const char *params)
706 if (!params) return ;
707 if (strcmp(params, "show_calendar")) return ;
709 EINA_LIST_FOREACH(clock_instances, l, inst)
711 _clock_popup_free(inst);
713 _clock_popup_new(inst);
717 _e_mod_action_cb_edge(E_Object *obj __UNUSED__, const char *params, E_Event_Zone_Edge *ev __UNUSED__)
719 _e_mod_action(params);
723 _e_mod_action_cb(E_Object *obj __UNUSED__, const char *params)
725 _e_mod_action(params);
729 _e_mod_action_cb_key(E_Object *obj __UNUSED__, const char *params, Ecore_Event_Key *ev __UNUSED__)
731 _e_mod_action(params);
735 _e_mod_action_cb_mouse(E_Object *obj __UNUSED__, const char *params, Ecore_Event_Mouse_Button *ev __UNUSED__)
737 _e_mod_action(params);
741 EAPI E_Module_Api e_modapi =
743 E_MODULE_API_VERSION,
748 e_modapi_init(E_Module *m)
750 conf_item_edd = E_CONFIG_DD_NEW("Config_Item", Config_Item);
753 #define T Config_Item
754 #define D conf_item_edd
755 E_CONFIG_VAL(D, T, id, STR);
756 E_CONFIG_VAL(D, T, weekend.start, INT);
757 E_CONFIG_VAL(D, T, weekend.len, INT);
758 E_CONFIG_VAL(D, T, week.start, INT);
759 E_CONFIG_VAL(D, T, digital_clock, INT);
760 E_CONFIG_VAL(D, T, digital_24h, INT);
761 E_CONFIG_VAL(D, T, show_seconds, INT);
763 conf_edd = E_CONFIG_DD_NEW("Config", Config);
768 E_CONFIG_LIST(D, T, items, conf_item_edd);
770 clock_config = e_config_domain_load("module.clock", conf_edd);
773 clock_config = E_NEW(Config, 1);
775 act = e_action_add("clock");
778 act->func.go = _e_mod_action_cb;
779 act->func.go_key = _e_mod_action_cb_key;
780 act->func.go_mouse = _e_mod_action_cb_mouse;
781 act->func.go_edge = _e_mod_action_cb_edge;
783 e_action_predef_name_set(_("Clock"), _("Show calendar"), "clock", "show_calendar", NULL, 0);
786 clock_config->module = m;
788 e_gadcon_provider_register(&_gadcon_class);
793 e_modapi_shutdown(E_Module *m __UNUSED__)
797 e_action_predef_name_del(_("Clock"), _("Show calendar"));
798 e_action_del("clock");
805 if (clock_config->config_dialog)
806 e_object_del(E_OBJECT(clock_config->config_dialog));
808 EINA_LIST_FREE(clock_config->items, ci)
810 eina_stringshare_del(ci->id);
817 E_CONFIG_DD_FREE(conf_edd);
818 E_CONFIG_DD_FREE(conf_item_edd);
819 conf_item_edd = NULL;
822 e_gadcon_provider_unregister(&_gadcon_class);
826 ecore_timer_del(update_today);
834 e_modapi_save(E_Module *m __UNUSED__)
836 e_config_domain_save("module.clock", conf_edd, clock_config);