[easytag/wip/musicbrainz-support-appwin-merge: 4/78] Implemented Select All, Unselect All Buttons. Added Artists and Type for Releases.



commit 326117137122710fc34b6e0144fd50a5f67f2510
Author: Abhinav <abhijangda hotmail com>
Date:   Mon May 19 20:21:58 2014 +0530

    Implemented Select All, Unselect All Buttons. Added Artists and Type for Releases.
    
    Added buttons in musicbrainz_dialog.ui
    Added callbacks for buttons in musicbrainz_dialog.c
    Added functions for above features in mbentityview.c
    Added Red Line support in mbentityview.c and mb_search.c

 data/musicbrainz_dialog.ui |    2 +-
 src/mb_search.c            |   34 ++++++++++++++--
 src/mb_search.h            |    5 ++-
 src/mbentityview.c         |   93 ++++++++++++++++++++++++++-----------------
 src/mbentityview.h         |    8 +++-
 src/musicbrainz_dialog.c   |   48 ++++++++++++++++++++++-
 6 files changed, 144 insertions(+), 46 deletions(-)
---
diff --git a/data/musicbrainz_dialog.ui b/data/musicbrainz_dialog.ui
index ade53f4..09288f1 100755
--- a/data/musicbrainz_dialog.ui
+++ b/data/musicbrainz_dialog.ui
@@ -636,7 +636,7 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkToolButton" id="toolbtnToggleRedLines">
+                              <object class="GtkToggleToolButton" id="toolbtnToggleRedLines">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
                                 <property name="label" translatable="yes">toolbutton8</property>
diff --git a/src/mb_search.c b/src/mb_search.c
index 1994cb4..b302c91 100644
--- a/src/mb_search.c
+++ b/src/mb_search.c
@@ -76,6 +76,7 @@ et_musicbrainz_search_in_entity (enum MB_ENTITY_TYPE child_type,
                 Mb5Artist artist;
                 artist = mb5_metadata_get_artist (metadata);
                 list = mb5_artist_get_releaselist (artist);
+                param_values[0] = "artists release-groups";
 
                 for (i = 0; i < mb5_release_list_size (list); i++)
                 {
@@ -83,16 +84,28 @@ et_musicbrainz_search_in_entity (enum MB_ENTITY_TYPE child_type,
                     release = mb5_release_list_item (list, i);
                     if (release)
                     {
+                        Mb5Metadata metadata_release;
+                        gchar release_mbid [NAME_MAX_SIZE];
                         GNode *node;
                         EtMbEntity *entity;
+                        mb5_release_get_id ((Mb5Release)release,
+                                            release_mbid,
+                                            sizeof (release_mbid));
+                        metadata_release = mb5_query_query (query, "release",
+                                                            release_mbid, "",
+                                                            1, param_names,
+                                                            param_values);
                         entity = g_malloc (sizeof (EtMbEntity));
-                        entity->entity = release;
+                        entity->entity = mb5_release_clone (mb5_metadata_get_release (metadata_release));    
            
                         entity->type = MB_ENTITY_TYPE_ALBUM;
+                        entity->is_red_line = FALSE;
                         node = g_node_new (entity);
                         g_node_append (root, node);
+                        mb5_metadata_delete (metadata_release);
                     }
                 }
             }
+            mb5_metadata_delete (metadata);
         }
         else
         {
@@ -254,7 +267,7 @@ et_musicbrainz_search (gchar *string, enum MB_ENTITY_TYPE type, GNode *root,
                 int i;
                 Mb5ArtistList list;
                 list = mb5_metadata_get_artistlist (metadata);
-
+    
                 for (i = 0; i < mb5_artist_list_size (list); i++)
                 {
                     Mb5Artist artist;
@@ -266,6 +279,7 @@ et_musicbrainz_search (gchar *string, enum MB_ENTITY_TYPE type, GNode *root,
                         entity = g_malloc (sizeof (EtMbEntity));
                         entity->entity = mb5_artist_clone (artist);
                         entity->type = MB_ENTITY_TYPE_ARTIST;
+                        entity->is_red_line = FALSE;
                         node = g_node_new (entity);
                         g_node_append (root, node);
                     }
@@ -287,6 +301,7 @@ et_musicbrainz_search (gchar *string, enum MB_ENTITY_TYPE type, GNode *root,
         metadata = mb5_query_query (query, "release", "", "", 2, param_names,
                                     param_values);
         result = mb5_query_get_lastresult (query);
+        g_free (param_values [0]);
 
         if (result == eQuery_Success)
         {
@@ -304,18 +319,29 @@ et_musicbrainz_search (gchar *string, enum MB_ENTITY_TYPE type, GNode *root,
                     release = mb5_release_list_item (list, i);
                     if (release)
                     {
+                        Mb5Metadata metadata_release;
+                        gchar release_mbid [NAME_MAX_SIZE];
                         GNode *node;
                         EtMbEntity *entity;
+
+                        mb5_release_get_id ((Mb5Release)release,
+                                            release_mbid,
+                                            sizeof (release_mbid));
+                        metadata_release = mb5_query_query (query, "release",
+                                                            release_mbid, "",
+                                                            1, param_names,
+                                                            param_values);
                         entity = g_malloc (sizeof (EtMbEntity));
-                        entity->entity = mb5_release_clone (release);
+                        entity->entity = mb5_release_clone (mb5_metadata_get_release (metadata_release));    
            
                         entity->type = MB_ENTITY_TYPE_ALBUM;
+                        entity->is_red_line = FALSE;
                         node = g_node_new (entity);
                         g_node_append (root, node);
+                        mb5_metadata_delete (metadata_release);
                     }
                 }
             }
 
-            g_free (param_values [0]);
             mb5_metadata_delete (metadata);
         }
         else
diff --git a/src/mb_search.h b/src/mb_search.h
index f91d920..4f7035f 100644
--- a/src/mb_search.h
+++ b/src/mb_search.h
@@ -31,6 +31,8 @@
  * Declarations *
  ****************/
 
+#define NAME_MAX_SIZE 256
+
 GCancellable *mb5_search_cancellable;
 
 /*
@@ -72,7 +74,8 @@ enum MB_ENTITY_TYPE
 typedef struct
 {
     Mb5Entity entity;
-    enum MB_ENTITY_TYPE type;    
+    enum MB_ENTITY_TYPE type;
+    gboolean is_red_line;
 } EtMbEntity;
 
 /**************
diff --git a/src/mbentityview.c b/src/mbentityview.c
index 9d4ccb9..50f75ca 100644
--- a/src/mbentityview.c
+++ b/src/mbentityview.c
@@ -26,8 +26,8 @@
 #include "mbentityview.h"
 #include "log.h"
 #include "musicbrainz_dialog.h"
+#include "mb_search.h"
 
-#define NAME_MAX_SIZE 256
 #define ET_MB_ENTITY_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
                                             ET_MB_ENTITY_VIEW_TYPE, \
                                             EtMbEntityViewPrivate))
@@ -173,7 +173,6 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
 {
     /* Traverse node in GNode and add it to list_store */
     enum MB_ENTITY_TYPE type;
-    //Mb5ReleaseList *release_list;
     Mb5ArtistCredit artist_credit;
     Mb5NameCreditList name_list;
     Mb5ReleaseGroup release_group;
@@ -224,13 +223,13 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
                 break;
 
             case MB_ENTITY_TYPE_ALBUM:
-                mb5_release_get_title ((Mb5Release)entity, name, sizeof (name));
+                mb5_release_get_title ((Mb5Release)entity, name,
+                                       sizeof (name));
                 gtk_list_store_append (list_store, &iter);
                 gtk_list_store_set (list_store, &iter, 
                                     MB_ALBUM_COLUMNS_NAME, name, -1);
 
                 artist_credit = mb5_release_get_artistcredit ((Mb5Release)entity);
-
                 if (artist_credit)
                 {
                     name_list = mb5_artistcredit_get_namecreditlist (artist_credit);
@@ -241,45 +240,35 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
                         Mb5NameCredit name_credit;
                         Mb5Artist name_credit_artist;
                         int size;
-
                         name_credit = mb5_namecredit_list_item (name_list, i);
                         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, ' ');
                     }
-
                     gtk_list_store_set (list_store, &iter,
                                         MB_ALBUM_COLUMNS_ARTIST,
                                         gstring->str, -1);
                     g_string_free (gstring, TRUE);
                 }
 
-                for (i = 0; i < mb5_namecredit_list_get_count (name_list); i++)
+                if (((EtMbEntity *)node->data)->is_red_line)
                 {
-                    Mb5NameCredit name_credit;
-                    int size;
-                    name_credit = mb5_namecredit_list_item (name_list, i);
-                    size = mb5_namecredit_get_name (name_credit, name, 
-                                                    NAME_MAX_SIZE);
-                    g_string_append_len (gstring, name, size);
-                    g_string_append_c (gstring, ' ');
-                    mb5_namecredit_delete (name_credit);
+                    gtk_list_store_set (list_store, &iter,
+                                        MB_ALBUM_COLUMNS_N, "red", -1);
+                }
+                else
+                {
+                    gtk_list_store_set (list_store, &iter,
+                                        MB_ALBUM_COLUMNS_N, "black", -1);
                 }
 
-                mb5_namecredit_list_delete (name_list);
-                mb5_artistcredit_delete (artist_credit);
-
-                gtk_list_store_set (list_store, &iter,
-                                    MB_ALBUM_COLUMNS_ARTIST, gstring->str, -1);
-                g_string_free (gstring, TRUE);
-
-                //TODO: Correct below code
-                /*release_list = mb5_release_get_releaselist ((Mb5Release)entity);
+                //TODO: Add number of tracks
+                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_RELEASES,
-                                    mb5_release_list_get_count (release_list), -1);
-                mb5_release_list_delete (release_list);*/
+                                    MB_ALBUM_COLUMNS_TYPE, name, -1);
                 break;
 
             case MB_ENTITY_TYPE_TRACK:
@@ -351,6 +340,7 @@ add_iter_to_list_store (GtkListStore *list_store, GNode *node)
                 break;
             
         }
+
         node = g_node_next_sibling (node);
     }
 }
@@ -411,23 +401,30 @@ show_data_in_entity_view (EtMbEntityView *entity_view)
             total_cols = 0;
     }
 
-    types = g_malloc (sizeof (GType) * total_cols);
+    types = g_malloc (sizeof (GType) * (total_cols + 1));
 
     for (i = 0; i < total_cols; i++)
     {
         types [i] = G_TYPE_STRING;
         renderer = gtk_cell_renderer_text_new ();
         column = gtk_tree_view_column_new_with_attributes (columns[type][i], 
-                                                           renderer, "text", i, NULL);
+                                                           renderer, "text", i,
+                                                           "foreground",
+                                                           total_cols, NULL);
         gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), column);
     }
 
-    priv->list_store = GTK_TREE_MODEL (gtk_list_store_newv (total_cols, types));
+    /* Setting the colour column */
+    types [total_cols] = G_TYPE_STRING;
+    renderer = gtk_cell_renderer_text_new ();
+    gtk_tree_view_column_new_with_attributes ("Colour Column", renderer,
+                                              "text", total_cols, NULL);
+
+    priv->list_store = GTK_TREE_MODEL (gtk_list_store_newv (total_cols + 1, types));
     g_free (types);
 
     gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), priv->list_store);
     g_object_unref (priv->list_store);
-
     add_iter_to_list_store (GTK_LIST_STORE (priv->list_store),
                             g_node_first_child (priv->mb_tree_current_node));
 }
@@ -520,10 +517,6 @@ search_in_levels_callback (GObject *source, GAsyncResult *res,
     priv->active_toggle_button = toggle_btn;
     gtk_tree_model_get (priv->list_store, &thread_data->iter, 0, &entity_name,
                         -1);
-    gtk_button_set_label (GTK_BUTTON (toggle_btn), entity_name);
-    gtk_widget_show_all (GTK_WIDGET (priv->bread_crumb_box));
-    ((EtMbEntity *)thread_data->child->data)->is_red_line = TRUE;
-    show_data_in_entity_view (entity_view);
     g_object_unref (res);
     g_free (thread_data);
 }
@@ -618,6 +611,12 @@ tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
     child = g_node_nth_child (priv->mb_tree_current_node,
                               depth);
 
+    if (((EtMbEntity *)child->data)->type ==
+        MB_ENTITY_TYPE_TRACK)
+    {
+        return;
+    }
+
     thread_data = g_malloc (sizeof (SearchInLevelThreadData));
     thread_data->entity_view = ET_MB_ENTITY_VIEW (user_data);
     thread_data->child = child;
@@ -694,11 +693,11 @@ et_mb_entity_view_set_tree_root (EtMbEntityView *entity_view, GNode *treeRoot)
                 break;
 
             case MB_ENTITY_TYPE_ALBUM:
-                gtk_button_set_label (GTK_BUTTON (btn), "Album");
+                gtk_button_set_label (GTK_BUTTON (btn), "Albums");
                 break;
 
             case MB_ENTITY_TYPE_TRACK:
-                gtk_button_set_label (GTK_BUTTON (btn), "Track");
+                gtk_button_set_label (GTK_BUTTON (btn), "Tracks");
                 break;
 
             default:
@@ -712,6 +711,8 @@ et_mb_entity_view_set_tree_root (EtMbEntityView *entity_view, GNode *treeRoot)
         show_data_in_entity_view (entity_view);
         g_signal_connect (G_OBJECT (btn), "clicked",
                           G_CALLBACK (toggle_button_clicked), entity_view);
+        gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)),
+                                     GTK_SELECTION_MULTIPLE);
     }
 }
 
@@ -728,3 +729,21 @@ et_mb_entity_view_new ()
 {
     return GTK_WIDGET (g_object_new (et_mb_entity_view_get_type (), NULL));
 }
+
+void
+et_mb_entity_view_select_all (EtMbEntityView *entity_view)
+{
+    EtMbEntityViewPrivate *priv;
+
+    priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
+    gtk_tree_selection_select_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
+}
+
+void
+et_mb_entity_view_unselect_all (EtMbEntityView *entity_view)
+{
+    EtMbEntityViewPrivate *priv;
+
+    priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
+    gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)));
+}
diff --git a/src/mbentityview.h b/src/mbentityview.h
index d16642d..46ba3fc 100644
--- a/src/mbentityview.h
+++ b/src/mbentityview.h
@@ -22,7 +22,6 @@
 #define __MB_ENTITY_VIEW_H__
 
 #include <gtk/gtk.h>
-#include "mb_search.h"
 
 #define ET_MB_ENTITY_VIEW_TYPE (et_mb_entity_view_get_type ())
 #define ET_MB_ENTITY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
@@ -101,5 +100,10 @@ et_mb_entity_view_get_type (void);
 GtkWidget *
 et_mb_entity_view_new (void);
 void
-et_mb_entity_view_set_tree_root (EtMbEntityView *entity_view, GNode *treeRoot);
+et_mb_entity_view_set_tree_root (EtMbEntityView *entity_view,
+                                 GNode *treeRoot);
+void
+et_mb_entity_view_select_all (EtMbEntityView *entity_view);
+void
+et_mb_entity_view_unselect_all (EtMbEntityView *entity_view);
 #endif /* __MB_ENTITY_VIEW_H__ */
\ No newline at end of file
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 8daa722..6063a3d 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -29,7 +29,8 @@
 #include "log.h"
 #include "musicbrainz_dialog.h"
 #include "mbentityview.h"
- 
+#include "mb_search.h"
+
 /***************
  * Declaration *
  ***************/
@@ -178,6 +179,48 @@ btn_manual_find_clicked (GtkWidget *btn, gpointer user_data)
 }
 
 static void
+tool_btn_toggle_red_lines_clicked (GtkWidget *btn, gpointer user_data)
+{
+    
+}
+
+static void
+tool_btn_up_clicked (GtkWidget *btn, gpointer user_data)
+{
+    
+}
+
+static void
+tool_btn_down_clicked (GtkWidget *btn, gpointer user_data)
+{
+    
+}
+
+static void
+tool_btn_invert_selection_clicked (GtkWidget *btn, gpointer user_data)
+{
+    
+}
+
+static void
+tool_btn_select_all_clicked (GtkWidget *btn, gpointer user_data)
+{
+    et_mb_entity_view_select_all (ET_MB_ENTITY_VIEW (entityView));
+}
+
+static void
+tool_btn_unselect_all_clicked (GtkWidget *btn, gpointer user_data)
+{
+    et_mb_entity_view_unselect_all (ET_MB_ENTITY_VIEW (entityView));
+}
+
+static void
+tool_btn_refersh_clicked (GtkWidget *btn, gpointer user_data)
+{
+    
+}
+
+static void
 btn_manual_stop_clicked (GtkWidget *btn, gpointer user_data)
 {
     g_cancellable_cancel (mb5_search_cancellable);
@@ -223,6 +266,9 @@ et_open_musicbrainz_dialog ()
     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, "toolbtnToggleRedLines"),
+                      "clicked", G_CALLBACK (tool_btn_toggle_red_lines_clicked),
+                      NULL);
 
     /* Fill Values in cb_manual_search_in */
     cb_manual_search_in = GTK_WIDGET (gtk_builder_get_object (builder,


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