Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

po/collect header sort #16072

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions data/darktableconfig.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -755,13 +755,6 @@
<shortdescription>sort film rolls by</shortdescription>
<longdescription>sets the collections-list order for film rolls</longdescription>
</dtconfig>
<dtconfig dialog="collect">
<name>plugins/collect/descending</name>
<type>bool</type>
<default>true</default>
<shortdescription>sort collection descending</shortdescription>
<longdescription>sort the following collections in descending order: 'film roll' by folder, 'folder', 'times' (e.g. 'capture date')</longdescription>
</dtconfig>
<dtconfig>
<name>ui_last/colorpicker_model</name>
<type>
Expand Down
19 changes: 12 additions & 7 deletions src/common/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
#include "common/file_location.h"
#include "common/module.h"

GList *dt_module_load_modules(const char *subdir, size_t module_size,
int (*load_module_so)(void *module, const char *libname, const char *plugin_name),
GList *dt_module_load_modules(const char *subdir,
const size_t module_size,
int (*load_module_so)(void *module,
const char *libname,
const char *plugin_name),
void (*init_module)(void *module),
gint (*sort_modules)(gconstpointer a, gconstpointer b))
{
Expand All @@ -41,12 +44,14 @@ GList *dt_module_load_modules(const char *subdir, size_t module_size,
while((dir_name = g_dir_read_name(dir)))
{
// get lib*.so
if(!g_str_has_prefix(dir_name, SHARED_MODULE_PREFIX)) continue;
if(!g_str_has_suffix(dir_name, SHARED_MODULE_SUFFIX)) continue;
if(!g_str_has_prefix(dir_name, SHARED_MODULE_PREFIX))
continue;
if(!g_str_has_suffix(dir_name, SHARED_MODULE_SUFFIX))
continue;
char *plugin_name = g_strndup(dir_name + name_offset, strlen(dir_name) - name_end);
void *module = calloc(1, module_size);
gchar *libname = g_module_build_path(plugindir, plugin_name);
int res = load_module_so(module, libname, plugin_name);
const int res = load_module_so(module, libname, plugin_name);
g_free(libname);
g_free(plugin_name);
if(res)
Expand All @@ -56,7 +61,8 @@ GList *dt_module_load_modules(const char *subdir, size_t module_size,
}
plugin_list = g_list_prepend(plugin_list, module);

if(init_module) init_module(module);
if(init_module)
init_module(module);
}
g_dir_close(dir);

Expand All @@ -73,4 +79,3 @@ GList *dt_module_load_modules(const char *subdir, size_t module_size,
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

8 changes: 5 additions & 3 deletions src/common/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

#include <glib.h>

GList *dt_module_load_modules(const char *subdir, size_t module_size,
int (*load_module_so)(void *module, const char *libname, const char *plugin_name),
GList *dt_module_load_modules(const char *subdir,
const size_t module_size,
int (*load_module_so)(void *module,
const char *libname,
const char *plugin_name),
void (*init_module)(void *module),
gint (*sort_modules)(gconstpointer a, gconstpointer b));

Expand All @@ -30,4 +33,3 @@ GList *dt_module_load_modules(const char *subdir, size_t module_size,
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

131 changes: 96 additions & 35 deletions src/libs/collect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,6 @@ static void _tree_view(dt_lib_collect_rule_t *dr)
dt_lib_collect_t *d = get_collect(dr);
const int property = _combo_get_active_collection(dr->combo);
char *format_separator = "";
gboolean sorting_always_asc = TRUE;

switch(property)
{
Expand All @@ -1333,7 +1332,6 @@ static void _tree_view(dt_lib_collect_rule_t *dr)
case DT_COLLECTION_PROP_EXPORT_TIMESTAMP:
case DT_COLLECTION_PROP_PRINT_TIMESTAMP:
format_separator = "%s:";
sorting_always_asc = FALSE;
break;
}

Expand Down Expand Up @@ -1566,7 +1564,7 @@ static void _tree_view(dt_lib_collect_rule_t *dr)
// this order should not be altered. the right feeding of the tree relies on it.
sorted_names = g_list_sort(sorted_names, _sort_folder_tag);
const gboolean sort_descend = dt_conf_get_bool("plugins/collect/descending");
if(sorting_always_asc || !sort_descend)
if(!sort_descend)
sorted_names = g_list_reverse(sorted_names);

const gboolean no_uncategorized =
Expand Down Expand Up @@ -1816,6 +1814,8 @@ static void _list_view(dt_lib_collect_rule_t *dr)
gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(d->listfilter));
if(d->view_rule != property)
{
const gboolean sort_descending = dt_conf_get_bool("plugins/collect/descending");

sqlite3_stmt *stmt;
GtkTreeIter iter;
g_object_unref(d->listfilter);
Expand All @@ -1838,7 +1838,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" WHERE mi.camera_id = cm.id"
" AND %s "
" GROUP BY LOWER(camera)"
" ORDER BY LOWER(camera)", where_ext);
" ORDER BY LOWER(camera) %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1863,8 +1865,10 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" FROM main.history_hash) ON id = imgid"
" WHERE %s"
" GROUP BY force_order"
" ORDER BY force_order",
_("basic"), _("auto applied"), _("altered"), _("basic"), where_ext);
" ORDER BY force_order %s",
_("basic"), _("auto applied"), _("altered"), _("basic"),
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1881,11 +1885,12 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" END as force_order"
" FROM main.images AS mi "
" WHERE %s"
" GROUP BY force_order ORDER BY force_order",
" GROUP BY force_order ORDER BY force_order %s",
DT_IMAGE_LOCAL_COPY,
_("copied locally"),
_("not copied locally"),
DT_IMAGE_LOCAL_COPY, where_ext);
DT_IMAGE_LOCAL_COPY, where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1895,7 +1900,10 @@ static void _list_view(dt_lib_collect_rule_t *dr)
"SELECT ROUND(aspect_ratio,1), 1, COUNT(*) AS count"
" FROM main.images AS mi "
" WHERE %s"
" GROUP BY ROUND(aspect_ratio,1)", where_ext);
" GROUP BY ROUND(aspect_ratio,1)"
" ORDER BY ROUND(aspect_ratio,1) %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1916,8 +1924,10 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" ON id = color_labels_id "
" WHERE %s"
" GROUP BY color"
" ORDER BY color ASC",
_("red"), _("yellow"), _("green"), _("blue"), _("purple"), where_ext);
" ORDER BY color %s",
_("red"), _("yellow"), _("green"), _("blue"), _("purple"),
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1932,7 +1942,8 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" WHERE mi.lens_id = ln.id"
" AND %s"
" GROUP BY LOWER(lens)"
" ORDER BY LOWER(lens)", where_ext);
" ORDER BY LOWER(lens) %s", where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1944,8 +1955,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY CAST(focal_length AS INTEGER)"
" ORDER BY CAST(focal_length AS INTEGER)",
where_ext);
" ORDER BY CAST(focal_length AS INTEGER) %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1956,8 +1968,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY iso"
" ORDER BY iso ASC",
where_ext);
" ORDER BY iso %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1968,8 +1981,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY aperture"
" ORDER BY aperture ASC",
where_ext);
" ORDER BY aperture %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1983,8 +1997,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY _exposure"
" ORDER BY exposure",
where_ext);
" ORDER BY exposure %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -1995,7 +2010,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY lower(filename)"
" ORDER BY lower(filename) ASC", where_ext);
" ORDER BY lower(filename) %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -2013,8 +2030,10 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY force_order"
" ORDER BY force_order ASC",
_("group leaders"), _("group followers"), where_ext);
" ORDER BY force_order %s",
_("group leaders"), _("group followers"),
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -2031,8 +2050,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" ON m.operation = h.operation"
" WHERE %s"
" GROUP BY lower(module_name)"
" ORDER BY lower(module_name) ASC",
where_ext);
" ORDER BY lower(module_name) %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

Expand All @@ -2053,8 +2073,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" ON mo.imgid = mi.id"
" WHERE %s"
" GROUP BY ver"
" ORDER BY ver ASC",
orders, where_ext);
" ORDER BY ver %s",
orders, where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
g_free(orders);
}
Expand All @@ -2070,7 +2091,8 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY rating"
" ORDER BY rating ASC", where_ext);
" ORDER BY rating %s", where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
}
break;
Expand Down Expand Up @@ -2100,8 +2122,9 @@ static void _list_view(dt_lib_collect_rule_t *dr)
" ON id = meta_data_id"
" WHERE %s"
" GROUP BY lower(value)"
" ORDER BY force_order ASC, lower(value) ASC",
_("not defined"), keyid, where_ext);
" ORDER BY force_order ASC, lower(value) %s",
_("not defined"), keyid, where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
}
}
Expand All @@ -2113,18 +2136,19 @@ static void _list_view(dt_lib_collect_rule_t *dr)
const gboolean sort_by_import_time =
dt_conf_is_equal("plugins/collect/filmroll_sort", "import time");

const gboolean sort_descending = dt_conf_get_bool("plugins/collect/descending");

if(sort_by_import_time)
{
if(sort_descending)
order_by = g_strdup("film_rolls_id DESC");
else
order_by = g_strdup("film_rolls_id");
order_by = g_strdup("film_rolls_id ASC");
}
else
{
order_by = g_strdup("lower(folder) ASC");
if(sort_descending)
order_by = g_strdup("lower(folder) DESC");
else
order_by = g_strdup("lower(folder) ASC");
}

// clang-format off
Expand Down Expand Up @@ -2167,7 +2191,7 @@ static void _list_view(dt_lib_collect_rule_t *dr)
folder = dt_image_film_roll_name(folder);
status = !sqlite3_column_int(stmt, 3);
}
else if (property == DT_COLLECTION_PROP_RATING)
else if(property == DT_COLLECTION_PROP_RATING)
{
const int rating = sqlite3_column_int(stmt, 0);
switch(rating)
Expand Down Expand Up @@ -3475,6 +3499,43 @@ static void _history_previous(dt_action_t *action)
}
}

static void _sort_reverse_changed(GtkDarktableToggleButton *widget, gpointer user_data)
{
const gboolean reverse = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
if(reverse)
dtgtk_togglebutton_set_paint(DTGTK_TOGGLEBUTTON(widget),
dtgtk_cairo_paint_sortby,
CPF_DIRECTION_DOWN, NULL);
else
dtgtk_togglebutton_set_paint(DTGTK_TOGGLEBUTTON(widget),
dtgtk_cairo_paint_sortby,
CPF_DIRECTION_UP, NULL);
dt_conf_set_bool("plugins/collect/descending", reverse);
gtk_widget_queue_draw((GtkWidget*)widget);

dt_collection_update_query(darktable.collection,
DT_COLLECTION_CHANGE_NEW_QUERY,
DT_COLLECTION_PROP_UNDEF, NULL);
}

GtkWidget *gui_tool_box(dt_lib_module_t *self)
{
// specific header action
const gboolean sort_descend = dt_conf_get_bool("plugins/collect/descending");

GtkWidget *sortb = dtgtk_togglebutton_new(dtgtk_cairo_paint_sortby,
sort_descend
? CPF_DIRECTION_DOWN
: CPF_DIRECTION_UP,
NULL);
dt_gui_add_class(sortb, "dt_ignore_fg_state");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sortb), sort_descend);
g_signal_connect(G_OBJECT(sortb),
"toggled",
G_CALLBACK(_sort_reverse_changed), self);
return sortb;
}

void gui_init(dt_lib_module_t *self)
{
dt_lib_collect_t *d = (dt_lib_collect_t *)calloc(1, sizeof(dt_lib_collect_t));
Expand Down
Loading