[easytag/wip/musicbrainz-support] Added Multi Level Manual Search for MusicBrainz



commit 1898e7e319a76ef015ac13979de10f93c9e14485
Author: Abhinav <abhijangda hotmail com>
Date:   Sat May 17 12:18:53 2014 +0530

    Added Multi Level Manual Search for MusicBrainz

 src/mb_search.c          |    7 +--
 src/mb_search.h          |   21 ++++++++++-
 src/mbentityview.c       |   93 ++++++++++++++++++++++++++++++++++++++-------
 src/musicbrainz_dialog.c |   25 ++++++++++++-
 4 files changed, 125 insertions(+), 21 deletions(-)
---
diff --git a/src/mb_search.c b/src/mb_search.c
index e851faf..5f3cfb3 100644
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -31,7 +31,7 @@
  *
  */
 void
-et_musicbrainz_search_in_entity (gchar *string, enum MB_ENTITY_TYPE child_type,
+et_musicbrainz_search_in_entity (enum MB_ENTITY_TYPE child_type,
                                  enum MB_ENTITY_TYPE parent_type,
                                  gchar *parent_mbid, GNode *root)
 {
@@ -67,7 +67,7 @@ et_musicbrainz_search_in_entity (gchar *string, enum MB_ENTITY_TYPE child_type,
                 for (i = 0; i < mb5_release_list_size (list); i++)
                 {
                     Mb5Release release;
-                    release = mb5_artist_list_item (list, i);
+                    release = mb5_release_list_item (list, i);
                     if (release)
                     {
                         GNode *node;
@@ -77,11 +77,10 @@ et_musicbrainz_search_in_entity (gchar *string, enum MB_ENTITY_TYPE child_type,
                         entity->type = MB_ENTITY_TYPE_ALBUM;
                         node = g_node_new (entity);
                         g_node_append (root, node);
+                        printf ("releases\n");
                     }
                 }
             }
-
-            g_free (param_values [0]);
         }
         else
         {
diff --git a/src/mb_search.h b/src/mb_search.h
index 5a8454a..1d46b56 100644
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -1,3 +1,22 @@
+/* mb_search.h - 2014/05/05 */
+/*
+ *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
+ *  Copyright (C) 2000-2014  Abhinav Jangda <abhijangda hotmail com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
 
 #ifndef __MB_SEARCH_H__
 #define __MB_SEARCH_H__
@@ -27,7 +46,7 @@ typedef struct
  **************/
 
 void
-et_musicbrainz_search_in_entity (gchar *string, enum MB_ENTITY_TYPE child_type,
+et_musicbrainz_search_in_entity (enum MB_ENTITY_TYPE child_type,
                                  enum MB_ENTITY_TYPE parent_type,
                                  gchar *parent_mbid, GNode *root);
 void
diff --git a/src/mbentityview.c b/src/mbentityview.c
index 302d53a..3bcbd4d 100644
--- a/src/mbentityview.c
+++ b/src/mbentityview.c
@@ -35,6 +35,7 @@ char *columns [MB_ENTITY_TYPE_COUNT][8] = {
     {"Name", "Country", "Album", "Date", "Time", "Number"},
     };
 
+static GSimpleAsyncResult *async_result;
 
 /*
  * EtMbEntityViewPrivate:
@@ -157,7 +158,7 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
 {
     /* Traverse node in GNode and add it to list_store */
     enum MB_ENTITY_TYPE type;
-    Mb5ReleaseList *release_list;
+    //Mb5ReleaseList *release_list;
     Mb5ArtistCredit artist_credit;
     Mb5NameCreditList name_list;
     int i;
@@ -365,24 +366,17 @@ toggle_button_clicked (GtkWidget *btn, gpointer user_data)
     show_data_in_entity_view (entity_view);
 }
 
-/*
- * tree_view_row_activated:
- * @tree_view: the object on which the signal is emitted
- * @path: the GtkTreePath for the activated row
- * @column: the GtkTreeViewColumn in which the activation occurred
- * @user_data: user data set when the signal handler was connected.
- *
- * Signal Handler for GtkTreeView "row-activated" signal.
- */
 static void
-tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
-                         GtkTreeViewColumn *column, gpointer user_data)
+search_in_levels_callback (GObject *source, GAsyncResult *res,
+                           gpointer user_data)
 {
     EtMbEntityView *entity_view;
     EtMbEntityViewPrivate *priv;
     GtkWidget *toggle_btn;
+    GtkTreeSelection *selection;
     int depth;
     GtkTreeIter iter;
+    GtkTreePath *path;
     gchar *entity_name;
     GNode *child;
 
@@ -390,7 +384,11 @@ tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
     priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
 
     /* Depth is 1-based */
+    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
+    gtk_tree_selection_get_selected (selection, &(priv->list_store), &iter);
+    path = gtk_tree_model_get_path (priv->list_store, &iter);
     depth = gtk_tree_path_get_depth (path);
+    gtk_tree_path_free (path);
     child = g_node_nth_child (priv->mb_tree_current_node,
                               depth - 1);
 
@@ -414,18 +412,82 @@ tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
     if (priv->active_toggle_button)
     {
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->active_toggle_button),
-                                           FALSE);
+                                      FALSE);
     }
 
-    gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (toggle_btn), TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_btn), TRUE);
     g_signal_connect (G_OBJECT (toggle_btn), "clicked",
                       G_CALLBACK (toggle_button_clicked), entity_view);
     priv->active_toggle_button = toggle_btn;
-    gtk_tree_model_get_iter (priv->list_store, &iter, path);
     gtk_tree_model_get (priv->list_store, &iter, 0, &entity_name, -1);
     gtk_button_set_label (GTK_BUTTON (toggle_btn), entity_name);
     gtk_widget_show_all (GTK_WIDGET (priv->bread_crumb_box));
     show_data_in_entity_view (entity_view);
+    g_object_unref (res);
+}
+                            
+static void
+search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
+                              GCancellable *cancellable)
+{
+    EtMbEntityView *entity_view;
+    EtMbEntityViewPrivate *priv;
+    GtkTreeSelection *selection;
+    GtkTreeIter iter;
+    GtkTreePath *path;
+    GNode *child;
+    gchar mbid [NAME_MAX_SIZE];
+    int depth;
+
+    entity_view = ET_MB_ENTITY_VIEW (g_async_result_get_user_data (G_ASYNC_RESULT (res)));
+    priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
+    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
+    gtk_tree_selection_get_selected (selection, &(priv->list_store), &iter);
+    path = gtk_tree_model_get_path (priv->list_store, &iter);
+    depth = gtk_tree_path_get_depth (path);
+    gtk_tree_path_free (path);
+    child = g_node_nth_child (priv->mb_tree_current_node,
+                              depth - 1);
+    if (((EtMbEntity *)child->data)->type == MB_ENTITY_TYPE_TRACK)
+    {
+        return;
+    }
+    else if (((EtMbEntity *)child->data)->type == MB_ENTITY_TYPE_ARTIST)
+    {
+        mb5_artist_get_id (((EtMbEntity *)child->data)->entity, mbid, sizeof (mbid));
+    }
+    else if (((EtMbEntity *)child->data)->type == MB_ENTITY_TYPE_ALBUM)
+    {
+        mb5_release_get_id (((EtMbEntity *)child->data)->entity, mbid, sizeof (mbid));
+    }
+    
+    et_musicbrainz_search_in_entity (((EtMbEntity *)child->data)->type + 1,
+                                     ((EtMbEntity *)child->data)->type, mbid,
+                                     child);
+}
+
+/*
+ * tree_view_row_activated:
+ * @tree_view: the object on which the signal is emitted
+ * @path: the GtkTreePath for the activated row
+ * @column: the GtkTreeViewColumn in which the activation occurred
+ * @user_data: user data set when the signal handler was connected.
+ *
+ * Signal Handler for GtkTreeView "row-activated" signal.
+ */
+static void
+tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
+                         GtkTreeViewColumn *column, gpointer user_data)
+{
+    /* TODO: Add Cancellable object */
+    /* TODO: Use GSimpleAsyncResult with GError */
+    /* TODO: Display Status Bar messages */
+    async_result = g_simple_async_result_new (NULL, search_in_levels_callback, 
+                                              user_data,
+                                              tree_view_row_activated);
+    g_simple_async_result_run_in_thread (async_result,
+                                         search_in_levels_thread_func,
+                                         0, NULL);
 }
 
 /*
@@ -501,6 +563,7 @@ et_mb_entity_view_set_tree_root (EtMbEntityView *entity_view, GNode *treeRoot)
         priv->bread_crumb_nodes [0] = treeRoot;
         priv->active_toggle_button = btn;
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (btn), TRUE);
+        gtk_widget_show_all (priv->bread_crumb_box);
         show_data_in_entity_view (entity_view);
     }
 }
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 670badf..4db418b 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -39,12 +39,19 @@ static GtkWidget *mbDialog;
 static GtkWidget *entityView;
 static GNode *mb_tree_root;
 static GSimpleAsyncResult *async_result;
-static GCancellable *cancellable;
 
 /*************
  * Functions *
  *************/
 
+/*
+ * manual_search_callback:
+ * @source: Source Object
+ * @res: GAsyncResult
+ * @user_data: User data
+ *
+ * Callback function for GAsyncResult for Manual Search.
+ */
 static void
 manual_search_callback (GObject *source, GAsyncResult *res,
                         gpointer user_data)
@@ -54,6 +61,14 @@ manual_search_callback (GObject *source, GAsyncResult *res,
     g_object_unref (res);
 }
 
+/*
+ * manual_search_thread_func:
+ * @res: GSimpleAsyncResult
+ * @obj: Source GObject
+ * @cancellable: GCancellable to cancel the operation
+ *
+ * Thread func of GSimpleAsyncResult to do Manual Search in another thread.
+ */
 static void
 manual_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
                            GCancellable *cancellable)
@@ -71,6 +86,13 @@ manual_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
                            type, mb_tree_root);
 }
 
+/*
+ * btn_manual_find_clicked:
+ * @btn: The source GtkButton
+ * @user_data: User data passed
+ *
+ * Signal Handler for "clicked" signal of mbSearchButton.
+ */
 static void
 btn_manual_find_clicked (GtkWidget *btn, gpointer user_data)
 {
@@ -82,6 +104,7 @@ btn_manual_find_clicked (GtkWidget *btn, gpointer user_data)
 
     /* TODO: Add Cancellable object */
     /* TODO: Use GSimpleAsyncResult with GError */
+    /* TODO: Display Status Bar messages */
     async_result = g_simple_async_result_new (NULL, manual_search_callback, 
                                               NULL, btn_manual_find_clicked);
     g_simple_async_result_run_in_thread (async_result,


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