[sound-juicer] Add barcode and catalog number to multiple_album_dialog



commit d6315bfaaa924906b63d717de592abc6fe22afc3
Author: Andreas Hehn <andreasgnmhehn noiseload de>
Date:   Thu Oct 29 20:52:05 2015 +0100

    Add barcode and catalog number to multiple_album_dialog
    
    Extend the details on the possible albums shown by the
    multiple_album_dialog by the barcode and the catalog number used by
    the label releasing the album/release.  This eases the selection of
    the correct musicbrainz release, when an album was released several
    times and the release label and country do not offer enough
    information to identify the release.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757156

 libjuicer/sj-metadata-musicbrainz5.c |    3 +
 libjuicer/sj-structures.c            |    2 +
 libjuicer/sj-structures.h            |    2 +
 src/sj-main.c                        |  116 ++++++++++++++++++++++++++++------
 4 files changed, 104 insertions(+), 19 deletions(-)
---
diff --git a/libjuicer/sj-metadata-musicbrainz5.c b/libjuicer/sj-metadata-musicbrainz5.c
index 126e01c..5987af9 100644
--- a/libjuicer/sj-metadata-musicbrainz5.c
+++ b/libjuicer/sj-metadata-musicbrainz5.c
@@ -348,6 +348,7 @@ get_release_labels (Mb5Release *release)
     label_data = g_new0 (LabelDetails, 1);
     label_data->name = g_strdup (buffer);
     GET (label_data->sortname, mb5_label_get_sortname, label);
+    GET (label_data->catalog_number, mb5_labelinfo_get_catalognumber, info);
     label_list = g_list_prepend (label_list, label_data);
   skip:
     ;
@@ -902,6 +903,8 @@ make_album_from_release (SjMetadataMusicbrainz5  *self,
   }
 
   album->disc_number = mb5_medium_get_position (medium);
+
+  GET(album->barcode, mb5_release_get_barcode, release);
   fill_tracks_from_medium (self, medium, album, cancellable, error);
   if (*error != NULL)
     return NULL;
diff --git a/libjuicer/sj-structures.c b/libjuicer/sj-structures.c
index ebd7181..579b9c8 100644
--- a/libjuicer/sj-structures.c
+++ b/libjuicer/sj-structures.c
@@ -59,6 +59,7 @@ void album_details_free(AlbumDetails *album)
   g_free (album->wikipedia);
   g_free (album->lyrics_url);
   g_free (album->country);
+  g_free (album->barcode);
   g_free (album->type);
   g_list_free_full (album->labels, (GDestroyNotify)label_details_free);
   g_free (album);
@@ -112,5 +113,6 @@ void label_details_free (LabelDetails *label)
 {
   g_free (label->name);
   g_free (label->sortname);
+  g_free (label->catalog_number);
   g_free (label);
 }
diff --git a/libjuicer/sj-structures.h b/libjuicer/sj-structures.h
index 5cb0b50..28e4aa6 100644
--- a/libjuicer/sj-structures.h
+++ b/libjuicer/sj-structures.h
@@ -81,6 +81,7 @@ struct _AlbumDetails {
   char *type;
   char *lyrics_url;
   char *country;
+  char *barcode;
 };
 
 struct _ArtistDetails {
@@ -101,6 +102,7 @@ struct _ArtistCredit
 struct _LabelDetails {
   char *name;
   char *sortname;
+  char *catalog_number;
 };
 
 void album_details_free(AlbumDetails *album);
diff --git a/src/sj-main.c b/src/sj-main.c
index 7142b5a..364cc08 100644
--- a/src/sj-main.c
+++ b/src/sj-main.c
@@ -871,15 +871,63 @@ static GString* format_label_text (GList* labels)
 
 /**
  * Utility function for multiple_album_dialog to format the
+ * catalog number and barcode of a release.
+ */
+static gchar* format_catalog_number_text (GList* labels)
+{
+   int count;
+   GString *catalog_text;
+   GList *l;
+
+   if (labels == NULL)
+     return NULL;
+
+   /* Count how may label entries actually have a catalog number entry */
+   count = 0;
+   for (l = labels; l != NULL; l = l->next) {
+     if (((LabelDetails*)l->data)->catalog_number != NULL)
+         count++;
+   }
+
+   if (count == 0)
+      return NULL;
+
+   /* Translators: this string is a list of catalog number(s) used by
+      the label(s) to identify the release */
+   catalog_text = g_string_new (ngettext("Catalog No.: ",
+                                         "Catalog Nos.: ",
+                                         count));
+   for(l = labels; l != NULL; l = l->next) {
+     char *catalog_number = ((LabelDetails*)l->data)->catalog_number;
+     if (catalog_number != NULL) {
+       if (count > 1) {
+           g_string_append_printf (catalog_text, "%s, ", catalog_number);
+       } else {
+           g_string_append (catalog_text, catalog_number);
+       }
+       count--;
+     }
+   }
+
+   return g_string_free (catalog_text, FALSE);
+}
+
+/**
+ * Utility function for multiple_album_dialog to format the
  * release label, date and country.
  */
 static char *format_release_details (AlbumDetails *album)
 {
-  gchar *details;
+  GString *details;
   GString *label_text = NULL;
+  gchar *catalog_number_text = NULL;
+
+  details = g_string_new(NULL);
 
-  if (album->labels)
+  if (album->labels != NULL) {
     label_text = format_label_text (album->labels);
+    catalog_number_text = format_catalog_number_text (album->labels);
+  }
 
   if (!sj_str_is_empty (album->country)) {
     if (album->labels) {
@@ -887,56 +935,86 @@ static char *format_release_details (AlbumDetails *album)
         /* Translators: this string appears when multiple CDs were
          * found in musicbrainz online database, it corresponds to
          * "Released: <country> in <year> on <label>" */
-        details = g_strdup_printf (_("Released: %s in %d on %s"),
-                                   album->country,
-                                   gst_date_time_get_year (album->release_date),
-                                   label_text->str);
+        g_string_append_printf (details,
+                                _("Released: %s in %d on %s"),
+                                album->country,
+                                gst_date_time_get_year (album->release_date),
+                                label_text->str);
       } else {
         /* Translators: this string appears when multiple CDs were
          * found in musicbrainz online database, it corresponds to
          * "Released: <country> on <label>" */
-        details = g_strdup_printf (_("Released: %s on %s"), album->country, label_text->str);
+        g_string_append_printf (details,
+                                _("Released: %s on %s"),
+                                album->country, label_text->str);
       }
     } else if (album->release_date && gst_date_time_has_year (album->release_date)) {
       /* Translators: this string appears when multiple CDs were
        * found in musicbrainz online database, it corresponds to
        * "Released: <country> in <year>" */
-      details = g_strdup_printf (_("Released: %s in %d"), album->country,
-                                 gst_date_time_get_year (album->release_date));
+      g_string_append_printf (details,
+                              _("Released: %s in %d"),
+                              album->country,
+                              gst_date_time_get_year (album->release_date));
     } else {
       /* Translators: this string appears when multiple CDs were
        * found in musicbrainz online database, it corresponds to
        * "Released: <country>" */
-      details = g_strdup_printf (_("Released: %s"), album->country);
+      g_string_append_printf (details, _("Released: %s"), album->country);
     }
   } else if (album->release_date && gst_date_time_has_year (album->release_date)) {
     if (album->labels) {
         /* Translators: this string appears when multiple CDs were
          * found in musicbrainz online database, it corresponds to
          * "Released in <year> on <label>" */
-        details = g_strdup_printf (_("Released in %d on %s"),
-                                   gst_date_time_get_year (album->release_date),
-                                   label_text->str);
+       g_string_append_printf (details,
+                               _("Released in %d on %s"),
+                               gst_date_time_get_year (album->release_date),
+                               label_text->str);
     } else {
         /* Translators: this string appears when multiple CDs were
          * found in musicbrainz online database, it corresponds to
          * "Released in <year>" */
-        details = g_strdup_printf(_("Released in %d"),
-                                  gst_date_time_get_year (album->release_date));
+        g_string_append_printf (details, _("Released in %d"),
+                                gst_date_time_get_year (album->release_date));
     }
   } else if (album->labels) {
     /* Translators: this string appears when multiple CDs were
      * found in musicbrainz online database, it corresponds to
      * "Released on <label>" */
-    details = g_strdup_printf (_("Released on %s"), label_text->str);
+    g_string_append_printf (details, _("Released on %s"), label_text->str);
   } else {
-    details = g_strdup (_("Release label, year & country unknown"));
+    g_string_append_printf (details,
+                            _("Release label, year & country unknown"));
+  }
+
+  if (catalog_number_text != NULL) {
+    if (album->barcode != NULL) {
+      /* Translators: the "Barcode" string identifies the number of the barcode
+       * printed on the release */
+      g_string_append_printf (details,
+                              "\n%s, %s %s",
+                              catalog_number_text,
+                              _("Barcode:"),
+                              album->barcode);
+    } else {
+      g_string_append_printf (details, "\n%s", catalog_number_text);
+    }
+  } else {
+    if (album->barcode != NULL) {
+      g_string_append_printf (details,
+                              "\n%s %s",
+                              _("Barcode:"),
+                              album->barcode);
+    }
   }
 
   if (label_text)
     g_string_free (label_text, TRUE);
 
-  return details;
+  g_free (catalog_number_text);
+
+  return g_string_free (details, FALSE);
 }
 
 /**
@@ -1007,7 +1085,7 @@ choose_album(GList *albums)
       g_string_append_printf (album_title,_(" (Disc %d/%d)"),
                               album->disc_number, album->disc_count);
 
-    markup = g_markup_printf_escaped ("<b>%s</b>\n<i>%s</i>\n%s", album_title->str,
+    markup = g_markup_printf_escaped ("<b>%s</b>\n<b><i>%s</i></b>\n%s", album_title->str,
                                                                   album->artist,
                                                                   release_details);
 


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