[easytag] Refactor and rename ET_File_Name_Generate()



commit 953914f2c31f38107019d7beb3d05342b0df706d
Author: David King <amigadave amigadave com>
Date:   Tue Jun 7 08:56:01 2016 +0100

    Refactor and rename ET_File_Name_Generate()
    
    Rename ET_File_Name_Generate() to et_file_generate_name(). Use
    g_return_val_if_fail() for invariant checks.

 src/cddb_dialog.c       |    5 ++-
 src/file.c              |   61 ++++++++++++++++++++++++++++------------------
 src/file.h              |    2 +-
 src/load_files_dialog.c |    2 +-
 src/scan_dialog.c       |    5 ++-
 5 files changed, 45 insertions(+), 30 deletions(-)
---
diff --git a/src/cddb_dialog.c b/src/cddb_dialog.c
index be688d9..2cb9958 100644
--- a/src/cddb_dialog.c
+++ b/src/cddb_dialog.c
@@ -2483,7 +2483,7 @@ Cddb_Set_Track_Infos_To_File_List (EtCDDBDialog *self)
                 et_filename_prepare (filename_generated_utf8,
                                      g_settings_get_boolean (MainSettings,
                                                              "rename-replace-illegal-chars"));
-                filename_new_utf8 = ET_File_Name_Generate (etfile,
+                filename_new_utf8 = et_file_generate_name (etfile,
                                                            filename_generated_utf8);
 
                 ET_Set_Filename_File_Name_Item(FileName,filename_new_utf8,NULL);
@@ -2615,7 +2615,8 @@ Cddb_Set_Track_Infos_To_File_List (EtCDDBDialog *self)
                 et_filename_prepare (filename_generated_utf8,
                                      g_settings_get_boolean (MainSettings,
                                                              "rename-replace-illegal-chars"));
-                filename_new_utf8 = ET_File_Name_Generate(etfile,filename_generated_utf8);
+                filename_new_utf8 = et_file_generate_name (etfile,
+                                                           filename_generated_utf8);
 
                 ET_Set_Filename_File_Name_Item(FileName,filename_new_utf8,NULL);
 
diff --git a/src/file.c b/src/file.c
index 041d613..773847c 100644
--- a/src/file.c
+++ b/src/file.c
@@ -1734,24 +1734,26 @@ void ET_Mark_File_Name_As_Saved (ET_File *ETFile)
 }
 
 /*
+ * et_file_generate_name:
+ * @ETFile: the file from which to read the existing name
+ * @new_file_name_utf8: UTF-8 encoded new filename
+ *
  * This function generates a new filename using path of the old file and the
  * new name.
- * - ETFile -> old_file_name : "/path_to_file/old_name.ext"
- * - new_file_name_utf8      : "new_name.ext"
- * Returns "/path_to_file/new_name.ext" into allocated data (in UTF-8)!
- * Notes :
- *   - filenames (basemane) musn't exceed 255 characters (i.e. : "new_name.ext")
- *   - ogg filename musn't exceed 255-6 characters as we use mkstemp
+ *
+ * Returns: a newly-allocated filename, in UTF-8
  */
 #if 1
 gchar *
-ET_File_Name_Generate (const ET_File *ETFile,
+et_file_generate_name (const ET_File *ETFile,
                        const gchar *new_file_name_utf8)
 {
     gchar *dirname_utf8;
 
-    if (ETFile && ETFile->FileNameNew->data && new_file_name_utf8
-    && (dirname_utf8=g_path_get_dirname(((File_Name *)ETFile->FileNameNew->data)->value_utf8)) )
+    g_return_val_if_fail (ETFile && ETFile->FileNameNew->data, NULL);
+    g_return_val_if_fail (new_file_name_utf8, NULL);
+
+    if ((dirname_utf8 = g_path_get_dirname (((File_Name *)ETFile->FileNameNew->data)->value_utf8)))
     {
         gchar *extension;
         gchar *new_file_name_path_utf8;
@@ -1762,32 +1764,43 @@ ET_File_Name_Generate (const ET_File *ETFile,
         // Check length of filename (limit ~255 characters)
         //ET_File_Name_Check_Length(ETFile,new_file_name_utf8);
 
-        // If filemame starts with /, it's a full filename with path but without extension
-        if (g_path_is_absolute(new_file_name_utf8))
+        if (g_path_is_absolute (new_file_name_utf8))
         {
-            // We just add the extension
-            new_file_name_path_utf8 = g_strconcat(new_file_name_utf8,extension,NULL);
-        }else
+            /* Just add the extension. */
+            new_file_name_path_utf8 = g_strconcat (new_file_name_utf8,
+                                                   extension, NULL);
+        }
+        else
         {
-            // New path (with filename)
-            if ( strcmp(dirname_utf8,G_DIR_SEPARATOR_S)==0 ) // Root directory?
-                new_file_name_path_utf8 = g_strconcat(dirname_utf8,new_file_name_utf8,extension,NULL);
+            /* New path (with filename). */
+            if (strcmp (dirname_utf8, G_DIR_SEPARATOR_S) == 0)
+            {
+                /* Root directory. */
+                new_file_name_path_utf8 = g_strconcat (dirname_utf8,
+                                                       new_file_name_utf8,
+                                                       extension, NULL);
+            }
             else
-                new_file_name_path_utf8 = 
g_strconcat(dirname_utf8,G_DIR_SEPARATOR_S,new_file_name_utf8,extension,NULL);
+            {
+                new_file_name_path_utf8 = g_strconcat (dirname_utf8,
+                                                       G_DIR_SEPARATOR_S,
+                                                       new_file_name_utf8,
+                                                       extension, NULL);
+            }
         }
 
         g_free (dirname_utf8);
-        g_free(extension);
-        return new_file_name_path_utf8; // in UTF-8
-    }else
-    {
-        return NULL;
+        g_free (extension);
+
+        return new_file_name_path_utf8;
     }
+
+    return NULL;
 }
 #else
 /* FOR TESTING */
 /* Returns filename in file system encoding */
-gchar *ET_File_Name_Generate (ET_File *ETFile, gchar *new_file_name_utf8)
+gchar *et_file_generate_name (ET_File *ETFile, gchar *new_file_name_utf8)
 {
     gchar *dirname;
 
diff --git a/src/file.h b/src/file.h
index 7f23df8..12b4ec8 100644
--- a/src/file.h
+++ b/src/file.h
@@ -79,7 +79,7 @@ gboolean ET_File_Data_Has_Redo_Data (const ET_File *ETFile);
 
 gboolean ET_Manage_Changes_Of_File_Data (ET_File *ETFile, File_Name *FileName, File_Tag *FileTag);
 void ET_Mark_File_Name_As_Saved (ET_File *ETFile);
-gchar *ET_File_Name_Generate (const ET_File *ETFile, const gchar *new_file_name);
+gchar *et_file_generate_name (const ET_File *ETFile, const gchar *new_file_name);
 gchar * ET_File_Format_File_Extension (const ET_File *ETFile);
 
 gint ET_Comp_Func_Sort_File_By_Ascending_Filename (const ET_File *ETFile1, const ET_File *ETFile2);
diff --git a/src/load_files_dialog.c b/src/load_files_dialog.c
index 8b70e16..6b3e982 100644
--- a/src/load_files_dialog.c
+++ b/src/load_files_dialog.c
@@ -123,7 +123,7 @@ Load_Filename_Set_Filenames (EtLoadFilesDialog *self)
                                                          "rename-replace-illegal-chars"));
 
             /* Build the filename with the path */
-            filename_new_utf8 = ET_File_Name_Generate(ETFile,list_text_tmp);
+            filename_new_utf8 = et_file_generate_name (ETFile, list_text_tmp);
             g_free(list_text_tmp);
 
             /* Set the new filename */
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 9ecfe7c..e4b096b 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -832,7 +832,8 @@ Scan_Rename_File_With_Mask (EtScanDialog *self, ET_File *ETFile)
     }
 
     /* Build the filename with the full path or relative to old path */
-    filename_new_utf8 = ET_File_Name_Generate(ETFile,filename_generated_utf8);
+    filename_new_utf8 = et_file_generate_name (ETFile,
+                                               filename_generated_utf8);
     g_free(filename_generated);
     g_free(filename_generated_utf8);
 
@@ -1355,7 +1356,7 @@ Scan_Process_Fields (EtScanDialog *self, ET_File *ETFile)
 
             Scan_Process_Fields_Functions (self, &string);
 
-            string_utf8 = ET_File_Name_Generate(ETFile,string);
+            string_utf8 = et_file_generate_name (ETFile, string);
             ET_Set_Filename_File_Name_Item(FileName,string_utf8,NULL);
             g_free(string_utf8);
             g_free(string);


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