[easytag/wip/musicbrainz-support-merge: 13/75] Implemented Search Selected Files
- From: Abhinav Jangda <abhijangda src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/musicbrainz-support-merge: 13/75] Implemented Search Selected Files
- Date: Fri, 15 Aug 2014 19:09:54 +0000 (UTC)
commit a598a558ef6f1ffdcffba1a48aecbf2a3b70d7fd
Author: Abhinav <abhijangda hotmail com>
Date: Sat Jun 7 14:26:22 2014 +0530
Implemented Search Selected Files
Added selected_find_thread_func which will search over all selected albumsAdded selected_find_callback
responsible for displaying the results.
Similar to Manual Search
src/musicbrainz_dialog.c | 166 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 165 insertions(+), 1 deletions(-)
---
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index ebbaba4..63a5bdb 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -30,6 +30,7 @@
#include "musicbrainz_dialog.h"
#include "mbentityview.h"
#include "mb_search.h"
+#include "browser.h"
/***************
* Declaration *
@@ -38,6 +39,10 @@
static GNode *mb_tree_root;
static GSimpleAsyncResult *async_result;
+typedef struct
+{
+ GHashTable *hash_table;
+} SelectedFindThreadData;
/*
* ManualSearchThreadData:
* @text_to_search: Manual Search Text
@@ -389,6 +394,163 @@ entry_tree_view_search_changed (GtkEditable *editable, gpointer user_data)
"entryTreeViewSearch"))));
}
+static void
+selected_find_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);
+ g_object_unref (((SelectedFindThreadData *)user_data)->hash_table);
+ g_free (user_data);
+ free_mb_tree (mb_tree_root);
+ mb_tree_root = g_node_new (NULL);
+ return;
+ }
+
+ et_mb_entity_view_set_tree_root (ET_MB_ENTITY_VIEW (entityView),
+ mb_tree_root);
+ gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+ 0, "Searching Completed");
+ g_object_unref (res);
+ g_object_unref (((SelectedFindThreadData *)user_data)->hash_table);
+ g_free (user_data);
+}
+
+static void
+selected_find_thread_func (GSimpleAsyncResult *res, GObject *obj,
+ GCancellable *cancellable)
+{
+ GList *list_keys;
+ GList *iter;
+ SelectedFindThreadData *thread_data;
+ GError *error;
+
+ 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));
+ list_keys = g_hash_table_get_keys (thread_data->hash_table);
+ iter = g_list_first (list_keys);
+
+ while (iter)
+ {
+ 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,
+ thread_data, error);
+ g_list_free (list_keys);
+ return;
+ }
+
+ if (!et_musicbrainz_search ((gchar *)iter->data, MB_ENTITY_TYPE_ALBUM,
+ mb_tree_root, &error, cancellable))
+ {
+ g_simple_async_report_gerror_in_idle (NULL,
+ mb5_search_error_callback,
+ thread_data, error);
+ g_list_free (list_keys);
+ return;
+ }
+
+ iter = g_list_next (iter);
+ }
+
+ g_list_free (list_keys);
+ g_simple_async_result_set_op_res_gboolean (res, TRUE);
+}
+
+static void
+bt_selected_find_clicked (GtkWidget *widget, gpointer user_data)
+{
+ GtkListStore *tree_model;
+ GtkTreeSelection *selection;
+ int count;
+ GList *iter_list;
+ GList *l;
+ GHashTable *hash_table;
+ SelectedFindThreadData *thread_data;
+
+ 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));
+ count = gtk_tree_selection_count_selected_rows(selection);
+
+ if (count > 0)
+ {
+ GList* list_sel_rows;
+
+ list_sel_rows = gtk_tree_selection_get_selected_rows(selection, NULL);
+
+ for (l = list_sel_rows; l != NULL; l = g_list_next (l))
+ {
+ GtkTreeIter iter;
+
+ if (gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_model),
+ &iter,
+ (GtkTreePath *) l->data))
+ {
+ iter_list = g_list_prepend (iter_list,
+ gtk_tree_iter_copy (&iter));
+ }
+ }
+
+ g_list_free_full (list_sel_rows,
+ (GDestroyNotify)gtk_tree_path_free);
+
+ }
+ else /* No rows selected, use the whole list */
+ {
+ GtkTreeIter current_iter;
+
+ gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree_model), ¤t_iter);
+
+ do
+ {
+ iter_list = g_list_prepend (iter_list,
+ gtk_tree_iter_copy (¤t_iter));
+ }
+ 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);
+ }
+
+ 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 = Browser_List_Get_ETFile_From_Iter ((GtkTreeIter *)l->data);
+ file_tag = (File_Tag *)etfile->FileTag->data;
+
+ if (file_tag->album != NULL)
+ {
+ g_hash_table_add (hash_table, file_tag->album);
+ }
+ }
+
+ g_list_free_full (iter_list, (GDestroyNotify)gtk_tree_iter_free);
+ thread_data = g_malloc (sizeof (SelectedFindThreadData));
+ thread_data->hash_table = hash_table;
+ mb5_search_cancellable = g_cancellable_new ();
+ async_result = g_simple_async_result_new (NULL, selected_find_callback,
+ thread_data,
+ bt_selected_find_clicked);
+ g_simple_async_result_run_in_thread (async_result,
+ selected_find_thread_func, 0,
+ mb5_search_cancellable);
+ gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+ 0, "Starting Selected Files Search");
+}
+
/*
* et_open_musicbrainz_dialog:
*
@@ -445,11 +607,13 @@ et_open_musicbrainz_dialog ()
g_signal_connect (gtk_builder_get_object (builder, "toolbtnToggleRedLines"),
"clicked", G_CALLBACK (tool_btn_toggle_red_lines_clicked),
NULL);
+ g_signal_connect (gtk_builder_get_object (builder, "btnSelectedFind"),
+ "clicked", G_CALLBACK (bt_selected_find_clicked),
+ NULL);
g_signal_connect_after (gtk_builder_get_object (builder, "entryTreeViewSearch"),
"changed",
G_CALLBACK (entry_tree_view_search_changed),
NULL);
-
/* Fill Values in cb_manual_search_in */
cb_manual_search_in = GTK_WIDGET (gtk_builder_get_object (builder,
"cbManualSearchIn"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]