Mercurial > geeqie.yaz
comparison src/collect.c @ 799:278962ba162a
use the new notification for collections
author | nadvornik |
---|---|
date | Sat, 07 Jun 2008 10:45:33 +0000 |
parents | a20ff446347e |
children | 764fd82dd099 |
comparison
equal
deleted
inserted
replaced
798:5055b5b0d75d | 799:278962ba162a |
---|---|
46 static void collection_window_insert(CollectWindow *cw, CollectInfo *ci); | 46 static void collection_window_insert(CollectWindow *cw, CollectInfo *ci); |
47 static void collection_window_remove(CollectWindow *cw, CollectInfo *ci); | 47 static void collection_window_remove(CollectWindow *cw, CollectInfo *ci); |
48 static void collection_window_update(CollectWindow *cw, CollectInfo *ci); | 48 static void collection_window_update(CollectWindow *cw, CollectInfo *ci); |
49 | 49 |
50 static void collection_window_close(CollectWindow *cw); | 50 static void collection_window_close(CollectWindow *cw); |
51 | |
52 static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data); | |
51 | 53 |
52 /* | 54 /* |
53 *------------------------------------------------------------------- | 55 *------------------------------------------------------------------- |
54 * data, list handling | 56 * data, list handling |
55 *------------------------------------------------------------------- | 57 *------------------------------------------------------------------- |
212 list = g_list_remove(list, ci); | 214 list = g_list_remove(list, ci); |
213 collection_info_free(ci); | 215 collection_info_free(ci); |
214 return list; | 216 return list; |
215 } | 217 } |
216 | 218 |
217 CollectInfo *collection_list_find(GList *list, const gchar *path) | 219 CollectInfo *collection_list_find_fd(GList *list, FileData *fd) |
218 { | 220 { |
219 GList *work = list; | 221 GList *work = list; |
220 | 222 |
221 while (work) | 223 while (work) |
222 { | 224 { |
223 CollectInfo *ci = work->data; | 225 CollectInfo *ci = work->data; |
224 if (strcmp(ci->fd->path, path) == 0) return ci; | 226 if (ci->fd == fd) return ci; |
225 work = work->next; | 227 work = work->next; |
226 } | 228 } |
227 | 229 |
228 return NULL; | 230 return NULL; |
229 } | 231 } |
360 } | 362 } |
361 | 363 |
362 untitled_counter++; | 364 untitled_counter++; |
363 } | 365 } |
364 | 366 |
367 file_data_register_notify_func(collection_notify_cb, cd, NOTIFY_PRIORITY_MEDIUM); | |
368 | |
365 return cd; | 369 return cd; |
366 } | 370 } |
367 | 371 |
368 void collection_free(CollectionData *cd) | 372 void collection_free(CollectionData *cd) |
369 { | 373 { |
371 | 375 |
372 DEBUG_1("collection \"%s\" freed", cd->name); | 376 DEBUG_1("collection \"%s\" freed", cd->name); |
373 | 377 |
374 collection_load_stop(cd); | 378 collection_load_stop(cd); |
375 collection_list_free(cd->list); | 379 collection_list_free(cd->list); |
380 | |
381 file_data_unregister_notify_func(collection_notify_cb, cd); | |
376 | 382 |
377 collection_list = g_list_remove(collection_list, cd); | 383 collection_list = g_list_remove(collection_list, cd); |
378 | 384 |
379 g_hash_table_destroy(cd->existence); | 385 g_hash_table_destroy(cd->existence); |
380 | 386 |
679 | 685 |
680 gint collection_remove(CollectionData *cd, FileData *fd) | 686 gint collection_remove(CollectionData *cd, FileData *fd) |
681 { | 687 { |
682 CollectInfo *ci; | 688 CollectInfo *ci; |
683 | 689 |
684 ci = collection_list_find(cd->list, fd->path); | 690 ci = collection_list_find_fd(cd->list, fd); |
685 | 691 |
686 if (!ci) return FALSE; | 692 if (!ci) return FALSE; |
687 | 693 |
688 g_hash_table_remove(cd->existence, fd->path); | 694 g_hash_table_remove(cd->existence, fd->path); |
689 | 695 |
732 } | 738 } |
733 | 739 |
734 gint collection_rename(CollectionData *cd, FileData *fd) | 740 gint collection_rename(CollectionData *cd, FileData *fd) |
735 { | 741 { |
736 CollectInfo *ci; | 742 CollectInfo *ci; |
737 const gchar *source = fd->change->source; | 743 ci = collection_list_find_fd(cd->list, fd); |
738 // const gchar *dest = fd->change->dest; | |
739 ci = collection_list_find(cd->list, source); | |
740 | 744 |
741 if (!ci) return FALSE; | 745 if (!ci) return FALSE; |
742 | 746 |
743 // g_free(ci->path); | |
744 // ci->path = g_strdup(dest); FIXME | |
745 cd->changed = TRUE; | 747 cd->changed = TRUE; |
746 | 748 |
747 collection_window_update(collection_window_find(cd), ci); | 749 collection_window_update(collection_window_find(cd), ci); |
748 | 750 |
749 return TRUE; | 751 return TRUE; |
758 *------------------------------------------------------------------- | 760 *------------------------------------------------------------------- |
759 * simple maintenance for renaming, deleting | 761 * simple maintenance for renaming, deleting |
760 *------------------------------------------------------------------- | 762 *------------------------------------------------------------------- |
761 */ | 763 */ |
762 | 764 |
763 void collection_maint_removed(FileData *fd) | 765 static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data) |
764 { | 766 { |
765 GList *work; | 767 CollectionData *cd = data; |
766 | 768 |
767 work = collection_list; | 769 if (!fd->change) return; |
768 while (work) | 770 |
769 { | 771 switch(fd->change->type) |
770 CollectionData *cd = work->data; | 772 { |
771 work = work->next; | 773 case FILEDATA_CHANGE_MOVE: |
772 | 774 case FILEDATA_CHANGE_RENAME: |
773 while (collection_remove(cd, fd)); | 775 collection_rename(cd, fd); |
774 } | 776 break; |
775 #if 0 | 777 case FILEDATA_CHANGE_COPY: |
776 /* Do we really need to do this? removed files are | 778 break; |
777 * automatically ignored when loading a collection. | 779 case FILEDATA_CHANGE_DELETE: |
778 */ | 780 while (collection_remove(cd, fd)); |
779 collect_manager_moved(fd, NULL); | 781 break; |
780 #endif | 782 case FILEDATA_CHANGE_UNSPECIFIED: |
781 } | 783 break; |
782 | 784 } |
783 void collection_maint_renamed(FileData *fd) | 785 |
784 { | 786 } |
785 GList *work; | 787 |
786 | |
787 work = collection_list; | |
788 while (work) | |
789 { | |
790 CollectionData *cd = work->data; | |
791 work = work->next; | |
792 | |
793 while (collection_rename(cd, fd)); | |
794 } | |
795 | |
796 collect_manager_moved(fd); | |
797 } | |
798 | 788 |
799 /* | 789 /* |
800 *------------------------------------------------------------------- | 790 *------------------------------------------------------------------- |
801 * window key presses | 791 * window key presses |
802 *------------------------------------------------------------------- | 792 *------------------------------------------------------------------- |