[easytag/wip/core-refactoring: 4/8] WIP Avoid using filename_from_display()



commit 57f1d40f339b24a3da5f2aa6399dac4d6b72bae2
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 |   15 +++++++++------
 src/browser.c            |   20 +++++++++++++-------
 src/file_name.c          |    1 +
 src/playlist_dialog.c    |    6 ++++++
 src/scan_dialog.c        |   20 ++++++++++++++------
 5 files changed, 43 insertions(+), 19 deletions(-)
---
diff --git a/src/application_window.c b/src/application_window.c
index 92da371..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;
     }
 
@@ -2035,7 +2038,7 @@ et_application_window_update_file_name_from_ui (EtApplicationWindow *self,
     //ET_File_Name_Check_Length(ETFile,filename);
 
     /* Filename (in file system encoding!). */
-    if (filename && *filename)
+    if (!et_str_empty (filename))
     {
         /* Regenerate the new filename (without path). */
         filename_new = g_strconcat (filename, extension, NULL);
diff --git a/src/browser.c b/src/browser.c
index 6443c96..356d994 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -4197,6 +4197,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;
@@ -4231,7 +4232,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;
@@ -4250,8 +4251,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;
@@ -4264,11 +4267,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 b47fc5d..c140f36 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]