📄 search.c
字号:
return TRUE; } else { image_loader_free(sd->img_loader); sd->img_loader = NULL; } } } if (tmatch && sd->match_dimensions_enable && sd->img_cd->dimensions) { CacheData *cd = sd->img_cd; tmatch = FALSE; tested = TRUE; if (sd->match_dimensions == SEARCH_MATCH_EQUAL) { tmatch = (cd->width == sd->search_width && cd->height == sd->search_height); } else if (sd->match_dimensions == SEARCH_MATCH_UNDER) { tmatch = (cd->width < sd->search_width && cd->height < sd->search_height); } else if (sd->match_dimensions == SEARCH_MATCH_OVER) { tmatch = (cd->width > sd->search_width && cd->height > sd->search_height); } else if (sd->match_dimensions == SEARCH_MATCH_BETWEEN) { tmatch = (MATCH_IS_BETWEEN(cd->width, sd->search_width, sd->search_width_end) && MATCH_IS_BETWEEN(cd->height, sd->search_height, sd->search_height_end)); } } if (tmatch && sd->match_similarity_enable && sd->img_cd->similarity) { gdouble value = 0.0; tmatch = FALSE; tested = TRUE; /* fixme: implement similarity checking */ if (sd->search_similarity_cd && sd->search_similarity_cd->similarity) { gdouble result; result = image_sim_compare_fast(sd->search_similarity_cd->sim, sd->img_cd->sim, (gdouble)sd->search_similarity / 100.0); result *= 100.0; if (result >= (gdouble)sd->search_similarity) { tmatch = TRUE; value = (gint)result; } } if (simval) *simval = value; } if (sd->img_cd->dimensions) { if (width) *width = sd->img_cd->width; if (height) *height = sd->img_cd->height; } cache_sim_data_free(sd->img_cd); sd->img_cd = NULL; *match = (tmatch && tested); return FALSE;}static gint search_file_next(SearchData *sd){ FileData *fd; gint match = TRUE; gint tested = FALSE; gint extra_only = FALSE; gint width = 0; gint height = 0; gint sim = 0; if (!sd->search_file_list) return FALSE; if (sd->img_cd) { /* on end of a CacheData load, skip recomparing non-extra match types */ extra_only = TRUE; match = FALSE; } else { sd->search_total++; } fd = sd->search_file_list->data; if (match && sd->match_name_enable && sd->search_name) { tested = TRUE; match = FALSE; if (sd->match_name == SEARCH_MATCH_EQUAL) { if (sd->search_name_match_case) { match = (strcmp(fd->name, sd->search_name) == 0); } else { match = (strcasecmp(fd->name, sd->search_name) == 0); } } else if (sd->match_name == SEARCH_MATCH_CONTAINS) { if (sd->search_name_match_case) { match = (strstr(fd->name, sd->search_name) != NULL); } else { /* sd->search_name is converted in search_start() */ gchar *haystack = g_utf8_strdown(fd->name, -1); match = (strstr(haystack, sd->search_name) != NULL); g_free(haystack); } } } if (match && sd->match_size_enable) { tested = TRUE; match = FALSE; if (sd->match_size == SEARCH_MATCH_EQUAL) { match = (fd->size == sd->search_size); } else if (sd->match_size == SEARCH_MATCH_UNDER) { match = (fd->size < sd->search_size); } else if (sd->match_size == SEARCH_MATCH_OVER) { match = (fd->size > sd->search_size); } else if (sd->match_size == SEARCH_MATCH_BETWEEN) { match = MATCH_IS_BETWEEN(fd->size, sd->search_size, sd->search_size_end); } } if (match && sd->match_date_enable) { tested = TRUE; match = FALSE; if (sd->match_date == SEARCH_MATCH_EQUAL) { struct tm *lt; lt = localtime(&fd->date); match = (lt && lt->tm_year == sd->search_date_y - 1900 && lt->tm_mon == sd->search_date_m - 1 && lt->tm_mday == sd->search_date_d); } else if (sd->match_date == SEARCH_MATCH_UNDER) { match = (fd->date < convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y)); } else if (sd->match_date == SEARCH_MATCH_OVER) { match = (fd->date > convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y) + 60 * 60 * 24 - 1); } else if (sd->match_date == SEARCH_MATCH_BETWEEN) { time_t a = convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y); time_t b = convert_dmy_to_time(sd->search_date_end_d, sd->search_date_end_m, sd->search_date_end_y); if (b >= a) { b += 60 * 60 * 24 - 1; } else { a += 60 * 60 * 24 - 1; } match = MATCH_IS_BETWEEN(fd->date, a, b); } } if (match && sd->match_keywords_enable && sd->search_keyword_list) { GList *list; tested = TRUE; match = FALSE; if (comment_cache_read(fd->path, &list, NULL)) { GList *needle; GList *haystack; if (sd->match_keywords == SEARCH_MATCH_ALL) { gint found = TRUE; needle = sd->search_keyword_list; while (needle && found) { found = FALSE; haystack = list; while (haystack && !found) { found = (strcasecmp((gchar *)needle->data, (gchar *)haystack->data) == 0); haystack = haystack->next; } needle = needle->next; } match = found; } else if (sd->match_keywords == SEARCH_MATCH_ANY) { gint found = FALSE; needle = sd->search_keyword_list; while (needle && !found) { haystack = list; while (haystack && !found) { found = (strcasecmp((gchar *)needle->data, (gchar *)haystack->data) == 0); haystack = haystack->next; } needle = needle->next; } match = found; } else if (sd->match_keywords == SEARCH_MATCH_NONE) { gint found = FALSE; needle = sd->search_keyword_list; while (needle && !found) { haystack = list; while (haystack && !found) { found = (strcasecmp((gchar *)needle->data, (gchar *)haystack->data) == 0); haystack = haystack->next; } needle = needle->next; } match = !found; } path_list_free(list); } else { match = (sd->match_keywords == SEARCH_MATCH_NONE); } } if ((match || extra_only) && (sd->match_dimensions_enable || sd->match_similarity_enable)) { tested = TRUE; if (search_file_do_extra(sd, fd, &match, &width, &height, &sim)) { sd->search_buffer_count += SEARCH_BUFFER_MATCH_LOAD; return TRUE; } } sd->search_file_list = g_list_remove(sd->search_file_list, fd); if (tested && match) { MatchFileData *mfd; mfd = g_new(MatchFileData, 1); memcpy(mfd, fd, sizeof(FileData)); g_free(fd); mfd->width = width; mfd->height = height; mfd->rank = sim; sd->search_buffer_list = g_list_prepend(sd->search_buffer_list, mfd); sd->search_buffer_count += SEARCH_BUFFER_MATCH_HIT; sd->search_count++; search_progress_update(sd, TRUE, -1.0); } else { file_data_free(fd); sd->search_buffer_count += SEARCH_BUFFER_MATCH_MISS; } return FALSE;}static gint search_step_cb(gpointer data){ SearchData *sd = data; FileData *fd; if (sd->search_buffer_count > SEARCH_BUFFER_FLUSH_SIZE) { search_buffer_flush(sd); search_progress_update(sd, TRUE, -1.0); } if (sd->search_file_list) { if (search_file_next(sd)) { sd->search_idle_id = -1; return FALSE; } return TRUE; } if (!sd->search_file_list && !sd->search_folder_list) { sd->search_idle_id = -1; search_stop(sd); search_result_thumb_step(sd); return FALSE; } fd = sd->search_folder_list->data; if (g_list_find(sd->search_done_list, fd) == NULL) { GList *list = NULL; GList *dlist = NULL; gint success = FALSE; sd->search_done_list = g_list_prepend(sd->search_done_list, fd); if (sd->search_type == SEARCH_MATCH_NONE) { success = filelist_read(fd->path, &list, &dlist); } else if (sd->search_type == SEARCH_MATCH_ALL && sd->search_path && strlen(fd->path) >= strlen(sd->search_path)) { const gchar *path; path = fd->path + strlen(sd->search_path); if (path != fd->path) success = filelist_read(path, &list, NULL); success |= filelist_read(fd->path, NULL, &dlist); if (success) { GList *work; work = list; while (work) { FileData *fdp; GList *link; gchar *meta_path; fdp = work->data; link = work; work = work->next; meta_path = cache_find_location(CACHE_TYPE_METADATA, fdp->path); if (!meta_path) { list = g_list_delete_link(list, link); file_data_free(fdp); } g_free(meta_path); } } } if (success) { list = filelist_sort(list, SORT_NAME, TRUE); sd->search_file_list = list; if (sd->search_path_recurse) { dlist = filelist_sort(dlist, SORT_NAME, TRUE); sd->search_folder_list = g_list_concat(dlist, sd->search_folder_list); } else { filelist_free(dlist); } } } else { sd->search_folder_list = g_list_remove(sd->search_folder_list, fd); sd->search_done_list = g_list_remove(sd->search_done_list, fd); file_data_free(fd); } return TRUE;}static void search_similarity_load_done_cb(ImageLoader *il, gpointer data){ SearchData *sd = data; search_file_load_process(sd, sd->search_similarity_cd);}static void search_start(SearchData *sd){ search_stop(sd); search_result_clear(sd); if (sd->search_path) { sd->search_folder_list = g_list_prepend(sd->search_folder_list, file_data_new_simple(sd->search_path)); } if (!sd->search_name_match_case) { /* convert to lowercase here, so that this is only done once per search */ gchar *tmp = g_utf8_strdown(sd->search_name, -1); g_free(sd->search_name); sd->search_name = tmp; } sd->search_count = 0; sd->search_total = 0; gtk_widget_set_sensitive(sd->box_search, FALSE); spinner_set_interval(sd->spinner, SPINNER_SPEED); gtk_widget_set_sensitive(sd->button_start, FALSE); gtk_widget_set_sensitive(sd->button_stop, TRUE); search_progress_update(sd, TRUE, -1.0); if (sd->match_similarity_enable && !sd->search_similarity_cd && isfile(sd->search_similarity_path)) { gchar *cd_path; cd_path = cache_find_location(CACHE_TYPE_SIM, sd->search_similarity_path); if (cd_path && filetime(sd->search_similarity_path) == filetime(cd_path)) { sd->search_similarity_cd = cache_sim_data_load(cd_path); } g_free(cd_path); if (!sd->search_similarity_cd || !sd->search_similarity_cd->similarity) { if (!sd->search_similarity_cd) { sd->search_similarity_cd = cache_sim_data_new(); } sd->img_loader = image_loader_new(sd->search_similarity_path); image_loader_set_error_func(sd->img_loader, search_similarity_load_done_cb, sd); if (image_loader_start(sd->img_loader, search_similarity_load_done_cb, sd)) { return; } image_loader_free(sd->img_loader); sd->img_loader = NULL; } } sd->search_idle_id = g_idle_add(search_step_cb, sd);}static void search_start_cb(GtkWidget *widget, gpointer data){ SearchData *sd = data; GtkTreeViewColumn *column; gchar *path; if (sd->search_folder_list) { search_stop(sd); search_result_thumb_step(sd); return; } if (sd->match_name_enable) history_combo_append_history(sd->entry_name, NULL); g_free(sd->search_name); sd->search_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_name))); g_free(sd->search_similarity_path); sd->search_similarity_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_similarity))); if (sd->match_similarity_enable) { if (!isfile(sd->search_similarity_path)) { file_util_warning_dialog(_("File not found"), _("Please enter an existing file for image content."), GTK_STOCK_DIALOG_WARNING, sd->window); return; } tab_completion_append_to_history(sd->entry_similarity, sd->search_similarity_path); } path_list_free(sd->search_keyword_list); sd->search_keyword_list = keyword_list_pull(sd->entry_keywords); date_selection_get(sd->date_sel, &sd->search_date_d, &sd->search_date_m, &sd->search_date_y); date_selection_get(sd->date_sel_end, &sd->search_date_end_d, &sd->search_date_end_m, &sd->search_date_end_y); column = gtk_tree_view_get_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_RANK - 1); gtk_tree_view_column_set_visible(column, sd->match_similarity_enable);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -