[goobox] ignore cover smaller then 10 pixels, give priority to libcoverart



commit e16541814748cc5c87981777de53d0a47eec07f4
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Mar 18 20:10:27 2013 +0100

    ignore cover smaller then 10 pixels, give priority to libcoverart

 src/dlg-cover-chooser.c |   45 +++++++++++++++++++++++++------------------
 src/dlg-cover-chooser.h |    2 +-
 src/goo-window.c        |   48 ++++++++++++++++++++++++++++++++--------------
 src/goo-window.h        |    7 +++--
 4 files changed, 64 insertions(+), 38 deletions(-)
---
diff --git a/src/dlg-cover-chooser.c b/src/dlg-cover-chooser.c
index d842c45..76ff251 100644
--- a/src/dlg-cover-chooser.c
+++ b/src/dlg-cover-chooser.c
@@ -571,10 +571,13 @@ image_data_ready_for_query_cb (void     *buffer,
                               gpointer  user_data)
 {
        FetchData *data = user_data;
+       gboolean   success;
 
-       if ((error == NULL) && (count > 0))
-               goo_window_set_cover_image_from_data (data->window, buffer, count);
-       else
+       success = (error == NULL) && (count > 0);
+       if (success)
+               success = goo_window_set_cover_image_from_data (data->window, buffer, count);
+
+       if (! success)
                fetch_cover_image_from_album_info (data->window,
                                                   goo_window_get_album (data->window),
                                                   FETCH_COVER_STAGE_AFTER_WEB_SEARCH);
@@ -652,10 +655,13 @@ image_data_ready_for_asin_cb (void     *buffer,
                              gpointer  user_data)
 {
        FetchData *data = user_data;
+       gboolean   success;
 
-       if ((error == NULL) && (count > 0))
-               goo_window_set_cover_image_from_data (data->window, buffer, count);
-       else
+       success = (error == NULL) && (count > 0);
+       if (success)
+               success = goo_window_set_cover_image_from_data (data->window, buffer, count);
+
+       if (! success)
                fetch_cover_image_from_album_info (data->window,
                                                   goo_window_get_album (data->window),
                                                   FETCH_COVER_STAGE_AFTER_ASIN);
@@ -811,12 +817,13 @@ metadata_get_coverart_cb (GObject      *source_object,
        CoverArtData *data = user_data;
        guchar       *buffer;
        gsize         size;
+       gboolean      success;
 
-       if (metadata_get_coverart_finish (result, &buffer, &size))
-               goo_window_set_cover_image_from_data (data->window,
-                                                     buffer,
-                                                     size);
-       else
+       success = metadata_get_coverart_finish (result, &buffer, &size);
+       if (success)
+               success = goo_window_set_cover_image_from_data (data->window, buffer, size);
+
+       if (! success)
                fetch_cover_image_from_album_info (data->window,
                                                   data->album,
                                                   FETCH_COVER_STAGE_AFTER_LIBCOVERART);
@@ -833,14 +840,6 @@ fetch_cover_image_from_album_info (GooWindow       *window,
                                   AlbumInfo       *album,
                                   FetchCoverStage  after_stage)
 {
-       if ((FETCH_COVER_STAGE_AFTER_ASIN > after_stage)
-           && (album != NULL)
-           && (album->asin != NULL))
-       {
-               fetch_cover_image_from_asin (window, album->asin);
-               return;
-       }
-
 #if HAVE_LIBCOVERART
 
        if ((FETCH_COVER_STAGE_AFTER_LIBCOVERART > after_stage)
@@ -863,6 +862,14 @@ fetch_cover_image_from_album_info (GooWindow       *window,
 
 #endif
 
+       if ((FETCH_COVER_STAGE_AFTER_ASIN > after_stage)
+           && (album != NULL)
+           && (album->asin != NULL))
+       {
+               fetch_cover_image_from_asin (window, album->asin);
+               return;
+       }
+
        if ((FETCH_COVER_STAGE_AFTER_WEB_SEARCH > after_stage)
            && (album != NULL)
            && (album->title != NULL)
diff --git a/src/dlg-cover-chooser.h b/src/dlg-cover-chooser.h
index 1bb5eeb..5315902 100644
--- a/src/dlg-cover-chooser.h
+++ b/src/dlg-cover-chooser.h
@@ -28,8 +28,8 @@
 
 typedef enum {
        FETCH_COVER_STAGE_0,
-       FETCH_COVER_STAGE_AFTER_ASIN,
        FETCH_COVER_STAGE_AFTER_LIBCOVERART,
+       FETCH_COVER_STAGE_AFTER_ASIN,
        FETCH_COVER_STAGE_AFTER_WEB_SEARCH
 } FetchCoverStage;
 
diff --git a/src/goo-window.c b/src/goo-window.c
index c2faa2c..e538e29 100644
--- a/src/goo-window.c
+++ b/src/goo-window.c
@@ -2541,16 +2541,23 @@ goo_window_get_player_info (GooWindow *window)
 }
 
 
-void
+#define MIN_COVER_SIZE 10
+
+
+gboolean
 goo_window_set_cover_image_from_pixbuf (GooWindow *window,
                                        GdkPixbuf *image)
 {
        GError    *error = NULL;
        GdkPixbuf *frame;
        char      *cover_filename;
+       gboolean   image_saved;
 
        if (image == NULL)
-               return;
+               return FALSE;
+
+       if ((gdk_pixbuf_get_width (image) < MIN_COVER_SIZE) || (gdk_pixbuf_get_height (image) < 
MIN_COVER_SIZE))
+               return FALSE;
 
        frame = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (image),
                                gdk_pixbuf_get_has_alpha (image),
@@ -2568,44 +2575,51 @@ goo_window_set_cover_image_from_pixbuf (GooWindow *window,
        cover_filename = goo_window_get_cover_filename (window);
        debug (DEBUG_INFO, "SAVE IMAGE %s\n", cover_filename);
 
-       if (! gdk_pixbuf_save (frame, cover_filename, "png", &error, NULL))
-               _gtk_error_dialog_from_gerror_run (GTK_WINDOW (window),
-                                                  _("Could not save cover image"),
-                                                  &error);
-       else {
+       image_saved = gdk_pixbuf_save (frame, cover_filename, "png", &error, NULL);
+       if (image_saved) {
                goo_window_set_current_cd_autofetch (window, FALSE);
                goo_window_update_cover (window);
        }
+       else
+               _gtk_error_dialog_from_gerror_run (GTK_WINDOW (window),
+                                                  _("Could not save cover image"),
+                                                  &error);
 
        g_free (cover_filename);
        g_object_unref (frame);
+
+       return image_saved;
 }
 
 
-void
+gboolean
 goo_window_set_cover_image (GooWindow  *window,
                            const char *filename)
 {
        GdkPixbuf *image;
        GError    *error = NULL;
+       gboolean   result;
 
        if (window->priv->hibernate)
-               return;
+               return FALSE;
 
        image = gdk_pixbuf_new_from_file (filename, &error);
        if (image == NULL) {
                _gtk_error_dialog_from_gerror_run (GTK_WINDOW (window),
                                                   _("Could not load image"),
                                                   &error);
-               return;
+               return FALSE;
        }
-       goo_window_set_cover_image_from_pixbuf (window, image);
+
+       result = goo_window_set_cover_image_from_pixbuf (window, image);
 
        g_object_unref (image);
+
+       return result;
 }
 
 
-void
+gboolean
 goo_window_set_cover_image_from_data (GooWindow *window,
                                      void      *buffer,
                                      gsize      count)
@@ -2613,24 +2627,28 @@ goo_window_set_cover_image_from_data (GooWindow *window,
        GInputStream *stream;
        GdkPixbuf    *image;
        GError       *error = NULL;
+       gboolean      result;
 
        if (window->priv->hibernate)
-               return;
+               return FALSE;
 
        stream = g_memory_input_stream_new_from_data (buffer, count, NULL);
        image = gdk_pixbuf_new_from_stream (stream, NULL, &error);
+
        if (image == NULL) {
                _gtk_error_dialog_from_gerror_run (GTK_WINDOW (window),
                                                   _("Could not load image"),
                                                   &error);
                g_object_unref (stream);
-               return;
+               return FALSE;
        }
 
-       goo_window_set_cover_image_from_pixbuf (window, image);
+       result = goo_window_set_cover_image_from_pixbuf (window, image);
 
        g_object_unref (image);
        g_object_unref (stream);
+
+       return result;
 }
 
 
diff --git a/src/goo-window.h b/src/goo-window.h
index 8d4e93b..133ce86 100644
--- a/src/goo-window.h
+++ b/src/goo-window.h
@@ -77,11 +77,12 @@ GList *     goo_window_get_tracks                (GooWindow    *window,
 GooPlayer * goo_window_get_player                (GooWindow    *window);
 GtkWidget * goo_window_get_player_info           (GooWindow    *window);
 void        goo_window_update_cover              (GooWindow    *window);
-void        goo_window_set_cover_image_from_pixbuf (GooWindow  *window,
+gboolean    goo_window_set_cover_image_from_pixbuf
+                                                (GooWindow  *window,
                                                  GdkPixbuf    *image);
-void        goo_window_set_cover_image           (GooWindow    *window,
+gboolean    goo_window_set_cover_image           (GooWindow    *window,
                                                  const char   *filename);
-void        goo_window_set_cover_image_from_data (GooWindow    *window,
+gboolean    goo_window_set_cover_image_from_data (GooWindow    *window,
                                                  void         *buffer,
                                                  gsize         count);
 char *      goo_window_get_cover_filename        (GooWindow    *window);


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