[easytag/wip/core-refactoring: 4/7] Refactor artist album file list functions
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/core-refactoring: 4/7] Refactor artist album file list functions
- Date: Thu, 8 Jan 2015 20:04:23 +0000 (UTC)
commit 0b5f299da7f40463a60b925611c9f0f37247f048
Author: David King <amigadave amigadave com>
Date: Mon Jan 5 23:24:14 2015 +0000
Refactor artist album file list functions
Take a file list as the first parameter.
src/browser.c | 7 ++++++-
src/file_list.c | 42 +++++++++++++++++++-----------------------
src/file_list.h | 3 +--
3 files changed, 26 insertions(+), 26 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index 6344474..f05c0ca 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -2755,7 +2755,12 @@ et_browser_set_display_mode (EtBrowser *self,
case ET_BROWSER_MODE_ARTIST:
/* Display Artist + Album lists. */
gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 1);
- ET_Create_Artist_Album_File_List ();
+ if (ETCore->ETArtistAlbumFileList)
+ {
+ et_artist_album_file_list_free (ETCore->ETArtistAlbumFileList);
+ }
+
+ ETCore->ETArtistAlbumFileList = et_artist_album_list_new_from_file_list (ETCore->ETFileList);
Browser_Artist_List_Load_Files (self, etfile);
break;
default:
diff --git a/src/file_list.c b/src/file_list.c
index 0542c43..a3c82e0 100644
--- a/src/file_list.c
+++ b/src/file_list.c
@@ -552,8 +552,9 @@ ET_Comp_Func_Sort_Etfile_Item_By_Ascending_Filename (const ET_File *ETFile1,
* - "AlbumList" list is a list of ETFile items.
* Note : use the function ET_Debug_Print_Artist_Album_List(...) to understand how it works, it needed...
*/
-static gboolean
-ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile)
+static GList *
+et_artist_album_list_add_file (GList *file_list,
+ ET_File *ETFile)
{
const gchar *ETFile_Artist;
const gchar *ETFile_Album;
@@ -564,14 +565,14 @@ ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile)
GList *etfilelist = NULL;
ET_File *etfile = NULL;
- g_return_val_if_fail (ETFile != NULL, FALSE);
+ g_return_if_fail (ETFile != NULL);
/* Album value of the ETFile passed in parameter. */
ETFile_Album = ((File_Tag *)ETFile->FileTag->data)->album;
/* Artist value of the ETFile passed in parameter. */
ETFile_Artist = ((File_Tag *)ETFile->FileTag->data)->artist;
- for (ArtistList = ETCore->ETArtistAlbumFileList; ArtistList != NULL;
+ for (ArtistList = file_list; ArtistList != NULL;
ArtistList = g_list_next (ArtistList))
{
AlbumList = (GList *)ArtistList->data; /* Take the first item */
@@ -616,7 +617,7 @@ ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile)
ETFile);
AlbumList->data = g_list_sort ((GList *)AlbumList->data,
(GCompareFunc)ET_Comp_Func_Sort_Etfile_Item_By_Ascending_Filename);
- return TRUE;
+ return file_list;
}
AlbumList = g_list_next (AlbumList);
@@ -629,7 +630,7 @@ ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile)
etfilelist);
ArtistList->data = g_list_sort ((GList *)ArtistList->data,
(GCompareFunc)ET_Comp_Func_Sort_Album_Item_By_Ascending_Album);
- return TRUE;
+ return file_list;
}
}
@@ -637,34 +638,29 @@ ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile)
* main list (=ETArtistAlbumFileList). */
etfilelist = g_list_append (NULL, ETFile);
AlbumList = g_list_append (NULL, etfilelist);
- ETCore->ETArtistAlbumFileList = g_list_append (ETCore->ETArtistAlbumFileList,
- AlbumList);
+ file_list = g_list_append (file_list, AlbumList);
/* Sort the list by ascending Artist. */
- ETCore->ETArtistAlbumFileList = g_list_sort (ETCore->ETArtistAlbumFileList,
-
(GCompareFunc)ET_Comp_Func_Sort_Artist_Item_By_Ascending_Artist);
+ /* TODO: Use g_list_insert_sorted() instead. */
+ file_list = g_list_sort (file_list,
+ (GCompareFunc)ET_Comp_Func_Sort_Artist_Item_By_Ascending_Artist);
- return TRUE;
+ return file_list;
}
-gboolean
-ET_Create_Artist_Album_File_List (void)
+GList *
+et_artist_album_list_new_from_file_list (GList *file_list)
{
+ GList *result = NULL;
GList *l;
- if (ETCore->ETArtistAlbumFileList)
- {
- et_artist_album_file_list_free (ETCore->ETArtistAlbumFileList);
- ETCore->ETArtistAlbumFileList = NULL;
- }
-
- for (l = g_list_first (ETCore->ETFileList); l != NULL; l = g_list_next (l))
+ for (l = g_list_first (file_list); l != NULL; l = g_list_next (l))
{
ET_File *ETFile = (ET_File *)l->data;
- ET_Add_File_To_Artist_Album_File_List(ETFile);
+ result = et_artist_album_list_add_file (result, ETFile);
}
- //ET_Debug_Print_Artist_Album_List(__FILE__,__LINE__,__FUNCTION__);
- return TRUE;
+
+ return result;
}
/*
diff --git a/src/file_list.h b/src/file_list.h
index e157d8c..2d5a44f 100644
--- a/src/file_list.h
+++ b/src/file_list.h
@@ -31,9 +31,8 @@ GList * ET_Add_File_To_File_List (gchar *filename);
gboolean ET_Remove_File_From_File_List (ET_File *ETFile);
void et_file_list_free (GList *file_list);
-gboolean ET_Create_Artist_Album_File_List (void);
+GList * et_artist_album_list_new_from_file_list (GList *file_list);
void et_artist_album_file_list_free (GList *file_list);
-gboolean ET_Remove_File_From_File_List (ET_File *ETFile);
gboolean et_file_list_check_all_saved (GList *etfilelist);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]