Enlightenment CVS committal

Author  : moom16
Project : e17
Module  : apps/eclair

Dir     : e17/apps/eclair/src


Modified Files:
        eclair.c eclair.h eclair_config.c eclair_cover.c 
        eclair_cover.h eclair_media_file.c eclair_meta_tag.c 
        eclair_playlist.c eclair_playlist.h eclair_utils.c 
        eclair_utils.h 


Log Message:

* Use ecore_file_* functions instead of my own
* Finish cover drag and drop support
* Fix some bugs and code cleanup


===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- eclair.c    7 May 2005 20:58:58 -0000       1.13
+++ eclair.c    8 May 2005 12:29:06 -0000       1.14
@@ -73,7 +73,7 @@
    eclair_subtitles_init(&eclair->subtitles);
    eclair_meta_tag_init(&eclair->meta_tag_manager, eclair);
    eclair_cover_init(&eclair->cover_manager, eclair);
-   eclair_update_current_file_info(eclair);
+   eclair_update_current_file_info(eclair, 0);
    
    for (l = filenames; l; l = l->next)
       eclair_playlist_add_uri(&eclair->playlist, (char *)l->data);
@@ -140,7 +140,7 @@
 }
 
 //Update the gui infos about the current media file
-void eclair_update_current_file_info(Eclair *eclair)
+void eclair_update_current_file_info(Eclair *eclair, Evas_Bool 
force_cover_update)
 {   
    char *window_title;
    char *artist_title_string;
@@ -162,7 +162,7 @@
             edje_object_part_text_set(eclair->gui_object, 
"current_media_name", artist_title_string);
             free(artist_title_string);
          }
-         else if ((filename = 
eclair_utils_path_to_filename(current_file->path)))
+         else if ((filename = ecore_file_get_file(current_file->path)))
             edje_object_part_text_set(eclair->gui_object, 
"current_media_name", filename);
          else
             edje_object_part_text_set(eclair->gui_object, 
"current_media_name", "No media opened");
@@ -187,14 +187,19 @@
 
    //Update the current cover
    if (current_file)
-      eclair_gui_cover_set(eclair, current_file->cover_path);
+   {
+      if (current_file->cover_path || (current_file->cover_path = 
eclair_cover_file_get_from_local(&eclair->cover_manager, current_file->artist, 
current_file->album, current_file->path)))
+         eclair_gui_cover_set(eclair, current_file->cover_path, 
force_cover_update);
+      else
+         eclair_gui_cover_set(eclair, NULL, force_cover_update);
+   }
    else
-      eclair_gui_cover_set(eclair, NULL);
+      eclair_gui_cover_set(eclair, NULL, force_cover_update);
 }
 
 //Set the cover displayed on the GUI
 //Remove it if cover_path == NULL
-void eclair_gui_cover_set(Eclair *eclair, const char *cover_path)
+void eclair_gui_cover_set(Eclair *eclair, const char *cover_path, Evas_Bool 
force_cover_update)
 {
    char *current_path = NULL;
 
@@ -204,7 +209,7 @@
    evas_object_image_file_get(eclair->gui_cover, &current_path, NULL);
    if (!current_path && !cover_path)
       return;
-   if (current_path && cover_path && (strcmp(current_path, cover_path) == 0))
+   if (!force_cover_update && current_path && cover_path && 
(strcmp(current_path, cover_path) == 0))
          return;
 
    if (eclair->gui_previous_cover)
@@ -221,6 +226,12 @@
    }
 
    evas_object_image_file_set(eclair->gui_cover, cover_path, NULL);
+   //TODO: evas_object_image_reload bug? need to do two reloads to really 
reload the image?!
+   if (current_path && cover_path && (strcmp(current_path, cover_path) == 0))
+   {
+      evas_object_image_reload(eclair->gui_cover);
+      evas_object_image_reload(eclair->gui_cover);
+   }
    if (cover_path)
    {
       edje_object_signal_emit(eclair->gui_object, "signal_cover_set", 
"eclair_bin");
@@ -650,7 +661,7 @@
 
    eclair_audio_level_set(eclair, 
emotion_object_audio_volume_get(new_video_object));
    eclair->video_object = new_video_object;
-   eclair_update_current_file_info(eclair);
+   eclair_update_current_file_info(eclair, 0);
 
    return NULL; 
 }
@@ -667,17 +678,17 @@
 //Display a message on segvs
 static void _eclair_on_segv(int num)
 {
-       fprintf (stderr, "\n\n");       
-       fprintf (stderr, "Oops, eclair has crashed (SIG: %d) :(\n", num);
-       fprintf (stderr, "\n");
-       fprintf (stderr, "Have you compiled the latest version of eclair, 
emotion, evas, and all eclair dependencies ?\n");
-       fprintf (stderr, "If it failed again, please report bugs to Mo0m 
([EMAIL PROTECTED])\n");
-       fprintf (stderr, "Describe how bugs happened, gdb traces, and so on 
;)\n");
-       fprintf (stderr, "\n");
-       fprintf (stderr, "With that, devs will be able to correct bugs faster 
and easier\n");
-       fprintf (stderr, "If you correct the bug, or see in which code part it 
can provide, include it too\n");
-       fprintf (stderr, "\n");
-       fprintf (stderr, "Thanks :)\n");
+       fprintf(stderr, "\n\n");        
+       fprintf(stderr, "Oops, eclair has crashed (SIG: %d) :(\n", num);
+       fprintf(stderr, "\n");
+       fprintf(stderr, "Have you compiled the latest version of eclair, 
emotion, evas, and all eclair dependencies ?\n");
+       fprintf(stderr, "If it failed again, please report bugs to Mo0m ([EMAIL 
PROTECTED])\n");
+       fprintf(stderr, "Describe how bugs happened, gdb traces, and so on 
;)\n");
+       fprintf(stderr, "\n");
+       fprintf(stderr, "With that, devs will be able to correct bugs faster 
and easier\n");
+       fprintf(stderr, "If you correct the bug, or see in which code part it 
can provide, include it too\n");
+       fprintf(stderr, "\n");
+       fprintf(stderr, "Thanks :)\n");
    
        exit(20);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- eclair.h    4 May 2005 21:36:50 -0000       1.6
+++ eclair.h    8 May 2005 12:29:06 -0000       1.7
@@ -8,10 +8,10 @@
 void eclair_shutdown(Eclair *eclair);
 void eclair_update(Eclair *eclair);
 void *eclair_file_chooser_thread(void *param);
-void eclair_update_current_file_info(Eclair *eclair);
+void eclair_update_current_file_info(Eclair *eclair, Evas_Bool 
force_cover_update);
 void eclair_playlist_container_scroll(Eclair *eclair, int num_entries);
 void eclair_playlist_container_scroll_percent_set(Eclair *eclair, double 
percent);
-void eclair_gui_cover_set(Eclair *eclair, const char *cover_path);
+void eclair_gui_cover_set(Eclair *eclair, const char *cover_path, Evas_Bool 
force_cover_update);
 
 //navigation functions
 void eclair_play_file(Eclair *eclair, const char *path);
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_config.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- eclair_config.c     7 May 2005 20:58:59 -0000       1.4
+++ eclair_config.c     8 May 2005 12:29:06 -0000       1.5
@@ -1,6 +1,5 @@
 #include "eclair_config.h"
-#include <sys/types.h>
-#include <sys/stat.h>
+#include <Ecore_File.h>
 #include <stdio.h>
 
 Evas_Bool eclair_config_init(Eclair_Config *config)
@@ -16,10 +15,10 @@
       return 0;
 
    sprintf(config->config_dir_path, "%s/.eclair/", home);
-   mkdir(config->config_dir_path, 0755);
+   ecore_file_mkdir(config->config_dir_path);
 
    sprintf(config->covers_dir_path, "%scovers/", config->config_dir_path);
-   mkdir(config->config_dir_path, 0755);
+   ecore_file_mkdir(config->covers_dir_path);
 
    sprintf(config->config_file_path, "%seclair.cfg", config->config_dir_path);
    config->config_file = fopen(config->config_file_path, "a+t");
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_cover.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- eclair_cover.c      7 May 2005 20:58:59 -0000       1.10
+++ eclair_cover.c      8 May 2005 12:29:06 -0000       1.11
@@ -16,6 +16,7 @@
 
 #define PACKET_CHUNK_SIZE 1024
 #define MAX_REQUEST_SIZE 1024
+#define NUM_EXTENSIONS 3
 
 typedef struct _Eclair_Cover_Packet_Chunk
 {
@@ -31,6 +32,7 @@
 
 const char *amazon_hostname = "webservices.amazon.com";
 const char *amazon_license_key = "0P1862RFDFSF4KYZQNG2";
+const char *cover_extensions[NUM_EXTENSIONS] = { "jpg", "jpeg", "png" };
 
 static int _eclair_cover_connect_to_hostname(const char *hostname);
 static int _eclair_cover_connect_to_host(const struct hostent *host);
@@ -38,11 +40,10 @@
 static int _eclair_cover_extract_http_body(char *packet, int packet_length, 
char **body);
 static int _eclair_cover_fetch(const char *url, char **data);
 
-static char *_eclair_cover_build_path_from_filepath(Eclair_Cover_Manager 
*cover_manager, const char *file_path, const char *cover_extension);
+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 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 char *_eclair_cover_convert_to_url_format(const char *string);
 static xmlNode *_eclair_cover_get_node_xml_tree(xmlNode *root_node, const char 
*prop);
 static xmlChar *_eclair_cover_get_prop_value_from_xml_tree(xmlNode *root_node, 
const char *prop);
 static void _eclair_cover_add_file_to_not_in_amazon_db_list(Evas_List **list, 
const char *artist, const char *album);
@@ -165,7 +166,7 @@
 
 //Return the path of the file of the album cover
 //NULL if failed. The returned path will have to be freed if success
-char *eclair_cover_file_get(Eclair_Cover_Manager *cover_manager, const char 
*artist, const char *album, const char *file_path)
+char *eclair_cover_file_get(Eclair_Cover_Manager *cover_manager, const char 
*artist, const char *album, char *file_path)
 {
    char *path;
 
@@ -181,30 +182,32 @@
 
 //Try to open the cover file on the disk if it exists
 //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, const char *file_path)
+char *eclair_cover_file_get_from_local(Eclair_Cover_Manager *cover_manager, 
const char *artist, const char *album, char *file_path)
 {
    char *cover_path;
-   FILE *cover_file;
+   int i;
 
-   if ((cover_path = _eclair_cover_build_path_from_filepath(cover_manager, 
file_path, "jpg")))
+   for (i = 0; i < NUM_EXTENSIONS; i++)
    {
-      if ((cover_file = fopen(cover_path, "rb")))
+      if ((cover_path = _eclair_cover_build_path_from_filepath(cover_manager, 
file_path, cover_extensions[i])))
       {
-         fclose(cover_file);
-         return cover_path;
+         if (ecore_file_exists(cover_path))
+            return cover_path;
+         free(cover_path);
       }
    }
-   free(cover_path);
 
-   if ((cover_path = _eclair_cover_build_path_from_artist_album(cover_manager, 
artist, album, "jpg")))
+   for (i = 0; i < NUM_EXTENSIONS; i++)
    {
-      if ((cover_file = fopen(cover_path, "rb")))
+      if ((cover_path = 
_eclair_cover_build_path_from_artist_album(cover_manager, artist, album, 
cover_extensions[i])))
       {
-         fclose(cover_file);
-         return cover_path;
+         if (ecore_file_exists(cover_path))
+            return cover_path;
+         free(cover_path);
       }
    }
-   free(cover_path);
+
+   //TODO: search if there is cover.jpg, or such file, in the directory of the 
file
 
    return NULL;
 }
@@ -241,7 +244,7 @@
    //Get the ASIN of the album
    keywords = (char *)malloc(strlen(artist) + strlen(album) + 2);
    sprintf(keywords, "%s %s", artist, album);
-   converted_keywords = _eclair_cover_convert_to_url_format(keywords);
+   converted_keywords = eclair_utils_add_uri_special_chars(keywords);
    free(keywords);
 
    _eclair_cover_build_url_for_item_search(converted_keywords, url);
@@ -528,19 +531,14 @@
 
 //Build the cover file path from file_path and cover_extension
 //The returned path has to be freed by the caller
-static char *_eclair_cover_build_path_from_filepath(Eclair_Cover_Manager 
*cover_manager, const char *file_path, const char *cover_extension)
+static char *_eclair_cover_build_path_from_filepath(Eclair_Cover_Manager 
*cover_manager, char *file_path, const char *cover_extension)
 {
-   char *cover_path, *ext_start, *filename_without_ext;
-   const char *filename;
+   char *cover_path, *filename_without_ext;
 
    if (!cover_manager || !file_path || !cover_extension || 
!cover_manager->eclair)
       return NULL;
 
-   filename = eclair_utils_path_to_filename(file_path);
-   filename_without_ext = strdup(filename);
-   if ((ext_start = rindex(filename_without_ext, '.')))
-      *ext_start = 0;
-
+   filename_without_ext = 
eclair_utils_file_get_filename_without_ext(file_path);
    cover_path = (char 
*)malloc(strlen(cover_manager->eclair->config.covers_dir_path) + 
strlen(filename_without_ext) + strlen(cover_extension) + 2);
    sprintf(cover_path, "%s%s.%s", 
cover_manager->eclair->config.covers_dir_path, filename_without_ext, 
cover_extension);
    free(filename_without_ext);
@@ -554,7 +552,8 @@
 {
    char *filename, *path, *c;
 
-   if (!cover_manager || !artist || !album || !cover_extension || 
!cover_manager->eclair)
+   if (!cover_manager || !artist || !album || !cover_extension || 
!cover_manager->eclair
+      || strlen(artist) <= 0 || strlen(album) <= 0 || strlen(cover_extension) 
<= 0)
       return NULL; 
 
    filename = (char *)malloc(strlen(artist) + strlen(album) + 
strlen(cover_extension) + 3);
@@ -584,44 +583,6 @@
       amazon_hostname, amazon_license_key, ASIN);
 }
 
-
-
-//Convert a string to URL format (eg. 'space' -> "%20"...)
-//The returned string has to be freed by the caller
-static char *_eclair_cover_convert_to_url_format(const char *string)
-{
-   char *new_string;
-   int i, j, string_length;
-
-   if (!string)
-      return NULL;
-
-   string_length = strlen(string);
-   new_string = (char *)malloc(string_length * 3 * sizeof(char) + 1);
-
-   for (i = 0, j = 0; i < string_length; i++, j++)
-   {
-      if (string[i] == ' ' || string[i] == ';'  || string[i] == '&'  || 
string[i] == '='  ||
-         string[i] == '<'  || string[i] == '>'  || string[i] == '?'  || 
string[i] == '@'  ||
-         string[i] == '\"' || string[i] == '['  || string[i] == '#'  || 
string[i] == '\\' ||
-         string[i] == '$'  || string[i] == ']'  || string[i] == '%'  || 
string[i] == '^'  ||
-         string[i] == '\'' || string[i] == '¨'  || string[i] == '+'  || 
string[i] == '{'  ||
-         string[i] == ','  || string[i] == '|'  || string[i] == '/'  || 
string[i] == '}'  ||
-         string[i] == ':'  || string[i] == '~')
-      {
-         new_string[j] = '%';
-         j++;
-         sprintf(&new_string[j], "%X", string[i]);
-         j++;
-      }
-      else
-         new_string[j] = string[i];
-   }
-   new_string[j] = 0;
-
-   return new_string;
-}
-
 //Search recursively the node called prop in the xml tree and return its value
 static xmlNode *_eclair_cover_get_node_xml_tree(xmlNode *root_node, const char 
*prop)
 {
@@ -671,10 +632,8 @@
    char *clean_uri, *cover_path, *new_path;
    Eclair_Media_File *current_file;
 
-   if (!cover_manager || !cover_manager->eclair || !uri)
-      return;
-
-   if (!(current_file = 
eclair_playlist_current_media_file(&cover_manager->eclair->playlist)))
+   if (!cover_manager || !cover_manager->eclair || !uri
+      || !(current_file = 
eclair_playlist_current_media_file(&cover_manager->eclair->playlist)))
       return;
 
    if (strstr(uri, "://"))
@@ -682,7 +641,7 @@
       if (!(clean_uri = eclair_utils_remove_uri_special_chars(uri)))
          return;
    
-      if ((strlen(uri) <= 7) || (strncmp(uri, "file://", 7) != 0))
+      if (strlen(uri) <= 7 || strncmp(uri, "file://", 7) != 0)
       {
          free(clean_uri);
          return;
@@ -693,13 +652,10 @@
    else
       cover_path = strdup(uri);
 
-   //TODO: extract extension
-   if (!(new_path = _eclair_cover_build_path_from_artist_album(cover_manager, 
current_file->artist, current_file->album, "jpg")))
+   if (!(new_path = _eclair_cover_build_path_from_artist_album(cover_manager, 
current_file->artist, current_file->album, 
eclair_utils_file_get_extension(cover_path)))
+      && !(new_path = _eclair_cover_build_path_from_filepath(cover_manager, 
current_file->path, eclair_utils_file_get_extension(cover_path))))
    {
-      //TODO:
-      //if (!(new_path = 
_eclair_cover_build_path_from_filepath(cover_manager)))
       free(cover_path);
-      free(new_path);
       return;
    }
    if (!ecore_file_cp(cover_path, new_path))
@@ -710,6 +666,7 @@
    }
 
    free(cover_path);
+   free(current_file->cover_path);
    current_file->cover_path = new_path;
-   eclair_update_current_file_info(cover_manager->eclair);
+   eclair_update_current_file_info(cover_manager->eclair, 1);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_cover.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- eclair_cover.h      7 May 2005 20:58:59 -0000       1.5
+++ eclair_cover.h      8 May 2005 12:29:06 -0000       1.6
@@ -6,8 +6,8 @@
 void eclair_cover_init(Eclair_Cover_Manager *cover_manager, Eclair *eclair);
 void eclair_cover_shutdown(Eclair_Cover_Manager *cover_manager);
 void eclair_cover_add_file_to_treat(Eclair_Cover_Manager *cover_manager, 
Eclair_Media_File *media_file);
-char *eclair_cover_file_get(Eclair_Cover_Manager *cover_manager, const char 
*artist, const char *album, const char *file_path);
-char *eclair_cover_file_get_from_local(Eclair_Cover_Manager *cover_manager, 
const char *artist, const char *album, const char *file_path);
+char *eclair_cover_file_get(Eclair_Cover_Manager *cover_manager, const char 
*artist, const char *album, char *file_path);
+char *eclair_cover_file_get_from_local(Eclair_Cover_Manager *cover_manager, 
const char *artist, const char *album, char *file_path);
 char *eclair_cover_file_get_from_amazon(Eclair_Cover_Manager *cover_manager, 
const char *artist, const char *album);
 void eclair_cover_current_set(Eclair_Cover_Manager *cover_manager, const char 
*uri);
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_media_file.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- eclair_media_file.c 4 May 2005 21:36:50 -0000       1.5
+++ eclair_media_file.c 8 May 2005 12:29:06 -0000       1.6
@@ -1,5 +1,6 @@
 #include "eclair_media_file.h"
 #include <Edje.h>
+#include <Ecore_File.h>
 #include "eclair.h"
 #include "eclair_playlist.h"
 #include "eclair_cover.h"
@@ -45,7 +46,7 @@
          edje_object_part_text_set(media_file->playlist_entry, 
"playlist_entry_name", artist_title_string);
          free(artist_title_string);
       }
-      else if ((filename = eclair_utils_path_to_filename(media_file->path)))
+      else if ((filename = ecore_file_get_file(media_file->path)))
          edje_object_part_text_set(media_file->playlist_entry, 
"playlist_entry_name", filename);
       else
          edje_object_part_text_set(media_file->playlist_entry, 
"playlist_entry_name", "Media");
@@ -64,5 +65,5 @@
 
    //If the media file is the current, we also update gui infos
    if (media_file == eclair_playlist_current_media_file(&eclair->playlist))
-      eclair_update_current_file_info(eclair);
+      eclair_update_current_file_info(eclair, 0);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_meta_tag.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- eclair_meta_tag.c   6 May 2005 18:52:26 -0000       1.7
+++ eclair_meta_tag.c   8 May 2005 12:29:06 -0000       1.8
@@ -84,7 +84,7 @@
    taglib_file_free(tag_file);
 
    //Try to load the cover
-   if (tag && !(media_file->cover_path = 
eclair_cover_file_get_from_local(&eclair->cover_manager, media_file->artist, 
media_file->album, media_file->path)))
+   if (tag && !media_file->cover_path && !(media_file->cover_path = 
eclair_cover_file_get_from_local(&eclair->cover_manager, media_file->artist, 
media_file->album, media_file->path)))
       eclair_cover_add_file_to_treat(&eclair->cover_manager, media_file);
 }
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_playlist.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- eclair_playlist.c   7 May 2005 20:58:59 -0000       1.6
+++ eclair_playlist.c   8 May 2005 12:29:06 -0000       1.7
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <Esmart/Esmart_Container.h>
 #include <Evas.h>
+#include <Ecore_File.h>
 #include <Edje.h>
 #include "eclair.h"
 #include "eclair_cover.h"
@@ -67,40 +68,74 @@
    return (Eclair_Media_File 
*)evas_list_data(evas_list_next(playlist->current));
 }
 
-Eclair_Media_File *eclair_playlist_add_uri(Eclair_Playlist *playlist, char 
*uri)
+//Add recursively a directory
+Evas_Bool eclair_playlist_add_dir(Eclair_Playlist *playlist, char *dir)
+{
+   Ecore_List *files;
+   Ecore_List_Node *l;
+   char *filename, *filepath;
+
+   if (!playlist || !dir || !ecore_file_is_dir(dir))
+      return 0;
+
+   if ((files = ecore_file_ls(dir)))
+   {
+      for (l = files->first; l; l = l->next)
+      {
+         if (!(filename = (char *)l->data))
+            continue;
+         filepath = (char *)malloc(strlen(dir) + strlen(filename) + 2);
+         sprintf(filepath, "%s/%s", dir, filename);
+         eclair_playlist_add_uri(playlist, filepath);
+         free(filepath);
+      }
+      ecore_list_destroy(files);
+   }
+   return 1;
+}
+
+//Add the media file located at the uri
+Evas_Bool eclair_playlist_add_uri(Eclair_Playlist *playlist, char *uri)
 {
    Eclair_Media_File *new_media_file;
    Evas_Coord min_height;
    Eclair *eclair;
-   char *clean_uri;
+   char *clean_uri, *new_path;
 
    if (!playlist || !uri)
-      return NULL;
-
-   new_media_file = eclair_media_file_new();
+      return 0;
 
    if (strstr(uri, "://"))
    {
       if (!(clean_uri = eclair_utils_remove_uri_special_chars(uri)))
-         return NULL;
+         return 0;
 
-      if ((strlen(clean_uri) <= 7) || (strncmp(clean_uri, "file://", 7) != 0))
-         new_media_file->path = clean_uri;
+      if (strlen(clean_uri) <= 7 || strncmp(clean_uri, "file://", 7) != 0)
+         new_path = clean_uri;
       else
       {
-         new_media_file->path = strdup(&clean_uri[7]);
+         new_path = strdup(&clean_uri[7]);
          free(clean_uri);
       }
    }
    else
-      new_media_file->path = strdup(uri);
+      new_path = strdup(uri);
+
+   if (eclair_playlist_add_dir(playlist, new_path))
+   {
+      free(new_path);
+      return 1;
+   }
+   
+   new_media_file = eclair_media_file_new();
+   new_media_file->path = new_path;
 
    if ((eclair = playlist->eclair))
    {
       if (eclair->playlist_container)
       {
          new_media_file->playlist_entry = 
edje_object_add(evas_object_evas_get(eclair->playlist_container));
-         edje_object_file_set(new_media_file->playlist_entry, PACKAGE_DATA_DIR 
"/themes/default.edj", "eclair_playlist_entry");
+         edje_object_file_set(new_media_file->playlist_entry, 
eclair->gui_theme_file, "eclair_playlist_entry");
          evas_object_data_set(new_media_file->playlist_entry, "media_file", 
new_media_file);
          if (eclair->playlist_entry_height <= 0)
          {
@@ -108,7 +143,7 @@
             eclair->playlist_entry_height = (int)min_height;
          }
          evas_object_resize(new_media_file->playlist_entry, 1, 
eclair->playlist_entry_height);
-         edje_object_part_text_set(new_media_file->playlist_entry, 
"playlist_entry_name", eclair_utils_path_to_filename(new_media_file->path));
+         edje_object_part_text_set(new_media_file->playlist_entry, 
"playlist_entry_name", ecore_file_get_file(new_media_file->path));
          edje_object_part_text_set(new_media_file->playlist_entry, 
"playlist_entry_length", "");
          edje_object_signal_callback_add(new_media_file->playlist_entry, 
"eclair_play_entry", "*", eclair_gui_play_entry_cb, eclair);
          esmart_container_element_append(eclair->playlist_container, 
new_media_file->playlist_entry);
@@ -123,7 +158,7 @@
    if (!playlist->current)
       eclair_playlist_current_set_list(playlist, playlist->playlist);
 
-   return (Eclair_Media_File *)evas_list_data(playlist->playlist->last);   
+   return 1;   
 }
 
 //Remove the media file from the playlist
@@ -198,7 +233,7 @@
    }
    
    playlist->current = list;
-   eclair_update_current_file_info(playlist->eclair);
+   eclair_update_current_file_info(playlist->eclair, 0);
 } 
 
 //Set the media file which is just before the active media file as the active 
media file 
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_playlist.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- eclair_playlist.h   7 May 2005 20:58:59 -0000       1.4
+++ eclair_playlist.h   8 May 2005 12:29:06 -0000       1.5
@@ -10,7 +10,8 @@
 Eclair_Media_File *eclair_playlist_prev_media_file(Eclair_Playlist *playlist);
 Eclair_Media_File *eclair_playlist_next_media_file(Eclair_Playlist *playlist);
 
-Eclair_Media_File *eclair_playlist_add_uri(Eclair_Playlist *playlist, char 
*uri);
+Evas_Bool eclair_playlist_add_dir(Eclair_Playlist *playlist, char *dir);
+Evas_Bool eclair_playlist_add_uri(Eclair_Playlist *playlist, char *uri);
 void eclair_playlist_remove_media_file(Eclair_Playlist *playlist, 
Eclair_Media_File *media_file);
 Evas_List *eclair_playlist_remove_media_file_list(Eclair_Playlist *playlist, 
Evas_List *list);
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_utils.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- eclair_utils.c      7 May 2005 20:58:59 -0000       1.3
+++ eclair_utils.c      8 May 2005 12:29:06 -0000       1.4
@@ -1,4 +1,5 @@
 #include "eclair_utils.h"
+#include <Ecore_File.h>
 #include <string.h>
 
 //Convert the progress rate in seconds to a string depending to the length of 
the media
@@ -15,21 +16,6 @@
    }
 }
 
-//Get filename from the path
-const char *eclair_utils_path_to_filename(const char *path)
-{
-   char *filename;
-
-   if (!path)
-      return NULL;
-
-   //TODO: check if it's a local file
-   if ((filename = rindex(path, '/')))
-      return &(filename[1]);
-   else
-      return path;
-}
-
 //Remove uri special chars (e.g. "%20" -> ' ')
 //The returned string has to be freed
 char *eclair_utils_remove_uri_special_chars(const char *uri)
@@ -67,6 +53,42 @@
    return clean_uri;
 }
 
+//Add the uri special chars (e.g. ' ' -> "%20")
+//The returned string has to be freed
+char *eclair_utils_add_uri_special_chars(const char *uri)
+{
+   int uri_length;
+   char *new_uri;
+   int i, j;
+
+   if (!uri)
+      return NULL;
+
+   uri_length = strlen(uri);
+   new_uri = (char *)malloc(uri_length * 3 + 1);
+
+   for (i = 0, j = 0; i < uri_length; i++, j++)
+   {
+      if (uri[i] == ' ' || uri[i] == ';'  || uri[i] == '&'  || uri[i] == '='  
||
+         uri[i] == '<'  || uri[i] == '>'  || uri[i] == '?'  || uri[i] == '@'  
||
+         uri[i] == '\"' || uri[i] == '['  || uri[i] == '#'  || uri[i] == '\\' 
||
+         uri[i] == '$'  || uri[i] == ']'  || uri[i] == '%'  || uri[i] == '^'  
||
+         uri[i] == '\'' || uri[i] == '¨'  || uri[i] == '+'  || uri[i] == '{'  
||
+         uri[i] == ','  || uri[i] == '|'  || uri[i] == '/'  || uri[i] == '}'  
||
+         uri[i] == ':'  || uri[i] == '~')
+      {
+         new_uri[j] = '%';
+         sprintf(&new_uri[j + 1], "%x", uri[i]);
+         j += 2;
+      }
+      else
+         new_uri[j] = uri[i];
+   }
+   new_uri[j] = 0;
+
+   return new_uri;
+}
+
 //Return the string "artist - title"
 //NULL if the media file doesn't have tag
 //This string has to be freed
@@ -96,3 +118,38 @@
 
    return string;
 }
+
+//Return the extension of the file
+//NULL if failed
+char *eclair_utils_file_get_extension(char *file)
+{
+   char *ext;
+
+   if (!file || !(ext = ecore_file_get_file(file)))
+      return NULL;
+
+   if ((ext = strrchr(ext, '.')))
+   {
+      ext++;
+      return ext;
+   }
+   return NULL;
+}
+
+//Return the filename of the file without the extension
+//The returned string has to be freed
+//NULL if failed
+char *eclair_utils_file_get_filename_without_ext(char *file)
+{
+   char *file_without_ext;
+   char *ext_start;
+
+   if (!file || !(file_without_ext = ecore_file_get_file(file)))
+      return NULL;
+
+   file_without_ext = strdup(file_without_ext);
+   if ((ext_start = strrchr(file_without_ext, '.')))
+      *ext_start = 0;
+
+   return file_without_ext;
+}
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/eclair/src/eclair_utils.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- eclair_utils.h      7 May 2005 20:58:59 -0000       1.3
+++ eclair_utils.h      8 May 2005 12:29:06 -0000       1.4
@@ -4,8 +4,10 @@
 #include "eclair_private.h"
 
 void eclair_utils_second_to_string(double position, double length, char 
*string);
-const char *eclair_utils_path_to_filename(const char *path);
-char *eclair_utils_remove_uri_special_chars(const char *uri);
 char *eclair_utils_mediafile_to_artist_title_string(const Eclair_Media_File 
*media_file);
+char *eclair_utils_add_uri_special_chars(const char *uri);
+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);
 
 #endif




-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to