Mercurial > geeqie.yaz
comparison src/view_file_list.c @ 769:110462fdf31b
simplified vflist_populate_view
author | nadvornik |
---|---|
date | Fri, 30 May 2008 19:53:52 +0000 |
parents | 81f9e8dbb4bf |
children | 842c15317bdf |
comparison
equal
deleted
inserted
replaced
768:ff51413f098d | 769:110462fdf31b |
---|---|
731 g_free(size); | 731 g_free(size); |
732 if (sidecars) | 732 if (sidecars) |
733 g_free(sidecars); | 733 g_free(sidecars); |
734 } | 734 } |
735 | 735 |
736 static void vflist_setup_iter_with_sidecars(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd) | 736 static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *parent_iter, GList *list, GList *selection) |
737 { | 737 { |
738 GList *work; | 738 GList *work; |
739 GtkTreeIter s_iter; | 739 GtkTreeIter iter; |
740 gint valid; | 740 gint valid; |
741 | 741 |
742 vflist_setup_iter(vf, store, iter, fd); | 742 valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(store), &iter, parent_iter); |
743 | 743 |
744 | 744 work = list; |
745 /* this is almost the same code as in vflist_populate_view | |
746 maybe it should be made more generic and used in both places */ | |
747 | |
748 | |
749 valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(store), &s_iter, iter); | |
750 | |
751 work = fd->sidecar_files; | |
752 while (work) | 745 while (work) |
753 { | 746 { |
754 gint match; | 747 gint match; |
755 FileData *sfd = work->data; | 748 FileData *fd = work->data; |
756 gint done = FALSE; | 749 gint done = FALSE; |
757 | 750 |
758 while (!done) | 751 while (!done) |
759 { | 752 { |
760 FileData *old_sfd = NULL; | 753 FileData *old_fd = NULL; |
754 gint old_version = 0; | |
761 | 755 |
762 if (valid) | 756 if (valid) |
763 { | 757 { |
764 gtk_tree_model_get(GTK_TREE_MODEL(store), &s_iter, FILE_COLUMN_POINTER, &old_sfd, -1); | 758 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, |
765 | 759 FILE_COLUMN_POINTER, &old_fd, |
766 if (sfd == old_sfd) | 760 FILE_COLUMN_VERSION, &old_version, |
761 -1); | |
762 | |
763 if (fd == old_fd) | |
767 { | 764 { |
768 match = 0; | 765 match = 0; |
769 } | 766 } |
770 else | 767 else |
771 { | 768 { |
772 match = filelist_sort_compare_filedata_full(sfd, old_sfd, SORT_NAME, TRUE); | 769 if (parent_iter) |
770 match = filelist_sort_compare_filedata_full(fd, old_fd, SORT_NAME, TRUE); /* always sort sidecars by name */ | |
771 else | |
772 match = filelist_sort_compare_filedata_full(fd, old_fd, vf->sort_method, vf->sort_ascend); | |
773 | |
774 if (match == 0) g_warning("multiple fd for the same path"); | |
773 } | 775 } |
776 | |
774 } | 777 } |
775 | |
776 else | 778 else |
777 { | 779 { |
778 match = -1; | 780 match = -1; |
779 } | 781 } |
780 | 782 |
782 { | 784 { |
783 GtkTreeIter new; | 785 GtkTreeIter new; |
784 | 786 |
785 if (valid) | 787 if (valid) |
786 { | 788 { |
787 gtk_tree_store_insert_before(store, &new, iter, &s_iter); | 789 gtk_tree_store_insert_before(store, &new, parent_iter, &iter); |
788 } | 790 } |
789 else | 791 else |
790 { | 792 { |
791 gtk_tree_store_append(store, &new, iter); | 793 gtk_tree_store_append(store, &new, parent_iter); |
792 } | 794 } |
793 | 795 |
794 vflist_setup_iter(vf, store, &new, sfd); | 796 vflist_setup_iter(vf, store, &new, fd); |
797 vflist_setup_iter_recursive(vf, store, &new, fd->sidecar_files, selection); | |
795 | 798 |
796 done = TRUE; | 799 done = TRUE; |
797 } | 800 } |
798 else if (match > 0) | 801 else if (match > 0) |
799 { | 802 { |
800 valid = gtk_tree_store_remove(store, &s_iter); | 803 valid = gtk_tree_store_remove(store, &iter); |
801 } | 804 } |
802 else | 805 else |
803 { | 806 { |
804 vflist_setup_iter(vf, store, &s_iter, sfd); | 807 if (fd->version != old_version) |
805 | 808 { |
806 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &s_iter); | 809 vflist_setup_iter(vf, store, &iter, fd); |
810 vflist_setup_iter_recursive(vf, store, &iter, fd->sidecar_files, selection); | |
811 } | |
812 | |
813 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
807 | 814 |
808 done = TRUE; | 815 done = TRUE; |
809 } | 816 } |
810 } | 817 } |
811 work = work->next; | 818 work = work->next; |
812 } | 819 } |
813 | 820 |
814 while (valid) | 821 while (valid) |
815 { | 822 { |
816 valid = gtk_tree_store_remove(store, &s_iter); | 823 valid = gtk_tree_store_remove(store, &iter); |
817 } | 824 } |
818 } | 825 } |
819 | 826 |
820 void vflist_sort_set(ViewFile *vf, SortType type, gint ascend) | 827 void vflist_sort_set(ViewFile *vf, SortType type, gint ascend) |
821 { | 828 { |
1458 } | 1465 } |
1459 | 1466 |
1460 static void vflist_populate_view(ViewFile *vf) | 1467 static void vflist_populate_view(ViewFile *vf) |
1461 { | 1468 { |
1462 GtkTreeStore *store; | 1469 GtkTreeStore *store; |
1463 GtkTreeIter iter; | |
1464 gint thumbs; | 1470 gint thumbs; |
1465 GList *work; | |
1466 GtkTreeRowReference *visible_row = NULL; | 1471 GtkTreeRowReference *visible_row = NULL; |
1467 GtkTreePath *tpath; | 1472 GtkTreePath *tpath; |
1468 gint valid; | |
1469 | 1473 |
1470 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview))); | 1474 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview))); |
1471 thumbs = VFLIST_INFO(vf, thumbs_enabled); | 1475 thumbs = VFLIST_INFO(vf, thumbs_enabled); |
1472 | 1476 |
1473 vflist_thumb_stop(vf); | 1477 vflist_thumb_stop(vf); |
1486 gtk_tree_path_free(tpath); | 1490 gtk_tree_path_free(tpath); |
1487 } | 1491 } |
1488 | 1492 |
1489 vflist_listview_set_height(vf->listview, thumbs); | 1493 vflist_listview_set_height(vf->listview, thumbs); |
1490 | 1494 |
1491 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); | 1495 vflist_setup_iter_recursive(vf, store, NULL, vf->list, NULL); |
1492 | 1496 |
1493 work = vf->list; | |
1494 while (work) | |
1495 { | |
1496 gint match; | |
1497 FileData *fd = work->data; | |
1498 gint done = FALSE; | |
1499 | |
1500 while (!done) | |
1501 { | |
1502 FileData *old_fd = NULL; | |
1503 gint old_version = 0; | |
1504 | |
1505 if (valid) | |
1506 { | |
1507 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, | |
1508 FILE_COLUMN_POINTER, &old_fd, | |
1509 FILE_COLUMN_VERSION, &old_version, | |
1510 -1); | |
1511 | |
1512 if (fd == old_fd) | |
1513 { | |
1514 match = 0; | |
1515 } | |
1516 else | |
1517 { | |
1518 match = filelist_sort_compare_filedata_full(fd, old_fd, vf->sort_method, vf->sort_ascend); | |
1519 if (match == 0) | |
1520 match = -1; /* probably should not happen*/ | |
1521 } | |
1522 } | |
1523 | |
1524 else | |
1525 { | |
1526 match = -1; | |
1527 } | |
1528 | |
1529 if (match < 0) | |
1530 { | |
1531 GtkTreeIter new; | |
1532 | |
1533 if (valid) | |
1534 { | |
1535 gtk_tree_store_insert_before(store, &new, NULL, &iter); | |
1536 } | |
1537 else | |
1538 { | |
1539 gtk_tree_store_append(store, &new, NULL); | |
1540 } | |
1541 vflist_setup_iter_with_sidecars(vf, store, &new, fd); | |
1542 | |
1543 done = TRUE; | |
1544 } | |
1545 else if (match > 0) | |
1546 { | |
1547 valid = gtk_tree_store_remove(store, &iter); | |
1548 } | |
1549 else | |
1550 { | |
1551 if (old_version != fd->version) | |
1552 vflist_setup_iter_with_sidecars(vf, store, &iter, fd); | |
1553 | |
1554 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
1555 | |
1556 done = TRUE; | |
1557 } | |
1558 } | |
1559 work = work->next; | |
1560 } | |
1561 | |
1562 while (valid) | |
1563 { | |
1564 valid = gtk_tree_store_remove(store, &iter); | |
1565 } | |
1566 | |
1567 if (visible_row) | 1497 if (visible_row) |
1568 { | 1498 { |
1569 if (gtk_tree_row_reference_valid(visible_row)) | 1499 if (gtk_tree_row_reference_valid(visible_row)) |
1570 { | 1500 { |
1571 tpath = gtk_tree_row_reference_get_path(visible_row); | 1501 tpath = gtk_tree_row_reference_get_path(visible_row); |