[gthumb/gthumb-3-4] sort catalogs by name, then by date
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb/gthumb-3-4] sort catalogs by name, then by date
- Date: Mon, 14 Mar 2016 08:34:54 +0000 (UTC)
commit 128b8330003e0414946803a53fa069348d091c0b
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Mar 12 18:11:41 2016 +0100
sort catalogs by name, then by date
extensions/catalogs/dlg-catalog-properties.c | 2 +-
extensions/catalogs/gth-catalog.c | 16 ++++-----
gthumb/glib-utils.c | 15 +++++++++
gthumb/glib-utils.h | 5 +++
gthumb/gth-folder-tree.c | 42 ++++++++++++++++++-------
gthumb/gth-main-default-metadata.c | 1 +
6 files changed, 59 insertions(+), 22 deletions(-)
---
diff --git a/extensions/catalogs/dlg-catalog-properties.c b/extensions/catalogs/dlg-catalog-properties.c
index 7461c07..70db13f 100644
--- a/extensions/catalogs/dlg-catalog-properties.c
+++ b/extensions/catalogs/dlg-catalog-properties.c
@@ -69,8 +69,8 @@ catalog_saved_cb (void **buffer,
gth_monitor_file_renamed (gth_main_get_default_monitor (),
data->original_file,
data->file_data->file);
-
}
+
gth_catalog_update_metadata (data->catalog, data->file_data);
gth_monitor_metadata_changed (gth_main_get_default_monitor (), data->file_data);
diff --git a/extensions/catalogs/gth-catalog.c b/extensions/catalogs/gth-catalog.c
index 2a7a158..807e239 100644
--- a/extensions/catalogs/gth-catalog.c
+++ b/extensions/catalogs/gth-catalog.c
@@ -694,16 +694,14 @@ update_standard_attributes (GFile *file,
if (gth_datetime_valid_date (date_time)) {
char *sort_order_s;
- int sort_order;
sort_order_s = gth_datetime_strftime (date_time, "%Y%m%d");
- sort_order = atoi (sort_order_s);
- g_file_info_set_sort_order (info, sort_order);
+ _g_file_info_set_secondary_sort_order (info, atoi (sort_order_s));
g_free (sort_order_s);
}
- else if (g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
- g_file_info_set_sort_order (info, 99999999);
+ else
+ g_file_info_remove_attribute (info, "gth::standard::secondary-sort-order");
display_name = get_display_name (file, name, date_time);
if (display_name != NULL) {
@@ -745,7 +743,6 @@ gth_catalog_update_metadata (GthCatalog *catalog,
char *raw;
char *formatted;
char *sort_order_s;
- int sort_order;
metadata = (GObject *) gth_metadata_new ();
raw = gth_datetime_to_exif_date (catalog->priv->date_time);
@@ -758,15 +755,16 @@ gth_catalog_update_metadata (GthCatalog *catalog,
g_file_info_set_attribute_object (file_data->info, "general::event-date", metadata);
sort_order_s = gth_datetime_strftime (catalog->priv->date_time, "%Y%m%d");
- sort_order = atoi (sort_order_s);
- g_file_info_set_sort_order (file_data->info, sort_order);
+ _g_file_info_set_secondary_sort_order (file_data->info, atoi (sort_order_s));
g_free (formatted);
g_free (raw);
g_object_unref (metadata);
}
- else
+ else {
g_file_info_remove_attribute (file_data->info, "general::event-date");
+ g_file_info_remove_attribute (file_data->info, "gth::standard::secondary-sort-order");
+ }
/* standard::display-name,standard::sort-order */
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index cf63930..6e79935 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -2937,6 +2937,21 @@ _g_file_info_swap_attributes (GFileInfo *info,
}
+void
+_g_file_info_set_secondary_sort_order (GFileInfo *info,
+ gint32 sort_order)
+{
+ g_file_info_set_attribute_int32 (info, "gth::standard::secondary-sort-order", sort_order);
+}
+
+
+gint32
+_g_file_info_get_secondary_sort_order (GFileInfo *info)
+{
+ return g_file_info_get_attribute_int32 (info, "gth::standard::secondary-sort-order");
+}
+
+
const char *
_g_content_type_guess_from_name (const char *filename)
{
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index 763ca26..7e087cd 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -323,6 +323,11 @@ gboolean _g_file_attributes_matches_any_v (const char *attributes,
void _g_file_info_swap_attributes (GFileInfo *info,
const char *attr1,
const char *attr2);
+void _g_file_info_set_secondary_sort_order
+ (GFileInfo *info,
+ gint32 sort_order);
+gint32 _g_file_info_get_secondary_sort_order
+ (GFileInfo *info);
const char * _g_content_type_guess_from_name (const char *filename);
gboolean _g_content_type_is_a (const char *type,
const char *supertype);
diff --git a/gthumb/gth-folder-tree.c b/gthumb/gth-folder-tree.c
index 7a0463e..4bf9574 100644
--- a/gthumb/gth-folder-tree.c
+++ b/gthumb/gth-folder-tree.c
@@ -56,6 +56,7 @@ enum {
COLUMN_FILE_DATA,
COLUMN_SORT_KEY,
COLUMN_SORT_ORDER,
+ COLUMN_SECONDARY_SORT_ORDER,
COLUMN_NAME,
COLUMN_NO_CHILD,
COLUMN_LOADED,
@@ -867,28 +868,35 @@ column_name_compare_func (GtkTreeModel *model,
GtkTreeIter *b,
gpointer user_data)
{
- char *key_a;
- char *key_b;
- int order_a;
- int order_b;
- PangoStyle style_a;
- PangoStyle style_b;
+ char *key_a, *key_b;
+ int order_a, order_b;
+ int sec_order_a, sec_order_b;
+ PangoStyle style_a, style_b;
gboolean result;
gtk_tree_model_get (model, a,
COLUMN_SORT_KEY, &key_a,
COLUMN_SORT_ORDER, &order_a,
+ COLUMN_SECONDARY_SORT_ORDER, &sec_order_a,
COLUMN_STYLE, &style_a,
-1);
gtk_tree_model_get (model, b,
COLUMN_SORT_KEY, &key_b,
COLUMN_SORT_ORDER, &order_b,
+ COLUMN_SECONDARY_SORT_ORDER, &sec_order_b,
COLUMN_STYLE, &style_b,
-1);
if (order_a == order_b) {
- if (style_a == style_b)
+ if (style_a == style_b) {
result = strcmp (key_a, key_b);
+ if (result == 0) {
+ if (sec_order_a < sec_order_b)
+ result = -1;
+ else if (sec_order_a > sec_order_b)
+ result = 1;
+ }
+ }
else if (style_a == PANGO_STYLE_ITALIC)
result = -1;
else
@@ -1071,6 +1079,7 @@ _gth_folder_tree_add_loading_item (GthFolderTree *folder_tree,
COLUMN_NAME, _("Loading…"),
COLUMN_SORT_KEY, sort_key,
COLUMN_SORT_ORDER, 0,
+ COLUMN_SECONDARY_SORT_ORDER, 0,
-1);
g_free (sort_key);
@@ -1097,6 +1106,7 @@ _gth_folder_tree_add_empty_item (GthFolderTree *folder_tree,
COLUMN_NAME, _("(Empty)"),
COLUMN_SORT_KEY, sort_key,
COLUMN_SORT_ORDER, 0,
+ COLUMN_SECONDARY_SORT_ORDER, 0,
-1);
g_free (sort_key);
@@ -1108,22 +1118,28 @@ _gth_folder_tree_set_file_data (GthFolderTree *folder_tree,
GtkTreeIter *iter,
GthFileData *file_data)
{
- const char *name;
+ const char *display_name;
+ const char *name_for_sorting;
char *sort_key;
- name = g_file_info_get_display_name (file_data->info);
- if (name == NULL)
+ display_name = g_file_info_get_display_name (file_data->info);
+ if (display_name == NULL)
return FALSE;
- sort_key = g_utf8_collate_key_for_filename (name, -1);
+ name_for_sorting = g_file_info_get_edit_name (file_data->info);
+ if (name_for_sorting == NULL)
+ name_for_sorting = display_name;
+
+ sort_key = g_utf8_collate_key_for_filename (name_for_sorting, -1);
gtk_tree_store_set (folder_tree->priv->tree_store, iter,
COLUMN_STYLE, PANGO_STYLE_NORMAL,
COLUMN_ICON, g_file_info_get_symbolic_icon (file_data->info),
COLUMN_TYPE, ENTRY_TYPE_FILE,
COLUMN_FILE_DATA, file_data,
- COLUMN_NAME, name,
+ COLUMN_NAME, display_name,
COLUMN_SORT_KEY, sort_key,
COLUMN_SORT_ORDER, g_file_info_get_sort_order (file_data->info),
+ COLUMN_SECONDARY_SORT_ORDER, _g_file_info_get_secondary_sort_order
(file_data->info),
COLUMN_NO_CHILD, g_file_info_get_attribute_boolean (file_data->info,
"gthumb::no-child"),
COLUMN_LOADED, FALSE,
-1);
@@ -1265,6 +1281,7 @@ gth_folder_tree_init (GthFolderTree *folder_tree)
G_TYPE_OBJECT,
G_TYPE_STRING,
G_TYPE_INT,
+ G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN);
@@ -1365,6 +1382,7 @@ gth_folder_tree_set_list (GthFolderTree *folder_tree,
COLUMN_NAME, _("(Open Parent)"),
COLUMN_SORT_KEY, sort_key,
COLUMN_SORT_ORDER, 0,
+ COLUMN_SECONDARY_SORT_ORDER, 0,
-1);
g_object_unref (icon);
diff --git a/gthumb/gth-main-default-metadata.c b/gthumb/gth-main-default-metadata.c
index 564a6c1..a9d066b 100644
--- a/gthumb/gth-main-default-metadata.c
+++ b/gthumb/gth-main-default-metadata.c
@@ -66,6 +66,7 @@ GthMetadataInfo file_metadata_info[] = {
{ "Embedded::Photo::Copyright", N_("Copyright"), "general", 31, NULL, GTH_METADATA_ALLOW_EVERYWHERE
},
{ "gth::file::emblems", "", "", 0, NULL, GTH_METADATA_ALLOW_NOWHERE },
+ { "gth::standard::secondary-sort-order", "", "", 0, NULL, GTH_METADATA_ALLOW_NOWHERE },
{ "image::width", "", "", 0, NULL, GTH_METADATA_ALLOW_NOWHERE },
{ "image::height", "", "", 0, NULL, GTH_METADATA_ALLOW_NOWHERE },
{ "frame::width", "", "", 0, NULL, GTH_METADATA_ALLOW_NOWHERE },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]