[easytag/wip/musicbrainz-support] Added Statusbar Messages in Manual Search



commit 4d9a90ebe52ec66415d4db71ac6ae56737521f81
Author: Abhinav <abhijangda hotmail com>
Date:   Sun May 18 20:45:50 2014 +0530

    Added Statusbar Messages in Manual Search

 src/mb_search.h          |    2 +-
 src/mbentityview.c       |   21 ++++++++++++++++++-
 src/musicbrainz_dialog.c |   47 +++++++++++++++++++++++++++++++++++++++++++--
 src/musicbrainz_dialog.h |    4 ++-
 4 files changed, 67 insertions(+), 7 deletions(-)
---
diff --git a/src/mb_search.h b/src/mb_search.h
index 17b8dfc..f91d920 100644
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -31,7 +31,7 @@
  * Declarations *
  ****************/
 
-GCancellable *cancellable;
+GCancellable *mb5_search_cancellable;
 
 /*
  * Error domain and codes for errors while reading/writing Opus files
diff --git a/src/mbentityview.c b/src/mbentityview.c
index effa913..1cc4390 100644
--- a/src/mbentityview.c
+++ b/src/mbentityview.c
@@ -426,6 +426,8 @@ search_in_levels_callback (GObject *source, GAsyncResult *res,
     gtk_button_set_label (GTK_BUTTON (toggle_btn), entity_name);
     gtk_widget_show_all (GTK_WIDGET (priv->bread_crumb_box));
     show_data_in_entity_view (entity_view);
+    gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                        0, "Retrieving Completed");
     g_object_unref (res);
     g_free (thread_data);
 }
@@ -437,7 +439,11 @@ search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
     SearchInLevelThreadData *thread_data;
     gchar mbid [NAME_MAX_SIZE];
     GError *error;
+    gchar *status_msg;
+    gchar parent_entity_str [NAME_MAX_SIZE];
+    gchar *child_entity_type_str;
 
+    child_entity_type_str = NULL;
     thread_data = g_async_result_get_user_data (G_ASYNC_RESULT (res));
 
     if (((EtMbEntity *)thread_data->child->data)->type ==
@@ -448,17 +454,28 @@ search_in_levels_thread_func (GSimpleAsyncResult *res, GObject *obj,
     else if (((EtMbEntity *)thread_data->child->data)->type ==
              MB_ENTITY_TYPE_ARTIST)
     {
+        child_entity_type_str = g_strdup ("Albums ");
         mb5_artist_get_id (((EtMbEntity *)thread_data->child->data)->entity,
                            mbid, sizeof (mbid));
+        mb5_artist_get_name (((EtMbEntity *)thread_data->child->data)->entity,
+                             parent_entity_str, sizeof (parent_entity_str));
     }
     else if (((EtMbEntity *)thread_data->child->data)->type ==
              MB_ENTITY_TYPE_ALBUM)
     {
+        child_entity_type_str = g_strdup ("Tracks ");
         mb5_release_get_id (((EtMbEntity *)thread_data->child->data)->entity,
                             mbid, sizeof (mbid));
+        mb5_release_get_title (((EtMbEntity *)thread_data->child->data)->entity,
+                               parent_entity_str, sizeof (parent_entity_str));
     }
 
     error = NULL;
+    status_msg = g_strconcat ("Retrieving ", child_entity_type_str, "for ",
+                              parent_entity_str, NULL);
+    et_show_status_msg_in_idle (status_msg);
+    g_free (status_msg);
+    g_free (child_entity_type_str);
 
     if (!et_musicbrainz_search_in_entity (((EtMbEntity *)thread_data->child->data)->type + 1,
                                           ((EtMbEntity *)thread_data->child->data)->type,
@@ -484,7 +501,6 @@ tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
                          GtkTreeViewColumn *column, gpointer user_data)
 {
     /* TODO: Add Cancellable object */
-    /* TODO: Display Status Bar messages */
     SearchInLevelThreadData *thread_data;
     EtMbEntityView *entity_view;
     EtMbEntityViewPrivate *priv;
@@ -501,7 +517,8 @@ tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
     thread_data->entity_view = ET_MB_ENTITY_VIEW (user_data);
     thread_data->child = child;
     gtk_tree_model_get_iter (priv->list_store, &thread_data->iter, path);
-
+    gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                        0, "Starting MusicBrainz Search");
     async_result = g_simple_async_result_new (NULL,
                                               search_in_levels_callback,
                                               thread_data,
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 08a25e3..8daa722 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -61,10 +61,34 @@ manual_search_callback (GObject *source, GAsyncResult *res,
 {
     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_free (user_data);
 }
 
+static void
+et_show_status_msg_in_idle_cb (GObject *obj, GAsyncResult *res,
+                               gpointer user_data)
+{
+    gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                        0, user_data);
+    g_free (user_data);
+    g_object_unref (res);
+}
+
+void
+et_show_status_msg_in_idle (gchar *message)
+{
+    GSimpleAsyncResult *async_res;
+
+    async_res = g_simple_async_result_new (NULL,
+                                           et_show_status_msg_in_idle_cb,
+                                           g_strdup (message),
+                                           et_show_status_msg_in_idle);
+    g_simple_async_result_complete_in_idle (async_res);
+}
+
 void
 mb5_search_error_callback (GObject *source, GAsyncResult *res,
                            gpointer user_data)
@@ -95,9 +119,13 @@ manual_search_thread_func (GSimpleAsyncResult *res, GObject *obj,
 {
     GError *error;
     ManualSearchThreadData *thread_data;
+    gchar *status_msg;
 
     error = NULL;
     thread_data = (ManualSearchThreadData *)g_async_result_get_user_data (G_ASYNC_RESULT (res));
+    status_msg = g_strconcat ("Searching ", thread_data->text_to_search, NULL);
+    et_show_status_msg_in_idle (status_msg);
+    g_free (status_msg);
 
     if (!et_musicbrainz_search (thread_data->text_to_search,
                                 thread_data->type, mb_tree_root, &error))
@@ -137,14 +165,22 @@ btn_manual_find_clicked (GtkWidget *btn, gpointer user_data)
     thread_data = g_malloc (sizeof (ManualSearchThreadData));
     thread_data->type = type;
     thread_data->text_to_search = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (cb_manual_search));
-    cancellable = g_cancellable_new ();
+    mb5_search_cancellable = g_cancellable_new ();
     /* TODO: Add Cancellable object */
-    /* TODO: Display Status Bar messages */
+    gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                        0, "Starting MusicBrainz Search");
     async_result = g_simple_async_result_new (NULL, manual_search_callback, 
                                               thread_data,
                                               btn_manual_find_clicked);
     g_simple_async_result_run_in_thread (async_result,
-                                         manual_search_thread_func, 0, NULL);
+                                         manual_search_thread_func, 0,
+                                         mb5_search_cancellable);
+}
+
+static void
+btn_manual_stop_clicked (GtkWidget *btn, gpointer user_data)
+{
+    g_cancellable_cancel (mb5_search_cancellable);
 }
 
 /*
@@ -184,6 +220,11 @@ et_open_musicbrainz_dialog ()
     g_signal_connect (gtk_builder_get_object (builder, "btnManualFind"),
                       "clicked", G_CALLBACK (btn_manual_find_clicked),
                       NULL);
+    g_signal_connect (gtk_builder_get_object (builder, "btnManualStop"),
+                      "clicked", G_CALLBACK (btn_manual_stop_clicked),
+                      NULL);
+
+    /* Fill Values in cb_manual_search_in */
     cb_manual_search_in = GTK_WIDGET (gtk_builder_get_object (builder,
                                                               "cbManualSearchIn"));
 
diff --git a/src/musicbrainz_dialog.h b/src/musicbrainz_dialog.h
index 653680e..ed5f02f 100644
--- a/src/musicbrainz_dialog.h
+++ b/src/musicbrainz_dialog.h
@@ -38,4 +38,6 @@ et_open_musicbrainz_dialog (void);
 void
 mb5_search_error_callback (GObject *source, GAsyncResult *res,
                            gpointer user_data);
-#endif /* __MUSICBRAINZ_DIALOG_H__ */
+void
+et_show_status_msg_in_idle (gchar *message);
+#endif /* __MUSICBRAINZ_DIALOG_H__ */
\ No newline at end of file


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