mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-02-20 00:14:06 +03:00
Implement a very basic favicon cache for the hotlist menu to use
This commit is contained in:
parent
dfc095bd90
commit
0c5bb37bea
@ -152,7 +152,9 @@ bool bitmap_save(void *bitmap, const char *path, unsigned flags)
|
||||
int err = 0;
|
||||
Object *dto = NULL;
|
||||
|
||||
if(!ami_download_check_overwrite(path, NULL, 0)) return false;
|
||||
if ((flags & AMI_BITMAP_FORCE_OVERWRITE) == 0) {
|
||||
if(!ami_download_check_overwrite(path, NULL, 0)) return false;
|
||||
}
|
||||
|
||||
if(dto = ami_datatype_object_from_bitmap(bitmap))
|
||||
{
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <libraries/Picasso96.h>
|
||||
|
||||
#define AMI_BITMAP_FORMAT RGBFB_R8G8B8A8
|
||||
#define AMI_BITMAP_FORCE_OVERWRITE 0xFF
|
||||
|
||||
struct bitmap {
|
||||
int width;
|
||||
|
37
amiga/gui.c
37
amiga/gui.c
@ -181,6 +181,7 @@ bool cli_force = false;
|
||||
|
||||
static char *current_user;
|
||||
static char *current_user_dir;
|
||||
static char *current_user_faviconcache;
|
||||
|
||||
static const __attribute__((used)) char *stack_cookie = "\0$STACK:262144\0";
|
||||
|
||||
@ -2769,9 +2770,40 @@ static void gui_quit(void)
|
||||
|
||||
FreeVec(current_user_options);
|
||||
FreeVec(current_user_dir);
|
||||
FreeVec(current_user_faviconcache);
|
||||
FreeVec(current_user);
|
||||
}
|
||||
|
||||
char *ami_gui_get_cache_favicon_name(nsurl *url, bool only_if_avail)
|
||||
{
|
||||
STRPTR filename = NULL;
|
||||
BPTR lock = 0;
|
||||
|
||||
if (filename = ASPrintf("%s/%x", current_user_faviconcache, nsurl_hash(url))) {
|
||||
LOG(("favicon cache location: %s", filename));
|
||||
|
||||
if (only_if_avail == true) {
|
||||
if(lock = Lock(filename, ACCESS_READ)) {
|
||||
UnLock(lock);
|
||||
return filename;
|
||||
}
|
||||
} else {
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ami_gui_cache_favicon(nsurl *url, struct bitmap *favicon)
|
||||
{
|
||||
STRPTR filename = NULL;
|
||||
|
||||
if (filename = ami_gui_get_cache_favicon_name(url, false)) {
|
||||
if(favicon) bitmap_save(favicon, filename, AMI_BITMAP_FORCE_OVERWRITE);
|
||||
FreeVec(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void ami_gui_update_hotlist_button(struct gui_window_2 *gwin)
|
||||
{
|
||||
char *url;
|
||||
@ -2785,6 +2817,9 @@ void ami_gui_update_hotlist_button(struct gui_window_2 *gwin)
|
||||
if(hotlist_has_url(nsurl)) {
|
||||
RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_FAVE], gwin->win, NULL,
|
||||
BUTTON_RenderImage, gwin->objects[GID_FAVE_RMV], TAG_DONE);
|
||||
|
||||
if (gwin->bw->window->favicon)
|
||||
ami_gui_cache_favicon(nsurl, content_get_bitmap(gwin->bw->window->favicon));
|
||||
} else {
|
||||
RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_FAVE], gwin->win, NULL,
|
||||
BUTTON_RenderImage, gwin->objects[GID_FAVE_ADD], TAG_DONE);
|
||||
@ -5127,8 +5162,10 @@ int main(int argc, char** argv)
|
||||
|
||||
current_user_options = ASPrintf("%s/Choices", current_user_dir);
|
||||
current_user_cache = ASPrintf("%s/Cache", current_user_dir);
|
||||
current_user_faviconcache = ASPrintf("%s/IconCache", current_user_dir);
|
||||
|
||||
if(lock = CreateDirTree(current_user_cache)) UnLock(lock);
|
||||
if(lock = CreateDirTree(current_user_faviconcache)) UnLock(lock);
|
||||
|
||||
ami_mime_init("PROGDIR:Resources/mimetypes");
|
||||
sprintf(temp, "%s/mimetypes.user", current_user_dir);
|
||||
|
@ -167,6 +167,7 @@ void ami_gui_tabs_toggle_all(void);
|
||||
bool ami_locate_resource(char *fullpath, const char *file);
|
||||
void ami_gui_update_hotlist_button(struct gui_window_2 *gwin);
|
||||
nserror ami_gui_new_blank_tab(struct gui_window_2 *gwin);
|
||||
char *ami_gui_get_cache_favicon_name(nsurl *url, bool only_if_avail);
|
||||
|
||||
struct TextFont *origrpfont;
|
||||
struct MinList *window_list;
|
||||
|
16
amiga/menu.c
16
amiga/menu.c
@ -405,6 +405,13 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin)
|
||||
BITMAP_SourceFile, gwin->menuicon[i],
|
||||
BITMAP_Masking, TRUE,
|
||||
BitMapEnd;
|
||||
|
||||
/* \todo make this scale the bitmap to these dimensions */
|
||||
SetAttrs(icon,
|
||||
BITMAP_Width, 16,
|
||||
BITMAP_Height, 16,
|
||||
TAG_DONE);
|
||||
|
||||
GetAttr(IA_Width, icon, (ULONG *)&icon_width);
|
||||
|
||||
if((gwin->menutype[i] == NM_ITEM) && (gwin->menutype[i+1] == NM_SUB)) {
|
||||
@ -551,7 +558,7 @@ void ami_menu_arexx_scan(struct gui_window_2 *gwin)
|
||||
static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char *title, nsurl *url, bool is_folder)
|
||||
{
|
||||
UBYTE type;
|
||||
char *icon;
|
||||
STRPTR icon;
|
||||
struct gui_window_2 *gw = (struct gui_window_2 *)userdata;
|
||||
|
||||
if(item >= AMI_MENU_HOTLIST_MAX) return false;
|
||||
@ -570,9 +577,10 @@ static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char
|
||||
}
|
||||
|
||||
if(is_folder == true) {
|
||||
icon = "icons/directory.png";
|
||||
icon = ASPrintf("icons/directory.png");
|
||||
} else {
|
||||
icon = "icons/content.png";
|
||||
icon = ami_gui_get_cache_favicon_name(url, true);
|
||||
if (icon == NULL) icon = ASPrintf("icons/content.png");
|
||||
}
|
||||
|
||||
ami_menu_alloc_item(gw, item, type, title,
|
||||
@ -580,6 +588,8 @@ static bool ami_menu_hotlist_add(void *userdata, int level, int item, const char
|
||||
if((is_folder == true) && (type == NM_SUB))
|
||||
gw->menu[item].nm_Flags = NM_ITEMDISABLED;
|
||||
|
||||
if(icon) FreeVec(icon);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user