Commit 17f17214 authored by Cosimo Cecchi's avatar Cosimo Cecchi

ui-utilities: move nautilus_thumbnail_frame_image() here

So that we can use it also for custom icons.
Also, merge some icon size checks into the function itself.
parent 40aed38d
......@@ -43,6 +43,7 @@
#include "nautilus-search-directory.h"
#include "nautilus-search-directory-file.h"
#include "nautilus-thumbnails.h"
#include "nautilus-ui-utilities.h"
#include "nautilus-vfs-file.h"
#include "nautilus-file-undo-operations.h"
#include "nautilus-file-undo-manager.h"
......@@ -4276,10 +4277,7 @@ nautilus_file_get_icon (NautilusFile *file,
MAX (h * scale, 1),
GDK_INTERP_BILINEAR);
/* We don't want frames around small icons */
if (!gdk_pixbuf_get_has_alpha(raw_pixbuf) || s >= 128) {
nautilus_thumbnail_frame_image (&scaled_pixbuf);
}
nautilus_ui_frame_image (&scaled_pixbuf);
g_object_unref (raw_pixbuf);
/* Don't scale up if more than 25%, then read the original
......
......@@ -59,11 +59,6 @@
/* Cool-off period between last file modification time and thumbnail creation */
#define THUMBNAIL_CREATION_DELAY_SECS 3
#define NAUTILUS_THUMBNAIL_FRAME_LEFT 3
#define NAUTILUS_THUMBNAIL_FRAME_TOP 3
#define NAUTILUS_THUMBNAIL_FRAME_RIGHT 3
#define NAUTILUS_THUMBNAIL_FRAME_BOTTOM 3
static gpointer thumbnail_thread_start (gpointer data);
/* structure used for making thumbnails, associating a uri with where the thumbnail is to be stored */
......@@ -190,51 +185,6 @@ thumbnail_thread_starter_cb (gpointer data)
return FALSE;
}
static GdkPixbuf *
nautilus_get_thumbnail_frame (void)
{
static GdkPixbuf *thumbnail_frame = NULL;
if (thumbnail_frame == NULL) {
GInputStream *stream = g_resources_open_stream ("/org/gnome/nautilus/icons/thumbnail_frame.png", 0, NULL);
if (stream != NULL) {
thumbnail_frame = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
g_object_unref (stream);
}
}
return thumbnail_frame;
}
void
nautilus_thumbnail_frame_image (GdkPixbuf **pixbuf)
{
GdkPixbuf *pixbuf_with_frame, *frame;
int left_offset, top_offset, right_offset, bottom_offset;
/* The pixbuf isn't already framed (i.e., it was not made by
* an old Nautilus), so we must embed it in a frame.
*/
frame = nautilus_get_thumbnail_frame ();
if (frame == NULL) {
return;
}
left_offset = NAUTILUS_THUMBNAIL_FRAME_LEFT;
top_offset = NAUTILUS_THUMBNAIL_FRAME_TOP;
right_offset = NAUTILUS_THUMBNAIL_FRAME_RIGHT;
bottom_offset = NAUTILUS_THUMBNAIL_FRAME_BOTTOM;
pixbuf_with_frame = eel_embed_image_in_frame
(*pixbuf, frame,
left_offset, top_offset, right_offset, bottom_offset);
g_object_unref (*pixbuf);
*pixbuf = pixbuf_with_frame;
}
void
nautilus_thumbnail_remove_from_queue (const char *file_uri)
{
......
......@@ -34,7 +34,6 @@ gboolean nautilus_can_thumbnail (NautilusFile *file);
gboolean nautilus_can_thumbnail_internally (NautilusFile *file);
gboolean nautilus_thumbnail_is_mimetype_limited_by_size
(const char *mime_type);
void nautilus_thumbnail_frame_image (GdkPixbuf **pixbuf);
/* Queue handling: */
void nautilus_thumbnail_remove_from_queue (const char *file_uri);
......
......@@ -23,12 +23,13 @@
*/
#include <config.h>
#include "nautilus-ui-utilities.h"
#include "nautilus-icon-info.h"
#include <gio/gio.h>
#include <eel/eel-graphic-effects.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <eel/eel-debug.h>
void
nautilus_ui_unmerge_ui (GtkUIManager *ui_manager,
......@@ -165,3 +166,58 @@ nautilus_escape_action_name (const char *action_name,
}
return g_string_free (s, FALSE);
}
static GdkPixbuf *
nautilus_get_thumbnail_frame (void)
{
static GdkPixbuf *thumbnail_frame = NULL;
if (thumbnail_frame == NULL) {
GInputStream *stream = g_resources_open_stream
("/org/gnome/nautilus/icons/thumbnail_frame.png", 0, NULL);
if (stream != NULL) {
thumbnail_frame = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
g_object_unref (stream);
}
}
return thumbnail_frame;
}
#define NAUTILUS_THUMBNAIL_FRAME_LEFT 3
#define NAUTILUS_THUMBNAIL_FRAME_TOP 3
#define NAUTILUS_THUMBNAIL_FRAME_RIGHT 3
#define NAUTILUS_THUMBNAIL_FRAME_BOTTOM 3
void
nautilus_ui_frame_image (GdkPixbuf **pixbuf)
{
GdkPixbuf *pixbuf_with_frame, *frame;
int left_offset, top_offset, right_offset, bottom_offset;
int size;
frame = nautilus_get_thumbnail_frame ();
if (frame == NULL) {
return;
}
size = MAX (gdk_pixbuf_get_width (*pixbuf),
gdk_pixbuf_get_height (*pixbuf));
/* We don't want frames around small icons */
if (size < 128 && gdk_pixbuf_get_has_alpha (*pixbuf)) {
return;
}
left_offset = NAUTILUS_THUMBNAIL_FRAME_LEFT;
top_offset = NAUTILUS_THUMBNAIL_FRAME_TOP;
right_offset = NAUTILUS_THUMBNAIL_FRAME_RIGHT;
bottom_offset = NAUTILUS_THUMBNAIL_FRAME_BOTTOM;
pixbuf_with_frame = eel_embed_image_in_frame
(*pixbuf, frame,
left_offset, top_offset, right_offset, bottom_offset);
g_object_unref (*pixbuf);
*pixbuf = pixbuf_with_frame;
}
......@@ -38,7 +38,8 @@ GtkAction * nautilus_action_from_menu_item (NautilusMenuItem *item);
GdkPixbuf * nautilus_ui_get_menu_icon (const char *icon_name);
char * nautilus_escape_action_name (const char *action_name, const char *prefix);
char * nautilus_escape_action_name (const char *action_name,
const char *prefix);
void nautilus_ui_frame_image (GdkPixbuf **pixbuf);
#endif /* NAUTILUS_UI_UTILITIES_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment