[easytag/wip/core-refactoring: 11/17] WIP avoid using filename_to_display()
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/core-refactoring: 11/17] WIP avoid using filename_to_display()
- Date: Fri, 8 Jan 2016 07:55:16 +0000 (UTC)
commit 38b3803c5cea9528be706ed624f2a452ce9ea415
Author: David King <amigadave amigadave com>
Date: Sat Jan 10 00:27:46 2015 +0000
WIP avoid using filename_to_display()
Use the GLib functions for converting filenames from the GLib file
encoding to UTF-8 for display. Avoid trying to guess the encoding, and
only pay attention to the G_FILENAME_ENCODING environment variable as an
override.
src/application.c | 23 +++++++++---------
src/browser.c | 24 +++++++++----------
src/charset.c | 58 -----------------------------------------------
src/charset.h | 1 -
src/easytag.c | 12 +++++-----
src/file_list.c | 32 +++++++++++++-------------
src/file_name.c | 2 +-
src/load_files_dialog.c | 10 ++++----
src/playlist_dialog.c | 2 +-
src/scan_dialog.c | 2 +-
src/tags/id3_tag.c | 4 +-
src/tags/ogg_tag.c | 9 -------
12 files changed, 55 insertions(+), 124 deletions(-)
---
diff --git a/src/application.c b/src/application.c
index 86210ab..7d20d72 100644
--- a/src/application.c
+++ b/src/application.c
@@ -401,7 +401,7 @@ et_application_open (GApplication *self,
GError *err = NULL;
GFileType type;
gchar *path;
- gchar *path_utf8;
+ gchar *display_path;
priv = et_application_get_instance_private (ET_APPLICATION (self));
@@ -414,7 +414,8 @@ et_application_open (GApplication *self,
check_for_hidden_path_in_tree (arg);
path = g_file_get_path (arg);
- path_utf8 = filename_to_display (path);
+ /* TODO: Use g_filename_display_basename? */
+ display_path = g_filename_display_name (path);
info = g_file_query_info (arg, G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, &err);
@@ -423,17 +424,17 @@ et_application_open (GApplication *self,
if (activated)
{
Log_Print (LOG_ERROR, _("Error while querying information for file ‘%s’: %s"),
- path_utf8, err->message);
+ display_path, err->message);
}
else
{
g_warning ("Error while querying information for file: '%s' (%s)",
- path_utf8, err->message);
+ display_path, err->message);
}
g_free (path);
- g_free (path_utf8);
+ g_free (display_path);
g_error_free (err);
return;
}
@@ -453,7 +454,7 @@ et_application_open (GApplication *self,
priv->init_directory = path;
}
- g_free (path_utf8);
+ g_free (display_path);
g_object_unref (info);
}
else if (type == G_FILE_TYPE_REGULAR)
@@ -463,7 +464,7 @@ et_application_open (GApplication *self,
if (parent)
{
- g_free (path_utf8);
+ g_free (display_path);
g_free (path);
if (activated)
@@ -486,17 +487,17 @@ et_application_open (GApplication *self,
}
else
{
- Log_Print (LOG_WARNING, _("Cannot open path ‘%s’"), path_utf8);
+ Log_Print (LOG_WARNING, _("Cannot open path ‘%s’"), display_path);
g_free (path);
- g_free (path_utf8);
+ g_free (display_path);
return;
}
}
else
{
- Log_Print (LOG_WARNING, _("Cannot open path ‘%s’"), path_utf8);
+ Log_Print (LOG_WARNING, _("Cannot open path ‘%s’"), display_path);
g_free (path);
- g_free (path_utf8);
+ g_free (display_path);
return;
}
diff --git a/src/browser.c b/src/browser.c
index 6db9fa3..55be29f 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -892,7 +892,7 @@ Browser_Tree_Node_Selected (EtBrowser *self, GtkTreeSelection *selection)
et_browser_set_current_path (self, pathName);
/* Display the selected path into the BrowserEntry */
- pathName_utf8 = filename_to_display(pathName);
+ pathName_utf8 = g_filename_display_name (pathName);
gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->entry_combo))), pathName_utf8);
/* Start to read the directory */
@@ -3201,7 +3201,6 @@ Browser_Tree_Rename_Directory (EtBrowser *self,
GtkTreeIter iter;
GtkTreePath *childpath;
GtkTreePath *parentpath;
- gchar *new_basename;
gchar *new_basename_utf8;
gchar *path;
@@ -3241,7 +3240,7 @@ Browser_Tree_Rename_Directory (EtBrowser *self,
if (childpath == NULL)
{
// ERROR! Could not find it!
- gchar *text_utf8 = filename_to_display(textsplit[i]);
+ gchar *text_utf8 = g_filename_display_name (textsplit[i]);
g_critical ("Error: Searching for %s, could not find node %s in tree.",
last_path, text_utf8);
g_strfreev(textsplit);
@@ -3256,8 +3255,7 @@ Browser_Tree_Rename_Directory (EtBrowser *self,
gtk_tree_path_free(parentpath);
/* Rename the on-screen node */
- new_basename = g_path_get_basename(new_path);
- new_basename_utf8 = filename_to_display(new_basename);
+ new_basename_utf8 = g_filename_display_basename (new_path);
gtk_tree_store_set(priv->directory_model, &iter,
TREE_COLUMN_DIR_NAME, new_basename_utf8,
TREE_COLUMN_FULL_PATH, new_path,
@@ -3272,7 +3270,6 @@ Browser_Tree_Rename_Directory (EtBrowser *self,
g_free(path);
g_strfreev(textsplit);
- g_free(new_basename);
g_free(new_basename_utf8);
}
@@ -3803,7 +3800,7 @@ open_file_selection_dialog (GtkWidget *entry,
if (response == GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- filename_utf8 = filename_to_display (filename);
+ filename_utf8 = g_filename_display_name (filename);
gtk_entry_set_text (GTK_ENTRY (entry), filename_utf8);
g_free (filename);
g_free (filename_utf8);
@@ -4074,7 +4071,8 @@ et_browser_show_rename_directory_dialog (EtBrowser *self)
return;
}
- directory_name_utf8 = filename_to_display(directory_name);
+ /* FIXME: Use g_filename_display_basename() to simplify the code above? */
+ directory_name_utf8 = g_filename_display_name (directory_name);
builder = gtk_builder_new_from_resource ("/org/gnome/EasyTAG/browser_dialogs.ui");
@@ -4274,9 +4272,9 @@ Rename_Directory (EtBrowser *self)
/* Build the current and new absolute paths */
last_path = g_strconcat(directory_parent, directory_last_name, NULL);
- last_path_utf8 = filename_to_display(last_path);
+ last_path_utf8 = g_filename_display_name (last_path);
new_path = g_strconcat(directory_parent, directory_new_name_file, NULL);
- new_path_utf8 = filename_to_display(new_path);
+ new_path_utf8 = g_filename_display_name (new_path);
/* TODO: Replace with g_file_move(). */
/* Check if the new directory name doesn't already exists, and detect if
@@ -4345,7 +4343,7 @@ Rename_Directory (EtBrowser *self)
/* Temporary path (useful when changing only string case) */
tmp_path = g_strdup_printf("%s.XXXXXX",last_path);
- tmp_path_utf8 = filename_to_display(tmp_path);
+ tmp_path_utf8 = g_filename_display_name (tmp_path);
if ( (fd_tmp = mkstemp(tmp_path)) >= 0 )
{
@@ -4422,9 +4420,9 @@ Rename_Directory (EtBrowser *self)
ETCore->ETFileDisplayed);
}else
{
- gchar *tmp = filename_to_display (et_browser_get_current_path (self));
+ gchar *tmp = g_filename_display_name (et_browser_get_current_path (self));
et_browser_entry_set_text (self, tmp);
- g_free(tmp);
+ g_free (tmp);
}
Destroy_Rename_Directory_Window (self);
diff --git a/src/charset.c b/src/charset.c
index 40b8f59..6eab881 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -430,64 +430,6 @@ convert_string_1 (const gchar *string, gssize length, const gchar *from_codeset,
}
/*
- * Convert a string from the filename system encoding to UTF-8.
- * - conversion OK : returns the UTF-8 string (new allocated)
- * - conversion KO : tries others encodings else returns an 'escaped' string
- */
-gchar *
-filename_to_display (const gchar *string)
-{
- gchar *ret = NULL;
- GError *error = NULL;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- if (g_utf8_validate(string, -1, NULL))
- {
- // String already in UTF-8
- ret = g_strdup(string);
- }else
- {
- const gchar *char_encoding;
-
- // Get encoding associated to the locale without using UTF-8 (ex , if LANG=fr_FR.UTF-8 it will
return ISO-8859-1)
- char_encoding = get_encoding_from_locale(get_locale());
- if (char_encoding)
- {
- //g_print("> char_encoding: %s\n",char_encoding);
- error = NULL;
- ret = g_convert(string, -1, "UTF-8", char_encoding, NULL, NULL, &error);
- }
-
- if (!ret)
- {
- // Failing that, try ISO-8859-1
- error = NULL;
- ret = g_convert(string, -1, "UTF-8", "ISO-8859-1", NULL, NULL, &error);
- }
-
- if (!ret)
- {
- gchar *escaped_str = g_strescape(string, NULL);
- Log_Print (LOG_ERROR,
- _("The filename ‘%s’ could not be converted into UTF-8: %s"),
- escaped_str,
- error && error->message ? error->message : _("Invalid UTF-8"));
- g_clear_error(&error);
-
- ret = escaped_str;
- }
- }
-
-#ifdef G_OS_WIN32
- ET_Win32_Path_Remove_Trailing_Slash (ret);
- ET_Win32_Path_Replace_Slashes (ret);
-#endif /* G_OS_WIN32 */
-
- return ret;
-}
-
-/*
* Convert a string from UTF-8 to the filename system encoding.
* - conversion OK : returns the string in filename system encoding (new allocated)
* - conversion KO : display error message + returns nothing!
diff --git a/src/charset.h b/src/charset.h
index decce1e..d77833b 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -30,7 +30,6 @@ const gchar *get_locale (void);
gchar *convert_string (const gchar *string, const gchar *from_codeset, const gchar *to_codeset, const
gboolean display_error);
gchar *convert_string_1 (const gchar *string, gssize length, const gchar *from_codeset, const gchar
*to_codeset, const gboolean display_error);
-gchar *filename_to_display (const gchar *string);
gchar *filename_from_display (const gchar *string);
gchar *Try_To_Validate_Utf8_String (const gchar *string);
diff --git a/src/easytag.c b/src/easytag.c
index a4a0516..ebcbae9 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -866,21 +866,21 @@ Read_Directory (const gchar *path_real)
{
// Message if the directory doesn't exist...
GtkWidget *msgdialog;
- gchar *path_utf8 = filename_to_display(path_real);
+ gchar *display_path = g_filename_display_name (path_real);
msgdialog = gtk_message_dialog_new(GTK_WINDOW(MainWindow),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
_("Cannot read directory ‘%s’"),
- path_utf8);
+ display_path);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog),
"%s", error->message);
gtk_window_set_title(GTK_WINDOW(msgdialog),_("Directory Read Error"));
gtk_dialog_run(GTK_DIALOG(msgdialog));
gtk_widget_destroy(msgdialog);
- g_free(path_utf8);
+ g_free (display_path);
ReadingDirectory = FALSE; //Allow a new reading
et_application_window_browser_set_sensitive (window, TRUE);
@@ -920,13 +920,13 @@ Read_Directory (const gchar *path_real)
{
GFile *file = l->data;
gchar *filename_real = g_file_get_path (file);
- gchar *filename_utf8 = filename_to_display(filename_real);
+ gchar *display_path = g_filename_display_name (filename_real);
- msg = g_strdup_printf (_("File: ‘%s’"), filename_utf8);
+ msg = g_strdup_printf (_("File: ‘%s’"), display_path);
et_application_window_status_bar_message (window, msg, FALSE);
g_free(msg);
- g_free(filename_utf8);
g_free (filename_real);
+ g_free (display_path);
ETCore->ETFileList = et_file_list_add (ETCore->ETFileList, file);
diff --git a/src/file_list.c b/src/file_list.c
index 894cd7b..27a7dc3 100644
--- a/src/file_list.c
+++ b/src/file_list.c
@@ -209,7 +209,7 @@ et_file_list_add (GList *file_list,
guint undo_key;
GFileInfo *fileinfo;
gchar *filename;
- gchar *filename_utf8;
+ gchar *display_path;
const gchar *locale_lc_ctype = getenv("LC_CTYPE");
GError *error = NULL;
gboolean success;
@@ -221,7 +221,7 @@ et_file_list_add (GList *file_list,
/* Get description of the file */
filename = g_file_get_path (file);
- filename_utf8 = filename_to_display (filename);
+ display_path = g_filename_display_name (filename);
description = ET_Get_File_Description (filename);
/* Get real extension of the file (keeping the case) */
@@ -230,7 +230,7 @@ et_file_list_add (GList *file_list,
/* Fill the File_Name structure for FileNameList */
FileName = et_file_name_new ();
FileName->saved = TRUE; /* The file hasn't been changed, so it's saved */
- ET_Set_Filename_File_Name_Item (FileName, filename_utf8, filename);
+ ET_Set_Filename_File_Name_Item (FileName, display_path, filename);
/* Fill the File_Tag structure for FileTagList */
FileTag = et_file_tag_new ();
@@ -250,7 +250,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_ERROR,
_("Error reading ID3 tag from file ‘%s’: %s"),
- filename_utf8, error->message);
+ display_path, error->message);
g_clear_error (&error);
}
break;
@@ -261,7 +261,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_ERROR,
_("Error reading tag from Ogg file ‘%s’: %s"),
- filename_utf8, error->message);
+ display_path, error->message);
g_clear_error (&error);
}
break;
@@ -272,7 +272,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_ERROR,
_("Error reading tag from FLAC file ‘%s’: %s"),
- filename_utf8, error->message);
+ display_path, error->message);
g_clear_error (&error);
}
break;
@@ -282,7 +282,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_ERROR,
_("Error reading APE tag from file ‘%s’: %s"),
- filename_utf8, error->message);
+ display_path, error->message);
g_clear_error (&error);
}
break;
@@ -292,7 +292,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_ERROR,
_("Error reading tag from MP4 file ‘%s’: %s"),
- filename_utf8, error->message);
+ display_path, error->message);
g_clear_error (&error);
}
break;
@@ -303,7 +303,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_ERROR,
_("Error reading tag from WavPack file ‘%s’: %s"),
- filename_utf8, error->message);
+ display_path, error->message);
g_clear_error (&error);
}
break;
@@ -314,7 +314,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_ERROR,
_("Error reading tag from Opus file ‘%s’: %s"),
- filename_utf8, error->message);
+ display_path, error->message);
g_clear_error (&error);
}
break;
@@ -342,7 +342,7 @@ et_file_list_add (GList *file_list,
/* FIXME: Translatable string. */
Log_Print (LOG_ERROR,
"FileTag: Undefined tag type (%d) for file %s",
- (gint)description->TagType, filename_utf8);
+ (gint)description->TagType, display_path);
break;
}
@@ -350,7 +350,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_WARNING,
_("The year value ‘%s’ seems to be invalid in file ‘%s’. The information will be lost
when saving"),
- FileTag->year, filename_utf8);
+ FileTag->year, display_path);
}
/* Fill the ET_File_Info structure */
@@ -430,7 +430,7 @@ et_file_list_add (GList *file_list,
/* FIXME: Translatable string. */
Log_Print (LOG_ERROR,
"ETFileInfo: Undefined file type (%d) for file %s",
- (gint)description->FileType, filename_utf8);
+ (gint)description->FileType, display_path);
/* To get at least the file size. */
success = et_core_read_file_info (file, ETFileInfo, &error);
break;
@@ -440,7 +440,7 @@ et_file_list_add (GList *file_list,
{
Log_Print (LOG_ERROR,
_("Error while querying information for file ‘%s’: %s"),
- filename_utf8, error->message);
+ display_path, error->message);
g_error_free (error);
}
@@ -509,7 +509,7 @@ et_file_list_add (GList *file_list,
if ( (FileName && FileName->saved==FALSE) || (FileTag && FileTag->saved==FALSE) )
{
Log_Print (LOG_INFO, _("Automatic corrections applied for file ‘%s’"),
- filename_utf8);
+ display_path);
}
/* Add the item to the ArtistAlbum list (placed here to take advantage of previous changes) */
@@ -518,7 +518,7 @@ et_file_list_add (GList *file_list,
//ET_Debug_Print_File_List(ETCore->ETFileList,__FILE__,__LINE__,__FUNCTION__);
g_free (filename);
- g_free (filename_utf8);
+ g_free (display_path);
return result;
}
diff --git a/src/file_name.c b/src/file_name.c
index 76c7cec..493e190 100644
--- a/src/file_name.c
+++ b/src/file_name.c
@@ -81,7 +81,7 @@ ET_Set_Filename_File_Name_Item (File_Name *FileName,
}
else if (filename)
{
- FileName->value_utf8 = filename_to_display (filename);
+ FileName->value_utf8 = g_filename_display_name (filename);
FileName->value = g_strdup (filename);
FileName->value_ck = g_utf8_collate_key_for_filename (FileName->value_utf8, -1);
}
diff --git a/src/load_files_dialog.c b/src/load_files_dialog.c
index a070d51..e0fff6b 100644
--- a/src/load_files_dialog.c
+++ b/src/load_files_dialog.c
@@ -244,7 +244,7 @@ Load_File_Content (G_GNUC_UNUSED GtkButton *button, gpointer user_data)
GError *error = NULL;
gsize size_read;
gchar *path;
- gchar *filename_utf8;
+ gchar *display_path;
gchar *line;
gchar *valid;
@@ -253,7 +253,7 @@ Load_File_Content (G_GNUC_UNUSED GtkButton *button, gpointer user_data)
/* The file to read. */
path = g_file_get_path (file);
- filename_utf8 = filename_to_display (path);
+ display_path = g_filename_display_name (path);
g_free (path);
istream = g_file_read (file, NULL, &error);
@@ -261,15 +261,15 @@ Load_File_Content (G_GNUC_UNUSED GtkButton *button, gpointer user_data)
if (!istream)
{
- Log_Print (LOG_ERROR, _("Cannot open file ‘%s’: %s"), filename_utf8,
+ Log_Print (LOG_ERROR, _("Cannot open file ‘%s’: %s"), display_path,
error->message);
g_error_free (error);
g_object_unref (file);
- g_free (filename_utf8);
+ g_free (display_path);
return;
}
- g_free (filename_utf8);
+ g_free (display_path);
data = g_data_input_stream_new (G_INPUT_STREAM (istream));
/* TODO: Find a safer alternative to _ANY. */
g_data_input_stream_set_newline_type (data,
diff --git a/src/playlist_dialog.c b/src/playlist_dialog.c
index a554f4f..f33eb36 100644
--- a/src/playlist_dialog.c
+++ b/src/playlist_dialog.c
@@ -439,7 +439,7 @@ write_button_clicked (EtPlaylistDialog *self)
}
// Path of the playlist file (may be truncated later if PLAYLIST_CREATE_IN_PARENT_DIR is TRUE)
- playlist_path_utf8 = filename_to_display (et_application_window_get_current_path (ET_APPLICATION_WINDOW
(MainWindow)));
+ playlist_path_utf8 = g_filename_display_name (et_application_window_get_current_path
(ET_APPLICATION_WINDOW (MainWindow)));
/* Build the playlist filename. */
if (g_settings_get_boolean (MainSettings, "playlist-use-mask"))
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 13957f4..4fcf472 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -524,7 +524,7 @@ Scan_Generate_New_Tag_From_Mask (ET_File *ETFile, gchar *mask)
{
gchar *mask_seq = mask_splitted[mask_splitted_index];
gchar *file_seq = file_splitted[file_splitted_index];
- gchar *file_seq_utf8 = filename_to_display(file_seq);
+ gchar *file_seq_utf8 = g_filename_display_name (file_seq);
//g_print(">%d> seq '%s' '%s'\n",loop,mask_seq,file_seq);
while (!et_str_empty (mask_seq))
diff --git a/src/tags/id3_tag.c b/src/tags/id3_tag.c
index a639cb9..7b568e4 100644
--- a/src/tags/id3_tag.c
+++ b/src/tags/id3_tag.c
@@ -1060,14 +1060,14 @@ gchar *Id3tag_Get_Field (const ID3Frame *id3_frame, ID3_FieldID id3_fieldid)
//g_print(">>ID:%d >'%s' (string1:'%s')
(num_chars:%d)\n",ID3Field_GetINT(id3_field_encoding),string,string1,num_chars);
out:
- // In case the conversion fails, try 'filename_to_display' character fix...
+ /* In case the conversion fails, try character fix. */
if (num_chars && !string1)
{
gchar *escaped_str = g_strescape(string, NULL);
g_debug ("Id3tag_Get_Field: Trying to fix string '%s'…", escaped_str);
g_free(escaped_str);
- string1 = filename_to_display(string);
+ string1 = g_filename_display_name (string);
/* TODO: Set a GError instead. */
if (!string1)
diff --git a/src/tags/ogg_tag.c b/src/tags/ogg_tag.c
index b1d8b31..b93813b 100644
--- a/src/tags/ogg_tag.c
+++ b/src/tags/ogg_tag.c
@@ -658,8 +658,6 @@ ogg_tag_read_file_tag (GFile *file,
{
GFileInputStream *istream;
EtOggState *state;
- gchar *filename;
- gchar *filename_utf8;
g_return_val_if_fail (file != NULL && FileTag != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -672,10 +670,6 @@ ogg_tag_read_file_tag (GFile *file,
return FALSE;
}
- filename = g_file_get_path (file);
- filename_utf8 = filename_to_display (filename);
- g_free (filename);
-
{
/* Check for an unsupported ID3v2 tag. */
guchar tmp_id3[4];
@@ -728,7 +722,6 @@ ogg_tag_read_file_tag (GFile *file,
{
g_assert (error == NULL || *error != NULL);
vcedit_clear(state);
- g_free (filename_utf8);
return FALSE;
}
@@ -743,14 +736,12 @@ ogg_tag_read_file_tag (GFile *file,
et_add_file_tags_from_vorbis_comments (vcedit_comments(state), FileTag);
vcedit_clear(state);
- g_free (filename_utf8);
return TRUE;
err:
g_assert (error == NULL || *error != NULL);
g_object_unref (istream);
- g_free (filename_utf8);
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]