/* icon_manager.c - gfxmenu icon manager. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/gui_string_util.h>
#include <grub/bitmap_scale.h>
#include <grub/icon_manager.h>
/* Currently hard coded to '.png' extension. */
typedef struct icon_entry
{
char *class_name;
} *icon_entry_t;
struct grub_gfxmenu_icon_manager
{
char *theme_path;
int icon_width;
int icon_height;
/* Icon cache: linked list w/ dummy head node. */
};
/* Create a new icon manager and return a point to it. */
{
if (! mgr)
return 0;
mgr->theme_path = 0;
mgr->icon_width = 0;
mgr->icon_height = 0;
/* Initialize the dummy head node. */
return mgr;
}
/* Destroy the icon manager MGR, freeing all resources used by it.
Note: Any bitmaps returned by grub_gfxmenu_icon_manager_get_icon()
are destroyed and must not be used by the caller after this function
is called. */
void
{
}
/* Clear the icon cache. */
void
{
{
}
}
/* Set the theme path. If the theme path is changed, the icon cache
is cleared. */
void
const char *path)
{
/* Clear the cache if the theme path has changed. */
}
/* Set the icon size. When icons are requested from the icon manager,
they are scaled to this size before being returned. If the size is
changed, the icon cache is cleared. */
void
{
/* If the width or height is changed, we must clear the cache, since the
scaled bitmaps are stored in the cache. */
}
/* Try to load an icon for the specified CLASS_NAME in the directory DIR.
Returns 0 if the icon could not be loaded, or returns a pointer to a new
bitmap if it was successful. */
static struct grub_video_bitmap *
const char *dir, const char *class_name)
{
char *path;
int l;
if (! path)
return 0;
l = grub_strlen (path);
{
path[l] = '/';
path[l+1] = 0;
}
if (! raw_bitmap)
return 0;
if (! scaled_bitmap)
{
grub_error_push ();
return 0;
}
return scaled_bitmap;
}
/* Get the icon for the specified class CLASS_NAME. If an icon for
CLASS_NAME already exists in the cache, then a reference to the cached
bitmap is returned. If it is not cached, then it is loaded and cached.
If no icon could be could for CLASS_NAME, then 0 is returned. */
static struct grub_video_bitmap *
{
/* First check the icon cache. */
{
}
if (! mgr->theme_path)
return 0;
/* Otherwise, we search for an icon to load. */
char *icons_dir;
icon = 0;
if (icons_dir)
{
}
if (! icon)
{
const char *icondir;
if (icondir)
}
/* No icon was found. */
/* This should probably be noted in the cache, so that a search is not
performed each time an icon for CLASS_NAME is requested. */
if (! icon)
return 0;
/* Insert a new cache entry for this icon. */
if (! entry)
{
return 0;
}
}
/* Get the best available icon for ENTRY. Beginning with the first class
listed in the menu entry and proceeding forward, an icon for each class
is searched for. The first icon found is returned. The returned icon
is scaled to the size specified by
grub_gfxmenu_icon_manager_set_icon_size().
Note: Bitmaps returned by this function are destroyed when the
icon manager is destroyed.
*/
struct grub_video_bitmap *
{
struct grub_menu_entry_class *c;
/* Try each class in succession. */
icon = 0;
return icon;
}