Skip to content

Commit

Permalink
Merge pull request #16666 from zisoft/group-id-filter
Browse files Browse the repository at this point in the history
add collection and filter for group_id
  • Loading branch information
TurboGit authored Apr 24, 2024
2 parents 8327e9f + 333b73c commit 740cbbd
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 266 deletions.
1 change: 0 additions & 1 deletion po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ src/libs/filters/date.c
src/libs/filters/exposure.c
src/libs/filters/filename.c
src/libs/filters/focal.c
src/libs/filters/grouping.c
src/libs/filters/history.c
src/libs/filters/iso.c
src/libs/filters/local_copy.c
Expand Down
62 changes: 20 additions & 42 deletions src/common/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ const char *dt_collection_name_untranslated(const dt_collection_properties_t pro
return N_("filename");
case DT_COLLECTION_PROP_GEOTAGGING:
return N_("geotagging");
case DT_COLLECTION_PROP_GROUPING:
return N_("grouping");
case DT_COLLECTION_PROP_GROUP_ID:
return N_("group");
case DT_COLLECTION_PROP_LOCAL_COPY:
return N_("local copy");
case DT_COLLECTION_PROP_MODULE:
Expand Down Expand Up @@ -1854,6 +1854,22 @@ static gchar *get_query_string(const dt_collection_properties_t property, const
query = dt_util_dstrcat(query, ")");
break;

case DT_COLLECTION_PROP_GROUP_ID: // group id
query = g_strdup("(");
// handle the possibility of multiple values
elems = _strsplit_quotes(escaped_text, ",", -1);
for(int i = 0; i < g_strv_length(elems); i++)
{
gchar *group_ids = _add_wildcards(elems[i]);
query = dt_util_dstrcat(query,
"%sgroup_id LIKE '%s'",
i>0?" OR ":"", group_ids);
g_free(group_ids);
}
g_strfreev(elems);
query = dt_util_dstrcat(query, ")");
break;

case DT_COLLECTION_PROP_FOCAL_LENGTH: // focal length
{
gchar *operator, *number1, *number2;
Expand Down Expand Up @@ -2094,45 +2110,6 @@ static gchar *get_query_string(const dt_collection_properties_t property, const
break;
}

case DT_COLLECTION_PROP_GROUPING: // grouping
if(!g_strcmp0(escaped_text, "$NO_GROUP"))
{
query = g_strdup("(mi.id = group_id AND "
"NOT EXISTS(SELECT 1 AS group_count"
" FROM main.images AS gc"
" WHERE gc.group_id = mi.group_id AND gc.id != mi.id))");
}
else if(!g_strcmp0(escaped_text, "$GROUP"))
{
query = g_strdup(
"(EXISTS(SELECT 1 FROM main.images AS gc"
" WHERE gc.group_id = mi.group_id AND gc.id != mi.id))");
}
else if(!g_strcmp0(escaped_text, "$LEADER"))
{
query = g_strdup(
"(mi.id = mi.group_id AND "
"EXISTS(SELECT 1 FROM main.images AS gc"
" WHERE gc.group_id = mi.group_id AND gc.id != mi.id))");
}
else if(!g_strcmp0(escaped_text, "$FOLLOWER"))
{
query = g_strdup("(mi.id != group_id)");
}
else if(!g_strcmp0(escaped_text, _("group leaders"))) // used in collect.c
{
query = g_strdup("(mi.id = group_id)");
}
else if(!g_strcmp0(escaped_text, _("group followers"))) // used in collect.c
{
query = g_strdup("(mi.id != group_id)");
}
else // by default, we select all the images
{
query = g_strdup("1 = 1");
}
break;

case DT_COLLECTION_PROP_MODULE: // dev module
{
// clang-format off
Expand Down Expand Up @@ -2635,7 +2612,8 @@ void dt_collection_update_query(const dt_collection_t *collection,
|| property == DT_COLLECTION_PROP_WHITEBALANCE
|| property == DT_COLLECTION_PROP_FLASH
|| property == DT_COLLECTION_PROP_EXPOSURE_PROGRAM
|| property == DT_COLLECTION_PROP_METERING_MODE))
|| property == DT_COLLECTION_PROP_METERING_MODE
|| property == DT_COLLECTION_PROP_GROUP_ID))
{
gchar *text_quoted = g_strdup_printf("\"%s\"", text);
g_free(text);
Expand Down
4 changes: 3 additions & 1 deletion src/common/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ typedef enum dt_collection_properties_t
DT_COLLECTION_PROP_WHITEBALANCE,
DT_COLLECTION_PROP_FLASH,
DT_COLLECTION_PROP_EXPOSURE_PROGRAM,
DT_COLLECTION_PROP_METERING_MODE
DT_COLLECTION_PROP_METERING_MODE,

DT_COLLECTION_PROP_GROUP_ID
} dt_collection_properties_t;

typedef enum dt_collection_change_t
Expand Down
3 changes: 2 additions & 1 deletion src/dtgtk/thumbnail.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,8 @@ static gboolean _event_grouping_release(GtkWidget *widget,
else // expand the group
darktable.gui->expanded_group_id = thumb->groupid;
dt_collection_update_query(darktable.collection,
DT_COLLECTION_CHANGE_RELOAD, DT_COLLECTION_PROP_GROUPING,
DT_COLLECTION_CHANGE_RELOAD,
DT_COLLECTION_PROP_UNDEF,
NULL);
}
return FALSE;
Expand Down
33 changes: 14 additions & 19 deletions src/libs/collect.c
Original file line number Diff line number Diff line change
Expand Up @@ -2084,23 +2084,15 @@ static void _list_view(dt_lib_collect_rule_t *dr)
// clang-format on
break;

case DT_COLLECTION_PROP_GROUPING: // Grouping, 2 hardcoded alternatives
case DT_COLLECTION_PROP_GROUP_ID: // group_id
// clang-format off
g_snprintf(query, sizeof(query),
"SELECT CASE"
" WHEN id = group_id THEN '%s'"
" ELSE '%s'"
" END as group_leader, 1, COUNT(*) AS count,"
" CASE"
" WHEN id = group_id THEN '0'"
" ELSE '1'"
" END AS force_order"
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY force_order"
" ORDER BY force_order %s",
_("group leaders"), _("group followers"),
where_ext,
"SELECT mi.group_id, 1, COUNT(*) AS count"
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY group_id"
" HAVING COUNT(*) > 1"
" ORDER BY group_id %s", where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;
Expand Down Expand Up @@ -2814,8 +2806,7 @@ static void row_activated_with_event(GtkTreeView *view,
|| item == DT_COLLECTION_PROP_COLORLABEL
|| item == DT_COLLECTION_PROP_GEOTAGGING
|| item == DT_COLLECTION_PROP_HISTORY
|| item == DT_COLLECTION_PROP_LOCAL_COPY
|| item == DT_COLLECTION_PROP_GROUPING)
|| item == DT_COLLECTION_PROP_LOCAL_COPY)
{
set_properties(d->rule + active); // we just have to set the selection
}
Expand Down Expand Up @@ -3363,7 +3354,7 @@ static void _populate_collect_combo(GtkWidget *w)
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_METERING_MODE);

dt_bauhaus_combobox_add_section(w, _("darktable"));
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_GROUPING);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_GROUP_ID);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_LOCAL_COPY);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_HISTORY);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_MODULE);
Expand Down Expand Up @@ -4060,6 +4051,11 @@ void init(struct dt_lib_module_t *self)
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_HISTORY);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_RATING);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_COLORLABEL);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_WHITEBALANCE);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_FLASH);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_EXPOSURE_PROGRAM);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_METERING_MODE);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_GROUP_ID);

for(unsigned int i = 0; i < DT_METADATA_NUMBER; i++)
{
Expand All @@ -4084,7 +4080,6 @@ void init(struct dt_lib_module_t *self)
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_FILENAME);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_GEOTAGGING);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_LOCAL_COPY);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_GROUPING);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_MODULE);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_ORDER);
}
Expand Down
9 changes: 4 additions & 5 deletions src/libs/filtering.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ typedef struct _filter_t
#include "libs/filters/exposure.c"
#include "libs/filters/filename.c"
#include "libs/filters/focal.c"
#include "libs/filters/grouping.c"
#include "libs/filters/history.c"
#include "libs/filters/iso.c"
#include "libs/filters/local_copy.c"
Expand All @@ -245,7 +244,7 @@ static _filter_t filters[]
{ DT_COLLECTION_PROP_FOCAL_LENGTH, _focal_widget_init, _focal_update },
{ DT_COLLECTION_PROP_ISO, _iso_widget_init, _iso_update },
{ DT_COLLECTION_PROP_EXPOSURE, _exposure_widget_init, _exposure_update },
{ DT_COLLECTION_PROP_GROUPING, _grouping_widget_init, _grouping_update },
{ DT_COLLECTION_PROP_GROUP_ID, _misc_widget_init, _misc_update },
{ DT_COLLECTION_PROP_LOCAL_COPY, _local_copy_widget_init, _local_copy_update },
{ DT_COLLECTION_PROP_HISTORY, _history_widget_init, _history_update },
{ DT_COLLECTION_PROP_ORDER, _module_order_widget_init, _module_order_update },
Expand Down Expand Up @@ -931,7 +930,7 @@ static gboolean _rule_show_popup(GtkWidget *widget, dt_lib_filtering_rule_t *rul
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_METERING_MODE);

_popup_add_item(spop, _("darktable"), 0, TRUE, NULL, NULL, self, 0.0);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_GROUPING);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_GROUP_ID);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_LOCAL_COPY);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_HISTORY);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_MODULE);
Expand Down Expand Up @@ -1002,7 +1001,7 @@ static void _populate_rules_combo(GtkWidget *w)
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_METERING_MODE);

dt_bauhaus_combobox_add_section(w, _("darktable"));
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_GROUPING);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_GROUP_ID);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_LOCAL_COPY);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_HISTORY);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_MODULE);
Expand Down Expand Up @@ -1678,7 +1677,7 @@ static void _topbar_populate_rules_combo(GtkWidget *w, dt_lib_filtering_t *d)

dt_bauhaus_combobox_add_section(w, _("darktable"));
nb = dt_bauhaus_combobox_length(w);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_GROUPING);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_GROUP_ID);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_LOCAL_COPY);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_HISTORY);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_MODULE);
Expand Down
Loading

0 comments on commit 740cbbd

Please sign in to comment.