[easytag/wip/et_core-refactor: 7/9] Split ET_File_Description out to separate file



commit d639f6ca9e60726dcb0932c168c2cfbedf83183c
Author: David King <amigadave amigadave com>
Date:   Sun Dec 28 20:32:27 2014 +0000

    Split ET_File_Description out to separate file

 Makefile.am            |    2 +
 src/easytag.c          |    3 +-
 src/et_core.c          |  105 ----------------------------------------
 src/et_core.h          |   22 +--------
 src/file_description.c |  125 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/file_description.h |   52 ++++++++++++++++++++
 6 files changed, 182 insertions(+), 127 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4807ca9..7caf5b5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,6 +50,7 @@ easytag_SOURCES = \
        src/enums.c \
        src/et_core.c \
        src/file_area.c \
+       src/file_description.c \
        src/file_tag.c \
        src/load_files_dialog.c \
        src/log.c \
@@ -106,6 +107,7 @@ easytag_headers = \
        src/easytag.h \
        src/et_core.h \
        src/file_area.h \
+       src/file_description.h \
        src/file_tag.h \
        src/genres.h \
        src/load_files_dialog.h \
diff --git a/src/easytag.c b/src/easytag.c
index cf24156..154cbe4 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -29,6 +29,7 @@
 
 #include "application_window.h"
 #include "browser.h"
+#include "file_description.h"
 #include "log.h"
 #include "misc.h"
 #include "cddb_dialog.h"
@@ -1161,7 +1162,7 @@ read_directory_recursively (GList *file_list, GFileEnumerator *dir_enumerator,
                 }
             }
             else if (type == G_FILE_TYPE_REGULAR &&
-                      ET_File_Is_Supported (file_name))
+                     et_file_is_supported (file_name))
             {
                 GFile *file = g_file_get_child (g_file_enumerator_get_container (dir_enumerator),
                                                 file_name);
diff --git a/src/et_core.c b/src/et_core.c
index 82d992e..8bef0e9 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -75,47 +75,6 @@
 
 ET_Core *ETCore = NULL;
 
-const ET_File_Description ETFileDescription[] =
-{
-#ifdef ENABLE_MP3
-    { MP3_FILE, ".mp3", ID3_TAG},
-    { MP2_FILE, ".mp2", ID3_TAG},
-#endif
-#ifdef ENABLE_OPUS
-    { OPUS_FILE, ".opus", OPUS_TAG},
-#endif
-#ifdef ENABLE_OGG
-    { OGG_FILE, ".ogg", OGG_TAG},
-    { OGG_FILE, ".oga", OGG_TAG},
-#endif
-#ifdef ENABLE_SPEEX
-    { SPEEX_FILE, ".spx", OGG_TAG}, /* Implemented by Pierre Dumuid. */
-#endif
-#ifdef ENABLE_FLAC
-    { FLAC_FILE, ".flac", FLAC_TAG},
-    { FLAC_FILE, ".fla",  FLAC_TAG},
-#endif
-    { MPC_FILE, ".mpc", APE_TAG}, /* Implemented by Artur Polaczynski. */
-    { MPC_FILE, ".mp+", APE_TAG}, /* Implemented by Artur Polaczynski. */
-    { MPC_FILE, ".mpp", APE_TAG}, /* Implemented by Artur Polaczynski. */
-    { MAC_FILE, ".ape", APE_TAG}, /* Implemented by Artur Polaczynski. */
-    { MAC_FILE, ".mac", APE_TAG}, /* Implemented by Artur Polaczynski. */
-    { OFR_FILE, ".ofr", APE_TAG},
-    { OFR_FILE, ".ofs", APE_TAG},
-#ifdef ENABLE_MP4
-    { MP4_FILE, ".mp4", MP4_TAG}, /* Implemented by Michael Ihde. */
-    { MP4_FILE, ".m4a", MP4_TAG}, /* Implemented by Michael Ihde. */
-    { MP4_FILE, ".m4p", MP4_TAG}, /* Implemented by Michael Ihde. */
-    { MP4_FILE, ".m4v", MP4_TAG},
-#endif
-#ifdef ENABLE_WAVPACK
-    { WAVPACK_FILE, ".wv", WAVPACK_TAG}, /* Implemented by Maarten Maathuis. */
-#endif
-    { UNKNOWN_FILE, "", UNKNOWN_TAG } /* This item must be placed at the end! */
-};
-
-const gsize ET_FILE_DESCRIPTION_SIZE = G_N_ELEMENTS (ETFileDescription) - 1;
-
 /*
  * Colors Used
  */
@@ -126,10 +85,6 @@ GdkRGBA RED = {1.0, 0.0, 0.0, 1.0 };
  * Prototypes *
  **************/
 
-//gboolean ET_File_Is_Supported (gchar *filename);
-static const ET_File_Description *ET_Get_File_Description (const gchar *filename);
-static const ET_File_Description *ET_Get_File_Description_From_Extension (const gchar *extension);
-
 static gboolean ET_Free_File_List                 (void);
 static gboolean ET_Free_File_Name_List            (GList *FileNameList);
 static gboolean ET_Free_File_Tag_List (GList *FileTagList);
@@ -187,66 +142,6 @@ static void set_sort_order_for_column_id (gint column_id,
  * Basic functions *
  *******************/
 
-/*
- * Returns the extension of the file
- */
-static const gchar *
-ET_Get_File_Extension (const gchar *filename)
-{
-    if (filename)
-        return strrchr(filename, '.');
-    else
-        return NULL;
-}
-
-
-/*
- * Determine description of file using his extension.
- * If extension is NULL or not found into the tab, it returns the last entry for UNKNOWN_FILE.
- */
-static const ET_File_Description *
-ET_Get_File_Description_From_Extension (const gchar *extension)
-{
-    guint i;
-
-    if (!extension) // Unknown file
-        return &ETFileDescription[ET_FILE_DESCRIPTION_SIZE];
-
-    for (i=0; i<ET_FILE_DESCRIPTION_SIZE; i++)  // Use of '<' instead of '<=' to avoid to test for Unknown 
file
-        if ( strcasecmp(extension,ETFileDescription[i].Extension)==0 )
-            return &ETFileDescription[i];
-
-    // If not found in the list
-    return &ETFileDescription[ET_FILE_DESCRIPTION_SIZE];
-}
-
-
-/*
- * Determines description of file.
- * Determines first the extension. If extension is NULL or not found into the tab,
- * it returns the last entry for UNKNOWN_FILE.
- */
-static const ET_File_Description *
-ET_Get_File_Description (const gchar *filename)
-{
-    return ET_Get_File_Description_From_Extension(ET_Get_File_Extension(filename));
-}
-
-
-/*
- * Returns TRUE if the file is supported, else returns FALSE
- */
-gboolean ET_File_Is_Supported (const gchar *filename)
-{
-    if (ET_Get_File_Description(filename)->FileType != UNKNOWN_FILE)
-        return TRUE;
-    else
-        return FALSE;
-}
-
-
-
-
 /*****************************************************************************
  * Manipulation of ET_Core functions (main functions needed for the program) *
  *****************************************************************************/
diff --git a/src/et_core.h b/src/et_core.h
index 2e35c3f..e0914a1 100644
--- a/src/et_core.h
+++ b/src/et_core.h
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
 #include <gdk/gdk.h>
 
 #include "core_types.h"
+#include "file_description.h"
 #include "file_tag.h"
 #include "picture.h"
 
@@ -50,27 +51,6 @@ struct _File_Name
 };
 
 /*
- * Structure for descripting supported files
- */
-typedef struct _ET_File_Description ET_File_Description;
-struct _ET_File_Description
-{
-    ET_File_Type FileType;    /* Type of file (ex: MP3) */
-    const gchar *Extension; /* Extension (ex: ".mp3") */
-    ET_Tag_Type  TagType;     /* Type of tag (ex: ID3) */
-};
-
-
-/*
- * Description of supported files
- */
-extern const ET_File_Description ETFileDescription[];
-
-/* Calculate the last index of the previous tab */
-extern const gsize ET_FILE_DESCRIPTION_SIZE;
-
-
-/*
  * Description of each item of the ETFileList list
  */
 typedef struct _ET_File ET_File;
diff --git a/src/file_description.c b/src/file_description.c
new file mode 100644
index 0000000..9a2b684
--- /dev/null
+++ b/src/file_description.c
@@ -0,0 +1,125 @@
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2014  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 "config.h"
+#include "file_description.h"
+
+#include <string.h>
+
+const ET_File_Description ETFileDescription[] =
+{
+#ifdef ENABLE_MP3
+    { MP3_FILE, ".mp3", ID3_TAG},
+    { MP2_FILE, ".mp2", ID3_TAG},
+#endif
+#ifdef ENABLE_OPUS
+    { OPUS_FILE, ".opus", OPUS_TAG},
+#endif
+#ifdef ENABLE_OGG
+    { OGG_FILE, ".ogg", OGG_TAG},
+    { OGG_FILE, ".oga", OGG_TAG},
+#endif
+#ifdef ENABLE_SPEEX
+    { SPEEX_FILE, ".spx", OGG_TAG}, /* Implemented by Pierre Dumuid. */
+#endif
+#ifdef ENABLE_FLAC
+    { FLAC_FILE, ".flac", FLAC_TAG},
+    { FLAC_FILE, ".fla",  FLAC_TAG},
+#endif
+    { MPC_FILE, ".mpc", APE_TAG}, /* Implemented by Artur Polaczynski. */
+    { MPC_FILE, ".mp+", APE_TAG}, /* Implemented by Artur Polaczynski. */
+    { MPC_FILE, ".mpp", APE_TAG}, /* Implemented by Artur Polaczynski. */
+    { MAC_FILE, ".ape", APE_TAG}, /* Implemented by Artur Polaczynski. */
+    { MAC_FILE, ".mac", APE_TAG}, /* Implemented by Artur Polaczynski. */
+    { OFR_FILE, ".ofr", APE_TAG},
+    { OFR_FILE, ".ofs", APE_TAG},
+#ifdef ENABLE_MP4
+    { MP4_FILE, ".mp4", MP4_TAG}, /* Implemented by Michael Ihde. */
+    { MP4_FILE, ".m4a", MP4_TAG}, /* Implemented by Michael Ihde. */
+    { MP4_FILE, ".m4p", MP4_TAG}, /* Implemented by Michael Ihde. */
+    { MP4_FILE, ".m4v", MP4_TAG},
+#endif
+#ifdef ENABLE_WAVPACK
+    { WAVPACK_FILE, ".wv", WAVPACK_TAG}, /* Implemented by Maarten Maathuis. */
+#endif
+    { UNKNOWN_FILE, "", UNKNOWN_TAG } /* This item must be placed at the end! */
+};
+
+const gsize ET_FILE_DESCRIPTION_SIZE = G_N_ELEMENTS (ETFileDescription) - 1;
+
+/*
+ * Returns the extension of the file
+ */
+const gchar *
+ET_Get_File_Extension (const gchar *filename)
+{
+    if (filename)
+    {
+        return strrchr (filename, '.');
+    }
+    else
+    {
+        return NULL;
+    }
+}
+
+
+/*
+ * Determine description of file using his extension.
+ * If extension is NULL or not found into the tab, it returns the last entry for UNKNOWN_FILE.
+ */
+static const ET_File_Description *
+ET_Get_File_Description_From_Extension (const gchar *extension)
+{
+    guint i;
+
+    if (!extension) // Unknown file
+        return &ETFileDescription[ET_FILE_DESCRIPTION_SIZE];
+
+    for (i=0; i<ET_FILE_DESCRIPTION_SIZE; i++)  // Use of '<' instead of '<=' to avoid to test for Unknown 
file
+        if ( strcasecmp(extension,ETFileDescription[i].Extension)==0 )
+            return &ETFileDescription[i];
+
+    // If not found in the list
+    return &ETFileDescription[ET_FILE_DESCRIPTION_SIZE];
+}
+
+
+/*
+ * Determines description of file.
+ * Determines first the extension. If extension is NULL or not found into the tab,
+ * it returns the last entry for UNKNOWN_FILE.
+ */
+const ET_File_Description *
+ET_Get_File_Description (const gchar *filename)
+{
+    return ET_Get_File_Description_From_Extension(ET_Get_File_Extension(filename));
+}
+
+
+/*
+ * Returns TRUE if the file is supported, else returns FALSE
+ */
+gboolean
+et_file_is_supported (const gchar *filename)
+{
+    if (ET_Get_File_Description(filename)->FileType != UNKNOWN_FILE)
+        return TRUE;
+    else
+        return FALSE;
+}
diff --git a/src/file_description.h b/src/file_description.h
new file mode 100644
index 0000000..cac2c88
--- /dev/null
+++ b/src/file_description.h
@@ -0,0 +1,52 @@
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2014  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_DESCRIPTION_H_
+#define ET_FILE_DESCRIPTION_H_
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#include "core_types.h"
+
+/*
+ * Structure for descripting supported files
+ */
+typedef struct
+{
+    ET_File_Type FileType;    /* Type of file (ex: MP3) */
+    const gchar *Extension; /* Extension (ex: ".mp3") */
+    ET_Tag_Type  TagType;     /* Type of tag (ex: ID3) */
+} ET_File_Description;
+
+/*
+ * Description of supported files
+ */
+extern const ET_File_Description ETFileDescription[];
+
+/* Calculate the last index of the previous tab */
+extern const gsize ET_FILE_DESCRIPTION_SIZE;
+
+const gchar * ET_Get_File_Extension (const gchar *filename);
+const ET_File_Description * ET_Get_File_Description (const gchar *filename);
+gboolean et_file_is_supported (const gchar *filename);
+
+G_END_DECLS
+
+#endif /* !ET_FILE_DESCRIPTION_H_ */


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