[easytag/wip/core-refactoring: 7/9] WIP Avoid using filename_from_display()
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/core-refactoring: 7/9] WIP Avoid using filename_from_display()
- Date: Fri, 15 Jan 2016 10:07:36 +0000 (UTC)
commit 684daca49be2f51a56f833976c09512bed2f6dd9
Author: David King <amigadave amigadave com>
Date: Thu Dec 31 10:09:45 2015 +0000
WIP Avoid using filename_from_display()
Use the GLib functions for converting filenames from UTF-8 to the GLib
filename encoding.
src/application_window.c | 13 ++++++++-----
src/browser.c | 20 +++++++++++++-------
src/file_name.c | 1 +
src/playlist_dialog.c | 6 ++++++
src/scan_dialog.c | 20 ++++++++++++++------
5 files changed, 42 insertions(+), 18 deletions(-)
---
diff --git a/src/application_window.c b/src/application_window.c
index b7e2c6a..67b4cfd 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -1994,34 +1994,37 @@ et_application_window_update_file_name_from_ui (EtApplicationWindow *self,
{
gchar *filename_new = NULL;
gchar *dirname = NULL;
- gchar *filename;
const gchar *filename_utf8;
+ gchar *filename;
+ GError *error = NULL;
gchar *extension;
g_return_if_fail (ETFile != NULL && FileName != NULL);
filename_utf8 = et_application_window_file_area_get_filename (self);
- filename = filename_from_display (filename_utf8);
+ filename = g_filename_from_utf8 (filename_utf8, -1, NULL, NULL, &error);
if (!filename)
{
/* If conversion fails... */
GtkWidget *msgdialog;
- gchar *filename_escaped_utf8 = g_strescape(filename_utf8, NULL);
+
msgdialog = gtk_message_dialog_new (GTK_WINDOW (self),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
_("Could not convert filename ā%sā to system filename encoding"),
- filename_escaped_utf8);
+ filename_utf8);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog),
_("Try setting the environment variable
G_FILENAME_ENCODING."));
gtk_window_set_title (GTK_WINDOW (msgdialog),
_("Filename translation"));
+ g_debug ("Error during filename conversion: %s", error->message);
gtk_dialog_run (GTK_DIALOG (msgdialog));
gtk_widget_destroy (msgdialog);
- g_free (filename_escaped_utf8);
+ g_error_free (error);
+
return;
}
diff --git a/src/browser.c b/src/browser.c
index a5b88e8..02c6fd7 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -4178,6 +4178,7 @@ Rename_Directory (EtBrowser *self)
gchar *directory_last_name;
gchar *directory_new_name;
gchar *directory_new_name_file;
+ GError *error = NULL;
gchar *last_path;
gchar *last_path_utf8;
gchar *new_path;
@@ -4212,7 +4213,7 @@ Rename_Directory (EtBrowser *self)
directory_new_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->rename_directory_entry)));
}
- /* Check if a name for the directory have been supplied */
+ /* Check if a name for the directory has been supplied. */
if (et_str_empty (directory_new_name))
{
GtkWidget *msgdialog;
@@ -4231,8 +4232,10 @@ Rename_Directory (EtBrowser *self)
return;
}
- /* Check that we can write the new directory name */
- directory_new_name_file = filename_from_display(directory_new_name);
+ /* Check that we can write the new directory name. */
+ directory_new_name_file = g_filename_from_utf8 (directory_new_name, -1,
+ NULL, NULL, &error);
+
if (!directory_new_name_file)
{
GtkWidget *msgdialog;
@@ -4245,11 +4248,14 @@ Rename_Directory (EtBrowser *self)
directory_new_name);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog),
_("Please use another name."));
- gtk_window_set_title(GTK_WINDOW(msgdialog),_("Directory Name Error"));
+ gtk_window_set_title (GTK_WINDOW (msgdialog),
+ _("Directory Name Error"));
- gtk_dialog_run(GTK_DIALOG(msgdialog));
- gtk_widget_destroy(msgdialog);
- g_free(directory_new_name_file);
+ g_debug ("Error during directory name conversion: %s", error->message);
+ gtk_dialog_run (GTK_DIALOG (msgdialog));
+ gtk_widget_destroy (msgdialog);
+ g_free (directory_new_name_file);
+ g_error_free (error);
}
g_free (directory_new_name);
diff --git a/src/file_name.c b/src/file_name.c
index 493e190..a7009a8 100644
--- a/src/file_name.c
+++ b/src/file_name.c
@@ -76,6 +76,7 @@ ET_Set_Filename_File_Name_Item (File_Name *FileName,
else if (filename_utf8)
{
FileName->value_utf8 = g_strdup (filename_utf8);
+ /* FIXME: Use g_filename_from_utf8(). */
FileName->value = filename_from_display (filename_utf8);
FileName->value_ck = g_utf8_collate_key_for_filename (FileName->value_utf8, -1);
}
diff --git a/src/playlist_dialog.c b/src/playlist_dialog.c
index f33eb36..53e2284 100644
--- a/src/playlist_dialog.c
+++ b/src/playlist_dialog.c
@@ -199,11 +199,13 @@ write_playlist (EtPlaylistDialog *self, GFile *file, GError **error)
case ET_PLAYLIST_CONTENT_EXTENDED_MASK:
{
/* Header uses information generated from a mask. */
+ /* FIXME: Use g_filename_from_utf8(). */
gchar *mask = filename_from_display (gtk_entry_get_text (GTK_ENTRY
(priv->content_mask_entry)));
/* Special case: do not replace illegal characters and
* do not check if there is a directory separator in
* the mask. */
gchar *filename_generated_utf8 = et_scan_generate_new_filename_from_mask (etfile,
mask, TRUE);
+ /* FIXME: Use g_filename_from_utf8(). */
gchar *filename_generated = filename_from_display (filename_generated_utf8);
to_write = g_string_new ("#EXTINF:");
@@ -323,11 +325,13 @@ write_playlist (EtPlaylistDialog *self, GFile *file, GError **error)
case ET_PLAYLIST_CONTENT_EXTENDED_MASK:
{
/* Header uses information generated from a mask. */
+ /* FIXME: Use g_filename_from_utf8(). */
gchar *mask = filename_from_display (gtk_entry_get_text (GTK_ENTRY
(priv->content_mask_entry)));
/* Special case: do not replace illegal characters and
* do not check if there is a directory separator in
* the mask. */
gchar *filename_generated_utf8 = et_scan_generate_new_filename_from_mask (etfile, mask,
TRUE);
+ /* FIXME: Use g_filename_from_utf8(). */
gchar *filename_generated = filename_from_display (filename_generated_utf8);
to_write = g_string_new ("#EXTINF:");
@@ -453,6 +457,7 @@ write_button_clicked (EtPlaylistDialog *self)
"playlist-filename-mask");
/* Generate filename from tag of the current selected file (FIXME). */
+ /* FIXME: Use g_filename_from_utf8(). */
temp = filename_from_display (playlist_name);
g_free (playlist_name);
playlist_basename_utf8 = et_scan_generate_new_filename_from_mask (ETCore->ETFileDisplayed,
@@ -528,6 +533,7 @@ write_button_clicked (EtPlaylistDialog *self)
g_free(playlist_path_utf8);
g_free(playlist_basename_utf8);
+ /* FIXME: Use g_filename_from_utf8(). */
playlist_name = filename_from_display(playlist_name_utf8);
{
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 4fcf472..f32202d 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -789,6 +789,7 @@ Scan_Rename_File_With_Mask (EtScanDialog *self, ET_File *ETFile)
gchar *filename_generated_utf8 = NULL;
gchar *filename_generated = NULL;
gchar *filename_new_utf8 = NULL;
+ GError *error = NULL;
gchar *mask = NULL;
File_Name *FileName;
@@ -812,22 +813,29 @@ Scan_Rename_File_With_Mask (EtScanDialog *self, ET_File *ETFile)
return;
}
- // Convert filename to file-system encoding
- filename_generated = filename_from_display(filename_generated_utf8);
+ /* Convert filename to file-system encoding. */
+ filename_generated = g_filename_from_utf8 (filename_generated_utf8, -1,
+ NULL, NULL, &error);
+
if (!filename_generated)
{
GtkWidget *msgdialog;
+
msgdialog = gtk_message_dialog_new (GTK_WINDOW (self),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
_("Could not convert filename ā%sā into system filename encoding"),
filename_generated_utf8);
- gtk_window_set_title(GTK_WINDOW(msgdialog),_("Filename translation"));
+ gtk_window_set_title (GTK_WINDOW (msgdialog),
+ _("Filename translation"));
+
+ g_debug ("Error during filename conversion: %s", error->message);
+ gtk_dialog_run (GTK_DIALOG (msgdialog));
+ gtk_widget_destroy (msgdialog);
+ g_free (filename_generated_utf8);
+ g_error_free (error);
- gtk_dialog_run(GTK_DIALOG(msgdialog));
- gtk_widget_destroy(msgdialog);
- g_free(filename_generated_utf8);
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]