Skip to content

Commit eb4dbd5

Browse files
committed
workspace: Do not depends on the library*.db order.
We make sure that default and memory DB are first added and then we list the others. This ensure that library.db (default) is present when adding the other workspace and avoid a crash due to null access. Closes #20140.
1 parent ca35370 commit eb4dbd5

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

src/gui/workspace.c

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -170,56 +170,45 @@ gboolean dt_workspace_create(const char *datadir)
170170

171171
gtk_window_set_position(GTK_WINDOW(session->db_screen), GTK_WIN_POS_CENTER);
172172

173-
GList *dbs = dt_read_file_pattern(datadir, "library*.db");
173+
GList *dbs = dt_read_file_pattern(datadir, "library-*.db");
174174

175175
GtkWidget *l1 = gtk_label_new(_("select an existing workspace"));
176176
dt_gui_dialog_add(session->db_screen, l1);
177177

178178
const char *current_db = dt_conf_get_string("database");
179-
gboolean current_db_found = FALSE;
179+
gboolean current_db_found = strcmp("default", current_db) == 0 ? TRUE : FALSE;
180180

181+
// add default workspace
182+
GtkBox *box = _insert_button(session, _("default"));
183+
// add a memory workspace just after default one
184+
box = _insert_button(session, _("memory"));
185+
186+
// add now only the non default libraries
181187
for(GList *l = g_list_first(dbs); l; l = g_list_next(l))
182188
{
183189
char *name = (char *)l->data;
184-
const gboolean is_default = strcmp(name, "library.db") == 0;
185-
GtkBox *box = NULL;
186190

187-
if(is_default)
188-
{
189-
box = _insert_button(session, _("default"));
190-
}
191-
else if(g_str_has_prefix(name, "library-"))
192-
{
193-
// skip "library-" prefix
194-
char *f = name + strlen("library") + 1;
195-
// end with the dot
196-
char *e = f;
197-
while(*e != '.') e++;
198-
*e = '\0';
199-
200-
box = _insert_button(session, f);
201-
}
191+
// skip "library-" prefix
192+
char *f = name + strlen("library") + 1;
193+
// end with the dot
194+
char *e = f;
195+
while(*e != '.') e++;
196+
*e = '\0';
197+
198+
box = _insert_button(session, f);
202199

203200
if(strcmp(name, current_db) == 0)
204201
current_db_found = TRUE;
205202

206-
if(is_default)
207-
{
208-
// add a memory workspace just after default one
209-
box = _insert_button(session, _("memory"));
210-
}
211-
else if(!is_default)
212-
{
213-
GList *bc = gtk_container_get_children(GTK_CONTAINER(box));
214-
GtkWidget *b = (GtkWidget *)g_list_first(bc)->data;
215-
g_list_free(bc);
216-
217-
GtkWidget *del = dtgtk_button_new(dtgtk_cairo_paint_remove, 0, NULL);
218-
g_signal_connect(G_OBJECT(del), "clicked",
219-
G_CALLBACK(_workspace_delete_db), session);
220-
g_object_set_data(G_OBJECT(del), "db", b);
221-
dt_gui_box_add(box, del);
222-
}
203+
GList *bc = gtk_container_get_children(GTK_CONTAINER(box));
204+
GtkWidget *b = (GtkWidget *)g_list_first(bc)->data;
205+
g_list_free(bc);
206+
207+
GtkWidget *del = dtgtk_button_new(dtgtk_cairo_paint_remove, 0, NULL);
208+
g_signal_connect(G_OBJECT(del), "clicked",
209+
G_CALLBACK(_workspace_delete_db), session);
210+
g_object_set_data(G_OBJECT(del), "db", b);
211+
dt_gui_box_add(box, del);
223212
}
224213

225214
g_list_free_full(dbs, g_free);
@@ -233,7 +222,7 @@ gboolean dt_workspace_create(const char *datadir)
233222

234223
GtkWidget *l2 = gtk_label_new(_("or create a new one"));
235224

236-
GtkBox *box = GTK_BOX(dt_gui_hbox());
225+
box = GTK_BOX(dt_gui_hbox());
237226
session->entry = gtk_entry_new();
238227
g_signal_connect(G_OBJECT(session->entry),
239228
"changed", G_CALLBACK(_workspace_entry_changed), session);

0 commit comments

Comments
 (0)