! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Filename sorting handles numbers and symbols incorrectly
Status:
RESOLVED: FIXED
Product:
Ristretto
Component:
Application

Comments

Description rmlipman 2013-01-08 20:38:45 CET
When sorting by name, Ristretto puts hyphens after spaces when the word before the space/hyphen ends in a number. In other programs like Thunar, name sorting puts hyphens before spaces for this case.

Copy an image into a separate folder twice with the following names:
test1-1.gif
test1 test 1.gif

What I expected:
In Thunar, test1-1.gif comes first. The same order should happen in Ristretto.

What happened:
In Ristretto, test1 test 1.gif comes first.
Comment 1 rmlipman 2013-01-08 20:40:25 CET
While testing this, I also found it sorted other symbols differently as well. Here are some of my findings with a few symbols:

Thunar order:
test1|1.gif
test1 1.gif
test1_1.gif
test1-1.gif
test1+1.gif

Ristretto order:
test1 1.gif
test1+1.gif
test1-1.gif
test1_1.gif
test1|1.gif

I'm not sure if this falls under the same bug as my other issue or if it's something separate.
Comment 2 Eric Koegel editbugs 2013-04-19 11:47:17 CEST
Created attachment 5003 
Use collate keys to handle filename sorting

This proposed patch uses g_utf8_collate_key_for_filename to generate collate keys that the image list can use to compare files. This simplifies the comparison function and sorts files the same way Thunar does which should fix both issues presented above.
Comment 3 Geoffrey Ehrman 2013-06-12 04:45:11 CEST
It would be very nice if ristretto matched thunar's behavior about case-sorting. One usage-case for me is to have ristretto and thunar open in parallel to organize photos, and having sorts match is essential for efficiency here. Maybe this should be a separate bug, however; I don't know.

The following change on top of Eric's patch seems to work:
--- a/src/image_list.c
+++ b/src/image_list.c
@@ -1358,7 +1358,7 @@ cb_rstto_image_list_image_name_compare_func (RsttoFile *a,
     const gchar *a_collate_key = rstto_file_get_collate_key (a);
     const gchar *b_collate_key = rstto_file_get_collate_key (b);
 
-    return g_strcmp0(a_collate_key, b_collate_key);
+    return g_ascii_strcasecmp(a_collate_key, b_collate_key);
 }
I doubt the ascii compare is ideal but I'm not familiar with C/glib and that was the best I could find  searching the documentation at https://developer.gnome.org/glib/2.28/glib-String-Utility-Functions.html.
Comment 4 Eric Koegel editbugs 2015-01-25 07:49:47 CET
g_strcmp0 should be sufficient after collating the files. g_utf8_casefold before calling the collate key might be useful. Do you have an example of some files that aren't being sorted the same as Thunar?
Comment 5 Steve Dodier-Lazaro editbugs 2015-02-08 20:35:37 CET
Eric,

I'm assigning the bug to you as you seem to be working on it. Let me know if you have a working patch that needs testing!

Thanks.
Comment 6 Eric Koegel editbugs 2015-02-09 09:31:16 CET
Created attachment 5919 
0001-Use-collate-keys-to-handle-filename-sorting-Bug-9731

This adds the casefold to perform the case insensitive sorting. It should be exactly like Thunar now.
Comment 7 Steve Dodier-Lazaro editbugs 2015-02-15 03:12:06 CET
Patch tested, works for me with rmlipman's test set.
Comment 8 Eric Koegel editbugs 2015-02-15 07:09:00 CET
Thanks, pushed to master in:
commit 788411a43227a0b8b2f31766b136bb9dc2e30030
Author: Eric Koegel <eric.koegel@gmail.com>
Date:   Mon Feb 9 11:18:50 2015 +0300

    Use collate keys to handle filename sorting (Bug #9731)
    
    This uses g_utf8_casefold and g_utf8_collate_key_for_filename on
    the files to perform case insensitive sorting the same way Thunar
    and Xfdesktop do.

http://git.xfce.org/apps/ristretto/commit/?id=788411a43227a0b8b2f31766b136bb9dc2e30030

Bug #9731

Reported by:
rmlipman
Reported on: 2013-01-08
Last modified on: 2015-02-15

People

Assignee:
Eric Koegel
CC List:
3 users

Version

Version:
master

Attachments

Additional information