summaryrefslogtreecommitdiff
path: root/src/nautilus-simple-search-bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nautilus-simple-search-bar.c')
-rw-r--r--src/nautilus-simple-search-bar.c81
1 files changed, 73 insertions, 8 deletions
diff --git a/src/nautilus-simple-search-bar.c b/src/nautilus-simple-search-bar.c
index 1130966ee..aefaad77b 100644
--- a/src/nautilus-simple-search-bar.c
+++ b/src/nautilus-simple-search-bar.c
@@ -25,18 +25,22 @@
#include <config.h>
#include "nautilus-simple-search-bar.h"
+#include <libgnomevfs/gnome-vfs-utils.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
-#include <libnautilus-extensions/nautilus-search-uri.h>
struct NautilusSimpleSearchBarDetails {
GtkEntry *entry;
};
-static char *nautilus_simple_search_bar_get_location (NautilusNavigationBar *bar);
-static void nautilus_simple_search_bar_set_location (NautilusNavigationBar *bar,
- const char *location);
-static void nautilus_simple_search_bar_initialize_class (NautilusSimpleSearchBarClass *class);
-static void nautilus_simple_search_bar_initialize (NautilusSimpleSearchBar *bar);
+static char * nautilus_simple_search_bar_get_location (NautilusNavigationBar *bar);
+static void nautilus_simple_search_bar_set_location (NautilusNavigationBar *bar,
+ const char *location);
+
+static char * nautilus_search_uri_to_simple_search_criteria (const char *location);
+static char * nautilus_simple_search_criteria_to_search_uri (const char *search_criteria);
+
+static void nautilus_simple_search_bar_initialize_class (NautilusSimpleSearchBarClass *class);
+static void nautilus_simple_search_bar_initialize (NautilusSimpleSearchBar *bar);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusSimpleSearchBar,
nautilus_simple_search_bar,
@@ -54,6 +58,7 @@ nautilus_simple_search_bar_initialize (NautilusSimpleSearchBar *bar)
{
GtkWidget *entry;
GtkWidget *hbox;
+ GtkWidget *find_them, *find_them_label;
hbox = gtk_hbox_new (0, FALSE);
@@ -61,8 +66,19 @@ nautilus_simple_search_bar_initialize (NautilusSimpleSearchBar *bar)
gtk_signal_connect_object (GTK_OBJECT (entry), "activate",
nautilus_navigation_bar_location_changed, GTK_OBJECT (bar));
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+
+ find_them = gtk_button_new ();
+ find_them_label = gtk_label_new ("Find Them!");
+ gtk_container_add (GTK_CONTAINER (find_them), find_them_label);
+ gtk_signal_connect_object (GTK_OBJECT (find_them), "pressed",
+ nautilus_navigation_bar_location_changed,
+ GTK_OBJECT (bar));
+ gtk_box_pack_start (GTK_BOX (hbox), find_them, FALSE, TRUE, 1);
+
gtk_container_add (GTK_CONTAINER (bar), hbox);
+
+
gtk_widget_show_all (hbox);
@@ -85,8 +101,6 @@ nautilus_simple_search_bar_set_location (NautilusNavigationBar *navigation_bar,
/* We shouldn't have gotten here if the uri can't be displayed
* using a simple search bar
*/
- g_return_if_fail (nautilus_search_uri_is_displayable_by_mode (location, NAUTILUS_SIMPLE_SEARCH_BAR));
-
bar = NAUTILUS_SIMPLE_SEARCH_BAR (navigation_bar);
/* Set the words in the box to be the words originally done in the search */
@@ -105,3 +119,54 @@ nautilus_simple_search_bar_get_location (NautilusNavigationBar *navigation_bar)
search_entry_text = gtk_entry_get_text (bar->entry);
return nautilus_simple_search_criteria_to_search_uri (search_entry_text);
}
+
+
+
+char *
+nautilus_search_uri_to_simple_search_criteria (const char *uri)
+{
+ /* FIXME: Not yet implemented. */
+ return g_strdup ("");
+}
+
+char *
+nautilus_simple_search_criteria_to_search_uri (const char *search_criteria)
+{
+ char **words;
+ char *search_uri;
+ char *fragment;
+ char *escaped_fragment;
+ int length, i;
+
+ g_return_val_if_fail (search_criteria != NULL, NULL);
+
+ words = g_new0 (char *, strlen (search_criteria));
+ words = g_strsplit (search_criteria, " ", strlen (search_criteria));
+ /* FIXME: this should eventually be: length = strlen ("[file%3A%2F%2F%2F]"); */
+ length = strlen ("[file:///]");
+ /* Count total length */
+ for (i = 0; words[i] != NULL; i++) {
+ length += strlen (words[i]) + strlen ("file_name contains & ");
+ }
+ fragment = g_new0 (char, length);
+ /* FIXME: this should eventually be: sprintf (fragment, "[file%%3A%%2F%%2F%%2F]"); */
+ sprintf (fragment, "[file:///]");
+ if (words[0] != NULL) {
+ for (i = 0; words[i+1] != NULL; i++) {
+ strcat (fragment, "file_name contains ");
+ strcat (fragment, words[i]);
+ strcat (fragment, " & ");
+ }
+ strcat (fragment, "file_name contains ");
+ strcat (fragment, words[i]);
+ }
+ escaped_fragment = gnome_vfs_escape_string (fragment);
+ g_free (fragment);
+ search_uri = g_strconcat ("search:", escaped_fragment, NULL);
+ g_free (escaped_fragment);
+#ifdef SEARCH_URI_DEBUG
+ printf ("Made uri %s from simple search criteria %s\n",
+ search_uri, search_criteria);
+#endif
+ return search_uri;
+}