commit 6b5d1cf8da6b0d2da96a9475f86f1dd7ecae9ee7
Author: phantomjinx <[email protected]>
Date: Sun Mar 13 18:12:24 2011 +0000
Refactor filetype getter functions to return GErrors
* Rather than display double warning dialogs, have the getter functions
populate a GError which is returned to the caller functions. The latter
use the message in the GError for augment a more general error message.
* Filetype plugins updated to populate the GError.
libgtkpod/file.c | 102 ++++++++++++++++++++++++++++++------
libgtkpod/file_convert.c | 2 +-
libgtkpod/filetype_iface.c | 46 ++++++++++-------
libgtkpod/filetype_iface.h | 38 +++++++------
plugins/filetype_flac/flacfile.c | 7 +--
plugins/filetype_flac/flacfile.h | 2 +-
plugins/filetype_m4a/m4afile.c | 15 +++---
plugins/filetype_m4a/m4afile.h | 6 +-
plugins/filetype_mp3/mp3file.c | 39 ++++++++------
plugins/filetype_mp3/mp3file.h | 13 +++--
plugins/filetype_mp4/mp4file.c | 32 +++++++----
plugins/filetype_mp4/mp4file.h | 6 +-
plugins/filetype_ogg/oggfile.c | 6 +-
plugins/filetype_ogg/oggfile.h | 2 +-
plugins/filetype_video/videofile.c | 2 +-
plugins/filetype_video/videofile.h | 2 +-
plugins/filetype_wav/wavfile.c | 6 +-
plugins/filetype_wav/wavfile.h | 2 +-
18 files changed, 212 insertions(+), 116 deletions(-)
---
diff --git a/libgtkpod/file.c b/libgtkpod/file.c
index 978df40..5f288bb 100644
--- a/libgtkpod/file.c
+++ b/libgtkpod/file.c
@@ -53,6 +53,8 @@
#include "misc_conversion.h"
#include "filetype_iface.h"
+#define UNKNOWN_ERROR "Unknown error"
+
/* The uppercase version of these extensions is tried as well. */
static const gchar *imageext[] =
{ ".jpg", ".jpeg", ".png", ".pbm", ".pgm", ".ppm", ".tif", ".tiff",
".gif", NULL };
@@ -977,6 +979,7 @@ Track *get_track_info_from_file(gchar *name, Track
*orig_track) {
FileType *filetype;
gint len;
gchar *name_utf8 = NULL;
+ GError *error = NULL;
g_return_val_if_fail (name, NULL);
@@ -1000,15 +1003,26 @@ Track *get_track_info_from_file(gchar *name, Track
*orig_track) {
return NULL;
filetype = determine_filetype(name);
- nti = filetype_get_file_info(filetype, name);
-
- if (!nti) {
+ if (!filetype) {
gtkpod_warning(
_("The filetype '%s' is not currently supported.\n\n"
"If you have a plugin that supports this filetype then
please enable it."), name_utf8);
return NULL;
}
+ nti = filetype_get_file_info(filetype, name, &error);
+ if (error || !nti) {
+ gtkpod_warning(_("No track information could be retrieved from the
file %s due to the following error:\n\n%s"), name_utf8, error->message);
+ g_error_free(error);
+ error = NULL;
+ g_free(name_utf8);
+ return NULL;
+ } else if (!nti) {
+ gtkpod_warning(_("No track information could be retrieved from the
file %s due to the following error:\n\nAn error was not returned."), name_utf8);
+ g_free(name_utf8);
+ return NULL;
+ }
+
switch (nti->mediatype) {
case ITDB_MEDIATYPE_AUDIOBOOK:
case ITDB_MEDIATYPE_PODCAST:
@@ -1612,14 +1626,14 @@ gboolean add_track_by_filename(iTunesDB *itdb, gchar
*fname, Playlist *plitem, g
\*------------------------------------------------------------------*/
/* Call the correct tag writing function for the filename @name */
-static gboolean file_write_info(gchar *name, Track *track) {
+static gboolean file_write_info(gchar *name, Track *track, GError *error) {
FileType *filetype;
g_return_val_if_fail (name, FALSE);
g_return_val_if_fail (track, FALSE);
filetype = determine_filetype(name);
- return filetype_write_file_info(filetype, name, track);
+ return filetype_write_file_info(filetype, name, track, &error);
}
/* Write tags to file */
@@ -1630,6 +1644,7 @@ gboolean write_tags_to_file(Track *track) {
gchar *prefs_charset = NULL;
Track *oldtrack;
gboolean track_charset_set;
+ GError *error = NULL;
g_return_val_if_fail (track, FALSE);
etr = track->userdata;
@@ -1653,15 +1668,33 @@ gboolean write_tags_to_file(Track *track) {
}
if (etr->pc_path_locale && (strlen(etr->pc_path_locale) > 0)) {
- if (file_write_info(etr->pc_path_locale, track) == FALSE) {
- gtkpod_warning(_("Couldn't change tags of file: %s\n"),
etr->pc_path_locale);
+ if (! file_write_info(etr->pc_path_locale, track, error)) {
+ gchar *msg = g_strdup_printf(_("Couldn't change tags of file:
%s"), etr->pc_path_locale);
+ if (error) {
+ gtkpod_warning("%s\n%s", msg, error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ else {
+ gtkpod_warning("%s\n%s", msg, UNKNOWN_ERROR);
+ }
+ g_free(msg);
}
}
if (!get_offline(itdb) && track->transferred && track->ipod_path &&
(g_utf8_strlen(track->ipod_path, -1) > 0)) {
/* need to get ipod filename */
ipod_fullpath = get_file_name_from_source(track, SOURCE_IPOD);
- if (file_write_info(ipod_fullpath, track) == FALSE) {
- gtkpod_warning(_("Couldn't change tags of file: %s\n"),
ipod_fullpath);
+ if (!file_write_info(ipod_fullpath, track, error)) {
+ gchar *msg = g_strdup_printf(_("Couldn't change tags of file:
%s\n"), ipod_fullpath);
+ if (error) {
+ gtkpod_warning("%s\n%s", msg, error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ else {
+ gtkpod_warning("%s\n%s", msg, UNKNOWN_ERROR);
+ }
+ g_free(msg);
}
g_free(ipod_fullpath);
}
@@ -1794,10 +1827,6 @@ void parse_offline_playcount(void) {
}
if (gp_increase_playcount(sha1, filename, 1) == FALSE) { /* didn't
find the track -> store */
gchar *filename_utf8 = charset_to_utf8(filename);
- /* if (gstr->len == 0) */
- /* { */
- /* gtkpod_warning (_("Couldn't find track for
playcount adjustment:\n")); */
- /* } */
g_string_append(gstr_filenames, filename_utf8);
g_string_append(gstr_filenames, "\n");
g_free(filename_utf8);
@@ -1858,12 +1887,33 @@ void parse_offline_playcount(void) {
gboolean read_soundcheck(Track *track) {
gchar *path;
FileType *filetype;
+ gboolean result = FALSE;
+ GError *error = NULL;
+ gchar *msg = g_strdup_printf(_("Failed to read sound check from track
because"));
g_return_val_if_fail (track, FALSE);
path = get_file_name_from_source(track, SOURCE_PREFER_LOCAL);
filetype = determine_filetype(path);
- return filetype_read_soundcheck(filetype, path, track);
+ if (! filetype) {
+ gtkpod_warning(_("%s\n\nfiletype of %s is not recognised."), msg,
path);
+ }
+ else {
+ if (!filetype_read_soundcheck(filetype, path, track, &error)) {
+ if (error) {
+ gtkpod_warning(_("%s\n\n%s"), msg, error->message);
+ } else {
+ gtkpod_warning(_("%s\n\n%s"), msg, UNKNOWN_ERROR);
+ }
+ } else {
+ // track read successfully
+ result = TRUE;
+ }
+ }
+
+ g_free(path);
+ g_free(msg);
+ return result;
}
/* Get lyrics from file */
@@ -1872,6 +1922,7 @@ gboolean read_lyrics_from_file(Track *track, gchar
**lyrics) {
gboolean result = FALSE;
ExtraTrackData *etr;
FileType *filetype;
+ GError *error = NULL;
g_return_val_if_fail (track, FALSE);
etr = track->userdata;
@@ -1883,7 +1934,16 @@ gboolean read_lyrics_from_file(Track *track, gchar
**lyrics) {
*lyrics = g_strdup_printf(_("Error: Could not determine filetype
for file at path: %s.\n\n"), path);
}
else {
- result = filetype_read_lyrics(filetype, path, lyrics);
+ result = filetype_read_lyrics(filetype, path, lyrics, &error);
+ if (!result) {
+ if (error) {
+ *lyrics = g_strdup_printf(_("Error: Failed to read lyrics
because:\n\n%s"), error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ else
+ *lyrics = g_strdup_printf(_("Error: Failed to read lyrics
because:\n\n%s"), UNKNOWN_ERROR);
+ }
}
} else {
*lyrics = g_strdup_printf(_("Error: Unable to get filename from
path"));
@@ -1911,6 +1971,7 @@ gboolean write_lyrics_to_file(Track *track) {
ExtraTrackData *etr;
iTunesDB *itdb;
FileType *filetype;
+ GError *error = NULL;
g_return_val_if_fail (track, FALSE);
etr = track->userdata;
@@ -1943,7 +2004,16 @@ gboolean write_lyrics_to_file(Track *track) {
}
}
else {
- result = filetype_write_lyrics(filetype, path, etr->lyrics);
+ result = filetype_write_lyrics(filetype, path, etr->lyrics, &error);
+ if (!result) {
+ if (error) {
+ gtkpod_warning(_("Lyrics not written due to the
error:\n\n%s"), error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ else
+ gtkpod_warning(_("Lyrics not written due to the error:\n%s"),
UNKNOWN_ERROR);
+ }
}
g_free(path);
diff --git a/libgtkpod/file_convert.c b/libgtkpod/file_convert.c
index 980f080..dd4d1ba 100644
--- a/libgtkpod/file_convert.c
+++ b/libgtkpod/file_convert.c
@@ -2103,7 +2103,7 @@ static gboolean conversion_convert_track(Conversion
*conv, ConvTrack *ctr) {
if (filetype) {
file_convert_lock(conv);
track = gp_track_new();
- retval = filetype_read_gapless(filetype, ctr->converted_file,
track);
+ retval = filetype_read_gapless(filetype, ctr->converted_file,
track, NULL);
if (ctr->valid && (retval == TRUE)) {
ctr->gapless.pregap = track->pregap;
diff --git a/libgtkpod/filetype_iface.c b/libgtkpod/filetype_iface.c
index ce088c4..3fa5325 100644
--- a/libgtkpod/filetype_iface.c
+++ b/libgtkpod/filetype_iface.c
@@ -31,6 +31,7 @@
#include <glib/gi18n-lib.h>
#include "gp_itdb.h"
+#include "gp_private.h"
#include "file.h"
#include "filetype_iface.h"
@@ -96,22 +97,22 @@ GList *filetype_get_suffixes(FileType *filetype) {
return FILE_TYPE_GET_INTERFACE(filetype)->suffixes;
}
-Track *filetype_get_file_info(FileType *filetype, const gchar *filename) {
+Track *filetype_get_file_info(FileType *filetype, const gchar *filename,
GError **error) {
if (!FILE_IS_TYPE(filetype))
return NULL;
- return FILE_TYPE_GET_INTERFACE(filetype)->get_file_info(filename);
+ return FILE_TYPE_GET_INTERFACE(filetype)->get_file_info(filename, error);
}
-gboolean filetype_write_file_info(FileType *filetype, const gchar *filename,
Track *track) {
+gboolean filetype_write_file_info(FileType *filetype, const gchar *filename,
Track *track, GError **error) {
if (!FILE_IS_TYPE(filetype))
return FALSE;
- return FILE_TYPE_GET_INTERFACE(filetype)->write_file_info(filename, track);
+ return FILE_TYPE_GET_INTERFACE(filetype)->write_file_info(filename, track,
error);
}
-gboolean filetype_read_soundcheck(FileType *filetype, const gchar *filename,
Track *track) {
+gboolean filetype_read_soundcheck(FileType *filetype, const gchar *filename,
Track *track, GError **error) {
if (!FILE_IS_TYPE(filetype))
return FALSE;
- return FILE_TYPE_GET_INTERFACE(filetype)->read_soundcheck(filename, track);
+ return FILE_TYPE_GET_INTERFACE(filetype)->read_soundcheck(filename, track,
error);
}
gchar *filetype_get_gain_cmd(FileType *filetype) {
@@ -120,22 +121,22 @@ gchar *filetype_get_gain_cmd(FileType *filetype) {
return FILE_TYPE_GET_INTERFACE(filetype)->get_gain_cmd();
}
-gboolean filetype_read_lyrics(FileType *filetype, const gchar *filename, gchar
**lyrics) {
+gboolean filetype_read_lyrics(FileType *filetype, const gchar *filename, gchar
**lyrics, GError **error) {
if (!FILE_IS_TYPE(filetype))
return FALSE;
- return FILE_TYPE_GET_INTERFACE(filetype)->read_lyrics(filename, lyrics);
+ return FILE_TYPE_GET_INTERFACE(filetype)->read_lyrics(filename, lyrics,
error);
}
-gboolean filetype_write_lyrics(FileType *filetype, const gchar *filename,
const gchar *lyrics) {
+gboolean filetype_write_lyrics(FileType *filetype, const gchar *filename,
const gchar *lyrics, GError **error) {
if (!FILE_IS_TYPE(filetype))
return FALSE;
- return FILE_TYPE_GET_INTERFACE(filetype)->write_lyrics(filename, lyrics);
+ return FILE_TYPE_GET_INTERFACE(filetype)->write_lyrics(filename, lyrics,
error);
}
-gboolean filetype_read_gapless(FileType *filetype, const gchar *filename,
Track *track) {
+gboolean filetype_read_gapless(FileType *filetype, const gchar *filename,
Track *track, GError **error) {
if (!FILE_IS_TYPE(filetype))
return FALSE;
- return FILE_TYPE_GET_INTERFACE(filetype)->read_gapless(filename, track);
+ return FILE_TYPE_GET_INTERFACE(filetype)->read_gapless(filename, track,
error);
}
gboolean filetype_can_convert(FileType *filetype) {
@@ -168,15 +169,15 @@ gboolean filetype_is_audio_filetype(FileType *filetype) {
return FILE_TYPE_GET_INTERFACE(filetype)->category == AUDIO;
}
-Track *filetype_no_track_info(const gchar *name) {
+Track *filetype_no_track_info(const gchar *name, GError **error) {
return NULL;
}
-gboolean filetype_no_write_file_info(const gchar *filename, Track *track) {
+gboolean filetype_no_write_file_info(const gchar *filename, Track *track,
GError **error) {
return FALSE;
}
-gboolean filetype_no_soundcheck(const gchar *filename, Track *track) {
+gboolean filetype_no_soundcheck(const gchar *filename, Track *track, GError
**error) {
return FALSE;
}
@@ -184,16 +185,17 @@ gchar *filetype_no_gain_cmd() {
return NULL;
}
-gboolean filetype_no_read_lyrics(const gchar *filename, gchar **lyrics) {
- *lyrics = g_strdup(_("Error: Lyrics not supported for this file format."));
+gboolean filetype_no_read_lyrics(const gchar *filename, gchar **lyrics, GError
**error) {
+ filetype_log_error (error,
+ _("Error: Lyrics not supported for this file format."));
return FALSE;
}
-gboolean filetype_no_write_lyrics(const gchar *filename, const gchar *lyrics) {
+gboolean filetype_no_write_lyrics(const gchar *filename, const gchar *lyrics,
GError **error) {
return FALSE;
}
-gboolean filetype_no_read_gapless(const gchar *filename, Track *track) {
+gboolean filetype_no_read_gapless(const gchar *filename, Track *track, GError
**error) {
return FALSE;
}
@@ -205,3 +207,9 @@ gchar * filetype_no_conversion_cmd() {
return NULL;
}
+void filetype_log_error(GError **error, gchar *msg) {
+ g_set_error (error,
+ GTKPOD_GENERAL_ERROR, /* error domain */
+ GTKPOD_GENERAL_ERROR_FAILED, /* error code */
+ msg);
+}
diff --git a/libgtkpod/filetype_iface.h b/libgtkpod/filetype_iface.h
index 9fe0d62..271fdf9 100644
--- a/libgtkpod/filetype_iface.h
+++ b/libgtkpod/filetype_iface.h
@@ -58,12 +58,12 @@ struct _FileTypeInterface {
gchar *description;
GList *suffixes;
filetype_category category;
- Track * (* get_file_info) (const gchar *filename);
- gboolean (* write_file_info) (const gchar *filename, Track *track);
- gboolean (* read_soundcheck) (const gchar *filename, Track *track);
- gboolean (* read_lyrics) (const gchar *filename, gchar **lyrics);
- gboolean (* write_lyrics) (const gchar *filename, const gchar *lyrics);
- gboolean (* read_gapless) (const gchar *filename, Track *track);
+ Track * (* get_file_info) (const gchar *filename, GError **error);
+ gboolean (* write_file_info) (const gchar *filename, Track *track, GError
**error);
+ gboolean (* read_soundcheck) (const gchar *filename, Track *track, GError
**error);
+ gboolean (* read_lyrics) (const gchar *filename, gchar **lyrics, GError
**error);
+ gboolean (* write_lyrics) (const gchar *filename, const gchar *lyrics,
GError **error);
+ gboolean (* read_gapless) (const gchar *filename, Track *track, GError
**error);
gchar * (* get_gain_cmd) (void);
gboolean (* can_convert) (void);
gchar * (* get_conversion_cmd) (void);
@@ -118,13 +118,13 @@ void filetype_init_core_types(GHashTable *typetable);
gchar *filetype_get_name(FileType *filetype);
gchar *filetype_get_description(FileType *filetype);
GList *filetype_get_suffixes(FileType *filetype);
-Track *filetype_get_file_info (FileType *filetype, const gchar *filename);
-gboolean filetype_write_file_info (FileType *filetype, const gchar *filename,
Track *track);
-gboolean filetype_read_soundcheck (FileType *filetype, const gchar *filename,
Track *track);
+Track *filetype_get_file_info (FileType *filetype, const gchar *filename,
GError **error);
+gboolean filetype_write_file_info (FileType *filetype, const gchar *filename,
Track *track, GError **error);
+gboolean filetype_read_soundcheck (FileType *filetype, const gchar *filename,
Track *track, GError **error);
gchar *filetype_get_gain_cmd(FileType *filetype);
-gboolean filetype_read_lyrics (FileType *filetype, const gchar *filename,
gchar **lyrics);
-gboolean filetype_write_lyrics (FileType *filetype, const gchar *filename,
const gchar *lyrics);
-gboolean filetype_read_gapless(FileType *filetype, const gchar *filename,
Track *track);
+gboolean filetype_read_lyrics (FileType *filetype, const gchar *filename,
gchar **lyrics, GError **error);
+gboolean filetype_write_lyrics (FileType *filetype, const gchar *filename,
const gchar *lyrics, GError **error);
+gboolean filetype_read_gapless(FileType *filetype, const gchar *filename,
Track *track, GError **error);
gboolean filetype_can_convert(FileType *filetype);
gchar *filetype_get_conversion_cmd(FileType *filetype);
@@ -136,14 +136,16 @@ gboolean filetype_is_audio_filetype(FileType *filetype);
gboolean filetype_is_m3u_filetype(FileType *filetype);
gboolean filetype_is_pls_filetype(FileType *filetype);
-Track *filetype_no_track_info(const gchar *name);
-gboolean filetype_no_write_file_info (const gchar *filename, Track *track);
-gboolean filetype_no_soundcheck (const gchar *filename, Track *track);
-gboolean filetype_no_read_lyrics (const gchar *filename, gchar **lyrics);
-gboolean filetype_no_write_lyrics (const gchar *filename, const gchar *lyrics);
-gboolean filetype_no_read_gapless (const gchar *filename, Track *track);
+Track *filetype_no_track_info(const gchar *name, GError **error);
+gboolean filetype_no_write_file_info (const gchar *filename, Track *track,
GError **error);
+gboolean filetype_no_soundcheck (const gchar *filename, Track *track, GError
**error);
+gboolean filetype_no_read_lyrics (const gchar *filename, gchar **lyrics,
GError **error);
+gboolean filetype_no_write_lyrics (const gchar *filename, const gchar *lyrics,
GError **error);
+gboolean filetype_no_read_gapless (const gchar *filename, Track *track, GError
**error);
gchar *filetype_no_gain_cmd();
gboolean filetype_no_convert();
gchar *filetype_no_conversion_cmd();
+void filetype_log_error(GError **error, gchar *msg);
+
#endif /* FILE_TYPE_IFACE_H_ */
diff --git a/plugins/filetype_flac/flacfile.c b/plugins/filetype_flac/flacfile.c
index 617b0c9..b455f4e 100644
--- a/plugins/filetype_flac/flacfile.c
+++ b/plugins/filetype_flac/flacfile.c
@@ -45,7 +45,7 @@
#include <string.h>
#include <FLAC/metadata.h>
-Track *flac_get_file_info(const gchar *flacFileName) {
+Track *flac_get_file_info(const gchar *flacFileName, GError **error) {
Track *track = NULL;
FLAC__StreamMetadata stream_data;
FLAC__StreamMetadata *tags;
@@ -54,7 +54,7 @@ Track *flac_get_file_info(const gchar *flacFileName) {
gchar *filename = NULL;
filename = charset_to_utf8(flacFileName);
- gtkpod_warning(_("'%s' does not appear to be an FLAC audio file.\n"),
filename);
+ filetype_log_error(error, g_strdup_printf(_("'%s' does not appear to
be an FLAC audio file.\n"), filename));
g_free(filename);
}
else {
@@ -67,9 +67,8 @@ Track *flac_get_file_info(const gchar *flacFileName) {
if (!FLAC__metadata_get_tags(flacFileName, &tags)) {
gchar *filename = NULL;
filename = charset_to_utf8(flacFileName);
- gtkpod_warning(_("Error retrieving tags for '%s'.\n"),
filename);
+ filetype_log_error(error, g_strdup_printf(_("Error retrieving
tags for '%s'.\n"), filename));
g_free(filename);
- /* FIXME: should NULL be returned if no tags? */
}
else {
gint i;
diff --git a/plugins/filetype_flac/flacfile.h b/plugins/filetype_flac/flacfile.h
index 0572fb7..5ff19a4 100644
--- a/plugins/filetype_flac/flacfile.h
+++ b/plugins/filetype_flac/flacfile.h
@@ -31,7 +31,7 @@
#include "libgtkpod/itdb.h"
-Track *flac_get_file_info (const gchar *flacFileName);
+Track *flac_get_file_info (const gchar *flacFileName, GError **error);
gboolean flac_can_convert();
gchar *flac_get_conversion_cmd();
diff --git a/plugins/filetype_m4a/m4afile.c b/plugins/filetype_m4a/m4afile.c
index 6a5d958..418639b 100644
--- a/plugins/filetype_m4a/m4afile.c
+++ b/plugins/filetype_m4a/m4afile.c
@@ -39,11 +39,12 @@
/* Info on how to implement new file formats: see mp3file.c for more info */
-Track *m4a_get_file_info(const gchar *m4aFileName) {
+Track *m4a_get_file_info(const gchar *m4aFileName, GError **error) {
gchar *path_utf8;
gchar *suf;
- Track *track = mp4_get_file_info(m4aFileName);
- g_return_val_if_fail(track, NULL);
+ Track *track = mp4_get_file_info(m4aFileName, error);
+ if (!track || error)
+ return track;
path_utf8 = charset_to_utf8(m4aFileName);
suf = strrchr(path_utf8, '.') + 1;
@@ -56,12 +57,12 @@ Track *m4a_get_file_info(const gchar *m4aFileName) {
return track;
}
-gboolean m4a_write_file_info(const gchar *filename, Track *track) {
- return mp4_write_file_info(filename, track);
+gboolean m4a_write_file_info(const gchar *filename, Track *track, GError
**error) {
+ return mp4_write_file_info(filename, track, error);
}
-gboolean m4a_read_soundcheck(const gchar *filename, Track *track) {
- return mp4_read_soundcheck(filename, track);
+gboolean m4a_read_soundcheck(const gchar *filename, Track *track, GError
**error) {
+ return mp4_read_soundcheck(filename, track, error);
}
gboolean m4a_can_convert() {
diff --git a/plugins/filetype_m4a/m4afile.h b/plugins/filetype_m4a/m4afile.h
index 6801ae7..832de9a 100644
--- a/plugins/filetype_m4a/m4afile.h
+++ b/plugins/filetype_m4a/m4afile.h
@@ -31,9 +31,9 @@
#include "libgtkpod/itdb.h"
-Track *m4a_get_file_info (const gchar *m4aFileName);
-gboolean m4a_write_file_info (const gchar *filename, Track *track);
-gboolean m4a_read_soundcheck (const gchar *filename, Track *track);
+Track *m4a_get_file_info (const gchar *m4aFileName, GError **error);
+gboolean m4a_write_file_info (const gchar *filename, Track *track, GError
**error);
+gboolean m4a_read_soundcheck (const gchar *filename, Track *track, GError
**error);
gboolean m4a_can_convert();
gchar *m4a_get_conversion_cmd();
gchar *m4a_get_gain_cmd();
diff --git a/plugins/filetype_mp3/mp3file.c b/plugins/filetype_mp3/mp3file.c
index 3b5ef9a..f946ce0 100644
--- a/plugins/filetype_mp3/mp3file.c
+++ b/plugins/filetype_mp3/mp3file.c
@@ -55,6 +55,8 @@
#include <glib.h>
#include <math.h>
+#include "libgtkpod/filetype_iface.h"
+
/*
* Description of each item of the TagList list
*/
@@ -1561,15 +1563,16 @@ void set_uncommon_tag(struct id3_tag *id3tag, const
gchar *id, const gchar *text
* Write the ID3 tags to the file.
* @returns: TRUE on success, else FALSE.
*/
-gboolean mp3_write_file_info(const gchar *filename, Track *track) {
+gboolean mp3_write_file_info(const gchar *filename, Track *track, GError
**error) {
struct id3_tag* id3tag;
struct id3_file* id3file;
- gint error = 0;
+ gint errorno = 0;
id3file = id3_file_open(filename, ID3_FILE_MODE_READWRITE);
if (!id3file) {
gchar *fbuf = charset_to_utf8(filename);
- g_print(_("ERROR while opening file: '%s' (%s).\n"), fbuf,
g_strerror(errno));
+ filetype_log_error(error,
+ g_strdup_printf(_("ERROR while opening file: '%s' (%s).\n"),
fbuf, g_strerror(errno)));
g_free(fbuf);
return FALSE;
}
@@ -1643,14 +1646,15 @@ gboolean mp3_write_file_info(const gchar *filename,
Track *track) {
if (id3_file_update(id3file) != 0) {
gchar *fbuf = charset_to_utf8(filename);
- g_print(_("ERROR while writing tag to file: '%s' (%s).\n"), fbuf,
g_strerror(errno));
+ filetype_log_error(error,
+ g_strdup_printf(_("ERROR while writing tag to file: '%s'
(%s).\n"), fbuf, g_strerror(errno)));
g_free(fbuf);
return FALSE;
}
id3_file_close(id3file);
- if (error)
+ if (errorno)
return FALSE;
else
return TRUE;
@@ -2239,7 +2243,7 @@ gboolean mp3_get_track_ape_replaygain(const gchar *path,
GainData *gd) {
*
* Returns TRUE if the soundcheck field could be set.
*/
-gboolean mp3_read_soundcheck(const gchar *path, Track *track) {
+gboolean mp3_read_soundcheck(const gchar *path, Track *track, GError **error) {
GainData gd;
gint replaygain_offset;
gint replaygain_mode_album_priority;
@@ -2524,7 +2528,7 @@ gboolean mp3_get_track_gapless(MP3Info *mp3i, GaplessData
*gd) {
* FALSE otherwise.
*/
-gboolean mp3_read_gapless(const gchar *path, Track *track) {
+gboolean mp3_read_gapless(const gchar *path, Track *track, GError **error) {
MP3Info *mp3i = NULL;
FILE *file;
@@ -2756,7 +2760,7 @@ gboolean id3_read_tags(const gchar *name, Track *track) {
/* Return a Track structure with all information read from the mp3
file filled in */
-Track *mp3_get_file_info(const gchar *name) {
+Track *mp3_get_file_info(const gchar *name, GError **error) {
Track *track = NULL;
MP3Info *mp3i = NULL;
FILE *file;
@@ -2775,7 +2779,8 @@ Track *mp3_get_file_info(const gchar *name) {
}
else {
gchar *fbuf = charset_to_utf8(name);
- gtkpod_warning(_("ERROR while opening file: '%s' (%s).\n"), fbuf,
g_strerror(errno));
+ filetype_log_error(error,
+ g_strdup_printf(_("ERROR while opening file: '%s' (%s).\n"),
fbuf, g_strerror(errno)));
g_free(fbuf);
return NULL;
}
@@ -2787,9 +2792,9 @@ Track *mp3_get_file_info(const gchar *name) {
id3_read_tags(name, track);
}
- mp3_read_soundcheck(name, track);
+ mp3_read_soundcheck(name, track, error);
- mp3_read_gapless(name, track);
+ mp3_read_gapless(name, track, error);
/* Get additional info (play time and bitrate */
if (mp3i) {
@@ -2807,7 +2812,8 @@ Track *mp3_get_file_info(const gchar *name) {
if (track->tracklen == 0) {
/* Tracks with zero play length are ignored by iPod... */
- gtkpod_warning(_("File \"%s\" has zero play length. Ignoring.\n"),
name);
+ filetype_log_error(error,
+ g_strdup_printf(_("File \"%s\" has zero play length.
Ignoring.\n"), name));
gp_track_free(track);
track = NULL;
}
@@ -2820,8 +2826,8 @@ Track *mp3_get_file_info(const gchar *name) {
track->mediatype = ITDB_MEDIATYPE_AUDIOBOOK;
else if (g_ascii_strcasecmp (track->genre, "podcast") == 0)
track->mediatype = ITDB_MEDIATYPE_PODCAST;
- }
}
+ }
return track;
}
@@ -2829,7 +2835,7 @@ Track *mp3_get_file_info(const gchar *name) {
*
* @returns: TRUE on success, else FALSE.
*/
-gboolean id3_lyrics_read(const gchar *filename, gchar **lyrics) {
+gboolean id3_lyrics_read(const gchar *filename, gchar **lyrics, GError
**error) {
struct id3_file *id3file;
struct id3_tag *id3tag;
@@ -2838,7 +2844,8 @@ gboolean id3_lyrics_read(const gchar *filename, gchar
**lyrics) {
if (!(id3file = id3_file_open(filename, ID3_FILE_MODE_READONLY))) {
gchar *fbuf = charset_to_utf8(filename);
- g_print(_("ERROR while opening file: '%s' (%s).\n"), fbuf,
g_strerror(errno));
+ filetype_log_error(error,
+ g_strdup_printf(_("ERROR while opening file: '%s'
(%s).\n"), fbuf, g_strerror(errno)));
g_free(fbuf);
return FALSE;
}
@@ -2851,7 +2858,7 @@ gboolean id3_lyrics_read(const gchar *filename, gchar
**lyrics) {
return TRUE;
}
-gboolean id3_lyrics_save(const gchar *filename, const gchar *lyrics) {
+gboolean id3_lyrics_save(const gchar *filename, const gchar *lyrics, GError
**error) {
struct id3_file *id3file;
struct id3_tag *id3tag;
diff --git a/plugins/filetype_mp3/mp3file.h b/plugins/filetype_mp3/mp3file.h
index 46640a3..615d074 100644
--- a/plugins/filetype_mp3/mp3file.h
+++ b/plugins/filetype_mp3/mp3file.h
@@ -32,15 +32,16 @@
#include "plugin.h"
#include "libgtkpod/itdb.h"
+#include "libgtkpod/gp_private.h"
-gboolean mp3_write_file_info (const gchar *filename, Track *track);
-Track *mp3_get_file_info (const gchar *name);
-gboolean mp3_read_soundcheck (const gchar *path, Track *track);
-gboolean mp3_read_gapless (const gchar *path, Track *track);
+gboolean mp3_write_file_info (const gchar *filename, Track *track, GError
**error);
+Track *mp3_get_file_info (const gchar *name, GError **error);
+gboolean mp3_read_soundcheck (const gchar *path, Track *track, GError **error);
+gboolean mp3_read_gapless (const gchar *path, Track *track, GError **error);
gboolean id3_read_tags (const gchar *name, Track *track);
-gboolean id3_lyrics_read (const gchar *filename, gchar **lyrics);
-gboolean id3_lyrics_save (const gchar *filename, const gchar *lyrics);
+gboolean id3_lyrics_read (const gchar *filename, gchar **lyrics, GError
**error);
+gboolean id3_lyrics_save (const gchar *filename, const gchar *lyrics, GError
**error);
gboolean mp3_can_convert();
gchar *mp3_get_conversion_cmd();
diff --git a/plugins/filetype_mp4/mp4file.c b/plugins/filetype_mp4/mp4file.c
index 725d777..fdf6258 100644
--- a/plugins/filetype_mp4/mp4file.c
+++ b/plugins/filetype_mp4/mp4file.c
@@ -545,9 +545,10 @@ static gboolean mp4_scan_soundcheck(MP4FileHandle mp4File,
Track *track) {
return success;
}
-gboolean mp4_read_soundcheck(const gchar *mp4FileName, Track *track) {
+gboolean mp4_read_soundcheck(const gchar *mp4FileName, Track *track, GError
**error) {
if (!mp4v2_handle) {
- gtkpod_warning(_("m4a/m4p/m4b soundcheck update for '%s' failed:
m4a/m4p/m4b not supported without the mp4v2 library. You must install the mp4v2
library.\n"), mp4FileName);
+ filetype_log_error(error,
+ g_strdup_printf(_("m4a/m4p/m4b soundcheck update for '%s'
failed: m4a/m4p/m4b/mp4 not supported without the mp4v2 library. You must
install the mp4v2 library.\n"), mp4FileName));
return FALSE;
}
@@ -581,23 +582,25 @@ gboolean mp4_read_soundcheck(const gchar *mp4FileName,
Track *track) {
}
if (!audio_or_video_found) {
gchar *filename = charset_to_utf8(mp4FileName);
- gtkpod_warning(_("'%s' does not appear to be a mp4 audio or video
file.\n"), filename);
+ filetype_log_error(error,
+ g_strdup_printf(_("'%s' does not appear to be a
m4a/m4b/m4v/mp4 audio or video file.\n"), filename));
g_free(filename);
}
MP4Close(mp4File);
}
else {
gchar *filename = charset_to_utf8(mp4FileName);
- gtkpod_warning(_("Could not open '%s' for reading, or file is not an
mp4 file.\n"), filename);
+ filetype_log_error(error,
+ g_strdup_printf(_("Could not open '%s' for
reading, or file is not an m4a/m4b/m4v/mp4 file.\n"), filename));
g_free(filename);
}
return success;
}
-Track *mp4_get_file_info(const gchar *mp4FileName) {
+Track *mp4_get_file_info(const gchar *mp4FileName, GError **error) {
if (!mp4v2_handle) {
- gtkpod_warning(_("Import of '%s' failed: m4a/m4p/m4b not supported
without the mp4v2 library. You must install the mp4v2 library.\n"),
mp4FileName);
+ filetype_log_error(error, g_strdup_printf(_("Import of '%s' failed:
file type not supported without the mp4v2 library. You must install the mp4v2
library.\n"), mp4FileName));
return NULL;
}
@@ -845,23 +848,26 @@ Track *mp4_get_file_info(const gchar *mp4FileName) {
}
if (!audio_or_video_found) {
gchar *filename = charset_to_utf8(mp4FileName);
- gtkpod_warning(_("'%s' does not appear to be a mp4 audio or video
file.\n"), filename);
+ filetype_log_error(error,
+ g_strdup_printf(_("'%s' does not appear to be a
m4a/m4p/m4b/mp4 audio or video file.\n"), filename));
g_free(filename);
}
MP4Close(mp4File);
}
else {
gchar *filename = charset_to_utf8(mp4FileName);
- gtkpod_warning(_("Could not open '%s' for reading, or file is not an
mp4 file.\n"), filename);
+ filetype_log_error(error,
+ g_strdup_printf(_("Could not open '%s' for
reading, or file is not an mp4 file.\n"), filename));
g_free(filename);
}
return track;
}
-gboolean mp4_write_file_info(const gchar *mp4FileName, Track *track) {
+gboolean mp4_write_file_info(const gchar *mp4FileName, Track *track, GError
**error) {
if (!mp4v2_handle) {
- gtkpod_warning(_("m4a/m4p/m4b metadata update for '%s' failed:
m4a/m4p/m4b not supported without the mp4v2 library. You must install the mp4v2
library.\n"), mp4FileName);
+ filetype_log_error(error,
+ g_strdup_printf(_("m4a/m4p/m4b/mp4
metadata update for '%s' failed: m4a/m4p/m4b not supported without the mp4v2
library. You must install the mp4v2 library.\n"), mp4FileName));
return FALSE;
}
@@ -983,7 +989,8 @@ gboolean mp4_write_file_info(const gchar *mp4FileName,
Track *track) {
}
else {
gchar *filename = charset_to_utf8(mp4FileName);
- gtkpod_warning(_("'%s' does not appear to be a mp4 audio
file.\n"), filename);
+ filetype_log_error(error,
+ g_strdup_printf(_("'%s' does not
appear to be a m4a/m4b/m4v/mp4 audio file.\n"), filename));
g_free(filename);
result = FALSE;
}
@@ -991,7 +998,8 @@ gboolean mp4_write_file_info(const gchar *mp4FileName,
Track *track) {
}
else {
gchar *filename = charset_to_utf8(mp4FileName);
- gtkpod_warning(_("Could not open '%s' for writing, or file is not an
mp4 file.\n"), filename);
+ filetype_log_error(error,
+ g_strdup_printf(_("Could not open '%s' for
writing, or file is not an m4a/m4b/m4v/mp4 file.\n"), filename));
g_free(filename);
result = FALSE;
}
diff --git a/plugins/filetype_mp4/mp4file.h b/plugins/filetype_mp4/mp4file.h
index 5bbbac5..27fde63 100644
--- a/plugins/filetype_mp4/mp4file.h
+++ b/plugins/filetype_mp4/mp4file.h
@@ -35,7 +35,7 @@
void mp4_init();
void mp4_close();
-gboolean mp4_write_file_info (const gchar *filename, Track *track);
-Track *mp4_get_file_info (const gchar *name);
-gboolean mp4_read_soundcheck (const gchar *filename, Track *track);
+gboolean mp4_write_file_info (const gchar *filename, Track *track, GError
**error);
+Track *mp4_get_file_info (const gchar *name, GError **error);
+gboolean mp4_read_soundcheck (const gchar *filename, Track *track, GError
**error);
#endif
diff --git a/plugins/filetype_ogg/oggfile.c b/plugins/filetype_ogg/oggfile.c
index 96c94c3..b653040 100644
--- a/plugins/filetype_ogg/oggfile.c
+++ b/plugins/filetype_ogg/oggfile.c
@@ -55,7 +55,7 @@
* A widely used suggested usage of the fields can be found here:
* http://wiki.xiph.org/index.php/VorbisComment
*/
-Track *ogg_get_file_info(const gchar *oggFileName) {
+Track *ogg_get_file_info(const gchar *oggFileName, GError **error) {
Track *track = NULL;
FILE *file = NULL;
@@ -63,7 +63,7 @@ Track *ogg_get_file_info(const gchar *oggFileName) {
if (file == NULL) {
gchar *filename = charset_to_utf8(oggFileName);
- gtkpod_warning(_("Could not open '%s' for reading.\n"), filename);
+ filetype_log_error(error, g_strdup_printf(_("Could not open '%s' for
reading.\n"), filename));
g_free(filename);
}
else {
@@ -71,7 +71,7 @@ Track *ogg_get_file_info(const gchar *oggFileName) {
if (ov_open(file, &oggFile, NULL, 0) != 0) {
gchar *filename = NULL;
filename = charset_to_utf8(oggFileName);
- gtkpod_warning(_("'%s' does not appear to be an Ogg audio
file.\n"), filename);
+ filetype_log_error(error, g_strdup_printf(_("'%s' does not appear
to be an Ogg audio file.\n"), filename));
g_free(filename);
fclose(file);
}
diff --git a/plugins/filetype_ogg/oggfile.h b/plugins/filetype_ogg/oggfile.h
index 09ce5b4..9d59441 100644
--- a/plugins/filetype_ogg/oggfile.h
+++ b/plugins/filetype_ogg/oggfile.h
@@ -31,7 +31,7 @@
#include "libgtkpod/itdb.h"
-Track *ogg_get_file_info (const gchar *name);
+Track *ogg_get_file_info (const gchar *name, GError **error);
gboolean ogg_can_convert();
gchar *ogg_get_conversion_cmd();
diff --git a/plugins/filetype_video/videofile.c
b/plugins/filetype_video/videofile.c
index db73a4f..b973a17 100644
--- a/plugins/filetype_video/videofile.c
+++ b/plugins/filetype_video/videofile.c
@@ -38,7 +38,7 @@
#include "plugin.h"
#include "videofile.h"
-Track *video_get_file_info(const gchar *filename) {
+Track *video_get_file_info(const gchar *filename, GError **error) {
Track *track = NULL;
track = gp_track_new();
diff --git a/plugins/filetype_video/videofile.h
b/plugins/filetype_video/videofile.h
index dcc2381..b3c2d5f 100644
--- a/plugins/filetype_video/videofile.h
+++ b/plugins/filetype_video/videofile.h
@@ -32,7 +32,7 @@
#include "libgtkpod/itdb.h"
-Track *video_get_file_info(const gchar *name);
+Track *video_get_file_info(const gchar *name, GError **error);
gboolean video_can_convert();
gchar *video_get_conversion_cmd();
diff --git a/plugins/filetype_wav/wavfile.c b/plugins/filetype_wav/wavfile.c
index 49d39ba..168ec4e 100644
--- a/plugins/filetype_wav/wavfile.c
+++ b/plugins/filetype_wav/wavfile.c
@@ -84,7 +84,7 @@ static gint read_le_short(FILE * file, gshort *ret) {
return TRUE;
}
-Track *wav_get_file_info(const gchar *filename) {
+Track *wav_get_file_info(const gchar *filename, GError **error) {
Track *track = NULL;
gchar *fn;
gchar magic[4];
@@ -95,7 +95,7 @@ Track *wav_get_file_info(const gchar *filename) {
memset(wav_file, 0, sizeof(WaveFile));
if (!(wav_file->file = fopen(filename, "rb"))) {
gchar *fn = charset_to_utf8(filename);
- gtkpod_warning(_("Could not open '%s' for reading.\n"), fn);
+ filetype_log_error(error, g_strdup_printf(_("Could not open '%s' for
reading.\n"), fn));
g_free(fn);
g_free(wav_file);
wav_file = NULL;
@@ -172,7 +172,7 @@ Track *wav_get_file_info(const gchar *filename) {
g_free(wav_file);
wav_file = NULL;
fn = charset_to_utf8(filename);
- gtkpod_warning(_("%s does not appear to be a supported wav file.\n"), fn);
+ filetype_log_error(error, g_strdup_printf(_("%s does not appear to be a
supported wav file.\n"), fn));
g_free(fn);
return NULL;
}
diff --git a/plugins/filetype_wav/wavfile.h b/plugins/filetype_wav/wavfile.h
index 6feda78..bf1136b 100644
--- a/plugins/filetype_wav/wavfile.h
+++ b/plugins/filetype_wav/wavfile.h
@@ -32,7 +32,7 @@
#include "libgtkpod/itdb.h"
-Track *wav_get_file_info(const gchar *name);
+Track *wav_get_file_info(const gchar *name, GError **error);
gboolean wav_can_convert();
gchar *wav_get_conversion_cmd();
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2