Part of a review of icon searching, to be completed on sunday.

SVN revision: 26025
This commit is contained in:
David Walter Seikel 2006-09-22 14:56:41 +00:00
parent e282477a21
commit f1b46bd67e
3 changed files with 45 additions and 19 deletions

View File

@ -45,10 +45,11 @@ struct _Ecore_Desktop
char *categories;
char *exec;
char *exec_params;
char *icon;
char *original_icon;
char *icon_class;
char *icon_theme;
char *icon;
char *icon_path;
time_t icon_time; /* For checking if the icon cache is valid. */
char *path;
char *URL;
char *file;
@ -81,6 +82,8 @@ struct _Ecore_Desktop_Icon_Theme
char *inherits;
char *directories;
int hidden;
/* Actually calling this st_mtime causes compile issues, must be some strange macros at work. */
time_t mtime; /* For checking if the cache is valid. */
};
typedef struct _Ecore_Desktop_Icon_Theme Ecore_Desktop_Icon_Theme;

View File

@ -299,8 +299,8 @@ _ecore_desktop_get(const char *file, const char *lang)
result->window_role);
IFGETDUP(value, "Icon", result->icon);
if (result->icon)
result->original_icon = strdup(result->icon);
IFGETDUP(value, "X-Enlightenment-IconTheme",
result->icon_theme);
IFGETDUP(value, "X-Enlightenment-IconClass",
result->icon_class);
IFGETDUP(value, "X-Enlightenment-IconPath",
@ -312,7 +312,6 @@ _ecore_desktop_get(const char *file, const char *lang)
if (result->icon[0] == '/')
{
result->icon_path = strdup(result->icon);
result->icon = NULL;
}
else /* It's a relative path. */
{
@ -335,7 +334,6 @@ _ecore_desktop_get(const char *file, const char *lang)
result->icon);
result->icon_path =
ecore_file_realpath(temp);
result->icon = NULL;
free(dir);
}
free(temp);
@ -394,7 +392,7 @@ _ecore_desktop_get(const char *file, const char *lang)
if (!result->icon_class)
{
size = 0;
if ((result->icon) && (result->icon[0] != '/'))
if ((result->icon) && (strchr(result->icon, '/') == NULL))
size += strlen(result->icon) + 1;
if (eap_name)
size += strlen(eap_name) + 1;
@ -409,12 +407,11 @@ _ecore_desktop_get(const char *file, const char *lang)
int done = 0;
result->icon_class[0] = '\0';
if ((result->icon) && (result->icon[0] != '/')
if ((result->icon) && (strchr(result->icon, '/') == NULL)
&& (result->icon[0] != '\0'))
{
strcat(result->icon_class, result->icon);
done = 1;
result->icon = NULL;
}
/* We do this here coz we don't want to lower case the result->icon part later. */
p = result->icon_class;
@ -592,6 +589,9 @@ ecore_desktop_save(Ecore_Desktop * desktop)
if (desktop->icon)
ecore_hash_set(desktop->group, strdup("Icon"),
strdup(desktop->icon));
if (desktop->icon_theme)
ecore_hash_set(desktop->group, strdup("X-Enlightenment-IconTheme"),
strdup(desktop->icon_theme));
if (desktop->icon_class)
ecore_hash_set(desktop->group, strdup("X-Enlightenment-IconClass"),
strdup(desktop->icon_class));
@ -772,7 +772,7 @@ _ecore_desktop_destroy(Ecore_Desktop * desktop)
IFFREE(desktop->exec_params)
IFFREE(desktop->categories)
IFFREE(desktop->icon)
IFFREE(desktop->original_icon)
IFFREE(desktop->icon_theme)
IFFREE(desktop->icon_class)
IFFREE(desktop->icon_path)
IFFREE(desktop->path)
@ -899,10 +899,10 @@ ecore_desktop_get_command(Ecore_Desktop * desktop, Ecore_List * files, int fill)
break;
case 'i': /* "--icon Icon" field from .desktop file, or empty. */
if (desktop->original_icon)
if (desktop->icon)
{
snprintf(buf, sizeof(buf), "--icon %s",
desktop->original_icon);
desktop->icon);
t = buf;
}
break;

View File

@ -19,7 +19,7 @@ _ecore_desktop_icon_theme_directory_destroy(Ecore_Desktop_Icon_Theme_Directory *
/* FIXME: We need a way for the client to disable searching for any of these that they don't support. */
static const char *ext[] =
{ ".edj", ".png", ".svgz", ".svg", ".xpm", NULL };
{ "", ".edj", ".png", ".svgz", ".svg", ".xpm", NULL }; /* "" is in case the icon already has an extension, search for that first. */
static int init_count = 0;
static Ecore_Hash *icon_theme_cache;
static int loaded = 0;
@ -140,10 +140,13 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
* it changed the theme to make sure that the new icons will eventually get
* used."
*
* The phrase "toplevel icon directories" is ambigous, but I guess they mean
* the directory where the index.theme file lives.
*
* On the other hand, OS caching (at least in linux) seems to do a reasonable
* job here.
*
* We could also precalculate and cache all the information extracted from
* We also precalculate and cache all the information extracted from
* the .theme files.
*/
@ -171,7 +174,7 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
{
int wanted_size;
int minimal_size = INT_MAX;
int i, j;
int i;
char *closest = NULL;
Ecore_Desktop_Icon_Theme_Directory *directory;
@ -230,11 +233,14 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
}
/* Look for icon with all extensions. */
for (j = 0; ext[j] != NULL; j++)
for (i = 0; ext[i] != NULL; i++)
{
/* Check if there will be an extension. */
if ((ext[i][0] == '\0') && (strrchr(icon, '.') == NULL))
continue;
snprintf(path, PATH_MAX,
"%s/%s/%s%s",
icon_theme, directory->path, icon, ext[j]);
icon_theme, directory->path, icon, ext[i]);
#ifdef DEBUG
printf("FDO icon = %s\n", path);
#endif
@ -243,7 +249,12 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
(ecore_desktop_paths_icons, path, 0, NULL, NULL);
if (found)
{
if (match) /* If there is a match in sizes, return the icon. */
if (ecore_file_is_dir(found))
{
free(found);
found = NULL;
}
else if (match) /* If there is a match in sizes, return the icon. */
break;
else if (result_size < minimal_size) /* While we are here, figure out our next fallback strategy. */
{
@ -251,6 +262,7 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
if (closest)
free(closest);
closest = found;
found = NULL;
}
else
{
@ -299,6 +311,9 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
/* Fall back strategy #4, Just search in the base of the icon directories. */
for (i = 0; ext[i] != NULL; i++)
{
/* Check if there will be an extension. */
if ((ext[i][0] == '\0') && (strrchr(icon, '.') == NULL))
continue;
snprintf(path, PATH_MAX, "%s%s", icon, ext[i]);
#ifdef DEBUG
printf("FDO icon = %s\n", path);
@ -307,7 +322,15 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
ecore_desktop_paths_file_find
(ecore_desktop_paths_icons, path, 0, NULL, NULL);
if (found)
break;
{
if (ecore_file_is_dir(found))
{
free(found);
found = NULL;
}
else
break;
}
}
}
}