aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/temperature/e_mod_main.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2006-04-20 11:30:25 +0000
committerCarsten Haitzler <raster@rasterman.com>2006-04-20 11:30:25 +0000
commitfbd972cdb9542663483c2f221e5424aebd286839 (patch)
treedf9a990ba980618fcc5a5d8a6aabca241db78071 /src/modules/temperature/e_mod_main.c
parente packages fixed up (diff)
downloadenlightenment-fbd972cdb9542663483c2f221e5424aebd286839.tar.gz
e packages build again - also not much point having an enlightenment-data as
it's built as an arch specific package and it is intrinsically required by e and cannot work without it nor is the data shared betwene e and other apps unless e itself is installed too SVN revision: 22260
Diffstat (limited to 'src/modules/temperature/e_mod_main.c')
-rw-r--r--src/modules/temperature/e_mod_main.c491
1 files changed, 245 insertions, 246 deletions
diff --git a/src/modules/temperature/e_mod_main.c b/src/modules/temperature/e_mod_main.c
index 1ad5a57da..9cde248f0 100644
--- a/src/modules/temperature/e_mod_main.c
+++ b/src/modules/temperature/e_mod_main.c
@@ -3,255 +3,153 @@
*/
#include "e.h"
#include "e_mod_main.h"
-#include "e_mod_config.h"
#ifdef __FreeBSD__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
-/* TODO List:
- *
- * which options should be in main menu, and which in face menu?
- */
-
-/* module private routines */
-static Temperature *_temperature_new();
-static void _temperature_free(Temperature *e);
-static int _temperature_cb_check(void *data);
-
-static void _temperature_face_init(void *data, E_Gadget_Face *face);
-static void _temperature_face_free(void *data, E_Gadget_Face *face);
-
-static void _temperature_face_level_set(E_Gadget_Face *face, double level);
-
-static E_Config_DD *conf_edd;
-static E_Config_DD *conf_face_edd;
-
-/* public module routines. all modules must have these */
-EAPI E_Module_Api e_modapi =
+/***************************************************************************/
+/**/
+/* gadcon requirements */
+static E_Gadcon_Client *_gc_init(E_Gadcon *gc, char *name, char *id, char *style);
+static void _gc_shutdown(E_Gadcon_Client *gcc);
+static void _gc_orient(E_Gadcon_Client *gcc);
+/* and actually define the gadcon class that this module provides (just 1) */
+static const E_Gadcon_Client_Class _gadcon_class =
{
- E_MODULE_API_VERSION,
- "Temperature"
+ GADCON_CLIENT_CLASS_VERSION,
+ "temperature",
+ {
+ _gc_init, _gc_shutdown, _gc_orient
+ }
};
+/**/
+/***************************************************************************/
-EAPI void *
-e_modapi_init(E_Module *m)
-{
- E_Gadget *gad = NULL;
- E_Gadget_Api *api;
- Temperature *e;
-
- e = _temperature_new();
-
- /* set up our actual gadget */
- api = E_NEW(E_Gadget_Api, 1);
- api->module = m;
- api->name = "temperature";
- api->func_face_init = _temperature_face_init;
- api->func_face_free = _temperature_face_free;
- api->data = e;
-
- gad = e_gadget_new(api);
- E_FREE(api);
-
- /* start the timer */
- e->gad = gad;
- e->temperature_check_timer = ecore_timer_add(e->conf->poll_time, _temperature_cb_check, gad);
- return gad;
-}
-
-EAPI int
-e_modapi_shutdown(E_Module *m)
-{
- E_Gadget *gad;
- Temperature *e;
+/***************************************************************************/
+/**/
+/* actual module specifics */
- E_CONFIG_DD_FREE(conf_edd);
- E_CONFIG_DD_FREE(conf_face_edd);
+typedef struct _Instance Instance;
- gad = m->data;
- if (!gad) return 0;
- e = gad->data;
- if (e)
- {
- if (e->config_dialog)
- {
- e_object_del(E_OBJECT(e->config_dialog));
- e->config_dialog = NULL;
- }
- _temperature_free(e);
- }
- e_object_del(E_OBJECT(gad));
- return 1;
-}
-
-EAPI int
-e_modapi_save(E_Module *m)
+struct _Instance
{
- E_Gadget *gad;
- Temperature *e;
-
- gad = m->data;
- if (!gad) return 0;
- e = gad->data;
- if (!e) return 0;
- e_config_domain_save("module.temperature", conf_edd, e->conf);
- return 1;
-}
+ E_Gadcon_Client *gcc;
+ Evas_Object *o_temp;
+};
-EAPI int
-e_modapi_info(E_Module *m)
-{
- char buf[4096];
+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);
+static int _temperature_cb_check(void *data);
+static void _temperature_face_level_set(Instance *inst, double level);
+static void _temperature_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi);
- snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
- m->icon_file = strdup(buf);
- return 1;
-}
+static E_Config_DD *conf_edd = NULL;
-EAPI int
-e_modapi_about(E_Module *m)
-{
- e_module_dialog_show(_("Enlightenment Temperature Module"),
- _("A module to measure the <hilight>ACPI Thermal sensor</hilight> on Linux.<br>"
- "It is especially useful for modern Laptops with high speed<br>"
- "CPUs that generate a lot of heat."));
- return 1;
-}
+Config *temperature_config = NULL;
-EAPI int
-e_modapi_config(E_Module *m)
+static E_Gadcon_Client *
+_gc_init(E_Gadcon *gc, char *name, char *id, char *style)
{
- E_Gadget *gad;
- Temperature *e;
+ Evas_Object *o;
+ E_Gadcon_Client *gcc;
+ Instance *inst;
- gad = m->data;
- if (!gad) return 0;
- e = gad->data;
- _config_temperature_module(e_container_current_get(e_manager_current_get()), e);
-
- return 1;
+ inst = E_NEW(Instance, 1);
+
+ o = edje_object_add(gc->evas);
+ e_theme_edje_object_set(o, "base/theme/modules/temperature",
+ "modules/temperature/main");
+
+ gcc = e_gadcon_client_new(gc, name, id, style, o);
+ gcc->data = inst;
+
+ inst->gcc = gcc;
+ inst->o_temp = o;
+
+ evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
+ _button_cb_mouse_down, inst);
+ temperature_config->instances = evas_list_append(temperature_config->instances, inst);
+ temperature_config->have_temp = -1;
+ _temperature_cb_check(NULL);
+ return gcc;
}
-
-
-/* module private routines */
-static Temperature *
-_temperature_new()
+static void
+_gc_shutdown(E_Gadcon_Client *gcc)
{
- Temperature *e;
-
- e = E_NEW(Temperature, 1);
- if (!e) return NULL;
-
- /* create the config edd */
- conf_face_edd = E_CONFIG_DD_NEW("Temperature_Config_Face", Config_Face);
-#undef T
-#undef D
-#define T Config_Face
-#define D conf_face_edd
- E_CONFIG_VAL(D, T, enabled, UCHAR);
-
- conf_edd = E_CONFIG_DD_NEW("Temperature_Config", Config);
-#undef T
-#undef D
-#define T Config
-#define D conf_edd
- E_CONFIG_VAL(D, T, poll_time, DOUBLE);
- E_CONFIG_VAL(D, T, low, INT);
- E_CONFIG_VAL(D, T, high, INT);
- E_CONFIG_LIST(D, T, faces, conf_face_edd);
- E_CONFIG_VAL(D, T, sensor_name, STR);
- E_CONFIG_VAL(D, T, units, INT);
-
- e->conf = e_config_domain_load("module.temperature", conf_edd);
- if (!e->conf)
- {
- e->conf = E_NEW(Config, 1);
- e->conf->poll_time = 10.0;
- e->conf->low = 30;
- e->conf->high = 80;
- e->conf->sensor_name = "temp1";
- e->conf->units = CELCIUS;
- }
- E_CONFIG_LIMIT(e->conf->poll_time, 0.5, 1000.0);
- E_CONFIG_LIMIT(e->conf->low, 0, 100);
- E_CONFIG_LIMIT(e->conf->high, 0, 220);
- E_CONFIG_LIMIT(e->conf->units, CELCIUS, FAHRENHEIT);
-
- e->have_temp = -1;
-
- return e;
+ Instance *inst;
+
+ inst = gcc->data;
+ temperature_config->instances = evas_list_remove(temperature_config->instances, inst);
+ evas_object_del(inst->o_temp);
+ free(inst);
}
-void _temperature_face_init(void *data, E_Gadget_Face *face)
+static void
+_gc_orient(E_Gadcon_Client *gcc)
{
- Temperature *e;
- Temperature_Face *ef;
- E_Gadman_Policy policy;
-
- e = data;
-
- ef = E_NEW(Temperature_Face, 1);
- if (!ef) return;
-
- e_gadget_face_theme_set(face, "base/theme/modules/temperature",
- "modules/temperature/main");
-
- policy = E_GADMAN_POLICY_ANYWHERE |
- E_GADMAN_POLICY_HMOVE |
- E_GADMAN_POLICY_VMOVE |
- E_GADMAN_POLICY_HSIZE |
- E_GADMAN_POLICY_VSIZE;
-
- e_gadman_client_policy_set(face->gmc, policy);
-
- ef->conf = evas_list_nth(e->conf->faces, face->face_num);
- if (!ef->conf)
- {
- ef->conf = E_NEW(Config_Face, 1);
- ef->conf->enabled = 1;
- e->conf->faces = evas_list_append(e->conf->faces, ef->conf);
- }
-
- face->data = ef;
-
- _temperature_cb_check(face->gad);
-
- return;
+ Instance *inst;
+
+ inst = gcc->data;
+ e_gadcon_client_aspect_set(gcc, 16, 16);
+ e_gadcon_client_min_size_set(gcc, 16, 16);
}
+/**/
+/***************************************************************************/
+/***************************************************************************/
+/**/
static void
-_temperature_free(Temperature *e)
+_button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
- Evas_List *l;
-
- ecore_timer_del(e->temperature_check_timer);
-
- for (l = e->conf->faces; l; l = l->next)
- free(l->data);
- evas_list_free(e->conf->faces);
- free(e->conf);
- free(e);
+ Instance *inst;
+ Evas_Event_Mouse_Down *ev;
+
+ inst = data;
+ ev = event_info;
+ if ((ev->button == 3) && (!temperature_config->menu))
+ {
+ E_Menu *mn;
+ E_Menu_Item *mi;
+ int cx, cy, cw, ch;
+
+ mn = e_menu_new();
+ e_menu_post_deactivate_callback_set(mn, _menu_cb_post, inst);
+ temperature_config->menu = mn;
+
+ mi = e_menu_item_new(mn);
+ e_menu_item_label_set(mi, _("Configuration"));
+ e_util_menu_item_edje_icon_set(mi, "enlightenment/configuration");
+ e_menu_item_callback_set(mi, _temperature_face_cb_menu_configure, NULL);
+
+ e_gadcon_client_util_menu_items_append(inst->gcc, mn, 0);
+
+ e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon,
+ &cx, &cy, &cw, &ch);
+ e_menu_activate_mouse(mn,
+ 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);
+ evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
+ EVAS_BUTTON_NONE, ev->timestamp, NULL);
+ }
}
static void
-_temperature_face_free(void *data, E_Gadget_Face *face)
+_menu_cb_post(void *data, E_Menu *m)
{
- Temperature_Face *ef;
- ef = face->data;
-
- free(ef);
+ if (!temperature_config->menu) return;
+ e_object_del(E_OBJECT(temperature_config->menu));
+ temperature_config->menu = NULL;
}
static int
_temperature_cb_check(void *data)
{
- E_Gadget *gad;
- E_Gadget_Face *face;
- Temperature *t;
int ret = 0;
+ Instance *inst;
Ecore_List *therms;
Evas_List *l;
int temp = 0;
@@ -261,11 +159,6 @@ _temperature_cb_check(void *data)
int len;
#endif
- gad = data;
- if (!gad) return 0;
- t = gad->data;
- if (!t) return 0;
-
#ifdef __FreeBSD__
if (mib[0] == -1)
{
@@ -305,7 +198,7 @@ _temperature_cb_check(void *data)
{
char *name, *sensor;
- sensor = t->conf->sensor_name;
+ sensor = temperature_config->sensor_name;
if (!sensor) sensor = "temp1";
while ((name = ecore_list_next(therms)))
@@ -370,77 +263,183 @@ _temperature_cb_check(void *data)
}
#endif
- if (t->conf->units == FAHRENHEIT)
- temp = (temp * 9.0 / 5.0) + 32;
+ if (temperature_config->units == FAHRENHEIT)
+ temp = (temp * 9.0 / 5.0) + 32;
if (ret)
{
char *utf8;
- if (t->have_temp != 1)
+ if (temperature_config->have_temp != 1)
{
/* enable therm object */
- for (l = gad->faces; l; l = l->next)
+ for (l = temperature_config->instances; l; l = l->next)
{
- face = l->data;
- edje_object_signal_emit(face->main_obj, "known", "");
+ inst = l->data;
+ edje_object_signal_emit(inst->o_temp, "known", "");
}
- t->have_temp = 1;
+ temperature_config->have_temp = 1;
}
- if (t->conf->units == FAHRENHEIT)
+ if (temperature_config->units == FAHRENHEIT)
snprintf(buf, sizeof(buf), "%iF", temp);
else
snprintf(buf, sizeof(buf), "%iC", temp);
utf8 = ecore_txt_convert("iso-8859-1", "utf-8", buf);
- for (l = gad->faces; l; l = l->next)
+ for (l = temperature_config->instances; l; l = l->next)
{
- face = l->data;
- _temperature_face_level_set(face,
- (double)(temp - t->conf->low) /
- (double)(t->conf->high - t->conf->low));
-
- edje_object_part_text_set(face->main_obj, "reading", utf8);
+ inst = l->data;
+ _temperature_face_level_set(inst,
+ (double)(temp - temperature_config->low) /
+ (double)(temperature_config->high - temperature_config->low));
+ edje_object_part_text_set(inst->o_temp, "reading", utf8);
}
free(utf8);
}
else
{
- if (t->have_temp != 0)
+ if (temperature_config->have_temp != 0)
{
/* disable therm object */
- for (l = gad->faces; l; l = l->next)
-
+ for (l = temperature_config->instances; l; l = l->next)
{
- face = l->data;
- edje_object_signal_emit(face->main_obj, "unknown", "");
- edje_object_part_text_set(face->main_obj, "reading", "NO TEMP");
- _temperature_face_level_set(face, 0.5);
+ inst = l->data;
+ edje_object_signal_emit(inst->o_temp, "unknown", "");
+ edje_object_part_text_set(inst->o_temp, "reading", "NO TEMP");
+ _temperature_face_level_set(inst, 0.5);
}
- t->have_temp = 0;
+ temperature_config->have_temp = 0;
}
}
return 1;
}
static void
-_temperature_face_level_set(E_Gadget_Face *face, double level)
+_temperature_face_level_set(Instance *inst, double level)
{
Edje_Message_Float msg;
if (level < 0.0) level = 0.0;
else if (level > 1.0) level = 1.0;
msg.val = level;
- edje_object_message_send(face->main_obj, EDJE_MESSAGE_FLOAT, 1, &msg);
+ edje_object_message_send(inst->o_temp, EDJE_MESSAGE_FLOAT, 1, &msg);
+}
+
+static void
+_temperature_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi)
+{
+ if (!temperature_config) return;
+ if (temperature_config->config_dialog) return;
+ _config_temperature_module();
}
void
-_temperature_face_cb_config_updated(Temperature *temp)
+_temperature_face_cb_config_updated(void)
+{
+ ecore_timer_del(temperature_config->temperature_check_timer);
+ temperature_config->temperature_check_timer =
+ ecore_timer_add(temperature_config->poll_time, _temperature_cb_check,
+ NULL);
+}
+
+/***************************************************************************/
+/**/
+/* module setup */
+EAPI E_Module_Api e_modapi =
+{
+ E_MODULE_API_VERSION,
+ "Temperature"
+};
+
+EAPI void *
+e_modapi_init(E_Module *m)
+{
+ conf_edd = E_CONFIG_DD_NEW("Temperature_Config", Config);
+#undef T
+#undef D
+#define T Config
+#define D conf_edd
+ E_CONFIG_VAL(D, T, poll_time, DOUBLE);
+ E_CONFIG_VAL(D, T, low, INT);
+ E_CONFIG_VAL(D, T, high, INT);
+ E_CONFIG_VAL(D, T, sensor_name, STR);
+ E_CONFIG_VAL(D, T, units, INT);
+
+ temperature_config = e_config_domain_load("module.temperature", conf_edd);
+ if (!temperature_config)
+ {
+ temperature_config = E_NEW(Config, 1);
+ temperature_config->poll_time = 10.0;
+ temperature_config->low = 30;
+ temperature_config->high = 80;
+ temperature_config->sensor_name = evas_stringshare_add("temp1");
+ temperature_config->units = CELCIUS;
+ }
+ E_CONFIG_LIMIT(temperature_config->poll_time, 0.5, 1000.0);
+ E_CONFIG_LIMIT(temperature_config->low, 0, 100);
+ E_CONFIG_LIMIT(temperature_config->high, 0, 220);
+ E_CONFIG_LIMIT(temperature_config->units, CELCIUS, FAHRENHEIT);
+
+ temperature_config->have_temp = -1;
+ temperature_config->temperature_check_timer =
+ ecore_timer_add(temperature_config->poll_time, _temperature_cb_check,
+ NULL);
+ e_gadcon_provider_register(&_gadcon_class);
+ return 1;
+}
+
+EAPI int
+e_modapi_shutdown(E_Module *m)
{
- /* Call all funcs needed to handle update */
- ecore_timer_del(temp->temperature_check_timer);
- temp->temperature_check_timer = ecore_timer_add(temp->conf->poll_time, _temperature_cb_check, temp->gad);
+ e_gadcon_provider_unregister(&_gadcon_class);
+ if (temperature_config->config_dialog)
+ e_object_del(E_OBJECT(temperature_config->config_dialog));
+ if (temperature_config->temperature_check_timer)
+ ecore_timer_del(temperature_config->temperature_check_timer);
+ if (temperature_config->sensor_name)
+ evas_stringshare_del(temperature_config->sensor_name);
+ free(temperature_config);
+ temperature_config = NULL;
+ E_CONFIG_DD_FREE(conf_edd);
+ return 1;
+}
+
+EAPI int
+e_modapi_save(E_Module *m)
+{
+ e_config_domain_save("module.temperature", conf_edd, temperature_config);
+ return 1;
+}
+
+EAPI int
+e_modapi_info(E_Module *m)
+{
+ char buf[4096];
+
+ snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
+ m->icon_file = strdup(buf);
+ return 1;
}
+EAPI int
+e_modapi_about(E_Module *m)
+{
+ e_module_dialog_show(_("Enlightenment Temperature Module"),
+ _("A module to measure the <hilight>ACPI Thermal sensor</hilight> on Linux.<br>"
+ "It is especially useful for modern Laptops with high speed<br>"
+ "CPUs that generate a lot of heat."));
+ return 1;
+}
+
+EAPI int
+e_modapi_config(E_Module *m)
+{
+ if (!temperature_config) return 0;
+ if (temperature_config->config_dialog) return 0;
+ _config_temperature_module();
+ return 1;
+}
+/**/
+/***************************************************************************/