forked from enlightenment/enlightenment
Allow module to fire its alarm given a percentage remaining threshold.
SVN revision: 30039
This commit is contained in:
parent
132e8b3022
commit
323620e492
|
@ -6,6 +6,7 @@ struct _E_Config_Dialog_Data
|
|||
int show_alert;
|
||||
double poll_time;
|
||||
int alarm_time;
|
||||
int alarm_percent;
|
||||
};
|
||||
|
||||
/* Protos */
|
||||
|
@ -45,8 +46,9 @@ _fill_data(E_Config_Dialog_Data *cfdata)
|
|||
{
|
||||
if (!battery_config) return;
|
||||
cfdata->alarm_time = battery_config->alarm;
|
||||
cfdata->alarm_percent = battery_config->alarm_p;
|
||||
cfdata->poll_time = battery_config->poll_time;
|
||||
if (cfdata->alarm_time > 0)
|
||||
if (cfdata->alarm_time > 0 || cfdata->alarm_percent > 0)
|
||||
cfdata->show_alert = 1;
|
||||
else
|
||||
cfdata->show_alert = 0;
|
||||
|
@ -88,9 +90,15 @@ _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
|
|||
{
|
||||
if (!battery_config) return 0;
|
||||
if (cfdata->show_alert)
|
||||
{
|
||||
battery_config->alarm = cfdata->alarm_time;
|
||||
battery_config->alarm_p = cfdata->alarm_percent;
|
||||
}
|
||||
else
|
||||
{
|
||||
battery_config->alarm = 0;
|
||||
battery_config->alarm_p = 0;
|
||||
}
|
||||
_battery_config_updated();
|
||||
e_config_save_queue();
|
||||
return 1;
|
||||
|
@ -108,16 +116,19 @@ _advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data
|
|||
ob = e_widget_label_add(evas, _("Check battery every:"));
|
||||
e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 0, 1, 0);
|
||||
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.1f seconds"), 0.5, 1000.0, 0.5, 0, &(cfdata->poll_time), NULL, 200);
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.1f seconds"), 0.5, 900.0, 0.5, 0, &(cfdata->poll_time), NULL, 200);
|
||||
e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 1, 0, 1, 0);
|
||||
|
||||
ob = e_widget_check_add(evas, _("Show alert when battery is low"), &(cfdata->show_alert));
|
||||
e_widget_frametable_object_append(of, ob, 0, 3, 1, 1, 1, 1, 1, 0);
|
||||
e_widget_frametable_object_append(of, ob, 0, 2, 1, 1, 1, 1, 1, 0);
|
||||
|
||||
ob = e_widget_label_add(evas, _("Alert when battery is down to:"));
|
||||
e_widget_frametable_object_append(of, ob, 0, 4, 1, 1, 1, 0, 1, 1);
|
||||
e_widget_frametable_object_append(of, ob, 0, 3, 1, 1, 1, 0, 1, 1);
|
||||
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f minutes"), 1, 60, 1, 0, NULL, &(cfdata->alarm_time), 200);
|
||||
e_widget_frametable_object_append(of, ob, 0, 4, 1, 1, 1, 0, 1, 0);
|
||||
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f percent"), 1, 100, 1, 0, NULL, &(cfdata->alarm_percent), 200);
|
||||
e_widget_frametable_object_append(of, ob, 0, 5, 1, 1, 1, 0, 1, 0);
|
||||
|
||||
e_widget_list_object_append(o, of, 1, 1, 0.5);
|
||||
|
@ -130,9 +141,15 @@ _advanced_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
|
|||
if (!battery_config) return 0;
|
||||
battery_config->poll_time = cfdata->poll_time;
|
||||
if (cfdata->show_alert)
|
||||
{
|
||||
battery_config->alarm = cfdata->alarm_time;
|
||||
battery_config->alarm_p = cfdata->alarm_percent;
|
||||
}
|
||||
else
|
||||
{
|
||||
battery_config->alarm = 0;
|
||||
battery_config->alarm_p = 0;
|
||||
}
|
||||
_battery_config_updated();
|
||||
e_config_save_queue();
|
||||
return 1;
|
||||
|
|
|
@ -559,6 +559,8 @@ _battery_linux_acpi_check(void)
|
|||
{
|
||||
if (((hours * 60) + minutes) <= battery_config->alarm)
|
||||
stat->alarm = 1;
|
||||
if (bat_val <= battery_config->alarm_p)
|
||||
stat->alarm = 1;
|
||||
}
|
||||
}
|
||||
if (level_unknown)
|
||||
|
@ -684,6 +686,8 @@ _battery_linux_apm_check(void)
|
|||
{
|
||||
if (((hours * 60) + minutes) <= battery_config->alarm)
|
||||
stat->alarm = 1;
|
||||
if (bat_val <= battery_config->alarm_p)
|
||||
stat->alarm = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -859,22 +863,8 @@ _battery_linux_powerbook_check(void)
|
|||
else if ((charging) || (discharging))
|
||||
{
|
||||
stat->has_battery = 1;
|
||||
if (charging)
|
||||
{
|
||||
stat->state = BATTERY_STATE_CHARGING;
|
||||
battery_config->alarm_triggered = 0;
|
||||
}
|
||||
else if (discharging)
|
||||
{
|
||||
stat->state = BATTERY_STATE_DISCHARGING;
|
||||
if (stat->level < 0.1)
|
||||
{
|
||||
if (((hours * 60) + minutes) <= battery_config->alarm)
|
||||
stat->alarm = 1;
|
||||
}
|
||||
}
|
||||
stat->level = (double)charge / (double)max_charge;
|
||||
if (stat->level > 1.0) stat->level = 1.0;
|
||||
if (stat->level > 1.0) stat->level = 1.0;
|
||||
tmp = (double)max_charge / 100;
|
||||
tmp = (double)charge / tmp;
|
||||
stat->level = (double)tmp / 100;
|
||||
|
@ -883,6 +873,22 @@ _battery_linux_powerbook_check(void)
|
|||
stat->reading = strdup(buf);
|
||||
snprintf(buf, sizeof(buf), "%i:%02i", hours, minutes);
|
||||
stat->time = strdup(buf);
|
||||
if (charging)
|
||||
{
|
||||
stat->state = BATTERY_STATE_CHARGING;
|
||||
battery_config->alarm_triggered = 0;
|
||||
}
|
||||
else if (discharging)
|
||||
{
|
||||
stat->state = BATTERY_STATE_DISCHARGING;
|
||||
if (stat->level < 0.1)
|
||||
{
|
||||
if (((hours * 60) + minutes) <= battery_config->alarm)
|
||||
stat->alarm = 1;
|
||||
if (stat->level <= battery_config->alarm_p)
|
||||
stat->alarm = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1027,6 +1033,8 @@ _battery_bsd_acpi_check(void)
|
|||
{
|
||||
if (((hours * 60) + minutes) <= battery_config->alarm)
|
||||
stat->alarm = 1;
|
||||
if (bat_val <= battery_config->alarm_p)
|
||||
stat->alarm = 1;
|
||||
}
|
||||
}
|
||||
if (level == -1)
|
||||
|
@ -1150,6 +1158,8 @@ _battery_bsd_apm_check(void)
|
|||
{
|
||||
if (((hours * 60) + minutes) <= battery_config->alarm)
|
||||
stat->alarm = 1;
|
||||
if (bat_val <= battery_config->alarm_p)
|
||||
stat->alarm = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1288,6 +1298,8 @@ _battery_darwin_check(void)
|
|||
*/
|
||||
if (currentval <= battery_config->alarm)
|
||||
stat->alarm = 1;
|
||||
if (stat->level <= battery_config->alarm_p)
|
||||
stat->alarm = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1397,6 +1409,7 @@ e_modapi_init(E_Module *m)
|
|||
#define D conf_edd
|
||||
E_CONFIG_VAL(D, T, poll_time, DOUBLE);
|
||||
E_CONFIG_VAL(D, T, alarm, INT);
|
||||
E_CONFIG_VAL(D, T, alarm_p, INT);
|
||||
|
||||
battery_config = e_config_domain_load("module.battery", conf_edd);
|
||||
if (!battery_config)
|
||||
|
@ -1404,9 +1417,11 @@ e_modapi_init(E_Module *m)
|
|||
battery_config = E_NEW(Config, 1);
|
||||
battery_config->poll_time = 30.0;
|
||||
battery_config->alarm = 30;
|
||||
battery_config->alarm_p = 10;
|
||||
}
|
||||
E_CONFIG_LIMIT(battery_config->poll_time, 0.5, 1000.0);
|
||||
E_CONFIG_LIMIT(battery_config->alarm, 0, 60);
|
||||
E_CONFIG_LIMIT(battery_config->alarm_p, 0, 100);
|
||||
|
||||
battery_config->battery_check_mode = CHECK_NONE;
|
||||
battery_config->battery_prev_drain = 1;
|
||||
|
|
|
@ -16,7 +16,8 @@ struct _Config
|
|||
{
|
||||
/* saved * loaded config values */
|
||||
double poll_time;
|
||||
int alarm;
|
||||
int alarm; /* Alarm on minutes remaining */
|
||||
int alarm_p; /* Alarm on percentage remaining */
|
||||
/* just config state */
|
||||
E_Module *module;
|
||||
E_Config_Dialog *config_dialog;
|
||||
|
|
Loading…
Reference in New Issue