enlightenment/src/modules/temperature/e_mod_config.c

373 lines
12 KiB
C
Raw Normal View History

#include "e.h"
#include "e_mod_main.h"
#define FAR_2_CEL(x) ((x - 32) / 9.0) * 5.0
#define CEL_2_FAR(x) (x * 9.0 / 5.0) + 32
struct _E_Config_Dialog_Data
{
struct
{
int interval;
} poll;
int unit_method;
#ifdef HAVE_EEZE
int backend;
#endif
struct
{
int low, high;
} temp;
int sensor;
Eina_List *sensors;
Evas_Object *o_high, *o_low;
Config_Face *inst;
};
/* local function prototypes */
static void *_create_data(E_Config_Dialog *cfd);
static void _fill_data_tempget(E_Config_Dialog_Data *cfdata);
static void _fill_sensors(E_Config_Dialog_Data *cfdata, const char *name);
static void _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void _cb_display_changed(void *data, Evas_Object *obj EINA_UNUSED);
static Eina_List *
temperature_get_bus_files(const char *bus)
{
Eina_List *result;
Eina_List *therms;
char path[PATH_MAX];
char busdir[PATH_MAX];
char *name;
result = NULL;
snprintf(busdir, sizeof(busdir), "/sys/bus/%s/devices", bus);
/* Look through all the devices for the given bus. */
therms = ecore_file_ls(busdir);
EINA_LIST_FREE(therms, name)
{
Eina_List *files;
char *file;
/* Search each device for temp*_input, these should be
* temperature devices. */
snprintf(path, sizeof(path), "%s/%s", busdir, name);
files = ecore_file_ls(path);
EINA_LIST_FREE(files, file)
{
if ((!strncmp("temp", file, 4)) &&
(!strcmp("_input", &file[strlen(file) - 6])))
{
char *f;
snprintf(path, sizeof(path),
"%s/%s/%s", busdir, name, file);
f = strdup(path);
if (f) result = eina_list_append(result, f);
}
free(file);
}
free(name);
}
return result;
}
void
config_temperature_module(Config_Face *inst)
{
E_Config_Dialog_View *v;
char buff[PATH_MAX];
v = E_NEW(E_Config_Dialog_View, 1);
v->create_cfdata = _create_data;
v->free_cfdata = _free_data;
v->basic.create_widgets = _basic_create;
v->basic.apply_cfdata = _basic_apply;
snprintf(buff, sizeof(buff),
"%s/e-module-temperature.edj", inst->module->dir);
inst->config_dialog =
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
e_config_dialog_new(NULL,
_("Temperature Settings"), "E",
"_e_mod_temperature_config_dialog", buff, 0, v, inst);
}
/* local function prototypes */
static void *
_create_data(E_Config_Dialog *cfd)
{
E_Config_Dialog_Data *cfdata;
cfdata = E_NEW(E_Config_Dialog_Data, 1);
cfdata->inst = cfd->data;
_fill_data_tempget(cfdata);
return cfdata;
}
static void
_fill_data_tempget(E_Config_Dialog_Data *cfdata)
{
cfdata->unit_method = cfdata->inst->units;
cfdata->poll.interval = cfdata->inst->poll_interval;
cfdata->temp.low = cfdata->inst->low;
cfdata->temp.high = cfdata->inst->high;
cfdata->sensor = 0;
#ifdef HAVE_EEZE
cfdata->backend = cfdata->inst->backend;
if (cfdata->backend == TEMPGET)
{
#endif
switch (cfdata->inst->sensor_type)
{
case SENSOR_TYPE_NONE:
case SENSOR_TYPE_FREEBSD:
case SENSOR_TYPE_OMNIBOOK:
case SENSOR_TYPE_LINUX_MACMINI:
case SENSOR_TYPE_LINUX_PBOOK:
case SENSOR_TYPE_LINUX_INTELCORETEMP:
break;
case SENSOR_TYPE_LINUX_I2C:
_fill_sensors(cfdata, "i2c");
break;
case SENSOR_TYPE_LINUX_PCI:
_fill_sensors(cfdata, "pci");
break;
case SENSOR_TYPE_LINUX_ACPI:
{
Eina_List *l;
if ((l = ecore_file_ls("/proc/acpi/thermal_zone")))
{
char *name;
int n = 0;
EINA_LIST_FREE(l, name)
{
cfdata->sensors =
eina_list_append(cfdata->sensors, name);
if (!strcmp(cfdata->inst->sensor_name, name))
cfdata->sensor = n;
n++;
}
}
break;
}
case SENSOR_TYPE_LINUX_SYS:
{
Eina_List *l;
if ((l = ecore_file_ls("/sys/class/thermal")))
{
char *name;
int n = 0;
EINA_LIST_FREE(l, name)
{
if (!strncmp(name, "thermal", 7))
{
cfdata->sensors =
eina_list_append(cfdata->sensors, name);
if (!strcmp(cfdata->inst->sensor_name, name))
cfdata->sensor = n;
n++;
}
}
}
break;
}
default:
break;
}
#ifdef HAVE_EEZE
}
#endif
}
static void
_fill_sensors(E_Config_Dialog_Data *cfdata, const char *name)
{
Eina_List *therms, *l;
char *n;
if (!name) return;
if ((therms = temperature_get_bus_files(name)))
{
char path[PATH_MAX];
EINA_LIST_FREE(therms, n)
{
if (ecore_file_exists(n))
{
int len;
sprintf(path, "%s", ecore_file_file_get(n));
len = strlen(path);
if (len > 6) path[len - 6] = '\0';
cfdata->sensors =
eina_list_append(cfdata->sensors, strdup(path));
}
free(n);
}
}
EINA_LIST_FOREACH(cfdata->sensors, l, n)
{
if (!strcmp(cfdata->inst->sensor_name, n)) break;
cfdata->sensor++;
}
}
static void
_free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
char *sensor;
cfdata->inst->config_dialog = NULL;
EINA_LIST_FREE(cfdata->sensors, sensor)
free(sensor);
E_FREE(cfdata);
}
static Evas_Object *
_basic_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata)
{
Evas_Object *otb, *ol, *ow;
E_Radio_Group *rg;
otb = e_widget_toolbook_add(evas, 24, 24);
if (cfdata->sensors)
{
Eina_List *l;
char *name;
int n = 0;
ol = e_widget_list_add(evas, 0, 0);
rg = e_widget_radio_group_new(&(cfdata->sensor));
EINA_LIST_FOREACH(cfdata->sensors, l, name)
{
ow = e_widget_radio_add(evas, _(name), n, rg);
e_widget_list_object_append(ol, ow, 1, 0, 0.5);
n++;
}
e_widget_toolbook_page_append(otb, NULL, _("Sensors"), ol,
1, 0, 1, 0, 0.5, 0.0);
}
ol = e_widget_list_add(evas, 0, 0);
rg = e_widget_radio_group_new(&(cfdata->unit_method));
ow = e_widget_radio_add(evas, _("Celsius"), CELSIUS, rg);
e_widget_on_change_hook_set(ow, _cb_display_changed, cfdata);
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
ow = e_widget_radio_add(evas, _("Fahrenheit"), FAHRENHEIT, rg);
e_widget_on_change_hook_set(ow, _cb_display_changed, cfdata);
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
e_widget_toolbook_page_append(otb, NULL, _("Display Units"), ol,
0, 0, 0, 0, 0.5, 0.0);
ol = e_widget_list_add(evas, 0, 0);
ow = e_widget_slider_add(evas, 1, 0, _("%1.0f ticks"), 1, 1024, 4, 0,
NULL, &(cfdata->poll.interval), 150);
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
e_widget_toolbook_page_append(otb, NULL, _("Check Interval"), ol,
1, 0, 1, 0, 0.5, 0.0);
ol = e_widget_list_add(evas, 0, 0);
ow = e_widget_label_add(evas, _("High Temperature"));
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
if (cfdata->unit_method == FAHRENHEIT)
cfdata->o_high =
e_widget_slider_add(evas, 1, 0, _("%1.0f F"), 0, 230, 5, 0,
NULL, &(cfdata->temp.high), 150);
else
cfdata->o_high =
e_widget_slider_add(evas, 1, 0, _("%1.0f C"), 0, 110, 5, 0,
NULL, &(cfdata->temp.high), 150);
e_widget_list_object_append(ol, cfdata->o_high, 1, 1, 0.5);
ow = e_widget_label_add(evas, _("Low Temperature"));
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
if (cfdata->unit_method == FAHRENHEIT)
cfdata->o_low =
e_widget_slider_add(evas, 1, 0, _("%1.0f F"), 0, 200, 5, 0,
NULL, &(cfdata->temp.low), 150);
else
cfdata->o_low =
e_widget_slider_add(evas, 1, 0, _("%1.0f C"), 0, 95, 5, 0,
NULL, &(cfdata->temp.low), 150);
e_widget_list_object_append(ol, cfdata->o_low, 1, 1, 0.5);
e_widget_toolbook_page_append(otb, NULL, _("Temperatures"), ol,
1, 0, 1, 0, 0.5, 0.0);
#ifdef HAVE_EEZE
ol = e_widget_list_add(evas, 0, 0);
rg = e_widget_radio_group_new(&(cfdata->backend));
ow = e_widget_radio_add(evas, _("Internal"), TEMPGET, rg);
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
ow = e_widget_radio_add(evas, _("udev"), UDEV, rg);
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
e_widget_toolbook_page_append(otb, NULL, _("Hardware"), ol,
0, 0, 0, 0, 0.5, 0.0);
#endif
e_widget_toolbook_page_show(otb, 0);
return otb;
}
static int
_basic_apply(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
cfdata->inst->poll_interval = cfdata->poll.interval;
cfdata->inst->units = cfdata->unit_method;
cfdata->inst->low = cfdata->temp.low;
cfdata->inst->high = cfdata->temp.high;
#ifdef HAVE_EEZE
cfdata->inst->backend = cfdata->backend;
#endif
eina_stringshare_replace(&cfdata->inst->sensor_name,
eina_list_nth(cfdata->sensors, cfdata->sensor));
e_config_save_queue();
temperature_face_update_config(cfdata->inst);
return 1;
}
static void
_cb_display_changed(void *data, Evas_Object *obj EINA_UNUSED)
{
E_Config_Dialog_Data *cfdata;
int val;
if (!(cfdata = data)) return;
if (cfdata->unit_method == FAHRENHEIT)
{
e_widget_slider_value_range_set(cfdata->o_low, 0, 200);
e_widget_slider_value_range_set(cfdata->o_high, 0, 230);
e_widget_slider_value_int_get(cfdata->o_low, &val);
e_widget_slider_value_int_set(cfdata->o_low, CEL_2_FAR(val));
e_widget_slider_value_int_get(cfdata->o_high, &val);
e_widget_slider_value_int_set(cfdata->o_high, CEL_2_FAR(val));
e_widget_slider_value_format_display_set(cfdata->o_low, _("%1.0f F"));
e_widget_slider_value_format_display_set(cfdata->o_high, _("%1.0f F"));
}
else
{
e_widget_slider_value_range_set(cfdata->o_low, 0, 95);
e_widget_slider_value_range_set(cfdata->o_high, 0, 110);
e_widget_slider_value_int_get(cfdata->o_low, &val);
e_widget_slider_value_int_set(cfdata->o_low, FAR_2_CEL(val));
e_widget_slider_value_int_get(cfdata->o_high, &val);
e_widget_slider_value_int_set(cfdata->o_high, FAR_2_CEL(val));
e_widget_slider_value_format_display_set(cfdata->o_low, _("%1.0f C"));
e_widget_slider_value_format_display_set(cfdata->o_high, _("%1.0f C"));
}
}