Enlightenment CVS committal

Author  : englebass
Project : e17
Module  : apps/e

Dir     : e17/apps/e/src/modules/temperature


Modified Files:
        e_mod_main.c e_mod_main.h 


Log Message:
We need id's for gadgets which are independent of shelves, so if we move
a gadget from one shelf to another it will keep the same config. Since the
id is mainly for the module to find the appropriate config for a gadget,
the module is now responsible for creating id's for gadgets config. One
problem is that we no longer can trust the id of a gadget, so we need to
store a reference between a gadget and its config after startup. No big
deal.

===================================================================
RCS file: /cvs/e/e17/apps/e/src/modules/temperature/e_mod_main.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -3 -r1.85 -r1.86
--- e_mod_main.c        25 Jul 2007 17:00:51 -0000      1.85
+++ e_mod_main.c        16 Sep 2007 00:02:53 -0000      1.86
@@ -17,13 +17,15 @@
 static void _gc_orient(E_Gadcon_Client *gcc);
 static char *_gc_label(void);
 static Evas_Object *_gc_icon(Evas *evas);
+static const char *_gc_id_new(void);
+static void _gc_id_del(const char *id);
 /* and actually define the gadcon class that this module provides (just 1) */
 static const E_Gadcon_Client_Class _gadcon_class =
 {
    GADCON_CLIENT_CLASS_VERSION,
      "temperature",
      {
-        _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon
+        _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, 
_gc_id_del
      },
    E_GADCON_CLIENT_STYLE_PLAIN
 };
@@ -42,6 +44,7 @@
 static void _temperature_face_cb_menu_configure(void *data, E_Menu *m, 
E_Menu_Item *mi);
 
 static Evas_Bool _temperature_face_shutdown(Evas_Hash *hash, const char *key, 
void *hdata, void *fdata);
+static Evas_Bool _temperature_face_id_max(Evas_Hash *hash, const char *key, 
void *hdata, void *fdata);
 
 static E_Config_DD *conf_edd = NULL;
 static E_Config_DD *conf_face_edd = NULL;
@@ -59,7 +62,7 @@
    if (!inst)
      {
        inst = E_NEW(Config_Face, 1);
-       temperature_config->faces = evas_hash_add(temperature_config->faces, 
id, inst);
+       inst->id = evas_stringshare_add(id);
        inst->poll_time = 10.0;
        inst->low = 30;
        inst->high = 80;
@@ -67,7 +70,9 @@
        inst->sensor_name = NULL;
        inst->sensor_path = NULL;
        inst->units = CELCIUS;
+       temperature_config->faces = 
evas_hash_direct_add(temperature_config->faces, inst->id, inst);
      }
+   if (!inst->id) evas_stringshare_add(id);
    E_CONFIG_LIMIT(inst->poll_time, 0.5, 1000.0);
    E_CONFIG_LIMIT(inst->low, 0, 100);
    E_CONFIG_LIMIT(inst->high, 0, 220);
@@ -139,6 +144,45 @@
    edje_object_file_set(o, buf, "icon");
    return o;
 }
+
+static const char *
+_gc_id_new(void)
+{
+   Config_Face *inst;
+   char         id[128];
+   int          num = 0;
+
+   evas_hash_foreach(temperature_config->faces, _temperature_face_id_max, 
&num);
+   snprintf(id, sizeof(id), "%s.%d", _gadcon_class.name, num + 1);
+
+   inst = E_NEW(Config_Face, 1);
+   inst->id = evas_stringshare_add(id);
+   inst->poll_time = 10.0;
+   inst->low = 30;
+   inst->high = 80;
+   inst->sensor_type = SENSOR_TYPE_NONE;
+   inst->sensor_name = NULL;
+   inst->sensor_path = NULL;
+   inst->units = CELCIUS;
+   temperature_config->faces = evas_hash_direct_add(temperature_config->faces, 
inst->id, inst);
+   return inst->id;
+}
+
+static void
+_gc_id_del(const char *id)
+{
+   Config_Face *inst;
+
+   inst = evas_hash_find(temperature_config->faces, id);
+   if (inst)
+     {
+       temperature_config->faces = evas_hash_del(temperature_config->faces, 
id, inst);
+       if (inst->sensor_name) evas_stringshare_del(inst->sensor_name);
+       if (inst->sensor_path) evas_stringshare_del(inst->sensor_path);
+       free(inst);
+     }
+}
+
 /**/
 /***************************************************************************/
 
@@ -525,10 +569,25 @@
 
    if (inst->sensor_name) evas_stringshare_del(inst->sensor_name);
    if (inst->sensor_path) evas_stringshare_del(inst->sensor_path);
+   if (inst->id) evas_stringshare_del(inst->id);
    free(inst);
    return 1;
 }
 
+static Evas_Bool
+_temperature_face_id_max(Evas_Hash *hash, const char *key, void *hdata, void 
*fdata)
+{
+   const char *p;
+   int        *max;
+   int         num = -1;
+
+   max = (int *)fdata;
+   p = strrchr(key, '.');
+   if (p) num = atoi(p + 1);
+   if (num > *max) *max = num;
+   return 1;
+}
+
 void 
 temperature_face_update_config(Config_Face *inst)
 {
@@ -595,6 +654,7 @@
    return result;
 }
 
+
 /***************************************************************************/
 /**/
 /* module setup */
@@ -612,6 +672,7 @@
 #undef D
 #define T Config_Face
 #define D conf_face_edd
+   E_CONFIG_VAL(D, T, id, STR);
    E_CONFIG_VAL(D, T, poll_time, DOUBLE);
    E_CONFIG_VAL(D, T, low, INT);
    E_CONFIG_VAL(D, T, high, INT);
===================================================================
RCS file: /cvs/e/e17/apps/e/src/modules/temperature/e_mod_main.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -3 -r1.29 -r1.30
--- e_mod_main.h        16 Jul 2007 21:27:22 -0000      1.29
+++ e_mod_main.h        16 Sep 2007 00:02:53 -0000      1.30
@@ -27,6 +27,7 @@
 
 struct _Config_Face
 {
+   const char      *id;
    /* saved * loaded config values */
    double           poll_time;
    int              low, high;



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to