[easytag] Refactor GList handling to iterate with for loops
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Refactor GList handling to iterate with for loops
- Date: Wed, 5 Mar 2014 23:49:06 +0000 (UTC)
commit 00a51984865ee079cb27f19c6199a09d40e68c7f
Author: David King <amigadave amigadave com>
Date: Wed Mar 5 22:51:37 2014 +0000
Refactor GList handling to iterate with for loops
src/browser.c | 13 +++++++------
src/easytag.c | 1 +
src/et_core.c | 31 +++++++++++++------------------
src/id3_tag.c | 9 ++++-----
src/id3v24_tag.c | 4 +---
5 files changed, 26 insertions(+), 32 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index 69b66c5..4887b73 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -535,7 +535,7 @@ Browser_List_Button_Press (GtkTreeView *treeView, GdkEventButton *event)
{
/* Double left mouse click */
// Select files of the same directory (useful when browsing sub-directories)
- GList *etfilelist = NULL;
+ GList *l;
gchar *path_ref = NULL;
gchar *patch_check = NULL;
GtkTreePath *currentPath = NULL;
@@ -547,19 +547,20 @@ Browser_List_Button_Press (GtkTreeView *treeView, GdkEventButton *event)
path_ref = g_path_get_dirname( ((File_Name *)ETCore->ETFileDisplayed->FileNameCur->data)->value );
// Search and select files of the same directory
- etfilelist = g_list_first(ETCore->ETFileDisplayedList);
- while (etfilelist)
+ for (l = g_list_first (ETCore->ETFileDisplayedList); l != NULL;
+ l = g_list_next (l))
{
// Path of the file to check if it is in the same directory
- patch_check = g_path_get_dirname( ((File_Name *)((ET_File
*)etfilelist->data)->FileNameCur->data)->value );
+ patch_check = g_path_get_dirname (((File_Name *)((ET_File *)l->data)->FileNameCur->data)->value);
if ( path_ref && patch_check && strcmp(path_ref,patch_check)==0 )
{
// Use of 'currentPath' to try to increase speed. Indeed, in many
// cases, the next file to select, is the next in the list
- currentPath = Browser_List_Select_File_By_Etfile2((ET_File
*)etfilelist->data,TRUE,currentPath);
+ currentPath = Browser_List_Select_File_By_Etfile2 ((ET_File *)l->data,
+ TRUE,
+ currentPath);
}
- etfilelist = g_list_next(etfilelist);
g_free(patch_check);
}
g_free(path_ref);
diff --git a/src/easytag.c b/src/easytag.c
index 7f6ecc7..7355e09 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1500,6 +1500,7 @@ Mini_Button_Clicked (GObject *object)
etfilelist = ET_Sort_File_List(etfilelist,SORTING_FILE_MODE);
etfilelistfull = ET_Sort_File_List(etfilelistfull,SORTING_FILE_MODE);
+ for (l = etfilelist; l != NULL; l = g_list_next (l))
while (etfilelist && etfilelistfull)
{
// To get the path of the file
diff --git a/src/et_core.c b/src/et_core.c
index 8da7103..4dbb1db 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -694,14 +694,13 @@ ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile)
gchar *ETFile_Album = ((File_Tag *)ETFile->FileTag->data)->album; // Album value of the ETFile
passed in parameter
gchar *etfile_artist = NULL;
gchar *etfile_album = NULL;
- GList *ArtistList = NULL;
+ GList *ArtistList;
GList *AlbumList = NULL;
GList *etfilelist = NULL;
ET_File *etfile = NULL;
-
- ArtistList = ETCore->ETArtistAlbumFileList;
- while (ArtistList)
+ for (ArtistList = ETCore->ETArtistAlbumFileList; ArtistList != NULL;
+ ArtistList = g_list_next (ArtistList))
{
AlbumList = (GList *)ArtistList->data; /* Take the first item */
if (AlbumList
@@ -741,7 +740,7 @@ ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile)
AlbumList->data = (gpointer) g_list_sort((GList
*)AlbumList->data,(GCompareFunc)ET_Comp_Func_Sort_Etfile_Item_By_Ascending_Filename);
return TRUE;
}
- AlbumList = AlbumList->next;
+ AlbumList = g_list_next (AlbumList);
}
// The "AlbumList" item was NOT found! => Add a new "AlbumList" item (+...) item to the
"ArtistList" list
etfilelist = g_list_append(NULL,ETFile);
@@ -750,7 +749,6 @@ ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile)
ArtistList->data = (gpointer) g_list_sort((GList
*)ArtistList->data,(GCompareFunc)ET_Comp_Func_Sort_Album_Item_By_Ascending_Album);
return TRUE;
}
- ArtistList = ArtistList->next;
}
// The "ArtistList" item was NOT found! => Add a new "ArtistList" to the main list
(=ETArtistAlbumFileList)
etfilelist = g_list_append(NULL,ETFile);
@@ -2029,12 +2027,11 @@ GList *ET_Displayed_File_List_By_Etfile (ET_File *ETFile)
{
GList *etfilelist;
- etfilelist = ET_Displayed_File_List_First();
- while (ETFile && etfilelist)
+ for (etfilelist = ET_Displayed_File_List_First (); etfilelist != NULL;
+ etfilelist = ET_Displayed_File_List_Next ())
{
- if ( ETFile == (ET_File *)etfilelist->data )
+ if (ETFile == (ET_File *)etfilelist->data)
break;
- etfilelist = ET_Displayed_File_List_Next();
}
ETCore->ETFileDisplayedList = etfilelist; // To "save" the position like in ET_File_List_Next... (not
very good - FIX ME)
return etfilelist;
@@ -3125,10 +3122,9 @@ ET_Display_File_Tag_To_UI (ET_File *ETFile)
PictureEntry_Update(FileTag->picture, FALSE);
// Count the number of items
- while (pic)
+ for (pic = FileTag->picture; pic != NULL; pic = pic->next)
{
nbr_pic++;
- pic = pic->next;
}
// Get page "Images" of the notebook
@@ -4058,12 +4054,13 @@ void ET_Update_Directory_Name_Into_File_List (gchar* last_path, gchar *new_path)
else
last_path_tmp = g_strconcat(last_path,G_DIR_SEPARATOR_S,NULL);
- filelist = g_list_first(ETCore->ETFileList);
- while (filelist)
+ for (filelist = g_list_first (ETCore->ETFileList); filelist != NULL;
+ filelist = g_list_next (filelist))
{
- if ( (file=filelist->data) && (filenamelist=file->FileNameList) )
+ if ((file = filelist->data))
{
- while (filenamelist)
+ for (filenamelist = file->FileNameList; filenamelist != NULL;
+ filenamelist = g_list_next (filenamelist))
{
File_Name *FileName = (File_Name *)filenamelist->data;
@@ -4090,10 +4087,8 @@ void ET_Update_Directory_Name_Into_File_List (gchar* last_path, gchar *new_path)
FileName->value_ck = g_utf8_collate_key_for_filename(FileName->value_utf8, -1);
}
}
- filenamelist = g_list_next(filenamelist);
}
}
- filelist = g_list_next(filelist);
}
g_free(last_path_tmp);
diff --git a/src/id3_tag.c b/src/id3_tag.c
index f6e8abf..b2cb847 100644
--- a/src/id3_tag.c
+++ b/src/id3_tag.c
@@ -433,10 +433,10 @@ Id3tag_Write_File_v23Tag (ET_File *ETFile)
***********/
while ( (id3_frame = ID3Tag_FindFrameWithID(id3_tag,ID3FID_PICTURE)) )
ID3Tag_RemoveFrame(id3_tag,id3_frame);
- pic = FileTag->picture;
- if (!pic)
- has_picture = 0;
- while (pic)
+
+ has_picture = FALSE;
+
+ for (pic = FileTag->picture; pic != NULL; pic = pic->next)
{
Picture_Format format = Picture_Format_From_Data(pic);
@@ -471,7 +471,6 @@ Id3tag_Write_File_v23Tag (ET_File *ETFile)
if ((id3_field = ID3Frame_GetField(id3_frame,ID3FN_DATA)))
ID3Field_SetBINARY(id3_field, pic->data, pic->size);
- pic = pic->next;
has_picture = TRUE;
}
diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index 52b079e..9324ef2 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -991,8 +991,7 @@ gboolean Id3tag_Write_File_v24Tag (ET_File *ETFile)
if (v2tag)
{
- pic = FileTag->picture;
- while (pic)
+ for (pic = FileTag->picture; pic != NULL; pic = pic->next)
{
gint i;
@@ -1025,7 +1024,6 @@ gboolean Id3tag_Write_File_v24Tag (ET_File *ETFile)
id3taglib_set_field(frame, pic->description, ID3_FIELD_TYPE_STRING, 0, 0, 0);
strip_tags = FALSE;
- pic = pic->next;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]