[easytag/wip/glist: 1/2] Refactor list handling in misc.c
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/glist: 1/2] Refactor list handling in misc.c
- Date: Thu, 23 May 2013 23:05:29 +0000 (UTC)
commit c109e854314e96f4a8a459ee5deecd8a8dcd0ad9
Author: David King <amigadave amigadave com>
Date: Wed May 22 22:24:57 2013 +0100
Refactor list handling in misc.c
src/misc.c | 105 +++++++++++++++++++++--------------------------------------
1 files changed, 38 insertions(+), 67 deletions(-)
---
diff --git a/src/misc.c b/src/misc.c
index f0da2d5..afbb60f 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -905,6 +905,7 @@ void Run_Audio_Player_Using_Selection (void)
{
GList *etfilelist = NULL;
GList *selfilelist = NULL;
+ GList *l;
ET_File *etfile;
GtkTreeSelection *selection;
@@ -912,17 +913,15 @@ void Run_Audio_Player_Using_Selection (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);
- etfilelist = g_list_append(etfilelist, etfile);
-
- if (!selfilelist->next) break;
- selfilelist = selfilelist->next;
+ etfilelist = g_list_prepend (etfilelist, etfile);
}
- g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
- g_list_free(selfilelist);
+ etfilelist = g_list_reverse (etfilelist);
+ g_list_free_full (selfilelist, (GDestroyNotify)gtk_tree_path_free);
Run_Audio_Player_Using_File_List(etfilelist);
@@ -947,14 +946,12 @@ void Run_Audio_Player_Using_Browser_Artist_List (void)
ARTIST_ALBUM_LIST_POINTER, &AlbumList,
-1);
- while (AlbumList)
+ for (; AlbumList != NULL; AlbumList = g_list_next (AlbumList))
{
etfilelist = g_list_copy((GList *)AlbumList->data);
- if (!concatenated_list)
- concatenated_list = etfilelist;
- else
- concatenated_list = g_list_concat(concatenated_list,etfilelist);
- AlbumList = AlbumList->next;
+ concatenated_list = concatenated_list ? g_list_concat (concatenated_list,
+ etfilelist)
+ : etfilelist;
}
Run_Audio_Player_Using_File_List(concatenated_list);
@@ -1637,20 +1634,20 @@ write_playlist (GFile *file, GError **error)
if (PLAYLIST_ONLY_SELECTED_FILES)
{
GList *selfilelist = NULL;
+ GList *l;
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
- while (selfilelist)
- {
- etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
- etfilelist = g_list_append(etfilelist, etfile);
- if (!selfilelist->next) break;
- selfilelist = selfilelist->next;
+ for (l = selfilelist; l != NULL; l = g_list_next (l))
+ {
+ etfile = Browser_List_Get_ETFile_From_Path (l->data);
+ etfilelist = g_list_prepend (etfilelist, etfile);
}
- g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
- g_list_free(selfilelist);
+ etfilelist = g_list_reverse (etfilelist);
+
+ g_list_free_full (selfilelist, (GDestroyNotify)gtk_tree_path_free);
}else
{
etfilelist = g_list_first(ETCore->ETFileList);
@@ -2627,29 +2624,25 @@ static void
Search_Result_List_Row_Selected (GtkTreeSelection *selection, gpointer data)
{
GList *selectedRows;
- GList *selectedRowsCopy;
+ GList *l;
ET_File *ETFile;
GtkTreeIter currentFile;
- gboolean found;
selectedRows = gtk_tree_selection_get_selected_rows(selection, NULL);
- selectedRowsCopy = selectedRows;
/* We might be called with no rows selected */
- if (g_list_length(selectedRows) == 0)
+ if (!selectedRows)
{
- g_list_foreach(selectedRowsCopy, (GFunc) gtk_tree_path_free, NULL);
- g_list_free(selectedRowsCopy);
return;
}
// Unselect files in the main list before re-selecting them...
Browser_List_Unselect_All_Files();
- while (selectedRows)
+ for (l = selectedRows; l != NULL; l = g_list_next (l))
{
- found = gtk_tree_model_get_iter(GTK_TREE_MODEL(SearchResultListModel), ¤tFile,
(GtkTreePath*)selectedRows->data);
- if (found)
+ if (gtk_tree_model_get_iter (GTK_TREE_MODEL (SearchResultListModel),
+ ¤tFile, (GtkTreePath *)l->data))
{
gtk_tree_model_get(GTK_TREE_MODEL(SearchResultListModel), ¤tFile,
SEARCH_RESULT_POINTER, &ETFile, -1);
@@ -2659,11 +2652,9 @@ Search_Result_List_Row_Selected (GtkTreeSelection *selection, gpointer data)
if (!selectedRows->next)
Action_Select_Nth_File_By_Etfile(ETFile);
}
- selectedRows = selectedRows->next;
}
- g_list_foreach(selectedRowsCopy, (GFunc) gtk_tree_path_free, NULL);
- g_list_free(selectedRowsCopy);
+ g_list_free_full (selectedRows, (GDestroyNotify)gtk_tree_path_free);
}
@@ -3514,12 +3505,11 @@ Load_Filename_List_Move_Up (GtkWidget *treeview)
{
GtkTreeSelection *selection;
GList *selectedRows;
- GList *selectedRowsCopy;
+ GList *l;
GtkTreeIter currentFile;
GtkTreeIter nextFile;
GtkTreePath *currentPath;
GtkTreeModel *treemodel;
- gboolean valid;
g_return_if_fail (treeview != NULL);
@@ -3527,20 +3517,16 @@ Load_Filename_List_Move_Up (GtkWidget *treeview)
treemodel = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
selectedRows = gtk_tree_selection_get_selected_rows(selection, NULL);
- if (g_list_length(selectedRows) == 0)
+ if (!selectedRows)
{
- g_list_foreach(selectedRows, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selectedRows);
return;
}
- selectedRowsCopy = selectedRows;
-
- while (selectedRows)
+ for (l = selectedRows; l != NULL; l = g_list_next (l))
{
- currentPath = (GtkTreePath*) selectedRows->data;
- valid = gtk_tree_model_get_iter(treemodel, ¤tFile, currentPath);
- if (valid)
+ currentPath = (GtkTreePath *)l->data;
+
+ if (gtk_tree_model_get_iter (treemodel, ¤tFile, currentPath))
{
// Find the entry above the node...
if (gtk_tree_path_prev(currentPath))
@@ -3550,14 +3536,9 @@ Load_Filename_List_Move_Up (GtkWidget *treeview)
gtk_list_store_swap(GTK_LIST_STORE(treemodel), ¤tFile, &nextFile);
}
}
-
- selectedRows = selectedRows->next;
- if (!selectedRows) break;
}
- g_list_foreach(selectedRowsCopy, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selectedRowsCopy);
-
+ g_list_free_full (selectedRows, (GDestroyNotify)gtk_tree_path_free);
}
/*
@@ -3568,12 +3549,11 @@ Load_Filename_List_Move_Down (GtkWidget *treeview)
{
GtkTreeSelection *selection;
GList *selectedRows;
- GList *selectedRowsCopy;
+ GList *l;
GtkTreeIter currentFile;
GtkTreeIter nextFile;
GtkTreePath *currentPath;
GtkTreeModel *treemodel;
- gboolean valid;
g_return_if_fail (treeview != NULL);
@@ -3581,34 +3561,25 @@ Load_Filename_List_Move_Down (GtkWidget *treeview)
treemodel = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
selectedRows = gtk_tree_selection_get_selected_rows(selection, NULL);
- if (g_list_length(selectedRows) == 0)
+ if (!selectedRows)
{
- g_list_foreach(selectedRows, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selectedRows);
return;
}
- selectedRowsCopy = selectedRows;
-
- while (selectedRows)
+ for (l = selectedRows; l != NULL; l = g_list_next (l))
{
- currentPath = (GtkTreePath*) selectedRows->data;
- valid = gtk_tree_model_get_iter(treemodel, ¤tFile, currentPath);
- if (valid)
+ currentPath = (GtkTreePath *)l->data;
+
+ if (gtk_tree_model_get_iter (treemodel, ¤tFile, currentPath))
{
// Find the entry below the node and swap the two nodes by iter
gtk_tree_path_next(currentPath);
if (gtk_tree_model_get_iter(treemodel, &nextFile, currentPath))
gtk_list_store_swap(GTK_LIST_STORE(treemodel), ¤tFile, &nextFile);
}
-
- if (!selectedRows->next) break;
- selectedRows = selectedRows->next;
}
- g_list_foreach(selectedRowsCopy, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(selectedRowsCopy);
-
+ g_list_free_full (selectedRows, (GDestroyNotify)gtk_tree_path_free);
}
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]