[file-roller] use natural order when sorting by filename
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller] use natural order when sorting by filename
- Date: Thu, 8 Sep 2011 16:59:39 +0000 (UTC)
commit 8703609e95dcee3abbec39dea567137c7fff23e9
Author: Paolo Bacchilega <paobac src gnome org>
Date: Thu Sep 8 18:55:44 2011 +0200
use natural order when sorting by filename
[bug #658173]
src/file-data.c | 41 +++++++++++++++++++++++++++++------------
src/file-data.h | 22 ++++++++++++----------
src/fr-window.c | 13 +++++++------
3 files changed, 48 insertions(+), 28 deletions(-)
---
diff --git a/src/file-data.c b/src/file-data.c
index 531b6e1..d584742 100644
--- a/src/file-data.c
+++ b/src/file-data.c
@@ -36,7 +36,7 @@ file_data_new (void)
fdata->content_type = NULL;
fdata->free_original_path = FALSE;
fdata->dir_size = 0;
-
+
return fdata;
}
@@ -53,6 +53,7 @@ file_data_free (FileData *fdata)
g_free (fdata->path);
g_free (fdata->link);
g_free (fdata->list_name);
+ g_free (fdata->sort_key);
g_free (fdata);
}
@@ -66,7 +67,7 @@ file_data_copy (FileData *src)
fdata->original_path = g_strdup (src->original_path);
fdata->free_original_path = TRUE;
-
+
fdata->full_path = g_strdup (src->full_path);
fdata->link = g_strdup (src->link);
fdata->size = src->size;
@@ -80,6 +81,7 @@ file_data_copy (FileData *src)
fdata->list_dir = src->list_dir;
fdata->list_name = g_strdup (src->list_name);
+ fdata->sort_key = g_strdup (src->sort_key);
return fdata;
}
@@ -89,10 +91,10 @@ GType
file_data_get_type (void)
{
static GType type = 0;
-
+
if (type == 0)
type = g_boxed_type_register_static ("FRFileData", (GBoxedCopyFunc) file_data_copy, (GBoxedFreeFunc) file_data_free);
-
+
return type;
}
@@ -100,10 +102,10 @@ file_data_get_type (void)
void
file_data_update_content_type (FileData *fdata)
{
-
- if (fdata->dir)
+
+ if (fdata->dir)
fdata->content_type = MIME_TYPE_DIRECTORY;
- else
+ else
fdata->content_type = get_static_string (g_content_type_guess (fdata->full_path, NULL, 0, NULL));
}
@@ -115,13 +117,28 @@ file_data_is_dir (FileData *fdata)
}
+void
+file_data_set_list_name (FileData *fdata,
+ const char *value)
+{
+ g_free (fdata->list_name);
+ fdata->list_name = g_strdup (value);
+
+ g_free (fdata->sort_key);
+ if (fdata->list_name != NULL)
+ fdata->sort_key = g_utf8_collate_key_for_filename (fdata->list_name, -1);
+ else
+ fdata->sort_key = NULL;
+}
+
+
int
file_data_compare_by_path (gconstpointer a,
gconstpointer b)
{
FileData *data_a = *((FileData **) a);
FileData *data_b = *((FileData **) b);
-
+
return strcmp (data_a->full_path, data_b->full_path);
}
@@ -132,7 +149,7 @@ find_path_in_file_data_array (GPtrArray *array,
{
int l, r, p, cmp = -1;
FileData *fd;
-
+
l = 0;
r = array->len;
while (l < r) {
@@ -140,12 +157,12 @@ find_path_in_file_data_array (GPtrArray *array,
fd = (FileData *) g_ptr_array_index (array, p);
cmp = strcmp (path, fd->original_path);
if (cmp == 0)
- return p;
+ return p;
else if (cmp < 0)
r = p;
- else
+ else
l = p + 1;
}
-
+
return -1;
}
diff --git a/src/file-data.h b/src/file-data.h
index 075170d..c1bc471 100644
--- a/src/file-data.h
+++ b/src/file-data.h
@@ -39,13 +39,14 @@ typedef struct {
gboolean dir; /* Whether this is a directory listed in the archive */
goffset dir_size;
const char *content_type;
-
+
/* Additional data. */
gboolean list_dir; /* Whether this entry is used to show
* a directory. */
char *list_name; /* The string visualized in the list
* view. */
+ char *sort_key;
/* Private data */
@@ -56,14 +57,15 @@ typedef struct {
GType file_data_get_type (void);
FileData * file_data_new (void);
-FileData * file_data_copy (FileData *src);
-void file_data_free (FileData *fdata);
-void file_data_update_content_type (FileData *fdata);
-gboolean file_data_is_dir (FileData *fdata);
-
-int file_data_compare_by_path (gconstpointer a,
- gconstpointer b);
-int find_path_in_file_data_array (GPtrArray *array,
- const char *path);
+FileData * file_data_copy (FileData *src);
+void file_data_free (FileData *fdata);
+void file_data_update_content_type (FileData *fdata);
+gboolean file_data_is_dir (FileData *fdata);
+void file_data_set_list_name (FileData *fdata,
+ const char *value);
+int file_data_compare_by_path (gconstpointer a,
+ gconstpointer b);
+int find_path_in_file_data_array (GPtrArray *array,
+ const char *path);
#endif /* FILE_DATA_H */
diff --git a/src/fr-window.c b/src/fr-window.c
index feea93c..8593ab8 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -953,7 +953,7 @@ sort_by_name (gconstpointer ptr1,
return 1;
}
- return strcasecmp (fdata1->list_name, fdata2->list_name);
+ return strcmp (fdata1->sort_key, fdata2->sort_key);
}
@@ -1127,7 +1127,7 @@ compute_file_list_name (FrWindow *window,
return FALSE;
if (window->priv->list_mode == FR_WINDOW_LIST_MODE_FLAT) {
- fdata->list_name = g_strdup (fdata->name);
+ file_data_set_list_name (fdata, fdata->name);
if (fdata->dir)
fdata->dir_size = 0;
return FALSE;
@@ -1144,7 +1144,7 @@ compute_file_list_name (FrWindow *window,
scan = fdata->full_path + current_dir_len;
end = strchr (scan, '/');
if ((end == NULL) && ! fdata->dir) { /* file */
- fdata->list_name = g_strdup (scan);
+ file_data_set_list_name (fdata, scan);
}
else { /* folder */
char *dir_name;
@@ -1163,8 +1163,10 @@ compute_file_list_name (FrWindow *window,
if ((end != NULL) && (*(end + 1) != '\0'))
fdata->list_dir = TRUE;
- fdata->list_name = dir_name;
+ file_data_set_list_name (fdata, dir_name);
fdata->dir_size = get_dir_size (window, current_dir, dir_name);
+
+ g_free (dir_name);
}
return TRUE;
@@ -1190,8 +1192,7 @@ fr_window_compute_list_names (FrWindow *window,
for (i = 0; i < files->len; i++) {
FileData *fdata = g_ptr_array_index (files, i);
- g_free (fdata->list_name);
- fdata->list_name = NULL;
+ file_data_set_list_name (fdata, NULL);
fdata->list_dir = FALSE;
/* the files array is sorted by path, when the visible list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]