]> err.no Git - mapper/blobdiff - src/search.c
Add header and cast properly.
[mapper] / src / search.c
index 983dcf816667a6b526b59f9a4913cba7dc3f0ba7..59ae62dbf3f177bac3418948873b753775ae7dbd 100644 (file)
@@ -24,8 +24,6 @@
 
 #include <config.h>
 
-#define _GNU_SOURCE
-
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include "help.h"
 #include "osm-db.h"
 #include "search.h"
-
-typedef struct _search_query poi_search_query;
-struct _search_query {
-       gdouble lat;
-       gdouble lon;
-       guint cat_id;
-       gchar *query;
-};
+#include "dialogs.h"
 
 typedef struct _search_dialog search_dialog;
 struct _search_dialog {
@@ -77,6 +68,7 @@ struct _search_dialog {
 };
 
 static search_dialog sd;
+static GtkListStore *search_model=NULL;
 
 static gboolean
 search_do_cb(GtkWidget *widget, gpointer data)
@@ -94,10 +86,18 @@ if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(s->cmb_category), &iter)==TRUE)
 else
        cid=-1;
 if (s->stype==SEARCH_TYPE_POI && cid==-1 && slen<2) {
+#ifdef WITH_HILDON
+       hildon_banner_show_information(s->dialog, NULL, _("Query string too short. Minimum 2 characters."));
+#else
        popup_error(s->dialog, _("Query string too short. Minimum 2 characters."));
+#endif
        return TRUE;
 } else if (slen<2 && s->stype!=SEARCH_TYPE_POI) {
+#ifdef WITH_HILDON
+       hildon_banner_show_information(s->dialog, NULL, _("Query string too short. Minimum 2 characters."));
+#else
        popup_error(s->dialog, _("Query string too short. Minimum 2 characters."));
+#endif
        return TRUE;
 }
 
@@ -105,14 +105,15 @@ st=g_strdup(gtk_entry_get_text(GTK_ENTRY(s->search_entry)));
 
 switch (s->stype) {
        case SEARCH_TYPE_POI:
+               MACRO_BANNER_SHOW_INFO(s->dialog, _("Searching POIs..."));
                sres=poi_search((cid==-1 && slen>0) ? POI_SEARCH_TEXT : (cid!=-1 && slen==0) ? POI_SEARCH_CAT : POI_SEARCH_TEXT_CAT, s->lat, s->lon, st, cid, &s->store);
        break;
        case SEARCH_TYPE_WAY:
+               MACRO_BANNER_SHOW_INFO(s->dialog, _("Searching streets..."));
                sres=osm_way_search(s->lat, s->lon, st, &s->store);
        break;
        case SEARCH_TYPE_PLACE:
-               popup_error(s->dialog, "Not yet implemented");
-               sres=FALSE;
+               sres=osm_place_search(s->lat, s->lon, st, &s->store);
        break;
 }
 
@@ -201,7 +202,6 @@ search_dialog *s=(search_dialog *)data;
 gdouble lat, lon;
 GtkTreeIter iter;
 GtkTreeModel *model;
-guint id;
 
 if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)), NULL, &iter))
        return;
@@ -214,7 +214,7 @@ gtk_tree_model_get(model, &iter, ITEM_LAT, &lat, -1);
 gtk_tree_model_get(model, &iter, ITEM_LON, &lon, -1);
 
 map_center_latlon(lat, lon);
-map_update_location_from_center();
+g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL);
 #if 0
 gtk_widget_destroy(s->dialog);
 #endif
@@ -226,6 +226,7 @@ mapper_search_dialog(mapper_search_type stype, gdouble lat, gdouble lon)
 GtkWidget *sw, *hbox, *label, *btn_search;
 GtkTreeViewColumn *column;
 GtkCellRenderer *renderer;
+GtkEntryCompletion *search_comp;
 gint res;
 
 sd.store=NULL;
@@ -242,6 +243,9 @@ sd.dialog = gtk_dialog_new_with_buttons(_("Search"),
                        GTK_STOCK_CLOSE, GTK_RESPONSE_REJECT, 
                        NULL);
 
+if (search_model==NULL)
+       search_model=gtk_list_store_new(1, G_TYPE_STRING);
+
 gtk_window_set_default_size(GTK_WINDOW(sd.dialog), 500, 300);
 
 hbox = gtk_hbox_new(FALSE, 4),
@@ -253,9 +257,7 @@ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
 sd.cmb_type=gtk_combo_box_new_text();
 gtk_combo_box_append_text(GTK_COMBO_BOX(sd.cmb_type), "POI");
 gtk_combo_box_append_text(GTK_COMBO_BOX(sd.cmb_type), "Street");
-#if 0
 gtk_combo_box_append_text(GTK_COMBO_BOX(sd.cmb_type), "Place");
-#endif
 gtk_box_pack_start(GTK_BOX(hbox), sd.cmb_type, FALSE, FALSE, 0);
 
 sd.cmb_category = category_combo_new();
@@ -263,6 +265,10 @@ gtk_box_pack_start(GTK_BOX(hbox), sd.cmb_category, FALSE, FALSE, 0);
 poi_category_combo_populate(sd.cmb_category, 0, TRUE);
 
 sd.search_entry=gtk_entry_new();
+search_comp=gtk_entry_completion_new();
+gtk_entry_completion_set_model(search_comp, GTK_TREE_MODEL(search_model));
+gtk_entry_completion_set_text_column(search_comp, 0);
+gtk_entry_set_completion(GTK_ENTRY(sd.search_entry), search_comp);
 gtk_box_pack_start(GTK_BOX(hbox), sd.search_entry, TRUE, TRUE, 0);
 
 btn_search=gtk_button_new_with_label(_("Search"));
@@ -320,7 +326,7 @@ while ((res=gtk_dialog_run(GTK_DIALOG(sd.dialog)))!=GTK_RESPONSE_REJECT) {
                        popup_error(sd.dialog, _("Select a location from the list."));
                } else {
                        map_center_latlon(lat, lon);
-                       map_update_location_from_center();
+                       g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL);
                }
                continue;
        break;
@@ -329,7 +335,7 @@ while ((res=gtk_dialog_run(GTK_DIALOG(sd.dialog)))!=GTK_RESPONSE_REJECT) {
                        popup_error(sd.dialog, _("Select a location from the list."));
                } else {
                        _dest.valid=TRUE;
-                       map_update_location_from_center();
+                       g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL);
                }
                continue;
        break;