From b3dc1b94e3cb2e36da7a53d4e1264ec0c8ee0271 Mon Sep 17 00:00:00 2001 From: Jeff Shipley Date: Mon, 29 Jul 2013 10:24:53 -0600 Subject: [PATCH] Change name of file copies (and links) (bug 7518) --- thunar/thunar-io-jobs-util.c | 62 ++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/thunar/thunar-io-jobs-util.c b/thunar/thunar-io-jobs-util.c index 1f9a151..2c44abc 100644 --- a/thunar/thunar-io-jobs-util.c +++ b/thunar/thunar-io-jobs-util.c @@ -28,20 +28,22 @@ #include #include #include +#include -static const gchar *duplicate_names[4][2] = +static const gchar *link_names[2] = { - /* Copy/link name for n <= 3 */ - { N_("copy of %s"), N_("link to %s"), }, - { N_("another copy of %s"), N_("another link to %s"), }, - { N_("third copy of %s"), N_("third link to %s"), }, + /* name for first link */ + N_("link to %s"), - /* Fallback copy/link name for n >= 4 */ - { N_("%uth copy of %s"), N_("%uth link to %s"), }, + /* name for all other links */ + N_("link %u to %s"), }; +/* used for " (copy N)." */ +static const gchar *copy_name = N_("%s (copy %d)%s"); + /** @@ -77,12 +79,13 @@ thunar_io_jobs_util_next_duplicate_file (ThunarJob *job, GError **error) { GFileInfo *info; - GError *err = NULL; - GFile *duplicate_file = NULL; - GFile *parent_file = NULL; - gchar *display_name; - gint type_index; - gint name_index; + GError *err = NULL; + GFile *duplicate_file = NULL; + GFile *parent_file = NULL; + const gchar *old_display_name; + gchar *display_name; + gchar *file_basename; + gchar *dot; _thunar_return_val_if_fail (THUNAR_IS_JOB (job), NULL); _thunar_return_val_if_fail (G_IS_FILE (file), NULL); @@ -106,22 +109,31 @@ thunar_io_jobs_util_next_duplicate_file (ThunarJob *job, return NULL; } - /* determine the type index (copy = 0, link = 1) */ - type_index = (copy ? 0 : 1); - - /* make sure the name index is not out of bounds */ - name_index = MIN (n-1, G_N_ELEMENTS (duplicate_names)-1); - - /* generate the display name for the nth copy/link of the source file */ - if (name_index < (gint) G_N_ELEMENTS (duplicate_names)-1) + old_display_name = g_file_info_get_display_name(info); + if (copy) { - display_name = g_strdup_printf (gettext (duplicate_names[name_index][type_index]), - g_file_info_get_display_name (info)); + /* get file extension */ + dot = thunar_util_str_get_extension(old_display_name); + if (dot) + { + /* place copy number "-N" between basename and extension */ + file_basename = g_strndup(old_display_name, dot - old_display_name); + display_name = g_strdup_printf (gettext (copy_name), file_basename, n, dot); + g_free(file_basename); + } + else + { + /* put copy number after filename */ + display_name = g_strdup_printf (gettext (copy_name), old_display_name, n, ""); + } } else { - display_name = g_strdup_printf (gettext (duplicate_names[name_index][type_index]), - n, g_file_info_get_display_name (info)); + /* create name for link */ + if (n == 1) + display_name = g_strdup_printf (gettext (link_names[0]), old_display_name); + else + display_name = g_strdup_printf (gettext (link_names[1]), n, old_display_name); } /* create the GFile for the copy/link */ -- 1.8.1.2