[easytag/wip/musicbrainz-support-merge: 6/75] Implemented selection Up and Down



commit 694a78da5eedbc44532b6e1adf4ebb3945511a37
Author: Abhinav <abhijangda hotmail com>
Date:   Sat May 24 21:23:38 2014 +0530

    Implemented selection Up and Down
    
    Added buttons for Up and Down in musicbrainz_dialog.ui. Added functions
    for above features in mbentityview.c & mbentityview.h. Added callbacks
    for functions in musicbrainz_dialog.c.

 data/musicbrainz_dialog.ui |   47 +++++++-----------
 src/mbentityview.c         |  115 ++++++++++++++++++++++++++++++++++++++++++--
 src/mbentityview.h         |   11 ++++
 src/musicbrainz_dialog.c   |   37 ++++++++++++--
 4 files changed, 172 insertions(+), 38 deletions(-)
---
diff --git a/data/musicbrainz_dialog.ui b/data/musicbrainz_dialog.ui
index 38547a2..2b036e1 100755
--- a/data/musicbrainz_dialog.ui
+++ b/data/musicbrainz_dialog.ui
@@ -6,50 +6,50 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-find</property>
   </object>
-  <object class="GtkImage" id="image8">
+  <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="image9">
+  <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="img_invert_selection">
+  <object class="GtkImage" id="image12">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">easytag-invert-selection</property>
+    <property name="stock">gtk-find</property>
   </object>
-  <object class="GtkImage" id="img_red_lines">
+  <object class="GtkImage" id="image13">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">easytag-red-lines</property>
+    <property name="stock">gtk-stop</property>
   </object>
-  <object class="GtkImage" id="img_unselect_all">
+  <object class="GtkImage" id="image8">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">easytag-unselect-all</property>
+    <property name="stock">gtk-find</property>
   </object>
-  <object class="GtkImage" id="image10">
+  <object class="GtkImage" id="image9">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">gtk-find</property>
+    <property name="stock">gtk-stop</property>
   </object>
-  <object class="GtkImage" id="image11">
+  <object class="GtkImage" id="img_invert_selection">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">gtk-stop</property>
+    <property name="stock">easytag-invert-selection</property>
   </object>
-  <object class="GtkImage" id="image12">
+  <object class="GtkImage" id="img_red_lines">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">gtk-find</property>
+    <property name="stock">easytag-red-lines</property>
   </object>
-  <object class="GtkImage" id="image13">
+  <object class="GtkImage" id="img_unselect_all">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="stock">gtk-stop</property>
+    <property name="stock">easytag-unselect-all</property>
   </object>
   <object class="GtkImage" id="image14">
     <property name="visible">True</property>
@@ -542,19 +542,10 @@
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
                                 <child>
-                                  <object class="GtkComboBoxText" id="cmbTextSearch">
-                                    <property name="width_request">131</property>
+                                  <object class="GtkEntry" id="entryTreeViewSearch">
                                     <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="tooltip_text" translatable="yes">Type the text to search 
in the results</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="can_focus">False</property>
-                                      </object>
-                                    </child>
+                                    <property name="can_focus">True</property>
+                                    <property name="invisible_char">●</property>
                                   </object>
                                 </child>
                               </object>
diff --git a/src/mbentityview.c b/src/mbentityview.c
index bad0815..f91fc03 100644
--- a/src/mbentityview.c
+++ b/src/mbentityview.c
@@ -42,6 +42,13 @@ char *columns [MB_ENTITY_TYPE_COUNT][8] = {
     {"Name", "Album", "Artist", "Time", "Number"},
     };
 
+enum ET_MB_DISPLAY_RESULTS
+{
+    ET_MB_DISPLAY_RESULTS_ALL = 0,
+    ET_MB_DISPLAY_RESULTS_RED = 1,
+    ET_MB_DISPLAY_RESULTS_SEARCH = 1 << 1,
+};
+
 static GSimpleAsyncResult *async_result;
 
 /*
@@ -70,6 +77,7 @@ typedef struct
     GtkTreeModel *filter;
     gboolean search_or_red;
     gboolean toggle_red_lines;
+    const gchar *text_to_search_in_results;
 } EtMbEntityViewPrivate;
 
 typedef struct
@@ -113,7 +121,27 @@ tree_filter_visible_func (GtkTreeModel *model, GtkTreeIter *iter,
 
     priv = (EtMbEntityViewPrivate *)data;
 
-    if (!priv->search_or_red)
+    if (priv->search_or_red == ET_MB_DISPLAY_RESULTS_ALL)
+    {
+        return TRUE;
+    }
+
+    if (priv->search_or_red & ET_MB_DISPLAY_RESULTS_SEARCH)
+    {
+        gchar *value;
+
+        gtk_tree_model_get (model, iter, 0, &value, -1);
+
+        if (g_strstr_len (value, -1, priv->text_to_search_in_results))
+        {
+            g_free (value);
+            return TRUE;
+        }
+
+        g_free (value);
+    }
+
+    if (priv->search_or_red & ET_MB_DISPLAY_RESULTS_RED)
     {
         gchar *value;
 
@@ -145,7 +173,7 @@ tree_filter_visible_func (GtkTreeModel *model, GtkTreeIter *iter,
         return priv->toggle_red_lines;
     }
 
-    return TRUE;
+    return FALSE;
 }
 
 /*
@@ -718,6 +746,7 @@ et_mb_entity_view_init (EtMbEntityView *entity_view)
     priv->mb_tree_current_node = NULL;
     priv->active_toggle_button = NULL;
     priv->toggle_red_lines = TRUE;
+    priv->search_or_red = ET_MB_DISPLAY_RESULTS_ALL;
 
     g_signal_connect (G_OBJECT (priv->tree_view), "row-activated",
                       G_CALLBACK (tree_view_row_activated), entity_view);
@@ -811,7 +840,7 @@ et_mb_entity_view_toggle_red_lines (EtMbEntityView *entity_view)
     EtMbEntityViewPrivate *priv;
 
     priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
-    priv->search_or_red = FALSE;
+    priv->search_or_red = priv->search_or_red | ET_MB_DISPLAY_RESULTS_RED;
     priv->toggle_red_lines = !priv->toggle_red_lines;
     gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
 }
@@ -827,7 +856,7 @@ et_mb_entity_view_invert_selection (EtMbEntityView *entity_view)
     selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
     if (!gtk_tree_model_get_iter_first (priv->filter, &filter_iter))
     {
-        return FALSE;
+        return;
     }
 
     do
@@ -843,3 +872,81 @@ et_mb_entity_view_invert_selection (EtMbEntityView *entity_view)
     }
     while (gtk_tree_model_iter_next (priv->filter, &filter_iter));
 }
+
+int
+et_mb_entity_view_get_current_level (EtMbEntityView *entity_view)
+{
+    EtMbEntityViewPrivate *priv;
+    GList *list;
+    int n;
+
+    priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
+    list = gtk_container_get_children (GTK_CONTAINER (priv->bread_crumb_box));
+    n = g_list_length (list);
+    g_list_free (list);
+
+    return n;
+}
+
+void
+et_mb_entity_view_search_in_results (EtMbEntityView *entity_view,
+                                     const gchar *text)
+{
+    EtMbEntityViewPrivate *priv;
+
+    priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
+    priv->text_to_search_in_results = text;
+    priv->search_or_red = priv->search_or_red | ET_MB_DISPLAY_RESULTS_SEARCH;
+    gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
+}
+
+void
+et_mb_entity_view_select_up (EtMbEntityView *entity_view)
+{
+    EtMbEntityViewPrivate *priv;
+    GtkTreeSelection *selection;
+    GtkTreeIter iter;
+
+    priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
+    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
+
+    if (!gtk_tree_selection_iter_is_selected (selection, &iter))
+    {
+        return;
+    }
+
+    if (!gtk_tree_model_iter_previous (priv->filter, &iter))
+    {
+        return;
+    }
+
+    gtk_tree_selection_select_iter (selection, &iter);
+}
+
+void
+et_mb_entity_view_select_down (EtMbEntityView *entity_view)
+{
+    EtMbEntityViewPrivate *priv;
+    GtkTreeSelection *selection;
+    GtkTreeIter iter;
+
+    priv = ET_MB_ENTITY_VIEW_GET_PRIVATE (entity_view);
+    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
+
+    if (!gtk_tree_selection_iter_is_selected (selection, &iter))
+    {
+        return;
+    }
+
+    if (!gtk_tree_model_iter_next (priv->filter, &iter))
+    {
+        return;
+    }
+
+    gtk_tree_selection_select_iter (selection, &iter);
+}
+
+void
+et_mb_entity_view_refresh_current_level (EtMbEntityView *entity_view)
+{
+}
diff --git a/src/mbentityview.h b/src/mbentityview.h
index 845748b..61fcac1 100644
--- a/src/mbentityview.h
+++ b/src/mbentityview.h
@@ -110,4 +110,15 @@ void
 et_mb_entity_view_toggle_red_lines (EtMbEntityView *entity_view);
 void
 et_mb_entity_view_invert_selection (EtMbEntityView *entity_view);
+int
+et_mb_entity_view_get_current_level (EtMbEntityView *entity_view);
+void
+et_mb_entity_view_search_in_results (EtMbEntityView *entity_view,
+                                     const gchar *text);
+void
+et_mb_entity_view_refresh_current_level (EtMbEntityView *entity_view);
+void
+et_mb_entity_view_select_up (EtMbEntityView *entity_view);
+void
+et_mb_entity_view_select_down (EtMbEntityView *entity_view);
 #endif /* __MB_ENTITY_VIEW_H__ */
diff --git a/src/musicbrainz_dialog.c b/src/musicbrainz_dialog.c
index 73f4c7c..88598b2 100644
--- a/src/musicbrainz_dialog.c
+++ b/src/musicbrainz_dialog.c
@@ -193,13 +193,13 @@ tool_btn_toggle_red_lines_clicked (GtkWidget *btn, gpointer user_data)
 static void
 tool_btn_up_clicked (GtkWidget *btn, gpointer user_data)
 {
-
+    et_mb_entity_view_select_up (ET_MB_ENTITY_VIEW (entityView));
 }
 
 static void
 tool_btn_down_clicked (GtkWidget *btn, gpointer user_data)
 {
-
+    et_mb_entity_view_select_down (ET_MB_ENTITY_VIEW (entityView));
 }
 
 static void
@@ -223,7 +223,13 @@ tool_btn_unselect_all_clicked (GtkWidget *btn, gpointer user_data)
 static void
 tool_btn_refersh_clicked (GtkWidget *btn, gpointer user_data)
 {
-
+    /* TODO: Implement Refresh Operation */
+    if (et_mb_entity_view_get_current_level (ET_MB_ENTITY_VIEW (entityView)) >
+        1)
+    {
+        /* Current level is more than 1, refereshing means downloading an */
+        /* entity's children */
+    }
 }
 
 static void
@@ -232,6 +238,13 @@ btn_manual_stop_clicked (GtkWidget *btn, gpointer user_data)
     g_cancellable_cancel (mb5_search_cancellable);
 }
 
+static void
+entry_tree_view_search_changed (GtkEditable *editable, gpointer user_data)
+{
+    et_mb_entity_view_search_in_results (ET_MB_ENTITY_VIEW (entityView),
+                    gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder, 
"entryTreeViewSearch"))));
+}
+
 /*
  * et_open_musicbrainz_dialog:
  *
@@ -272,13 +285,25 @@ 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),
+    g_signal_connect (gtk_builder_get_object (builder, "toolbtnUp"),
+                      "clicked", G_CALLBACK (tool_btn_up_clicked),
+                      NULL);
+    g_signal_connect (gtk_builder_get_object (builder, "toolbtnDown"),
+                      "clicked", G_CALLBACK (tool_btn_down_clicked),
+                      NULL);
+    g_signal_connect (gtk_builder_get_object (builder, "toolbtnSelectAll"),
+                      "clicked", G_CALLBACK (tool_btn_select_all_clicked),
+                      NULL);
+    g_signal_connect (gtk_builder_get_object (builder, "toolbtnUnselectAll"),
+                      "clicked", G_CALLBACK (tool_btn_unselect_all_clicked),
                       NULL);
     g_signal_connect (gtk_builder_get_object (builder, "toolbtnInvertSelection"),
                       "clicked", G_CALLBACK (tool_btn_invert_selection_clicked),
                       NULL);
-
+    g_signal_connect_after (gtk_builder_get_object (builder, "entryTreeViewSearch"),
+                            "changed",
+                            G_CALLBACK (entry_tree_view_search_changed),
+                            NULL);
     /* Fill Values in cb_manual_search_in */
     cb_manual_search_in = GTK_WIDGET (gtk_builder_get_object (builder,
                                                               "cbManualSearchIn"));


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