basic clock port

This commit is contained in:
Mike Blumenkrantz 2015-12-23 21:13:28 -05:00
parent 6aa305d098
commit c224b458b5
8 changed files with 310 additions and 344 deletions

View File

@ -1,8 +1,7 @@
#include "e_mod_main.h"
#include "gadget.h"
EINTERN Evas_Object *
start_create(Evas_Object *parent, unsigned int *id EINA_UNUSED, Z_Gadget_Site_Orient orient);
EINTERN void
gadget_demo(void);
@ -274,7 +273,6 @@ e_modapi_init(E_Module *m)
e_action_predef_name_set(D_("Desksanity"), D_("Manage Window Focus For Me"), "ds_key", NULL, NULL, 0);
act->func.go = ds_key;
z_gadget_type_add("Start", start_create);
gadget_demo();
return m;

View File

@ -5,4 +5,8 @@ module_la_SOURCES += \
src/gadgets/core.c \
src/gadgets/demo.c \
src/gadgets/gadget.h \
src/gadgets/start/start.c
src/gadgets/start/start.c \
src/gadgets/clock/clock.c \
src/gadgets/clock/clock.h \
src/gadgets/clock/mod.c \
src/gadgets/clock/time.c

View File

@ -1,58 +1,10 @@
#include "e.h"
#include "clock.h"
/* actual module specifics */
typedef struct _Instance Instance;
struct _Instance
{
E_Gadcon_Client *gcc;
Evas_Object *o_clock, *o_table, *o_popclock, *o_cal;
E_Gadcon_Popup *popup;
int madj;
char year[8];
char month[64];
const char *daynames[7];
unsigned char daynums[7][6];
Eina_Bool dayweekends[7][6];
Eina_Bool dayvalids[7][6];
Eina_Bool daytoday[7][6];
Config_Item *cfg;
};
/* gadcon requirements */
static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
static void _gc_shutdown(E_Gadcon_Client *gcc);
static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
static const char *_gc_label(const E_Gadcon_Client_Class *client_class);
static Evas_Object *_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas);
static const char *_gc_id_new(const E_Gadcon_Client_Class *client_class);
static Config_Item *_conf_item_get(const char *id);
static void _clock_popup_free(Instance *inst);
Config *clock_config = NULL;
static E_Config_DD *conf_edd = NULL;
static E_Config_DD *conf_item_edd = NULL;
static Eina_List *clock_instances = NULL;
static E_Action *act = NULL;
/* and actually define the gadcon class that this module provides (just 1) */
static const E_Gadcon_Client_Class _gadcon_class =
{
GADCON_CLIENT_CLASS_VERSION,
"clock",
{
_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
},
E_GADCON_CLIENT_STYLE_PLAIN
};
EINTERN Config *clock_config = NULL;
EINTERN Eina_List *clock_instances = NULL;
static void
_clock_month_update(Instance *inst)
_clock_calendar_month_update(Instance *inst)
{
Evas_Object *od, *oi;
int x, y;
@ -103,8 +55,8 @@ _clock_month_prev_cb(void *data, Evas_Object *obj EINA_UNUSED, const char *emiss
{
Instance *inst = data;
inst->madj--;
_time_eval(inst);
_clock_month_update(inst);
time_instance_update(inst);
_clock_calendar_month_update(inst);
}
static void
@ -112,15 +64,15 @@ _clock_month_next_cb(void *data, Evas_Object *obj EINA_UNUSED, const char *emiss
{
Instance *inst = data;
inst->madj++;
_time_eval(inst);
_clock_month_update(inst);
time_instance_update(inst);
_clock_calendar_month_update(inst);
}
static void
_clock_settings_cb(void *d1, void *d2 EINA_UNUSED)
{
Instance *inst = d1;
e_int_config_clock_module(NULL, inst->cfg);
//e_int_config_clock_module(NULL, inst->cfg);
e_object_del(E_OBJECT(inst->popup));
inst->popup = NULL;
inst->o_popclock = NULL;
@ -136,20 +88,21 @@ _popclock_del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *info E
}
}
static void
_clock_popup_new(Instance *inst)
EINTERN void
clock_popup_new(Instance *inst)
{
/*
Evas *evas;
Evas_Object *o, *oi;
char todaystr[128];
if (inst->popup) return;
_todaystr_eval(inst, todaystr, sizeof(todaystr) - 1);
time_string_format(inst, todaystr, sizeof(todaystr) - 1);
inst->madj = 0;
_time_eval(inst);
time_instance_update(inst);
inst->popup = e_gadcon_popup_new(inst->gcc, 0);
evas = e_comp->evas;
@ -200,7 +153,7 @@ _clock_popup_new(Instance *inst)
inst->o_cal = oi;
e_theme_edje_object_set(oi, "base/theme/modules/clock",
"e/modules/clock/calendar");
_clock_month_update(inst);
_clock_calendar_month_update(inst);
elm_object_signal_callback_add(oi, "e,action,prev", "*",
_clock_month_prev_cb, inst);
@ -214,78 +167,51 @@ _clock_popup_new(Instance *inst)
evas_smart_objects_calculate(evas);
e_gadcon_popup_content_set(inst->popup, inst->o_table);
e_gadcon_popup_show(inst->popup);
*/
}
static void
_eval_instance_size(Instance *inst)
{
Evas_Coord mw, mh, omw, omh;
Evas_Coord mw, mh;
int sw = 0, sh = 0;
edje_object_size_min_get(inst->o_clock, &mw, &mh);
omw = mw;
omh = mh;
edje_object_size_min_get(elm_layout_edje_get(inst->o_clock), &mw, &mh);
if ((mw < 1) || (mh < 1))
{
Evas_Coord x, y, sw = 0, sh = 0, ow, oh;
Eina_Bool horiz;
const char *orient;
Evas_Coord ow, oh;
Evas_Object *owner;
switch (inst->gcc->gadcon->orient)
owner = z_gadget_site_get(inst->o_clock);
switch (z_gadget_site_orient_get(owner))
{
case E_GADCON_ORIENT_TOP:
case E_GADCON_ORIENT_CORNER_TL:
case E_GADCON_ORIENT_CORNER_TR:
case E_GADCON_ORIENT_BOTTOM:
case E_GADCON_ORIENT_CORNER_BL:
case E_GADCON_ORIENT_CORNER_BR:
case E_GADCON_ORIENT_HORIZ:
horiz = EINA_TRUE;
orient = "e,state,horizontal";
case Z_GADGET_SITE_ORIENT_HORIZONTAL:
evas_object_geometry_get(owner, NULL, NULL, NULL, &sh);
break;
case E_GADCON_ORIENT_LEFT:
case E_GADCON_ORIENT_CORNER_LB:
case E_GADCON_ORIENT_CORNER_LT:
case E_GADCON_ORIENT_RIGHT:
case E_GADCON_ORIENT_CORNER_RB:
case E_GADCON_ORIENT_CORNER_RT:
case E_GADCON_ORIENT_VERT:
horiz = EINA_FALSE;
orient = "e,state,vertical";
case Z_GADGET_SITE_ORIENT_VERTICAL:
evas_object_geometry_get(owner, NULL, NULL, &sw, NULL);
break;
default:
horiz = EINA_TRUE;
orient = "e,state,float";
}
if (inst->gcc->gadcon->shelf)
{
if (horiz)
sh = inst->gcc->gadcon->shelf->h;
else
sw = inst->gcc->gadcon->shelf->w;
default: break;
}
evas_object_geometry_get(inst->o_clock, NULL, NULL, &ow, &oh);
if (orient)
edje_object_signal_emit(inst->o_clock, orient, "e");
evas_object_resize(inst->o_clock, sw, sh);
edje_object_message_signal_process(inst->o_clock);
edje_object_message_signal_process(elm_layout_edje_get(inst->o_clock));
edje_object_parts_extends_calc(inst->o_clock, &x, &y, &mw, &mh);
edje_object_parts_extends_calc(elm_layout_edje_get(inst->o_clock), NULL, NULL, &mw, &mh);
evas_object_resize(inst->o_clock, ow, oh);
}
if (mw < 4) mw = 4;
if (mh < 4) mh = 4;
if (mw < omw) mw = omw;
if (mh < omh) mh = omh;
if (mw < sw) mw = sw;
if (mh < sh) mh = sh;
e_gadcon_client_aspect_set(inst->gcc, mw, mh);
e_gadcon_client_min_size_set(inst->gcc, mw, mh);
evas_object_size_hint_aspect_set(inst->o_clock, EVAS_ASPECT_CONTROL_BOTH, mw, mh);
}
void
@ -300,7 +226,7 @@ e_int_clock_instances_redo(Eina_Bool all)
Evas_Object *o = inst->o_clock;
if ((!all) && (!inst->cfg->changed)) continue;
_todaystr_eval(inst, todaystr, sizeof(todaystr) - 1);
time_string_format(inst, todaystr, sizeof(todaystr) - 1);
if (inst->cfg->digital_clock)
e_theme_edje_object_set(o, "base/theme/modules/clock",
"e/modules/clock/digital");
@ -308,20 +234,20 @@ e_int_clock_instances_redo(Eina_Bool all)
e_theme_edje_object_set(o, "base/theme/modules/clock",
"e/modules/clock/main");
if (inst->cfg->show_date)
edje_object_signal_emit(o, "e,state,date,on", "e");
elm_layout_signal_emit(o, "e,state,date,on", "e");
else
edje_object_signal_emit(o, "e,state,date,off", "e");
elm_layout_signal_emit(o, "e,state,date,off", "e");
if (inst->cfg->digital_24h)
edje_object_signal_emit(o, "e,state,24h,on", "e");
elm_layout_signal_emit(o, "e,state,24h,on", "e");
else
edje_object_signal_emit(o, "e,state,24h,off", "e");
elm_layout_signal_emit(o, "e,state,24h,off", "e");
if (inst->cfg->show_seconds)
edje_object_signal_emit(o, "e,state,seconds,on", "e");
elm_layout_signal_emit(o, "e,state,seconds,on", "e");
else
edje_object_signal_emit(o, "e,state,seconds,off", "e");
elm_layout_signal_emit(o, "e,state,seconds,off", "e");
edje_object_part_text_set(o, "e.text.today", todaystr);
edje_object_message_signal_process(o);
elm_object_part_text_set(o, "e.text.today", todaystr);
edje_object_message_signal_process(elm_layout_edje_get(o));
_eval_instance_size(inst);
if (inst->o_popclock)
@ -354,8 +280,8 @@ e_int_clock_instances_redo(Eina_Bool all)
}
static void
_clock_popup_free(Instance *inst)
EINTERN void
clock_popup_free(Instance *inst)
{
if (!inst->popup) return;
E_FREE_FUNC(inst->popup, e_object_del);
@ -368,7 +294,7 @@ _clock_menu_cb_cfg(void *data, E_Menu *menu EINA_UNUSED, E_Menu_Item *mi EINA_UN
Instance *inst = data;
E_FREE_FUNC(inst->popup, e_object_del);
e_int_config_clock_module(NULL, inst->cfg);
//e_int_config_clock_module(NULL, inst->cfg);
}
static void
@ -379,11 +305,13 @@ _clock_cb_mouse_down(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_U
if (ev->button == 1)
{
if (inst->popup) _clock_popup_free(inst);
else _clock_popup_new(inst);
if (inst->popup) clock_popup_free(inst);
else clock_popup_new(inst);
}
else if (ev->button == 3)
{
#warning FIXME
#if 0
E_Zone *zone;
E_Menu *m;
E_Menu_Item *mi;
@ -405,6 +333,7 @@ _clock_cb_mouse_down(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_U
1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
EVAS_BUTTON_NONE, ev->timestamp, NULL);
#endif
}
}
@ -414,92 +343,15 @@ _clock_sizing_changed_cb(void *data, Evas_Object *obj EINA_UNUSED, const char *e
_eval_instance_size(data);
}
static E_Gadcon_Client *
_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
{
Evas_Object *o;
E_Gadcon_Client *gcc;
Instance *inst;
char todaystr[128];
inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id);
_todaystr_eval(inst, todaystr, sizeof(todaystr) - 1);
o = edje_object_add(gc->evas);
edje_object_signal_callback_add(o, "e,state,sizing,changed", "*",
_clock_sizing_changed_cb, inst);
if (inst->cfg->digital_clock)
e_theme_edje_object_set(o, "base/theme/modules/clock",
"e/modules/clock/digital");
else
e_theme_edje_object_set(o, "base/theme/modules/clock",
"e/modules/clock/main");
if (inst->cfg->show_date)
edje_object_signal_emit(o, "e,state,date,on", "e");
else
edje_object_signal_emit(o, "e,state,date,off", "e");
if (inst->cfg->digital_24h)
edje_object_signal_emit(o, "e,state,24h,on", "e");
else
edje_object_signal_emit(o, "e,state,24h,off", "e");
if (inst->cfg->show_seconds)
edje_object_signal_emit(o, "e,state,seconds,on", "e");
else
edje_object_signal_emit(o, "e,state,seconds,off", "e");
edje_object_part_text_set(o, "e.text.today", todaystr);
edje_object_message_signal_process(o);
evas_object_show(o);
gcc = e_gadcon_client_new(gc, name, id, style, o);
gcc->data = inst;
inst->gcc = gcc;
inst->o_clock = o;
evas_object_event_callback_add(inst->o_clock,
EVAS_CALLBACK_MOUSE_DOWN,
_clock_cb_mouse_down,
inst);
clock_instances = eina_list_append(clock_instances, inst);
return gcc;
}
static void
_gc_shutdown(E_Gadcon_Client *gcc)
clock_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Instance *inst;
Instance *inst = data;
inst = gcc->data;
clock_instances = eina_list_remove(clock_instances, inst);
evas_object_del(inst->o_clock);
_clock_popup_free(inst);
_clear_timestrs(inst);
clock_popup_free(inst);
time_daynames_clear(inst);
free(inst);
if ((!clock_instances) && (update_today))
{
ecore_timer_del(update_today);
update_today = NULL;
}
}
static void
_gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient EINA_UNUSED)
{
_eval_instance_size(gcc->data);
}
static const char *
_gc_label(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
{
return _("Clock");
}
static Evas_Object *
@ -515,24 +367,20 @@ _gc_icon(const E_Gadcon_Client_Class *client_class EINA_UNUSED, Evas *evas)
return o;
}
static const char *
_gc_id_new(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
{
Config_Item *ci = NULL;
ci = _conf_item_get(NULL);
return ci->id;
}
static Config_Item *
_conf_item_get(const char *id)
_conf_item_get(unsigned int *id)
{
Config_Item *ci;
Eina_List *l;
GADCON_CLIENT_CONFIG_GET(Config_Item, clock_config->items, _gadcon_class, id);
if (*id)
{
EINA_LIST_FOREACH(clock_config->items, l, ci)
if (*id == ci->id) return ci;
}
ci = E_NEW(Config_Item, 1);
ci->id = eina_stringshare_add(id);
ci->id = clock_config->items ? eina_list_count(clock_config->items) : 1;
ci->weekend.start = 6;
ci->weekend.len = 2;
ci->week.start = 1;
@ -547,8 +395,76 @@ _conf_item_get(const char *id)
return ci;
}
EINTERN Evas_Object *
clock_create(Evas_Object *parent, unsigned int *id)
static void
_clock_gadget_added_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
_eval_instance_size(data);
evas_object_smart_callback_del_full(obj, "gadget_added", _clock_gadget_added_cb, data);
}
EINTERN Evas_Object *
clock_create(Evas_Object *parent, unsigned int *id, Z_Gadget_Site_Orient orient)
{
Evas_Object *o;
Instance *inst;
char todaystr[128];
const char *sig = NULL;
inst = E_NEW(Instance, 1);
inst->cfg = _conf_item_get(id);
time_string_format(inst, todaystr, sizeof(todaystr) - 1);
o = elm_layout_add(parent);
elm_layout_signal_callback_add(o, "e,state,sizing,changed", "*",
_clock_sizing_changed_cb, inst);
if (inst->cfg->digital_clock)
e_theme_edje_object_set(o, "base/theme/modules/clock",
"e/modules/clock/digital");
else
e_theme_edje_object_set(o, "base/theme/modules/clock",
"e/modules/clock/main");
if (inst->cfg->show_date)
elm_layout_signal_emit(o, "e,state,date,on", "e");
else
elm_layout_signal_emit(o, "e,state,date,off", "e");
if (inst->cfg->digital_24h)
elm_layout_signal_emit(o, "e,state,24h,on", "e");
else
elm_layout_signal_emit(o, "e,state,24h,off", "e");
if (inst->cfg->show_seconds)
elm_layout_signal_emit(o, "e,state,seconds,on", "e");
else
elm_layout_signal_emit(o, "e,state,seconds,off", "e");
elm_object_part_text_set(o, "e.text.today", todaystr);
switch (orient)
{
case Z_GADGET_SITE_ORIENT_HORIZONTAL:
sig = "e,state,horizontal";
break;
case Z_GADGET_SITE_ORIENT_VERTICAL:
sig = "e,state,vertical";
break;
default:
sig = "e,state,float";
}
elm_layout_signal_emit(inst->o_clock, sig, "e");
inst->o_clock = o;
evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, clock_del, inst);
evas_object_smart_callback_add(parent, "gadget_added", _clock_gadget_added_cb, inst);
evas_object_event_callback_add(inst->o_clock,
EVAS_CALLBACK_MOUSE_DOWN,
_clock_cb_mouse_down,
inst);
clock_instances = eina_list_append(clock_instances, inst);
return o;
}

View File

@ -1,5 +1,11 @@
#ifndef E_MOD_MAIN_H
#define E_MOD_MAIN_H
#ifndef CLOCK_H
#define CLOCK_H
#include "e.h"
#include "gadget.h"
#define _(X) (X)
#define N_(X) (X)
E_API extern E_Module_Api e_modapi;
@ -9,6 +15,7 @@ E_API int e_modapi_save (E_Module *m);
typedef struct _Config Config;
typedef struct _Config_Item Config_Item;
typedef struct _Instance Instance;
struct _Config
{
@ -20,7 +27,7 @@ struct _Config
struct _Config_Item
{
const char *id;
unsigned int id;
struct {
int start, len; // 0->6 0 == sun, 6 == sat, number of days
} weekend;
@ -34,9 +41,37 @@ struct _Config_Item
Eina_Bool changed;
};
struct _Instance
{
E_Gadcon_Client *gcc;
Evas_Object *o_clock, *o_table, *o_popclock, *o_cal;
E_Gadcon_Popup *popup;
int madj;
char year[8];
char month[64];
const char *daynames[7];
unsigned char daynums[7][6];
Eina_Bool dayweekends[7][6];
Eina_Bool dayvalids[7][6];
Eina_Bool daytoday[7][6];
Config_Item *cfg;
};
void e_int_config_clock_module(Evas_Object *parent, Config_Item *ci);
void e_int_clock_instances_redo(Eina_Bool all);
EINTERN void time_daynames_clear(Instance *inst);
EINTERN void time_string_format(Instance *inst, char *buf, int bufsz);
EINTERN void time_instance_update(Instance *inst);
EINTERN Evas_Object *clock_create(Evas_Object *parent, unsigned int *id, Z_Gadget_Site_Orient orient);
EINTERN void clock_popup_new(Instance *inst);
EINTERN void clock_popup_free(Instance *inst);
extern Config *clock_config;
extern Eina_List *clock_instances;
#endif

View File

@ -1,6 +1,8 @@
#include "e.h"
#include "clock.h"
static E_Config_DD *conf_edd = NULL;
static E_Config_DD *conf_item_edd = NULL;
static E_Action *act = NULL;
static void
_e_mod_action(const char *params)
@ -8,14 +10,13 @@ _e_mod_action(const char *params)
Eina_List *l;
Instance *inst;
if (!params) return;
if (strcmp(params, "show_calendar")) return;
if (!eina_streq(params, "show_calendar")) return;
EINA_LIST_FOREACH(clock_instances, l, inst)
if (inst->popup)
_clock_popup_free(inst);
clock_popup_free(inst);
else
_clock_popup_new(inst);
clock_popup_new(inst);
}
static void
@ -24,23 +25,15 @@ _e_mod_action_cb(E_Object *obj EINA_UNUSED, const char *params)
_e_mod_action(params);
}
/* module setup */
E_API E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Clock"
};
E_API void *
e_modapi_init(E_Module *m)
EINTERN void
clock_init(void)
{
conf_item_edd = E_CONFIG_DD_NEW("Config_Item", Config_Item);
#undef T
#undef D
#define T Config_Item
#define D conf_item_edd
E_CONFIG_VAL(D, T, id, STR);
E_CONFIG_VAL(D, T, id, UINT);
E_CONFIG_VAL(D, T, weekend.start, INT);
E_CONFIG_VAL(D, T, weekend.len, INT);
E_CONFIG_VAL(D, T, week.start, INT);
@ -72,15 +65,11 @@ e_modapi_init(E_Module *m)
e_action_predef_name_set(N_("Clock"), N_("Toggle calendar"), "clock", "show_calendar", NULL, 0);
}
clock_config->module = m;
z_gadget_type_add("clock", clock_create);
return m;
z_gadget_type_add("Clock", clock_create);
}
E_API int
e_modapi_shutdown(E_Module *m EINA_UNUSED)
EINTERN void
clock_shutdown(void)
{
if (act)
{
@ -109,7 +98,30 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED)
conf_item_edd = NULL;
conf_edd = NULL;
e_gadcon_provider_unregister(&_gadcon_class);
z_gadget_type_del("Clock");
}
#if 0
/* module setup */
E_API E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Clock"
};
E_API void *
e_modapi_init(E_Module *m)
{
clock_init();
clock_config->module = m;
return m;
}
E_API int
e_modapi_shutdown(E_Module *m EINA_UNUSED)
{
return 1;
}
@ -120,3 +132,4 @@ e_modapi_save(E_Module *m EINA_UNUSED)
e_config_domain_save("module.clock", conf_edd, clock_config);
return 1;
}
#endif

View File

@ -1,4 +1,3 @@
#include "e.h"
#include "clock.h"
#include <sys/time.h>
@ -11,23 +10,17 @@ static Eina_List *clock_eio_handlers = NULL;
static Ecore_Timer *update_today = NULL;
static void
_clear_timestrs(Instance *inst)
EINTERN void
time_daynames_clear(Instance *inst)
{
int x;
for (x = 0; x < 7; x++)
{
if (inst->daynames[x])
{
eina_stringshare_del(inst->daynames[x]);
inst->daynames[x] = NULL;
}
}
eina_stringshare_replace(&inst->daynames[x], NULL);
}
static void
_todaystr_eval(Instance *inst, char *buf, int bufsz)
EINTERN void
time_string_format(Instance *inst, char *buf, int bufsz)
{
if (!inst->cfg->show_date)
{
@ -60,96 +53,30 @@ _todaystr_eval(Instance *inst, char *buf, int bufsz)
}
static void
_time_eval(Instance *inst)
EINTERN void
time_instance_update(Instance *inst)
{
struct timeval timev;
struct tm *tm, tms, tmm, tm2;
time_t tt;
int started = 0, num, i;
int day;
tzset();
gettimeofday(&timev, NULL);
tt = (time_t)(timev.tv_sec);
tm = localtime(&tt);
_clear_timestrs(inst);
if (tm)
time_daynames_clear(inst);
if (!tm) return;
// tms == current date time "saved"
// tm2 == date to look at adjusting for madj
// tm2 == month baseline @ 1st
memcpy(&tms, tm, sizeof(struct tm));
num = 0;
for (day = (0 - 6); day < (31 + 16); day++)
{
int day;
// tms == current date time "saved"
// tm2 == date to look at adjusting for madj
// tm2 == month baseline @ 1st
memcpy(&tms, tm, sizeof(struct tm));
num = 0;
for (day = (0 - 6); day < (31 + 16); day++)
{
memcpy(&tmm, &tms, sizeof(struct tm));
tmm.tm_sec = 0;
tmm.tm_min = 0;
tmm.tm_hour = 10;
tmm.tm_mon += inst->madj;
tmm.tm_mday = 1; // start at the 1st of the month
tmm.tm_wday = 0; // ignored by mktime
tmm.tm_yday = 0; // ignored by mktime
tmm.tm_isdst = 0; // ignored by mktime
tt = mktime(&tmm);
tm = localtime(&tt);
memcpy(&tm2, tm, sizeof(struct tm));
tt = mktime(&tmm);
tt += (day * 60 * 60 * 24);
tm = localtime(&tt);
memcpy(&tmm, tm, sizeof(struct tm));
if (!started)
{
if (tm->tm_wday == inst->cfg->week.start)
{
char buf[32];
for (i = 0; i < 7; i++, tm->tm_wday = (tm->tm_wday + 1) % 7)
{
strftime(buf, sizeof(buf), "%a", tm);
inst->daynames[i] = eina_stringshare_add(buf);
}
started = 1;
}
}
if (started)
{
int y = num / 7;
int x = num % 7;
if (y < 6)
{
inst->daynums[x][y] = tmm.tm_mday;
inst->dayvalids[x][y] = 0;
if (tmm.tm_mon == tm2.tm_mon) inst->dayvalids[x][y] = 1;
inst->daytoday[x][y] = 0;
if ((tmm.tm_mon == tms.tm_mon) &&
(tmm.tm_year == tms.tm_year) &&
(tmm.tm_mday == tms.tm_mday))
inst->daytoday[x][y] = 1;
inst->dayweekends[x][y] = 0;
for (i = inst->cfg->weekend.start;
i < (inst->cfg->weekend.start + inst->cfg->weekend.len);
i++)
{
if (tmm.tm_wday == (i % 7))
{
inst->dayweekends[x][y] = 1;
break;
}
}
}
num++;
}
}
memcpy(&tmm, &tms, sizeof(struct tm));
tmm.tm_sec = 0;
tmm.tm_min = 0;
@ -162,11 +89,75 @@ _time_eval(Instance *inst)
tt = mktime(&tmm);
tm = localtime(&tt);
memcpy(&tm2, tm, sizeof(struct tm));
inst->year[sizeof(inst->year) - 1] = 0;
strftime(inst->year, sizeof(inst->year) - 1, "%Y", (const struct tm *)&tm2);
inst->month[sizeof(inst->month) - 1] = 0;
strftime(inst->month, sizeof(inst->month) - 1, "%B", (const struct tm *)&tm2); // %b for short month
tt = mktime(&tmm);
tt += (day * 60 * 60 * 24);
tm = localtime(&tt);
memcpy(&tmm, tm, sizeof(struct tm));
if (!started)
{
if (tm->tm_wday == inst->cfg->week.start)
{
char buf[32];
for (i = 0; i < 7; i++, tm->tm_wday = (tm->tm_wday + 1) % 7)
{
strftime(buf, sizeof(buf), "%a", tm);
inst->daynames[i] = eina_stringshare_add(buf);
}
started = 1;
}
}
if (started)
{
int y = num / 7;
int x = num % 7;
if (y < 6)
{
inst->daynums[x][y] = tmm.tm_mday;
inst->dayvalids[x][y] = 0;
if (tmm.tm_mon == tm2.tm_mon) inst->dayvalids[x][y] = 1;
inst->daytoday[x][y] = 0;
if ((tmm.tm_mon == tms.tm_mon) &&
(tmm.tm_year == tms.tm_year) &&
(tmm.tm_mday == tms.tm_mday))
inst->daytoday[x][y] = 1;
inst->dayweekends[x][y] = 0;
for (i = inst->cfg->weekend.start;
i < (inst->cfg->weekend.start + inst->cfg->weekend.len);
i++)
{
if (tmm.tm_wday == (i % 7))
{
inst->dayweekends[x][y] = 1;
break;
}
}
}
num++;
}
}
memcpy(&tmm, &tms, sizeof(struct tm));
tmm.tm_sec = 0;
tmm.tm_min = 0;
tmm.tm_hour = 10;
tmm.tm_mon += inst->madj;
tmm.tm_mday = 1; // start at the 1st of the month
tmm.tm_wday = 0; // ignored by mktime
tmm.tm_yday = 0; // ignored by mktime
tmm.tm_isdst = 0; // ignored by mktime
tt = mktime(&tmm);
tm = localtime(&tt);
memcpy(&tm2, tm, sizeof(struct tm));
inst->year[sizeof(inst->year) - 1] = 0;
strftime(inst->year, sizeof(inst->year) - 1, "%Y", (const struct tm *)&tm2);
inst->month[sizeof(inst->month) - 1] = 0;
strftime(inst->month, sizeof(inst->month) - 1, "%B", (const struct tm *)&tm2); // %b for short month
}

View File

@ -1,5 +1,9 @@
#include "gadget.h"
EINTERN Evas_Object *start_create(Evas_Object *parent, unsigned int *id EINA_UNUSED, Z_Gadget_Site_Orient orient);;
EINTERN void clock_init(void);
EINTERN void clock_shutdown(void);
static Evas_Object *shelf;
static Evas_Object *site;
@ -12,11 +16,14 @@ gadget_demo(void)
if (!eina_streq(getenv("USER"), "zmike")) return;
if (e_comp->w > 1200) return;
z_gadget_type_add("Start", start_create);
clock_init();
ly = elm_layout_add(e_comp->elm);
e_theme_edje_object_set(ly, NULL, "e/shelf/default/base");
site = z_gadget_site_add(ly, Z_GADGET_SITE_ORIENT_VERTICAL);
z_gadget_site_anchor(site, Z_GADGET_SITE_ANCHOR_LEFT);
elm_object_part_content_set(ly, "e.swallow.content", site);
elm_layout_signal_emit(ly, "e,state,orientation,left", "e");
evas_object_geometry_set(ly, 0, 0, 48, e_comp->h);
@ -29,4 +36,5 @@ gadget_demo(void)
evas_object_clip_set(shelf, e_comp_zone_xy_get(0, 0)->bg_clip_object);
z_gadget_site_gadget_add(site, "Start");
z_gadget_site_gadget_add(site, "Clock");
}

View File

@ -21,7 +21,7 @@ struct _Instance
};
static void
do_orient(Instance *inst, Z_Gadget_Site_Orient orient, Z_Gadget_Site_Anchor anchor, Z_Gadget_Site_Gravity gravity EINA_UNUSED)
do_orient(Instance *inst, Z_Gadget_Site_Orient orient, Z_Gadget_Site_Anchor anchor)
{
char buf[4096];
const char *s = "float";
@ -182,7 +182,7 @@ _anchor_change(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
Instance *inst = data;
do_orient(inst, z_gadget_site_orient_get(obj), z_gadget_site_anchor_get(obj), z_gadget_site_gravity_get(obj));
do_orient(inst, z_gadget_site_orient_get(obj), z_gadget_site_anchor_get(obj));
}
EINTERN Evas_Object *
@ -200,12 +200,13 @@ start_create(Evas_Object *parent, unsigned int *id EINA_UNUSED, Z_Gadget_Site_Or
elm_layout_signal_emit(o, "e,state,unfocused", "e");
inst->o_button = o;
evas_object_size_hint_aspect_set(o, EVAS_ASPECT_CONTROL_BOTH, 1, 1);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
_button_cb_mouse_down, inst);
evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, start_del, inst);
evas_object_smart_callback_add(parent, "gadget_anchor", _anchor_change, inst);
do_orient(inst, orient, z_gadget_site_anchor_get(parent), z_gadget_site_gravity_get(parent));
do_orient(inst, orient, z_gadget_site_anchor_get(parent));
return o;
}