battery module now will use hal - if it finds it, for battery info. tested by
killing hald and seeing if fallback to batget works. :) at least if hal is runing and already monitoring power/battery and polling - e will just flow along with it. pre-hal batget still is there. SVN revision: 37646
This commit is contained in:
parent
f35d682414
commit
60827e2c96
|
@ -4,6 +4,10 @@
|
|||
#include "e.h"
|
||||
#include "e_mod_main.h"
|
||||
|
||||
#define UNKNOWN 0
|
||||
#define NOHAL 1
|
||||
#define HAL 2
|
||||
|
||||
#define POPUP_DEBOUNCE_CYCLES 2
|
||||
|
||||
/* gadcon requirements */
|
||||
|
@ -36,6 +40,7 @@ struct _Instance
|
|||
E_Gadcon_Popup *warning;
|
||||
};
|
||||
|
||||
static void _battery_update(int full, int time_left, int have_battery, int have_power);
|
||||
static int _battery_cb_exe_data(void *data, int type, void *event);
|
||||
static int _battery_cb_exe_del(void *data, int type, void *event);
|
||||
static void _button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
|
@ -230,6 +235,483 @@ _battery_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi)
|
|||
e_int_config_battery_module(m->zone->container, NULL);
|
||||
}
|
||||
|
||||
/* dbus/hal stuff */
|
||||
typedef struct _Hal_Battery Hal_Battery;
|
||||
typedef struct _Hal_Ac_Adapter Hal_Ac_Adapter;
|
||||
|
||||
struct _Hal_Battery
|
||||
{
|
||||
const char *udi;
|
||||
E_DBus_Signal_Handler *prop_change;
|
||||
int present;
|
||||
int percent;
|
||||
int can_charge;
|
||||
int current_charge;
|
||||
int design_charge;
|
||||
int last_full_charge;
|
||||
int charge_rate;
|
||||
int time_left;
|
||||
int is_charging;
|
||||
int is_discharging;
|
||||
const char *charge_units;
|
||||
const char *technology;
|
||||
const char *model;
|
||||
const char *vendor;
|
||||
const char *type;
|
||||
};
|
||||
|
||||
struct _Hal_Ac_Adapter
|
||||
{
|
||||
const char *udi;
|
||||
E_DBus_Signal_Handler *prop_change;
|
||||
int present;
|
||||
const char *product;
|
||||
};
|
||||
|
||||
static void _battery_hal_update(void);
|
||||
static void _battery_hal_shutdown(void);
|
||||
static void _battery_hal_battery_props(void *data, void *reply_data, DBusError *error);
|
||||
static void _battery_hal_ac_adapter_props(void *data, void *reply_data, DBusError *error);
|
||||
static void _battery_hal_battery_property_changed(void *data, DBusMessage *msg);
|
||||
static void _battery_hal_ac_adatper_property_changed(void *data, DBusMessage *msg);
|
||||
static void _battery_hal_battery_add(const char *udi);
|
||||
static void _battery_hal_battery_del(const char *udi);
|
||||
static void _battery_hal_ac_adapter_add(const char *udi);
|
||||
static void _battery_hal_ac_adapter_del(const char *udi);
|
||||
static void _battery_hal_find_battery(void *user_data, void *reply_data, DBusError *error);
|
||||
static void _battery_hal_find_ac(void *user_data, void *reply_data, DBusError *error);
|
||||
static void _battery_hal_is_battery(void *user_data, void *reply_data, DBusError *err);
|
||||
static void _battery_hal_is_ac_adapter(void *user_data, void *reply_data, DBusError *err);
|
||||
static void _battery_hal_dev_add(void *data, DBusMessage *msg);
|
||||
static void _battery_hal_dev_del(void *data, DBusMessage *msg);
|
||||
static void _battery_hal_have_hal(void *data, DBusMessage *msg, DBusError *err);
|
||||
|
||||
static Eina_List *hal_batteries = NULL;
|
||||
static Eina_List *hal_ac_adapters = NULL;
|
||||
static double init_time = 0;
|
||||
|
||||
static void
|
||||
_battery_hal_update(void)
|
||||
{
|
||||
Eina_List *l;
|
||||
int full = -1;
|
||||
int time_left = -1;
|
||||
int have_battery = 0;
|
||||
int have_power = 0;
|
||||
|
||||
int batnum = 0;
|
||||
int acnum = 0;
|
||||
|
||||
for (l = hal_ac_adapters; l; l = l->next)
|
||||
{
|
||||
Hal_Battery *hac;
|
||||
|
||||
hac = l->data;
|
||||
if (hac->present) acnum++;
|
||||
}
|
||||
for (l = hal_batteries; l; l = l->next)
|
||||
{
|
||||
Hal_Battery *hbat;
|
||||
|
||||
hbat = l->data;
|
||||
have_battery = 1;
|
||||
batnum++;
|
||||
if (hbat->is_charging) have_power = 1;
|
||||
full += hbat->percent;
|
||||
if (hbat->time_left > 0)
|
||||
{
|
||||
if (time_left < 0) time_left = hbat->time_left;
|
||||
else time_left += hbat->time_left;
|
||||
}
|
||||
}
|
||||
if (batnum > 0) full /= batnum;
|
||||
|
||||
if ((acnum >= 0) && (batnum == 0))
|
||||
_battery_update(full, time_left, have_battery, have_power);
|
||||
else
|
||||
{
|
||||
_battery_update(full, time_left, have_battery, have_power);
|
||||
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_shutdown(void)
|
||||
{
|
||||
E_DBus_Connection *conn;
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
// FIXME: free all bat/ac adapters, cattery_config stuff etc.
|
||||
if (battery_config->hal.have)
|
||||
{
|
||||
dbus_pending_call_cancel(battery_config->hal.have);
|
||||
battery_config->hal.have = NULL;
|
||||
}
|
||||
if (battery_config->hal.dev_add)
|
||||
{
|
||||
e_dbus_signal_handler_del(conn, battery_config->hal.dev_add);
|
||||
battery_config->hal.dev_add = NULL;
|
||||
}
|
||||
if (battery_config->hal.dev_del)
|
||||
{
|
||||
e_dbus_signal_handler_del(conn, battery_config->hal.dev_del);
|
||||
battery_config->hal.dev_del = NULL;
|
||||
}
|
||||
while (hal_ac_adapters)
|
||||
{
|
||||
Hal_Ac_Adapter *hac;
|
||||
|
||||
hac = hal_ac_adapters->data;
|
||||
e_dbus_signal_handler_del(conn, hac->prop_change);
|
||||
eina_stringshare_del(hac->udi);
|
||||
free(hac);
|
||||
hal_ac_adapters = eina_list_remove_list(hal_ac_adapters, hal_ac_adapters);
|
||||
}
|
||||
while (hal_batteries)
|
||||
{
|
||||
Hal_Battery *hbat;
|
||||
|
||||
hbat = hal_batteries->data;
|
||||
e_dbus_signal_handler_del(conn, hbat->prop_change);
|
||||
eina_stringshare_del(hbat->udi);
|
||||
free(hbat);
|
||||
hal_batteries = eina_list_remove_list(hal_batteries, hal_batteries);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_battery_props(void *data, void *reply_data, DBusError *error)
|
||||
{
|
||||
E_Hal_Properties *ret = reply_data;
|
||||
int err = 0;
|
||||
int i;
|
||||
char *str;
|
||||
Hal_Battery *hbat;
|
||||
|
||||
hbat = data;
|
||||
|
||||
#undef GET_BOOL
|
||||
#undef GET_INT
|
||||
#undef GET_STR
|
||||
#define GET_BOOL(val, s) hbat->val = e_hal_property_bool_get(ret, s, &err)
|
||||
#define GET_INT(val, s) hbat->val = e_hal_property_int_get(ret, s, &err)
|
||||
#define GET_STR(val, s) \
|
||||
if (hbat->val) eina_stringshare_del(hbat->val); \
|
||||
hbat->val = NULL; \
|
||||
str = e_hal_property_string_get(ret, s, &err); \
|
||||
if (str) \
|
||||
{ \
|
||||
hbat->val = eina_stringshare_add(str); \
|
||||
free(str); \
|
||||
}
|
||||
|
||||
GET_BOOL(present, "battery.present");
|
||||
GET_STR(technology, "battery.reporting.technology");
|
||||
GET_STR(model, "battery.model");
|
||||
GET_STR(vendor, "battery.vendor");
|
||||
GET_STR(type, "battery.type");
|
||||
GET_STR(charge_units, "battery.reporting.unit");
|
||||
GET_INT(percent, "battery.charge_level.percentage");
|
||||
GET_BOOL(can_charge, "battery.is_rechargeable");
|
||||
GET_INT(current_charge, "battery.charge_level.current");
|
||||
GET_INT(charge_rate, "battery.charge_level.rate");
|
||||
GET_INT(design_charge, "battery.charge_level.design");
|
||||
GET_INT(last_full_charge, "battery.charge_level.last_full");
|
||||
GET_INT(time_left, "battery.remaining_time");
|
||||
GET_BOOL(is_charging, "battery.rechargeable.is_charging");
|
||||
GET_BOOL(is_discharging, "battery.rechargeable.is_discharging");
|
||||
|
||||
_battery_hal_update();
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_ac_adapter_props(void *data, void *reply_data, DBusError *error)
|
||||
{
|
||||
E_Hal_Properties *ret = reply_data;
|
||||
int err = 0;
|
||||
int i;
|
||||
char *str;
|
||||
Hal_Ac_Adapter *hac;
|
||||
|
||||
hac = data;
|
||||
|
||||
#undef GET_BOOL
|
||||
#undef GET_INT
|
||||
#undef GET_STR
|
||||
#define GET_BOOL(val, s) hac->val = e_hal_property_bool_get(ret, s, &err)
|
||||
#define GET_INT(val, s) hac->val = e_hal_property_int_get(ret, s, &err)
|
||||
#define GET_STR(val, s) \
|
||||
if (hac->val) eina_stringshare_del(hac->val); \
|
||||
hac->val = NULL; \
|
||||
str = e_hal_property_string_get(ret, s, &err); \
|
||||
if (str) \
|
||||
{ \
|
||||
hac->val = eina_stringshare_add(str); \
|
||||
free(str); \
|
||||
}
|
||||
|
||||
GET_BOOL(present, "ac_adapter.present");
|
||||
GET_STR(product, "info.product");
|
||||
_battery_hal_update();
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_battery_property_changed(void *data, DBusMessage *msg)
|
||||
{
|
||||
E_DBus_Connection *conn;
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
// FIXME: e_dbus doesnt allow us to track this pending call
|
||||
e_hal_device_get_all_properties(conn, ((Hal_Battery *)data)->udi,
|
||||
_battery_hal_battery_props, data);
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_ac_adapter_property_changed(void *data, DBusMessage *msg)
|
||||
{
|
||||
E_DBus_Connection *conn;
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
// FIXME: e_dbus doesnt allow us to track this pending call
|
||||
e_hal_device_get_all_properties(conn, ((Hal_Ac_Adapter *)data)->udi,
|
||||
_battery_hal_ac_adapter_props, data);
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_battery_add(const char *udi)
|
||||
{
|
||||
E_DBus_Connection *conn;
|
||||
Hal_Battery *hbat;
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
// FIXME: look for battery with same udi - if so delete and replace
|
||||
hbat = E_NEW(Hal_Battery, 1);
|
||||
if (!hbat) return;
|
||||
hbat->udi = eina_stringshare_add(udi);
|
||||
hal_batteries = eina_list_append(hal_batteries, hbat);
|
||||
hbat->prop_change =
|
||||
e_dbus_signal_handler_add(conn, E_HAL_SENDER, udi,
|
||||
E_HAL_DEVICE_INTERFACE, "PropertyModified",
|
||||
_battery_hal_battery_property_changed,
|
||||
hbat);
|
||||
// FIXME: e_dbus doesnt allow us to track this pending call
|
||||
e_hal_device_get_all_properties(conn, udi,
|
||||
_battery_hal_battery_props, hbat);
|
||||
_battery_hal_update();
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_battery_del(const char *udi)
|
||||
{
|
||||
E_DBus_Connection *conn;
|
||||
Eina_List *l;
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
for (l = hal_batteries; l; l = l->next)
|
||||
{
|
||||
Hal_Battery *hbat;
|
||||
|
||||
hbat = l->data;
|
||||
if (!strcmp(udi, hbat->udi))
|
||||
{
|
||||
e_dbus_signal_handler_del(conn, hbat->prop_change);
|
||||
eina_stringshare_del(hbat->udi);
|
||||
free(hbat);
|
||||
hal_batteries = eina_list_remove_list(hal_batteries, l);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_battery_hal_update();
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_ac_adapter_add(const char *udi)
|
||||
{
|
||||
E_DBus_Connection *conn;
|
||||
Hal_Ac_Adapter *hac;
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
hac = E_NEW(Hal_Ac_Adapter, 1);
|
||||
if (!hac) return;
|
||||
hac->udi = eina_stringshare_add(udi);
|
||||
hal_ac_adapters = eina_list_append(hal_ac_adapters, hac);
|
||||
hac->prop_change =
|
||||
e_dbus_signal_handler_add(conn, E_HAL_SENDER, udi,
|
||||
E_HAL_DEVICE_INTERFACE, "PropertyModified",
|
||||
_battery_hal_ac_adapter_property_changed,
|
||||
hac);
|
||||
// FIXME: e_dbus doesnt allow us to track this pending call
|
||||
e_hal_device_get_all_properties(conn, udi,
|
||||
_battery_hal_ac_adapter_props, hac);
|
||||
_battery_hal_update();
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_ac_adapter_del(const char *udi)
|
||||
{
|
||||
E_DBus_Connection *conn;
|
||||
Eina_List *l;
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
for (l = hal_ac_adapters; l; l = l->next)
|
||||
{
|
||||
Hal_Ac_Adapter *hac;
|
||||
|
||||
hac = l->data;
|
||||
if (!strcmp(udi, hac->udi))
|
||||
{
|
||||
e_dbus_signal_handler_del(conn, hac->prop_change);
|
||||
eina_stringshare_del(hac->udi);
|
||||
free(hac);
|
||||
hal_ac_adapters = eina_list_remove_list(hal_ac_adapters, l);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_battery_hal_update();
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_find_battery(void *user_data, void *reply_data, DBusError *error)
|
||||
{
|
||||
char *device;
|
||||
E_Hal_Manager_Find_Device_By_Capability_Return *ret;
|
||||
|
||||
ret = reply_data;
|
||||
if (ecore_list_count(ret->strings) < 1) return;
|
||||
ecore_list_first_goto(ret->strings);
|
||||
while ((device = ecore_list_next(ret->strings)))
|
||||
_battery_hal_battery_add(device);
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_find_ac(void *user_data, void *reply_data, DBusError *err)
|
||||
{
|
||||
char *device;
|
||||
E_Hal_Manager_Find_Device_By_Capability_Return *ret;
|
||||
|
||||
ret = reply_data;
|
||||
if (ecore_list_count(ret->strings) < 1) return;
|
||||
ecore_list_first_goto(ret->strings);
|
||||
while ((device = ecore_list_next(ret->strings)))
|
||||
_battery_hal_ac_adapter_add(device);
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_is_battery(void *user_data, void *reply_data, DBusError *err)
|
||||
{
|
||||
char *udi = user_data;
|
||||
E_Hal_Device_Query_Capability_Return *ret;
|
||||
|
||||
ret = reply_data;
|
||||
if (dbus_error_is_set(err))
|
||||
{
|
||||
dbus_error_free(err);
|
||||
goto error;
|
||||
}
|
||||
if (ret && ret->boolean) _battery_hal_battery_add(udi);
|
||||
error:
|
||||
free(udi);
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_is_ac_adapter(void *user_data, void *reply_data, DBusError *err)
|
||||
{
|
||||
char *udi = user_data;
|
||||
E_Hal_Device_Query_Capability_Return *ret;
|
||||
|
||||
ret = reply_data;
|
||||
if (dbus_error_is_set(err))
|
||||
{
|
||||
dbus_error_free(err);
|
||||
goto error;
|
||||
}
|
||||
if (ret && ret->boolean) _battery_hal_ac_adapter_add(udi);
|
||||
error:
|
||||
free(udi);
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_dev_add(void *data, DBusMessage *msg)
|
||||
{
|
||||
DBusError err;
|
||||
char *udi = NULL;
|
||||
E_DBus_Connection *conn;
|
||||
|
||||
dbus_error_init(&err);
|
||||
dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
|
||||
if (!udi) return;
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
// FIXME: e_dbus doesnt allow us to track this pending call
|
||||
e_hal_device_query_capability(conn, udi, "battery",
|
||||
_battery_hal_is_battery, strdup(udi));
|
||||
e_hal_device_query_capability(conn, udi, "ac_adapter",
|
||||
_battery_hal_is_ac_adapter, strdup(udi));
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_dev_del(void *data, DBusMessage *msg)
|
||||
{
|
||||
DBusError err;
|
||||
char *udi = NULL;
|
||||
|
||||
dbus_error_init(&err);
|
||||
dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
|
||||
if (!udi) return;
|
||||
_battery_hal_battery_del(udi);
|
||||
_battery_hal_ac_adapter_del(udi);
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_hal_have_hal(void *data, DBusMessage *msg, DBusError *err)
|
||||
{
|
||||
dbus_bool_t ok = 0;
|
||||
E_DBus_Connection *conn;
|
||||
|
||||
battery_config->hal.have = NULL;
|
||||
if (dbus_error_is_set(err))
|
||||
{
|
||||
battery_config->have_hal = NOHAL;
|
||||
_battery_config_updated();
|
||||
return;
|
||||
}
|
||||
dbus_message_get_args(msg, err, DBUS_TYPE_BOOLEAN, &ok, DBUS_TYPE_INVALID);
|
||||
if (!ok)
|
||||
{
|
||||
battery_config->have_hal = NOHAL;
|
||||
_battery_config_updated();
|
||||
return;
|
||||
}
|
||||
battery_config->have_hal = HAL;
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (!conn) return;
|
||||
// FIXME: e_dbus doesnt allow us to track this pending call
|
||||
e_hal_manager_find_device_by_capability
|
||||
(conn, "battery", _battery_hal_find_battery, NULL);
|
||||
e_hal_manager_find_device_by_capability
|
||||
(conn, "ac_adapter", _battery_hal_find_ac, NULL);
|
||||
battery_config->hal.dev_add =
|
||||
e_dbus_signal_handler_add(conn, "org.freedesktop.Hal",
|
||||
"/org/freedesktop/Hal/Manager",
|
||||
"org.freedesktop.Hal.Manager",
|
||||
"DeviceAdded", _battery_hal_dev_add, NULL);
|
||||
battery_config->hal.dev_del =
|
||||
e_dbus_signal_handler_add(conn, "org.freedesktop.Hal",
|
||||
"/org/freedesktop/Hal/Manager",
|
||||
"org.freedesktop.Hal.Manager",
|
||||
"DeviceRemoved", _battery_hal_dev_del, NULL);
|
||||
init_time = ecore_time_get();
|
||||
}
|
||||
|
||||
/* end dbus/hal stuff */
|
||||
|
||||
void
|
||||
_battery_config_updated(void)
|
||||
{
|
||||
|
@ -243,20 +725,39 @@ _battery_config_updated(void)
|
|||
for (l = battery_config->instances; l; l = l->next)
|
||||
_battery_warning_popup_destroy(l->data);
|
||||
}
|
||||
|
||||
if (battery_config->batget_exe)
|
||||
if (battery_config->have_hal == UNKNOWN)
|
||||
{
|
||||
ecore_exe_terminate(battery_config->batget_exe);
|
||||
ecore_exe_free(battery_config->batget_exe);
|
||||
if (!e_dbus_bus_get(DBUS_BUS_SYSTEM))
|
||||
battery_config->have_hal = NOHAL;
|
||||
}
|
||||
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);
|
||||
if (battery_config->have_hal == NOHAL)
|
||||
{
|
||||
if (battery_config->batget_exe)
|
||||
{
|
||||
ecore_exe_terminate(battery_config->batget_exe);
|
||||
ecore_exe_free(battery_config->batget_exe);
|
||||
}
|
||||
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);
|
||||
}
|
||||
else if (battery_config->have_hal == UNKNOWN)
|
||||
{
|
||||
E_DBus_Connection *conn;
|
||||
DBusPendingCall *call;
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
|
||||
if (conn)
|
||||
battery_config->hal.have =
|
||||
e_dbus_name_has_owner(conn, "org.freedesktop.Hal",
|
||||
_battery_hal_have_hal, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -352,6 +853,168 @@ _battery_warning_popup(Instance *inst, int time, double percent)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_battery_update(int full, int time_left, int have_battery, int have_power)
|
||||
{
|
||||
Eina_List *l;
|
||||
static int debounce_popup = 0;
|
||||
|
||||
if (debounce_popup > POPUP_DEBOUNCE_CYCLES)
|
||||
debounce_popup = 0;
|
||||
for (l = battery_config->instances; l; l = l->next)
|
||||
{
|
||||
Instance *inst;
|
||||
|
||||
inst = l->data;
|
||||
if (have_power != battery_config->have_power)
|
||||
{
|
||||
if (have_power)
|
||||
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)
|
||||
{
|
||||
_battery_face_level_set(inst->o_battery,
|
||||
(double)full / 100.0);
|
||||
if (inst->popup_battery)
|
||||
_battery_face_level_set(inst->popup_battery,
|
||||
(double)full / 100.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_battery_face_level_set(inst->o_battery, 0.0);
|
||||
edje_object_part_text_set(inst->o_battery,
|
||||
"e.text.reading",
|
||||
_("N/A"));
|
||||
}
|
||||
|
||||
if (time_left != battery_config->time_left)
|
||||
{
|
||||
_battery_face_time_set(inst->o_battery, time_left);
|
||||
if (inst->popup_battery)
|
||||
_battery_face_time_set(inst->popup_battery,
|
||||
time_left);
|
||||
}
|
||||
|
||||
if (have_battery && (!have_power) && (full != 100) &&
|
||||
((battery_config->alert && ((time_left / 60) <= battery_config->alert)) ||
|
||||
(battery_config->alert_p && (full <= battery_config->alert_p)))
|
||||
)
|
||||
{
|
||||
if (++debounce_popup == POPUP_DEBOUNCE_CYCLES)
|
||||
{
|
||||
double t;
|
||||
|
||||
t = ecore_time_get() - init_time;
|
||||
if (t > 5.0)
|
||||
_battery_warning_popup(inst, time_left, (double)full/100.0);
|
||||
else
|
||||
debounce_popup = 0;
|
||||
}
|
||||
}
|
||||
else if (have_power)
|
||||
_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;
|
||||
}
|
||||
|
||||
static int
|
||||
_battery_cb_exe_data(void *data, int type, void *event)
|
||||
{
|
||||
Ecore_Exe_Event_Data *ev;
|
||||
|
||||
ev = event;
|
||||
if (ev->exe != battery_config->batget_exe) return 1;
|
||||
if ((ev->lines) && (ev->lines[0].line))
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; ev->lines[i].line; i++)
|
||||
{
|
||||
if (!strcmp(ev->lines[i].line, "ERROR"))
|
||||
{
|
||||
Eina_List *l;
|
||||
|
||||
for (l = battery_config->instances; l; l = l->next)
|
||||
{
|
||||
Instance *inst;
|
||||
|
||||
inst = l->data;
|
||||
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"));
|
||||
|
||||
if (inst->popup_battery)
|
||||
{
|
||||
edje_object_signal_emit(inst->popup_battery,
|
||||
"e,state,unknown", "e");
|
||||
edje_object_part_text_set(inst->popup_battery,
|
||||
"e.text.reading", _("ERROR"));
|
||||
edje_object_part_text_set(inst->popup_battery,
|
||||
"e.text.time", _("ERROR"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int full = 0;
|
||||
int time_left = 0;
|
||||
int have_battery = 0;
|
||||
int have_power = 0;
|
||||
|
||||
if (sscanf(ev->lines[i].line, "%i %i %i %i",
|
||||
&full, &time_left, &have_battery, &have_power)
|
||||
== 4)
|
||||
_battery_update(full, time_left, have_battery, have_power);
|
||||
else
|
||||
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_battery_cb_exe_del(void *data, int type, void *event)
|
||||
{
|
||||
Ecore_Exe_Event_Del *ev;
|
||||
|
||||
ev = event;
|
||||
if (ev->exe != battery_config->batget_exe) return 1;
|
||||
battery_config->batget_exe = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* module setup */
|
||||
EAPI E_Module_Api e_modapi =
|
||||
{
|
||||
|
@ -444,6 +1107,9 @@ e_modapi_shutdown(E_Module *m)
|
|||
e_object_del(E_OBJECT(battery_config->menu));
|
||||
battery_config->menu = NULL;
|
||||
}
|
||||
|
||||
_battery_hal_shutdown();
|
||||
|
||||
free(battery_config);
|
||||
battery_config = NULL;
|
||||
E_CONFIG_DD_FREE(conf_edd);
|
||||
|
@ -456,153 +1122,3 @@ e_modapi_save(E_Module *m)
|
|||
e_config_domain_save("module.battery", conf_edd, battery_config);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
_battery_cb_exe_data(void *data, int type, void *event)
|
||||
{
|
||||
Ecore_Exe_Event_Data *ev;
|
||||
|
||||
ev = event;
|
||||
if (ev->exe != battery_config->batget_exe) return 1;
|
||||
if ((ev->lines) && (ev->lines[0].line))
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; ev->lines[i].line; i++)
|
||||
{
|
||||
if (!strcmp(ev->lines[i].line, "ERROR"))
|
||||
{
|
||||
Eina_List *l;
|
||||
|
||||
for (l = battery_config->instances; l; l = l->next)
|
||||
{
|
||||
Instance *inst;
|
||||
|
||||
inst = l->data;
|
||||
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"));
|
||||
|
||||
if (inst->popup_battery)
|
||||
{
|
||||
edje_object_signal_emit(inst->popup_battery,
|
||||
"e,state,unknown", "e");
|
||||
edje_object_part_text_set(inst->popup_battery,
|
||||
"e.text.reading", _("ERROR"));
|
||||
edje_object_part_text_set(inst->popup_battery,
|
||||
"e.text.time", _("ERROR"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int full = 0;
|
||||
int time_left = 0;
|
||||
int have_battery = 0;
|
||||
int have_power = 0;
|
||||
Eina_List *l;
|
||||
static int debounce_popup = 0;
|
||||
|
||||
if (debounce_popup > POPUP_DEBOUNCE_CYCLES)
|
||||
debounce_popup = 0;
|
||||
|
||||
if (sscanf(ev->lines[i].line, "%i %i %i %i",
|
||||
&full, &time_left, &have_battery, &have_power)
|
||||
== 4)
|
||||
{
|
||||
for (l = battery_config->instances; l; l = l->next)
|
||||
{
|
||||
Instance *inst;
|
||||
|
||||
inst = l->data;
|
||||
if (have_power != battery_config->have_power)
|
||||
{
|
||||
if (have_power)
|
||||
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)
|
||||
{
|
||||
_battery_face_level_set(inst->o_battery,
|
||||
(double)full / 100.0);
|
||||
if (inst->popup_battery)
|
||||
_battery_face_level_set(inst->popup_battery,
|
||||
(double)full / 100.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_battery_face_level_set(inst->o_battery, 0.0);
|
||||
edje_object_part_text_set(inst->o_battery,
|
||||
"e.text.reading",
|
||||
_("N/A"));
|
||||
}
|
||||
|
||||
if (time_left != battery_config->time_left)
|
||||
{
|
||||
_battery_face_time_set(inst->o_battery, time_left);
|
||||
if (inst->popup_battery)
|
||||
_battery_face_time_set(inst->popup_battery,
|
||||
time_left);
|
||||
}
|
||||
|
||||
if (have_battery && !have_power && (full != 100) &&
|
||||
((battery_config->alert && ((time_left/60) <= battery_config->alert)) ||
|
||||
(battery_config->alert_p && (full <= battery_config->alert_p)))
|
||||
)
|
||||
{
|
||||
if (++debounce_popup == POPUP_DEBOUNCE_CYCLES)
|
||||
_battery_warning_popup(inst, time_left, (double)full/100.0);
|
||||
}
|
||||
else if (have_power)
|
||||
_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);
|
||||
}
|
||||
}
|
||||
else
|
||||
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
|
||||
battery_config->full = full;
|
||||
battery_config->time_left = time_left;
|
||||
battery_config->have_battery = have_battery;
|
||||
battery_config->have_power = have_power;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_battery_cb_exe_del(void *data, int type, void *event)
|
||||
{
|
||||
Ecore_Exe_Event_Del *ev;
|
||||
|
||||
ev = event;
|
||||
if (ev->exe != battery_config->batget_exe) return 1;
|
||||
battery_config->batget_exe = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -27,10 +27,19 @@ struct _Config
|
|||
Ecore_Exe *batget_exe;
|
||||
Ecore_Event_Handler *batget_data_handler;
|
||||
Ecore_Event_Handler *batget_del_handler;
|
||||
int have_hal;
|
||||
int full;
|
||||
int time_left;
|
||||
int have_battery;
|
||||
int have_power;
|
||||
struct {
|
||||
// FIXME: on bat_conf del dbus_pending_call_cancel(hal.have);
|
||||
// then set hal.have to NULL
|
||||
DBusPendingCall *have;
|
||||
// FIXME: on bat_conf del e_dbus_signal_handler_del() these
|
||||
E_DBus_Signal_Handler *dev_add;
|
||||
E_DBus_Signal_Handler *dev_del;
|
||||
} hal;
|
||||
};
|
||||
|
||||
EAPI extern E_Module_Api e_modapi;
|
||||
|
|
Loading…
Reference in New Issue