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



commit 6f4fc018915f6a9c42d8231e7f5f56869da019d3
Author: David King <amigadave amigadave com>
Date:   Wed May 22 20:43:18 2013 +0100

    Refactor list handling in easytag.c

 src/easytag.c |  209 ++++++++++++++++++++++-----------------------------------
 1 files changed, 79 insertions(+), 130 deletions(-)
---
diff --git a/src/easytag.c b/src/easytag.c
index 41e12f3..b81d17f 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1260,6 +1260,7 @@ Mini_Button_Clicked (GObject *object)
 {
     GList *etfilelist = NULL;
     GList *selection_filelist = NULL;
+    GList *l;
     gchar *string_to_set = NULL;
     gchar *string_to_set1 = NULL;
     gchar *msg = NULL;
@@ -1276,32 +1277,28 @@ Mini_Button_Clicked (GObject *object)
     // Warning : 'selection_filelist' is not a list of 'ETFile' items!
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
     selection_filelist = gtk_tree_selection_get_selected_rows(selection, NULL);
+
     // Create an 'ETFile' list from 'selection_filelist'
-    while (selection_filelist)
+    for (l = selection_filelist; l != NULL; l = g_list_next (l))
     {
-        etfile = Browser_List_Get_ETFile_From_Path(selection_filelist->data);
+        etfile = Browser_List_Get_ETFile_From_Path (l->data);
         etfilelist = g_list_append(etfilelist,etfile);
-
-        if (!selection_filelist->next) break;
-        selection_filelist = g_list_next(selection_filelist);
     }
-    g_list_foreach(selection_filelist, (GFunc)gtk_tree_path_free, NULL);
-    g_list_free(selection_filelist);
+
+    g_list_free_full (selection_filelist, (GDestroyNotify)gtk_tree_path_free);
 
 
     if (object == G_OBJECT (TitleEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(TitleEntry),0,-1); // The string to apply to all 
other files
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->title,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with title '%s'."),string_to_set);
@@ -1311,16 +1308,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (ArtistEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(ArtistEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->artist,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with artist '%s'."),string_to_set);
@@ -1330,16 +1325,13 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (AlbumArtistEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(AlbumArtistEntry),0,-1);
-        while (etfilelist)
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->album_artist,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with album artist '%s'."),string_to_set);
@@ -1349,16 +1341,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (AlbumEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(AlbumEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->album,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with album '%s'."),string_to_set);
@@ -1368,16 +1358,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (DiscNumberEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(DiscNumberEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
             etfile = (ET_File *)etfilelist->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->disc_number,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with disc number '%s'."),string_to_set);
@@ -1387,16 +1375,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (YearEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(YearEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->year,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with year '%s'."),string_to_set);
@@ -1408,9 +1394,10 @@ Mini_Button_Clicked (GObject *object)
         /* Used of Track and Total Track values */
         string_to_set = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(TrackEntryCombo)))));
         string_to_set1 = gtk_editable_get_chars(GTK_EDITABLE(TrackTotalEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
 
@@ -1420,9 +1407,6 @@ Mini_Button_Clicked (GObject *object)
                 ET_Set_Field_File_Tag_Item(&FileTag->track,string_to_set);
             ET_Set_Field_File_Tag_Item(&FileTag->track_total,string_to_set1);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
 
         if ( string_to_set && g_utf8_strlen(string_to_set, -1) > 0 ) //&& atoi(string_to_set)>0 )
@@ -1499,11 +1483,11 @@ Mini_Button_Clicked (GObject *object)
     else if (object==G_OBJECT(TrackMButtonNbrFiles))
     {
         /* Used of Track and Total Track values */
-        while (etfilelist)
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
             gchar *path_utf8, *filename_utf8;
 
-            etfile        = (ET_File *)etfilelist->data;
+            etfile        = (ET_File *)l->data;
             filename_utf8 = ((File_Name *)etfile->FileNameNew->data)->value_utf8;
             path_utf8     = g_path_get_dirname(filename_utf8);
             if (NUMBER_TRACK_FORMATED)
@@ -1518,9 +1502,6 @@ Mini_Button_Clicked (GObject *object)
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->track_total,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
 
         if ( string_to_set1 != NULL && g_utf8_strlen(string_to_set1, -1)>0 ) //&& atoi(string_to_set1)>0 )
@@ -1534,16 +1515,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (gtk_bin_get_child (GTK_BIN (GenreCombo))))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(GenreCombo))),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->genre,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with genre '%s'."),string_to_set);
@@ -1560,16 +1539,14 @@ Mini_Button_Clicked (GObject *object)
         //string_to_set = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(textbuffer),&start_iter,&end_iter,TRUE);
 
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(CommentEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->comment,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with comment '%s'."),string_to_set);
@@ -1579,16 +1556,13 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (ComposerEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(ComposerEntry),0,-1);
-        while (etfilelist)
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->composer,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with composer '%s'."),string_to_set);
@@ -1598,16 +1572,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (OrigArtistEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(OrigArtistEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->orig_artist,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with original artist '%s'."),string_to_set);
@@ -1617,16 +1589,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (CopyrightEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(CopyrightEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->copyright,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with copyright '%s'."),string_to_set);
@@ -1636,16 +1606,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (URLEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(URLEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->url,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with URL '%s'."),string_to_set);
@@ -1655,16 +1623,14 @@ Mini_Button_Clicked (GObject *object)
     else if (object == G_OBJECT (EncodedByEntry))
     {
         string_to_set = gtk_editable_get_chars(GTK_EDITABLE(EncodedByEntry),0,-1);
-        while (etfilelist)
+
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Item(&FileTag->encoded_by,string_to_set);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
             msg = g_strdup_printf(_("Selected files tagged with encoder name '%s'."),string_to_set);
@@ -1692,16 +1658,13 @@ Mini_Button_Clicked (GObject *object)
             } while (gtk_tree_model_iter_next(model, &iter));
         }
 
-        while (etfilelist)
+        for (l = etfilelist; l != NULL; l = g_list_next (l))
         {
-            etfile = (ET_File *)etfilelist->data;
+            etfile = (ET_File *)l->data;
             FileTag = ET_File_Tag_Item_New();
             ET_Copy_File_Tag_Item(etfile,FileTag);
             ET_Set_Field_File_Tag_Picture((Picture **)&FileTag->picture, res);
             ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
-
-            if (!etfilelist->next) break;
-            etfilelist = g_list_next(etfilelist);
         }
         if (res)
             msg = g_strdup (_("Selected files tagged with images."));
@@ -2050,6 +2013,7 @@ void Action_Scan_Selected_Files (void)
 void Action_Remove_Selected_Tags (void)
 {
     GList *selfilelist = NULL;
+    GList *l;
     ET_File *etfile;
     File_Tag *FileTag;
     gint progress_bar_index;
@@ -2070,9 +2034,10 @@ void Action_Remove_Selected_Tags (void)
 
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
     selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
-    while (selfilelist)
+
+    for (l = selfilelist; l != NULL; l = g_list_next (l))
     {
-        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
+        etfile = Browser_List_Get_ETFile_From_Path (l->data);
         FileTag = ET_File_Tag_Item_New();
         ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
@@ -2081,13 +2046,9 @@ void Action_Remove_Selected_Tags (void)
         /* Needed to refresh status bar */
         while (gtk_events_pending())
             gtk_main_iteration();
-
-        if (!selfilelist->next) break;
-        selfilelist = g_list_next(selfilelist);
     }
 
-    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
-    g_list_free(selfilelist);
+    g_list_free_full (selfilelist, (GDestroyNotify)gtk_tree_path_free);
 
     // Refresh the whole list (faster than file by file) to show changes
     Browser_List_Refresh_Whole_List();
@@ -2110,6 +2071,7 @@ void Action_Remove_Selected_Tags (void)
 gint Action_Undo_Selected_Files (void)
 {
     GList *selfilelist = NULL;
+    GList *l;
     gboolean state = FALSE;
     ET_File *etfile;
     GtkTreeSelection *selection;
@@ -2122,17 +2084,14 @@ gint Action_Undo_Selected_Files (void)
 
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
     selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
-    while (selfilelist)
+
+    for (l = selfilelist; l != NULL; l = g_list_next (l))
     {
-        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
+        etfile = Browser_List_Get_ETFile_From_Path (l->data);
         state |= ET_Undo_File_Data(etfile);
-
-        if (!selfilelist->next) break;
-        selfilelist = g_list_next(selfilelist);
     }
 
-    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
-    g_list_free(selfilelist);
+    g_list_free_full (selfilelist, (GDestroyNotify)gtk_tree_path_free);
 
     // Refresh the whole list (faster than file by file) to show changes
     Browser_List_Refresh_Whole_List();
@@ -2177,6 +2136,7 @@ void Action_Undo_From_History_List (void)
 gint Action_Redo_Selected_File (void)
 {
     GList *selfilelist = NULL;
+    GList *l;
     gboolean state = FALSE;
     ET_File *etfile;
     GtkTreeSelection *selection;
@@ -2189,17 +2149,14 @@ gint Action_Redo_Selected_File (void)
 
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
     selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
-    while (selfilelist)
+
+    for (l = selfilelist; l != NULL; l = g_list_next (l))
     {
-        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
+        etfile = Browser_List_Get_ETFile_From_Path (l->data);
         state |= ET_Redo_File_Data(etfile);
-
-        if (!selfilelist->next) break;
-        selfilelist = g_list_next(selfilelist);
     }
 
-    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
-    g_list_free(selfilelist);
+    g_list_free_full (selfilelist, (GDestroyNotify)gtk_tree_path_free);
 
     // Refresh the whole list (faster than file by file) to show changes
     Browser_List_Refresh_Whole_List();
@@ -2274,6 +2231,7 @@ Save_Selected_Files_With_Answer (gboolean force_saving_files)
     gint toreturn;
     GList *etfilelist = NULL;
     GList *selfilelist = NULL;
+    GList *l;
     ET_File *etfile;
     GtkTreeSelection *selection;
 
@@ -2281,16 +2239,14 @@ Save_Selected_Files_With_Answer (gboolean force_saving_files)
 
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
     selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
-    while (selfilelist)
+
+    for (l = selfilelist; l != NULL; l = g_list_next (l))
     {
-        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
+        etfile = Browser_List_Get_ETFile_From_Path (l->data);
         etfilelist = g_list_append(etfilelist, etfile);
-
-        if (!selfilelist->next) break;
-        selfilelist = selfilelist->next;
     }
-    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
-    g_list_free(selfilelist);
+
+    g_list_free_full (selfilelist, (GDestroyNotify)gtk_tree_path_free);
 
     toreturn = Save_List_Of_Files(etfilelist, force_saving_files);
     g_list_free(etfilelist);
@@ -2519,6 +2475,7 @@ Delete_Selected_Files_With_Answer (void)
 {
     GList *selfilelist;
     GList *rowreflist = NULL;
+    GList *l;
     gint   progress_bar_index;
     gint   saving_answer;
     gint   nb_files_to_delete;
@@ -2557,21 +2514,21 @@ Delete_Selected_Files_With_Answer (void)
 
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
     selfilelist = gtk_tree_selection_get_selected_rows(selection, &treemodel);
-    while (selfilelist)
+
+    for (l = selfilelist; l != NULL; l = g_list_next (l))
     {
-        rowref = gtk_tree_row_reference_new(treemodel, selfilelist->data);
+        rowref = gtk_tree_row_reference_new (treemodel, l->data);
         rowreflist = g_list_append(rowreflist, rowref);
-
-        if (!selfilelist->next) break;
-        selfilelist = selfilelist->next;
     }
 
-    while (rowreflist)
+    g_list_free_full (selfilelist, (GDestroyNotify)gtk_tree_path_free);
+
+    for (l = rowreflist; l != NULL; l = g_list_next (l))
     {
         GtkTreePath *path;
         ET_File *ETFile;
 
-        path = gtk_tree_row_reference_get_path(rowreflist->data);
+        path = gtk_tree_row_reference_get_path (l->data);
         ETFile = Browser_List_Get_ETFile_From_Path(path);
         gtk_tree_path_free(path);
 
@@ -2612,19 +2569,11 @@ Delete_Selected_Files_With_Answer (void)
                 Tag_Area_Set_Sensitive(TRUE);
                 File_Area_Set_Sensitive(TRUE);
 
-                g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
-                g_list_free(selfilelist);
                 return -1; // We stop all actions
         }
-
-        if (!rowreflist->next) break;
-        rowreflist = rowreflist->next;
     }
 
-    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
-    g_list_free(selfilelist);
-    g_list_foreach(rowreflist, (GFunc) gtk_tree_row_reference_free, NULL);
-    g_list_free(rowreflist);
+    g_list_free_full (rowreflist, (GDestroyNotify)gtk_tree_row_reference_free);
 
     if (nb_files_deleted < nb_files_to_delete)
         msg = g_strdup (_("Files have been partially deleted"));


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