[PATCH] Make drive/volume display name comparison case-insensitive and locale-aware
- From: Christian Neumair <chris gnome-de org>
- To: gnome-vfs-list gnome org
- Subject: [PATCH] Make drive/volume display name comparison case-insensitive and locale-aware
- Date: Sat, 01 Apr 2006 13:04:45 +0200
The attached patch makes gnome_vfs_drive_compare and
gnome_vfs_volume_compare make case-independent and locale sensitive, so
that it can be used to sort volumes and drives. This will allow
Nautilus, gnome-panel, the file choosers and others to keep a consistent
volume sort order, cf. bug 321320 [1] and others.
[1] http://bugzilla.gnome.org/show_bug.cgi?id=321320
--
Christian Neumair <chris gnome-de org>
Index: libgnomevfs/gnome-vfs-drive.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-drive.c,v
retrieving revision 1.14
diff -u -p -r1.14 gnome-vfs-drive.c
--- libgnomevfs/gnome-vfs-drive.c 19 Feb 2006 00:59:30 -0000 1.14
+++ libgnomevfs/gnome-vfs-drive.c 1 Apr 2006 10:55:18 -0000
@@ -193,6 +239,7 @@ gnome_vfs_drive_finalize (GObject *objec
g_free (priv->device_path);
g_free (priv->activation_uri);
g_free (priv->display_name);
+ g_free (priv->display_name_key);
g_free (priv->icon);
g_free (priv->hal_udi);
g_free (priv->hal_drive_udi);
@@ -478,7 +558,7 @@ gnome_vfs_drive_compare (GnomeVFSDrive *
return res;
}
- res = strcmp (priva->display_name, privb->display_name);
+ res = strcmp (priva->display_name_key, privb->display_name_key);
if (res != 0) {
return res;
}
@@ -593,7 +673,15 @@ _gnome_vfs_drive_from_corba (const GNOME
drive->priv->display_name = decode_corba_string_or_null (corba_drive->display_name, TRUE);
drive->priv->icon = decode_corba_string_or_null (corba_drive->icon, TRUE);
drive->priv->hal_udi = decode_corba_string_or_null (corba_drive->hal_udi, TRUE);
-
+
+ if (drive->priv->display_name != NULL) {
+ char *tmp = g_utf8_casefold (drive->priv->display_name, -1);
+ drive->priv->display_name_key = g_utf8_collate_key (tmp, -1);
+ g_free (tmp);
+ } else {
+ drive->priv->display_name_key = NULL;
+ }
+
drive->priv->is_user_visible = corba_drive->is_user_visible;
drive->priv->is_connected = corba_drive->is_connected;
Index: libgnomevfs/gnome-vfs-hal-mounts.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-hal-mounts.c,v
retrieving revision 1.29
diff -u -p -r1.29 gnome-vfs-hal-mounts.c
--- libgnomevfs/gnome-vfs-hal-mounts.c 20 Mar 2006 16:52:56 -0000 1.29
+++ libgnomevfs/gnome-vfs-hal-mounts.c 1 Apr 2006 10:55:23 -0000
@@ -837,6 +837,9 @@ _hal_add_drive_without_volumes (GnomeVFS
name = _hal_drive_policy_get_display_name (volume_monitor_daemon, hal_drive, NULL);
drive->priv->display_name = _gnome_vfs_volume_monitor_uniquify_drive_name (volume_monitor, name);
g_free (name);
+ name = g_utf8_casefold (drive->priv->display_name, -1);
+ drive->priv->display_name_key = g_utf8_collate_key (name, -1);
+ g_free (name);
drive->priv->is_user_visible = TRUE;
drive->priv->volumes = NULL;
drive->priv->hal_udi = g_strdup (libhal_drive_get_udi (hal_drive));
@@ -988,6 +991,9 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
name = _hal_drive_policy_get_display_name (volume_monitor_daemon, hal_drive, hal_volume);
drive->priv->display_name = _gnome_vfs_volume_monitor_uniquify_drive_name (volume_monitor, name);
g_free (name);
+ name = g_utf8_casefold (drive->priv->display_name, -1);
+ drive->priv->display_name_key = g_utf8_collate_key (name, -1);
+ g_free (name);
drive->priv->is_user_visible = allowed_by_policy;
drive->priv->volumes = NULL;
drive->priv->hal_udi = g_strdup (libhal_volume_get_udi (hal_volume));
@@ -1037,6 +1043,9 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
name = _hal_volume_policy_get_display_name (volume_monitor_daemon, hal_drive, hal_volume);
vol->priv->display_name = _gnome_vfs_volume_monitor_uniquify_volume_name (volume_monitor, name);
+ g_free (name);
+ name = g_utf8_casefold (drive->priv->display_name, -1);
+ drive->priv->display_name_key = g_utf8_collate_key (name, -1);
g_free (name);
vol->priv->icon = _hal_volume_policy_get_icon (volume_monitor_daemon, hal_drive, hal_volume);
vol->priv->is_user_visible = allowed_by_policy &&
Index: libgnomevfs/gnome-vfs-volume-monitor-daemon.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-monitor-daemon.c,v
retrieving revision 1.21
diff -u -p -r1.21 gnome-vfs-volume-monitor-daemon.c
--- libgnomevfs/gnome-vfs-volume-monitor-daemon.c 22 Nov 2005 14:34:09 -0000 1.21
+++ libgnomevfs/gnome-vfs-volume-monitor-daemon.c 1 Apr 2006 10:55:27 -0000
@@ -51,6 +51,7 @@ typedef struct {
char *id;
char *uri;
char *display_name;
+ char *display_name_key;
char *icon;
} GnomeVFSConnectedServer;
@@ -638,7 +639,7 @@ create_drive_from_mount_point (GnomeVFSV
{
GnomeVFSDrive *drive;
GnomeVFSVolume *mounted_volume;
- char *uri;
+ char *name, *uri;
if (mount->is_loopback ||
!(mount->is_user_mountable ||
@@ -694,6 +695,10 @@ create_drive_from_mount_point (GnomeVFSV
drive->priv->icon = get_drive_icon_from_type (drive->priv->device_type, mount->mount_path);
drive->priv->display_name = get_drive_name (volume_monitor, drive, mount);
+
+ name = g_utf8_casefold (drive->priv->display_name, -1);
+ drive->priv->display_name_key = g_utf8_collate_key (name, -1);
+ g_free (name);
drive->priv->is_user_visible = TRUE;
drive->priv->volumes = NULL;
@@ -959,7 +964,11 @@ create_vol_from_mount (GnomeVFSVolumeMon
vol->priv->display_name = _gnome_vfs_volume_monitor_uniquify_volume_name (volume_monitor, utf8_name);
g_free (display_name);
g_free (utf8_name);
-
+
+ display_name = g_utf8_casefold (vol->priv->display_name, -1);
+ vol->priv->display_name_key = g_utf8_collate_key (display_name, -1);
+ g_free (display_name);
+
vol->priv->icon = get_icon_from_type (vol->priv->device_type, mount->mount_path);
vol->priv->is_user_visible = 0;
@@ -1083,6 +1092,7 @@ connected_server_free (GnomeVFSConnected
g_free (server->id);
g_free (server->uri);
g_free (server->display_name);
+ g_free (server->display_name_key);
g_free (server->icon);
g_free (server);
}
@@ -1101,7 +1111,7 @@ connected_server_compare (GnomeVFSConnec
if (res != 0) {
return res;
}
- res = strcmp (a->display_name, b->display_name);
+ res = strcmp (a->display_name_key, b->display_name_key);
if (res != 0) {
return res;
}
@@ -1156,9 +1166,16 @@ get_connected_servers (GnomeVFSVolumeMon
g_free (server->icon);
g_free (server);
} else {
+ char *name;
+
if (server->display_name == NULL) {
server->display_name = g_strdup (_("Network server"));
}
+
+ name = g_utf8_casefold (server->display_name);
+ server->display_name_key = g_utf8_collate_key (name, -1);
+ g_free (name);
+
if (server->icon == NULL) {
server->icon = g_strdup ("gnome-fs-share");
}
@@ -1180,13 +1197,18 @@ create_volume_from_connected_server (Gno
GnomeVFSConnectedServer *server)
{
GnomeVFSVolume *vol;
-
+ char *name;
vol = g_object_new (GNOME_VFS_TYPE_VOLUME, NULL);
vol->priv->volume_type = GNOME_VFS_VOLUME_TYPE_CONNECTED_SERVER;
vol->priv->activation_uri = g_strdup (server->uri);
vol->priv->display_name = _gnome_vfs_volume_monitor_uniquify_volume_name (volume_monitor, server->display_name);
+
+ name = g_utf8_casefold (vol->priv->display_name, -1);
+ vol->priv->display_name_key = g_utf8_collate_key (name, -1);
+ g_free (name);
+
vol->priv->icon = g_strdup (server->icon);
vol->priv->gconf_id = g_strdup (server->id);
vol->priv->is_mounted = 1;
Index: libgnomevfs/gnome-vfs-volume-monitor-private.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-monitor-private.h,v
retrieving revision 1.11
diff -u -p -r1.11 gnome-vfs-volume-monitor-private.h
--- libgnomevfs/gnome-vfs-volume-monitor-private.h 19 Feb 2006 00:59:30 -0000 1.11
+++ libgnomevfs/gnome-vfs-volume-monitor-private.h 1 Apr 2006 10:55:27 -0000
@@ -50,6 +50,7 @@ struct _GnomeVFSVolumePrivate {
char *activation_uri;
char *filesystem_type;
char *display_name;
+ char *display_name_key;
char *icon;
gboolean is_user_visible;
@@ -79,6 +80,7 @@ struct _GnomeVFSDrivePrivate {
char *activation_uri;
char *display_name;
+ char *display_name_key;
char *icon;
gboolean is_user_visible;
Index: libgnomevfs/gnome-vfs-volume.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume.c,v
retrieving revision 1.11
diff -u -p -r1.11 gnome-vfs-volume.c
--- libgnomevfs/gnome-vfs-volume.c 14 Nov 2005 11:41:13 -0000 1.11
+++ libgnomevfs/gnome-vfs-volume.c 1 Apr 2006 10:55:32 -0000
@@ -152,6 +153,7 @@ gnome_vfs_volume_finalize (GObject *obje
g_free (priv->activation_uri);
g_free (priv->filesystem_type);
g_free (priv->display_name);
+ g_free (priv->display_name_key);
g_free (priv->icon);
g_free (priv->gconf_id);
g_free (priv->hal_udi);
@@ -453,7 +490,7 @@ gnome_vfs_volume_compare (GnomeVFSVolume
return res;
}
- res = strcmp (priva->display_name, privb->display_name);
+ res = strcmp (priva->display_name_key, privb->display_name_key);
if (res != 0) {
return res;
}
@@ -552,7 +589,15 @@ _gnome_vfs_volume_from_corba (const GNOM
volume->priv->icon = decode_corba_string_or_null (corba_volume->icon, TRUE);
volume->priv->gconf_id = decode_corba_string_or_null (corba_volume->gconf_id, TRUE);
volume->priv->hal_udi = decode_corba_string_or_null (corba_volume->hal_udi, TRUE);
-
+
+ if (volume->priv->display_name != NULL) {
+ char *tmp = g_utf8_casefold (volume->priv->display_name, -1);
+ volume->priv->display_name_key = g_utf8_collate_key (tmp, -1);
+ g_free (tmp);
+ } else {
+ volume->priv->display_name_key = NULL;
+ }
+
volume->priv->is_user_visible = corba_volume->is_user_visible;
volume->priv->is_read_only = corba_volume->is_read_only;
volume->priv->is_mounted = corba_volume->is_mounted;
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]