[easytag/wip/musicbrainz-support-merge: 27/75] Implemented Apply TAGs
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/musicbrainz-support-merge: 27/75] Implemented Apply TAGs
- Date: Sat, 30 Aug 2014 07:48:15 +0000 (UTC)
commit b97eba159220dfb504c85a580783c98cfbf072cf
Author: Abhinav <abhijangda hotmail com>
Date: Mon Jun 30 18:30:36 2014 +0530
Implemented Apply TAGs
Added ApplyTAGs button & TagChoiceDialog in musicbrainz_dialog.ui
Implemented TagChoiceTreeView in musicbrainz_dialog.c
Added helper function et_mb5_release_get_artists_name in mb_search.c
Implemented et_set_file_tag & btn_apply_changes_clicked in musicbrainz_dialog.c
data/musicbrainz_dialog.ui | 90 +++++++++++++++-
src/mb_search.c | 39 +++++++
src/mb_search.h | 2 +
src/musicbrainz_dialog.c | 254 +++++++++++++++++++++++++++++++++++---------
4 files changed, 334 insertions(+), 51 deletions(-)
---
diff --git a/data/musicbrainz_dialog.ui b/data/musicbrainz_dialog.ui
index ef5e334..23100ae 100755
--- a/data/musicbrainz_dialog.ui
+++ b/data/musicbrainz_dialog.ui
@@ -139,7 +139,7 @@
<property name="spacing">4</property>
<child>
<object class="GtkButton" id="btnSelectedFind">
- <property name="label" translatable="yes">Search Selected Find</property>
+ <property name="label" translatable="yes">Search Selected File</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -472,6 +472,94 @@
</object>
</child>
</object>
+ <object class="GtkDialog" id="tag_choice_dialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox2">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area2">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="btn_cancel">
+ <property name="label" translatable="yes">Cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="btn_apply">
+ <property name="label" translatable="yes">Apply</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Select the Tag you want to apply:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkTreeView" id="tag_choice_treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection" id="treeview-selection1"/>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">btn_cancel</action-widget>
+ <action-widget response="1">btn_apply</action-widget>
+ </action-widgets>
+ </object>
<object class="GtkTreeStore" id="treestore1">
<columns>
<!-- column-name Entities -->
diff --git a/src/mb_search.c b/src/mb_search.c
index ae65428..3398caf 100755
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -52,6 +52,45 @@ et_mb5_search_error_quark (void)
return g_quark_from_static_string ("et-mb5-search-error-quark");
}
+gchar *
+et_mb5_release_get_artists_names (Mb5Release release)
+{
+ GString *album_artist;
+ int i;
+ Mb5ArtistCredit artist_credit;
+
+ album_artist = g_string_new ("");
+ artist_credit = mb5_release_get_artistcredit (release);
+
+ if (artist_credit)
+ {
+ Mb5NameCreditList name_list;
+ gchar temp[NAME_MAX_SIZE];
+
+ name_list = mb5_artistcredit_get_namecreditlist (artist_credit);
+
+ for (i = 0; i < mb5_namecredit_list_size (name_list); i++)
+ {
+ Mb5NameCredit name_credit;
+ Mb5Artist name_credit_artist;
+ int size;
+
+ name_credit = mb5_namecredit_list_item (name_list, i);
+ name_credit_artist = mb5_namecredit_get_artist (name_credit);
+ size = mb5_artist_get_name (name_credit_artist, temp,
+ sizeof (temp));
+ g_string_append_len (album_artist, temp, size);
+
+ if (i + 1 < mb5_namecredit_list_size (name_list))
+ {
+ g_string_append_len (album_artist, ", ", 2);
+ }
+ }
+ }
+
+ return g_string_free (album_artist, FALSE);
+}
+
void
et_musicbrainz_search_set_server_port (gchar *_server, int _port)
{
diff --git a/src/mb_search.h b/src/mb_search.h
index 8c966d6..1c3b5f0 100755
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -100,6 +100,8 @@ et_musicbrainz_search_in_entity (MbEntityKind child_type,
gboolean
et_musicbrainz_search (gchar *string, MbEntityKind type, GNode *root,
GError **error, GCancellable *cancellable);
+gchar *
+et_mb5_release_get_artists_names (Mb5Release release);
void
free_mb_tree (GNode **node);
void
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 8aa3d09..907d586 100755
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -41,6 +41,17 @@
static void
get_first_selected_file (ET_File **et_file);
+enum TagChoiceColumns
+{
+ TAG_CHOICE_TITLE,
+ TAG_CHOICE_ALBUM,
+ TAG_CHOICE_ARTIST,
+ TAG_CHOICE_ALBUM_ARTIST,
+ TAG_CHOICE_DATE,
+ TAG_CHOICE_COUNTRY,
+ TAG_CHOICE_COLS_N
+};
+
typedef enum
{
ET_MB_SEARCH_TYPE_MANUAL,
@@ -64,6 +75,9 @@ typedef struct
GNode *mb_tree_root;
GSimpleAsyncResult *async_result;
EtMbSearch *search;
+ GtkBuilder *tag_choices_builder;
+ GtkWidget *tag_choices_dialog;
+ GtkTreeModel *tag_choices_list_store;
} MusicBrainzDialogPrivate;
static MusicBrainzDialogPrivate *mb_dialog_priv;
@@ -837,6 +851,24 @@ et_music_brainz_dialog_stop_set_sensitive (gboolean sensitive)
}
static void
+et_set_file_tag (ET_File *et_file, gchar *title, gchar *artist,
+ gchar *album, gchar *album_artist, gchar *date,
+ gchar *country)
+{
+ File_Tag *file_tag;
+
+ file_tag = ET_File_Tag_Item_New();
+ ET_Copy_File_Tag_Item (et_file, file_tag);
+ ET_Set_Field_File_Tag_Item (&file_tag->title, title);
+ ET_Set_Field_File_Tag_Item (&file_tag->artist, artist);
+ ET_Set_Field_File_Tag_Item (&file_tag->album, album);
+ ET_Set_Field_File_Tag_Item (&file_tag->album_artist, album_artist);
+ ET_Set_Field_File_Tag_Item (&file_tag->year, date);
+ ET_Manage_Changes_Of_File_Data (et_file, NULL, file_tag);
+ ET_Display_File_Data_To_UI (ETCore->ETFileDisplayed);
+}
+
+static void
btn_apply_changes_clicked (GtkWidget *widget, gpointer data)
{
if (mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_MANUAL)
@@ -857,74 +889,196 @@ btn_apply_changes_clicked (GtkWidget *widget, gpointer data)
if (et_file)
{
- File_Tag *file_tag;
- gchar string [NAME_MAX_SIZE];
int size;
+ Mb5ReleaseList *release_list;
+ GtkListStore *tag_choice_list_store;
+ GtkWidget *tag_choice_dialog;
+ GtkWidget *tag_choice_tree_view;
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
+ Mb5ArtistCredit artist_credit;
+ int i;
+ gchar title [NAME_MAX_SIZE];
+ gchar *album_artist;
+ gchar album[NAME_MAX_SIZE];
+ gchar date[NAME_MAX_SIZE];
+ gchar country[NAME_MAX_SIZE];
+
+ GString *artist;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
- file_tag = (File_Tag *)et_file->FileTag->data;
- size = mb5_recording_get_title (et_entity->entity, string,
- sizeof (string));
- string [size] = '\0';
- ET_Set_Field_File_Tag_Item (&file_tag->title, string);
-
- //ET_Set_Field_File_Tag_Item (&file_tag->artist,
- //ET_Set_Field_File_Tag_Item (&file_tag->album,
-
- /*ET_Set_Field_File_Tag_Item (&file_tag->year,
+ release_list = mb5_recording_get_releaselist (et_entity->entity);
+ artist_credit = mb5_recording_get_artistcredit (et_entity->entity);
+ artist = g_string_new ("");
- if (cddbsettoallfields || cddbsettotrack)
- {
- snprintf (buffer, sizeof (buffer), "%s",
- et_track_number_to_string (cddbtrackalbum->track_number));
+ if (artist_credit)
+ {
+ Mb5NameCreditList name_list;
- ET_Set_Field_File_Tag_Item(&FileTag->track,buffer);
- }
+ name_list = mb5_artistcredit_get_namecreditlist (artist_credit);
- if (cddbsettoallfields || cddbsettotracktotal)
+ for (i = 0; i < mb5_namecredit_list_size (name_list); i++)
{
- snprintf (buffer, sizeof (buffer), "%s",
- et_track_number_to_string (list_length));
-
- ET_Set_Field_File_Tag_Item(&FileTag->track_total,buffer);
+ Mb5NameCredit name_credit;
+ Mb5Artist name_credit_artist;
+
+ name_credit = mb5_namecredit_list_item (name_list, i);
+ name_credit_artist = mb5_namecredit_get_artist (name_credit);
+ size = mb5_artist_get_name (name_credit_artist, title,
+ sizeof (title));
+ g_string_append_len (artist, title, size);
+
+ if (i + 1 < mb5_namecredit_list_size (name_list))
+ {
+ g_string_append_len (artist, ", ", 2);
+ }
}
+ }
- if ( (cddbsettoallfields || cddbsettogenre) && (cddbtrackalbum->cddbalbum->genre ||
cddbtrackalbum->cddbalbum->category) )
+ size = mb5_recording_get_title (et_entity->entity, title,
+ sizeof (title));
+ title [size] = '\0';
+ size = mb5_release_list_size (release_list);
+
+ if (size > 1)
+ {
+ /* More than one releases show Dialog and let user decide */
+ tag_choice_dialog = GTK_WIDGET (gtk_builder_get_object (builder,
+ "tag_choice_dialog"));
+ tag_choice_tree_view = GTK_WIDGET (gtk_builder_get_object (builder,
+ "tag_choice_treeview"));
+ tag_choice_list_store = gtk_list_store_new (TAG_CHOICE_COLS_N,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Title",
+ renderer, "text",
+ TAG_CHOICE_TITLE,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_tree_view),
+ column);
+
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Album",
+ renderer, "text",
+ TAG_CHOICE_ALBUM,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_tree_view),
+ column);
+
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Artist",
+ renderer, "text",
+ TAG_CHOICE_ARTIST,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_tree_view),
+ column);
+
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Album Artist",
+ renderer, "text",
+ TAG_CHOICE_ALBUM_ARTIST,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_tree_view),
+ column);
+
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Date",
+ renderer, "text",
+ TAG_CHOICE_DATE,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_tree_view),
+ column);
+
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Country",
+ renderer, "text",
+ TAG_CHOICE_COUNTRY,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_tree_view),
+ column);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (tag_choice_tree_view),
+ GTK_TREE_MODEL (tag_choice_list_store));
+
+ for (size--; size >= 0; size--)
{
- if (cddbtrackalbum->cddbalbum->genre && g_utf8_strlen(cddbtrackalbum->cddbalbum->genre,
-1)>0)
-
ET_Set_Field_File_Tag_Item(&FileTag->genre,Cddb_Get_Id3_Genre_From_Cddb_Genre(cddbtrackalbum->cddbalbum->genre));
- else
-
ET_Set_Field_File_Tag_Item(&FileTag->genre,Cddb_Get_Id3_Genre_From_Cddb_Genre(cddbtrackalbum->cddbalbum->category));
+ Mb5Release release;
+
+ release = mb5_release_list_item (release_list, size);
+ mb5_release_get_title (release, album, sizeof (album));
+ album_artist = et_mb5_release_get_artists_names (release);
+ mb5_release_get_date (release, date, sizeof (date));
+ mb5_release_get_country (release, country, sizeof (country));
+
+ gtk_list_store_insert_with_values (GTK_LIST_STORE (tag_choice_list_store),
+ &iter, -1, TAG_CHOICE_TITLE, title,
+ TAG_CHOICE_ALBUM, album,
+ TAG_CHOICE_ARTIST, artist->str,
+ TAG_CHOICE_ALBUM_ARTIST, album_artist,
+ TAG_CHOICE_DATE, date,
+ TAG_CHOICE_COUNTRY, country, -1);
+ g_free (album_artist);
}
- }*/
- /*if ( (cddbsettoallfields || cddbsettofilename) )
- {
- gchar *filename_generated_utf8;
- gchar *filename_new_utf8;
+ gtk_widget_set_size_request (tag_choice_dialog, 600, 200);
+ gtk_widget_show_all (tag_choice_dialog);
- // Allocation of a new FileName
- FileName = ET_File_Name_Item_New();
+ if (gtk_dialog_run (GTK_DIALOG (tag_choice_dialog)) == 0)
+ {
+ g_string_free (artist, TRUE);
+ gtk_widget_destroy (tag_choice_dialog);
- // Build the filename with the path
- snprintf (buffer, sizeof (buffer), "%s",
- et_track_number_to_string (cddbtrackalbum->track_number));
+ return;
+ }
- filename_generated_utf8 = g_strconcat(buffer," - ",cddbtrackalbum->track_name,NULL);
- ET_File_Name_Convert_Character(filename_generated_utf8); // Replace invalid characters
- filename_new_utf8 = ET_File_Name_Generate(*etfile,filename_generated_utf8);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tag_choice_tree_view));
+ if (gtk_tree_selection_get_selected (selection,
+ (GtkTreeModel **)&tag_choice_list_store,
+ &iter))
+ {
+ gchar *ret_album;
+ gchar *ret_album_artist;
+ gchar *ret_date;
+ gchar *ret_country;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (tag_choice_list_store),
+ &iter, TAG_CHOICE_ALBUM, &ret_album,
+ TAG_CHOICE_ALBUM_ARTIST,&ret_album_artist,
+ TAG_CHOICE_DATE, &ret_date,
+ TAG_CHOICE_COUNTRY, &ret_country,
+ -1);
+ et_set_file_tag (et_file, title, artist->str,
+ ret_album, ret_album_artist,
+ ret_date, ret_country);
+ g_free (ret_album);
+ g_free (ret_album_artist);
+ g_free (ret_date);
+ g_free (ret_country);
+ }
- ET_Set_Filename_File_Name_Item(FileName,filename_new_utf8,NULL);
+ g_string_free (artist, TRUE);
+ gtk_widget_destroy (tag_choice_dialog);
- g_free(filename_generated_utf8);
- g_free(filename_new_utf8);
+ return;
}
- ET_Manage_Changes_Of_File_Data(*etfile,FileName,FileTag);
-
- // Then run current scanner if asked...
- if (ScannerWindow && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(CddbRunScanner)) )
- Scan_Select_Mode_And_Run_Scanner(*etfile);*/
-
+ mb5_release_get_title (mb5_release_list_item (release_list, 0),
+ album, sizeof (album));
+ album_artist = et_mb5_release_get_artists_names (mb5_release_list_item (release_list, 0));
+ mb5_release_get_date (mb5_release_list_item (release_list, 0),
+ date, sizeof (date));
+ mb5_release_get_country (mb5_release_list_item (release_list, 0),
+ country, sizeof (country));
+ et_set_file_tag (et_file, title, artist->str,
+ album, album_artist,
+ date, country);
+ g_free (album_artist);
+ g_string_free (artist, TRUE);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]