[nautilus] ui-utilities: move nautilus_thumbnail_frame_image() here



commit 17f17214a64674bd3079d1a252fed2b6103f9ff4
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Aug 31 12:22:15 2012 -0400

    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.

 libnautilus-private/nautilus-file.c         |    6 +--
 libnautilus-private/nautilus-thumbnails.c   |   50 ----------------------
 libnautilus-private/nautilus-thumbnails.h   |    1 -
 libnautilus-private/nautilus-ui-utilities.c |   60 ++++++++++++++++++++++++++-
 libnautilus-private/nautilus-ui-utilities.h |    5 +-
 5 files changed, 63 insertions(+), 59 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 6691f7b..75565c3 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -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
diff --git a/libnautilus-private/nautilus-thumbnails.c b/libnautilus-private/nautilus-thumbnails.c
index b58de57..15ba59a 100644
--- a/libnautilus-private/nautilus-thumbnails.c
+++ b/libnautilus-private/nautilus-thumbnails.c
@@ -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)
 {
diff --git a/libnautilus-private/nautilus-thumbnails.h b/libnautilus-private/nautilus-thumbnails.h
index 64e0b62..ce46f57 100644
--- a/libnautilus-private/nautilus-thumbnails.h
+++ b/libnautilus-private/nautilus-thumbnails.h
@@ -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);
diff --git a/libnautilus-private/nautilus-ui-utilities.c b/libnautilus-private/nautilus-ui-utilities.c
index 69fbdb1..539ddca 100644
--- a/libnautilus-private/nautilus-ui-utilities.c
+++ b/libnautilus-private/nautilus-ui-utilities.c
@@ -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;
+}
diff --git a/libnautilus-private/nautilus-ui-utilities.h b/libnautilus-private/nautilus-ui-utilities.h
index 642aa72..12e2e5e 100644
--- a/libnautilus-private/nautilus-ui-utilities.h
+++ b/libnautilus-private/nautilus-ui-utilities.h
@@ -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 */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]