Enlightenment CVS committal

Author  : englebass
Project : e_modules
Module  : weather

Dir     : e_modules/weather


Modified Files:
        e_mod_main.c 


Log Message:
Implement id_new()

===================================================================
RCS file: /cvs/e/e_modules/weather/e_mod_main.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -3 -r1.57 -r1.58
--- e_mod_main.c        16 Sep 2007 00:28:42 -0000      1.57
+++ e_mod_main.c        16 Sep 2007 03:31:42 -0000      1.58
@@ -8,6 +8,7 @@
 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 E_Config_DD *conf_edd = NULL;
 static E_Config_DD *conf_item_edd = NULL;
@@ -17,7 +18,7 @@
 /* Define Gadcon Class */
 static const E_Gadcon_Client_Class _gadcon_class = {
   GADCON_CLIENT_CLASS_VERSION,
-  "weather", {_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon},
+  "weather", {_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, 
_gc_id_new, NULL},
   E_GADCON_CLIENT_STYLE_PLAIN
 };
 
@@ -189,6 +190,15 @@
   return o;
 }
 
+static const char *
+_gc_id_new (void)
+{
+   Config_Item *ci;
+
+   ci = _weather_config_item_get (NULL);
+   return ci->id;
+}
+
 static void
 _weather_cb_mouse_down (void *data, Evas * e, Evas_Object * obj,
                        void *event_info)
@@ -249,28 +259,47 @@
 static Config_Item *
 _weather_config_item_get (const char *id)
 {
-  Evas_List *l;
-  Config_Item *ci;
-
-  for (l = weather_config->items; l; l = l->next)
-    {
-      ci = l->data;
-      if (!ci->id)
-       continue;
-      if (!strcmp (ci->id, id))
-       return ci;
-    }
-
-  ci = E_NEW (Config_Item, 1);
-  ci->id = evas_stringshare_add (id);
-  ci->poll_time = 900.0;
-  ci->display = 0;
-  ci->degrees = DEGREES_F;
-  ci->host = evas_stringshare_add ("www.rssweather.com");
-  ci->code = evas_stringshare_add ("KJFK");
+   Evas_List *l;
+   Config_Item *ci;
+   char buf[128];
+
+   if (!id)
+     {
+       int  num = 0;
+
+       /* Create id */
+       if (weather_config->items)
+         {
+            const char *p;
+            ci = evas_list_last (weather_config->items)->data;
+            p = strrchr (ci->id, '.');
+            if (p) num = atoi (p + 1) + 1;
+         }
+       snprintf (buf, sizeof (buf), "%s.%d", _gadcon_class.name, num);
+       id = buf;
+     }
+   else
+     {
+       for (l = weather_config->items; l; l = l->next)
+         {
+            ci = l->data;
+            if (!ci->id)
+              continue;
+            if (!strcmp (ci->id, id))
+              return ci;
+         }
+     }
+
+   ci = E_NEW (Config_Item, 1);
+   ci->id = evas_stringshare_add (id);
+   ci->poll_time = 900.0;
+   ci->display = 0;
+   ci->degrees = DEGREES_F;
+   ci->host = evas_stringshare_add ("www.rssweather.com");
+   ci->code = evas_stringshare_add ("KJFK");
 
-  weather_config->items = evas_list_append (weather_config->items, ci);
-  return ci;
+   weather_config->items = evas_list_append (weather_config->items, ci);
+   return ci;
 }
 
 /* Gadman Module Setup */



-------------------------------------------------------------------------
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