[easytag/wip/glist: 8/12] Refactor list handling in browser.c



commit 95d0983f8ad0e19cba3d7c7acfb4d517173109c2
Author: David King <amigadave amigadave com>
Date:   Wed May 22 20:12:58 2013 +0100

    Refactor list handling in browser.c

 src/browser.c |   30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index 12afc3d..eaea428 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -955,10 +955,8 @@ Browser_List_Row_Selected (GtkTreeSelection *selection, gpointer data)
      * After a file is deleted, this function is called :
      * So we must handle the situation if no rows are selected
      */
-    if (g_list_length(selectedRows) == 0)
+    if (!selectedRows)
     {
-        g_list_foreach(selectedRows, (GFunc) gtk_tree_path_free, NULL);
-        g_list_free(selectedRows);
         return;
     }
 
@@ -977,8 +975,7 @@ Browser_List_Row_Selected (GtkTreeSelection *selection, gpointer data)
         Action_Select_Nth_File_By_Etfile(LastBrowserListETFileSelected);
     }
 
-    g_list_foreach(selectedRows, (GFunc) gtk_tree_path_free, NULL);
-    g_list_free(selectedRows);
+    g_list_free_full (selectedRows, (GDestroyNotify)gtk_tree_path_free);
 }
 
 /*
@@ -1232,8 +1229,8 @@ void Browser_List_Refresh_File_In_List (ET_File *ETFile)
                 }
             }
         }
-        g_list_foreach(selectedRow, (GFunc) gtk_tree_path_free, NULL);
-        g_list_free(selectedRow);
+
+        g_list_free_full (selectedRow, (GDestroyNotify)gtk_tree_path_free);
     }
 
     // 3/3. Fails, now we browse the full list to find it
@@ -4142,10 +4139,10 @@ Run_Program_With_Selected_Files (GtkWidget *combobox)
     gchar   *program_name;
     ET_File *ETFile;
     GList   *selected_paths;
+    GList *l;
     GList   *args_list = NULL;
     GtkTreeIter iter;
     gboolean program_ran;
-    gboolean valid;
 
     if (!GTK_IS_COMBO_BOX(combobox) || !ETCore->ETFileDisplayedList)
         return;
@@ -4155,27 +4152,26 @@ Run_Program_With_Selected_Files (GtkWidget *combobox)
 
     // List of files to pass as parameters
     selected_paths = 
gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList)), NULL);
-    while (selected_paths)
+
+    for (l = selected_paths; l != NULL; l = g_list_next (l))
     {
-        valid = gtk_tree_model_get_iter(GTK_TREE_MODEL(fileListModel), &iter, 
(GtkTreePath*)selected_paths->data);
-        if (valid)
+        if (gtk_tree_model_get_iter (GTK_TREE_MODEL (fileListModel), &iter,
+                                     (GtkTreePath *)l->data))
         {
             gtk_tree_model_get(GTK_TREE_MODEL(fileListModel), &iter,
                                LIST_FILE_POINTER, &ETFile,
                                -1);
 
-            args_list = g_list_append(args_list,((File_Name *)ETFile->FileNameCur->data)->value);
+            args_list = g_list_prepend (args_list,
+                                        ((File_Name *)ETFile->FileNameCur->data)->value);
             //args_list = g_list_append(args_list,((File_Name *)ETFile->FileNameCur->data)->value_utf8);
         }
-
-        if (!selected_paths->next) break;
-        selected_paths = selected_paths->next;
     }
 
+    args_list = g_list_reverse (args_list);
     program_ran = Run_Program(program_name,args_list);
 
-    g_list_foreach(selected_paths, (GFunc)gtk_tree_path_free, NULL);
-    g_list_free(selected_paths);
+    g_list_free_full (selected_paths, (GDestroyNotify)gtk_tree_path_free);
     g_list_free(args_list);
 
     if (program_ran)


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