2004-12-27 00:33:52 -08:00
|
|
|
#include "e.h"
|
|
|
|
#include "e_mod_main.h"
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
/* gadcon requirements */
|
2006-05-31 09:19:11 -07:00
|
|
|
static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
|
2006-04-20 04:30:25 -07:00
|
|
|
static void _gc_shutdown(E_Gadcon_Client *gcc);
|
2008-11-03 19:57:45 -08:00
|
|
|
static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
|
|
|
|
static char *_gc_label(E_Gadcon_Client_Class *client_class);
|
|
|
|
static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas);
|
|
|
|
static const char *_gc_id_new(E_Gadcon_Client_Class *client_class);
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2010-06-19 10:53:49 -07:00
|
|
|
Eina_List *device_batteries;
|
|
|
|
Eina_List *device_ac_adapters;
|
|
|
|
double init_time;
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
/* and actually define the gadcon class that this module provides (just 1) */
|
|
|
|
static const E_Gadcon_Client_Class _gadcon_class =
|
2004-12-27 00:33:52 -08:00
|
|
|
{
|
2006-04-20 04:30:25 -07:00
|
|
|
GADCON_CLIENT_CLASS_VERSION,
|
|
|
|
"battery",
|
2006-01-06 13:30:53 -08:00
|
|
|
{
|
List of changes:
1. Gadcon sities:
-- 'E_Gadcon_Site' enum to list all available sities,
-- added 'is_site' callback for distinguish gadcon sities,
-- 'e_gadcon_site_is_*' helpers written to use in gadget modules,
-- gadcon config dialogs modified to show only gadgets that appropriate
to selected gadcon site,
-- all gadget modules updated for using new callback.
When callback is not provided in module, then gadget can be used in
any gadcon site.
2. Filemanager:
-- added error icon to unexisting path dialog,
-- added callback 'func.abort' to 'E_Fm2_Op_Registry_Entry' to specify
abort operation sequence (if not provided, then operation is not
cancelable),
-- added parameter to 'e_fm2_op_registry_entry_add' to specify abort
method on construct 'E_Fm2_Op_Registry_Entry' or make non-cancelable
operation if this function is not provided,
-- added 'e_fm2_operation_abort' call to cancel efm2 operation,
-- added method '_e_fm2_operation_abort_internal' that represent efm2
default handler of operation cancelling,
-- 'done' and 'total' fields of 'E_Fm2_Op_Registry_Entry' changed to
off_t type, also all message handlers modified to work with it
(to show progress for large files correctly),
-- improved file operation progress processing,
-- added cancel button to operation progress gadget in filemanager window,
-- added delete file glyph to operation progress gadget,
-- improved status message for efm2 operation progress.
3. Filemanager slave:
-- fixed critical bug in message handling via stdin/stdout,
-- fixed critical bug in removing task from list,
-- improved 'E_FM_OP_ABORT' handling,
-- fix rollback counting on moving files.
4. Fileman_opinfo module:
-- a new theme writed: status string and gadget for view operation status
in summary and detail modes,
-- summary mode: operation glyph, state message, progressbar, abort button,
-- detail mode: all for summary + from filename, to filename,
-- summary/detailed button works as trigger,
-- added source of module theme and used images.
4. Pathbar module:
-- non-critical fix, just for safety.
Also patch contains several minor updates to serve main task.
SVN revision: 41224
2009-06-29 07:38:03 -07:00
|
|
|
_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
|
2006-08-08 23:38:35 -07:00
|
|
|
},
|
|
|
|
E_GADCON_CLIENT_STYLE_PLAIN
|
2006-04-20 04:30:25 -07:00
|
|
|
};
|
2005-02-09 04:14:08 -08:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
/* actual module specifics */
|
|
|
|
typedef struct _Instance Instance;
|
2004-12-27 00:33:52 -08:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
struct _Instance
|
2004-12-27 00:33:52 -08:00
|
|
|
{
|
2006-04-20 04:30:25 -07:00
|
|
|
E_Gadcon_Client *gcc;
|
|
|
|
Evas_Object *o_battery;
|
2008-05-03 12:51:49 -07:00
|
|
|
Evas_Object *popup_battery;
|
|
|
|
E_Gadcon_Popup *warning;
|
2006-04-20 04:30:25 -07:00
|
|
|
};
|
2005-02-10 04:00:39 -08:00
|
|
|
|
2010-04-30 18:13:38 -07:00
|
|
|
static void _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery, Eina_Bool have_power);
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool _battery_cb_exe_data(void *data, int type, void *event);
|
|
|
|
static Eina_Bool _battery_cb_exe_del(void *data, int type, void *event);
|
2006-04-20 04:30:25 -07:00
|
|
|
static void _button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
|
|
|
static void _menu_cb_post(void *data, E_Menu *m);
|
2008-05-03 12:51:49 -07:00
|
|
|
static void _battery_face_level_set(Evas_Object *battery, double level);
|
|
|
|
static void _battery_face_time_set(Evas_Object *battery, int time);
|
2006-04-20 04:30:25 -07:00
|
|
|
static void _battery_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi);
|
2004-12-27 00:33:52 -08:00
|
|
|
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool _battery_cb_warning_popup_timeout(void *data);
|
2008-05-03 12:51:49 -07:00
|
|
|
static void _battery_cb_warning_popup_hide(void *data, Evas *e, Evas_Object *obj, void *event);
|
2008-05-03 14:49:37 -07:00
|
|
|
static void _battery_warning_popup_destroy(Instance *inst);
|
2008-05-03 12:51:49 -07:00
|
|
|
static void _battery_warning_popup(Instance *inst, int time, double percent);
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
static E_Config_DD *conf_edd = NULL;
|
2004-12-27 00:33:52 -08:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
Config *battery_config = NULL;
|
2004-12-27 00:33:52 -08:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
static E_Gadcon_Client *
|
2006-05-31 09:19:11 -07:00
|
|
|
_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
|
2004-12-27 00:33:52 -08:00
|
|
|
{
|
|
|
|
Evas_Object *o;
|
2006-04-20 04:30:25 -07:00
|
|
|
E_Gadcon_Client *gcc;
|
|
|
|
Instance *inst;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2008-03-09 10:31:12 -07:00
|
|
|
battery_config->full = -2;
|
|
|
|
battery_config->time_left = -2;
|
2010-04-30 18:13:38 -07:00
|
|
|
battery_config->time_full = -2;
|
2008-03-09 10:31:12 -07:00
|
|
|
battery_config->have_battery = -2;
|
|
|
|
battery_config->have_power = -2;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
inst = E_NEW(Instance, 1);
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
o = edje_object_add(gc->evas);
|
2005-04-22 22:16:25 -07:00
|
|
|
e_theme_edje_object_set(o, "base/theme/modules/battery",
|
2006-08-22 21:02:03 -07:00
|
|
|
"e/modules/battery/main");
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-12-30 15:32:25 -08:00
|
|
|
gcc = e_gadcon_client_new(gc, name, id, style, o);
|
2006-04-20 04:30:25 -07:00
|
|
|
gcc->data = inst;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
inst->gcc = gcc;
|
|
|
|
inst->o_battery = o;
|
2008-05-03 12:51:49 -07:00
|
|
|
inst->warning = NULL;
|
|
|
|
inst->popup_battery = NULL;
|
|
|
|
|
2010-05-22 00:04:26 -07:00
|
|
|
#ifdef HAVE_EEZE
|
|
|
|
eeze_init();
|
2010-04-30 18:13:38 -07:00
|
|
|
#else
|
2010-05-16 22:14:50 -07:00
|
|
|
e_dbus_init();
|
2010-04-30 18:13:38 -07:00
|
|
|
e_hal_init();
|
|
|
|
#endif
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
|
|
|
|
_button_cb_mouse_down, inst);
|
2008-05-03 13:12:57 -07:00
|
|
|
battery_config->instances =
|
2008-10-22 04:49:33 -07:00
|
|
|
eina_list_append(battery_config->instances, inst);
|
2008-03-04 02:35:30 -08:00
|
|
|
_battery_config_updated();
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
return gcc;
|
2005-02-10 04:00:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-04-20 04:30:25 -07:00
|
|
|
_gc_shutdown(E_Gadcon_Client *gcc)
|
2005-02-10 04:00:39 -08:00
|
|
|
{
|
2006-04-20 04:30:25 -07:00
|
|
|
Instance *inst;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2010-05-22 00:04:26 -07:00
|
|
|
#ifdef HAVE_EEZE
|
|
|
|
eeze_shutdown();
|
2010-04-30 18:13:38 -07:00
|
|
|
#else
|
|
|
|
e_hal_shutdown();
|
2010-05-16 22:14:50 -07:00
|
|
|
e_dbus_shutdown();
|
2010-04-30 18:13:38 -07:00
|
|
|
#endif
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
inst = gcc->data;
|
2008-05-03 13:12:57 -07:00
|
|
|
battery_config->instances =
|
2008-10-22 04:49:33 -07:00
|
|
|
eina_list_remove(battery_config->instances, inst);
|
2006-04-20 04:30:25 -07:00
|
|
|
evas_object_del(inst->o_battery);
|
2008-05-03 15:18:35 -07:00
|
|
|
if (inst->warning)
|
2008-05-03 12:51:49 -07:00
|
|
|
{
|
|
|
|
e_object_del(E_OBJECT(inst->warning));
|
|
|
|
inst->popup_battery = NULL;
|
|
|
|
}
|
2008-05-03 13:12:57 -07:00
|
|
|
E_FREE(inst);
|
2005-02-10 04:00:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-02 13:42:59 -08:00
|
|
|
_gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__)
|
2005-02-10 04:00:39 -08:00
|
|
|
{
|
2006-04-20 04:30:25 -07:00
|
|
|
Instance *inst;
|
2008-06-30 01:48:29 -07:00
|
|
|
Evas_Coord mw, mh, mxw, mxh;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
inst = gcc->data;
|
2008-03-04 22:00:25 -08:00
|
|
|
mw = 0, mh = 0;
|
|
|
|
edje_object_size_min_get(inst->o_battery, &mw, &mh);
|
2008-06-30 01:48:29 -07:00
|
|
|
edje_object_size_max_get(inst->o_battery, &mxw, &mxh);
|
2008-03-04 22:00:25 -08:00
|
|
|
if ((mw < 1) || (mh < 1))
|
|
|
|
edje_object_size_min_calc(inst->o_battery, &mw, &mh);
|
|
|
|
if (mw < 4) mw = 4;
|
|
|
|
if (mh < 4) mh = 4;
|
2008-06-30 01:48:29 -07:00
|
|
|
if ((mxw > 0) && (mxh > 0))
|
|
|
|
e_gadcon_client_aspect_set(gcc, mxw, mxh);
|
2008-03-04 22:00:25 -08:00
|
|
|
e_gadcon_client_min_size_set(gcc, mw, mh);
|
2004-12-27 00:33:52 -08:00
|
|
|
}
|
2006-05-09 06:02:48 -07:00
|
|
|
|
|
|
|
static char *
|
2010-03-02 13:42:59 -08:00
|
|
|
_gc_label(E_Gadcon_Client_Class *client_class __UNUSED__)
|
2006-05-09 06:02:48 -07:00
|
|
|
{
|
|
|
|
return _("Battery");
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
2010-03-02 13:42:59 -08:00
|
|
|
_gc_icon(E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas)
|
2006-05-09 06:02:48 -07:00
|
|
|
{
|
|
|
|
Evas_Object *o;
|
|
|
|
char buf[4096];
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-05-09 06:02:48 -07:00
|
|
|
o = edje_object_add(evas);
|
2007-03-24 16:12:23 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/e-module-battery.edj",
|
2006-05-09 06:02:48 -07:00
|
|
|
e_module_dir_get(battery_config->module));
|
|
|
|
edje_object_file_set(o, buf, "icon");
|
|
|
|
return o;
|
|
|
|
}
|
2007-09-15 17:02:53 -07:00
|
|
|
|
|
|
|
static const char *
|
2010-03-02 13:42:59 -08:00
|
|
|
_gc_id_new(E_Gadcon_Client_Class *client_class __UNUSED__)
|
2007-09-15 17:02:53 -07:00
|
|
|
{
|
|
|
|
return _gadcon_class.name;
|
|
|
|
}
|
|
|
|
|
2004-12-27 00:33:52 -08:00
|
|
|
static void
|
2006-04-20 04:30:25 -07:00
|
|
|
_button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
2004-12-27 00:33:52 -08:00
|
|
|
{
|
2006-04-20 04:30:25 -07:00
|
|
|
Instance *inst;
|
|
|
|
Evas_Event_Mouse_Down *ev;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
inst = data;
|
|
|
|
ev = event_info;
|
|
|
|
if ((ev->button == 3) && (!battery_config->menu))
|
2005-01-25 06:24:38 -08:00
|
|
|
{
|
2010-09-09 07:44:21 -07:00
|
|
|
E_Menu *ma, *mg;
|
2006-04-20 04:30:25 -07:00
|
|
|
E_Menu_Item *mi;
|
2008-11-07 21:48:47 -08:00
|
|
|
int cx, cy;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2010-09-09 07:44:21 -07:00
|
|
|
ma = e_menu_new();
|
|
|
|
e_menu_post_deactivate_callback_set(ma, _menu_cb_post, inst);
|
|
|
|
battery_config->menu = ma;
|
2006-04-20 04:30:25 -07:00
|
|
|
|
2010-09-09 07:44:21 -07:00
|
|
|
mg = e_menu_new();
|
|
|
|
|
|
|
|
mi = e_menu_item_new(mg);
|
2008-11-22 00:42:54 -08:00
|
|
|
e_menu_item_label_set(mi, _("Settings"));
|
2009-03-08 16:09:48 -07:00
|
|
|
e_util_menu_item_theme_icon_set(mi, "configure");
|
2006-04-20 04:30:25 -07:00
|
|
|
e_menu_item_callback_set(mi, _battery_face_cb_menu_configure, NULL);
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2010-09-09 07:44:21 -07:00
|
|
|
e_gadcon_client_util_menu_items_append(inst->gcc, ma, mg, 0);
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon,
|
2008-11-07 21:48:47 -08:00
|
|
|
&cx, &cy, NULL, NULL);
|
2010-09-09 08:20:23 -07:00
|
|
|
e_menu_activate_mouse(ma,
|
2006-04-20 04:30:25 -07:00
|
|
|
e_util_zone_current_get(e_manager_current_get()),
|
|
|
|
cx + ev->output.x, cy + ev->output.y, 1, 1,
|
|
|
|
E_MENU_POP_DIRECTION_DOWN, ev->timestamp);
|
2005-01-25 06:24:38 -08:00
|
|
|
}
|
2008-05-03 13:12:57 -07:00
|
|
|
if (ev->button == 1)
|
|
|
|
_battery_cb_warning_popup_hide(data, e, obj, event_info);
|
2004-12-27 00:33:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-02 13:42:59 -08:00
|
|
|
_menu_cb_post(void *data __UNUSED__, E_Menu *m __UNUSED__)
|
2004-12-27 00:33:52 -08:00
|
|
|
{
|
2006-04-20 04:30:25 -07:00
|
|
|
if (!battery_config->menu) return;
|
|
|
|
e_object_del(E_OBJECT(battery_config->menu));
|
|
|
|
battery_config->menu = NULL;
|
2004-12-27 00:33:52 -08:00
|
|
|
}
|
2004-12-27 02:49:46 -08:00
|
|
|
|
|
|
|
static void
|
2008-05-03 12:51:49 -07:00
|
|
|
_battery_face_level_set(Evas_Object *battery, double level)
|
2004-12-27 02:49:46 -08:00
|
|
|
{
|
|
|
|
Edje_Message_Float msg;
|
2008-05-03 12:51:49 -07:00
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%i%%", (int)(level*100.0));
|
|
|
|
edje_object_part_text_set(battery, "e.text.reading", buf);
|
2005-02-09 04:14:08 -08:00
|
|
|
|
2004-12-27 02:49:46 -08:00
|
|
|
if (level < 0.0) level = 0.0;
|
|
|
|
else if (level > 1.0) level = 1.0;
|
|
|
|
msg.val = level;
|
2008-05-03 12:51:49 -07:00
|
|
|
edje_object_message_send(battery, EDJE_MESSAGE_FLOAT, 1, &msg);
|
|
|
|
}
|
|
|
|
|
2008-06-13 23:18:30 -07:00
|
|
|
static void
|
2010-04-30 18:13:38 -07:00
|
|
|
_battery_face_time_set(Evas_Object *battery, int time)
|
2008-05-03 12:51:49 -07:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
int hrs, mins;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2010-04-30 18:13:38 -07:00
|
|
|
if (time < 0) return;
|
|
|
|
|
|
|
|
hrs = (time / 3600);
|
|
|
|
mins = ((time) / 60 - (hrs * 60));
|
2008-05-03 12:51:49 -07:00
|
|
|
if (hrs < 0) hrs = 0;
|
|
|
|
if (mins < 0) mins = 0;
|
2010-01-15 11:36:00 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%i:%02i", hrs, mins);
|
2008-05-03 12:51:49 -07:00
|
|
|
edje_object_part_text_set(battery, "e.text.time", buf);
|
2005-02-10 04:51:16 -08:00
|
|
|
}
|
2005-10-25 03:51:58 -07:00
|
|
|
|
2010-03-02 13:42:59 -08:00
|
|
|
static void
|
|
|
|
_battery_face_cb_menu_configure(void *data __UNUSED__, E_Menu *m, E_Menu_Item *mi __UNUSED__)
|
2005-12-14 14:46:51 -08:00
|
|
|
{
|
2006-04-20 04:30:25 -07:00
|
|
|
if (!battery_config) return;
|
|
|
|
if (battery_config->config_dialog) return;
|
2007-10-31 05:44:40 -07:00
|
|
|
e_int_config_battery_module(m->zone->container, NULL);
|
2006-04-20 04:30:25 -07:00
|
|
|
}
|
|
|
|
|
2010-04-30 18:13:38 -07:00
|
|
|
|
2010-05-17 00:17:59 -07:00
|
|
|
Battery *
|
|
|
|
_battery_battery_find(const char *udi)
|
2010-04-30 18:13:38 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
2010-05-17 00:17:59 -07:00
|
|
|
Battery *bat;
|
2010-05-16 22:14:50 -07:00
|
|
|
EINA_LIST_FOREACH(device_batteries, l, bat)
|
2010-05-18 03:39:30 -07:00
|
|
|
{/* these are always stringshared */
|
|
|
|
if (udi == bat->udi) return bat;
|
2010-04-30 18:13:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2008-11-14 19:42:19 -08:00
|
|
|
}
|
|
|
|
|
2010-05-17 00:17:59 -07:00
|
|
|
Ac_Adapter *
|
|
|
|
_battery_ac_adapter_find(const char *udi)
|
2010-04-30 18:13:38 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
2010-05-16 22:14:50 -07:00
|
|
|
Ac_Adapter *ac;
|
|
|
|
EINA_LIST_FOREACH(device_ac_adapters, l, ac)
|
2010-05-18 03:39:30 -07:00
|
|
|
{/* these are always stringshared */
|
|
|
|
if (udi == ac->udi) return ac;
|
2010-04-30 18:13:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2008-11-14 19:42:19 -08:00
|
|
|
}
|
|
|
|
|
2010-05-17 00:17:59 -07:00
|
|
|
void
|
|
|
|
_battery_device_update(void)
|
2010-05-16 22:14:50 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
2010-05-18 03:39:30 -07:00
|
|
|
Battery *bat;
|
|
|
|
Ac_Adapter *ac;
|
2010-05-16 22:14:50 -07:00
|
|
|
int full = -1;
|
|
|
|
int time_left = -1;
|
|
|
|
int time_full = -1;
|
|
|
|
int have_battery = 0;
|
|
|
|
int have_power = 0;
|
2010-05-18 03:39:30 -07:00
|
|
|
int charging = 0;
|
2010-05-16 22:14:50 -07:00
|
|
|
|
|
|
|
int batnum = 0;
|
|
|
|
int acnum = 0;
|
|
|
|
|
2010-05-18 03:39:30 -07:00
|
|
|
EINA_LIST_FOREACH(device_ac_adapters, l, ac)
|
2010-05-16 22:14:50 -07:00
|
|
|
if (ac->present) acnum++;
|
2010-05-18 03:39:30 -07:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH(device_batteries, l, bat)
|
2010-05-16 22:14:50 -07:00
|
|
|
{
|
2010-05-18 03:39:30 -07:00
|
|
|
if (!bat->got_prop)
|
|
|
|
continue;
|
2010-05-16 22:14:50 -07:00
|
|
|
have_battery = 1;
|
|
|
|
batnum++;
|
2010-05-18 03:39:30 -07:00
|
|
|
if (bat->charging == 1) have_power = 1;
|
2010-05-16 22:14:50 -07:00
|
|
|
if (full == -1) full = 0;
|
2010-05-18 03:39:30 -07:00
|
|
|
if (bat->percent >= 0)
|
|
|
|
full += bat->percent;
|
|
|
|
else if (bat->last_full_charge > 0)
|
2010-05-16 22:14:50 -07:00
|
|
|
full += (bat->current_charge * 100) / bat->last_full_charge;
|
|
|
|
else if (bat->design_charge > 0)
|
|
|
|
full += (bat->current_charge * 100) / bat->design_charge;
|
|
|
|
if (bat->time_left > 0)
|
|
|
|
{
|
|
|
|
if (time_left < 0) time_left = bat->time_left;
|
|
|
|
else time_left += bat->time_left;
|
|
|
|
}
|
|
|
|
if (bat->time_full > 0)
|
|
|
|
{
|
|
|
|
if (time_full < 0) time_full = bat->time_full;
|
|
|
|
else time_full += bat->time_full;
|
|
|
|
}
|
2010-05-18 03:39:30 -07:00
|
|
|
charging += bat->charging;
|
2010-05-16 22:14:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((device_batteries) && (batnum == 0))
|
|
|
|
return; /* not ready yet, no properties received for any battery */
|
|
|
|
|
|
|
|
if (batnum > 0) full /= batnum;
|
2010-05-18 13:15:11 -07:00
|
|
|
if ((full == 100) && have_power)
|
|
|
|
{
|
|
|
|
time_left = -1;
|
|
|
|
time_full = -1;
|
|
|
|
}
|
2010-05-16 22:14:50 -07:00
|
|
|
if (time_left < 1) time_left = -1;
|
|
|
|
if (time_full < 1) time_full = -1;
|
|
|
|
|
|
|
|
_battery_update(full, time_left, time_full, have_battery, have_power);
|
|
|
|
if ((acnum >= 0) && (batnum == 0))
|
|
|
|
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
void
|
|
|
|
_battery_config_updated(void)
|
|
|
|
{
|
2010-05-18 03:39:30 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Instance *inst;
|
2008-03-03 01:48:37 -08:00
|
|
|
char buf[4096];
|
2010-08-30 12:57:36 -07:00
|
|
|
int ok = 0;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
if (!battery_config) return;
|
2008-05-03 14:49:37 -07:00
|
|
|
|
2008-05-03 15:18:35 -07:00
|
|
|
if (battery_config->instances)
|
2008-05-03 14:49:37 -07:00
|
|
|
{
|
2010-05-18 03:39:30 -07:00
|
|
|
EINA_LIST_FOREACH(battery_config->instances, l, inst)
|
|
|
|
_battery_warning_popup_destroy(inst);
|
2008-05-03 14:49:37 -07:00
|
|
|
}
|
2010-08-30 12:57:36 -07:00
|
|
|
if (battery_config->batget_exe)
|
|
|
|
{
|
|
|
|
ecore_exe_terminate(battery_config->batget_exe);
|
|
|
|
ecore_exe_free(battery_config->batget_exe);
|
|
|
|
battery_config->batget_exe = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((battery_config->force_mode == UNKNOWN) ||
|
|
|
|
(battery_config->force_mode == SUBSYSTEM))
|
2008-03-04 02:35:30 -08:00
|
|
|
{
|
2010-05-22 00:04:26 -07:00
|
|
|
#ifdef HAVE_EEZE
|
2010-08-30 12:57:36 -07:00
|
|
|
ok = _battery_udev_start();
|
2010-05-18 03:39:30 -07:00
|
|
|
#else
|
2010-08-30 12:57:36 -07:00
|
|
|
ok = _battery_dbus_start();
|
2010-05-18 03:39:30 -07:00
|
|
|
#endif
|
2008-03-04 02:35:30 -08:00
|
|
|
}
|
2010-08-30 12:57:36 -07:00
|
|
|
if (ok) return;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2010-08-30 12:57:36 -07:00
|
|
|
if ((battery_config->force_mode == UNKNOWN) ||
|
2010-05-18 03:39:30 -07:00
|
|
|
(battery_config->force_mode == NOSUBSYSTEM))
|
2008-11-14 19:42:19 -08:00
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/batget %i",
|
|
|
|
e_module_dir_get(battery_config->module), MODULE_ARCH,
|
|
|
|
battery_config->poll_interval);
|
|
|
|
|
|
|
|
battery_config->batget_exe =
|
|
|
|
ecore_exe_pipe_run(buf, ECORE_EXE_PIPE_READ |
|
|
|
|
ECORE_EXE_PIPE_READ_LINE_BUFFERED |
|
|
|
|
ECORE_EXE_NOT_LEADER, NULL);
|
|
|
|
}
|
2006-04-20 04:30:25 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool
|
2008-05-03 14:49:37 -07:00
|
|
|
_battery_cb_warning_popup_timeout(void *data)
|
2008-05-03 12:51:49 -07:00
|
|
|
{
|
|
|
|
Instance *inst;
|
|
|
|
|
2008-05-03 13:12:57 -07:00
|
|
|
inst = data;
|
2008-05-03 14:49:37 -07:00
|
|
|
e_gadcon_popup_hide(inst->warning);
|
2009-01-31 19:26:46 -08:00
|
|
|
battery_config->alert_timer = NULL;
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_CANCEL;
|
2008-05-03 12:51:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-02 13:42:59 -08:00
|
|
|
_battery_cb_warning_popup_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
|
2008-05-03 12:51:49 -07:00
|
|
|
{
|
|
|
|
Instance *inst = NULL;
|
|
|
|
|
|
|
|
inst = (Instance *)data;
|
2008-05-03 13:12:57 -07:00
|
|
|
if ((!inst) || (!inst->warning)) return;
|
2008-05-03 14:49:37 -07:00
|
|
|
e_gadcon_popup_hide(inst->warning);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_battery_warning_popup_destroy(Instance *inst)
|
|
|
|
{
|
2009-01-31 19:26:46 -08:00
|
|
|
if (battery_config->alert_timer)
|
|
|
|
{
|
|
|
|
ecore_timer_del(battery_config->alert_timer);
|
|
|
|
battery_config->alert_timer = NULL;
|
|
|
|
}
|
2008-06-13 23:18:30 -07:00
|
|
|
if ((!inst) || (!inst->warning)) return;
|
2008-05-03 14:49:37 -07:00
|
|
|
e_object_del(E_OBJECT(inst->warning));
|
|
|
|
inst->warning = NULL;
|
|
|
|
inst->popup_battery = NULL;
|
2008-05-03 12:51:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_battery_warning_popup(Instance *inst, int time, double percent)
|
|
|
|
{
|
|
|
|
Evas *e = NULL;
|
|
|
|
Evas_Object *rect = NULL, *popup_bg = NULL;
|
|
|
|
int x,y,w,h;
|
|
|
|
|
2008-05-03 13:12:57 -07:00
|
|
|
if ((!inst) || (inst->warning)) return;
|
2008-05-03 12:51:49 -07:00
|
|
|
|
2009-06-07 01:56:16 -07:00
|
|
|
inst->warning = e_gadcon_popup_new(inst->gcc);
|
2008-05-03 13:12:57 -07:00
|
|
|
if (!inst->warning) return;
|
2008-05-03 12:51:49 -07:00
|
|
|
|
|
|
|
e = inst->warning->win->evas;
|
|
|
|
|
|
|
|
popup_bg = edje_object_add(e);
|
|
|
|
inst->popup_battery = edje_object_add(e);
|
|
|
|
|
2008-05-03 13:12:57 -07:00
|
|
|
if ((!popup_bg) || (!inst->popup_battery))
|
2008-05-03 12:51:49 -07:00
|
|
|
{
|
|
|
|
e_object_free(E_OBJECT(inst->warning));
|
|
|
|
inst->warning = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2008-05-03 12:51:49 -07:00
|
|
|
e_theme_edje_object_set(popup_bg, "base/theme/modules/battery/popup",
|
|
|
|
"e/modules/battery/popup");
|
|
|
|
e_theme_edje_object_set(inst->popup_battery, "base/theme/modules/battery",
|
|
|
|
"e/modules/battery/main");
|
|
|
|
edje_object_part_swallow(popup_bg, "battery", inst->popup_battery);
|
|
|
|
|
2008-10-19 03:59:20 -07:00
|
|
|
edje_object_part_text_set(popup_bg, "e.text.title",
|
|
|
|
_("Your battery is low!"));
|
|
|
|
edje_object_part_text_set(popup_bg, "e.text.label",
|
|
|
|
_("AC power is recommended."));
|
|
|
|
|
2008-05-03 12:51:49 -07:00
|
|
|
e_gadcon_popup_content_set(inst->warning, popup_bg);
|
|
|
|
e_gadcon_popup_show(inst->warning);
|
|
|
|
|
|
|
|
evas_object_geometry_get(inst->warning->o_bg, &x, &y, &w, &h);
|
|
|
|
|
|
|
|
rect = evas_object_rectangle_add(e);
|
2008-05-03 13:12:57 -07:00
|
|
|
if (rect)
|
2008-05-03 12:51:49 -07:00
|
|
|
{
|
|
|
|
evas_object_move(rect, x, y);
|
|
|
|
evas_object_resize(rect, w, h);
|
|
|
|
evas_object_color_set(rect, 255, 255, 255, 0);
|
|
|
|
evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN ,
|
2008-05-03 13:12:57 -07:00
|
|
|
_battery_cb_warning_popup_hide, inst);
|
2008-05-03 12:51:49 -07:00
|
|
|
evas_object_repeat_events_set(rect, 1);
|
|
|
|
evas_object_show(rect);
|
|
|
|
}
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2008-05-03 12:51:49 -07:00
|
|
|
_battery_face_time_set(inst->popup_battery, time);
|
|
|
|
_battery_face_level_set(inst->popup_battery, percent);
|
|
|
|
edje_object_signal_emit(inst->popup_battery, "e,state,discharging", "e");
|
|
|
|
|
2009-01-31 19:26:46 -08:00
|
|
|
if ((battery_config->alert_timeout > 0) &&
|
|
|
|
(!battery_config->alert_timer))
|
2008-05-03 13:12:57 -07:00
|
|
|
{
|
2009-01-31 19:26:46 -08:00
|
|
|
battery_config->alert_timer =
|
|
|
|
ecore_timer_add(battery_config->alert_timeout,
|
|
|
|
_battery_cb_warning_popup_timeout, inst);
|
2008-05-03 13:12:57 -07:00
|
|
|
}
|
2008-05-03 12:51:49 -07:00
|
|
|
}
|
|
|
|
|
2008-11-14 19:42:19 -08:00
|
|
|
static void
|
2010-04-30 18:13:38 -07:00
|
|
|
_battery_update(int full, int time_left, int time_full, Eina_Bool have_battery, Eina_Bool have_power)
|
2008-11-14 19:42:19 -08:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Instance *inst;
|
2008-11-14 20:25:09 -08:00
|
|
|
static double debounce_time = 0.0;
|
2008-11-14 19:42:19 -08:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(battery_config->instances, l, inst)
|
2008-11-14 19:42:19 -08:00
|
|
|
{
|
|
|
|
if (have_power != battery_config->have_power)
|
|
|
|
{
|
2010-05-18 03:39:30 -07:00
|
|
|
if (have_power && (full < 100))
|
2008-11-14 19:42:19 -08:00
|
|
|
edje_object_signal_emit(inst->o_battery,
|
|
|
|
"e,state,charging",
|
|
|
|
"e");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edje_object_signal_emit(inst->o_battery,
|
|
|
|
"e,state,discharging",
|
|
|
|
"e");
|
|
|
|
if (inst->popup_battery)
|
|
|
|
edje_object_signal_emit(inst->popup_battery,
|
|
|
|
"e,state,discharging", "e");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (have_battery)
|
|
|
|
{
|
|
|
|
if (battery_config->full != full)
|
|
|
|
{
|
2008-11-16 20:10:07 -08:00
|
|
|
double val;
|
|
|
|
|
|
|
|
if (full >= 100) val = 1.0;
|
|
|
|
else val = (double)full / 100.0;
|
|
|
|
_battery_face_level_set(inst->o_battery, val);
|
2008-11-14 19:42:19 -08:00
|
|
|
if (inst->popup_battery)
|
2008-11-16 20:10:07 -08:00
|
|
|
_battery_face_level_set(inst->popup_battery, val);
|
2008-11-14 19:42:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_battery_face_level_set(inst->o_battery, 0.0);
|
|
|
|
edje_object_part_text_set(inst->o_battery,
|
|
|
|
"e.text.reading",
|
|
|
|
_("N/A"));
|
|
|
|
}
|
|
|
|
|
2010-05-18 03:39:30 -07:00
|
|
|
if ((time_full < 0) && (time_left != battery_config->time_left))
|
2008-11-14 19:42:19 -08:00
|
|
|
{
|
|
|
|
_battery_face_time_set(inst->o_battery, time_left);
|
|
|
|
if (inst->popup_battery)
|
|
|
|
_battery_face_time_set(inst->popup_battery,
|
|
|
|
time_left);
|
|
|
|
}
|
2010-05-18 03:39:30 -07:00
|
|
|
else if ((time_left < 0) && (time_full != battery_config->time_full))
|
2010-04-30 18:13:38 -07:00
|
|
|
{
|
|
|
|
_battery_face_time_set(inst->o_battery, time_full);
|
|
|
|
if (inst->popup_battery)
|
|
|
|
_battery_face_time_set(inst->popup_battery,
|
|
|
|
time_full);
|
|
|
|
}
|
2010-05-19 10:53:16 -07:00
|
|
|
if (have_battery && (!have_power) && (full < 100) &&
|
2008-11-16 19:42:21 -08:00
|
|
|
(((time_left > 0) && battery_config->alert && ((time_left / 60) <= battery_config->alert)) ||
|
2008-11-14 19:42:19 -08:00
|
|
|
(battery_config->alert_p && (full <= battery_config->alert_p)))
|
|
|
|
)
|
|
|
|
{
|
2008-11-14 20:25:09 -08:00
|
|
|
double t;
|
|
|
|
|
|
|
|
t = ecore_time_get();
|
|
|
|
if ((t - debounce_time) > 30.0)
|
2008-11-14 19:42:19 -08:00
|
|
|
{
|
2008-11-14 20:25:09 -08:00
|
|
|
debounce_time = t;
|
|
|
|
if ((t - init_time) > 5.0)
|
|
|
|
_battery_warning_popup(inst, time_left, (double)full / 100.0);
|
2008-11-14 19:42:19 -08:00
|
|
|
}
|
|
|
|
}
|
2010-05-19 10:57:17 -07:00
|
|
|
else if (have_power || ((time_left / 60) > battery_config->alert))
|
2008-11-14 19:42:19 -08:00
|
|
|
_battery_warning_popup_destroy(inst);
|
|
|
|
}
|
|
|
|
if (!have_battery)
|
|
|
|
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((have_power) || (full > 95))
|
|
|
|
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
|
|
|
|
else if (full > 30)
|
|
|
|
e_powersave_mode_set(E_POWERSAVE_MODE_HIGH);
|
|
|
|
else
|
|
|
|
e_powersave_mode_set(E_POWERSAVE_MODE_EXTREME);
|
|
|
|
}
|
|
|
|
battery_config->full = full;
|
|
|
|
battery_config->time_left = time_left;
|
|
|
|
battery_config->have_battery = have_battery;
|
|
|
|
battery_config->have_power = have_power;
|
|
|
|
}
|
|
|
|
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool
|
2010-03-02 13:42:59 -08:00
|
|
|
_battery_cb_exe_data(void *data __UNUSED__, int type __UNUSED__, void *event)
|
2008-11-14 19:42:19 -08:00
|
|
|
{
|
|
|
|
Ecore_Exe_Event_Data *ev;
|
2010-05-18 03:39:30 -07:00
|
|
|
Instance *inst;
|
|
|
|
Eina_List *l;
|
|
|
|
int i;
|
2008-11-14 19:42:19 -08:00
|
|
|
|
|
|
|
ev = event;
|
2010-06-24 09:19:12 -07:00
|
|
|
if (ev->exe != battery_config->batget_exe) return ECORE_CALLBACK_PASS_ON;
|
2008-11-14 19:42:19 -08:00
|
|
|
if ((ev->lines) && (ev->lines[0].line))
|
|
|
|
{
|
2010-05-18 03:39:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; ev->lines[i].line; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(ev->lines[i].line, "ERROR"))
|
|
|
|
EINA_LIST_FOREACH(battery_config->instances, l, inst)
|
|
|
|
{
|
|
|
|
edje_object_signal_emit(inst->o_battery,
|
|
|
|
"e,state,unknown", "e");
|
|
|
|
edje_object_part_text_set(inst->o_battery,
|
|
|
|
"e.text.reading", _("ERROR"));
|
|
|
|
edje_object_part_text_set(inst->o_battery,
|
|
|
|
"e.text.time", _("ERROR"));
|
2008-11-14 19:42:19 -08:00
|
|
|
|
|
|
|
if (inst->popup_battery)
|
|
|
|
{
|
|
|
|
edje_object_signal_emit(inst->popup_battery,
|
2010-05-18 03:39:30 -07:00
|
|
|
"e,state,unknown", "e");
|
2008-11-14 19:42:19 -08:00
|
|
|
edje_object_part_text_set(inst->popup_battery,
|
2010-05-18 03:39:30 -07:00
|
|
|
"e.text.reading", _("ERROR"));
|
2008-11-14 19:42:19 -08:00
|
|
|
edje_object_part_text_set(inst->popup_battery,
|
2010-05-18 03:39:30 -07:00
|
|
|
"e.text.time", _("ERROR"));
|
2008-11-14 19:42:19 -08:00
|
|
|
}
|
2010-05-18 03:39:30 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int full = 0;
|
|
|
|
int time_left = 0;
|
|
|
|
int time_full = 0;
|
|
|
|
int have_battery = 0;
|
|
|
|
int have_power = 0;
|
|
|
|
|
|
|
|
if (sscanf(ev->lines[i].line, "%i %i %i %i %i", &full, &time_left, &time_full,
|
|
|
|
&have_battery, &have_power) == 5)
|
2010-05-16 08:00:35 -07:00
|
|
|
_battery_update(full, time_left, time_full,
|
2010-05-18 03:39:30 -07:00
|
|
|
have_battery, have_power);
|
2008-11-14 19:42:19 -08:00
|
|
|
else
|
|
|
|
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
|
2010-05-18 03:39:30 -07:00
|
|
|
}
|
|
|
|
}
|
2008-11-14 19:42:19 -08:00
|
|
|
}
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_DONE;
|
|
|
|
}
|
2008-11-14 19:42:19 -08:00
|
|
|
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool
|
2010-03-02 13:42:59 -08:00
|
|
|
_battery_cb_exe_del(void *data __UNUSED__, int type __UNUSED__, void *event)
|
2008-11-14 19:42:19 -08:00
|
|
|
{
|
|
|
|
Ecore_Exe_Event_Del *ev;
|
|
|
|
|
|
|
|
ev = event;
|
2010-06-24 09:19:12 -07:00
|
|
|
if (ev->exe != battery_config->batget_exe) return ECORE_CALLBACK_PASS_ON;
|
2008-11-14 19:42:19 -08:00
|
|
|
battery_config->batget_exe = NULL;
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
2008-11-14 19:42:19 -08:00
|
|
|
}
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
/* module setup */
|
|
|
|
EAPI E_Module_Api e_modapi =
|
|
|
|
{
|
2008-05-03 13:12:57 -07:00
|
|
|
E_MODULE_API_VERSION, "Battery"
|
2006-04-20 04:30:25 -07:00
|
|
|
};
|
|
|
|
|
2006-06-06 08:19:36 -07:00
|
|
|
EAPI void *
|
2006-04-20 04:30:25 -07:00
|
|
|
e_modapi_init(E_Module *m)
|
|
|
|
{
|
2007-10-31 08:15:33 -07:00
|
|
|
char buf[4096];
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
conf_edd = E_CONFIG_DD_NEW("Battery_Config", Config);
|
|
|
|
#undef T
|
|
|
|
#undef D
|
|
|
|
#define T Config
|
|
|
|
#define D conf_edd
|
2008-01-10 23:33:57 -08:00
|
|
|
E_CONFIG_VAL(D, T, poll_interval, INT);
|
2008-05-03 12:51:49 -07:00
|
|
|
E_CONFIG_VAL(D, T, alert, INT);
|
|
|
|
E_CONFIG_VAL(D, T, alert_p, INT);
|
|
|
|
E_CONFIG_VAL(D, T, alert_timeout, INT);
|
2009-01-31 19:26:46 -08:00
|
|
|
E_CONFIG_VAL(D, T, force_mode, INT);
|
2010-06-20 20:39:50 -07:00
|
|
|
#ifdef HAVE_EEZE
|
|
|
|
E_CONFIG_VAL(D, T, fuzzy, INT);
|
|
|
|
#endif
|
2006-04-20 04:30:25 -07:00
|
|
|
|
|
|
|
battery_config = e_config_domain_load("module.battery", conf_edd);
|
|
|
|
if (!battery_config)
|
|
|
|
{
|
2010-06-20 20:39:50 -07:00
|
|
|
battery_config = E_NEW(Config, 1);
|
|
|
|
battery_config->poll_interval = 512;
|
|
|
|
battery_config->alert = 30;
|
|
|
|
battery_config->alert_p = 10;
|
|
|
|
battery_config->alert_timeout = 0;
|
|
|
|
battery_config->force_mode = 0;
|
|
|
|
#ifdef HAVE_EEZE
|
|
|
|
battery_config->fuzzy = 0;
|
|
|
|
#endif
|
2006-04-20 04:30:25 -07:00
|
|
|
}
|
2008-03-03 01:48:37 -08:00
|
|
|
E_CONFIG_LIMIT(battery_config->poll_interval, 4, 4096);
|
2008-05-03 12:51:49 -07:00
|
|
|
E_CONFIG_LIMIT(battery_config->alert, 0, 60);
|
|
|
|
E_CONFIG_LIMIT(battery_config->alert_p, 0, 100);
|
|
|
|
E_CONFIG_LIMIT(battery_config->alert_timeout, 0, 300);
|
2009-01-31 19:26:46 -08:00
|
|
|
E_CONFIG_LIMIT(battery_config->force_mode, 0, 2);
|
2008-03-03 19:35:03 -08:00
|
|
|
|
2006-05-09 06:02:48 -07:00
|
|
|
battery_config->module = m;
|
2008-03-03 01:48:37 -08:00
|
|
|
battery_config->full = -2;
|
|
|
|
battery_config->time_left = -2;
|
2010-04-30 18:13:38 -07:00
|
|
|
battery_config->time_full = -2;
|
2008-03-03 01:48:37 -08:00
|
|
|
battery_config->have_battery = -2;
|
|
|
|
battery_config->have_power = -2;
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2008-03-03 01:48:37 -08:00
|
|
|
battery_config->batget_data_handler =
|
|
|
|
ecore_event_handler_add(ECORE_EXE_EVENT_DATA,
|
2008-05-03 13:12:57 -07:00
|
|
|
_battery_cb_exe_data, NULL);
|
2008-03-03 01:48:37 -08:00
|
|
|
battery_config->batget_del_handler =
|
|
|
|
ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
|
2008-05-03 13:12:57 -07:00
|
|
|
_battery_cb_exe_del, NULL);
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
e_gadcon_provider_register(&_gadcon_class);
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2007-10-31 08:15:33 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/e-module-battery.edj", e_module_dir_get(m));
|
2008-05-03 13:12:57 -07:00
|
|
|
e_configure_registry_category_add("advanced", 80, _("Advanced"), NULL,
|
2009-03-15 10:41:46 -07:00
|
|
|
"preferences-advanced");
|
2008-05-03 13:12:57 -07:00
|
|
|
e_configure_registry_item_add("advanced/battery", 100, _("Battery Meter"),
|
|
|
|
NULL, buf, e_int_config_battery_module);
|
|
|
|
|
2006-07-24 21:09:41 -07:00
|
|
|
return m;
|
2006-04-20 04:30:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
2010-03-02 13:42:59 -08:00
|
|
|
e_modapi_shutdown(E_Module *m __UNUSED__)
|
2006-04-20 04:30:25 -07:00
|
|
|
{
|
2007-10-31 05:21:02 -07:00
|
|
|
e_configure_registry_item_del("advanced/battery");
|
|
|
|
e_configure_registry_category_del("advanced");
|
2006-04-20 04:30:25 -07:00
|
|
|
e_gadcon_provider_unregister(&_gadcon_class);
|
2008-03-04 03:35:00 -08:00
|
|
|
|
2009-01-31 19:26:46 -08:00
|
|
|
if (battery_config->alert_timer)
|
|
|
|
ecore_timer_del(battery_config->alert_timer);
|
|
|
|
|
2008-03-04 03:35:00 -08:00
|
|
|
if (battery_config->batget_exe)
|
|
|
|
{
|
|
|
|
ecore_exe_terminate(battery_config->batget_exe);
|
|
|
|
ecore_exe_free(battery_config->batget_exe);
|
|
|
|
battery_config->batget_exe = NULL;
|
|
|
|
}
|
2008-03-03 01:48:37 -08:00
|
|
|
|
|
|
|
if (battery_config->batget_data_handler)
|
|
|
|
{
|
|
|
|
ecore_event_handler_del(battery_config->batget_data_handler);
|
|
|
|
battery_config->batget_data_handler = NULL;
|
|
|
|
}
|
|
|
|
if (battery_config->batget_del_handler)
|
|
|
|
{
|
|
|
|
ecore_event_handler_del(battery_config->batget_del_handler);
|
|
|
|
battery_config->batget_del_handler = NULL;
|
|
|
|
}
|
2008-05-03 13:12:57 -07:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
if (battery_config->config_dialog)
|
|
|
|
e_object_del(E_OBJECT(battery_config->config_dialog));
|
2006-04-21 08:54:11 -07:00
|
|
|
if (battery_config->menu)
|
|
|
|
{
|
|
|
|
e_menu_post_deactivate_callback_set(battery_config->menu, NULL, NULL);
|
|
|
|
e_object_del(E_OBJECT(battery_config->menu));
|
|
|
|
battery_config->menu = NULL;
|
|
|
|
}
|
2008-11-14 19:42:19 -08:00
|
|
|
|
2010-05-22 00:04:26 -07:00
|
|
|
#ifdef HAVE_EEZE
|
2010-05-18 03:39:30 -07:00
|
|
|
_battery_udev_stop();
|
|
|
|
#else
|
|
|
|
_battery_dbus_stop();
|
|
|
|
#endif
|
2008-11-14 19:42:19 -08:00
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
free(battery_config);
|
|
|
|
battery_config = NULL;
|
|
|
|
E_CONFIG_DD_FREE(conf_edd);
|
|
|
|
return 1;
|
2005-12-14 14:46:51 -08:00
|
|
|
}
|
|
|
|
|
2006-04-20 04:30:25 -07:00
|
|
|
EAPI int
|
2010-03-02 13:42:59 -08:00
|
|
|
e_modapi_save(E_Module *m __UNUSED__)
|
2005-12-14 14:46:51 -08:00
|
|
|
{
|
2006-04-20 04:30:25 -07:00
|
|
|
e_config_domain_save("module.battery", conf_edd, battery_config);
|
|
|
|
return 1;
|
2005-12-14 14:46:51 -08:00
|
|
|
}
|