From 9444339035aa8b937d9c7b7bf993c8ece31cc359 Mon Sep 17 00:00:00 2001 Message-Id: <9444339035aa8b937d9c7b7bf993c8ece31cc359.1374915463.git.jshipley@fastmail.fm> In-Reply-To: References: From: Jeff Shipley Date: Sat, 27 Jul 2013 02:53:32 -0600 Subject: [PATCH 8/8] Change name of file copies (and links) (bug 7518) --- thunar/thunar-io-jobs-util.c | 50 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/thunar/thunar-io-jobs-util.c b/thunar/thunar-io-jobs-util.c index 1f9a151..675aba4 100644 --- a/thunar/thunar-io-jobs-util.c +++ b/thunar/thunar-io-jobs-util.c @@ -28,18 +28,17 @@ #include #include #include +#include -static const gchar *duplicate_names[4][2] = +static const gchar *link_names[4] = { - /* 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"), }; @@ -81,8 +80,8 @@ thunar_io_jobs_util_next_duplicate_file (ThunarJob *job, GFile *duplicate_file = NULL; GFile *parent_file = NULL; gchar *display_name; - gint type_index; - gint name_index; + 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 +105,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) + 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(display_name); + if (dot) + { + /* place copy number "-N" between basename and extension */ + file_basename = g_strndup(display_name, dot - display_name); + display_name = g_strdup_printf ("%s-%d%s", file_basename, n+1, dot); + g_free(file_basename); + } + else + { + /* put copy number after filename */ + display_name = g_strdup_printf ("%s-%d", display_name, n+1); + } } 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]), display_name); + else + display_name = g_strdup_printf (gettext (link_names[1]), n, display_name); } /* create the GFile for the copy/link */ -- 1.7.9.5