[easytag/wip/musicbrainz-support-merge: 124/149] Implemented Fetch More Data operation



commit 1f453049242a015992aecb9a1d8e160b4c9a155d
Author: Abhinav <abhijangda hotmail com>
Date:   Fri Aug 22 20:53:59 2014 +0530

    Implemented Fetch More Data operation
    
    Added Fetch More Data Button in musicbrainz_dialog.ui. Added support for
    offset and fetching more data in mb_search.c. Changed Search in
    musicbrainz_dialog.c to get offset & use it to fetch more data. Changed
    mbentityview.c to fetch more data for AutomaticSearch.

 data/musicbrainz_dialog.ui |   14 +++
 src/mb_search.c            |  101 +++++++++++++++++------
 src/mb_search.h            |    9 ++-
 src/mbentityview.c         |   20 ++++-
 src/mbentityview.h         |    2 +
 src/musicbrainz_dialog.c   |  194 +++++++++++++++++++++++++++++++++++++++-----
 tests/test-musicbrainz.c   |   20 +++---
 7 files changed, 298 insertions(+), 62 deletions(-)
---
diff --git a/data/musicbrainz_dialog.ui b/data/musicbrainz_dialog.ui
index 5c0c7da..1763d0b 100644
--- a/data/musicbrainz_dialog.ui
+++ b/data/musicbrainz_dialog.ui
@@ -362,6 +362,20 @@
                         <property name="homogeneous">True</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkToolButton" id="btn_fetch_more">
+                        <property name="visible">True</property>
+                        <property name="sensitive">False</property>
+                        <property name="can_focus">False</property>
+                        <property name="tooltip_text" translatable="yes">Fetch more results</property>
+                        <property name="use_underline">True</property>
+                        <property name="stock_id">gtk-save</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="homogeneous">True</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
diff --git a/src/mb_search.c b/src/mb_search.c
index 160cd0e..37758a4 100644
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -31,9 +31,6 @@
  * Declarations *
  ****************/
 
-#define SEARCH_LIMIT_STR "5"
-#define SEARCH_LIMIT_INT 5
-
 static gchar *server = NULL;
 static int port = 0;
 
@@ -199,8 +196,10 @@ et_musicbrainz_search_set_server_port (gchar *_server, int _port)
 gboolean
 et_musicbrainz_search_in_entity (MbEntityKind child_type,
                                  MbEntityKind parent_type,
-                                 gchar *parent_mbid, GNode *root,
-                                 GError **error, GCancellable *cancellable)
+                                 gchar *parent_mbid, 
+                                 GNode *root, int offset,
+                                 GError **error, 
+                                 GCancellable *cancellable)
 {
     Mb5Query query;
     Mb5Metadata metadata;
@@ -420,7 +419,7 @@ et_musicbrainz_search_in_entity (MbEntityKind child_type,
     {
         mb5_query_delete (query);
 
-        return et_musicbrainz_search (parent_mbid, child_type, root, error,
+        return et_musicbrainz_search (parent_mbid, child_type, root, offset, error,
                                       cancellable);
     }
 
@@ -539,6 +538,49 @@ free_mb_node_children (GNode *node)
     }
 }
 
+EtMbEntity *
+et_mb_entity_copy (EtMbEntity *etentity)
+{
+    EtMbEntity *entity;
+    
+    if (!etentity)
+    {
+        return NULL;
+    }
+
+    entity = g_slice_new (EtMbEntity);
+    entity->type = etentity->type;
+
+    switch (entity->type)
+    {
+        case MB_ENTITY_KIND_ARTIST:
+            entity->entity = mb5_artist_clone (etentity->entity);
+            break;
+
+        case MB_ENTITY_KIND_ALBUM:
+            entity->entity = mb5_release_clone (etentity->entity);
+            break;
+
+        case MB_ENTITY_KIND_TRACK:
+            entity->entity = mb5_recording_clone (etentity->entity);
+            break;
+
+        case MB_ENTITY_KIND_FREEDBID:
+            entity->entity = mb5_freedbdisc_clone (etentity->entity);
+            break;
+
+        case MB_ENTITY_KIND_DISCID:
+            entity->entity = mb5_disc_clone (etentity->entity);
+            break;
+
+        default:
+            g_slice_free (EtMbEntity, entity);
+            return NULL;
+    }
+
+    return entity;
+}
+
 /*
  * et_musicbrainz_search_artist:
  * @string: String to search
@@ -551,26 +593,29 @@ free_mb_node_children (GNode *node)
  * Search for Artists with name as @string
  */
 static gboolean
-et_musicbrainz_search_artist (gchar *string, GNode *root, GError **error,
-                              GCancellable *cancellable)
+et_musicbrainz_search_artist (gchar *string, GNode *root, int offset, 
+                              GError **error, GCancellable *cancellable)
 {
     Mb5Query query;
     Mb5Metadata metadata;
     tQueryResult result;
-    char *param_values[2];
-    char *param_names[2];
+    char *param_values[3];
+    char *param_names[3];
 
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     param_names[0] = "query";
     param_names[1] = "limit";
     param_values[1] = SEARCH_LIMIT_STR;
+    param_names[2] = "offset";
+    param_values[2] = g_strdup_printf ("%d", offset);
     query = mb5_query_new (USER_AGENT, server, port);
     CHECK_CANCELLED(cancellable);
     param_values[0] = g_strconcat ("artist:", string, NULL);
-    metadata = mb5_query_query (query, "artist", "", "", 2, param_names,
+    metadata = mb5_query_query (query, "artist", "", "", 3, param_names,
                                 param_values);
     g_free (param_values[0]);
+    g_free (param_values[2]);
     result = mb5_query_get_lastresult (query);
 
     if (result == eQuery_Success)
@@ -640,15 +685,15 @@ et_musicbrainz_search_artist (gchar *string, GNode *root, GError **error,
  * Search for Albums with name as @string
  */
 static gboolean
-et_musicbrainz_search_album (gchar *string, GNode *root, GError **error,
-                             GCancellable *cancellable)
+et_musicbrainz_search_album (gchar *string, GNode *root, int offset, 
+                             GError **error, GCancellable *cancellable)
 {
     Mb5Query query;
     Mb5Metadata metadata;
     Mb5Metadata metadata_release;
     tQueryResult result;
-    char *param_values[2];
-    char *param_names[2];
+    char *param_values[3];
+    char *param_names[3];
 
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
@@ -656,14 +701,17 @@ et_musicbrainz_search_album (gchar *string, GNode *root, GError **error,
     metadata_release = NULL;
     param_names[0] = "query";
     param_names[1] = "limit";
+    param_names[2] = "offset";
+    param_values[2] = g_strdup_printf ("%d", offset);
     param_values[1] = SEARCH_LIMIT_STR;
     query = mb5_query_new (USER_AGENT, server, port);
     param_values[0] = g_strconcat ("release:", string, NULL);
     CHECK_CANCELLED(cancellable);
-    metadata = mb5_query_query (query, "release", "", "", 2, param_names,
+    metadata = mb5_query_query (query, "release", "", "", 3, param_names,
                                 param_values);
     result = mb5_query_get_lastresult (query);
     g_free (param_values[0]);
+    g_free (param_values[2]);
 
     if (result == eQuery_Success)
     {
@@ -797,30 +845,33 @@ et_musicbrainz_search_album (gchar *string, GNode *root, GError **error,
  * Search for Tracks with name as @string
  */
 static gboolean
-et_musicbrainz_search_track (gchar *string, GNode *root, GError **error,
-                             GCancellable *cancellable)
+et_musicbrainz_search_track (gchar *string, GNode *root, int offset, 
+                             GError **error, GCancellable *cancellable)
 {
     Mb5Query query;
     Mb5Metadata metadata;
     Mb5Metadata metadata_recording;
     tQueryResult result;
-    char *param_values[2];
-    char *param_names[2];
+    char *param_values[3];
+    char *param_names[3];
 
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     metadata = NULL;
     param_names[0] = "query";
     param_names[1] = "limit";
+    param_names[2] = "offset";
+    param_values[2] = g_strdup_printf ("%d", offset);
     param_values[1] = SEARCH_LIMIT_STR;
     metadata_recording = NULL;
     query = mb5_query_new (USER_AGENT, server, port);
     param_values[0] = g_strconcat ("recordings:", string, NULL);
     CHECK_CANCELLED(cancellable);
-    metadata = mb5_query_query (query, "recording", "", "", 2,
+    metadata = mb5_query_query (query, "recording", "", "", 3,
                                 param_names, param_values);
     result = mb5_query_get_lastresult (query);
     g_free (param_values[0]);
+    g_free (param_values[2]);
 
     if (result == eQuery_Success)
     {
@@ -1197,22 +1248,22 @@ et_musicbrainz_search_freedbid (gchar *string, GNode *root, GError **error,
  * Returns: TRUE if successfull, FALSE if not.
  */
 gboolean
-et_musicbrainz_search (gchar *string, MbEntityKind type, GNode *root,
+et_musicbrainz_search (gchar *string, MbEntityKind type, GNode *root, int offset,
                        GError **error, GCancellable *cancellable)
 {
     switch (type)
     {
         case MB_ENTITY_KIND_ARTIST:
-            return et_musicbrainz_search_artist (string, root, error,
+            return et_musicbrainz_search_artist (string, root, offset, error,
                                                  cancellable);
     
 
         case MB_ENTITY_KIND_ALBUM:
-            return et_musicbrainz_search_album (string, root, error,
+            return et_musicbrainz_search_album (string, root, offset, error,
                                                 cancellable);
 
         case MB_ENTITY_KIND_TRACK:
-            return et_musicbrainz_search_track (string, root, error,
+            return et_musicbrainz_search_track (string, root, offset, error,
                                                 cancellable);
 
         case MB_ENTITY_KIND_DISCID:
diff --git a/src/mb_search.h b/src/mb_search.h
index 327ed7a..3889b02 100644
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -116,15 +116,18 @@ gboolean
 et_musicbrainz_search_in_entity (MbEntityKind child_type,
                                  MbEntityKind parent_type,
                                  gchar *parent_mbid, GNode *root,
-                                 GError **error, GCancellable *cancellable);
+                                 int offset, GError **error, 
+                                 GCancellable *cancellable);
 gboolean
-et_musicbrainz_search (gchar *string, MbEntityKind type, GNode *root,
-                       GError **error, GCancellable *cancellable);
+et_musicbrainz_search (gchar *string, MbEntityKind type, GNode *root, 
+                       int offset, GError **error, GCancellable *cancellable);
 gchar *
 et_mb5_release_get_artists_names (Mb5Release release);
 gchar *
 et_mb5_recording_get_artists_names (Mb5Recording recording);
 void
 free_mb_tree (GNode **node);
+EtMbEntity *
+et_mb_entity_copy (EtMbEntity *etentity);
 #endif /* __MB_SEARCH_H__ */
 #endif /* ENABLE_MUSICBRAINZ */
diff --git a/src/mbentityview.c b/src/mbentityview.c
index 7c4ecf6..65e52ae 100644
--- a/src/mbentityview.c
+++ b/src/mbentityview.c
@@ -800,8 +800,9 @@ search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
 
     if (!et_musicbrainz_search_in_entity (to_search,
                                           ((EtMbEntity *)thread_data->child->data)->type,
-                                          mbid, thread_data->child, &error,
-                                          cancellable))
+                                          mbid, thread_data->child, 
+                                          g_node_n_children (thread_data->child), 
+                                          &error, cancellable))
     {
         g_simple_async_report_gerror_in_idle (NULL,
                                               mb5_search_error_callback,
@@ -813,6 +814,21 @@ search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
 }
 
 /*
+ * et_mb_entity_view_fetch_more_at_current_level:
+ * @entity_view: Fetch more data at current level
+ *
+ * To Fetch more results at current level.
+ */
+void
+et_mb_entity_view_fetch_more_at_current_level (EtMbEntityView *entity_view)
+{
+    EtMbEntityViewPrivate *priv;
+
+    priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
+    search_in_levels (entity_view, priv->mb_tree_current_node, NULL, TRUE);
+}
+
+/*
  * tree_view_row_activated:
  * @tree_view: the object on which the signal is emitted
  * @path: the GtkTreePath for the activated row
diff --git a/src/mbentityview.h b/src/mbentityview.h
index c756542..f4f6ee1 100644
--- a/src/mbentityview.h
+++ b/src/mbentityview.h
@@ -182,6 +182,8 @@ et_mb_entity_view_get_selected_entity_list (EtMbEntityView *entity_view,
                                             GList **list);
 EtMbEntity *
 et_mb_entity_view_get_current_entity (EtMbEntityView *entity_view);
+void
+et_mb_entity_view_fetch_more_at_current_level (EtMbEntityView *entity_view);
 G_END_DECLS
 
 #endif /* ENABLE_MUSICBRAINZ */
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index dd58f18..54a30bc 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -122,6 +122,7 @@ typedef struct
 {
     EtMbSearch parent;
     GList *list_iter;
+    GArray *n_nodes;
 } EtMbSelectedSearch;
 
 /*
@@ -186,6 +187,7 @@ typedef struct
     GHashTable *hash_table;
     GList *list_iter;
     GNode *node;
+    GArray *n_nodes;
 } SelectedFindThreadData;
 
 /*
@@ -231,7 +233,8 @@ static void
 et_mb_set_search_manual (EtMbSearch **search, gchar *to_search,
                          GNode *node, MbEntityKind type);
 static void
-et_mb_set_selected_search (EtMbSearch **search, GList *list_files);
+et_mb_set_selected_search (EtMbSearch **search, GArray *n_nodes,
+                           GList *list_files);
 static void
 et_mb_set_automatic_search (EtMbSearch **search);
 static void
@@ -362,6 +365,7 @@ et_mb_destroy_search (EtMbSearch **search)
         {
             g_list_free_full (((EtMbSelectedSearch *)(*search))->list_iter,
                               (GDestroyNotify)gtk_tree_iter_free);
+            g_array_free (((EtMbSelectedSearch *)(*search))->n_nodes, TRUE);
             g_slice_free (EtMbSelectedSearch,
                           (EtMbSelectedSearch *)(*search));
             break;
@@ -397,6 +401,8 @@ et_mb_set_search_manual (EtMbSearch **search, gchar *to_search,
     manual_search->to_search_type = type;
     *search = (EtMbSearch *)manual_search;
     (*search)->type = ET_MB_SEARCH_TYPE_MANUAL;
+    gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btn_fetch_more")),
+                              TRUE);
 }
 
 /*
@@ -407,12 +413,16 @@ et_mb_set_search_manual (EtMbSearch **search, gchar *to_search,
  * Set the EtMbSearch as Selected Search.
  */
 static void
-et_mb_set_selected_search (EtMbSearch **search, GList *list_files)
+et_mb_set_selected_search (EtMbSearch **search, GArray *n_nodes,
+                           GList *list_files)
 {
     et_mb_destroy_search (search);
     *search = (EtMbSearch *)g_slice_new (EtMbSelectedSearch);
     (*search)->type = ET_MB_SEARCH_TYPE_SELECTED;
     ((EtMbSelectedSearch *)(*search))->list_iter = list_files;
+    ((EtMbSelectedSearch *)(*search))->n_nodes = n_nodes;
+    gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btn_fetch_more")),
+                              TRUE);
 }
 
 /*
@@ -427,6 +437,8 @@ et_mb_set_automatic_search (EtMbSearch **search)
     et_mb_destroy_search (search);
     *search = (EtMbSearch *)g_slice_new (EtMbAutomaticSearch);
     (*search)->type = ET_MB_SEARCH_TYPE_AUTOMATIC;
+    gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btn_fetch_more")),
+                              FALSE);
 }
 
 /*
@@ -529,8 +541,9 @@ manual_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
 
     if (!et_musicbrainz_search (thread_data->text_to_search,
                                 thread_data->type, 
-                                thread_data->node, &error,
-                                cancellable))
+                                thread_data->node,
+                                g_node_n_children (thread_data->node),
+                                &error, cancellable))
     {
         g_simple_async_report_gerror_in_idle (NULL,
                                               mb5_search_error_callback,
@@ -553,6 +566,120 @@ manual_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
 }
 
 /*
+ * btn_fetch_more_clicked:
+ * @btn: GtkButton
+ * @user_data: Additional Data
+ *
+ * Callback of "clicked" signal handler for btn_fetch_more.
+ */
+static void
+btn_fetch_more_clicked (GtkWidget *btn, gpointer user_data)
+{
+    EtMusicBrainzDialog *dlg;
+    EtMusicBrainzDialogPrivate *mb_dialog_priv;
+    int level;
+
+    dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
+    mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
+    level = et_mb_entity_view_get_current_level (ET_MB_ENTITY_VIEW (mb_dialog_priv->entityView));
+
+    if (mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_AUTOMATIC && 
+        level <= 2)
+    {
+        et_mb_entity_view_fetch_more_at_current_level (ET_MB_ENTITY_VIEW (mb_dialog_priv->entityView));
+        return;
+    }
+
+    if (level != 1)
+    {
+        return;
+    }
+
+    if (mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_MANUAL)
+    {
+        ManualSearchThreadData *thread_data;
+        EtMbManualSearch *manual_search;
+
+        manual_search = (EtMbManualSearch *)mb_dialog_priv->search;
+        thread_data = g_slice_new (ManualSearchThreadData);
+        thread_data->type = manual_search->to_search_type;
+        thread_data->node = g_node_copy_deep (mb_dialog_priv->mb_tree_root, 
+                                              (GCopyFunc)et_mb_entity_copy, NULL);
+        thread_data->text_to_search = manual_search->to_search;
+        mb5_search_cancellable = g_cancellable_new ();
+        gtk_statusbar_push (mb_dialog_priv->statusbar, 0,
+                            _("Starting MusicBrainz Search"));
+        mb_dialog_priv->async_result = g_simple_async_result_new (NULL, 
+                                                                  manual_search_callback,
+                                                                  thread_data,
+                                                                  btn_fetch_more_clicked);
+        g_simple_async_result_run_in_thread (mb_dialog_priv->async_result,
+                                             manual_search_thread_func, 0,
+                                             mb5_search_cancellable);
+        et_music_brainz_dialog_stop_set_sensitive (TRUE);
+    }
+    else if (mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_SELECTED)
+    {
+        GList *iter_list;
+        GList *l;
+        GHashTable *hash_table;
+        SelectedFindThreadData *thread_data;
+        EtMbSelectedSearch *selected_search;
+        GtkTreeView *browser_list;
+        GtkTreeSelection *selection;
+
+        selection = et_application_window_browser_get_selection (ET_APPLICATION_WINDOW (MainWindow));
+        browser_list = gtk_tree_selection_get_tree_view (selection);   
+        iter_list = NULL;
+        l = NULL;
+    
+        if (!get_selected_iter_list (GTK_TREE_VIEW (browser_list), &iter_list))
+        {
+            gtk_statusbar_push (mb_dialog_priv->statusbar,
+                            0, _("No Files Selected"));
+            return;
+        }
+    
+        hash_table = g_hash_table_new (g_str_hash, g_str_equal);
+    
+        for (l = iter_list; l != NULL; l = g_list_next (l))
+        {
+            ET_File *etfile;
+            File_Tag *file_tag;
+    
+            etfile = et_application_window_browser_get_et_file_from_iter (ET_APPLICATION_WINDOW (MainWindow),
+                                                                          (GtkTreeIter *)l->data);
+    
+            file_tag = (File_Tag *)etfile->FileTag->data;
+    
+            if (file_tag->album != NULL)
+            {
+                g_hash_table_add (hash_table, file_tag->album);
+            }
+        }
+    
+        selected_search = (EtMbSelectedSearch *)mb_dialog_priv->search;
+        thread_data = g_slice_new (SelectedFindThreadData);
+        thread_data->hash_table = hash_table;
+        thread_data->list_iter = iter_list;
+        thread_data->node = g_node_copy_deep (mb_dialog_priv->mb_tree_root, 
+                                              (GCopyFunc)et_mb_entity_copy, NULL);
+        thread_data->n_nodes = g_array_ref (selected_search->n_nodes);
+        mb5_search_cancellable = g_cancellable_new ();
+        mb_dialog_priv->async_result = g_simple_async_result_new (NULL,
+                                                                  selected_find_callback,
+                                                                  thread_data,
+                                                                  btn_fetch_more_clicked);
+        g_simple_async_result_run_in_thread (mb_dialog_priv->async_result,
+                                             selected_find_thread_func, 0,
+                                             mb5_search_cancellable);
+        gtk_statusbar_push (mb_dialog_priv->statusbar, 0,
+                            _("Starting Selected Files Search"));
+        et_music_brainz_dialog_stop_set_sensitive (TRUE);
+    }
+}
+
+/*
  * btn_manual_find_clicked:
  * @btn: GtkButton
  * @user_data: User data
@@ -819,7 +946,9 @@ selected_find_callback (GObject *source, GAsyncResult *res,
         g_object_unref (res);
         g_hash_table_destroy (thread_data->hash_table);
         et_music_brainz_dialog_stop_set_sensitive (FALSE);
+        g_array_unref (thread_data->n_nodes);
         g_slice_free (SelectedFindThreadData, user_data);
+
         return;
     }
 
@@ -840,6 +969,7 @@ selected_find_callback (GObject *source, GAsyncResult *res,
     }
 
     et_mb_set_selected_search (&mb_dialog_priv->search,
+                               thread_data->n_nodes,
                                ((SelectedFindThreadData *)user_data)->list_iter);
     g_slice_free (SelectedFindThreadData, user_data);
 }
@@ -860,18 +990,25 @@ selected_find_thread_func (GSimpleAsyncResult *res, GObject *obj,
     GList *iter;
     SelectedFindThreadData *thread_data;
     GError *error;
+    int i;
+    int children;
 
+    i = 0;
     g_simple_async_result_set_op_res_gboolean (res, FALSE);
     error = NULL;
     thread_data = g_async_result_get_user_data (G_ASYNC_RESULT (res));
     list_keys = g_hash_table_get_keys (thread_data->hash_table);
+    g_array_set_size (thread_data->n_nodes, g_list_length (list_keys));
     iter = g_list_first (list_keys);
 
     while (iter)
     {
+        children = g_node_n_children (thread_data->node);
+
         if (!et_musicbrainz_search ((gchar *)iter->data, MB_ENTITY_KIND_ALBUM,
-                                    thread_data->node, &error,
-                                    cancellable))
+                                    thread_data->node, 
+                                    g_array_index (thread_data->n_nodes, int, i),
+                                    &error, cancellable))
         {
             g_simple_async_report_gerror_in_idle (NULL,
                                                   mb5_search_error_callback,
@@ -880,6 +1017,8 @@ selected_find_thread_func (GSimpleAsyncResult *res, GObject *obj,
             return;
         }
 
+        g_array_index (thread_data->n_nodes, int, i) += g_node_n_children (thread_data->node) - children;
+ 
         if (g_cancellable_is_cancelled (cancellable))
         {
             g_set_error (&error, ET_MB5_SEARCH_ERROR,
@@ -893,6 +1032,7 @@ selected_find_thread_func (GSimpleAsyncResult *res, GObject *obj,
         }
 
         iter = g_list_next (iter);
+        i++;
     }
 
     g_list_free (list_keys);
@@ -1029,6 +1169,7 @@ btn_selected_find_clicked (GtkWidget *button, gpointer data)
     thread_data->hash_table = hash_table;
     thread_data->list_iter = iter_list;
     thread_data->node = g_node_new (NULL);
+    thread_data->n_nodes = g_array_new (FALSE, TRUE, sizeof (int));
     mb5_search_cancellable = g_cancellable_new ();
     mb_dialog_priv->async_result = g_simple_async_result_new (NULL,
                                                               selected_find_callback,
@@ -1037,8 +1178,8 @@ btn_selected_find_clicked (GtkWidget *button, gpointer data)
     g_simple_async_result_run_in_thread (mb_dialog_priv->async_result,
                                          selected_find_thread_func, 0,
                                          mb5_search_cancellable);
-    gtk_statusbar_push (mb_dialog_priv->statusbar,
-                        0, _("Starting Selected Files Search"));
+    gtk_statusbar_push (mb_dialog_priv->statusbar, 0,
+                        _("Starting Selected Files Search"));
     et_music_brainz_dialog_stop_set_sensitive (TRUE);
 }
 
@@ -1114,11 +1255,13 @@ discid_search_callback (GObject *source, GAsyncResult *res,
     et_mb_entity_view_clear_all (ET_MB_ENTITY_VIEW (mb_dialog_priv->entityView));
     et_mb_entity_view_set_tree_root (ET_MB_ENTITY_VIEW (mb_dialog_priv->entityView),
                                      mb_dialog_priv->mb_tree_root);
-    gtk_statusbar_push (mb_dialog_priv->statusbar,
-                        0, _("Searching Completed"));
+    gtk_statusbar_push (mb_dialog_priv->statusbar, 0,
+                        _("Searching Completed"));
     g_object_unref (res);
     g_slice_free (DiscIDSearchThreadData, thread_data);
     et_music_brainz_dialog_stop_set_sensitive (FALSE);
+    gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btn_fetch_more")),
+                              FALSE);
 
     if (mb_dialog_priv->exit_on_complete)
     {
@@ -1176,7 +1319,7 @@ discid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
 
     thread_data = g_async_result_get_user_data (G_ASYNC_RESULT (res));
     if (!et_musicbrainz_search (discid, MB_ENTITY_KIND_DISCID,
-                                thread_data->node,
+                                thread_data->node, 0,
                                 &error, cancellable))
     {
         g_simple_async_report_gerror_in_idle (NULL,
@@ -1265,6 +1408,7 @@ freedbid_search_callback (GObject *source, GAsyncResult *res,
         return;
     }
 
+    free_mb_tree (&mb_dialog_priv->mb_tree_root);
     mb_dialog_priv->mb_tree_root = thread_data->node;
     et_mb_entity_view_clear_all (ET_MB_ENTITY_VIEW (mb_dialog_priv->entityView));
     et_mb_entity_view_set_tree_root (ET_MB_ENTITY_VIEW (mb_dialog_priv->entityView),
@@ -1316,7 +1460,7 @@ freedbid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
 
     if (!et_musicbrainz_search (thread_data->cddb_discid,
                                 MB_ENTITY_KIND_FREEDBID,
-                                thread_data->node,
+                                thread_data->node, 0,
                                 &error, cancellable))
     {
         g_simple_async_report_gerror_in_idle (NULL,
@@ -1819,9 +1963,9 @@ et_initialize_tag_choice_dialog (EtMusicBrainzDialogPrivate *mb_dialog_priv)
 
     renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes ("Title",
-                                               renderer, "text",
-                                               TAG_CHOICE_TITLE,
-                                               NULL);
+                                                       renderer, "text",
+                                                       TAG_CHOICE_TITLE,
+                                                       NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (tag_choice_list),
                                  column);
 
@@ -1871,7 +2015,8 @@ et_music_brainz_get_exit_on_complete (void)
 {
     EtMusicBrainzDialogPrivate *mb_dialog_priv;
 
-    mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (ET_MUSICBRAINZ_DIALOG (mbDialog));    
+    mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (ET_MUSICBRAINZ_DIALOG (mbDialog));
+
     return mb_dialog_priv->exit_on_complete;
 }
 
@@ -1956,7 +2101,7 @@ et_music_brainz_dialog_stop_set_sensitive (gboolean sensitive)
                               !sensitive);
     gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btn_apply_changes")),
                               !sensitive);
-    gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btnApplyChanges")),
+    gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btn_fetch_more")),
                               !sensitive);
 }
 
@@ -2073,7 +2218,7 @@ et_musicbrainz_dialog_init (EtMusicBrainzDialog *dialog)
     gtk_window_set_title (GTK_WINDOW (dialog), "MusicBrainz Search");
     gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                         box, TRUE, TRUE, 2);
-    gtk_widget_set_size_request (GTK_WIDGET (dialog), 660, 500);
+    gtk_widget_set_size_request (GTK_WIDGET (dialog), 700, 500);
     gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "central_box")),
                         priv->entityView, TRUE, TRUE, 2);
     et_initialize_tag_choice_dialog (priv);
@@ -2119,10 +2264,12 @@ et_musicbrainz_dialog_init (EtMusicBrainzDialog *dialog)
     g_signal_connect (gtk_builder_get_object (builder, "btn_apply_changes"),
                       "clicked", G_CALLBACK (btn_apply_changes_clicked),
                       NULL);
- 
     g_signal_connect (gtk_builder_get_object (builder, "btn_automatic_search"),
                       "clicked", G_CALLBACK (btn_automatic_search_clicked),
                       NULL);
+    g_signal_connect (gtk_builder_get_object (builder, "btn_fetch_more"),
+                      "clicked", G_CALLBACK (btn_fetch_more_clicked),
+                      NULL);
     g_signal_connect_after (gtk_builder_get_object (builder, "entry_tree_view_search"),
                             "changed",
                             G_CALLBACK (entry_tree_view_search_changed),
@@ -2132,9 +2279,12 @@ et_musicbrainz_dialog_init (EtMusicBrainzDialog *dialog)
     cb_manual_search_in = GTK_WIDGET (gtk_builder_get_object (builder,
                                                               "cb_manual_search_in"));
 
-    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cb_manual_search_in), "Artist");
-    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cb_manual_search_in), "Album");
-    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cb_manual_search_in), "Track");
+    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cb_manual_search_in),
+                                    _("Artist"));
+    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cb_manual_search_in),
+                                    _("Album"));
+    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (cb_manual_search_in),
+                                    _("Track"));
 
     gtk_combo_box_set_active (GTK_COMBO_BOX (cb_manual_search_in), 1);
 
diff --git a/tests/test-musicbrainz.c b/tests/test-musicbrainz.c
index 1e696a5..68831c1 100644
--- a/tests/test-musicbrainz.c
+++ b/tests/test-musicbrainz.c
@@ -95,7 +95,7 @@ mb_search_test (void)
     err = NULL;
     mbTreeNode = g_node_new (NULL);
     if (et_musicbrainz_search ("Westlife", MB_ENTITY_KIND_ARTIST, mbTreeNode,
-                               &err, NULL))
+                               0, &err, NULL))
     {
         EtMbEntity *etentity;
 
@@ -113,7 +113,7 @@ mb_search_test (void)
     mbTreeNode = g_node_new (NULL);
 
     if (et_musicbrainz_search ("Never Gone", MB_ENTITY_KIND_ALBUM, mbTreeNode,
-                               &err, NULL))
+                               0, &err, NULL))
     {
         EtMbEntity *etentity;
 
@@ -131,7 +131,7 @@ mb_search_test (void)
     mbTreeNode = g_node_new (NULL);
 
     if (et_musicbrainz_search ("I Still", MB_ENTITY_KIND_TRACK, mbTreeNode,
-                               &err, NULL))
+                               0, &err, NULL))
     {
         EtMbEntity *etentity;
 
@@ -150,7 +150,7 @@ mb_search_test (void)
 
     if (et_musicbrainz_search ("lwHl8fGzJyLXQR33ug60E8jhf4k-",
                                MB_ENTITY_KIND_DISCID, mbTreeNode,
-                               &err, NULL))
+                               0, &err, NULL))
     {
         EtMbEntity *etentity;
 
@@ -169,7 +169,7 @@ mb_search_test (void)
 
     if (et_musicbrainz_search ("24028103",
                                MB_ENTITY_KIND_FREEDBID, mbTreeNode,
-                               &err, NULL))
+                               0, &err, NULL))
     {
         EtMbEntity *etentity;
 
@@ -195,7 +195,7 @@ mb_search_in_test (void)
     mbTreeNode = g_node_new (NULL);
 
     if (et_musicbrainz_search ("Westlife", MB_ENTITY_KIND_ARTIST, mbTreeNode,
-                               &err, NULL))
+                               0, &err, NULL))
     {
         EtMbEntity *etentity;
         GNode *westlife_node;
@@ -209,7 +209,7 @@ mb_search_in_test (void)
 
         if (et_musicbrainz_search_in_entity (MB_ENTITY_KIND_ALBUM,
                                              MB_ENTITY_KIND_ARTIST, mbid,
-                                             westlife_node, &err, NULL))
+                                             westlife_node, 0, &err, NULL))
         {
             EtMbEntity *etentity;
 
@@ -230,7 +230,7 @@ mb_search_in_test (void)
     mbTreeNode = g_node_new (NULL);
 
     if (et_musicbrainz_search ("Never Gone", MB_ENTITY_KIND_ALBUM, mbTreeNode,
-                               &err, NULL))
+                               0, &err, NULL))
     {
         EtMbEntity *etentity;
         GNode *never_gone_node;
@@ -243,7 +243,7 @@ mb_search_in_test (void)
 
         if (et_musicbrainz_search_in_entity (MB_ENTITY_KIND_TRACK,
                                              MB_ENTITY_KIND_ALBUM, mbid,
-                                             never_gone_node, &err, NULL))
+                                             never_gone_node, 0, &err, NULL))
         {
             EtMbEntity *etentity;
 
@@ -564,4 +564,4 @@ main (int argc, char** argv)
     g_thread_unref (thread);
 
     return 0;
-}
\ No newline at end of file
+}


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