[easytag] Move File_Name to a separate file
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Move File_Name to a separate file
- Date: Fri, 13 Feb 2015 21:24:23 +0000 (UTC)
commit d9ce201e78e42993c7bac186fbd109fd801c2ee7
Author: David King <amigadave amigadave com>
Date: Fri Feb 13 18:24:37 2015 +0000
Move File_Name to a separate file
Makefile.am | 2 +
src/cddb_dialog.c | 8 +-
src/file.c | 157 +++++-----------------------------------------
src/file.h | 16 +-----
src/file_list.c | 4 +-
src/file_name.c | 126 +++++++++++++++++++++++++++++++++++++
src/file_name.h | 45 +++++++++++++
src/load_files_dialog.c | 2 +-
src/scan_dialog.c | 6 +-
src/tags/flac_tag.c | 2 +-
src/tags/id3_tag.c | 2 +-
11 files changed, 203 insertions(+), 167 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 3b3b948..4d36340 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -53,6 +53,7 @@ easytag_SOURCES = \
src/file_description.c \
src/file_info.c \
src/file_list.c \
+ src/file_name.c \
src/file_tag.c \
src/load_files_dialog.c \
src/log.c \
@@ -113,6 +114,7 @@ easytag_headers = \
src/file_description.h \
src/file_info.h \
src/file_list.h \
+ src/file_name.h \
src/file_tag.h \
src/genres.h \
src/load_files_dialog.h \
diff --git a/src/cddb_dialog.c b/src/cddb_dialog.c
index 8b96939..c87e891 100644
--- a/src/cddb_dialog.c
+++ b/src/cddb_dialog.c
@@ -2447,8 +2447,8 @@ Cddb_Set_Track_Infos_To_File_List (EtCDDBDialog *self)
gchar *filename_generated_utf8;
gchar *filename_new_utf8;
- // Allocation of a new FileName
- FileName = ET_File_Name_Item_New();
+ /* Allocation of a new FileName. */
+ FileName = et_file_name_new ();
/* Build the filename with the path. */
track_number = et_track_number_to_string (cddbtrackalbum->track_number);
@@ -2578,8 +2578,8 @@ Cddb_Set_Track_Infos_To_File_List (EtCDDBDialog *self)
gchar *filename_generated_utf8;
gchar *filename_new_utf8;
- // Allocation of a new FileName
- FileName = ET_File_Name_Item_New();
+ /* Allocation of a new FileName. */
+ FileName = et_file_name_new ();
/* Build the filename with the path. */
track_number = et_track_number_to_string (cddbtrackalbum->track_number);
diff --git a/src/file.c b/src/file.c
index 96ec534..eaa722a 100644
--- a/src/file.c
+++ b/src/file.c
@@ -70,9 +70,6 @@
static gboolean ET_Free_File_Name_List (GList *FileNameList);
static gboolean ET_Free_File_Tag_List (GList *FileTagList);
-static void ET_Free_File_Name_Item (File_Name *FileName);
-
-static void ET_Initialize_File_Name_Item (File_Name *FileName);
static void ET_Display_Filename_To_UI (const ET_File *ETFile);
static EtFileHeaderFields * ET_Display_File_Info_To_UI (const ET_File *ETFile);
@@ -82,26 +79,11 @@ static gboolean ET_Save_File_Name_From_UI (const ET_File *ETFile,
static void ET_Mark_File_Tag_As_Saved (ET_File *ETFile);
-static gboolean ET_Detect_Changes_Of_File_Name (const File_Name *FileName1,
- const File_Name *FileName2);
static gboolean ET_Add_File_Name_To_List (ET_File *ETFile,
File_Name *FileName);
static gboolean ET_Add_File_Tag_To_List (ET_File *ETFile, File_Tag *FileTag);
-static gchar *ET_File_Name_Format_Extension (const ET_File *ETFile);
-
-/*
- * Create a new File_Name structure
- */
-File_Name *ET_File_Name_Item_New (void)
-{
- File_Name *FileName;
-
- FileName = g_slice_new (File_Name);
- ET_Initialize_File_Name_Item (FileName);
-
- return FileName;
-}
+static gchar *ET_File_Format_File_Extension (const ET_File *ETFile);
/*
* Create a new ET_File structure
@@ -117,19 +99,6 @@ ET_File_Item_New (void)
}
-static void
-ET_Initialize_File_Name_Item (File_Name *FileName)
-{
- if (FileName)
- {
- FileName->key = ET_Undo_Key_New();
- FileName->saved = FALSE;
- FileName->value = NULL;
- FileName->value_utf8 = NULL;
- FileName->value_ck = NULL;
- }
-}
-
/* Key for Undo */
guint
ET_Undo_Key_New (void)
@@ -1059,27 +1028,11 @@ ET_Free_File_Name_List (GList *FileNameList)
FileNameList = g_list_first (FileNameList);
- g_list_free_full (FileNameList, (GDestroyNotify)ET_Free_File_Name_Item);
+ g_list_free_full (FileNameList, (GDestroyNotify)et_file_name_free);
return TRUE;
}
-
-/*
- * Frees a File_Name item.
- */
-static void
-ET_Free_File_Name_Item (File_Name *FileName)
-{
- g_return_if_fail (FileName != NULL);
-
- g_free(FileName->value);
- g_free(FileName->value_utf8);
- g_free(FileName->value_ck);
- g_slice_free (File_Name, FileName);
-}
-
-
/*
* Frees the full list: GList *TagList.
*/
@@ -1110,41 +1063,6 @@ ET_Free_File_Tag_List (GList *FileTagList)
* Copying functions *
*********************/
-/*
- * Fill content of a FileName item according to the filename passed in argument (UTF-8 filename or not)
- * Calculate also the collate key.
- * It treats numbers intelligently so that "file1" "file10" "file5" is sorted as "file1" "file5" "file10"
- */
-gboolean
-ET_Set_Filename_File_Name_Item (File_Name *FileName,
- const gchar *filename_utf8,
- const gchar *filename)
-{
- g_return_val_if_fail (FileName != NULL, FALSE);
-
- if (filename_utf8 && filename)
- {
- FileName->value_utf8 = g_strdup(filename_utf8);
- FileName->value = g_strdup(filename);
- FileName->value_ck = g_utf8_collate_key_for_filename(FileName->value_utf8, -1);
- }else if (filename_utf8)
- {
- FileName->value_utf8 = g_strdup(filename_utf8);
- FileName->value = filename_from_display(filename_utf8);
- FileName->value_ck = g_utf8_collate_key_for_filename(FileName->value_utf8, -1);
- }else if (filename)
- {
- FileName->value_utf8 = filename_to_display(filename);;
- FileName->value = g_strdup(filename);
- FileName->value_ck = g_utf8_collate_key_for_filename(FileName->value_utf8, -1);
- }else
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
/************************
* Displaying functions *
************************/
@@ -1372,7 +1290,6 @@ void ET_Save_File_Data_From_UI (ET_File *ETFile)
const ET_File_Description *description;
File_Name *FileName;
File_Tag *FileTag;
- guint undo_key;
const gchar *cur_filename_utf8;
g_return_if_fail (ETFile != NULL && ETFile->FileNameCur != NULL
@@ -1380,15 +1297,10 @@ void ET_Save_File_Data_From_UI (ET_File *ETFile)
cur_filename_utf8 = ((File_Name *)((GList *)ETFile->FileNameCur)->data)->value_utf8;
description = ETFile->ETFileDescription;
- undo_key = ET_Undo_Key_New();
- /*
- * Save filename and generate undo for filename
- */
- FileName = g_slice_new (File_Name);
- ET_Initialize_File_Name_Item (FileName);
- FileName->key = undo_key;
+ /* Save filename and generate undo for filename. */
+ FileName = et_file_name_new ();
ET_Save_File_Name_From_UI(ETFile,FileName); // Used for all files!
switch (description->TagType)
@@ -1481,8 +1393,8 @@ ET_Save_File_Name_From_UI (const ET_File *ETFile, File_Name *FileName)
// Get the current path to the file
dirname = g_path_get_dirname( ((File_Name *)ETFile->FileNameNew->data)->value );
- // Convert filename extension (lower or upper)
- extension = ET_File_Name_Format_Extension(ETFile);
+ /* Convert filename extension (lower or upper). */
+ extension = ET_File_Format_File_Extension (ETFile);
// Check length of filename (limit ~255 characters)
//ET_File_Name_Check_Length(ETFile,filename);
@@ -1554,8 +1466,8 @@ ET_Save_File_Name_Internal (const ET_File *ETFile,
if ((pos=strrchr(filename, '.'))!=NULL)
*pos = 0;
- // Convert filename extension (lower/upper)
- extension = ET_File_Name_Format_Extension(ETFile);
+ /* Convert filename extension (lower/upper). */
+ extension = ET_File_Format_File_Extension (ETFile);
// Check length of filename
//ET_File_Name_Check_Length(ETFile,filename);
@@ -1941,13 +1853,15 @@ ET_Manage_Changes_Of_File_Data (ET_File *ETFile,
*/
if (FileName)
{
- if ( ETFile->FileNameNew && ET_Detect_Changes_Of_File_Name( (File_Name
*)(ETFile->FileNameNew)->data,FileName )==TRUE )
+ if (ETFile->FileNameNew
+ && et_file_name_detect_difference ((File_Name *)(ETFile->FileNameNew)->data,
+ FileName) == TRUE)
{
ET_Add_File_Name_To_List(ETFile,FileName);
undo_added |= TRUE;
}else
{
- ET_Free_File_Name_Item(FileName);
+ et_file_name_free (FileName);
}
}
@@ -1983,43 +1897,6 @@ ET_Manage_Changes_Of_File_Data (ET_File *ETFile,
}
/*
- * Compares two File_Name items :
- * - returns TRUE if there aren't the same
- * - else returns FALSE
- */
-static gboolean
-ET_Detect_Changes_Of_File_Name (const File_Name *FileName1,
- const File_Name *FileName2)
-{
- const gchar *filename1_ck;
- const gchar *filename2_ck;
-
- if (!FileName1 && !FileName2) return FALSE;
- if (FileName1 && !FileName2) return TRUE;
- if (!FileName1 && FileName2) return TRUE;
-
- /* Both FileName1 and FileName2 are != NULL. */
- if (!FileName1->value && !FileName2->value) return FALSE;
- if (FileName1->value && !FileName2->value) return TRUE;
- if (!FileName1->value && FileName2->value) return TRUE;
-
- /* Compare collate keys (with FileName->value converted to UTF-8 as it
- * contains raw data). */
- filename1_ck = FileName1->value_ck;
- filename2_ck = FileName2->value_ck;
-
- /* Filename changed ? (we check path + file). */
- if (strcmp (filename1_ck, filename2_ck) != 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-/*
* Add a FileName item to the history list of ETFile
*/
static gboolean
@@ -2292,8 +2169,8 @@ ET_File_Name_Generate (const ET_File *ETFile,
gchar *extension;
gchar *new_file_name_path_utf8;
- // Convert filename extension (lower/upper)
- extension = ET_File_Name_Format_Extension(ETFile);
+ /* Convert filename extension (lower/upper). */
+ extension = ET_File_Format_File_Extension (ETFile);
// Check length of filename (limit ~255 characters)
//ET_File_Name_Check_Length(ETFile,new_file_name_utf8);
@@ -2336,8 +2213,8 @@ gchar *ET_File_Name_Generate (ET_File *ETFile, gchar *new_file_name_utf8)
new_file_name = filename_from_display(new_file_name_utf8);
- // Convert filename extension (lower/upper)
- extension = ET_File_Name_Format_Extension(ETFile);
+ /* Convert filename extension (lower/upper). */
+ extension = ET_File_Format_File_Extension (ETFile);
// Check length of filename (limit ~255 characters)
//ET_File_Name_Check_Length(ETFile,new_file_name_utf8);
@@ -2370,7 +2247,7 @@ gchar *ET_File_Name_Generate (ET_File *ETFile, gchar *new_file_name_utf8)
/* Convert filename extension (lower/upper/no change). */
static gchar *
-ET_File_Name_Format_Extension (const ET_File *ETFile)
+ET_File_Format_File_Extension (const ET_File *ETFile)
{
EtFilenameExtensionMode mode;
diff --git a/src/file.h b/src/file.h
index 8eaf789..0aa7d69 100644
--- a/src/file.h
+++ b/src/file.h
@@ -26,21 +26,10 @@ G_BEGIN_DECLS
#include "core_types.h"
#include "file_description.h"
#include "file_info.h"
+#include "file_name.h"
#include "file_tag.h"
/*
- * Description of each item of the FileNameList list
- */
-typedef struct
-{
- guint key;
- gboolean saved; /* Set to TRUE if this filename had been saved */
- gchar *value; /* The filename containing the full path and the extension of the file */
- gchar *value_utf8; /* Same than "value", but converted to UTF-8 to avoid multiple call to the
convertion function */
- gchar *value_ck; /* Collate key of "value_utf8" to speed up comparaison */
-} File_Name;
-
-/*
* Description of each item of the ETFileList list
*/
typedef struct
@@ -76,11 +65,8 @@ typedef struct
gboolean ET_Check_If_File_Is_Saved (const ET_File *ETFile);
ET_File * ET_File_Item_New (void);
-File_Name * ET_File_Name_Item_New (void);
void ET_Free_File_List_Item (ET_File *ETFile);
-gboolean ET_Set_Filename_File_Name_Item (File_Name *FileName, const gchar *filename_utf8, const gchar
*filename);
-
void ET_Display_File_Data_To_UI (ET_File *ETFile);
void ET_Save_File_Data_From_UI (ET_File *ETFile);
gboolean ET_Save_File_Name_Internal (const ET_File *ETFile, File_Name *FileName);
diff --git a/src/file_list.c b/src/file_list.c
index 93c0059..f29bc8f 100644
--- a/src/file_list.c
+++ b/src/file_list.c
@@ -224,7 +224,7 @@ et_file_list_add (GList *file_list,
ETFileExtension = g_strdup(ET_Get_File_Extension(filename));
/* Fill the File_Name structure for FileNameList */
- FileName = ET_File_Name_Item_New();
+ FileName = et_file_name_new ();
FileName->saved = TRUE; /* The file hasn't been changed, so it's saved */
FileName->value = filename;
FileName->value_utf8 = filename_utf8;
@@ -446,7 +446,7 @@ et_file_list_add (GList *file_list,
*/
undo_key = ET_Undo_Key_New();
- FileName = ET_File_Name_Item_New();
+ FileName = et_file_name_new ();
FileName->key = undo_key;
ET_Save_File_Name_Internal(ETFile,FileName);
diff --git a/src/file_name.c b/src/file_name.c
new file mode 100644
index 0000000..f63f1e7
--- /dev/null
+++ b/src/file_name.c
@@ -0,0 +1,126 @@
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2015 David King <amigadave amigadave com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "file_name.h"
+
+#include "charset.h"
+#include "file.h"
+
+#include <string.h>
+
+/*
+ * Create a new File_Name structure
+ */
+File_Name *
+et_file_name_new (void)
+{
+ File_Name *file_name;
+
+ file_name = g_slice_new (File_Name);
+ file_name->key = ET_Undo_Key_New ();
+ file_name->saved = FALSE;
+ file_name->value = NULL;
+ file_name->value_utf8 = NULL;
+ file_name->value_ck = NULL;
+
+ return file_name;
+}
+
+/*
+ * Frees a File_Name item.
+ */
+void
+et_file_name_free (File_Name *file_name)
+{
+ g_return_if_fail (file_name != NULL);
+
+ g_free (file_name->value);
+ g_free (file_name->value_utf8);
+ g_free (file_name->value_ck);
+ g_slice_free (File_Name, file_name);
+}
+
+/*
+ * Fill content of a FileName item according to the filename passed in argument (UTF-8 filename or not)
+ * Calculate also the collate key.
+ * It treats numbers intelligently so that "file1" "file10" "file5" is sorted as "file1" "file5" "file10"
+ */
+void
+ET_Set_Filename_File_Name_Item (File_Name *FileName,
+ const gchar *filename_utf8,
+ const gchar *filename)
+{
+ g_return_if_fail (FileName != NULL);
+
+ if (filename_utf8 && filename)
+ {
+ FileName->value_utf8 = g_strdup (filename_utf8);
+ FileName->value = g_strdup (filename);
+ FileName->value_ck = g_utf8_collate_key_for_filename (FileName->value_utf8, -1);
+ }
+ else if (filename_utf8)
+ {
+ FileName->value_utf8 = g_strdup (filename_utf8);
+ FileName->value = filename_from_display (filename_utf8);
+ FileName->value_ck = g_utf8_collate_key_for_filename (FileName->value_utf8, -1);
+ }
+ else if (filename)
+ {
+ FileName->value_utf8 = filename_to_display (filename);;
+ FileName->value = g_strdup (filename);
+ FileName->value_ck = g_utf8_collate_key_for_filename (FileName->value_utf8, -1);
+ }
+}
+
+/*
+ * Compares two File_Name items :
+ * - returns TRUE if there aren't the same
+ * - else returns FALSE
+ */
+gboolean
+et_file_name_detect_difference (const File_Name *a,
+ const File_Name *b)
+{
+ const gchar *filename1_ck;
+ const gchar *filename2_ck;
+
+ g_return_val_if_fail (a && b, FALSE);
+
+ if (a && !b) return TRUE;
+ if (!a && b) return TRUE;
+
+ /* Both a and b are != NULL. */
+ if (!a->value && !b->value) return FALSE;
+ if (a->value && !b->value) return TRUE;
+ if (!a->value && b->value) return TRUE;
+
+ /* Compare collate keys (with FileName->value converted to UTF-8 as it
+ * contains raw data). */
+ filename1_ck = a->value_ck;
+ filename2_ck = b->value_ck;
+
+ /* Filename changed ? (we check path + file). */
+ if (strcmp (filename1_ck, filename2_ck) != 0)
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
diff --git a/src/file_name.h b/src/file_name.h
new file mode 100644
index 0000000..a916c53
--- /dev/null
+++ b/src/file_name.h
@@ -0,0 +1,45 @@
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2015 David King <amigadave amigadave com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef ET_FILE_NAME_H_
+#define ET_FILE_NAME_H_
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Description of each item of the FileNameList list
+ */
+typedef struct
+{
+ guint key;
+ gboolean saved; /* Set to TRUE if this filename had been saved */
+ gchar *value; /* The filename containing the full path and the extension of the file */
+ gchar *value_utf8; /* Same than "value", but converted to UTF-8 to avoid multiple call to the convertion
function */
+ gchar *value_ck; /* Collate key of "value_utf8" to speed up comparison. */
+} File_Name;
+
+File_Name * et_file_name_new (void);
+void et_file_name_free (File_Name *file_name);
+void ET_Set_Filename_File_Name_Item (File_Name *FileName, const gchar *filename_utf8, const gchar *filename);
+gboolean et_file_name_detect_difference (const File_Name *a, const File_Name *b);
+
+G_END_DECLS
+
+#endif /* !ET_FILE_NAME_H_ */
diff --git a/src/load_files_dialog.c b/src/load_files_dialog.c
index 1d562a1..f3cdb71 100644
--- a/src/load_files_dialog.c
+++ b/src/load_files_dialog.c
@@ -128,7 +128,7 @@ Load_Filename_Set_Filenames (EtLoadFilesDialog *self)
/* Set the new filename */
// Create a new 'File_Name' item
- FileName = ET_File_Name_Item_New();
+ FileName = et_file_name_new ();
// Save changes of the 'File_Name' item
ET_Set_Filename_File_Name_Item(FileName,filename_new_utf8,NULL);
ET_Manage_Changes_Of_File_Data(ETFile,FileName,NULL);
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 263270f..6783451 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -828,8 +828,8 @@ Scan_Rename_File_With_Mask (EtScanDialog *self, ET_File *ETFile)
g_free(filename_generated_utf8);
/* Set the new filename */
- // Create a new 'File_Name' item
- FileName = ET_File_Name_Item_New();
+ /* Create a new 'File_Name' item. */
+ FileName = et_file_name_new ();
// Save changes of the 'File_Name' item
ET_Set_Filename_File_Name_Item(FileName,filename_new_utf8,NULL);
@@ -1334,7 +1334,7 @@ Scan_Process_Fields (EtScanDialog *self, ET_File *ETFile)
filename_utf8 = st_filename->value_utf8;
if (!FileName)
- FileName = ET_File_Name_Item_New();
+ FileName = et_file_name_new ();
string = g_path_get_basename(filename_utf8);
// Remove the extension to set it to lower case (to avoid problem with undo)
diff --git a/src/tags/flac_tag.c b/src/tags/flac_tag.c
index 5e97c2f..632d515 100644
--- a/src/tags/flac_tag.c
+++ b/src/tags/flac_tag.c
@@ -1190,7 +1190,7 @@ flac_tag_write_file_tag (const ET_File *ETFile,
{
// Delete the ID3 tags (create a dummy ETFile for the Id3tag_... function)
ET_File *ETFile_tmp = ET_File_Item_New();
- File_Name *FileName_tmp = ET_File_Name_Item_New();
+ File_Name *FileName_tmp = et_file_name_new ();
File_Tag *FileTag_tmp = et_file_tag_new ();
// Same file...
FileName_tmp->value = g_strdup(filename);
diff --git a/src/tags/id3_tag.c b/src/tags/id3_tag.c
index e192c67..ab5530d 100644
--- a/src/tags/id3_tag.c
+++ b/src/tags/id3_tag.c
@@ -565,7 +565,7 @@ id3tag_write_file_v23tag (const ET_File *ETFile,
{
// Delete the APE tag (create a dummy ETFile for the Ape_Tag_... function)
ET_File *ETFile_tmp = ET_File_Item_New();
- File_Name *FileName_tmp = ET_File_Name_Item_New();
+ File_Name *FileName_tmp = et_file_name_new ();
File_Tag *FileTag_tmp = et_file_tag_new();
// Same file...
FileName_tmp->value = g_strdup(filename);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]