comparison src/search.c @ 138:71e1ebee420e

replaced gchar* path with FileData *fd
author nadvornik
date Tue, 11 Sep 2007 20:06:29 +0000
parents 9d5c75b5ec28
children 0584cb78aa14
comparison
equal deleted inserted replaced
137:be3328a58875 138:71e1ebee420e
181 }; 181 };
182 182
183 typedef struct _MatchFileData MatchFileData; 183 typedef struct _MatchFileData MatchFileData;
184 struct _MatchFileData 184 struct _MatchFileData
185 { 185 {
186 FileData fd; 186 FileData *fd;
187 gint width; 187 gint width;
188 gint height; 188 gint height;
189 gint rank; 189 gint rank;
190 }; 190 };
191 191
331 331
332 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); 332 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view));
333 valid = gtk_tree_model_get_iter_first(store, iter); 333 valid = gtk_tree_model_get_iter_first(store, iter);
334 while (valid) 334 while (valid)
335 { 335 {
336 FileData *fd_n; 336 MatchFileData *mfd;
337 n++; 337 n++;
338 338
339 gtk_tree_model_get(store, iter, SEARCH_COLUMN_POINTER, &fd_n, -1); 339 gtk_tree_model_get(store, iter, SEARCH_COLUMN_POINTER, &mfd, -1);
340 if (fd_n == fd) return n; 340 if (mfd->fd == fd) return n;
341 valid = gtk_tree_model_iter_next(store, iter); 341 valid = gtk_tree_model_iter_next(store, iter);
342 } 342 }
343 343
344 return -1; 344 return -1;
345 } 345 }
356 slist = gtk_tree_selection_get_selected_rows(selection, &store); 356 slist = gtk_tree_selection_get_selected_rows(selection, &store);
357 work = slist; 357 work = slist;
358 while (!found && work) 358 while (!found && work)
359 { 359 {
360 GtkTreePath *tpath = work->data; 360 GtkTreePath *tpath = work->data;
361 FileData *fd_n; 361 MatchFileData *mfd_n;
362 GtkTreeIter iter; 362 GtkTreeIter iter;
363 363
364 gtk_tree_model_get_iter(store, &iter, tpath); 364 gtk_tree_model_get_iter(store, &iter, tpath);
365 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd_n, -1); 365 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd_n, -1);
366 if (fd_n == fd) found = TRUE; 366 if (mfd_n->fd == fd) found = TRUE;
367 work = work->next; 367 work = work->next;
368 } 368 }
369 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); 369 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL);
370 g_list_free(slist); 370 g_list_free(slist);
371 371
391 n++; 391 n++;
392 392
393 if (bytes || list) 393 if (bytes || list)
394 { 394 {
395 GtkTreePath *tpath = work->data; 395 GtkTreePath *tpath = work->data;
396 FileData *fd; 396 MatchFileData *mfd;
397 GtkTreeIter iter; 397 GtkTreeIter iter;
398 398
399 gtk_tree_model_get_iter(store, &iter, tpath); 399 gtk_tree_model_get_iter(store, &iter, tpath);
400 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd, -1); 400 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1);
401 total += fd->size; 401 total += mfd->fd->size;
402 402
403 if (list) plist = g_list_prepend(plist, g_strdup(fd->path)); 403 if (list) plist = g_list_prepend(plist, file_data_ref(mfd->fd));
404 } 404 }
405 405
406 work = work->next; 406 work = work->next;
407 } 407 }
408 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); 408 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL);
442 while (valid) 442 while (valid)
443 { 443 {
444 n++; 444 n++;
445 if (bytes || list) 445 if (bytes || list)
446 { 446 {
447 FileData *fd; 447 MatchFileData *mfd;
448 448
449 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd, -1); 449 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1);
450 total += fd->size; 450 total += mfd->fd->size;
451 451
452 if (list) plist = g_list_prepend(plist, g_strdup(fd->path)); 452 if (list) plist = g_list_prepend(plist, file_data_ref(mfd->fd));
453 } 453 }
454 valid = gtk_tree_model_iter_next(store, &iter); 454 valid = gtk_tree_model_iter_next(store, &iter);
455 } 455 }
456 456
457 if (bytes) *bytes = total; 457 if (bytes) *bytes = total;
458 if (list) *list = g_list_reverse(plist); 458 if (list) *list = g_list_reverse(plist);
459 459
460 return n; 460 return n;
461 } 461 }
462 462
463 static GList *search_result_get_path_list(SearchData *sd) 463 static GList *search_result_get_filelist(SearchData *sd)
464 { 464 {
465 GList *list = NULL; 465 GList *list = NULL;
466 466
467 search_result_util(sd, NULL, &list); 467 search_result_util(sd, NULL, &list);
468 return list; 468 return list;
479 GtkListStore *store; 479 GtkListStore *store;
480 GtkTreeIter iter; 480 GtkTreeIter iter;
481 gchar *text_size; 481 gchar *text_size;
482 gchar *text_dim = NULL; 482 gchar *text_dim = NULL;
483 483
484 fd = (FileData *)mfd; 484 fd = mfd->fd;
485 485
486 if (!fd) return; 486 if (!fd) return;
487 487
488 text_size = text_from_size(fd->size); 488 text_size = text_from_size(fd->size);
489 if (mfd->width > 0 && mfd->height > 0) text_dim = g_strdup_printf("%d x %d", mfd->width, mfd->height); 489 if (mfd->width > 0 && mfd->height > 0) text_dim = g_strdup_printf("%d x %d", mfd->width, mfd->height);
490 490
491 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view))); 491 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)));
492 gtk_list_store_append(store, &iter); 492 gtk_list_store_append(store, &iter);
493 gtk_list_store_set(store, &iter, 493 gtk_list_store_set(store, &iter,
494 SEARCH_COLUMN_POINTER, fd, 494 SEARCH_COLUMN_POINTER, mfd,
495 SEARCH_COLUMN_RANK, mfd->rank, 495 SEARCH_COLUMN_RANK, mfd->rank,
496 SEARCH_COLUMN_THUMB, fd->pixbuf, 496 SEARCH_COLUMN_THUMB, fd->pixbuf,
497 SEARCH_COLUMN_NAME, fd->name, 497 SEARCH_COLUMN_NAME, fd->name,
498 SEARCH_COLUMN_SIZE, text_size, 498 SEARCH_COLUMN_SIZE, text_size,
499 SEARCH_COLUMN_DATE, text_from_time(fd->date), 499 SEARCH_COLUMN_DATE, text_from_time(fd->date),
515 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); 515 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view));
516 516
517 valid = gtk_tree_model_get_iter_first(store, &iter); 517 valid = gtk_tree_model_get_iter_first(store, &iter);
518 while (valid) 518 while (valid)
519 { 519 {
520 FileData *fd; 520 MatchFileData *mfd;
521 521
522 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd, -1); 522 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1);
523 list = g_list_prepend(list, fd); 523 list = g_list_prepend(list, mfd->fd);
524 524
525 valid = gtk_tree_model_iter_next(store, &iter); 525 valid = gtk_tree_model_iter_next(store, &iter);
526 } 526 }
527 527
528 /* clear it here, so that the FileData in list is not freed */ 528 /* clear it here, so that the FileData in list is not freed */
532 } 532 }
533 533
534 static gboolean search_result_free_node(GtkTreeModel *store, GtkTreePath *tpath, 534 static gboolean search_result_free_node(GtkTreeModel *store, GtkTreePath *tpath,
535 GtkTreeIter *iter, gpointer data) 535 GtkTreeIter *iter, gpointer data)
536 { 536 {
537 FileData *fd; 537 MatchFileData *mfd;
538 538
539 gtk_tree_model_get(store, iter, SEARCH_COLUMN_POINTER, &fd, -1); 539 gtk_tree_model_get(store, iter, SEARCH_COLUMN_POINTER, &mfd, -1);
540 file_data_free(fd); 540 file_data_unref(mfd->fd);
541 g_free(mfd);
541 542
542 return FALSE; 543 return FALSE;
543 } 544 }
544 545
545 static void search_result_clear(SearchData *sd) 546 static void search_result_clear(SearchData *sd)
558 sd->thumb_fd = NULL; 559 sd->thumb_fd = NULL;
559 560
560 search_status_update(sd); 561 search_status_update(sd);
561 } 562 }
562 563
563 static void search_result_remove_item(SearchData *sd, FileData *fd, GtkTreeIter *iter) 564 static void search_result_remove_item(SearchData *sd, MatchFileData *mfd, GtkTreeIter *iter)
564 { 565 {
565 GtkTreeModel *store; 566 GtkTreeModel *store;
566 567
567 if (!fd || !iter) return; 568 if (!mfd || !iter) return;
568 569
569 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); 570 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view));
570 571
571 tree_view_move_cursor_away(GTK_TREE_VIEW(sd->result_view), iter, TRUE); 572 tree_view_move_cursor_away(GTK_TREE_VIEW(sd->result_view), iter, TRUE);
572 573
573 gtk_list_store_remove(GTK_LIST_STORE(store), iter); 574 gtk_list_store_remove(GTK_LIST_STORE(store), iter);
574 if (sd->click_fd == fd) sd->click_fd = NULL; 575 if (sd->click_fd == mfd->fd) sd->click_fd = NULL;
575 if (sd->thumb_fd == fd) sd->thumb_fd = NULL; 576 if (sd->thumb_fd == mfd->fd) sd->thumb_fd = NULL;
576 file_data_free(fd); 577 file_data_unref(mfd->fd);
578 g_free(mfd);
577 } 579 }
578 580
579 static void search_result_remove(SearchData *sd, FileData *fd) 581 static void search_result_remove(SearchData *sd, FileData *fd)
580 { 582 {
581 GtkTreeModel *store; 583 GtkTreeModel *store;
584 586
585 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); 587 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view));
586 valid = gtk_tree_model_get_iter_first(store, &iter); 588 valid = gtk_tree_model_get_iter_first(store, &iter);
587 while (valid) 589 while (valid)
588 { 590 {
589 FileData *fd_n; 591 MatchFileData *mfd;
590 592
591 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd_n, -1); 593 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1);
592 if (fd_n == fd) 594 if (mfd->fd == fd)
593 { 595 {
594 search_result_remove_item(sd, fd_n, &iter); 596 search_result_remove_item(sd, mfd, &iter);
595 return; 597 return;
596 } 598 }
597 599
598 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); 600 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
599 } 601 }
612 work = slist; 614 work = slist;
613 while (work) 615 while (work)
614 { 616 {
615 GtkTreePath *tpath = work->data; 617 GtkTreePath *tpath = work->data;
616 GtkTreeIter iter; 618 GtkTreeIter iter;
617 FileData *fd; 619 MatchFileData *mfd;
618 620
619 gtk_tree_model_get_iter(store, &iter, tpath); 621 gtk_tree_model_get_iter(store, &iter, tpath);
620 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd, -1); 622 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1);
621 flist = g_list_prepend(flist, fd); 623 flist = g_list_prepend(flist, mfd->fd);
622 work = work->next; 624 work = work->next;
623 } 625 }
624 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); 626 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL);
625 g_list_free(slist); 627 g_list_free(slist);
626 628
640 static void search_result_edit_selected(SearchData *sd, gint n) 642 static void search_result_edit_selected(SearchData *sd, gint n)
641 { 643 {
642 GList *list; 644 GList *list;
643 645
644 list = search_result_selection_list(sd); 646 list = search_result_selection_list(sd);
645 start_editor_from_path_list(n, list); 647 start_editor_from_filelist(n, list);
646 path_list_free(list); 648 filelist_free(list);
647 } 649 }
648 650
649 static void search_result_collection_from_selection(SearchData *sd) 651 static void search_result_collection_from_selection(SearchData *sd)
650 { 652 {
651 CollectWindow *w; 653 CollectWindow *w;
652 GList *list; 654 GList *list;
653 655
654 list = search_result_selection_list(sd); 656 list = search_result_selection_list(sd);
655 w = collection_window_new(NULL); 657 w = collection_window_new(NULL);
656 collection_table_add_path_list(w->table, list); 658 collection_table_add_filelist(w->table, list);
657 path_list_free(list); 659 filelist_free(list);
658 } 660 }
659 661
660 static gint search_result_update_idle_cb(gpointer data) 662 static gint search_result_update_idle_cb(gpointer data)
661 { 663 {
662 SearchData *sd = data; 664 SearchData *sd = data;
732 734
733 static void search_result_thumb_step(SearchData *sd) 735 static void search_result_thumb_step(SearchData *sd)
734 { 736 {
735 GtkTreeModel *store; 737 GtkTreeModel *store;
736 GtkTreeIter iter; 738 GtkTreeIter iter;
737 FileData *fd = NULL; 739 MatchFileData *mfd = NULL;
738 gint valid; 740 gint valid;
739 gint row = 0; 741 gint row = 0;
740 gint length = 0; 742 gint length = 0;
741 743
742 if (!sd->thumb_enable) return; 744 if (!sd->thumb_enable) return;
743 745
744 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); 746 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view));
745 747
746 valid = gtk_tree_model_get_iter_first(store, &iter); 748 valid = gtk_tree_model_get_iter_first(store, &iter);
747 while (!fd && valid) 749 while (!mfd && valid)
748 { 750 {
749 GdkPixbuf *pixbuf; 751 GdkPixbuf *pixbuf;
750 752
751 length++; 753 length++;
752 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd, SEARCH_COLUMN_THUMB, &pixbuf, -1); 754 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, SEARCH_COLUMN_THUMB, &pixbuf, -1);
753 if (pixbuf || fd->pixbuf) 755 if (pixbuf || mfd->fd->pixbuf)
754 { 756 {
755 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, SEARCH_COLUMN_THUMB, fd->pixbuf, -1); 757 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, SEARCH_COLUMN_THUMB, mfd->fd->pixbuf, -1);
756 row++; 758 row++;
757 fd = NULL; 759 mfd = NULL;
758 } 760 }
759 valid = gtk_tree_model_iter_next(store, &iter); 761 valid = gtk_tree_model_iter_next(store, &iter);
760 } 762 }
761 if (valid) 763 if (valid)
762 { 764 {
763 while (gtk_tree_model_iter_next(store, &iter)) length++; 765 while (gtk_tree_model_iter_next(store, &iter)) length++;
764 } 766 }
765 767
766 if (!fd) 768 if (!mfd)
767 { 769 {
768 sd->thumb_fd = NULL; 770 sd->thumb_fd = NULL;
769 thumb_loader_free(sd->thumb_loader); 771 thumb_loader_free(sd->thumb_loader);
770 sd->thumb_loader = NULL; 772 sd->thumb_loader = NULL;
771 773
773 return; 775 return;
774 } 776 }
775 777
776 search_progress_update(sd, FALSE, (gdouble)row/length); 778 search_progress_update(sd, FALSE, (gdouble)row/length);
777 779
778 sd->thumb_fd = fd; 780 sd->thumb_fd = mfd->fd;
779 thumb_loader_free(sd->thumb_loader); 781 thumb_loader_free(sd->thumb_loader);
780 sd->thumb_loader = thumb_loader_new(thumb_max_width, thumb_max_height); 782 sd->thumb_loader = thumb_loader_new(thumb_max_width, thumb_max_height);
781 783
782 thumb_loader_set_callbacks(sd->thumb_loader, 784 thumb_loader_set_callbacks(sd->thumb_loader,
783 search_result_thumb_done_cb, 785 search_result_thumb_done_cb,
784 search_result_thumb_done_cb, 786 search_result_thumb_done_cb,
785 NULL, 787 NULL,
786 sd); 788 sd);
787 if (!thumb_loader_start(sd->thumb_loader, fd->path)) 789 if (!thumb_loader_start(sd->thumb_loader, mfd->fd->path))
788 { 790 {
789 search_result_thumb_do(sd); 791 search_result_thumb_do(sd);
790 search_result_thumb_step(sd); 792 search_result_thumb_step(sd);
791 } 793 }
792 } 794 }
848 850
849 static void sr_menu_view_cb(GtkWidget *widget, gpointer data) 851 static void sr_menu_view_cb(GtkWidget *widget, gpointer data)
850 { 852 {
851 SearchData *sd = data; 853 SearchData *sd = data;
852 854
853 if (sd->click_fd) layout_image_set_path(NULL, sd->click_fd->path); 855 if (sd->click_fd) layout_image_set_fd(NULL, sd->click_fd);
854 } 856 }
855 857
856 static void sr_menu_viewnew_cb(GtkWidget *widget, gpointer data) 858 static void sr_menu_viewnew_cb(GtkWidget *widget, gpointer data)
857 { 859 {
858 SearchData *sd = data; 860 SearchData *sd = data;
859 GList *list; 861 GList *list;
860 862
861 list = search_result_selection_list(sd); 863 list = search_result_selection_list(sd);
862 view_window_new_from_list(list); 864 view_window_new_from_list(list);
863 path_list_free(list); 865 filelist_free(list);
864 } 866 }
865 867
866 static void sr_menu_select_all_cb(GtkWidget *widget, gpointer data) 868 static void sr_menu_select_all_cb(GtkWidget *widget, gpointer data)
867 { 869 {
868 SearchData *sd = data; 870 SearchData *sd = data;
908 } 910 }
909 911
910 static void sr_menu_print_cb(GtkWidget *widget, gpointer data) 912 static void sr_menu_print_cb(GtkWidget *widget, gpointer data)
911 { 913 {
912 SearchData *sd = data; 914 SearchData *sd = data;
913 const gchar *path; 915 FileData *fd;
914 916
915 path = (sd->click_fd) ? sd->click_fd->path : NULL; 917 print_window_new(sd->click_fd, search_result_selection_list(sd),
916 918 search_result_get_filelist(sd), sd->window);
917 print_window_new(path, search_result_selection_list(sd),
918 search_result_get_path_list(sd), sd->window);
919 } 919 }
920 920
921 static void sr_menu_copy_cb(GtkWidget *widget, gpointer data) 921 static void sr_menu_copy_cb(GtkWidget *widget, gpointer data)
922 { 922 {
923 SearchData *sd = data; 923 SearchData *sd = data;
1030 { 1030 {
1031 SearchData *sd = data; 1031 SearchData *sd = data;
1032 GtkTreeModel *store; 1032 GtkTreeModel *store;
1033 GtkTreePath *tpath; 1033 GtkTreePath *tpath;
1034 GtkTreeIter iter; 1034 GtkTreeIter iter;
1035 FileData *fd = NULL; 1035 MatchFileData *mfd = NULL;
1036 1036
1037 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); 1037 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1038 1038
1039 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, 1039 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
1040 &tpath, NULL, NULL, NULL)) 1040 &tpath, NULL, NULL, NULL))
1041 { 1041 {
1042 gtk_tree_model_get_iter(store, &iter, tpath); 1042 gtk_tree_model_get_iter(store, &iter, tpath);
1043 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd, -1); 1043 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1);
1044 gtk_tree_path_free(tpath); 1044 gtk_tree_path_free(tpath);
1045 } 1045 }
1046 1046
1047 sd->click_fd = fd; 1047 sd->click_fd = mfd ? mfd->fd : NULL;
1048 1048
1049 if (bevent->button == 3) 1049 if (bevent->button == 3)
1050 { 1050 {
1051 GtkWidget *menu; 1051 GtkWidget *menu;
1052 1052
1053 menu = search_result_menu(sd, (fd != NULL), (search_result_count(sd, NULL) == 0)); 1053 menu = search_result_menu(sd, (mfd != NULL), (search_result_count(sd, NULL) == 0));
1054 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); 1054 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
1055 } 1055 }
1056 1056
1057 if (!fd) return FALSE; 1057 if (!mfd) return FALSE;
1058 1058
1059 if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS) 1059 if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS)
1060 { 1060 {
1061 layout_image_set_path(NULL, fd->path); 1061 layout_image_set_fd(NULL, mfd->fd);
1062 } 1062 }
1063 1063
1064 if (bevent->button == 2) return TRUE; 1064 if (bevent->button == 2) return TRUE;
1065 1065
1066 if (bevent->button == 3) 1066 if (bevent->button == 3)
1067 { 1067 {
1068 if (!search_result_row_selected(sd, fd)) 1068 if (!search_result_row_selected(sd, mfd->fd))
1069 { 1069 {
1070 GtkTreeSelection *selection; 1070 GtkTreeSelection *selection;
1071 1071
1072 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); 1072 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1073 gtk_tree_selection_unselect_all(selection); 1073 gtk_tree_selection_unselect_all(selection);
1081 } 1081 }
1082 1082
1083 if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS && 1083 if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS &&
1084 !(bevent->state & GDK_SHIFT_MASK ) && 1084 !(bevent->state & GDK_SHIFT_MASK ) &&
1085 !(bevent->state & GDK_CONTROL_MASK ) && 1085 !(bevent->state & GDK_CONTROL_MASK ) &&
1086 search_result_row_selected(sd, fd)) 1086 search_result_row_selected(sd, mfd->fd))
1087 { 1087 {
1088 /* this selection handled on release_cb */ 1088 /* this selection handled on release_cb */
1089 gtk_widget_grab_focus(widget); 1089 gtk_widget_grab_focus(widget);
1090 return TRUE; 1090 return TRUE;
1091 } 1091 }
1098 SearchData *sd = data; 1098 SearchData *sd = data;
1099 GtkTreeModel *store; 1099 GtkTreeModel *store;
1100 GtkTreePath *tpath; 1100 GtkTreePath *tpath;
1101 GtkTreeIter iter; 1101 GtkTreeIter iter;
1102 1102
1103 FileData *fd = NULL; 1103 MatchFileData *mfd = NULL;
1104 1104
1105 if (bevent->button != 1 && bevent->button != 2) return TRUE; 1105 if (bevent->button != 1 && bevent->button != 2) return TRUE;
1106 1106
1107 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); 1107 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1108 1108
1109 if ((bevent->x != 0 || bevent->y != 0) && 1109 if ((bevent->x != 0 || bevent->y != 0) &&
1110 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, 1110 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
1111 &tpath, NULL, NULL, NULL)) 1111 &tpath, NULL, NULL, NULL))
1112 { 1112 {
1113 gtk_tree_model_get_iter(store, &iter, tpath); 1113 gtk_tree_model_get_iter(store, &iter, tpath);
1114 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd, -1); 1114 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1);
1115 gtk_tree_path_free(tpath); 1115 gtk_tree_path_free(tpath);
1116 } 1116 }
1117 1117
1118 if (bevent->button == 2) 1118 if (bevent->button == 2)
1119 { 1119 {
1120 if (fd && sd->click_fd == fd) 1120 if (mfd && sd->click_fd == mfd->fd)
1121 { 1121 {
1122 GtkTreeSelection *selection; 1122 GtkTreeSelection *selection;
1123 1123
1124 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); 1124 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1125 if (search_result_row_selected(sd, fd)) 1125 if (search_result_row_selected(sd, mfd->fd))
1126 { 1126 {
1127 gtk_tree_selection_unselect_iter(selection, &iter); 1127 gtk_tree_selection_unselect_iter(selection, &iter);
1128 } 1128 }
1129 else 1129 else
1130 { 1130 {
1132 } 1132 }
1133 } 1133 }
1134 return TRUE; 1134 return TRUE;
1135 } 1135 }
1136 1136
1137 if (fd && sd->click_fd == fd && 1137 if (mfd && sd->click_fd == mfd->fd &&
1138 !(bevent->state & GDK_SHIFT_MASK ) && 1138 !(bevent->state & GDK_SHIFT_MASK ) &&
1139 !(bevent->state & GDK_CONTROL_MASK ) && 1139 !(bevent->state & GDK_CONTROL_MASK ) &&
1140 search_result_row_selected(sd, fd)) 1140 search_result_row_selected(sd, mfd->fd))
1141 { 1141 {
1142 GtkTreeSelection *selection; 1142 GtkTreeSelection *selection;
1143 1143
1144 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); 1144 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1145 gtk_tree_selection_unselect_all(selection); 1145 gtk_tree_selection_unselect_all(selection);
1160 SearchData *sd = data; 1160 SearchData *sd = data;
1161 gint stop_signal = FALSE; 1161 gint stop_signal = FALSE;
1162 GtkTreeModel *store; 1162 GtkTreeModel *store;
1163 GtkTreeSelection *selection; 1163 GtkTreeSelection *selection;
1164 GList *slist; 1164 GList *slist;
1165 FileData *fd = NULL; 1165 MatchFileData *mfd = NULL;
1166 1166
1167 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); 1167 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view));
1168 slist = gtk_tree_selection_get_selected_rows(selection, &store); 1168 slist = gtk_tree_selection_get_selected_rows(selection, &store);
1169 if (slist) 1169 if (slist)
1170 { 1170 {
1175 last = g_list_last(slist); 1175 last = g_list_last(slist);
1176 tpath = last->data; 1176 tpath = last->data;
1177 1177
1178 /* last is newest selected file */ 1178 /* last is newest selected file */
1179 gtk_tree_model_get_iter(store, &iter, tpath); 1179 gtk_tree_model_get_iter(store, &iter, tpath);
1180 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &fd, -1); 1180 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1);
1181 } 1181 }
1182 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); 1182 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL);
1183 g_list_free(slist); 1183 g_list_free(slist);
1184 1184
1185 if (event->state & GDK_CONTROL_MASK) 1185 if (event->state & GDK_CONTROL_MASK)
1261 { 1261 {
1262 stop_signal = TRUE; 1262 stop_signal = TRUE;
1263 switch (event->keyval) 1263 switch (event->keyval)
1264 { 1264 {
1265 case GDK_Return: case GDK_KP_Enter: 1265 case GDK_Return: case GDK_KP_Enter:
1266 if (fd) layout_image_set_path(NULL, fd->path); 1266 if (mfd) layout_image_set_fd(NULL, mfd->fd);
1267 break; 1267 break;
1268 case 'V': case 'v': 1268 case 'V': case 'v':
1269 { 1269 {
1270 GList *list; 1270 GList *list;
1271 1271
1272 list = search_result_selection_list(sd); 1272 list = search_result_selection_list(sd);
1273 view_window_new_from_list(list); 1273 view_window_new_from_list(list);
1274 path_list_free(list); 1274 filelist_free(list);
1275 } 1275 }
1276 break; 1276 break;
1277 case GDK_Delete: case GDK_KP_Delete: 1277 case GDK_Delete: case GDK_KP_Delete:
1278 search_result_remove_selection(sd); 1278 search_result_remove_selection(sd);
1279 break; 1279 break;
1283 case GDK_Menu: 1283 case GDK_Menu:
1284 case GDK_F10: 1284 case GDK_F10:
1285 { 1285 {
1286 GtkWidget *menu; 1286 GtkWidget *menu;
1287 1287
1288 sd->click_fd = fd; 1288 sd->click_fd = mfd->fd;
1289 menu = search_result_menu(sd, (fd != NULL), (search_result_count(sd, NULL) > 0)); 1289 menu = search_result_menu(sd, (mfd != NULL), (search_result_count(sd, NULL) > 0));
1290 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, 1290 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
1291 search_result_menu_pos_cb, sd, 0, GDK_CURRENT_TIME); 1291 search_result_menu_pos_cb, sd, 0, GDK_CURRENT_TIME);
1292 } 1292 }
1293 break; 1293 break;
1294 default: 1294 default:
1351 { 1351 {
1352 case TARGET_URI_LIST: 1352 case TARGET_URI_LIST:
1353 case TARGET_TEXT_PLAIN: 1353 case TARGET_TEXT_PLAIN:
1354 list = search_result_selection_list(sd); 1354 list = search_result_selection_list(sd);
1355 if (!list) return; 1355 if (!list) return;
1356 uri_text = uri_text_from_list(list, &length, (info == TARGET_TEXT_PLAIN)); 1356 uri_text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN));
1357 path_list_free(list); 1357 filelist_free(list);
1358 break; 1358 break;
1359 default: 1359 default:
1360 uri_text = NULL; 1360 uri_text = NULL;
1361 break; 1361 break;
1362 } 1362 }
1500 cache_sim_data_set_similarity(cd, sim); 1500 cache_sim_data_set_similarity(cd, sim);
1501 image_sim_free(sim); 1501 image_sim_free(sim);
1502 } 1502 }
1503 1503
1504 if (enable_thumb_caching && 1504 if (enable_thumb_caching &&
1505 sd->img_loader && sd->img_loader->path) 1505 sd->img_loader && sd->img_loader->fd)
1506 { 1506 {
1507 gchar *base; 1507 gchar *base;
1508 const gchar *path; 1508 const gchar *path;
1509 mode_t mode = 0755; 1509 mode_t mode = 0755;
1510 1510
1511 path = sd->img_loader->path; 1511 path = sd->img_loader->fd->path;
1512 base = cache_get_location(CACHE_TYPE_SIM, path, FALSE, &mode); 1512 base = cache_get_location(CACHE_TYPE_SIM, path, FALSE, &mode);
1513 if (cache_ensure_dir_exists(base, mode)) 1513 if (cache_ensure_dir_exists(base, mode))
1514 { 1514 {
1515 g_free(cd->path); 1515 g_free(cd->path);
1516 cd->path = cache_get_location(CACHE_TYPE_SIM, path, TRUE, NULL); 1516 cd->path = cache_get_location(CACHE_TYPE_SIM, path, TRUE, NULL);
1517 if (cache_sim_data_save(cd)) 1517 if (cache_sim_data_save(cd))
1518 { 1518 {
1519 filetime_set(cd->path, filetime(sd->img_loader->path)); 1519 filetime_set(cd->path, filetime(sd->img_loader->fd->path));
1520 } 1520 }
1521 } 1521 }
1522 g_free(base); 1522 g_free(base);
1523 } 1523 }
1524 } 1524 }
1564 if (new_data) 1564 if (new_data)
1565 { 1565 {
1566 if ((sd->match_dimensions_enable && !sd->img_cd->dimensions) || 1566 if ((sd->match_dimensions_enable && !sd->img_cd->dimensions) ||
1567 (sd->match_similarity_enable && !sd->img_cd->similarity)) 1567 (sd->match_similarity_enable && !sd->img_cd->similarity))
1568 { 1568 {
1569 sd->img_loader = image_loader_new(fd->path); 1569 sd->img_loader = image_loader_new(fd);
1570 image_loader_set_error_func(sd->img_loader, search_file_load_done_cb, sd); 1570 image_loader_set_error_func(sd->img_loader, search_file_load_done_cb, sd);
1571 if (image_loader_start(sd->img_loader, search_file_load_done_cb, sd)) 1571 if (image_loader_start(sd->img_loader, search_file_load_done_cb, sd))
1572 { 1572 {
1573 return TRUE; 1573 return TRUE;
1574 } 1574 }
1770 GList *list; 1770 GList *list;
1771 1771
1772 tested = TRUE; 1772 tested = TRUE;
1773 match = FALSE; 1773 match = FALSE;
1774 1774
1775 if (comment_cache_read(fd->path, &list, NULL)) 1775 if (comment_cache_read(fd, &list, NULL))
1776 { 1776 {
1777 GList *needle; 1777 GList *needle;
1778 GList *haystack; 1778 GList *haystack;
1779 1779
1780 if (sd->match_keywords == SEARCH_MATCH_ALL) 1780 if (sd->match_keywords == SEARCH_MATCH_ALL)
1833 needle = needle->next; 1833 needle = needle->next;
1834 } 1834 }
1835 1835
1836 match = !found; 1836 match = !found;
1837 } 1837 }
1838 path_list_free(list); 1838 string_list_free(list);
1839 } 1839 }
1840 else 1840 else
1841 { 1841 {
1842 match = (sd->match_keywords == SEARCH_MATCH_NONE); 1842 match = (sd->match_keywords == SEARCH_MATCH_NONE);
1843 } 1843 }
1860 if (tested && match) 1860 if (tested && match)
1861 { 1861 {
1862 MatchFileData *mfd; 1862 MatchFileData *mfd;
1863 1863
1864 mfd = g_new(MatchFileData, 1); 1864 mfd = g_new(MatchFileData, 1);
1865 memcpy(mfd, fd, sizeof(FileData)); 1865 mfd->fd = fd;
1866 g_free(fd);
1867 1866
1868 mfd->width = width; 1867 mfd->width = width;
1869 mfd->height = height; 1868 mfd->height = height;
1870 mfd->rank = sim; 1869 mfd->rank = sim;
1871 1870
1874 sd->search_count++; 1873 sd->search_count++;
1875 search_progress_update(sd, TRUE, -1.0); 1874 search_progress_update(sd, TRUE, -1.0);
1876 } 1875 }
1877 else 1876 else
1878 { 1877 {
1879 file_data_free(fd); 1878 file_data_unref(fd);
1880 sd->search_buffer_count += SEARCH_BUFFER_MATCH_MISS; 1879 sd->search_buffer_count += SEARCH_BUFFER_MATCH_MISS;
1881 } 1880 }
1882 1881
1883 return FALSE; 1882 return FALSE;
1884 } 1883 }
1954 1953
1955 meta_path = cache_find_location(CACHE_TYPE_METADATA, fdp->path); 1954 meta_path = cache_find_location(CACHE_TYPE_METADATA, fdp->path);
1956 if (!meta_path) 1955 if (!meta_path)
1957 { 1956 {
1958 list = g_list_delete_link(list, link); 1957 list = g_list_delete_link(list, link);
1959 file_data_free(fdp); 1958 file_data_unref(fdp);
1960 } 1959 }
1961 g_free(meta_path); 1960 g_free(meta_path);
1962 } 1961 }
1963 } 1962 }
1964 } 1963 }
1981 } 1980 }
1982 else 1981 else
1983 { 1982 {
1984 sd->search_folder_list = g_list_remove(sd->search_folder_list, fd); 1983 sd->search_folder_list = g_list_remove(sd->search_folder_list, fd);
1985 sd->search_done_list = g_list_remove(sd->search_done_list, fd); 1984 sd->search_done_list = g_list_remove(sd->search_done_list, fd);
1986 file_data_free(fd); 1985 file_data_unref(fd);
1987 } 1986 }
1988 1987
1989 return TRUE; 1988 return TRUE;
1990 } 1989 }
1991 1990
2041 if (!sd->search_similarity_cd) 2040 if (!sd->search_similarity_cd)
2042 { 2041 {
2043 sd->search_similarity_cd = cache_sim_data_new(); 2042 sd->search_similarity_cd = cache_sim_data_new();
2044 } 2043 }
2045 2044
2046 sd->img_loader = image_loader_new(sd->search_similarity_path); 2045 sd->img_loader = image_loader_new(file_data_new_simple(sd->search_similarity_path));
2047 image_loader_set_error_func(sd->img_loader, search_similarity_load_done_cb, sd); 2046 image_loader_set_error_func(sd->img_loader, search_similarity_load_done_cb, sd);
2048 if (image_loader_start(sd->img_loader, search_similarity_load_done_cb, sd)) 2047 if (image_loader_start(sd->img_loader, search_similarity_load_done_cb, sd))
2049 { 2048 {
2050 return; 2049 return;
2051 } 2050 }
2087 return; 2086 return;
2088 } 2087 }
2089 tab_completion_append_to_history(sd->entry_similarity, sd->search_similarity_path); 2088 tab_completion_append_to_history(sd->entry_similarity, sd->search_similarity_path);
2090 } 2089 }
2091 2090
2092 path_list_free(sd->search_keyword_list); 2091 string_list_free(sd->search_keyword_list);
2093 sd->search_keyword_list = keyword_list_pull(sd->entry_keywords); 2092 sd->search_keyword_list = keyword_list_pull(sd->entry_keywords);
2094 2093
2095 date_selection_get(sd->date_sel, &sd->search_date_d, &sd->search_date_m, &sd->search_date_y); 2094 date_selection_get(sd->date_sel, &sd->search_date_d, &sd->search_date_m, &sd->search_date_y);
2096 date_selection_get(sd->date_sel_end, &sd->search_date_end_d, &sd->search_date_end_m, &sd->search_date_end_y); 2095 date_selection_get(sd->date_sel_end, &sd->search_date_end_d, &sd->search_date_end_m, &sd->search_date_end_y);
2097 2096
2192 } 2191 }
2193 2192
2194 static gint search_result_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data) 2193 static gint search_result_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
2195 { 2194 {
2196 gint n = GPOINTER_TO_INT(data); 2195 gint n = GPOINTER_TO_INT(data);
2197 FileData *fda; 2196 MatchFileData *fda;
2198 FileData *fdb; 2197 MatchFileData *fdb;
2199 2198
2200 gtk_tree_model_get(model, a, SEARCH_COLUMN_POINTER, &fda, -1); 2199 gtk_tree_model_get(model, a, SEARCH_COLUMN_POINTER, &fda, -1);
2201 gtk_tree_model_get(model, b, SEARCH_COLUMN_POINTER, &fdb, -1); 2200 gtk_tree_model_get(model, b, SEARCH_COLUMN_POINTER, &fdb, -1);
2202 2201
2203 if (!fda || !fdb) return 0; 2202 if (!fda || !fdb) return 0;
2204 2203
2205 switch (n) 2204 switch (n)
2206 { 2205 {
2207 case SEARCH_COLUMN_RANK: 2206 case SEARCH_COLUMN_RANK:
2208 if (((MatchFileData *)fda)->rank > ((MatchFileData *)fdb)->rank) return 1; 2207 if (((MatchFileData *)fda)->rank > (fdb)->rank) return 1;
2209 if (((MatchFileData *)fda)->rank < ((MatchFileData *)fdb)->rank) return -1; 2208 if (((MatchFileData *)fda)->rank < (fdb)->rank) return -1;
2210 return 0; 2209 return 0;
2211 break; 2210 break;
2212 case SEARCH_COLUMN_NAME: 2211 case SEARCH_COLUMN_NAME:
2213 return CASE_SORT(fda->name, fdb->name); 2212 return CASE_SORT(fda->fd->name, fdb->fd->name);
2214 break; 2213 break;
2215 case SEARCH_COLUMN_SIZE: 2214 case SEARCH_COLUMN_SIZE:
2216 if (fda->size > fdb->size) return 1; 2215 if (fda->fd->size > fdb->fd->size) return 1;
2217 if (fda->size < fdb->size) return -1; 2216 if (fda->fd->size < fdb->fd->size) return -1;
2218 return 0; 2217 return 0;
2219 break; 2218 break;
2220 case SEARCH_COLUMN_DATE: 2219 case SEARCH_COLUMN_DATE:
2221 if (fda->date > fdb->date) return 1; 2220 if (fda->fd->date > fdb->fd->date) return 1;
2222 if (fda->date < fdb->date) return -1; 2221 if (fda->fd->date < fdb->fd->date) return -1;
2223 return 0; 2222 return 0;
2224 break; 2223 break;
2225 case SEARCH_COLUMN_DIMENSIONS: 2224 case SEARCH_COLUMN_DIMENSIONS:
2226 return sort_matchdata_dimensions((MatchFileData *)fda, (MatchFileData *)fdb); 2225 return sort_matchdata_dimensions(fda, fdb);
2227 break; 2226 break;
2228 case SEARCH_COLUMN_PATH: 2227 case SEARCH_COLUMN_PATH:
2229 return CASE_SORT(fda->path, fdb->path); 2228 return CASE_SORT(fda->fd->path, fdb->fd->path);
2230 break; 2229 break;
2231 default: 2230 default:
2232 break; 2231 break;
2233 } 2232 }
2234 2233
2498 search_result_clear(sd); 2497 search_result_clear(sd);
2499 2498
2500 g_free(sd->search_path); 2499 g_free(sd->search_path);
2501 g_free(sd->search_name); 2500 g_free(sd->search_name);
2502 g_free(sd->search_similarity_path); 2501 g_free(sd->search_similarity_path);
2503 path_list_free(sd->search_keyword_list); 2502 string_list_free(sd->search_keyword_list);
2504 2503
2505 g_free(sd); 2504 g_free(sd);
2506 } 2505 }
2507 2506
2508 void search_new(const gchar *path, const gchar *example_file) 2507 void search_new(const gchar *path, const gchar *example_file)
2799 *------------------------------------------------------------------- 2798 *-------------------------------------------------------------------
2800 * maintenance (move, delete, etc.) 2799 * maintenance (move, delete, etc.)
2801 *------------------------------------------------------------------- 2800 *-------------------------------------------------------------------
2802 */ 2801 */
2803 2802
2804 static void search_result_change_path(SearchData *sd, const gchar *path, const gchar *newpath) 2803 static void search_result_change_path(SearchData *sd, FileData *fd)
2805 { 2804 {
2806 GtkTreeModel *store; 2805 GtkTreeModel *store;
2807 GtkTreeIter iter; 2806 GtkTreeIter iter;
2808 gint valid; 2807 gint valid;
2809 2808
2810 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); 2809 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view));
2811 valid = gtk_tree_model_get_iter_first(store, &iter); 2810 valid = gtk_tree_model_get_iter_first(store, &iter);
2812 while (valid) 2811 while (valid)
2813 { 2812 {
2814 GtkTreeIter current; 2813 GtkTreeIter current;
2815 FileData *fd; 2814 MatchFileData *mfd;
2816 2815
2817 current = iter; 2816 current = iter;
2818 valid = gtk_tree_model_iter_next(store, &iter); 2817 valid = gtk_tree_model_iter_next(store, &iter);
2819 2818
2820 gtk_tree_model_get(store, &current, SEARCH_COLUMN_POINTER, &fd, -1); 2819 gtk_tree_model_get(store, &current, SEARCH_COLUMN_POINTER, &mfd, -1);
2821 if (strcmp(fd->path, path) == 0) 2820 if (mfd->fd == fd)
2822 { 2821 {
2823 if (newpath) 2822 if (fd->change && fd->change->dest)
2824 { 2823 {
2825 g_free(fd->path);
2826 fd->path = g_strdup(newpath);
2827 fd->name = filename_from_path(fd->path);
2828
2829 gtk_list_store_set(GTK_LIST_STORE(store), &current, 2824 gtk_list_store_set(GTK_LIST_STORE(store), &current,
2830 SEARCH_COLUMN_NAME, fd->name, 2825 SEARCH_COLUMN_NAME, mfd->fd->name,
2831 SEARCH_COLUMN_PATH, fd->path, -1); 2826 SEARCH_COLUMN_PATH, mfd->fd->path, -1);
2832 } 2827 }
2833 else 2828 else
2834 { 2829 {
2835 search_result_remove_item(sd, fd, &current); 2830 search_result_remove_item(sd, mfd, &current);
2836 } 2831 }
2837 } 2832 }
2838 } 2833 }
2839 } 2834 }
2840 2835
2841 void search_maint_renamed(const gchar *source, const gchar *dest) 2836 void search_maint_renamed(FileData *fd)
2842 { 2837 {
2843 GList *work; 2838 GList *work;
2844 2839
2845 work = search_window_list; 2840 work = search_window_list;
2846 while (work) 2841 while (work)
2847 { 2842 {
2848 SearchData *sd = work->data; 2843 SearchData *sd = work->data;
2849 work = work->next; 2844 work = work->next;
2850 2845
2851 search_result_change_path(sd, source, dest); 2846 search_result_change_path(sd, fd);
2852 } 2847 }
2853 } 2848 }
2854 2849
2855 void search_maint_removed(const gchar *path) 2850 void search_maint_removed(FileData *fd)
2856 { 2851 {
2857 search_maint_renamed(path, NULL); 2852 search_maint_renamed(fd);
2858 } 2853 }
2859 2854