Little changes at elm profile functios + some new free()-ing helpers.

SVN revision: 53878
This commit is contained in:
Gustavo Lima Chaves 2010-10-25 17:36:07 +00:00
parent 5ecd61282a
commit 1a0fae3aa9
4 changed files with 130 additions and 54 deletions

View File

@ -736,6 +736,7 @@ _profiles_list_fill(Evas_Object *l_widget, Eina_List *p_names)
const char *cur_profile = NULL;
const char *profile;
void *sel_it = NULL;
Eina_List *l;
if (!p_names)
return;
@ -745,7 +746,7 @@ _profiles_list_fill(Evas_Object *l_widget, Eina_List *p_names)
cur_profile = elm_profile_current_get();
EINA_LIST_FREE(p_names, profile)
EINA_LIST_FOREACH(p_names, l, profile)
{
Efreet_Desktop *desk = NULL;
char buf[PATH_MAX], *pdir;
@ -790,7 +791,6 @@ _profiles_list_fill(Evas_Object *l_widget, Eina_List *p_names)
if (pdir)
free(pdir);
free((void *)profile);
if (desk)
efreet_desktop_free(desk);
@ -910,6 +910,8 @@ _status_config_profiles(Evas_Object *win, Evas_Object *holder)
_profiles_list_fill(li, profs);
elm_profile_list_free(profs);
edje_thaw();
evas_event_thaw(evas);

View File

@ -334,6 +334,7 @@ extern "C" {
EAPI const char *elm_profile_current_get(void);
EAPI char *elm_profile_dir_get(const char *profile);
EAPI Eina_List *elm_profile_list_get(void);
EAPI void elm_profile_list_free(Eina_List *l);
EAPI void elm_profile_set(const char *profile);
EAPI void elm_profile_all_set(const char *profile);

View File

@ -283,7 +283,8 @@ _desc_shutdown(void)
_config_edd = NULL;
}
static int _cb_sort_files(char *f1, char *f2)
static int
_sort_files_cb(const void *f1, const void *f2)
{
return strcmp(f1, f2);
}
@ -320,10 +321,13 @@ _elm_config_profile_dir_get(const char *prof)
Eina_List *
_elm_config_profiles_list(void)
{
const Eina_File_Direct_Info *info;
const char *home = NULL;
Eina_List *flist = NULL;
char buf[PATH_MAX], *p;
Eina_List *files;
Eina_Iterator *file_it;
struct stat buffer;
char buf[PATH_MAX];
const char *dir;
size_t len;
home = getenv("HOME");
@ -334,70 +338,110 @@ _elm_config_profiles_list(void)
".elementary/config",
sizeof(".elementary/config") - 1);
files = ecore_file_ls(buf);
file_it = eina_file_direct_ls(buf);
if (!file_it)
goto sys;
buf[len] = '/';
len++;
p = buf + len;
len = sizeof(buf) - len;
if (files)
{
char *file;
files = eina_list_sort(files, 0, (Eina_Compare_Cb)_cb_sort_files);
EINA_LIST_FREE(files, file)
{
if (eina_strlcpy(p, file, len) >= len)
{
free(file);
continue;
}
if (ecore_file_is_dir(buf))
flist = eina_list_append(flist, file);
else
free(file);
}
EINA_ITERATOR_FOREACH(file_it, info)
{
if (info->name_length >= len)
continue;
switch (info->dirent->d_type)
{
case DT_UNKNOWN:
if (stat(info->path, &buffer) != 0)
goto it_free;
if (S_ISDIR(buffer.st_mode))
flist =
eina_list_sorted_insert(flist, _sort_files_cb,
eina_stringshare_add(info->path +
info->name_start));
break;
case DT_DIR:
flist =
eina_list_sorted_insert(flist, _sort_files_cb,
eina_stringshare_add(info->path +
info->name_start));
break;
default:
continue;
}
}
eina_iterator_free(file_it);
sys:
len = eina_str_join_len(buf, sizeof(buf), '/', _elm_data_dir,
strlen(_elm_data_dir), "config",
sizeof("config") - 1);
files = ecore_file_ls(buf);
file_it = eina_file_direct_ls(buf);
if (!file_it)
goto list_free;
buf[len] = '/';
len++;
p = buf + len;
len = sizeof(buf) - len;
if (files)
{
char *file;
files = eina_list_sort(files, 0, (Eina_Compare_Cb)_cb_sort_files);
EINA_LIST_FREE(files, file)
{
if (eina_strlcpy(p, file, len) >= len)
{
free(file);
continue;
}
if (ecore_file_is_dir(buf))
{
const Eina_List *l;
const char *tmp;
EINA_LIST_FOREACH(flist, l, tmp)
if (!strcmp(file, tmp)) break;
#define S_ISDIR_CASE_DO \
{ \
const Eina_List *l; \
const char *tmp; \
EINA_LIST_FOREACH(flist, l, tmp) \
if (!strcmp(info->path + info->name_start, tmp)) \
break; \
\
if (!l) \
flist = \
eina_list_sorted_insert(flist, _sort_files_cb, \
eina_stringshare_add(info->path + \
info->name_start)); \
} \
if (!l)
flist = eina_list_append(flist, file);
else free(file);
}
else
free(file);
}
len = sizeof(buf) - len;
EINA_ITERATOR_FOREACH(file_it, info)
{
if (info->name_length >= len)
continue;
switch (info->dirent->d_type)
{
case DT_UNKNOWN:
if (stat(info->path, &buffer) != 0)
goto it_free;
if (S_ISDIR(buffer.st_mode))
S_ISDIR_CASE_DO
break;
case DT_DIR:
S_ISDIR_CASE_DO
break;
default:
continue;
}
}
return flist;
#undef S_ISDIR_CASE_DO
it_free:
eina_iterator_free(file_it);
list_free:
EINA_LIST_FREE(flist, dir)
eina_stringshare_del(dir);
return NULL;
}
static void

View File

@ -1232,7 +1232,7 @@ elm_profile_current_get(void)
* @return The profile's directory path.
* @ingroup Profile
*
* @note You must free() the return value after usage.
* @note You must free it with elm_profile_dir_free().
*/
EAPI char *
elm_profile_dir_get(const char *profile)
@ -1240,15 +1240,28 @@ elm_profile_dir_get(const char *profile)
return _elm_config_profile_dir_get(profile);
}
/**
* Free an Elementary's profile directory path, as returned by
* elm_profile_dir_get().
*
* @param p_dir The profile's path
* @ingroup Profile
*
*/
EAPI void
elm_profile_dir_free(const char *p_dir)
{
free((void *)p_dir);
}
/**
* Get Elementary's list of available profiles.
*
* @return The profiles list.
* @ingroup Profile
*
* @note You must free() the strings which came as list data after
* usage of the return value. Consider using the @c EINA_LIST_FREE()
* macro.
* @note One must free this list, after usage, with the function
* elm_profile_list_free().
*/
EAPI Eina_List *
elm_profile_list_get(void)
@ -1256,6 +1269,22 @@ elm_profile_list_get(void)
return _elm_config_profiles_list();
}
/**
* Free Elementary's list of available profiles.
*
* @param The profiles list, as returned by elm_profile_list_get().
* @ingroup Profile
*
*/
EAPI void
elm_profile_list_free(Eina_List *l)
{
const char *dir;
EINA_LIST_FREE(l, dir)
eina_stringshare_del(dir);
}
/**
* Set Elementary's profile.
*