From 88d62c58ebbea6f08dd45394678d3092ef6ba649 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 1 Nov 2007 18:11:50 +0200 Subject: [PATCH] Fix searching of POIs with just category. Use helper functions to get lat/lon or item id from list view. --- src/search.c | 94 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/src/search.c b/src/search.c index 5044327..65d7afe 100644 --- a/src/search.c +++ b/src/search.c @@ -51,7 +51,7 @@ #include "poi-gui.h" #include "osm.h" #include "help.h" - +#include "osm-db.h" #include "search.h" typedef struct _search_query poi_search_query; @@ -89,23 +89,22 @@ search_dialog *s=(search_dialog *)data; slen=strlen(gtk_entry_get_text(GTK_ENTRY(s->search_entry))); -if (slen<2 && s->stype==SEARCH_TYPE_POI && cid!=-1) { +if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(s->cmb_category), &iter)==TRUE) + gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(s->cmb_category)), &iter, 0, &cid, -1); +else + cid=-1; +if (s->stype==SEARCH_TYPE_POI && cid==-1 && slen<2) { + popup_error(s->dialog, _("Query string too short. Minimum 2 characters.")); + return TRUE; +} else if (slen<2 && s->stype!=SEARCH_TYPE_POI) { popup_error(s->dialog, _("Query string too short. Minimum 2 characters.")); return TRUE; -} else if (slen<3 && s->stype!=SEARCH_TYPE_POI) { - popup_error(s->dialog, _("Query string too short. Minimum 3 characters.")); - return TRUE; } st=g_strdup(gtk_entry_get_text(GTK_ENTRY(s->search_entry))); switch (s->stype) { case SEARCH_TYPE_POI: - if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(s->cmb_category), &iter)==TRUE) - gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(s->cmb_category)), &iter, 0, &cid, -1); - else - cid=-1; - if (poi_search((cid==-1) ? POI_SEARCH_TEXT : POI_SEARCH_TEXT_CAT, s->lat, s->lon, st, cid, &s->store)==TRUE) { gtk_tree_view_set_model(GTK_TREE_VIEW(s->list), GTK_TREE_MODEL(s->store)); g_object_unref(G_OBJECT(s->store)); @@ -132,51 +131,68 @@ return TRUE; } static gboolean -search_goto_cb(GtkWidget *widget, gpointer data) +search_get_list_item_latlon(GtkWidget *list, gdouble *lat, gdouble *lon) { GtkTreeIter iter; GtkTreeModel *model; -gdouble lat, lon; -search_dialog *s=(search_dialog *)data; -if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(s->list)), NULL, &iter)) { - popup_error(s->dialog, _("Select one POI from the list.")); - return TRUE; +if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(list)), NULL, &iter)) + return FALSE; + +model=gtk_tree_view_get_model(GTK_TREE_VIEW(list)); +if (!model) + return FALSE; + +gtk_tree_model_get(model, &iter, ITEM_LAT, lat, -1); +gtk_tree_model_get(model, &iter, ITEM_LON, lon, -1); +return TRUE; } -model=gtk_tree_view_get_model(GTK_TREE_VIEW(s->list)); +static guint +search_get_list_item_id(GtkWidget *list) +{ +guint id; +GtkTreeIter iter; +GtkTreeModel *model; + +if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(list)), NULL, &iter)) + return 0; + +model=gtk_tree_view_get_model(GTK_TREE_VIEW(list)); if (!model) - return TRUE; + return 0; + +gtk_tree_model_get(model, &iter, ITEM_ID, &id, -1); +return id; +} + +static gboolean +search_goto_cb(GtkWidget *widget, gpointer data) +{ +gdouble lat, lon; +search_dialog *s=(search_dialog *)data; -gtk_tree_model_get(model, &iter, ITEM_LAT, &lat, -1); -gtk_tree_model_get(model, &iter, ITEM_LON, &lon, -1); +if (search_get_list_item_latlon(s->list, &lat, &lon)==FALSE) { + popup_error(s->dialog, _("Select a location from the list.")); + return TRUE; +} map_center_latlon(lat, lon); map_update_location_from_center(); - return TRUE; } static gboolean search_route_to_cb(GtkWidget *widget, gpointer data) { -GtkTreeIter iter; -GtkTreeModel *model; search_dialog *s=(search_dialog *)data; -if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(s->list)), NULL, &iter)) { - popup_error(s->dialog, _("Select one POI from the list.")); +if (search_get_list_item_latlon(s->list, &_dest.lat, &_dest.lon)==FALSE) { + popup_error(s->dialog, _("Select a location from the list.")); return TRUE; } -model=gtk_tree_view_get_model(GTK_TREE_VIEW(s->list)); -if (!model) - return TRUE; - _dest.valid=TRUE; -gtk_tree_model_get(model, &iter, ITEM_LAT, &_dest.lat, -1); -gtk_tree_model_get(model, &iter, ITEM_LON, &_dest.lon, -1); - map_update_location_from_center(); return TRUE; @@ -185,7 +201,14 @@ return TRUE; static gboolean search_edit_cb(GtkWidget *widget, gpointer data) { +search_dialog *s=(search_dialog *)data; +switch (s->stype) { + case SEARCH_TYPE_POI: + break; + default: + break; +} return TRUE; } @@ -222,9 +245,12 @@ return TRUE; } static void -search_item_activated_cb(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) +search_item_activated_cb(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer data) { -g_printf("Boom!\n"); +#if 0 +search_dialog *s=(search_dialog *)data; +gtk_widget_destroy(sd.dialog); +#endif } gboolean -- 2.39.5