[easytag/wip/musicbrainz-support-merge: 63/75] Apply TAGs add Composer Tag



commit 41a79733fb6fd705077ee2c7802afd2449ac5f5f
Author: Abhinav <abhijangda hotmail com>
Date:   Fri Aug 15 01:01:33 2014 +0530

    Apply TAGs add Composer Tag
    
    Use "artist-rels" to get Composer Tag.
    If available Composer Tag will also be applied.
    Use et_mb5_recording_get_composers to get all composers

 src/mb_search.c          |   55 ++++++++++++++++++++++++++++++++++++++++++++++
 src/mb_search.h          |    2 +
 src/musicbrainz_dialog.c |   34 +++++++++++++++++++++-------
 3 files changed, 82 insertions(+), 9 deletions(-)
---
diff --git a/src/mb_search.c b/src/mb_search.c
index e1db982..90ac599 100755
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -34,6 +34,7 @@
 static gchar *server = NULL;
 static int port = 0;
 
+#define COMPOSER_STR "composer"
 #define USER_AGENT PACKAGE_NAME"/"PACKAGE_VERSION" ( "PACKAGE_URL" ) "
 #define CHECK_CANCELLED(cancellable) if (g_cancellable_is_cancelled (cancellable))\
                                      {\
@@ -117,6 +118,60 @@ et_mb5_recording_get_artists_names (Mb5Recording recording)
 }
 
 /*
+ * et_mb5_recording_get_composers:
+ * @recording: Mb5Recording
+ *
+ * Get composers for a recording.
+ *
+ * Returns: A string containing composers.
+ */
+gchar *
+et_mb5_recording_get_composers (Mb5Recording recording)
+{
+    Mb5RelationListList relation_lists;
+    int i;
+    int j;
+    GString *composers;
+    
+    composers = g_string_new ("");
+    relation_lists = mb5_recording_get_relationlistlist (recording);
+    
+    for (i = 0; i < mb5_relationlist_list_size (relation_lists); i++)
+    {
+        Mb5RelationList relation_list;
+        
+        relation_list = mb5_relationlist_list_item (relation_lists, i);
+        
+        for (j = 0; j < mb5_relation_list_size (relation_list); j++)
+        {
+            Mb5Relation relation;
+            Mb5Artist artist;
+            gchar name[NAME_MAX_SIZE];
+
+            relation = mb5_relation_list_item (relation_list, j);
+            artist = mb5_relation_get_artist (relation);
+            mb5_relation_get_type (relation, name, sizeof (name));
+
+            if (g_strcmp0 (name, COMPOSER_STR))
+            {
+                continue;
+            }
+
+            mb5_artist_get_name (artist, name, sizeof (name));
+            
+            if (!(*composers->str))
+            {
+                g_string_append (composers, ", ");
+            }
+        
+            g_string_append (composers, name);
+        }
+    }
+
+    return g_string_free (composers, FALSE);
+}
+
+/*
  * et_mb5_release_get_artists_names:
  * @release: Mb5Release
  *
diff --git a/src/mb_search.h b/src/mb_search.h
index 2edea39..29acb16 100755
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -125,6 +125,8 @@ gchar *
 et_mb5_release_get_artists_names (Mb5Release release);
 gchar *
 et_mb5_recording_get_artists_names (Mb5Recording recording);
+gchar *
+et_mb5_recording_get_composers (Mb5Recording recording);
 int
 et_mb5_recording_get_medium_track_for_release (Mb5Release release,
                                                int **discids, int **trackids,
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 4ec4e96..f1df377 100755
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -70,6 +70,7 @@ enum TagChoiceColumns
     TAG_CHOICE_DISC_TOTAL,
     TAG_CHOICE_TRACK_NUMBER,
     TAG_CHOICE_TRACK_TOTAL,
+    TAG_CHOICE_COMPOSERS,
     TAG_CHOICE_COLS_N
 };
 
@@ -308,7 +309,7 @@ static void
 et_set_file_tag (ET_File *et_file, gchar *title, gchar *artist,
                  gchar *album, gchar *album_artist, gchar *date,
                  gchar *country, gchar *disc, gchar *track,
-                 gchar *disc_total, gchar *track_total);
+                 gchar *disc_total, gchar *track_total, gchar *composer);
 static void
 btn_apply_changes_clicked (GtkWidget *widget, gpointer data);
 static void
@@ -1728,7 +1729,7 @@ static void
 et_set_file_tag (ET_File *et_file, gchar *title, gchar *artist,
                  gchar *album, gchar *album_artist, gchar *date,
                  gchar *country, gchar *disc, gchar *track,
-                 gchar *disc_total, gchar *track_total)
+                 gchar *disc_total, gchar *track_total, gchar *composer)
 {
     File_Tag *file_tag;
 
@@ -1743,7 +1744,7 @@ et_set_file_tag (ET_File *et_file, gchar *title, gchar *artist,
     ET_Set_Field_File_Tag_Item (&file_tag->disc_total, disc_total);
     ET_Set_Field_File_Tag_Item (&file_tag->track, track);
     ET_Set_Field_File_Tag_Item (&file_tag->disc_number, disc);
-    printf ("%s %s\n", track_total, disc_total);
+    ET_Set_Field_File_Tag_Item (&file_tag->composer, composer);
     ET_Manage_Changes_Of_File_Data (et_file, NULL, file_tag);
     ET_Display_File_Data_To_UI (ETCore->ETFileDisplayed);
 }
@@ -1915,6 +1916,7 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
     gchar *track;
     gchar *track_total;
     gchar *disc_total;
+    gchar *composers;
     GtkTreeIter iter;
     GtkTreeSelection *selection;
     GtkWidget *tag_choice_tree_view;
@@ -1941,7 +1943,8 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
     title[size] = '\0';
     size = mb5_release_list_size (release_list);
     release = NULL;
-
+    composers = et_mb5_recording_get_composers (recording);
+    
     if (album_entity)
     {
         gchar id[NAME_MAX_SIZE];
@@ -1988,7 +1991,7 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
             et_set_file_tag (et_file, title, artist,
                              album, album_artist,
                              date, country, disc, track,
-                             disc_total, track_total);
+                             disc_total, track_total, composers);
             g_free (discids);
             g_free (trackids);
             g_free (disc);
@@ -2001,11 +2004,12 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
         {
             et_set_file_tag (et_file, title, artist,
                              album, album_artist,
-                             date, country, "", "", "", "");
+                             date, country, "", "", "", "", composers);
         }
 
         g_free (album_artist);
         g_free (artist);
+        g_free (composers);
 
         return TRUE;
     }
@@ -2048,6 +2052,8 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
                                                    track,
                                                    TAG_CHOICE_TRACK_TOTAL,
                                                    track_total,
+                                                   TAG_CHOICE_COMPOSERS,
+                                                   composers
                                                    -1);
                 g_free (disc_total);
                 g_free (track_total);
@@ -2059,6 +2065,7 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
             g_free (trackids);    
             g_free (album_artist);
             g_free (track_count);
+            g_free (composers);
         }
 
         gtk_widget_set_size_request (mb_dialog_priv->tag_choice_dialog,
@@ -2103,7 +2110,7 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
             et_set_file_tag (et_file, title, artist,
                              ret_album, ret_album_artist,
                              ret_date, ret_country, disc, track, disc_total, 
-                             track_total);
+                             track_total, composers);
             g_free (ret_album);
             g_free (ret_album_artist);
             g_free (ret_date);
@@ -2113,6 +2120,7 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
             g_free (track_total);
             g_free (disc);
             g_free (track);
+            g_free (composers);
     
             gtk_widget_hide (mb_dialog_priv->tag_choice_dialog);
             gtk_list_store_clear (GTK_LIST_STORE (mb_dialog_priv->tag_choice_store));
@@ -2122,7 +2130,7 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, EtMbEntity *album_entity,
         else
         {
             g_free (artist);
-    
+            g_free (composers);
             gtk_widget_hide (mb_dialog_priv->tag_choice_dialog);
             gtk_list_store_clear (GTK_LIST_STORE (mb_dialog_priv->tag_choice_store));
     
@@ -2184,7 +2192,7 @@ et_initialize_tag_choice_dialog (EtMusicBrainzDialogPrivate *mb_dialog_priv)
                                      G_TYPE_STRING, G_TYPE_STRING,
                                      G_TYPE_STRING, G_TYPE_STRING,
                                      G_TYPE_STRING, G_TYPE_STRING,
-                                     G_TYPE_STRING);
+                                     G_TYPE_STRING, G_TYPE_STRING);
     mb_dialog_priv->tag_choice_store = GTK_TREE_MODEL (list_store);
     gtk_tree_view_set_model (GTK_TREE_VIEW (tag_choice_list),
                              mb_dialog_priv->tag_choice_store);
@@ -2269,6 +2277,14 @@ et_initialize_tag_choice_dialog (EtMusicBrainzDialogPrivate *mb_dialog_priv)
                                                        NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_list),
                                  column);
+    
+    renderer = gtk_cell_renderer_text_new ();
+    column = gtk_tree_view_column_new_with_attributes ("Composer",
+                                                       renderer, "text",
+                                                       TAG_CHOICE_COMPOSERS,
+                                                       NULL);
+    gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_list),
+                                 column);
 }
 
 gboolean


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