Commit fb3471c6 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

[search] allow to search in the catalogs and libraries as well

parent b300336c
......@@ -773,16 +773,24 @@ get_tag_value (const char *buffer,
const char *tag_start,
const char *tag_end)
{
char *begin_tag;
char *end_tag;
char *value;
char *begin_tag;
value = NULL;
begin_tag = strstr (buffer, tag_start);
if (begin_tag != NULL) {
begin_tag += strlen (tag_start);
char *end_tag;
char *xml;
DomDocument *doc;
end_tag = strstr (begin_tag, tag_end);
value = g_strndup (begin_tag, end_tag - begin_tag);
xml = g_strndup (begin_tag, (end_tag - begin_tag) + strlen (tag_end));
doc = dom_document_new ();
if (dom_document_load (doc, xml, strlen (xml), NULL))
value = g_strdup (dom_element_get_inner_text (DOM_ELEMENT (doc)->first_child));
g_object_unref (doc);
g_free (xml);
}
return value;
......
......@@ -66,19 +66,11 @@ void
gth_browser_activate_action_edit_find (GtkAction *action,
GthBrowser *browser)
{
GthSearch *search;
GthFileSource *file_source;
GtkWidget *dialog;
GthSearch *search;
GtkWidget *dialog;
search = gth_search_new ();
file_source = gth_main_get_file_source (gth_browser_get_location (browser));
if (GTH_IS_FILE_SOURCE_VFS (file_source)) {
GFile *folder;
folder = gth_file_source_to_gio_file (file_source, gth_browser_get_location (browser));
gth_search_set_folder (search, folder);
g_object_unref (folder);
}
gth_search_set_folder (search, gth_browser_get_location (browser));
gth_search_set_recursive (search, TRUE);
dialog = gth_search_editor_dialog_new (_("Find"), search, GTK_WINDOW (browser));
......@@ -92,7 +84,6 @@ gth_browser_activate_action_edit_find (GtkAction *action,
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
gtk_window_present (GTK_WINDOW (dialog));
g_object_unref (file_source);
g_object_unref (search);
}
......
......@@ -24,12 +24,11 @@
</packing>
</child>
<child>
<object class="GtkFileChooserButton" id="start_at_filechooserbutton">
<property name="width_request">200</property>
<object class="GtkHBox" id="location_box">
<property name="visible">True</property>
<property name="action">select-folder</property>
<property name="create_folders">False</property>
<property name="title" translatable="yes"></property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">1</property>
......
......@@ -28,14 +28,10 @@
#include "gth-search-editor-dialog.h"
#define GET_WIDGET(name) _gtk_builder_get_widget (self->priv->builder, (name))
static gpointer parent_class = NULL;
struct _GthSearchEditorDialogPrivate {
GtkBuilder *builder;
GtkWidget *search_editor;
};
......@@ -117,7 +113,7 @@ gth_search_editor_dialog_construct (GthSearchEditorDialog *self,
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), 5);
gtk_container_set_border_width (GTK_CONTAINER (self), 5);
self->priv->search_editor = gth_search_editor_new (search);
self->priv->search_editor = gth_search_editor_new (search);
gtk_container_set_border_width (GTK_CONTAINER (self->priv->search_editor), 5);
gtk_widget_show (self->priv->search_editor);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), self->priv->search_editor, TRUE, TRUE, 0);
......
......@@ -35,6 +35,7 @@ static gpointer parent_class = NULL;
struct _GthSearchEditorPrivate {
GtkBuilder *builder;
GtkWidget *location_chooser;
GtkWidget *match_type_combobox;
};
......@@ -129,6 +130,10 @@ gth_search_editor_construct (GthSearchEditor *self,
gtk_container_set_border_width (GTK_CONTAINER (content), 0);
gtk_box_pack_start (GTK_BOX (self), content, TRUE, TRUE, 0);
self->priv->location_chooser = gth_location_chooser_new ();
gtk_widget_show (self->priv->location_chooser);
gtk_box_pack_start (GTK_BOX (GET_WIDGET ("location_box")), self->priv->location_chooser, TRUE, TRUE, 0);
self->priv->match_type_combobox = gtk_combo_box_new_text ();
_gtk_combo_box_append_texts (GTK_COMBO_BOX (self->priv->match_type_combobox),
_("all the following rules"),
......@@ -147,7 +152,7 @@ gth_search_editor_construct (GthSearchEditor *self,
GtkWidget *
gth_search_editor_new (GthSearch *search)
gth_search_editor_new (GthSearch *search)
{
GthSearchEditor *self;
......@@ -216,7 +221,12 @@ _gth_search_editor_add_test (GthSearchEditor *self,
static void
_gth_search_editor_set_new_search (GthSearchEditor *self)
{
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (GET_WIDGET ("start_at_filechooserbutton")), get_home_uri ());
GFile *home_location;
home_location = g_file_new_for_uri (get_home_uri ());
gth_location_chooser_set_current (GTH_LOCATION_CHOOSER (self->priv->location_chooser), home_location);
g_object_unref (home_location);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("include_subfolders_checkbutton")), TRUE);
_gtk_container_remove_children (GTK_CONTAINER (GET_WIDGET ("tests_box")), NULL, NULL);
}
......@@ -237,15 +247,7 @@ gth_search_editor_set_search (GthSearchEditor *self,
return;
}
if (gth_search_get_folder (search) != NULL) {
char *uri;
uri = g_file_get_uri (gth_search_get_folder (search));
if (uri != NULL) {
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (GET_WIDGET ("start_at_filechooserbutton")), uri);
g_free (uri);
}
}
gth_location_chooser_set_current (GTH_LOCATION_CHOOSER (self->priv->location_chooser), gth_search_get_folder (search));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("include_subfolders_checkbutton")), gth_search_is_recursive (search));
test = gth_search_get_test (search);
......@@ -277,21 +279,16 @@ gth_search_editor_get_search (GthSearchEditor *self,
GError **error)
{
GthSearch *search;
char *uri;
GFile *folder;
GthTest *test;
GList *test_selectors;
GList *scan;
search = gth_search_new ();
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (GET_WIDGET ("start_at_filechooserbutton")));
if (uri != NULL) {
GFile *folder;
folder = g_file_new_for_uri (uri);
folder = gth_location_chooser_get_current (GTH_LOCATION_CHOOSER (self->priv->location_chooser));
if (folder != NULL)
gth_search_set_folder (search, folder);
g_object_unref (folder);
}
gth_search_set_recursive (search, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("include_subfolders_checkbutton"))));
......
......@@ -30,14 +30,15 @@
struct _GthSearchTaskPrivate
{
GthBrowser *browser;
GthSearch *search;
GthTestChain *test;
GFile *search_catalog;
gboolean io_operation;
GError *error;
gulong location_ready_id;
GtkWidget *dialog;
GthBrowser *browser;
GthSearch *search;
GthTestChain *test;
GFile *search_catalog;
gboolean io_operation;
GError *error;
gulong location_ready_id;
GtkWidget *dialog;
GthFileSource *file_source;
};
......@@ -60,6 +61,7 @@ gth_task_finalize (GObject *object)
task = GTH_SEARCH_TASK (object);
if (task->priv != NULL) {
g_object_unref (task->priv->file_source);
g_object_unref (task->priv->search);
g_object_unref (task->priv->test);
g_object_unref (task->priv->search_catalog);
......@@ -146,7 +148,8 @@ save_search_result_copy_done_cb (void *buffer,
static void
done_func (GError *error,
done_func (GObject *object,
GError *error,
gpointer user_data)
{
GthSearchTask *task = user_data;
......@@ -290,15 +293,17 @@ browser_location_ready_cb (GthBrowser *browser,
}
task->priv->io_operation = TRUE;
g_directory_foreach_child (gth_search_get_folder (task->priv->search),
gth_search_is_recursive (task->priv->search),
TRUE,
eel_gconf_get_boolean (PREF_FAST_FILE_TYPE, TRUE) ? GFILE_STANDARD_ATTRIBUTES_WITH_FAST_CONTENT_TYPE : GFILE_STANDARD_ATTRIBUTES_WITH_CONTENT_TYPE,
gth_task_get_cancellable (GTH_TASK (task)),
start_dir_func,
for_each_file_func,
done_func,
task);
task->priv->file_source = gth_main_get_file_source (gth_search_get_folder (task->priv->search));
gth_file_source_set_cancellable (task->priv->file_source, gth_task_get_cancellable (GTH_TASK (task)));
gth_file_source_for_each_child (task->priv->file_source,
gth_search_get_folder (task->priv->search),
gth_search_is_recursive (task->priv->search),
eel_gconf_get_boolean (PREF_FAST_FILE_TYPE, TRUE) ? GFILE_STANDARD_ATTRIBUTES_WITH_FAST_CONTENT_TYPE : GFILE_STANDARD_ATTRIBUTES_WITH_CONTENT_TYPE,
start_dir_func,
for_each_file_func,
done_func,
task);
}
......
......@@ -787,6 +787,17 @@ gth_file_source_set_active (GthFileSource *file_source,
}
void
gth_file_source_set_cancellable (GthFileSource *file_source,
GCancellable *cancellable)
{
_g_object_unref (file_source->priv->cancellable);
file_source->priv->cancellable = NULL;
if (cancellable != NULL)
file_source->priv->cancellable = g_object_ref (cancellable);
}
GList *
gth_file_source_get_entry_points (GthFileSource *file_source)
{
......
......@@ -126,7 +126,9 @@ GType gth_file_source_get_type (void) G_GNUC_CONST;
/*< public >*/
GList * gth_file_source_get_entry_points (GthFileSource *file_source); /* GthFileData list */
void gth_file_source_set_cancellable (GthFileSource *file_source,
GCancellable *cancellable);
GList * gth_file_source_get_entry_points (GthFileSource *file_source); /* returns GthFileData list */
GList * gth_file_source_get_current_list (GthFileSource *file_source, /* GFile list */
GFile *file);
GFile * gth_file_source_to_gio_file (GthFileSource *file_source,
......
......@@ -319,6 +319,9 @@ gth_main_get_file_source (GFile *file)
char *uri;
GthFileSource *file_source;
if (file == NULL)
return NULL;
uri = g_file_get_uri (file);
file_source = gth_main_get_file_source_for_uri (uri);
g_free (uri);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment