[easytag/wip/musicbrainz-support-merge: 3/51] Refined MusicBrainz UI & Selected Files Search



commit 5165ed9405d1f07e492321be3f22d070ad0fed6b
Author: Abhinav <abhijangda hotmail com>
Date:   Fri Aug 22 18:43:58 2014 +0530

    Refined MusicBrainz UI & Selected Files Search
    
    Removed Tabs from MusicBrainz UI and added simple buttons
    Changed Selected Files Search to search for 1 Album only

 data/musicbrainz_dialog.ui |  400 +++++++++-----------------------------------
 src/musicbrainz_dialog.c   |  304 +++++++++++++++++++---------------
 2 files changed, 245 insertions(+), 459 deletions(-)
---
diff --git a/data/musicbrainz_dialog.ui b/data/musicbrainz_dialog.ui
index 99caa04..053076a 100644
--- a/data/musicbrainz_dialog.ui
+++ b/data/musicbrainz_dialog.ui
@@ -6,42 +6,21 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-find</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="image12">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="stock">gtk-find</property>
-  </object>
-  <object class="GtkImage" id="image14">
+  <object class="GtkImage" id="img_red_lines">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">gtk-missing-image</property>
-    <property name="icon-size">5</property>
+    <property name="stock">easytag-red-lines</property>
   </object>
-  <object class="GtkImage" id="image8">
+  <object class="GtkImage" id="img_unselect_all">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">gtk-find</property>
+    <property name="stock">easytag-unselect-all</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="GtkDialog" id="mbDialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -58,370 +37,143 @@
             <property name="orientation">vertical</property>
             <property name="spacing">1</property>
             <child>
-              <object class="GtkNotebook" id="notebook1">
+              <object class="GtkBox" id="box7">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">2</property>
                 <child>
-                  <object class="GtkVBox" id="vbox1">
+                  <object class="GtkHBox" id="hbox3">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
+                    <property name="spacing">5</property>
                     <child>
-                      <object class="GtkFrame" id="frame1">
+                      <object class="GtkLabel" id="label7">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="label_xalign">0</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkAlignment" id="alignment1">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="top_padding">2</property>
-                            <property name="left_padding">12</property>
-                            <child>
-                              <object class="GtkHBox" id="hbox1">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="spacing">5</property>
-                                <child>
-                                  <object class="GtkLabel" id="label4">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="label" translatable="yes">Search:</property>
-                                  </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="position">0</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkComboBoxText" id="cbAutomaticSearch">
-                                    <property name="width_request">240</property>
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="entry_text_column">0</property>
-                                    <property name="id_column">1</property>
-                                  </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="padding">4</property>
-                                    <property name="position">1</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkButton" id="btnAutomaticFind">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="receives_default">True</property>
-                                    <property name="image">image8</property>
-                                    <property name="image_position">top</property>
-                                  </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="position">2</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
-                        <child type="label">
-                          <object class="GtkLabel" id="label5">
+                        <property name="label" translatable="yes">Search:</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBoxText" id="cbManualSearch">
+                        <property name="width_request">190</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="has_entry">True</property>
+                        <property name="entry_text_column">0</property>
+                        <property name="id_column">1</property>
+                        <child internal-child="entry">
+                          <object class="GtkEntry" id="comboboxtext-entry">
                             <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="label" translatable="yes">Automatic Search in MusicBrainz 
Database</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">●</property>
                           </object>
                         </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
-                        <property name="position">0</property>
+                        <property name="padding">4</property>
+                        <property name="position">1</property>
                       </packing>
                     </child>
-                  </object>
-                </child>
-                <child type="tab">
-                  <object class="GtkLabel" id="label1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="label" translatable="yes">Automatic Search</property>
-                  </object>
-                  <packing>
-                    <property name="tab_fill">False</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkBox" id="box7">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="orientation">vertical</property>
                     <child>
-                      <object class="GtkLabel" id="label6">
+                      <object class="GtkLabel" id="label14">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">0.0099999997764825821</property>
-                        <property name="label" translatable="yes">Manually Search MusicBrainz 
Database</property>
+                        <property name="label" translatable="yes">Through:</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">True</property>
-                        <property name="position">0</property>
+                        <property name="position">2</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkAlignment" id="alignment3">
+                      <object class="GtkComboBoxText" id="cbManualSearchIn">
+                        <property name="width_request">110</property>
+                        <property name="height_request">26</property>
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="top_padding">3</property>
-                        <property name="left_padding">12</property>
-                        <child>
-                          <object class="GtkHBox" id="hbox3">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="spacing">5</property>
-                            <child>
-                              <object class="GtkLabel" id="label7">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">Search:</property>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                                <property name="position">0</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkComboBoxText" id="cbManualSearch">
-                                <property name="width_request">240</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="has_entry">True</property>
-                                <property name="entry_text_column">0</property>
-                                <property name="id_column">1</property>
-                                <child internal-child="entry">
-                                  <object class="GtkEntry" id="combobox-entry">
-                                    <property name="can_focus">True</property>
-                                  </object>
-                                </child>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                                <property name="padding">4</property>
-                                <property name="position">1</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkLabel" id="label14">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">Through:</property>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">True</property>
-                                <property name="position">2</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkComboBoxText" id="cbManualSearchIn">
-                                <property name="width_request">120</property>
-                                <property name="height_request">26</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                                <property name="position">3</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkButton" id="btnManualFind">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="receives_default">True</property>
-                                <property name="tooltip_text" translatable="yes">Start Manual Search 
</property>
-                                <property name="image">findimage</property>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                                <property name="position">4</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <placeholder/>
-                            </child>
-                          </object>
-                        </child>
+                        <property name="entry_text_column">0</property>
+                        <property name="id_column">1</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
+                        <property name="fill">False</property>
+                        <property name="position">3</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="btnManualFind">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="has_tooltip">True</property>
+                        <property name="tooltip_markup" translatable="yes">Start Manual Search </property>
+                        <property name="tooltip_text" translatable="yes">Start Manual Search </property>
+                        <property name="image">findimage</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">4</property>
                       </packing>
                     </child>
                   </object>
                   <packing>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-                <child type="tab">
-                  <object class="GtkLabel" id="label13">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_right">1</property>
-                    <property name="label" translatable="yes">Manual Search</property>
-                  </object>
-                  <packing>
-                    <property name="position">1</property>
-                    <property name="tab_fill">False</property>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkBox" id="box3">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="orientation">vertical</property>
+                    <property name="spacing">4</property>
                     <child>
-                      <object class="GtkBox" id="box6">
+                      <object class="GtkButton" id="btnSelectedFind">
+                        <property name="label" translatable="yes">Search Selected Find</property>
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="spacing">5</property>
-                        <child>
-                          <object class="GtkLabel" id="label2">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes"> Scan Selected Files from MusicBrainz 
Database based on their album:</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">True</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <placeholder/>
-                        </child>
-                        <child>
-                          <object class="GtkButton" id="btnSelectedFind">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="image">image10</property>
-                            <property name="image_position">right</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">3</property>
-                          </packing>
-                        </child>
+                        <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="padding">4</property>
+                        <property name="fill">True</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
-                  </object>
-                  <packing>
-                    <property name="position">2</property>
-                    <property name="tab_fill">False</property>
-                  </packing>
-                </child>
-                <child type="tab">
-                  <object class="GtkLabel" id="label10">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_left">1</property>
-                    <property name="label" translatable="yes">Scan Selected Files</property>
-                  </object>
-                  <packing>
-                    <property name="position">2</property>
-                    <property name="tab_fill">False</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkBox" id="box4">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="orientation">vertical</property>
-                    <property name="spacing">1</property>
                     <child>
-                      <object class="GtkBox" id="box5">
+                      <object class="GtkButton" id="btnDiscFind">
+                        <property name="label" translatable="yes">DiscID Search</property>
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="spacing">3</property>
-                        <child>
-                          <object class="GtkLabel" id="label12">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">0.019999999552965164</property>
-                            <property name="label" translatable="yes"> Insert Disc into Disc Drive to search 
into MusicBrainz Data Base with DiscID: </property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkButton" id="btnDiscFind">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="image">image12</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <placeholder/>
-                        </child>
+                        <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="padding">4</property>
-                        <property name="position">0</property>
+                        <property name="position">2</property>
                       </packing>
                     </child>
                   </object>
                   <packing>
-                    <property name="position">3</property>
-                    <property name="tab_fill">False</property>
-                  </packing>
-                </child>
-                <child type="tab">
-                  <object class="GtkLabel" id="label9">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="label" translatable="yes">Disc Lookup</property>
-                  </object>
-                  <packing>
-                    <property name="position">3</property>
-                    <property name="tab_fill">False</property>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">2</property>
                   </packing>
                 </child>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="padding">1</property>
                 <property name="position">0</property>
               </packing>
             </child>
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index f58842e..6528173 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -38,7 +38,8 @@
 /***************
  * Declaration *
  ***************/
-//static GSimpleAsyncResult *async_result;
+static void
+get_first_selected_file (ET_File  **et_file);
 
 typedef struct
 {
@@ -48,10 +49,6 @@ typedef struct
 
 static MusicBrainzDialogPrivate *mb_dialog_priv;
 
-typedef struct
-{
-    GHashTable *hash_table;
-} SelectedFindThreadData;
 /*
  * ManualSearchThreadData:
  * @text_to_search: Manual Search Text
@@ -432,90 +429,63 @@ entry_tree_view_search_changed (GtkEditable *editable, gpointer user_data)
 }
 
 static void
-selected_find_callback (GObject *source, GAsyncResult *res,
-                        gpointer user_data)
+bt_selected_find_clicked (GtkWidget *widget, gpointer user_data)
 {
-    if (!g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res)))
+    ET_File *et_file;
+    File_Tag *file_tag;
+    GtkWidget *cb_manual_search;
+    GtkWidget *cb_manual_search_in;
+    GtkWidget *entry;
+    int type;
+
+    et_file = NULL;
+    get_first_selected_file (&et_file);
+
+    if (!et_file)
     {
-        g_object_unref (res);
-        g_object_unref (((SelectedFindThreadData *)user_data)->hash_table);
-        g_free (user_data);
-        free_mb_tree (mb_dialog_priv->mb_tree_root);
-        mb_dialog_priv->mb_tree_root = g_node_new (NULL);
+        gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                        0, _("No File Selected."));
         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_object_unref (((SelectedFindThreadData *)user_data)->hash_table);
-    g_free (user_data);
-    et_music_brainz_dialog_stop_set_sensitive (FALSE);
+    file_tag = (File_Tag *)et_file->FileTag->data;
+    cb_manual_search_in = GTK_WIDGET (gtk_builder_get_object (builder,
+                                                              "cbManualSearchIn"));
+    type = gtk_combo_box_get_active (GTK_COMBO_BOX (cb_manual_search_in));
 
-    if (exit_on_complete)
+    if (type == -1)
     {
-        btn_close_clicked (NULL, NULL);
+        return;
     }
-}
-
-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);
+    cb_manual_search = GTK_WIDGET (gtk_builder_get_object (builder,
+                                                           "cbManualSearch"));
+    entry = gtk_bin_get_child (GTK_BIN (cb_manual_search));
 
-    while (iter)
+    if (type == MB_ENTITY_KIND_ARTIST)
     {
-        if (!et_musicbrainz_search ((gchar *)iter->data, MB_ENTITY_KIND_ALBUM,
-                                    mb_dialog_priv->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;
-        }
-
-        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;
-        }
-
-        iter = g_list_next (iter);
+        gtk_entry_set_text (GTK_ENTRY (entry), file_tag->artist);
+    }
+    else if (type == MB_ENTITY_KIND_ALBUM)
+    {
+        gtk_entry_set_text (GTK_ENTRY (entry), file_tag->album);
+    }
+    else if (type == MB_ENTITY_KIND_TRACK)
+    {
+        gtk_entry_set_text (GTK_ENTRY (entry), file_tag->title);
     }
 
-    g_list_free (list_keys);
-    g_simple_async_result_set_op_res_gboolean (res, TRUE);
+    btn_manual_find_clicked (NULL, NULL);
 }
 
 static void
-bt_selected_find_clicked (GtkWidget *widget, gpointer user_data)
+get_first_selected_file (ET_File  **et_file)
 {
     GtkListStore *tree_model;
     GtkTreeSelection *selection;
     int count;
     GList *iter_list;
     GList *l;
-    GHashTable *hash_table;
-    SelectedFindThreadData *thread_data;
     GtkTreeView *browser_list;
 
     selection = et_application_window_browser_get_selection (ET_APPLICATION_WINDOW (MainWindow));
@@ -523,85 +493,25 @@ bt_selected_find_clicked (GtkWidget *widget, gpointer user_data)
     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;
 
     if (count > 0)
     {
         GList* list_sel_rows;
+        GtkTreeIter iter;
 
         list_sel_rows = gtk_tree_selection_get_selected_rows(selection, NULL);
-
-        for (l = list_sel_rows; l != NULL; l = g_list_next (l))
+        if (gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_model),
+                                    &iter,
+                                    (GtkTreePath *)list_sel_rows->data))
         {
-            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));
-            }
+            *et_file = et_application_window_browser_get_et_file_from_iter (ET_APPLICATION_WINDOW 
(MainWindow),
+                                                                            &iter);
         }
 
         g_list_free_full (list_sel_rows,
                           (GDestroyNotify)gtk_tree_path_free);
-
-    }
-    else /* No rows selected, use the whole list */
-    {
-        GtkTreeIter current_iter;
-
-        if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree_model),
-                                           &current_iter))
-        {
-            /* No row is present, return */
-            return;
-        }
-
-        do
-        {
-            iter_list = g_list_prepend (iter_list,
-                                        gtk_tree_iter_copy (&current_iter));
-        }
-        while (gtk_tree_model_iter_next(GTK_TREE_MODEL(tree_model),
-               &current_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 = et_application_window_browser_get_et_file_from_iter (ET_APPLICATION_WINDOW (MainWindow),
-                                                                      (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 ();
-    mb_dialog_priv->async_result = g_simple_async_result_new (NULL,
-                                                              selected_find_callback,
-                                                              thread_data,
-                                                              bt_selected_find_clicked);
-    g_simple_async_result_run_in_thread (mb_dialog_priv->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_music_brainz_dialog_stop_set_sensitive (TRUE);
 }
 
 static void
@@ -708,6 +618,126 @@ btn_close_clicked (GtkWidget *button, gpointer data)
     gtk_dialog_response (GTK_DIALOG (mbDialog), GTK_RESPONSE_DELETE_EVENT);
 }
 
+#if 0
+static void
+btn_automatic_search_clicked (GtkWidget *button, gpointer data)
+{
+    GtkListStore *tree_model;
+    GtkTreeSelection *selection;
+    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;
+
+    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;
+
+        if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree_model),
+                                           &current_iter))
+        {
+            /* No row is present, return */
+            gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                                0, _("No file selected"));
+            return;
+        }
+
+        do
+        {
+            iter_list = g_list_prepend (iter_list,
+                                        gtk_tree_iter_copy (&current_iter));
+        }
+        while (gtk_tree_model_iter_next(GTK_TREE_MODEL(tree_model),
+               &current_iter));
+
+        count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(tree_model),
+                                               NULL);
+    }
+
+    if (count == 0)
+    {
+        gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                            0, _("No file selected"));
+        return;
+    }
+
+    else if (count > 99)
+    {
+        gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                            0, _("More than 99 files selected. Cannot send the request."));
+        return;
+    }
+
+    else
+    {
+        gchar *msg;
+        msg = g_strdup_printf (ngettext (_("One file selected"),
+                                         _("%d files selected"), count), count);
+        gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                            0, msg);
+        g_free (msg);
+    }
+
+    /* Compute Discid from list */
+    total_id = 0;
+    num_tracks = count;
+
+    for (l = iter_list; l != NULL; l = g_list_next (l))
+    {
+        ET_File *etfile;
+        gulong secs = 0;
+
+        etfile = Browser_List_Get_ETFile_From_Iter ((GtkTreeIter *)l->data);
+        secs = etfile->ETFileInfo->duration;
+        total_frames += secs * 75;
+        disc_length  += secs;
+        while (secs > 0)
+        {
+            total_id = total_id + (secs % 10);
+            secs = secs / 10;
+        }
+    }
+
+    cddb_discid = g_strdup_printf("%08x",(guint)(((total_id % 0xFF) << 24) |
+                                         (disc_length << 8) | num_tracks));
+}
+#endif
+
 void
 et_music_brainz_dialog_stop_set_sensitive (gboolean sensitive)
 {
@@ -715,6 +745,7 @@ et_music_brainz_dialog_stop_set_sensitive (gboolean sensitive)
                               sensitive);
 }
 
+/* FIXME: Pressing Escape while there is a search gives error */
 static gboolean
 et_music_brainz_dialog_delete_event (GtkWidget *widget, GdkEvent *event,
                                      gpointer data)
@@ -770,7 +801,7 @@ et_open_musicbrainz_dialog ()
     gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "centralBox")),
                         entityView, TRUE, TRUE, 2);
 
-    g_signal_connect (mbDialog, "delete-event", G_CALLBACK (et_music_brainz_dialog_delete_event), NULL);
+    //g_signal_connect (mbDialog, "delete-event", G_CALLBACK (et_music_brainz_dialog_delete_event), NULL);
     cb_search = GTK_WIDGET (gtk_builder_get_object (builder, "cbManualSearch"));
     g_signal_connect (gtk_bin_get_child (GTK_BIN (cb_search)), "activate",
                       G_CALLBACK (btn_manual_find_clicked), NULL);
@@ -810,6 +841,9 @@ et_open_musicbrainz_dialog ()
     g_signal_connect (gtk_builder_get_object (builder, "btnClose"),
                       "clicked", G_CALLBACK (btn_close_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]