[easytag/wip/musicbrainz-support-merge: 2/51] Set values in EtMbEntityTreeView in one go



commit 2d2ad42cf969ef3ea2ba1180fb17bc5df6fa8b07
Author: Abhinav <abhijangda hotmail com>
Date:   Tue Jun 24 23:27:19 2014 +0530

    Set values in EtMbEntityTreeView in one go
    
    Call gtk_list_store_set just once for all columns instead of for every colum

 src/mb_search.c          |    1 -
 src/mbentityview.c       |  157 ++++++++++++++++++++++++++--------------------
 src/musicbrainz_dialog.c |   48 ++++++++++++++
 src/musicbrainz_dialog.h |    1 +
 4 files changed, 139 insertions(+), 68 deletions(-)
---
diff --git a/src/mb_search.c b/src/mb_search.c
index b29321f..c59a362 100644
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -238,7 +238,6 @@ et_musicbrainz_search_in_entity (MbEntityKind child_type,
                         {
                             Mb5Recording recording;
 
-
                             if (g_cancellable_is_cancelled (cancellable))
                             {
                                 g_set_error (error, ET_MB5_SEARCH_ERROR,
diff --git a/src/mbentityview.c b/src/mbentityview.c
index c9ec5ac..e2b4467 100644
--- a/src/mbentityview.c
+++ b/src/mbentityview.c
@@ -258,9 +258,7 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
     int i;
     int minutes;
     int seconds;
-    GString *gstring;
     GtkTreeIter iter;
-    gchar name [NAME_MAX_SIZE];
 
     type = ((EtMbEntity *)node->data)->type;
     while (node)
@@ -272,49 +270,59 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
         switch (type)
         {
             case MB_ENTITY_KIND_ARTIST:
-                mb5_artist_get_name ((Mb5Artist)entity, name, sizeof (name));
-                gtk_list_store_insert_with_values (list_store, &iter, -1,
-                                                   MB_ARTIST_COLUMNS_N,
-                                                   "black", -1);
-                gtk_list_store_set (list_store, &iter,
-                                    MB_ARTIST_COLUMNS_NAME, name, -1);
+            {
+                gchar gender [NAME_MAX_SIZE];
+                gchar type [NAME_MAX_SIZE];               
+                gchar name [NAME_MAX_SIZE];
 
-                mb5_artist_get_gender ((Mb5Artist)entity, name,
-                                       sizeof (name));
-                gtk_list_store_set (list_store, &iter,
-                                    MB_ARTIST_COLUMNS_GENDER, name, -1);
-
-                mb5_artist_get_type ((Mb5Artist)entity, name, sizeof (name));
-                gtk_list_store_set (list_store, &iter,
-                                    MB_ARTIST_COLUMNS_TYPE,
-                                    name, -1);
+                mb5_artist_get_name ((Mb5Artist)entity, name, sizeof (name));
+                mb5_artist_get_gender ((Mb5Artist)entity, gender,
+                                       sizeof (gender));
+                mb5_artist_get_type ((Mb5Artist)entity, type, sizeof (type));
 
                 if (((EtMbEntity *)node->data)->is_red_line)
                 {
-                    gtk_list_store_set (list_store, &iter,
-                                        MB_ARTIST_COLUMNS_N, "red", -1);
+                    gtk_list_store_insert_with_values (list_store, &iter, -1,
+                                                       MB_ARTIST_COLUMNS_NAME,
+                                                       name,
+                                                       MB_ARTIST_COLUMNS_GENDER,
+                                                       gender,
+                                                       MB_ARTIST_COLUMNS_TYPE,
+                                                       type,
+                                                       MB_ARTIST_COLUMNS_N,
+                                                       "red", -1);
                 }
                 else
                 {
-                    gtk_list_store_set (list_store, &iter,
-                                        MB_ARTIST_COLUMNS_N, "black", -1);
+                    gtk_list_store_insert_with_values (list_store, &iter, -1,
+                                                       MB_ARTIST_COLUMNS_NAME,
+                                                       name,
+                                                       MB_ARTIST_COLUMNS_GENDER,
+                                                       gender,
+                                                       MB_ARTIST_COLUMNS_TYPE,
+                                                       type,
+                                                       MB_ARTIST_COLUMNS_N,
+                                                       "black", -1);
                 }
 
                 break;
+            }
 
             case MB_ENTITY_KIND_ALBUM:
-                mb5_release_get_title ((Mb5Release)entity, name,
-                                       sizeof (name));
-                gtk_list_store_insert_with_values (list_store, &iter, -1,
-                                        MB_ALBUM_COLUMNS_N, "black", -1);
-                gtk_list_store_set (list_store, &iter,
-                                    MB_ALBUM_COLUMNS_NAME, name, -1);
+            {
+                gchar group [NAME_MAX_SIZE];
+                GString *gstring;
+                gchar name [NAME_MAX_SIZE];
 
+                release_group = mb5_release_get_releasegroup ((Mb5Release)entity);
+                mb5_releasegroup_get_primarytype (release_group, group,
+                                                  sizeof (group));
                 artist_credit = mb5_release_get_artistcredit ((Mb5Release)entity);
+                gstring = g_string_new ("");
+
                 if (artist_credit)
                 {
                     name_list = mb5_artistcredit_get_namecreditlist (artist_credit);
-                    gstring = g_string_new ("");
 
                     for (i = 0; i < mb5_namecredit_list_size (name_list); i++)
                     {
@@ -328,42 +336,51 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
                         g_string_append_len (gstring, name, size);
                         g_string_append_c (gstring, ' ');
                     }
-                    gtk_list_store_set (list_store, &iter,
-                                        MB_ALBUM_COLUMNS_ARTIST,
-                                        gstring->str, -1);
-                    g_string_free (gstring, TRUE);
                 }
 
+                mb5_release_get_title ((Mb5Release)entity, name,
+                                       sizeof (name));
+                
                 if (((EtMbEntity *)node->data)->is_red_line)
                 {
-                    gtk_list_store_set (list_store, &iter,
-                                        MB_ALBUM_COLUMNS_N, "red", -1);
+                    gtk_list_store_insert_with_values (list_store, &iter, -1,
+                                                       MB_ALBUM_COLUMNS_NAME, 
+                                                       name,
+                                                       MB_ALBUM_COLUMNS_ARTIST,
+                                                       gstring->str,
+                                                       MB_ALBUM_COLUMNS_TYPE,
+                                                       group,
+                                                       MB_ALBUM_COLUMNS_N,
+                                                       "red", -1);
                 }
                 else
                 {
-                    gtk_list_store_set (list_store, &iter,
+                    gtk_list_store_insert_with_values (list_store, &iter, -1,
+                                        MB_ALBUM_COLUMNS_NAME, name,
+                                        MB_ALBUM_COLUMNS_ARTIST,
+                                        gstring->str,
+                                        MB_ALBUM_COLUMNS_TYPE, group,
                                         MB_ALBUM_COLUMNS_N, "black", -1);
                 }
 
-                release_group = mb5_release_get_releasegroup ((Mb5Release)entity);
-                mb5_releasegroup_get_primarytype (release_group, name,
-                                                  sizeof (name));
-                gtk_list_store_set (list_store, &iter,
-                                    MB_ALBUM_COLUMNS_TYPE, name, -1);
+                g_string_free (gstring, TRUE);
+
                 break;
+            }
 
             case MB_ENTITY_KIND_TRACK:
-                mb5_recording_get_title ((Mb5Recording)entity, name,
-                                         sizeof (name));
-                gtk_list_store_append (list_store, &iter);
-                gtk_list_store_set (list_store, &iter,
-                                    MB_TRACK_COLUMNS_NAME, name, -1);
+            {
+                GString *artists;
+                GString *releases;
+                gchar name [NAME_MAX_SIZE];
+                gchar time [NAME_MAX_SIZE];
 
                 artist_credit = mb5_recording_get_artistcredit ((Mb5Release)entity);
+                artists = g_string_new ("");
+
                 if (artist_credit)
                 {
                     name_list = mb5_artistcredit_get_namecreditlist (artist_credit);
-                    gstring = g_string_new ("");
 
                     for (i = 0; i < mb5_namecredit_list_size (name_list); i++)
                     {
@@ -375,22 +392,16 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
                         name_credit_artist = mb5_namecredit_get_artist (name_credit);
                         size = mb5_artist_get_name (name_credit_artist, name,
                                                     sizeof (name));
-                        g_string_append_len (gstring, name, size);
-                        g_string_append_c (gstring, ' ');
+                        g_string_append_len (artists, name, size);
+                        g_string_append_c (artists, ' ');
                     }
-
-                    gtk_list_store_set (list_store, &iter,
-                                        MB_TRACK_COLUMNS_ARTIST,
-                                        gstring->str, -1);
-                    g_string_free (gstring, TRUE);
                 }
 
                 release_list = mb5_recording_get_releaselist ((Mb5Recording)entity);
+                releases = g_string_new ("");
 
                 if (release_list)
                 {
-                    gstring = g_string_new ("");
-
                     for (i = 0; i < mb5_release_list_size (release_list); i++)
                     {
                         Mb5Release release;
@@ -399,25 +410,31 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
                         release = mb5_release_list_item (release_list, i);
                         size = mb5_release_get_title (release, name,
                                                       sizeof (name));
-                        g_string_append_len (gstring, name, size);
-                        g_string_append_c (gstring, ' ');
+                        g_string_append_len (releases, name, size);
+                        g_string_append_c (releases, ' ');
                     }
-
-                    gtk_list_store_set (list_store, &iter,
-                                        MB_TRACK_COLUMNS_ALBUM,
-                                        gstring->str, -1);
-                    g_string_free (gstring, TRUE);
                 }
 
                 minutes = mb5_recording_get_length ((Mb5Recording)entity)/60000;
                 seconds = mb5_recording_get_length ((Mb5Recording)entity)%60000;
-                i = g_snprintf (name, NAME_MAX_SIZE, "%d:%d", minutes,
+                i = g_snprintf (time, NAME_MAX_SIZE, "%d:%d", minutes,
                                 seconds/1000);
-                name [i] = '\0';
-                gtk_list_store_set (list_store, &iter,
-                                    MB_TRACK_COLUMNS_TIME,
-                                    name, -1);
+                time [i] = '\0';
+                mb5_recording_get_title ((Mb5Recording)entity, name,
+                                         sizeof (name));
+                gtk_list_store_insert_with_values (list_store, &iter, -1,
+                                                   MB_TRACK_COLUMNS_NAME, name,
+                                                   MB_TRACK_COLUMNS_ARTIST,
+                                                   artists->str,
+                                                   MB_TRACK_COLUMNS_ALBUM,
+                                                   releases->str,
+                                                   MB_TRACK_COLUMNS_TIME,
+                                                   time, -1);
+                g_string_free (releases, TRUE);
+                g_string_free (artists, TRUE);
+
                 break;
+            }
 
             case MB_ENTITY_KIND_COUNT:
             case MB_ENTITY_KIND_DISCID:
@@ -638,6 +655,12 @@ search_in_levels_callback (GObject *source, GAsyncResult *res,
 
     g_free (thread_data);
     et_music_brainz_dialog_stop_set_sensitive (FALSE);
+
+    if (exit_on_complete)
+    {
+        gtk_dialog_response (GTK_DIALOG (mbDialog),
+                             GTK_RESPONSE_DELETE_EVENT);
+    }
 }
 
 /*
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 7b3bdeb..f58842e 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -65,6 +65,13 @@ typedef struct
     int type;
 } ManualSearchThreadData;
 
+/****************
+ * Declarations *
+ ***************/
+
+static void
+btn_close_clicked (GtkWidget *button, gpointer data);
+
 /*************
  * Functions *
  *************/
@@ -104,6 +111,11 @@ manual_search_callback (GObject *source, GAsyncResult *res,
     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);
+
+    if (exit_on_complete)
+    {
+        btn_close_clicked (NULL, NULL);
+    }
 }
 
 /*
@@ -166,6 +178,11 @@ mb5_search_error_callback (GObject *source, GAsyncResult *res,
                                        "statusbar")), 0, dest->message);
     g_error_free (dest);
     et_music_brainz_dialog_stop_set_sensitive (FALSE);
+
+    if (exit_on_complete)
+    {
+        btn_close_clicked (NULL, NULL);
+    }
 }
 
 /*
@@ -436,6 +453,11 @@ selected_find_callback (GObject *source, GAsyncResult *res,
     g_object_unref (((SelectedFindThreadData *)user_data)->hash_table);
     g_free (user_data);
     et_music_brainz_dialog_stop_set_sensitive (FALSE);
+
+    if (exit_on_complete)
+    {
+        btn_close_clicked (NULL, NULL);
+    }
 }
 
 static void
@@ -601,6 +623,11 @@ discid_search_callback (GObject *source, GAsyncResult *res,
     g_object_unref (res);
     g_free (user_data);
     et_music_brainz_dialog_stop_set_sensitive (FALSE);
+
+    if (exit_on_complete)
+    {
+        btn_close_clicked (NULL, NULL);
+    }
 }
 
 static void
@@ -688,6 +715,25 @@ et_music_brainz_dialog_stop_set_sensitive (gboolean sensitive)
                               sensitive);
 }
 
+static gboolean
+et_music_brainz_dialog_delete_event (GtkWidget *widget, GdkEvent *event,
+                                     gpointer data)
+{
+    if (gtk_widget_get_sensitive (GTK_WIDGET (gtk_builder_get_object (builder,
+                                  "btnStop"))))
+    {
+        gtk_statusbar_push (GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")),
+                            0,
+                            _("Currently there is a search in progress. Please wait for it to exit."));
+        exit_on_complete = TRUE;
+        btn_manual_stop_clicked (NULL, NULL);
+
+        return TRUE;
+    }
+
+     return FALSE;
+}
+
 /*
  * et_open_musicbrainz_dialog:
  *
@@ -717,12 +763,14 @@ et_open_musicbrainz_dialog ()
 
     mb_dialog_priv = g_malloc (sizeof (MusicBrainzDialogPrivate));
     mb_dialog_priv->mb_tree_root = g_node_new (NULL);
+    exit_on_complete = FALSE;
     entityView = et_mb_entity_view_new ();
     mbDialog = GTK_WIDGET (gtk_builder_get_object (builder, "mbDialog"));
     gtk_widget_set_size_request (mbDialog, 660, 500);
     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);
     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);
diff --git a/src/musicbrainz_dialog.h b/src/musicbrainz_dialog.h
index 1f17f54..342d203 100644
--- a/src/musicbrainz_dialog.h
+++ b/src/musicbrainz_dialog.h
@@ -32,6 +32,7 @@
 GtkBuilder *builder;
 GtkWidget *mbDialog;
 GtkWidget *entityView;
+gboolean exit_on_complete;
 
 /**************
  * Prototypes *


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