Mercurial > geeqie.yaz
comparison src/filedata.c @ 1722:844714862249
fixed and simplified sidecar grouping code
author | nadvornik |
---|---|
date | Thu, 24 Sep 2009 21:52:44 +0000 |
parents | 9c7d4fe93759 |
children | 368a7e7cc695 |
comparison
equal
deleted
inserted
replaced
1721:728aa6bf4988 | 1722:844714862249 |
---|---|
182 { | 182 { |
183 g_free(basename); | 183 g_free(basename); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 #if 0 | |
187 static void file_data_basename_hash_remove(GHashTable *basename_hash, FileData *fd) | 188 static void file_data_basename_hash_remove(GHashTable *basename_hash, FileData *fd) |
188 { | 189 { |
189 GList *list; | 190 GList *list; |
190 const gchar *ext = extension_from_path(fd->path); | 191 const gchar *ext = extension_from_path(fd->path); |
191 gchar *basename = ext ? g_strndup(fd->path, ext - fd->path) : g_strdup(fd->path); | 192 gchar *basename = ext ? g_strndup(fd->path, ext - fd->path) : g_strdup(fd->path); |
205 { | 206 { |
206 g_hash_table_remove(basename_hash, basename); | 207 g_hash_table_remove(basename_hash, basename); |
207 g_free(basename); | 208 g_free(basename); |
208 } | 209 } |
209 } | 210 } |
211 #endif | |
210 | 212 |
211 static void file_data_basename_hash_remove_list(gpointer key, gpointer value, gpointer data) | 213 static void file_data_basename_hash_remove_list(gpointer key, gpointer value, gpointer data) |
212 { | 214 { |
213 filelist_free((GList *)value); | 215 filelist_free((GList *)value); |
214 } | 216 } |
236 fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1); | 238 fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1); |
237 #endif | 239 #endif |
238 g_free(caseless_name); | 240 g_free(caseless_name); |
239 } | 241 } |
240 | 242 |
241 static void file_data_set_path(FileData *fd, const gchar *path, GHashTable *basename_hash) | 243 static void file_data_set_path(FileData *fd, const gchar *path) |
242 { | 244 { |
243 g_assert(path /* && *path*/); /* view_dir_tree uses FileData with zero length path */ | 245 g_assert(path /* && *path*/); /* view_dir_tree uses FileData with zero length path */ |
244 g_assert(file_data_pool); | 246 g_assert(file_data_pool); |
245 | 247 |
246 if (basename_hash && fd->path) file_data_basename_hash_remove(basename_hash, fd); | |
247 | |
248 g_free(fd->path); | 248 g_free(fd->path); |
249 | 249 |
250 if (fd->original_path) | 250 if (fd->original_path) |
251 { | 251 { |
252 g_hash_table_remove(file_data_pool, fd->original_path); | 252 g_hash_table_remove(file_data_pool, fd->original_path); |
295 if (fd->extension == NULL) | 295 if (fd->extension == NULL) |
296 { | 296 { |
297 fd->extension = fd->name + strlen(fd->name); | 297 fd->extension = fd->name + strlen(fd->name); |
298 } | 298 } |
299 | 299 |
300 if (basename_hash) file_data_basename_hash_insert(basename_hash, fd); /* we can ignore the special cases above - they don't have extensions */ | |
301 | |
302 file_data_set_collate_keys(fd); | 300 file_data_set_collate_keys(fd); |
303 } | 301 } |
304 | 302 |
305 static gboolean file_data_check_changed_files_recursive(FileData *fd, struct stat *st) | 303 static gboolean file_data_check_changed_files_recursive(FileData *fd, struct stat *st) |
306 { | 304 { |
349 | 347 |
350 if (fd->parent) fd = fd->parent; | 348 if (fd->parent) fd = fd->parent; |
351 | 349 |
352 if (!stat_utf8(fd->path, &st)) | 350 if (!stat_utf8(fd->path, &st)) |
353 { | 351 { |
352 GList *sidecars; | |
354 GList *work; | 353 GList *work; |
355 FileData *sfd = NULL; | 354 FileData *sfd = NULL; |
356 | 355 |
357 /* parent is missing, we have to rebuild whole group */ | 356 /* parent is missing, we have to rebuild whole group */ |
358 ret = TRUE; | 357 ret = TRUE; |
359 fd->size = 0; | 358 fd->size = 0; |
360 fd->date = 0; | 359 fd->date = 0; |
361 | 360 |
362 work = fd->sidecar_files; | 361 /* file_data_disconnect_sidecar_file might delete the file, |
362 we have to keep the reference to prevent this */ | |
363 sidecars = filelist_copy(fd->sidecar_files); | |
364 work = sidecars; | |
363 while (work) | 365 while (work) |
364 { | 366 { |
365 sfd = work->data; | 367 sfd = work->data; |
366 work = work->next; | 368 work = work->next; |
367 | 369 |
368 file_data_disconnect_sidecar_file(fd, sfd); | 370 file_data_disconnect_sidecar_file(fd, sfd); |
369 } | 371 } |
370 if (sfd) file_data_check_sidecars(sfd, NULL); /* this will group the sidecars back together */ | 372 if (sfd) file_data_check_sidecars(sfd, NULL); /* this will group the sidecars back together */ |
373 /* now we can release the sidecars */ | |
374 filelist_free(sidecars); | |
371 file_data_send_notification(fd, NOTIFY_REREAD); | 375 file_data_send_notification(fd, NOTIFY_REREAD); |
372 } | 376 } |
373 else | 377 else |
374 { | 378 { |
375 ret |= file_data_check_changed_files_recursive(fd, &st); | 379 ret |= file_data_check_changed_files_recursive(fd, &st); |
405 } | 409 } |
406 | 410 |
407 if (fd) | 411 if (fd) |
408 { | 412 { |
409 gboolean changed; | 413 gboolean changed; |
410 if (basename_hash) file_data_basename_hash_insert(basename_hash, fd); | 414 if (basename_hash) |
415 { | |
416 file_data_basename_hash_insert(basename_hash, fd); | |
417 if (check_sidecars) | |
418 file_data_check_sidecars(fd, basename_hash); | |
419 } | |
411 | 420 |
412 if (fd->parent) | 421 if (fd->parent) |
413 changed = file_data_check_changed_files(fd); | 422 changed = file_data_check_changed_files(fd); |
414 else | 423 else |
415 changed = file_data_check_changed_files_recursive(fd, st); | 424 changed = file_data_check_changed_files_recursive(fd, st); |
426 fd->date = st->st_mtime; | 435 fd->date = st->st_mtime; |
427 fd->mode = st->st_mode; | 436 fd->mode = st->st_mode; |
428 fd->ref = 1; | 437 fd->ref = 1; |
429 fd->magick = 0x12345678; | 438 fd->magick = 0x12345678; |
430 | 439 |
431 file_data_set_path(fd, path_utf8, basename_hash); /* set path, name, collate_key_*, original_path */ | 440 file_data_set_path(fd, path_utf8); /* set path, name, collate_key_*, original_path */ |
441 if (basename_hash) file_data_basename_hash_insert(basename_hash, fd); | |
432 | 442 |
433 if (check_sidecars) | 443 if (check_sidecars) |
434 file_data_check_sidecars(fd, basename_hash); | 444 file_data_check_sidecars(fd, basename_hash); |
435 | 445 |
436 return fd; | 446 return fd; |
2401 */ | 2411 */ |
2402 DEBUG_1("can't rename fd, target exists %s -> %s", fd->change->dest, fd->path); | 2412 DEBUG_1("can't rename fd, target exists %s -> %s", fd->change->dest, fd->path); |
2403 } | 2413 } |
2404 else | 2414 else |
2405 { | 2415 { |
2406 file_data_set_path(fd, fd->change->dest, NULL); | 2416 file_data_set_path(fd, fd->change->dest); |
2407 } | 2417 } |
2408 } | 2418 } |
2409 file_data_increment_version(fd); | 2419 file_data_increment_version(fd); |
2410 file_data_send_notification(fd, NOTIFY_CHANGE); | 2420 file_data_send_notification(fd, NOTIFY_CHANGE); |
2411 | 2421 |