[easytag/wip/musicbrainz-support] Added Fetch More Data for Manual Search



commit 91f13d7d21719375b89f80d78b80201557d4f5e1
Author: Abhinav <abhijangda hotmail com>
Date:   Wed Aug 6 00:14:31 2014 +0530

    Added Fetch More Data for Manual Search

 data/musicbrainz_dialog.ui |   14 ++++++++
 src/mb_search.c            |   74 +++++++++++++++++++++++++++++++++++++------
 src/mb_search.h            |    2 +
 src/musicbrainz_dialog.c   |   67 ++++++++++++++++++++++++++++++++++-----
 4 files changed, 137 insertions(+), 20 deletions(-)
---
diff --git a/data/musicbrainz_dialog.ui b/data/musicbrainz_dialog.ui
index 5c0c7da..1763d0b 100755
--- 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 7aec562..4264322 100755
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -31,8 +31,8 @@
  * Declarations *
  ****************/
 
-#define SEARCH_LIMIT_STR "5"
-#define SEARCH_LIMIT_INT 5
+#define SEARCH_LIMIT_STR "2"
+#define SEARCH_LIMIT_INT 2
 
 static gchar *server = NULL;
 static int port = 0;
@@ -539,6 +539,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
@@ -557,20 +600,23 @@ et_musicbrainz_search_artist (gchar *string, GNode *root, GError **error,
     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", g_node_n_children (root));
     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)
@@ -647,8 +693,8 @@ et_musicbrainz_search_album (gchar *string, GNode *root, GError **error,
     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 +702,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", g_node_n_children (root));
     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)
     {
@@ -804,23 +853,26 @@ et_musicbrainz_search_track (gchar *string, GNode *root, GError **error,
     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", g_node_n_children (root));
     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)
     {
diff --git a/src/mb_search.h b/src/mb_search.h
index cf8b27c..e981c9f 100755
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -126,5 +126,7 @@ void
 free_mb_tree (GNode **node);
 void
 et_set_cancel_error (GError **error);
+EtMbEntity *
+et_mb_entity_copy (EtMbEntity *etentity);
 #endif /* __MB_SEARCH_H__ */
 #endif /* ENABLE_libmusicbrainz */
\ No newline at end of file
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index aabecc7..30b596e 100755
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -384,6 +384,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);
 }
 
 /*
@@ -400,6 +402,8 @@ et_mb_set_selected_search (EtMbSearch **search, GList *list_files)
     *search = (EtMbSearch *)g_slice_new (EtMbSelectedSearch);
     (*search)->type = ET_MB_SEARCH_TYPE_SELECTED;
     ((EtMbSelectedSearch *)(*search))->list_iter = list_files;
+    gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btn_fetch_more")),
+                              TRUE);
 }
 
 /*
@@ -414,6 +418,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);
 }
 
 /*
@@ -539,6 +545,40 @@ manual_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
     g_simple_async_result_set_op_res_gboolean (res, TRUE);
 }
 
+static void
+btn_fetch_more_clicked (GtkWidget *btn, gpointer user_data)
+{
+    EtMusicBrainzDialog *dlg;
+    EtMusicBrainzDialogPrivate *mb_dialog_priv;
+
+    dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
+    mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
+    
+    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_manual_find_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);
+    }
+}
+
 /*
  * btn_manual_stop_clicked:
  * @btn: GtkButton
@@ -1242,6 +1282,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),
@@ -1787,9 +1828,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);
 
@@ -1839,7 +1880,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;
 }
 
@@ -1924,6 +1966,8 @@ 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, "btn_fetch_more")),
+                              !sensitive);
 }
 
 /*
@@ -2039,7 +2083,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);
@@ -2085,10 +2129,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),
@@ -2098,9 +2144,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);
 


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