[nautilus] Add film strip in nautilus rather than in thumbnailer



commit 94d208755dbadf126fb7a6e770fe6f4ffc40535b
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Feb 8 16:26:08 2014 +0100

    Add film strip in nautilus rather than in thumbnailer
    
    This allows front-ends such as Totem to use the generated thumbnails
    without the film strip.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723907

 icons/filmholes.png                             |  Bin 0 -> 173 bytes
 libnautilus-private/Makefile.am                 |    1 +
 libnautilus-private/nautilus-file.c             |   24 ++++++++-
 libnautilus-private/nautilus-ui-utilities.c     |   56 +++++++++++++++++--
 libnautilus-private/nautilus-ui-utilities.h     |    1 +
 libnautilus-private/nautilus-video-mime-types.h |   65 +++++++++++++++++++++++
 src/nautilus.gresource.xml                      |    1 +
 7 files changed, 141 insertions(+), 7 deletions(-)
---
diff --git a/icons/filmholes.png b/icons/filmholes.png
new file mode 100644
index 0000000..84b7e1e
Binary files /dev/null and b/icons/filmholes.png differ
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index dc8e1d1..0717986 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -172,6 +172,7 @@ libnautilus_private_la_SOURCES = \
        nautilus-tree-view-drag-dest.h \
        nautilus-ui-utilities.c \
        nautilus-ui-utilities.h \
+       nautilus-video-mime-types.h \
        nautilus-vfs-directory.c \
        nautilus-vfs-directory.h \
        nautilus-vfs-file.c \
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 482ad21..6a8de7e 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -42,6 +42,7 @@
 #include "nautilus-search-directory-file.h"
 #include "nautilus-thumbnails.h"
 #include "nautilus-ui-utilities.h"
+#include "nautilus-video-mime-types.h"
 #include "nautilus-vfs-file.h"
 #include "nautilus-file-undo-operations.h"
 #include "nautilus-file-undo-manager.h"
@@ -4064,6 +4065,24 @@ nautilus_file_should_show_thumbnail (NautilusFile *file)
        return FALSE;
 }
 
+static gboolean
+nautilus_is_video_file (NautilusFile *file)
+{
+       const char *mime_type;
+       guint i;
+
+       mime_type = eel_ref_str_peek (file->details->mime_type);
+       if (mime_type == NULL)
+               return FALSE;
+
+       for (i = 0; video_mime_types[i] != NULL; i++) {
+               if (g_content_type_equals (video_mime_types[i], mime_type))
+                       return TRUE;
+       }
+
+       return FALSE;
+}
+
 static void
 prepend_icon_name (const char *name,
                   GThemedIcon *icon)
@@ -4294,7 +4313,10 @@ nautilus_file_get_icon (NautilusFile *file,
 
                        /* We don't want frames around small icons */
                        if (!gdk_pixbuf_get_has_alpha (raw_pixbuf) || s >= 128 * scale) {
-                               nautilus_ui_frame_image (&scaled_pixbuf);
+                               if (nautilus_is_video_file (file))
+                                       nautilus_ui_frame_video (&scaled_pixbuf);
+                               else
+                                       nautilus_ui_frame_image (&scaled_pixbuf);
                        }
 
                        g_object_unref (raw_pixbuf);
diff --git a/libnautilus-private/nautilus-ui-utilities.c b/libnautilus-private/nautilus-ui-utilities.c
index 7b08b8c..785079d 100644
--- a/libnautilus-private/nautilus-ui-utilities.c
+++ b/libnautilus-private/nautilus-ui-utilities.c
@@ -176,12 +176,7 @@ 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);
-               }
+               thumbnail_frame = gdk_pixbuf_new_from_resource 
("/org/gnome/nautilus/icons/thumbnail_frame.png", NULL);
        }
 
        return thumbnail_frame;
@@ -215,3 +210,52 @@ nautilus_ui_frame_image (GdkPixbuf **pixbuf)
 
        *pixbuf = pixbuf_with_frame;
 }
+
+static GdkPixbuf *filmholes_left = NULL;
+static GdkPixbuf *filmholes_right = NULL;
+
+static gboolean
+ensure_filmholes (void)
+{
+       if (filmholes_left == NULL) {
+               filmholes_left = gdk_pixbuf_new_from_resource ("/org/gnome/nautilus/icons/filmholes.png", 
NULL);
+       }
+       if (filmholes_right == NULL &&
+           filmholes_left != NULL) {
+               filmholes_right = gdk_pixbuf_flip (filmholes_left, FALSE);
+       }
+
+       return (filmholes_left && filmholes_right);
+}
+
+void
+nautilus_ui_frame_video (GdkPixbuf **pixbuf)
+{
+       int width, height;
+       int holes_width, holes_height;
+       int i;
+
+       if (!ensure_filmholes ())
+               return;
+
+       width = gdk_pixbuf_get_width (*pixbuf);
+       height = gdk_pixbuf_get_height (*pixbuf);
+       holes_width = gdk_pixbuf_get_width (filmholes_left);
+       holes_height = gdk_pixbuf_get_height (filmholes_left);
+
+       for (i = 0; i < height; i += holes_height) {
+               gdk_pixbuf_composite (filmholes_left, *pixbuf, 0, i,
+                                     MIN (width, holes_width),
+                                     MIN (height - i, holes_height),
+                                     0, i, 1, 1, GDK_INTERP_NEAREST, 255);
+       }
+
+       for (i = 0; i < height; i += holes_height) {
+               gdk_pixbuf_composite (filmholes_right, *pixbuf,
+                                     width - holes_width, i,
+                                     MIN (width, holes_width),
+                                     MIN (height - i, holes_height),
+                                     width - holes_width, i,
+                                     1, 1, GDK_INTERP_NEAREST, 255);
+       }
+}
diff --git a/libnautilus-private/nautilus-ui-utilities.h b/libnautilus-private/nautilus-ui-utilities.h
index d988585..0341478 100644
--- a/libnautilus-private/nautilus-ui-utilities.h
+++ b/libnautilus-private/nautilus-ui-utilities.h
@@ -42,5 +42,6 @@ GdkPixbuf * nautilus_ui_get_menu_icon              (const char        *icon_name
 char * nautilus_escape_action_name                 (const char        *action_name,
                                                    const char        *prefix);
 void   nautilus_ui_frame_image                     (GdkPixbuf        **pixbuf);
+void   nautilus_ui_frame_video                     (GdkPixbuf        **pixbuf);
 
 #endif /* NAUTILUS_UI_UTILITIES_H */
diff --git a/libnautilus-private/nautilus-video-mime-types.h b/libnautilus-private/nautilus-video-mime-types.h
new file mode 100644
index 0000000..e0d4aac
--- /dev/null
+++ b/libnautilus-private/nautilus-video-mime-types.h
@@ -0,0 +1,65 @@
+/* generated with mime-type-include.sh in the totem module, don't edit or 
+   commit in the nautilus module without filing a bug against totem */
+static const char *video_mime_types[] = {
+"application/mxf",
+"application/ogg",
+"application/ram",
+"application/sdp",
+"application/vnd.apple.mpegurl",
+"application/vnd.ms-wpl",
+"application/vnd.rn-realmedia",
+"application/x-extension-m4a",
+"application/x-extension-mp4",
+"application/x-flash-video",
+"application/x-matroska",
+"application/x-netshow-channel",
+"application/x-ogg",
+"application/x-quicktimeplayer",
+"application/x-shorten",
+"image/vnd.rn-realpix",
+"image/x-pict",
+"misc/ultravox",
+"text/x-google-video-pointer",
+"video/3gp",
+"video/3gpp",
+"video/dv",
+"video/divx",
+"video/fli",
+"video/flv",
+"video/mp2t",
+"video/mp4",
+"video/mp4v-es",
+"video/mpeg",
+"video/msvideo",
+"video/ogg",
+"video/quicktime",
+"video/vivo",
+"video/vnd.divx",
+"video/vnd.mpegurl",
+"video/vnd.rn-realvideo",
+"video/vnd.vivo",
+"video/webm",
+"video/x-anim",
+"video/x-avi",
+"video/x-flc",
+"video/x-fli",
+"video/x-flic",
+"video/x-flv",
+"video/x-m4v",
+"video/x-matroska",
+"video/x-mpeg",
+"video/x-mpeg2",
+"video/x-ms-asf",
+"video/x-ms-asx",
+"video/x-msvideo",
+"video/x-ms-wm",
+"video/x-ms-wmv",
+"video/x-ms-wmx",
+"video/x-ms-wvx",
+"video/x-nsv",
+"video/x-ogm+ogg",
+"video/x-theora+ogg",
+"video/x-totem-stream",
+"audio/x-pn-realaudio",
+NULL
+};
diff --git a/src/nautilus.gresource.xml b/src/nautilus.gresource.xml
index 62f8e11..15287d5 100644
--- a/src/nautilus.gresource.xml
+++ b/src/nautilus.gresource.xml
@@ -10,6 +10,7 @@
     <file>nautilus-shell-ui.xml</file>
     <file>nautilus-app-menu.ui</file>
     <file alias="icons/thumbnail_frame.png">../icons/thumbnail_frame.png</file>
+    <file alias="icons/filmholes.png">../icons/filmholes.png</file>
     <file alias="icons/knob.png">../icons/knob.png</file>
   </gresource>
 </gresources>


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