Bail early on error.

Jump out of search when found.


SVN revision: 26046
This commit is contained in:
sebastid 2006-09-23 08:48:49 +00:00 committed by sebastid
parent 833f9c2a9c
commit 9cb768108e
1 changed files with 123 additions and 156 deletions

View File

@ -157,6 +157,11 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
Ecore_Desktop_Icon_Theme *theme;
char path[PATH_MAX];
char *found = NULL;
int wanted_size;
int minimal_size = INT_MAX;
int i;
char *closest = NULL;
Ecore_Desktop_Icon_Theme_Directory *directory;
if ((icon == NULL) || (icon[0] == '\0'))
return NULL;
@ -172,15 +177,8 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
printf("SEARCHING FOR %s\n", icn);
#endif
if (theme)
{
if (theme->Directories)
{
int wanted_size;
int minimal_size = INT_MAX;
int i;
char *closest = NULL;
Ecore_Desktop_Icon_Theme_Directory *directory;
if (!theme) return NULL;
if (!theme->Directories) goto done;
wanted_size = atoi(icon_size);
/* Loop through the themes directories. */
@ -197,44 +195,26 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
switch (directory->type[0])
{
case 'F': /* Fixed. */
{
match = (wanted_size == directory->size);
result_size = abs(directory->size - wanted_size);
break;
}
case 'S': /* Scaled. */
{
match =
((directory->minimum <= wanted_size)
&& (wanted_size <= directory->maximum));
match = ((directory->minimum <= wanted_size) &&
(wanted_size <= directory->maximum));
if (wanted_size < directory->minimum)
result_size =
directory->minimum - wanted_size;
result_size = directory->minimum - wanted_size;
if (wanted_size > directory->maximum)
result_size =
wanted_size - directory->maximum;
result_size = wanted_size - directory->maximum;
break;
}
default: /* Threshold. */
{
match =
(((directory->size -
directory->threshold) <=
wanted_size)
&& (wanted_size <=
(directory->size +
directory->threshold)));
if (wanted_size <
(directory->size - directory->threshold))
result_size =
directory->minimum - wanted_size;
if (wanted_size >
(directory->size + directory->threshold))
result_size =
wanted_size - directory->maximum;
match = (((directory->size - directory->threshold) <= wanted_size) &&
(wanted_size <= (directory->size + directory->threshold)));
if (wanted_size < (directory->size - directory->threshold))
result_size = directory->minimum - wanted_size;
if (wanted_size > (directory->size + directory->threshold))
result_size = wanted_size - directory->maximum;
break;
}
}
/* Look for icon with all extensions. */
for (i = 0; ext[i] != NULL; i++)
@ -242,15 +222,13 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
/* Check if there will be an extension. */
if ((ext[i][0] == '\0') && (strrchr(icon, '.') == NULL))
continue;
snprintf(path, PATH_MAX,
"%s/%s/%s%s",
snprintf(path, PATH_MAX, "%s/%s/%s%s",
icon_theme, directory->path, icon, ext[i]);
#ifdef DEBUG
printf("FDO icon = %s\n", path);
#endif
found =
ecore_desktop_paths_file_find
(ecore_desktop_paths_icons, path, 0, NULL, NULL);
found = ecore_desktop_paths_file_find(ecore_desktop_paths_icons, path,
0, NULL, NULL);
if (found)
{
if (ecore_file_is_dir(found))
@ -259,12 +237,11 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
found = NULL;
}
else if (match) /* If there is a match in sizes, return the icon. */
break;
goto done;
else if (result_size < minimal_size) /* While we are here, figure out our next fallback strategy. */
{
minimal_size = result_size;
if (closest)
free(closest);
if (closest) free(closest);
closest = found;
found = NULL;
}
@ -276,42 +253,34 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
}
}
}
if (found)
break;
} /* while ((directory = ecore_list_next(directory_paths)) != NULL) */
if (!found)
{
/* Fall back strategy #1, look for closest size in this theme. */
found = closest;
if (found) goto done;
/* Fall back strategy #2, Try again with the parent themes. */
if ((!found) && (theme->Inherits)
&& (strcmp(icon_theme, "hicolor") != 0))
if ((theme->Inherits) && (strcmp(icon_theme, "hicolor") != 0))
{
char *inherits;
ecore_list_goto_first(theme->Inherits);
while ((inherits = ecore_list_next(theme->Inherits)) != NULL)
{
found = (char *) _ecore_desktop_icon_find0(icon, icon_size, inherits);
if (found)
break;
found = _ecore_desktop_icon_find0(icon, icon_size, inherits);
if (found) goto done;
}
}
/* Fall back strategy #3, Try the default hicolor theme. */
if ((!found)
&& (!(theme->Inherits))
&& (strcmp(icon_theme, "hicolor") != 0))
if ((!(theme->Inherits)) && (strcmp(icon_theme, "hicolor") != 0))
{
found = (char *)
_ecore_desktop_icon_find0(icon, icon_size, "hicolor");
found = _ecore_desktop_icon_find0(icon, icon_size, "hicolor");
if (found) goto done;
}
if (!found)
{
/* Fall back strategy #4, Just search in the base of the icon directories. */
for (i = 0; ext[i] != NULL; i++)
{
@ -322,9 +291,8 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
#ifdef DEBUG
printf("FDO icon = %s\n", path);
#endif
found =
ecore_desktop_paths_file_find
(ecore_desktop_paths_icons, path, 0, NULL, NULL);
found = ecore_desktop_paths_file_find(ecore_desktop_paths_icons,
path, 0, NULL, NULL);
if (found)
{
if (ecore_file_is_dir(found))
@ -333,14 +301,13 @@ _ecore_desktop_icon_find0(const char *icon, const char *icon_size,
found = NULL;
}
else
break;
goto done;
}
}
}
}
} /* if (theme->Directories) */
done:
ecore_desktop_icon_theme_destroy(theme);
} /* if (theme) */
return found;
}