From 8de0b42d9d9e6d5d603848297330d73cff5324f6 Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Sun, 22 Jan 2023 14:21:38 -0500 Subject: [PATCH] util: Use proper file collation API glib-rs provides an API to get file collation keys that can be used for comparison. This means we do not need to use the function for this ourselves. This commit gets rid of the manual binding for `g_utf8_collate_key_by_filename ()` in favor of the glib-rs API. --- src/util.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/util.rs b/src/util.rs index 9edc2eb..02fdebc 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,21 +1,11 @@ use crate::deps::*; use gio::prelude::*; -use glib::translate::*; use anyhow::Context; use std::fmt::{Debug, Write}; -pub fn utf8_collate_key_for_filename(filename: &str) -> String { - unsafe { - from_glib_full(glib::ffi::g_utf8_collate_key_for_filename( - filename.to_glib_none().0, - filename.len() as isize, - )) - } -} - pub fn get_file_display_name(file: &gio::File) -> Option { let info = query_attributes(file, vec![&gio::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME]).ok()?; @@ -60,7 +50,10 @@ pub fn compare_by_name(file_a: &gio::File, file_b: &gio::File) -> std::cmp::Orde let name_a = get_file_display_name(file_a).unwrap_or_default(); let name_b = get_file_display_name(file_b).unwrap_or_default(); - utf8_collate_key_for_filename(&name_a).cmp(&utf8_collate_key_for_filename(&name_b)) + let key_a = glib::FilenameCollationKey::from(name_a); + let key_b = glib::FilenameCollationKey::from(name_b); + + key_a.cmp(&key_b) } pub async fn spawn(