[easytag/wip/core-refactoring: 18/24] Refactor file list freeing functions



commit e9225a10b223f6ac1a5ffb9e15c882b273846373
Author: David King <amigadave amigadave com>
Date:   Mon Jan 5 22:48:49 2015 +0000

    Refactor file list freeing functions
    
    Accept the list to be freed as a parameter. Zero out the list pointer in
    ET_Core_Free() instead of in the list freeing functions.

 src/et_core.c   |   20 +++++++++++++---
 src/file_list.c |   64 +++++++++++++++++++-----------------------------------
 src/file_list.h |    8 +++---
 3 files changed, 43 insertions(+), 49 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index ebe33c0..6e11fb2 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -47,16 +47,28 @@ ET_Core_Free (void)
 
     /* First frees lists. */
     if (ETCore->ETFileList)
-        ET_Free_File_List();
+    {
+        et_file_list_free (ETCore->ETFileList);
+        ETCore->ETFileList = NULL;
+    }
 
     if (ETCore->ETFileDisplayedList)
-        ET_Free_Displayed_File_List();
+    {
+        et_displayed_file_list_free (ETCore->ETFileDisplayedList);
+        ETCore->ETFileDisplayedList = NULL;
+    }
 
     if (ETCore->ETHistoryFileList)
-        ET_Free_History_File_List();
+    {
+        et_history_file_list_free (ETCore->ETHistoryFileList);
+        ETCore->ETHistoryFileList = NULL;
+    }
 
     if (ETCore->ETArtistAlbumFileList)
-        ET_Free_Artist_Album_File_List();
+    {
+        et_artist_album_file_list_free (ETCore->ETArtistAlbumFileList);
+        ETCore->ETArtistAlbumFileList = NULL;
+    }
 
     if (ETCore)
     {
diff --git a/src/file_list.c b/src/file_list.c
index 0c4b946..be60040 100644
--- a/src/file_list.c
+++ b/src/file_list.c
@@ -62,18 +62,17 @@
 #endif
 
 /*
- * Frees the full main list of files: GList *ETFileList and reinitialize it.
+ * et_file_list_free:
+ * @file_list: (element-type ET_File) (allow-none): a list of files
+ *
+ * Frees the full list of files.
  */
-gboolean
-ET_Free_File_List (void)
+void
+et_file_list_free (GList *file_list)
 {
-    g_return_val_if_fail (ETCore != NULL && ETCore->ETFileList != NULL, FALSE);
+    g_return_if_fail (file_list != NULL);
 
-    g_list_free_full (ETCore->ETFileList,
-                      (GDestroyNotify)ET_Free_File_List_Item);
-    ETCore->ETFileList = NULL;
-
-    return TRUE;
+    g_list_free_full (file_list, (GDestroyNotify)ET_Free_File_List_Item);
 }
 
 static void
@@ -85,53 +84,38 @@ et_history_file_free (ET_History_File *file)
 /*
  * History list contains only pointers, so no data to free except the history structure.
  */
-gboolean
-ET_Free_History_File_List (void)
+void
+et_history_file_list_free (GList *file_list)
 {
-    g_return_val_if_fail (ETCore != NULL && ETCore->ETHistoryFileList != NULL,
-                          FALSE);
-
-    ETCore->ETHistoryFileList = g_list_first (ETCore->ETHistoryFileList);
-
-    g_list_free_full (ETCore->ETHistoryFileList,
-                      (GDestroyNotify)et_history_file_free);
+    g_return_if_fail (file_list != NULL);
 
-    ETCore->ETHistoryFileList = NULL;
-
-    return TRUE;
+    g_list_free_full (file_list, (GDestroyNotify)et_history_file_free);
 }
 
 /*
  * "Display" list contains only pointers, so NOTHING to free
  */
-gboolean
-ET_Free_Displayed_File_List (void)
+void
+et_displayed_file_list_free (GList *file_list)
 {
-    g_return_val_if_fail (ETCore != NULL
-                          && ETCore->ETFileDisplayedList != NULL, FALSE);
-
-    ETCore->ETFileDisplayedList = NULL;
-
-    return TRUE;
 }
 
 /*
  * ArtistAlbum list contains 3 levels of lists
  */
-gboolean
-ET_Free_Artist_Album_File_List (void)
+void
+et_artist_album_file_list_free (GList *file_list)
 {
     GList *l;
 
-    g_return_val_if_fail (ETCore != NULL
-                          && ETCore->ETArtistAlbumFileList != NULL, FALSE);
+    g_return_if_fail (file_list != NULL);
 
     /* Pointers are stored inside the artist/album list-stores, so free them
      * first. */
     et_application_window_browser_clear_artist_model (ET_APPLICATION_WINDOW (MainWindow));
     et_application_window_browser_clear_album_model (ET_APPLICATION_WINDOW (MainWindow));
 
-    for (l = ETCore->ETArtistAlbumFileList; l != NULL; l = g_list_next (l))
+    for (l = file_list; l != NULL; l = g_list_next (l))
     {
         GList *m;
 
@@ -146,12 +130,7 @@ ET_Free_Artist_Album_File_List (void)
             g_list_free ((GList *)l->data);
     }
 
-    if (ETCore->ETArtistAlbumFileList)
-        g_list_free(ETCore->ETArtistAlbumFileList);
-
-    ETCore->ETArtistAlbumFileList = NULL;
-
-    return TRUE;
+    g_list_free (file_list);
 }
 
 /* Key for each item of ETFileList */
@@ -679,7 +658,10 @@ ET_Create_Artist_Album_File_List (void)
     GList *l;
 
     if (ETCore->ETArtistAlbumFileList)
-        ET_Free_Artist_Album_File_List();
+    {
+        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))
     {
diff --git a/src/file_list.h b/src/file_list.h
index 5ec7cbc..8bc9c06 100644
--- a/src/file_list.h
+++ b/src/file_list.h
@@ -29,10 +29,10 @@ G_BEGIN_DECLS
 
 GList * ET_Add_File_To_File_List (gchar *filename);
 gboolean ET_Remove_File_From_File_List (ET_File *ETFile);
-gboolean ET_Free_File_List (void);
+void et_file_list_free (GList *file_list);
 
 gboolean ET_Create_Artist_Album_File_List (void);
-gboolean ET_Free_Artist_Album_File_List (void);
+void et_artist_album_file_list_free (GList *file_list);
 
 gboolean et_file_list_check_all_saved (GList *etfilelist);
 
@@ -43,14 +43,14 @@ GList * ET_Displayed_File_List_Last (void);
 GList * ET_Displayed_File_List_By_Etfile (const ET_File *ETFile);
 
 gboolean ET_Set_Displayed_File_List (GList *ETFileList);
-gboolean ET_Free_Displayed_File_List (void);
+void et_displayed_file_list_free (GList *file_list);
 
 gboolean ET_Add_File_To_History_List (ET_File *ETFile);
 ET_File * ET_Undo_History_File_Data (void);
 ET_File * ET_Redo_History_File_Data (void);
 gboolean ET_History_File_List_Has_Undo_Data (void);
 gboolean ET_History_File_List_Has_Redo_Data (void);
-gboolean ET_Free_History_File_List (void);
+void et_history_file_list_free (GList *file_list);
 
 void ET_Update_Directory_Name_Into_File_List (const gchar *last_path, const gchar *new_path);
 guint ET_Get_Number_Of_Files_In_Directory (const gchar *path_utf8);


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