Revision: 1757
          http://gtkpod.svn.sourceforge.net/gtkpod/?rev=1757&view=rev
Author:   phantom_sf
Date:     2007-11-04 17:48:37 -0800 (Sun, 04 Nov 2007)

Log Message:
-----------
2007-11-04 P.G. Richardson <phantom_sf at users.sourceforge.net>

  * src/display_photos.c
  
  New ipods do not necessarily have ITDB_THUMB_PHOTO_LARGE or any
  other photo format so cannot assume these in display of thumbs in
  iconview or preview components.
  
  Fix is to find the first existing smalled thumb in the case of the
  iconview and biggest in the case of preview and scale the pixbufs
  to uniform sizes.
  
  Also, fix to clear the preview when a data change like remove occurs.

Modified Paths:
--------------
    gtkpod/trunk/ChangeLog_detailed
    gtkpod/trunk/src/display_photo.c

Modified: gtkpod/trunk/ChangeLog_detailed
===================================================================
--- gtkpod/trunk/ChangeLog_detailed     2007-11-05 01:16:46 UTC (rev 1756)
+++ gtkpod/trunk/ChangeLog_detailed     2007-11-05 01:48:37 UTC (rev 1757)
@@ -1,5 +1,19 @@
 2007-11-04 P.G. Richardson <phantom_sf at users.sourceforge.net>
 
+  * src/display_photos.c
+  
+  New ipods do not necessarily have ITDB_THUMB_PHOTO_LARGE or any
+  other photo format so cannot assume these in display of thumbs in
+  iconview or preview components.
+  
+  Fix is to find the first existing smalled thumb in the case of the
+  iconview and biggest in the case of preview and scale the pixbufs
+  to uniform sizes.
+  
+  Also, fix to clear the preview when a data change like remove occurs.
+
+2007-11-04 P.G. Richardson <phantom_sf at users.sourceforge.net>
+
   * src/fetchcover.c
   
   Opened up filename handling functions to rest of gtkpod.

Modified: gtkpod/trunk/src/display_photo.c
===================================================================
--- gtkpod/trunk/src/display_photo.c    2007-11-05 01:16:46 UTC (rev 1756)
+++ gtkpod/trunk/src/display_photo.c    2007-11-05 01:48:37 UTC (rev 1757)
@@ -81,6 +81,15 @@
                { "STRING", 0, DND_TEXT_PLAIN }
 };
 
+/* Photo types to try and use in displaying thumbnails */
+static gint photo_types[] = {
+                               ITDB_THUMB_PHOTO_SMALL,
+                   ITDB_THUMB_PHOTO_LARGE,
+                   ITDB_THUMB_PHOTO_FULL_SCREEN,
+                   ITDB_THUMB_PHOTO_TV_SCREEN
+                   };
+static gint PHOTO_TYPES_SIZE = 4;
+
 /* Declarations */
 static void gphoto_create_albumview();
 static void gphoto_create_thumbnailview();
@@ -594,43 +603,49 @@
 /* Display the selected thumbnail image in the preview window */
 static void gphoto_display_photo_preview(Artwork *artwork)
 {
-       Thumb *thumb;
+       Thumb *thumb = NULL;
        GdkPixbuf *pixbuf, *scaled;
        gint width, height;
        gdouble ratio;
-
+       gint i;
+       
        g_return_if_fail (artwork);
 
-       thumb= itdb_artwork_get_thumb_by_type (artwork, 
ITDB_THUMB_PHOTO_FULL_SCREEN);
-       if (thumb)
+       for (i = (PHOTO_TYPES_SIZE - 1); i >= 0 && thumb == NULL; --i)
        {
-               pixbuf = itdb_thumb_get_gdk_pixbuf (device, thumb);
-               g_return_if_fail (pixbuf);
+               /* Start from biggest photo type and go smaller */
+               thumb = itdb_artwork_get_thumb_by_type (artwork, 
photo_types[i]);
+       }
+                       
+       /* should have a thumb now but check anyway and fire off a warning if 
it is still null */
+       g_return_if_fail (thumb);
+       
+       pixbuf = itdb_thumb_get_gdk_pixbuf (device, thumb);
+       g_return_if_fail (pixbuf);
 
-               /* Size of the preview GtkImage is set to 220x176, technically 
-                * the same as PHOTO_FULL_SCREEN for a normal ipod.
-                */
-               width = gdk_pixbuf_get_width (pixbuf);
-               height = gdk_pixbuf_get_height (pixbuf);
-               ratio = (gdouble) width / (gdouble) height;
+       /* Size of the preview GtkImage is set to 220x176, technically 
+        * the same as PHOTO_FULL_SCREEN for a normal ipod.
+        */
+       width = gdk_pixbuf_get_width (pixbuf);
+       height = gdk_pixbuf_get_height (pixbuf);
+       ratio = (gdouble) width / (gdouble) height;
 
-               if (height > PHOTO_FULL_SCREEN_HEIGHT)
-               {
-                       height = PHOTO_FULL_SCREEN_HEIGHT;
-                       width = ratio * height;
-               }
+       if (height > PHOTO_FULL_SCREEN_HEIGHT)
+       {
+               height = PHOTO_FULL_SCREEN_HEIGHT;
+               width = ratio * height;
+       }
 
-               if (width > PHOTO_FULL_SCREEN_WIDTH)
-               {
-                       width = PHOTO_FULL_SCREEN_WIDTH;
-                       height = width / ratio;
-               }
+       if (width > PHOTO_FULL_SCREEN_WIDTH)
+       {
+               width = PHOTO_FULL_SCREEN_WIDTH;
+               height = width / ratio;
+       }
 
-               scaled= gdk_pixbuf_scale_simple (pixbuf, width, height, 
GDK_INTERP_NEAREST);
-               gdk_pixbuf_unref (pixbuf);
+       scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, 
GDK_INTERP_NEAREST);
+       gdk_pixbuf_unref (pixbuf);
 
-               gtk_image_set_from_pixbuf (photo_preview_image, scaled);
-       }
+       gtk_image_set_from_pixbuf (photo_preview_image, scaled);
 }
 
 /* Convenience function that sets the flags on the Extra iTunes Database
@@ -643,6 +658,8 @@
        eitdb = ipod_itdb->userdata;
        eitdb->photo_data_changed = TRUE;
        eitdb->data_changed = TRUE;
+       
+       gtk_image_clear (photo_preview_image);
 }
 
 /**
@@ -738,27 +755,55 @@
 static void gphoto_add_image_to_iconview(Artwork *photo, gint index)
 {
        GdkPixbuf *pixbuf= NULL;
-       Thumb *thumb= NULL;
-       GtkListStore *model= NULL;
-       GtkTreeIter iter;
+               GdkPixbuf *scaled = NULL;
+               Thumb *thumb= NULL;
+               GtkListStore *model= NULL;
+               GtkTreeIter iter;
+               gint i;
+               /* default sizes taken from smallest photo image type in 
itdb_device.c */
+               gint icon_width = 42, icon_height = 30;
+               gfloat pixbuf_width, pixbuf_height;
+               gfloat ratio;
 
-       model = GTK_LIST_STORE (gtk_icon_view_get_model (thumbnail_view));
-
-       thumb = itdb_artwork_get_thumb_by_type (photo, ITDB_THUMB_PHOTO_LARGE);
-       if (thumb)
-       {
+               model = GTK_LIST_STORE (gtk_icon_view_get_model 
(thumbnail_view));
+               for (i = 0; i < PHOTO_TYPES_SIZE && thumb == NULL; ++i)
+               {
+                       thumb = itdb_artwork_get_thumb_by_type (photo, 
photo_types[i]);
+               }
+               
+               /* should have a thumb now but check anyway and fire off a 
warning if it is still null */
+               g_return_if_fail (thumb);
+               
                pixbuf = itdb_thumb_get_gdk_pixbuf (device, thumb);
                g_return_if_fail (pixbuf);
 
+               pixbuf_width = gdk_pixbuf_get_width (pixbuf);
+               pixbuf_height = gdk_pixbuf_get_height (pixbuf);
+               ratio = pixbuf_width / pixbuf_height;
+               
+               if (pixbuf_width > icon_width)
+               {
+                       pixbuf_width = icon_width;
+                       pixbuf_height = pixbuf_width / ratio;
+               }
+               
+               if (pixbuf_height > icon_height)
+               {
+                       pixbuf_height = icon_height;
+                       pixbuf_width = pixbuf_height * ratio;
+               }
+               
+               scaled = gdk_pixbuf_scale_simple(pixbuf, pixbuf_width, 
pixbuf_height, GDK_INTERP_NEAREST);
+               gdk_pixbuf_unref (pixbuf);
+               
                gchar *index_str= NULL;
                index_str = (gchar *) g_malloc (sizeof(gint));
                g_sprintf (index_str, "%d", index);
-
+               
                /* Add a new row to the model */
                gtk_list_store_append (model, &iter);
-               gtk_list_store_set (model, &iter, COL_THUMB_NAIL, pixbuf, 
COL_THUMB_FILENAME, index_str, COL_THUMB_ARTWORK, photo, -1);
+               gtk_list_store_set (model, &iter, COL_THUMB_NAIL, scaled, 
COL_THUMB_FILENAME, index_str, COL_THUMB_ARTWORK, photo, -1);
                g_free (index_str);
-       }
 }
 
 /**


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to