Enlightenment CVS committal

Author  : moom16
Project : e17
Module  : apps/eclair

Dir     : e17/apps/eclair/src


Modified Files:
        eclair.c eclair_cover.c eclair_utils.c eclair_utils.h 


Log Message:
* Remove some debug printfs
* Add support of covers located in the directory of the media file, such 
as "cover.png" or "folder.jpg"...

===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -3 -r1.22 -r1.23
--- eclair.c    1 Jul 2005 14:25:39 -0000       1.22
+++ eclair.c    2 Jul 2005 13:04:55 -0000       1.23
@@ -540,13 +540,6 @@
    emotion_object_position_set(eclair->video_object, eclair->seek_to_pos);
 }
 
-static void testff(void *data, Evas_Object *obj, const char *part)
-{
-   Evas_Coord x, y, w, h;
-   edje_object_part_geometry_get(obj, part, &x, &y, &w, &h);
-   printf("%s %p %s -> %d %d %d %d\n", part, obj, 
edje_object_part_text_get(obj, part), x, y, w, h);
-}
-
 //Create the gui window and load the edje theme
 static Evas_Bool _eclair_create_gui_window(Eclair *eclair)
 {
@@ -558,8 +551,6 @@
       _eclair_create_playlist_container_object(eclair, eclair->gui_window);
       _eclair_create_cover_object(eclair, eclair->gui_window);
       eclair_window_add_default_callbacks(eclair->gui_window, eclair);
-      edje_object_text_change_cb_set(eclair->gui_window->edje_object, testff, 
NULL);
-      printf("%p\n", eclair->gui_window->edje_object);
       return 1;
    }
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_cover.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- eclair_cover.c      10 Jun 2005 18:30:46 -0000      1.13
+++ eclair_cover.c      2 Jul 2005 13:04:55 -0000       1.14
@@ -17,6 +17,7 @@
 #define PACKET_CHUNK_SIZE 1024
 #define MAX_REQUEST_SIZE 1024
 #define NUM_EXTENSIONS 3
+#define NUM_COVER_NAMES 2
 
 typedef struct _Eclair_Cover_Packet_Chunk
 {
@@ -33,6 +34,7 @@
 const char *amazon_hostname = "webservices.amazon.com";
 const char *amazon_license_key = "0P1862RFDFSF4KYZQNG2";
 const char *cover_extensions[NUM_EXTENSIONS] = { "jpg", "jpeg", "png" };
+const char *cover_names[NUM_COVER_NAMES] = { "cover", "folder" };
 
 static int _eclair_cover_connect_to_hostname(const char *hostname);
 static int _eclair_cover_connect_to_host(const struct hostent *host);
@@ -42,6 +44,7 @@
 
 static char *_eclair_cover_build_path_from_filepath(Eclair_Cover_Manager 
*cover_manager, char *file_path, const char *cover_extension);
 static char *_eclair_cover_build_path_from_artist_album(Eclair_Cover_Manager 
*cover_manager, const char *artist, const char *album, const char 
*cover_extension);
+static char *_eclair_cover_build_cover_filename(const char *cover_name, const 
char *cover_extension);
 static void _eclair_cover_build_url_for_item_search(const char *keywords, char 
url[MAX_REQUEST_SIZE]);
 static void _eclair_cover_build_url_for_item_images(const char *ASIN, char 
url[MAX_REQUEST_SIZE]);
 static xmlNode *_eclair_cover_get_node_xml_tree(xmlNode *root_node, const char 
*prop);
@@ -194,31 +197,39 @@
 //NULL if failed. The returned path will have to be freed if success
 char *eclair_cover_file_get_from_local(Eclair_Cover_Manager *cover_manager, 
const char *artist, const char *album, char *file_path)
 {
-   char *cover_path;
-   int i;
+   char *cover_filename, *cover_path;
+   int i, j;
 
    for (i = 0; i < NUM_EXTENSIONS; i++)
    {
-      if ((cover_path = _eclair_cover_build_path_from_filepath(cover_manager, 
file_path, cover_extensions[i])))
-      {
-         if (ecore_file_exists(cover_path))
-            return cover_path;
-         free(cover_path);
-      }
+      if ((cover_path = _eclair_cover_build_path_from_filepath(cover_manager, 
file_path, cover_extensions[i]))
+         && ecore_file_exists(cover_path))
+         return cover_path;
+      free(cover_path);
    }
 
    for (i = 0; i < NUM_EXTENSIONS; i++)
    {
-      if ((cover_path = 
_eclair_cover_build_path_from_artist_album(cover_manager, artist, album, 
cover_extensions[i])))
+      if ((cover_path = 
_eclair_cover_build_path_from_artist_album(cover_manager, artist, album, 
cover_extensions[i]))
+         && ecore_file_exists(cover_path))
+         return cover_path;
+      free(cover_path);
+   }
+
+   for (i = 0; i < NUM_COVER_NAMES; i++)
+   {
+      for (j = 0; j < NUM_EXTENSIONS; j++)
       {
-         if (ecore_file_exists(cover_path))
+         if ((cover_filename = 
_eclair_cover_build_cover_filename(cover_names[i], cover_extensions[j]))
+            && (cover_path = eclair_utils_search_file(cover_filename, 
ecore_file_get_dir(file_path))))
+         {
+            free(cover_filename);
             return cover_path;
-         free(cover_path);
+         }
+         free(cover_filename);
       }
    }
 
-   //TODO: search if there is cover.jpg, or such file, in the directory of the 
file
-
    return NULL;
 }
 
@@ -540,13 +551,12 @@
 }
 
 //Build the cover file path from file_path and cover_extension
-//The returned path has to be freed by the caller
+//The returned path has to be freed
 static char *_eclair_cover_build_path_from_filepath(Eclair_Cover_Manager 
*cover_manager, char *file_path, const char *cover_extension)
 {
    char *cover_path, *filename_without_ext;
 
-   if (!cover_manager || !file_path || !cover_extension || 
!cover_manager->eclair
-      || strlen(file_path) <= 0 || strlen(cover_extension) <= 0)
+   if (!cover_manager || !file_path || !cover_extension || 
!cover_manager->eclair || strlen(file_path) <= 0)
       return NULL;
 
    filename_without_ext = 
eclair_utils_file_get_filename_without_ext(file_path);
@@ -558,13 +568,13 @@
 }
 
 //Build the cover file path from artist and album
-//The returned path has to be freed by the caller
+//The returned path has to be freed
 static char *_eclair_cover_build_path_from_artist_album(Eclair_Cover_Manager 
*cover_manager, const char *artist, const char *album, const char 
*cover_extension)
 {
    char *filename, *path, *c;
 
    if (!cover_manager || !artist || !album || !cover_extension || 
!cover_manager->eclair
-      || strlen(artist) <= 0 || strlen(album) <= 0 || strlen(cover_extension) 
<= 0)
+      || strlen(artist) <= 0 || strlen(album) <= 0)
       return NULL; 
 
    filename = malloc(strlen(artist) + strlen(album) + strlen(cover_extension) 
+ 3);
@@ -580,6 +590,21 @@
    return path;
 }
 
+//Build the cover filename from the cover name ("cover", "folder", ...) and 
its extension
+//The returned filename has to be freed
+static char *_eclair_cover_build_cover_filename(const char *cover_name, const 
char *cover_extension)
+{
+   char *cover_filename;
+
+   if (!cover_name || !cover_extension)
+      return NULL;
+
+   cover_filename = malloc(strlen(cover_name) + strlen(cover_extension) + 2);
+   sprintf(cover_filename, "%s.%s", cover_name, cover_extension);
+
+   return cover_filename;
+}
+
 //Build a request to make a search on amazon.com webservices
 static void _eclair_cover_build_url_for_item_search(const char *keywords, char 
url[MAX_REQUEST_SIZE])
 {
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_utils.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- eclair_utils.c      18 Jun 2005 16:00:35 -0000      1.7
+++ eclair_utils.c      2 Jul 2005 13:04:55 -0000       1.8
@@ -22,11 +22,6 @@
    }
 }
 
-//TODO:
-/*
-return (float)rand() / (float)RAND_MAX * (Max - Min) + Min;
-*/
-
 //Remove uri special chars (e.g. "%20" -> ' ')
 //The returned string has to be freed
 char *eclair_utils_remove_uri_special_chars(const char *uri)
@@ -153,8 +148,41 @@
    return file_without_ext;
 }
 
-//TODO:
+//Search for a file in the dir root_dir with the name filename, regardless to 
the case
+//Return NULL if no file found, otherwise, the path of the file
+//Returned value has to be freed
+char *eclair_utils_search_file(const char *filename, const char *root_dir)
+{
+   Ecore_List *files;
+   char *file;
+   char *result = NULL;
+
+   if (!filename || !root_dir)
+      return NULL;
+
+   files = ecore_file_ls(root_dir);
+   ecore_list_goto_first(files);
+   while ((file = ecore_list_next(files)))
+   {
+      if (strcasecmp(file, filename) == 0)
+      {
+         result = malloc(strlen(root_dir) + strlen(file) + 2);
+         sprintf(result, "%s/%s", root_dir, file);
+         break;
+      }
+   }
+   ecore_list_destroy(files);
+   return result;
+}
+
+//Return a random integer between min and max
 int eclair_utils_get_random_int(int min, int max)
 {
-   return (int)(((float)rand() / RAND_MAX) * (max - min) + 0.5f) + min;
+   return (int)((float)rand() / RAND_MAX * (max - min) + 0.5f) + min;
+}
+
+//Return a random float between min and max
+int eclair_utils_get_random_float(float min, float max)
+{
+   return (float)rand() / RAND_MAX * (max - min) + min;
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_utils.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- eclair_utils.h      18 Jun 2005 16:00:35 -0000      1.6
+++ eclair_utils.h      2 Jul 2005 13:04:55 -0000       1.7
@@ -10,6 +10,8 @@
 char *eclair_utils_remove_uri_special_chars(const char *uri);
 char *eclair_utils_file_get_extension(char *file);
 char *eclair_utils_file_get_filename_without_ext(char *file);
+char *eclair_utils_search_file(const char *filename, const char *root_dir);
 int eclair_utils_get_random_int(int min, int max);
+int eclair_utils_get_random_float(float min, float max);
 
 #endif




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to