icondir support

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-11-21 15:29:12 +01:00
parent 8dec533a1c
commit aff798d6f4
2 changed files with 18 additions and 13 deletions

View file

@ -150,18 +150,25 @@ grub_resolve_relative_path (const char *base, const char *path)
char *abspath; char *abspath;
char *canonpath; char *canonpath;
char *p; char *p;
grub_size_t l;
/* If PATH is an absolute path, then just use it as is. */ /* If PATH is an absolute path, then just use it as is. */
if (path[0] == '/' || path[0] == '(') if (path[0] == '/' || path[0] == '(')
return canonicalize_path (path); return canonicalize_path (path);
abspath = grub_malloc (grub_strlen (base) + grub_strlen (path) + 1); abspath = grub_malloc (grub_strlen (base) + grub_strlen (path) + 3);
if (! abspath) if (! abspath)
return 0; return 0;
/* Concatenate BASE and PATH. /* Concatenate BASE and PATH. */
Note that BASE is expected to have a trailing slash. */
p = grub_stpcpy (abspath, base); p = grub_stpcpy (abspath, base);
l = grub_strlen (abspath);
if (l == 0 || abspath[l-1] != '/')
{
*p = '/';
p++;
*p = 0;
}
grub_stpcpy (p, path); grub_stpcpy (p, path);
canonpath = canonicalize_path (abspath); canonpath = canonicalize_path (abspath);

View file

@ -26,6 +26,7 @@
#include <grub/bitmap_scale.h> #include <grub/bitmap_scale.h>
#include <grub/menu.h> #include <grub/menu.h>
#include <grub/icon_manager.h> #include <grub/icon_manager.h>
#include <grub/env.h>
/* Currently hard coded to '.png' extension. */ /* Currently hard coded to '.png' extension. */
static const char icon_extension[] = ".png"; static const char icon_extension[] = ".png";
@ -200,19 +201,16 @@ get_icon_by_class (grub_gfxmenu_icon_manager_t mgr, const char *class_name)
icon = try_loading_icon (mgr, icons_dir, class_name); icon = try_loading_icon (mgr, icons_dir, class_name);
grub_free (icons_dir); grub_free (icons_dir);
} }
grub_free (theme_dir);
if (! icon) if (! icon)
{ {
/* If the theme doesn't have an appropriate icon, check in const char *icondir;
"grub/themes/icons". */
/* TODO use GRUB prefix "/icons" */ icondir = grub_env_get ("icondir");
icons_dir = grub_resolve_relative_path (theme_dir, "../icons/"); if (icondir)
if (icons_dir) icon = try_loading_icon (mgr, icondir, class_name);
{
icon = try_loading_icon (mgr, icons_dir, class_name);
grub_free (icons_dir);
}
} }
grub_free (theme_dir);
/* No icon was found. */ /* No icon was found. */
/* This should probably be noted in the cache, so that a search is not /* This should probably be noted in the cache, so that a search is not