From 87aad0c6520f34d1d4cdcdc337cc73a023e58026 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sun, 26 Apr 2020 09:52:32 +0100 Subject: [PATCH] Search on collection Additional option on Search window - search on a Collection --- doc/docbook/GuideImageSearchSearch.xml | 6 ++ src/collect.c | 36 ++++++++ src/collect.h | 2 + src/search.c | 112 ++++++++++++++++++++++++- 4 files changed, 153 insertions(+), 3 deletions(-) diff --git a/doc/docbook/GuideImageSearchSearch.xml b/doc/docbook/GuideImageSearchSearch.xml index b47528cf..6b7c83d9 100644 --- a/doc/docbook/GuideImageSearchSearch.xml +++ b/doc/docbook/GuideImageSearchSearch.xml @@ -64,6 +64,12 @@ The search will include all files currently listed in the results list. Use this to refine a previous search. + + + Collection + + The search will include all files in the selected collection. + diff --git a/src/collect.c b/src/collect.c index 851a8539..30e592f6 100644 --- a/src/collect.c +++ b/src/collect.c @@ -425,6 +425,42 @@ void collection_contents(const gchar *name, GString **contents) } } +/** + * @brief Returns a list of filedatas of the contents of a Collection + * @param[in] name The name of the collection, with or wihout extension + * + * + */ +GList *collection_contents_fd(const gchar *name) +{ + gchar *path; + CollectionData *cd; + CollectInfo *ci; + GList *work; + FileData *fd; + GList *list = NULL; + + if (is_collection(name)) + { + path = collection_path(name); + cd = collection_new(""); + collection_load(cd, path, COLLECTION_LOAD_APPEND); + work = cd->list; + while (work) + { + ci = work->data; + fd = ci->fd; + list = g_list_append(list, ci->fd); + + work = work->next; + } + g_free(path); + collection_free(cd); + } + + return list; +} + /* *------------------------------------------------------------------- * please use these to actually add/remove stuff diff --git a/src/collect.h b/src/collect.h index 4475ad91..f5226a73 100644 --- a/src/collect.h +++ b/src/collect.h @@ -89,5 +89,7 @@ gboolean collection_window_modified_exists(void); gboolean is_collection(const gchar *param); gchar *collection_path(const gchar *param); void collection_contents(const gchar *name, GString **contents); +GList *collection_contents_fd(const gchar *name); + #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ diff --git a/src/search.c b/src/search.c index 2bb031b4..987c45a8 100644 --- a/src/search.c +++ b/src/search.c @@ -73,7 +73,8 @@ typedef enum { SEARCH_MATCH_OVER, SEARCH_MATCH_BETWEEN, SEARCH_MATCH_ALL, - SEARCH_MATCH_ANY + SEARCH_MATCH_ANY, + SEARCH_MATCH_COLLECTION } MatchType; enum { @@ -102,6 +103,10 @@ struct _SearchData GtkWidget *button_help; GtkWidget *spinner; + GtkWidget *collection; + GtkWidget *fd_button; + GtkWidget *collection_entry; + GtkWidget *box_search; GtkWidget *menu_path; @@ -261,7 +266,8 @@ struct _MatchList static const MatchList text_search_menu_path[] = { { N_("folder"), SEARCH_MATCH_NONE }, { N_("comments"), SEARCH_MATCH_ALL }, - { N_("results"), SEARCH_MATCH_CONTAINS } + { N_("results"), SEARCH_MATCH_CONTAINS }, + { N_("collection"), SEARCH_MATCH_COLLECTION } }; static const MatchList text_search_menu_name[] = { @@ -911,6 +917,8 @@ static void search_result_thumb_height(SearchData *sd) static void search_result_thumb_enable(SearchData *sd, gboolean enable) { + GtkTreeViewColumn *column; + if (sd->thumb_enable == enable) return; if (sd->thumb_enable) @@ -932,6 +940,12 @@ static void search_result_thumb_enable(SearchData *sd, gboolean enable) search_progress_update(sd, TRUE, -1.0); } + column = gtk_tree_view_get_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_THUMB - 1); + if (column) + { + gtk_tree_view_column_set_visible(column, enable); + } + sd->thumb_enable = enable; search_result_thumb_height(sd); @@ -2622,6 +2636,7 @@ static void search_start_cb(GtkWidget *widget, gpointer data) GtkTreeViewColumn *column; gchar *path; gchar *entry_text; + gchar *collection; if (sd->search_folder_list) { @@ -2747,6 +2762,29 @@ static void search_start_cb(GtkWidget *widget, gpointer data) sd->search_file_list = g_list_concat(sd->search_file_list, list); } + else if (sd->search_type == SEARCH_MATCH_COLLECTION) + { + collection = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->collection_entry))); + + if (is_collection(collection)) + { + GList *list = NULL; + + list = collection_contents_fd(collection); + + file_data_unref(sd->search_dir_fd); + sd->search_dir_fd = NULL; + + search_start(sd); + + sd->search_file_list = g_list_concat(sd->search_file_list, list); + } + else + { + file_util_warning_dialog(_("Collection not found"), _("Please enter an existing collection name."), GTK_STOCK_DIALOG_WARNING, sd->window); + } + g_free(collection); + } } /* @@ -2891,6 +2929,7 @@ static void menu_choice_path_cb(GtkWidget *combo, gpointer data) menu_choice_set_visible(gtk_widget_get_parent(sd->check_recurse), (sd->search_type == SEARCH_MATCH_NONE)); + menu_choice_set_visible(sd->collection, (sd->search_type == SEARCH_MATCH_COLLECTION)); } static void menu_choice_name_cb(GtkWidget *combo, gpointer data) @@ -3167,6 +3206,54 @@ static void search_window_destroy_cb(GtkWidget *widget, gpointer data) g_free(sd); } +static void select_collection_dialog_close_cb(FileDialog *fdlg, gpointer data) +{ + file_dialog_close(fdlg); +} + +static void select_collection_dialog_ok_cb(FileDialog *fdlg, gpointer data) +{ + SearchData *sd = data; + gchar *path; + gchar *path_noext; + gchar *collection; + + path = g_strdup(gtk_entry_get_text(GTK_ENTRY(fdlg->entry))); + path_noext = remove_extension_from_path(path); + collection = g_path_get_basename(path_noext); + + gtk_entry_set_text(GTK_ENTRY(sd->collection_entry), collection); + file_dialog_close(fdlg); + + g_free(path); + g_free(path_noext); + g_free(collection); +} + +static gboolean select_collection_clicked_cb(GtkWidget *widget, gpointer data) +{ + SearchData *sd = data; + FileDialog *fdlg; + const gchar *title; + const gchar *btntext; + gpointer btnfunc; + const gchar *stock_id; + + title = _("Select collection"); + btntext = NULL; + btnfunc = select_collection_dialog_ok_cb; + stock_id = GTK_STOCK_OK; + + fdlg = file_util_file_dlg(title, "dlg_collection", sd->window, select_collection_dialog_close_cb, sd); + + generic_dialog_add_message(GENERIC_DIALOG(fdlg), NULL, title, NULL, FALSE); + file_dialog_add_button(fdlg, stock_id, btntext, btnfunc, TRUE); + + file_dialog_add_path_widgets(fdlg, get_collections_dir(), NULL, "search_collection", GQ_COLLECTION_EXT, _("Collection Files")); + + gtk_widget_show(GENERIC_DIALOG(fdlg)->dialog); +} + void search_new(FileData *dir_fd, FileData *example_file) { SearchData *sd; @@ -3179,6 +3266,7 @@ void search_new(FileData *dir_fd, FileData *example_file) GtkListStore *store; GtkTreeSortable *sortable; GtkTreeSelection *selection; + GtkTreeViewColumn *column; GtkWidget *combo; GdkGeometry geometry; gint i; @@ -3277,6 +3365,19 @@ void search_new(FileData *dir_fd, FileData *example_file) sd->check_recurse = pref_checkbox_new_int(hbox2, _("Recurse"), sd->search_path_recurse, &sd->search_path_recurse); + sd->collection = pref_box_new(hbox, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); + sd->collection_entry = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(sd->collection_entry), ""); + gtk_box_pack_start(GTK_BOX(sd->collection), sd->collection_entry, TRUE, TRUE, 0); + gtk_widget_show(sd->collection_entry); + + sd->fd_button = gtk_button_new_with_label("..."); + g_signal_connect(G_OBJECT(sd->fd_button), "clicked", G_CALLBACK(select_collection_clicked_cb), sd); + gtk_box_pack_start(GTK_BOX(sd->collection), sd->fd_button, FALSE, FALSE, 0); + gtk_widget_show(sd->fd_button); + + gtk_widget_hide(sd->collection); + /* Search for file name */ hbox = menu_choice(sd->box_search, &sd->check_name, &sd->menu_name, _("File name"), &sd->match_name_enable, @@ -3537,7 +3638,7 @@ void search_new(FileData *dir_fd, FileData *example_file) gtk_tree_view_set_enable_search(GTK_TREE_VIEW(sd->result_view), FALSE); search_result_add_column(sd, SEARCH_COLUMN_RANK, _("Rank"), FALSE, FALSE); - search_result_add_column(sd, SEARCH_COLUMN_THUMB, "", TRUE, FALSE); + search_result_add_column(sd, SEARCH_COLUMN_THUMB, _("Thumb"), TRUE, FALSE); search_result_add_column(sd, SEARCH_COLUMN_NAME, _("Name"), FALSE, FALSE); search_result_add_column(sd, SEARCH_COLUMN_SIZE, _("Size"), FALSE, TRUE); search_result_add_column(sd, SEARCH_COLUMN_DATE, _("Date"), FALSE, TRUE); @@ -3595,6 +3696,11 @@ void search_new(FileData *dir_fd, FileData *example_file) sd->button_close = pref_button_new(hbox, GTK_STOCK_CLOSE, NULL, FALSE, G_CALLBACK(search_window_close_cb), sd); gtk_widget_set_sensitive(sd->button_close, TRUE); + search_result_thumb_enable(sd, TRUE); + search_result_thumb_enable(sd, FALSE); + column = gtk_tree_view_get_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_RANK - 1); + gtk_tree_view_column_set_visible(column, FALSE); + search_status_update(sd); search_progress_update(sd, FALSE, -1.0); -- 2.20.1