[easytag/wip/musicbrainz-support-merge: 21/71] Enable Stop Button only during searching



commit ab2fb094e224d3b95bd21fc8d4b566011fbe7138
Author: Abhinav <abhijangda hotmail com>
Date:   Tue Jun 24 21:30:08 2014 +0530

    Enable Stop Button only during searching
    
    Changed GtkBox to GtkToolBar
    Added Stop button
    Implemented et_music_brainz_dialog_set_stop_sensitive and used it in callbacks of a search

 data/musicbrainz_dialog.ui |  145 ++++++++++++++-----------------------------
 src/mbentityview.c         |   12 +---
 src/musicbrainz_dialog.c   |   43 ++++++++-----
 src/musicbrainz_dialog.h   |    2 +
 4 files changed, 78 insertions(+), 124 deletions(-)
---
diff --git a/data/musicbrainz_dialog.ui b/data/musicbrainz_dialog.ui
index 7531e14..99caa04 100644
--- a/data/musicbrainz_dialog.ui
+++ b/data/musicbrainz_dialog.ui
@@ -6,41 +6,16 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-find</property>
   </object>
-  <object class="GtkImage" id="img_invert_selection">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">easytag-invert-selection</property>
-  </object>
-  <object class="GtkImage" id="img_red_lines">
-    <property name="visible">True</property>
-    <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="GtkImage" id="image10">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="stock">gtk-find</property>
   </object>
-  <object class="GtkImage" id="image11">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-stop</property>
-  </object>
   <object class="GtkImage" id="image12">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="stock">gtk-find</property>
   </object>
-  <object class="GtkImage" id="image13">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-stop</property>
-  </object>
   <object class="GtkImage" id="image14">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -52,10 +27,20 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-find</property>
   </object>
-  <object class="GtkImage" id="image9">
+  <object class="GtkImage" id="img_invert_selection">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">easytag-invert-selection</property>
+  </object>
+  <object class="GtkImage" id="img_red_lines">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">gtk-stop</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>
@@ -66,21 +51,6 @@
       <object class="GtkBox" id="dialog-vbox1">
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <placeholder/>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkBox" id="box1">
             <property name="visible">True</property>
@@ -154,18 +124,7 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkButton" id="btnAutomaticStop">
-                                    <property name="visible">True</property>
-                                    <property name="sensitive">False</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="receives_default">True</property>
-                                    <property name="image">image9</property>
-                                  </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="position">4</property>
-                                  </packing>
+                                  <placeholder/>
                                 </child>
                               </object>
                             </child>
@@ -299,19 +258,7 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkButton" id="btnManualStop">
-                                <property name="visible">True</property>
-                                <property name="sensitive">False</property>
-                                <property name="can_focus">True</property>
-                                <property name="receives_default">True</property>
-                                <property name="tooltip_text" translatable="yes">Stop Manual 
Search</property>
-                                <property name="image">stopimage</property>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                                <property name="position">5</property>
-                              </packing>
+                              <placeholder/>
                             </child>
                           </object>
                         </child>
@@ -363,6 +310,9 @@
                           </packing>
                         </child>
                         <child>
+                          <placeholder/>
+                        </child>
+                        <child>
                           <object class="GtkButton" id="btnSelectedFind">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
@@ -376,20 +326,6 @@
                             <property name="position">3</property>
                           </packing>
                         </child>
-                        <child>
-                          <object class="GtkButton" id="btnSelectedStop">
-                            <property name="visible">True</property>
-                            <property name="sensitive">False</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="image">image11</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">4</property>
-                          </packing>
-                        </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>
@@ -454,18 +390,7 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkButton" id="btnDiscStop">
-                            <property name="visible">True</property>
-                            <property name="sensitive">False</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="image">image13</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">2</property>
-                          </packing>
+                          <placeholder/>
                         </child>
                       </object>
                       <packing>
@@ -666,6 +591,20 @@
                                 <property name="homogeneous">True</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkToolButton" id="btnStop">
+                                <property name="visible">True</property>
+                                <property name="sensitive">False</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">toolbutton3</property>
+                                <property name="use_underline">True</property>
+                                <property name="stock_id">gtk-cancel</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="homogeneous">True</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="expand">False</property>
@@ -763,14 +702,24 @@
             <property name="position">1</property>
           </packing>
         </child>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
       </object>
     </child>
   </object>
-  <object class="GtkImage" id="stopimage">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-stop</property>
-  </object>
   <object class="GtkTreeStore" id="treestore1">
     <columns>
       <!-- column-name Entities -->
diff --git a/src/mbentityview.c b/src/mbentityview.c
index f8a5a76..c9ec5ac 100644
--- a/src/mbentityview.c
+++ b/src/mbentityview.c
@@ -115,10 +115,6 @@ typedef struct
  * Prototypes *
  **************/
 
-static void
-et_mb_entity_view_class_init (EtMbEntityViewClass *klass);
-static void
-et_mb_entity_view_init (EtMbEntityView *proj_notebook);
 static GtkWidget *
 insert_togglebtn_in_breadcrumb (GtkBox *breadCrumb);
 static void
@@ -510,14 +506,8 @@ show_data_in_entity_view (EtMbEntityView *entity_view)
 
     /* Setting the colour column */
     types [total_cols] = G_TYPE_STRING;
-    //if (priv->list_store == NULL)
     priv->list_store = GTK_TREE_MODEL (gtk_list_store_newv (total_cols + 1,
                                                             types));
-    /*else FIXME:
-    {
-        gtk_list_store_clear (GTK_LIST_STORE (priv->list_store));
-        gtk_list_store_set_column_types (GTK_LIST_STORE (priv->list_store), total_cols + 1, types);
-    }*/
     priv->filter = GTK_TREE_MODEL (gtk_tree_model_filter_new (priv->list_store,
                                                               NULL));
     gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter),
@@ -647,6 +637,7 @@ search_in_levels_callback (GObject *source, GAsyncResult *res,
     }
 
     g_free (thread_data);
+    et_music_brainz_dialog_stop_set_sensitive (FALSE);
 }
 
 /*
@@ -803,6 +794,7 @@ tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
     g_simple_async_result_run_in_thread (async_result,
                                          search_in_levels_thread_func,
                                          0, mb5_search_cancellable);
+    et_music_brainz_dialog_stop_set_sensitive (TRUE);
 }
 
 /*
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index fb26b8c..d129ff8 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -103,6 +103,7 @@ manual_search_callback (GObject *source, GAsyncResult *res,
                                                             "cbManualSearch"));
     gtk_combo_box_text_append_text (combo_box,
                                     gtk_combo_box_text_get_active_text (combo_box));
+    et_music_brainz_dialog_stop_set_sensitive (FALSE);
 }
 
 /*
@@ -164,6 +165,7 @@ mb5_search_error_callback (GObject *source, GAsyncResult *res,
     gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder,
                                        "statusbar")), 0, dest->message);
     g_error_free (dest);
+    et_music_brainz_dialog_stop_set_sensitive (FALSE);
 }
 
 /*
@@ -281,6 +283,7 @@ btn_manual_find_clicked (GtkWidget *btn, gpointer user_data)
     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);
 }
 
 /*
@@ -432,6 +435,7 @@ selected_find_callback (GObject *source, GAsyncResult *res,
     g_object_unref (res);
     g_object_unref (((SelectedFindThreadData *)user_data)->hash_table);
     g_free (user_data);
+    et_music_brainz_dialog_stop_set_sensitive (FALSE);
 }
 
 static void
@@ -525,7 +529,12 @@ bt_selected_find_clicked (GtkWidget *widget, gpointer user_data)
     {
         GtkTreeIter current_iter;
 
-        gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree_model), &current_iter);
+        if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree_model),
+                                           &current_iter))
+        {
+            /* No row is present, return */
+            return;
+        }
 
         do
         {
@@ -570,6 +579,7 @@ bt_selected_find_clicked (GtkWidget *widget, gpointer user_data)
                                          mb5_search_cancellable);
     gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
                         0, _("Starting Selected Files Search"));
+    et_music_brainz_dialog_stop_set_sensitive (TRUE);
 }
 
 static void
@@ -590,6 +600,7 @@ discid_search_callback (GObject *source, GAsyncResult *res,
                         0, _("Searching Completed"));
     g_object_unref (res);
     g_free (user_data);
+    et_music_brainz_dialog_stop_set_sensitive (FALSE);
 }
 
 static void
@@ -654,21 +665,27 @@ btn_discid_search (GtkWidget *button, gpointer data)
     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, discid_search_callback,
-                                              NULL,
-                                              btn_manual_find_clicked);
+    mb_dialog_priv->async_result = g_simple_async_result_new (NULL, 
+                                                              discid_search_callback,
+                                                              NULL,
+                                                              btn_manual_find_clicked);
     g_simple_async_result_run_in_thread (mb_dialog_priv->async_result,
                                          discid_search_thread_func, 0,
                                          mb5_search_cancellable);
+    et_music_brainz_dialog_stop_set_sensitive (TRUE);
 }
 
 static void
 btn_close_clicked (GtkWidget *button, gpointer data)
 {
-    gtk_widget_destroy (mbDialog);
-    g_object_unref (G_OBJECT (builder));
-    free_mb_tree (mb_dialog_priv->mb_tree_root);
-    g_free (mb_dialog_priv);
+    gtk_dialog_response (GTK_DIALOG (mbDialog), GTK_RESPONSE_DELETE_EVENT);
+}
+
+void
+et_music_brainz_dialog_stop_set_sensitive (gboolean sensitive)
+{
+    gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (builder, "btnStop")),
+                              sensitive);
 }
 
 /*
@@ -702,7 +719,7 @@ et_open_musicbrainz_dialog ()
     mb_dialog_priv->mb_tree_root = g_node_new (NULL);
     entityView = et_mb_entity_view_new ();
     mbDialog = GTK_WIDGET (gtk_builder_get_object (builder, "mbDialog"));
-    gtk_widget_set_size_request (mbDialog, 600, 500);
+    gtk_widget_set_size_request (mbDialog, 660, 500);
     gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "centralBox")),
                         entityView, TRUE, TRUE, 2);
 
@@ -712,9 +729,6 @@ 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);
     g_signal_connect (gtk_builder_get_object (builder, "toolbtnUp"),
                       "clicked", G_CALLBACK (tool_btn_up_clicked),
                       NULL);
@@ -739,13 +753,10 @@ et_open_musicbrainz_dialog ()
     g_signal_connect (gtk_builder_get_object (builder, "btnSelectedFind"),
                       "clicked", G_CALLBACK (bt_selected_find_clicked),
                       NULL);
-    g_signal_connect (gtk_builder_get_object (builder, "btnSelectedStop"),
-                      "clicked", G_CALLBACK (btn_manual_stop_clicked),
-                      NULL);
     g_signal_connect (gtk_builder_get_object (builder, "btnDiscFind"),
                       "clicked", G_CALLBACK (btn_discid_search),
                       NULL);
-    g_signal_connect (gtk_builder_get_object (builder, "btnDiscStop"),
+    g_signal_connect (gtk_builder_get_object (builder, "btnStop"),
                       "clicked", G_CALLBACK (btn_manual_stop_clicked),
                       NULL);
     g_signal_connect (gtk_builder_get_object (builder, "btnClose"),
diff --git a/src/musicbrainz_dialog.h b/src/musicbrainz_dialog.h
index 0b8e290..1f17f54 100644
--- a/src/musicbrainz_dialog.h
+++ b/src/musicbrainz_dialog.h
@@ -44,5 +44,7 @@ mb5_search_error_callback (GObject *source, GAsyncResult *res,
                            gpointer user_data);
 void
 et_show_status_msg_in_idle (gchar *message);
+void
+et_music_brainz_dialog_stop_set_sensitive (gboolean sensitive);
 #endif /* __MUSICBRAINZ_DIALOG_H__ */
 #endif /* ENABLE_MUSICBRAINZ */


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