Hi, here's the result of my first work on E's internals (and widgets):
i wrote a simple addon that allow to select a wallpaper directly from
get-e.org, actually only from static backgrounds.

 Requirements:
ecore_file with libcurl support(updated > 14 january)

How it works:
My module get and parse a RSS feed from get-e.org, obtaining a list of
images of static backgrounds that actually are available on get-e.org,
downloading all images and shows it in efm. When you choose an image
and click OK, the module get the real background you've choose,
already in edj format, and copy it into ~/.e/e/backgrounds. Now the
new wallpaper is available in the first window of wallpaper
configuration dialog.

Status:
This is a preview. It works (just tested 5 minutes ago), and it works
fine also without DSL connection (i'm testing it with GPRS/UMTS). I'm
sure that something can be done in a better way, and it miss some cool
features, like caching of results to avoid useless connections, and
proxy support (i'm not sure but i think that it will be done by
libcurl internals).

Todo:
Implement a way to use a image cache to avoid connections
Test in proxy environment
Animated backgrounds support
Other sites support (Flickr,DeviantArt,...)

Thanks:
devilhorns and morlenxus for initial support, exhibit's guys for
example code, raster for enthusiasm, kainx and englebass for support
to make the attached diff :)

If you like this way to get backgrounds from get-e.org, there's two
other things that can be done easily in the same way: 0) animated
backgrounds, 1) themes.
Feel free to send a comment, to hate/love/commit it.

Regards

Massimiliano
Index: Makefile.am
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/modules/conf_wallpaper/Makefile.am,v
retrieving revision 1.1
diff -u -r1.1 Makefile.am
--- Makefile.am	4 Jul 2007 15:09:24 -0000	1.1
+++ Makefile.am	17 Jan 2008 22:44:43 -0000
@@ -25,7 +25,9 @@
 			 e_int_config_wallpaper_gradient.h \
 			 e_int_config_wallpaper.h \
 			 e_int_config_wallpaper_import.c \
-			 e_int_config_wallpaper_import.h
+			 e_int_config_wallpaper_import.h \
+			 e_int_config_wallpaper_web.c \
+			 e_int_config_wallpaper_web.h
 
 module_la_LIBADD       = @e_libs@ @dlopen_libs@
 module_la_LDFLAGS      = -module -avoid-version
Index: e_int_config_wallpaper.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/modules/conf_wallpaper/e_int_config_wallpaper.c,v
retrieving revision 1.8
diff -u -r1.8 e_int_config_wallpaper.c
--- e_int_config_wallpaper.c	14 Dec 2007 16:34:47 -0000	1.8
+++ e_int_config_wallpaper.c	17 Jan 2008 22:44:46 -0000
@@ -55,6 +55,7 @@
    /* dialogs */
    E_Win *win_import;
    E_Dialog *dia_gradient;
+   E_Dialog *dia_web;
 };
 
 EAPI E_Config_Dialog *
@@ -151,6 +152,15 @@
    cfdata->dia_gradient = NULL;
 }
 
+EAPI void
+e_int_config_wallpaper_web_done(E_Config_Dialog *dia)
+{
+   E_Config_Dialog_Data *cfdata;
+
+   cfdata = dia->cfdata;
+   cfdata->dia_web = NULL;
+}
+
 EAPI void 
 e_int_config_wallpaper_handler_set(Evas_Object *obj, const char *path, void *data) 
 {
@@ -381,6 +391,18 @@
 }
 
 static void
+_cb_web(void *data1, void *data2)
+{
+   E_Config_Dialog_Data *cfdata;
+
+   cfdata = data1;
+   if (cfdata->dia_web)
+      e_win_raise(cfdata->dia_web->win);
+   else
+      cfdata->dia_web = e_int_config_wallpaper_web(cfdata->cfd);   
+}
+
+static void
 _fill_data(E_Config_Dialog_Data *cfdata)
 {
    char path[4096];
@@ -460,6 +482,8 @@
      e_int_config_wallpaper_del(cfdata->win_import);
    if (cfdata->dia_gradient) 
      e_int_config_wallpaper_gradient_del(cfdata->dia_gradient);
+   if (cfdata->dia_web)
+     e_int_config_wallpaper_web_del(cfdata->dia_web);
    E_FREE(cfdata->bg);
    E_FREE(cfd->data);
    E_FREE(cfdata);
@@ -558,6 +582,12 @@
    ow = e_widget_button_add(evas, _("Gradient..."), "enlightenment/gradient",
 			    _cb_gradient, cfdata, NULL);
    e_widget_table_object_append(ot, ow, 1, 1, 1, 1, 1, 0, 0, 0);
+   if (ecore_file_download_protocol_available("http://";))
+   {
+      ow = e_widget_button_add(evas, _("Website..."), "enlightenment/website",
+			       _cb_web, cfdata, NULL);
+      e_widget_table_object_append(ot, ow, 2, 1, 1, 1, 1, 0, 0, 0);
+   }
 
    mw = 320;
    mh = (320 * zone->h) / zone->w;
@@ -704,6 +734,12 @@
    ow = e_widget_button_add(evas, _("Gradient..."), "enlightenment/gradient",
 			    _cb_gradient, cfdata, NULL);
    e_widget_table_object_append(ot, ow, 1, 1, 1, 1, 1, 0, 0, 0);
+   if (ecore_file_download_protocol_available("http://";))
+   {
+      ow = e_widget_button_add(evas, _("Website..."), "enlightenment/website",
+			       _cb_web, cfdata, NULL);
+      e_widget_table_object_append(ot, ow, 2, 1, 1, 1, 1, 0, 0, 0);
+   }
 
    mw = 320;
    mh = (320 * zone->h) / zone->w;
Index: e_int_config_wallpaper_web.c
===================================================================
RCS file: e_int_config_wallpaper_web.c
diff -N e_int_config_wallpaper_web.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ e_int_config_wallpaper_web.c	17 Jan 2008 22:44:48 -0000
@@ -0,0 +1,454 @@
+/*
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
+#include "e.h"
+#include "e_mod_main.h"
+#include "stdlib.h"
+#include "string.h"
+#include "Ecore_File.h"
+
+typedef struct _Import Import;
+
+struct _Import {
+   E_Config_Dialog *parent;
+   E_Config_Dialog_Data *cfdata;
+   E_Dialog *dia;
+};
+
+struct _E_Config_Dialog_Data 
+{
+   Evas_Object *ofm;
+   Evas_Object *o;
+   Evas_Object *osfm;
+   
+   FILE *edjfh; 
+   E_Dialog *dia;
+   Ecore_Hash *hash; 
+   char *edj;
+   int img_count;
+   int ready_for_edj;
+   int curl_pending;
+};
+
+static void _gete_static_cb_sel(void *data, E_Dialog *dia);
+void	    _gete_static_cb_parse_feed(void *data, const char *file, int status);
+void	    _gete_static_cb_image_complete(void *data, const char *file, int status);
+int	    _gete_static_cb_edj_progress(void *data, const char *file, long int dltotal, long int dlnow, long int ultotal, long int ulnow);
+void	    _gete_static_cb_edj_complete(void *data, const char *file, int status);
+static void _gete_static_get_tmp_images(E_Config_Dialog_Data *cfdata);
+static void _import_cb_dia_del(void *obj);
+static void _import_cb_close(void *data, E_Dialog *dia);
+static void _import_cb_ok(void *data, E_Dialog *dia);
+static void _import_edj_download(Import *import);
+static void _cb_file_double_click(void *data, Evas_Object *obj, void *ev_info);
+static void _cb_file_click(void *data, Evas_Object *obj, void *ev_info);
+
+EAPI E_Dialog *
+e_int_config_wallpaper_web(E_Config_Dialog *parent)
+{
+   Evas *evas;
+   E_Dialog *dia;
+   Import *import;
+   E_Config_Dialog_Data *cfdata;
+
+   Evas_Object *o, *ol, *of, *ofm, *osfm, *otl;
+   Evas_Coord mw, mh; 
+   E_Fm2_Config fmc;
+
+   import = E_NEW(Import, 1);
+   if (!import) 
+      return NULL;
+
+   dia = e_dialog_new(parent->con, "E", "_wallpaper_web_dialog");
+   if (!dia) 
+   { 
+      free(import);
+      return NULL;	
+   }
+
+   if (ecore_file_is_dir("/tmp/conf_wallpaper"))
+   {
+      ecore_file_recursive_rm("/tmp/conf_wallpaper");
+      ecore_file_mkdir("/tmp/conf_wallpaper");
+   }
+
+   dia->data = import;
+   e_object_del_attach_func_set(E_OBJECT(dia), _import_cb_dia_del);
+   e_win_centered_set(dia->win, 1);
+
+   evas = e_win_evas_get(dia->win);
+
+   cfdata = E_NEW(E_Config_Dialog_Data, 1);
+
+   cfdata->img_count = 0;
+   cfdata->ready_for_edj = 0;
+   cfdata->curl_pending = 0;
+   import->cfdata = cfdata;
+   import->dia = dia;
+   cfdata->dia = dia;
+
+   import->parent = parent;
+
+   e_dialog_title_set(dia, _("Choose a website from list..."));
+
+   o = e_widget_list_add(evas, 0, 1);
+   cfdata->o = o;
+   cfdata->edjfh = tmpfile(); 
+   cfdata->hash = ecore_hash_new(ecore_str_hash, ecore_str_compare); 
+   of = e_widget_framelist_add(evas, "Websites", 1);
+   ol = e_widget_ilist_add(evas, 24, 24, NULL);
+   e_widget_ilist_append(ol, NULL, "get-e.org - Static",
+			 _gete_static_cb_sel, cfdata, NULL); // get-e.org static bg
+   //e_widget_ilist_append(ol, NULL, "kde-look.org", NULL, NULL, 0);
+   //e_widget_ilist_append(ol, NULL, "flickr.com", NULL, NULL, 0);
+   e_widget_ilist_go(ol);
+
+   e_widget_framelist_object_append(of, ol);
+   e_widget_list_object_append(o, of, 1, 1, 0.5);
+
+   ofm = e_fm2_add(evas);
+   memset(&fmc, 0, sizeof(E_Fm2_Config));
+   cfdata->ofm = ofm;
+   fmc.view.mode = E_FM2_VIEW_MODE_LIST;
+   fmc.view.open_dirs_in_place = 1;
+   fmc.view.selector = 1;
+   fmc.view.single_click = 0;
+   fmc.view.no_subdir_jump = 0;
+   fmc.icon.list.w = 48;
+   fmc.icon.list.h = 48;
+   fmc.icon.fixed.w = 1;
+   fmc.icon.fixed.h = 1;
+   fmc.icon.extension.show = 0;
+   fmc.icon.key_hint = NULL;
+   fmc.list.sort.no_case = 1;
+   fmc.list.sort.dirs.first = 0;
+   fmc.list.sort.dirs.last = 1;
+   fmc.selection.single = 1;
+   fmc.selection.windows_modifiers = 0;
+   e_fm2_config_set(ofm, &fmc);
+   e_fm2_icon_menu_flags_set(ofm, E_FM2_MENU_NO_SHOW_HIDDEN);
+   
+   evas_object_smart_callback_add(ofm, "selected", _cb_file_double_click, cfdata);   
+   evas_object_smart_callback_add(ofm, "selection_change", _cb_file_click, cfdata);
+   
+   osfm = e_widget_scrollframe_pan_add(evas, ofm,
+                                     e_fm2_pan_set,
+                                     e_fm2_pan_get,
+                                     e_fm2_pan_max_get,
+                                     e_fm2_pan_child_size_get);
+   cfdata->osfm = osfm;
+   ecore_file_mkdir("/tmp/conf_wallpaper");
+   e_fm2_path_set(cfdata->ofm, "/tmp/conf_wallpaper", "/");
+   e_widget_list_object_append(cfdata->o, cfdata->osfm, 1, 1, 0.5);
+   e_widget_min_size_set(osfm, 160, 160);
+
+   e_widget_min_size_get(o, &mw, &mh); 
+   e_dialog_content_set(dia, o, mw, mh);
+
+   e_dialog_button_add(dia, _("OK"), NULL, _import_cb_ok, cfdata);
+   e_dialog_button_add(dia, _("Cancel"), NULL, _import_cb_close, cfdata);
+   e_dialog_button_disable_num_set(dia, 0, 1);
+
+   e_dialog_resizable_set(dia, 1);
+   e_dialog_show(dia);
+   
+   e_dialog_border_icon_set(dia, "enlightenment/background");
+
+   return dia;
+}
+
+void
+e_int_config_wallpaper_web_del(E_Dialog *dia)
+{
+   Import *import;
+
+   import = dia->data;
+
+   e_int_config_wallpaper_web_done(import->parent); 
+   E_FREE(import->cfdata);
+   E_FREE(import);
+   e_object_unref(E_OBJECT(dia));
+}
+
+static void
+_gete_static_cb_sel(void *data, E_Dialog *dia)
+{
+   E_Config_Dialog_Data *cfdata;
+
+   cfdata = data;
+
+   if (ecore_file_exists("/tmp/gete.xml"))
+      ecore_file_unlink("/tmp/gete.xml");
+
+   e_dialog_title_set(cfdata->dia, "Getting feed...");
+   cfdata->curl_pending = 1;
+   if(ecore_file_download("http://www.get-e.org/Backgrounds/Static/feed.xml";, "/tmp/gete.xml", _gete_static_cb_parse_feed, NULL, cfdata))
+   //if(ecore_file_download("http://localhost/get_e_feed.xml";, "/tmp/gete.xml", _gete_static_cb_parse_feed, NULL, cfdata))
+      e_dialog_title_set(cfdata->dia, "Getting feed... DONE!");
+   else
+      e_dialog_title_set(cfdata->dia, "Getting feed... FAILED!");
+}
+
+void
+_gete_static_cb_parse_feed(void *data, const char *file, int status)
+{
+   E_Config_Dialog_Data *cfdata;
+   FILE *fh;
+   char instr[255];
+   char *edj = NULL;
+   char *img = NULL;
+   char *tmpstr;
+   char *tinstr;
+   char *timg;
+
+   int state = 0;
+
+   cfdata = data;
+
+   cfdata->curl_pending = 0;
+   fh = fopen("/tmp/gete.xml", "r");
+   while (fgets(instr, 255, fh) != NULL)
+   {
+      if (strstr(instr, "<item>") != NULL)
+      {
+	 edj = NULL;
+	 img = NULL;
+	 state = 1;      
+      }
+
+      if ((strstr(instr, "<link>") !=  NULL) && (state == 1))
+      {
+	 tinstr = strdup(instr); 
+	 edj = strtok(tinstr, ">");
+	 edj = strtok(NULL, "<");
+	 tmpstr = strrchr(ecore_file_file_get(edj), '.');
+	 if (strstr(tmpstr, "edj") != NULL)
+	    state = 2;
+	 
+	 free(tinstr);
+      }
+
+      if ((strstr(instr, "<enclosure") != NULL) && (state == 2))
+      {
+	 tinstr = strdup(instr); 
+         img = strtok(tinstr, "\"");
+         img = strtok(NULL, "\"");
+	 strcat(img, "\n");
+	 state = 3;
+
+	 free(tinstr);
+      } 
+
+      if ((strstr(instr, "</item>") != NULL) && (state == 3))
+      {
+	 timg = strdup(img);
+	 fputs(strtok(timg, "\n"), cfdata->edjfh);
+	 fputs("$", cfdata->edjfh);
+	 fputs(edj, cfdata->edjfh);
+	 fputs("$\n", cfdata->edjfh);
+	 cfdata->img_count++;
+	 state = 0;
+   
+	 free(timg);
+      }
+
+   }
+
+   fclose(fh);
+   e_dialog_title_set(cfdata->dia, "Parsing feed... DONE!");
+   rewind(cfdata->edjfh);
+  
+   _gete_static_get_tmp_images(cfdata);
+
+   //e_dialog_button_disable_num_set(cfdata->dia, 0, 0); 
+   // Moved, I enable OK button only when all images are downloaded
+}
+
+static void
+_gete_static_get_tmp_images(E_Config_Dialog_Data *cfdata) 
+{
+   char instr[255];
+   char tmpurl[255];
+   char tmpimg[255];
+   char tmpedj[255];
+   
+   cfdata->curl_pending = 1;
+   while(fgets(instr, 255, cfdata->edjfh) != NULL)
+   {
+      snprintf(tmpimg, sizeof(tmpimg), "%s", ecore_file_file_get(strtok(instr, "$")));
+      snprintf(tmpurl, sizeof(tmpurl), "/tmp/conf_wallpaper/%s", tmpimg);
+      snprintf(tmpedj, sizeof(tmpedj), "%s", strtok(NULL, "$"));
+      ecore_file_download(instr, tmpurl, _gete_static_cb_image_complete, NULL, cfdata);
+      ecore_hash_set(cfdata->hash, 
+		     (void *)ecore_string_instance(tmpimg), 
+		     (void *)ecore_string_instance(tmpedj));
+   }
+
+}
+
+static void
+_import_cb_dia_del(void *obj)
+{
+   E_Dialog *dia = obj;
+   
+   e_int_config_wallpaper_web_del(dia);
+}
+
+static void 
+_cb_file_double_click(void *data, Evas_Object *obj, void *ev_info)
+{
+   /*E_Config_Dialog_Data *cfdata;
+   Evas_List *sels;
+   E_Fm2_Icon_Info *icon_info;
+
+   cfdata = data;
+   sels = e_fm2_selected_list_get(cfdata->ofm);
+   if (!sels)
+      return;
+   icon_info = sels->data;
+   printf("[double click] %s\n", icon_info->file);*/
+   
+   // Unused atm, interesting to simulate click on Ok button
+}
+
+static void 
+_cb_file_click(void *data, Evas_Object *obj, void *ev_info)
+{
+   E_Config_Dialog_Data *cfdata;
+   Evas_List *sels;
+   E_Fm2_Icon_Info *icon_info;
+
+   cfdata = data;
+   sels = e_fm2_selected_list_get(cfdata->ofm);
+   if (!sels)
+      return;
+   if (cfdata->ready_for_edj == 0)
+      return;
+   icon_info = sels->data;
+   cfdata->edj = ecore_hash_get(cfdata->hash, icon_info->file);
+}
+
+static void 
+_import_cb_close(void *data, E_Dialog *dia) 
+{
+   E_Config_Dialog_Data *cfdata;
+   
+   cfdata = data;
+   if (cfdata->curl_pending == 1)
+   {
+      ecore_file_download_abort_all();
+   }      
+   ecore_file_download_shutdown();
+   e_int_config_wallpaper_web_del(dia);
+}
+
+static void 
+_import_cb_ok(void *data, E_Dialog *dia)
+{
+   Import *import;
+   E_Config_Dialog_Data *cfdata;
+   Evas_List *sels;
+
+   import = dia->data;
+   cfdata = data;
+   sels = e_fm2_selected_list_get(cfdata->ofm);
+   if (sels)
+   {
+      _import_edj_download(import);
+      return;
+   }
+
+   e_int_config_wallpaper_web_del(dia);
+}
+
+static void 
+_import_edj_download(Import *import)
+{
+   Import *i;
+   E_Config_Dialog_Data *cfdata;
+   int num = 0;
+   const char *file;
+   const char *homedir;
+   char buf[4096];
+
+   i = import;
+   cfdata = i->cfdata;
+   
+   cfdata->curl_pending = 1;
+   file = ecore_file_file_get(cfdata->edj);
+   homedir = e_user_homedir_get();
+   snprintf(buf, sizeof(buf), "%s/.e/e/backgrounds/%s", homedir, file);
+   e_dialog_title_set(cfdata->dia, "Downloading of edje file...");
+   ecore_file_download(cfdata->edj, buf,
+		       _gete_static_cb_edj_complete,
+		       _gete_static_cb_edj_progress,
+		       import);
+}  
+
+void 
+_gete_static_cb_edj_complete(void *data, const char *file, int status)
+{
+   Import *import;
+   char dest[4096];
+
+   import = data;
+   import->cfdata->curl_pending = 0;
+   snprintf(dest, sizeof(dest), 
+	    "%s/.e/e/backgrounds/%s", 
+	    e_user_homedir_get(), 
+	    ecore_file_file_get(import->cfdata->edj));   
+   e_int_config_wallpaper_update(import->parent, dest);
+   e_int_config_wallpaper_web_del(import->dia);   
+}
+
+void
+_gete_static_cb_image_complete(void *data, const char *file, int status)
+{
+   E_Config_Dialog_Data *cfdata;
+   char title[1024];
+   static int got = 0;
+   
+   cfdata = data;
+   if (got + 1 > cfdata->img_count)
+   {
+      got = 0;
+   } else if (got + 1 < cfdata->img_count)
+   {
+      snprintf(title, sizeof(title), "Download %d images of %d", ++got, cfdata->img_count);
+      e_dialog_title_set(cfdata->dia, title);
+      cfdata->ready_for_edj = 0;
+   } else
+   {
+      cfdata->curl_pending = 0;
+      cfdata->ready_for_edj = 1;
+      e_dialog_title_set(cfdata->dia, "Choose an image from list");
+      e_dialog_button_disable_num_set(cfdata->dia, 0, 0); 
+   }
+}
+
+int
+_gete_static_cb_edj_progress(void *data, const char *file, long int dltotal, long int dlnow, long int ultotal, long int ulnow)
+{
+   Import *import;
+   double status;
+   char title[45];
+   static long int last;
+
+   import = data;
+   
+   if (dlnow == 0 || dltotal == 0)
+      return 0;
+
+   if (last)
+   {
+      status = (double) ((double) dlnow) / ((double) dltotal);
+      snprintf(title, sizeof(title), "Downloading of edje file... %d%% done", 
+	       (int) (status * 100.0)),
+      e_dialog_title_set(import->cfdata->dia, title);
+   }
+
+   last = dlnow;
+   
+   return 0;
+}
+
Index: e_int_config_wallpaper_web.h
===================================================================
RCS file: e_int_config_wallpaper_web.h
diff -N e_int_config_wallpaper_web.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ e_int_config_wallpaper_web.h	17 Jan 2008 22:44:48 -0000
@@ -0,0 +1,10 @@
+#ifdef E_TYPEDEFS
+#else
+#ifndef E_INT_CONFIG_WALLPAPER_WEB_H
+#define E_INT_CONFIG_WALLPAPER_WEB_H
+
+EAPI E_Dialog *e_int_config_wallpaper_web(E_Config_Dialog *parent);
+EAPI void      e_int_config_wallpaper_web_del(E_Dialog *dia);
+    
+#endif
+#endif
Index: e_mod_main.h
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/modules/conf_wallpaper/e_mod_main.h,v
retrieving revision 1.2
diff -u -r1.2 e_mod_main.h
--- e_mod_main.h	31 Oct 2007 12:23:12 -0000	1.2
+++ e_mod_main.h	17 Jan 2008 22:44:48 -0000
@@ -8,10 +8,12 @@
 #include "e_int_config_wallpaper.h"
 #include "e_int_config_wallpaper_import.h"
 #include "e_int_config_wallpaper_gradient.h"
+#include "e_int_config_wallpaper_web.h"
 #undef E_TYPEDEFS
 #include "e_int_config_wallpaper.h"
 #include "e_int_config_wallpaper_import.h"
 #include "e_int_config_wallpaper_gradient.h"
+#include "e_int_config_wallpaper_web.h"
 
 EAPI extern E_Module_Api e_modapi;
 
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to