[easytag/wip/musicbrainz-support-merge: 44/71] Changed behaviour on error
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/musicbrainz-support-merge: 44/71] Changed behaviour on error
- Date: Sun, 31 Aug 2014 20:18:17 +0000 (UTC)
commit 73b3586aa2640a531ee15cbb66e1fb9f4f6d787d
Author: Abhinav <abhijangda hotmail com>
Date: Sun Aug 3 17:58:21 2014 +0530
Changed behaviour on error
Free downloaded nodes in case of an error during search operation.
Achieved it by creating a new parent node in ThreadData of Search,
then setting this node as new parent node for EtMbEntityView.
src/mb_search.c | 5 ++
src/musicbrainz_dialog.c | 145 ++++++++++++++++++++++++++++------------------
2 files changed, 94 insertions(+), 56 deletions(-)
---
diff --git a/src/mb_search.c b/src/mb_search.c
index 2e7acc1..adc8313 100644
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -445,6 +445,11 @@ et_musicbrainz_search_in_entity (MbEntityKind child_type,
cancel:
+ if (metadata_entity)
+ {
+ mb5_metadata_delete (metadata_entity);
+ }
+
if (metadata)
{
mb5_metadata_delete (metadata);
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index a45c3c9..edd3133 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -84,19 +84,6 @@ typedef enum
} EtMbSearchType;
/*
- * SelectedFindThreadData:
- * @text_to_search: Manual Search Text
- * @type: Type of Entity
- *
- * Thread Data for storing Manual Search's data.
- */
-typedef struct
-{
- GHashTable *hash_table;
- GList *list_iter;
-} SelectedFindThreadData;
-
-/*
* EtMbSearch:
* @type: Type of Search
*
@@ -184,8 +171,47 @@ typedef struct
{
gchar *text_to_search;
int type;
+ GNode *node;
} ManualSearchThreadData;
+/*
+ * SelectedFindThreadData:
+ * @text_to_search: Manual Search Text
+ * @type: Type of Entity
+ *
+ * Thread Data for storing Manual Search's data.
+ */
+typedef struct
+{
+ GHashTable *hash_table;
+ GList *list_iter;
+ GNode *node;
+} SelectedFindThreadData;
+
+/*
+ * DiscIDSearchThreadData:
+ * @node: GNode
+ *
+ * Data for DiscID Search.
+ */
+typedef struct
+{
+ GNode *node;
+} DiscIDSearchThreadData;
+
+/*
+ * FreeDBIDSearchThreadData:
+ * @node: GNode
+ * @cddb_discid: FreeDB Discid
+ *
+ * Thread Data for FreeDB ID Search.
+ */
+typedef struct
+{
+ GNode *node;
+ gchar *cddb_discid;
+} FreeDBIDSearchThreadData;
+
/**************
* Prototypes *
**************/
@@ -424,23 +450,21 @@ manual_search_callback (GObject *source, GAsyncResult *res,
simple_async = G_SIMPLE_ASYNC_RESULT (res);
dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
+ thread_data = (ManualSearchThreadData *)user_data;
if (!g_simple_async_result_get_op_res_gboolean (simple_async))
{
g_object_unref (res);
g_slice_free (ManualSearchThreadData, user_data);
et_music_brainz_dialog_stop_set_sensitive (FALSE);
-
- if (priv)
- {
- free_mb_tree (&priv->mb_tree_root);
- priv->mb_tree_root = g_node_new (NULL);
- }
+ free_mb_tree (&thread_data->node);
return;
}
- thread_data = (ManualSearchThreadData *)user_data;
+ et_mb_entity_view_clear_all (ET_MB_ENTITY_VIEW (priv->entityView));
+ free_mb_tree (&priv->mb_tree_root);
+ priv->mb_tree_root = thread_data->node;
et_mb_entity_view_set_tree_root (ET_MB_ENTITY_VIEW (priv->entityView),
priv->mb_tree_root);
gtk_statusbar_push (priv->statusbar, 0, _("Searching Completed"));
@@ -509,7 +533,7 @@ manual_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
if (!et_musicbrainz_search (thread_data->text_to_search,
thread_data->type,
- mb_dialog_priv->mb_tree_root, &error,
+ thread_data->node, &error,
cancellable))
{
g_simple_async_report_gerror_in_idle (NULL,
@@ -560,17 +584,11 @@ btn_manual_find_clicked (GtkWidget *btn, gpointer user_data)
return;
}
- if (g_node_first_child (mb_dialog_priv->mb_tree_root))
- {
- 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 (mb_dialog_priv->entityView));
cb_manual_search = GTK_WIDGET (gtk_builder_get_object (builder,
"cb_manual_search"));
thread_data = g_slice_new (ManualSearchThreadData);
thread_data->type = type;
+ thread_data->node = g_node_new (NULL);
thread_data->text_to_search = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (cb_manual_search));
mb5_search_cancellable = g_cancellable_new ();
gtk_statusbar_push (mb_dialog_priv->statusbar, 0,
@@ -727,8 +745,6 @@ tool_btn_refresh_clicked (GtkWidget *btn, gpointer user_data)
GtkWidget *entry;
manual_search = (EtMbManualSearch *)mb_dialog_priv->search;
- et_mb_entity_view_clear_all (ET_MB_ENTITY_VIEW (mb_dialog_priv->entityView));
- free_mb_tree (&mb_dialog_priv->mb_tree_root);
mb_dialog_priv->mb_tree_root = g_node_new (NULL);
entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (builder, "cb_manual_search")));
gtk_entry_set_text (GTK_ENTRY (entry), manual_search->to_search);
@@ -738,16 +754,10 @@ tool_btn_refresh_clicked (GtkWidget *btn, gpointer user_data)
}
else if (mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_SELECTED)
{
- 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 (mb_dialog_priv->entityView));
btn_selected_find_clicked (NULL, NULL);
}
else if (mb_dialog_priv->search->type == ET_MB_SEARCH_TYPE_AUTOMATIC)
{
- 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 (mb_dialog_priv->entityView));
btn_automatic_search_clicked (NULL, NULL);
}
}
@@ -802,27 +812,30 @@ selected_find_callback (GObject *source, GAsyncResult *res,
{
EtMusicBrainzDialogPrivate *mb_dialog_priv;
EtMusicBrainzDialog *dlg;
+ SelectedFindThreadData *thread_data;
dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
+ thread_data = user_data;
if (!g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res)))
{
g_object_unref (res);
- g_hash_table_destroy (((SelectedFindThreadData *)user_data)->hash_table);
+ g_hash_table_destroy (thread_data->hash_table);
et_music_brainz_dialog_stop_set_sensitive (FALSE);
g_slice_free (SelectedFindThreadData, user_data);
- free_mb_tree (&mb_dialog_priv->mb_tree_root);
- mb_dialog_priv->mb_tree_root = g_node_new (NULL);
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),
mb_dialog_priv->mb_tree_root);
gtk_statusbar_push (mb_dialog_priv->statusbar,
0, _("Searching Completed"));
g_object_unref (res);
- g_hash_table_destroy (((SelectedFindThreadData *)user_data)->hash_table);
+ g_hash_table_destroy (thread_data->hash_table);
et_music_brainz_dialog_stop_set_sensitive (FALSE);
if (mb_dialog_priv->exit_on_complete)
@@ -858,14 +871,14 @@ selected_find_thread_func (GSimpleAsyncResult *res, GObject *obj,
mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
g_simple_async_result_set_op_res_gboolean (res, FALSE);
error = NULL;
- thread_data = (SelectedFindThreadData *)g_async_result_get_user_data (G_ASYNC_RESULT (res));
+ thread_data = g_async_result_get_user_data (G_ASYNC_RESULT (res));
list_keys = g_hash_table_get_keys (thread_data->hash_table);
iter = g_list_first (list_keys);
while (iter)
{
if (!et_musicbrainz_search ((gchar *)iter->data, MB_ENTITY_KIND_ALBUM,
- mb_dialog_priv->mb_tree_root, &error,
+ thread_data->node, &error,
cancellable))
{
g_simple_async_report_gerror_in_idle (NULL,
@@ -1023,6 +1036,7 @@ btn_selected_find_clicked (GtkWidget *button, gpointer data)
thread_data = g_slice_new (SelectedFindThreadData);
thread_data->hash_table = hash_table;
thread_data->list_iter = iter_list;
+ thread_data->node = g_node_new (NULL);
mb5_search_cancellable = g_cancellable_new ();
mb_dialog_priv->async_result = g_simple_async_result_new (NULL,
selected_find_callback,
@@ -1089,19 +1103,23 @@ discid_search_callback (GObject *source, GAsyncResult *res,
{
EtMusicBrainzDialogPrivate *mb_dialog_priv;
EtMusicBrainzDialog *dlg;
+ DiscIDSearchThreadData *thread_data;
+ thread_data = user_data;
dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
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);
+ free_mb_tree (&thread_data->node);
et_music_brainz_dialog_stop_set_sensitive (FALSE);
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),
mb_dialog_priv->mb_tree_root);
gtk_statusbar_push (mb_dialog_priv->statusbar,
@@ -1133,6 +1151,7 @@ discid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
gchar *discid;
EtMusicBrainzDialogPrivate *mb_dialog_priv;
EtMusicBrainzDialog *dlg;
+ DiscIDSearchThreadData *thread_data;
dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
@@ -1167,8 +1186,9 @@ discid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
return;
}
+ thread_data = g_async_result_get_user_data (G_ASYNC_RESULT (res));
if (!et_musicbrainz_search (discid, MB_ENTITY_KIND_DISCID,
- mb_dialog_priv->mb_tree_root,
+ thread_data->node,
&error, cancellable))
{
g_simple_async_report_gerror_in_idle (NULL,
@@ -1195,9 +1215,12 @@ btn_discid_search_clicked (GtkWidget *button, gpointer data)
{
EtMusicBrainzDialogPrivate *mb_dialog_priv;
EtMusicBrainzDialog *dlg;
-
+ DiscIDSearchThreadData *thread_data;
+
dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
+ thread_data = g_slice_new (DiscIDSearchThreadData);
+ thread_data->node = g_node_new (NULL);
mb5_search_cancellable = g_cancellable_new ();
gtk_statusbar_push (mb_dialog_priv->statusbar,
0, _("Starting MusicBrainz Search"));
@@ -1238,26 +1261,31 @@ freedbid_search_callback (GObject *source, GAsyncResult *res,
{
EtMusicBrainzDialogPrivate *mb_dialog_priv;
EtMusicBrainzDialog *dlg;
+ FreeDBIDSearchThreadData *thread_data;
dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
+ thread_data = 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);
+ free_mb_tree (&thread_data->node);
+ g_free (thread_data->cddb_discid);
+ g_slice_free (FreeDBIDSearchThreadData, thread_data);
et_music_brainz_dialog_stop_set_sensitive (FALSE);
return;
}
+ 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),
mb_dialog_priv->mb_tree_root);
gtk_statusbar_push (mb_dialog_priv->statusbar,
0, _("Searching Completed"));
g_object_unref (res);
- g_free (user_data);
+ g_free (thread_data->cddb_discid);
+ g_slice_free (FreeDBIDSearchThreadData, thread_data);
et_music_brainz_dialog_stop_set_sensitive (FALSE);
et_mb_set_automatic_search (&mb_dialog_priv->search);
@@ -1283,13 +1311,14 @@ freedbid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
gchar *freedbid;
EtMusicBrainzDialogPrivate *mb_dialog_priv;
EtMusicBrainzDialog *dlg;
+ FreeDBIDSearchThreadData *thread_data;
dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
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));
+ thread_data = g_async_result_get_user_data (G_ASYNC_RESULT (res));
if (g_cancellable_is_cancelled (cancellable))
{
@@ -1302,8 +1331,9 @@ freedbid_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
return;
}
- if (!et_musicbrainz_search (freedbid, MB_ENTITY_KIND_FREEDBID,
- mb_dialog_priv->mb_tree_root,
+ if (!et_musicbrainz_search (thread_data->cddb_discid,
+ MB_ENTITY_KIND_FREEDBID,
+ thread_data->node,
&error, cancellable))
{
g_simple_async_report_gerror_in_idle (NULL,
@@ -1339,6 +1369,7 @@ btn_automatic_search_clicked (GtkWidget *btn, gpointer data)
GtkTreeView *browser_list;
EtMusicBrainzDialogPrivate *mb_dialog_priv;
EtMusicBrainzDialog *dlg;
+ FreeDBIDSearchThreadData *thread_data;
dlg = ET_MUSICBRAINZ_DIALOG (mbDialog);
mb_dialog_priv = ET_MUSICBRAINZ_DIALOG_GET_PRIVATE (dlg);
@@ -1421,7 +1452,7 @@ btn_automatic_search_clicked (GtkWidget *btn, gpointer data)
0, msg);
g_free (msg);
}
-
+
/* Compute Discid from list */
total_id = 0;
num_tracks = count;
@@ -1444,15 +1475,17 @@ btn_automatic_search_clicked (GtkWidget *btn, gpointer data)
}
}
+ thread_data = g_slice_new (FreeDBIDSearchThreadData);
+ thread_data->node = g_node_new (NULL);
cddb_discid = g_strdup_printf ("%08x", (guint)(((total_id % 0xFF) << 24) |
(disc_length << 8) | num_tracks));
-
+ thread_data->cddb_discid = cddb_discid;
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,
freedbid_search_callback,
- cddb_discid,
+ thread_data,
btn_automatic_search_clicked);
g_simple_async_result_run_in_thread (mb_dialog_priv->async_result,
freedbid_search_thread_func, 0,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]