[easytag] Use GFile in header reading functions



commit aca762a3063b33300ceb783d5a97f79a92307149
Author: David King <amigadave amigadave com>
Date:   Mon Oct 27 23:57:19 2014 +0000

    Use GFile in header reading functions

 src/et_core.c                 |   38 ++++++++----------
 src/tags/flac_header.c        |   14 +-----
 src/tags/flac_header.h        |    2 +-
 src/tags/monkeyaudio_header.c |   29 +++++---------
 src/tags/monkeyaudio_header.h |    2 +-
 src/tags/mp4_header.cc        |   42 ++++++++++----------
 src/tags/mp4_header.h         |    2 +-
 src/tags/mp4_tag.cc           |   36 ++++++++----------
 src/tags/mpeg_header.c        |   25 +++++++++---
 src/tags/mpeg_header.h        |    2 +-
 src/tags/musepack_header.c    |   29 +++++---------
 src/tags/musepack_header.h    |    2 +-
 src/tags/ogg_header.c         |   82 +++++++++++++++++++----------------------
 src/tags/ogg_header.h         |    6 +--
 src/tags/opus_header.c        |    1 -
 src/tags/wavpack_header.c     |   17 ++++----
 src/tags/wavpack_header.h     |    2 +-
 17 files changed, 152 insertions(+), 179 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index 93224c3..30ef00e 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -175,7 +175,7 @@ static gboolean ET_Add_File_To_Artist_Album_File_List (ET_File *ETFile);
 static guint ET_Displayed_File_List_Get_Length      (void);
 static void ET_Displayed_File_List_Number (void);
 
-static gboolean et_core_read_file_info (const gchar *filename,
+static gboolean et_core_read_file_info (GFile *file,
                                         ET_File_Info *ETFileInfo,
                                         GError **error);
 
@@ -616,42 +616,40 @@ GList *ET_Add_File_To_File_List (gchar *filename)
 #if defined ENABLE_MP3 && defined ENABLE_ID3LIB
         case MP3_FILE:
         case MP2_FILE:
-            success = mpeg_header_read_file_info (filename, ETFileInfo,
-                                                  &error);
+            success = et_mpeg_header_read_file_info (file, ETFileInfo, &error);
             break;
 #endif
 #ifdef ENABLE_OGG
         case OGG_FILE:
-            success = ogg_header_read_file_info (filename, ETFileInfo, &error);
+            success = et_ogg_header_read_file_info (file, ETFileInfo, &error);
             break;
 #endif
 #ifdef ENABLE_SPEEX
         case SPEEX_FILE:
-            success = speex_header_read_file_info (filename, ETFileInfo,
-                                                   &error);
+            success = et_speex_header_read_file_info (file, ETFileInfo,
+                                                      &error);
             break;
 #endif
 #ifdef ENABLE_FLAC
         case FLAC_FILE:
-            success = flac_header_read_file_info (file, ETFileInfo,
-                                                  &error);
+            success = et_flac_header_read_file_info (file, ETFileInfo, &error);
             break;
 #endif
         case MPC_FILE:
-            success = mpc_header_read_file_info (filename, ETFileInfo, &error);
+            success = et_mpc_header_read_file_info (file, ETFileInfo, &error);
             break;
         case MAC_FILE:
-            success = mac_header_read_file_info (filename, ETFileInfo, &error);
+            success = et_mac_header_read_file_info (file, ETFileInfo, &error);
             break;
 #ifdef ENABLE_WAVPACK
         case WAVPACK_FILE:
-            success = wavpack_header_read_file_info (filename, ETFileInfo,
-                                                     &error);
+            success = et_wavpack_header_read_file_info (file, ETFileInfo,
+                                                        &error);
             break;
 #endif
 #ifdef ENABLE_MP4
         case MP4_FILE:
-            success = mp4_header_read_file_info (filename, ETFileInfo, &error);
+            success = et_mp4_header_read_file_info (file, ETFileInfo, &error);
             break;
 #endif
 #ifdef ENABLE_OPUS
@@ -664,7 +662,7 @@ GList *ET_Add_File_To_File_List (gchar *filename)
             /* FIXME: Translatable string. */
             Log_Print(LOG_ERROR,"ETFileInfo: Undefined file type (%d) for file 
%s",ETFileDescription->FileType,filename_utf8);
             /* To get at least the file size. */
-            success = et_core_read_file_info (filename, ETFileInfo, &error);
+            success = et_core_read_file_info (file, ETFileInfo, &error);
             break;
     }
 
@@ -4319,7 +4317,7 @@ void ET_Mark_File_Name_As_Saved (ET_File *ETFile)
 
 /*
  * et_core_read_file_info:
- * @filename: (type filename): a file from which to read information
+ * @file: a file from which to read information
  * @ETFileInfo: (out caller-allocates): a file information structure
  * @error: a #GError to provide information on erros, or %NULL to ignore
  *
@@ -4329,23 +4327,21 @@ void ET_Mark_File_Name_As_Saved (ET_File *ETFile)
  * Returns: %TRUE on success, %FALSE otherwise
  */
 static gboolean
-et_core_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo,
+et_core_read_file_info (GFile *file,
+                        ET_File_Info *ETFileInfo,
                         GError **error)
 {
-    GFile *file;
     GFileInfo *info;
 
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+    g_return_val_if_fail (file != NULL && ETFileInfo != NULL, FALSE);
 
-    file = g_file_new_for_path (filename);
     info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
                               G_FILE_QUERY_INFO_NONE, NULL, error);
 
     if (!info)
     {
         g_assert (error == NULL || *error != NULL);
-        g_object_unref (file);
         return FALSE;
     }
 
@@ -4358,7 +4354,7 @@ et_core_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo,
 
     g_assert (error == NULL || *error == NULL);
     g_object_unref (info);
-    g_object_unref (file);
+
     return TRUE;
 }
 
diff --git a/src/tags/flac_header.c b/src/tags/flac_header.c
index 7a1a9c7..f796c18 100644
--- a/src/tags/flac_header.c
+++ b/src/tags/flac_header.c
@@ -17,13 +17,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-/*
- * Code taken from :
- * FLAC - Free Lossless Audio Codec - v1.0.3
- * Copyright (C) 2001  Josh Coalson
- *
- */
-
 #include "config.h" /* For definition of ENABLE_FLAC. */
 
 #ifdef ENABLE_FLAC
@@ -33,7 +26,6 @@
 #include <FLAC/all.h>
 #include <errno.h>
 
-#include "easytag.h"
 #include "et_core.h"
 #include "flac_header.h"
 #include "misc.h"
@@ -170,9 +162,9 @@ et_flac_close_func (FLAC__IOHandle handle)
 /* Header info of FLAC file */
 
 gboolean
-flac_header_read_file_info (GFile *file,
-                            ET_File_Info *ETFileInfo,
-                            GError **error)
+et_flac_header_read_file_info (GFile *file,
+                               ET_File_Info *ETFileInfo,
+                               GError **error)
 {
     GFileInfo *info;
     FLAC__Metadata_Chain *chain;
diff --git a/src/tags/flac_header.h b/src/tags/flac_header.h
index 2dce50c..f962222 100644
--- a/src/tags/flac_header.h
+++ b/src/tags/flac_header.h
@@ -24,7 +24,7 @@
 
 G_BEGIN_DECLS
 
-gboolean flac_header_read_file_info (GFile* file, ET_File_Info *ETFileInfo, GError **error);
+gboolean et_flac_header_read_file_info (GFile *file, ET_File_Info *ETFileInfo, GError **error);
 EtFileHeaderFields * et_flac_header_display_file_info_to_ui (const ET_File *ETFile);
 void et_flac_file_header_fields_free (EtFileHeaderFields *fields);
 
diff --git a/src/tags/monkeyaudio_header.c b/src/tags/monkeyaudio_header.c
index 0cfb5fe..2a00820 100644
--- a/src/tags/monkeyaudio_header.c
+++ b/src/tags/monkeyaudio_header.c
@@ -18,46 +18,39 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
 
-#include "easytag.h"
 #include "et_core.h"
 #include "misc.h"
-#include "setting.h"
-#include "charset.h"
 #include "monkeyaudio_header.h"
 #include "libapetag/info_mac.h"
 
-
-/***************
- * Header info *
- ***************/
-
 gboolean
-mac_header_read_file_info (const gchar *filename,
-                           ET_File_Info *ETFileInfo,
-                           GError **error)
+et_mac_header_read_file_info (GFile *file,
+                              ET_File_Info *ETFileInfo,
+                              GError **error)
 {
+    gchar *filename;
     StreamInfoMac Info;
 
-    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+    g_return_val_if_fail (file != NULL && ETFileInfo != NULL, FALSE);
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
+    filename = g_file_get_path (file);
+
     if (info_mac_read (filename, &Info))
     {
         g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s",
                      _("Error opening Monkey’s Audio file"));
+        g_free (filename);
         return FALSE;
     }
 
+    g_free (filename);
+
     ETFileInfo->mpc_profile   = g_strdup(Info.CompresionName);
     ETFileInfo->version       = Info.Version;
     ETFileInfo->bitrate       = Info.Bitrate/1000.0;
diff --git a/src/tags/monkeyaudio_header.h b/src/tags/monkeyaudio_header.h
index b14b75b..fc7ce64 100644
--- a/src/tags/monkeyaudio_header.h
+++ b/src/tags/monkeyaudio_header.h
@@ -25,7 +25,7 @@
 
 G_BEGIN_DECLS
 
-gboolean mac_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
+gboolean et_mac_header_read_file_info (GFile *file, ET_File_Info *ETFileInfo, GError **error);
 EtFileHeaderFields * et_mac_header_display_file_info_to_ui (const ET_File *ETFile);
 void et_mac_file_header_fields_free (EtFileHeaderFields *fields);
 
diff --git a/src/tags/mp4_header.cc b/src/tags/mp4_header.cc
index c6578d9..23028ea 100644
--- a/src/tags/mp4_header.cc
+++ b/src/tags/mp4_header.cc
@@ -22,47 +22,50 @@
 /* This file is intended to be included directly in mp4_tag.cc */
 
 /*
- * mp4_header_read_file_info:
+ * et_mp4_header_read_file_info:
  *
  * Get header info into the ETFileInfo structure
  */
 gboolean
-mp4_header_read_file_info (const gchar *filename,
-                           ET_File_Info *ETFileInfo,
-                           GError **error)
+et_mp4_header_read_file_info (GFile *file,
+                              ET_File_Info *ETFileInfo,
+                              GError **error)
 {
+    GFileInfo *info;
     const TagLib::MP4::Properties *properties;
 
-    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+    g_return_val_if_fail (file != NULL && ETFileInfo != NULL, FALSE);
 
     /* Get size of file */
-    ETFileInfo->size = et_get_file_size (filename);
+    info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                              G_FILE_QUERY_INFO_NONE, NULL, error);
+
+    if (!info)
+    {
+        return FALSE;
+    }
+
+    ETFileInfo->size = g_file_info_get_size (info);
+    g_object_unref (info);
 
-    GFile *file = g_file_new_for_path (filename);
     GIO_InputStream stream (file);
 
     if (!stream.isOpen ())
     {
-        gchar *filename_utf8 = filename_to_display (filename);
         const GError *tmp_error = stream.getError ();
+
         g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                     _("Error while opening file ‘%s’: %s"), filename_utf8,
-                     tmp_error->message);
-        g_free (filename_utf8);
+                     _("Error while opening file: %s"), tmp_error->message);
         return FALSE;
     }
 
     TagLib::MP4::File mp4file (&stream);
 
-    g_object_unref (file);
-
     if (!mp4file.isOpen ())
     {
-        gchar *filename_utf8 = filename_to_display (filename);
         g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                     _("Error while opening file ‘%s’: %s"), filename_utf8,
+                     _("Error while opening file: %s"),
                      _("MP4 format invalid"));
-        g_free (filename_utf8);
         return FALSE;
     }
 
@@ -70,11 +73,8 @@ mp4_header_read_file_info (const gchar *filename,
 
     if (properties == NULL)
     {
-        gchar *filename_utf8 = filename_to_display (filename);
-        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                     _("Error reading properties from file ‘%s’"),
-                     filename_utf8);
-        g_free (filename_utf8);
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s",
+                     _("Error reading properties from file"));
         return FALSE;
     }
 
diff --git a/src/tags/mp4_header.h b/src/tags/mp4_header.h
index 81700ca..6395d99 100644
--- a/src/tags/mp4_header.h
+++ b/src/tags/mp4_header.h
@@ -25,7 +25,7 @@
 
 G_BEGIN_DECLS
 
-gboolean mp4_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
+gboolean et_mp4_header_read_file_info (GFile *file, ET_File_Info *ETFileInfo, GError **error);
 EtFileHeaderFields * et_mp4_header_display_file_info_to_ui (const ET_File *ETFile);
 void et_mp4_file_header_fields_free (EtFileHeaderFields *fields);
 
diff --git a/src/tags/mp4_tag.cc b/src/tags/mp4_tag.cc
index 63119f9..7181d46 100644
--- a/src/tags/mp4_tag.cc
+++ b/src/tags/mp4_tag.cc
@@ -1,23 +1,22 @@
-/*
- *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
- *  Copyright (C) 2012-1014  David King <amigadave amigadave com>
- *  Copyright (C) 2001-2005  Jerome Couderc <easytag gmail com>
- *  Copyright (C) 2005  Michael Ihde <mike ihde randomwalking com>
- *  Copyright (C) 2005  Stewart Whitman <swhitman cox net>
+/* EasyTAG - Tag editor for MP3 and Ogg Vorbis files
+ * Copyright (C) 2012-1014  David King <amigadave amigadave com>
+ * Copyright (C) 2001-2005  Jerome Couderc <easytag gmail com>
+ * Copyright (C) 2005  Michael Ihde <mike ihde randomwalking com>
+ * Copyright (C) 2005  Stewart Whitman <swhitman cox net>
  *
- *  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 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.
+ * 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.
+ * 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" // For definition of ENABLE_MP4
@@ -26,13 +25,10 @@
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
-#include <stdlib.h>
 
 #include "mp4_header.h"
 #include "mp4_tag.h"
 #include "picture.h"
-#include "easytag.h"
-#include "setting.h"
 #include "log.h"
 #include "misc.h"
 #include "et_core.h"
diff --git a/src/tags/mpeg_header.c b/src/tags/mpeg_header.c
index 4e67119..2913b53 100644
--- a/src/tags/mpeg_header.c
+++ b/src/tags/mpeg_header.c
@@ -26,7 +26,6 @@
 #include <errno.h>
 
 #include "mpeg_header.h"
-#include "easytag.h"
 #include "misc.h"
 
 #include <id3.h>
@@ -67,32 +66,46 @@ channel_mode_name (int mode)
  * Read infos into header of first frame
  */
 gboolean
-mpeg_header_read_file_info (const gchar *filename,
-                            ET_File_Info *ETFileInfo,
-                            GError **error)
+et_mpeg_header_read_file_info (GFile *file,
+                               ET_File_Info *ETFileInfo,
+                               GError **error)
 {
+    GFileInfo *info;
+    gchar *filename;
     /*
      * With id3lib, the header frame couldn't be read if the file contains an ID3v2 tag with an APIC frame
      */
     ID3Tag *id3_tag = NULL;    /* Tag defined by the id3lib */
     const Mp3_Headerinfo* headerInfo = NULL;
 
-    g_return_val_if_fail (filename != NULL || ETFileInfo != NULL, FALSE);
+    g_return_val_if_fail (file != NULL || ETFileInfo != NULL, FALSE);
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     /* Get size of file */
-    ETFileInfo->size = et_get_file_size (filename);
+    info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                              G_FILE_QUERY_INFO_NONE, NULL, error);
+
+    if (!info)
+    {
+        return FALSE;
+    }
+
+    ETFileInfo->size = g_file_info_get_size (info);
+    g_object_unref (info);
 
     /* Get data from tag */
     if ((id3_tag = ID3Tag_New()) == NULL)
     {
         g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM, "%s",
                      g_strerror (ENOMEM));
+        g_object_unref (info);
         return FALSE;
     }
 
     /* Link the file to the tag (uses ID3TT_ID3V2 to get header if APIC is present in Tag) */
+    filename = g_file_get_path (file);
     ID3Tag_LinkWithFlags(id3_tag,filename,ID3TT_ID3V2);
+    g_free (filename);
 
     if ( (headerInfo = ID3Tag_GetMp3HeaderInfo(id3_tag)) )
     {
diff --git a/src/tags/mpeg_header.h b/src/tags/mpeg_header.h
index 6d4e904..f80d411 100644
--- a/src/tags/mpeg_header.h
+++ b/src/tags/mpeg_header.h
@@ -24,7 +24,7 @@
 
 G_BEGIN_DECLS
 
-gboolean mpeg_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
+gboolean et_mpeg_header_read_file_info (GFile *file, ET_File_Info *ETFileInfo, GError **error);
 EtFileHeaderFields * et_mpeg_header_display_file_info_to_ui (const ET_File *ETFile);
 void et_mpeg_file_header_fields_free (EtFileHeaderFields *fields);
 
diff --git a/src/tags/musepack_header.c b/src/tags/musepack_header.c
index 9c0e4f5..a696eda 100644
--- a/src/tags/musepack_header.c
+++ b/src/tags/musepack_header.c
@@ -18,46 +18,39 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
 
-#include "easytag.h"
 #include "et_core.h"
 #include "misc.h"
-#include "setting.h"
-#include "charset.h"
 #include "musepack_header.h"
 #include "libapetag/info_mpc.h"
 
-
-/***************
- * Header info *
- ***************/
-
 gboolean
-mpc_header_read_file_info (const gchar *filename,
-                           ET_File_Info *ETFileInfo,
-                           GError **error)
+et_mpc_header_read_file_info (GFile *file,
+                              ET_File_Info *ETFileInfo,
+                              GError **error)
 {
+    gchar *filename;
     StreamInfoMpc Info;
 
-    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+    g_return_val_if_fail (file != NULL && ETFileInfo != NULL, FALSE);
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
+    filename = g_file_get_path (file);
+
     if (info_mpc_read (filename, &Info))
     {
         g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s",
                      _("Error opening Musepack file"));
+        g_free (filename);
         return FALSE;
     }
 
+    g_free (filename);
+
     ETFileInfo->mpc_profile = g_strdup(Info.ProfileName);
     ETFileInfo->version     = Info.StreamVersion;
     ETFileInfo->bitrate     = Info.Bitrate/1000.0;
diff --git a/src/tags/musepack_header.h b/src/tags/musepack_header.h
index 58da0e8..33ab473 100644
--- a/src/tags/musepack_header.h
+++ b/src/tags/musepack_header.h
@@ -25,7 +25,7 @@
 
 G_BEGIN_DECLS
 
-gboolean mpc_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
+gboolean et_mpc_header_read_file_info (GFile *file, ET_File_Info *ETFileInfo, GError **error);
 EtFileHeaderFields * et_mpc_header_display_file_info_to_ui (const ET_File *ETFile);
 void et_mpc_file_header_fields_free (EtFileHeaderFields *fields);
 
diff --git a/src/tags/ogg_header.c b/src/tags/ogg_header.c
index c86a4d7..9cca686 100644
--- a/src/tags/ogg_header.c
+++ b/src/tags/ogg_header.c
@@ -32,18 +32,10 @@
 #include "vcedit.h"
 #endif
 
-#include "easytag.h"
 #include "ogg_header.h"
 #include "et_core.h"
-#include "charset.h"
-#include "log.h"
 #include "misc.h"
 
-
-/*************
- * Functions *
- *************/
-
 /*
  * et_ogg_error_quark:
  *
@@ -171,7 +163,6 @@ et_ogg_close_func (void *datasource)
 {
     EtOggState *state = (EtOggState *)datasource;
 
-    g_clear_object (&state->file);
     g_clear_object (&state->istream);
     g_clear_error (&state->error);
 
@@ -195,9 +186,9 @@ et_ogg_tell_func (void *datasource)
 }
 
 gboolean
-ogg_header_read_file_info (const gchar *filename,
-                           ET_File_Info *ETFileInfo,
-                           GError **error)
+et_ogg_header_read_file_info (GFile *file,
+                              ET_File_Info *ETFileInfo,
+                              GError **error)
 {
     OggVorbis_File vf;
     vorbis_info *vi;
@@ -206,29 +197,35 @@ ogg_header_read_file_info (const gchar *filename,
     glong rate = 0;
     glong bitrate_nominal = 0;
     gdouble duration = 0;
-    gulong filesize;
     gint res;
     ov_callbacks callbacks = { et_ogg_read_func, et_ogg_seek_func,
                                et_ogg_close_func, et_ogg_tell_func };
     EtOggState state;
-    gchar *filename_utf8;
+    GFileInfo *info;
 
-    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+    g_return_val_if_fail (file != NULL && ETFileInfo != NULL, FALSE);
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-    state.file = g_file_new_for_path (filename);
+    info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                              G_FILE_QUERY_INFO_NONE, NULL, error);
+
+    if (!info)
+    {
+        return FALSE;
+    }
+
+    ETFileInfo->size = g_file_info_get_size (info);
+    g_object_unref (info);
+
+    state.file = file;
     state.error = NULL;
     state.istream = G_INPUT_STREAM (g_file_read (state.file, NULL,
                                                  &state.error));
 
-    filename_utf8 = filename_to_display (filename);
-
     if (!state.istream)
     {
         g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                     _("Error while opening file ‘%s’: %s"), filename_utf8,
-                     state.error->message);
-        g_free (filename_utf8);
+                     _("Error while opening file: %s"), state.error->message);
         return FALSE;
     }
 
@@ -243,11 +240,9 @@ ogg_header_read_file_info (const gchar *filename,
         }
         else
         {
-            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                       _("The specified bitstream does not exist or the "
-                         "file has been initialized improperly (file: ‘%s’)"),
-                       filename_utf8);
-            g_free (filename_utf8);
+            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s",
+                         _("The specified bitstream does not exist or the "
+                         "file has been initialized improperly"));
             et_ogg_close_func (&state);
             return FALSE;
         }
@@ -287,23 +282,18 @@ ogg_header_read_file_info (const gchar *filename,
             g_set_error (error, state.error->domain, state.error->code,
                          "%s", message);
             et_ogg_close_func (&state);
-            g_free (filename_utf8);
             return FALSE;
         }
 
         et_ogg_close_func (&state);
     }
 
-    filesize = et_get_file_size (filename);
-
     ETFileInfo->version    = encoder_version;
     ETFileInfo->bitrate    = bitrate_nominal/1000;
     ETFileInfo->samplerate = rate;
     ETFileInfo->mode       = channels;
-    ETFileInfo->size       = filesize;
     ETFileInfo->duration   = duration;
 
-    g_free(filename_utf8);
     return TRUE;
 }
 
@@ -311,9 +301,9 @@ ogg_header_read_file_info (const gchar *filename,
 #ifdef ENABLE_SPEEX
 
 gboolean
-speex_header_read_file_info (const gchar *filename,
-                             ET_File_Info *ETFileInfo,
-                             GError **error)
+et_speex_header_read_file_info (GFile *file,
+                                ET_File_Info *ETFileInfo,
+                                GError **error)
 {
     vcedit_state *state;
     SpeexHeader  *si;
@@ -322,27 +312,35 @@ speex_header_read_file_info (const gchar *filename,
     glong rate = 0;
     glong bitrate = 0;
     gdouble duration = 0;
-    gulong filesize;
-    GFile *gfile;
+    GFileInfo *info;
     GError *tmp_error = NULL;
 
-    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+    g_return_val_if_fail (file != NULL && ETFileInfo != NULL, FALSE);
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     state = vcedit_new_state();    // Allocate memory for 'state'
-    gfile = g_file_new_for_path (filename);
 
-    if (!vcedit_open (state, gfile, &tmp_error))
+    if (!vcedit_open (state, file, &tmp_error))
     {
         g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                      _("Failed to open file as Vorbis: %s"),
                      tmp_error->message);
         g_error_free (tmp_error);
-        g_object_unref (gfile);
         vcedit_clear (state);
         return FALSE;
     }
 
+    info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+                              G_FILE_QUERY_INFO_NONE, NULL, error);
+
+    if (!info)
+    {
+        return FALSE;
+    }
+
+    ETFileInfo->size = g_file_info_get_size (info);
+    g_object_unref (info);
+
     // Get Speex information
     if ( (si=state->si) != NULL )
     {
@@ -358,20 +356,16 @@ speex_header_read_file_info (const gchar *filename,
         //g_print("compressed length: %ld bytes\n",(long)(ov_raw_total(&vf,-1)));
     }
 
-    filesize = et_get_file_size (filename);
-
     ETFileInfo->mpc_version = g_strdup(encoder_version);
     ETFileInfo->bitrate     = bitrate/1000;
     ETFileInfo->samplerate  = rate;
     ETFileInfo->mode        = channels;
-    ETFileInfo->size        = filesize;
     //if (bitrate > 0)
     //    ETFileInfo->duration = filesize*8/bitrate/1000; // FIXME : Approximation!! Needs to remove tag 
size!
     //else
         ETFileInfo->duration   = duration;
 
     vcedit_clear(state);
-    g_object_unref (gfile);
     return TRUE;
 }
 #endif
diff --git a/src/tags/ogg_header.h b/src/tags/ogg_header.h
index b4dfed3..533eea7 100644
--- a/src/tags/ogg_header.h
+++ b/src/tags/ogg_header.h
@@ -69,13 +69,11 @@ typedef enum
     ET_OGG_ERROR_OUTPUT
 } EtOGGError;
 
-gboolean ogg_header_read_file_info (const gchar *filename,
-                                    ET_File_Info *ETFileInfo,
-                                    GError **error);
+gboolean et_ogg_header_read_file_info (GFile *file, ET_File_Info *ETFileInfo, GError **error);
 EtFileHeaderFields * et_ogg_header_display_file_info_to_ui (const ET_File *ETFile);
 void et_ogg_file_header_fields_free (EtFileHeaderFields *fields);
 
-gboolean speex_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
+gboolean et_speex_header_read_file_info (GFile *file, ET_File_Info *ETFileInfo, GError **error);
 
 G_END_DECLS
 
diff --git a/src/tags/opus_header.c b/src/tags/opus_header.c
index 464d4db..6a8b282 100644
--- a/src/tags/opus_header.c
+++ b/src/tags/opus_header.c
@@ -200,7 +200,6 @@ et_opus_read_file_info (GFile *gfile, ET_File_Info *ETFileInfo,
 
 /*
  * et_opus_header_display_file_info_to_ui:
- * @filename: file to display info of
  * @ETFile: ET_File to display information
  *
  * Display header info from ET_File.
diff --git a/src/tags/wavpack_header.c b/src/tags/wavpack_header.c
index 46f2fbc..e90102a 100644
--- a/src/tags/wavpack_header.c
+++ b/src/tags/wavpack_header.c
@@ -17,37 +17,36 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <config.h>
+#include "config.h"
 
 #ifdef ENABLE_WAVPACK
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
 #include <wavpack/wavpack.h>
 
 #include "easytag.h"
 #include "et_core.h"
 #include "misc.h"
-#include "charset.h"
 #include "wavpack_header.h"
 
 
 gboolean
-wavpack_header_read_file_info (const gchar *filename,
-                               ET_File_Info *ETFileInfo,
-                               GError **error)
+et_wavpack_header_read_file_info (GFile *file,
+                                  ET_File_Info *ETFileInfo,
+                                  GError **error)
 {
+    gchar *filename;
     WavpackContext *wpc;
     gchar message[80];
 
-    g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+    g_return_val_if_fail (file != NULL && ETFileInfo != NULL, FALSE);
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     /* TODO: Use WavpackOpenFileInputEx() instead. */
+    filename = g_file_get_path (file);
     wpc = WavpackOpenFileInput (filename, message, 0, 0);
+    g_free (filename);
 
     if (wpc == NULL)
     {
diff --git a/src/tags/wavpack_header.h b/src/tags/wavpack_header.h
index 12ed760..c65330b 100644
--- a/src/tags/wavpack_header.h
+++ b/src/tags/wavpack_header.h
@@ -24,7 +24,7 @@
 
 G_BEGIN_DECLS
 
-gboolean wavpack_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
+gboolean et_wavpack_header_read_file_info (GFile *file, ET_File_Info *ETFileInfo, GError **error);
 EtFileHeaderFields * et_wavpack_header_display_file_info_to_ui (const ET_File *ETFile);
 void et_wavpack_file_header_fields_free (EtFileHeaderFields *fields);
 


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