[easytag/wip/musicbrainz-support-merge: 31/75] Implemented Automatic Search
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/musicbrainz-support-merge: 31/75] Implemented Automatic Search
- Date: Fri, 29 Aug 2014 22:24:15 +0000 (UTC)
commit ef27ae60779ebf06d7759ef5a03d78ed91d2e615
Author: Abhinav <abhijangda hotmail com>
Date: Fri Aug 22 20:41:34 2014 +0530
Implemented Automatic Search
Added Automatic Search button in musicbrainz_dialog.ui
Added FreeDBID search support in mb_search.c
Added support for displaying FreeDBID results in mbentityview.c
Implemented Automatic Search clicked callback, freedbid_search_thread_func and freedbid_search_callback
Added new Search Type FreeDBID
data/musicbrainz_dialog.ui | 104 ++++++++++++-------
src/mb_search.c | 60 +++++++++++
src/mb_search.h | 1 +
src/mbentityview.c | 57 +++++++++--
src/mbentityview.h | 8 ++
src/musicbrainz_dialog.c | 235 +++++++++++++++++++++++++++++++++-----------
6 files changed, 360 insertions(+), 105 deletions(-)
---
diff --git a/data/musicbrainz_dialog.ui b/data/musicbrainz_dialog.ui
index df69716..90223be 100755
--- a/data/musicbrainz_dialog.ui
+++ b/data/musicbrainz_dialog.ui
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <object class="GtkImage" id="img_unselect_all">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="stock">easytag-unselect-all</property>
- </object>
<object class="GtkImage" id="findimage">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -21,6 +16,11 @@
<property name="can_focus">False</property>
<property name="stock">easytag-red-lines</property>
</object>
+ <object class="GtkImage" id="img_unselect_all">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">easytag-unselect-all</property>
+ </object>
<object class="GtkDialog" id="mbDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
@@ -151,6 +151,19 @@
</packing>
</child>
<child>
+ <object class="GtkButton" id="btnAutomaticSearch">
+ <property name="label" translatable="yes">Automatic Search</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>
+ <child>
<object class="GtkButton" id="btnDiscFind">
<property name="label" translatable="yes">DiscID Search</property>
<property name="visible">True</property>
@@ -389,38 +402,13 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkBox" id="box10">
+ <object class="GtkCheckButton" id="chkUseDLM">
+ <property name="label" translatable="yes">Match lines with the Levenshtein
algorithm</property>
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="spacing">4</property>
- <child>
- <object class="GtkButton" id="btnClose">
- <property name="label" translatable="yes">Close</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="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="btnApplyChanges">
- <property name="label" translatable="yes">Apply Tag Changes</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">False</property>
- <property name="pack_type">end</property>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">True</property>
@@ -431,11 +419,51 @@
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">True</property>
+ <property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
+ <object class="GtkBox" id="box10">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkButton" id="btnClose">
+ <property name="label" translatable="yes">Close</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="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="btnApplyChanges">
+ <property name="label" translatable="yes">Apply Tag Changes</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">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkStatusbar" id="statusbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -444,7 +472,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
</object>
diff --git a/src/mb_search.c b/src/mb_search.c
index ee936ed..ea915be 100755
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -353,6 +353,12 @@ et_musicbrainz_search_in_entity (MbEntityKind child_type,
goto err;
}
}
+ else if (child_type == MB_ENTITY_KIND_ALBUM &&
+ parent_type == MB_ENTITY_KIND_FREEDBID)
+ {
+ return et_musicbrainz_search (parent_mbid, child_type, root, error,
+ cancellable);
+ }
CHECK_CANCELLED(cancellable);
mb5_query_delete (query);
@@ -721,6 +727,60 @@ et_musicbrainz_search (gchar *string, MbEntityKind type, GNode *root,
goto err;
}
}
+ else if (type == MB_ENTITY_KIND_FREEDBID)
+ {
+ param_values [0] = g_strconcat ("discid:", string, NULL);
+ metadata = mb5_query_query (query, "freedb", "", "", 2, param_names,
+ param_values);
+ result = mb5_query_get_lastresult (query);
+ g_free (param_values [0]);
+
+ if (result == eQuery_Success)
+ {
+ if (metadata)
+ {
+ int i;
+ Mb5FreeDBDiscList list;
+ gchar *message;
+
+ list = mb5_metadata_get_freedbdisclist (metadata);
+ message = g_strdup_printf (_("Found %d Result(s)"),
+ mb5_freedbdisc_list_size (list));
+#ifndef TEST
+ //et_show_status_msg_in_idle (message);
+#endif
+ g_free (message);
+
+ for (i = 0; i < mb5_freedbdisc_list_size (list); i++)
+ {
+ Mb5FreeDBDisc freedbdisc;
+
+ CHECK_CANCELLED(cancellable);
+ freedbdisc = mb5_freedbdisc_list_item (list, i);
+
+ if (freedbdisc)
+ {
+ gchar buf [NAME_MAX_SIZE];
+ GNode *node;
+ EtMbEntity *entity;
+ int size;
+
+ size = mb5_freedbdisc_get_title (freedbdisc,
+ buf, sizeof (buf));
+ buf [size] = '\0';
+ entity = g_malloc (sizeof (EtMbEntity));
+ entity->entity = mb5_freedbdisc_clone (freedbdisc);
+ entity->type = MB_ENTITY_KIND_FREEDBID;
+ entity->is_red_line = FALSE;
+ node = g_node_new (entity);
+ g_node_append (root, node);
+ }
+ }
+ }
+
+ mb5_metadata_delete (metadata);
+ }
+ }
mb5_query_delete (query);
CHECK_CANCELLED(cancellable);
diff --git a/src/mb_search.h b/src/mb_search.h
index 8b2fc63..700bcb7 100755
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -75,6 +75,7 @@ typedef enum _MbEntityKind
MB_ENTITY_KIND_ARTIST = 0,
MB_ENTITY_KIND_ALBUM,
MB_ENTITY_KIND_TRACK,
+ MB_ENTITY_KIND_FREEDBID,
MB_ENTITY_KIND_COUNT,
MB_ENTITY_KIND_DISCID,
} MbEntityKind;
diff --git a/src/mbentityview.c b/src/mbentityview.c
index 61e0be4..ed22022 100644
--- a/src/mbentityview.c
+++ b/src/mbentityview.c
@@ -40,10 +40,11 @@ G_DEFINE_TYPE (EtMbEntityView, et_mb_entity_view, GTK_TYPE_BOX)
* Declaration *
***************/
-char *columns [MB_ENTITY_KIND_COUNT][8] = {
+char *columns [MB_ENTITY_KIND_COUNT][10] = {
{"Name", "Gender", "Type"},
{"Name", "Artist", "Type"},
{"Name", "Album", "Artist", "Time"},
+ {"FreeDB ID", "Title", "Artist"}
};
/*
@@ -471,6 +472,27 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
break;
}
+ case MB_ENTITY_KIND_FREEDBID:
+ {
+ gchar freedbid [NAME_MAX_SIZE];
+ gchar title [NAME_MAX_SIZE];
+ gchar artist [NAME_MAX_SIZE];
+
+ mb5_freedbdisc_get_artist ((Mb5FreeDBDisc)entity,
+ artist, sizeof (artist));
+ mb5_freedbdisc_get_title ((Mb5FreeDBDisc)entity,
+ title, sizeof (title));
+ mb5_freedbdisc_get_id ((Mb5FreeDBDisc)entity,
+ freedbid, sizeof (freedbid));
+ gtk_list_store_insert_with_values (list_store, &iter, -1,
+ MB_FREEDBID_COLUMNS_ID,
+ freedbid,
+ MB_FREEDBID_COLUMNS_NAME,
+ title,
+ MB_FREEDBID_COLUMNS_ARTIST,
+ artist, -1);
+ }
+
case MB_ENTITY_KIND_COUNT:
case MB_ENTITY_KIND_DISCID:
break;
@@ -539,6 +561,10 @@ show_data_in_entity_view (EtMbEntityView *entity_view)
total_cols = MB_TRACK_COLUMNS_N;
break;
+ case MB_ENTITY_KIND_FREEDBID:
+ total_cols = MB_FREEDBID_COLUMNS_N;
+ break;
+
default:
total_cols = 0;
}
@@ -682,8 +708,8 @@ search_in_levels_callback (GObject *source, GAsyncResult *res,
G_CALLBACK (toggle_button_clicked), entity_view);
priv->active_toggle_button = toggle_btn;
- gtk_tree_model_get (priv->list_store, &thread_data->iter, 0, &entity_name,
- -1);
+ gtk_tree_model_get (priv->list_store, &thread_data->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));
}
@@ -724,6 +750,7 @@ search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
gchar *status_msg;
gchar parent_entity_str [NAME_MAX_SIZE];
gchar *child_entity_type_str;
+ MbEntityKind to_search;
child_entity_type_str = NULL;
thread_data = g_async_result_get_user_data (G_ASYNC_RESULT (res));
@@ -753,6 +780,7 @@ search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
mbid, sizeof (mbid));
mb5_artist_get_name (((EtMbEntity *)thread_data->child->data)->entity,
parent_entity_str, sizeof (parent_entity_str));
+ to_search = MB_ENTITY_KIND_ALBUM;
}
else if (((EtMbEntity *)thread_data->child->data)->type ==
MB_ENTITY_KIND_ALBUM)
@@ -762,6 +790,16 @@ search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
mbid, sizeof (mbid));
mb5_release_get_title (((EtMbEntity *)thread_data->child->data)->entity,
parent_entity_str, sizeof (parent_entity_str));
+ to_search = MB_ENTITY_KIND_TRACK;
+ }
+ else if (((EtMbEntity *)thread_data->child->data)->type ==
+ MB_ENTITY_KIND_FREEDBID)
+ {
+ child_entity_type_str = g_strdup ("Albums ");
+ mb5_freedbdisc_get_title (((EtMbEntity *)thread_data->child->data)->entity,
+ mbid, sizeof (mbid));
+ g_stpcpy (parent_entity_str, mbid);
+ to_search = MB_ENTITY_KIND_ALBUM;
}
error = NULL;
@@ -782,7 +820,7 @@ search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
return;
}
- if (!et_musicbrainz_search_in_entity (((EtMbEntity *)thread_data->child->data)->type + 1,
+ if (!et_musicbrainz_search_in_entity (to_search,
((EtMbEntity *)thread_data->child->data)->type,
mbid, thread_data->child, &error,
cancellable))
@@ -830,7 +868,8 @@ tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
child = g_node_nth_child (priv->mb_tree_current_node,
depth);
- search_in_levels (ET_MB_ENTITY_VIEW (user_data), child, &filter_iter, FALSE);
+ search_in_levels (ET_MB_ENTITY_VIEW (user_data), child, &filter_iter,
+ FALSE);
}
static void
@@ -842,7 +881,7 @@ search_in_levels (EtMbEntityView *entity_view, GNode *child,
if (((EtMbEntity *)child->data)->type ==
MB_ENTITY_KIND_TRACK)
- {printf ("sdsd\n");
+ {
return;
}
@@ -966,6 +1005,10 @@ et_mb_entity_view_set_tree_root (EtMbEntityView *entity_view, GNode *treeRoot)
gtk_button_set_label (GTK_BUTTON (btn), _("Tracks"));
break;
+ case MB_ENTITY_KIND_FREEDBID:
+ gtk_button_set_label (GTK_BUTTON (btn), _("FreeDB Disc"));
+ break;
+
default:
break;
}
@@ -1198,11 +1241,9 @@ void
et_mb_entity_view_refresh_current_level (EtMbEntityView *entity_view)
{
EtMbEntityViewPrivate *priv;
- EtMbEntity *et_entity;
GNode *child;
priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
- et_entity = priv->mb_tree_current_node->data;
/* Delete Current Data */
et_mb_entity_view_clear_all (entity_view);
diff --git a/src/mbentityview.h b/src/mbentityview.h
index fb4eeda..4fd5e7c 100755
--- a/src/mbentityview.h
+++ b/src/mbentityview.h
@@ -98,6 +98,14 @@ enum MB_TRACK_COLUMNS
MB_TRACK_COLUMNS_N
};
+enum MB_FREEDBID_COLUMNS
+{
+ MB_FREEDBID_COLUMNS_ID,
+ MB_FREEDBID_COLUMNS_NAME,
+ MB_FREEDBID_COLUMNS_ARTIST,
+ MB_FREEDBID_COLUMNS_N
+};
+
/**************
* Prototypes *
**************/
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 911501e..5bb8d88 100755
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -26,6 +26,7 @@
#include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h>
#include <discid/discid.h>
+#include <openssl/ssl.h>
#include "easytag.h"
#include "log.h"
@@ -57,6 +58,7 @@ typedef enum
{
ET_MB_SEARCH_TYPE_MANUAL,
ET_MB_SEARCH_TYPE_SELECTED,
+ ET_MB_SEARCH_TYPE_AUTOMATIC,
} EtMbSearchType;
typedef struct
@@ -86,6 +88,11 @@ typedef struct
typedef struct
{
+ EtMbSearch parent;
+} EtMbAutomaticSearch;
+
+typedef struct
+{
GNode *mb_tree_root;
GSimpleAsyncResult *async_result;
EtMbSearch *search;
@@ -117,6 +124,8 @@ static void
btn_close_clicked (GtkWidget *button, gpointer data);
static void
bt_selected_find_clicked (GtkWidget *widget, gpointer user_data);
+static void
+btn_automatic_search_clicked (GtkWidget *button, gpointer data);
/*************
* Functions *
*************/
@@ -135,6 +144,9 @@ et_mb_destroy_search (EtMbSearch **search)
g_list_free_full (((EtMbSelectedSearch *)(*search))->list_iter,
(GDestroyNotify)gtk_tree_iter_free);
}
+ else if ((*search)->type == ET_MB_SEARCH_TYPE_AUTOMATIC)
+ {
+ }
g_free (*search);
}
@@ -161,6 +173,14 @@ et_mb_set_selected_search (EtMbSearch **search, GList *list_files)
((EtMbSelectedSearch *)(*search))->list_iter = list_files;
}
+static void
+et_mb_set_automatic_search (EtMbSearch **search)
+{
+ et_mb_destroy_search (search);
+ *search = g_malloc (sizeof (EtMbAutomaticSearch));
+ (*search)->type = ET_MB_SEARCH_TYPE_AUTOMATIC;
+}
+
/*
* manual_search_callback:
* @source: Source Object
@@ -305,7 +325,8 @@ manual_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
}
thread_data = (ManualSearchThreadData *)g_async_result_get_user_data (G_ASYNC_RESULT (res));
- status_msg = g_strdup_printf (_("Searching %s"), thread_data->text_to_search);
+ status_msg = g_strdup_printf (_("Searching %s"),
+ thread_data->text_to_search);
et_show_status_msg_in_idle (status_msg);
g_free (status_msg);
@@ -515,9 +536,21 @@ tool_btn_refresh_clicked (GtkWidget *btn, gpointer user_data)
//EtMbSelectedSearch *search;
//search = (EtMbSelectedSearch *)mb_dialog_priv->search;
+ free_mb_tree (&mb_dialog_priv->mb_tree_root);
+ mb_dialog_priv->mb_tree_root = g_node_new (NULL);
et_mb_entity_view_clear_all (ET_MB_ENTITY_VIEW (entityView));
bt_selected_find_clicked (NULL, NULL);
}
+ else if (mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_AUTOMATIC)
+ {
+ //EtMbSelectedSearch *search;
+
+ //search = (EtMbSelectedSearch *)mb_dialog_priv->search;
+ free_mb_tree (&mb_dialog_priv->mb_tree_root);
+ mb_dialog_priv->mb_tree_root = g_node_new (NULL);
+ et_mb_entity_view_clear_all (ET_MB_ENTITY_VIEW (entityView));
+ btn_automatic_search_clicked (NULL, NULL);
+ }
}
/*
@@ -637,13 +670,11 @@ get_selected_iter_list (GtkTreeView *tree_view, GList **list)
GtkTreeSelection *selection;
int count;
GList *l;
- GHashTable *hash_table;
- SelectedFindThreadData *thread_data;
GtkTreeView *browser_list;
selection = et_application_window_browser_get_selection (ET_APPLICATION_WINDOW (MainWindow));
browser_list = gtk_tree_selection_get_tree_view (selection);
- tree_model = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(browser_list)));
+ tree_model = GTK_TREE_MODEL(gtk_tree_view_get_model(GTK_TREE_VIEW(browser_list)));
count = gtk_tree_selection_count_selected_rows(selection);
if (count > 0)
@@ -674,8 +705,8 @@ get_selected_iter_list (GtkTreeView *tree_view, GList **list)
{
GtkTreeIter current_iter;
- if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree_model),
- ¤t_iter))
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (tree_model),
+ ¤t_iter))
{
/* No row is present, return */
return 0;
@@ -686,11 +717,11 @@ get_selected_iter_list (GtkTreeView *tree_view, GList **list)
*list = g_list_prepend (*list,
gtk_tree_iter_copy (¤t_iter));
}
- while (gtk_tree_model_iter_next(GTK_TREE_MODEL(tree_model),
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (tree_model),
¤t_iter));
- count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(tree_model),
- NULL);
+ count = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(tree_model),
+ NULL);
}
return count;
@@ -757,13 +788,10 @@ get_first_selected_file (ET_File **et_file)
GtkListStore *tree_model;
GtkTreeSelection *selection;
int count;
- GList *iter_list;
- GList *l;
GtkTreeView *browser_list;
selection = et_application_window_browser_get_selection (ET_APPLICATION_WINDOW (MainWindow));
browser_list = gtk_tree_selection_get_tree_view (selection);
- iter_list = NULL;
tree_model = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(browser_list)));
count = gtk_tree_selection_count_selected_rows(selection);
*et_file = NULL;
@@ -852,7 +880,8 @@ discid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
return;
}
- if (!et_musicbrainz_search (discid, MB_ENTITY_KIND_DISCID, mb_dialog_priv->mb_tree_root,
+ if (!et_musicbrainz_search (discid, MB_ENTITY_KIND_DISCID,
+ mb_dialog_priv->mb_tree_root,
&error, cancellable))
{
g_simple_async_report_gerror_in_idle (NULL,
@@ -862,8 +891,6 @@ discid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
return;
}
- et_mb_entity_view_set_tree_root (ET_MB_ENTITY_VIEW (entityView),
- mb_dialog_priv->mb_tree_root);
discid_free (disc);
g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res),
TRUE);
@@ -891,7 +918,71 @@ btn_close_clicked (GtkWidget *button, gpointer data)
gtk_dialog_response (GTK_DIALOG (mbDialog), GTK_RESPONSE_DELETE_EVENT);
}
-#if 0
+static void
+freedbid_search_callback (GObject *source, GAsyncResult *res,
+ gpointer user_data)
+{
+ if (!g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res)))
+ {
+ g_object_unref (res);
+ free_mb_tree (&mb_dialog_priv->mb_tree_root);
+ mb_dialog_priv->mb_tree_root = g_node_new (NULL);
+ g_free (user_data);
+ return;
+ }
+
+ et_mb_entity_view_set_tree_root (ET_MB_ENTITY_VIEW (entityView),
+ mb_dialog_priv->mb_tree_root);
+ gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+ 0, _("Searching Completed"));
+ g_object_unref (res);
+ g_free (user_data);
+ et_music_brainz_dialog_stop_set_sensitive (FALSE);
+ et_mb_set_automatic_search (&mb_dialog_priv->search);
+
+ if (exit_on_complete)
+ {
+ btn_close_clicked (NULL, NULL);
+ }
+}
+
+static void
+freedbid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
+ GCancellable *cancellable)
+{
+ GError *error;
+ gchar *freedbid;
+
+ error = NULL;
+ g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res),
+ FALSE);
+ freedbid = g_async_result_get_user_data (G_ASYNC_RESULT (res));
+
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ g_set_error (&error, ET_MB5_SEARCH_ERROR,
+ ET_MB5_SEARCH_ERROR_CANCELLED,
+ _("Operation cancelled by user"));
+ g_simple_async_report_gerror_in_idle (NULL,
+ mb5_search_error_callback,
+ NULL, error);
+ return;
+ }
+
+ if (!et_musicbrainz_search (freedbid, MB_ENTITY_KIND_FREEDBID,
+ mb_dialog_priv->mb_tree_root,
+ &error, cancellable))
+ {
+ g_simple_async_report_gerror_in_idle (NULL,
+ mb5_search_error_callback,
+ NULL, error);
+ return;
+ }
+
+ g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res),
+ TRUE);
+}
+
static void
btn_automatic_search_clicked (GtkWidget *button, gpointer data)
{
@@ -900,18 +991,17 @@ btn_automatic_search_clicked (GtkWidget *button, gpointer data)
int count;
GList *iter_list;
GList *l;
- GHashTable *hash_table;
- SelectedFindThreadData *thread_data;
int total_id;
int num_tracks;
guint total_frames = 150;
guint disc_length = 2;
- gchar *query_string;
gchar *cddb_discid;
+ GtkTreeView *browser_list;
iter_list = NULL;
- tree_model = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(BrowserList)));
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
+ selection = et_application_window_browser_get_selection (ET_APPLICATION_WINDOW (MainWindow));
+ browser_list = gtk_tree_selection_get_tree_view (selection);
+ tree_model = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(browser_list)));
count = gtk_tree_selection_count_selected_rows(selection);
if (count > 0)
@@ -995,10 +1085,12 @@ btn_automatic_search_clicked (GtkWidget *button, gpointer data)
ET_File *etfile;
gulong secs = 0;
- etfile = Browser_List_Get_ETFile_From_Iter ((GtkTreeIter *)l->data);
+ etfile = et_application_window_browser_get_et_file_from_iter (ET_APPLICATION_WINDOW (MainWindow),
+ (GtkTreeIter *)l->data);
secs = etfile->ETFileInfo->duration;
total_frames += secs * 75;
disc_length += secs;
+
while (secs > 0)
{
total_id = total_id + (secs % 10);
@@ -1006,16 +1098,28 @@ btn_automatic_search_clicked (GtkWidget *button, gpointer data)
}
}
- cddb_discid = g_strdup_printf("%08x",(guint)(((total_id % 0xFF) << 24) |
- (disc_length << 8) | num_tracks));
+ cddb_discid = g_strdup_printf ("%08x", (guint)(((total_id % 0xFF) << 24) |
+ (disc_length << 8) | num_tracks));
+
+ mb5_search_cancellable = g_cancellable_new ();
+ gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+ 0, _("Starting MusicBrainz Search"));
+ mb_dialog_priv->async_result = g_simple_async_result_new (NULL,
+ freedbid_search_callback,
+ cddb_discid,
+ btn_automatic_search_clicked);
+ g_simple_async_result_run_in_thread (mb_dialog_priv->async_result,
+ freedbid_search_thread_func, 0,
+ mb5_search_cancellable);
+ et_music_brainz_dialog_stop_set_sensitive (TRUE);
}
-#endif
void
et_music_brainz_dialog_stop_set_sensitive (gboolean sensitive)
{
gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btnStop")),
sensitive);
+ gtk_widget_set_sensitive (entityView, !sensitive);
}
static void
@@ -1055,7 +1159,7 @@ btn_apply_changes_clicked (GtkWidget *widget, gpointer data)
&file_iter_list))
{
gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
- 0, _("No Files Selected"));
+ 0, _("No Files Selected"));
return;
}
@@ -1063,7 +1167,7 @@ btn_apply_changes_clicked (GtkWidget *widget, gpointer data)
&track_iter_list))
{
gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
- 0, _("No Track Selected"));
+ 0, _("No Track Selected"));
g_list_free_full (file_iter_list, (GDestroyNotify)gtk_tree_iter_free);
return;
@@ -1073,23 +1177,20 @@ btn_apply_changes_clicked (GtkWidget *widget, gpointer data)
MB_ENTITY_KIND_TRACK)
{
gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
- 0, _("No Track Selected"));
+ 0, _("No Track Selected"));
g_list_free_full (file_iter_list, (GDestroyNotify)gtk_tree_iter_free);
g_list_free (track_iter_list);
return;
}
- if (mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_MANUAL ||
- mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_SELECTED)
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "chkUseDLM"))))
{
EtMbEntity *et_entity;
EtMbEntity *album_entity;
- GHashTable *hash_table;
gchar album [NAME_MAX_SIZE];
album_entity = et_mb_entity_view_get_current_entity (ET_MB_ENTITY_VIEW (entityView));
- hash_table = g_hash_table_new (g_str_hash, g_str_equal);
mb5_release_get_title (album_entity->entity, album, sizeof (album));
for (list_iter1 = track_iter_list; list_iter1;
@@ -1119,24 +1220,14 @@ btn_apply_changes_clicked (GtkWidget *widget, gpointer data)
filename = ((File_Name *)et_file->FileNameCur->data)->value;
file_tag = (File_Tag *)et_file->FileTag->data;
- if (g_hash_table_contains (hash_table, filename))
+ if (mb_dialog_priv->search->type ==
+ ET_MB_SEARCH_TYPE_SELECTED &&
+ !file_tag->album && g_strcmp0 (file_tag->album, album))
{
continue;
}
- if (!file_tag->album && g_strcmp0 (file_tag->album, album))
- {
- continue;
- }
-
- if (file_tag->title)
- {
- distance = dlm (file_tag->title, title);
- }
- else
- {
- distance = dlm (filename, title);
- }
+ distance = dlm (filename, title);
if (distance < min_distance)
{
@@ -1147,16 +1238,41 @@ btn_apply_changes_clicked (GtkWidget *widget, gpointer data)
if (best_et_file)
{
- if (et_apply_track_tag_to_et_file (et_entity->entity,
- best_et_file))
+ et_apply_track_tag_to_et_file (et_entity->entity,
+ best_et_file);
+ while (gtk_events_pending ())
{
- g_hash_table_add (hash_table,
- ((File_Name *)best_et_file->FileNameCur->data)->value);
-
- while (gtk_events_pending ())
- {
- gtk_main_iteration ();
- }
+ gtk_main_iteration ();
+ }
+ }
+ }
+ }
+ else
+ {
+ EtMbEntity *et_entity;
+ EtMbEntity *album_entity;
+ gchar album [NAME_MAX_SIZE];
+
+ album_entity = et_mb_entity_view_get_current_entity (ET_MB_ENTITY_VIEW (entityView));
+ mb5_release_get_title (album_entity->entity, album, sizeof (album));
+ list_iter2 = file_iter_list;
+
+ for (list_iter1 = track_iter_list; list_iter1 && list_iter2;
+ list_iter1 = g_list_next (list_iter1),
+ list_iter2 = g_list_next (list_iter2))
+ {
+ ET_File *et_file;
+
+ et_entity = list_iter1->data;
+ et_file = et_application_window_browser_get_et_file_from_iter (ET_APPLICATION_WINDOW
(MainWindow),
+ list_iter2->data);
+
+ if (et_apply_track_tag_to_et_file (et_entity->entity,
+ et_file))
+ {
+ while (gtk_events_pending ())
+ {
+ gtk_main_iteration ();
}
}
}
@@ -1204,7 +1320,8 @@ et_apply_track_tag_to_et_file (Mb5Recording recording, ET_File *et_file)
mb5_release_get_country (release, country, sizeof (country));
gtk_list_store_insert_with_values (GTK_LIST_STORE (mb_dialog_priv->tag_choice_store),
- &iter, -1, TAG_CHOICE_TITLE, title,
+ &iter, -1,
+ TAG_CHOICE_TITLE, title,
TAG_CHOICE_ALBUM, album,
TAG_CHOICE_ARTIST, artist,
TAG_CHOICE_ALBUM_ARTIST, album_artist,
@@ -1446,9 +1563,9 @@ et_open_musicbrainz_dialog ()
"clicked", G_CALLBACK (btn_apply_changes_clicked),
NULL);
- //g_signal_connect (gtk_builder_get_object (builder, "btnAutomaticSearch"),
- // "clicked", G_CALLBACK (btn_automatic_search_clicked),
- // NULL);
+ g_signal_connect (gtk_builder_get_object (builder, "btnAutomaticSearch"),
+ "clicked", G_CALLBACK (btn_automatic_search_clicked),
+ NULL);
g_signal_connect_after (gtk_builder_get_object (builder, "entryTreeViewSearch"),
"changed",
G_CALLBACK (entry_tree_view_search_changed),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]