Skip to content

Commit

Permalink
remove unused config entries
Browse files Browse the repository at this point in the history
If a preset is renamed or deleted, the corresponding config entry is
deleted, so we don't have zombie entries in dt config.
  • Loading branch information
zisoft committed Jan 12, 2025
1 parent b97b45a commit e8337a9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/control/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,14 @@ gboolean dt_conf_key_exists(const char *key)
return (res || dt_confgen_value_exists(key, DT_DEFAULT));
}

/** remove key from conf */
void dt_conf_remove_key(const char *key)
{
dt_pthread_mutex_lock(&darktable.conf->mutex);
g_hash_table_remove(darktable.conf->table, key);
dt_pthread_mutex_unlock(&darktable.conf->mutex);
}

static void _conf_add(char *key, char *val, dt_conf_dreggn_t *d)
{
if(strncmp(key, d->match, strlen(d->match)) == 0)
Expand Down
1 change: 1 addition & 0 deletions src/control/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void dt_conf_init(dt_conf_t *cf, const char *filename, GSList *override_entries)
void dt_conf_cleanup(dt_conf_t *cf);
void dt_conf_save(dt_conf_t *cf);
gboolean dt_conf_key_exists(const char *key);
void dt_conf_remove_key(const char *key);
gboolean dt_conf_key_not_empty(const char *key);
GSList *dt_conf_all_string_entries(const char *dir);
void dt_conf_string_entry_free(gpointer data);
Expand Down
49 changes: 45 additions & 4 deletions src/libs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -1320,9 +1320,26 @@ static void _fill_batch_export_list(dt_lib_module_t *self)
{
dt_lib_export_t *d = self->data;

GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(d->batch_treeview)));
gtk_list_store_clear(store);
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(d->batch_treeview));
GtkTreeIter iter;

// save all preset names from the store to check if presets were renamed/deleted
GList *nonexistent_presets = NULL;
gboolean valid = gtk_tree_model_get_iter_first(model, &iter);
while(valid)
{
char *preset_name;

gtk_tree_model_get(model, &iter,
DT_EXPORT_BATCH_COL_NAME, &preset_name,
-1);

nonexistent_presets = g_list_prepend(nonexistent_presets, g_strdup(preset_name));
valid = gtk_tree_model_iter_next(model, &iter);
}

// clear and refill the store
gtk_list_store_clear(GTK_LIST_STORE(model));
gboolean has_active = FALSE;

sqlite3_stmt *stmt;
Expand All @@ -1342,16 +1359,40 @@ static void _fill_batch_export_list(dt_lib_module_t *self)
gboolean active = dt_conf_get_bool(setting);
g_free(setting);

gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
DT_EXPORT_BATCH_COL_ACTIVE, active,
DT_EXPORT_BATCH_COL_NAME, name,
-1);
has_active |= active;

// remove unchanged preset names from the list so the list will
// contain only preset names which no longer exist
for(GList *preset_iter = nonexistent_presets; preset_iter; preset_iter = g_list_next(preset_iter))
{
gchar *preset_name = (gchar *)preset_iter->data;
if(!g_strcmp0(preset_name, name))
{
g_free(preset_name);
nonexistent_presets = g_list_remove_link(nonexistent_presets, preset_iter);
break;
}
}
}
sqlite3_finalize(stmt);

gtk_widget_set_sensitive(GTK_WIDGET(d->batch_export_button), has_active);

// remove non-existent entries from config
for(GList *preset_iter = nonexistent_presets; preset_iter; preset_iter = g_list_next(preset_iter))
{
const gchar *preset_name = (gchar *)preset_iter->data;
gchar *setting = g_strdup_printf(CONFIG_PREFIX "batch_%s", preset_name);
dt_conf_remove_key(setting);
g_free(setting);
}

g_list_free_full(nonexistent_presets, g_free);
}

static void _export_presets_changed_callback(gpointer instance, gpointer module, dt_lib_module_t *self)
Expand Down

0 comments on commit e8337a9

Please sign in to comment.