Mercurial > geeqie.yaz
comparison src/search.c @ 1057:c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
author | nadvornik |
---|---|
date | Tue, 07 Oct 2008 18:37:32 +0000 |
parents | 1646720364cf |
children | 577d726e32f0 |
comparison
equal
deleted
inserted
replaced
1056:5a5784eb61df | 1057:c28eb027dd5b |
---|---|
124 | 124 |
125 GtkWidget *check_keywords; | 125 GtkWidget *check_keywords; |
126 GtkWidget *menu_keywords; | 126 GtkWidget *menu_keywords; |
127 GtkWidget *entry_keywords; | 127 GtkWidget *entry_keywords; |
128 | 128 |
129 GtkWidget *check_comment; | |
130 GtkWidget *menu_comment; | |
131 GtkWidget *entry_comment; | |
132 | |
129 FileData *search_dir_fd; | 133 FileData *search_dir_fd; |
130 gint search_path_recurse; | 134 gint search_path_recurse; |
131 gchar *search_name; | 135 gchar *search_name; |
132 gint search_name_match_case; | 136 gint search_name_match_case; |
133 gint64 search_size; | 137 gint64 search_size; |
144 gint search_height_end; | 148 gint search_height_end; |
145 gint search_similarity; | 149 gint search_similarity; |
146 gchar *search_similarity_path; | 150 gchar *search_similarity_path; |
147 CacheData *search_similarity_cd; | 151 CacheData *search_similarity_cd; |
148 GList *search_keyword_list; | 152 GList *search_keyword_list; |
153 gchar *search_comment; | |
154 gint search_comment_match_case; | |
149 | 155 |
150 MatchType search_type; | 156 MatchType search_type; |
151 | 157 |
152 MatchType match_name; | 158 MatchType match_name; |
153 MatchType match_size; | 159 MatchType match_size; |
154 MatchType match_date; | 160 MatchType match_date; |
155 MatchType match_dimensions; | 161 MatchType match_dimensions; |
156 MatchType match_keywords; | 162 MatchType match_keywords; |
163 MatchType match_comment; | |
157 | 164 |
158 gboolean match_name_enable; | 165 gboolean match_name_enable; |
159 gboolean match_size_enable; | 166 gboolean match_size_enable; |
160 gboolean match_date_enable; | 167 gboolean match_date_enable; |
161 gboolean match_dimensions_enable; | 168 gboolean match_dimensions_enable; |
162 gboolean match_similarity_enable; | 169 gboolean match_similarity_enable; |
163 gboolean match_keywords_enable; | 170 gboolean match_keywords_enable; |
171 gboolean match_comment_enable; | |
164 | 172 |
165 GList *search_folder_list; | 173 GList *search_folder_list; |
166 GList *search_done_list; | 174 GList *search_done_list; |
167 GList *search_file_list; | 175 GList *search_file_list; |
168 GList *search_buffer_list; | 176 GList *search_buffer_list; |
227 | 235 |
228 static const MatchList text_search_menu_keyword[] = { | 236 static const MatchList text_search_menu_keyword[] = { |
229 { N_("match all"), SEARCH_MATCH_ALL }, | 237 { N_("match all"), SEARCH_MATCH_ALL }, |
230 { N_("match any"), SEARCH_MATCH_ANY }, | 238 { N_("match any"), SEARCH_MATCH_ANY }, |
231 { N_("exclude"), SEARCH_MATCH_NONE } | 239 { N_("exclude"), SEARCH_MATCH_NONE } |
240 }; | |
241 | |
242 static const MatchList text_search_menu_comment[] = { | |
243 { N_("contains"), SEARCH_MATCH_CONTAINS }, | |
244 { N_("miss"), SEARCH_MATCH_NONE } | |
232 }; | 245 }; |
233 | 246 |
234 static GList *search_window_list = NULL; | 247 static GList *search_window_list = NULL; |
235 | 248 |
236 | 249 |
1855 } | 1868 } |
1856 string_list_free(list); | 1869 string_list_free(list); |
1857 } | 1870 } |
1858 else | 1871 else |
1859 { | 1872 { |
1860 match = (sd->match_keywords == SEARCH_MATCH_NONE); | 1873 match = (sd->match_comment == SEARCH_MATCH_NONE); |
1874 } | |
1875 } | |
1876 | |
1877 if (match && sd->match_comment_enable && sd->search_comment && strlen(sd->search_comment)) | |
1878 { | |
1879 gchar *comment; | |
1880 | |
1881 tested = TRUE; | |
1882 match = FALSE; | |
1883 | |
1884 if (comment_read(fd, NULL, &comment)) | |
1885 { | |
1886 if (! sd->search_comment_match_case) | |
1887 { | |
1888 gchar *tmp = g_utf8_strdown(comment, -1); | |
1889 g_free(comment); | |
1890 comment = tmp; | |
1891 } | |
1892 | |
1893 if (sd->match_comment == SEARCH_MATCH_CONTAINS) | |
1894 { | |
1895 match = (strstr(comment, sd->search_comment) != NULL); | |
1896 } | |
1897 else if (sd->match_comment == SEARCH_MATCH_NONE) | |
1898 { | |
1899 match = (strstr(comment, sd->search_comment) == NULL); | |
1900 } | |
1901 g_free(comment); | |
1902 } | |
1903 else | |
1904 { | |
1905 match = (sd->match_comment == SEARCH_MATCH_NONE); | |
1861 } | 1906 } |
1862 } | 1907 } |
1863 | 1908 |
1864 if ((match || extra_only) && | 1909 if ((match || extra_only) && |
1865 (sd->match_dimensions_enable || sd->match_similarity_enable)) | 1910 (sd->match_dimensions_enable || sd->match_similarity_enable)) |
2033 gchar *tmp = g_utf8_strdown(sd->search_name, -1); | 2078 gchar *tmp = g_utf8_strdown(sd->search_name, -1); |
2034 g_free(sd->search_name); | 2079 g_free(sd->search_name); |
2035 sd->search_name = tmp; | 2080 sd->search_name = tmp; |
2036 } | 2081 } |
2037 | 2082 |
2083 if (!sd->search_comment_match_case) | |
2084 { | |
2085 /* convert to lowercase here, so that this is only done once per search */ | |
2086 gchar *tmp = g_utf8_strdown(sd->search_comment, -1); | |
2087 g_free(sd->search_comment); | |
2088 sd->search_comment = tmp; | |
2089 } | |
2090 | |
2038 sd->search_count = 0; | 2091 sd->search_count = 0; |
2039 sd->search_total = 0; | 2092 sd->search_total = 0; |
2040 | 2093 |
2041 gtk_widget_set_sensitive(sd->box_search, FALSE); | 2094 gtk_widget_set_sensitive(sd->box_search, FALSE); |
2042 spinner_set_interval(sd->spinner, SPINNER_SPEED); | 2095 spinner_set_interval(sd->spinner, SPINNER_SPEED); |
2094 } | 2147 } |
2095 | 2148 |
2096 if (sd->match_name_enable) history_combo_append_history(sd->entry_name, NULL); | 2149 if (sd->match_name_enable) history_combo_append_history(sd->entry_name, NULL); |
2097 g_free(sd->search_name); | 2150 g_free(sd->search_name); |
2098 sd->search_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_name))); | 2151 sd->search_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_name))); |
2152 | |
2153 /* XXX */ | |
2154 g_free(sd->search_comment); | |
2155 sd->search_comment = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_comment))); | |
2099 | 2156 |
2100 g_free(sd->search_similarity_path); | 2157 g_free(sd->search_similarity_path); |
2101 sd->search_similarity_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_similarity))); | 2158 sd->search_similarity_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_similarity))); |
2102 if (sd->match_similarity_enable) | 2159 if (sd->match_similarity_enable) |
2103 { | 2160 { |
2372 SearchData *sd = data; | 2429 SearchData *sd = data; |
2373 | 2430 |
2374 if (!menu_choice_get_match_type(combo, &sd->match_keywords)) return; | 2431 if (!menu_choice_get_match_type(combo, &sd->match_keywords)) return; |
2375 } | 2432 } |
2376 | 2433 |
2434 static void menu_choice_comment_cb(GtkWidget *combo, gpointer data) | |
2435 { | |
2436 SearchData *sd = data; | |
2437 | |
2438 if (!menu_choice_get_match_type(combo, &sd->match_comment)) return; | |
2439 } | |
2440 | |
2377 static void menu_choice_spin_cb(GtkAdjustment *adjustment, gpointer data) | 2441 static void menu_choice_spin_cb(GtkAdjustment *adjustment, gpointer data) |
2378 { | 2442 { |
2379 gint *value = data; | 2443 gint *value = data; |
2380 | 2444 |
2381 *value = (gint)gtk_adjustment_get_value(adjustment); | 2445 *value = (gint)gtk_adjustment_get_value(adjustment); |
2514 search_result_clear(sd); | 2578 search_result_clear(sd); |
2515 | 2579 |
2516 file_data_unref(sd->search_dir_fd); | 2580 file_data_unref(sd->search_dir_fd); |
2517 | 2581 |
2518 g_free(sd->search_name); | 2582 g_free(sd->search_name); |
2583 g_free(sd->search_comment); | |
2519 g_free(sd->search_similarity_path); | 2584 g_free(sd->search_similarity_path); |
2520 string_list_free(sd->search_keyword_list); | 2585 string_list_free(sd->search_keyword_list); |
2521 | 2586 |
2522 file_data_unregister_notify_func(search_notify_cb, sd); | 2587 file_data_unregister_notify_func(search_notify_cb, sd); |
2523 | 2588 |
2548 sd->search_height = 480; | 2613 sd->search_height = 480; |
2549 sd->search_width_end = 1024; | 2614 sd->search_width_end = 1024; |
2550 sd->search_height_end = 768; | 2615 sd->search_height_end = 768; |
2551 sd->search_name = NULL; | 2616 sd->search_name = NULL; |
2552 sd->search_name_match_case = FALSE; | 2617 sd->search_name_match_case = FALSE; |
2618 sd->search_comment = NULL; | |
2619 sd->search_comment_match_case = FALSE; | |
2553 | 2620 |
2554 sd->search_type = SEARCH_MATCH_NONE; | 2621 sd->search_type = SEARCH_MATCH_NONE; |
2555 | 2622 |
2556 sd->match_name = SEARCH_MATCH_CONTAINS; | 2623 sd->match_name = SEARCH_MATCH_CONTAINS; |
2557 sd->match_size = SEARCH_MATCH_EQUAL; | 2624 sd->match_size = SEARCH_MATCH_EQUAL; |
2558 sd->match_date = SEARCH_MATCH_EQUAL; | 2625 sd->match_date = SEARCH_MATCH_EQUAL; |
2559 sd->match_dimensions = SEARCH_MATCH_EQUAL; | 2626 sd->match_dimensions = SEARCH_MATCH_EQUAL; |
2560 sd->match_keywords = SEARCH_MATCH_ALL; | 2627 sd->match_keywords = SEARCH_MATCH_ALL; |
2628 sd->match_comment = SEARCH_MATCH_CONTAINS; | |
2561 | 2629 |
2562 sd->match_name_enable = TRUE; | 2630 sd->match_name_enable = TRUE; |
2563 sd->match_size_enable = FALSE; | 2631 sd->match_size_enable = FALSE; |
2564 sd->match_date_enable = FALSE; | 2632 sd->match_date_enable = FALSE; |
2565 sd->match_dimensions_enable = FALSE; | 2633 sd->match_dimensions_enable = FALSE; |
2566 sd->match_similarity_enable = FALSE; | 2634 sd->match_similarity_enable = FALSE; |
2567 sd->match_keywords_enable = FALSE; | 2635 sd->match_keywords_enable = FALSE; |
2636 sd->match_comment_enable = FALSE; | |
2568 | 2637 |
2569 sd->search_similarity = 95; | 2638 sd->search_similarity = 95; |
2570 sd->search_similarity_path = example_file ? g_strdup(example_file->path) : NULL; | 2639 sd->search_similarity_path = example_file ? g_strdup(example_file->path) : NULL; |
2571 sd->search_similarity_cd = NULL; | 2640 sd->search_similarity_cd = NULL; |
2572 | 2641 |
2618 gtk_box_pack_start(GTK_BOX(hbox2), combo, TRUE, TRUE, 0); | 2687 gtk_box_pack_start(GTK_BOX(hbox2), combo, TRUE, TRUE, 0); |
2619 gtk_widget_show(combo); | 2688 gtk_widget_show(combo); |
2620 sd->check_recurse = pref_checkbox_new_int(hbox2, _("Recurse"), | 2689 sd->check_recurse = pref_checkbox_new_int(hbox2, _("Recurse"), |
2621 sd->search_path_recurse, &sd->search_path_recurse); | 2690 sd->search_path_recurse, &sd->search_path_recurse); |
2622 | 2691 |
2692 /* Search for file name */ | |
2623 hbox = menu_choice(sd->box_search, &sd->check_name, &sd->menu_name, | 2693 hbox = menu_choice(sd->box_search, &sd->check_name, &sd->menu_name, |
2624 _("File name"), &sd->match_name_enable, | 2694 _("File name"), &sd->match_name_enable, |
2625 text_search_menu_name, sizeof(text_search_menu_name) / sizeof(MatchList), | 2695 text_search_menu_name, sizeof(text_search_menu_name) / sizeof(MatchList), |
2626 G_CALLBACK(menu_choice_name_cb), sd); | 2696 G_CALLBACK(menu_choice_name_cb), sd); |
2627 combo = history_combo_new(&sd->entry_name, "", "search_name", -1); | 2697 combo = history_combo_new(&sd->entry_name, "", "search_name", -1); |
2628 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); | 2698 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); |
2629 gtk_widget_show(combo); | 2699 gtk_widget_show(combo); |
2630 pref_checkbox_new_int(hbox, _("Match case"), | 2700 pref_checkbox_new_int(hbox, _("Match case"), |
2631 sd->search_name_match_case, &sd->search_name_match_case); | 2701 sd->search_name_match_case, &sd->search_name_match_case); |
2632 | 2702 |
2703 /* Search for file size */ | |
2633 hbox = menu_choice(sd->box_search, &sd->check_size, &sd->menu_size, | 2704 hbox = menu_choice(sd->box_search, &sd->check_size, &sd->menu_size, |
2634 _("File size is"), &sd->match_size_enable, | 2705 _("File size is"), &sd->match_size_enable, |
2635 text_search_menu_size, sizeof(text_search_menu_size) / sizeof(MatchList), | 2706 text_search_menu_size, sizeof(text_search_menu_size) / sizeof(MatchList), |
2636 G_CALLBACK(menu_choice_size_cb), sd); | 2707 G_CALLBACK(menu_choice_size_cb), sd); |
2637 sd->spin_size = menu_spin(hbox, 0, 1024*1024*1024, sd->search_size, | 2708 sd->spin_size = menu_spin(hbox, 0, 1024*1024*1024, sd->search_size, |
2640 gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); | 2711 gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); |
2641 pref_label_new(hbox2, _("and")); | 2712 pref_label_new(hbox2, _("and")); |
2642 sd->spin_size_end = menu_spin(hbox2, 0, 1024*1024*1024, sd->search_size_end, | 2713 sd->spin_size_end = menu_spin(hbox2, 0, 1024*1024*1024, sd->search_size_end, |
2643 G_CALLBACK(menu_choice_spin_cb), &sd->search_size_end); | 2714 G_CALLBACK(menu_choice_spin_cb), &sd->search_size_end); |
2644 | 2715 |
2716 /* Search for file date */ | |
2645 hbox = menu_choice(sd->box_search, &sd->check_date, &sd->menu_date, | 2717 hbox = menu_choice(sd->box_search, &sd->check_date, &sd->menu_date, |
2646 _("File date is"), &sd->match_date_enable, | 2718 _("File date is"), &sd->match_date_enable, |
2647 text_search_menu_date, sizeof(text_search_menu_date) / sizeof(MatchList), | 2719 text_search_menu_date, sizeof(text_search_menu_date) / sizeof(MatchList), |
2648 G_CALLBACK(menu_choice_date_cb), sd); | 2720 G_CALLBACK(menu_choice_date_cb), sd); |
2649 sd->date_sel = date_selection_new(); | 2721 sd->date_sel = date_selection_new(); |
2657 sd->date_sel_end = date_selection_new(); | 2729 sd->date_sel_end = date_selection_new(); |
2658 date_selection_time_set(sd->date_sel_end, time(NULL)); | 2730 date_selection_time_set(sd->date_sel_end, time(NULL)); |
2659 gtk_box_pack_start(GTK_BOX(hbox2), sd->date_sel_end, FALSE, FALSE, 0); | 2731 gtk_box_pack_start(GTK_BOX(hbox2), sd->date_sel_end, FALSE, FALSE, 0); |
2660 gtk_widget_show(sd->date_sel_end); | 2732 gtk_widget_show(sd->date_sel_end); |
2661 | 2733 |
2734 /* Search for image dimensions */ | |
2662 hbox = menu_choice(sd->box_search, &sd->check_dimensions, &sd->menu_dimensions, | 2735 hbox = menu_choice(sd->box_search, &sd->check_dimensions, &sd->menu_dimensions, |
2663 _("Image dimensions are"), &sd->match_dimensions_enable, | 2736 _("Image dimensions are"), &sd->match_dimensions_enable, |
2664 text_search_menu_size, sizeof(text_search_menu_size) / sizeof(MatchList), | 2737 text_search_menu_size, sizeof(text_search_menu_size) / sizeof(MatchList), |
2665 G_CALLBACK(menu_choice_dimensions_cb), sd); | 2738 G_CALLBACK(menu_choice_dimensions_cb), sd); |
2666 pad_box = pref_box_new(hbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 2); | 2739 pad_box = pref_box_new(hbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 2); |
2677 G_CALLBACK(menu_choice_spin_cb), &sd->search_width_end); | 2750 G_CALLBACK(menu_choice_spin_cb), &sd->search_width_end); |
2678 pref_label_new(hbox2, "x"); | 2751 pref_label_new(hbox2, "x"); |
2679 sd->spin_height_end = menu_spin(hbox2, 0, 1000000, sd->search_height_end, | 2752 sd->spin_height_end = menu_spin(hbox2, 0, 1000000, sd->search_height_end, |
2680 G_CALLBACK(menu_choice_spin_cb), &sd->search_height_end); | 2753 G_CALLBACK(menu_choice_spin_cb), &sd->search_height_end); |
2681 | 2754 |
2755 /* Search for image similarity */ | |
2682 hbox = menu_choice(sd->box_search, &sd->check_similarity, NULL, | 2756 hbox = menu_choice(sd->box_search, &sd->check_similarity, NULL, |
2683 _("Image content is"), &sd->match_similarity_enable, | 2757 _("Image content is"), &sd->match_similarity_enable, |
2684 NULL, 0, NULL, sd); | 2758 NULL, 0, NULL, sd); |
2685 sd->spin_similarity = menu_spin(hbox, 80, 100, sd->search_similarity, | 2759 sd->spin_similarity = menu_spin(hbox, 80, 100, sd->search_similarity, |
2686 G_CALLBACK(menu_choice_spin_cb), &sd->search_similarity); | 2760 G_CALLBACK(menu_choice_spin_cb), &sd->search_similarity); |
2693 "search_similarity_path", -1, NULL, NULL); | 2767 "search_similarity_path", -1, NULL, NULL); |
2694 tab_completion_add_select_button(sd->entry_similarity, NULL, FALSE); | 2768 tab_completion_add_select_button(sd->entry_similarity, NULL, FALSE); |
2695 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); | 2769 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); |
2696 gtk_widget_show(combo); | 2770 gtk_widget_show(combo); |
2697 | 2771 |
2772 /* Search for image keywords */ | |
2698 hbox = menu_choice(sd->box_search, &sd->check_keywords, &sd->menu_keywords, | 2773 hbox = menu_choice(sd->box_search, &sd->check_keywords, &sd->menu_keywords, |
2699 _("Keywords"), &sd->match_keywords_enable, | 2774 _("Keywords"), &sd->match_keywords_enable, |
2700 text_search_menu_keyword, sizeof(text_search_menu_keyword) / sizeof(MatchList), | 2775 text_search_menu_keyword, sizeof(text_search_menu_keyword) / sizeof(MatchList), |
2701 G_CALLBACK(menu_choice_keyword_cb), sd); | 2776 G_CALLBACK(menu_choice_keyword_cb), sd); |
2702 sd->entry_keywords = gtk_entry_new(); | 2777 sd->entry_keywords = gtk_entry_new(); |
2703 gtk_box_pack_start(GTK_BOX(hbox), sd->entry_keywords, TRUE, TRUE, 0); | 2778 gtk_box_pack_start(GTK_BOX(hbox), sd->entry_keywords, TRUE, TRUE, 0); |
2704 gtk_widget_set_sensitive(sd->entry_keywords, sd->match_keywords_enable); | 2779 gtk_widget_set_sensitive(sd->entry_keywords, sd->match_keywords_enable); |
2705 g_signal_connect(G_OBJECT(sd->check_keywords), "toggled", | 2780 g_signal_connect(G_OBJECT(sd->check_keywords), "toggled", |
2706 G_CALLBACK(menu_choice_check_cb), sd->entry_keywords); | 2781 G_CALLBACK(menu_choice_check_cb), sd->entry_keywords); |
2707 gtk_widget_show(sd->entry_keywords); | 2782 gtk_widget_show(sd->entry_keywords); |
2783 | |
2784 /* Search for image comment */ | |
2785 hbox = menu_choice(sd->box_search, &sd->check_comment, &sd->menu_comment, | |
2786 _("Comment"), &sd->match_comment_enable, | |
2787 text_search_menu_comment, sizeof(text_search_menu_comment) / sizeof(MatchList), | |
2788 G_CALLBACK(menu_choice_comment_cb), sd); | |
2789 sd->entry_comment = gtk_entry_new(); | |
2790 gtk_box_pack_start(GTK_BOX(hbox), sd->entry_comment, TRUE, TRUE, 0); | |
2791 gtk_widget_set_sensitive(sd->entry_comment, sd->match_comment_enable); | |
2792 g_signal_connect(G_OBJECT(sd->check_comment), "toggled", | |
2793 G_CALLBACK(menu_choice_check_cb), sd->entry_comment); | |
2794 gtk_widget_show(sd->entry_comment); | |
2795 pref_checkbox_new_int(hbox, _("Match case"), | |
2796 sd->search_comment_match_case, &sd->search_comment_match_case); | |
2797 | |
2798 /* Done the types of searches */ | |
2708 | 2799 |
2709 scrolled = gtk_scrolled_window_new(NULL, NULL); | 2800 scrolled = gtk_scrolled_window_new(NULL, NULL); |
2710 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | 2801 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); |
2711 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | 2802 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
2712 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | 2803 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |