Refactor icons handling. Reducing strdups, improve memory cache usage
This commit is contained in:
parent
b32d0d86dc
commit
9e5fb1ef27
1 changed files with 15 additions and 30 deletions
|
@ -703,7 +703,6 @@ midori_view_mime_icon (MidoriView* view,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_ref (icon);
|
|
||||||
midori_view_apply_icon (view, icon, icon_name);
|
midori_view_apply_icon (view, icon, icon_name);
|
||||||
g_free (icon_name);
|
g_free (icon_name);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -819,17 +818,11 @@ katze_net_icon_transfer_cb (KatzeNetRequest* request,
|
||||||
g_warning ("Error writing to file %s "
|
g_warning ("Error writing to file %s "
|
||||||
"in katze_net_icon_transfer_cb()", priv->icon_file);
|
"in katze_net_icon_transfer_cb()", priv->icon_file);
|
||||||
}
|
}
|
||||||
pixbuf = gdk_pixbuf_new_from_file (priv->icon_file, NULL);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
pixbuf = katze_pixbuf_new_from_buffer ((guchar*)request->data,
|
pixbuf = katze_pixbuf_new_from_buffer ((guchar*)request->data,
|
||||||
request->length, request->mime_type, NULL);
|
request->length, request->mime_type, NULL);
|
||||||
|
|
||||||
if (pixbuf)
|
|
||||||
g_object_ref (pixbuf);
|
|
||||||
|
|
||||||
g_hash_table_insert (priv->view->memory,
|
g_hash_table_insert (priv->view->memory,
|
||||||
g_strdup (priv->icon_file), pixbuf);
|
g_strdup (priv->icon_uri), g_object_ref (pixbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pixbuf)
|
if (!pixbuf)
|
||||||
|
@ -842,10 +835,8 @@ katze_net_icon_transfer_cb (KatzeNetRequest* request,
|
||||||
settings = gtk_widget_get_settings (priv->view->web_view);
|
settings = gtk_widget_get_settings (priv->view->web_view);
|
||||||
gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
|
gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
|
||||||
pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, icon_width, icon_height, GDK_INTERP_BILINEAR);
|
pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, icon_width, icon_height, GDK_INTERP_BILINEAR);
|
||||||
|
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
|
|
||||||
katze_assign (priv->view->icon_uri, g_strdup (priv->icon_uri));
|
|
||||||
midori_view_update_icon (priv->view, pixbuf_scaled);
|
midori_view_update_icon (priv->view, pixbuf_scaled);
|
||||||
katze_net_icon_priv_free (priv);
|
katze_net_icon_priv_free (priv);
|
||||||
}
|
}
|
||||||
|
@ -863,8 +854,7 @@ _midori_web_view_load_icon (MidoriView* view)
|
||||||
|
|
||||||
if (midori_uri_is_http (view->icon_uri) || midori_uri_is_http (view->uri))
|
if (midori_uri_is_http (view->icon_uri) || midori_uri_is_http (view->uri))
|
||||||
{
|
{
|
||||||
gchar* icon_uri = g_strdup (view->icon_uri);
|
if (!view->icon_uri)
|
||||||
if (!icon_uri)
|
|
||||||
{
|
{
|
||||||
guint i = 8;
|
guint i = 8;
|
||||||
while (view->uri[i] != '\0' && view->uri[i] != '/')
|
while (view->uri[i] != '\0' && view->uri[i] != '/')
|
||||||
|
@ -872,28 +862,22 @@ _midori_web_view_load_icon (MidoriView* view)
|
||||||
if (view->uri[i] == '/')
|
if (view->uri[i] == '/')
|
||||||
{
|
{
|
||||||
gchar* path = g_strndup (view->uri, i);
|
gchar* path = g_strndup (view->uri, i);
|
||||||
icon_uri = g_strdup_printf ("%s/favicon.ico", path);
|
view->icon_uri = g_strdup_printf ("%s/favicon.ico", path);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
icon_uri = g_strdup_printf ("%s/favicon.ico", view->uri);
|
view->icon_uri = g_strdup_printf ("%s/favicon.ico", view->uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
icon_file = katze_net_get_cached_path (NULL, icon_uri, "icons");
|
if ((pixbuf = g_hash_table_lookup (view->memory, view->icon_uri)))
|
||||||
if (g_hash_table_lookup_extended (view->memory,
|
goto process_pixbuf;
|
||||||
icon_file, NULL, (gpointer)&pixbuf))
|
|
||||||
|
icon_file = katze_net_get_cached_path (NULL, view->icon_uri, "icons");
|
||||||
|
if ((pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL)))
|
||||||
{
|
{
|
||||||
|
g_hash_table_insert (view->memory,
|
||||||
|
g_strdup (view->icon_uri), g_object_ref (pixbuf));
|
||||||
g_free (icon_file);
|
g_free (icon_file);
|
||||||
if (pixbuf)
|
|
||||||
{
|
|
||||||
g_object_ref (pixbuf);
|
|
||||||
katze_assign (view->icon_uri, icon_uri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL)))
|
|
||||||
{
|
|
||||||
g_free (icon_file);
|
|
||||||
katze_assign (view->icon_uri, icon_uri);
|
|
||||||
}
|
}
|
||||||
else if (!view->special)
|
else if (!view->special)
|
||||||
{
|
{
|
||||||
|
@ -901,15 +885,16 @@ _midori_web_view_load_icon (MidoriView* view)
|
||||||
|
|
||||||
priv = g_slice_new (KatzeNetIconPriv);
|
priv = g_slice_new (KatzeNetIconPriv);
|
||||||
priv->icon_file = icon_file;
|
priv->icon_file = icon_file;
|
||||||
priv->icon_uri = icon_uri;
|
priv->icon_uri = g_strdup (view->icon_uri);
|
||||||
priv->view = view;
|
priv->view = view;
|
||||||
|
|
||||||
katze_net_load_uri (NULL, icon_uri,
|
katze_net_load_uri (NULL, priv->icon_uri,
|
||||||
(KatzeNetStatusCb)katze_net_icon_status_cb,
|
(KatzeNetStatusCb)katze_net_icon_status_cb,
|
||||||
(KatzeNetTransferCb)katze_net_icon_transfer_cb, priv);
|
(KatzeNetTransferCb)katze_net_icon_transfer_cb, priv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process_pixbuf:
|
||||||
if (pixbuf)
|
if (pixbuf)
|
||||||
{
|
{
|
||||||
settings = gtk_widget_get_settings (view->web_view);
|
settings = gtk_widget_get_settings (view->web_view);
|
||||||
|
|
Loading…
Reference in a new issue